@@ -126,14 +126,14 @@ |
||
126 | 126 | */ |
127 | 127 | function getpaid_doing_it_wrong( $function, $message, $version ) { |
128 | 128 | |
129 | - $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
130 | - |
|
131 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
132 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
133 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
134 | - } else { |
|
135 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
136 | - } |
|
129 | + $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
|
130 | + |
|
131 | + if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
132 | + do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
133 | + error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
134 | + } else { |
|
135 | + _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | } |
139 | 139 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns the errors as html |
@@ -15,35 +15,35 @@ discard block |
||
15 | 15 | * @param bool $wrap whether or not to wrap the errors. |
16 | 16 | * @since 1.0.19 |
17 | 17 | */ |
18 | -function getpaid_get_errors_html( $clear = true, $wrap = true ) { |
|
18 | +function getpaid_get_errors_html($clear = true, $wrap = true) { |
|
19 | 19 | |
20 | 20 | $errors = ''; |
21 | - foreach ( wpinv_get_errors() as $id => $error ) { |
|
22 | - $type = 'error'; |
|
21 | + foreach (wpinv_get_errors() as $id => $error) { |
|
22 | + $type = 'error'; |
|
23 | 23 | |
24 | - if ( is_array( $error ) ) { |
|
24 | + if (is_array($error)) { |
|
25 | 25 | $type = $error['type']; |
26 | 26 | $error = $error['text']; |
27 | 27 | } |
28 | 28 | |
29 | - if ( $wrap ) { |
|
29 | + if ($wrap) { |
|
30 | 30 | |
31 | 31 | $errors .= aui()->alert( |
32 | 32 | array( |
33 | - 'content' => wp_kses_post( $error ), |
|
33 | + 'content' => wp_kses_post($error), |
|
34 | 34 | 'type' => $type, |
35 | 35 | ) |
36 | 36 | ); |
37 | 37 | |
38 | 38 | } else { |
39 | 39 | |
40 | - $id = esc_attr( $id ); |
|
41 | - $error = wp_kses_post( $error ); |
|
40 | + $id = esc_attr($id); |
|
41 | + $error = wp_kses_post($error); |
|
42 | 42 | $errors .= "<div data-code='$id'>$error</div>"; |
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - if ( $clear ) { |
|
46 | + if ($clear) { |
|
47 | 47 | wpinv_clear_errors(); |
48 | 48 | } |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * Prints (then clears) all available errors. |
56 | 56 | */ |
57 | 57 | function wpinv_print_errors() { |
58 | - echo wp_kses_post( getpaid_get_errors_html() ); |
|
58 | + echo wp_kses_post(getpaid_get_errors_html()); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -69,54 +69,54 @@ discard block |
||
69 | 69 | $all_errors = array( |
70 | 70 | 'perm_cancel_subscription' => array( |
71 | 71 | 'type' => 'error', |
72 | - 'text' => __( 'You do not have permission to cancel this subscription', 'invoicing' ), |
|
72 | + 'text' => __('You do not have permission to cancel this subscription', 'invoicing'), |
|
73 | 73 | ), |
74 | 74 | 'cannot_cancel_subscription' => array( |
75 | 75 | 'type' => 'error', |
76 | - 'text' => __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ), |
|
76 | + 'text' => __('This subscription cannot be cancelled as it is not active.', 'invoicing'), |
|
77 | 77 | ), |
78 | 78 | 'cancelled_subscription' => array( |
79 | 79 | 'type' => 'success', |
80 | - 'text' => __( 'Subscription cancelled successfully.', 'invoicing' ), |
|
80 | + 'text' => __('Subscription cancelled successfully.', 'invoicing'), |
|
81 | 81 | ), |
82 | 82 | 'address_updated' => array( |
83 | 83 | 'type' => 'success', |
84 | - 'text' => __( 'Address updated successfully.', 'invoicing' ), |
|
84 | + 'text' => __('Address updated successfully.', 'invoicing'), |
|
85 | 85 | ), |
86 | 86 | 'perm_delete_invoice' => array( |
87 | 87 | 'type' => 'error', |
88 | - 'text' => __( 'You do not have permission to delete this invoice', 'invoicing' ), |
|
88 | + 'text' => __('You do not have permission to delete this invoice', 'invoicing'), |
|
89 | 89 | ), |
90 | 90 | 'cannot_delete_invoice' => array( |
91 | 91 | 'type' => 'error', |
92 | - 'text' => __( 'This invoice cannot be deleted as it has already been paid.', 'invoicing' ), |
|
92 | + 'text' => __('This invoice cannot be deleted as it has already been paid.', 'invoicing'), |
|
93 | 93 | ), |
94 | 94 | 'deleted_invoice' => array( |
95 | 95 | 'type' => 'success', |
96 | - 'text' => __( 'Invoice deleted successfully.', 'invoicing' ), |
|
96 | + 'text' => __('Invoice deleted successfully.', 'invoicing'), |
|
97 | 97 | ), |
98 | 98 | 'card_declined' => array( |
99 | 99 | 'type' => 'error', |
100 | - 'text' => __( 'Your card was declined.', 'invoicing' ), |
|
100 | + 'text' => __('Your card was declined.', 'invoicing'), |
|
101 | 101 | ), |
102 | 102 | 'invalid_currency' => array( |
103 | 103 | 'type' => 'error', |
104 | - 'text' => __( 'The chosen payment gateway does not support this currency.', 'invoicing' ), |
|
104 | + 'text' => __('The chosen payment gateway does not support this currency.', 'invoicing'), |
|
105 | 105 | ), |
106 | 106 | ); |
107 | 107 | |
108 | - $errors = apply_filters( 'wpinv_errors', array() ); |
|
108 | + $errors = apply_filters('wpinv_errors', array()); |
|
109 | 109 | |
110 | - if ( isset( $_GET['wpinv-notice'] ) && isset( $all_errors[ $_GET['wpinv-notice'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
111 | - $errors[ $_GET['wpinv-notice'] ] = $all_errors[ $_GET['wpinv-notice'] ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
110 | + if (isset($_GET['wpinv-notice']) && isset($all_errors[$_GET['wpinv-notice']])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
111 | + $errors[$_GET['wpinv-notice']] = $all_errors[$_GET['wpinv-notice']]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
112 | 112 | } |
113 | 113 | |
114 | - if ( isset( $GLOBALS['wpinv_notice'] ) && isset( $all_errors[ $GLOBALS['wpinv_notice'] ] ) ) { |
|
115 | - $errors[ $GLOBALS['wpinv_notice'] ] = $all_errors[ $GLOBALS['wpinv_notice'] ]; |
|
114 | + if (isset($GLOBALS['wpinv_notice']) && isset($all_errors[$GLOBALS['wpinv_notice']])) { |
|
115 | + $errors[$GLOBALS['wpinv_notice']] = $all_errors[$GLOBALS['wpinv_notice']]; |
|
116 | 116 | } |
117 | 117 | |
118 | - if ( isset( $GLOBALS['wpinv_custom_notice'] ) ) { |
|
119 | - $errors[ $GLOBALS['wpinv_notice']['code'] ] = $GLOBALS['wpinv_custom_notice']; |
|
118 | + if (isset($GLOBALS['wpinv_custom_notice'])) { |
|
119 | + $errors[$GLOBALS['wpinv_notice']['code']] = $GLOBALS['wpinv_custom_notice']; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return $errors; |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * @param string $error The error message. |
130 | 130 | * @param string $type The error type. |
131 | 131 | */ |
132 | -function wpinv_set_error( $error_id, $message = '', $type = 'error' ) { |
|
132 | +function wpinv_set_error($error_id, $message = '', $type = 'error') { |
|
133 | 133 | |
134 | - if ( ! empty( $message ) ) { |
|
134 | + if (!empty($message)) { |
|
135 | 135 | $GLOBALS['wpinv_custom_notice'] = array( |
136 | 136 | 'code' => $error_id, |
137 | 137 | 'type' => $type, |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * |
148 | 148 | */ |
149 | 149 | function wpinv_has_errors() { |
150 | - return count( wpinv_get_errors() ) > 0; |
|
150 | + return count(wpinv_get_errors()) > 0; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | */ |
157 | 157 | function wpinv_clear_errors() { |
158 | - unset( $GLOBALS['wpinv_notice'] ); |
|
158 | + unset($GLOBALS['wpinv_notice']); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | */ |
165 | 165 | function wpinv_unset_error() { |
166 | - unset( $GLOBALS['wpinv_notice'] ); |
|
166 | + unset($GLOBALS['wpinv_notice']); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | * @param string $message Message to log. |
175 | 175 | * @param string $version Version the message was added in. |
176 | 176 | */ |
177 | -function getpaid_doing_it_wrong( $function, $message, $version ) { |
|
177 | +function getpaid_doing_it_wrong($function, $message, $version) { |
|
178 | 178 | |
179 | 179 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
180 | 180 | |
181 | - if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) { |
|
182 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
183 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
181 | + if (wp_doing_ajax() || defined('REST_REQUEST')) { |
|
182 | + do_action('doing_it_wrong_run', $function, $message, $version); |
|
183 | + error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); |
|
184 | 184 | } else { |
185 | - _doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) ); |
|
185 | + _doing_it_wrong(esc_html($function), wp_kses_post($message), esc_html($version)); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
@@ -196,41 +196,41 @@ discard block |
||
196 | 196 | * @param string $line The line that contains the error. |
197 | 197 | * @param bool $exit Whether or not to exit function execution. |
198 | 198 | */ |
199 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
199 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
200 | 200 | |
201 | - if ( true === apply_filters( 'wpinv_log_errors', true ) ) { |
|
201 | + if (true === apply_filters('wpinv_log_errors', true)) { |
|
202 | 202 | |
203 | 203 | // Ensure the log is a scalar. |
204 | - if ( ! is_scalar( $log ) ) { |
|
205 | - $log = print_r( $log, true ); |
|
204 | + if (!is_scalar($log)) { |
|
205 | + $log = print_r($log, true); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // Add title. |
209 | - if ( ! empty( $title ) ) { |
|
210 | - $log = $title . ' ' . trim( $log ); |
|
209 | + if (!empty($title)) { |
|
210 | + $log = $title . ' ' . trim($log); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // Add the file to the label. |
214 | - if ( ! empty( $file ) ) { |
|
214 | + if (!empty($file)) { |
|
215 | 215 | $log .= ' in ' . $file; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Add the line number to the label. |
219 | - if ( ! empty( $line ) ) { |
|
219 | + if (!empty($line)) { |
|
220 | 220 | $log .= ' on line ' . $line; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Log the message. |
224 | - error_log( trim( $log ) ); |
|
224 | + error_log(trim($log)); |
|
225 | 225 | |
226 | 226 | // ... and a backtrace. |
227 | - if ( false !== $title && false !== $file ) { |
|
228 | - error_log( 'Backtrace ' . wp_debug_backtrace_summary() ); |
|
227 | + if (false !== $title && false !== $file) { |
|
228 | + error_log('Backtrace ' . wp_debug_backtrace_summary()); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | // Maybe exit. |
233 | - if ( $exit ) { |
|
233 | + if ($exit) { |
|
234 | 234 | exit; |
235 | 235 | } |
236 | 236 |
@@ -12,49 +12,49 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | - |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Registers the reports page. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function register_reports_page() { |
|
33 | - |
|
34 | - add_submenu_page( |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | + add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | + |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Registers the reports page. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function register_reports_page() { |
|
33 | + |
|
34 | + add_submenu_page( |
|
35 | 35 | 'wpinv', |
36 | 36 | __( 'Reports', 'invoicing' ), |
37 | 37 | __( 'Reports', 'invoicing' ), |
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | 40 | array( $this, 'display_reports_page' ) |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Displays the reports page. |
|
47 | - * |
|
48 | - */ |
|
49 | - public function display_reports_page() { |
|
45 | + /** |
|
46 | + * Displays the reports page. |
|
47 | + * |
|
48 | + */ |
|
49 | + public function display_reports_page() { |
|
50 | 50 | |
51 | - // Prepare variables. |
|
52 | - $tabs = $this->get_tabs(); |
|
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
51 | + // Prepare variables. |
|
52 | + $tabs = $this->get_tabs(); |
|
53 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | - // Display the current tab. |
|
57 | - ?> |
|
56 | + // Display the current tab. |
|
57 | + ?> |
|
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach ( $tabs as $key => $label ) { |
|
66 | + foreach ( $tabs as $key => $label ) { |
|
67 | 67 | |
68 | - $key = sanitize_key( $key ); |
|
69 | - $label = esc_html( $label ); |
|
70 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | - $url = esc_url( |
|
68 | + $key = sanitize_key( $key ); |
|
69 | + $label = esc_html( $label ); |
|
70 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | + $url = esc_url( |
|
72 | 72 | add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
73 | 73 | ); |
74 | 74 | |
75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
75 | + echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
76 | 76 | |
77 | - } |
|
78 | - ?> |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
@@ -86,82 +86,82 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | - // Wordfence loads an unsupported version of chart js on our page. |
|
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
89 | + // Wordfence loads an unsupported version of chart js on our page. |
|
90 | + wp_deregister_style( 'chart-js' ); |
|
91 | + wp_deregister_script( 'chart-js' ); |
|
92 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Retrieves reports page tabs. |
|
98 | - * |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function get_tabs() { |
|
96 | + /** |
|
97 | + * Retrieves reports page tabs. |
|
98 | + * |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function get_tabs() { |
|
102 | 102 | |
103 | - $tabs = array( |
|
104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | - 'export' => __( 'Export', 'invoicing' ), |
|
106 | - ); |
|
103 | + $tabs = array( |
|
104 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | + 'export' => __( 'Export', 'invoicing' ), |
|
106 | + ); |
|
107 | 107 | |
108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
109 | - } |
|
108 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Displays the reports tab. |
|
113 | - * |
|
114 | - */ |
|
115 | - public function display_reports_tab() { |
|
111 | + /** |
|
112 | + * Displays the reports tab. |
|
113 | + * |
|
114 | + */ |
|
115 | + public function display_reports_tab() { |
|
116 | 116 | |
117 | - $reports = new GetPaid_Reports_Report(); |
|
118 | - $reports->display(); |
|
117 | + $reports = new GetPaid_Reports_Report(); |
|
118 | + $reports->display(); |
|
119 | 119 | |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Displays the exports tab. |
|
124 | - * |
|
125 | - */ |
|
126 | - public function display_exports_tab() { |
|
122 | + /** |
|
123 | + * Displays the exports tab. |
|
124 | + * |
|
125 | + */ |
|
126 | + public function display_exports_tab() { |
|
127 | 127 | |
128 | - $exports = new GetPaid_Reports_Export(); |
|
129 | - $exports->display(); |
|
128 | + $exports = new GetPaid_Reports_Export(); |
|
129 | + $exports->display(); |
|
130 | 130 | |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Donwnloads a graph. |
|
135 | - * |
|
136 | - * @param array $args |
|
137 | - */ |
|
138 | - public function download_graph( $args ) { |
|
133 | + /** |
|
134 | + * Donwnloads a graph. |
|
135 | + * |
|
136 | + * @param array $args |
|
137 | + */ |
|
138 | + public function download_graph( $args ) { |
|
139 | 139 | |
140 | - if ( ! empty( $args['graph'] ) ) { |
|
141 | - $downloader = new GetPaid_Graph_Downloader(); |
|
142 | - $downloader->download( $args['graph'] ); |
|
143 | - } |
|
140 | + if ( ! empty( $args['graph'] ) ) { |
|
141 | + $downloader = new GetPaid_Graph_Downloader(); |
|
142 | + $downloader->download( $args['graph'] ); |
|
143 | + } |
|
144 | 144 | |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Exports invoices. |
|
149 | - * |
|
150 | - * @param array $args |
|
151 | - */ |
|
152 | - public function export_invoices( $args ) { |
|
147 | + /** |
|
148 | + * Exports invoices. |
|
149 | + * |
|
150 | + * @param array $args |
|
151 | + */ |
|
152 | + public function export_invoices( $args ) { |
|
153 | 153 | |
154 | - if ( ! empty( $args['post_type'] ) ) { |
|
154 | + if ( ! empty( $args['post_type'] ) ) { |
|
155 | 155 | |
156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
157 | - $downloader = new GetPaid_Subscription_Exporter(); |
|
158 | - } else { |
|
159 | - $downloader = new GetPaid_Invoice_Exporter(); |
|
160 | - } |
|
156 | + if ( 'subscriptions' === $args['post_type'] ) { |
|
157 | + $downloader = new GetPaid_Subscription_Exporter(); |
|
158 | + } else { |
|
159 | + $downloader = new GetPaid_Invoice_Exporter(); |
|
160 | + } |
|
161 | 161 | |
162 | - $downloader->export( $args['post_type'], $args ); |
|
163 | - } |
|
162 | + $downloader->export( $args['post_type'], $args ); |
|
163 | + } |
|
164 | 164 | |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | 167 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports Class. |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | + add_action('getpaid_authenticated_admin_action_export_invoices', array($this, 'export_invoices')); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | |
34 | 34 | add_submenu_page( |
35 | 35 | 'wpinv', |
36 | - __( 'Reports', 'invoicing' ), |
|
37 | - __( 'Reports', 'invoicing' ), |
|
36 | + __('Reports', 'invoicing'), |
|
37 | + __('Reports', 'invoicing'), |
|
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | - array( $this, 'display_reports_page' ) |
|
40 | + array($this, 'display_reports_page') |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |
@@ -50,46 +50,46 @@ discard block |
||
50 | 50 | |
51 | 51 | // Prepare variables. |
52 | 52 | $tabs = $this->get_tabs(); |
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
53 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
54 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | 56 | // Display the current tab. |
57 | 57 | ?> |
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
61 | - <h1><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1> |
|
61 | + <h1><?php echo esc_html($tabs[$current_tab]); ?></h1> |
|
62 | 62 | |
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach ( $tabs as $key => $label ) { |
|
66 | + foreach ($tabs as $key => $label) { |
|
67 | 67 | |
68 | - $key = sanitize_key( $key ); |
|
69 | - $label = esc_html( $label ); |
|
68 | + $key = sanitize_key($key); |
|
69 | + $label = esc_html($label); |
|
70 | 70 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
71 | 71 | $url = esc_url( |
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
72 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
73 | 73 | ); |
74 | 74 | |
75 | - echo wp_kses_post( "\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>" ); |
|
75 | + echo wp_kses_post("\n\t\t\t<a href='$url' class='" . $class . "'>$label</a>"); |
|
76 | 76 | |
77 | 77 | } |
78 | 78 | ?> |
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
82 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
83 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
82 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
83 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | 89 | // Wordfence loads an unsupported version of chart js on our page. |
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array( 'jquery' ), '3.7.1', true ); |
|
90 | + wp_deregister_style('chart-js'); |
|
91 | + wp_deregister_script('chart-js'); |
|
92 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.min.js', array('jquery'), '3.7.1', true); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | public function get_tabs() { |
102 | 102 | |
103 | 103 | $tabs = array( |
104 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
105 | - 'export' => __( 'Export', 'invoicing' ), |
|
104 | + 'reports' => __('Reports', 'invoicing'), |
|
105 | + 'export' => __('Export', 'invoicing'), |
|
106 | 106 | ); |
107 | 107 | |
108 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
108 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $args |
137 | 137 | */ |
138 | - public function download_graph( $args ) { |
|
138 | + public function download_graph($args) { |
|
139 | 139 | |
140 | - if ( ! empty( $args['graph'] ) ) { |
|
140 | + if (!empty($args['graph'])) { |
|
141 | 141 | $downloader = new GetPaid_Graph_Downloader(); |
142 | - $downloader->download( $args['graph'] ); |
|
142 | + $downloader->download($args['graph']); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | } |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param array $args |
151 | 151 | */ |
152 | - public function export_invoices( $args ) { |
|
152 | + public function export_invoices($args) { |
|
153 | 153 | |
154 | - if ( ! empty( $args['post_type'] ) ) { |
|
154 | + if (!empty($args['post_type'])) { |
|
155 | 155 | |
156 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
156 | + if ('subscriptions' === $args['post_type']) { |
|
157 | 157 | $downloader = new GetPaid_Subscription_Exporter(); |
158 | 158 | } else { |
159 | 159 | $downloader = new GetPaid_Invoice_Exporter(); |
160 | 160 | } |
161 | 161 | |
162 | - $downloader->export( $args['post_type'], $args ); |
|
162 | + $downloader->export($args['post_type'], $args); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
@@ -12,218 +12,218 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Reports_Report |
|
17 | - */ |
|
18 | - public $handler; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->handler = new GetPaid_Reports_Report(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Prepares the datastore handler. |
|
30 | - * |
|
31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | - */ |
|
33 | - public function prepare_handler( $graph ) { |
|
34 | - |
|
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | - } |
|
38 | - |
|
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Prepares the output stream. |
|
45 | - * |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function prepare_output() { |
|
49 | - |
|
50 | - $output = fopen( 'php://output', 'w' ); |
|
51 | - |
|
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | - } |
|
55 | - |
|
56 | - return $output; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Prepares the file type. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function prepare_file_type( $graph ) { |
|
65 | - |
|
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | - |
|
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | - |
|
72 | - return $file_type; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Handles the actual download. |
|
77 | - * |
|
78 | - */ |
|
79 | - public function download( $graph ) { |
|
80 | - global $wpdb; |
|
81 | - |
|
82 | - $handler = $this->prepare_handler( $graph ); |
|
83 | - $stream = $this->prepare_output(); |
|
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
92 | - } else { |
|
93 | - $this->download_json( $stats, $stream, $headers ); |
|
94 | - } |
|
95 | - |
|
96 | - fclose( $stream ); |
|
97 | - exit; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Downloads graph as csv |
|
102 | - * |
|
103 | - * @param array $stats The stats being downloaded. |
|
104 | - * @param resource $stream The stream to output to. |
|
105 | - * @param array $headers The fields to stream. |
|
106 | - * @since 1.0.19 |
|
107 | - */ |
|
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
109 | - |
|
110 | - // Output the csv column headers. |
|
111 | - fputcsv( $stream, $headers ); |
|
112 | - |
|
113 | - // Loop through |
|
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
118 | - } |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Downloads graph as json |
|
124 | - * |
|
125 | - * @param array $stats The stats being downloaded. |
|
126 | - * @param resource $stream The stream to output to. |
|
127 | - * @param array $headers The fields to stream. |
|
128 | - * @since 1.0.19 |
|
129 | - */ |
|
130 | - public function download_json( $stats, $stream, $headers ) { |
|
131 | - |
|
132 | - $prepared = array(); |
|
133 | - |
|
134 | - // Loop through |
|
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | - } |
|
138 | - |
|
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Downloads graph as xml |
|
145 | - * |
|
146 | - * @param array $stats The stats being downloaded. |
|
147 | - * @param resource $stream The stream to output to. |
|
148 | - * @param array $headers The fields to stream. |
|
149 | - * @since 1.0.19 |
|
150 | - */ |
|
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
152 | - |
|
153 | - $prepared = array(); |
|
154 | - |
|
155 | - // Loop through |
|
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | - } |
|
159 | - |
|
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
162 | - |
|
163 | - fwrite( $stream, $xml->asXML() ); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Converts stats array to xml |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @since 1.0.19 |
|
172 | - */ |
|
173 | - public function convert_array_xml( $data, $xml ) { |
|
174 | - |
|
175 | - // Loop through |
|
176 | - foreach ( $data as $key => $value ) { |
|
177 | - |
|
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | - |
|
180 | - if ( is_array( $value ) ) { |
|
181 | - |
|
182 | - if ( is_numeric( $key ) ) { |
|
183 | - $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | - } |
|
185 | - |
|
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
188 | - |
|
189 | - } else { |
|
190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
191 | - } |
|
15 | + /** |
|
16 | + * @var GetPaid_Reports_Report |
|
17 | + */ |
|
18 | + public $handler; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->handler = new GetPaid_Reports_Report(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Prepares the datastore handler. |
|
30 | + * |
|
31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | + */ |
|
33 | + public function prepare_handler( $graph ) { |
|
34 | + |
|
35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | + wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | + } |
|
38 | + |
|
39 | + return new $this->handler->views[ $graph ]['class'](); |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Prepares the output stream. |
|
45 | + * |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function prepare_output() { |
|
49 | + |
|
50 | + $output = fopen( 'php://output', 'w' ); |
|
51 | + |
|
52 | + if ( false === $output ) { |
|
53 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | + } |
|
55 | + |
|
56 | + return $output; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Prepares the file type. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function prepare_file_type( $graph ) { |
|
65 | + |
|
66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | + |
|
69 | + header( "Content-Type:application/$file_type" ); |
|
70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | + |
|
72 | + return $file_type; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Handles the actual download. |
|
77 | + * |
|
78 | + */ |
|
79 | + public function download( $graph ) { |
|
80 | + global $wpdb; |
|
81 | + |
|
82 | + $handler = $this->prepare_handler( $graph ); |
|
83 | + $stream = $this->prepare_output(); |
|
84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | + $file_type = $this->prepare_file_type( $graph ); |
|
87 | + |
|
88 | + if ( 'csv' == $file_type ) { |
|
89 | + $this->download_csv( $stats, $stream, $headers ); |
|
90 | + } elseif ( 'xml' == $file_type ) { |
|
91 | + $this->download_xml( $stats, $stream, $headers ); |
|
92 | + } else { |
|
93 | + $this->download_json( $stats, $stream, $headers ); |
|
94 | + } |
|
95 | + |
|
96 | + fclose( $stream ); |
|
97 | + exit; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Downloads graph as csv |
|
102 | + * |
|
103 | + * @param array $stats The stats being downloaded. |
|
104 | + * @param resource $stream The stream to output to. |
|
105 | + * @param array $headers The fields to stream. |
|
106 | + * @since 1.0.19 |
|
107 | + */ |
|
108 | + public function download_csv( $stats, $stream, $headers ) { |
|
109 | + |
|
110 | + // Output the csv column headers. |
|
111 | + fputcsv( $stream, $headers ); |
|
112 | + |
|
113 | + // Loop through |
|
114 | + foreach ( $stats as $stat ) { |
|
115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | + $row = array_map( 'maybe_serialize', $row ); |
|
117 | + fputcsv( $stream, $row ); |
|
118 | + } |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Downloads graph as json |
|
124 | + * |
|
125 | + * @param array $stats The stats being downloaded. |
|
126 | + * @param resource $stream The stream to output to. |
|
127 | + * @param array $headers The fields to stream. |
|
128 | + * @since 1.0.19 |
|
129 | + */ |
|
130 | + public function download_json( $stats, $stream, $headers ) { |
|
131 | + |
|
132 | + $prepared = array(); |
|
133 | + |
|
134 | + // Loop through |
|
135 | + foreach ( $stats as $stat ) { |
|
136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | + } |
|
138 | + |
|
139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Downloads graph as xml |
|
145 | + * |
|
146 | + * @param array $stats The stats being downloaded. |
|
147 | + * @param resource $stream The stream to output to. |
|
148 | + * @param array $headers The fields to stream. |
|
149 | + * @since 1.0.19 |
|
150 | + */ |
|
151 | + public function download_xml( $stats, $stream, $headers ) { |
|
152 | + |
|
153 | + $prepared = array(); |
|
154 | + |
|
155 | + // Loop through |
|
156 | + foreach ( $stats as $stat ) { |
|
157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | + } |
|
159 | + |
|
160 | + $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | + $this->convert_array_xml( $prepared, $xml ); |
|
162 | + |
|
163 | + fwrite( $stream, $xml->asXML() ); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Converts stats array to xml |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @since 1.0.19 |
|
172 | + */ |
|
173 | + public function convert_array_xml( $data, $xml ) { |
|
174 | + |
|
175 | + // Loop through |
|
176 | + foreach ( $data as $key => $value ) { |
|
177 | + |
|
178 | + $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | + |
|
180 | + if ( is_array( $value ) ) { |
|
181 | + |
|
182 | + if ( is_numeric( $key ) ) { |
|
183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | + } |
|
185 | + |
|
186 | + $subnode = $xml->addChild( $key ); |
|
187 | + $this->convert_array_xml( $value, $subnode ); |
|
188 | + |
|
189 | + } else { |
|
190 | + $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Prepares a single row for download. |
|
198 | - * |
|
199 | - * @param stdClass|array $row The row to prepare.. |
|
200 | - * @param array $fields The fields to stream. |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function prepare_row( $row, $fields ) { |
|
196 | + /** |
|
197 | + * Prepares a single row for download. |
|
198 | + * |
|
199 | + * @param stdClass|array $row The row to prepare.. |
|
200 | + * @param array $fields The fields to stream. |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function prepare_row( $row, $fields ) { |
|
205 | 205 | |
206 | - $prepared = array(); |
|
207 | - $row = (array) $row; |
|
206 | + $prepared = array(); |
|
207 | + $row = (array) $row; |
|
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ( $fields as $field ) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | - continue; |
|
214 | - } |
|
211 | + if ( $field === 'total' ) { |
|
212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | + continue; |
|
214 | + } |
|
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | - continue; |
|
219 | - } |
|
216 | + if ( $field === 'total_raw' ) { |
|
217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | + continue; |
|
219 | + } |
|
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
222 | 222 | |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - return $prepared; |
|
226 | - } |
|
225 | + return $prepared; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | 229 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(esc_html__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 83 | $stream = $this->prepare_output(); |
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
86 | + $file_type = $this->prepare_file_type($graph); |
|
87 | + |
|
88 | + if ('csv' == $file_type) { |
|
89 | + $this->download_csv($stats, $stream, $headers); |
|
90 | + } elseif ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + $row = array_map('maybe_serialize', $row); |
|
117 | + fputcsv($stream, $row); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $headers The fields to stream. |
128 | 128 | * @since 1.0.19 |
129 | 129 | */ |
130 | - public function download_json( $stats, $stream, $headers ) { |
|
130 | + public function download_json($stats, $stream, $headers) { |
|
131 | 131 | |
132 | 132 | $prepared = array(); |
133 | 133 | |
134 | 134 | // Loop through |
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
135 | + foreach ($stats as $stat) { |
|
136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
137 | 137 | } |
138 | 138 | |
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
139 | + fwrite($stream, wp_json_encode($prepared)); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @param array $headers The fields to stream. |
149 | 149 | * @since 1.0.19 |
150 | 150 | */ |
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
151 | + public function download_xml($stats, $stream, $headers) { |
|
152 | 152 | |
153 | 153 | $prepared = array(); |
154 | 154 | |
155 | 155 | // Loop through |
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
156 | + foreach ($stats as $stat) { |
|
157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
158 | 158 | } |
159 | 159 | |
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
161 | + $this->convert_array_xml($prepared, $xml); |
|
162 | 162 | |
163 | - fwrite( $stream, $xml->asXML() ); |
|
163 | + fwrite($stream, $xml->asXML()); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * @access public |
171 | 171 | * @since 1.0.19 |
172 | 172 | */ |
173 | - public function convert_array_xml( $data, $xml ) { |
|
173 | + public function convert_array_xml($data, $xml) { |
|
174 | 174 | |
175 | 175 | // Loop through |
176 | - foreach ( $data as $key => $value ) { |
|
176 | + foreach ($data as $key => $value) { |
|
177 | 177 | |
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
178 | + $key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key); |
|
179 | 179 | |
180 | - if ( is_array( $value ) ) { |
|
180 | + if (is_array($value)) { |
|
181 | 181 | |
182 | - if ( is_numeric( $key ) ) { |
|
182 | + if (is_numeric($key)) { |
|
183 | 183 | $key = 'item' . $key; //dealing with <0/>..<n/> issues |
184 | 184 | } |
185 | 185 | |
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
186 | + $subnode = $xml->addChild($key); |
|
187 | + $this->convert_array_xml($value, $subnode); |
|
188 | 188 | |
189 | 189 | } else { |
190 | - $xml->addChild( $key, htmlspecialchars( $value ) ); |
|
190 | + $xml->addChild($key, htmlspecialchars($value)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 207 | $row = (array) $row; |
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ($fields as $field) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | <?php if ( $tabs ) { ?> |
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
19 | - } |
|
20 | - do_action( 'wpi_addons_tabs' ); |
|
21 | - ?> |
|
17 | + foreach ( $tabs as $name => $label ) { |
|
18 | + echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
19 | + } |
|
20 | + do_action( 'wpi_addons_tabs' ); |
|
21 | + ?> |
|
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if ( $current_tab == 'membership' ) { |
|
26 | + if ( $current_tab == 'membership' ) { |
|
27 | 27 | |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div class="wpi-membership-tab-conatiner"> |
31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2> |
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
40 | - echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) ); |
|
41 | - ?> |
|
39 | + $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
40 | + echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) ); |
|
41 | + ?> |
|
42 | 42 | </p> |
43 | 43 | <?php } ?> |
44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
52 | - if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
55 | - } |
|
56 | - } |
|
57 | - ?> |
|
51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
52 | + if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | + foreach ( $addons as $addon ) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
55 | + } |
|
56 | + } |
|
57 | + ?> |
|
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | <h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3> |
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
68 | + if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | + foreach ( $addons as $addon ) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </ul> |
75 | 75 | </div> |
76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
85 | - ?> |
|
84 | + echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
85 | + ?> |
|
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
105 | - ?> |
|
104 | + echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
105 | + ?> |
|
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
108 | 108 | <p> |
@@ -126,26 +126,26 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - } else { |
|
130 | - $installed_plugins = get_plugins(); |
|
129 | + } else { |
|
130 | + $installed_plugins = get_plugins(); |
|
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | - //print_r($addons); |
|
134 | - ?> |
|
132 | + if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | + //print_r($addons); |
|
134 | + ?> |
|
135 | 135 | <ul class="wpi-products"> |
136 | 136 | <?php |
137 | 137 | foreach ( $addons as $addon ) : |
138 | 138 | if ( 965 == $addon->info->id ) { |
139 | 139 | continue;}// don't show quote add on |
140 | - ?> |
|
140 | + ?> |
|
141 | 141 | <li class="wpi-product"> |
142 | 142 | <div class="wpi-product-title"> |
143 | 143 | <h3> |
144 | 144 | <?php |
145 | - if ( ! empty( $addon->info->excerpt ) ) { |
|
146 | - wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
147 | - } |
|
148 | - echo esc_html( $addon->info->title ); |
|
145 | + if ( ! empty( $addon->info->excerpt ) ) { |
|
146 | + wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
147 | + } |
|
148 | + echo esc_html( $addon->info->title ); |
|
149 | 149 | ?> |
150 | 150 | </h3> |
151 | 151 | </div> |
@@ -156,32 +156,32 @@ discard block |
||
156 | 156 | <?php |
157 | 157 | endif; |
158 | 158 | |
159 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
160 | - $addon->info->slug = 'getpaid-stripe-payments'; |
|
161 | - $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
162 | - } |
|
163 | - |
|
164 | - if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
165 | - echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
166 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
167 | - echo '</a>'; |
|
168 | - } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
169 | - if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
170 | - $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
171 | - } else { |
|
172 | - // if installed show activation link |
|
173 | - if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
174 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
175 | - } else { |
|
176 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
177 | - } |
|
178 | - } |
|
179 | - echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
180 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
181 | - echo '</a>'; |
|
182 | - } |
|
183 | - |
|
184 | - ?> |
|
159 | + if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
160 | + $addon->info->slug = 'getpaid-stripe-payments'; |
|
161 | + $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
162 | + } |
|
163 | + |
|
164 | + if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
165 | + echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
166 | + echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
167 | + echo '</a>'; |
|
168 | + } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
169 | + if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
170 | + $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
171 | + } else { |
|
172 | + // if installed show activation link |
|
173 | + if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
174 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
175 | + } else { |
|
176 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
177 | + } |
|
178 | + } |
|
179 | + echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
180 | + echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
181 | + echo '</a>'; |
|
182 | + } |
|
183 | + |
|
184 | + ?> |
|
185 | 185 | |
186 | 186 | </span> |
187 | 187 | |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | <span class="wpi-product-button"> |
190 | 190 | <?php |
191 | 191 | $addon_obj->output_button( $addon ); |
192 | - ?> |
|
192 | + ?> |
|
193 | 193 | </span> |
194 | 194 | |
195 | 195 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
196 | 196 | <?php |
197 | 197 | endif; |
198 | - } |
|
198 | + } |
|
199 | 199 | } |
200 | - ?> |
|
200 | + ?> |
|
201 | 201 | |
202 | 202 | |
203 | 203 | <div class="clearfix" ></div> |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button> |
217 | 217 | <br> |
218 | 218 | <?php |
219 | - printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
220 | - ?> |
|
219 | + printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
220 | + ?> |
|
221 | 221 | </span> |
222 | 222 | </div> |
223 | 223 |
@@ -3,27 +3,27 @@ discard block |
||
3 | 3 | * Admin View: Page - Addons |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
11 | 11 | <div class="wrap wpi_addons_wrap"> |
12 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
12 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
13 | 13 | |
14 | - <?php if ( $tabs ) { ?> |
|
14 | + <?php if ($tabs) { ?> |
|
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
17 | + foreach ($tabs as $name => $label) { |
|
18 | + echo '<a href="' . esc_url(admin_url('admin.php?page=wpi-addons&tab=' . $name)) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . esc_html($label) . '</a>'; |
|
19 | 19 | } |
20 | - do_action( 'wpi_addons_tabs' ); |
|
20 | + do_action('wpi_addons_tabs'); |
|
21 | 21 | ?> |
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if ( $current_tab == 'membership' ) { |
|
26 | + if ($current_tab == 'membership') { |
|
27 | 27 | |
28 | 28 | ?> |
29 | 29 | |
@@ -32,42 +32,42 @@ discard block |
||
32 | 32 | <!-- |
33 | 33 | <h2>With our WPInvoicing Membership you get access to all our products!</h2> |
34 | 34 | <p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p>--> |
35 | - <?php if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { ?> |
|
36 | - <h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2> |
|
35 | + <?php if (defined('WP_EASY_UPDATES_ACTIVE')) { ?> |
|
36 | + <h2><?php esc_html_e('Have a membership key?', 'invoicing'); ?></h2> |
|
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
40 | - echo wp_kses_post( $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ) ); |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1'); |
|
40 | + echo wp_kses_post($wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108, 12351))); |
|
41 | 41 | ?> |
42 | 42 | </p> |
43 | 43 | <?php } ?> |
44 | 44 | |
45 | 45 | <div class="membership-cta-contet"> |
46 | 46 | <div class="main-cta"> |
47 | - <h2><?php esc_html_e( 'Membership benefits Include:', 'invoicing' ); ?></h2> |
|
47 | + <h2><?php esc_html_e('Membership benefits Include:', 'invoicing'); ?></h2> |
|
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | 51 | $addon_obj = new WPInv_Admin_Addons(); |
52 | - if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
52 | + if ($addons = $addon_obj->get_section_data('addons')) { |
|
53 | + foreach ($addons as $addon) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | ?> |
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
61 | - <h3><?php esc_html_e( 'Membership Starts from', 'invoicing' ); ?></h3> |
|
61 | + <h3><?php esc_html_e('Membership Starts from', 'invoicing'); ?></h3> |
|
62 | 62 | <h4>$99</h4> |
63 | - <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e( 'Buy Membership', 'invoicing' ); ?></a> |
|
63 | + <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e('Buy Membership', 'invoicing'); ?></a> |
|
64 | 64 | </div> |
65 | - <h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3> |
|
65 | + <h3><?php esc_html_e('Included Gateways:', 'invoicing'); ?></h3> |
|
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
68 | + if ($addons = $addon_obj->get_section_data('gateways')) { |
|
69 | + foreach ($addons as $addon) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | ?> |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
84 | + echo '<img src="' . esc_url(plugins_url('images/t-image2.png', dirname(__FILE__))) . '" > '; |
|
85 | 85 | ?> |
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
104 | + echo '<img src="' . esc_url(plugins_url('images/t-image1.png', dirname(__FILE__))) . '" > '; |
|
105 | 105 | ?> |
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | </div> |
118 | 118 | </div> |
119 | 119 | <div class="member-footer"> |
120 | - <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e( 'Buy Membership', 'invoicing' ); ?></a> |
|
121 | - <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e( 'Create Invoice', 'invoicing' ); ?></a> |
|
120 | + <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e('Buy Membership', 'invoicing'); ?></a> |
|
121 | + <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e('Create Invoice', 'invoicing'); ?></a> |
|
122 | 122 | </div> |
123 | 123 | </div> |
124 | 124 | |
@@ -129,55 +129,55 @@ discard block |
||
129 | 129 | } else { |
130 | 130 | $installed_plugins = get_plugins(); |
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
132 | + if ($addons = $addon_obj->get_section_data($current_tab)) : |
|
133 | 133 | //print_r($addons); |
134 | 134 | ?> |
135 | 135 | <ul class="wpi-products"> |
136 | 136 | <?php |
137 | - foreach ( $addons as $addon ) : |
|
138 | - if ( 965 == $addon->info->id ) { |
|
139 | -continue;}// don't show quote add on |
|
137 | + foreach ($addons as $addon) : |
|
138 | + if (965 == $addon->info->id) { |
|
139 | +continue; }// don't show quote add on |
|
140 | 140 | ?> |
141 | 141 | <li class="wpi-product"> |
142 | 142 | <div class="wpi-product-title"> |
143 | 143 | <h3> |
144 | 144 | <?php |
145 | - if ( ! empty( $addon->info->excerpt ) ) { |
|
146 | - wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
145 | + if (!empty($addon->info->excerpt)) { |
|
146 | + wpi_help_tip($addon->info->excerpt, false, false, true); |
|
147 | 147 | } |
148 | - echo esc_html( $addon->info->title ); |
|
148 | + echo esc_html($addon->info->title); |
|
149 | 149 | ?> |
150 | 150 | </h3> |
151 | 151 | </div> |
152 | 152 | |
153 | 153 | <span class="wpi-product-image"> |
154 | - <?php if ( ! empty( $addon->info->thumbnail ) ) : ?> |
|
155 | - <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
|
154 | + <?php if (!empty($addon->info->thumbnail)) : ?> |
|
155 | + <img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/> |
|
156 | 156 | <?php |
157 | 157 | endif; |
158 | 158 | |
159 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
159 | + if ('stripe-payment-gateway' == $addon->info->slug) { |
|
160 | 160 | $addon->info->slug = 'getpaid-stripe-payments'; |
161 | 161 | $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
162 | 162 | } |
163 | 163 | |
164 | - if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
165 | - echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
166 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
164 | + if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === 'https://wordpress.org') { |
|
165 | + echo '<a href="' . esc_url(admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug)) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
166 | + echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>'; |
|
167 | 167 | echo '</a>'; |
168 | - } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
169 | - if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
170 | - $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
168 | + } elseif (isset($addon->info->link) && (substr($addon->info->link, 0, 23) === 'https://wpinvoicing.com' || substr($addon->info->link, 0, 21) === 'https://wpgetpaid.com')) { |
|
169 | + if (defined('WP_EASY_UPDATES_ACTIVE')) { |
|
170 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true'); |
|
171 | 171 | } else { |
172 | 172 | // if installed show activation link |
173 | - if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
173 | + if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) { |
|
174 | 174 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
175 | 175 | } else { |
176 | 176 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
177 | 177 | } |
178 | 178 | } |
179 | - echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
180 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
179 | + echo '<a href="' . esc_url($url) . '" class="thickbox">'; |
|
180 | + echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>'; |
|
181 | 181 | echo '</a>'; |
182 | 182 | } |
183 | 183 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | <span class="wpi-product-button"> |
190 | 190 | <?php |
191 | - $addon_obj->output_button( $addon ); |
|
191 | + $addon_obj->output_button($addon); |
|
192 | 192 | ?> |
193 | 193 | </span> |
194 | 194 | |
@@ -202,21 +202,21 @@ discard block |
||
202 | 202 | |
203 | 203 | <div class="clearfix" ></div> |
204 | 204 | |
205 | - <?php if ( $current_tab == 'addons' ) { ?> |
|
206 | - <p><?php printf( esc_attr__( 'All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/addons/">','</a>' ); ?></p> |
|
207 | - <?php } if ( $current_tab == 'gateways' ) { ?> |
|
208 | - <p><?php printf( esc_attr__( 'All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/gateways/">','</a>' ); ?></p> |
|
205 | + <?php if ($current_tab == 'addons') { ?> |
|
206 | + <p><?php printf(esc_attr__('All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/addons/">', '</a>'); ?></p> |
|
207 | + <?php } if ($current_tab == 'gateways') { ?> |
|
208 | + <p><?php printf(esc_attr__('All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/gateways/">', '</a>'); ?></p> |
|
209 | 209 | <?php } ?> |
210 | 210 | |
211 | - <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post( sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing' ), wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php' ), 'activate-plugin_wp-easy-updates/external-updates.php' ) ) ); ?></span></div> |
|
212 | - <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post( sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing' ), admin_url( 'plugin-install.php?tab=upload&wpeu-install=true' ) ) ); ?></span></div> |
|
211 | + <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'))); ?></span></div> |
|
212 | + <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url('plugin-install.php?tab=upload&wpeu-install=true'))); ?></span></div> |
|
213 | 213 | <div id="wpeu-licence-popup" style="display:none;"> |
214 | 214 | <span class="wpi-notification noti-white"> |
215 | - <h3 class="wpeu-licence-title"><?php esc_html_e( 'Licence key', 'invoicing' ); ?></h3> |
|
216 | - <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button> |
|
215 | + <h3 class="wpeu-licence-title"><?php esc_html_e('Licence key', 'invoicing'); ?></h3> |
|
216 | + <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e('Enter your licence key', 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e('Install', 'invoicing'); ?></button> |
|
217 | 217 | <br> |
218 | 218 | <?php |
219 | - printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
219 | + printf(esc_html__('%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>'); |
|
220 | 220 | ?> |
221 | 221 | </span> |
222 | 222 | </div> |
@@ -12,38 +12,38 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // (Maybe) set form items. |
|
38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
39 | - |
|
40 | - // Confirm items key. |
|
41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
44 | - } |
|
45 | - |
|
46 | - $items = array(); |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // (Maybe) set form items. |
|
38 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
39 | + |
|
40 | + // Confirm items key. |
|
41 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | + if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
44 | + } |
|
45 | + |
|
46 | + $items = array(); |
|
47 | 47 | $item_ids = array(); |
48 | 48 | |
49 | 49 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -69,61 +69,61 @@ discard block |
||
69 | 69 | $items[] = $item; |
70 | 70 | } |
71 | 71 | } |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | 74 | $payment_form->set_items( $items ); |
75 | 75 | |
76 | - } |
|
77 | - |
|
78 | - // Process each individual item. |
|
79 | - foreach ( $payment_form->get_items() as $item ) { |
|
80 | - $this->process_item( $item, $selected_items, $submission ); |
|
81 | - } |
|
82 | - |
|
83 | - } |
|
76 | + } |
|
84 | 77 | |
85 | - /** |
|
86 | - * Process a single item. |
|
87 | - * |
|
88 | - * @param GetPaid_Form_Item $item |
|
89 | - * @param array $selected_items |
|
90 | - * @param GetPaid_Payment_Form_Submission $submission |
|
91 | - */ |
|
92 | - public function process_item( $item, $selected_items, $submission ) { |
|
78 | + // Process each individual item. |
|
79 | + foreach ( $payment_form->get_items() as $item ) { |
|
80 | + $this->process_item( $item, $selected_items, $submission ); |
|
81 | + } |
|
93 | 82 | |
94 | - // Abort if this is an optional item and it has not been selected. |
|
95 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
96 | - return; |
|
97 | - } |
|
83 | + } |
|
98 | 84 | |
99 | - // (maybe) let customers change the quantities and prices. |
|
100 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
101 | - |
|
102 | - // Maybe change the quantities. |
|
103 | - if ( $item->allows_quantities() ) { |
|
104 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
105 | - } |
|
85 | + /** |
|
86 | + * Process a single item. |
|
87 | + * |
|
88 | + * @param GetPaid_Form_Item $item |
|
89 | + * @param array $selected_items |
|
90 | + * @param GetPaid_Payment_Form_Submission $submission |
|
91 | + */ |
|
92 | + public function process_item( $item, $selected_items, $submission ) { |
|
93 | + |
|
94 | + // Abort if this is an optional item and it has not been selected. |
|
95 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + // (maybe) let customers change the quantities and prices. |
|
100 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
101 | + |
|
102 | + // Maybe change the quantities. |
|
103 | + if ( $item->allows_quantities() ) { |
|
104 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
105 | + } |
|
106 | 106 | |
107 | - // Maybe change the price. |
|
108 | - if ( $item->user_can_set_their_price() ) { |
|
109 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
107 | + // Maybe change the price. |
|
108 | + if ( $item->user_can_set_their_price() ) { |
|
109 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
110 | 110 | |
111 | - if ( $item->get_minimum_price() > $price ) { |
|
112 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
113 | - } |
|
111 | + if ( $item->get_minimum_price() > $price ) { |
|
112 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
113 | + } |
|
114 | 114 | |
115 | - $item->set_price( $price ); |
|
115 | + $item->set_price( $price ); |
|
116 | 116 | |
117 | - } |
|
118 | - } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - if ( 0 == $item->get_quantity() ) { |
|
121 | - return; |
|
122 | - } |
|
120 | + if ( 0 == $item->get_quantity() ) { |
|
121 | + return; |
|
122 | + } |
|
123 | 123 | |
124 | - // Save the item. |
|
125 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
124 | + // Save the item. |
|
125 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
126 | 126 | |
127 | - } |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -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 | * Payment form submission itemss class |
@@ -23,37 +23,37 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $data = $submission->get_data(); |
29 | 29 | $payment_form = $submission->get_payment_form(); |
30 | 30 | |
31 | 31 | // Prepare the selected items. |
32 | 32 | $selected_items = array(); |
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
33 | + if (!empty($data['getpaid-items'])) { |
|
34 | + $selected_items = wpinv_clean($data['getpaid-items']); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // (Maybe) set form items. |
38 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
38 | + if (isset($data['getpaid-form-items'])) { |
|
39 | 39 | |
40 | 40 | // Confirm items key. |
41 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
42 | - if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) { |
|
43 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
41 | + $form_items = wpinv_clean($data['getpaid-form-items']); |
|
42 | + if (!isset($data['getpaid-form-items-key']) || $data['getpaid-form-items-key'] !== md5(NONCE_KEY . AUTH_KEY . $form_items)) { |
|
43 | + throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing')); |
|
44 | 44 | } |
45 | 45 | |
46 | - $items = array(); |
|
46 | + $items = array(); |
|
47 | 47 | $item_ids = array(); |
48 | 48 | |
49 | - foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
|
50 | - if ( ! in_array( $item_id, $item_ids ) ) { |
|
51 | - $item = new GetPaid_Form_Item( $item_id ); |
|
52 | - $item->set_quantity( $qty ); |
|
49 | + foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) { |
|
50 | + if (!in_array($item_id, $item_ids)) { |
|
51 | + $item = new GetPaid_Form_Item($item_id); |
|
52 | + $item->set_quantity($qty); |
|
53 | 53 | |
54 | - if ( 0 == $qty ) { |
|
55 | - $item->set_allow_quantities( true ); |
|
56 | - $item->set_is_required( false ); |
|
54 | + if (0 == $qty) { |
|
55 | + $item->set_allow_quantities(true); |
|
56 | + $item->set_is_required(false); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $item_ids[] = $item->get_id(); |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - if ( ! $payment_form->is_default() ) { |
|
64 | + if (!$payment_form->is_default()) { |
|
65 | 65 | |
66 | - foreach ( $payment_form->get_items() as $item ) { |
|
67 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
66 | + foreach ($payment_form->get_items() as $item) { |
|
67 | + if (!in_array($item->get_id(), $item_ids)) { |
|
68 | 68 | $item_ids[] = $item->get_id(); |
69 | 69 | $items[] = $item; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | - $payment_form->set_items( $items ); |
|
74 | + $payment_form->set_items($items); |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Process each individual item. |
79 | - foreach ( $payment_form->get_items() as $item ) { |
|
80 | - $this->process_item( $item, $selected_items, $submission ); |
|
79 | + foreach ($payment_form->get_items() as $item) { |
|
80 | + $this->process_item($item, $selected_items, $submission); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | } |
@@ -89,40 +89,40 @@ discard block |
||
89 | 89 | * @param array $selected_items |
90 | 90 | * @param GetPaid_Payment_Form_Submission $submission |
91 | 91 | */ |
92 | - public function process_item( $item, $selected_items, $submission ) { |
|
92 | + public function process_item($item, $selected_items, $submission) { |
|
93 | 93 | |
94 | 94 | // Abort if this is an optional item and it has not been selected. |
95 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
95 | + if (!$item->is_required() && !isset($selected_items[$item->get_id()])) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // (maybe) let customers change the quantities and prices. |
100 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
100 | + if (isset($selected_items[$item->get_id()])) { |
|
101 | 101 | |
102 | 102 | // Maybe change the quantities. |
103 | - if ( $item->allows_quantities() ) { |
|
104 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
103 | + if ($item->allows_quantities()) { |
|
104 | + $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // Maybe change the price. |
108 | - if ( $item->user_can_set_their_price() ) { |
|
109 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
108 | + if ($item->user_can_set_their_price()) { |
|
109 | + $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']); |
|
110 | 110 | |
111 | - if ( $item->get_minimum_price() > $price ) { |
|
112 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
111 | + if ($item->get_minimum_price() > $price) { |
|
112 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price()))); |
|
113 | 113 | } |
114 | 114 | |
115 | - $item->set_price( $price ); |
|
115 | + $item->set_price($price); |
|
116 | 116 | |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( 0 == $item->get_quantity() ) { |
|
120 | + if (0 == $item->get_quantity()) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | 124 | // Save the item. |
125 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
125 | + $this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission); |
|
126 | 126 | |
127 | 127 | } |
128 | 128 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,356 +114,356 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true, |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true, |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | 266 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ( $items as $key => $value ) { |
|
271 | 271 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
278 | 278 | |
279 | - continue; |
|
279 | + continue; |
|
280 | 280 | |
281 | - } |
|
281 | + } |
|
282 | 282 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ( $item->can_purchase() ) { |
|
288 | 288 | |
289 | - $value = (float) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
289 | + $value = (float) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
295 | 295 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
298 | 298 | |
299 | - continue; |
|
300 | - } |
|
299 | + continue; |
|
300 | + } |
|
301 | 301 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
310 | 310 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
331 | 331 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
334 | 334 | |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
348 | 348 | |
349 | - continue; |
|
350 | - } |
|
349 | + continue; |
|
350 | + } |
|
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | - return $prepared; |
|
355 | - } |
|
356 | - |
|
357 | - $items = array(); |
|
358 | - foreach ( $prepared as $item ) { |
|
359 | - $items[] = $item->prepare_data_for_use(); |
|
360 | - } |
|
361 | - |
|
362 | - return $items; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Get a single item belonging to the form. |
|
367 | - * |
|
368 | - * @since 1.0.19 |
|
369 | - * @param int $item_id The item id to return. |
|
370 | - * @return GetPaid_Form_Item|bool |
|
371 | - */ |
|
372 | - public function get_item( $item_id ) { |
|
373 | - |
|
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | - return false; |
|
376 | - } |
|
377 | - |
|
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
380 | - return $item; |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - return false; |
|
385 | - |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets a single element. |
|
390 | - * |
|
391 | - * @since 1.0.19 |
|
392 | - * @param string $element_type The element type to return. |
|
393 | - * @return array|bool |
|
394 | - */ |
|
395 | - public function get_element_type( $element_type ) { |
|
396 | - |
|
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | - return false; |
|
399 | - } |
|
400 | - |
|
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | - |
|
403 | - if ( $element['type'] == $element_type ) { |
|
404 | - return $element; |
|
405 | - } |
|
353 | + if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + return $prepared; |
|
355 | + } |
|
356 | + |
|
357 | + $items = array(); |
|
358 | + foreach ( $prepared as $item ) { |
|
359 | + $items[] = $item->prepare_data_for_use(); |
|
360 | + } |
|
361 | + |
|
362 | + return $items; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Get a single item belonging to the form. |
|
367 | + * |
|
368 | + * @since 1.0.19 |
|
369 | + * @param int $item_id The item id to return. |
|
370 | + * @return GetPaid_Form_Item|bool |
|
371 | + */ |
|
372 | + public function get_item( $item_id ) { |
|
373 | + |
|
374 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + return false; |
|
376 | + } |
|
377 | + |
|
378 | + foreach ( $this->get_items() as $item ) { |
|
379 | + if ( $item->get_id() == (int) $item_id ) { |
|
380 | + return $item; |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + return false; |
|
385 | + |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets a single element. |
|
390 | + * |
|
391 | + * @since 1.0.19 |
|
392 | + * @param string $element_type The element type to return. |
|
393 | + * @return array|bool |
|
394 | + */ |
|
395 | + public function get_element_type( $element_type ) { |
|
396 | + |
|
397 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + return false; |
|
399 | + } |
|
400 | + |
|
401 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + |
|
403 | + if ( $element['type'] == $element_type ) { |
|
404 | + return $element; |
|
405 | + } |
|
406 | 406 | } |
407 | 407 | |
408 | - return false; |
|
409 | - |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the total amount earned via this form. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return float |
|
418 | - */ |
|
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Get the total amount refunded via this form. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return float |
|
429 | - */ |
|
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Get the total amount cancelled via this form. |
|
436 | - * |
|
437 | - * @since 1.0.19 |
|
438 | - * @param string $context View or edit context. |
|
439 | - * @return float |
|
440 | - */ |
|
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Get the total amount failed via this form. |
|
447 | - * |
|
448 | - * @since 1.0.19 |
|
449 | - * @param string $context View or edit context. |
|
450 | - * @return float |
|
451 | - */ |
|
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Get the currency. |
|
458 | - * |
|
459 | - * @since 1.0.19 |
|
460 | - * @param string $context View or edit context. |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function get_currency() { |
|
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | - } |
|
408 | + return false; |
|
409 | + |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the total amount earned via this form. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return float |
|
418 | + */ |
|
419 | + public function get_earned( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'earned', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Get the total amount refunded via this form. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return float |
|
429 | + */ |
|
430 | + public function get_refunded( $context = 'view' ) { |
|
431 | + return $this->get_prop( 'refunded', $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Get the total amount cancelled via this form. |
|
436 | + * |
|
437 | + * @since 1.0.19 |
|
438 | + * @param string $context View or edit context. |
|
439 | + * @return float |
|
440 | + */ |
|
441 | + public function get_cancelled( $context = 'view' ) { |
|
442 | + return $this->get_prop( 'cancelled', $context ); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Get the total amount failed via this form. |
|
447 | + * |
|
448 | + * @since 1.0.19 |
|
449 | + * @param string $context View or edit context. |
|
450 | + * @return float |
|
451 | + */ |
|
452 | + public function get_failed( $context = 'view' ) { |
|
453 | + return $this->get_prop( 'failed', $context ); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Get the currency. |
|
458 | + * |
|
459 | + * @since 1.0.19 |
|
460 | + * @param string $context View or edit context. |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function get_currency() { |
|
464 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + } |
|
467 | 467 | |
468 | 468 | /* |
469 | 469 | |-------------------------------------------------------------------------- |
@@ -476,22 +476,22 @@ discard block |
||
476 | 476 | */ |
477 | 477 | |
478 | 478 | /** |
479 | - * Set plugin version when the item was created. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - */ |
|
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
479 | + * Set plugin version when the item was created. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + */ |
|
483 | + public function set_version( $value ) { |
|
484 | + $this->set_prop( 'version', $value ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Set date when the item was created. |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $value Value to set. |
|
488 | + * Set date when the item was created. |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $value Value to set. |
|
492 | 492 | * @return bool Whether or not the date was set. |
493 | - */ |
|
494 | - public function set_date_created( $value ) { |
|
493 | + */ |
|
494 | + public function set_date_created( $value ) { |
|
495 | 495 | $date = strtotime( $value ); |
496 | 496 | |
497 | 497 | if ( $date ) { |
@@ -504,13 +504,13 @@ discard block |
||
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
507 | - * Set date when the item was last modified. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param string $value Value to set. |
|
507 | + * Set date when the item was last modified. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param string $value Value to set. |
|
511 | 511 | * @return bool Whether or not the date was set. |
512 | - */ |
|
513 | - public function set_date_modified( $value ) { |
|
512 | + */ |
|
513 | + public function set_date_modified( $value ) { |
|
514 | 514 | $date = strtotime( $value ); |
515 | 515 | |
516 | 516 | if ( $date ) { |
@@ -523,164 +523,164 @@ discard block |
||
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
526 | - * Set the item name. |
|
527 | - * |
|
528 | - * @since 1.0.19 |
|
529 | - * @param string $value New name. |
|
530 | - */ |
|
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Alias of self::set_name(). |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - * @param string $value New name. |
|
540 | - */ |
|
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Set the owner of the item. |
|
547 | - * |
|
548 | - * @since 1.0.19 |
|
549 | - * @param int $value New author. |
|
550 | - */ |
|
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Set the form elements. |
|
557 | - * |
|
558 | - * @since 1.0.19 |
|
559 | - * @sinve 2.3.4 Array values sanitized. |
|
560 | - * @param array $value Form elements. |
|
561 | - */ |
|
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | - } |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Sanitize array values. |
|
570 | - * |
|
571 | - * @param $value |
|
572 | - * |
|
573 | - * @return mixed |
|
574 | - */ |
|
575 | - public function sanitize_array_values( $value ) { |
|
576 | - |
|
577 | - // sanitize |
|
578 | - if ( ! empty( $value ) ) { |
|
579 | - |
|
580 | - foreach ( $value as $key => $val_arr ) { |
|
581 | - |
|
582 | - if ( is_array( $val_arr ) ) { |
|
583 | - // check if we have sub array items. |
|
584 | - $sub_arr = array(); |
|
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - // we allow some html in description so we sanitize it separately. |
|
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | - |
|
595 | - // sanitize array elements |
|
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | - |
|
598 | - // add back the description if set |
|
599 | - if ( isset( $val_arr['description'] ) ) { |
|
526 | + * Set the item name. |
|
527 | + * |
|
528 | + * @since 1.0.19 |
|
529 | + * @param string $value New name. |
|
530 | + */ |
|
531 | + public function set_name( $value ) { |
|
532 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Alias of self::set_name(). |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + * @param string $value New name. |
|
540 | + */ |
|
541 | + public function set_title( $value ) { |
|
542 | + $this->set_name( $value ); |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Set the owner of the item. |
|
547 | + * |
|
548 | + * @since 1.0.19 |
|
549 | + * @param int $value New author. |
|
550 | + */ |
|
551 | + public function set_author( $value ) { |
|
552 | + $this->set_prop( 'author', (int) $value ); |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Set the form elements. |
|
557 | + * |
|
558 | + * @since 1.0.19 |
|
559 | + * @sinve 2.3.4 Array values sanitized. |
|
560 | + * @param array $value Form elements. |
|
561 | + */ |
|
562 | + public function set_elements( $value ) { |
|
563 | + if ( is_array( $value ) ) { |
|
564 | + $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
565 | + } |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Sanitize array values. |
|
570 | + * |
|
571 | + * @param $value |
|
572 | + * |
|
573 | + * @return mixed |
|
574 | + */ |
|
575 | + public function sanitize_array_values( $value ) { |
|
576 | + |
|
577 | + // sanitize |
|
578 | + if ( ! empty( $value ) ) { |
|
579 | + |
|
580 | + foreach ( $value as $key => $val_arr ) { |
|
581 | + |
|
582 | + if ( is_array( $val_arr ) ) { |
|
583 | + // check if we have sub array items. |
|
584 | + $sub_arr = array(); |
|
585 | + foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | + if ( is_array( $val2 ) ) { |
|
587 | + $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | + unset( $val_arr[ $key ][ $key2 ] ); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + // we allow some html in description so we sanitize it separately. |
|
593 | + $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
594 | + |
|
595 | + // sanitize array elements |
|
596 | + $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
597 | + |
|
598 | + // add back the description if set |
|
599 | + if ( isset( $val_arr['description'] ) ) { |
|
600 | 600 | $value[ $key ]['description'] = $help_text;} |
601 | 601 | |
602 | - // add back sub array items after its been sanitized. |
|
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | - } |
|
606 | - } |
|
602 | + // add back sub array items after its been sanitized. |
|
603 | + if ( ! empty( $sub_arr ) ) { |
|
604 | + $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
605 | + } |
|
606 | + } |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
610 | - return $value; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Set the form items. |
|
615 | - * |
|
616 | - * @since 1.0.19 |
|
617 | - * @param array $value Form elements. |
|
618 | - */ |
|
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set the total amount earned via this form. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param float $value Amount earned. |
|
630 | - */ |
|
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Set the total amount refunded via this form. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - * @param float $value Amount refunded. |
|
641 | - */ |
|
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Set the total amount cancelled via this form. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @param float $value Amount cancelled. |
|
652 | - */ |
|
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Set the total amount failed via this form. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @param float $value Amount cancelled. |
|
663 | - */ |
|
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
667 | - } |
|
610 | + return $value; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Set the form items. |
|
615 | + * |
|
616 | + * @since 1.0.19 |
|
617 | + * @param array $value Form elements. |
|
618 | + */ |
|
619 | + public function set_items( $value ) { |
|
620 | + if ( is_array( $value ) ) { |
|
621 | + $this->set_prop( 'items', $value ); |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set the total amount earned via this form. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param float $value Amount earned. |
|
630 | + */ |
|
631 | + public function set_earned( $value ) { |
|
632 | + $value = max( (float) $value, 0 ); |
|
633 | + $this->set_prop( 'earned', $value ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Set the total amount refunded via this form. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + * @param float $value Amount refunded. |
|
641 | + */ |
|
642 | + public function set_refunded( $value ) { |
|
643 | + $value = max( (float) $value, 0 ); |
|
644 | + $this->set_prop( 'refunded', $value ); |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Set the total amount cancelled via this form. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @param float $value Amount cancelled. |
|
652 | + */ |
|
653 | + public function set_cancelled( $value ) { |
|
654 | + $value = max( (float) $value, 0 ); |
|
655 | + $this->set_prop( 'cancelled', $value ); |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * Set the total amount failed via this form. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @param float $value Amount cancelled. |
|
663 | + */ |
|
664 | + public function set_failed( $value ) { |
|
665 | + $value = max( (float) $value, 0 ); |
|
666 | + $this->set_prop( 'failed', $value ); |
|
667 | + } |
|
668 | 668 | |
669 | 669 | /** |
670 | 670 | * Create an item. For backwards compatibilty. |
671 | 671 | * |
672 | 672 | * @deprecated |
673 | - * @return int item id |
|
673 | + * @return int item id |
|
674 | 674 | */ |
675 | 675 | public function create( $data = array() ) { |
676 | 676 | |
677 | - // Set the properties. |
|
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
680 | - } |
|
677 | + // Set the properties. |
|
678 | + if ( is_array( $data ) ) { |
|
679 | + $this->set_props( $data ); |
|
680 | + } |
|
681 | 681 | |
682 | - // Save the item. |
|
683 | - return $this->save(); |
|
682 | + // Save the item. |
|
683 | + return $this->save(); |
|
684 | 684 | |
685 | 685 | } |
686 | 686 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | * Updates an item. For backwards compatibilty. |
689 | 689 | * |
690 | 690 | * @deprecated |
691 | - * @return int item id |
|
691 | + * @return int item id |
|
692 | 692 | */ |
693 | 693 | public function update( $data = array() ) { |
694 | 694 | return $this->create( $data ); |
@@ -704,22 +704,22 @@ discard block |
||
704 | 704 | */ |
705 | 705 | |
706 | 706 | /** |
707 | - * Checks whether this is the default payment form. |
|
708 | - * |
|
709 | - * @since 1.0.19 |
|
710 | - * @return bool |
|
711 | - */ |
|
707 | + * Checks whether this is the default payment form. |
|
708 | + * |
|
709 | + * @since 1.0.19 |
|
710 | + * @return bool |
|
711 | + */ |
|
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | 714 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | 717 | /** |
718 | - * Checks whether the form is active. |
|
719 | - * |
|
720 | - * @since 1.0.19 |
|
721 | - * @return bool |
|
722 | - */ |
|
718 | + * Checks whether the form is active. |
|
719 | + * |
|
720 | + * @since 1.0.19 |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
@@ -728,81 +728,81 @@ discard block |
||
728 | 728 | } |
729 | 729 | |
730 | 730 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Checks whether the form has a given item. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - * @return bool |
|
738 | - */ |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Checks whether the form has a given item. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | 739 | public function has_item( $item_id ) { |
740 | 740 | return false !== $this->get_item( $item_id ); |
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Checks whether the form has a given element. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * @return bool |
|
748 | - */ |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Checks whether the form has a given element. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * @return bool |
|
748 | + */ |
|
749 | 749 | public function has_element_type( $element_type ) { |
750 | 750 | return false !== $this->get_element_type( $element_type ); |
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Checks whether this form is recurring or not. |
|
755 | - * |
|
756 | - * @since 1.0.19 |
|
757 | - * @return bool |
|
758 | - */ |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Checks whether this form is recurring or not. |
|
755 | + * |
|
756 | + * @since 1.0.19 |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
762 | - return $this->invoice->is_recurring(); |
|
763 | - } |
|
761 | + if ( ! empty( $this->invoice ) ) { |
|
762 | + return $this->invoice->is_recurring(); |
|
763 | + } |
|
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ( $this->get_items() as $item ) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
768 | - return true; |
|
769 | - } |
|
767 | + if ( $item->is_recurring() ) { |
|
768 | + return true; |
|
769 | + } |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | return false; |
773 | - } |
|
773 | + } |
|
774 | 774 | |
775 | - /** |
|
776 | - * Retrieves the form's html. |
|
777 | - * |
|
778 | - * @since 1.0.19 |
|
779 | - */ |
|
775 | + /** |
|
776 | + * Retrieves the form's html. |
|
777 | + * |
|
778 | + * @since 1.0.19 |
|
779 | + */ |
|
780 | 780 | public function get_html( $extra_markup = '' ) { |
781 | 781 | |
782 | - // Return the HTML. |
|
783 | - return wpinv_get_template_html( |
|
784 | - 'payment-forms/form.php', |
|
785 | - array( |
|
786 | - 'form' => $this, |
|
787 | - 'extra_markup' => $extra_markup, |
|
788 | - ) |
|
789 | - ); |
|
790 | - |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Displays the payment form. |
|
795 | - * |
|
796 | - * @since 1.0.19 |
|
797 | - */ |
|
782 | + // Return the HTML. |
|
783 | + return wpinv_get_template_html( |
|
784 | + 'payment-forms/form.php', |
|
785 | + array( |
|
786 | + 'form' => $this, |
|
787 | + 'extra_markup' => $extra_markup, |
|
788 | + ) |
|
789 | + ); |
|
790 | + |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Displays the payment form. |
|
795 | + * |
|
796 | + * @since 1.0.19 |
|
797 | + */ |
|
798 | 798 | public function display( $extra_markup = '' ) { |
799 | - wpinv_get_template( |
|
800 | - 'payment-forms/form.php', |
|
801 | - array( |
|
802 | - 'form' => $this, |
|
803 | - 'extra_markup' => $extra_markup, |
|
804 | - ) |
|
805 | - ); |
|
799 | + wpinv_get_template( |
|
800 | + 'payment-forms/form.php', |
|
801 | + array( |
|
802 | + 'form' => $this, |
|
803 | + 'extra_markup' => $extra_markup, |
|
804 | + ) |
|
805 | + ); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] == $element_type ) { |
|
403 | + if ($element['type'] == $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
798 | + public function display($extra_markup = '') { |
|
799 | 799 | wpinv_get_template( |
800 | 800 | 'payment-forms/form.php', |
801 | 801 | array( |
@@ -13,96 +13,96 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
93 | - parent::__construct(); |
|
90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | + add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
93 | + parent::__construct(); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Process Payment. |
|
98 | - * |
|
99 | - * |
|
100 | - * @param WPInv_Invoice $invoice Invoice. |
|
101 | - * @param array $submission_data Posted checkout fields. |
|
102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | + * Process Payment. |
|
98 | + * |
|
99 | + * |
|
100 | + * @param WPInv_Invoice $invoice Invoice. |
|
101 | + * @param array $submission_data Posted checkout fields. |
|
102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the PayPal request URL for an invoice. |
|
129 | - * |
|
130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_request_url( $invoice ) { |
|
128 | + * Get the PayPal request URL for an invoice. |
|
129 | + * |
|
130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_request_url( $invoice ) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
146 | 146 | |
147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
148 | 148 | |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | - * Get PayPal Args for passing to PP. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function get_paypal_args( $invoice ) { |
|
152 | + * Get PayPal Args for passing to PP. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function get_paypal_args( $invoice ) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | - |
|
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | - $force_one_line_item = true; |
|
164 | - } |
|
165 | - |
|
166 | - $paypal_args = apply_filters( |
|
167 | - 'getpaid_paypal_args', |
|
168 | - array_merge( |
|
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | - ), |
|
172 | - $invoice |
|
173 | - ); |
|
174 | - |
|
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + |
|
162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + $force_one_line_item = true; |
|
164 | + } |
|
165 | + |
|
166 | + $paypal_args = apply_filters( |
|
167 | + 'getpaid_paypal_args', |
|
168 | + array_merge( |
|
169 | + $this->get_transaction_args( $invoice ), |
|
170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | + ), |
|
172 | + $invoice |
|
173 | + ); |
|
174 | + |
|
175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Get transaction args for paypal request. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function get_transaction_args( $invoice ) { |
|
185 | - |
|
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | - return array( |
|
179 | + * Get transaction args for paypal request. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function get_transaction_args( $invoice ) { |
|
185 | + |
|
186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + return array( |
|
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get line item args for paypal request. |
|
213 | - * |
|
214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
212 | + * Get line item args for paypal request. |
|
213 | + * |
|
214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
221 | + if ( $force_one_line_item ) { |
|
222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
223 | 223 | } |
224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Get line item args for paypal request as a single line item. |
|
247 | - * |
|
248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | - $this->delete_line_items(); |
|
246 | + * Get line item args for paypal request as a single line item. |
|
247 | + * |
|
248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + $this->delete_line_items(); |
|
253 | 253 | |
254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
256 | 256 | |
257 | - return $this->get_line_items(); |
|
257 | + return $this->get_line_items(); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Return all line items. |
|
262 | - */ |
|
263 | - protected function get_line_items() { |
|
264 | - return $this->line_items; |
|
265 | - } |
|
261 | + * Return all line items. |
|
262 | + */ |
|
263 | + protected function get_line_items() { |
|
264 | + return $this->line_items; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | - * Remove all line items. |
|
269 | - */ |
|
270 | - protected function delete_line_items() { |
|
271 | - $this->line_items = array(); |
|
268 | + * Remove all line items. |
|
269 | + */ |
|
270 | + protected function delete_line_items() { |
|
271 | + $this->line_items = array(); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Prepare line items to send to paypal. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
278 | - */ |
|
279 | - protected function prepare_line_items( $invoice ) { |
|
280 | - $this->delete_line_items(); |
|
281 | - |
|
282 | - // Items. |
|
283 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | - $amount = $item->get_price(); |
|
285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
275 | + * Prepare line items to send to paypal. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
278 | + */ |
|
279 | + protected function prepare_line_items( $invoice ) { |
|
280 | + $this->delete_line_items(); |
|
281 | + |
|
282 | + // Items. |
|
283 | + foreach ( $invoice->get_items() as $item ) { |
|
284 | + $amount = $item->get_price(); |
|
285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Add PayPal Line Item. |
|
298 | - * |
|
299 | - * @param string $item_name Item name. |
|
300 | - * @param float $quantity Item quantity. |
|
301 | - * @param float $amount Amount. |
|
302 | - * @param string $item_number Item number. |
|
303 | - */ |
|
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | - |
|
307 | - $item = apply_filters( |
|
308 | - 'getpaid_paypal_line_item', |
|
309 | - array( |
|
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | - 'quantity' => (float) $quantity, |
|
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | - 'item_number' => $item_number, |
|
314 | - ), |
|
315 | - $item_name, |
|
316 | - $quantity, |
|
317 | - $amount, |
|
318 | - $item_number |
|
319 | - ); |
|
320 | - |
|
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
297 | + * Add PayPal Line Item. |
|
298 | + * |
|
299 | + * @param string $item_name Item name. |
|
300 | + * @param float $quantity Item quantity. |
|
301 | + * @param float $amount Amount. |
|
302 | + * @param string $item_number Item number. |
|
303 | + */ |
|
304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | + |
|
307 | + $item = apply_filters( |
|
308 | + 'getpaid_paypal_line_item', |
|
309 | + array( |
|
310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'quantity' => (float) $quantity, |
|
312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'item_number' => $item_number, |
|
314 | + ), |
|
315 | + $item_name, |
|
316 | + $quantity, |
|
317 | + $amount, |
|
318 | + $item_number |
|
319 | + ); |
|
320 | + |
|
321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | - * |
|
332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | - $max_paypal_length = 2083; |
|
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | - |
|
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | - return $paypal_args; |
|
344 | - } |
|
345 | - |
|
346 | - return apply_filters( |
|
347 | - 'getpaid_paypal_args', |
|
348 | - array_merge( |
|
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
351 | - ), |
|
352 | - $invoice |
|
353 | - ); |
|
330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | + * |
|
332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + $max_paypal_length = 2083; |
|
340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + |
|
342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + return $paypal_args; |
|
344 | + } |
|
345 | + |
|
346 | + return apply_filters( |
|
347 | + 'getpaid_paypal_args', |
|
348 | + array_merge( |
|
349 | + $this->get_transaction_args( $invoice ), |
|
350 | + $this->get_line_item_args( $invoice, true ) |
|
351 | + ), |
|
352 | + $invoice |
|
353 | + ); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Processes recurring invoices. |
|
359 | - * |
|
360 | - * @param array $paypal_args PayPal args. |
|
361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
362 | - */ |
|
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
358 | + * Processes recurring invoices. |
|
359 | + * |
|
360 | + * @param array $paypal_args PayPal args. |
|
361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
362 | + */ |
|
363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
382 | 382 | $subscription_item = $invoice->get_recurring( true ); |
383 | 383 | |
384 | - // Convert 365 days to 1 year. |
|
385 | - if ( 'D' == $period && 365 == $interval ) { |
|
386 | - $period = 'Y'; |
|
387 | - $interval = 1; |
|
388 | - } |
|
384 | + // Convert 365 days to 1 year. |
|
385 | + if ( 'D' == $period && 365 == $interval ) { |
|
386 | + $period = 'Y'; |
|
387 | + $interval = 1; |
|
388 | + } |
|
389 | 389 | |
390 | 390 | if ( $subscription_item->has_free_trial() ) { |
391 | 391 | |
392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
393 | 393 | |
394 | - // Trial period length. |
|
395 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
394 | + // Trial period length. |
|
395 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
396 | 396 | |
397 | - // Trial period. |
|
398 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
397 | + // Trial period. |
|
398 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
399 | 399 | |
400 | 400 | } elseif ( $initial_amount != $recurring_amount ) { |
401 | 401 | |
@@ -418,40 +418,40 @@ discard block |
||
418 | 418 | } |
419 | 419 | |
420 | 420 | // We have a recurring payment |
421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
421 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
422 | 422 | |
423 | - // Subscription price |
|
424 | - $paypal_args['a3'] = $recurring_amount; |
|
423 | + // Subscription price |
|
424 | + $paypal_args['a3'] = $recurring_amount; |
|
425 | 425 | |
426 | - // Subscription duration |
|
427 | - $paypal_args['p3'] = $interval; |
|
426 | + // Subscription duration |
|
427 | + $paypal_args['p3'] = $interval; |
|
428 | 428 | |
429 | - // Subscription period |
|
430 | - $paypal_args['t3'] = $period; |
|
429 | + // Subscription period |
|
430 | + $paypal_args['t3'] = $period; |
|
431 | 431 | |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Recurring payments |
435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
435 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
436 | 436 | |
437 | - // Non-recurring payments |
|
438 | - $paypal_args['src'] = 0; |
|
437 | + // Non-recurring payments |
|
438 | + $paypal_args['src'] = 0; |
|
439 | 439 | |
440 | - } else { |
|
440 | + } else { |
|
441 | 441 | |
442 | - $paypal_args['src'] = 1; |
|
442 | + $paypal_args['src'] = 1; |
|
443 | 443 | |
444 | - if ( $bill_times > 0 ) { |
|
444 | + if ( $bill_times > 0 ) { |
|
445 | 445 | |
446 | - // An initial period is being used to charge a sign-up fee |
|
447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | - $bill_times--; |
|
449 | - } |
|
446 | + // An initial period is being used to charge a sign-up fee |
|
447 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | + $bill_times--; |
|
449 | + } |
|
450 | 450 | |
451 | 451 | // Make sure it's not over the max of 52 |
452 | 452 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
453 | 453 | |
454 | - } |
|
454 | + } |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | // Force return URL so that order description & instructions display |
@@ -466,19 +466,19 @@ discard block |
||
466 | 466 | } |
467 | 467 | |
468 | 468 | return apply_filters( |
469 | - 'getpaid_paypal_subscription_args', |
|
470 | - $paypal_args, |
|
471 | - $invoice |
|
469 | + 'getpaid_paypal_subscription_args', |
|
470 | + $paypal_args, |
|
471 | + $invoice |
|
472 | 472 | ); |
473 | 473 | |
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Processes ipns and marks payments as complete. |
|
478 | - * |
|
479 | - * @return void |
|
480 | - */ |
|
481 | - public function verify_ipn() { |
|
477 | + * Processes ipns and marks payments as complete. |
|
478 | + * |
|
479 | + * @return void |
|
480 | + */ |
|
481 | + public function verify_ipn() { |
|
482 | 482 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
483 | 483 | } |
484 | 484 | |
@@ -488,19 +488,19 @@ discard block |
||
488 | 488 | public function sandbox_notice() { |
489 | 489 | |
490 | 490 | return sprintf( |
491 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
492 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
493 | - '</a>' |
|
494 | - ); |
|
491 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
492 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
493 | + '</a>' |
|
494 | + ); |
|
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - /** |
|
499 | - * Filters the gateway settings. |
|
500 | - * |
|
501 | - * @param array $admin_settings |
|
502 | - */ |
|
503 | - public function admin_settings( $admin_settings ) { |
|
498 | + /** |
|
499 | + * Filters the gateway settings. |
|
500 | + * |
|
501 | + * @param array $admin_settings |
|
502 | + */ |
|
503 | + public function admin_settings( $admin_settings ) { |
|
504 | 504 | |
505 | 505 | $currencies = sprintf( |
506 | 506 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -510,31 +510,31 @@ discard block |
||
510 | 510 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
511 | 511 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
512 | 512 | |
513 | - // Access tokens. |
|
514 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
515 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
513 | + // Access tokens. |
|
514 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
515 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
516 | 516 | |
517 | - $admin_settings['paypal_connect'] = array( |
|
518 | - 'type' => 'hook', |
|
519 | - 'id' => 'paypal_connect', |
|
520 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
521 | - ); |
|
517 | + $admin_settings['paypal_connect'] = array( |
|
518 | + 'type' => 'hook', |
|
519 | + 'id' => 'paypal_connect', |
|
520 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
521 | + ); |
|
522 | 522 | |
523 | 523 | $admin_settings['paypal_email'] = array( |
524 | 524 | 'type' => 'text', |
525 | - 'class' => 'live-auth-data', |
|
525 | + 'class' => 'live-auth-data', |
|
526 | 526 | 'id' => 'paypal_email', |
527 | 527 | 'name' => __( 'Live Email Address', 'invoicing' ), |
528 | 528 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
529 | 529 | ); |
530 | 530 | |
531 | - $admin_settings['paypal_sandbox_email'] = array( |
|
531 | + $admin_settings['paypal_sandbox_email'] = array( |
|
532 | 532 | 'type' => 'text', |
533 | - 'class' => 'sandbox-auth-data', |
|
533 | + 'class' => 'sandbox-auth-data', |
|
534 | 534 | 'id' => 'paypal_sandbox_email', |
535 | 535 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
536 | 536 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
537 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
537 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
538 | 538 | ); |
539 | 539 | |
540 | 540 | $admin_settings['paypal_ipn_url'] = array( |
@@ -546,29 +546,29 @@ discard block |
||
546 | 546 | 'readonly' => true, |
547 | 547 | ); |
548 | 548 | |
549 | - return $admin_settings; |
|
550 | - } |
|
549 | + return $admin_settings; |
|
550 | + } |
|
551 | 551 | |
552 | - /** |
|
553 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
554 | - * |
|
555 | - * |
|
552 | + /** |
|
553 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
554 | + * |
|
555 | + * |
|
556 | 556 | * @param array $data |
557 | 557 | * @return string |
558 | - */ |
|
559 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
560 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Retrieves the PayPal connect URL. |
|
565 | - * |
|
566 | - * |
|
558 | + */ |
|
559 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
560 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Retrieves the PayPal connect URL. |
|
565 | + * |
|
566 | + * |
|
567 | 567 | * @param bool $is_sandbox |
568 | - * @param string $redirect |
|
568 | + * @param string $redirect |
|
569 | 569 | * @return string |
570 | - */ |
|
571 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
570 | + */ |
|
571 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
572 | 572 | |
573 | 573 | $redirect_url = add_query_arg( |
574 | 574 | array( |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | 'tab' => 'gateways', |
579 | 579 | 'section' => 'paypal', |
580 | 580 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
581 | - 'redirect' => urlencode( $redirect ), |
|
581 | + 'redirect' => urlencode( $redirect ), |
|
582 | 582 | ), |
583 | 583 | admin_url( 'admin.php' ) |
584 | 584 | ); |
@@ -593,12 +593,12 @@ discard block |
||
593 | 593 | |
594 | 594 | } |
595 | 595 | |
596 | - /** |
|
597 | - * Generates settings page js. |
|
598 | - * |
|
596 | + /** |
|
597 | + * Generates settings page js. |
|
598 | + * |
|
599 | 599 | * @return void |
600 | - */ |
|
601 | - public static function display_connect_buttons() { |
|
600 | + */ |
|
601 | + public static function display_connect_buttons() { |
|
602 | 602 | |
603 | 603 | ?> |
604 | 604 | <div class="wpinv-paypal-connect-live"> |
@@ -640,70 +640,70 @@ discard block |
||
640 | 640 | <?php |
641 | 641 | } |
642 | 642 | |
643 | - /** |
|
644 | - * Connects to PayPal. |
|
645 | - * |
|
646 | - * @param array $data Connection data. |
|
647 | - * @return void |
|
648 | - */ |
|
649 | - public function connect_paypal( $data ) { |
|
650 | - |
|
651 | - $sandbox = $this->is_sandbox(); |
|
652 | - $data = wp_unslash( $data ); |
|
653 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
654 | - |
|
655 | - if ( isset( $data['live_mode'] ) ) { |
|
656 | - $sandbox = empty( $data['live_mode'] ); |
|
657 | - } |
|
658 | - |
|
659 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
660 | - wpinv_update_option( 'paypal_active', 1 ); |
|
661 | - |
|
662 | - if ( ! empty( $data['error_description'] ) ) { |
|
663 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
664 | - } else { |
|
665 | - |
|
666 | - // Retrieve the user info. |
|
667 | - $user_info = wp_remote_get( |
|
668 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
669 | - array( |
|
670 | - |
|
671 | - 'headers' => array( |
|
672 | - 'Authorization' => 'Bearer ' . $access_token, |
|
673 | - 'Content-type' => 'application/json', |
|
674 | - ), |
|
675 | - |
|
676 | - ) |
|
677 | - ); |
|
678 | - |
|
679 | - if ( is_wp_error( $user_info ) ) { |
|
680 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
681 | - } else { |
|
682 | - |
|
683 | - // Create application. |
|
684 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
685 | - |
|
686 | - if ( $sandbox ) { |
|
687 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
688 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
689 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
690 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
691 | - } else { |
|
692 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
693 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
694 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
695 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
696 | - } |
|
643 | + /** |
|
644 | + * Connects to PayPal. |
|
645 | + * |
|
646 | + * @param array $data Connection data. |
|
647 | + * @return void |
|
648 | + */ |
|
649 | + public function connect_paypal( $data ) { |
|
650 | + |
|
651 | + $sandbox = $this->is_sandbox(); |
|
652 | + $data = wp_unslash( $data ); |
|
653 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
654 | + |
|
655 | + if ( isset( $data['live_mode'] ) ) { |
|
656 | + $sandbox = empty( $data['live_mode'] ); |
|
657 | + } |
|
658 | + |
|
659 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
660 | + wpinv_update_option( 'paypal_active', 1 ); |
|
661 | + |
|
662 | + if ( ! empty( $data['error_description'] ) ) { |
|
663 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
664 | + } else { |
|
665 | + |
|
666 | + // Retrieve the user info. |
|
667 | + $user_info = wp_remote_get( |
|
668 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
669 | + array( |
|
670 | + |
|
671 | + 'headers' => array( |
|
672 | + 'Authorization' => 'Bearer ' . $access_token, |
|
673 | + 'Content-type' => 'application/json', |
|
674 | + ), |
|
675 | + |
|
676 | + ) |
|
677 | + ); |
|
678 | + |
|
679 | + if ( is_wp_error( $user_info ) ) { |
|
680 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
681 | + } else { |
|
682 | + |
|
683 | + // Create application. |
|
684 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
685 | + |
|
686 | + if ( $sandbox ) { |
|
687 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
688 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
689 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
690 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
691 | + } else { |
|
692 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
693 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
694 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
695 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
696 | + } |
|
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
700 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
701 | 701 | |
702 | - if ( isset( $data['step'] ) ) { |
|
703 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
704 | - } |
|
705 | - wp_redirect( $redirect ); |
|
706 | - exit; |
|
707 | - } |
|
702 | + if ( isset( $data['step'] ) ) { |
|
703 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
704 | + } |
|
705 | + wp_redirect( $redirect ); |
|
706 | + exit; |
|
707 | + } |
|
708 | 708 | |
709 | 709 | } |
@@ -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 class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
90 | + add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2); |
|
91 | + add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal')); |
|
92 | + add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons')); |
|
93 | 93 | parent::__construct(); |
94 | 94 | } |
95 | 95 | |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
105 | + public function process_payment($invoice, $submission_data, $submission) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
108 | + $paypal_redirect = $this->get_request_url($invoice); |
|
109 | 109 | |
110 | 110 | // Add a note about the request url. |
111 | 111 | $invoice->add_note( |
112 | 112 | sprintf( |
113 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
114 | - esc_url( $paypal_redirect ) |
|
113 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
114 | + esc_url($paypal_redirect) |
|
115 | 115 | ), |
116 | 116 | false, |
117 | 117 | false, |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ); |
120 | 120 | |
121 | 121 | // Redirect to PayPal |
122 | - wp_redirect( $paypal_redirect ); |
|
122 | + wp_redirect($paypal_redirect); |
|
123 | 123 | exit; |
124 | 124 | |
125 | 125 | } |
@@ -130,21 +130,21 @@ discard block |
||
130 | 130 | * @param WPInv_Invoice $invoice Invoice object. |
131 | 131 | * @return string |
132 | 132 | */ |
133 | - public function get_request_url( $invoice ) { |
|
133 | + public function get_request_url($invoice) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
139 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
140 | 140 | |
141 | - if ( $invoice->is_recurring() ) { |
|
141 | + if ($invoice->is_recurring()) { |
|
142 | 142 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
143 | 143 | } else { |
144 | 144 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
145 | 145 | } |
146 | 146 | |
147 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
147 | + return add_query_arg($paypal_args, $this->endpoint); |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -154,25 +154,25 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - protected function get_paypal_args( $invoice ) { |
|
157 | + protected function get_paypal_args($invoice) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
160 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
161 | 161 | |
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
162 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
163 | 163 | $force_one_line_item = true; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $paypal_args = apply_filters( |
167 | 167 | 'getpaid_paypal_args', |
168 | 168 | array_merge( |
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + $this->get_transaction_args($invoice), |
|
170 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
171 | 171 | ), |
172 | 172 | $invoice |
173 | 173 | ); |
174 | 174 | |
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
175 | + return $this->fix_request_length($invoice, $paypal_args); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * @param WPInv_Invoice $invoice Invoice object. |
182 | 182 | * @return array |
183 | 183 | */ |
184 | - protected function get_transaction_args( $invoice ) { |
|
184 | + protected function get_transaction_args($invoice) { |
|
185 | 185 | |
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
186 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
187 | 187 | return array( |
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | 'rm' => is_ssl() ? 2 : 1, |
195 | 195 | 'upload' => 1, |
196 | 196 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
197 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
198 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
199 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
200 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
197 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
198 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
199 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
200 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
201 | 201 | 'custom' => $invoice->get_id(), |
202 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
203 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
204 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
205 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
206 | - 'cbt' => get_bloginfo( 'name' ), |
|
202 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
203 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
204 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
205 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
206 | + 'cbt' => get_bloginfo('name'), |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
@@ -215,30 +215,30 @@ discard block |
||
215 | 215 | * @param bool $force_one_line_item Create only one item for this invoice. |
216 | 216 | * @return array |
217 | 217 | */ |
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
218 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
222 | - return $this->get_line_item_args_single_item( $invoice ); |
|
221 | + if ($force_one_line_item) { |
|
222 | + return $this->get_line_item_args_single_item($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Send each line item individually. |
226 | 226 | $line_item_args = array(); |
227 | 227 | |
228 | 228 | // Prepare line items. |
229 | - $this->prepare_line_items( $invoice ); |
|
229 | + $this->prepare_line_items($invoice); |
|
230 | 230 | |
231 | 231 | // Add taxes to the cart |
232 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
233 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
232 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
233 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // Add discount. |
237 | - if ( $invoice->get_total_discount() > 0 ) { |
|
238 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
237 | + if ($invoice->get_total_discount() > 0) { |
|
238 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge($line_item_args, $this->get_line_items()); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | * @param WPInv_Invoice $invoice Invoice object. |
249 | 249 | * @return array |
250 | 250 | */ |
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
251 | + protected function get_line_item_args_single_item($invoice) { |
|
252 | 252 | $this->delete_line_items(); |
253 | 253 | |
254 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
254 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
255 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
256 | 256 | |
257 | 257 | return $this->get_line_items(); |
258 | 258 | } |
@@ -276,19 +276,19 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @param WPInv_Invoice $invoice Invoice object. |
278 | 278 | */ |
279 | - protected function prepare_line_items( $invoice ) { |
|
279 | + protected function prepare_line_items($invoice) { |
|
280 | 280 | $this->delete_line_items(); |
281 | 281 | |
282 | 282 | // Items. |
283 | - foreach ( $invoice->get_items() as $item ) { |
|
283 | + foreach ($invoice->get_items() as $item) { |
|
284 | 284 | $amount = $item->get_price(); |
285 | 285 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
286 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
290 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
291 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * @param float $amount Amount. |
302 | 302 | * @param string $item_number Item number. |
303 | 303 | */ |
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
304 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
305 | + $index = (count($this->line_items) / 4) + 1; |
|
306 | 306 | |
307 | 307 | $item = apply_filters( |
308 | 308 | 'getpaid_paypal_line_item', |
309 | 309 | array( |
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
310 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
311 | 311 | 'quantity' => (float) $quantity, |
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
312 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
313 | 313 | 'item_number' => $item_number, |
314 | 314 | ), |
315 | 315 | $item_name, |
@@ -318,12 +318,12 @@ discard block |
||
318 | 318 | $item_number |
319 | 319 | ); |
320 | 320 | |
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
321 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
322 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -335,19 +335,19 @@ discard block |
||
335 | 335 | * @param array $paypal_args Arguments sent to Paypal in the request. |
336 | 336 | * @return array |
337 | 337 | */ |
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
338 | + protected function fix_request_length($invoice, $paypal_args) { |
|
339 | 339 | $max_paypal_length = 2083; |
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
340 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
341 | 341 | |
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
342 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
343 | 343 | return $paypal_args; |
344 | 344 | } |
345 | 345 | |
346 | 346 | return apply_filters( |
347 | 347 | 'getpaid_paypal_args', |
348 | 348 | array_merge( |
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
349 | + $this->get_transaction_args($invoice), |
|
350 | + $this->get_line_item_args($invoice, true) |
|
351 | 351 | ), |
352 | 352 | $invoice |
353 | 353 | ); |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * @param array $paypal_args PayPal args. |
361 | 361 | * @param WPInv_Invoice $invoice Invoice object. |
362 | 362 | */ |
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
363 | + public function process_subscription($paypal_args, $invoice) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
366 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
367 | 367 | return $paypal_args; |
368 | 368 | } |
369 | 369 | |
@@ -371,23 +371,23 @@ discard block |
||
371 | 371 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
372 | 372 | |
373 | 373 | // Subscription name. |
374 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
374 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
375 | 375 | |
376 | 376 | // Get subscription args. |
377 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1 ) ); |
|
377 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
378 | 378 | $interval = (int) $subscription->get_frequency(); |
379 | 379 | $bill_times = (int) $subscription->get_bill_times(); |
380 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
381 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
382 | - $subscription_item = $invoice->get_recurring( true ); |
|
380 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
381 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
382 | + $subscription_item = $invoice->get_recurring(true); |
|
383 | 383 | |
384 | 384 | // Convert 365 days to 1 year. |
385 | - if ( 'D' == $period && 365 == $interval ) { |
|
385 | + if ('D' == $period && 365 == $interval) { |
|
386 | 386 | $period = 'Y'; |
387 | 387 | $interval = 1; |
388 | 388 | } |
389 | 389 | |
390 | - if ( $subscription_item->has_free_trial() ) { |
|
390 | + if ($subscription_item->has_free_trial()) { |
|
391 | 391 | |
392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
393 | 393 | |
@@ -397,28 +397,28 @@ discard block |
||
397 | 397 | // Trial period. |
398 | 398 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
399 | 399 | |
400 | - } elseif ( $initial_amount != $recurring_amount ) { |
|
400 | + } elseif ($initial_amount != $recurring_amount) { |
|
401 | 401 | |
402 | 402 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
403 | 403 | |
404 | - if ( 1 == $bill_times ) { |
|
404 | + if (1 == $bill_times) { |
|
405 | 405 | $param_number = 3; |
406 | 406 | } else { |
407 | 407 | $param_number = 1; |
408 | 408 | } |
409 | 409 | |
410 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
410 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
411 | 411 | |
412 | 412 | // Sign Up interval |
413 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
413 | + $paypal_args['p' . $param_number] = $interval; |
|
414 | 414 | |
415 | 415 | // Sign Up unit of duration |
416 | - $paypal_args[ 't' . $param_number ] = $period; |
|
416 | + $paypal_args['t' . $param_number] = $period; |
|
417 | 417 | |
418 | 418 | } |
419 | 419 | |
420 | 420 | // We have a recurring payment |
421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
421 | + if (!isset($param_number) || 1 == $param_number) { |
|
422 | 422 | |
423 | 423 | // Subscription price |
424 | 424 | $paypal_args['a3'] = $recurring_amount; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | // Recurring payments |
435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
435 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
436 | 436 | |
437 | 437 | // Non-recurring payments |
438 | 438 | $paypal_args['src'] = 0; |
@@ -441,15 +441,15 @@ discard block |
||
441 | 441 | |
442 | 442 | $paypal_args['src'] = 1; |
443 | 443 | |
444 | - if ( $bill_times > 0 ) { |
|
444 | + if ($bill_times > 0) { |
|
445 | 445 | |
446 | 446 | // An initial period is being used to charge a sign-up fee |
447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
447 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
448 | 448 | $bill_times--; |
449 | 449 | } |
450 | 450 | |
451 | 451 | // Make sure it's not over the max of 52 |
452 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
452 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
453 | 453 | |
454 | 454 | } |
455 | 455 | } |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | $paypal_args['rm'] = 2; |
459 | 459 | |
460 | 460 | // Get rid of redudant items. |
461 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
461 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
462 | 462 | |
463 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
464 | - unset( $paypal_args[ $arg ] ); |
|
463 | + if (isset($paypal_args[$arg])) { |
|
464 | + unset($paypal_args[$arg]); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @return void |
480 | 480 | */ |
481 | 481 | public function verify_ipn() { |
482 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
482 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | public function sandbox_notice() { |
489 | 489 | |
490 | 490 | return sprintf( |
491 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
491 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
492 | 492 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
493 | 493 | '</a>' |
494 | 494 | ); |
@@ -500,49 +500,49 @@ discard block |
||
500 | 500 | * |
501 | 501 | * @param array $admin_settings |
502 | 502 | */ |
503 | - public function admin_settings( $admin_settings ) { |
|
503 | + public function admin_settings($admin_settings) { |
|
504 | 504 | |
505 | 505 | $currencies = sprintf( |
506 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
507 | - implode( ', ', $this->currencies ) |
|
506 | + __('Supported Currencies: %s', 'invoicing'), |
|
507 | + implode(', ', $this->currencies) |
|
508 | 508 | ); |
509 | 509 | |
510 | 510 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
511 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
511 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
512 | 512 | |
513 | 513 | // Access tokens. |
514 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
515 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
514 | + $live_email = wpinv_get_option('paypal_email'); |
|
515 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
516 | 516 | |
517 | 517 | $admin_settings['paypal_connect'] = array( |
518 | 518 | 'type' => 'hook', |
519 | 519 | 'id' => 'paypal_connect', |
520 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
520 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
521 | 521 | ); |
522 | 522 | |
523 | 523 | $admin_settings['paypal_email'] = array( |
524 | 524 | 'type' => 'text', |
525 | 525 | 'class' => 'live-auth-data', |
526 | 526 | 'id' => 'paypal_email', |
527 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
528 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
527 | + 'name' => __('Live Email Address', 'invoicing'), |
|
528 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
529 | 529 | ); |
530 | 530 | |
531 | 531 | $admin_settings['paypal_sandbox_email'] = array( |
532 | 532 | 'type' => 'text', |
533 | 533 | 'class' => 'sandbox-auth-data', |
534 | 534 | 'id' => 'paypal_sandbox_email', |
535 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
536 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
537 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
535 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
536 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
537 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
538 | 538 | ); |
539 | 539 | |
540 | 540 | $admin_settings['paypal_ipn_url'] = array( |
541 | 541 | 'type' => 'ipn_url', |
542 | 542 | 'id' => 'paypal_ipn_url', |
543 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
543 | + 'name' => __('IPN Url', 'invoicing'), |
|
544 | 544 | 'std' => $this->notify_url, |
545 | - 'desc' => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
545 | + 'desc' => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
546 | 546 | 'readonly' => true, |
547 | 547 | ); |
548 | 548 | |
@@ -556,8 +556,8 @@ discard block |
||
556 | 556 | * @param array $data |
557 | 557 | * @return string |
558 | 558 | */ |
559 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
560 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
559 | + public static function maybe_get_connect_url($url = '', $data = array()) { |
|
560 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -568,25 +568,25 @@ discard block |
||
568 | 568 | * @param string $redirect |
569 | 569 | * @return string |
570 | 570 | */ |
571 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
571 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
572 | 572 | |
573 | 573 | $redirect_url = add_query_arg( |
574 | 574 | array( |
575 | 575 | 'getpaid-admin-action' => 'connect_paypal', |
576 | 576 | 'page' => 'wpinv-settings', |
577 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
577 | + 'live_mode' => (int) empty($is_sandbox), |
|
578 | 578 | 'tab' => 'gateways', |
579 | 579 | 'section' => 'paypal', |
580 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
581 | - 'redirect' => urlencode( $redirect ), |
|
580 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
581 | + 'redirect' => urlencode($redirect), |
|
582 | 582 | ), |
583 | - admin_url( 'admin.php' ) |
|
583 | + admin_url('admin.php') |
|
584 | 584 | ); |
585 | 585 | |
586 | 586 | return add_query_arg( |
587 | 587 | array( |
588 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
589 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ), |
|
588 | + 'live_mode' => (int) empty($is_sandbox), |
|
589 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)), |
|
590 | 590 | ), |
591 | 591 | 'https://ayecode.io/oauth/paypal' |
592 | 592 | ); |
@@ -602,10 +602,10 @@ discard block |
||
602 | 602 | |
603 | 603 | ?> |
604 | 604 | <div class="wpinv-paypal-connect-live"> |
605 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a> |
|
605 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a> |
|
606 | 606 | </div> |
607 | 607 | <div class="wpinv-paypal-connect-sandbox"> |
608 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a> |
|
608 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a> |
|
609 | 609 | </div> |
610 | 610 | |
611 | 611 | <script> |
@@ -646,26 +646,26 @@ discard block |
||
646 | 646 | * @param array $data Connection data. |
647 | 647 | * @return void |
648 | 648 | */ |
649 | - public function connect_paypal( $data ) { |
|
649 | + public function connect_paypal($data) { |
|
650 | 650 | |
651 | 651 | $sandbox = $this->is_sandbox(); |
652 | - $data = wp_unslash( $data ); |
|
653 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
652 | + $data = wp_unslash($data); |
|
653 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
654 | 654 | |
655 | - if ( isset( $data['live_mode'] ) ) { |
|
656 | - $sandbox = empty( $data['live_mode'] ); |
|
655 | + if (isset($data['live_mode'])) { |
|
656 | + $sandbox = empty($data['live_mode']); |
|
657 | 657 | } |
658 | 658 | |
659 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
660 | - wpinv_update_option( 'paypal_active', 1 ); |
|
659 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
660 | + wpinv_update_option('paypal_active', 1); |
|
661 | 661 | |
662 | - if ( ! empty( $data['error_description'] ) ) { |
|
663 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
662 | + if (!empty($data['error_description'])) { |
|
663 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
664 | 664 | } else { |
665 | 665 | |
666 | 666 | // Retrieve the user info. |
667 | 667 | $user_info = wp_remote_get( |
668 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
668 | + !$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
669 | 669 | array( |
670 | 670 | |
671 | 671 | 'headers' => array( |
@@ -676,33 +676,33 @@ discard block |
||
676 | 676 | ) |
677 | 677 | ); |
678 | 678 | |
679 | - if ( is_wp_error( $user_info ) ) { |
|
680 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
679 | + if (is_wp_error($user_info)) { |
|
680 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
681 | 681 | } else { |
682 | 682 | |
683 | 683 | // Create application. |
684 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
684 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
685 | 685 | |
686 | - if ( $sandbox ) { |
|
687 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
688 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
689 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
690 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
686 | + if ($sandbox) { |
|
687 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
688 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
689 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
690 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
691 | 691 | } else { |
692 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
693 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
694 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
695 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
692 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
693 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
694 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
695 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
696 | 696 | } |
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
700 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
701 | 701 | |
702 | - if ( isset( $data['step'] ) ) { |
|
703 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
702 | + if (isset($data['step'])) { |
|
703 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
704 | 704 | } |
705 | - wp_redirect( $redirect ); |
|
705 | + wp_redirect($redirect); |
|
706 | 706 | exit; |
707 | 707 | } |
708 | 708 |
@@ -42,92 +42,92 @@ discard block |
||
42 | 42 | <tr class="wpinv-item wpinv-item-<?php echo esc_attr( $invoice->get_status() ); ?>"> |
43 | 43 | <?php |
44 | 44 | |
45 | - foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : |
|
45 | + foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : |
|
46 | 46 | |
47 | - $column_id = sanitize_html_class( $column_id ); |
|
48 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
47 | + $column_id = sanitize_html_class( $column_id ); |
|
48 | + $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
49 | 49 | |
50 | - echo "<td class='" . esc_attr( $column_id . ' ' . $class ) . "'>"; |
|
51 | - switch ( $column_id ) { |
|
50 | + echo "<td class='" . esc_attr( $column_id . ' ' . $class ) . "'>"; |
|
51 | + switch ( $column_id ) { |
|
52 | 52 | |
53 | - case 'invoice-number': |
|
54 | - echo wp_kses_post( wpinv_invoice_link( $invoice ) ); |
|
55 | - break; |
|
53 | + case 'invoice-number': |
|
54 | + echo wp_kses_post( wpinv_invoice_link( $invoice ) ); |
|
55 | + break; |
|
56 | 56 | |
57 | - case 'created-date': |
|
58 | - echo esc_html( getpaid_format_date_value( $invoice->get_date_created() ) ); |
|
59 | - break; |
|
57 | + case 'created-date': |
|
58 | + echo esc_html( getpaid_format_date_value( $invoice->get_date_created() ) ); |
|
59 | + break; |
|
60 | 60 | |
61 | - case 'payment-date': |
|
62 | - if ( $invoice->needs_payment() ) { |
|
63 | - echo '—'; |
|
64 | - } else { |
|
65 | - echo esc_html( getpaid_format_date_value( $invoice->get_date_completed() ) ); |
|
66 | - } |
|
61 | + case 'payment-date': |
|
62 | + if ( $invoice->needs_payment() ) { |
|
63 | + echo '—'; |
|
64 | + } else { |
|
65 | + echo esc_html( getpaid_format_date_value( $invoice->get_date_completed() ) ); |
|
66 | + } |
|
67 | 67 | |
68 | - break; |
|
68 | + break; |
|
69 | 69 | |
70 | - case 'invoice-status': |
|
71 | - echo wp_kses_post( $invoice->get_status_label_html() ); |
|
70 | + case 'invoice-status': |
|
71 | + echo wp_kses_post( $invoice->get_status_label_html() ); |
|
72 | 72 | |
73 | - break; |
|
73 | + break; |
|
74 | 74 | |
75 | - case 'invoice-total': |
|
76 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
75 | + case 'invoice-total': |
|
76 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
77 | 77 | |
78 | - break; |
|
78 | + break; |
|
79 | 79 | |
80 | - case 'invoice-actions': |
|
81 | - $actions = array( |
|
80 | + case 'invoice-actions': |
|
81 | + $actions = array( |
|
82 | 82 | |
83 | - 'pay' => array( |
|
84 | - 'url' => $invoice->get_checkout_payment_url(), |
|
85 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
86 | - 'class' => 'btn-success', |
|
87 | - ), |
|
83 | + 'pay' => array( |
|
84 | + 'url' => $invoice->get_checkout_payment_url(), |
|
85 | + 'name' => __( 'Pay Now', 'invoicing' ), |
|
86 | + 'class' => 'btn-success', |
|
87 | + ), |
|
88 | 88 | |
89 | - 'print' => array( |
|
90 | - 'url' => $invoice->get_view_url(), |
|
91 | - 'name' => __( 'View', 'invoicing' ), |
|
92 | - 'class' => 'btn-secondary', |
|
93 | - 'attrs' => 'target="_blank"', |
|
94 | - ), |
|
95 | - ); |
|
89 | + 'print' => array( |
|
90 | + 'url' => $invoice->get_view_url(), |
|
91 | + 'name' => __( 'View', 'invoicing' ), |
|
92 | + 'class' => 'btn-secondary', |
|
93 | + 'attrs' => 'target="_blank"', |
|
94 | + ), |
|
95 | + ); |
|
96 | 96 | |
97 | - if ( ! $invoice->needs_payment() ) { |
|
98 | - unset( $actions['pay'] ); |
|
99 | - } |
|
97 | + if ( ! $invoice->needs_payment() ) { |
|
98 | + unset( $actions['pay'] ); |
|
99 | + } |
|
100 | 100 | |
101 | - if ( $invoice->needs_payment() ) { |
|
102 | - $actions['delete'] = array( |
|
103 | - 'url' => getpaid_get_authenticated_action_url( 'delete_invoice', add_query_arg( 'invoice_id', $invoice->get_id() ) ), |
|
104 | - 'name' => __( 'Delete', 'invoicing' ), |
|
105 | - 'class' => 'btn-danger', |
|
106 | - ); |
|
107 | - } |
|
101 | + if ( $invoice->needs_payment() ) { |
|
102 | + $actions['delete'] = array( |
|
103 | + 'url' => getpaid_get_authenticated_action_url( 'delete_invoice', add_query_arg( 'invoice_id', $invoice->get_id() ) ), |
|
104 | + 'name' => __( 'Delete', 'invoicing' ), |
|
105 | + 'class' => 'btn-danger', |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | |
109 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type ); |
|
109 | + $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type ); |
|
110 | 110 | |
111 | - foreach ( $actions as $key => $action ) { |
|
112 | - $class = ! empty( $action['class'] ) ? sanitize_html_class( $action['class'] ) : ''; |
|
113 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . esc_attr( $class . ' ' . sanitize_html_class( $key ) ) . '" ' . ( ! empty( $action['attrs'] ) ? esc_html( $action['attrs'] ) : '' ) . '>' . esc_attr( $action['name'] ) . '</a>'; |
|
114 | - } |
|
111 | + foreach ( $actions as $key => $action ) { |
|
112 | + $class = ! empty( $action['class'] ) ? sanitize_html_class( $action['class'] ) : ''; |
|
113 | + echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . esc_attr( $class . ' ' . sanitize_html_class( $key ) ) . '" ' . ( ! empty( $action['attrs'] ) ? esc_html( $action['attrs'] ) : '' ) . '>' . esc_attr( $action['name'] ) . '</a>'; |
|
114 | + } |
|
115 | 115 | |
116 | - break; |
|
116 | + break; |
|
117 | 117 | |
118 | - default: |
|
119 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
120 | - break; |
|
118 | + default: |
|
119 | + do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
120 | + break; |
|
121 | 121 | |
122 | 122 | |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
125 | + do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
126 | 126 | |
127 | - echo '</td>'; |
|
127 | + echo '</td>'; |
|
128 | 128 | |
129 | - endforeach; |
|
130 | - ?> |
|
129 | + endforeach; |
|
130 | + ?> |
|
131 | 131 | </tr> |
132 | 132 | |
133 | 133 | <?php endforeach; ?> |
@@ -141,18 +141,18 @@ discard block |
||
141 | 141 | <?php if ( 1 < $invoices->max_num_pages ) : ?> |
142 | 142 | <div class="invoicing-Pagination"> |
143 | 143 | <?php |
144 | - $big = 999999; |
|
145 | - |
|
146 | - echo wp_kses_post( |
|
147 | - paginate_links( |
|
148 | - array( |
|
149 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
150 | - 'format' => '?paged=%#%', |
|
151 | - 'total' => $invoices->max_num_pages, |
|
152 | - ) |
|
153 | - ) |
|
144 | + $big = 999999; |
|
145 | + |
|
146 | + echo wp_kses_post( |
|
147 | + paginate_links( |
|
148 | + array( |
|
149 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
150 | + 'format' => '?paged=%#%', |
|
151 | + 'total' => $invoices->max_num_pages, |
|
152 | + ) |
|
153 | + ) |
|
154 | 154 | ); |
155 | - ?> |
|
155 | + ?> |
|
156 | 156 | </div> |
157 | 157 | <?php endif; ?> |
158 | 158 |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Current page. |
13 | -$current_page = empty( $_GET['page'] ) ? 1 : absint( $_GET['page'] ); |
|
13 | +$current_page = empty($_GET['page']) ? 1 : absint($_GET['page']); |
|
14 | 14 | |
15 | 15 | // Fires before displaying user invoices. |
16 | -do_action( 'wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type ); |
|
16 | +do_action('wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type); |
|
17 | 17 | |
18 | 18 | wpinv_print_errors(); |
19 | 19 | |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | |
22 | 22 | |
23 | 23 | <div class="table-responsive"> |
24 | - <table class="table table-bordered table-hover getpaid-user-invoices <?php echo esc_attr( $post_type ); ?>"> |
|
24 | + <table class="table table-bordered table-hover getpaid-user-invoices <?php echo esc_attr($post_type); ?>"> |
|
25 | 25 | |
26 | 26 | |
27 | 27 | <thead> |
28 | 28 | <tr> |
29 | 29 | |
30 | - <?php foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : ?> |
|
31 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo ( ! empty( $column_name['class'] ) ? sanitize_html_class( $column_name['class'] ) : ''); ?> border-bottom-0"> |
|
32 | - <span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span> |
|
30 | + <?php foreach (wpinv_get_user_invoices_columns($post_type) as $column_id => $column_name) : ?> |
|
31 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? sanitize_html_class($column_name['class']) : ''); ?> border-bottom-0"> |
|
32 | + <span class="nobr"><?php echo esc_html($column_name['title']); ?></span> |
|
33 | 33 | </th> |
34 | 34 | <?php endforeach; ?> |
35 | 35 | |
@@ -39,43 +39,43 @@ discard block |
||
39 | 39 | |
40 | 40 | |
41 | 41 | <tbody> |
42 | - <?php foreach ( $invoices->invoices as $invoice ) : ?> |
|
42 | + <?php foreach ($invoices->invoices as $invoice) : ?> |
|
43 | 43 | |
44 | - <tr class="wpinv-item wpinv-item-<?php echo esc_attr( $invoice->get_status() ); ?>"> |
|
44 | + <tr class="wpinv-item wpinv-item-<?php echo esc_attr($invoice->get_status()); ?>"> |
|
45 | 45 | <?php |
46 | 46 | |
47 | - foreach ( wpinv_get_user_invoices_columns( $post_type ) as $column_id => $column_name ) : |
|
47 | + foreach (wpinv_get_user_invoices_columns($post_type) as $column_id => $column_name) : |
|
48 | 48 | |
49 | - $column_id = sanitize_html_class( $column_id ); |
|
50 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
49 | + $column_id = sanitize_html_class($column_id); |
|
50 | + $class = empty($column_name['class']) ? '' : sanitize_html_class($column_name['class']); |
|
51 | 51 | |
52 | - echo "<td class='" . esc_attr( $column_id . ' ' . $class ) . "'>"; |
|
53 | - switch ( $column_id ) { |
|
52 | + echo "<td class='" . esc_attr($column_id . ' ' . $class) . "'>"; |
|
53 | + switch ($column_id) { |
|
54 | 54 | |
55 | 55 | case 'invoice-number': |
56 | - echo wp_kses_post( wpinv_invoice_link( $invoice ) ); |
|
56 | + echo wp_kses_post(wpinv_invoice_link($invoice)); |
|
57 | 57 | break; |
58 | 58 | |
59 | 59 | case 'created-date': |
60 | - echo esc_html( getpaid_format_date_value( $invoice->get_date_created() ) ); |
|
60 | + echo esc_html(getpaid_format_date_value($invoice->get_date_created())); |
|
61 | 61 | break; |
62 | 62 | |
63 | 63 | case 'payment-date': |
64 | - if ( $invoice->needs_payment() ) { |
|
64 | + if ($invoice->needs_payment()) { |
|
65 | 65 | echo '—'; |
66 | 66 | } else { |
67 | - echo esc_html( getpaid_format_date_value( $invoice->get_date_completed() ) ); |
|
67 | + echo esc_html(getpaid_format_date_value($invoice->get_date_completed())); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | break; |
71 | 71 | |
72 | 72 | case 'invoice-status': |
73 | - echo wp_kses_post( $invoice->get_status_label_html() ); |
|
73 | + echo wp_kses_post($invoice->get_status_label_html()); |
|
74 | 74 | |
75 | 75 | break; |
76 | 76 | |
77 | 77 | case 'invoice-total': |
78 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
78 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
79 | 79 | |
80 | 80 | break; |
81 | 81 | |
@@ -84,47 +84,47 @@ discard block |
||
84 | 84 | |
85 | 85 | 'pay' => array( |
86 | 86 | 'url' => $invoice->get_checkout_payment_url(), |
87 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
87 | + 'name' => __('Pay Now', 'invoicing'), |
|
88 | 88 | 'class' => 'btn-success', |
89 | 89 | ), |
90 | 90 | |
91 | 91 | 'print' => array( |
92 | 92 | 'url' => $invoice->get_view_url(), |
93 | - 'name' => __( 'View', 'invoicing' ), |
|
93 | + 'name' => __('View', 'invoicing'), |
|
94 | 94 | 'class' => 'btn-secondary', |
95 | 95 | 'attrs' => 'target="_blank"', |
96 | 96 | ), |
97 | 97 | ); |
98 | 98 | |
99 | - if ( ! $invoice->needs_payment() ) { |
|
100 | - unset( $actions['pay'] ); |
|
99 | + if (!$invoice->needs_payment()) { |
|
100 | + unset($actions['pay']); |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $invoice->needs_payment() ) { |
|
103 | + if ($invoice->needs_payment()) { |
|
104 | 104 | $actions['delete'] = array( |
105 | - 'url' => getpaid_get_authenticated_action_url( 'delete_invoice', add_query_arg( 'invoice_id', $invoice->get_id() ) ), |
|
106 | - 'name' => __( 'Delete', 'invoicing' ), |
|
105 | + 'url' => getpaid_get_authenticated_action_url('delete_invoice', add_query_arg('invoice_id', $invoice->get_id())), |
|
106 | + 'name' => __('Delete', 'invoicing'), |
|
107 | 107 | 'class' => 'btn-danger', |
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice, $post_type ); |
|
111 | + $actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice, $post_type); |
|
112 | 112 | |
113 | - foreach ( $actions as $key => $action ) { |
|
114 | - $class = ! empty( $action['class'] ) ? sanitize_html_class( $action['class'] ) : ''; |
|
115 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . esc_attr( $class . ' ' . sanitize_html_class( $key ) ) . '" ' . ( ! empty( $action['attrs'] ) ? esc_html( $action['attrs'] ) : '' ) . '>' . esc_attr( $action['name'] ) . '</a>'; |
|
113 | + foreach ($actions as $key => $action) { |
|
114 | + $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
115 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm btn-block ' . esc_attr($class . ' ' . sanitize_html_class($key)) . '" ' . (!empty($action['attrs']) ? esc_html($action['attrs']) : '') . '>' . esc_attr($action['name']) . '</a>'; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | break; |
119 | 119 | |
120 | 120 | default: |
121 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
121 | + do_action("wpinv_user_invoices_column_$column_id", $invoice); |
|
122 | 122 | break; |
123 | 123 | |
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
127 | + do_action("wpinv_user_invoices_column_after_$column_id", $invoice); |
|
128 | 128 | |
129 | 129 | echo '</td>'; |
130 | 130 | |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | </table> |
139 | 139 | </div> |
140 | 140 | |
141 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
141 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
142 | 142 | |
143 | - <?php if ( 1 < $invoices->max_num_pages ) : ?> |
|
143 | + <?php if (1 < $invoices->max_num_pages) : ?> |
|
144 | 144 | <div class="invoicing-Pagination"> |
145 | 145 | <?php |
146 | 146 | $big = 999999; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | echo wp_kses_post( |
149 | 149 | paginate_links( |
150 | 150 | array( |
151 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
151 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
152 | 152 | 'format' => '?paged=%#%', |
153 | 153 | 'total' => $invoices->max_num_pages, |
154 | 154 | ) |
@@ -158,4 +158,4 @@ discard block |
||
158 | 158 | </div> |
159 | 159 | <?php endif; ?> |
160 | 160 | |
161 | -<?php do_action( 'wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type ); ?> |
|
161 | +<?php do_action('wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages, $post_type); ?> |
@@ -8,45 +8,45 @@ discard block |
||
8 | 8 | * @var WPInv_Invoice $invoice |
9 | 9 | * @var array $columns |
10 | 10 | */ |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | -$meta_data = getpaid_get_invoice_meta( $invoice ); |
|
13 | +$meta_data = getpaid_get_invoice_meta($invoice); |
|
14 | 14 | |
15 | -if ( isset( $meta_data['status'] ) ) { |
|
15 | +if (isset($meta_data['status'])) { |
|
16 | 16 | $meta_data['status']['value'] = $invoice->get_status_nicename(); |
17 | 17 | } |
18 | 18 | |
19 | -do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); |
|
19 | +do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); |
|
20 | 20 | |
21 | 21 | ?> |
22 | 22 | |
23 | 23 | <div id="wpinv-email-details"> |
24 | 24 | |
25 | 25 | <h3 class="invoice-details-title"> |
26 | - <?php echo sprintf( esc_html__( '%s Details', 'invoicing' ), esc_html( ucfirst( $invoice->get_invoice_quote_type() ) ) ); ?> |
|
26 | + <?php echo sprintf(esc_html__('%s Details', 'invoicing'), esc_html(ucfirst($invoice->get_invoice_quote_type()))); ?> |
|
27 | 27 | </h3> |
28 | 28 | |
29 | 29 | <table class="table table-bordered table-sm"> |
30 | 30 | |
31 | - <?php foreach ( $meta_data as $key => $data ) : ?> |
|
31 | + <?php foreach ($meta_data as $key => $data) : ?> |
|
32 | 32 | |
33 | - <?php if ( ! empty( $data['value'] ) ) : ?> |
|
33 | + <?php if (!empty($data['value'])) : ?> |
|
34 | 34 | |
35 | - <?php do_action( "getpaid_before_email_details_$key", $invoice, $data ); ?> |
|
35 | + <?php do_action("getpaid_before_email_details_$key", $invoice, $data); ?> |
|
36 | 36 | |
37 | - <tr class="getpaid-email-details-<?php echo esc_attr( $key ); ?>"> |
|
37 | + <tr class="getpaid-email-details-<?php echo esc_attr($key); ?>"> |
|
38 | 38 | |
39 | 39 | <td class="getpaid-lable-td"> |
40 | - <?php echo esc_html( $data['label'] ); ?> |
|
40 | + <?php echo esc_html($data['label']); ?> |
|
41 | 41 | </td> |
42 | 42 | |
43 | 43 | <td class="getpaid-value-td"> |
44 | - <span class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>-value"><?php echo wp_kses_post( $data['value'] ); ?></span> |
|
44 | + <span class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>-value"><?php echo wp_kses_post($data['value']); ?></span> |
|
45 | 45 | </td> |
46 | 46 | |
47 | 47 | </tr> |
48 | 48 | |
49 | - <?php do_action( "getpaid_after_email_details_$key", $invoice, $data ); ?> |
|
49 | + <?php do_action("getpaid_after_email_details_$key", $invoice, $data); ?> |
|
50 | 50 | |
51 | 51 | <?php endif; ?> |
52 | 52 | |
@@ -56,4 +56,4 @@ discard block |
||
56 | 56 | |
57 | 57 | </div> |
58 | 58 | |
59 | -<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?> |
|
59 | +<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?> |