@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | * Hook in methods. |
15 | 15 | */ |
16 | 16 | public static function init() { |
17 | - add_action( 'init', array( __CLASS__, 'init_hooks' ), 0 ); |
|
18 | - add_action( 'admin_notices', array( __CLASS__, 'notices' ) ); |
|
17 | + add_action('init', array(__CLASS__, 'init_hooks'), 0); |
|
18 | + add_action('admin_notices', array(__CLASS__, 'notices')); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function init_hooks() { |
22 | - if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) { |
|
23 | - $checkout_page = wpinv_get_option( 'checkout_page', '' ); |
|
24 | - $success_page = wpinv_get_option( 'success_page', '' ); |
|
25 | - $failure_page = wpinv_get_option( 'failure_page', '' ); |
|
26 | - $history_page = wpinv_get_option( 'invoice_history_page', '' ); |
|
27 | - $subscr_page = wpinv_get_option( 'invoice_subscription_page', '' ); |
|
28 | - if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) { |
|
22 | + if (false === ($page_uris = get_transient('wpinv_cache_excluded_uris'))) { |
|
23 | + $checkout_page = wpinv_get_option('checkout_page', ''); |
|
24 | + $success_page = wpinv_get_option('success_page', ''); |
|
25 | + $failure_page = wpinv_get_option('failure_page', ''); |
|
26 | + $history_page = wpinv_get_option('invoice_history_page', ''); |
|
27 | + $subscr_page = wpinv_get_option('invoice_subscription_page', ''); |
|
28 | + if (empty($checkout_page) || empty($success_page) || empty($failure_page) || empty($history_page) || empty($subscr_page)) { |
|
29 | 29 | return; |
30 | 30 | } |
31 | 31 | |
@@ -39,34 +39,34 @@ discard block |
||
39 | 39 | $page_uris[] = 'p=' . $subscr_page; |
40 | 40 | |
41 | 41 | // Exclude permalinks |
42 | - $checkout_page = get_post( $checkout_page ); |
|
43 | - $success_page = get_post( $success_page ); |
|
44 | - $failure_page = get_post( $failure_page ); |
|
45 | - $history_page = get_post( $history_page ); |
|
46 | - $subscr_page = get_post( $subscr_page ); |
|
42 | + $checkout_page = get_post($checkout_page); |
|
43 | + $success_page = get_post($success_page); |
|
44 | + $failure_page = get_post($failure_page); |
|
45 | + $history_page = get_post($history_page); |
|
46 | + $subscr_page = get_post($subscr_page); |
|
47 | 47 | |
48 | - if ( ! is_null( $checkout_page ) ) { |
|
48 | + if (!is_null($checkout_page)) { |
|
49 | 49 | $page_uris[] = '/' . $checkout_page->post_name; |
50 | 50 | } |
51 | - if ( ! is_null( $success_page ) ) { |
|
51 | + if (!is_null($success_page)) { |
|
52 | 52 | $page_uris[] = '/' . $success_page->post_name; |
53 | 53 | } |
54 | - if ( ! is_null( $failure_page ) ) { |
|
54 | + if (!is_null($failure_page)) { |
|
55 | 55 | $page_uris[] = '/' . $failure_page->post_name; |
56 | 56 | } |
57 | - if ( ! is_null( $history_page ) ) { |
|
57 | + if (!is_null($history_page)) { |
|
58 | 58 | $page_uris[] = '/' . $history_page->post_name; |
59 | 59 | } |
60 | - if ( ! is_null( $subscr_page ) ) { |
|
60 | + if (!is_null($subscr_page)) { |
|
61 | 61 | $page_uris[] = '/' . $subscr_page->post_name; |
62 | 62 | } |
63 | 63 | |
64 | - set_transient( 'wpinv_cache_excluded_uris', $page_uris ); |
|
64 | + set_transient('wpinv_cache_excluded_uris', $page_uris); |
|
65 | 65 | } |
66 | 66 | |
67 | - if ( is_array( $page_uris ) ) { |
|
68 | - foreach ( $page_uris as $uri ) { |
|
69 | - if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { |
|
67 | + if (is_array($page_uris)) { |
|
68 | + foreach ($page_uris as $uri) { |
|
69 | + if (strstr($_SERVER['REQUEST_URI'], $uri)) { |
|
70 | 70 | self::nocache(); |
71 | 71 | break; |
72 | 72 | } |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * @access private |
80 | 80 | */ |
81 | 81 | private static function nocache() { |
82 | - if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
|
83 | - define( 'DONOTCACHEPAGE', true ); |
|
82 | + if (!defined('DONOTCACHEPAGE')) { |
|
83 | + define('DONOTCACHEPAGE', true); |
|
84 | 84 | } |
85 | - if ( ! defined( 'DONOTCACHEOBJECT' ) ) { |
|
86 | - define( 'DONOTCACHEOBJECT', true ); |
|
85 | + if (!defined('DONOTCACHEOBJECT')) { |
|
86 | + define('DONOTCACHEOBJECT', true); |
|
87 | 87 | } |
88 | - if ( ! defined( 'DONOTCACHEDB' ) ) { |
|
89 | - define( 'DONOTCACHEDB', true ); |
|
88 | + if (!defined('DONOTCACHEDB')) { |
|
89 | + define('DONOTCACHEDB', true); |
|
90 | 90 | } |
91 | 91 | nocache_headers(); |
92 | 92 | } |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * notices function. |
96 | 96 | */ |
97 | 97 | public static function notices() { |
98 | - if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) { |
|
98 | + if (!function_exists('w3tc_pgcache_flush') || !function_exists('w3_instance')) { |
|
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - $config = w3_instance( 'W3_Config' ); |
|
103 | - $enabled = $config->get_integer( 'dbcache.enabled' ); |
|
104 | - $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); |
|
102 | + $config = w3_instance('W3_Config'); |
|
103 | + $enabled = $config->get_integer('dbcache.enabled'); |
|
104 | + $settings = array_map('trim', $config->get_array('dbcache.reject.sql')); |
|
105 | 105 | |
106 | - if ( $enabled && ! in_array( '_wp_session_', $settings ) ) { |
|
106 | + if ($enabled && !in_array('_wp_session_', $settings)) { |
|
107 | 107 | ?> |
108 | 108 | <div class="error"> |
109 | - <p><?php printf( __( 'In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing' ), '<code>_wp_session_</code>', admin_url( 'admin.php?page=w3tc_dbcache' ) ); ?></p> |
|
109 | + <p><?php printf(__('In order for <strong>database caching</strong> to work with Invoicing you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'invoicing'), '<code>_wp_session_</code>', admin_url('admin.php?page=w3tc_dbcache')); ?></p> |
|
110 | 110 | </div> |
111 | 111 | <?php |
112 | 112 | } |
@@ -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 apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
395 | + <h3 class="wpinv-notes-t"><?php echo 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( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $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(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $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); |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | check_ajax_referer( 'getpaid_form_nonce' ); |
262 | 262 | |
263 | 263 | // Is the request set up correctly? |
264 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
265 | - echo aui()->alert( |
|
266 | - array( |
|
267 | - 'type' => 'warning', |
|
268 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
269 | - ) |
|
264 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
265 | + echo aui()->alert( |
|
266 | + array( |
|
267 | + 'type' => 'warning', |
|
268 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
269 | + ) |
|
270 | 270 | ); |
271 | 271 | exit; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Payment form or button? |
275 | - if ( ! empty( $_GET['form'] ) ) { |
|
275 | + if ( ! empty( $_GET['form'] ) ) { |
|
276 | 276 | $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
277 | 277 | |
278 | 278 | if ( false !== strpos( $form, '|' ) ) { |
@@ -325,10 +325,10 @@ discard block |
||
325 | 325 | getpaid_display_payment_form( $form ); |
326 | 326 | } |
327 | 327 | } elseif ( ! empty( $_GET['invoice'] ) ) { |
328 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
328 | + getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
329 | 329 | } else { |
330 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
331 | - getpaid_display_item_payment_form( $items ); |
|
330 | + $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
331 | + getpaid_display_item_payment_form( $items ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | exit; |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | if ( is_wp_error( $error ) ) { |
649 | 649 | $alert = $error->get_error_message(); |
650 | 650 | wp_send_json_success( compact( 'alert' ) ); |
651 | - } |
|
651 | + } |
|
652 | 652 | |
653 | 653 | // Update totals. |
654 | 654 | $invoice->recalculate_total(); |
@@ -1083,12 +1083,12 @@ discard block |
||
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | /** |
1086 | - * Handles file uploads. |
|
1087 | - * |
|
1088 | - * @since 1.0.0 |
|
1089 | - * @return void |
|
1090 | - */ |
|
1091 | - public static function file_upload() { |
|
1086 | + * Handles file uploads. |
|
1087 | + * |
|
1088 | + * @since 1.0.0 |
|
1089 | + * @return void |
|
1090 | + */ |
|
1091 | + public static function file_upload() { |
|
1092 | 1092 | |
1093 | 1093 | // Check nonce. |
1094 | 1094 | check_ajax_referer( 'getpaid_form_nonce' ); |
@@ -1149,7 +1149,7 @@ discard block |
||
1149 | 1149 | |
1150 | 1150 | wp_send_json_success( $response ); |
1151 | 1151 | |
1152 | - } |
|
1152 | + } |
|
1153 | 1153 | |
1154 | 1154 | } |
1155 | 1155 |
@@ -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 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -106,36 +106,36 @@ discard block |
||
106 | 106 | 'file_upload' => true, |
107 | 107 | ); |
108 | 108 | |
109 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
110 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
109 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
110 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | |
113 | - if ( $nopriv ) { |
|
114 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
115 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
116 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | + if ($nopriv) { |
|
114 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
115 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
116 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | 121 | public static function add_note() { |
122 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
122 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
123 | 123 | |
124 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
124 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
125 | 125 | die( -1 ); |
126 | 126 | } |
127 | 127 | |
128 | - $post_id = absint( $_POST['post_id'] ); |
|
129 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
130 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
128 | + $post_id = absint($_POST['post_id']); |
|
129 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
130 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
131 | 131 | |
132 | 132 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
133 | 133 | |
134 | - if ( $post_id > 0 ) { |
|
135 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
134 | + if ($post_id > 0) { |
|
135 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
136 | 136 | |
137 | - if ( $note_id > 0 && ! is_wp_error( $note_id ) ) { |
|
138 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
137 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
138 | + wpinv_get_invoice_note_line_item($note_id); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | public static function delete_note() { |
146 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
146 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
147 | 147 | |
148 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
148 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
149 | 149 | die( -1 ); |
150 | 150 | } |
151 | 151 | |
152 | - $note_id = (int)$_POST['note_id']; |
|
152 | + $note_id = (int) $_POST['note_id']; |
|
153 | 153 | |
154 | - if ( $note_id > 0 ) { |
|
155 | - wp_delete_comment( $note_id, true ); |
|
154 | + if ($note_id > 0) { |
|
155 | + wp_delete_comment($note_id, true); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | die(); |
@@ -170,34 +170,34 @@ discard block |
||
170 | 170 | public static function get_billing_details() { |
171 | 171 | |
172 | 172 | // Verify nonce. |
173 | - check_ajax_referer( 'wpinv-nonce' ); |
|
173 | + check_ajax_referer('wpinv-nonce'); |
|
174 | 174 | |
175 | 175 | // Can the user manage the plugin? |
176 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
176 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
177 | 177 | die( -1 ); |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Do we have a user id? |
181 | 181 | $user_id = (int) $_GET['user_id']; |
182 | 182 | |
183 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
183 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
184 | 184 | die( -1 ); |
185 | 185 | } |
186 | 186 | |
187 | 187 | // Fetch the billing details. |
188 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
189 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
188 | + $billing_details = wpinv_get_user_address($user_id); |
|
189 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
190 | 190 | |
191 | 191 | // unset the user id and email. |
192 | - $to_ignore = array( 'user_id', 'email' ); |
|
192 | + $to_ignore = array('user_id', 'email'); |
|
193 | 193 | |
194 | - foreach ( $to_ignore as $key ) { |
|
195 | - if ( isset( $billing_details[ $key ] ) ) { |
|
196 | - unset( $billing_details[ $key ] ); |
|
194 | + foreach ($to_ignore as $key) { |
|
195 | + if (isset($billing_details[$key])) { |
|
196 | + unset($billing_details[$key]); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - wp_send_json_success( $billing_details ); |
|
200 | + wp_send_json_success($billing_details); |
|
201 | 201 | |
202 | 202 | } |
203 | 203 | |
@@ -207,47 +207,47 @@ discard block |
||
207 | 207 | public static function check_new_user_email() { |
208 | 208 | |
209 | 209 | // Verify nonce. |
210 | - check_ajax_referer( 'wpinv-nonce' ); |
|
210 | + check_ajax_referer('wpinv-nonce'); |
|
211 | 211 | |
212 | 212 | // Can the user manage the plugin? |
213 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
213 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
214 | 214 | die( -1 ); |
215 | 215 | } |
216 | 216 | |
217 | 217 | // We need an email address. |
218 | - if ( empty( $_GET['email'] ) ) { |
|
219 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
218 | + if (empty($_GET['email'])) { |
|
219 | + _e("Provide the new user's email address", 'invoicing'); |
|
220 | 220 | exit; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Ensure the email is valid. |
224 | - $email = sanitize_email( $_GET['email'] ); |
|
225 | - if ( ! is_email( $email ) ) { |
|
226 | - _e( 'Invalid email address', 'invoicing' ); |
|
224 | + $email = sanitize_email($_GET['email']); |
|
225 | + if (!is_email($email)) { |
|
226 | + _e('Invalid email address', 'invoicing'); |
|
227 | 227 | exit; |
228 | 228 | } |
229 | 229 | |
230 | 230 | // And it does not exist. |
231 | - $id = email_exists( $email ); |
|
232 | - if ( $id ) { |
|
233 | - wp_send_json_success( compact( 'id' ) ); |
|
231 | + $id = email_exists($email); |
|
232 | + if ($id) { |
|
233 | + wp_send_json_success(compact('id')); |
|
234 | 234 | } |
235 | 235 | |
236 | - wp_send_json_success( true ); |
|
236 | + wp_send_json_success(true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | public static function run_tool() { |
240 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
241 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
240 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
241 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
242 | 242 | die( -1 ); |
243 | 243 | } |
244 | 244 | |
245 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
245 | + $tool = sanitize_text_field($_POST['tool']); |
|
246 | 246 | |
247 | - do_action( 'wpinv_run_tool' ); |
|
247 | + do_action('wpinv_run_tool'); |
|
248 | 248 | |
249 | - if ( ! empty( $tool ) ) { |
|
250 | - do_action( 'wpinv_tool_' . $tool ); |
|
249 | + if (!empty($tool)) { |
|
250 | + do_action('wpinv_tool_' . $tool); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -258,43 +258,43 @@ discard block |
||
258 | 258 | global $getpaid_force_checkbox; |
259 | 259 | |
260 | 260 | // Check nonce. |
261 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
261 | + check_ajax_referer('getpaid_form_nonce'); |
|
262 | 262 | |
263 | 263 | // Is the request set up correctly? |
264 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) { |
|
264 | + if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) { |
|
265 | 265 | echo aui()->alert( |
266 | 266 | array( |
267 | 267 | 'type' => 'warning', |
268 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | exit; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Payment form or button? |
275 | - if ( ! empty( $_GET['form'] ) ) { |
|
276 | - $form = sanitize_text_field( urldecode( $_GET['form'] ) ); |
|
275 | + if (!empty($_GET['form'])) { |
|
276 | + $form = sanitize_text_field(urldecode($_GET['form'])); |
|
277 | 277 | |
278 | - if ( false !== strpos( $form, '|' ) ) { |
|
279 | - $form_pos = strpos( $form, '|' ); |
|
280 | - $_items = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) ); |
|
281 | - $form = substr( $form, 0, $form_pos ); |
|
278 | + if (false !== strpos($form, '|')) { |
|
279 | + $form_pos = strpos($form, '|'); |
|
280 | + $_items = getpaid_convert_items_to_array(substr($form, $form_pos + 1)); |
|
281 | + $form = substr($form, 0, $form_pos); |
|
282 | 282 | |
283 | 283 | // Retrieve appropriate payment form. |
284 | - $payment_form = new GetPaid_Payment_Form( $form ); |
|
285 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
284 | + $payment_form = new GetPaid_Payment_Form($form); |
|
285 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
286 | 286 | |
287 | 287 | $items = array(); |
288 | 288 | $item_ids = array(); |
289 | 289 | |
290 | - foreach ( $_items as $item_id => $qty ) { |
|
291 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
292 | - $item = new GetPaid_Form_Item( $item_id ); |
|
293 | - $item->set_quantity( $qty ); |
|
290 | + foreach ($_items as $item_id => $qty) { |
|
291 | + if (!in_array($item_id, $item_ids)) { |
|
292 | + $item = new GetPaid_Form_Item($item_id); |
|
293 | + $item->set_quantity($qty); |
|
294 | 294 | |
295 | - if ( 0 == $qty ) { |
|
296 | - $item->set_allow_quantities( true ); |
|
297 | - $item->set_is_required( false ); |
|
295 | + if (0 == $qty) { |
|
296 | + $item->set_allow_quantities(true); |
|
297 | + $item->set_is_required(false); |
|
298 | 298 | $getpaid_force_checkbox = true; |
299 | 299 | } |
300 | 300 | |
@@ -303,32 +303,32 @@ discard block |
||
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - if ( ! $payment_form->is_default() ) { |
|
306 | + if (!$payment_form->is_default()) { |
|
307 | 307 | |
308 | - foreach ( $payment_form->get_items() as $item ) { |
|
309 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
308 | + foreach ($payment_form->get_items() as $item) { |
|
309 | + if (!in_array($item->get_id(), $item_ids)) { |
|
310 | 310 | $item_ids[] = $item->get_id(); |
311 | 311 | $items[] = $item; |
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
315 | 315 | |
316 | - $payment_form->set_items( $items ); |
|
317 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $_items ) ); |
|
318 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
316 | + $payment_form->set_items($items); |
|
317 | + $extra_items = esc_attr(getpaid_convert_items_to_string($_items)); |
|
318 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
319 | 319 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
320 | 320 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
321 | - $payment_form->display( $extra_items ); |
|
321 | + $payment_form->display($extra_items); |
|
322 | 322 | $getpaid_force_checkbox = false; |
323 | 323 | |
324 | 324 | } else { |
325 | - getpaid_display_payment_form( $form ); |
|
325 | + getpaid_display_payment_form($form); |
|
326 | 326 | } |
327 | -} elseif ( ! empty( $_GET['invoice'] ) ) { |
|
328 | - getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) ); |
|
327 | +} elseif (!empty($_GET['invoice'])) { |
|
328 | + getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice'])); |
|
329 | 329 | } else { |
330 | - $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) ); |
|
331 | - getpaid_display_item_payment_form( $items ); |
|
330 | + $items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item']))); |
|
331 | + getpaid_display_item_payment_form($items); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | exit; |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | public static function payment_form() { |
344 | 344 | |
345 | 345 | // Check nonce. |
346 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
346 | + check_ajax_referer('getpaid_form_nonce'); |
|
347 | 347 | |
348 | 348 | // ... form fields... |
349 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
350 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
349 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
350 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
351 | 351 | exit; |
352 | 352 | } |
353 | 353 | |
354 | 354 | // Process the payment form. |
355 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
356 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
355 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
356 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
357 | 357 | $checkout->process_checkout(); |
358 | 358 | |
359 | 359 | exit; |
@@ -366,55 +366,55 @@ discard block |
||
366 | 366 | */ |
367 | 367 | public static function get_payment_form_states_field() { |
368 | 368 | |
369 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
369 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
370 | 370 | exit; |
371 | 371 | } |
372 | 372 | |
373 | - $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] ); |
|
373 | + $elements = getpaid_get_payment_form_elements((int) $_GET['form']); |
|
374 | 374 | |
375 | - if ( empty( $elements ) ) { |
|
375 | + if (empty($elements)) { |
|
376 | 376 | exit; |
377 | 377 | } |
378 | 378 | |
379 | 379 | $address_fields = array(); |
380 | - foreach ( $elements as $element ) { |
|
381 | - if ( 'address' === $element['type'] ) { |
|
380 | + foreach ($elements as $element) { |
|
381 | + if ('address' === $element['type']) { |
|
382 | 382 | $address_fields = $element; |
383 | 383 | break; |
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | - if ( empty( $address_fields ) ) { |
|
387 | + if (empty($address_fields)) { |
|
388 | 388 | exit; |
389 | 389 | } |
390 | 390 | |
391 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
391 | + foreach ($address_fields['fields'] as $address_field) { |
|
392 | 392 | |
393 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
393 | + if ('wpinv_state' == $address_field['name']) { |
|
394 | 394 | |
395 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
396 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
397 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
398 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
399 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
400 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
395 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
396 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
397 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
398 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
399 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
400 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
401 | 401 | |
402 | - if ( ! empty( $address_field['required'] ) ) { |
|
402 | + if (!empty($address_field['required'])) { |
|
403 | 403 | $label .= "<span class='text-danger'> *</span>"; |
404 | 404 | } |
405 | 405 | |
406 | 406 | $html = getpaid_get_states_select_markup( |
407 | - sanitize_text_field( $_GET['country'] ), |
|
407 | + sanitize_text_field($_GET['country']), |
|
408 | 408 | $value, |
409 | 409 | $placeholder, |
410 | 410 | $label, |
411 | 411 | $description, |
412 | - ! empty( $address_field['required'] ), |
|
412 | + !empty($address_field['required']), |
|
413 | 413 | $wrap_class, |
414 | - sanitize_text_field( $_GET['name'] ) |
|
414 | + sanitize_text_field($_GET['name']) |
|
415 | 415 | ); |
416 | 416 | |
417 | - wp_send_json_success( $html ); |
|
417 | + wp_send_json_success($html); |
|
418 | 418 | exit; |
419 | 419 | |
420 | 420 | } |
@@ -429,66 +429,66 @@ discard block |
||
429 | 429 | public static function recalculate_invoice_totals() { |
430 | 430 | |
431 | 431 | // Verify nonce. |
432 | - check_ajax_referer( 'wpinv-nonce' ); |
|
432 | + check_ajax_referer('wpinv-nonce'); |
|
433 | 433 | |
434 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
434 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
435 | 435 | exit; |
436 | 436 | } |
437 | 437 | |
438 | 438 | // We need an invoice. |
439 | - if ( empty( $_POST['post_id'] ) ) { |
|
439 | + if (empty($_POST['post_id'])) { |
|
440 | 440 | exit; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Fetch the invoice. |
444 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
444 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
445 | 445 | |
446 | 446 | // Ensure it exists. |
447 | - if ( ! $invoice->get_id() ) { |
|
447 | + if (!$invoice->get_id()) { |
|
448 | 448 | exit; |
449 | 449 | } |
450 | 450 | |
451 | 451 | // Maybe set the country, state, currency. |
452 | - foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) { |
|
453 | - if ( isset( $_POST[ $key ] ) ) { |
|
452 | + foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) { |
|
453 | + if (isset($_POST[$key])) { |
|
454 | 454 | $method = "set_$key"; |
455 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
455 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
459 | 459 | // Maybe disable taxes. |
460 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
460 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
461 | 461 | |
462 | 462 | // Discount code. |
463 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
464 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
465 | - if ( $discount->exists() ) { |
|
466 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
463 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
464 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
465 | + if ($discount->exists()) { |
|
466 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
467 | 467 | } else { |
468 | - $invoice->remove_discount( 'discount_code' ); |
|
468 | + $invoice->remove_discount('discount_code'); |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | |
472 | 472 | // Recalculate totals. |
473 | 473 | $invoice->recalculate_total(); |
474 | 474 | |
475 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
476 | - $suscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
477 | - if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
478 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
479 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
475 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
476 | + $suscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
477 | + if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
478 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
479 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | $totals = array( |
483 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
484 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
485 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
483 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
484 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
485 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
486 | 486 | 'total' => $total, |
487 | 487 | ); |
488 | 488 | |
489 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
489 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
490 | 490 | |
491 | - wp_send_json_success( compact( 'totals' ) ); |
|
491 | + wp_send_json_success(compact('totals')); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -497,33 +497,33 @@ discard block |
||
497 | 497 | public static function get_invoice_items() { |
498 | 498 | |
499 | 499 | // Verify nonce. |
500 | - check_ajax_referer( 'wpinv-nonce' ); |
|
500 | + check_ajax_referer('wpinv-nonce'); |
|
501 | 501 | |
502 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
502 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
503 | 503 | exit; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // We need an invoice and items. |
507 | - if ( empty( $_POST['post_id'] ) ) { |
|
507 | + if (empty($_POST['post_id'])) { |
|
508 | 508 | exit; |
509 | 509 | } |
510 | 510 | |
511 | 511 | // Fetch the invoice. |
512 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
512 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
513 | 513 | |
514 | 514 | // Ensure it exists. |
515 | - if ( ! $invoice->get_id() ) { |
|
515 | + if (!$invoice->get_id()) { |
|
516 | 516 | exit; |
517 | 517 | } |
518 | 518 | |
519 | 519 | // Return an array of invoice items. |
520 | 520 | $items = array(); |
521 | 521 | |
522 | - foreach ( $invoice->get_items() as $item ) { |
|
523 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() ); |
|
522 | + foreach ($invoice->get_items() as $item) { |
|
523 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal()); |
|
524 | 524 | } |
525 | 525 | |
526 | - wp_send_json_success( compact( 'items' ) ); |
|
526 | + wp_send_json_success(compact('items')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -532,50 +532,50 @@ discard block |
||
532 | 532 | public static function edit_invoice_item() { |
533 | 533 | |
534 | 534 | // Verify nonce. |
535 | - check_ajax_referer( 'wpinv-nonce' ); |
|
535 | + check_ajax_referer('wpinv-nonce'); |
|
536 | 536 | |
537 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
537 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
538 | 538 | exit; |
539 | 539 | } |
540 | 540 | |
541 | 541 | // We need an invoice and item details. |
542 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
542 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
543 | 543 | exit; |
544 | 544 | } |
545 | 545 | |
546 | 546 | // Fetch the invoice. |
547 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
547 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
548 | 548 | |
549 | 549 | // Ensure it exists and its not been paid for. |
550 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
550 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
551 | 551 | exit; |
552 | 552 | } |
553 | 553 | |
554 | 554 | // Format the data. |
555 | - $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) ); |
|
555 | + $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'))); |
|
556 | 556 | |
557 | 557 | // Ensure that we have an item id. |
558 | - if ( empty( $data['id'] ) ) { |
|
558 | + if (empty($data['id'])) { |
|
559 | 559 | exit; |
560 | 560 | } |
561 | 561 | |
562 | 562 | // Abort if the invoice does not have the specified item. |
563 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
563 | + $item = $invoice->get_item((int) $data['id']); |
|
564 | 564 | |
565 | - if ( empty( $item ) ) { |
|
565 | + if (empty($item)) { |
|
566 | 566 | exit; |
567 | 567 | } |
568 | 568 | |
569 | 569 | // Update the item. |
570 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
571 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
572 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
573 | - $item->set_quantity( floatval( $data['quantity'] ) ); |
|
570 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
571 | + $item->set_name(sanitize_text_field($data['name'])); |
|
572 | + $item->set_description(wp_kses_post($data['description'])); |
|
573 | + $item->set_quantity(floatval($data['quantity'])); |
|
574 | 574 | |
575 | 575 | // Add it to the invoice. |
576 | - $error = $invoice->add_item( $item ); |
|
576 | + $error = $invoice->add_item($item); |
|
577 | 577 | $alert = false; |
578 | - if ( is_wp_error( $error ) ) { |
|
578 | + if (is_wp_error($error)) { |
|
579 | 579 | $alert = $error->get_error_message(); |
580 | 580 | } |
581 | 581 | |
@@ -588,11 +588,11 @@ discard block |
||
588 | 588 | // Return an array of invoice items. |
589 | 589 | $items = array(); |
590 | 590 | |
591 | - foreach ( $invoice->get_items() as $item ) { |
|
592 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
591 | + foreach ($invoice->get_items() as $item) { |
|
592 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
593 | 593 | } |
594 | 594 | |
595 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
595 | + wp_send_json_success(compact('items', 'alert')); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -601,53 +601,53 @@ discard block |
||
601 | 601 | public static function create_invoice_item() { |
602 | 602 | |
603 | 603 | // Verify nonce. |
604 | - check_ajax_referer( 'wpinv-nonce' ); |
|
604 | + check_ajax_referer('wpinv-nonce'); |
|
605 | 605 | |
606 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
606 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
607 | 607 | exit; |
608 | 608 | } |
609 | 609 | |
610 | 610 | // We need an invoice and item details. |
611 | - if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) { |
|
611 | + if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) { |
|
612 | 612 | exit; |
613 | 613 | } |
614 | 614 | |
615 | 615 | // Fetch the invoice. |
616 | - $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) ); |
|
616 | + $invoice = new WPInv_Invoice(intval($_POST['invoice_id'])); |
|
617 | 617 | |
618 | 618 | // Ensure it exists and its not been paid for. |
619 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
619 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
620 | 620 | exit; |
621 | 621 | } |
622 | 622 | |
623 | 623 | // Format the data. |
624 | - $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) ); |
|
624 | + $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick'])); |
|
625 | 625 | |
626 | 626 | $item = new WPInv_Item(); |
627 | - $item->set_price( getpaid_standardize_amount( $data['price'] ) ); |
|
628 | - $item->set_name( sanitize_text_field( $data['name'] ) ); |
|
629 | - $item->set_description( wp_kses_post( $data['description'] ) ); |
|
630 | - $item->set_type( sanitize_text_field( $data['type'] ) ); |
|
631 | - $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) ); |
|
632 | - $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) ); |
|
633 | - $item->set_status( 'publish' ); |
|
627 | + $item->set_price(getpaid_standardize_amount($data['price'])); |
|
628 | + $item->set_name(sanitize_text_field($data['name'])); |
|
629 | + $item->set_description(wp_kses_post($data['description'])); |
|
630 | + $item->set_type(sanitize_text_field($data['type'])); |
|
631 | + $item->set_vat_rule(sanitize_text_field($data['vat_rule'])); |
|
632 | + $item->set_vat_class(sanitize_text_field($data['vat_class'])); |
|
633 | + $item->set_status('publish'); |
|
634 | 634 | $item->save(); |
635 | 635 | |
636 | - if ( ! $item->exists() ) { |
|
637 | - $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' ); |
|
638 | - wp_send_json_success( compact( 'alert' ) ); |
|
636 | + if (!$item->exists()) { |
|
637 | + $alert = __('Could not create invoice item. Please try again.', 'invoicing'); |
|
638 | + wp_send_json_success(compact('alert')); |
|
639 | 639 | } |
640 | 640 | |
641 | - $item = new GetPaid_Form_Item( $item->get_id() ); |
|
642 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
641 | + $item = new GetPaid_Form_Item($item->get_id()); |
|
642 | + $item->set_quantity(floatval($data['qty'])); |
|
643 | 643 | |
644 | 644 | // Add it to the invoice. |
645 | - $error = $invoice->add_item( $item ); |
|
645 | + $error = $invoice->add_item($item); |
|
646 | 646 | $alert = false; |
647 | 647 | |
648 | - if ( is_wp_error( $error ) ) { |
|
648 | + if (is_wp_error($error)) { |
|
649 | 649 | $alert = $error->get_error_message(); |
650 | - wp_send_json_success( compact( 'alert' ) ); |
|
650 | + wp_send_json_success(compact('alert')); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | // Update totals. |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | $invoice->recalculate_total(); |
661 | 661 | $invoice->save(); |
662 | 662 | ob_start(); |
663 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
663 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
664 | 664 | $row = ob_get_clean(); |
665 | - wp_send_json_success( compact( 'row' ) ); |
|
665 | + wp_send_json_success(compact('row')); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -671,33 +671,33 @@ discard block |
||
671 | 671 | public static function remove_invoice_item() { |
672 | 672 | |
673 | 673 | // Verify nonce. |
674 | - check_ajax_referer( 'wpinv-nonce' ); |
|
674 | + check_ajax_referer('wpinv-nonce'); |
|
675 | 675 | |
676 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
676 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
677 | 677 | exit; |
678 | 678 | } |
679 | 679 | |
680 | 680 | // We need an invoice and an item. |
681 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
681 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
682 | 682 | exit; |
683 | 683 | } |
684 | 684 | |
685 | 685 | // Fetch the invoice. |
686 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
686 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
687 | 687 | |
688 | 688 | // Ensure it exists and its not been paid for. |
689 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
689 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
690 | 690 | exit; |
691 | 691 | } |
692 | 692 | |
693 | 693 | // Abort if the invoice does not have the specified item. |
694 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
694 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
695 | 695 | |
696 | - if ( empty( $item ) ) { |
|
696 | + if (empty($item)) { |
|
697 | 697 | exit; |
698 | 698 | } |
699 | 699 | |
700 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
700 | + $invoice->remove_item((int) $_POST['item_id']); |
|
701 | 701 | |
702 | 702 | // Update totals. |
703 | 703 | $invoice->recalculate_total(); |
@@ -708,11 +708,11 @@ discard block |
||
708 | 708 | // Return an array of invoice items. |
709 | 709 | $items = array(); |
710 | 710 | |
711 | - foreach ( $invoice->get_items() as $item ) { |
|
712 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
711 | + foreach ($invoice->get_items() as $item) { |
|
712 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
713 | 713 | } |
714 | 714 | |
715 | - wp_send_json_success( compact( 'items' ) ); |
|
715 | + wp_send_json_success(compact('items')); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -721,68 +721,68 @@ discard block |
||
721 | 721 | public static function recalculate_full_prices() { |
722 | 722 | |
723 | 723 | // Verify nonce. |
724 | - check_ajax_referer( 'wpinv-nonce' ); |
|
724 | + check_ajax_referer('wpinv-nonce'); |
|
725 | 725 | |
726 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
726 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
727 | 727 | exit; |
728 | 728 | } |
729 | 729 | |
730 | 730 | // We need an invoice and item. |
731 | - if ( empty( $_POST['post_id'] ) ) { |
|
731 | + if (empty($_POST['post_id'])) { |
|
732 | 732 | exit; |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Fetch the invoice. |
736 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
736 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
737 | 737 | $alert = false; |
738 | 738 | |
739 | 739 | // Ensure it exists and its not been paid for. |
740 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
740 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
741 | 741 | exit; |
742 | 742 | } |
743 | 743 | |
744 | - $invoice->set_items( array() ); |
|
744 | + $invoice->set_items(array()); |
|
745 | 745 | |
746 | - if ( ! empty( $_POST['getpaid_items'] ) ) { |
|
746 | + if (!empty($_POST['getpaid_items'])) { |
|
747 | 747 | |
748 | - foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) { |
|
749 | - $item = new GetPaid_Form_Item( $item_id ); |
|
748 | + foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) { |
|
749 | + $item = new GetPaid_Form_Item($item_id); |
|
750 | 750 | |
751 | - if ( $item->exists() ) { |
|
752 | - $item->set_price( getpaid_standardize_amount( $args['price'] ) ); |
|
753 | - $item->set_quantity( floatval( $args['quantity'] ) ); |
|
754 | - $item->set_name( sanitize_text_field( $args['name'] ) ); |
|
755 | - $item->set_description( wp_kses_post( $args['description'] ) ); |
|
756 | - $invoice->add_item( $item ); |
|
751 | + if ($item->exists()) { |
|
752 | + $item->set_price(getpaid_standardize_amount($args['price'])); |
|
753 | + $item->set_quantity(floatval($args['quantity'])); |
|
754 | + $item->set_name(sanitize_text_field($args['name'])); |
|
755 | + $item->set_description(wp_kses_post($args['description'])); |
|
756 | + $invoice->add_item($item); |
|
757 | 757 | } |
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
761 | - $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) ); |
|
761 | + $invoice->set_disable_taxes(!empty($_POST['disable_taxes'])); |
|
762 | 762 | |
763 | 763 | // Maybe set the country, state, currency. |
764 | - foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) { |
|
765 | - if ( isset( $_POST[ $key ] ) ) { |
|
766 | - $_key = str_replace( 'wpinv_', '', $key ); |
|
764 | + foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) { |
|
765 | + if (isset($_POST[$key])) { |
|
766 | + $_key = str_replace('wpinv_', '', $key); |
|
767 | 767 | $method = "set_$_key"; |
768 | - $invoice->$method( sanitize_text_field( $_POST[ $key ] ) ); |
|
768 | + $invoice->$method(sanitize_text_field($_POST[$key])); |
|
769 | 769 | } |
770 | 770 | } |
771 | 771 | |
772 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
773 | - if ( $discount->exists() ) { |
|
774 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
772 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
773 | + if ($discount->exists()) { |
|
774 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
775 | 775 | } else { |
776 | - $invoice->remove_discount( 'discount_code' ); |
|
776 | + $invoice->remove_discount('discount_code'); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | // Save the invoice. |
780 | 780 | $invoice->recalculate_total(); |
781 | 781 | $invoice->save(); |
782 | 782 | ob_start(); |
783 | - GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice ); |
|
783 | + GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice); |
|
784 | 784 | $table = ob_get_clean(); |
785 | - wp_send_json_success( compact( 'table' ) ); |
|
785 | + wp_send_json_success(compact('table')); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -791,42 +791,42 @@ discard block |
||
791 | 791 | public static function admin_add_invoice_item() { |
792 | 792 | |
793 | 793 | // Verify nonce. |
794 | - check_ajax_referer( 'wpinv-nonce' ); |
|
794 | + check_ajax_referer('wpinv-nonce'); |
|
795 | 795 | |
796 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
796 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
797 | 797 | exit; |
798 | 798 | } |
799 | 799 | |
800 | 800 | // We need an invoice and item. |
801 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
801 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
802 | 802 | exit; |
803 | 803 | } |
804 | 804 | |
805 | 805 | // Fetch the invoice. |
806 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
806 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
807 | 807 | $alert = false; |
808 | 808 | |
809 | 809 | // Ensure it exists and its not been paid for. |
810 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
810 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
811 | 811 | exit; |
812 | 812 | } |
813 | 813 | |
814 | 814 | // Add the item. |
815 | - $item = new GetPaid_Form_Item( (int) $_POST['item_id'] ); |
|
816 | - $error = $invoice->add_item( $item ); |
|
815 | + $item = new GetPaid_Form_Item((int) $_POST['item_id']); |
|
816 | + $error = $invoice->add_item($item); |
|
817 | 817 | |
818 | - if ( is_wp_error( $error ) ) { |
|
818 | + if (is_wp_error($error)) { |
|
819 | 819 | $alert = $error->get_error_message(); |
820 | - wp_send_json_success( compact( 'alert' ) ); |
|
820 | + wp_send_json_success(compact('alert')); |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | // Save the invoice. |
824 | 824 | $invoice->recalculate_total(); |
825 | 825 | $invoice->save(); |
826 | 826 | ob_start(); |
827 | - GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice ); |
|
827 | + GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice); |
|
828 | 828 | $row = ob_get_clean(); |
829 | - wp_send_json_success( compact( 'row' ) ); |
|
829 | + wp_send_json_success(compact('row')); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -835,39 +835,39 @@ discard block |
||
835 | 835 | public static function add_invoice_items() { |
836 | 836 | |
837 | 837 | // Verify nonce. |
838 | - check_ajax_referer( 'wpinv-nonce' ); |
|
838 | + check_ajax_referer('wpinv-nonce'); |
|
839 | 839 | |
840 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
840 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
841 | 841 | exit; |
842 | 842 | } |
843 | 843 | |
844 | 844 | // We need an invoice and items. |
845 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
845 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
846 | 846 | exit; |
847 | 847 | } |
848 | 848 | |
849 | 849 | // Fetch the invoice. |
850 | - $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) ); |
|
850 | + $invoice = new WPInv_Invoice(intval($_POST['post_id'])); |
|
851 | 851 | $alert = false; |
852 | 852 | |
853 | 853 | // Ensure it exists and its not been paid for. |
854 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
854 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
855 | 855 | exit; |
856 | 856 | } |
857 | 857 | |
858 | 858 | // Add the items. |
859 | - foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) { |
|
859 | + foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) { |
|
860 | 860 | |
861 | - $item = new GetPaid_Form_Item( (int) $data['id'] ); |
|
861 | + $item = new GetPaid_Form_Item((int) $data['id']); |
|
862 | 862 | |
863 | - if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) { |
|
864 | - $item->set_quantity( floatval( $data['qty'] ) ); |
|
863 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
864 | + $item->set_quantity(floatval($data['qty'])); |
|
865 | 865 | } |
866 | 866 | |
867 | - if ( $item->get_id() > 0 ) { |
|
868 | - $error = $invoice->add_item( $item ); |
|
867 | + if ($item->get_id() > 0) { |
|
868 | + $error = $invoice->add_item($item); |
|
869 | 869 | |
870 | - if ( is_wp_error( $error ) ) { |
|
870 | + if (is_wp_error($error)) { |
|
871 | 871 | $alert = $error->get_error_message(); |
872 | 872 | } |
873 | 873 | } |
@@ -880,11 +880,11 @@ discard block |
||
880 | 880 | // Return an array of invoice items. |
881 | 881 | $items = array(); |
882 | 882 | |
883 | - foreach ( $invoice->get_items() as $item ) { |
|
884 | - $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
883 | + foreach ($invoice->get_items() as $item) { |
|
884 | + $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
885 | 885 | } |
886 | 886 | |
887 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
887 | + wp_send_json_success(compact('items', 'alert')); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
@@ -893,15 +893,15 @@ discard block |
||
893 | 893 | public static function get_invoicing_items() { |
894 | 894 | |
895 | 895 | // Verify nonce. |
896 | - check_ajax_referer( 'wpinv-nonce' ); |
|
896 | + check_ajax_referer('wpinv-nonce'); |
|
897 | 897 | |
898 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
898 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
899 | 899 | exit; |
900 | 900 | } |
901 | 901 | |
902 | 902 | // We need a search term. |
903 | - if ( empty( $_GET['search'] ) ) { |
|
904 | - wp_send_json_success( array() ); |
|
903 | + if (empty($_GET['search'])) { |
|
904 | + wp_send_json_success(array()); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | // Retrieve items. |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | 'orderby' => 'title', |
911 | 911 | 'order' => 'ASC', |
912 | 912 | 'posts_per_page' => -1, |
913 | - 'post_status' => array( 'publish' ), |
|
914 | - 's' => sanitize_text_field( urldecode( $_GET['search'] ) ), |
|
913 | + 'post_status' => array('publish'), |
|
914 | + 's' => sanitize_text_field(urldecode($_GET['search'])), |
|
915 | 915 | 'meta_query' => array( |
916 | 916 | array( |
917 | 917 | 'key' => '_wpinv_type', |
@@ -921,25 +921,25 @@ discard block |
||
921 | 921 | ), |
922 | 922 | ); |
923 | 923 | |
924 | - if ( ! empty( $_GET['ignore'] ) ) { |
|
925 | - $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) ); |
|
924 | + if (!empty($_GET['ignore'])) { |
|
925 | + $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore'])); |
|
926 | 926 | } |
927 | 927 | |
928 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
928 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
929 | 929 | $data = array(); |
930 | 930 | |
931 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) ); |
|
931 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id'])); |
|
932 | 932 | |
933 | - foreach ( $items as $item ) { |
|
934 | - $item = new GetPaid_Form_Item( $item ); |
|
933 | + foreach ($items as $item) { |
|
934 | + $item = new GetPaid_Form_Item($item); |
|
935 | 935 | $data[] = array( |
936 | 936 | 'id' => (int) $item->get_id(), |
937 | - 'text' => strip_tags( $item->get_name() ), |
|
938 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
937 | + 'text' => strip_tags($item->get_name()), |
|
938 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
939 | 939 | ); |
940 | 940 | } |
941 | 941 | |
942 | - wp_send_json_success( $data ); |
|
942 | + wp_send_json_success($data); |
|
943 | 943 | |
944 | 944 | } |
945 | 945 | |
@@ -949,37 +949,37 @@ discard block |
||
949 | 949 | public static function get_customers() { |
950 | 950 | |
951 | 951 | // Verify nonce. |
952 | - check_ajax_referer( 'wpinv-nonce' ); |
|
952 | + check_ajax_referer('wpinv-nonce'); |
|
953 | 953 | |
954 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
954 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
955 | 955 | exit; |
956 | 956 | } |
957 | 957 | |
958 | 958 | // We need a search term. |
959 | - if ( empty( $_GET['search'] ) ) { |
|
960 | - wp_send_json_success( array() ); |
|
959 | + if (empty($_GET['search'])) { |
|
960 | + wp_send_json_success(array()); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | // Retrieve customers. |
964 | 964 | |
965 | 965 | $customer_args = array( |
966 | - 'fields' => array( 'ID', 'user_email', 'display_name' ), |
|
966 | + 'fields' => array('ID', 'user_email', 'display_name'), |
|
967 | 967 | 'orderby' => 'display_name', |
968 | - 'search' => '*' . sanitize_text_field( $_GET['search'] ) . '*', |
|
969 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
968 | + 'search' => '*' . sanitize_text_field($_GET['search']) . '*', |
|
969 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
970 | 970 | ); |
971 | 971 | |
972 | - $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) ); |
|
972 | + $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args)); |
|
973 | 973 | $data = array(); |
974 | 974 | |
975 | - foreach ( $customers as $customer ) { |
|
975 | + foreach ($customers as $customer) { |
|
976 | 976 | $data[] = array( |
977 | 977 | 'id' => (int) $customer->ID, |
978 | - 'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ), |
|
978 | + 'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)), |
|
979 | 979 | ); |
980 | 980 | } |
981 | 981 | |
982 | - wp_send_json_success( $data ); |
|
982 | + wp_send_json_success($data); |
|
983 | 983 | |
984 | 984 | } |
985 | 985 | |
@@ -989,28 +989,28 @@ discard block |
||
989 | 989 | public static function get_aui_states_field() { |
990 | 990 | |
991 | 991 | // Verify nonce. |
992 | - check_ajax_referer( 'wpinv-nonce' ); |
|
992 | + check_ajax_referer('wpinv-nonce'); |
|
993 | 993 | |
994 | 994 | // We need a country. |
995 | - if ( empty( $_GET['country'] ) ) { |
|
995 | + if (empty($_GET['country'])) { |
|
996 | 996 | exit; |
997 | 997 | } |
998 | 998 | |
999 | - $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) ); |
|
1000 | - $state = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state(); |
|
1001 | - $name = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state'; |
|
1002 | - $class = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm'; |
|
999 | + $states = wpinv_get_country_states(sanitize_text_field($_GET['country'])); |
|
1000 | + $state = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state(); |
|
1001 | + $name = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state'; |
|
1002 | + $class = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm'; |
|
1003 | 1003 | |
1004 | - if ( empty( $states ) ) { |
|
1004 | + if (empty($states)) { |
|
1005 | 1005 | |
1006 | 1006 | $html = aui()->input( |
1007 | 1007 | array( |
1008 | 1008 | 'type' => 'text', |
1009 | 1009 | 'id' => 'wpinv_state', |
1010 | 1010 | 'name' => $name, |
1011 | - 'label' => __( 'State', 'invoicing' ), |
|
1011 | + 'label' => __('State', 'invoicing'), |
|
1012 | 1012 | 'label_type' => 'vertical', |
1013 | - 'placeholder' => __( 'State', 'invoicing' ), |
|
1013 | + 'placeholder' => __('State', 'invoicing'), |
|
1014 | 1014 | 'class' => $class, |
1015 | 1015 | 'value' => $state, |
1016 | 1016 | ) |
@@ -1022,9 +1022,9 @@ discard block |
||
1022 | 1022 | array( |
1023 | 1023 | 'id' => 'wpinv_state', |
1024 | 1024 | 'name' => $name, |
1025 | - 'label' => __( 'State', 'invoicing' ), |
|
1025 | + 'label' => __('State', 'invoicing'), |
|
1026 | 1026 | 'label_type' => 'vertical', |
1027 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
1027 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
1028 | 1028 | 'class' => $class, |
1029 | 1029 | 'value' => $state, |
1030 | 1030 | 'options' => $states, |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | wp_send_json_success( |
1039 | 1039 | array( |
1040 | 1040 | 'html' => $html, |
1041 | - 'select' => ! empty( $states ), |
|
1041 | + 'select' => !empty($states), |
|
1042 | 1042 | ) |
1043 | 1043 | ); |
1044 | 1044 | |
@@ -1052,11 +1052,11 @@ discard block |
||
1052 | 1052 | public static function payment_form_refresh_prices() { |
1053 | 1053 | |
1054 | 1054 | // Check nonce. |
1055 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1055 | + check_ajax_referer('getpaid_form_nonce'); |
|
1056 | 1056 | |
1057 | 1057 | // ... form fields... |
1058 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
1059 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
1058 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
1059 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
1060 | 1060 | exit; |
1061 | 1061 | } |
1062 | 1062 | |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | $submission = new GetPaid_Payment_Form_Submission(); |
1065 | 1065 | |
1066 | 1066 | // Do we have an error? |
1067 | - if ( ! empty( $submission->last_error ) ) { |
|
1067 | + if (!empty($submission->last_error)) { |
|
1068 | 1068 | wp_send_json_error( |
1069 | 1069 | array( |
1070 | 1070 | 'code' => $submission->last_error_code, |
@@ -1074,12 +1074,12 @@ discard block |
||
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | // Prepare the response. |
1077 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
1077 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
1078 | 1078 | |
1079 | 1079 | // Filter the response. |
1080 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
1080 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
1081 | 1081 | |
1082 | - wp_send_json_success( $response ); |
|
1082 | + wp_send_json_success($response); |
|
1083 | 1083 | } |
1084 | 1084 | |
1085 | 1085 | /** |
@@ -1091,63 +1091,63 @@ discard block |
||
1091 | 1091 | public static function file_upload() { |
1092 | 1092 | |
1093 | 1093 | // Check nonce. |
1094 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
1094 | + check_ajax_referer('getpaid_form_nonce'); |
|
1095 | 1095 | |
1096 | - if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) { |
|
1097 | - wp_die( __( 'Bad Request', 'invoicing' ), 400 ); |
|
1096 | + if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) { |
|
1097 | + wp_die(__('Bad Request', 'invoicing'), 400); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | // Fetch form. |
1101 | - $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) ); |
|
1101 | + $form = new GetPaid_Payment_Form(intval($_POST['form_id'])); |
|
1102 | 1102 | |
1103 | - if ( ! $form->is_active() ) { |
|
1104 | - wp_send_json_error( __( 'Payment form not active', 'invoicing' ) ); |
|
1103 | + if (!$form->is_active()) { |
|
1104 | + wp_send_json_error(__('Payment form not active', 'invoicing')); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | // Fetch appropriate field. |
1108 | - $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) ); |
|
1109 | - if ( empty( $upload_field ) ) { |
|
1110 | - wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) ); |
|
1108 | + $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name'])))); |
|
1109 | + if (empty($upload_field)) { |
|
1110 | + wp_send_json_error(__('Invalid upload field.', 'invoicing')); |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | // Prepare allowed file types. |
1114 | - $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' ); |
|
1114 | + $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png'); |
|
1115 | 1115 | $all_types = getpaid_get_allowed_mime_types(); |
1116 | 1116 | $mime_types = array(); |
1117 | 1117 | |
1118 | - foreach ( $file_types as $file_type ) { |
|
1119 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
1120 | - $mime_types[] = $all_types[ $file_type ]; |
|
1118 | + foreach ($file_types as $file_type) { |
|
1119 | + if (isset($all_types[$file_type])) { |
|
1120 | + $mime_types[] = $all_types[$file_type]; |
|
1121 | 1121 | } |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) { |
|
1125 | - wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) ); |
|
1124 | + if (!in_array($_FILES['file']['type'], $mime_types)) { |
|
1125 | + wp_send_json_error(__('Unsupported file type.', 'invoicing')); |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | // Upload file. |
1129 | - $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) ); |
|
1130 | - $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name ); |
|
1129 | + $file_name = explode('.', strtolower($_FILES['file']['name'])); |
|
1130 | + $file_name = uniqid('getpaid-') . '.' . array_pop($file_name); |
|
1131 | 1131 | |
1132 | 1132 | $uploaded = wp_upload_bits( |
1133 | 1133 | $file_name, |
1134 | 1134 | null, |
1135 | - file_get_contents( $_FILES['file']['tmp_name'] ) |
|
1135 | + file_get_contents($_FILES['file']['tmp_name']) |
|
1136 | 1136 | ); |
1137 | 1137 | |
1138 | - if ( ! empty( $uploaded['error'] ) ) { |
|
1139 | - wp_send_json_error( $uploaded['error'] ); |
|
1138 | + if (!empty($uploaded['error'])) { |
|
1139 | + wp_send_json_error($uploaded['error']); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | // Retrieve response. |
1143 | 1143 | $response = sprintf( |
1144 | 1144 | '<input type="hidden" name="%s[%s]" value="%s" />', |
1145 | - esc_attr( sanitize_text_field( $_POST['field_name'] ) ), |
|
1146 | - esc_url( $uploaded['url'] ), |
|
1147 | - esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) ) |
|
1145 | + esc_attr(sanitize_text_field($_POST['field_name'])), |
|
1146 | + esc_url($uploaded['url']), |
|
1147 | + esc_attr(sanitize_text_field(strtolower($_FILES['file']['name']))) |
|
1148 | 1148 | ); |
1149 | 1149 | |
1150 | - wp_send_json_success( $response ); |
|
1150 | + wp_send_json_success($response); |
|
1151 | 1151 | |
1152 | 1152 | } |
1153 | 1153 |
@@ -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 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,125 +175,125 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) { |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) { |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | 184 | } |
185 | - $templates[] = $slug . '.php'; |
|
185 | + $templates[] = $slug . '.php'; |
|
186 | 186 | |
187 | - // Allow template parts to be filtered |
|
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + // Allow template parts to be filtered |
|
188 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
189 | 189 | |
190 | - // Return the part that is found |
|
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + // Return the part that is found |
|
191 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
195 | - // No file found yet |
|
196 | - $located = false; |
|
195 | + // No file found yet |
|
196 | + $located = false; |
|
197 | 197 | |
198 | - // Try to find a template file |
|
199 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + // Try to find a template file |
|
199 | + foreach ( (array)$template_names as $template_name ) { |
|
200 | 200 | |
201 | - // Continue if template is empty |
|
202 | - if ( empty( $template_name ) ) { |
|
203 | - continue; |
|
201 | + // Continue if template is empty |
|
202 | + if ( empty( $template_name ) ) { |
|
203 | + continue; |
|
204 | 204 | } |
205 | 205 | |
206 | - // Trim off any slashes from the template name |
|
207 | - $template_name = ltrim( $template_name, '/' ); |
|
206 | + // Trim off any slashes from the template name |
|
207 | + $template_name = ltrim( $template_name, '/' ); |
|
208 | 208 | |
209 | - // try locating this template file by looping through the template paths |
|
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | + // try locating this template file by looping through the template paths |
|
210 | + foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
213 | - $located = $template_path . $template_name; |
|
214 | - break; |
|
215 | - } |
|
216 | - } |
|
212 | + if ( file_exists( $template_path . $template_name ) ) { |
|
213 | + $located = $template_path . $template_name; |
|
214 | + break; |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
219 | - break; |
|
220 | - } |
|
221 | - } |
|
218 | + if ( ! empty( $located ) ) { |
|
219 | + break; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | + load_template( $located, $require_once ); |
|
225 | 225 | } |
226 | 226 | |
227 | - return $located; |
|
227 | + return $located; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_get_theme_template_paths() { |
231 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
231 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
232 | 232 | |
233 | - $file_paths = array( |
|
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | - 100 => wpinv_get_templates_dir(), |
|
237 | - ); |
|
233 | + $file_paths = array( |
|
234 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
236 | + 100 => wpinv_get_templates_dir(), |
|
237 | + ); |
|
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
240 | 240 | |
241 | - // sort the file paths based on priority |
|
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
241 | + // sort the file paths based on priority |
|
242 | + ksort( $file_paths, SORT_NUMERIC ); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map( 'trailingslashit', $file_paths ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | - $pages = array(); |
|
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
249 | + $pages = array(); |
|
250 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | - return; |
|
257 | - } |
|
255 | + if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | 258 | |
259 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
259 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
260 | 260 | } |
261 | 261 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
262 | 262 | |
263 | 263 | function wpinv_add_body_classes( $class ) { |
264 | - $classes = (array)$class; |
|
264 | + $classes = (array)$class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
267 | - $classes[] = 'wpinv-checkout'; |
|
268 | - $classes[] = 'wpinv-page'; |
|
269 | - } |
|
266 | + if ( wpinv_is_checkout() ) { |
|
267 | + $classes[] = 'wpinv-checkout'; |
|
268 | + $classes[] = 'wpinv-page'; |
|
269 | + } |
|
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
272 | - $classes[] = 'wpinv-success'; |
|
273 | - $classes[] = 'wpinv-page'; |
|
274 | - } |
|
271 | + if ( wpinv_is_success_page() ) { |
|
272 | + $classes[] = 'wpinv-success'; |
|
273 | + $classes[] = 'wpinv-page'; |
|
274 | + } |
|
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
277 | - $classes[] = 'wpinv-failed-transaction'; |
|
278 | - $classes[] = 'wpinv-page'; |
|
279 | - } |
|
276 | + if ( wpinv_is_failed_transaction_page() ) { |
|
277 | + $classes[] = 'wpinv-failed-transaction'; |
|
278 | + $classes[] = 'wpinv-page'; |
|
279 | + } |
|
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
282 | - $classes[] = 'wpinv-history'; |
|
283 | - $classes[] = 'wpinv-page'; |
|
284 | - } |
|
281 | + if ( wpinv_is_invoice_history_page() ) { |
|
282 | + $classes[] = 'wpinv-history'; |
|
283 | + $classes[] = 'wpinv-page'; |
|
284 | + } |
|
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | - $classes[] = 'wpinv-subscription'; |
|
288 | - $classes[] = 'wpinv-page'; |
|
289 | - } |
|
286 | + if ( wpinv_is_subscriptions_history_page() ) { |
|
287 | + $classes[] = 'wpinv-subscription'; |
|
288 | + $classes[] = 'wpinv-page'; |
|
289 | + } |
|
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
292 | - $classes[] = 'wpinv-test-mode'; |
|
293 | - $classes[] = 'wpinv-page'; |
|
294 | - } |
|
291 | + if ( wpinv_is_test_mode() ) { |
|
292 | + $classes[] = 'wpinv-test-mode'; |
|
293 | + $classes[] = 'wpinv-page'; |
|
294 | + } |
|
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique( $classes ); |
|
297 | 297 | } |
298 | 298 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
299 | 299 | |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | |
312 | 312 | $output = wpinv_html_select( |
313 | 313 | array( |
314 | - 'name' => $name, |
|
315 | - 'selected' => $selected, |
|
316 | - 'options' => $options, |
|
317 | - 'show_option_all' => false, |
|
318 | - 'show_option_none' => false, |
|
314 | + 'name' => $name, |
|
315 | + 'selected' => $selected, |
|
316 | + 'options' => $options, |
|
317 | + 'show_option_all' => false, |
|
318 | + 'show_option_none' => false, |
|
319 | 319 | ) |
320 | 320 | ); |
321 | 321 | |
@@ -344,11 +344,11 @@ discard block |
||
344 | 344 | |
345 | 345 | $output = wpinv_html_select( |
346 | 346 | array( |
347 | - 'name' => $name, |
|
348 | - 'selected' => $selected, |
|
349 | - 'options' => $options, |
|
350 | - 'show_option_all' => false, |
|
351 | - 'show_option_none' => false, |
|
347 | + 'name' => $name, |
|
348 | + 'selected' => $selected, |
|
349 | + 'options' => $options, |
|
350 | + 'show_option_all' => false, |
|
351 | + 'show_option_none' => false, |
|
352 | 352 | ) |
353 | 353 | ); |
354 | 354 | |
@@ -512,16 +512,16 @@ discard block |
||
512 | 512 | |
513 | 513 | $output = wpinv_html_select( |
514 | 514 | array( |
515 | - 'name' => $args['name'], |
|
516 | - 'selected' => $args['selected'], |
|
517 | - 'id' => $args['id'], |
|
518 | - 'class' => $args['class'], |
|
519 | - 'options' => $options, |
|
520 | - 'multiple' => $args['multiple'], |
|
521 | - 'placeholder' => $args['placeholder'], |
|
522 | - 'show_option_all' => $args['show_option_all'], |
|
523 | - 'show_option_none' => $args['show_option_none'], |
|
524 | - 'data' => $args['data'], |
|
515 | + 'name' => $args['name'], |
|
516 | + 'selected' => $args['selected'], |
|
517 | + 'id' => $args['id'], |
|
518 | + 'class' => $args['class'], |
|
519 | + 'options' => $options, |
|
520 | + 'multiple' => $args['multiple'], |
|
521 | + 'placeholder' => $args['placeholder'], |
|
522 | + 'show_option_all' => $args['show_option_all'], |
|
523 | + 'show_option_none' => $args['show_option_none'], |
|
524 | + 'data' => $args['data'], |
|
525 | 525 | ) |
526 | 526 | ); |
527 | 527 | |
@@ -822,21 +822,21 @@ discard block |
||
822 | 822 | |
823 | 823 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
824 | 824 | |
825 | - // Remove unavailable tags. |
|
825 | + // Remove unavailable tags. |
|
826 | 826 | $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
827 | 827 | |
828 | 828 | // Clean up white space. |
829 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
829 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
830 | 830 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
831 | 831 | |
832 | 832 | // Break newlines apart and remove empty lines/trim commas and white space. |
833 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
833 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
834 | 834 | |
835 | 835 | // Add html breaks. |
836 | - $formatted_address = implode( $separator, $formatted_address ); |
|
836 | + $formatted_address = implode( $separator, $formatted_address ); |
|
837 | 837 | |
838 | - // We're done! |
|
839 | - return $formatted_address; |
|
838 | + // We're done! |
|
839 | + return $formatted_address; |
|
840 | 840 | |
841 | 841 | } |
842 | 842 | |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | function getpaid_display_invoice_subscriptions( $invoice ) { |
883 | 883 | |
884 | 884 | // Subscriptions. |
885 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
885 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
886 | 886 | |
887 | 887 | if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
888 | 888 | return; |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | function wpinv_empty_cart_message() { |
1097 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1097 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | /** |
@@ -1291,10 +1291,10 @@ discard block |
||
1291 | 1291 | |
1292 | 1292 | if ( 0 == count( $form->get_items() ) ) { |
1293 | 1293 | echo aui()->alert( |
1294 | - array( |
|
1295 | - 'type' => 'warning', |
|
1296 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1297 | - ) |
|
1294 | + array( |
|
1295 | + 'type' => 'warning', |
|
1296 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1297 | + ) |
|
1298 | 1298 | ); |
1299 | 1299 | return; |
1300 | 1300 | } |
@@ -1315,21 +1315,21 @@ discard block |
||
1315 | 1315 | $invoice = wpinv_get_invoice( $invoice_id ); |
1316 | 1316 | |
1317 | 1317 | if ( empty( $invoice ) ) { |
1318 | - echo aui()->alert( |
|
1319 | - array( |
|
1320 | - 'type' => 'warning', |
|
1321 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1322 | - ) |
|
1318 | + echo aui()->alert( |
|
1319 | + array( |
|
1320 | + 'type' => 'warning', |
|
1321 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1322 | + ) |
|
1323 | 1323 | ); |
1324 | 1324 | return; |
1325 | 1325 | } |
1326 | 1326 | |
1327 | 1327 | if ( $invoice->is_paid() ) { |
1328 | - echo aui()->alert( |
|
1329 | - array( |
|
1330 | - 'type' => 'warning', |
|
1331 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1332 | - ) |
|
1328 | + echo aui()->alert( |
|
1329 | + array( |
|
1330 | + 'type' => 'warning', |
|
1331 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1332 | + ) |
|
1333 | 1333 | ); |
1334 | 1334 | return; |
1335 | 1335 | } |
@@ -1391,7 +1391,7 @@ discard block |
||
1391 | 1391 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - if ( ! empty( $items ) ) { |
|
1394 | + if ( ! empty( $items ) ) { |
|
1395 | 1395 | $items = esc_attr( $items ); |
1396 | 1396 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1397 | 1397 | } |
@@ -1577,21 +1577,21 @@ discard block |
||
1577 | 1577 | |
1578 | 1578 | return aui()->select( |
1579 | 1579 | array( |
1580 | - 'options' => $states, |
|
1581 | - 'name' => esc_attr( $field_name ), |
|
1582 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1583 | - 'value' => sanitize_text_field( $state ), |
|
1584 | - 'placeholder' => $placeholder, |
|
1585 | - 'required' => $required, |
|
1586 | - 'label' => wp_kses_post( $label ), |
|
1587 | - 'label_type' => 'vertical', |
|
1588 | - 'help_text' => $help_text, |
|
1589 | - 'class' => 'getpaid-address-field wpinv_state', |
|
1590 | - 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1591 | - 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1592 | - 'extra_attributes' => array( |
|
1593 | - 'autocomplete' => 'address-level1', |
|
1594 | - ), |
|
1580 | + 'options' => $states, |
|
1581 | + 'name' => esc_attr( $field_name ), |
|
1582 | + 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1583 | + 'value' => sanitize_text_field( $state ), |
|
1584 | + 'placeholder' => $placeholder, |
|
1585 | + 'required' => $required, |
|
1586 | + 'label' => wp_kses_post( $label ), |
|
1587 | + 'label_type' => 'vertical', |
|
1588 | + 'help_text' => $help_text, |
|
1589 | + 'class' => 'getpaid-address-field wpinv_state', |
|
1590 | + 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
|
1591 | + 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
|
1592 | + 'extra_attributes' => array( |
|
1593 | + 'autocomplete' => 'address-level1', |
|
1594 | + ), |
|
1595 | 1595 | ) |
1596 | 1596 | ); |
1597 | 1597 |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,58 +170,58 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) { |
|
182 | + if (isset($name)) { |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | } |
185 | 185 | $templates[] = $slug . '.php'; |
186 | 186 | |
187 | 187 | // Allow template parts to be filtered |
188 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
189 | 189 | |
190 | 190 | // Return the part that is found |
191 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | + return wpinv_locate_tmpl($templates, $load, false); |
|
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
194 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
195 | 195 | // No file found yet |
196 | 196 | $located = false; |
197 | 197 | |
198 | 198 | // Try to find a template file |
199 | - foreach ( (array)$template_names as $template_name ) { |
|
199 | + foreach ((array) $template_names as $template_name) { |
|
200 | 200 | |
201 | 201 | // Continue if template is empty |
202 | - if ( empty( $template_name ) ) { |
|
202 | + if (empty($template_name)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Trim off any slashes from the template name |
207 | - $template_name = ltrim( $template_name, '/' ); |
|
207 | + $template_name = ltrim($template_name, '/'); |
|
208 | 208 | |
209 | 209 | // try locating this template file by looping through the template paths |
210 | - foreach ( wpinv_get_theme_template_paths() as $template_path ) { |
|
210 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
211 | 211 | |
212 | - if ( file_exists( $template_path . $template_name ) ) { |
|
212 | + if (file_exists($template_path . $template_name)) { |
|
213 | 213 | $located = $template_path . $template_name; |
214 | 214 | break; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - if ( ! empty( $located ) ) { |
|
218 | + if (!empty($located)) { |
|
219 | 219 | break; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if ( ( true == $load ) && ! empty( $located ) ) { |
|
224 | - load_template( $located, $require_once ); |
|
223 | + if ((true == $load) && !empty($located)) { |
|
224 | + load_template($located, $require_once); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | return $located; |
@@ -231,81 +231,81 @@ discard block |
||
231 | 231 | $template_dir = wpinv_get_theme_template_dir_name(); |
232 | 232 | |
233 | 233 | $file_paths = array( |
234 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
235 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
234 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
235 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
236 | 236 | 100 => wpinv_get_templates_dir(), |
237 | 237 | ); |
238 | 238 | |
239 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
239 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
240 | 240 | |
241 | 241 | // sort the file paths based on priority |
242 | - ksort( $file_paths, SORT_NUMERIC ); |
|
242 | + ksort($file_paths, SORT_NUMERIC); |
|
243 | 243 | |
244 | - return array_map( 'trailingslashit', $file_paths ); |
|
244 | + return array_map('trailingslashit', $file_paths); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | function wpinv_checkout_meta_tags() { |
248 | 248 | |
249 | 249 | $pages = array(); |
250 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
252 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
253 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
250 | + $pages[] = wpinv_get_option('success_page'); |
|
251 | + $pages[] = wpinv_get_option('failure_page'); |
|
252 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
253 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
254 | 254 | |
255 | - if ( ! wpinv_is_checkout() && ! is_page( $pages ) ) { |
|
255 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | 259 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
260 | 260 | } |
261 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
261 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
262 | 262 | |
263 | -function wpinv_add_body_classes( $class ) { |
|
264 | - $classes = (array)$class; |
|
263 | +function wpinv_add_body_classes($class) { |
|
264 | + $classes = (array) $class; |
|
265 | 265 | |
266 | - if ( wpinv_is_checkout() ) { |
|
266 | + if (wpinv_is_checkout()) { |
|
267 | 267 | $classes[] = 'wpinv-checkout'; |
268 | 268 | $classes[] = 'wpinv-page'; |
269 | 269 | } |
270 | 270 | |
271 | - if ( wpinv_is_success_page() ) { |
|
271 | + if (wpinv_is_success_page()) { |
|
272 | 272 | $classes[] = 'wpinv-success'; |
273 | 273 | $classes[] = 'wpinv-page'; |
274 | 274 | } |
275 | 275 | |
276 | - if ( wpinv_is_failed_transaction_page() ) { |
|
276 | + if (wpinv_is_failed_transaction_page()) { |
|
277 | 277 | $classes[] = 'wpinv-failed-transaction'; |
278 | 278 | $classes[] = 'wpinv-page'; |
279 | 279 | } |
280 | 280 | |
281 | - if ( wpinv_is_invoice_history_page() ) { |
|
281 | + if (wpinv_is_invoice_history_page()) { |
|
282 | 282 | $classes[] = 'wpinv-history'; |
283 | 283 | $classes[] = 'wpinv-page'; |
284 | 284 | } |
285 | 285 | |
286 | - if ( wpinv_is_subscriptions_history_page() ) { |
|
286 | + if (wpinv_is_subscriptions_history_page()) { |
|
287 | 287 | $classes[] = 'wpinv-subscription'; |
288 | 288 | $classes[] = 'wpinv-page'; |
289 | 289 | } |
290 | 290 | |
291 | - if ( wpinv_is_test_mode() ) { |
|
291 | + if (wpinv_is_test_mode()) { |
|
292 | 292 | $classes[] = 'wpinv-test-mode'; |
293 | 293 | $classes[] = 'wpinv-page'; |
294 | 294 | } |
295 | 295 | |
296 | - return array_unique( $classes ); |
|
296 | + return array_unique($classes); |
|
297 | 297 | } |
298 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
298 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
299 | 299 | |
300 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
301 | - $current = date( 'Y' ); |
|
302 | - $start_year = $current - absint( $years_before ); |
|
303 | - $end_year = $current + absint( $years_after ); |
|
304 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
300 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
301 | + $current = date('Y'); |
|
302 | + $start_year = $current - absint($years_before); |
|
303 | + $end_year = $current + absint($years_after); |
|
304 | + $selected = empty($selected) ? date('Y') : $selected; |
|
305 | 305 | $options = array(); |
306 | 306 | |
307 | - while ( $start_year <= $end_year ) { |
|
308 | - $options[ absint( $start_year ) ] = $start_year; |
|
307 | + while ($start_year <= $end_year) { |
|
308 | + $options[absint($start_year)] = $start_year; |
|
309 | 309 | $start_year++; |
310 | 310 | } |
311 | 311 | |
@@ -322,25 +322,25 @@ discard block |
||
322 | 322 | return $output; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
325 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
326 | 326 | |
327 | 327 | $options = array( |
328 | - '1' => __( 'January', 'invoicing' ), |
|
329 | - '2' => __( 'February', 'invoicing' ), |
|
330 | - '3' => __( 'March', 'invoicing' ), |
|
331 | - '4' => __( 'April', 'invoicing' ), |
|
332 | - '5' => __( 'May', 'invoicing' ), |
|
333 | - '6' => __( 'June', 'invoicing' ), |
|
334 | - '7' => __( 'July', 'invoicing' ), |
|
335 | - '8' => __( 'August', 'invoicing' ), |
|
336 | - '9' => __( 'September', 'invoicing' ), |
|
337 | - '10' => __( 'October', 'invoicing' ), |
|
338 | - '11' => __( 'November', 'invoicing' ), |
|
339 | - '12' => __( 'December', 'invoicing' ), |
|
328 | + '1' => __('January', 'invoicing'), |
|
329 | + '2' => __('February', 'invoicing'), |
|
330 | + '3' => __('March', 'invoicing'), |
|
331 | + '4' => __('April', 'invoicing'), |
|
332 | + '5' => __('May', 'invoicing'), |
|
333 | + '6' => __('June', 'invoicing'), |
|
334 | + '7' => __('July', 'invoicing'), |
|
335 | + '8' => __('August', 'invoicing'), |
|
336 | + '9' => __('September', 'invoicing'), |
|
337 | + '10' => __('October', 'invoicing'), |
|
338 | + '11' => __('November', 'invoicing'), |
|
339 | + '12' => __('December', 'invoicing'), |
|
340 | 340 | ); |
341 | 341 | |
342 | 342 | // If no month is selected, default to the current month |
343 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
343 | + $selected = empty($selected) ? date('n') : $selected; |
|
344 | 344 | |
345 | 345 | $output = wpinv_html_select( |
346 | 346 | array( |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | return $output; |
356 | 356 | } |
357 | 357 | |
358 | -function wpinv_html_select( $args = array() ) { |
|
358 | +function wpinv_html_select($args = array()) { |
|
359 | 359 | $defaults = array( |
360 | 360 | 'options' => array(), |
361 | 361 | 'name' => null, |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | 'selected' => 0, |
365 | 365 | 'placeholder' => null, |
366 | 366 | 'multiple' => false, |
367 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
368 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
367 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
368 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
369 | 369 | 'data' => array(), |
370 | 370 | 'onchange' => null, |
371 | 371 | 'required' => false, |
@@ -373,74 +373,74 @@ discard block |
||
373 | 373 | 'readonly' => false, |
374 | 374 | ); |
375 | 375 | |
376 | - $args = wp_parse_args( $args, $defaults ); |
|
376 | + $args = wp_parse_args($args, $defaults); |
|
377 | 377 | |
378 | 378 | $data_elements = ''; |
379 | - foreach ( $args['data'] as $key => $value ) { |
|
380 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
379 | + foreach ($args['data'] as $key => $value) { |
|
380 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
381 | 381 | } |
382 | 382 | |
383 | - if ( $args['multiple'] ) { |
|
383 | + if ($args['multiple']) { |
|
384 | 384 | $multiple = ' MULTIPLE'; |
385 | 385 | } else { |
386 | 386 | $multiple = ''; |
387 | 387 | } |
388 | 388 | |
389 | - if ( $args['placeholder'] ) { |
|
389 | + if ($args['placeholder']) { |
|
390 | 390 | $placeholder = $args['placeholder']; |
391 | 391 | } else { |
392 | 392 | $placeholder = ''; |
393 | 393 | } |
394 | 394 | |
395 | 395 | $options = ''; |
396 | - if ( ! empty( $args['onchange'] ) ) { |
|
397 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
396 | + if (!empty($args['onchange'])) { |
|
397 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
398 | 398 | } |
399 | 399 | |
400 | - if ( ! empty( $args['required'] ) ) { |
|
400 | + if (!empty($args['required'])) { |
|
401 | 401 | $options .= ' required="required"'; |
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $args['disabled'] ) ) { |
|
404 | + if (!empty($args['disabled'])) { |
|
405 | 405 | $options .= ' disabled'; |
406 | 406 | } |
407 | 407 | |
408 | - if ( ! empty( $args['readonly'] ) ) { |
|
408 | + if (!empty($args['readonly'])) { |
|
409 | 409 | $options .= ' readonly'; |
410 | 410 | } |
411 | 411 | |
412 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
413 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
412 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
413 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
414 | 414 | |
415 | - if ( $args['show_option_all'] ) { |
|
416 | - if ( $args['multiple'] ) { |
|
417 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
415 | + if ($args['show_option_all']) { |
|
416 | + if ($args['multiple']) { |
|
417 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
418 | 418 | } else { |
419 | - $selected = selected( $args['selected'], 0, false ); |
|
419 | + $selected = selected($args['selected'], 0, false); |
|
420 | 420 | } |
421 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
421 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
422 | 422 | } |
423 | 423 | |
424 | - if ( ! empty( $args['options'] ) ) { |
|
424 | + if (!empty($args['options'])) { |
|
425 | 425 | |
426 | - if ( $args['show_option_none'] ) { |
|
427 | - if ( $args['multiple'] ) { |
|
428 | - $selected = selected( true, in_array( '', $args['selected'] ), false ); |
|
426 | + if ($args['show_option_none']) { |
|
427 | + if ($args['multiple']) { |
|
428 | + $selected = selected(true, in_array('', $args['selected']), false); |
|
429 | 429 | } else { |
430 | - $selected = selected( $args['selected'] === '', true, false ); |
|
430 | + $selected = selected($args['selected'] === '', true, false); |
|
431 | 431 | } |
432 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
432 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
433 | 433 | } |
434 | 434 | |
435 | - foreach ( $args['options'] as $key => $option ) { |
|
435 | + foreach ($args['options'] as $key => $option) { |
|
436 | 436 | |
437 | - if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
438 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
437 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
438 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
439 | 439 | } else { |
440 | - $selected = selected( $args['selected'], $key, false ); |
|
440 | + $selected = selected($args['selected'], $key, false); |
|
441 | 441 | } |
442 | 442 | |
443 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
443 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | return $output; |
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_item_dropdown( $args = array() ) { |
|
452 | +function wpinv_item_dropdown($args = array()) { |
|
453 | 453 | $defaults = array( |
454 | 454 | 'name' => 'wpi_item', |
455 | 455 | 'id' => 'wpi_item', |
@@ -457,14 +457,14 @@ discard block |
||
457 | 457 | 'multiple' => false, |
458 | 458 | 'selected' => 0, |
459 | 459 | 'number' => -1, |
460 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
461 | - 'data' => array( 'search-type' => 'item' ), |
|
460 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
461 | + 'data' => array('search-type' => 'item'), |
|
462 | 462 | 'show_option_all' => false, |
463 | 463 | 'show_option_none' => false, |
464 | 464 | 'show_recurring' => false, |
465 | 465 | ); |
466 | 466 | |
467 | - $args = wp_parse_args( $args, $defaults ); |
|
467 | + $args = wp_parse_args($args, $defaults); |
|
468 | 468 | |
469 | 469 | $item_args = array( |
470 | 470 | 'post_type' => 'wpi_item', |
@@ -473,40 +473,40 @@ discard block |
||
473 | 473 | 'posts_per_page' => $args['number'], |
474 | 474 | ); |
475 | 475 | |
476 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
476 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
477 | 477 | |
478 | - $items = get_posts( $item_args ); |
|
478 | + $items = get_posts($item_args); |
|
479 | 479 | $options = array(); |
480 | - if ( $items ) { |
|
481 | - foreach ( $items as $item ) { |
|
482 | - $title = esc_html( $item->post_title ); |
|
480 | + if ($items) { |
|
481 | + foreach ($items as $item) { |
|
482 | + $title = esc_html($item->post_title); |
|
483 | 483 | |
484 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
485 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
484 | + if (!empty($args['show_recurring'])) { |
|
485 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
486 | 486 | } |
487 | 487 | |
488 | - $options[ absint( $item->ID ) ] = $title; |
|
488 | + $options[absint($item->ID)] = $title; |
|
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | 492 | // This ensures that any selected items are included in the drop down |
493 | - if ( is_array( $args['selected'] ) ) { |
|
494 | - foreach ( $args['selected'] as $item ) { |
|
495 | - if ( ! in_array( $item, $options ) ) { |
|
496 | - $title = get_the_title( $item ); |
|
497 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
498 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
493 | + if (is_array($args['selected'])) { |
|
494 | + foreach ($args['selected'] as $item) { |
|
495 | + if (!in_array($item, $options)) { |
|
496 | + $title = get_the_title($item); |
|
497 | + if (!empty($args['show_recurring'])) { |
|
498 | + $title .= wpinv_get_item_suffix($item, false); |
|
499 | 499 | } |
500 | - $options[ $item ] = $title; |
|
500 | + $options[$item] = $title; |
|
501 | 501 | } |
502 | 502 | } |
503 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
504 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
505 | - $title = get_the_title( $args['selected'] ); |
|
506 | - if ( ! empty( $args['show_recurring'] ) ) { |
|
507 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
503 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
504 | + if (!in_array($args['selected'], $options)) { |
|
505 | + $title = get_the_title($args['selected']); |
|
506 | + if (!empty($args['show_recurring'])) { |
|
507 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
508 | 508 | } |
509 | - $options[ $args['selected'] ] = get_the_title( $args['selected'] ); |
|
509 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -543,16 +543,16 @@ discard block |
||
543 | 543 | ); |
544 | 544 | |
545 | 545 | $options = array(); |
546 | - if ( $items ) { |
|
547 | - foreach ( $items as $item ) { |
|
548 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
546 | + if ($items) { |
|
547 | + foreach ($items as $item) { |
|
548 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | 552 | return $options; |
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_html_checkbox( $args = array() ) { |
|
555 | +function wpinv_html_checkbox($args = array()) { |
|
556 | 556 | $defaults = array( |
557 | 557 | 'name' => null, |
558 | 558 | 'current' => null, |
@@ -563,17 +563,17 @@ discard block |
||
563 | 563 | ), |
564 | 564 | ); |
565 | 565 | |
566 | - $args = wp_parse_args( $args, $defaults ); |
|
566 | + $args = wp_parse_args($args, $defaults); |
|
567 | 567 | |
568 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
568 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
569 | 569 | $attr = ''; |
570 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
570 | + if (!empty($args['options']['disabled'])) { |
|
571 | 571 | $attr .= ' disabled="disabled"'; |
572 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
572 | + } elseif (!empty($args['options']['readonly'])) { |
|
573 | 573 | $attr .= ' readonly'; |
574 | 574 | } |
575 | 575 | |
576 | - $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . esc_attr( $class ) . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
576 | + $output = '<input type="checkbox"' . $attr . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . esc_attr($class) . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
577 | 577 | |
578 | 578 | return $output; |
579 | 579 | } |
@@ -581,34 +581,34 @@ discard block |
||
581 | 581 | /** |
582 | 582 | * Displays a hidden field. |
583 | 583 | */ |
584 | -function getpaid_hidden_field( $name, $value ) { |
|
585 | - echo "<input type='hidden' name='" . esc_attr( $name ) . "' value=' " . esc_attr( $value ) . "' />"; |
|
584 | +function getpaid_hidden_field($name, $value) { |
|
585 | + echo "<input type='hidden' name='" . esc_attr($name) . "' value=' " . esc_attr($value) . "' />"; |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
589 | 589 | * Displays a submit field. |
590 | 590 | */ |
591 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
592 | - echo "<input type='submit' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "' class='btn " . esc_attr( $class ) . "' />"; |
|
591 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
592 | + echo "<input type='submit' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='btn " . esc_attr($class) . "' />"; |
|
593 | 593 | } |
594 | 594 | |
595 | -function wpinv_html_text( $args = array() ) { |
|
595 | +function wpinv_html_text($args = array()) { |
|
596 | 596 | // Backwards compatibility |
597 | - if ( func_num_args() > 1 ) { |
|
597 | + if (func_num_args() > 1) { |
|
598 | 598 | $args = func_get_args(); |
599 | 599 | |
600 | 600 | $name = $args[0]; |
601 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
602 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
603 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
601 | + $value = isset($args[1]) ? $args[1] : ''; |
|
602 | + $label = isset($args[2]) ? $args[2] : ''; |
|
603 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | $defaults = array( |
607 | 607 | 'id' => '', |
608 | - 'name' => isset( $name ) ? $name : 'text', |
|
609 | - 'value' => isset( $value ) ? $value : null, |
|
610 | - 'label' => isset( $label ) ? $label : null, |
|
611 | - 'desc' => isset( $desc ) ? $desc : null, |
|
608 | + 'name' => isset($name) ? $name : 'text', |
|
609 | + 'value' => isset($value) ? $value : null, |
|
610 | + 'label' => isset($label) ? $label : null, |
|
611 | + 'desc' => isset($desc) ? $desc : null, |
|
612 | 612 | 'placeholder' => '', |
613 | 613 | 'class' => 'regular-text', |
614 | 614 | 'disabled' => false, |
@@ -618,41 +618,41 @@ discard block |
||
618 | 618 | 'data' => false, |
619 | 619 | ); |
620 | 620 | |
621 | - $args = wp_parse_args( $args, $defaults ); |
|
621 | + $args = wp_parse_args($args, $defaults); |
|
622 | 622 | |
623 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
623 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
624 | 624 | $options = ''; |
625 | - if ( $args['required'] ) { |
|
625 | + if ($args['required']) { |
|
626 | 626 | $options .= ' required="required"'; |
627 | 627 | } |
628 | - if ( $args['readonly'] ) { |
|
628 | + if ($args['readonly']) { |
|
629 | 629 | $options .= ' readonly'; |
630 | 630 | } |
631 | - if ( $args['readonly'] ) { |
|
631 | + if ($args['readonly']) { |
|
632 | 632 | $options .= ' readonly'; |
633 | 633 | } |
634 | 634 | |
635 | 635 | $data = ''; |
636 | - if ( ! empty( $args['data'] ) ) { |
|
637 | - foreach ( $args['data'] as $key => $value ) { |
|
638 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
636 | + if (!empty($args['data'])) { |
|
637 | + foreach ($args['data'] as $key => $value) { |
|
638 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
639 | 639 | } |
640 | 640 | } |
641 | 641 | |
642 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
643 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
644 | - if ( ! empty( $args['desc'] ) ) { |
|
645 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
642 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
643 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
644 | + if (!empty($args['desc'])) { |
|
645 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
646 | 646 | } |
647 | 647 | |
648 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
648 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
649 | 649 | |
650 | 650 | $output .= '</span>'; |
651 | 651 | |
652 | 652 | return $output; |
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_html_textarea( $args = array() ) { |
|
655 | +function wpinv_html_textarea($args = array()) { |
|
656 | 656 | $defaults = array( |
657 | 657 | 'name' => 'textarea', |
658 | 658 | 'value' => null, |
@@ -663,31 +663,31 @@ discard block |
||
663 | 663 | 'placeholder' => '', |
664 | 664 | ); |
665 | 665 | |
666 | - $args = wp_parse_args( $args, $defaults ); |
|
666 | + $args = wp_parse_args($args, $defaults); |
|
667 | 667 | |
668 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
668 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
669 | 669 | $disabled = ''; |
670 | - if ( $args['disabled'] ) { |
|
670 | + if ($args['disabled']) { |
|
671 | 671 | $disabled = ' disabled="disabled"'; |
672 | 672 | } |
673 | 673 | |
674 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
675 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
676 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
674 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
675 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
676 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
677 | 677 | |
678 | - if ( ! empty( $args['desc'] ) ) { |
|
679 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
678 | + if (!empty($args['desc'])) { |
|
679 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
680 | 680 | } |
681 | 681 | $output .= '</span>'; |
682 | 682 | |
683 | 683 | return $output; |
684 | 684 | } |
685 | 685 | |
686 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
686 | +function wpinv_html_ajax_user_search($args = array()) { |
|
687 | 687 | $defaults = array( |
688 | 688 | 'name' => 'user_id', |
689 | 689 | 'value' => null, |
690 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
690 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
691 | 691 | 'label' => null, |
692 | 692 | 'desc' => null, |
693 | 693 | 'class' => '', |
@@ -696,13 +696,13 @@ discard block |
||
696 | 696 | 'data' => false, |
697 | 697 | ); |
698 | 698 | |
699 | - $args = wp_parse_args( $args, $defaults ); |
|
699 | + $args = wp_parse_args($args, $defaults); |
|
700 | 700 | |
701 | 701 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
702 | 702 | |
703 | 703 | $output = '<span class="wpinv_user_search_wrap">'; |
704 | - $output .= wpinv_html_text( $args ); |
|
705 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
704 | + $output .= wpinv_html_text($args); |
|
705 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
706 | 706 | $output .= '</span>'; |
707 | 707 | |
708 | 708 | return $output; |
@@ -713,44 +713,44 @@ discard block |
||
713 | 713 | * |
714 | 714 | * @param string $template the template that is currently being used. |
715 | 715 | */ |
716 | -function wpinv_template( $template ) { |
|
716 | +function wpinv_template($template) { |
|
717 | 717 | global $post; |
718 | 718 | |
719 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
719 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
720 | 720 | |
721 | 721 | // If the user can view this invoice, display it. |
722 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
722 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
723 | 723 | |
724 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
724 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
725 | 725 | |
726 | 726 | // Else display an error message. |
727 | 727 | } else { |
728 | 728 | |
729 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
729 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
730 | 730 | |
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | 734 | return $template; |
735 | 735 | } |
736 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
736 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
737 | 737 | |
738 | 738 | function wpinv_get_business_address() { |
739 | 739 | $business_address = wpinv_store_address(); |
740 | - $business_address = ! empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
740 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
741 | 741 | |
742 | 742 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
743 | 743 | |
744 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
744 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
748 | 748 | * Displays the company address. |
749 | 749 | */ |
750 | 750 | function wpinv_display_from_address() { |
751 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
751 | + wpinv_get_template('invoice/company-address.php'); |
|
752 | 752 | } |
753 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
753 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
754 | 754 | |
755 | 755 | /** |
756 | 756 | * Generates a watermark text for an invoice. |
@@ -758,9 +758,9 @@ discard block |
||
758 | 758 | * @param WPInv_Invoice $invoice |
759 | 759 | * @return string |
760 | 760 | */ |
761 | -function wpinv_watermark( $invoice ) { |
|
762 | - $watermark = wpinv_get_watermark( $invoice ); |
|
763 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
761 | +function wpinv_watermark($invoice) { |
|
762 | + $watermark = wpinv_get_watermark($invoice); |
|
763 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
@@ -769,37 +769,37 @@ discard block |
||
769 | 769 | * @param WPInv_Invoice $invoice |
770 | 770 | * @return string |
771 | 771 | */ |
772 | -function wpinv_get_watermark( $invoice ) { |
|
772 | +function wpinv_get_watermark($invoice) { |
|
773 | 773 | return $invoice->get_status_nicename(); |
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
777 | 777 | * @deprecated |
778 | 778 | */ |
779 | -function wpinv_display_invoice_details( $invoice ) { |
|
780 | - return getpaid_invoice_meta( $invoice ); |
|
779 | +function wpinv_display_invoice_details($invoice) { |
|
780 | + return getpaid_invoice_meta($invoice); |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | /** |
784 | 784 | * Displays invoice meta. |
785 | 785 | */ |
786 | -function getpaid_invoice_meta( $invoice ) { |
|
786 | +function getpaid_invoice_meta($invoice) { |
|
787 | 787 | |
788 | - $invoice = new WPInv_Invoice( $invoice ); |
|
788 | + $invoice = new WPInv_Invoice($invoice); |
|
789 | 789 | |
790 | 790 | // Ensure that we have an invoice. |
791 | - if ( 0 == $invoice->get_id() ) { |
|
791 | + if (0 == $invoice->get_id()) { |
|
792 | 792 | return; |
793 | 793 | } |
794 | 794 | |
795 | 795 | // Get the invoice meta. |
796 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
796 | + $meta = getpaid_get_invoice_meta($invoice); |
|
797 | 797 | |
798 | 798 | // Display the meta. |
799 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
799 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
800 | 800 | |
801 | 801 | } |
802 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
802 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
803 | 803 | |
804 | 804 | /** |
805 | 805 | * Retrieves the address markup to use on Invoices. |
@@ -811,29 +811,29 @@ discard block |
||
811 | 811 | * @param string $separator How to separate address lines. |
812 | 812 | * @return string |
813 | 813 | */ |
814 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
814 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
815 | 815 | |
816 | 816 | // Retrieve the address markup... |
817 | - $country = empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
818 | - $format = wpinv_get_full_address_format( $country ); |
|
817 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
818 | + $format = wpinv_get_full_address_format($country); |
|
819 | 819 | |
820 | 820 | // ... and the replacements. |
821 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
821 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
822 | 822 | |
823 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
823 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
824 | 824 | |
825 | 825 | // Remove unavailable tags. |
826 | - $formatted_address = preg_replace( '/\{\{\w+\}\}/', '', $formatted_address ); |
|
826 | + $formatted_address = preg_replace('/\{\{\w+\}\}/', '', $formatted_address); |
|
827 | 827 | |
828 | 828 | // Clean up white space. |
829 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
830 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
829 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
830 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
831 | 831 | |
832 | 832 | // Break newlines apart and remove empty lines/trim commas and white space. |
833 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
833 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
834 | 834 | |
835 | 835 | // Add html breaks. |
836 | - $formatted_address = implode( $separator, $formatted_address ); |
|
836 | + $formatted_address = implode($separator, $formatted_address); |
|
837 | 837 | |
838 | 838 | // We're done! |
839 | 839 | return $formatted_address; |
@@ -845,119 +845,119 @@ discard block |
||
845 | 845 | * |
846 | 846 | * @param WPInv_Invoice $invoice |
847 | 847 | */ |
848 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
849 | - if ( ! empty( $invoice ) ) { |
|
850 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
848 | +function wpinv_display_to_address($invoice = 0) { |
|
849 | + if (!empty($invoice)) { |
|
850 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
851 | 851 | } |
852 | 852 | } |
853 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
853 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
854 | 854 | |
855 | 855 | |
856 | 856 | /** |
857 | 857 | * Displays invoice line items. |
858 | 858 | */ |
859 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
859 | +function wpinv_display_line_items($invoice_id = 0) { |
|
860 | 860 | |
861 | 861 | // Prepare the invoice. |
862 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
862 | + $invoice = new WPInv_Invoice($invoice_id); |
|
863 | 863 | |
864 | 864 | // Abort if there is no invoice. |
865 | - if ( 0 == $invoice->get_id() ) { |
|
865 | + if (0 == $invoice->get_id()) { |
|
866 | 866 | return; |
867 | 867 | } |
868 | 868 | |
869 | 869 | // Line item columns. |
870 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
871 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
870 | + $columns = getpaid_invoice_item_columns($invoice); |
|
871 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
872 | 872 | |
873 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
873 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
874 | 874 | } |
875 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
875 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
876 | 876 | |
877 | 877 | /** |
878 | 878 | * Displays invoice subscriptions. |
879 | 879 | * |
880 | 880 | * @param WPInv_Invoice $invoice |
881 | 881 | */ |
882 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
882 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
883 | 883 | |
884 | 884 | // Subscriptions. |
885 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
885 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
886 | 886 | |
887 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
887 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
888 | 888 | return; |
889 | 889 | } |
890 | 890 | |
891 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
891 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
892 | 892 | |
893 | 893 | // Display related subscriptions. |
894 | - if ( is_array( $subscriptions ) ) { |
|
895 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
896 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
894 | + if (is_array($subscriptions)) { |
|
895 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
896 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
897 | 897 | } |
898 | 898 | |
899 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
900 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
901 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
899 | + if ($main_subscription->get_total_payments() > 1) { |
|
900 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
901 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | } |
905 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55 ); |
|
906 | -add_action( 'wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11 ); |
|
905 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 55); |
|
906 | +add_action('wpinv_receipt_end', 'getpaid_display_invoice_subscriptions', 11); |
|
907 | 907 | |
908 | 908 | /** |
909 | 909 | * Displays invoice notices on invoices. |
910 | 910 | */ |
911 | 911 | function wpinv_display_invoice_notice() { |
912 | 912 | |
913 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
914 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
913 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
914 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
915 | 915 | |
916 | - if ( empty( $label ) && empty( $notice ) ) { |
|
916 | + if (empty($label) && empty($notice)) { |
|
917 | 917 | return; |
918 | 918 | } |
919 | 919 | |
920 | 920 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
921 | 921 | |
922 | - if ( ! empty( $label ) ) { |
|
923 | - $label = esc_html( $label ); |
|
922 | + if (!empty($label)) { |
|
923 | + $label = esc_html($label); |
|
924 | 924 | echo "<h5>$label</h5>"; |
925 | 925 | } |
926 | 926 | |
927 | - if ( ! empty( $notice ) ) { |
|
928 | - echo '<small class="form-text text-muted">' . wp_kses_post( wpautop( wptexturize( $notice ) ) ) . '</small>'; |
|
927 | + if (!empty($notice)) { |
|
928 | + echo '<small class="form-text text-muted">' . wp_kses_post(wpautop(wptexturize($notice))) . '</small>'; |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | echo '</div>'; |
932 | 932 | } |
933 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
933 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
934 | 934 | |
935 | 935 | /** |
936 | 936 | * @param WPInv_Invoice $invoice |
937 | 937 | */ |
938 | -function wpinv_display_invoice_notes( $invoice ) { |
|
938 | +function wpinv_display_invoice_notes($invoice) { |
|
939 | 939 | |
940 | 940 | // Retrieve the notes. |
941 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
941 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
942 | 942 | |
943 | 943 | // Abort if we have non. |
944 | - if ( empty( $notes ) ) { |
|
944 | + if (empty($notes)) { |
|
945 | 945 | return; |
946 | 946 | } |
947 | 947 | |
948 | 948 | // Echo the note. |
949 | 949 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
950 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) . '</h2>'; |
|
950 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>'; |
|
951 | 951 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
952 | 952 | |
953 | - foreach ( $notes as $note ) { |
|
954 | - wpinv_get_invoice_note_line_item( $note ); |
|
953 | + foreach ($notes as $note) { |
|
954 | + wpinv_get_invoice_note_line_item($note); |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | echo '</ul>'; |
958 | 958 | echo '</div>'; |
959 | 959 | } |
960 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
960 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
961 | 961 | |
962 | 962 | /** |
963 | 963 | * Loads scripts on our invoice templates. |
@@ -965,32 +965,32 @@ discard block |
||
965 | 965 | function wpinv_display_style() { |
966 | 966 | |
967 | 967 | // Make sure that all scripts have been loaded. |
968 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
969 | - do_action( 'wp_enqueue_scripts' ); |
|
968 | + if (!did_action('wp_enqueue_scripts')) { |
|
969 | + do_action('wp_enqueue_scripts'); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | // Register the invoices style. |
973 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
973 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
974 | 974 | |
975 | 975 | // Load required styles |
976 | - wp_print_styles( 'wpinv-single-style' ); |
|
977 | - wp_print_styles( 'ayecode-ui' ); |
|
976 | + wp_print_styles('wpinv-single-style'); |
|
977 | + wp_print_styles('ayecode-ui'); |
|
978 | 978 | |
979 | 979 | // Maybe load custom css. |
980 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
980 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
981 | 981 | |
982 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
983 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
984 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
982 | + if (isset($custom_css) && !empty($custom_css)) { |
|
983 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
984 | + $custom_css = str_replace('>', '>', $custom_css); |
|
985 | 985 | echo '<style type="text/css">'; |
986 | - echo wp_kses_post( $custom_css ); |
|
986 | + echo wp_kses_post($custom_css); |
|
987 | 987 | echo '</style>'; |
988 | 988 | } |
989 | 989 | |
990 | 990 | wp_site_icon(); |
991 | 991 | } |
992 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
993 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
992 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
993 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
994 | 994 | |
995 | 995 | |
996 | 996 | /** |
@@ -1002,41 +1002,41 @@ discard block |
||
1002 | 1002 | // Retrieve the current invoice. |
1003 | 1003 | $invoice_id = getpaid_get_current_invoice_id(); |
1004 | 1004 | |
1005 | - if ( empty( $invoice_id ) ) { |
|
1005 | + if (empty($invoice_id)) { |
|
1006 | 1006 | |
1007 | 1007 | return aui()->alert( |
1008 | 1008 | array( |
1009 | 1009 | 'type' => 'warning', |
1010 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1010 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1011 | 1011 | ) |
1012 | 1012 | ); |
1013 | 1013 | |
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | // Can the user view this invoice? |
1017 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1017 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1018 | 1018 | |
1019 | 1019 | return aui()->alert( |
1020 | 1020 | array( |
1021 | 1021 | 'type' => 'warning', |
1022 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1022 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1023 | 1023 | ) |
1024 | 1024 | ); |
1025 | 1025 | |
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | // Ensure that it is not yet paid for. |
1029 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1029 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1030 | 1030 | |
1031 | 1031 | // Maybe mark it as viewed. |
1032 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1032 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1033 | 1033 | |
1034 | - if ( $invoice->is_paid() ) { |
|
1034 | + if ($invoice->is_paid()) { |
|
1035 | 1035 | |
1036 | 1036 | return aui()->alert( |
1037 | 1037 | array( |
1038 | 1038 | 'type' => 'success', |
1039 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1039 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1040 | 1040 | ) |
1041 | 1041 | ); |
1042 | 1042 | |
@@ -1046,15 +1046,15 @@ discard block |
||
1046 | 1046 | $wpi_checkout_id = $invoice_id; |
1047 | 1047 | |
1048 | 1048 | // Retrieve appropriate payment form. |
1049 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
1050 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1049 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
1050 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1051 | 1051 | |
1052 | - if ( ! $payment_form->exists() ) { |
|
1052 | + if (!$payment_form->exists()) { |
|
1053 | 1053 | |
1054 | 1054 | return aui()->alert( |
1055 | 1055 | array( |
1056 | 1056 | 'type' => 'warning', |
1057 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1057 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1058 | 1058 | ) |
1059 | 1059 | ); |
1060 | 1060 | |
@@ -1063,29 +1063,29 @@ discard block |
||
1063 | 1063 | // Set the invoice. |
1064 | 1064 | $payment_form->invoice = $invoice; |
1065 | 1065 | |
1066 | - if ( ! $payment_form->is_default() ) { |
|
1066 | + if (!$payment_form->is_default()) { |
|
1067 | 1067 | |
1068 | 1068 | $items = array(); |
1069 | 1069 | $item_ids = array(); |
1070 | 1070 | |
1071 | - foreach ( $invoice->get_items() as $item ) { |
|
1072 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1071 | + foreach ($invoice->get_items() as $item) { |
|
1072 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1073 | 1073 | $item_ids[] = $item->get_id(); |
1074 | 1074 | $items[] = $item; |
1075 | 1075 | } |
1076 | 1076 | } |
1077 | 1077 | |
1078 | - foreach ( $payment_form->get_items() as $item ) { |
|
1079 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1078 | + foreach ($payment_form->get_items() as $item) { |
|
1079 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1080 | 1080 | $item_ids[] = $item->get_id(); |
1081 | 1081 | $items[] = $item; |
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | |
1085 | - $payment_form->set_items( $items ); |
|
1085 | + $payment_form->set_items($items); |
|
1086 | 1086 | |
1087 | 1087 | } else { |
1088 | - $payment_form->set_items( $invoice->get_items() ); |
|
1088 | + $payment_form->set_items($invoice->get_items()); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | // Generate the html. |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | function wpinv_empty_cart_message() { |
1097 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1097 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | /** |
@@ -1111,76 +1111,76 @@ discard block |
||
1111 | 1111 | ) |
1112 | 1112 | ); |
1113 | 1113 | } |
1114 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1114 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1115 | 1115 | |
1116 | 1116 | /** |
1117 | 1117 | * Filters the receipt page. |
1118 | 1118 | */ |
1119 | -function wpinv_filter_success_page_content( $content ) { |
|
1119 | +function wpinv_filter_success_page_content($content) { |
|
1120 | 1120 | |
1121 | 1121 | // Maybe abort early. |
1122 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
1122 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
1123 | 1123 | return $content; |
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | // Ensure this is our page. |
1127 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1127 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1128 | 1128 | |
1129 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1130 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1129 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1130 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1131 | 1131 | |
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | return $content; |
1135 | 1135 | } |
1136 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1136 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1137 | 1137 | |
1138 | -function wpinv_invoice_link( $invoice_id ) { |
|
1139 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1138 | +function wpinv_invoice_link($invoice_id) { |
|
1139 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1140 | 1140 | |
1141 | - if ( empty( $invoice ) ) { |
|
1141 | + if (empty($invoice)) { |
|
1142 | 1142 | return null; |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1145 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1146 | 1146 | |
1147 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1147 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1148 | 1148 | } |
1149 | 1149 | |
1150 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1151 | - if ( empty( $note ) ) { |
|
1150 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1151 | + if (empty($note)) { |
|
1152 | 1152 | return null; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - if ( is_int( $note ) ) { |
|
1156 | - $note = get_comment( $note ); |
|
1155 | + if (is_int($note)) { |
|
1156 | + $note = get_comment($note); |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | - if ( ! ( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1159 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1160 | 1160 | return null; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | - $note_classes = array( 'note' ); |
|
1164 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1163 | + $note_classes = array('note'); |
|
1164 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1165 | 1165 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1166 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1167 | - $note_classes = ! empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1166 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1167 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1168 | 1168 | |
1169 | 1169 | ob_start(); |
1170 | 1170 | ?> |
1171 | - <li rel="<?php echo absint( $note->comment_ID ); ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1171 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1172 | 1172 | <div class="note_content"> |
1173 | 1173 | |
1174 | - <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?> |
|
1174 | + <?php echo wptexturize(wp_kses_post($note->comment_content)); ?> |
|
1175 | 1175 | |
1176 | - <?php if ( ! is_admin() ) : ?> |
|
1176 | + <?php if (!is_admin()) : ?> |
|
1177 | 1177 | <em class="small form-text text-muted mt-0"> |
1178 | 1178 | <?php |
1179 | 1179 | printf( |
1180 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1180 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1181 | 1181 | $note->comment_author, |
1182 | - getpaid_format_date_value( $note->comment_date ), |
|
1183 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1182 | + getpaid_format_date_value($note->comment_date), |
|
1183 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1184 | 1184 | ); |
1185 | 1185 | ?> |
1186 | 1186 | </em> |
@@ -1188,21 +1188,21 @@ discard block |
||
1188 | 1188 | |
1189 | 1189 | </div> |
1190 | 1190 | |
1191 | - <?php if ( is_admin() ) : ?> |
|
1191 | + <?php if (is_admin()) : ?> |
|
1192 | 1192 | |
1193 | 1193 | <p class="meta px-4 py-2"> |
1194 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1194 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1195 | 1195 | <?php |
1196 | 1196 | printf( |
1197 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1197 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1198 | 1198 | $note->comment_author, |
1199 | - getpaid_format_date_value( $note->comment_date ), |
|
1200 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1199 | + getpaid_format_date_value($note->comment_date), |
|
1200 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1201 | 1201 | ); |
1202 | 1202 | ?> |
1203 | 1203 | </abbr> |
1204 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1205 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1204 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1205 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1206 | 1206 | <?php } ?> |
1207 | 1207 | </p> |
1208 | 1208 | |
@@ -1211,10 +1211,10 @@ discard block |
||
1211 | 1211 | </li> |
1212 | 1212 | <?php |
1213 | 1213 | $note_content = ob_get_clean(); |
1214 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1214 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1215 | 1215 | |
1216 | - if ( $echo ) { |
|
1217 | - echo wp_kses_post( $note_content ); |
|
1216 | + if ($echo) { |
|
1217 | + echo wp_kses_post($note_content); |
|
1218 | 1218 | } else { |
1219 | 1219 | return $note_content; |
1220 | 1220 | } |
@@ -1227,43 +1227,43 @@ discard block |
||
1227 | 1227 | * @return string |
1228 | 1228 | */ |
1229 | 1229 | function wpinv_get_policy_text() { |
1230 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1230 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1231 | 1231 | |
1232 | - $text = wpinv_get_option( 'invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ) ); |
|
1232 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1233 | 1233 | |
1234 | - if ( ! $privacy_page_id ) { |
|
1235 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1234 | + if (!$privacy_page_id) { |
|
1235 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1238 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1239 | 1239 | |
1240 | 1240 | $find_replace = array( |
1241 | 1241 | '[wpinv_privacy_policy]' => $privacy_link, |
1242 | 1242 | ); |
1243 | 1243 | |
1244 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1244 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1245 | 1245 | |
1246 | - return wp_kses_post( wpautop( $privacy_text ) ); |
|
1246 | + return wp_kses_post(wpautop($privacy_text)); |
|
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | function wpinv_oxygen_fix_conflict() { |
1250 | 1250 | global $ct_ignore_post_types; |
1251 | 1251 | |
1252 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1252 | + if (!is_array($ct_ignore_post_types)) { |
|
1253 | 1253 | $ct_ignore_post_types = array(); |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1256 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1257 | 1257 | |
1258 | - foreach ( $post_types as $post_type ) { |
|
1258 | + foreach ($post_types as $post_type) { |
|
1259 | 1259 | $ct_ignore_post_types[] = $post_type; |
1260 | 1260 | |
1261 | 1261 | // Ignore post type |
1262 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1262 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1263 | 1263 | } |
1264 | 1264 | |
1265 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1266 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1265 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1266 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | /** |
@@ -1271,10 +1271,10 @@ discard block |
||
1271 | 1271 | * |
1272 | 1272 | * @param GetPaid_Payment_Form $form |
1273 | 1273 | */ |
1274 | -function getpaid_display_payment_form( $form ) { |
|
1274 | +function getpaid_display_payment_form($form) { |
|
1275 | 1275 | |
1276 | - if ( is_numeric( $form ) ) { |
|
1277 | - $form = new GetPaid_Payment_Form( $form ); |
|
1276 | + if (is_numeric($form)) { |
|
1277 | + $form = new GetPaid_Payment_Form($form); |
|
1278 | 1278 | } |
1279 | 1279 | |
1280 | 1280 | $form->display(); |
@@ -1284,58 +1284,58 @@ discard block |
||
1284 | 1284 | /** |
1285 | 1285 | * Helper function to display a item payment form on the frontend. |
1286 | 1286 | */ |
1287 | -function getpaid_display_item_payment_form( $items ) { |
|
1287 | +function getpaid_display_item_payment_form($items) { |
|
1288 | 1288 | |
1289 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1290 | - $form->set_items( $items ); |
|
1289 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1290 | + $form->set_items($items); |
|
1291 | 1291 | |
1292 | - if ( 0 == count( $form->get_items() ) ) { |
|
1292 | + if (0 == count($form->get_items())) { |
|
1293 | 1293 | echo aui()->alert( |
1294 | 1294 | array( |
1295 | 1295 | 'type' => 'warning', |
1296 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1296 | + 'content' => __('No published items found', 'invoicing'), |
|
1297 | 1297 | ) |
1298 | 1298 | ); |
1299 | 1299 | return; |
1300 | 1300 | } |
1301 | 1301 | |
1302 | - $extra_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1303 | - $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items ); |
|
1302 | + $extra_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1303 | + $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items); |
|
1304 | 1304 | $extra_items = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />"; |
1305 | 1305 | $extra_items .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />"; |
1306 | 1306 | |
1307 | - $form->display( $extra_items ); |
|
1307 | + $form->display($extra_items); |
|
1308 | 1308 | } |
1309 | 1309 | |
1310 | 1310 | /** |
1311 | 1311 | * Helper function to display an invoice payment form on the frontend. |
1312 | 1312 | */ |
1313 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1313 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1314 | 1314 | |
1315 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1315 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1316 | 1316 | |
1317 | - if ( empty( $invoice ) ) { |
|
1317 | + if (empty($invoice)) { |
|
1318 | 1318 | echo aui()->alert( |
1319 | 1319 | array( |
1320 | 1320 | 'type' => 'warning', |
1321 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1321 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1322 | 1322 | ) |
1323 | 1323 | ); |
1324 | 1324 | return; |
1325 | 1325 | } |
1326 | 1326 | |
1327 | - if ( $invoice->is_paid() ) { |
|
1327 | + if ($invoice->is_paid()) { |
|
1328 | 1328 | echo aui()->alert( |
1329 | 1329 | array( |
1330 | 1330 | 'type' => 'warning', |
1331 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1331 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1332 | 1332 | ) |
1333 | 1333 | ); |
1334 | 1334 | return; |
1335 | 1335 | } |
1336 | 1336 | |
1337 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1338 | - $form->set_items( $invoice->get_items() ); |
|
1337 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1338 | + $form->set_items($invoice->get_items()); |
|
1339 | 1339 | |
1340 | 1340 | $form->display(); |
1341 | 1341 | } |
@@ -1343,23 +1343,23 @@ discard block |
||
1343 | 1343 | /** |
1344 | 1344 | * Helper function to convert item string to array. |
1345 | 1345 | */ |
1346 | -function getpaid_convert_items_to_array( $items ) { |
|
1347 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1346 | +function getpaid_convert_items_to_array($items) { |
|
1347 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1348 | 1348 | $prepared = array(); |
1349 | 1349 | |
1350 | - foreach ( $items as $item ) { |
|
1351 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1350 | + foreach ($items as $item) { |
|
1351 | + $data = array_map('trim', explode('|', $item)); |
|
1352 | 1352 | |
1353 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1353 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1354 | 1354 | continue; |
1355 | 1355 | } |
1356 | 1356 | |
1357 | 1357 | $quantity = 1; |
1358 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1358 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1359 | 1359 | $quantity = (float) $data[1]; |
1360 | 1360 | } |
1361 | 1361 | |
1362 | - $prepared[ $data[0] ] = $quantity; |
|
1362 | + $prepared[$data[0]] = $quantity; |
|
1363 | 1363 | |
1364 | 1364 | } |
1365 | 1365 | |
@@ -1369,13 +1369,13 @@ discard block |
||
1369 | 1369 | /** |
1370 | 1370 | * Helper function to convert item array to string. |
1371 | 1371 | */ |
1372 | -function getpaid_convert_items_to_string( $items ) { |
|
1372 | +function getpaid_convert_items_to_string($items) { |
|
1373 | 1373 | $prepared = array(); |
1374 | 1374 | |
1375 | - foreach ( $items as $item => $quantity ) { |
|
1375 | + foreach ($items as $item => $quantity) { |
|
1376 | 1376 | $prepared[] = "$item|$quantity"; |
1377 | 1377 | } |
1378 | - return implode( ',', $prepared ); |
|
1378 | + return implode(',', $prepared); |
|
1379 | 1379 | } |
1380 | 1380 | |
1381 | 1381 | /** |
@@ -1383,21 +1383,21 @@ discard block |
||
1383 | 1383 | * |
1384 | 1384 | * Provide a label and one of $form, $items or $invoice. |
1385 | 1385 | */ |
1386 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1387 | - $label = sanitize_text_field( $label ); |
|
1386 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1387 | + $label = sanitize_text_field($label); |
|
1388 | 1388 | |
1389 | - if ( ! empty( $form ) ) { |
|
1390 | - $form = esc_attr( $form ); |
|
1389 | + if (!empty($form)) { |
|
1390 | + $form = esc_attr($form); |
|
1391 | 1391 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - if ( ! empty( $items ) ) { |
|
1395 | - $items = esc_attr( $items ); |
|
1394 | + if (!empty($items)) { |
|
1395 | + $items = esc_attr($items); |
|
1396 | 1396 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1397 | 1397 | } |
1398 | 1398 | |
1399 | - if ( ! empty( $invoice ) ) { |
|
1400 | - $invoice = esc_attr( $invoice ); |
|
1399 | + if (!empty($invoice)) { |
|
1400 | + $invoice = esc_attr($invoice); |
|
1401 | 1401 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1402 | 1402 | } |
1403 | 1403 | |
@@ -1408,18 +1408,18 @@ discard block |
||
1408 | 1408 | * |
1409 | 1409 | * @param WPInv_Invoice $invoice |
1410 | 1410 | */ |
1411 | -function getpaid_the_invoice_description( $invoice ) { |
|
1411 | +function getpaid_the_invoice_description($invoice) { |
|
1412 | 1412 | $description = $invoice->get_description(); |
1413 | 1413 | |
1414 | - if ( empty( $description ) ) { |
|
1414 | + if (empty($description)) { |
|
1415 | 1415 | return; |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - $description = wp_kses_post( wpautop( $description ) ); |
|
1418 | + $description = wp_kses_post(wpautop($description)); |
|
1419 | 1419 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>"; |
1420 | 1420 | } |
1421 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1422 | -add_action( 'wpinv_email_billing_details', 'getpaid_the_invoice_description', 100 ); |
|
1421 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1422 | +add_action('wpinv_email_billing_details', 'getpaid_the_invoice_description', 100); |
|
1423 | 1423 | |
1424 | 1424 | /** |
1425 | 1425 | * Render element on a form. |
@@ -1427,60 +1427,60 @@ discard block |
||
1427 | 1427 | * @param array $element |
1428 | 1428 | * @param GetPaid_Payment_Form $form |
1429 | 1429 | */ |
1430 | -function getpaid_payment_form_element( $element, $form ) { |
|
1430 | +function getpaid_payment_form_element($element, $form) { |
|
1431 | 1431 | |
1432 | 1432 | // Set up the args. |
1433 | - $element_type = trim( $element['type'] ); |
|
1433 | + $element_type = trim($element['type']); |
|
1434 | 1434 | $element['form'] = $form; |
1435 | - extract( $element ); |
|
1435 | + extract($element); |
|
1436 | 1436 | |
1437 | 1437 | // Try to locate the appropriate template. |
1438 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1438 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1439 | 1439 | |
1440 | 1440 | // Abort if this is not our element. |
1441 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1441 | + if (empty($located) || !file_exists($located)) { |
|
1442 | 1442 | return; |
1443 | 1443 | } |
1444 | 1444 | |
1445 | 1445 | // Generate the class and id of the element. |
1446 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1447 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1446 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1447 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1448 | 1448 | |
1449 | 1449 | // Echo the opening wrapper. |
1450 | 1450 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1451 | 1451 | |
1452 | 1452 | // Fires before displaying a given element type's content. |
1453 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1453 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1454 | 1454 | |
1455 | 1455 | // Include the template for the element. |
1456 | 1456 | include $located; |
1457 | 1457 | |
1458 | 1458 | // Fires after displaying a given element type's content. |
1459 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1459 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1460 | 1460 | |
1461 | 1461 | // Echo the closing wrapper. |
1462 | 1462 | echo '</div>'; |
1463 | 1463 | } |
1464 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1464 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1465 | 1465 | |
1466 | 1466 | /** |
1467 | 1467 | * Render an element's edit page. |
1468 | 1468 | * |
1469 | 1469 | * @param WP_Post $post |
1470 | 1470 | */ |
1471 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1471 | +function getpaid_payment_form_edit_element_template($post) { |
|
1472 | 1472 | |
1473 | 1473 | // Retrieve all elements. |
1474 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1474 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1475 | 1475 | |
1476 | - foreach ( $all_elements as $element ) { |
|
1476 | + foreach ($all_elements as $element) { |
|
1477 | 1477 | |
1478 | 1478 | // Try to locate the appropriate template. |
1479 | - $element = esc_attr( sanitize_key( $element ) ); |
|
1480 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1479 | + $element = esc_attr(sanitize_key($element)); |
|
1480 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1481 | 1481 | |
1482 | 1482 | // Continue if this is not our element. |
1483 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1483 | + if (empty($located) || !file_exists($located)) { |
|
1484 | 1484 | continue; |
1485 | 1485 | } |
1486 | 1486 | |
@@ -1491,7 +1491,7 @@ discard block |
||
1491 | 1491 | } |
1492 | 1492 | |
1493 | 1493 | } |
1494 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1494 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1495 | 1495 | |
1496 | 1496 | /** |
1497 | 1497 | * Render an element's preview. |
@@ -1500,16 +1500,16 @@ discard block |
||
1500 | 1500 | function getpaid_payment_form_render_element_preview_template() { |
1501 | 1501 | |
1502 | 1502 | // Retrieve all elements. |
1503 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1503 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1504 | 1504 | |
1505 | - foreach ( $all_elements as $element ) { |
|
1505 | + foreach ($all_elements as $element) { |
|
1506 | 1506 | |
1507 | 1507 | // Try to locate the appropriate template. |
1508 | - $element = sanitize_key( $element ); |
|
1509 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1508 | + $element = sanitize_key($element); |
|
1509 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1510 | 1510 | |
1511 | 1511 | // Continue if this is not our element. |
1512 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1512 | + if (empty($located) || !file_exists($located)) { |
|
1513 | 1513 | continue; |
1514 | 1514 | } |
1515 | 1515 | |
@@ -1520,7 +1520,7 @@ discard block |
||
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | } |
1523 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1523 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1524 | 1524 | |
1525 | 1525 | /** |
1526 | 1526 | * Shows a list of gateways that support recurring payments. |
@@ -1528,17 +1528,17 @@ discard block |
||
1528 | 1528 | function wpinv_get_recurring_gateways_text() { |
1529 | 1529 | $gateways = array(); |
1530 | 1530 | |
1531 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1532 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1533 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1531 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1532 | + if (wpinv_gateway_support_subscription($key)) { |
|
1533 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1534 | 1534 | } |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( empty( $gateways ) ) { |
|
1538 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) . '</span>'; |
|
1537 | + if (empty($gateways)) { |
|
1538 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . '</span>'; |
|
1539 | 1539 | } |
1540 | 1540 | |
1541 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) . '</span>'; |
|
1541 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . '</span>'; |
|
1542 | 1542 | |
1543 | 1543 | } |
1544 | 1544 | |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | * @return GetPaid_Template |
1549 | 1549 | */ |
1550 | 1550 | function getpaid_template() { |
1551 | - return getpaid()->get( 'template' ); |
|
1551 | + return getpaid()->get('template'); |
|
1552 | 1552 | } |
1553 | 1553 | |
1554 | 1554 | /** |
@@ -1557,8 +1557,8 @@ discard block |
||
1557 | 1557 | * @param array args |
1558 | 1558 | * @return string |
1559 | 1559 | */ |
1560 | -function getpaid_paginate_links( $args ) { |
|
1561 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1560 | +function getpaid_paginate_links($args) { |
|
1561 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1562 | 1562 | } |
1563 | 1563 | |
1564 | 1564 | /** |
@@ -1568,22 +1568,22 @@ discard block |
||
1568 | 1568 | * @param string state |
1569 | 1569 | * @return string |
1570 | 1570 | */ |
1571 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) { |
|
1571 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') { |
|
1572 | 1572 | |
1573 | - $states = wpinv_get_country_states( $country ); |
|
1574 | - $uniqid = uniqid( '_' ); |
|
1573 | + $states = wpinv_get_country_states($country); |
|
1574 | + $uniqid = uniqid('_'); |
|
1575 | 1575 | |
1576 | - if ( ! empty( $states ) ) { |
|
1576 | + if (!empty($states)) { |
|
1577 | 1577 | |
1578 | 1578 | return aui()->select( |
1579 | 1579 | array( |
1580 | 1580 | 'options' => $states, |
1581 | - 'name' => esc_attr( $field_name ), |
|
1582 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1583 | - 'value' => sanitize_text_field( $state ), |
|
1581 | + 'name' => esc_attr($field_name), |
|
1582 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1583 | + 'value' => sanitize_text_field($state), |
|
1584 | 1584 | 'placeholder' => $placeholder, |
1585 | 1585 | 'required' => $required, |
1586 | - 'label' => wp_kses_post( $label ), |
|
1586 | + 'label' => wp_kses_post($label), |
|
1587 | 1587 | 'label_type' => 'vertical', |
1588 | 1588 | 'help_text' => $help_text, |
1589 | 1589 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1599,14 +1599,14 @@ discard block |
||
1599 | 1599 | |
1600 | 1600 | return aui()->input( |
1601 | 1601 | array( |
1602 | - 'name' => esc_attr( $field_name ), |
|
1603 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1602 | + 'name' => esc_attr($field_name), |
|
1603 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1604 | 1604 | 'placeholder' => $placeholder, |
1605 | 1605 | 'required' => $required, |
1606 | - 'label' => wp_kses_post( $label ), |
|
1606 | + 'label' => wp_kses_post($label), |
|
1607 | 1607 | 'label_type' => 'vertical', |
1608 | 1608 | 'help_text' => $help_text, |
1609 | - 'value' => sanitize_text_field( $state ), |
|
1609 | + 'value' => sanitize_text_field($state), |
|
1610 | 1610 | 'class' => 'getpaid-address-field wpinv_state', |
1611 | 1611 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1612 | 1612 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1624,16 +1624,16 @@ discard block |
||
1624 | 1624 | * @param array $element |
1625 | 1625 | * @return string |
1626 | 1626 | */ |
1627 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1627 | +function getpaid_get_form_element_grid_class($element) { |
|
1628 | 1628 | |
1629 | 1629 | $class = 'col-12'; |
1630 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1630 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1631 | 1631 | |
1632 | - if ( $width == 'half' ) { |
|
1632 | + if ($width == 'half') { |
|
1633 | 1633 | $class .= ' col-md-6'; |
1634 | 1634 | } |
1635 | 1635 | |
1636 | - if ( $width == 'third' ) { |
|
1636 | + if ($width == 'third') { |
|
1637 | 1637 | $class .= ' col-md-4'; |
1638 | 1638 | } |
1639 | 1639 | |
@@ -1648,15 +1648,15 @@ discard block |
||
1648 | 1648 | * |
1649 | 1649 | * @return string |
1650 | 1650 | */ |
1651 | -function getpaid_embed_url( $payment_form = false, $items = false ) { |
|
1651 | +function getpaid_embed_url($payment_form = false, $items = false) { |
|
1652 | 1652 | |
1653 | 1653 | return add_query_arg( |
1654 | 1654 | array( |
1655 | 1655 | 'getpaid_embed' => 1, |
1656 | - 'form' => $payment_form ? absint( $payment_form ) : false, |
|
1657 | - 'item' => $items ? urlencode( $items ) : false, |
|
1656 | + 'form' => $payment_form ? absint($payment_form) : false, |
|
1657 | + 'item' => $items ? urlencode($items) : false, |
|
1658 | 1658 | ), |
1659 | - home_url( 'index.php' ) |
|
1659 | + home_url('index.php') |
|
1660 | 1660 | ); |
1661 | 1661 | |
1662 | 1662 | } |
@@ -1666,13 +1666,13 @@ discard block |
||
1666 | 1666 | * |
1667 | 1667 | * @return string |
1668 | 1668 | */ |
1669 | -function getpaid_filter_embed_template( $template ) { |
|
1669 | +function getpaid_filter_embed_template($template) { |
|
1670 | 1670 | |
1671 | - if ( isset( $_GET['getpaid_embed'] ) ) { |
|
1672 | - wpinv_get_template( 'payment-forms/embed.php' ); |
|
1671 | + if (isset($_GET['getpaid_embed'])) { |
|
1672 | + wpinv_get_template('payment-forms/embed.php'); |
|
1673 | 1673 | exit; |
1674 | 1674 | } |
1675 | 1675 | |
1676 | 1676 | return $template; |
1677 | 1677 | } |
1678 | -add_filter( 'template_include', 'getpaid_filter_embed_template' ); |
|
1678 | +add_filter('template_include', 'getpaid_filter_embed_template'); |
@@ -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 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * @deprecated |
20 | 20 | */ |
21 | 21 | function wpinv_get_invoice_cart() { |
22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @deprecated |
27 | 27 | */ |
28 | -function wpinv_get_invoice_description( $invoice ) { |
|
29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
28 | +function wpinv_get_invoice_description($invoice) { |
|
29 | + $invoice = new WPInv_Invoice($invoice); |
|
30 | 30 | return $invoice->get_description(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @deprecated |
35 | 35 | */ |
36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
37 | + $invoice = new WPInv_Invoice($invoice); |
|
38 | 38 | return $invoice->get_currency(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @deprecated |
43 | 43 | */ |
44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
44 | +function wpinv_get_payment_user_email($invoice) { |
|
45 | + $invoice = new WPInv_Invoice($invoice); |
|
46 | 46 | return $invoice->get_email(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @deprecated |
51 | 51 | */ |
52 | -function wpinv_get_user_id( $invoice ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
52 | +function wpinv_get_user_id($invoice) { |
|
53 | + $invoice = new WPInv_Invoice($invoice); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @deprecated |
59 | 59 | */ |
60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
61 | + $invoice = new WPInv_Invoice($invoice); |
|
62 | 62 | |
63 | - if ( $return_label ) { |
|
63 | + if ($return_label) { |
|
64 | 64 | return $invoice->get_status_nicename(); |
65 | 65 | } |
66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @deprecated |
72 | 72 | */ |
73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
74 | + $invoice = new WPInv_Invoice($invoice); |
|
75 | 75 | |
76 | - if ( $return_label ) { |
|
76 | + if ($return_label) { |
|
77 | 77 | return $invoice->get_gateway_title(); |
78 | 78 | } |
79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @deprecated |
85 | 85 | */ |
86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
87 | + return wpinv_get_payment_gateway($invoice, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @deprecated |
92 | 92 | */ |
93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
94 | + $invoice = new WPInv_Invoice($invoice); |
|
95 | 95 | return $invoice->get_transaction_id(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @deprecated |
100 | 100 | */ |
101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
103 | - return $invoice->get_meta( $meta_key, $single ); |
|
101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
103 | + return $invoice->get_meta($meta_key, $single); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @deprecated |
108 | 108 | */ |
109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @deprecated |
116 | 116 | */ |
117 | -function wpinv_get_items( $invoice = 0 ) { |
|
118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
117 | +function wpinv_get_items($invoice = 0) { |
|
118 | + $invoice = new WPInv_Invoice($invoice); |
|
119 | 119 | return $invoice->get_items(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @deprecated |
124 | 124 | */ |
125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
125 | +function wpinv_get_fees($invoice = 0) { |
|
126 | + $invoice = new WPInv_Invoice($invoice); |
|
127 | 127 | return $invoice->get_fees(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @deprecated |
132 | 132 | */ |
133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
133 | +function wpinv_get_invoice_ip($invoice) { |
|
134 | + $invoice = new WPInv_Invoice($invoice); |
|
135 | 135 | return $invoice->get_ip(); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @deprecated |
140 | 140 | */ |
141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
141 | +function wpinv_get_invoice_user_info($invoice) { |
|
142 | + $invoice = new WPInv_Invoice($invoice); |
|
143 | 143 | return $invoice->get_user_info(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @deprecated |
148 | 148 | */ |
149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
150 | + $invoice = new WPInv_Invoice($invoice); |
|
151 | 151 | $subtotal = $invoice->get_subtotal(); |
152 | 152 | |
153 | - if ( $currency ) { |
|
154 | - return wpinv_price( $subtotal, $invoice->get_currency() ); |
|
153 | + if ($currency) { |
|
154 | + return wpinv_price($subtotal, $invoice->get_currency()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @deprecated |
162 | 162 | */ |
163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
164 | + $invoice = new WPInv_Invoice($invoice); |
|
165 | 165 | $tax = $invoice->get_total_tax(); |
166 | 166 | |
167 | - if ( $currency ) { |
|
168 | - return wpinv_price( $tax, $invoice->get_currency() ); |
|
167 | + if ($currency) { |
|
168 | + return wpinv_price($tax, $invoice->get_currency()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @deprecated |
176 | 176 | */ |
177 | -function wpinv_discount( $invoice = 0, $currency = false ) { |
|
178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
177 | +function wpinv_discount($invoice = 0, $currency = false) { |
|
178 | + $invoice = new WPInv_Invoice($invoice); |
|
179 | 179 | $discount = $invoice->get_total_discount(); |
180 | 180 | |
181 | - if ( $currency ) { |
|
182 | - return wpinv_price( $discount, $invoice->get_currency() ); |
|
181 | + if ($currency) { |
|
182 | + return wpinv_price($discount, $invoice->get_currency()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @deprecated |
190 | 190 | */ |
191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
191 | +function wpinv_discount_code($invoice = 0) { |
|
192 | + $invoice = new WPInv_Invoice($invoice); |
|
193 | 193 | return $invoice->get_discount_code(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @deprecated |
198 | 198 | */ |
199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice); |
|
201 | 201 | $total = $invoice->get_total(); |
202 | 202 | |
203 | - if ( $currency ) { |
|
204 | - return wpinv_price( $total, $invoice->get_currency() ); |
|
203 | + if ($currency) { |
|
204 | + return wpinv_price($total, $invoice->get_currency()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * @deprecated |
212 | 212 | */ |
213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
214 | + $invoice = new WPInv_Invoice($invoice); |
|
215 | 215 | |
216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
217 | 217 | $date_created = $invoice->get_created_date(); |
218 | 218 | |
219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @deprecated |
224 | 224 | */ |
225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
226 | - wpinv_get_date_created( $invoice, $format ); |
|
225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
226 | + wpinv_get_date_created($invoice, $format); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @deprecated |
231 | 231 | */ |
232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
233 | + $invoice = new WPInv_Invoice($invoice); |
|
234 | 234 | return $invoice->get_vat_number(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @deprecated |
239 | 239 | */ |
240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
241 | + $invoice = new WPInv_Invoice($invoice); |
|
242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @deprecated |
247 | 247 | */ |
248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
248 | +function wpinv_get_payment_key($invoice = 0) { |
|
249 | + $invoice = new WPInv_Invoice($invoice); |
|
250 | 250 | return $invoice->get_key(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @deprecated |
255 | 255 | */ |
256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
257 | + $invoice = new WPInv_Invoice($invoice); |
|
258 | 258 | return $invoice->get_number(); |
259 | 259 | } |
260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * @deprecated |
403 | 403 | */ |
404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
406 | - return $invoice->update_status( $new_status ); |
|
404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
405 | + $invoice = new WPInv_Invoice($invoice); |
|
406 | + return $invoice->update_status($new_status); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * @deprecated |
458 | 458 | */ |
459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
460 | 460 | |
461 | 461 | // Fetch the invoice. |
462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
463 | 463 | |
464 | - if ( 0 == $invoice->get_id() ) { |
|
464 | + if (0 == $invoice->get_id()) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Prepare the transaction id. |
469 | - if ( empty( $transaction_id ) ) { |
|
469 | + if (empty($transaction_id)) { |
|
470 | 470 | $transaction_id = $invoice_id; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Set the transaction id; |
474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
475 | 475 | |
476 | 476 | // Save the invoice. |
477 | 477 | return $invoice->save(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | * @param WPInv_Invoice $invoice |
485 | 485 | * @param string $gateway |
486 | 486 | */ |
487 | -function wpinv_send_to_gateway( $gateway, $invoice ) { |
|
487 | +function wpinv_send_to_gateway($gateway, $invoice) { |
|
488 | 488 | |
489 | 489 | $payment_data = array( |
490 | 490 | 'invoice_id' => $invoice->get_id(), |
491 | 491 | 'items' => $invoice->get_cart_details(), |
492 | - 'cart_discounts' => array( $invoice->get_discount_code() ), |
|
492 | + 'cart_discounts' => array($invoice->get_discount_code()), |
|
493 | 493 | 'fees' => $invoice->get_total_fees(), |
494 | 494 | 'subtotal' => $invoice->get_subtotal(), |
495 | 495 | 'discount' => $invoice->get_total_discount(), |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | 'price' => $invoice->get_total(), |
498 | 498 | 'invoice_key' => $invoice->get_key(), |
499 | 499 | 'user_email' => $invoice->get_email(), |
500 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
500 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
501 | 501 | 'user_info' => $invoice->get_user_info(), |
502 | - 'post_data' => wp_kses_post( wp_unslash( $_POST ) ), |
|
502 | + 'post_data' => wp_kses_post(wp_unslash($_POST)), |
|
503 | 503 | 'cart_details' => $invoice->get_cart_details(), |
504 | 504 | 'gateway' => $gateway, |
505 | 505 | 'card_info' => array(), |
506 | - 'gateway_nonce' => wp_create_nonce( 'wpi-gateway' ), |
|
506 | + 'gateway_nonce' => wp_create_nonce('wpi-gateway'), |
|
507 | 507 | ); |
508 | 508 | |
509 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
509 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | /** |
520 | 520 | * @deprecated |
521 | 521 | */ |
522 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
523 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
524 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
525 | - wp_die( $message, $title, array( 'response' => $status ) ); |
|
522 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
523 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
524 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
525 | + wp_die($message, $title, array('response' => $status)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -640,14 +640,14 @@ discard block |
||
640 | 640 | /** |
641 | 641 | * @deprecated |
642 | 642 | */ |
643 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
644 | - return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display ); |
|
643 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
644 | + return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | 648 | * @deprecated |
649 | 649 | */ |
650 | -function wpinv_clean_invoice_number( $number ) { |
|
650 | +function wpinv_clean_invoice_number($number) { |
|
651 | 651 | return $number; |
652 | 652 | } |
653 | 653 | |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | /** |
853 | 853 | * @deprecated |
854 | 854 | */ |
855 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
855 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
856 | 856 | |
857 | - if ( $echo ) { |
|
858 | - echo wp_kses_post( wpinv_item_price( $item_id ) ); |
|
857 | + if ($echo) { |
|
858 | + echo wp_kses_post(wpinv_item_price($item_id)); |
|
859 | 859 | } else { |
860 | - return wpinv_item_price( $item_id ); |
|
860 | + return wpinv_item_price($item_id); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | } |
@@ -1272,6 +1272,6 @@ discard block |
||
1272 | 1272 | * @return WPInv_Subscription|bool |
1273 | 1273 | * @deprecated |
1274 | 1274 | */ |
1275 | -function wpinv_get_subscription( $invoice ) { |
|
1276 | - return wpinv_get_invoice_subscription( $invoice ); |
|
1275 | +function wpinv_get_subscription($invoice) { |
|
1276 | + return wpinv_get_invoice_subscription($invoice); |
|
1277 | 1277 | } |
@@ -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 | } |