@@ -5,237 +5,237 @@ |
||
5 | 5 | |
6 | 6 | abstract class Wpinv_DB { |
7 | 7 | |
8 | - /** |
|
9 | - * The name of our database table |
|
10 | - * |
|
11 | - * @access public |
|
12 | - * @since 1.0.0 |
|
13 | - */ |
|
14 | - public $table_name; |
|
15 | - |
|
16 | - /** |
|
17 | - * The version of our database table |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @since 1.0.0 |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * The name of the primary column |
|
26 | - * |
|
27 | - * @access public |
|
28 | - * @since 1.0.0 |
|
29 | - */ |
|
30 | - public $primary_key; |
|
31 | - |
|
32 | - /** |
|
33 | - * Get things started |
|
34 | - * |
|
35 | - * @access public |
|
36 | - * @since 1.0.0 |
|
37 | - */ |
|
38 | - public function __construct() {} |
|
39 | - |
|
40 | - /** |
|
41 | - * Whitelist of columns |
|
42 | - * |
|
43 | - * @access public |
|
44 | - * @since 1.0.0 |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function get_columns() { |
|
48 | - return array(); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Default column values |
|
53 | - * |
|
54 | - * @access public |
|
55 | - * @since 1.0.0 |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function get_column_defaults() { |
|
59 | - return array(); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Retrieve a row by the primary key |
|
64 | - * |
|
65 | - * @access public |
|
66 | - * @since 1.0.0 |
|
67 | - * @return object |
|
68 | - */ |
|
69 | - public function get( $row_id ) { |
|
70 | - global $wpdb; |
|
71 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Retrieve a row by a specific column / value |
|
76 | - * |
|
77 | - * @access public |
|
78 | - * @since 1.0.0 |
|
79 | - * @return object |
|
80 | - */ |
|
81 | - public function get_by( $column, $row_id ) { |
|
82 | - global $wpdb; |
|
83 | - $column = esc_sql( $column ); |
|
84 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Retrieve a specific column's value by the primary key |
|
89 | - * |
|
90 | - * @access public |
|
91 | - * @since 1.0.0 |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function get_column( $column, $row_id ) { |
|
95 | - global $wpdb; |
|
96 | - $column = esc_sql( $column ); |
|
97 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Retrieve a specific column's value by the the specified column / value |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @since 1.0.0 |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function get_column_by( $column, $column_where, $column_value ) { |
|
108 | - global $wpdb; |
|
109 | - $column_where = esc_sql( $column_where ); |
|
110 | - $column = esc_sql( $column ); |
|
111 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Insert a new row |
|
116 | - * |
|
117 | - * @access public |
|
118 | - * @since 1.0.0 |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function insert( $data, $type = '' ) { |
|
122 | - global $wpdb; |
|
123 | - |
|
124 | - // Set default values |
|
125 | - $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
126 | - |
|
127 | - do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
128 | - |
|
129 | - // Initialise column format array |
|
130 | - $column_formats = $this->get_columns(); |
|
131 | - |
|
132 | - // Force fields to lower case |
|
133 | - $data = array_change_key_case( $data ); |
|
134 | - |
|
135 | - // White list columns |
|
136 | - $data = array_intersect_key( $data, $column_formats ); |
|
137 | - |
|
138 | - // Reorder $column_formats to match the order of columns given in $data |
|
139 | - $data_keys = array_keys( $data ); |
|
140 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
141 | - |
|
142 | - $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
143 | - $wpdb_insert_id = $wpdb->insert_id; |
|
144 | - |
|
145 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
146 | - |
|
147 | - return $wpdb_insert_id; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Update a row |
|
152 | - * |
|
153 | - * @access public |
|
154 | - * @since 1.0.0 |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function update( $row_id, $data = array(), $where = '' ) { |
|
158 | - |
|
159 | - global $wpdb; |
|
160 | - |
|
161 | - // Row ID must be positive integer |
|
162 | - $row_id = absint( $row_id ); |
|
163 | - |
|
164 | - if( empty( $row_id ) ) { |
|
165 | - return false; |
|
166 | - } |
|
167 | - |
|
168 | - if( empty( $where ) ) { |
|
169 | - $where = $this->primary_key; |
|
170 | - } |
|
171 | - |
|
172 | - // Initialise column format array |
|
173 | - $column_formats = $this->get_columns(); |
|
174 | - |
|
175 | - // Force fields to lower case |
|
176 | - $data = array_change_key_case( $data ); |
|
177 | - |
|
178 | - // White list columns |
|
179 | - $data = array_intersect_key( $data, $column_formats ); |
|
180 | - |
|
181 | - // Reorder $column_formats to match the order of columns given in $data |
|
182 | - $data_keys = array_keys( $data ); |
|
183 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
184 | - |
|
185 | - if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - return true; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Delete a row identified by the primary key |
|
194 | - * |
|
195 | - * @access public |
|
196 | - * @since 1.0.0 |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function delete( $row_id = 0 ) { |
|
200 | - |
|
201 | - global $wpdb; |
|
202 | - |
|
203 | - // Row ID must be positive integer |
|
204 | - $row_id = absint( $row_id ); |
|
205 | - |
|
206 | - if( empty( $row_id ) ) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
211 | - return false; |
|
212 | - } |
|
213 | - |
|
214 | - return true; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Check if the given table exists |
|
219 | - * |
|
220 | - * @since 2.4 |
|
221 | - * @param string $table The table name |
|
222 | - * @return bool If the table name exists |
|
223 | - */ |
|
224 | - public function table_exists( $table ) { |
|
225 | - global $wpdb; |
|
226 | - $table = sanitize_text_field( $table ); |
|
227 | - |
|
228 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Check if the table was ever installed |
|
233 | - * |
|
234 | - * @since 2.4 |
|
235 | - * @return bool Returns if the customers table was installed and upgrade routine run |
|
236 | - */ |
|
237 | - public function installed() { |
|
238 | - return $this->table_exists( $this->table_name ); |
|
239 | - } |
|
8 | + /** |
|
9 | + * The name of our database table |
|
10 | + * |
|
11 | + * @access public |
|
12 | + * @since 1.0.0 |
|
13 | + */ |
|
14 | + public $table_name; |
|
15 | + |
|
16 | + /** |
|
17 | + * The version of our database table |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @since 1.0.0 |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * The name of the primary column |
|
26 | + * |
|
27 | + * @access public |
|
28 | + * @since 1.0.0 |
|
29 | + */ |
|
30 | + public $primary_key; |
|
31 | + |
|
32 | + /** |
|
33 | + * Get things started |
|
34 | + * |
|
35 | + * @access public |
|
36 | + * @since 1.0.0 |
|
37 | + */ |
|
38 | + public function __construct() {} |
|
39 | + |
|
40 | + /** |
|
41 | + * Whitelist of columns |
|
42 | + * |
|
43 | + * @access public |
|
44 | + * @since 1.0.0 |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function get_columns() { |
|
48 | + return array(); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Default column values |
|
53 | + * |
|
54 | + * @access public |
|
55 | + * @since 1.0.0 |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function get_column_defaults() { |
|
59 | + return array(); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Retrieve a row by the primary key |
|
64 | + * |
|
65 | + * @access public |
|
66 | + * @since 1.0.0 |
|
67 | + * @return object |
|
68 | + */ |
|
69 | + public function get( $row_id ) { |
|
70 | + global $wpdb; |
|
71 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Retrieve a row by a specific column / value |
|
76 | + * |
|
77 | + * @access public |
|
78 | + * @since 1.0.0 |
|
79 | + * @return object |
|
80 | + */ |
|
81 | + public function get_by( $column, $row_id ) { |
|
82 | + global $wpdb; |
|
83 | + $column = esc_sql( $column ); |
|
84 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Retrieve a specific column's value by the primary key |
|
89 | + * |
|
90 | + * @access public |
|
91 | + * @since 1.0.0 |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function get_column( $column, $row_id ) { |
|
95 | + global $wpdb; |
|
96 | + $column = esc_sql( $column ); |
|
97 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) ); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Retrieve a specific column's value by the the specified column / value |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @since 1.0.0 |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function get_column_by( $column, $column_where, $column_value ) { |
|
108 | + global $wpdb; |
|
109 | + $column_where = esc_sql( $column_where ); |
|
110 | + $column = esc_sql( $column ); |
|
111 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Insert a new row |
|
116 | + * |
|
117 | + * @access public |
|
118 | + * @since 1.0.0 |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function insert( $data, $type = '' ) { |
|
122 | + global $wpdb; |
|
123 | + |
|
124 | + // Set default values |
|
125 | + $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
126 | + |
|
127 | + do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
128 | + |
|
129 | + // Initialise column format array |
|
130 | + $column_formats = $this->get_columns(); |
|
131 | + |
|
132 | + // Force fields to lower case |
|
133 | + $data = array_change_key_case( $data ); |
|
134 | + |
|
135 | + // White list columns |
|
136 | + $data = array_intersect_key( $data, $column_formats ); |
|
137 | + |
|
138 | + // Reorder $column_formats to match the order of columns given in $data |
|
139 | + $data_keys = array_keys( $data ); |
|
140 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
141 | + |
|
142 | + $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
143 | + $wpdb_insert_id = $wpdb->insert_id; |
|
144 | + |
|
145 | + do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
146 | + |
|
147 | + return $wpdb_insert_id; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Update a row |
|
152 | + * |
|
153 | + * @access public |
|
154 | + * @since 1.0.0 |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function update( $row_id, $data = array(), $where = '' ) { |
|
158 | + |
|
159 | + global $wpdb; |
|
160 | + |
|
161 | + // Row ID must be positive integer |
|
162 | + $row_id = absint( $row_id ); |
|
163 | + |
|
164 | + if( empty( $row_id ) ) { |
|
165 | + return false; |
|
166 | + } |
|
167 | + |
|
168 | + if( empty( $where ) ) { |
|
169 | + $where = $this->primary_key; |
|
170 | + } |
|
171 | + |
|
172 | + // Initialise column format array |
|
173 | + $column_formats = $this->get_columns(); |
|
174 | + |
|
175 | + // Force fields to lower case |
|
176 | + $data = array_change_key_case( $data ); |
|
177 | + |
|
178 | + // White list columns |
|
179 | + $data = array_intersect_key( $data, $column_formats ); |
|
180 | + |
|
181 | + // Reorder $column_formats to match the order of columns given in $data |
|
182 | + $data_keys = array_keys( $data ); |
|
183 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
184 | + |
|
185 | + if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + return true; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Delete a row identified by the primary key |
|
194 | + * |
|
195 | + * @access public |
|
196 | + * @since 1.0.0 |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function delete( $row_id = 0 ) { |
|
200 | + |
|
201 | + global $wpdb; |
|
202 | + |
|
203 | + // Row ID must be positive integer |
|
204 | + $row_id = absint( $row_id ); |
|
205 | + |
|
206 | + if( empty( $row_id ) ) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
211 | + return false; |
|
212 | + } |
|
213 | + |
|
214 | + return true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Check if the given table exists |
|
219 | + * |
|
220 | + * @since 2.4 |
|
221 | + * @param string $table The table name |
|
222 | + * @return bool If the table name exists |
|
223 | + */ |
|
224 | + public function table_exists( $table ) { |
|
225 | + global $wpdb; |
|
226 | + $table = sanitize_text_field( $table ); |
|
227 | + |
|
228 | + return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Check if the table was ever installed |
|
233 | + * |
|
234 | + * @since 2.4 |
|
235 | + * @return bool Returns if the customers table was installed and upgrade routine run |
|
236 | + */ |
|
237 | + public function installed() { |
|
238 | + return $this->table_exists( $this->table_name ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -30,36 +30,36 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | function wpinv_can_checkout() { |
33 | - $can_checkout = true; // Always true for now |
|
33 | + $can_checkout = true; // Always true for now |
|
34 | 34 | |
35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
35 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function wpinv_get_success_page_uri() { |
39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
40 | - $page_id = absint( $page_id ); |
|
39 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
40 | + $page_id = absint( $page_id ); |
|
41 | 41 | |
42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
42 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function wpinv_get_history_page_uri() { |
46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
47 | - $page_id = absint( $page_id ); |
|
46 | + $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
47 | + $page_id = absint( $page_id ); |
|
48 | 48 | |
49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
49 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function wpinv_is_success_page() { |
53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
53 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
54 | + $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
55 | 55 | |
56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
56 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_invoice_history_page() { |
60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
61 | - $ret = $ret ? is_page( $ret ) : false; |
|
62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
60 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
61 | + $ret = $ret ? is_page( $ret ) : false; |
|
62 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | function wpinv_is_subscriptions_history_page() { |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | function wpinv_send_to_success_page( $args = null ) { |
72 | - $redirect = wpinv_get_success_page_uri(); |
|
72 | + $redirect = wpinv_get_success_page_uri(); |
|
73 | 73 | |
74 | 74 | if ( !empty( $args ) ) { |
75 | 75 | // Check for backward compatibility |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
93 | 93 | |
94 | 94 | if ( !empty( $args ) ) { |
95 | 95 | // Check for backward compatibility |
@@ -109,72 +109,72 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
116 | - // Check for backward compatibility |
|
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
115 | + if ( !empty( $args ) ) { |
|
116 | + // Check for backward compatibility |
|
117 | + if ( is_string( $args ) ) |
|
118 | + $args = str_replace( '?', '', $args ); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args( $args ); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
123 | - } |
|
122 | + $uri = add_query_arg( $args, $uri ); |
|
123 | + } |
|
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | - } |
|
129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | + } |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function wpinv_send_back_to_checkout( $args = array() ) { |
137 | - $redirect = wpinv_get_checkout_uri(); |
|
137 | + $redirect = wpinv_get_checkout_uri(); |
|
138 | 138 | |
139 | - if ( ! empty( $args ) ) { |
|
140 | - // Check for backward compatibility |
|
141 | - if ( is_string( $args ) ) |
|
142 | - $args = str_replace( '?', '', $args ); |
|
139 | + if ( ! empty( $args ) ) { |
|
140 | + // Check for backward compatibility |
|
141 | + if ( is_string( $args ) ) |
|
142 | + $args = str_replace( '?', '', $args ); |
|
143 | 143 | |
144 | - $args = wp_parse_args( $args ); |
|
144 | + $args = wp_parse_args( $args ); |
|
145 | 145 | |
146 | - $redirect = add_query_arg( $args, $redirect ); |
|
147 | - } |
|
146 | + $redirect = add_query_arg( $args, $redirect ); |
|
147 | + } |
|
148 | 148 | |
149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
150 | - exit; |
|
149 | + wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
150 | + exit; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | function wpinv_get_success_page_url( $query_string = null ) { |
154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
155 | - $success_page = get_permalink( $success_page ); |
|
154 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
155 | + $success_page = get_permalink( $success_page ); |
|
156 | 156 | |
157 | - if ( $query_string ) |
|
158 | - $success_page .= $query_string; |
|
157 | + if ( $query_string ) |
|
158 | + $success_page .= $query_string; |
|
159 | 159 | |
160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
160 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
164 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
166 | 166 | |
167 | - if ( $extras ) |
|
168 | - $uri .= $extras; |
|
167 | + if ( $extras ) |
|
168 | + $uri .= $extras; |
|
169 | 169 | |
170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
170 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_is_failed_transaction_page() { |
174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
174 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
175 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
177 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -218,262 +218,262 @@ discard block |
||
218 | 218 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
219 | 219 | |
220 | 220 | function wpinv_process_paypal_ipn() { |
221 | - // Check the request method is POST |
|
222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
223 | - return; |
|
224 | - } |
|
225 | - |
|
226 | - // Set initial post data to empty string |
|
227 | - $post_data = ''; |
|
228 | - |
|
229 | - // Fallback just in case post_max_size is lower than needed |
|
230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
231 | - $post_data = file_get_contents( 'php://input' ); |
|
232 | - } else { |
|
233 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
234 | - ini_set( 'post_max_size', '12M' ); |
|
235 | - } |
|
236 | - // Start the encoded data collection with notification command |
|
237 | - $encoded_data = 'cmd=_notify-validate'; |
|
238 | - |
|
239 | - // Get current arg separator |
|
240 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
241 | - |
|
242 | - // Verify there is a post_data |
|
243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
244 | - // Append the data |
|
245 | - $encoded_data .= $arg_separator.$post_data; |
|
246 | - } else { |
|
247 | - // Check if POST is empty |
|
248 | - if ( empty( $_POST ) ) { |
|
249 | - // Nothing to do |
|
250 | - return; |
|
251 | - } else { |
|
252 | - // Loop through each POST |
|
253 | - foreach ( $_POST as $key => $value ) { |
|
254 | - // Encode the value and append the data |
|
255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - // Convert collected post data to an array |
|
261 | - parse_str( $encoded_data, $encoded_data_array ); |
|
262 | - |
|
263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
265 | - $new_key = str_replace( '&', '&', $key ); |
|
266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
267 | - |
|
268 | - unset( $encoded_data_array[ $key ] ); |
|
269 | - $encoded_data_array[ $new_key ] = $value; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - // Get the PayPal redirect uri |
|
274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
275 | - |
|
276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
277 | - // Validate the IPN |
|
278 | - |
|
279 | - $remote_post_vars = array( |
|
280 | - 'method' => 'POST', |
|
281 | - 'timeout' => 45, |
|
282 | - 'redirection' => 5, |
|
283 | - 'httpversion' => '1.1', |
|
284 | - 'blocking' => true, |
|
285 | - 'headers' => array( |
|
286 | - 'host' => 'www.paypal.com', |
|
287 | - 'connection' => 'close', |
|
288 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
289 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
290 | - |
|
291 | - ), |
|
292 | - 'sslverify' => false, |
|
293 | - 'body' => $encoded_data_array |
|
294 | - ); |
|
295 | - |
|
296 | - // Get response |
|
297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
298 | - |
|
299 | - if ( is_wp_error( $api_response ) ) { |
|
300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
301 | - return; // Something went wrong |
|
302 | - } |
|
303 | - |
|
304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
306 | - return; // Response not okay |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - // Check if $post_data_array has been populated |
|
311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
312 | - return; |
|
313 | - |
|
314 | - $defaults = array( |
|
315 | - 'txn_type' => '', |
|
316 | - 'payment_status' => '' |
|
317 | - ); |
|
318 | - |
|
319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
320 | - |
|
321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
221 | + // Check the request method is POST |
|
222 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
223 | + return; |
|
224 | + } |
|
225 | + |
|
226 | + // Set initial post data to empty string |
|
227 | + $post_data = ''; |
|
228 | + |
|
229 | + // Fallback just in case post_max_size is lower than needed |
|
230 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
231 | + $post_data = file_get_contents( 'php://input' ); |
|
232 | + } else { |
|
233 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
234 | + ini_set( 'post_max_size', '12M' ); |
|
235 | + } |
|
236 | + // Start the encoded data collection with notification command |
|
237 | + $encoded_data = 'cmd=_notify-validate'; |
|
238 | + |
|
239 | + // Get current arg separator |
|
240 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
241 | + |
|
242 | + // Verify there is a post_data |
|
243 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
244 | + // Append the data |
|
245 | + $encoded_data .= $arg_separator.$post_data; |
|
246 | + } else { |
|
247 | + // Check if POST is empty |
|
248 | + if ( empty( $_POST ) ) { |
|
249 | + // Nothing to do |
|
250 | + return; |
|
251 | + } else { |
|
252 | + // Loop through each POST |
|
253 | + foreach ( $_POST as $key => $value ) { |
|
254 | + // Encode the value and append the data |
|
255 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + // Convert collected post data to an array |
|
261 | + parse_str( $encoded_data, $encoded_data_array ); |
|
262 | + |
|
263 | + foreach ( $encoded_data_array as $key => $value ) { |
|
264 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
265 | + $new_key = str_replace( '&', '&', $key ); |
|
266 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
267 | + |
|
268 | + unset( $encoded_data_array[ $key ] ); |
|
269 | + $encoded_data_array[ $new_key ] = $value; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + // Get the PayPal redirect uri |
|
274 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
275 | + |
|
276 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
277 | + // Validate the IPN |
|
278 | + |
|
279 | + $remote_post_vars = array( |
|
280 | + 'method' => 'POST', |
|
281 | + 'timeout' => 45, |
|
282 | + 'redirection' => 5, |
|
283 | + 'httpversion' => '1.1', |
|
284 | + 'blocking' => true, |
|
285 | + 'headers' => array( |
|
286 | + 'host' => 'www.paypal.com', |
|
287 | + 'connection' => 'close', |
|
288 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
289 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
290 | + |
|
291 | + ), |
|
292 | + 'sslverify' => false, |
|
293 | + 'body' => $encoded_data_array |
|
294 | + ); |
|
295 | + |
|
296 | + // Get response |
|
297 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
298 | + |
|
299 | + if ( is_wp_error( $api_response ) ) { |
|
300 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
301 | + return; // Something went wrong |
|
302 | + } |
|
303 | + |
|
304 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
305 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
306 | + return; // Response not okay |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + // Check if $post_data_array has been populated |
|
311 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
312 | + return; |
|
313 | + |
|
314 | + $defaults = array( |
|
315 | + 'txn_type' => '', |
|
316 | + 'payment_status' => '' |
|
317 | + ); |
|
318 | + |
|
319 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
320 | + |
|
321 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
322 | 322 | |
323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
324 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
325 | - |
|
326 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
327 | - // Allow PayPal IPN types to be processed separately |
|
328 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
329 | - } else { |
|
330 | - // Fallback to web accept just in case the txn_type isn't present |
|
331 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
332 | - } |
|
333 | - exit; |
|
323 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
324 | + wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
325 | + |
|
326 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
327 | + // Allow PayPal IPN types to be processed separately |
|
328 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
329 | + } else { |
|
330 | + // Fallback to web accept just in case the txn_type isn't present |
|
331 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
332 | + } |
|
333 | + exit; |
|
334 | 334 | } |
335 | 335 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
336 | 336 | |
337 | 337 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
338 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
339 | - return; |
|
340 | - } |
|
341 | - |
|
342 | - if( empty( $invoice_id ) ) { |
|
343 | - return; |
|
344 | - } |
|
345 | - |
|
346 | - // Collect payment details |
|
347 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
348 | - $paypal_amount = $data['mc_gross']; |
|
349 | - $payment_status = strtolower( $data['payment_status'] ); |
|
350 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
351 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
352 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
353 | - |
|
354 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
355 | - return; // this isn't a PayPal standard IPN |
|
356 | - } |
|
357 | - |
|
358 | - // Verify payment recipient |
|
359 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
360 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
361 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
362 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
363 | - return; |
|
364 | - } |
|
365 | - |
|
366 | - // Verify payment currency |
|
367 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
368 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
369 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
370 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
371 | - return; |
|
372 | - } |
|
373 | - |
|
374 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
375 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
376 | - // No email associated with purchase, so store from PayPal |
|
377 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
378 | - |
|
379 | - // Setup and store the customer's details |
|
380 | - $user_info = array( |
|
381 | - 'user_id' => '-1', |
|
382 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
383 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
384 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
385 | - 'discount' => '', |
|
386 | - ); |
|
387 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
388 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
389 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
390 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
391 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
392 | - |
|
393 | - $payment_meta['user_info'] = $user_info; |
|
394 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
395 | - } |
|
396 | - |
|
397 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
398 | - // Process a refund |
|
399 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
400 | - } else { |
|
401 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
402 | - return; // Only paid payments once |
|
403 | - } |
|
404 | - |
|
405 | - // Retrieve the total purchase amount (before PayPal) |
|
406 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
407 | - |
|
408 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
409 | - // The prices don't match |
|
410 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
411 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
412 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
413 | - return; |
|
414 | - } |
|
415 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
416 | - // Purchase keys don't match |
|
417 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
418 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
419 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
420 | - return; |
|
421 | - } |
|
422 | - |
|
423 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
424 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
425 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
426 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
427 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
428 | - // Look for possible pending reasons, such as an echeck |
|
429 | - $note = ''; |
|
430 | - |
|
431 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
432 | - case 'echeck' : |
|
433 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
434 | - break; |
|
338 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
339 | + return; |
|
340 | + } |
|
341 | + |
|
342 | + if( empty( $invoice_id ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | + |
|
346 | + // Collect payment details |
|
347 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
348 | + $paypal_amount = $data['mc_gross']; |
|
349 | + $payment_status = strtolower( $data['payment_status'] ); |
|
350 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
351 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
352 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
353 | + |
|
354 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
355 | + return; // this isn't a PayPal standard IPN |
|
356 | + } |
|
357 | + |
|
358 | + // Verify payment recipient |
|
359 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
360 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
361 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
362 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
363 | + return; |
|
364 | + } |
|
365 | + |
|
366 | + // Verify payment currency |
|
367 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
368 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
369 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
370 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
371 | + return; |
|
372 | + } |
|
373 | + |
|
374 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
375 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
376 | + // No email associated with purchase, so store from PayPal |
|
377 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
378 | + |
|
379 | + // Setup and store the customer's details |
|
380 | + $user_info = array( |
|
381 | + 'user_id' => '-1', |
|
382 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
383 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
384 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
385 | + 'discount' => '', |
|
386 | + ); |
|
387 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
388 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
389 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
390 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
391 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
392 | + |
|
393 | + $payment_meta['user_info'] = $user_info; |
|
394 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
395 | + } |
|
396 | + |
|
397 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
398 | + // Process a refund |
|
399 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
400 | + } else { |
|
401 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
402 | + return; // Only paid payments once |
|
403 | + } |
|
404 | + |
|
405 | + // Retrieve the total purchase amount (before PayPal) |
|
406 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
407 | + |
|
408 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
409 | + // The prices don't match |
|
410 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
411 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
412 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
413 | + return; |
|
414 | + } |
|
415 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
416 | + // Purchase keys don't match |
|
417 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
418 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
419 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
420 | + return; |
|
421 | + } |
|
422 | + |
|
423 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
424 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
425 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
426 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
427 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
428 | + // Look for possible pending reasons, such as an echeck |
|
429 | + $note = ''; |
|
430 | + |
|
431 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
432 | + case 'echeck' : |
|
433 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
434 | + break; |
|
435 | 435 | |
436 | 436 | case 'address' : |
437 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
438 | - break; |
|
437 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
438 | + break; |
|
439 | 439 | |
440 | 440 | case 'intl' : |
441 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
442 | - break; |
|
441 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
442 | + break; |
|
443 | 443 | |
444 | 444 | case 'multi-currency' : |
445 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
446 | - break; |
|
445 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
446 | + break; |
|
447 | 447 | |
448 | 448 | case 'paymentreview' : |
449 | 449 | case 'regulatory_review' : |
450 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
451 | - break; |
|
450 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
451 | + break; |
|
452 | 452 | |
453 | 453 | case 'unilateral' : |
454 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
455 | - break; |
|
454 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
455 | + break; |
|
456 | 456 | |
457 | 457 | case 'upgrade' : |
458 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
459 | - break; |
|
458 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
459 | + break; |
|
460 | 460 | |
461 | 461 | case 'verify' : |
462 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
463 | - break; |
|
464 | - |
|
465 | - case 'other' : |
|
466 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
467 | - break; |
|
468 | - } |
|
469 | - |
|
470 | - if ( ! empty( $note ) ) { |
|
471 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
472 | - } |
|
473 | - } else { |
|
474 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
475 | - } |
|
476 | - } |
|
462 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
463 | + break; |
|
464 | + |
|
465 | + case 'other' : |
|
466 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
467 | + break; |
|
468 | + } |
|
469 | + |
|
470 | + if ( ! empty( $note ) ) { |
|
471 | + wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
472 | + } |
|
473 | + } else { |
|
474 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
475 | + } |
|
476 | + } |
|
477 | 477 | } |
478 | 478 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
479 | 479 | |
@@ -661,34 +661,34 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
664 | - // Collect payment details |
|
664 | + // Collect payment details |
|
665 | 665 | |
666 | - if( empty( $invoice_id ) ) { |
|
667 | - return; |
|
668 | - } |
|
666 | + if( empty( $invoice_id ) ) { |
|
667 | + return; |
|
668 | + } |
|
669 | 669 | |
670 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
671 | - return; // Only refund payments once |
|
672 | - } |
|
670 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
671 | + return; // Only refund payments once |
|
672 | + } |
|
673 | 673 | |
674 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
675 | - $refund_amount = $data['mc_gross'] * -1; |
|
674 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
675 | + $refund_amount = $data['mc_gross'] * -1; |
|
676 | 676 | |
677 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
677 | + do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
678 | 678 | |
679 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
680 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
679 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
680 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
681 | 681 | |
682 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
682 | + do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
683 | 683 | |
684 | - return; // This is a partial refund |
|
685 | - } |
|
684 | + return; // This is a partial refund |
|
685 | + } |
|
686 | 686 | |
687 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
688 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
689 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
687 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
688 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
689 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
690 | 690 | |
691 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
691 | + do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |
@@ -103,29 +103,29 @@ discard block |
||
103 | 103 | |
104 | 104 | function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
105 | 105 | if ( ! empty( $args ) && is_array( $args ) ) { |
106 | - extract( $args ); |
|
107 | - } |
|
106 | + extract( $args ); |
|
107 | + } |
|
108 | 108 | |
109 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
110 | - // Allow 3rd party plugin filter template file from their plugin. |
|
111 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
109 | + $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
110 | + // Allow 3rd party plugin filter template file from their plugin. |
|
111 | + $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
112 | 112 | |
113 | - if ( ! file_exists( $located ) ) { |
|
113 | + if ( ! file_exists( $located ) ) { |
|
114 | 114 | _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
115 | - return; |
|
116 | - } |
|
115 | + return; |
|
116 | + } |
|
117 | 117 | |
118 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
118 | + do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
119 | 119 | |
120 | - include( $located ); |
|
120 | + include( $located ); |
|
121 | 121 | |
122 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
122 | + do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
126 | - ob_start(); |
|
127 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
128 | - return ob_get_clean(); |
|
126 | + ob_start(); |
|
127 | + wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
128 | + return ob_get_clean(); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
@@ -155,126 +155,126 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
158 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
158 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
159 | 159 | |
160 | - // Setup possible parts |
|
161 | - $templates = array(); |
|
162 | - if ( isset( $name ) ) |
|
163 | - $templates[] = $slug . '-' . $name . '.php'; |
|
164 | - $templates[] = $slug . '.php'; |
|
160 | + // Setup possible parts |
|
161 | + $templates = array(); |
|
162 | + if ( isset( $name ) ) |
|
163 | + $templates[] = $slug . '-' . $name . '.php'; |
|
164 | + $templates[] = $slug . '.php'; |
|
165 | 165 | |
166 | - // Allow template parts to be filtered |
|
167 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
166 | + // Allow template parts to be filtered |
|
167 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
168 | 168 | |
169 | - // Return the part that is found |
|
170 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
169 | + // Return the part that is found |
|
170 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
174 | - // No file found yet |
|
175 | - $located = false; |
|
174 | + // No file found yet |
|
175 | + $located = false; |
|
176 | 176 | |
177 | - // Try to find a template file |
|
178 | - foreach ( (array)$template_names as $template_name ) { |
|
177 | + // Try to find a template file |
|
178 | + foreach ( (array)$template_names as $template_name ) { |
|
179 | 179 | |
180 | - // Continue if template is empty |
|
181 | - if ( empty( $template_name ) ) |
|
182 | - continue; |
|
180 | + // Continue if template is empty |
|
181 | + if ( empty( $template_name ) ) |
|
182 | + continue; |
|
183 | 183 | |
184 | - // Trim off any slashes from the template name |
|
185 | - $template_name = ltrim( $template_name, '/' ); |
|
184 | + // Trim off any slashes from the template name |
|
185 | + $template_name = ltrim( $template_name, '/' ); |
|
186 | 186 | |
187 | - // try locating this template file by looping through the template paths |
|
188 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
187 | + // try locating this template file by looping through the template paths |
|
188 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
189 | 189 | |
190 | - if( file_exists( $template_path . $template_name ) ) { |
|
191 | - $located = $template_path . $template_name; |
|
192 | - break; |
|
193 | - } |
|
194 | - } |
|
190 | + if( file_exists( $template_path . $template_name ) ) { |
|
191 | + $located = $template_path . $template_name; |
|
192 | + break; |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - if( !empty( $located ) ) { |
|
197 | - break; |
|
198 | - } |
|
199 | - } |
|
196 | + if( !empty( $located ) ) { |
|
197 | + break; |
|
198 | + } |
|
199 | + } |
|
200 | 200 | |
201 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
202 | - load_template( $located, $require_once ); |
|
201 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
202 | + load_template( $located, $require_once ); |
|
203 | 203 | |
204 | - return $located; |
|
204 | + return $located; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_theme_template_paths() { |
208 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
208 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
209 | 209 | |
210 | - $file_paths = array( |
|
211 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
212 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
213 | - 100 => wpinv_get_templates_dir() |
|
214 | - ); |
|
210 | + $file_paths = array( |
|
211 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
212 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
213 | + 100 => wpinv_get_templates_dir() |
|
214 | + ); |
|
215 | 215 | |
216 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
216 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
217 | 217 | |
218 | - // sort the file paths based on priority |
|
219 | - ksort( $file_paths, SORT_NUMERIC ); |
|
218 | + // sort the file paths based on priority |
|
219 | + ksort( $file_paths, SORT_NUMERIC ); |
|
220 | 220 | |
221 | - return array_map( 'trailingslashit', $file_paths ); |
|
221 | + return array_map( 'trailingslashit', $file_paths ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_theme_template_dir_name() { |
225 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
225 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | function wpinv_checkout_meta_tags() { |
229 | 229 | |
230 | - $pages = array(); |
|
231 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
232 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
233 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
234 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
230 | + $pages = array(); |
|
231 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
232 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
233 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
234 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
235 | 235 | |
236 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
237 | - return; |
|
238 | - } |
|
236 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
237 | + return; |
|
238 | + } |
|
239 | 239 | |
240 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
240 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
241 | 241 | } |
242 | 242 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
243 | 243 | |
244 | 244 | function wpinv_add_body_classes( $class ) { |
245 | - $classes = (array)$class; |
|
245 | + $classes = (array)$class; |
|
246 | 246 | |
247 | - if( wpinv_is_checkout() ) { |
|
248 | - $classes[] = 'wpinv-checkout'; |
|
249 | - $classes[] = 'wpinv-page'; |
|
250 | - } |
|
247 | + if( wpinv_is_checkout() ) { |
|
248 | + $classes[] = 'wpinv-checkout'; |
|
249 | + $classes[] = 'wpinv-page'; |
|
250 | + } |
|
251 | 251 | |
252 | - if( wpinv_is_success_page() ) { |
|
253 | - $classes[] = 'wpinv-success'; |
|
254 | - $classes[] = 'wpinv-page'; |
|
255 | - } |
|
252 | + if( wpinv_is_success_page() ) { |
|
253 | + $classes[] = 'wpinv-success'; |
|
254 | + $classes[] = 'wpinv-page'; |
|
255 | + } |
|
256 | 256 | |
257 | - if( wpinv_is_failed_transaction_page() ) { |
|
258 | - $classes[] = 'wpinv-failed-transaction'; |
|
259 | - $classes[] = 'wpinv-page'; |
|
260 | - } |
|
257 | + if( wpinv_is_failed_transaction_page() ) { |
|
258 | + $classes[] = 'wpinv-failed-transaction'; |
|
259 | + $classes[] = 'wpinv-page'; |
|
260 | + } |
|
261 | 261 | |
262 | - if( wpinv_is_invoice_history_page() ) { |
|
263 | - $classes[] = 'wpinv-history'; |
|
264 | - $classes[] = 'wpinv-page'; |
|
265 | - } |
|
262 | + if( wpinv_is_invoice_history_page() ) { |
|
263 | + $classes[] = 'wpinv-history'; |
|
264 | + $classes[] = 'wpinv-page'; |
|
265 | + } |
|
266 | 266 | |
267 | - if( wpinv_is_subscriptions_history_page() ) { |
|
268 | - $classes[] = 'wpinv-subscription'; |
|
269 | - $classes[] = 'wpinv-page'; |
|
270 | - } |
|
267 | + if( wpinv_is_subscriptions_history_page() ) { |
|
268 | + $classes[] = 'wpinv-subscription'; |
|
269 | + $classes[] = 'wpinv-page'; |
|
270 | + } |
|
271 | 271 | |
272 | - if( wpinv_is_test_mode() ) { |
|
273 | - $classes[] = 'wpinv-test-mode'; |
|
274 | - $classes[] = 'wpinv-page'; |
|
275 | - } |
|
272 | + if( wpinv_is_test_mode() ) { |
|
273 | + $classes[] = 'wpinv-test-mode'; |
|
274 | + $classes[] = 'wpinv-page'; |
|
275 | + } |
|
276 | 276 | |
277 | - return array_unique( $classes ); |
|
277 | + return array_unique( $classes ); |
|
278 | 278 | } |
279 | 279 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
280 | 280 | |
@@ -1408,7 +1408,7 @@ discard block |
||
1408 | 1408 | add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
1409 | 1409 | |
1410 | 1410 | function wpinv_empty_cart_message() { |
1411 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1411 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | /** |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | * @return void |
1419 | 1419 | */ |
1420 | 1420 | function wpinv_empty_checkout_cart() { |
1421 | - echo wpinv_empty_cart_message(); |
|
1421 | + echo wpinv_empty_cart_message(); |
|
1422 | 1422 | } |
1423 | 1423 | add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
1424 | 1424 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
5 | - exit; |
|
5 | + exit; |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -13,183 +13,183 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class WPInv_Subscription { |
15 | 15 | |
16 | - private $subs_db; |
|
16 | + private $subs_db; |
|
17 | + |
|
18 | + public $id = 0; |
|
19 | + public $customer_id = 0; |
|
20 | + public $period = ''; |
|
21 | + public $initial_amount = ''; |
|
22 | + public $recurring_amount = ''; |
|
23 | + public $bill_times = 0; |
|
24 | + public $transaction_id = ''; |
|
25 | + public $parent_payment_id = 0; |
|
26 | + public $product_id = 0; |
|
27 | + public $created = '0000-00-00 00:00:00'; |
|
28 | + public $expiration = '0000-00-00 00:00:00'; |
|
29 | + public $trial_period = ''; |
|
30 | + public $status = 'pending'; |
|
31 | + public $profile_id = ''; |
|
32 | + public $gateway = ''; |
|
33 | + public $customer; |
|
17 | 34 | |
18 | - public $id = 0; |
|
19 | - public $customer_id = 0; |
|
20 | - public $period = ''; |
|
21 | - public $initial_amount = ''; |
|
22 | - public $recurring_amount = ''; |
|
23 | - public $bill_times = 0; |
|
24 | - public $transaction_id = ''; |
|
25 | - public $parent_payment_id = 0; |
|
26 | - public $product_id = 0; |
|
27 | - public $created = '0000-00-00 00:00:00'; |
|
28 | - public $expiration = '0000-00-00 00:00:00'; |
|
29 | - public $trial_period = ''; |
|
30 | - public $status = 'pending'; |
|
31 | - public $profile_id = ''; |
|
32 | - public $gateway = ''; |
|
33 | - public $customer; |
|
34 | - |
|
35 | - /** |
|
36 | - * Get us started |
|
37 | - * |
|
38 | - * @since 1.0.0 |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
35 | + /** |
|
36 | + * Get us started |
|
37 | + * |
|
38 | + * @since 1.0.0 |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
42 | 42 | |
43 | - $this->subs_db = new WPInv_Subscriptions_DB; |
|
43 | + $this->subs_db = new WPInv_Subscriptions_DB; |
|
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if( $_by_profile_id ) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
50 | - return false; |
|
51 | - } |
|
49 | + if( empty( $_sub ) ) { |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | |
53 | - $_id_or_object = $_sub; |
|
53 | + $_id_or_object = $_sub; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
58 | - } |
|
57 | + return $this->setup_subscription( $_id_or_object ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Setup the subscription object |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
60 | + /** |
|
61 | + * Setup the subscription object |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + private function setup_subscription( $id_or_object = 0 ) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
69 | - return false; |
|
70 | - } |
|
68 | + if( empty( $id_or_object ) ) { |
|
69 | + return false; |
|
70 | + } |
|
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if( is_numeric( $id_or_object ) ) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get( $id_or_object ); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif( is_object( $id_or_object ) ) { |
|
77 | 77 | |
78 | - $sub = $id_or_object; |
|
78 | + $sub = $id_or_object; |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
83 | - return false; |
|
84 | - } |
|
82 | + if( empty( $sub ) ) { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
87 | - $this->$key = $value; |
|
88 | - } |
|
86 | + foreach( $sub as $key => $value ) { |
|
87 | + $this->$key = $value; |
|
88 | + } |
|
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata( $this->customer_id ); |
|
91 | + $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
94 | 94 | |
95 | - return $this; |
|
96 | - } |
|
95 | + return $this; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Magic __get function to dispatch a call to retrieve a private property |
|
100 | - * |
|
101 | - * @since 1.0.0 |
|
102 | - */ |
|
103 | - public function __get( $key ) { |
|
98 | + /** |
|
99 | + * Magic __get function to dispatch a call to retrieve a private property |
|
100 | + * |
|
101 | + * @since 1.0.0 |
|
102 | + */ |
|
103 | + public function __get( $key ) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if( method_exists( $this, 'get_' . $key ) ) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func( array( $this, 'get_' . $key ) ); |
|
108 | 108 | |
109 | - } else { |
|
109 | + } else { |
|
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Creates a subscription |
|
119 | - * |
|
120 | - * @since 1.0.0 |
|
121 | - * @param array $data Array of attributes for a subscription |
|
122 | - * @return mixed false if data isn't passed and class not instantiated for creation |
|
123 | - */ |
|
124 | - public function create( $data = array() ) { |
|
117 | + /** |
|
118 | + * Creates a subscription |
|
119 | + * |
|
120 | + * @since 1.0.0 |
|
121 | + * @param array $data Array of attributes for a subscription |
|
122 | + * @return mixed false if data isn't passed and class not instantiated for creation |
|
123 | + */ |
|
124 | + public function create( $data = array() ) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
127 | - return false; |
|
128 | - } |
|
126 | + if ( $this->id != 0 ) { |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | |
130 | - $defaults = array( |
|
131 | - 'customer_id' => 0, |
|
132 | - 'frequency' => '', |
|
133 | - 'period' => '', |
|
134 | - 'initial_amount' => '', |
|
135 | - 'recurring_amount' => '', |
|
136 | - 'bill_times' => 0, |
|
137 | - 'parent_payment_id' => 0, |
|
138 | - 'product_id' => 0, |
|
139 | - 'created' => '', |
|
140 | - 'expiration' => '', |
|
141 | - 'status' => '', |
|
142 | - 'profile_id' => '', |
|
143 | - ); |
|
130 | + $defaults = array( |
|
131 | + 'customer_id' => 0, |
|
132 | + 'frequency' => '', |
|
133 | + 'period' => '', |
|
134 | + 'initial_amount' => '', |
|
135 | + 'recurring_amount' => '', |
|
136 | + 'bill_times' => 0, |
|
137 | + 'parent_payment_id' => 0, |
|
138 | + 'product_id' => 0, |
|
139 | + 'created' => '', |
|
140 | + 'expiration' => '', |
|
141 | + 'status' => '', |
|
142 | + 'profile_id' => '', |
|
143 | + ); |
|
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args( $data, $defaults ); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
150 | 150 | |
151 | - // Force an active subscription to expired if expiration date is in the past |
|
152 | - $args['status'] = 'expired'; |
|
151 | + // Force an active subscription to expired if expiration date is in the past |
|
152 | + $args['status'] = 'expired'; |
|
153 | 153 | |
154 | - } |
|
155 | - } |
|
154 | + } |
|
155 | + } |
|
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action( 'wpinv_subscription_pre_create', $args ); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert( $args, 'subscription' ); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription( $id ); |
|
164 | 164 | |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Updates a subscription |
|
169 | - * |
|
170 | - * @since 1.0.0 |
|
171 | - * @param array $args Array of fields to update |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function update( $args = array() ) { |
|
167 | + /** |
|
168 | + * Updates a subscription |
|
169 | + * |
|
170 | + * @since 1.0.0 |
|
171 | + * @param array $args Array of fields to update |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function update( $args = array() ) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update( $this->id, $args ); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
179 | 179 | |
180 | - return $ret; |
|
180 | + return $ret; |
|
181 | 181 | |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Delete the subscription |
|
186 | - * |
|
187 | - * @since 1.0.0 |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function delete() { |
|
191 | - return $this->subs_db->delete( $this->id ); |
|
192 | - } |
|
184 | + /** |
|
185 | + * Delete the subscription |
|
186 | + * |
|
187 | + * @since 1.0.0 |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function delete() { |
|
191 | + return $this->subs_db->delete( $this->id ); |
|
192 | + } |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * Retrieves the parent payment ID |
@@ -366,185 +366,185 @@ discard block |
||
366 | 366 | return false; |
367 | 367 | } |
368 | 368 | |
369 | - /** |
|
370 | - * Retrieves the transaction ID from the subscription |
|
371 | - * |
|
372 | - * @since 1.0.0 |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function get_transaction_id() { |
|
369 | + /** |
|
370 | + * Retrieves the transaction ID from the subscription |
|
371 | + * |
|
372 | + * @since 1.0.0 |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function get_transaction_id() { |
|
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if( empty( $this->transaction_id ) ) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
383 | - } |
|
381 | + if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | + $this->set_transaction_id( $txn_id ); |
|
383 | + } |
|
384 | 384 | |
385 | - } |
|
385 | + } |
|
386 | 386 | |
387 | - return $this->transaction_id; |
|
387 | + return $this->transaction_id; |
|
388 | 388 | |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | - /** |
|
392 | - * Stores the transaction ID for the subscription purchase |
|
393 | - * |
|
394 | - * @since 1.0.0.4 |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
399 | - $this->transaction_id = $txn_id; |
|
400 | - } |
|
391 | + /** |
|
392 | + * Stores the transaction ID for the subscription purchase |
|
393 | + * |
|
394 | + * @since 1.0.0.4 |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function set_transaction_id( $txn_id = '' ) { |
|
398 | + $this->update( array( 'transaction_id' => $txn_id ) ); |
|
399 | + $this->transaction_id = $txn_id; |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Renews a subscription |
|
404 | - * |
|
405 | - * @since 1.0.0 |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function renew() { |
|
402 | + /** |
|
403 | + * Renews a subscription |
|
404 | + * |
|
405 | + * @since 1.0.0 |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function renew() { |
|
409 | 409 | |
410 | - $expires = $this->get_expiration_time(); |
|
410 | + $expires = $this->get_expiration_time(); |
|
411 | 411 | |
412 | 412 | |
413 | - // Determine what date to use as the start for the new expiration calculation |
|
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
413 | + // Determine what date to use as the start for the new expiration calculation |
|
414 | + if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | - } else { |
|
418 | + } else { |
|
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time( 'timestamp' ); |
|
421 | 421 | |
422 | - } |
|
422 | + } |
|
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
425 | 425 | |
426 | 426 | |
427 | - $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
427 | + $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
428 | + $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
432 | - } |
|
430 | + if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | + $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
432 | + } |
|
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
437 | 437 | |
438 | - $this->status = 'active'; |
|
439 | - $times_billed = $this->get_times_billed(); |
|
438 | + $this->status = 'active'; |
|
439 | + $times_billed = $this->get_times_billed(); |
|
440 | 440 | |
441 | - // Complete subscription if applicable |
|
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
443 | - $this->complete(); |
|
444 | - $this->status = 'completed'; |
|
445 | - } |
|
441 | + // Complete subscription if applicable |
|
442 | + if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
443 | + $this->complete(); |
|
444 | + $this->status = 'completed'; |
|
445 | + } |
|
446 | 446 | |
447 | - $args = array( |
|
448 | - 'expiration' => $expiration, |
|
449 | - 'status' => $this->status, |
|
450 | - ); |
|
447 | + $args = array( |
|
448 | + 'expiration' => $expiration, |
|
449 | + 'status' => $this->status, |
|
450 | + ); |
|
451 | 451 | |
452 | 452 | $this->subs_db->update( $this->id, $args ); |
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | + do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
456 | 456 | |
457 | - } |
|
457 | + } |
|
458 | 458 | |
459 | - /** |
|
460 | - * Marks a subscription as completed |
|
461 | - * |
|
462 | - * Subscription is completed when the number of payments matches the billing_times field |
|
463 | - * |
|
464 | - * @since 1.0.0 |
|
465 | - * @return void |
|
466 | - */ |
|
467 | - public function complete() { |
|
459 | + /** |
|
460 | + * Marks a subscription as completed |
|
461 | + * |
|
462 | + * Subscription is completed when the number of payments matches the billing_times field |
|
463 | + * |
|
464 | + * @since 1.0.0 |
|
465 | + * @return void |
|
466 | + */ |
|
467 | + public function complete() { |
|
468 | 468 | |
469 | - // Only mark a subscription as complete if it's not already cancelled. |
|
470 | - if ( 'cancelled' === $this->status ) { |
|
471 | - return; |
|
472 | - } |
|
469 | + // Only mark a subscription as complete if it's not already cancelled. |
|
470 | + if ( 'cancelled' === $this->status ) { |
|
471 | + return; |
|
472 | + } |
|
473 | 473 | |
474 | - $args = array( |
|
475 | - 'status' => 'completed' |
|
476 | - ); |
|
474 | + $args = array( |
|
475 | + 'status' => 'completed' |
|
476 | + ); |
|
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
479 | 479 | |
480 | - $this->status = 'completed'; |
|
480 | + $this->status = 'completed'; |
|
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
483 | 483 | |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - } |
|
486 | + } |
|
487 | 487 | |
488 | - /** |
|
489 | - * Marks a subscription as expired |
|
490 | - * |
|
491 | - * Subscription is completed when the billing times is reached |
|
492 | - * |
|
493 | - * @since 1.0.0 |
|
494 | - * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
495 | - * @return void |
|
496 | - */ |
|
497 | - public function expire( $check_expiration = false ) { |
|
488 | + /** |
|
489 | + * Marks a subscription as expired |
|
490 | + * |
|
491 | + * Subscription is completed when the billing times is reached |
|
492 | + * |
|
493 | + * @since 1.0.0 |
|
494 | + * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
495 | + * @return void |
|
496 | + */ |
|
497 | + public function expire( $check_expiration = false ) { |
|
498 | 498 | |
499 | - $expiration = $this->expiration; |
|
499 | + $expiration = $this->expiration; |
|
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if( $check_expiration ) { |
|
502 | 502 | |
503 | - // check_expiration() updates $this->expiration so compare to $expiration above |
|
503 | + // check_expiration() updates $this->expiration so compare to $expiration above |
|
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
506 | 506 | |
507 | - return false; // Do not mark as expired since real expiration date is in the future |
|
508 | - } |
|
507 | + return false; // Do not mark as expired since real expiration date is in the future |
|
508 | + } |
|
509 | 509 | |
510 | - } |
|
510 | + } |
|
511 | 511 | |
512 | - $args = array( |
|
513 | - 'status' => 'expired' |
|
514 | - ); |
|
512 | + $args = array( |
|
513 | + 'status' => 'expired' |
|
514 | + ); |
|
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
517 | 517 | |
518 | - $this->status = 'expired'; |
|
518 | + $this->status = 'expired'; |
|
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
521 | 521 | |
522 | - } |
|
522 | + } |
|
523 | 523 | |
524 | - } |
|
524 | + } |
|
525 | 525 | |
526 | - /** |
|
527 | - * Marks a subscription as failing |
|
528 | - * |
|
529 | - * @since 2.4.2 |
|
530 | - * @return void |
|
531 | - */ |
|
532 | - public function failing() { |
|
526 | + /** |
|
527 | + * Marks a subscription as failing |
|
528 | + * |
|
529 | + * @since 2.4.2 |
|
530 | + * @return void |
|
531 | + */ |
|
532 | + public function failing() { |
|
533 | 533 | |
534 | - $args = array( |
|
535 | - 'status' => 'failing' |
|
536 | - ); |
|
534 | + $args = array( |
|
535 | + 'status' => 'failing' |
|
536 | + ); |
|
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
539 | 539 | |
540 | - $this->status = 'failing'; |
|
540 | + $this->status = 'failing'; |
|
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
543 | 543 | |
544 | 544 | |
545 | - } |
|
545 | + } |
|
546 | 546 | |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | 549 | /** |
550 | 550 | * Marks a subscription as cancelled |
@@ -578,22 +578,22 @@ discard block |
||
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
581 | - /** |
|
582 | - * Determines if subscription can be cancelled |
|
583 | - * |
|
584 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
585 | - * that can be cancelled with a profile ID through the merchant processor |
|
586 | - * |
|
587 | - * @since 1.0.0 |
|
588 | - * @return bool |
|
589 | - */ |
|
590 | - public function can_cancel() { |
|
581 | + /** |
|
582 | + * Determines if subscription can be cancelled |
|
583 | + * |
|
584 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
585 | + * that can be cancelled with a profile ID through the merchant processor |
|
586 | + * |
|
587 | + * @since 1.0.0 |
|
588 | + * @return bool |
|
589 | + */ |
|
590 | + public function can_cancel() { |
|
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
596 | - } |
|
595 | + return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
596 | + } |
|
597 | 597 | |
598 | 598 | /** |
599 | 599 | * Returns an array of subscription statuses that can be cancelled |
@@ -606,197 +606,197 @@ discard block |
||
606 | 606 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
607 | 607 | } |
608 | 608 | |
609 | - /** |
|
610 | - * Retrieves the URL to cancel subscription |
|
611 | - * |
|
612 | - * @since 1.0.0 |
|
613 | - * @return string |
|
614 | - */ |
|
615 | - public function get_cancel_url() { |
|
609 | + /** |
|
610 | + * Retrieves the URL to cancel subscription |
|
611 | + * |
|
612 | + * @since 1.0.0 |
|
613 | + * @return string |
|
614 | + */ |
|
615 | + public function get_cancel_url() { |
|
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
620 | - } |
|
619 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
620 | + } |
|
621 | 621 | |
622 | - /** |
|
623 | - * Determines if subscription can be manually renewed |
|
624 | - * |
|
625 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
626 | - * that can be renewed manually |
|
627 | - * |
|
628 | - * @since 2.5 |
|
629 | - * @return bool |
|
630 | - */ |
|
631 | - public function can_renew() { |
|
622 | + /** |
|
623 | + * Determines if subscription can be manually renewed |
|
624 | + * |
|
625 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
626 | + * that can be renewed manually |
|
627 | + * |
|
628 | + * @since 2.5 |
|
629 | + * @return bool |
|
630 | + */ |
|
631 | + public function can_renew() { |
|
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Retrieves the URL to renew a subscription |
|
638 | - * |
|
639 | - * @since 2.5 |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function get_renew_url() { |
|
643 | - |
|
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
645 | - |
|
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Determines if subscription can have their payment method updated |
|
651 | - * |
|
652 | - * @since 1.0.0 |
|
653 | - * @return bool |
|
654 | - */ |
|
655 | - public function can_update() { |
|
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Retrieves the URL to update subscription |
|
661 | - * |
|
662 | - * @since 1.0.0 |
|
663 | - * @return void |
|
664 | - */ |
|
665 | - public function get_update_url() { |
|
666 | - |
|
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
668 | - |
|
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
670 | - } |
|
671 | - |
|
672 | - /** |
|
673 | - * Determines if subscription is active |
|
674 | - * |
|
675 | - * @since 1.0.0 |
|
676 | - * @return void |
|
677 | - */ |
|
678 | - public function is_active() { |
|
679 | - |
|
680 | - $ret = false; |
|
681 | - |
|
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
683 | - $ret = true; |
|
684 | - } |
|
685 | - |
|
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Determines if subscription is expired |
|
692 | - * |
|
693 | - * @since 1.0.0 |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function is_expired() { |
|
697 | - |
|
698 | - $ret = false; |
|
699 | - |
|
700 | - if ( $this->status == 'expired' ) { |
|
701 | - |
|
702 | - $ret = true; |
|
703 | - |
|
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
705 | - |
|
706 | - $ret = false; |
|
707 | - $expiration = $this->get_expiration_time(); |
|
708 | - |
|
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
710 | - $ret = true; |
|
711 | - |
|
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
713 | - $this->expire(); |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - } |
|
718 | - |
|
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
720 | - |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * Retrieves the expiration date |
|
725 | - * |
|
726 | - * @since 1.0.0 |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_expiration() { |
|
730 | - return $this->expiration; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Retrieves the expiration date in a timestamp |
|
735 | - * |
|
736 | - * @since 1.0.0 |
|
737 | - * @return int |
|
738 | - */ |
|
739 | - public function get_expiration_time() { |
|
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Retrieves the subscription status |
|
745 | - * |
|
746 | - * @since 1.0.0 |
|
747 | - * @return int |
|
748 | - */ |
|
749 | - public function get_status() { |
|
750 | - |
|
751 | - // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
752 | - $this->is_expired(); |
|
753 | - return $this->status; |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Retrieves the subscription status label |
|
758 | - * |
|
759 | - * @since 1.0.0 |
|
760 | - * @return int |
|
761 | - */ |
|
762 | - public function get_status_label() { |
|
763 | - |
|
764 | - switch( $this->get_status() ) { |
|
765 | - case 'active' : |
|
766 | - $status = __( 'Active', 'invoicing' ); |
|
767 | - break; |
|
768 | - |
|
769 | - case 'cancelled' : |
|
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
771 | - break; |
|
772 | - |
|
773 | - case 'expired' : |
|
774 | - $status = __( 'Expired', 'invoicing' ); |
|
775 | - break; |
|
776 | - |
|
777 | - case 'pending' : |
|
778 | - $status = __( 'Pending', 'invoicing' ); |
|
779 | - break; |
|
780 | - |
|
781 | - case 'failing' : |
|
782 | - $status = __( 'Failing', 'invoicing' ); |
|
783 | - break; |
|
784 | - |
|
785 | - case 'trialling' : |
|
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
787 | - break; |
|
788 | - |
|
789 | - case 'completed' : |
|
790 | - $status = __( 'Completed', 'invoicing' ); |
|
791 | - break; |
|
792 | - |
|
793 | - default: |
|
794 | - $status = ucfirst( $this->get_status() ); |
|
795 | - break; |
|
796 | - } |
|
797 | - |
|
798 | - return $status; |
|
799 | - } |
|
633 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Retrieves the URL to renew a subscription |
|
638 | + * |
|
639 | + * @since 2.5 |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function get_renew_url() { |
|
643 | + |
|
644 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
645 | + |
|
646 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Determines if subscription can have their payment method updated |
|
651 | + * |
|
652 | + * @since 1.0.0 |
|
653 | + * @return bool |
|
654 | + */ |
|
655 | + public function can_update() { |
|
656 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Retrieves the URL to update subscription |
|
661 | + * |
|
662 | + * @since 1.0.0 |
|
663 | + * @return void |
|
664 | + */ |
|
665 | + public function get_update_url() { |
|
666 | + |
|
667 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
668 | + |
|
669 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
670 | + } |
|
671 | + |
|
672 | + /** |
|
673 | + * Determines if subscription is active |
|
674 | + * |
|
675 | + * @since 1.0.0 |
|
676 | + * @return void |
|
677 | + */ |
|
678 | + public function is_active() { |
|
679 | + |
|
680 | + $ret = false; |
|
681 | + |
|
682 | + if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
683 | + $ret = true; |
|
684 | + } |
|
685 | + |
|
686 | + return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Determines if subscription is expired |
|
692 | + * |
|
693 | + * @since 1.0.0 |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function is_expired() { |
|
697 | + |
|
698 | + $ret = false; |
|
699 | + |
|
700 | + if ( $this->status == 'expired' ) { |
|
701 | + |
|
702 | + $ret = true; |
|
703 | + |
|
704 | + } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
705 | + |
|
706 | + $ret = false; |
|
707 | + $expiration = $this->get_expiration_time(); |
|
708 | + |
|
709 | + if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
710 | + $ret = true; |
|
711 | + |
|
712 | + if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
713 | + $this->expire(); |
|
714 | + } |
|
715 | + } |
|
716 | + |
|
717 | + } |
|
718 | + |
|
719 | + return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
720 | + |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * Retrieves the expiration date |
|
725 | + * |
|
726 | + * @since 1.0.0 |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_expiration() { |
|
730 | + return $this->expiration; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Retrieves the expiration date in a timestamp |
|
735 | + * |
|
736 | + * @since 1.0.0 |
|
737 | + * @return int |
|
738 | + */ |
|
739 | + public function get_expiration_time() { |
|
740 | + return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Retrieves the subscription status |
|
745 | + * |
|
746 | + * @since 1.0.0 |
|
747 | + * @return int |
|
748 | + */ |
|
749 | + public function get_status() { |
|
750 | + |
|
751 | + // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
752 | + $this->is_expired(); |
|
753 | + return $this->status; |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Retrieves the subscription status label |
|
758 | + * |
|
759 | + * @since 1.0.0 |
|
760 | + * @return int |
|
761 | + */ |
|
762 | + public function get_status_label() { |
|
763 | + |
|
764 | + switch( $this->get_status() ) { |
|
765 | + case 'active' : |
|
766 | + $status = __( 'Active', 'invoicing' ); |
|
767 | + break; |
|
768 | + |
|
769 | + case 'cancelled' : |
|
770 | + $status = __( 'Cancelled', 'invoicing' ); |
|
771 | + break; |
|
772 | + |
|
773 | + case 'expired' : |
|
774 | + $status = __( 'Expired', 'invoicing' ); |
|
775 | + break; |
|
776 | + |
|
777 | + case 'pending' : |
|
778 | + $status = __( 'Pending', 'invoicing' ); |
|
779 | + break; |
|
780 | + |
|
781 | + case 'failing' : |
|
782 | + $status = __( 'Failing', 'invoicing' ); |
|
783 | + break; |
|
784 | + |
|
785 | + case 'trialling' : |
|
786 | + $status = __( 'Trialling', 'invoicing' ); |
|
787 | + break; |
|
788 | + |
|
789 | + case 'completed' : |
|
790 | + $status = __( 'Completed', 'invoicing' ); |
|
791 | + break; |
|
792 | + |
|
793 | + default: |
|
794 | + $status = ucfirst( $this->get_status() ); |
|
795 | + break; |
|
796 | + } |
|
797 | + |
|
798 | + return $status; |
|
799 | + } |
|
800 | 800 | |
801 | 801 | /** |
802 | 802 | * Retrieves the subscription status label |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | // Load WP_List_Table if not loaded |
15 | 15 | if( ! class_exists( 'WP_List_Table' ) ) { |
16 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
16 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -23,102 +23,102 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class WPInv_Subscription_Reports_Table extends WP_List_Table { |
25 | 25 | |
26 | - /** |
|
27 | - * Number of results to show per page |
|
28 | - * |
|
29 | - * @since 1.0.0 |
|
30 | - */ |
|
31 | - |
|
32 | - public $per_page = 20; |
|
33 | - public $total_count = 0; |
|
34 | - public $active_count = 0; |
|
35 | - public $pending_count = 0; |
|
36 | - public $expired_count = 0; |
|
37 | - public $completed_count = 0; |
|
38 | - public $trialling_count = 0; |
|
39 | - public $cancelled_count = 0; |
|
40 | - public $failing_count = 0; |
|
41 | - |
|
42 | - /** |
|
43 | - * Get things started |
|
44 | - * |
|
45 | - * @access private |
|
46 | - * @since 1.0.0 |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - function __construct(){ |
|
50 | - global $status, $page; |
|
51 | - |
|
52 | - // Set parent defaults |
|
53 | - parent::__construct( array( |
|
54 | - 'singular' => 'subscription', |
|
55 | - 'plural' => 'subscriptions', |
|
56 | - 'ajax' => false |
|
57 | - ) ); |
|
58 | - |
|
59 | - $this->get_subscription_counts(); |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Retrieve the view types |
|
65 | - * |
|
66 | - * @access public |
|
67 | - * @since 1.0.0 |
|
68 | - * @return array $views All the views available |
|
69 | - */ |
|
70 | - public function get_views() { |
|
71 | - |
|
72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | - $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
75 | - $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | - $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | - |
|
82 | - $views = array( |
|
83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
91 | - ); |
|
92 | - |
|
93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Show the search field |
|
98 | - * |
|
99 | - * @since 2.5 |
|
100 | - * @access public |
|
101 | - * |
|
102 | - * @param string $text Label for the search box |
|
103 | - * @param string $input_id ID of the search box |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function search_box( $text, $input_id ) { |
|
108 | - |
|
109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
110 | - return; |
|
111 | - } |
|
112 | - |
|
113 | - $input_id = $input_id . '-search-input'; |
|
114 | - |
|
115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
117 | - } |
|
118 | - |
|
119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
121 | - } |
|
26 | + /** |
|
27 | + * Number of results to show per page |
|
28 | + * |
|
29 | + * @since 1.0.0 |
|
30 | + */ |
|
31 | + |
|
32 | + public $per_page = 20; |
|
33 | + public $total_count = 0; |
|
34 | + public $active_count = 0; |
|
35 | + public $pending_count = 0; |
|
36 | + public $expired_count = 0; |
|
37 | + public $completed_count = 0; |
|
38 | + public $trialling_count = 0; |
|
39 | + public $cancelled_count = 0; |
|
40 | + public $failing_count = 0; |
|
41 | + |
|
42 | + /** |
|
43 | + * Get things started |
|
44 | + * |
|
45 | + * @access private |
|
46 | + * @since 1.0.0 |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + function __construct(){ |
|
50 | + global $status, $page; |
|
51 | + |
|
52 | + // Set parent defaults |
|
53 | + parent::__construct( array( |
|
54 | + 'singular' => 'subscription', |
|
55 | + 'plural' => 'subscriptions', |
|
56 | + 'ajax' => false |
|
57 | + ) ); |
|
58 | + |
|
59 | + $this->get_subscription_counts(); |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Retrieve the view types |
|
65 | + * |
|
66 | + * @access public |
|
67 | + * @since 1.0.0 |
|
68 | + * @return array $views All the views available |
|
69 | + */ |
|
70 | + public function get_views() { |
|
71 | + |
|
72 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
74 | + $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
75 | + $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
77 | + $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
81 | + |
|
82 | + $views = array( |
|
83 | + 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
84 | + 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
85 | + 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
86 | + 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
87 | + 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
88 | + 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
89 | + 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
90 | + 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
91 | + ); |
|
92 | + |
|
93 | + return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Show the search field |
|
98 | + * |
|
99 | + * @since 2.5 |
|
100 | + * @access public |
|
101 | + * |
|
102 | + * @param string $text Label for the search box |
|
103 | + * @param string $input_id ID of the search box |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function search_box( $text, $input_id ) { |
|
108 | + |
|
109 | + if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
110 | + return; |
|
111 | + } |
|
112 | + |
|
113 | + $input_id = $input_id . '-search-input'; |
|
114 | + |
|
115 | + if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
117 | + } |
|
118 | + |
|
119 | + if ( ! empty( $_REQUEST['order'] ) ) { |
|
120 | + echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
121 | + } |
|
122 | 122 | ?> |
123 | 123 | <p class="search-box"> |
124 | 124 | <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
@@ -127,18 +127,18 @@ discard block |
||
127 | 127 | <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
128 | 128 | </p> |
129 | 129 | <?php |
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Render most columns |
|
134 | - * |
|
135 | - * @access private |
|
136 | - * @since 1.0.0 |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - function column_default( $item, $column_name ) { |
|
140 | - return $item->$column_name; |
|
141 | - } |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Render most columns |
|
134 | + * |
|
135 | + * @access private |
|
136 | + * @since 1.0.0 |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + function column_default( $item, $column_name ) { |
|
140 | + return $item->$column_name; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Subscription id column |
@@ -151,244 +151,244 @@ discard block |
||
151 | 151 | return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
152 | 152 | } |
153 | 153 | |
154 | - /** |
|
155 | - * Customer column |
|
156 | - * |
|
157 | - * @access private |
|
158 | - * @since 1.0.0 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - function column_customer_id( $item ) { |
|
162 | - $subscriber = get_userdata( $item->customer_id ); |
|
163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | - |
|
165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Status column |
|
170 | - * |
|
171 | - * @access private |
|
172 | - * @since 1.0.0 |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - function column_status( $item ) { |
|
176 | - return $item->get_status_label(); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Period column |
|
181 | - * |
|
182 | - * @access private |
|
183 | - * @since 1.0.0 |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - function column_period( $item ) { |
|
187 | - |
|
188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
189 | - |
|
190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Billing Times column |
|
195 | - * |
|
196 | - * @access private |
|
197 | - * @since 1.0.0 |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - function column_bill_times( $item ) { |
|
201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Initial Amount column |
|
206 | - * |
|
207 | - * @access private |
|
208 | - * @since 1.0.0 |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - function column_initial_amount( $item ) { |
|
212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Renewal date column |
|
217 | - * |
|
218 | - * @access private |
|
219 | - * @since 1.0.0 |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - function column_renewal_date( $item ) { |
|
223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Payment column |
|
228 | - * |
|
229 | - * @access private |
|
230 | - * @since 1.0.0 |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - function column_parent_payment_id( $item ) { |
|
234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Product ID column |
|
239 | - * |
|
240 | - * @access private |
|
241 | - * @since 1.0.0 |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - function column_product_id( $item ) { |
|
245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Render the edit column |
|
250 | - * |
|
251 | - * @access private |
|
252 | - * @since 2.0 |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - function column_actions( $item ) { |
|
256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Retrieve the table columns |
|
262 | - * |
|
263 | - * @access private |
|
264 | - * @since 1.0.0 |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - |
|
268 | - function get_columns(){ |
|
269 | - $columns = array( |
|
270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | - 'status' => __( 'Status', 'invoicing' ), |
|
273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
280 | - ); |
|
281 | - |
|
282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Retrieve the current page number |
|
287 | - * |
|
288 | - * @access private |
|
289 | - * @since 1.0.0 |
|
290 | - * @return int |
|
291 | - */ |
|
292 | - function get_paged() { |
|
293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Retrieve the subscription counts |
|
298 | - * |
|
299 | - * @access public |
|
300 | - * @since 1.4 |
|
301 | - * @return void |
|
302 | - */ |
|
303 | - public function get_subscription_counts() { |
|
304 | - |
|
305 | - global $wp_query; |
|
306 | - |
|
307 | - $db = new WPInv_Subscriptions_DB; |
|
308 | - |
|
309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
310 | - |
|
311 | - $this->total_count = $db->count(); |
|
312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
319 | - |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Setup the final data for the table |
|
324 | - * |
|
325 | - * @access private |
|
326 | - * @since 1.0.0 |
|
327 | - * @uses $this->_column_headers |
|
328 | - * @uses $this->items |
|
329 | - * @uses $this->get_columns() |
|
330 | - * @uses $this->get_sortable_columns() |
|
331 | - * @uses $this->get_pagenum() |
|
332 | - * @uses $this->set_pagination_args() |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - function prepare_items() { |
|
336 | - |
|
337 | - $columns = $this->get_columns(); |
|
338 | - $hidden = array(); // No hidden columns |
|
339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
340 | - $sortable = $this->get_sortable_columns(); |
|
341 | - |
|
342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
343 | - |
|
344 | - $current_page = $this->get_pagenum(); |
|
345 | - |
|
346 | - $db = new WPInv_Subscriptions_DB; |
|
347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
348 | - $args = array( |
|
349 | - 'number' => $this->per_page, |
|
350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
351 | - 'search' => $search |
|
352 | - ); |
|
353 | - |
|
354 | - if ( 'any' !== $status ) { |
|
355 | - $args['status'] = $status; |
|
356 | - } |
|
357 | - |
|
358 | - $this->items = $db->get_subscriptions( $args ); |
|
359 | - |
|
360 | - switch ( $status ) { |
|
361 | - case 'active': |
|
362 | - $total_items = $this->active_count; |
|
363 | - break; |
|
364 | - case 'pending': |
|
365 | - $total_items = $this->pending_count; |
|
366 | - break; |
|
367 | - case 'expired': |
|
368 | - $total_items = $this->expired_count; |
|
369 | - break; |
|
370 | - case 'cancelled': |
|
371 | - $total_items = $this->cancelled_count; |
|
372 | - break; |
|
373 | - case 'failing': |
|
374 | - $total_items = $this->failing_count; |
|
375 | - break; |
|
376 | - case 'trialling': |
|
377 | - $total_items = $this->trialling_count; |
|
378 | - break; |
|
379 | - case 'completed': |
|
380 | - $total_items = $this->completed_count; |
|
381 | - break; |
|
382 | - case 'any': |
|
383 | - default: |
|
384 | - $total_items = $this->total_count; |
|
385 | - break; |
|
386 | - } |
|
387 | - |
|
388 | - $this->set_pagination_args( array( |
|
389 | - 'total_items' => $total_items, |
|
390 | - 'per_page' => $this->per_page, |
|
391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | - ) ); |
|
393 | - } |
|
154 | + /** |
|
155 | + * Customer column |
|
156 | + * |
|
157 | + * @access private |
|
158 | + * @since 1.0.0 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + function column_customer_id( $item ) { |
|
162 | + $subscriber = get_userdata( $item->customer_id ); |
|
163 | + $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
164 | + |
|
165 | + return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Status column |
|
170 | + * |
|
171 | + * @access private |
|
172 | + * @since 1.0.0 |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + function column_status( $item ) { |
|
176 | + return $item->get_status_label(); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Period column |
|
181 | + * |
|
182 | + * @access private |
|
183 | + * @since 1.0.0 |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + function column_period( $item ) { |
|
187 | + |
|
188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
189 | + |
|
190 | + return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Billing Times column |
|
195 | + * |
|
196 | + * @access private |
|
197 | + * @since 1.0.0 |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + function column_bill_times( $item ) { |
|
201 | + return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times ); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Initial Amount column |
|
206 | + * |
|
207 | + * @access private |
|
208 | + * @since 1.0.0 |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + function column_initial_amount( $item ) { |
|
212 | + return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Renewal date column |
|
217 | + * |
|
218 | + * @access private |
|
219 | + * @since 1.0.0 |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + function column_renewal_date( $item ) { |
|
223 | + return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Payment column |
|
228 | + * |
|
229 | + * @access private |
|
230 | + * @since 1.0.0 |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + function column_parent_payment_id( $item ) { |
|
234 | + return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Product ID column |
|
239 | + * |
|
240 | + * @access private |
|
241 | + * @since 1.0.0 |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + function column_product_id( $item ) { |
|
245 | + return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Render the edit column |
|
250 | + * |
|
251 | + * @access private |
|
252 | + * @since 2.0 |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + function column_actions( $item ) { |
|
256 | + return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Retrieve the table columns |
|
262 | + * |
|
263 | + * @access private |
|
264 | + * @since 1.0.0 |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + |
|
268 | + function get_columns(){ |
|
269 | + $columns = array( |
|
270 | + 'sub_id' => __( 'ID', 'invoicing' ), |
|
271 | + 'customer_id' => __( 'Customer', 'invoicing' ), |
|
272 | + 'status' => __( 'Status', 'invoicing' ), |
|
273 | + 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
274 | + 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
275 | + 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
276 | + 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
277 | + 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
278 | + 'product_id' => __( 'Item', 'invoicing' ), |
|
279 | + 'actions' => __( 'Actions', 'invoicing' ), |
|
280 | + ); |
|
281 | + |
|
282 | + return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Retrieve the current page number |
|
287 | + * |
|
288 | + * @access private |
|
289 | + * @since 1.0.0 |
|
290 | + * @return int |
|
291 | + */ |
|
292 | + function get_paged() { |
|
293 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Retrieve the subscription counts |
|
298 | + * |
|
299 | + * @access public |
|
300 | + * @since 1.4 |
|
301 | + * @return void |
|
302 | + */ |
|
303 | + public function get_subscription_counts() { |
|
304 | + |
|
305 | + global $wp_query; |
|
306 | + |
|
307 | + $db = new WPInv_Subscriptions_DB; |
|
308 | + |
|
309 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
310 | + |
|
311 | + $this->total_count = $db->count(); |
|
312 | + $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
313 | + $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
314 | + $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
315 | + $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
316 | + $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
317 | + $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
318 | + $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
319 | + |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Setup the final data for the table |
|
324 | + * |
|
325 | + * @access private |
|
326 | + * @since 1.0.0 |
|
327 | + * @uses $this->_column_headers |
|
328 | + * @uses $this->items |
|
329 | + * @uses $this->get_columns() |
|
330 | + * @uses $this->get_sortable_columns() |
|
331 | + * @uses $this->get_pagenum() |
|
332 | + * @uses $this->set_pagination_args() |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + function prepare_items() { |
|
336 | + |
|
337 | + $columns = $this->get_columns(); |
|
338 | + $hidden = array(); // No hidden columns |
|
339 | + $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
340 | + $sortable = $this->get_sortable_columns(); |
|
341 | + |
|
342 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
343 | + |
|
344 | + $current_page = $this->get_pagenum(); |
|
345 | + |
|
346 | + $db = new WPInv_Subscriptions_DB; |
|
347 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
348 | + $args = array( |
|
349 | + 'number' => $this->per_page, |
|
350 | + 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
351 | + 'search' => $search |
|
352 | + ); |
|
353 | + |
|
354 | + if ( 'any' !== $status ) { |
|
355 | + $args['status'] = $status; |
|
356 | + } |
|
357 | + |
|
358 | + $this->items = $db->get_subscriptions( $args ); |
|
359 | + |
|
360 | + switch ( $status ) { |
|
361 | + case 'active': |
|
362 | + $total_items = $this->active_count; |
|
363 | + break; |
|
364 | + case 'pending': |
|
365 | + $total_items = $this->pending_count; |
|
366 | + break; |
|
367 | + case 'expired': |
|
368 | + $total_items = $this->expired_count; |
|
369 | + break; |
|
370 | + case 'cancelled': |
|
371 | + $total_items = $this->cancelled_count; |
|
372 | + break; |
|
373 | + case 'failing': |
|
374 | + $total_items = $this->failing_count; |
|
375 | + break; |
|
376 | + case 'trialling': |
|
377 | + $total_items = $this->trialling_count; |
|
378 | + break; |
|
379 | + case 'completed': |
|
380 | + $total_items = $this->completed_count; |
|
381 | + break; |
|
382 | + case 'any': |
|
383 | + default: |
|
384 | + $total_items = $this->total_count; |
|
385 | + break; |
|
386 | + } |
|
387 | + |
|
388 | + $this->set_pagination_args( array( |
|
389 | + 'total_items' => $total_items, |
|
390 | + 'per_page' => $this->per_page, |
|
391 | + 'total_pages' => ceil( $total_items / $this->per_page ) |
|
392 | + ) ); |
|
393 | + } |
|
394 | 394 | } |
@@ -876,322 +876,322 @@ discard block |
||
876 | 876 | } |
877 | 877 | |
878 | 878 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
879 | - $pages_options = array(); |
|
879 | + $pages_options = array(); |
|
880 | 880 | |
881 | - if( $default_label !== NULL && $default_label !== false ) { |
|
882 | - $pages_options = array( '' => $default_label ); // Blank option |
|
883 | - } |
|
881 | + if( $default_label !== NULL && $default_label !== false ) { |
|
882 | + $pages_options = array( '' => $default_label ); // Blank option |
|
883 | + } |
|
884 | 884 | |
885 | - $pages = get_pages(); |
|
886 | - if ( $pages ) { |
|
887 | - foreach ( $pages as $page ) { |
|
888 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
885 | + $pages = get_pages(); |
|
886 | + if ( $pages ) { |
|
887 | + foreach ( $pages as $page ) { |
|
888 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
889 | 889 | $pages_options[ $page->ID ] = $title; |
890 | - } |
|
891 | - } |
|
890 | + } |
|
891 | + } |
|
892 | 892 | |
893 | - return $pages_options; |
|
893 | + return $pages_options; |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | function wpinv_header_callback( $args ) { |
897 | - if ( !empty( $args['desc'] ) ) { |
|
897 | + if ( !empty( $args['desc'] ) ) { |
|
898 | 898 | echo $args['desc']; |
899 | 899 | } |
900 | 900 | } |
901 | 901 | |
902 | 902 | function wpinv_hidden_callback( $args ) { |
903 | - global $wpinv_options; |
|
904 | - |
|
905 | - if ( isset( $args['set_value'] ) ) { |
|
906 | - $value = $args['set_value']; |
|
907 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
908 | - $value = $wpinv_options[ $args['id'] ]; |
|
909 | - } else { |
|
910 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
911 | - } |
|
912 | - |
|
913 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
914 | - $args['readonly'] = true; |
|
915 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
916 | - $name = ''; |
|
917 | - } else { |
|
918 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
919 | - } |
|
920 | - |
|
921 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
903 | + global $wpinv_options; |
|
904 | + |
|
905 | + if ( isset( $args['set_value'] ) ) { |
|
906 | + $value = $args['set_value']; |
|
907 | + } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
908 | + $value = $wpinv_options[ $args['id'] ]; |
|
909 | + } else { |
|
910 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
911 | + } |
|
912 | + |
|
913 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
914 | + $args['readonly'] = true; |
|
915 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
916 | + $name = ''; |
|
917 | + } else { |
|
918 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
919 | + } |
|
920 | + |
|
921 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
922 | 922 | |
923 | - echo $html; |
|
923 | + echo $html; |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | function wpinv_checkbox_callback( $args ) { |
927 | - global $wpinv_options; |
|
927 | + global $wpinv_options; |
|
928 | 928 | |
929 | 929 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
930 | 930 | |
931 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
932 | - $name = ''; |
|
933 | - } else { |
|
934 | - $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
935 | - } |
|
931 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
932 | + $name = ''; |
|
933 | + } else { |
|
934 | + $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
|
935 | + } |
|
936 | 936 | |
937 | - $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
938 | - $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
939 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
937 | + $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
938 | + $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
|
939 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
940 | 940 | |
941 | - echo $html; |
|
941 | + echo $html; |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | function wpinv_multicheck_callback( $args ) { |
945 | - global $wpinv_options; |
|
945 | + global $wpinv_options; |
|
946 | 946 | |
947 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
947 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
948 | 948 | |
949 | - if ( ! empty( $args['options'] ) ) { |
|
950 | - foreach( $args['options'] as $key => $option ): |
|
951 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
952 | - if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
953 | - $enabled = $sanitize_key; |
|
954 | - } else { |
|
955 | - $enabled = NULL; |
|
956 | - } |
|
957 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
958 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>'; |
|
959 | - endforeach; |
|
960 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
961 | - } |
|
949 | + if ( ! empty( $args['options'] ) ) { |
|
950 | + foreach( $args['options'] as $key => $option ): |
|
951 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
952 | + if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
953 | + $enabled = $sanitize_key; |
|
954 | + } else { |
|
955 | + $enabled = NULL; |
|
956 | + } |
|
957 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
958 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>'; |
|
959 | + endforeach; |
|
960 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
961 | + } |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | function wpinv_payment_icons_callback( $args ) { |
965 | - global $wpinv_options; |
|
965 | + global $wpinv_options; |
|
966 | 966 | |
967 | 967 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
968 | 968 | |
969 | - if ( ! empty( $args['options'] ) ) { |
|
970 | - foreach( $args['options'] as $key => $option ) { |
|
969 | + if ( ! empty( $args['options'] ) ) { |
|
970 | + foreach( $args['options'] as $key => $option ) { |
|
971 | 971 | $sanitize_key = wpinv_sanitize_key( $key ); |
972 | 972 | |
973 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
974 | - $enabled = $option; |
|
975 | - } else { |
|
976 | - $enabled = NULL; |
|
977 | - } |
|
978 | - |
|
979 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
980 | - |
|
981 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
982 | - |
|
983 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
984 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
985 | - } else { |
|
986 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
987 | - |
|
988 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
989 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
990 | - } else { |
|
991 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
992 | - $content_dir = WP_CONTENT_DIR; |
|
993 | - |
|
994 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
995 | - // Replaces backslashes with forward slashes for Windows systems |
|
996 | - $image = wp_normalize_path( $image ); |
|
997 | - $content_dir = wp_normalize_path( $content_dir ); |
|
998 | - } |
|
999 | - |
|
1000 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
1001 | - } |
|
1002 | - |
|
1003 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
1004 | - } |
|
1005 | - echo $option . '</label>'; |
|
1006 | - } |
|
1007 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
1008 | - } |
|
973 | + if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
974 | + $enabled = $option; |
|
975 | + } else { |
|
976 | + $enabled = NULL; |
|
977 | + } |
|
978 | + |
|
979 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
980 | + |
|
981 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
982 | + |
|
983 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
984 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
985 | + } else { |
|
986 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
987 | + |
|
988 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
989 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
990 | + } else { |
|
991 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
992 | + $content_dir = WP_CONTENT_DIR; |
|
993 | + |
|
994 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
995 | + // Replaces backslashes with forward slashes for Windows systems |
|
996 | + $image = wp_normalize_path( $image ); |
|
997 | + $content_dir = wp_normalize_path( $content_dir ); |
|
998 | + } |
|
999 | + |
|
1000 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
1001 | + } |
|
1002 | + |
|
1003 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
1004 | + } |
|
1005 | + echo $option . '</label>'; |
|
1006 | + } |
|
1007 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
1008 | + } |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | function wpinv_radio_callback( $args ) { |
1012 | - global $wpinv_options; |
|
1012 | + global $wpinv_options; |
|
1013 | 1013 | |
1014 | 1014 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1015 | 1015 | |
1016 | 1016 | foreach ( $args['options'] as $key => $option ) : |
1017 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
1017 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
1018 | 1018 | |
1019 | 1019 | $checked = false; |
1020 | 1020 | |
1021 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
1022 | - $checked = true; |
|
1023 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
1024 | - $checked = true; |
|
1021 | + if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
1022 | + $checked = true; |
|
1023 | + elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
1024 | + $checked = true; |
|
1025 | 1025 | |
1026 | - echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
1027 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
1028 | - endforeach; |
|
1026 | + echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
|
1027 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
1028 | + endforeach; |
|
1029 | 1029 | |
1030 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
1030 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | function wpinv_gateways_callback( $args ) { |
1034 | - global $wpinv_options; |
|
1034 | + global $wpinv_options; |
|
1035 | 1035 | |
1036 | 1036 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1037 | 1037 | |
1038 | - foreach ( $args['options'] as $key => $option ) : |
|
1039 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
1038 | + foreach ( $args['options'] as $key => $option ) : |
|
1039 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
1040 | 1040 | |
1041 | 1041 | if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
1042 | - $enabled = '1'; |
|
1043 | - else |
|
1044 | - $enabled = null; |
|
1042 | + $enabled = '1'; |
|
1043 | + else |
|
1044 | + $enabled = null; |
|
1045 | 1045 | |
1046 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
1047 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
1048 | - endforeach; |
|
1046 | + echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
1047 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
1048 | + endforeach; |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | function wpinv_gateway_select_callback($args) { |
1052 | - global $wpinv_options; |
|
1052 | + global $wpinv_options; |
|
1053 | 1053 | |
1054 | 1054 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1055 | 1055 | |
1056 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">'; |
|
1056 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">'; |
|
1057 | 1057 | |
1058 | - foreach ( $args['options'] as $key => $option ) : |
|
1059 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
1058 | + foreach ( $args['options'] as $key => $option ) : |
|
1059 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
1060 | 1060 | $selected = selected( $key, $args['selected'], false ); |
1061 | 1061 | } else { |
1062 | 1062 | $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
1063 | 1063 | } |
1064 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
1065 | - endforeach; |
|
1064 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
1065 | + endforeach; |
|
1066 | 1066 | |
1067 | - echo '</select>'; |
|
1068 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1067 | + echo '</select>'; |
|
1068 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | function wpinv_text_callback( $args ) { |
1072 | - global $wpinv_options; |
|
1072 | + global $wpinv_options; |
|
1073 | 1073 | |
1074 | 1074 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1075 | 1075 | |
1076 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1077 | - $value = $wpinv_options[ $args['id'] ]; |
|
1078 | - } else { |
|
1079 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1080 | - } |
|
1081 | - |
|
1082 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
1083 | - $args['readonly'] = true; |
|
1084 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1085 | - $name = ''; |
|
1086 | - } else { |
|
1087 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
1088 | - } |
|
1089 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
1090 | - |
|
1091 | - $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
1092 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1093 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
1094 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1095 | - |
|
1096 | - echo $html; |
|
1076 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1077 | + $value = $wpinv_options[ $args['id'] ]; |
|
1078 | + } else { |
|
1079 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1080 | + } |
|
1081 | + |
|
1082 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
1083 | + $args['readonly'] = true; |
|
1084 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1085 | + $name = ''; |
|
1086 | + } else { |
|
1087 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
1088 | + } |
|
1089 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
1090 | + |
|
1091 | + $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
|
1092 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1093 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
1094 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1095 | + |
|
1096 | + echo $html; |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | 1099 | function wpinv_number_callback( $args ) { |
1100 | - global $wpinv_options; |
|
1100 | + global $wpinv_options; |
|
1101 | 1101 | |
1102 | 1102 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1103 | 1103 | |
1104 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1105 | - $value = $wpinv_options[ $args['id'] ]; |
|
1106 | - } else { |
|
1107 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1108 | - } |
|
1109 | - |
|
1110 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
1111 | - $args['readonly'] = true; |
|
1112 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1113 | - $name = ''; |
|
1114 | - } else { |
|
1115 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
1116 | - } |
|
1117 | - |
|
1118 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
1119 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
1120 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
1121 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
1122 | - |
|
1123 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1124 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1125 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1126 | - |
|
1127 | - echo $html; |
|
1104 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1105 | + $value = $wpinv_options[ $args['id'] ]; |
|
1106 | + } else { |
|
1107 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1108 | + } |
|
1109 | + |
|
1110 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
1111 | + $args['readonly'] = true; |
|
1112 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1113 | + $name = ''; |
|
1114 | + } else { |
|
1115 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
1116 | + } |
|
1117 | + |
|
1118 | + $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
1119 | + $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
1120 | + $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
1121 | + $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
1122 | + |
|
1123 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1124 | + $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1125 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1126 | + |
|
1127 | + echo $html; |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | function wpinv_textarea_callback( $args ) { |
1131 | - global $wpinv_options; |
|
1131 | + global $wpinv_options; |
|
1132 | 1132 | |
1133 | 1133 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1134 | 1134 | |
1135 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1136 | - $value = $wpinv_options[ $args['id'] ]; |
|
1137 | - } else { |
|
1138 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1139 | - } |
|
1135 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1136 | + $value = $wpinv_options[ $args['id'] ]; |
|
1137 | + } else { |
|
1138 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1139 | + } |
|
1140 | 1140 | |
1141 | 1141 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
1142 | 1142 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
1143 | 1143 | |
1144 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1145 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1144 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1145 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1146 | 1146 | |
1147 | - echo $html; |
|
1147 | + echo $html; |
|
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | function wpinv_password_callback( $args ) { |
1151 | - global $wpinv_options; |
|
1151 | + global $wpinv_options; |
|
1152 | 1152 | |
1153 | 1153 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1154 | 1154 | |
1155 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1156 | - $value = $wpinv_options[ $args['id'] ]; |
|
1157 | - } else { |
|
1158 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1159 | - } |
|
1155 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1156 | + $value = $wpinv_options[ $args['id'] ]; |
|
1157 | + } else { |
|
1158 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1159 | + } |
|
1160 | 1160 | |
1161 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1162 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
1163 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1161 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1162 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
1163 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1164 | 1164 | |
1165 | - echo $html; |
|
1165 | + echo $html; |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | 1168 | function wpinv_missing_callback($args) { |
1169 | - printf( |
|
1170 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
1171 | - '<strong>' . $args['id'] . '</strong>' |
|
1172 | - ); |
|
1169 | + printf( |
|
1170 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
1171 | + '<strong>' . $args['id'] . '</strong>' |
|
1172 | + ); |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | 1175 | function wpinv_select_callback($args) { |
1176 | - global $wpinv_options; |
|
1176 | + global $wpinv_options; |
|
1177 | 1177 | |
1178 | 1178 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1179 | 1179 | |
1180 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1181 | - $value = $wpinv_options[ $args['id'] ]; |
|
1182 | - } else { |
|
1183 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1184 | - } |
|
1180 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1181 | + $value = $wpinv_options[ $args['id'] ]; |
|
1182 | + } else { |
|
1183 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1184 | + } |
|
1185 | 1185 | |
1186 | 1186 | if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
1187 | 1187 | $value = $args['selected']; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - if ( isset( $args['placeholder'] ) ) { |
|
1191 | - $placeholder = $args['placeholder']; |
|
1192 | - } else { |
|
1193 | - $placeholder = ''; |
|
1194 | - } |
|
1190 | + if ( isset( $args['placeholder'] ) ) { |
|
1191 | + $placeholder = $args['placeholder']; |
|
1192 | + } else { |
|
1193 | + $placeholder = ''; |
|
1194 | + } |
|
1195 | 1195 | |
1196 | 1196 | if( !empty( $args['onchange'] ) ) { |
1197 | 1197 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
@@ -1199,142 +1199,142 @@ discard block |
||
1199 | 1199 | $onchange = ''; |
1200 | 1200 | } |
1201 | 1201 | |
1202 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
1202 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
1203 | 1203 | |
1204 | - foreach ( $args['options'] as $option => $name ) { |
|
1205 | - $selected = selected( $option, $value, false ); |
|
1206 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1207 | - } |
|
1204 | + foreach ( $args['options'] as $option => $name ) { |
|
1205 | + $selected = selected( $option, $value, false ); |
|
1206 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1207 | + } |
|
1208 | 1208 | |
1209 | - $html .= '</select>'; |
|
1210 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1209 | + $html .= '</select>'; |
|
1210 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1211 | 1211 | |
1212 | - echo $html; |
|
1212 | + echo $html; |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | function wpinv_color_select_callback( $args ) { |
1216 | - global $wpinv_options; |
|
1216 | + global $wpinv_options; |
|
1217 | 1217 | |
1218 | 1218 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1219 | 1219 | |
1220 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1221 | - $value = $wpinv_options[ $args['id'] ]; |
|
1222 | - } else { |
|
1223 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1224 | - } |
|
1220 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1221 | + $value = $wpinv_options[ $args['id'] ]; |
|
1222 | + } else { |
|
1223 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1224 | + } |
|
1225 | 1225 | |
1226 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
1226 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
1227 | 1227 | |
1228 | - foreach ( $args['options'] as $option => $color ) { |
|
1229 | - $selected = selected( $option, $value, false ); |
|
1230 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
1231 | - } |
|
1228 | + foreach ( $args['options'] as $option => $color ) { |
|
1229 | + $selected = selected( $option, $value, false ); |
|
1230 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
1231 | + } |
|
1232 | 1232 | |
1233 | - $html .= '</select>'; |
|
1234 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1233 | + $html .= '</select>'; |
|
1234 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1235 | 1235 | |
1236 | - echo $html; |
|
1236 | + echo $html; |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | 1239 | function wpinv_rich_editor_callback( $args ) { |
1240 | - global $wpinv_options, $wp_version; |
|
1240 | + global $wpinv_options, $wp_version; |
|
1241 | 1241 | |
1242 | 1242 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1243 | 1243 | |
1244 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1245 | - $value = $wpinv_options[ $args['id'] ]; |
|
1244 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1245 | + $value = $wpinv_options[ $args['id'] ]; |
|
1246 | 1246 | |
1247 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
1248 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1249 | - } |
|
1250 | - } else { |
|
1251 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1252 | - } |
|
1247 | + if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
1248 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1249 | + } |
|
1250 | + } else { |
|
1251 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1252 | + } |
|
1253 | 1253 | |
1254 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
1254 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
1255 | 1255 | |
1256 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
1257 | - ob_start(); |
|
1258 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
1259 | - $html = ob_get_clean(); |
|
1260 | - } else { |
|
1261 | - $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1262 | - } |
|
1256 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
1257 | + ob_start(); |
|
1258 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
1259 | + $html = ob_get_clean(); |
|
1260 | + } else { |
|
1261 | + $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1262 | + } |
|
1263 | 1263 | |
1264 | - $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1264 | + $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1265 | 1265 | |
1266 | - echo $html; |
|
1266 | + echo $html; |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | function wpinv_upload_callback( $args ) { |
1270 | - global $wpinv_options; |
|
1270 | + global $wpinv_options; |
|
1271 | 1271 | |
1272 | 1272 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1273 | 1273 | |
1274 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1275 | - $value = $wpinv_options[$args['id']]; |
|
1276 | - } else { |
|
1277 | - $value = isset($args['std']) ? $args['std'] : ''; |
|
1278 | - } |
|
1274 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1275 | + $value = $wpinv_options[$args['id']]; |
|
1276 | + } else { |
|
1277 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1278 | + } |
|
1279 | 1279 | |
1280 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1281 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1282 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
1283 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1280 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1281 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1282 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
1283 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1284 | 1284 | |
1285 | - echo $html; |
|
1285 | + echo $html; |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | function wpinv_color_callback( $args ) { |
1289 | - global $wpinv_options; |
|
1289 | + global $wpinv_options; |
|
1290 | 1290 | |
1291 | 1291 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1292 | 1292 | |
1293 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1294 | - $value = $wpinv_options[ $args['id'] ]; |
|
1295 | - } else { |
|
1296 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1297 | - } |
|
1293 | + if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1294 | + $value = $wpinv_options[ $args['id'] ]; |
|
1295 | + } else { |
|
1296 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1297 | + } |
|
1298 | 1298 | |
1299 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
1299 | + $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
1300 | 1300 | |
1301 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
1302 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1301 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
1302 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1303 | 1303 | |
1304 | - echo $html; |
|
1304 | + echo $html; |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | 1307 | function wpinv_country_states_callback($args) { |
1308 | - global $wpinv_options; |
|
1308 | + global $wpinv_options; |
|
1309 | 1309 | |
1310 | 1310 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
1311 | 1311 | |
1312 | - if ( isset( $args['placeholder'] ) ) { |
|
1313 | - $placeholder = $args['placeholder']; |
|
1314 | - } else { |
|
1315 | - $placeholder = ''; |
|
1316 | - } |
|
1312 | + if ( isset( $args['placeholder'] ) ) { |
|
1313 | + $placeholder = $args['placeholder']; |
|
1314 | + } else { |
|
1315 | + $placeholder = ''; |
|
1316 | + } |
|
1317 | 1317 | |
1318 | - $states = wpinv_get_country_states(); |
|
1318 | + $states = wpinv_get_country_states(); |
|
1319 | 1319 | |
1320 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ''; |
|
1321 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
1320 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ''; |
|
1321 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
1322 | 1322 | |
1323 | - foreach ( $states as $option => $name ) { |
|
1324 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
1325 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1326 | - } |
|
1323 | + foreach ( $states as $option => $name ) { |
|
1324 | + $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
1325 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1326 | + } |
|
1327 | 1327 | |
1328 | - $html .= '</select>'; |
|
1329 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1328 | + $html .= '</select>'; |
|
1329 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1330 | 1330 | |
1331 | - echo $html; |
|
1331 | + echo $html; |
|
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | function wpinv_tax_rates_callback($args) { |
1335 | - global $wpinv_options; |
|
1336 | - $rates = wpinv_get_tax_rates(); |
|
1337 | - ob_start(); ?> |
|
1335 | + global $wpinv_options; |
|
1336 | + $rates = wpinv_get_tax_rates(); |
|
1337 | + ob_start(); ?> |
|
1338 | 1338 | </td><tr> |
1339 | 1339 | <td colspan="2" class="wpinv_tax_tdbox"> |
1340 | 1340 | <p><?php echo $args['desc']; ?></p> |
@@ -1358,39 +1358,39 @@ discard block |
||
1358 | 1358 | <tr> |
1359 | 1359 | <td class="wpinv_tax_country"> |
1360 | 1360 | <?php |
1361 | - echo wpinv_html_select( array( |
|
1362 | - 'options' => wpinv_get_country_list( true ), |
|
1363 | - 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
1361 | + echo wpinv_html_select( array( |
|
1362 | + 'options' => wpinv_get_country_list( true ), |
|
1363 | + 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
|
1364 | 1364 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
1365 | - 'selected' => $rate['country'], |
|
1366 | - 'show_option_all' => false, |
|
1367 | - 'show_option_none' => false, |
|
1368 | - 'class' => 'wpinv-tax-country', |
|
1369 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1370 | - ) ); |
|
1371 | - ?> |
|
1365 | + 'selected' => $rate['country'], |
|
1366 | + 'show_option_all' => false, |
|
1367 | + 'show_option_none' => false, |
|
1368 | + 'class' => 'wpinv-tax-country', |
|
1369 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1370 | + ) ); |
|
1371 | + ?> |
|
1372 | 1372 | </td> |
1373 | 1373 | <td class="wpinv_tax_state"> |
1374 | 1374 | <?php |
1375 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
1376 | - if( !empty( $states ) ) { |
|
1377 | - echo wpinv_html_select( array( |
|
1378 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
1379 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
1375 | + $states = wpinv_get_country_states( $rate['country'] ); |
|
1376 | + if( !empty( $states ) ) { |
|
1377 | + echo wpinv_html_select( array( |
|
1378 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
1379 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
|
1380 | 1380 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
1381 | - 'selected' => $rate['state'], |
|
1382 | - 'show_option_all' => false, |
|
1383 | - 'show_option_none' => false, |
|
1384 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
1385 | - ) ); |
|
1386 | - } else { |
|
1387 | - echo wpinv_html_text( array( |
|
1388 | - 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
1389 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
1381 | + 'selected' => $rate['state'], |
|
1382 | + 'show_option_all' => false, |
|
1383 | + 'show_option_none' => false, |
|
1384 | + 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
1385 | + ) ); |
|
1386 | + } else { |
|
1387 | + echo wpinv_html_text( array( |
|
1388 | + 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
|
1389 | + 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
1390 | 1390 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
1391 | - ) ); |
|
1392 | - } |
|
1393 | - ?> |
|
1391 | + ) ); |
|
1392 | + } |
|
1393 | + ?> |
|
1394 | 1394 | </td> |
1395 | 1395 | <td class="wpinv_tax_global"> |
1396 | 1396 | <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
@@ -1405,19 +1405,19 @@ discard block |
||
1405 | 1405 | <tr> |
1406 | 1406 | <td class="wpinv_tax_country"> |
1407 | 1407 | <?php |
1408 | - echo wpinv_html_select( array( |
|
1409 | - 'options' => wpinv_get_country_list( true ), |
|
1410 | - 'name' => 'tax_rates[0][country]', |
|
1411 | - 'show_option_all' => false, |
|
1412 | - 'show_option_none' => false, |
|
1413 | - 'class' => 'wpinv-tax-country', |
|
1414 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1415 | - ) ); ?> |
|
1408 | + echo wpinv_html_select( array( |
|
1409 | + 'options' => wpinv_get_country_list( true ), |
|
1410 | + 'name' => 'tax_rates[0][country]', |
|
1411 | + 'show_option_all' => false, |
|
1412 | + 'show_option_none' => false, |
|
1413 | + 'class' => 'wpinv-tax-country', |
|
1414 | + 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1415 | + ) ); ?> |
|
1416 | 1416 | </td> |
1417 | 1417 | <td class="wpinv_tax_state"> |
1418 | 1418 | <?php echo wpinv_html_text( array( |
1419 | - 'name' => 'tax_rates[0][state]' |
|
1420 | - ) ); ?> |
|
1419 | + 'name' => 'tax_rates[0][state]' |
|
1420 | + ) ); ?> |
|
1421 | 1421 | </td> |
1422 | 1422 | <td class="wpinv_tax_global"> |
1423 | 1423 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
1433 | 1433 | </table> |
1434 | 1434 | <?php |
1435 | - echo ob_get_clean(); |
|
1435 | + echo ob_get_clean(); |
|
1436 | 1436 | } |
1437 | 1437 | |
1438 | 1438 | function wpinv_tools_callback($args) { |
@@ -1460,15 +1460,15 @@ discard block |
||
1460 | 1460 | } |
1461 | 1461 | |
1462 | 1462 | function wpinv_descriptive_text_callback( $args ) { |
1463 | - echo wp_kses_post( $args['desc'] ); |
|
1463 | + echo wp_kses_post( $args['desc'] ); |
|
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | function wpinv_hook_callback( $args ) { |
1467 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1467 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1468 | 1468 | } |
1469 | 1469 | |
1470 | 1470 | function wpinv_set_settings_cap() { |
1471 | - return 'manage_options'; |
|
1471 | + return 'manage_options'; |
|
1472 | 1472 | } |
1473 | 1473 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1474 | 1474 |
@@ -8,23 +8,23 @@ discard block |
||
8 | 8 | */ |
9 | 9 | function wpinv_subscriptions_page() { |
10 | 10 | |
11 | - if ( ! empty( $_GET['id'] ) ) { |
|
11 | + if ( ! empty( $_GET['id'] ) ) { |
|
12 | 12 | |
13 | 13 | wpinv_recurring_subscription_details(); |
14 | 14 | |
15 | - return; |
|
15 | + return; |
|
16 | 16 | |
17 | - } |
|
18 | - ?> |
|
17 | + } |
|
18 | + ?> |
|
19 | 19 | <div class="wrap"> |
20 | 20 | |
21 | 21 | <h1> |
22 | 22 | <?php _e( 'Subscriptions', 'invoicing' ); ?> |
23 | 23 | </h1> |
24 | 24 | <?php |
25 | - $subscribers_table = new WPInv_Subscription_Reports_Table(); |
|
26 | - $subscribers_table->prepare_items(); |
|
27 | - ?> |
|
25 | + $subscribers_table = new WPInv_Subscription_Reports_Table(); |
|
26 | + $subscribers_table->prepare_items(); |
|
27 | + ?> |
|
28 | 28 | |
29 | 29 | <form id="subscribers-filter" method="get"> |
30 | 30 | |
@@ -47,24 +47,24 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function wpinv_recurring_subscription_details() { |
49 | 49 | |
50 | - $render = true; |
|
50 | + $render = true; |
|
51 | 51 | |
52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
54 | - } |
|
52 | + if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
53 | + die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
54 | + } |
|
55 | 55 | |
56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
56 | + if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
57 | 57 | die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - $sub_id = (int) $_GET['id']; |
|
61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
60 | + $sub_id = (int) $_GET['id']; |
|
61 | + $sub = new WPInv_Subscription( $sub_id ); |
|
62 | 62 | |
63 | - if ( empty( $sub ) ) { |
|
64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
65 | - } |
|
63 | + if ( empty( $sub ) ) { |
|
64 | + die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - ?> |
|
67 | + ?> |
|
68 | 68 | <div class="wrap"> |
69 | 69 | <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
70 | 70 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | </td> |
89 | 89 | <td> |
90 | 90 | <?php |
91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
95 | - ?> |
|
91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
92 | + $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
93 | + $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
94 | + printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
95 | + ?> |
|
96 | 96 | </td> |
97 | 97 | </tr> |
98 | 98 | <tr> |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | |
135 | 135 | ?> |
136 | 136 | <a href="<?php echo esc_url( add_query_arg( array( |
137 | - 'post' => $sub->product_id, |
|
138 | - 'action' => 'edit' |
|
139 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
137 | + 'post' => $sub->product_id, |
|
138 | + 'action' => 'edit' |
|
139 | + ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
140 | 140 | </td> |
141 | 141 | </tr> |
142 | 142 | <tr> |
@@ -299,58 +299,58 @@ discard block |
||
299 | 299 | */ |
300 | 300 | function wpinv_recurring_process_subscription_update() { |
301 | 301 | |
302 | - if( empty( $_POST['sub_id'] ) ) { |
|
303 | - return; |
|
304 | - } |
|
302 | + if( empty( $_POST['sub_id'] ) ) { |
|
303 | + return; |
|
304 | + } |
|
305 | 305 | |
306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
307 | - return; |
|
308 | - } |
|
306 | + if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
307 | + return; |
|
308 | + } |
|
309 | 309 | |
310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
311 | - return; |
|
312 | - } |
|
310 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
311 | + return; |
|
312 | + } |
|
313 | 313 | |
314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
316 | - } |
|
314 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
315 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
316 | + } |
|
317 | 317 | |
318 | - $expiration = date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'] ) ); |
|
319 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
320 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
321 | - $product_id = absint( $_POST['product_id'] ); |
|
322 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
323 | - $subscription->update( array( |
|
324 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
325 | - 'expiration' => $expiration, |
|
326 | - 'profile_id' => $profile_id, |
|
327 | - 'product_id' => $product_id, |
|
328 | - 'transaction_id' => $transaction_id, |
|
329 | - ) ); |
|
318 | + $expiration = date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'] ) ); |
|
319 | + $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
320 | + $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
321 | + $product_id = absint( $_POST['product_id'] ); |
|
322 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
323 | + $subscription->update( array( |
|
324 | + 'status' => sanitize_text_field( $_POST['status'] ), |
|
325 | + 'expiration' => $expiration, |
|
326 | + 'profile_id' => $profile_id, |
|
327 | + 'product_id' => $product_id, |
|
328 | + 'transaction_id' => $transaction_id, |
|
329 | + ) ); |
|
330 | 330 | |
331 | - $status = sanitize_text_field( $_POST['status'] ); |
|
331 | + $status = sanitize_text_field( $_POST['status'] ); |
|
332 | 332 | |
333 | - switch( $status ) { |
|
333 | + switch( $status ) { |
|
334 | 334 | |
335 | - case 'cancelled' : |
|
335 | + case 'cancelled' : |
|
336 | 336 | |
337 | - $subscription->cancel(); |
|
338 | - break; |
|
337 | + $subscription->cancel(); |
|
338 | + break; |
|
339 | 339 | |
340 | - case 'expired' : |
|
340 | + case 'expired' : |
|
341 | 341 | |
342 | - $subscription->expire(); |
|
343 | - break; |
|
342 | + $subscription->expire(); |
|
343 | + break; |
|
344 | 344 | |
345 | - case 'completed' : |
|
345 | + case 'completed' : |
|
346 | 346 | |
347 | - $subscription->complete(); |
|
348 | - break; |
|
347 | + $subscription->complete(); |
|
348 | + break; |
|
349 | 349 | |
350 | - } |
|
350 | + } |
|
351 | 351 | |
352 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
353 | - exit; |
|
352 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
353 | + exit; |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
@@ -364,30 +364,30 @@ discard block |
||
364 | 364 | */ |
365 | 365 | function wpinv_recurring_process_subscription_deletion() { |
366 | 366 | |
367 | - if( empty( $_POST['sub_id'] ) ) { |
|
368 | - return; |
|
369 | - } |
|
367 | + if( empty( $_POST['sub_id'] ) ) { |
|
368 | + return; |
|
369 | + } |
|
370 | 370 | |
371 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
372 | - return; |
|
373 | - } |
|
371 | + if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
372 | + return; |
|
373 | + } |
|
374 | 374 | |
375 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
376 | - return; |
|
377 | - } |
|
375 | + if( ! current_user_can( 'manage_invoicing') ) { |
|
376 | + return; |
|
377 | + } |
|
378 | 378 | |
379 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
380 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
381 | - } |
|
379 | + if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
380 | + wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
381 | + } |
|
382 | 382 | |
383 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
383 | + $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
384 | 384 | |
385 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
385 | + delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
386 | 386 | |
387 | - $subscription->delete(); |
|
387 | + $subscription->delete(); |
|
388 | 388 | |
389 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
390 | - exit; |
|
389 | + wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
390 | + exit; |
|
391 | 391 | |
392 | 392 | } |
393 | 393 | add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
@@ -176,69 +176,69 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | function wpinv_admin_messages() { |
179 | - global $wpinv_options, $pagenow, $post; |
|
179 | + global $wpinv_options, $pagenow, $post; |
|
180 | 180 | |
181 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
182 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
183 | - } |
|
181 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
182 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
183 | + } |
|
184 | 184 | |
185 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
186 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
187 | - } |
|
185 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
186 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
187 | + } |
|
188 | 188 | |
189 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
190 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
191 | - } |
|
189 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
190 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
191 | + } |
|
192 | 192 | |
193 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
194 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
195 | - } |
|
193 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
194 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
195 | + } |
|
196 | 196 | |
197 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
198 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
199 | - } |
|
197 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
198 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
199 | + } |
|
200 | 200 | |
201 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
202 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
203 | - } |
|
201 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
202 | + add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
203 | + } |
|
204 | 204 | |
205 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
206 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
207 | - } |
|
205 | + if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
206 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
207 | + } |
|
208 | 208 | |
209 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
210 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
209 | + if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
210 | + add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
214 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
214 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
218 | 218 | add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
219 | 219 | } |
220 | 220 | |
221 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
222 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
223 | - } |
|
221 | + if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
222 | + add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
223 | + } |
|
224 | 224 | |
225 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
226 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
227 | - } |
|
225 | + if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
226 | + add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
227 | + } |
|
228 | 228 | |
229 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
230 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
231 | - } |
|
229 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
230 | + add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
231 | + } |
|
232 | 232 | |
233 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
234 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
233 | + if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
234 | + $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
235 | 235 | |
236 | - if ( !empty( $message ) ) { |
|
237 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
238 | - } |
|
239 | - } |
|
236 | + if ( !empty( $message ) ) { |
|
237 | + add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - settings_errors( 'wpinv-notices' ); |
|
241 | + settings_errors( 'wpinv-notices' ); |
|
242 | 242 | } |
243 | 243 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
244 | 244 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | break; |
302 | 302 | case 'id' : |
303 | 303 | echo $post->ID; |
304 | - echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
304 | + echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
305 | 305 | <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
306 | 306 | if ( $wpinv_euvat->allow_vat_rules() ) { |
307 | 307 | echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |