@@ -12,72 +12,72 @@ discard block |
||
12 | 12 | */ |
13 | 13 | abstract class GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $stats; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->prepare_stats(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Retrieves the current range. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function get_range() { |
|
33 | - $valid_ranges = $this->get_periods(); |
|
34 | - |
|
35 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
36 | - return sanitize_key( $_GET['date_range'] ); |
|
37 | - } |
|
38 | - |
|
39 | - return '7_days'; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Returns an array of date ranges. |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function get_periods() { |
|
48 | - |
|
49 | - $periods = array( |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $stats; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->prepare_stats(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Retrieves the current range. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function get_range() { |
|
33 | + $valid_ranges = $this->get_periods(); |
|
34 | + |
|
35 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
36 | + return sanitize_key( $_GET['date_range'] ); |
|
37 | + } |
|
38 | + |
|
39 | + return '7_days'; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Returns an array of date ranges. |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function get_periods() { |
|
48 | + |
|
49 | + $periods = array( |
|
50 | 50 | 'today' => __( 'Today', 'invoicing' ), |
51 | 51 | 'yesterday' => __( 'Yesterday', 'invoicing' ), |
52 | 52 | '7_days' => __( 'Last 7 days', 'invoicing' ), |
53 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
54 | - '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
55 | - '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
56 | - '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
57 | - '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
58 | - ); |
|
59 | - |
|
60 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Retrieves the current range's sql. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function get_range_sql( $range ) { |
|
68 | - |
|
69 | - $date = 'CAST(meta.completed_date AS DATE)'; |
|
53 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
54 | + '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
55 | + '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
56 | + '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
57 | + '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
58 | + ); |
|
59 | + |
|
60 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Retrieves the current range's sql. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function get_range_sql( $range ) { |
|
68 | + |
|
69 | + $date = 'CAST(meta.completed_date AS DATE)'; |
|
70 | 70 | $datetime = 'meta.completed_date'; |
71 | 71 | |
72 | 72 | // Prepare durations. |
73 | 73 | $today = current_time( 'Y-m-d' ); |
74 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
75 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
76 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
77 | - $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
78 | - $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
79 | - $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
80 | - $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
74 | + $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
75 | + $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
76 | + $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
77 | + $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
78 | + $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
79 | + $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
80 | + $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
81 | 81 | |
82 | 82 | $ranges = array( |
83 | 83 | |
@@ -94,130 +94,130 @@ discard block |
||
94 | 94 | '7_days' => array( |
95 | 95 | "DATE($datetime)", |
96 | 96 | "$date BETWEEN '$seven_days_ago' AND '$today'" |
97 | - ), |
|
97 | + ), |
|
98 | 98 | |
99 | - '30_days' => array( |
|
99 | + '30_days' => array( |
|
100 | 100 | "DATE($datetime)", |
101 | 101 | "$date BETWEEN '$thirty_days_ago' AND '$today'" |
102 | - ), |
|
102 | + ), |
|
103 | 103 | |
104 | - '60_days' => array( |
|
104 | + '60_days' => array( |
|
105 | 105 | "DATE($datetime)", |
106 | 106 | "$date BETWEEN '$sixty_days_ago' AND '$today'" |
107 | - ), |
|
107 | + ), |
|
108 | 108 | |
109 | - '90_days' => array( |
|
109 | + '90_days' => array( |
|
110 | 110 | "WEEK($datetime)", |
111 | 111 | "$date BETWEEN '$ninety_days_ago' AND '$today'" |
112 | - ), |
|
112 | + ), |
|
113 | 113 | |
114 | - '180_days' => array( |
|
114 | + '180_days' => array( |
|
115 | 115 | "WEEK($datetime)", |
116 | 116 | "$date BETWEEN '$one_eighty_days_ago' AND '$today'" |
117 | - ), |
|
117 | + ), |
|
118 | 118 | |
119 | - '360_days' => array( |
|
119 | + '360_days' => array( |
|
120 | 120 | "WEEK($datetime)", |
121 | 121 | "$date BETWEEN '$three_sixty_days_ago' AND '$today'" |
122 | 122 | ), |
123 | 123 | |
124 | 124 | ); |
125 | 125 | |
126 | - $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
127 | - return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Retrieves the hours in a day |
|
133 | - * |
|
134 | - */ |
|
135 | - public function get_hours_in_a_day() { |
|
136 | - |
|
137 | - return array( |
|
138 | - '12AM' => __( '12 AM', 'invoicing'), |
|
139 | - '1AM' => __( '1 AM', 'invoicing'), |
|
140 | - '2AM' => __( '2 AM', 'invoicing'), |
|
141 | - '3AM' => __( '3 AM', 'invoicing'), |
|
142 | - '4AM' => __( '4 AM', 'invoicing'), |
|
143 | - '5AM' => __( '5 AM', 'invoicing'), |
|
144 | - '6AM' => __( '6 AM', 'invoicing'), |
|
145 | - '7AM' => __( '7 AM', 'invoicing'), |
|
146 | - '8AM' => __( '8 AM', 'invoicing'), |
|
147 | - '9AM' => __( '9 AM', 'invoicing'), |
|
148 | - '10AM' => __( '10 AM', 'invoicing'), |
|
149 | - '11AM' => __( '11 AM', 'invoicing'), |
|
150 | - '12pm' => __( '12 PM', 'invoicing'), |
|
151 | - '1PM' => __( '1 PM', 'invoicing'), |
|
152 | - '2PM' => __( '2 PM', 'invoicing'), |
|
153 | - '3PM' => __( '3 PM', 'invoicing'), |
|
154 | - '4PM' => __( '4 PM', 'invoicing'), |
|
155 | - '5PM' => __( '5 PM', 'invoicing'), |
|
156 | - '6PM' => __( '6 PM', 'invoicing'), |
|
157 | - '7PM' => __( '7 PM', 'invoicing'), |
|
158 | - '8PM' => __( '8 PM', 'invoicing'), |
|
159 | - '9PM' => __( '9 PM', 'invoicing'), |
|
160 | - '10PM' => __( '10 PM', 'invoicing'), |
|
161 | - '11PM' => __( '11 PM', 'invoicing'), |
|
162 | - ); |
|
163 | - |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Retrieves the days in a period |
|
168 | - * |
|
169 | - */ |
|
170 | - public function get_days_in_period( $days ) { |
|
171 | - |
|
172 | - $return = array(); |
|
173 | - $format = 'Y-m-d'; |
|
174 | - |
|
175 | - if ( $days < 8 ) { |
|
176 | - $format = 'D'; |
|
177 | - } |
|
178 | - |
|
179 | - if ( $days < 32 ) { |
|
180 | - $format = 'M j'; |
|
181 | - } |
|
182 | - |
|
183 | - while ( $days > 0 ) { |
|
184 | - |
|
185 | - $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
186 | - $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
187 | - $return[ $key ] = $label; |
|
188 | - $days--; |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - return $return; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Retrieves the weeks in a period |
|
197 | - * |
|
198 | - */ |
|
199 | - public function get_weeks_in_period( $days ) { |
|
200 | - |
|
201 | - $return = array(); |
|
202 | - |
|
203 | - while ( $days > 0 ) { |
|
204 | - |
|
205 | - $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
206 | - $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
207 | - $return[ $key ] = $label; |
|
208 | - $days--; |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - return $return; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Displays the report card. |
|
217 | - * |
|
218 | - */ |
|
219 | - public function display() { |
|
220 | - ?> |
|
126 | + $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
127 | + return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Retrieves the hours in a day |
|
133 | + * |
|
134 | + */ |
|
135 | + public function get_hours_in_a_day() { |
|
136 | + |
|
137 | + return array( |
|
138 | + '12AM' => __( '12 AM', 'invoicing'), |
|
139 | + '1AM' => __( '1 AM', 'invoicing'), |
|
140 | + '2AM' => __( '2 AM', 'invoicing'), |
|
141 | + '3AM' => __( '3 AM', 'invoicing'), |
|
142 | + '4AM' => __( '4 AM', 'invoicing'), |
|
143 | + '5AM' => __( '5 AM', 'invoicing'), |
|
144 | + '6AM' => __( '6 AM', 'invoicing'), |
|
145 | + '7AM' => __( '7 AM', 'invoicing'), |
|
146 | + '8AM' => __( '8 AM', 'invoicing'), |
|
147 | + '9AM' => __( '9 AM', 'invoicing'), |
|
148 | + '10AM' => __( '10 AM', 'invoicing'), |
|
149 | + '11AM' => __( '11 AM', 'invoicing'), |
|
150 | + '12pm' => __( '12 PM', 'invoicing'), |
|
151 | + '1PM' => __( '1 PM', 'invoicing'), |
|
152 | + '2PM' => __( '2 PM', 'invoicing'), |
|
153 | + '3PM' => __( '3 PM', 'invoicing'), |
|
154 | + '4PM' => __( '4 PM', 'invoicing'), |
|
155 | + '5PM' => __( '5 PM', 'invoicing'), |
|
156 | + '6PM' => __( '6 PM', 'invoicing'), |
|
157 | + '7PM' => __( '7 PM', 'invoicing'), |
|
158 | + '8PM' => __( '8 PM', 'invoicing'), |
|
159 | + '9PM' => __( '9 PM', 'invoicing'), |
|
160 | + '10PM' => __( '10 PM', 'invoicing'), |
|
161 | + '11PM' => __( '11 PM', 'invoicing'), |
|
162 | + ); |
|
163 | + |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Retrieves the days in a period |
|
168 | + * |
|
169 | + */ |
|
170 | + public function get_days_in_period( $days ) { |
|
171 | + |
|
172 | + $return = array(); |
|
173 | + $format = 'Y-m-d'; |
|
174 | + |
|
175 | + if ( $days < 8 ) { |
|
176 | + $format = 'D'; |
|
177 | + } |
|
178 | + |
|
179 | + if ( $days < 32 ) { |
|
180 | + $format = 'M j'; |
|
181 | + } |
|
182 | + |
|
183 | + while ( $days > 0 ) { |
|
184 | + |
|
185 | + $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
186 | + $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
187 | + $return[ $key ] = $label; |
|
188 | + $days--; |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + return $return; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Retrieves the weeks in a period |
|
197 | + * |
|
198 | + */ |
|
199 | + public function get_weeks_in_period( $days ) { |
|
200 | + |
|
201 | + $return = array(); |
|
202 | + |
|
203 | + while ( $days > 0 ) { |
|
204 | + |
|
205 | + $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
206 | + $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
207 | + $return[ $key ] = $label; |
|
208 | + $days--; |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + return $return; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Displays the report card. |
|
217 | + * |
|
218 | + */ |
|
219 | + public function display() { |
|
220 | + ?> |
|
221 | 221 | |
222 | 222 | <div class="row"> |
223 | 223 | <div class="col-12"> |
@@ -231,20 +231,20 @@ discard block |
||
231 | 231 | |
232 | 232 | <?php |
233 | 233 | |
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Prepares the report stats. |
|
238 | - * |
|
239 | - * Extend this in child classes. |
|
240 | - */ |
|
241 | - abstract public function prepare_stats(); |
|
242 | - |
|
243 | - /** |
|
244 | - * Displays the actual report. |
|
245 | - * |
|
246 | - * Extend this in child classes. |
|
247 | - */ |
|
248 | - abstract public function display_stats(); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Prepares the report stats. |
|
238 | + * |
|
239 | + * Extend this in child classes. |
|
240 | + */ |
|
241 | + abstract public function prepare_stats(); |
|
242 | + |
|
243 | + /** |
|
244 | + * Displays the actual report. |
|
245 | + * |
|
246 | + * Extend this in child classes. |
|
247 | + */ |
|
248 | + abstract public function display_stats(); |
|
249 | 249 | |
250 | 250 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Abstract_Report Class. |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | public function get_range() { |
33 | 33 | $valid_ranges = $this->get_periods(); |
34 | 34 | |
35 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
36 | - return sanitize_key( $_GET['date_range'] ); |
|
35 | + if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) { |
|
36 | + return sanitize_key($_GET['date_range']); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return '7_days'; |
@@ -47,37 +47,37 @@ discard block |
||
47 | 47 | public function get_periods() { |
48 | 48 | |
49 | 49 | $periods = array( |
50 | - 'today' => __( 'Today', 'invoicing' ), |
|
51 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
52 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
53 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
54 | - '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
55 | - '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
56 | - '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
57 | - '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
50 | + 'today' => __('Today', 'invoicing'), |
|
51 | + 'yesterday' => __('Yesterday', 'invoicing'), |
|
52 | + '7_days' => __('Last 7 days', 'invoicing'), |
|
53 | + '30_days' => __('Last 30 days', 'invoicing'), |
|
54 | + '60_days' => __('Last 60 days', 'invoicing'), |
|
55 | + '90_days' => __('Last 90 days', 'invoicing'), |
|
56 | + '180_days' => __('Last 180 days', 'invoicing'), |
|
57 | + '360_days' => __('Last 360 days', 'invoicing'), |
|
58 | 58 | ); |
59 | 59 | |
60 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
60 | + return apply_filters('getpaid_earning_periods', $periods); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Retrieves the current range's sql. |
65 | 65 | * |
66 | 66 | */ |
67 | - public function get_range_sql( $range ) { |
|
67 | + public function get_range_sql($range) { |
|
68 | 68 | |
69 | - $date = 'CAST(meta.completed_date AS DATE)'; |
|
69 | + $date = 'CAST(meta.completed_date AS DATE)'; |
|
70 | 70 | $datetime = 'meta.completed_date'; |
71 | 71 | |
72 | 72 | // Prepare durations. |
73 | - $today = current_time( 'Y-m-d' ); |
|
74 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
75 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
76 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
77 | - $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
78 | - $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
79 | - $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
80 | - $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
73 | + $today = current_time('Y-m-d'); |
|
74 | + $yesterday = date('Y-m-d', strtotime('-1 day', current_time('timestamp'))); |
|
75 | + $seven_days_ago = date('Y-m-d', strtotime('-7 days', current_time('timestamp'))); |
|
76 | + $thirty_days_ago = date('Y-m-d', strtotime('-30 days', current_time('timestamp'))); |
|
77 | + $ninety_days_ago = date('Y-m-d', strtotime('-90 days', current_time('timestamp'))); |
|
78 | + $sixty_days_ago = date('Y-m-d', strtotime('-60 days', current_time('timestamp'))); |
|
79 | + $one_eighty_days_ago = date('Y-m-d', strtotime('-180 days', current_time('timestamp'))); |
|
80 | + $three_sixty_days_ago = date('Y-m-d', strtotime('-360 days', current_time('timestamp'))); |
|
81 | 81 | |
82 | 82 | $ranges = array( |
83 | 83 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | |
124 | 124 | ); |
125 | 125 | |
126 | - $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges[ '7_days' ]; |
|
127 | - return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
126 | + $sql = isset($ranges[$range]) ? $ranges[$range] : $ranges['7_days']; |
|
127 | + return apply_filters('getpaid_earning_graphs_get_range_sql', $sql, $range); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
@@ -135,30 +135,30 @@ discard block |
||
135 | 135 | public function get_hours_in_a_day() { |
136 | 136 | |
137 | 137 | return array( |
138 | - '12AM' => __( '12 AM', 'invoicing'), |
|
139 | - '1AM' => __( '1 AM', 'invoicing'), |
|
140 | - '2AM' => __( '2 AM', 'invoicing'), |
|
141 | - '3AM' => __( '3 AM', 'invoicing'), |
|
142 | - '4AM' => __( '4 AM', 'invoicing'), |
|
143 | - '5AM' => __( '5 AM', 'invoicing'), |
|
144 | - '6AM' => __( '6 AM', 'invoicing'), |
|
145 | - '7AM' => __( '7 AM', 'invoicing'), |
|
146 | - '8AM' => __( '8 AM', 'invoicing'), |
|
147 | - '9AM' => __( '9 AM', 'invoicing'), |
|
148 | - '10AM' => __( '10 AM', 'invoicing'), |
|
149 | - '11AM' => __( '11 AM', 'invoicing'), |
|
150 | - '12pm' => __( '12 PM', 'invoicing'), |
|
151 | - '1PM' => __( '1 PM', 'invoicing'), |
|
152 | - '2PM' => __( '2 PM', 'invoicing'), |
|
153 | - '3PM' => __( '3 PM', 'invoicing'), |
|
154 | - '4PM' => __( '4 PM', 'invoicing'), |
|
155 | - '5PM' => __( '5 PM', 'invoicing'), |
|
156 | - '6PM' => __( '6 PM', 'invoicing'), |
|
157 | - '7PM' => __( '7 PM', 'invoicing'), |
|
158 | - '8PM' => __( '8 PM', 'invoicing'), |
|
159 | - '9PM' => __( '9 PM', 'invoicing'), |
|
160 | - '10PM' => __( '10 PM', 'invoicing'), |
|
161 | - '11PM' => __( '11 PM', 'invoicing'), |
|
138 | + '12AM' => __('12 AM', 'invoicing'), |
|
139 | + '1AM' => __('1 AM', 'invoicing'), |
|
140 | + '2AM' => __('2 AM', 'invoicing'), |
|
141 | + '3AM' => __('3 AM', 'invoicing'), |
|
142 | + '4AM' => __('4 AM', 'invoicing'), |
|
143 | + '5AM' => __('5 AM', 'invoicing'), |
|
144 | + '6AM' => __('6 AM', 'invoicing'), |
|
145 | + '7AM' => __('7 AM', 'invoicing'), |
|
146 | + '8AM' => __('8 AM', 'invoicing'), |
|
147 | + '9AM' => __('9 AM', 'invoicing'), |
|
148 | + '10AM' => __('10 AM', 'invoicing'), |
|
149 | + '11AM' => __('11 AM', 'invoicing'), |
|
150 | + '12pm' => __('12 PM', 'invoicing'), |
|
151 | + '1PM' => __('1 PM', 'invoicing'), |
|
152 | + '2PM' => __('2 PM', 'invoicing'), |
|
153 | + '3PM' => __('3 PM', 'invoicing'), |
|
154 | + '4PM' => __('4 PM', 'invoicing'), |
|
155 | + '5PM' => __('5 PM', 'invoicing'), |
|
156 | + '6PM' => __('6 PM', 'invoicing'), |
|
157 | + '7PM' => __('7 PM', 'invoicing'), |
|
158 | + '8PM' => __('8 PM', 'invoicing'), |
|
159 | + '9PM' => __('9 PM', 'invoicing'), |
|
160 | + '10PM' => __('10 PM', 'invoicing'), |
|
161 | + '11PM' => __('11 PM', 'invoicing'), |
|
162 | 162 | ); |
163 | 163 | |
164 | 164 | } |
@@ -167,24 +167,24 @@ discard block |
||
167 | 167 | * Retrieves the days in a period |
168 | 168 | * |
169 | 169 | */ |
170 | - public function get_days_in_period( $days ) { |
|
170 | + public function get_days_in_period($days) { |
|
171 | 171 | |
172 | 172 | $return = array(); |
173 | 173 | $format = 'Y-m-d'; |
174 | 174 | |
175 | - if ( $days < 8 ) { |
|
175 | + if ($days < 8) { |
|
176 | 176 | $format = 'D'; |
177 | 177 | } |
178 | 178 | |
179 | - if ( $days < 32 ) { |
|
179 | + if ($days < 32) { |
|
180 | 180 | $format = 'M j'; |
181 | 181 | } |
182 | 182 | |
183 | - while ( $days > 0 ) { |
|
183 | + while ($days > 0) { |
|
184 | 184 | |
185 | - $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
186 | - $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
187 | - $return[ $key ] = $label; |
|
185 | + $key = date('Y-m-d', strtotime("-$days days", current_time('timestamp'))); |
|
186 | + $label = date_i18n($format, strtotime("-$days days", current_time('timestamp'))); |
|
187 | + $return[$key] = $label; |
|
188 | 188 | $days--; |
189 | 189 | |
190 | 190 | } |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | * Retrieves the weeks in a period |
197 | 197 | * |
198 | 198 | */ |
199 | - public function get_weeks_in_period( $days ) { |
|
199 | + public function get_weeks_in_period($days) { |
|
200 | 200 | |
201 | 201 | $return = array(); |
202 | 202 | |
203 | - while ( $days > 0 ) { |
|
203 | + while ($days > 0) { |
|
204 | 204 | |
205 | - $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
206 | - $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
207 | - $return[ $key ] = $label; |
|
205 | + $key = date('W', strtotime("-$days days", current_time('timestamp'))); |
|
206 | + $label = date_i18n('Y-m-d', strtotime("-$days days", current_time('timestamp'))); |
|
207 | + $return[$key] = $label; |
|
208 | 208 | $days--; |
209 | 209 | |
210 | 210 | } |
@@ -13,154 +13,154 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_MaxMind_Database_Service { |
15 | 15 | |
16 | - /** |
|
17 | - * The name of the MaxMind database to utilize. |
|
18 | - */ |
|
19 | - const DATABASE = 'GeoLite2-Country'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The extension for the MaxMind database. |
|
23 | - */ |
|
24 | - const DATABASE_EXTENSION = '.mmdb'; |
|
25 | - |
|
26 | - /** |
|
27 | - * A prefix for the MaxMind database filename. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $database_prefix; |
|
32 | - |
|
33 | - /** |
|
34 | - * Class constructor. |
|
35 | - * |
|
36 | - * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | - */ |
|
38 | - public function __construct( $database_prefix ) { |
|
39 | - $this->database_prefix = $database_prefix; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Fetches the path that the database should be stored. |
|
44 | - * |
|
45 | - * @return string The local database path. |
|
46 | - */ |
|
47 | - public function get_database_path() { |
|
48 | - $uploads_dir = wp_upload_dir(); |
|
49 | - |
|
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
52 | - $database_path .= $this->database_prefix . '-'; |
|
53 | - } |
|
54 | - $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | - |
|
56 | - // Filter the geolocation database storage path. |
|
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fetches the database from the MaxMind service. |
|
62 | - * |
|
63 | - * @param string $license_key The license key to be used when downloading the database. |
|
64 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | - */ |
|
66 | - public function download_database( $license_key ) { |
|
67 | - |
|
68 | - $download_uri = add_query_arg( |
|
69 | - array( |
|
70 | - 'edition_id' => self::DATABASE, |
|
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | - 'suffix' => 'tar.gz', |
|
73 | - ), |
|
74 | - 'https://download.maxmind.com/app/geoip_download' |
|
75 | - ); |
|
76 | - |
|
77 | - // Needed for the download_url call right below. |
|
78 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | - |
|
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | - |
|
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | - // Transform the error into something more informative. |
|
84 | - $error_data = $tmp_archive_path->get_error_data(); |
|
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | - return new WP_Error( |
|
87 | - 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | - } |
|
94 | - |
|
95 | - // Extract the database from the archive. |
|
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Extracts the downloaded database. |
|
102 | - * |
|
103 | - * @param string $tmp_archive_path The database archive path. |
|
104 | - * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | - */ |
|
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | - |
|
108 | - // Extract the database from the archive. |
|
109 | - $tmp_database_path = ''; |
|
110 | - |
|
111 | - try { |
|
112 | - |
|
113 | - $file = new PharData( $tmp_archive_path ); |
|
114 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | - |
|
116 | - $file->extractTo( |
|
117 | - dirname( $tmp_archive_path ), |
|
118 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | - true |
|
120 | - ); |
|
121 | - |
|
122 | - } catch ( Exception $exception ) { |
|
123 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
124 | - } finally { |
|
125 | - // Remove the archive since we only care about a single file in it. |
|
126 | - unlink( $tmp_archive_path ); |
|
127 | - } |
|
128 | - |
|
129 | - return $tmp_database_path; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Fetches the ISO country code associated with an IP address. |
|
134 | - * |
|
135 | - * @param string $ip_address The IP address to find the country code for. |
|
136 | - * @return string The country code for the IP address, or empty if not found. |
|
137 | - */ |
|
138 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
139 | - $country_code = ''; |
|
140 | - |
|
141 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
142 | - return $country_code; |
|
143 | - } |
|
144 | - |
|
145 | - $database_path = $this->get_database_path(); |
|
146 | - if ( ! file_exists( $database_path ) ) { |
|
147 | - return $country_code; |
|
148 | - } |
|
149 | - |
|
150 | - try { |
|
151 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | - $data = $reader->get( $ip_address ); |
|
153 | - |
|
154 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
155 | - $country_code = $data['country']['iso_code']; |
|
156 | - } |
|
157 | - |
|
158 | - $reader->close(); |
|
159 | - } catch ( Exception $e ) { |
|
160 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
161 | - } |
|
162 | - |
|
163 | - return $country_code; |
|
164 | - } |
|
16 | + /** |
|
17 | + * The name of the MaxMind database to utilize. |
|
18 | + */ |
|
19 | + const DATABASE = 'GeoLite2-Country'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The extension for the MaxMind database. |
|
23 | + */ |
|
24 | + const DATABASE_EXTENSION = '.mmdb'; |
|
25 | + |
|
26 | + /** |
|
27 | + * A prefix for the MaxMind database filename. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $database_prefix; |
|
32 | + |
|
33 | + /** |
|
34 | + * Class constructor. |
|
35 | + * |
|
36 | + * @param string|null $database_prefix A prefix for the MaxMind database filename. |
|
37 | + */ |
|
38 | + public function __construct( $database_prefix ) { |
|
39 | + $this->database_prefix = $database_prefix; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Fetches the path that the database should be stored. |
|
44 | + * |
|
45 | + * @return string The local database path. |
|
46 | + */ |
|
47 | + public function get_database_path() { |
|
48 | + $uploads_dir = wp_upload_dir(); |
|
49 | + |
|
50 | + $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | + if ( ! empty( $this->database_prefix ) ) { |
|
52 | + $database_path .= $this->database_prefix . '-'; |
|
53 | + } |
|
54 | + $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
|
55 | + |
|
56 | + // Filter the geolocation database storage path. |
|
57 | + return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fetches the database from the MaxMind service. |
|
62 | + * |
|
63 | + * @param string $license_key The license key to be used when downloading the database. |
|
64 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
65 | + */ |
|
66 | + public function download_database( $license_key ) { |
|
67 | + |
|
68 | + $download_uri = add_query_arg( |
|
69 | + array( |
|
70 | + 'edition_id' => self::DATABASE, |
|
71 | + 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
72 | + 'suffix' => 'tar.gz', |
|
73 | + ), |
|
74 | + 'https://download.maxmind.com/app/geoip_download' |
|
75 | + ); |
|
76 | + |
|
77 | + // Needed for the download_url call right below. |
|
78 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
79 | + |
|
80 | + $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
81 | + |
|
82 | + if ( is_wp_error( $tmp_archive_path ) ) { |
|
83 | + // Transform the error into something more informative. |
|
84 | + $error_data = $tmp_archive_path->get_error_data(); |
|
85 | + if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
86 | + return new WP_Error( |
|
87 | + 'getpaid_maxmind_geolocation_database_license_key', |
|
88 | + __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
93 | + } |
|
94 | + |
|
95 | + // Extract the database from the archive. |
|
96 | + return $this->extract_downloaded_database( $tmp_archive_path ); |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Extracts the downloaded database. |
|
102 | + * |
|
103 | + * @param string $tmp_archive_path The database archive path. |
|
104 | + * @return string|WP_Error The path to the database file or an error if invalid. |
|
105 | + */ |
|
106 | + protected function extract_downloaded_database( $tmp_archive_path ) { |
|
107 | + |
|
108 | + // Extract the database from the archive. |
|
109 | + $tmp_database_path = ''; |
|
110 | + |
|
111 | + try { |
|
112 | + |
|
113 | + $file = new PharData( $tmp_archive_path ); |
|
114 | + $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | + |
|
116 | + $file->extractTo( |
|
117 | + dirname( $tmp_archive_path ), |
|
118 | + trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | + true |
|
120 | + ); |
|
121 | + |
|
122 | + } catch ( Exception $exception ) { |
|
123 | + return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
124 | + } finally { |
|
125 | + // Remove the archive since we only care about a single file in it. |
|
126 | + unlink( $tmp_archive_path ); |
|
127 | + } |
|
128 | + |
|
129 | + return $tmp_database_path; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Fetches the ISO country code associated with an IP address. |
|
134 | + * |
|
135 | + * @param string $ip_address The IP address to find the country code for. |
|
136 | + * @return string The country code for the IP address, or empty if not found. |
|
137 | + */ |
|
138 | + public function get_iso_country_code_for_ip( $ip_address ) { |
|
139 | + $country_code = ''; |
|
140 | + |
|
141 | + if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
142 | + return $country_code; |
|
143 | + } |
|
144 | + |
|
145 | + $database_path = $this->get_database_path(); |
|
146 | + if ( ! file_exists( $database_path ) ) { |
|
147 | + return $country_code; |
|
148 | + } |
|
149 | + |
|
150 | + try { |
|
151 | + $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | + $data = $reader->get( $ip_address ); |
|
153 | + |
|
154 | + if ( isset( $data['country']['iso_code'] ) ) { |
|
155 | + $country_code = $data['country']['iso_code']; |
|
156 | + } |
|
157 | + |
|
158 | + $reader->close(); |
|
159 | + } catch ( Exception $e ) { |
|
160 | + wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
161 | + } |
|
162 | + |
|
163 | + return $country_code; |
|
164 | + } |
|
165 | 165 | |
166 | 166 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The service class responsible for interacting with MaxMind databases. |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param string|null $database_prefix A prefix for the MaxMind database filename. |
37 | 37 | */ |
38 | - public function __construct( $database_prefix ) { |
|
38 | + public function __construct($database_prefix) { |
|
39 | 39 | $this->database_prefix = $database_prefix; |
40 | 40 | } |
41 | 41 | |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | public function get_database_path() { |
48 | 48 | $uploads_dir = wp_upload_dir(); |
49 | 49 | |
50 | - $database_path = trailingslashit( $uploads_dir['basedir'] ) . 'invoicing/'; |
|
51 | - if ( ! empty( $this->database_prefix ) ) { |
|
50 | + $database_path = trailingslashit($uploads_dir['basedir']) . 'invoicing/'; |
|
51 | + if (!empty($this->database_prefix)) { |
|
52 | 52 | $database_path .= $this->database_prefix . '-'; |
53 | 53 | } |
54 | 54 | $database_path .= self::DATABASE . self::DATABASE_EXTENSION; |
55 | 55 | |
56 | 56 | // Filter the geolocation database storage path. |
57 | - return apply_filters( 'getpaid_maxmind_geolocation_database_path', $database_path ); |
|
57 | + return apply_filters('getpaid_maxmind_geolocation_database_path', $database_path); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | * @param string $license_key The license key to be used when downloading the database. |
64 | 64 | * @return string|WP_Error The path to the database file or an error if invalid. |
65 | 65 | */ |
66 | - public function download_database( $license_key ) { |
|
66 | + public function download_database($license_key) { |
|
67 | 67 | |
68 | 68 | $download_uri = add_query_arg( |
69 | 69 | array( |
70 | 70 | 'edition_id' => self::DATABASE, |
71 | - 'license_key' => urlencode( wpinv_clean( $license_key ) ), |
|
71 | + 'license_key' => urlencode(wpinv_clean($license_key)), |
|
72 | 72 | 'suffix' => 'tar.gz', |
73 | 73 | ), |
74 | 74 | 'https://download.maxmind.com/app/geoip_download' |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | // Needed for the download_url call right below. |
78 | 78 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
79 | 79 | |
80 | - $tmp_archive_path = download_url( esc_url_raw( $download_uri ) ); |
|
80 | + $tmp_archive_path = download_url(esc_url_raw($download_uri)); |
|
81 | 81 | |
82 | - if ( is_wp_error( $tmp_archive_path ) ) { |
|
82 | + if (is_wp_error($tmp_archive_path)) { |
|
83 | 83 | // Transform the error into something more informative. |
84 | 84 | $error_data = $tmp_archive_path->get_error_data(); |
85 | - if ( isset( $error_data['code'] ) && $error_data['code'] == 401 ) { |
|
85 | + if (isset($error_data['code']) && $error_data['code'] == 401) { |
|
86 | 86 | return new WP_Error( |
87 | 87 | 'getpaid_maxmind_geolocation_database_license_key', |
88 | - __( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' ) |
|
88 | + __('The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing') |
|
89 | 89 | ); |
90 | 90 | } |
91 | 91 | |
92 | - return new WP_Error( 'getpaid_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) ); |
|
92 | + return new WP_Error('getpaid_maxmind_geolocation_database_download', __('Failed to download the MaxMind database.', 'invoicing')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Extract the database from the archive. |
96 | - return $this->extract_downloaded_database( $tmp_archive_path ); |
|
96 | + return $this->extract_downloaded_database($tmp_archive_path); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -103,27 +103,27 @@ discard block |
||
103 | 103 | * @param string $tmp_archive_path The database archive path. |
104 | 104 | * @return string|WP_Error The path to the database file or an error if invalid. |
105 | 105 | */ |
106 | - protected function extract_downloaded_database( $tmp_archive_path ) { |
|
106 | + protected function extract_downloaded_database($tmp_archive_path) { |
|
107 | 107 | |
108 | 108 | // Extract the database from the archive. |
109 | 109 | $tmp_database_path = ''; |
110 | 110 | |
111 | 111 | try { |
112 | 112 | |
113 | - $file = new PharData( $tmp_archive_path ); |
|
114 | - $tmp_database_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION; |
|
113 | + $file = new PharData($tmp_archive_path); |
|
114 | + $tmp_database_path = trailingslashit(dirname($tmp_archive_path)) . trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION; |
|
115 | 115 | |
116 | 116 | $file->extractTo( |
117 | - dirname( $tmp_archive_path ), |
|
118 | - trailingslashit( $file->current()->getFilename() ) . self::DATABASE . self::DATABASE_EXTENSION, |
|
117 | + dirname($tmp_archive_path), |
|
118 | + trailingslashit($file->current()->getFilename()) . self::DATABASE . self::DATABASE_EXTENSION, |
|
119 | 119 | true |
120 | 120 | ); |
121 | 121 | |
122 | - } catch ( Exception $exception ) { |
|
123 | - return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() ); |
|
122 | + } catch (Exception $exception) { |
|
123 | + return new WP_Error('invoicing_maxmind_geolocation_database_archive', $exception->getMessage()); |
|
124 | 124 | } finally { |
125 | 125 | // Remove the archive since we only care about a single file in it. |
126 | - unlink( $tmp_archive_path ); |
|
126 | + unlink($tmp_archive_path); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | return $tmp_database_path; |
@@ -135,29 +135,29 @@ discard block |
||
135 | 135 | * @param string $ip_address The IP address to find the country code for. |
136 | 136 | * @return string The country code for the IP address, or empty if not found. |
137 | 137 | */ |
138 | - public function get_iso_country_code_for_ip( $ip_address ) { |
|
138 | + public function get_iso_country_code_for_ip($ip_address) { |
|
139 | 139 | $country_code = ''; |
140 | 140 | |
141 | - if ( ! class_exists( 'MaxMind\Db\Reader' ) ) { |
|
141 | + if (!class_exists('MaxMind\Db\Reader')) { |
|
142 | 142 | return $country_code; |
143 | 143 | } |
144 | 144 | |
145 | 145 | $database_path = $this->get_database_path(); |
146 | - if ( ! file_exists( $database_path ) ) { |
|
146 | + if (!file_exists($database_path)) { |
|
147 | 147 | return $country_code; |
148 | 148 | } |
149 | 149 | |
150 | 150 | try { |
151 | - $reader = new MaxMind\Db\Reader( $database_path ); |
|
152 | - $data = $reader->get( $ip_address ); |
|
151 | + $reader = new MaxMind\Db\Reader($database_path); |
|
152 | + $data = $reader->get($ip_address); |
|
153 | 153 | |
154 | - if ( isset( $data['country']['iso_code'] ) ) { |
|
154 | + if (isset($data['country']['iso_code'])) { |
|
155 | 155 | $country_code = $data['country']['iso_code']; |
156 | 156 | } |
157 | 157 | |
158 | 158 | $reader->close(); |
159 | - } catch ( Exception $e ) { |
|
160 | - wpinv_error_log( $e->getMessage(), 'SOURCE: MaxMind GeoLocation' ); |
|
159 | + } catch (Exception $e) { |
|
160 | + wpinv_error_log($e->getMessage(), 'SOURCE: MaxMind GeoLocation'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | return $country_code; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Subscription_Data_Store { |
17 | 17 | |
18 | - /** |
|
19 | - * A map of database fields to data types. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $database_fields_to_data_type = array( |
|
25 | - 'id' => '%d', |
|
26 | - 'customer_id' => '%d', |
|
27 | - 'frequency' => '%d', |
|
28 | - 'period' => '%s', |
|
29 | - 'initial_amount' => '%s', |
|
30 | - 'recurring_amount' => '%s', |
|
31 | - 'bill_times' => '%d', |
|
32 | - 'transaction_id' => '%s', |
|
33 | - 'parent_payment_id' => '%d', |
|
34 | - 'product_id' => '%d', |
|
35 | - 'created' => '%s', |
|
36 | - 'expiration' => '%s', |
|
37 | - 'trial_period' => '%s', |
|
38 | - 'status' => '%s', |
|
39 | - 'profile_id' => '%s', |
|
40 | - ); |
|
41 | - |
|
42 | - /* |
|
18 | + /** |
|
19 | + * A map of database fields to data types. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $database_fields_to_data_type = array( |
|
25 | + 'id' => '%d', |
|
26 | + 'customer_id' => '%d', |
|
27 | + 'frequency' => '%d', |
|
28 | + 'period' => '%s', |
|
29 | + 'initial_amount' => '%s', |
|
30 | + 'recurring_amount' => '%s', |
|
31 | + 'bill_times' => '%d', |
|
32 | + 'transaction_id' => '%s', |
|
33 | + 'parent_payment_id' => '%d', |
|
34 | + 'product_id' => '%d', |
|
35 | + 'created' => '%s', |
|
36 | + 'expiration' => '%s', |
|
37 | + 'trial_period' => '%s', |
|
38 | + 'status' => '%s', |
|
39 | + 'profile_id' => '%s', |
|
40 | + ); |
|
41 | + |
|
42 | + /* |
|
43 | 43 | |-------------------------------------------------------------------------- |
44 | 44 | | CRUD Methods |
45 | 45 | |-------------------------------------------------------------------------- |
46 | 46 | */ |
47 | 47 | |
48 | - /** |
|
49 | - * Method to create a new subscription in the database. |
|
50 | - * |
|
51 | - * @param WPInv_Subscription $subscription Subscription object. |
|
52 | - */ |
|
53 | - public function create( &$subscription ) { |
|
54 | - global $wpdb; |
|
55 | - |
|
56 | - $values = array(); |
|
57 | - $formats = array(); |
|
58 | - |
|
59 | - $fields = $this->database_fields_to_data_type; |
|
60 | - unset( $fields['id'] ); |
|
61 | - |
|
62 | - foreach ( $fields as $key => $format ) { |
|
63 | - $method = "get_$key"; |
|
64 | - $values[$key] = $subscription->$method( 'edit' ); |
|
65 | - $formats[] = $format; |
|
66 | - } |
|
67 | - |
|
68 | - $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats ); |
|
69 | - |
|
70 | - if ( $result ) { |
|
71 | - $subscription->set_id( $wpdb->insert_id ); |
|
72 | - $subscription->apply_changes(); |
|
73 | - $subscription->clear_cache(); |
|
74 | - update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() ); |
|
75 | - do_action( 'getpaid_new_subscription', $subscription ); |
|
76 | - return true; |
|
77 | - } |
|
78 | - |
|
79 | - return false; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Method to read a subscription from the database. |
|
84 | - * |
|
85 | - * @param WPInv_Subscription $subscription Subscription object. |
|
86 | - * |
|
87 | - */ |
|
88 | - public function read( &$subscription ) { |
|
89 | - global $wpdb; |
|
90 | - |
|
91 | - $subscription->set_defaults(); |
|
92 | - |
|
93 | - if ( ! $subscription->get_id() ) { |
|
94 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
95 | - $subscription->set_id( 0 ); |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - // Maybe retrieve from the cache. |
|
100 | - $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
101 | - |
|
102 | - // If not found, retrieve from the db. |
|
103 | - if ( false === $raw_subscription ) { |
|
104 | - |
|
105 | - $raw_subscription = $wpdb->get_row( |
|
106 | - $wpdb->prepare( |
|
107 | - "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d", |
|
108 | - $subscription->get_id() |
|
109 | - ) |
|
110 | - ); |
|
111 | - |
|
112 | - // Update the cache with our data |
|
113 | - wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
114 | - |
|
115 | - } |
|
116 | - |
|
117 | - if ( ! $raw_subscription ) { |
|
118 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
123 | - $method = "set_$key"; |
|
124 | - $subscription->$method( $raw_subscription->$key ); |
|
125 | - } |
|
126 | - |
|
127 | - $subscription->set_object_read( true ); |
|
128 | - do_action( 'getpaid_read_subscription', $subscription ); |
|
129 | - |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Method to update a subscription in the database. |
|
134 | - * |
|
135 | - * @param WPInv_Subscription $subscription Subscription object. |
|
136 | - */ |
|
137 | - public function update( &$subscription ) { |
|
138 | - global $wpdb; |
|
139 | - |
|
140 | - $changes = $subscription->get_changes(); |
|
141 | - $values = array(); |
|
142 | - $formats = array(); |
|
143 | - |
|
144 | - foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
145 | - if ( array_key_exists( $key, $changes ) ) { |
|
146 | - $method = "get_$key"; |
|
147 | - $values[$key] = $subscription->$method( 'edit' ); |
|
148 | - $formats[] = $format; |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - if ( empty( $values ) ) { |
|
153 | - return; |
|
154 | - } |
|
155 | - |
|
156 | - $wpdb->update( |
|
157 | - $wpdb->prefix . 'wpinv_subscriptions', |
|
158 | - $values, |
|
159 | - array( |
|
160 | - 'id' => $subscription->get_id(), |
|
161 | - ), |
|
162 | - $formats, |
|
163 | - '%d' |
|
164 | - ); |
|
165 | - |
|
166 | - // Apply the changes. |
|
167 | - $subscription->apply_changes(); |
|
168 | - |
|
169 | - // Delete cache. |
|
170 | - $subscription->clear_cache(); |
|
171 | - |
|
172 | - update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() ); |
|
173 | - |
|
174 | - // Fire a hook. |
|
175 | - do_action( 'getpaid_update_subscription', $subscription ); |
|
176 | - |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Method to delete a subscription from the database. |
|
181 | - * |
|
182 | - * @param WPInv_Subscription $subscription |
|
183 | - */ |
|
184 | - public function delete( &$subscription ) { |
|
185 | - global $wpdb; |
|
186 | - |
|
187 | - $wpdb->query( |
|
188 | - $wpdb->prepare( |
|
189 | - "DELETE FROM {$wpdb->prefix}getpaid_subscriptions |
|
48 | + /** |
|
49 | + * Method to create a new subscription in the database. |
|
50 | + * |
|
51 | + * @param WPInv_Subscription $subscription Subscription object. |
|
52 | + */ |
|
53 | + public function create( &$subscription ) { |
|
54 | + global $wpdb; |
|
55 | + |
|
56 | + $values = array(); |
|
57 | + $formats = array(); |
|
58 | + |
|
59 | + $fields = $this->database_fields_to_data_type; |
|
60 | + unset( $fields['id'] ); |
|
61 | + |
|
62 | + foreach ( $fields as $key => $format ) { |
|
63 | + $method = "get_$key"; |
|
64 | + $values[$key] = $subscription->$method( 'edit' ); |
|
65 | + $formats[] = $format; |
|
66 | + } |
|
67 | + |
|
68 | + $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats ); |
|
69 | + |
|
70 | + if ( $result ) { |
|
71 | + $subscription->set_id( $wpdb->insert_id ); |
|
72 | + $subscription->apply_changes(); |
|
73 | + $subscription->clear_cache(); |
|
74 | + update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() ); |
|
75 | + do_action( 'getpaid_new_subscription', $subscription ); |
|
76 | + return true; |
|
77 | + } |
|
78 | + |
|
79 | + return false; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Method to read a subscription from the database. |
|
84 | + * |
|
85 | + * @param WPInv_Subscription $subscription Subscription object. |
|
86 | + * |
|
87 | + */ |
|
88 | + public function read( &$subscription ) { |
|
89 | + global $wpdb; |
|
90 | + |
|
91 | + $subscription->set_defaults(); |
|
92 | + |
|
93 | + if ( ! $subscription->get_id() ) { |
|
94 | + $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
95 | + $subscription->set_id( 0 ); |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + // Maybe retrieve from the cache. |
|
100 | + $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
101 | + |
|
102 | + // If not found, retrieve from the db. |
|
103 | + if ( false === $raw_subscription ) { |
|
104 | + |
|
105 | + $raw_subscription = $wpdb->get_row( |
|
106 | + $wpdb->prepare( |
|
107 | + "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d", |
|
108 | + $subscription->get_id() |
|
109 | + ) |
|
110 | + ); |
|
111 | + |
|
112 | + // Update the cache with our data |
|
113 | + wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
114 | + |
|
115 | + } |
|
116 | + |
|
117 | + if ( ! $raw_subscription ) { |
|
118 | + $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
123 | + $method = "set_$key"; |
|
124 | + $subscription->$method( $raw_subscription->$key ); |
|
125 | + } |
|
126 | + |
|
127 | + $subscription->set_object_read( true ); |
|
128 | + do_action( 'getpaid_read_subscription', $subscription ); |
|
129 | + |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Method to update a subscription in the database. |
|
134 | + * |
|
135 | + * @param WPInv_Subscription $subscription Subscription object. |
|
136 | + */ |
|
137 | + public function update( &$subscription ) { |
|
138 | + global $wpdb; |
|
139 | + |
|
140 | + $changes = $subscription->get_changes(); |
|
141 | + $values = array(); |
|
142 | + $formats = array(); |
|
143 | + |
|
144 | + foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
145 | + if ( array_key_exists( $key, $changes ) ) { |
|
146 | + $method = "get_$key"; |
|
147 | + $values[$key] = $subscription->$method( 'edit' ); |
|
148 | + $formats[] = $format; |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + if ( empty( $values ) ) { |
|
153 | + return; |
|
154 | + } |
|
155 | + |
|
156 | + $wpdb->update( |
|
157 | + $wpdb->prefix . 'wpinv_subscriptions', |
|
158 | + $values, |
|
159 | + array( |
|
160 | + 'id' => $subscription->get_id(), |
|
161 | + ), |
|
162 | + $formats, |
|
163 | + '%d' |
|
164 | + ); |
|
165 | + |
|
166 | + // Apply the changes. |
|
167 | + $subscription->apply_changes(); |
|
168 | + |
|
169 | + // Delete cache. |
|
170 | + $subscription->clear_cache(); |
|
171 | + |
|
172 | + update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() ); |
|
173 | + |
|
174 | + // Fire a hook. |
|
175 | + do_action( 'getpaid_update_subscription', $subscription ); |
|
176 | + |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Method to delete a subscription from the database. |
|
181 | + * |
|
182 | + * @param WPInv_Subscription $subscription |
|
183 | + */ |
|
184 | + public function delete( &$subscription ) { |
|
185 | + global $wpdb; |
|
186 | + |
|
187 | + $wpdb->query( |
|
188 | + $wpdb->prepare( |
|
189 | + "DELETE FROM {$wpdb->prefix}getpaid_subscriptions |
|
190 | 190 | WHERE id = %d", |
191 | - $subscription->get_id() |
|
192 | - ) |
|
193 | - ); |
|
191 | + $subscription->get_id() |
|
192 | + ) |
|
193 | + ); |
|
194 | 194 | |
195 | - delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' ); |
|
196 | - delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' ); |
|
195 | + delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' ); |
|
196 | + delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' ); |
|
197 | 197 | |
198 | - // Delete cache. |
|
199 | - $subscription->clear_cache(); |
|
198 | + // Delete cache. |
|
199 | + $subscription->clear_cache(); |
|
200 | 200 | |
201 | - // Fire a hook. |
|
202 | - do_action( 'getpaid_delete_subscription', $subscription ); |
|
201 | + // Fire a hook. |
|
202 | + do_action( 'getpaid_delete_subscription', $subscription ); |
|
203 | 203 | |
204 | - $subscription->set_id( 0 ); |
|
205 | - } |
|
204 | + $subscription->set_id( 0 ); |
|
205 | + } |
|
206 | 206 | |
207 | - /* |
|
207 | + /* |
|
208 | 208 | |-------------------------------------------------------------------------- |
209 | 209 | | Additional Methods |
210 | 210 | |-------------------------------------------------------------------------- |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Subscription_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -50,29 +50,29 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param WPInv_Subscription $subscription Subscription object. |
52 | 52 | */ |
53 | - public function create( &$subscription ) { |
|
53 | + public function create(&$subscription) { |
|
54 | 54 | global $wpdb; |
55 | 55 | |
56 | 56 | $values = array(); |
57 | 57 | $formats = array(); |
58 | 58 | |
59 | 59 | $fields = $this->database_fields_to_data_type; |
60 | - unset( $fields['id'] ); |
|
60 | + unset($fields['id']); |
|
61 | 61 | |
62 | - foreach ( $fields as $key => $format ) { |
|
62 | + foreach ($fields as $key => $format) { |
|
63 | 63 | $method = "get_$key"; |
64 | - $values[$key] = $subscription->$method( 'edit' ); |
|
64 | + $values[$key] = $subscription->$method('edit'); |
|
65 | 65 | $formats[] = $format; |
66 | 66 | } |
67 | 67 | |
68 | - $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats ); |
|
68 | + $result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $values, $formats); |
|
69 | 69 | |
70 | - if ( $result ) { |
|
71 | - $subscription->set_id( $wpdb->insert_id ); |
|
70 | + if ($result) { |
|
71 | + $subscription->set_id($wpdb->insert_id); |
|
72 | 72 | $subscription->apply_changes(); |
73 | 73 | $subscription->clear_cache(); |
74 | - update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() ); |
|
75 | - do_action( 'getpaid_new_subscription', $subscription ); |
|
74 | + update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id()); |
|
75 | + do_action('getpaid_new_subscription', $subscription); |
|
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
@@ -85,22 +85,22 @@ discard block |
||
85 | 85 | * @param WPInv_Subscription $subscription Subscription object. |
86 | 86 | * |
87 | 87 | */ |
88 | - public function read( &$subscription ) { |
|
88 | + public function read(&$subscription) { |
|
89 | 89 | global $wpdb; |
90 | 90 | |
91 | 91 | $subscription->set_defaults(); |
92 | 92 | |
93 | - if ( ! $subscription->get_id() ) { |
|
94 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
95 | - $subscription->set_id( 0 ); |
|
93 | + if (!$subscription->get_id()) { |
|
94 | + $subscription->last_error = __('Invalid subscription ID.', 'invoicing'); |
|
95 | + $subscription->set_id(0); |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // Maybe retrieve from the cache. |
100 | - $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
100 | + $raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions'); |
|
101 | 101 | |
102 | 102 | // If not found, retrieve from the db. |
103 | - if ( false === $raw_subscription ) { |
|
103 | + if (false === $raw_subscription) { |
|
104 | 104 | |
105 | 105 | $raw_subscription = $wpdb->get_row( |
106 | 106 | $wpdb->prepare( |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | ); |
111 | 111 | |
112 | 112 | // Update the cache with our data |
113 | - wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
113 | + wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions'); |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | |
117 | - if ( ! $raw_subscription ) { |
|
118 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
117 | + if (!$raw_subscription) { |
|
118 | + $subscription->last_error = __('Invalid subscription ID.', 'invoicing'); |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
122 | - foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
123 | - $method = "set_$key"; |
|
124 | - $subscription->$method( $raw_subscription->$key ); |
|
122 | + foreach (array_keys($this->database_fields_to_data_type) as $key) { |
|
123 | + $method = "set_$key"; |
|
124 | + $subscription->$method($raw_subscription->$key); |
|
125 | 125 | } |
126 | 126 | |
127 | - $subscription->set_object_read( true ); |
|
128 | - do_action( 'getpaid_read_subscription', $subscription ); |
|
127 | + $subscription->set_object_read(true); |
|
128 | + do_action('getpaid_read_subscription', $subscription); |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Subscription $subscription Subscription object. |
136 | 136 | */ |
137 | - public function update( &$subscription ) { |
|
137 | + public function update(&$subscription) { |
|
138 | 138 | global $wpdb; |
139 | 139 | |
140 | 140 | $changes = $subscription->get_changes(); |
141 | 141 | $values = array(); |
142 | 142 | $formats = array(); |
143 | 143 | |
144 | - foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
145 | - if ( array_key_exists( $key, $changes ) ) { |
|
144 | + foreach ($this->database_fields_to_data_type as $key => $format) { |
|
145 | + if (array_key_exists($key, $changes)) { |
|
146 | 146 | $method = "get_$key"; |
147 | - $values[$key] = $subscription->$method( 'edit' ); |
|
147 | + $values[$key] = $subscription->$method('edit'); |
|
148 | 148 | $formats[] = $format; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - if ( empty( $values ) ) { |
|
152 | + if (empty($values)) { |
|
153 | 153 | return; |
154 | 154 | } |
155 | 155 | |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | // Delete cache. |
170 | 170 | $subscription->clear_cache(); |
171 | 171 | |
172 | - update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() ); |
|
172 | + update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id()); |
|
173 | 173 | |
174 | 174 | // Fire a hook. |
175 | - do_action( 'getpaid_update_subscription', $subscription ); |
|
175 | + do_action('getpaid_update_subscription', $subscription); |
|
176 | 176 | |
177 | 177 | } |
178 | 178 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @param WPInv_Subscription $subscription |
183 | 183 | */ |
184 | - public function delete( &$subscription ) { |
|
184 | + public function delete(&$subscription) { |
|
185 | 185 | global $wpdb; |
186 | 186 | |
187 | 187 | $wpdb->query( |
@@ -192,16 +192,16 @@ discard block |
||
192 | 192 | ) |
193 | 193 | ); |
194 | 194 | |
195 | - delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' ); |
|
196 | - delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' ); |
|
195 | + delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id'); |
|
196 | + delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id'); |
|
197 | 197 | |
198 | 198 | // Delete cache. |
199 | 199 | $subscription->clear_cache(); |
200 | 200 | |
201 | 201 | // Fire a hook. |
202 | - do_action( 'getpaid_delete_subscription', $subscription ); |
|
202 | + do_action('getpaid_delete_subscription', $subscription); |
|
203 | 203 | |
204 | - $subscription->set_id( 0 ); |
|
204 | + $subscription->set_id(0); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /* |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
94 | - } else { |
|
95 | - $this->set_object_read( true ); |
|
96 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | + $this->set_id( $item_id ); |
|
92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | + $this->set_id( $item_id ); |
|
94 | + } else { |
|
95 | + $this->set_object_read( true ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
101 | + if ( $this->get_id() > 0 ) { |
|
102 | 102 | $this->post = get_post( $this->get_id() ); |
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read( $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
122 | 122 | */ |
123 | 123 | |
124 | 124 | /** |
125 | - * Get parent item ID. |
|
126 | - * |
|
127 | - * @since 1.0.19 |
|
128 | - * @param string $context View or edit context. |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
125 | + * Get parent item ID. |
|
126 | + * |
|
127 | + * @since 1.0.19 |
|
128 | + * @param string $context View or edit context. |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function get_parent_id( $context = 'view' ) { |
|
132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Get item status. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @param string $context View or edit context. |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
136 | + * Get item status. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @param string $context View or edit context. |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function get_status( $context = 'view' ) { |
|
143 | + return $this->get_prop( 'status', $context ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Get plugin version when the item was created. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * @param string $context View or edit context. |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
147 | + * Get plugin version when the item was created. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * @param string $context View or edit context. |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function get_version( $context = 'view' ) { |
|
154 | + return $this->get_prop( 'version', $context ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * Get date when the item was created. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param string $context View or edit context. |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
158 | + * Get date when the item was created. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param string $context View or edit context. |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_date_created( $context = 'view' ) { |
|
165 | + return $this->get_prop( 'date_created', $context ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get GMT date when the item was created. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * @param string $context View or edit context. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
169 | + * Get GMT date when the item was created. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * @param string $context View or edit context. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
176 | 176 | $date = $this->get_date_created( $context ); |
177 | 177 | |
178 | 178 | if ( $date ) { |
179 | 179 | $date = get_gmt_from_date( $date ); |
180 | 180 | } |
181 | - return $date; |
|
181 | + return $date; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get date when the item was last modified. |
|
186 | - * |
|
187 | - * @since 1.0.19 |
|
188 | - * @param string $context View or edit context. |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
185 | + * Get date when the item was last modified. |
|
186 | + * |
|
187 | + * @since 1.0.19 |
|
188 | + * @param string $context View or edit context. |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_date_modified( $context = 'view' ) { |
|
192 | + return $this->get_prop( 'date_modified', $context ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Get GMT date when the item was last modified. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
196 | + * Get GMT date when the item was last modified. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | 203 | $date = $this->get_date_modified( $context ); |
204 | 204 | |
205 | 205 | if ( $date ) { |
206 | 206 | $date = get_gmt_from_date( $date ); |
207 | 207 | } |
208 | - return $date; |
|
208 | + return $date; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get the item name. |
|
213 | - * |
|
214 | - * @since 1.0.19 |
|
215 | - * @param string $context View or edit context. |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
212 | + * Get the item name. |
|
213 | + * |
|
214 | + * @since 1.0.19 |
|
215 | + * @param string $context View or edit context. |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function get_name( $context = 'view' ) { |
|
219 | + return $this->get_prop( 'name', $context ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Alias of self::get_name(). |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @param string $context View or edit context. |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
223 | + * Alias of self::get_name(). |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @param string $context View or edit context. |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_title( $context = 'view' ) { |
|
230 | + return $this->get_name( $context ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Get the item description. |
|
235 | - * |
|
236 | - * @since 1.0.19 |
|
237 | - * @param string $context View or edit context. |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
234 | + * Get the item description. |
|
235 | + * |
|
236 | + * @since 1.0.19 |
|
237 | + * @param string $context View or edit context. |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function get_description( $context = 'view' ) { |
|
241 | + return $this->get_prop( 'description', $context ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Alias of self::get_description(). |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
245 | + * Alias of self::get_description(). |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_excerpt( $context = 'view' ) { |
|
252 | + return $this->get_description( $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Alias of self::get_description(). |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
256 | + * Alias of self::get_description(). |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function get_summary( $context = 'view' ) { |
|
263 | + return $this->get_description( $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get the owner of the item. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @param string $context View or edit context. |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
275 | - } |
|
267 | + * Get the owner of the item. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @param string $context View or edit context. |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function get_author( $context = 'view' ) { |
|
274 | + return (int) $this->get_prop( 'author', $context ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Alias of self::get_author(). |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @param string $context View or edit context. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get the price of the item. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return float |
|
294 | - */ |
|
295 | - public function get_price( $context = 'view' ) { |
|
277 | + /** |
|
278 | + * Alias of self::get_author(). |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @param string $context View or edit context. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + public function get_owner( $context = 'view' ) { |
|
285 | + return $this->get_author( $context ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get the price of the item. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return float |
|
294 | + */ |
|
295 | + public function get_price( $context = 'view' ) { |
|
296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Get the inital price of the item. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return float |
|
305 | - */ |
|
306 | - public function get_initial_price( $context = 'view' ) { |
|
299 | + /** |
|
300 | + * Get the inital price of the item. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return float |
|
305 | + */ |
|
306 | + public function get_initial_price( $context = 'view' ) { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price( $context ); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
311 | - $price = 0; |
|
312 | - } |
|
310 | + if ( $this->has_free_trial() ) { |
|
311 | + $price = 0; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | - * Returns a formated price. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @param string $context View or edit context. |
|
322 | - * @return string |
|
323 | - */ |
|
318 | + * Returns a formated price. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @param string $context View or edit context. |
|
322 | + * @return string |
|
323 | + */ |
|
324 | 324 | public function get_the_price() { |
325 | 325 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the formated initial price. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @param string $context View or edit context. |
|
333 | - * @return string |
|
334 | - */ |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the formated initial price. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @param string $context View or edit context. |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function get_the_initial_price() { |
336 | 336 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Get the VAT rule of the item. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param string $context View or edit context. |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function get_vat_rule( $context = 'view' ) { |
|
340 | + * Get the VAT rule of the item. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param string $context View or edit context. |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function get_vat_rule( $context = 'view' ) { |
|
347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | - * Get the VAT class of the item. |
|
352 | - * |
|
353 | - * @since 1.0.19 |
|
354 | - * @param string $context View or edit context. |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function get_vat_class( $context = 'view' ) { |
|
351 | + * Get the VAT class of the item. |
|
352 | + * |
|
353 | + * @since 1.0.19 |
|
354 | + * @param string $context View or edit context. |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function get_vat_class( $context = 'view' ) { |
|
358 | 358 | return $this->get_prop( 'vat_class', $context ); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Get the type of the item. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $context View or edit context. |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_type( $context = 'view' ) { |
|
362 | + * Get the type of the item. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $context View or edit context. |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_type( $context = 'view' ) { |
|
369 | 369 | return $this->get_prop( 'type', $context ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Get the custom id of the item. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_custom_id( $context = 'view' ) { |
|
373 | + * Get the custom id of the item. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_custom_id( $context = 'view' ) { |
|
380 | 380 | return $this->get_prop( 'custom_id', $context ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the custom name of the item. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_custom_name( $context = 'view' ) { |
|
384 | + * Get the custom name of the item. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_custom_name( $context = 'view' ) { |
|
391 | 391 | return $this->get_prop( 'custom_name', $context ); |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Get the custom singular name of the item. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
395 | + * Get the custom singular name of the item. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Checks if an item is editable.. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function get_is_editable( $context = 'view' ) { |
|
406 | + * Checks if an item is editable.. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function get_is_editable( $context = 'view' ) { |
|
413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Alias of self::get_is_editable(). |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return int |
|
422 | - */ |
|
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
417 | + * Alias of self::get_is_editable(). |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return int |
|
422 | + */ |
|
423 | + public function get_editable( $context = 'view' ) { |
|
424 | + return $this->get_is_editable( $context ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Checks if dynamic pricing is enabled. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
428 | + * Checks if dynamic pricing is enabled. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return float |
|
444 | - */ |
|
445 | - public function get_minimum_price( $context = 'view' ) { |
|
439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return float |
|
444 | + */ |
|
445 | + public function get_minimum_price( $context = 'view' ) { |
|
446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Checks if this is a recurring item. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return int |
|
455 | - */ |
|
456 | - public function get_is_recurring( $context = 'view' ) { |
|
450 | + * Checks if this is a recurring item. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return int |
|
455 | + */ |
|
456 | + public function get_is_recurring( $context = 'view' ) { |
|
457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - /** |
|
461 | - * Get the recurring price of the item. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return float |
|
466 | - */ |
|
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
460 | + /** |
|
461 | + * Get the recurring price of the item. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return float |
|
466 | + */ |
|
467 | + public function get_recurring_price( $context = 'view' ) { |
|
468 | + $price = $this->get_price( $context ); |
|
469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Get the formatted recurring price of the item. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return string |
|
478 | - */ |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Get the formatted recurring price of the item. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return string |
|
478 | + */ |
|
479 | 479 | public function get_the_recurring_price() { |
480 | 480 | return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the first renewal date (in timestamps) of the item. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return int |
|
488 | - */ |
|
489 | - public function get_first_renewal_date() { |
|
490 | - |
|
491 | - $periods = array( |
|
492 | - 'D' => 'days', |
|
493 | - 'W' => 'weeks', |
|
494 | - 'M' => 'months', |
|
495 | - 'Y' => 'years', |
|
496 | - ); |
|
497 | - |
|
498 | - $period = $this->get_recurring_period(); |
|
499 | - $interval = $this->get_recurring_interval(); |
|
500 | - |
|
501 | - if ( $this->has_free_trial() ) { |
|
502 | - $period = $this->get_trial_period(); |
|
503 | - $interval = $this->get_trial_interval(); |
|
504 | - } |
|
505 | - |
|
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the first renewal date (in timestamps) of the item. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return int |
|
488 | + */ |
|
489 | + public function get_first_renewal_date() { |
|
490 | + |
|
491 | + $periods = array( |
|
492 | + 'D' => 'days', |
|
493 | + 'W' => 'weeks', |
|
494 | + 'M' => 'months', |
|
495 | + 'Y' => 'years', |
|
496 | + ); |
|
497 | + |
|
498 | + $period = $this->get_recurring_period(); |
|
499 | + $interval = $this->get_recurring_interval(); |
|
500 | + |
|
501 | + if ( $this->has_free_trial() ) { |
|
502 | + $period = $this->get_trial_period(); |
|
503 | + $interval = $this->get_trial_interval(); |
|
504 | + } |
|
505 | + |
|
506 | + $period = $periods[ $period ]; |
|
507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * Get the recurring period. |
|
514 | - * |
|
515 | - * @since 1.0.19 |
|
516 | - * @param bool $full Return abbreviation or in full. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function get_recurring_period( $full = false ) { |
|
513 | + * Get the recurring period. |
|
514 | + * |
|
515 | + * @since 1.0.19 |
|
516 | + * @param bool $full Return abbreviation or in full. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function get_recurring_period( $full = false ) { |
|
520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
521 | 521 | |
522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | - * Get the recurring interval. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - * @param string $context View or edit context. |
|
534 | - * @return int |
|
535 | - */ |
|
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
530 | + * Get the recurring interval. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + * @param string $context View or edit context. |
|
534 | + * @return int |
|
535 | + */ |
|
536 | + public function get_recurring_interval( $context = 'view' ) { |
|
537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
540 | - $interval = 1; |
|
541 | - } |
|
539 | + if ( $interval < 1 ) { |
|
540 | + $interval = 1; |
|
541 | + } |
|
542 | 542 | |
543 | 543 | return $interval; |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the recurring limit. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return int |
|
552 | - */ |
|
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
547 | + * Get the recurring limit. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return int |
|
552 | + */ |
|
553 | + public function get_recurring_limit( $context = 'view' ) { |
|
554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Checks if we have a free trial. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
558 | + * Checks if we have a free trial. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function get_is_free_trial( $context = 'view' ) { |
|
565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Alias for self::get_is_free_trial(). |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_free_trial( $context = 'view' ) { |
|
569 | + * Alias for self::get_is_free_trial(). |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_free_trial( $context = 'view' ) { |
|
576 | 576 | return $this->get_is_free_trial( $context ); |
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | - * Get the trial period. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param bool $full Return abbreviation or in full. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_trial_period( $full = false ) { |
|
580 | + * Get the trial period. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param bool $full Return abbreviation or in full. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_trial_period( $full = false ) { |
|
587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
588 | 588 | |
589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,104 +594,104 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the trial interval. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - * @param string $context View or edit context. |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function get_trial_interval( $context = 'view' ) { |
|
597 | + * Get the trial interval. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + * @param string $context View or edit context. |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function get_trial_interval( $context = 'view' ) { |
|
604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * Get the item's edit url. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_edit_url() { |
|
607 | + /** |
|
608 | + * Get the item's edit url. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_edit_url() { |
|
614 | 614 | return get_edit_post_link( $this->get_id() ); |
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Given an item's name/custom id, it returns its id. |
|
619 | - * |
|
620 | - * |
|
621 | - * @static |
|
622 | - * @param string $value The item name or custom id. |
|
623 | - * @param string $field Either name or custom_id. |
|
624 | - * @param string $type in case you need to search for a given type. |
|
625 | - * @since 1.0.15 |
|
626 | - * @return int |
|
627 | - */ |
|
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | - |
|
630 | - // Trim the value. |
|
631 | - $value = sanitize_text_field( $value ); |
|
632 | - if ( empty( $value ) ) { |
|
633 | - return 0; |
|
634 | - } |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Given an item's name/custom id, it returns its id. |
|
619 | + * |
|
620 | + * |
|
621 | + * @static |
|
622 | + * @param string $value The item name or custom id. |
|
623 | + * @param string $field Either name or custom_id. |
|
624 | + * @param string $type in case you need to search for a given type. |
|
625 | + * @since 1.0.15 |
|
626 | + * @return int |
|
627 | + */ |
|
628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | + |
|
630 | + // Trim the value. |
|
631 | + $value = sanitize_text_field( $value ); |
|
632 | + if ( empty( $value ) ) { |
|
633 | + return 0; |
|
634 | + } |
|
635 | 635 | |
636 | 636 | // Valid fields. |
637 | 637 | $fields = array( 'custom_id', 'name', 'slug' ); |
638 | 638 | |
639 | - // Ensure a field has been passed. |
|
640 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
641 | - return 0; |
|
642 | - } |
|
643 | - |
|
644 | - if ( $field == 'name' ) { |
|
645 | - $field = 'slug'; |
|
646 | - } |
|
647 | - |
|
648 | - // Maybe retrieve from the cache. |
|
649 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
650 | - if ( ! empty( $item_id ) ) { |
|
651 | - return $item_id; |
|
652 | - } |
|
653 | - |
|
654 | - // Fetch from the db. |
|
655 | - $items = array(); |
|
656 | - if ( $field == 'slug' ) { |
|
657 | - $items = get_posts( |
|
658 | - array( |
|
659 | - 'post_type' => 'wpi_item', |
|
660 | - 'name' => $value, |
|
661 | - 'posts_per_page' => 1, |
|
662 | - 'post_status' => 'any', |
|
663 | - ) |
|
664 | - ); |
|
665 | - } |
|
666 | - |
|
667 | - if ( $field =='custom_id' ) { |
|
668 | - $items = get_posts( |
|
669 | - array( |
|
670 | - 'post_type' => 'wpi_item', |
|
671 | - 'posts_per_page' => 1, |
|
672 | - 'post_status' => 'any', |
|
673 | - 'meta_query' => array( |
|
674 | - array( |
|
675 | - 'key' => '_wpinv_type', |
|
676 | - 'value' => $type, |
|
677 | - ), |
|
678 | - array( |
|
679 | - 'key' => '_wpinv_custom_id', |
|
680 | - 'value' => $value, |
|
681 | - ) |
|
682 | - ) |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - |
|
687 | - if ( empty( $items ) ) { |
|
688 | - return 0; |
|
689 | - } |
|
690 | - |
|
691 | - // Update the cache with our data |
|
692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | - |
|
694 | - return $items[0]->ID; |
|
639 | + // Ensure a field has been passed. |
|
640 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
641 | + return 0; |
|
642 | + } |
|
643 | + |
|
644 | + if ( $field == 'name' ) { |
|
645 | + $field = 'slug'; |
|
646 | + } |
|
647 | + |
|
648 | + // Maybe retrieve from the cache. |
|
649 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
650 | + if ( ! empty( $item_id ) ) { |
|
651 | + return $item_id; |
|
652 | + } |
|
653 | + |
|
654 | + // Fetch from the db. |
|
655 | + $items = array(); |
|
656 | + if ( $field == 'slug' ) { |
|
657 | + $items = get_posts( |
|
658 | + array( |
|
659 | + 'post_type' => 'wpi_item', |
|
660 | + 'name' => $value, |
|
661 | + 'posts_per_page' => 1, |
|
662 | + 'post_status' => 'any', |
|
663 | + ) |
|
664 | + ); |
|
665 | + } |
|
666 | + |
|
667 | + if ( $field =='custom_id' ) { |
|
668 | + $items = get_posts( |
|
669 | + array( |
|
670 | + 'post_type' => 'wpi_item', |
|
671 | + 'posts_per_page' => 1, |
|
672 | + 'post_status' => 'any', |
|
673 | + 'meta_query' => array( |
|
674 | + array( |
|
675 | + 'key' => '_wpinv_type', |
|
676 | + 'value' => $type, |
|
677 | + ), |
|
678 | + array( |
|
679 | + 'key' => '_wpinv_custom_id', |
|
680 | + 'value' => $value, |
|
681 | + ) |
|
682 | + ) |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + |
|
687 | + if ( empty( $items ) ) { |
|
688 | + return 0; |
|
689 | + } |
|
690 | + |
|
691 | + // Update the cache with our data |
|
692 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | + |
|
694 | + return $items[0]->ID; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -724,52 +724,52 @@ discard block |
||
724 | 724 | */ |
725 | 725 | |
726 | 726 | /** |
727 | - * Set parent order ID. |
|
728 | - * |
|
729 | - * @since 1.0.19 |
|
730 | - */ |
|
731 | - public function set_parent_id( $value ) { |
|
732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | - return; |
|
734 | - } |
|
735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | - } |
|
737 | - |
|
738 | - /** |
|
739 | - * Sets item status. |
|
740 | - * |
|
741 | - * @since 1.0.19 |
|
742 | - * @param string $status New status. |
|
743 | - * @return array details of change. |
|
744 | - */ |
|
745 | - public function set_status( $status ) { |
|
727 | + * Set parent order ID. |
|
728 | + * |
|
729 | + * @since 1.0.19 |
|
730 | + */ |
|
731 | + public function set_parent_id( $value ) { |
|
732 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | + return; |
|
734 | + } |
|
735 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * Sets item status. |
|
740 | + * |
|
741 | + * @since 1.0.19 |
|
742 | + * @param string $status New status. |
|
743 | + * @return array details of change. |
|
744 | + */ |
|
745 | + public function set_status( $status ) { |
|
746 | 746 | $old_status = $this->get_status(); |
747 | 747 | |
748 | 748 | $this->set_prop( 'status', $status ); |
749 | 749 | |
750 | - return array( |
|
751 | - 'from' => $old_status, |
|
752 | - 'to' => $status, |
|
753 | - ); |
|
750 | + return array( |
|
751 | + 'from' => $old_status, |
|
752 | + 'to' => $status, |
|
753 | + ); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
757 | - * Set plugin version when the item was created. |
|
758 | - * |
|
759 | - * @since 1.0.19 |
|
760 | - */ |
|
761 | - public function set_version( $value ) { |
|
762 | - $this->set_prop( 'version', $value ); |
|
757 | + * Set plugin version when the item was created. |
|
758 | + * |
|
759 | + * @since 1.0.19 |
|
760 | + */ |
|
761 | + public function set_version( $value ) { |
|
762 | + $this->set_prop( 'version', $value ); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
766 | - * Set date when the item was created. |
|
767 | - * |
|
768 | - * @since 1.0.19 |
|
769 | - * @param string $value Value to set. |
|
766 | + * Set date when the item was created. |
|
767 | + * |
|
768 | + * @since 1.0.19 |
|
769 | + * @param string $value Value to set. |
|
770 | 770 | * @return bool Whether or not the date was set. |
771 | - */ |
|
772 | - public function set_date_created( $value ) { |
|
771 | + */ |
|
772 | + public function set_date_created( $value ) { |
|
773 | 773 | $date = strtotime( $value ); |
774 | 774 | |
775 | 775 | if ( $date ) { |
@@ -782,13 +782,13 @@ discard block |
||
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
785 | - * Set date when the item was last modified. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $value Value to set. |
|
785 | + * Set date when the item was last modified. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $value Value to set. |
|
789 | 789 | * @return bool Whether or not the date was set. |
790 | - */ |
|
791 | - public function set_date_modified( $value ) { |
|
790 | + */ |
|
791 | + public function set_date_modified( $value ) { |
|
792 | 792 | $date = strtotime( $value ); |
793 | 793 | |
794 | 794 | if ( $date ) { |
@@ -801,115 +801,115 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Set the item name. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @param string $value New name. |
|
808 | - */ |
|
809 | - public function set_name( $value ) { |
|
804 | + * Set the item name. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @param string $value New name. |
|
808 | + */ |
|
809 | + public function set_name( $value ) { |
|
810 | 810 | $name = sanitize_text_field( $value ); |
811 | - $this->set_prop( 'name', $name ); |
|
811 | + $this->set_prop( 'name', $name ); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
815 | - * Alias of self::set_name(). |
|
816 | - * |
|
817 | - * @since 1.0.19 |
|
818 | - * @param string $value New name. |
|
819 | - */ |
|
820 | - public function set_title( $value ) { |
|
821 | - $this->set_name( $value ); |
|
815 | + * Alias of self::set_name(). |
|
816 | + * |
|
817 | + * @since 1.0.19 |
|
818 | + * @param string $value New name. |
|
819 | + */ |
|
820 | + public function set_title( $value ) { |
|
821 | + $this->set_name( $value ); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
825 | - * Set the item description. |
|
826 | - * |
|
827 | - * @since 1.0.19 |
|
828 | - * @param string $value New description. |
|
829 | - */ |
|
830 | - public function set_description( $value ) { |
|
825 | + * Set the item description. |
|
826 | + * |
|
827 | + * @since 1.0.19 |
|
828 | + * @param string $value New description. |
|
829 | + */ |
|
830 | + public function set_description( $value ) { |
|
831 | 831 | $description = wp_kses_post( $value ); |
832 | - return $this->set_prop( 'description', $description ); |
|
832 | + return $this->set_prop( 'description', $description ); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
836 | - * Alias of self::set_description(). |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - * @param string $value New description. |
|
840 | - */ |
|
841 | - public function set_excerpt( $value ) { |
|
842 | - $this->set_description( $value ); |
|
836 | + * Alias of self::set_description(). |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + * @param string $value New description. |
|
840 | + */ |
|
841 | + public function set_excerpt( $value ) { |
|
842 | + $this->set_description( $value ); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Alias of self::set_description(). |
|
847 | - * |
|
848 | - * @since 1.0.19 |
|
849 | - * @param string $value New description. |
|
850 | - */ |
|
851 | - public function set_summary( $value ) { |
|
852 | - $this->set_description( $value ); |
|
846 | + * Alias of self::set_description(). |
|
847 | + * |
|
848 | + * @since 1.0.19 |
|
849 | + * @param string $value New description. |
|
850 | + */ |
|
851 | + public function set_summary( $value ) { |
|
852 | + $this->set_description( $value ); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
856 | - * Set the owner of the item. |
|
857 | - * |
|
858 | - * @since 1.0.19 |
|
859 | - * @param int $value New author. |
|
860 | - */ |
|
861 | - public function set_author( $value ) { |
|
862 | - $this->set_prop( 'author', (int) $value ); |
|
863 | - } |
|
856 | + * Set the owner of the item. |
|
857 | + * |
|
858 | + * @since 1.0.19 |
|
859 | + * @param int $value New author. |
|
860 | + */ |
|
861 | + public function set_author( $value ) { |
|
862 | + $this->set_prop( 'author', (int) $value ); |
|
863 | + } |
|
864 | 864 | |
865 | - /** |
|
866 | - * Alias of self::set_author(). |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param int $value New author. |
|
870 | - */ |
|
871 | - public function set_owner( $value ) { |
|
872 | - $this->set_author( $value ); |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Set the price of the item. |
|
877 | - * |
|
878 | - * @since 1.0.19 |
|
879 | - * @param float $value New price. |
|
880 | - */ |
|
881 | - public function set_price( $value ) { |
|
865 | + /** |
|
866 | + * Alias of self::set_author(). |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param int $value New author. |
|
870 | + */ |
|
871 | + public function set_owner( $value ) { |
|
872 | + $this->set_author( $value ); |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Set the price of the item. |
|
877 | + * |
|
878 | + * @since 1.0.19 |
|
879 | + * @param float $value New price. |
|
880 | + */ |
|
881 | + public function set_price( $value ) { |
|
882 | 882 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
886 | - * Set the VAT rule of the item. |
|
887 | - * |
|
888 | - * @since 1.0.19 |
|
889 | - * @param string $value new rule. |
|
890 | - */ |
|
891 | - public function set_vat_rule( $value ) { |
|
886 | + * Set the VAT rule of the item. |
|
887 | + * |
|
888 | + * @since 1.0.19 |
|
889 | + * @param string $value new rule. |
|
890 | + */ |
|
891 | + public function set_vat_rule( $value ) { |
|
892 | 892 | $this->set_prop( 'vat_rule', $value ); |
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
896 | - * Set the VAT class of the item. |
|
897 | - * |
|
898 | - * @since 1.0.19 |
|
899 | - * @param string $value new class. |
|
900 | - */ |
|
901 | - public function set_vat_class( $value ) { |
|
896 | + * Set the VAT class of the item. |
|
897 | + * |
|
898 | + * @since 1.0.19 |
|
899 | + * @param string $value new class. |
|
900 | + */ |
|
901 | + public function set_vat_class( $value ) { |
|
902 | 902 | $this->set_prop( 'vat_class', $value ); |
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
906 | - * Set the type of the item. |
|
907 | - * |
|
908 | - * @since 1.0.19 |
|
909 | - * @param string $value new item type. |
|
910 | - * @return string |
|
911 | - */ |
|
912 | - public function set_type( $value ) { |
|
906 | + * Set the type of the item. |
|
907 | + * |
|
908 | + * @since 1.0.19 |
|
909 | + * @param string $value new item type. |
|
910 | + * @return string |
|
911 | + */ |
|
912 | + public function set_type( $value ) { |
|
913 | 913 | |
914 | 914 | if ( empty( $value ) ) { |
915 | 915 | $value = 'custom'; |
@@ -919,132 +919,132 @@ discard block |
||
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
922 | - * Set the custom id of the item. |
|
923 | - * |
|
924 | - * @since 1.0.19 |
|
925 | - * @param string $value new custom id. |
|
926 | - */ |
|
927 | - public function set_custom_id( $value ) { |
|
922 | + * Set the custom id of the item. |
|
923 | + * |
|
924 | + * @since 1.0.19 |
|
925 | + * @param string $value new custom id. |
|
926 | + */ |
|
927 | + public function set_custom_id( $value ) { |
|
928 | 928 | $this->set_prop( 'custom_id', $value ); |
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | - * Set the custom name of the item. |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $value new custom name. |
|
936 | - */ |
|
937 | - public function set_custom_name( $value ) { |
|
932 | + * Set the custom name of the item. |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $value new custom name. |
|
936 | + */ |
|
937 | + public function set_custom_name( $value ) { |
|
938 | 938 | $this->set_prop( 'custom_name', $value ); |
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
942 | - * Set the custom singular name of the item. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - * @param string $value new custom singular name. |
|
946 | - */ |
|
947 | - public function set_custom_singular_name( $value ) { |
|
942 | + * Set the custom singular name of the item. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + * @param string $value new custom singular name. |
|
946 | + */ |
|
947 | + public function set_custom_singular_name( $value ) { |
|
948 | 948 | $this->set_prop( 'custom_singular_name', $value ); |
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
952 | - * Sets if an item is editable.. |
|
953 | - * |
|
954 | - * @since 1.0.19 |
|
955 | - * @param int|bool $value whether or not the item is editable. |
|
956 | - */ |
|
957 | - public function set_is_editable( $value ) { |
|
958 | - $this->set_prop( 'is_editable', (int) $value ); |
|
952 | + * Sets if an item is editable.. |
|
953 | + * |
|
954 | + * @since 1.0.19 |
|
955 | + * @param int|bool $value whether or not the item is editable. |
|
956 | + */ |
|
957 | + public function set_is_editable( $value ) { |
|
958 | + $this->set_prop( 'is_editable', (int) $value ); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | /** |
962 | - * Sets if dynamic pricing is enabled. |
|
963 | - * |
|
964 | - * @since 1.0.19 |
|
965 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
966 | - */ |
|
967 | - public function set_is_dynamic_pricing( $value ) { |
|
962 | + * Sets if dynamic pricing is enabled. |
|
963 | + * |
|
964 | + * @since 1.0.19 |
|
965 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
966 | + */ |
|
967 | + public function set_is_dynamic_pricing( $value ) { |
|
968 | 968 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
972 | - * Sets the minimum price if dynamic pricing is enabled. |
|
973 | - * |
|
974 | - * @since 1.0.19 |
|
975 | - * @param float $value minimum price. |
|
976 | - */ |
|
977 | - public function set_minimum_price( $value ) { |
|
972 | + * Sets the minimum price if dynamic pricing is enabled. |
|
973 | + * |
|
974 | + * @since 1.0.19 |
|
975 | + * @param float $value minimum price. |
|
976 | + */ |
|
977 | + public function set_minimum_price( $value ) { |
|
978 | 978 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
982 | - * Sets if this is a recurring item. |
|
983 | - * |
|
984 | - * @since 1.0.19 |
|
985 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
986 | - */ |
|
987 | - public function set_is_recurring( $value ) { |
|
982 | + * Sets if this is a recurring item. |
|
983 | + * |
|
984 | + * @since 1.0.19 |
|
985 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
986 | + */ |
|
987 | + public function set_is_recurring( $value ) { |
|
988 | 988 | $this->set_prop( 'is_recurring', (int) $value ); |
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
992 | - * Set the recurring period. |
|
993 | - * |
|
994 | - * @since 1.0.19 |
|
995 | - * @param string $value new period. |
|
996 | - */ |
|
997 | - public function set_recurring_period( $value ) { |
|
992 | + * Set the recurring period. |
|
993 | + * |
|
994 | + * @since 1.0.19 |
|
995 | + * @param string $value new period. |
|
996 | + */ |
|
997 | + public function set_recurring_period( $value ) { |
|
998 | 998 | $this->set_prop( 'recurring_period', $value ); |
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | /** |
1002 | - * Set the recurring interval. |
|
1003 | - * |
|
1004 | - * @since 1.0.19 |
|
1005 | - * @param int $value recurring interval. |
|
1006 | - */ |
|
1007 | - public function set_recurring_interval( $value ) { |
|
1002 | + * Set the recurring interval. |
|
1003 | + * |
|
1004 | + * @since 1.0.19 |
|
1005 | + * @param int $value recurring interval. |
|
1006 | + */ |
|
1007 | + public function set_recurring_interval( $value ) { |
|
1008 | 1008 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | /** |
1012 | - * Get the recurring limit. |
|
1013 | - * @since 1.0.19 |
|
1014 | - * @param int $value The recurring limit. |
|
1015 | - * @return int |
|
1016 | - */ |
|
1017 | - public function set_recurring_limit( $value ) { |
|
1012 | + * Get the recurring limit. |
|
1013 | + * @since 1.0.19 |
|
1014 | + * @param int $value The recurring limit. |
|
1015 | + * @return int |
|
1016 | + */ |
|
1017 | + public function set_recurring_limit( $value ) { |
|
1018 | 1018 | $this->set_prop( 'recurring_limit', (int) $value ); |
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | /** |
1022 | - * Checks if we have a free trial. |
|
1023 | - * |
|
1024 | - * @since 1.0.19 |
|
1025 | - * @param int|bool $value whether or not it has a free trial. |
|
1026 | - */ |
|
1027 | - public function set_is_free_trial( $value ) { |
|
1022 | + * Checks if we have a free trial. |
|
1023 | + * |
|
1024 | + * @since 1.0.19 |
|
1025 | + * @param int|bool $value whether or not it has a free trial. |
|
1026 | + */ |
|
1027 | + public function set_is_free_trial( $value ) { |
|
1028 | 1028 | $this->set_prop( 'is_free_trial', (int) $value ); |
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | /** |
1032 | - * Set the trial period. |
|
1033 | - * |
|
1034 | - * @since 1.0.19 |
|
1035 | - * @param string $value trial period. |
|
1036 | - */ |
|
1037 | - public function set_trial_period( $value ) { |
|
1032 | + * Set the trial period. |
|
1033 | + * |
|
1034 | + * @since 1.0.19 |
|
1035 | + * @param string $value trial period. |
|
1036 | + */ |
|
1037 | + public function set_trial_period( $value ) { |
|
1038 | 1038 | $this->set_prop( 'trial_period', $value ); |
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
1042 | - * Set the trial interval. |
|
1043 | - * |
|
1044 | - * @since 1.0.19 |
|
1045 | - * @param int $value trial interval. |
|
1046 | - */ |
|
1047 | - public function set_trial_interval( $value ) { |
|
1042 | + * Set the trial interval. |
|
1043 | + * |
|
1044 | + * @since 1.0.19 |
|
1045 | + * @param int $value trial interval. |
|
1046 | + */ |
|
1047 | + public function set_trial_interval( $value ) { |
|
1048 | 1048 | $this->set_prop( 'trial_interval', $value ); |
1049 | 1049 | } |
1050 | 1050 | |
@@ -1052,17 +1052,17 @@ discard block |
||
1052 | 1052 | * Create an item. For backwards compatibilty. |
1053 | 1053 | * |
1054 | 1054 | * @deprecated |
1055 | - * @return int item id |
|
1055 | + * @return int item id |
|
1056 | 1056 | */ |
1057 | 1057 | public function create( $data = array() ) { |
1058 | 1058 | |
1059 | - // Set the properties. |
|
1060 | - if ( is_array( $data ) ) { |
|
1061 | - $this->set_props( $data ); |
|
1062 | - } |
|
1059 | + // Set the properties. |
|
1060 | + if ( is_array( $data ) ) { |
|
1061 | + $this->set_props( $data ); |
|
1062 | + } |
|
1063 | 1063 | |
1064 | - // Save the item. |
|
1065 | - return $this->save(); |
|
1064 | + // Save the item. |
|
1065 | + return $this->save(); |
|
1066 | 1066 | |
1067 | 1067 | } |
1068 | 1068 | |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * Updates an item. For backwards compatibilty. |
1071 | 1071 | * |
1072 | 1072 | * @deprecated |
1073 | - * @return int item id |
|
1073 | + * @return int item id |
|
1074 | 1074 | */ |
1075 | 1075 | public function update( $data = array() ) { |
1076 | 1076 | return $this->create( $data ); |
@@ -1086,93 +1086,93 @@ discard block |
||
1086 | 1086 | */ |
1087 | 1087 | |
1088 | 1088 | /** |
1089 | - * Checks whether the item has enabled dynamic pricing. |
|
1090 | - * |
|
1091 | - * @since 1.0.19 |
|
1092 | - * @return bool |
|
1093 | - */ |
|
1094 | - public function user_can_set_their_price() { |
|
1089 | + * Checks whether the item has enabled dynamic pricing. |
|
1090 | + * |
|
1091 | + * @since 1.0.19 |
|
1092 | + * @return bool |
|
1093 | + */ |
|
1094 | + public function user_can_set_their_price() { |
|
1095 | 1095 | return (bool) $this->get_is_dynamic_pricing(); |
1096 | - } |
|
1096 | + } |
|
1097 | 1097 | |
1098 | - /** |
|
1099 | - * Checks whether the item is recurring. |
|
1100 | - * |
|
1101 | - * @since 1.0.19 |
|
1102 | - * @return bool |
|
1103 | - */ |
|
1104 | - public function is_recurring() { |
|
1098 | + /** |
|
1099 | + * Checks whether the item is recurring. |
|
1100 | + * |
|
1101 | + * @since 1.0.19 |
|
1102 | + * @return bool |
|
1103 | + */ |
|
1104 | + public function is_recurring() { |
|
1105 | 1105 | return (bool) $this->get_is_recurring(); |
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | /** |
1109 | - * Checks whether the item has a free trial. |
|
1110 | - * |
|
1111 | - * @since 1.0.19 |
|
1112 | - * @return bool |
|
1113 | - */ |
|
1109 | + * Checks whether the item has a free trial. |
|
1110 | + * |
|
1111 | + * @since 1.0.19 |
|
1112 | + * @return bool |
|
1113 | + */ |
|
1114 | 1114 | public function has_free_trial() { |
1115 | 1115 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1116 | 1116 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | /** |
1120 | - * Checks whether the item is free. |
|
1121 | - * |
|
1122 | - * @since 1.0.19 |
|
1123 | - * @return bool |
|
1124 | - */ |
|
1120 | + * Checks whether the item is free. |
|
1121 | + * |
|
1122 | + * @since 1.0.19 |
|
1123 | + * @return bool |
|
1124 | + */ |
|
1125 | 1125 | public function is_free() { |
1126 | 1126 | $is_free = $this->get_price() == 0; |
1127 | 1127 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | /** |
1131 | - * Checks the item status against a passed in status. |
|
1132 | - * |
|
1133 | - * @param array|string $status Status to check. |
|
1134 | - * @return bool |
|
1135 | - */ |
|
1136 | - public function has_status( $status ) { |
|
1137 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1138 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1131 | + * Checks the item status against a passed in status. |
|
1132 | + * |
|
1133 | + * @param array|string $status Status to check. |
|
1134 | + * @return bool |
|
1135 | + */ |
|
1136 | + public function has_status( $status ) { |
|
1137 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1138 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | /** |
1142 | - * Checks the item type against a passed in types. |
|
1143 | - * |
|
1144 | - * @param array|string $type Type to check. |
|
1145 | - * @return bool |
|
1146 | - */ |
|
1147 | - public function is_type( $type ) { |
|
1148 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1149 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1150 | - } |
|
1142 | + * Checks the item type against a passed in types. |
|
1143 | + * |
|
1144 | + * @param array|string $type Type to check. |
|
1145 | + * @return bool |
|
1146 | + */ |
|
1147 | + public function is_type( $type ) { |
|
1148 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1149 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1150 | + } |
|
1151 | 1151 | |
1152 | 1152 | /** |
1153 | - * Checks whether the item is editable. |
|
1154 | - * |
|
1155 | - * @since 1.0.19 |
|
1156 | - * @return bool |
|
1157 | - */ |
|
1153 | + * Checks whether the item is editable. |
|
1154 | + * |
|
1155 | + * @since 1.0.19 |
|
1156 | + * @return bool |
|
1157 | + */ |
|
1158 | 1158 | public function is_editable() { |
1159 | 1159 | $is_editable = $this->get_is_editable(); |
1160 | 1160 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1161 | - } |
|
1161 | + } |
|
1162 | 1162 | |
1163 | - /** |
|
1164 | - * Returns an array of cart fees. |
|
1165 | - */ |
|
1166 | - public function get_fees() { |
|
1163 | + /** |
|
1164 | + * Returns an array of cart fees. |
|
1165 | + */ |
|
1166 | + public function get_fees() { |
|
1167 | 1167 | return array(); |
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
1171 | - * Checks whether the item is purchasable. |
|
1172 | - * |
|
1173 | - * @since 1.0.19 |
|
1174 | - * @return bool |
|
1175 | - */ |
|
1171 | + * Checks whether the item is purchasable. |
|
1172 | + * |
|
1173 | + * @since 1.0.19 |
|
1174 | + * @return bool |
|
1175 | + */ |
|
1176 | 1176 | public function can_purchase() { |
1177 | 1177 | $can_purchase = $this->exists(); |
1178 | 1178 | |
@@ -1184,11 +1184,11 @@ discard block |
||
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | /** |
1187 | - * Checks whether the item supports dynamic pricing. |
|
1188 | - * |
|
1189 | - * @since 1.0.19 |
|
1190 | - * @return bool |
|
1191 | - */ |
|
1187 | + * Checks whether the item supports dynamic pricing. |
|
1188 | + * |
|
1189 | + * @since 1.0.19 |
|
1190 | + * @return bool |
|
1191 | + */ |
|
1192 | 1192 | public function supports_dynamic_pricing() { |
1193 | 1193 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1194 | 1194 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -78,30 +78,30 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
80 | 80 | */ |
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
81 | + public function __construct($item = 0) { |
|
82 | + parent::__construct($item); |
|
83 | + |
|
84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
85 | + $this->set_id($item); |
|
86 | + } elseif ($item instanceof self) { |
|
87 | + $this->set_id($item->get_id()); |
|
88 | + } elseif (!empty($item->ID)) { |
|
89 | + $this->set_id($item->ID); |
|
90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
91 | + $this->set_id($item_id); |
|
92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
93 | + $this->set_id($item_id); |
|
94 | 94 | } else { |
95 | - $this->set_object_read( true ); |
|
95 | + $this->set_object_read(true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
102 | - $this->post = get_post( $this->get_id() ); |
|
101 | + if ($this->get_id() > 0) { |
|
102 | + $this->post = get_post($this->get_id()); |
|
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read($this); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param string $context View or edit context. |
129 | 129 | * @return int |
130 | 130 | */ |
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
131 | + public function get_parent_id($context = 'view') { |
|
132 | + return (int) $this->get_prop('parent_id', $context); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $context View or edit context. |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
142 | + public function get_status($context = 'view') { |
|
143 | + return $this->get_prop('status', $context); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | * @param string $context View or edit context. |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
153 | + public function get_version($context = 'view') { |
|
154 | + return $this->get_prop('version', $context); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | * @param string $context View or edit context. |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
164 | + public function get_date_created($context = 'view') { |
|
165 | + return $this->get_prop('date_created', $context); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | * @param string $context View or edit context. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
176 | - $date = $this->get_date_created( $context ); |
|
175 | + public function get_date_created_gmt($context = 'view') { |
|
176 | + $date = $this->get_date_created($context); |
|
177 | 177 | |
178 | - if ( $date ) { |
|
179 | - $date = get_gmt_from_date( $date ); |
|
178 | + if ($date) { |
|
179 | + $date = get_gmt_from_date($date); |
|
180 | 180 | } |
181 | 181 | return $date; |
182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param string $context View or edit context. |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
191 | + public function get_date_modified($context = 'view') { |
|
192 | + return $this->get_prop('date_modified', $context); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | - $date = $this->get_date_modified( $context ); |
|
202 | + public function get_date_modified_gmt($context = 'view') { |
|
203 | + $date = $this->get_date_modified($context); |
|
204 | 204 | |
205 | - if ( $date ) { |
|
206 | - $date = get_gmt_from_date( $date ); |
|
205 | + if ($date) { |
|
206 | + $date = get_gmt_from_date($date); |
|
207 | 207 | } |
208 | 208 | return $date; |
209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | * @param string $context View or edit context. |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
218 | + public function get_name($context = 'view') { |
|
219 | + return $this->get_prop('name', $context); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @param string $context View or edit context. |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
229 | + public function get_title($context = 'view') { |
|
230 | + return $this->get_name($context); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @param string $context View or edit context. |
238 | 238 | * @return string |
239 | 239 | */ |
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
240 | + public function get_description($context = 'view') { |
|
241 | + return $this->get_prop('description', $context); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param string $context View or edit context. |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
251 | + public function get_excerpt($context = 'view') { |
|
252 | + return $this->get_description($context); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | * @param string $context View or edit context. |
260 | 260 | * @return string |
261 | 261 | */ |
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
262 | + public function get_summary($context = 'view') { |
|
263 | + return $this->get_description($context); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $context View or edit context. |
271 | 271 | * @return int |
272 | 272 | */ |
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
273 | + public function get_author($context = 'view') { |
|
274 | + return (int) $this->get_prop('author', $context); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @param string $context View or edit context. |
282 | 282 | * @return int |
283 | 283 | */ |
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
284 | + public function get_owner($context = 'view') { |
|
285 | + return $this->get_author($context); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param string $context View or edit context. |
293 | 293 | * @return float |
294 | 294 | */ |
295 | - public function get_price( $context = 'view' ) { |
|
296 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
295 | + public function get_price($context = 'view') { |
|
296 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,15 +303,15 @@ discard block |
||
303 | 303 | * @param string $context View or edit context. |
304 | 304 | * @return float |
305 | 305 | */ |
306 | - public function get_initial_price( $context = 'view' ) { |
|
306 | + public function get_initial_price($context = 'view') { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price($context); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
310 | + if ($this->has_free_trial()) { |
|
311 | 311 | $price = 0; |
312 | 312 | } |
313 | 313 | |
314 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
314 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return string |
323 | 323 | */ |
324 | 324 | public function get_the_price() { |
325 | - return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
|
325 | + return wpinv_price(wpinv_format_amount($this->get_price())); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return string |
334 | 334 | */ |
335 | 335 | public function get_the_initial_price() { |
336 | - return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
|
336 | + return wpinv_price(wpinv_format_amount($this->get_initial_price())); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | * @param string $context View or edit context. |
344 | 344 | * @return string |
345 | 345 | */ |
346 | - public function get_vat_rule( $context = 'view' ) { |
|
347 | - return $this->get_prop( 'vat_rule', $context ); |
|
346 | + public function get_vat_rule($context = 'view') { |
|
347 | + return $this->get_prop('vat_rule', $context); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | * @param string $context View or edit context. |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - public function get_vat_class( $context = 'view' ) { |
|
358 | - return $this->get_prop( 'vat_class', $context ); |
|
357 | + public function get_vat_class($context = 'view') { |
|
358 | + return $this->get_prop('vat_class', $context); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | * @param string $context View or edit context. |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public function get_type( $context = 'view' ) { |
|
369 | - return $this->get_prop( 'type', $context ); |
|
368 | + public function get_type($context = 'view') { |
|
369 | + return $this->get_prop('type', $context); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @param string $context View or edit context. |
377 | 377 | * @return string |
378 | 378 | */ |
379 | - public function get_custom_id( $context = 'view' ) { |
|
380 | - return $this->get_prop( 'custom_id', $context ); |
|
379 | + public function get_custom_id($context = 'view') { |
|
380 | + return $this->get_prop('custom_id', $context); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | * @param string $context View or edit context. |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_custom_name( $context = 'view' ) { |
|
391 | - return $this->get_prop( 'custom_name', $context ); |
|
390 | + public function get_custom_name($context = 'view') { |
|
391 | + return $this->get_prop('custom_name', $context); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * @param string $context View or edit context. |
399 | 399 | * @return string |
400 | 400 | */ |
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
402 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
401 | + public function get_custom_singular_name($context = 'view') { |
|
402 | + return $this->get_prop('custom_singular_name', $context); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @param string $context View or edit context. |
410 | 410 | * @return int |
411 | 411 | */ |
412 | - public function get_is_editable( $context = 'view' ) { |
|
413 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
412 | + public function get_is_editable($context = 'view') { |
|
413 | + return (int) $this->get_prop('is_editable', $context); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $context View or edit context. |
421 | 421 | * @return int |
422 | 422 | */ |
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
423 | + public function get_editable($context = 'view') { |
|
424 | + return $this->get_is_editable($context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param string $context View or edit context. |
432 | 432 | * @return int |
433 | 433 | */ |
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
434 | + public function get_is_dynamic_pricing($context = 'view') { |
|
435 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $context View or edit context. |
443 | 443 | * @return float |
444 | 444 | */ |
445 | - public function get_minimum_price( $context = 'view' ) { |
|
446 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
445 | + public function get_minimum_price($context = 'view') { |
|
446 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | * @param string $context View or edit context. |
454 | 454 | * @return int |
455 | 455 | */ |
456 | - public function get_is_recurring( $context = 'view' ) { |
|
457 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
456 | + public function get_is_recurring($context = 'view') { |
|
457 | + return (int) $this->get_prop('is_recurring', $context); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | * @param string $context View or edit context. |
465 | 465 | * @return float |
466 | 466 | */ |
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
469 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
467 | + public function get_recurring_price($context = 'view') { |
|
468 | + $price = $this->get_price($context); |
|
469 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return string |
478 | 478 | */ |
479 | 479 | public function get_the_recurring_price() { |
480 | - return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
|
480 | + return wpinv_price(wpinv_format_amount($this->get_recurring_price())); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -498,15 +498,15 @@ discard block |
||
498 | 498 | $period = $this->get_recurring_period(); |
499 | 499 | $interval = $this->get_recurring_interval(); |
500 | 500 | |
501 | - if ( $this->has_free_trial() ) { |
|
501 | + if ($this->has_free_trial()) { |
|
502 | 502 | $period = $this->get_trial_period(); |
503 | 503 | $interval = $this->get_trial_interval(); |
504 | 504 | } |
505 | 505 | |
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
506 | + $period = $periods[$period]; |
|
507 | + $interval = empty($interval) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
509 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | * @param bool $full Return abbreviation or in full. |
517 | 517 | * @return string |
518 | 518 | */ |
519 | - public function get_recurring_period( $full = false ) { |
|
520 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
519 | + public function get_recurring_period($full = false) { |
|
520 | + $period = $this->get_prop('recurring_period', 'view'); |
|
521 | 521 | |
522 | - if ( $full && ! is_bool( $full ) ) { |
|
522 | + if ($full && !is_bool($full)) { |
|
523 | 523 | $full = false; |
524 | 524 | } |
525 | 525 | |
526 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
526 | + return getpaid_sanitize_recurring_period($period, $full); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,10 +533,10 @@ discard block |
||
533 | 533 | * @param string $context View or edit context. |
534 | 534 | * @return int |
535 | 535 | */ |
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
536 | + public function get_recurring_interval($context = 'view') { |
|
537 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
539 | + if ($interval < 1) { |
|
540 | 540 | $interval = 1; |
541 | 541 | } |
542 | 542 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param string $context View or edit context. |
551 | 551 | * @return int |
552 | 552 | */ |
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
554 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
553 | + public function get_recurring_limit($context = 'view') { |
|
554 | + return (int) $this->get_prop('recurring_limit', $context); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @param string $context View or edit context. |
562 | 562 | * @return int |
563 | 563 | */ |
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
565 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
564 | + public function get_is_free_trial($context = 'view') { |
|
565 | + return (int) $this->get_prop('is_free_trial', $context); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | * @param string $context View or edit context. |
573 | 573 | * @return int |
574 | 574 | */ |
575 | - public function get_free_trial( $context = 'view' ) { |
|
576 | - return $this->get_is_free_trial( $context ); |
|
575 | + public function get_free_trial($context = 'view') { |
|
576 | + return $this->get_is_free_trial($context); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,14 +583,14 @@ discard block |
||
583 | 583 | * @param bool $full Return abbreviation or in full. |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - public function get_trial_period( $full = false ) { |
|
587 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
586 | + public function get_trial_period($full = false) { |
|
587 | + $period = $this->get_prop('trial_period', 'view'); |
|
588 | 588 | |
589 | - if ( $full && ! is_bool( $full ) ) { |
|
589 | + if ($full && !is_bool($full)) { |
|
590 | 590 | $full = false; |
591 | 591 | } |
592 | 592 | |
593 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
593 | + return getpaid_sanitize_recurring_period($period, $full); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | * @param string $context View or edit context. |
601 | 601 | * @return int |
602 | 602 | */ |
603 | - public function get_trial_interval( $context = 'view' ) { |
|
604 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
603 | + public function get_trial_interval($context = 'view') { |
|
604 | + return (int) $this->get_prop('trial_interval', $context); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | * @return string |
612 | 612 | */ |
613 | 613 | public function get_edit_url() { |
614 | - return get_edit_post_link( $this->get_id() ); |
|
614 | + return get_edit_post_link($this->get_id()); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -625,35 +625,35 @@ discard block |
||
625 | 625 | * @since 1.0.15 |
626 | 626 | * @return int |
627 | 627 | */ |
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
628 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
629 | 629 | |
630 | 630 | // Trim the value. |
631 | - $value = sanitize_text_field( $value ); |
|
632 | - if ( empty( $value ) ) { |
|
631 | + $value = sanitize_text_field($value); |
|
632 | + if (empty($value)) { |
|
633 | 633 | return 0; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // Valid fields. |
637 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
637 | + $fields = array('custom_id', 'name', 'slug'); |
|
638 | 638 | |
639 | 639 | // Ensure a field has been passed. |
640 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
640 | + if (empty($field) || !in_array($field, $fields)) { |
|
641 | 641 | return 0; |
642 | 642 | } |
643 | 643 | |
644 | - if ( $field == 'name' ) { |
|
644 | + if ($field == 'name') { |
|
645 | 645 | $field = 'slug'; |
646 | 646 | } |
647 | 647 | |
648 | 648 | // Maybe retrieve from the cache. |
649 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
650 | - if ( ! empty( $item_id ) ) { |
|
649 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
650 | + if (!empty($item_id)) { |
|
651 | 651 | return $item_id; |
652 | 652 | } |
653 | 653 | |
654 | 654 | // Fetch from the db. |
655 | 655 | $items = array(); |
656 | - if ( $field == 'slug' ) { |
|
656 | + if ($field == 'slug') { |
|
657 | 657 | $items = get_posts( |
658 | 658 | array( |
659 | 659 | 'post_type' => 'wpi_item', |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | ); |
665 | 665 | } |
666 | 666 | |
667 | - if ( $field =='custom_id' ) { |
|
667 | + if ($field == 'custom_id') { |
|
668 | 668 | $items = get_posts( |
669 | 669 | array( |
670 | 670 | 'post_type' => 'wpi_item', |
@@ -684,12 +684,12 @@ discard block |
||
684 | 684 | ); |
685 | 685 | } |
686 | 686 | |
687 | - if ( empty( $items ) ) { |
|
687 | + if (empty($items)) { |
|
688 | 688 | return 0; |
689 | 689 | } |
690 | 690 | |
691 | 691 | // Update the cache with our data |
692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
692 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
693 | 693 | |
694 | 694 | return $items[0]->ID; |
695 | 695 | } |
@@ -697,19 +697,19 @@ discard block |
||
697 | 697 | /** |
698 | 698 | * Margic method for retrieving a property. |
699 | 699 | */ |
700 | - public function __get( $key ) { |
|
700 | + public function __get($key) { |
|
701 | 701 | |
702 | 702 | // Check if we have a helper method for that. |
703 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
704 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
703 | + if (method_exists($this, 'get_' . $key)) { |
|
704 | + return call_user_func(array($this, 'get_' . $key)); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | // Check if the key is in the associated $post object. |
708 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
708 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
709 | 709 | return $this->post->$key; |
710 | 710 | } |
711 | 711 | |
712 | - return $this->get_prop( $key ); |
|
712 | + return $this->get_prop($key); |
|
713 | 713 | |
714 | 714 | } |
715 | 715 | |
@@ -728,11 +728,11 @@ discard block |
||
728 | 728 | * |
729 | 729 | * @since 1.0.19 |
730 | 730 | */ |
731 | - public function set_parent_id( $value ) { |
|
732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
731 | + public function set_parent_id($value) { |
|
732 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
733 | 733 | return; |
734 | 734 | } |
735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
735 | + $this->set_prop('parent_id', absint($value)); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -742,10 +742,10 @@ discard block |
||
742 | 742 | * @param string $status New status. |
743 | 743 | * @return array details of change. |
744 | 744 | */ |
745 | - public function set_status( $status ) { |
|
745 | + public function set_status($status) { |
|
746 | 746 | $old_status = $this->get_status(); |
747 | 747 | |
748 | - $this->set_prop( 'status', $status ); |
|
748 | + $this->set_prop('status', $status); |
|
749 | 749 | |
750 | 750 | return array( |
751 | 751 | 'from' => $old_status, |
@@ -758,8 +758,8 @@ discard block |
||
758 | 758 | * |
759 | 759 | * @since 1.0.19 |
760 | 760 | */ |
761 | - public function set_version( $value ) { |
|
762 | - $this->set_prop( 'version', $value ); |
|
761 | + public function set_version($value) { |
|
762 | + $this->set_prop('version', $value); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -769,11 +769,11 @@ discard block |
||
769 | 769 | * @param string $value Value to set. |
770 | 770 | * @return bool Whether or not the date was set. |
771 | 771 | */ |
772 | - public function set_date_created( $value ) { |
|
773 | - $date = strtotime( $value ); |
|
772 | + public function set_date_created($value) { |
|
773 | + $date = strtotime($value); |
|
774 | 774 | |
775 | - if ( $date ) { |
|
776 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
775 | + if ($date) { |
|
776 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
777 | 777 | return true; |
778 | 778 | } |
779 | 779 | |
@@ -788,11 +788,11 @@ discard block |
||
788 | 788 | * @param string $value Value to set. |
789 | 789 | * @return bool Whether or not the date was set. |
790 | 790 | */ |
791 | - public function set_date_modified( $value ) { |
|
792 | - $date = strtotime( $value ); |
|
791 | + public function set_date_modified($value) { |
|
792 | + $date = strtotime($value); |
|
793 | 793 | |
794 | - if ( $date ) { |
|
795 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
794 | + if ($date) { |
|
795 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
796 | 796 | return true; |
797 | 797 | } |
798 | 798 | |
@@ -806,9 +806,9 @@ discard block |
||
806 | 806 | * @since 1.0.19 |
807 | 807 | * @param string $value New name. |
808 | 808 | */ |
809 | - public function set_name( $value ) { |
|
810 | - $name = sanitize_text_field( $value ); |
|
811 | - $this->set_prop( 'name', $name ); |
|
809 | + public function set_name($value) { |
|
810 | + $name = sanitize_text_field($value); |
|
811 | + $this->set_prop('name', $name); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
@@ -817,8 +817,8 @@ discard block |
||
817 | 817 | * @since 1.0.19 |
818 | 818 | * @param string $value New name. |
819 | 819 | */ |
820 | - public function set_title( $value ) { |
|
821 | - $this->set_name( $value ); |
|
820 | + public function set_title($value) { |
|
821 | + $this->set_name($value); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -827,9 +827,9 @@ discard block |
||
827 | 827 | * @since 1.0.19 |
828 | 828 | * @param string $value New description. |
829 | 829 | */ |
830 | - public function set_description( $value ) { |
|
831 | - $description = wp_kses_post( $value ); |
|
832 | - return $this->set_prop( 'description', $description ); |
|
830 | + public function set_description($value) { |
|
831 | + $description = wp_kses_post($value); |
|
832 | + return $this->set_prop('description', $description); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,8 +838,8 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | * @param string $value New description. |
840 | 840 | */ |
841 | - public function set_excerpt( $value ) { |
|
842 | - $this->set_description( $value ); |
|
841 | + public function set_excerpt($value) { |
|
842 | + $this->set_description($value); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
@@ -848,8 +848,8 @@ discard block |
||
848 | 848 | * @since 1.0.19 |
849 | 849 | * @param string $value New description. |
850 | 850 | */ |
851 | - public function set_summary( $value ) { |
|
852 | - $this->set_description( $value ); |
|
851 | + public function set_summary($value) { |
|
852 | + $this->set_description($value); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
@@ -858,8 +858,8 @@ discard block |
||
858 | 858 | * @since 1.0.19 |
859 | 859 | * @param int $value New author. |
860 | 860 | */ |
861 | - public function set_author( $value ) { |
|
862 | - $this->set_prop( 'author', (int) $value ); |
|
861 | + public function set_author($value) { |
|
862 | + $this->set_prop('author', (int) $value); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -868,8 +868,8 @@ discard block |
||
868 | 868 | * @since 1.0.19 |
869 | 869 | * @param int $value New author. |
870 | 870 | */ |
871 | - public function set_owner( $value ) { |
|
872 | - $this->set_author( $value ); |
|
871 | + public function set_owner($value) { |
|
872 | + $this->set_author($value); |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | /** |
@@ -878,8 +878,8 @@ discard block |
||
878 | 878 | * @since 1.0.19 |
879 | 879 | * @param float $value New price. |
880 | 880 | */ |
881 | - public function set_price( $value ) { |
|
882 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
881 | + public function set_price($value) { |
|
882 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -888,8 +888,8 @@ discard block |
||
888 | 888 | * @since 1.0.19 |
889 | 889 | * @param string $value new rule. |
890 | 890 | */ |
891 | - public function set_vat_rule( $value ) { |
|
892 | - $this->set_prop( 'vat_rule', $value ); |
|
891 | + public function set_vat_rule($value) { |
|
892 | + $this->set_prop('vat_rule', $value); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -898,8 +898,8 @@ discard block |
||
898 | 898 | * @since 1.0.19 |
899 | 899 | * @param string $value new class. |
900 | 900 | */ |
901 | - public function set_vat_class( $value ) { |
|
902 | - $this->set_prop( 'vat_class', $value ); |
|
901 | + public function set_vat_class($value) { |
|
902 | + $this->set_prop('vat_class', $value); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
@@ -909,13 +909,13 @@ discard block |
||
909 | 909 | * @param string $value new item type. |
910 | 910 | * @return string |
911 | 911 | */ |
912 | - public function set_type( $value ) { |
|
912 | + public function set_type($value) { |
|
913 | 913 | |
914 | - if ( empty( $value ) ) { |
|
914 | + if (empty($value)) { |
|
915 | 915 | $value = 'custom'; |
916 | 916 | } |
917 | 917 | |
918 | - $this->set_prop( 'type', $value ); |
|
918 | + $this->set_prop('type', $value); |
|
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
@@ -924,8 +924,8 @@ discard block |
||
924 | 924 | * @since 1.0.19 |
925 | 925 | * @param string $value new custom id. |
926 | 926 | */ |
927 | - public function set_custom_id( $value ) { |
|
928 | - $this->set_prop( 'custom_id', $value ); |
|
927 | + public function set_custom_id($value) { |
|
928 | + $this->set_prop('custom_id', $value); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | * @since 1.0.19 |
935 | 935 | * @param string $value new custom name. |
936 | 936 | */ |
937 | - public function set_custom_name( $value ) { |
|
938 | - $this->set_prop( 'custom_name', $value ); |
|
937 | + public function set_custom_name($value) { |
|
938 | + $this->set_prop('custom_name', $value); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -944,8 +944,8 @@ discard block |
||
944 | 944 | * @since 1.0.19 |
945 | 945 | * @param string $value new custom singular name. |
946 | 946 | */ |
947 | - public function set_custom_singular_name( $value ) { |
|
948 | - $this->set_prop( 'custom_singular_name', $value ); |
|
947 | + public function set_custom_singular_name($value) { |
|
948 | + $this->set_prop('custom_singular_name', $value); |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
@@ -954,8 +954,8 @@ discard block |
||
954 | 954 | * @since 1.0.19 |
955 | 955 | * @param int|bool $value whether or not the item is editable. |
956 | 956 | */ |
957 | - public function set_is_editable( $value ) { |
|
958 | - $this->set_prop( 'is_editable', (int) $value ); |
|
957 | + public function set_is_editable($value) { |
|
958 | + $this->set_prop('is_editable', (int) $value); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | /** |
@@ -964,8 +964,8 @@ discard block |
||
964 | 964 | * @since 1.0.19 |
965 | 965 | * @param int|bool $value whether or not dynamic pricing is allowed. |
966 | 966 | */ |
967 | - public function set_is_dynamic_pricing( $value ) { |
|
968 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
967 | + public function set_is_dynamic_pricing($value) { |
|
968 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
@@ -974,8 +974,8 @@ discard block |
||
974 | 974 | * @since 1.0.19 |
975 | 975 | * @param float $value minimum price. |
976 | 976 | */ |
977 | - public function set_minimum_price( $value ) { |
|
978 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
977 | + public function set_minimum_price($value) { |
|
978 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
@@ -984,8 +984,8 @@ discard block |
||
984 | 984 | * @since 1.0.19 |
985 | 985 | * @param int|bool $value whether or not dynamic pricing is allowed. |
986 | 986 | */ |
987 | - public function set_is_recurring( $value ) { |
|
988 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
987 | + public function set_is_recurring($value) { |
|
988 | + $this->set_prop('is_recurring', (int) $value); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
@@ -994,8 +994,8 @@ discard block |
||
994 | 994 | * @since 1.0.19 |
995 | 995 | * @param string $value new period. |
996 | 996 | */ |
997 | - public function set_recurring_period( $value ) { |
|
998 | - $this->set_prop( 'recurring_period', $value ); |
|
997 | + public function set_recurring_period($value) { |
|
998 | + $this->set_prop('recurring_period', $value); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | /** |
@@ -1004,8 +1004,8 @@ discard block |
||
1004 | 1004 | * @since 1.0.19 |
1005 | 1005 | * @param int $value recurring interval. |
1006 | 1006 | */ |
1007 | - public function set_recurring_interval( $value ) { |
|
1008 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
1007 | + public function set_recurring_interval($value) { |
|
1008 | + return $this->set_prop('recurring_interval', (int) $value); |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | /** |
@@ -1014,8 +1014,8 @@ discard block |
||
1014 | 1014 | * @param int $value The recurring limit. |
1015 | 1015 | * @return int |
1016 | 1016 | */ |
1017 | - public function set_recurring_limit( $value ) { |
|
1018 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
1017 | + public function set_recurring_limit($value) { |
|
1018 | + $this->set_prop('recurring_limit', (int) $value); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | /** |
@@ -1024,8 +1024,8 @@ discard block |
||
1024 | 1024 | * @since 1.0.19 |
1025 | 1025 | * @param int|bool $value whether or not it has a free trial. |
1026 | 1026 | */ |
1027 | - public function set_is_free_trial( $value ) { |
|
1028 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
1027 | + public function set_is_free_trial($value) { |
|
1028 | + $this->set_prop('is_free_trial', (int) $value); |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | /** |
@@ -1034,8 +1034,8 @@ discard block |
||
1034 | 1034 | * @since 1.0.19 |
1035 | 1035 | * @param string $value trial period. |
1036 | 1036 | */ |
1037 | - public function set_trial_period( $value ) { |
|
1038 | - $this->set_prop( 'trial_period', $value ); |
|
1037 | + public function set_trial_period($value) { |
|
1038 | + $this->set_prop('trial_period', $value); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
@@ -1044,8 +1044,8 @@ discard block |
||
1044 | 1044 | * @since 1.0.19 |
1045 | 1045 | * @param int $value trial interval. |
1046 | 1046 | */ |
1047 | - public function set_trial_interval( $value ) { |
|
1048 | - $this->set_prop( 'trial_interval', $value ); |
|
1047 | + public function set_trial_interval($value) { |
|
1048 | + $this->set_prop('trial_interval', $value); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | /** |
@@ -1054,11 +1054,11 @@ discard block |
||
1054 | 1054 | * @deprecated |
1055 | 1055 | * @return int item id |
1056 | 1056 | */ |
1057 | - public function create( $data = array() ) { |
|
1057 | + public function create($data = array()) { |
|
1058 | 1058 | |
1059 | 1059 | // Set the properties. |
1060 | - if ( is_array( $data ) ) { |
|
1061 | - $this->set_props( $data ); |
|
1060 | + if (is_array($data)) { |
|
1061 | + $this->set_props($data); |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | // Save the item. |
@@ -1072,8 +1072,8 @@ discard block |
||
1072 | 1072 | * @deprecated |
1073 | 1073 | * @return int item id |
1074 | 1074 | */ |
1075 | - public function update( $data = array() ) { |
|
1076 | - return $this->create( $data ); |
|
1075 | + public function update($data = array()) { |
|
1076 | + return $this->create($data); |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | /* |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | */ |
1114 | 1114 | public function has_free_trial() { |
1115 | 1115 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1116 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
1116 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | /** |
@@ -1123,8 +1123,8 @@ discard block |
||
1123 | 1123 | * @return bool |
1124 | 1124 | */ |
1125 | 1125 | public function is_free() { |
1126 | - $is_free = $this->get_price() == 0; |
|
1127 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
1126 | + $is_free = $this->get_price() == 0; |
|
1127 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | /** |
@@ -1133,9 +1133,9 @@ discard block |
||
1133 | 1133 | * @param array|string $status Status to check. |
1134 | 1134 | * @return bool |
1135 | 1135 | */ |
1136 | - public function has_status( $status ) { |
|
1137 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1138 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1136 | + public function has_status($status) { |
|
1137 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
1138 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | /** |
@@ -1144,9 +1144,9 @@ discard block |
||
1144 | 1144 | * @param array|string $type Type to check. |
1145 | 1145 | * @return bool |
1146 | 1146 | */ |
1147 | - public function is_type( $type ) { |
|
1148 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1149 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1147 | + public function is_type($type) { |
|
1148 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
1149 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | public function is_editable() { |
1159 | 1159 | $is_editable = $this->get_is_editable(); |
1160 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
1160 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | /** |
@@ -1176,11 +1176,11 @@ discard block |
||
1176 | 1176 | public function can_purchase() { |
1177 | 1177 | $can_purchase = $this->exists(); |
1178 | 1178 | |
1179 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
1179 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
1180 | 1180 | $can_purchase = false; |
1181 | 1181 | } |
1182 | 1182 | |
1183 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
1183 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | /** |
@@ -1190,6 +1190,6 @@ discard block |
||
1190 | 1190 | * @return bool |
1191 | 1191 | */ |
1192 | 1192 | public function supports_dynamic_pricing() { |
1193 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
1193 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
1194 | 1194 | } |
1195 | 1195 | } |
@@ -12,43 +12,43 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Earnings extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves the earning graphs. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function get_graphs() { |
|
15 | + /** |
|
16 | + * Retrieves the earning graphs. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function get_graphs() { |
|
20 | 20 | |
21 | - $graphs = array( |
|
21 | + $graphs = array( |
|
22 | 22 | |
23 | 23 | 'total' => __( 'Earnings', 'invoicing' ), |
24 | 24 | 'discount' => __( 'Discount', 'invoicing' ), |
25 | - 'fees_total' => __( 'Fees', 'invoicing' ), |
|
26 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
25 | + 'fees_total' => __( 'Fees', 'invoicing' ), |
|
26 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
27 | 27 | |
28 | - ); |
|
28 | + ); |
|
29 | 29 | |
30 | - return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
30 | + return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
31 | 31 | |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Retrieves the earning sql. |
|
36 | - * |
|
37 | - */ |
|
38 | - public function get_sql( $range ) { |
|
39 | - global $wpdb; |
|
34 | + /** |
|
35 | + * Retrieves the earning sql. |
|
36 | + * |
|
37 | + */ |
|
38 | + public function get_sql( $range ) { |
|
39 | + global $wpdb; |
|
40 | 40 | |
41 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
42 | - $clauses = $this->get_range_sql( $range ); |
|
43 | - $graphs = array_keys( $this->get_graphs() ); |
|
44 | - $graphs_sql = array(); |
|
41 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
42 | + $clauses = $this->get_range_sql( $range ); |
|
43 | + $graphs = array_keys( $this->get_graphs() ); |
|
44 | + $graphs_sql = array(); |
|
45 | 45 | |
46 | - foreach ( $graphs as $graph ) { |
|
47 | - $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
|
48 | - } |
|
46 | + foreach ( $graphs as $graph ) { |
|
47 | + $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
|
48 | + } |
|
49 | 49 | |
50 | - $graphs_sql = implode( ', ', $graphs_sql ); |
|
51 | - $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
|
50 | + $graphs_sql = implode( ', ', $graphs_sql ); |
|
51 | + $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
|
52 | 52 | FROM $wpdb->posts |
53 | 53 | LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID |
54 | 54 | WHERE meta.post_id IS NOT NULL |
@@ -58,94 +58,94 @@ discard block |
||
58 | 58 | GROUP BY {$clauses[0]} |
59 | 59 | "; |
60 | 60 | |
61 | - return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
62 | - |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Prepares the report stats. |
|
67 | - * |
|
68 | - */ |
|
69 | - public function prepare_stats() { |
|
70 | - global $wpdb; |
|
71 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Retrieves report labels. |
|
76 | - * |
|
77 | - */ |
|
78 | - public function get_labels( $range ) { |
|
79 | - |
|
80 | - $labels = array( |
|
81 | - 'today' => $this->get_hours_in_a_day(), |
|
82 | - 'yesterday' => $this->get_hours_in_a_day(), |
|
83 | - '7_days' => $this->get_days_in_period( 7 ), |
|
84 | - '30_days' => $this->get_days_in_period( 30 ), |
|
85 | - '60_days' => $this->get_days_in_period( 60 ), |
|
86 | - '90_days' => $this->get_weeks_in_period( 90 ), |
|
87 | - '180_days' => $this->get_weeks_in_period( 180 ), |
|
88 | - '360_days' => $this->get_weeks_in_period( 360 ), |
|
89 | - ); |
|
90 | - |
|
91 | - $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels[ '7_days' ]; |
|
92 | - return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Retrieves report datasets. |
|
97 | - * |
|
98 | - */ |
|
99 | - public function get_datasets( $labels ) { |
|
100 | - |
|
101 | - $datasets = array(); |
|
102 | - |
|
103 | - foreach ( $this->get_graphs() as $key => $label ) { |
|
104 | - $datasets[ $key ] = array( |
|
105 | - 'label' => $label, |
|
106 | - 'data' => $this->get_data( $key, $labels ) |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Retrieves report data. |
|
115 | - * |
|
116 | - */ |
|
117 | - public function get_data( $key, $labels ) { |
|
118 | - |
|
119 | - $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
120 | - $prepared = array(); |
|
121 | - |
|
122 | - foreach ( $labels as $label ) { |
|
123 | - |
|
124 | - $value = 0; |
|
125 | - if ( isset( $data[ $label ] ) ) { |
|
126 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
127 | - } |
|
128 | - |
|
129 | - $prepared[] = $value; |
|
130 | - } |
|
131 | - |
|
132 | - return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
133 | - |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Displays the report card. |
|
138 | - * |
|
139 | - */ |
|
140 | - public function display() { |
|
141 | - |
|
142 | - $labels = $this->get_labels( $this->get_range() ); |
|
143 | - $chart_data = array( |
|
144 | - 'labels' => array_values( $labels ), |
|
145 | - 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
146 | - ); |
|
147 | - |
|
148 | - ?> |
|
61 | + return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
62 | + |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Prepares the report stats. |
|
67 | + * |
|
68 | + */ |
|
69 | + public function prepare_stats() { |
|
70 | + global $wpdb; |
|
71 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Retrieves report labels. |
|
76 | + * |
|
77 | + */ |
|
78 | + public function get_labels( $range ) { |
|
79 | + |
|
80 | + $labels = array( |
|
81 | + 'today' => $this->get_hours_in_a_day(), |
|
82 | + 'yesterday' => $this->get_hours_in_a_day(), |
|
83 | + '7_days' => $this->get_days_in_period( 7 ), |
|
84 | + '30_days' => $this->get_days_in_period( 30 ), |
|
85 | + '60_days' => $this->get_days_in_period( 60 ), |
|
86 | + '90_days' => $this->get_weeks_in_period( 90 ), |
|
87 | + '180_days' => $this->get_weeks_in_period( 180 ), |
|
88 | + '360_days' => $this->get_weeks_in_period( 360 ), |
|
89 | + ); |
|
90 | + |
|
91 | + $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels[ '7_days' ]; |
|
92 | + return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Retrieves report datasets. |
|
97 | + * |
|
98 | + */ |
|
99 | + public function get_datasets( $labels ) { |
|
100 | + |
|
101 | + $datasets = array(); |
|
102 | + |
|
103 | + foreach ( $this->get_graphs() as $key => $label ) { |
|
104 | + $datasets[ $key ] = array( |
|
105 | + 'label' => $label, |
|
106 | + 'data' => $this->get_data( $key, $labels ) |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Retrieves report data. |
|
115 | + * |
|
116 | + */ |
|
117 | + public function get_data( $key, $labels ) { |
|
118 | + |
|
119 | + $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
120 | + $prepared = array(); |
|
121 | + |
|
122 | + foreach ( $labels as $label ) { |
|
123 | + |
|
124 | + $value = 0; |
|
125 | + if ( isset( $data[ $label ] ) ) { |
|
126 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
127 | + } |
|
128 | + |
|
129 | + $prepared[] = $value; |
|
130 | + } |
|
131 | + |
|
132 | + return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
133 | + |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Displays the report card. |
|
138 | + * |
|
139 | + */ |
|
140 | + public function display() { |
|
141 | + |
|
142 | + $labels = $this->get_labels( $this->get_range() ); |
|
143 | + $chart_data = array( |
|
144 | + 'labels' => array_values( $labels ), |
|
145 | + 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
146 | + ); |
|
147 | + |
|
148 | + ?> |
|
149 | 149 | |
150 | 150 | <?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?> |
151 | 151 | <div class="row mb-4"> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | |
166 | 166 | <?php |
167 | 167 | |
168 | - } |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Displays the actual report. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function display_graph( $key, $dataset, $labels ) { |
|
170 | + /** |
|
171 | + * Displays the actual report. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function display_graph( $key, $dataset, $labels ) { |
|
175 | 175 | |
176 | - ?> |
|
176 | + ?> |
|
177 | 177 | |
178 | 178 | <canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key( $key ); ?>"></canvas> |
179 | 179 | |
@@ -223,49 +223,49 @@ discard block |
||
223 | 223 | </script> |
224 | 224 | |
225 | 225 | <?php |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Displays the actual report. |
|
230 | - * |
|
231 | - */ |
|
232 | - public function display_stats() {} |
|
228 | + /** |
|
229 | + * Displays the actual report. |
|
230 | + * |
|
231 | + */ |
|
232 | + public function display_stats() {} |
|
233 | 233 | |
234 | - /** |
|
235 | - * Displays the range selector. |
|
236 | - * |
|
237 | - */ |
|
238 | - public function display_range_selector() { |
|
234 | + /** |
|
235 | + * Displays the range selector. |
|
236 | + * |
|
237 | + */ |
|
238 | + public function display_range_selector() { |
|
239 | 239 | |
240 | - ?> |
|
240 | + ?> |
|
241 | 241 | |
242 | 242 | <form method="get" class="getpaid-filter-earnings"> |
243 | 243 | <?php |
244 | 244 | |
245 | - getpaid_hidden_field( 'page', 'wpinv-reports' ); |
|
246 | - getpaid_hidden_field( 'tab', 'reports' ); |
|
247 | - |
|
248 | - $html = aui()->select( |
|
249 | - array( |
|
250 | - 'name' => 'date_range', |
|
251 | - 'id' => 'view' . uniqid( '_' ), |
|
252 | - 'placeholder' => __( 'Select a date range', 'invoicing' ), |
|
253 | - 'label' => __( 'Date Range', 'invoicing' ), |
|
254 | - 'options' => $this->get_periods(), |
|
255 | - 'value' => $this->get_range(), |
|
256 | - 'no_wrap' => true, |
|
257 | - 'extra_attributes' => array( |
|
258 | - 'onChange' => 'this.form.submit()', |
|
259 | - ), |
|
260 | - ) |
|
261 | - ); |
|
262 | - |
|
263 | - echo str_replace( 'custom-select', '', $html ); |
|
264 | - ?> |
|
245 | + getpaid_hidden_field( 'page', 'wpinv-reports' ); |
|
246 | + getpaid_hidden_field( 'tab', 'reports' ); |
|
247 | + |
|
248 | + $html = aui()->select( |
|
249 | + array( |
|
250 | + 'name' => 'date_range', |
|
251 | + 'id' => 'view' . uniqid( '_' ), |
|
252 | + 'placeholder' => __( 'Select a date range', 'invoicing' ), |
|
253 | + 'label' => __( 'Date Range', 'invoicing' ), |
|
254 | + 'options' => $this->get_periods(), |
|
255 | + 'value' => $this->get_range(), |
|
256 | + 'no_wrap' => true, |
|
257 | + 'extra_attributes' => array( |
|
258 | + 'onChange' => 'this.form.submit()', |
|
259 | + ), |
|
260 | + ) |
|
261 | + ); |
|
262 | + |
|
263 | + echo str_replace( 'custom-select', '', $html ); |
|
264 | + ?> |
|
265 | 265 | |
266 | 266 | </form> |
267 | 267 | |
268 | 268 | <?php |
269 | - } |
|
269 | + } |
|
270 | 270 | |
271 | 271 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report_Earnings Class. |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | |
21 | 21 | $graphs = array( |
22 | 22 | |
23 | - 'total' => __( 'Earnings', 'invoicing' ), |
|
24 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
25 | - 'fees_total' => __( 'Fees', 'invoicing' ), |
|
26 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
23 | + 'total' => __('Earnings', 'invoicing'), |
|
24 | + 'discount' => __('Discount', 'invoicing'), |
|
25 | + 'fees_total' => __('Fees', 'invoicing'), |
|
26 | + 'tax' => __('Tax', 'invoicing'), |
|
27 | 27 | |
28 | 28 | ); |
29 | 29 | |
30 | - return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
30 | + return apply_filters('getpaid_earning_graphs', $graphs); |
|
31 | 31 | |
32 | 32 | } |
33 | 33 | |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | * Retrieves the earning sql. |
36 | 36 | * |
37 | 37 | */ |
38 | - public function get_sql( $range ) { |
|
38 | + public function get_sql($range) { |
|
39 | 39 | global $wpdb; |
40 | 40 | |
41 | 41 | $table = $wpdb->prefix . 'getpaid_invoices'; |
42 | - $clauses = $this->get_range_sql( $range ); |
|
43 | - $graphs = array_keys( $this->get_graphs() ); |
|
42 | + $clauses = $this->get_range_sql($range); |
|
43 | + $graphs = array_keys($this->get_graphs()); |
|
44 | 44 | $graphs_sql = array(); |
45 | 45 | |
46 | - foreach ( $graphs as $graph ) { |
|
46 | + foreach ($graphs as $graph) { |
|
47 | 47 | $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
48 | 48 | } |
49 | 49 | |
50 | - $graphs_sql = implode( ', ', $graphs_sql ); |
|
50 | + $graphs_sql = implode(', ', $graphs_sql); |
|
51 | 51 | $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
52 | 52 | FROM $wpdb->posts |
53 | 53 | LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | GROUP BY {$clauses[0]} |
59 | 59 | "; |
60 | 60 | |
61 | - return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
61 | + return apply_filters('getpaid_earning_graphs_get_sql', $sql, $range); |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | |
@@ -68,68 +68,68 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function prepare_stats() { |
70 | 70 | global $wpdb; |
71 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
71 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Retrieves report labels. |
76 | 76 | * |
77 | 77 | */ |
78 | - public function get_labels( $range ) { |
|
78 | + public function get_labels($range) { |
|
79 | 79 | |
80 | 80 | $labels = array( |
81 | 81 | 'today' => $this->get_hours_in_a_day(), |
82 | 82 | 'yesterday' => $this->get_hours_in_a_day(), |
83 | - '7_days' => $this->get_days_in_period( 7 ), |
|
84 | - '30_days' => $this->get_days_in_period( 30 ), |
|
85 | - '60_days' => $this->get_days_in_period( 60 ), |
|
86 | - '90_days' => $this->get_weeks_in_period( 90 ), |
|
87 | - '180_days' => $this->get_weeks_in_period( 180 ), |
|
88 | - '360_days' => $this->get_weeks_in_period( 360 ), |
|
83 | + '7_days' => $this->get_days_in_period(7), |
|
84 | + '30_days' => $this->get_days_in_period(30), |
|
85 | + '60_days' => $this->get_days_in_period(60), |
|
86 | + '90_days' => $this->get_weeks_in_period(90), |
|
87 | + '180_days' => $this->get_weeks_in_period(180), |
|
88 | + '360_days' => $this->get_weeks_in_period(360), |
|
89 | 89 | ); |
90 | 90 | |
91 | - $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels[ '7_days' ]; |
|
92 | - return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
91 | + $label = isset($labels[$range]) ? $labels[$range] : $labels['7_days']; |
|
92 | + return apply_filters('getpaid_earning_graphs_get_labels', $label, $range); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Retrieves report datasets. |
97 | 97 | * |
98 | 98 | */ |
99 | - public function get_datasets( $labels ) { |
|
99 | + public function get_datasets($labels) { |
|
100 | 100 | |
101 | 101 | $datasets = array(); |
102 | 102 | |
103 | - foreach ( $this->get_graphs() as $key => $label ) { |
|
104 | - $datasets[ $key ] = array( |
|
103 | + foreach ($this->get_graphs() as $key => $label) { |
|
104 | + $datasets[$key] = array( |
|
105 | 105 | 'label' => $label, |
106 | - 'data' => $this->get_data( $key, $labels ) |
|
106 | + 'data' => $this->get_data($key, $labels) |
|
107 | 107 | ); |
108 | 108 | } |
109 | 109 | |
110 | - return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
110 | + return apply_filters('getpaid_earning_graphs_get_datasets', $datasets, $labels); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Retrieves report data. |
115 | 115 | * |
116 | 116 | */ |
117 | - public function get_data( $key, $labels ) { |
|
117 | + public function get_data($key, $labels) { |
|
118 | 118 | |
119 | - $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
119 | + $data = wp_list_pluck($this->stats, $key, 'completed_date'); |
|
120 | 120 | $prepared = array(); |
121 | 121 | |
122 | - foreach ( $labels as $label ) { |
|
122 | + foreach ($labels as $label) { |
|
123 | 123 | |
124 | 124 | $value = 0; |
125 | - if ( isset( $data[ $label ] ) ) { |
|
126 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
125 | + if (isset($data[$label])) { |
|
126 | + $value = wpinv_round_amount(wpinv_sanitize_amount($data[$label])); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $prepared[] = $value; |
130 | 130 | } |
131 | 131 | |
132 | - return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
132 | + return apply_filters('getpaid_earning_graphs_get_data', $prepared, $key, $labels); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function display() { |
141 | 141 | |
142 | - $labels = $this->get_labels( $this->get_range() ); |
|
142 | + $labels = $this->get_labels($this->get_range()); |
|
143 | 143 | $chart_data = array( |
144 | - 'labels' => array_values( $labels ), |
|
145 | - 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
144 | + 'labels' => array_values($labels), |
|
145 | + 'datasets' => $this->get_datasets(array_keys($labels)), |
|
146 | 146 | ); |
147 | 147 | |
148 | 148 | ?> |
149 | 149 | |
150 | - <?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?> |
|
150 | + <?php foreach ($chart_data['datasets'] as $key => $dataset) : ?> |
|
151 | 151 | <div class="row mb-4"> |
152 | 152 | <div class="col-12"> |
153 | 153 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | <?php $this->display_range_selector(); ?> |
157 | 157 | </div> |
158 | 158 | <div class="card-body"> |
159 | - <?php $this->display_graph( $key, $dataset, $chart_data['labels'] ); ?> |
|
159 | + <?php $this->display_graph($key, $dataset, $chart_data['labels']); ?> |
|
160 | 160 | </div> |
161 | 161 | </div> |
162 | 162 | </div> |
@@ -171,26 +171,26 @@ discard block |
||
171 | 171 | * Displays the actual report. |
172 | 172 | * |
173 | 173 | */ |
174 | - public function display_graph( $key, $dataset, $labels ) { |
|
174 | + public function display_graph($key, $dataset, $labels) { |
|
175 | 175 | |
176 | 176 | ?> |
177 | 177 | |
178 | - <canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key( $key ); ?>"></canvas> |
|
178 | + <canvas id="getpaid-chartjs-earnings-<?php echo sanitize_key($key); ?>"></canvas> |
|
179 | 179 | |
180 | 180 | <script> |
181 | 181 | window.addEventListener( 'DOMContentLoaded', function() { |
182 | 182 | |
183 | - var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo sanitize_key( $key ); ?>' ).getContext('2d'); |
|
183 | + var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo sanitize_key($key); ?>' ).getContext('2d'); |
|
184 | 184 | new Chart( |
185 | 185 | ctx, |
186 | 186 | { |
187 | 187 | type: 'line', |
188 | 188 | data: { |
189 | - 'labels': <?php echo wp_json_encode( $labels ); ?>, |
|
189 | + 'labels': <?php echo wp_json_encode($labels); ?>, |
|
190 | 190 | 'datasets': [ |
191 | 191 | { |
192 | - label: '<?php echo esc_attr( $dataset['label'] ); ?>', |
|
193 | - data: <?php echo wp_json_encode( $dataset['data'] ); ?>, |
|
192 | + label: '<?php echo esc_attr($dataset['label']); ?>', |
|
193 | + data: <?php echo wp_json_encode($dataset['data']); ?>, |
|
194 | 194 | backgroundColor: 'rgba(54, 162, 235, 0.1)', |
195 | 195 | borderColor: 'rgb(54, 162, 235)', |
196 | 196 | borderWidth: 4, |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | <form method="get" class="getpaid-filter-earnings"> |
243 | 243 | <?php |
244 | 244 | |
245 | - getpaid_hidden_field( 'page', 'wpinv-reports' ); |
|
246 | - getpaid_hidden_field( 'tab', 'reports' ); |
|
245 | + getpaid_hidden_field('page', 'wpinv-reports'); |
|
246 | + getpaid_hidden_field('tab', 'reports'); |
|
247 | 247 | |
248 | 248 | $html = aui()->select( |
249 | 249 | array( |
250 | 250 | 'name' => 'date_range', |
251 | - 'id' => 'view' . uniqid( '_' ), |
|
252 | - 'placeholder' => __( 'Select a date range', 'invoicing' ), |
|
253 | - 'label' => __( 'Date Range', 'invoicing' ), |
|
251 | + 'id' => 'view' . uniqid('_'), |
|
252 | + 'placeholder' => __('Select a date range', 'invoicing'), |
|
253 | + 'label' => __('Date Range', 'invoicing'), |
|
254 | 254 | 'options' => $this->get_periods(), |
255 | 255 | 'value' => $this->get_range(), |
256 | 256 | 'no_wrap' => true, |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | ) |
261 | 261 | ); |
262 | 262 | |
263 | - echo str_replace( 'custom-select', '', $html ); |
|
263 | + echo str_replace('custom-select', '', $html); |
|
264 | 264 | ?> |
265 | 265 | |
266 | 266 | </form> |
@@ -16,164 +16,164 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_MaxMind_Geolocation { |
18 | 18 | |
19 | - /** |
|
20 | - * The service responsible for interacting with the MaxMind database. |
|
21 | - * |
|
22 | - * @var GetPaid_MaxMind_Database_Service |
|
23 | - */ |
|
24 | - private $database_service; |
|
25 | - |
|
26 | - /** |
|
27 | - * Initialize the integration. |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - /** |
|
32 | - * Supports overriding the database service to be used. |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @return mixed|null The geolocation database service. |
|
36 | - */ |
|
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | - } |
|
41 | - |
|
42 | - // Bind to the scheduled updater action. |
|
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | - |
|
45 | - // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | - |
|
48 | - // Handle maxmind key updates. |
|
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get database service. |
|
55 | - * |
|
56 | - * @return GetPaid_MaxMind_Database_Service|null |
|
57 | - */ |
|
58 | - public function get_database_service() { |
|
59 | - return $this->database_service; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Checks to make sure that the license key is valid. |
|
64 | - * |
|
65 | - * @param string $license_key The new license key. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function handle_key_updates( $license_key ) { |
|
69 | - |
|
70 | - // Trim whitespaces and strip slashes. |
|
71 | - $license_key = trim( $license_key ); |
|
72 | - |
|
73 | - // Abort if the license key is empty or unchanged. |
|
74 | - if ( empty( $license_key ) ) { |
|
75 | - return $license_key; |
|
76 | - } |
|
77 | - |
|
78 | - // Abort if a database exists and the license key is unchaged. |
|
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | - return $license_key; |
|
81 | - } |
|
82 | - |
|
83 | - // Check the license key by attempting to download the Geolocation database. |
|
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | - return $license_key; |
|
88 | - } |
|
89 | - |
|
90 | - $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | - |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Updates the database used for geolocation queries. |
|
96 | - * |
|
97 | - * @param string $tmp_database_path Temporary database path. |
|
98 | - */ |
|
99 | - public function update_database( $tmp_database_path = null ) { |
|
100 | - |
|
101 | - // Allow us to easily interact with the filesystem. |
|
102 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
103 | - WP_Filesystem(); |
|
104 | - global $wp_filesystem; |
|
105 | - |
|
106 | - // Remove any existing archives to comply with the MaxMind TOS. |
|
107 | - $target_database_path = $this->database_service->get_database_path(); |
|
108 | - |
|
109 | - // If there's no database path, we can't store the database. |
|
110 | - if ( empty( $target_database_path ) ) { |
|
111 | - return; |
|
112 | - } |
|
113 | - |
|
114 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | - $wp_filesystem->delete( $target_database_path ); |
|
116 | - } |
|
117 | - |
|
118 | - // We can't download a database if there's no license key configured. |
|
119 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | - if ( empty( $license_key ) ) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - if ( empty( $tmp_database_path ) ) { |
|
125 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
126 | - } |
|
127 | - |
|
128 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
130 | - return; |
|
131 | - } |
|
132 | - |
|
133 | - // Move the new database into position. |
|
134 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
140 | - * |
|
141 | - * @param array $data Geolocation data. |
|
142 | - * @param string $ip_address The IP address to geolocate. |
|
143 | - * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
144 | - */ |
|
145 | - public function get_geolocation( $data, $ip_address ) { |
|
146 | - |
|
147 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
148 | - return $data; |
|
149 | - } |
|
150 | - |
|
151 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
152 | - |
|
153 | - return array( |
|
154 | - 'country' => $country_code, |
|
155 | - 'state' => '', |
|
156 | - 'city' => '', |
|
157 | - 'postcode' => '', |
|
158 | - ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Fetches the prefix for the MaxMind database file. |
|
164 | - * |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - private function get_database_prefix() { |
|
168 | - |
|
169 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
170 | - |
|
171 | - if ( empty( $prefix ) ) { |
|
172 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
174 | - } |
|
175 | - |
|
176 | - return $prefix; |
|
177 | - } |
|
19 | + /** |
|
20 | + * The service responsible for interacting with the MaxMind database. |
|
21 | + * |
|
22 | + * @var GetPaid_MaxMind_Database_Service |
|
23 | + */ |
|
24 | + private $database_service; |
|
25 | + |
|
26 | + /** |
|
27 | + * Initialize the integration. |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + /** |
|
32 | + * Supports overriding the database service to be used. |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @return mixed|null The geolocation database service. |
|
36 | + */ |
|
37 | + $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | + if ( null === $this->database_service ) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | + } |
|
41 | + |
|
42 | + // Bind to the scheduled updater action. |
|
43 | + add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | + |
|
45 | + // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | + add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | + |
|
48 | + // Handle maxmind key updates. |
|
49 | + add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get database service. |
|
55 | + * |
|
56 | + * @return GetPaid_MaxMind_Database_Service|null |
|
57 | + */ |
|
58 | + public function get_database_service() { |
|
59 | + return $this->database_service; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Checks to make sure that the license key is valid. |
|
64 | + * |
|
65 | + * @param string $license_key The new license key. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function handle_key_updates( $license_key ) { |
|
69 | + |
|
70 | + // Trim whitespaces and strip slashes. |
|
71 | + $license_key = trim( $license_key ); |
|
72 | + |
|
73 | + // Abort if the license key is empty or unchanged. |
|
74 | + if ( empty( $license_key ) ) { |
|
75 | + return $license_key; |
|
76 | + } |
|
77 | + |
|
78 | + // Abort if a database exists and the license key is unchaged. |
|
79 | + if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | + return $license_key; |
|
81 | + } |
|
82 | + |
|
83 | + // Check the license key by attempting to download the Geolocation database. |
|
84 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | + getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | + return $license_key; |
|
88 | + } |
|
89 | + |
|
90 | + $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | + |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Updates the database used for geolocation queries. |
|
96 | + * |
|
97 | + * @param string $tmp_database_path Temporary database path. |
|
98 | + */ |
|
99 | + public function update_database( $tmp_database_path = null ) { |
|
100 | + |
|
101 | + // Allow us to easily interact with the filesystem. |
|
102 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
103 | + WP_Filesystem(); |
|
104 | + global $wp_filesystem; |
|
105 | + |
|
106 | + // Remove any existing archives to comply with the MaxMind TOS. |
|
107 | + $target_database_path = $this->database_service->get_database_path(); |
|
108 | + |
|
109 | + // If there's no database path, we can't store the database. |
|
110 | + if ( empty( $target_database_path ) ) { |
|
111 | + return; |
|
112 | + } |
|
113 | + |
|
114 | + if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | + $wp_filesystem->delete( $target_database_path ); |
|
116 | + } |
|
117 | + |
|
118 | + // We can't download a database if there's no license key configured. |
|
119 | + $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | + if ( empty( $license_key ) ) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + if ( empty( $tmp_database_path ) ) { |
|
125 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
126 | + } |
|
127 | + |
|
128 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | + wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
130 | + return; |
|
131 | + } |
|
132 | + |
|
133 | + // Move the new database into position. |
|
134 | + $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | + $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
140 | + * |
|
141 | + * @param array $data Geolocation data. |
|
142 | + * @param string $ip_address The IP address to geolocate. |
|
143 | + * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
144 | + */ |
|
145 | + public function get_geolocation( $data, $ip_address ) { |
|
146 | + |
|
147 | + if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
148 | + return $data; |
|
149 | + } |
|
150 | + |
|
151 | + $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
152 | + |
|
153 | + return array( |
|
154 | + 'country' => $country_code, |
|
155 | + 'state' => '', |
|
156 | + 'city' => '', |
|
157 | + 'postcode' => '', |
|
158 | + ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Fetches the prefix for the MaxMind database file. |
|
164 | + * |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + private function get_database_prefix() { |
|
168 | + |
|
169 | + $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
170 | + |
|
171 | + if ( empty( $prefix ) ) { |
|
172 | + $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | + update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
174 | + } |
|
175 | + |
|
176 | + return $prefix; |
|
177 | + } |
|
178 | 178 | |
179 | 179 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Uses MaxMind for Geolocation |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | * @since 1.0.19 |
35 | 35 | * @return mixed|null The geolocation database service. |
36 | 36 | */ |
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
37 | + $this->database_service = apply_filters('getpaid_maxmind_geolocation_database_service', null); |
|
38 | + if (null === $this->database_service) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service($this->get_database_prefix()); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // Bind to the scheduled updater action. |
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
43 | + add_action('getpaid_update_geoip_databases', array($this, 'update_database')); |
|
44 | 44 | |
45 | 45 | // Bind to the geolocation filter for MaxMind database lookups. |
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
46 | + add_filter('getpaid_get_geolocation', array($this, 'get_geolocation'), 10, 2); |
|
47 | 47 | |
48 | 48 | // Handle maxmind key updates. |
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
49 | + add_filter('wpinv_settings_sanitize_maxmind_license_key', array($this, 'handle_key_updates')); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -65,29 +65,29 @@ discard block |
||
65 | 65 | * @param string $license_key The new license key. |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function handle_key_updates( $license_key ) { |
|
68 | + public function handle_key_updates($license_key) { |
|
69 | 69 | |
70 | 70 | // Trim whitespaces and strip slashes. |
71 | - $license_key = trim( $license_key ); |
|
71 | + $license_key = trim($license_key); |
|
72 | 72 | |
73 | 73 | // Abort if the license key is empty or unchanged. |
74 | - if ( empty( $license_key ) ) { |
|
74 | + if (empty($license_key)) { |
|
75 | 75 | return $license_key; |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Abort if a database exists and the license key is unchaged. |
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
79 | + if (file_exists($this->database_service->get_database_path() && $license_key == wpinv_get_option('maxmind_license_key'))) { |
|
80 | 80 | return $license_key; |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Check the license key by attempting to download the Geolocation database. |
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
84 | + $tmp_database_path = $this->database_service->download_database($license_key); |
|
85 | + if (is_wp_error($tmp_database_path)) { |
|
86 | + getpaid_admin()->show_error($tmp_database_path->get_error_message()); |
|
87 | 87 | return $license_key; |
88 | 88 | } |
89 | 89 | |
90 | - $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
90 | + $this->update_database(/** @scrutinizer ignore-type */ $tmp_database_path); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @param string $tmp_database_path Temporary database path. |
98 | 98 | */ |
99 | - public function update_database( $tmp_database_path = null ) { |
|
99 | + public function update_database($tmp_database_path = null) { |
|
100 | 100 | |
101 | 101 | // Allow us to easily interact with the filesystem. |
102 | 102 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
@@ -107,32 +107,32 @@ discard block |
||
107 | 107 | $target_database_path = $this->database_service->get_database_path(); |
108 | 108 | |
109 | 109 | // If there's no database path, we can't store the database. |
110 | - if ( empty( $target_database_path ) ) { |
|
110 | + if (empty($target_database_path)) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
115 | - $wp_filesystem->delete( $target_database_path ); |
|
114 | + if ($wp_filesystem->exists($target_database_path)) { |
|
115 | + $wp_filesystem->delete($target_database_path); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // We can't download a database if there's no license key configured. |
119 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
120 | - if ( empty( $license_key ) ) { |
|
119 | + $license_key = wpinv_get_option('maxmind_license_key'); |
|
120 | + if (empty($license_key)) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - if ( empty( $tmp_database_path ) ) { |
|
125 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
124 | + if (empty($tmp_database_path)) { |
|
125 | + $tmp_database_path = $this->database_service->download_database($license_key); |
|
126 | 126 | } |
127 | 127 | |
128 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
129 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
128 | + if (is_wp_error($tmp_database_path)) { |
|
129 | + wpinv_error_log($tmp_database_path->get_error_message()); |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | 133 | // Move the new database into position. |
134 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
135 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
134 | + $wp_filesystem->move($tmp_database_path, $target_database_path, true); |
|
135 | + $wp_filesystem->delete(dirname($tmp_database_path)); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | * @param string $ip_address The IP address to geolocate. |
143 | 143 | * @return array Geolocation including country code, state, city and postcode based on an IP address. |
144 | 144 | */ |
145 | - public function get_geolocation( $data, $ip_address ) { |
|
145 | + public function get_geolocation($data, $ip_address) { |
|
146 | 146 | |
147 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
147 | + if (!empty($data['country']) || empty($ip_address)) { |
|
148 | 148 | return $data; |
149 | 149 | } |
150 | 150 | |
151 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
151 | + $country_code = $this->database_service->get_iso_country_code_for_ip($ip_address); |
|
152 | 152 | |
153 | 153 | return array( |
154 | 154 | 'country' => $country_code, |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | */ |
167 | 167 | private function get_database_prefix() { |
168 | 168 | |
169 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
169 | + $prefix = get_option('wpinv_maxmind_database_prefix'); |
|
170 | 170 | |
171 | - if ( empty( $prefix ) ) { |
|
172 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
173 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
171 | + if (empty($prefix)) { |
|
172 | + $prefix = md5(uniqid('wpinv')); |
|
173 | + update_option('wpinv_maxmind_database_prefix', $prefix); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $prefix; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report_Items Class. |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | * Retrieves the earning sql. |
17 | 17 | * |
18 | 18 | */ |
19 | - public function get_sql( $range ) { |
|
19 | + public function get_sql($range) { |
|
20 | 20 | global $wpdb; |
21 | 21 | |
22 | 22 | $table = $wpdb->prefix . 'getpaid_invoices'; |
23 | - $clauses = $this->get_range_sql( $range ); |
|
23 | + $clauses = $this->get_range_sql($range); |
|
24 | 24 | |
25 | 25 | $sql = "SELECT |
26 | 26 | meta.gateway AS gateway, |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | ORDER BY total DESC |
36 | 36 | "; |
37 | 37 | |
38 | - return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
38 | + return apply_filters('getpaid_gateways_graphs_get_sql', $sql, $range); |
|
39 | 39 | |
40 | 40 | } |
41 | 41 | |
@@ -45,30 +45,30 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function prepare_stats() { |
47 | 47 | global $wpdb; |
48 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
49 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
48 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
49 | + $this->stats = $this->normalize_stats($this->stats); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Normalizes the report stats. |
54 | 54 | * |
55 | 55 | */ |
56 | - public function normalize_stats( $stats ) { |
|
56 | + public function normalize_stats($stats) { |
|
57 | 57 | $normalized = array(); |
58 | 58 | $others = 0; |
59 | 59 | $did = 0; |
60 | 60 | |
61 | - foreach ( $stats as $stat ) { |
|
61 | + foreach ($stats as $stat) { |
|
62 | 62 | |
63 | - if ( $did > 4 ) { |
|
63 | + if ($did > 4) { |
|
64 | 64 | |
65 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
65 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
66 | 66 | |
67 | 67 | } else { |
68 | 68 | |
69 | 69 | $normalized[] = array( |
70 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
71 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
70 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
71 | + 'gateway' => strip_tags(wpinv_get_gateway_admin_label($stat->gateway)), |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | $did++; |
77 | 77 | } |
78 | 78 | |
79 | - if ( $others > 0 ) { |
|
79 | + if ($others > 0) { |
|
80 | 80 | |
81 | 81 | $normalized[] = array( |
82 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
83 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
82 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
83 | + 'gateway' => esc_html__('Others', 'invoicing'), |
|
84 | 84 | ); |
85 | 85 | |
86 | 86 | } |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function get_data() { |
96 | 96 | |
97 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
98 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
97 | + $data = wp_list_pluck($this->stats, 'total'); |
|
98 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
99 | 99 | |
100 | - shuffle( $colors ); |
|
100 | + shuffle($colors); |
|
101 | 101 | |
102 | 102 | return array( |
103 | 103 | 'data' => $data, |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | */ |
113 | 113 | public function get_labels() { |
114 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
114 | + return wp_list_pluck($this->stats, 'gateway'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | { |
133 | 133 | type: 'doughnut', |
134 | 134 | data: { |
135 | - 'labels': <?php echo wp_json_encode( $this->get_labels() ); ?>, |
|
136 | - 'datasets': [ <?php echo wp_json_encode( $this->get_data() ); ?> ] |
|
135 | + 'labels': <?php echo wp_json_encode($this->get_labels()); ?>, |
|
136 | + 'datasets': [ <?php echo wp_json_encode($this->get_data()); ?> ] |
|
137 | 137 | }, |
138 | 138 | options: { |
139 | 139 | legend: { |
@@ -12,22 +12,22 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Gateways extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $field = 'gateway'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Retrieves the earning sql. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function get_sql( $range ) { |
|
25 | - global $wpdb; |
|
26 | - |
|
27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | - $clauses = $this->get_range_sql( $range ); |
|
29 | - |
|
30 | - $sql = "SELECT |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $field = 'gateway'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Retrieves the earning sql. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function get_sql( $range ) { |
|
25 | + global $wpdb; |
|
26 | + |
|
27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | + $clauses = $this->get_range_sql( $range ); |
|
29 | + |
|
30 | + $sql = "SELECT |
|
31 | 31 | meta.gateway AS gateway, |
32 | 32 | SUM(total) as total |
33 | 33 | FROM $wpdb->posts |
@@ -40,91 +40,91 @@ discard block |
||
40 | 40 | ORDER BY total DESC |
41 | 41 | "; |
42 | 42 | |
43 | - return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
43 | + return apply_filters( 'getpaid_gateways_graphs_get_sql', $sql, $range ); |
|
44 | 44 | |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Prepares the report stats. |
|
49 | - * |
|
50 | - */ |
|
51 | - public function prepare_stats() { |
|
52 | - global $wpdb; |
|
53 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
54 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
55 | - } |
|
47 | + /** |
|
48 | + * Prepares the report stats. |
|
49 | + * |
|
50 | + */ |
|
51 | + public function prepare_stats() { |
|
52 | + global $wpdb; |
|
53 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
54 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Normalizes the report stats. |
|
59 | - * |
|
60 | - */ |
|
61 | - public function normalize_stats( $stats ) { |
|
62 | - $normalized = array(); |
|
63 | - $others = 0; |
|
64 | - $did = 0; |
|
57 | + /** |
|
58 | + * Normalizes the report stats. |
|
59 | + * |
|
60 | + */ |
|
61 | + public function normalize_stats( $stats ) { |
|
62 | + $normalized = array(); |
|
63 | + $others = 0; |
|
64 | + $did = 0; |
|
65 | 65 | |
66 | - foreach ( $stats as $stat ) { |
|
66 | + foreach ( $stats as $stat ) { |
|
67 | 67 | |
68 | - if ( $did > 4 ) { |
|
68 | + if ( $did > 4 ) { |
|
69 | 69 | |
70 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
70 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
71 | 71 | |
72 | - } else { |
|
72 | + } else { |
|
73 | 73 | |
74 | - $normalized[] = array( |
|
75 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
76 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
77 | - ); |
|
74 | + $normalized[] = array( |
|
75 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
76 | + 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
77 | + ); |
|
78 | 78 | |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - $did++; |
|
82 | - } |
|
81 | + $did++; |
|
82 | + } |
|
83 | 83 | |
84 | - if ( $others > 0 ) { |
|
84 | + if ( $others > 0 ) { |
|
85 | 85 | |
86 | - $normalized[] = array( |
|
87 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
88 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
89 | - ); |
|
86 | + $normalized[] = array( |
|
87 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
88 | + 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
89 | + ); |
|
90 | 90 | |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - return $normalized; |
|
94 | - } |
|
93 | + return $normalized; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Retrieves report data. |
|
98 | - * |
|
99 | - */ |
|
100 | - public function get_data() { |
|
96 | + /** |
|
97 | + * Retrieves report data. |
|
98 | + * |
|
99 | + */ |
|
100 | + public function get_data() { |
|
101 | 101 | |
102 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
103 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
102 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
103 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
104 | 104 | |
105 | - shuffle( $colors ); |
|
105 | + shuffle( $colors ); |
|
106 | 106 | |
107 | - return array( |
|
108 | - 'data' => $data, |
|
109 | - 'backgroundColor' => $colors, |
|
110 | - ); |
|
107 | + return array( |
|
108 | + 'data' => $data, |
|
109 | + 'backgroundColor' => $colors, |
|
110 | + ); |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Retrieves report labels. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function get_labels() { |
|
119 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
120 | - } |
|
114 | + /** |
|
115 | + * Retrieves report labels. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function get_labels() { |
|
119 | + return wp_list_pluck( $this->stats, 'gateway' ); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Displays the actual report. |
|
124 | - * |
|
125 | - */ |
|
126 | - public function display_stats() { |
|
127 | - ?> |
|
122 | + /** |
|
123 | + * Displays the actual report. |
|
124 | + * |
|
125 | + */ |
|
126 | + public function display_stats() { |
|
127 | + ?> |
|
128 | 128 | |
129 | 129 | <canvas id="getpaid-chartjs-earnings-gateways"></canvas> |
130 | 130 | |
@@ -153,6 +153,6 @@ discard block |
||
153 | 153 | </script> |
154 | 154 | |
155 | 155 | <?php |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report_Discounts Class. |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | * Retrieves the discounts sql. |
17 | 17 | * |
18 | 18 | */ |
19 | - public function get_sql( $range ) { |
|
19 | + public function get_sql($range) { |
|
20 | 20 | global $wpdb; |
21 | 21 | |
22 | 22 | $table = $wpdb->prefix . 'getpaid_invoices'; |
23 | - $clauses = $this->get_range_sql( $range ); |
|
23 | + $clauses = $this->get_range_sql($range); |
|
24 | 24 | |
25 | 25 | $sql = "SELECT |
26 | 26 | meta.discount_code AS discount_code, |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | ORDER BY total DESC |
37 | 37 | "; |
38 | 38 | |
39 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
39 | + return apply_filters('getpaid_discounts_graphs_get_sql', $sql, $range); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -46,30 +46,30 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function prepare_stats() { |
48 | 48 | global $wpdb; |
49 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
50 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
49 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
50 | + $this->stats = $this->normalize_stats($this->stats); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Normalizes the report stats. |
55 | 55 | * |
56 | 56 | */ |
57 | - public function normalize_stats( $stats ) { |
|
57 | + public function normalize_stats($stats) { |
|
58 | 58 | $normalized = array(); |
59 | 59 | $others = 0; |
60 | 60 | $did = 0; |
61 | 61 | |
62 | - foreach ( $stats as $stat ) { |
|
62 | + foreach ($stats as $stat) { |
|
63 | 63 | |
64 | - if ( $did > 4 ) { |
|
64 | + if ($did > 4) { |
|
65 | 65 | |
66 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
66 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
67 | 67 | |
68 | 68 | } else { |
69 | 69 | |
70 | 70 | $normalized[] = array( |
71 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
72 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
71 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
72 | + 'discount_code' => strip_tags($stat->discount_code), |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | } |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | $did++; |
78 | 78 | } |
79 | 79 | |
80 | - if ( $others > 0 ) { |
|
80 | + if ($others > 0) { |
|
81 | 81 | |
82 | 82 | $normalized[] = array( |
83 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
84 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
83 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
84 | + 'discount_code' => esc_html__('Others', 'invoicing'), |
|
85 | 85 | ); |
86 | 86 | |
87 | 87 | } |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function get_data() { |
97 | 97 | |
98 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
99 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
98 | + $data = wp_list_pluck($this->stats, 'total'); |
|
99 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
100 | 100 | |
101 | - shuffle( $colors ); |
|
101 | + shuffle($colors); |
|
102 | 102 | |
103 | 103 | return array( |
104 | 104 | 'data' => $data, |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * |
113 | 113 | */ |
114 | 114 | public function get_labels() { |
115 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
115 | + return wp_list_pluck($this->stats, 'discount_code'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | { |
134 | 134 | type: 'doughnut', |
135 | 135 | data: { |
136 | - 'labels': <?php echo wp_json_encode( $this->get_labels() ); ?>, |
|
137 | - 'datasets': [ <?php echo wp_json_encode( $this->get_data() ); ?> ] |
|
136 | + 'labels': <?php echo wp_json_encode($this->get_labels()); ?>, |
|
137 | + 'datasets': [ <?php echo wp_json_encode($this->get_data()); ?> ] |
|
138 | 138 | }, |
139 | 139 | options: { |
140 | 140 | legend: { |
@@ -12,22 +12,22 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Discounts extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $field = 'discount_code'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Retrieves the discounts sql. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function get_sql( $range ) { |
|
25 | - global $wpdb; |
|
26 | - |
|
27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | - $clauses = $this->get_range_sql( $range ); |
|
29 | - |
|
30 | - $sql = "SELECT |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $field = 'discount_code'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Retrieves the discounts sql. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function get_sql( $range ) { |
|
25 | + global $wpdb; |
|
26 | + |
|
27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | + $clauses = $this->get_range_sql( $range ); |
|
29 | + |
|
30 | + $sql = "SELECT |
|
31 | 31 | meta.discount_code AS discount_code, |
32 | 32 | SUM(total) as total |
33 | 33 | FROM $wpdb->posts |
@@ -41,91 +41,91 @@ discard block |
||
41 | 41 | ORDER BY total DESC |
42 | 42 | "; |
43 | 43 | |
44 | - return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
44 | + return apply_filters( 'getpaid_discounts_graphs_get_sql', $sql, $range ); |
|
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Prepares the report stats. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function prepare_stats() { |
|
53 | - global $wpdb; |
|
54 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
55 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
56 | - } |
|
48 | + /** |
|
49 | + * Prepares the report stats. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function prepare_stats() { |
|
53 | + global $wpdb; |
|
54 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
55 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Normalizes the report stats. |
|
60 | - * |
|
61 | - */ |
|
62 | - public function normalize_stats( $stats ) { |
|
63 | - $normalized = array(); |
|
64 | - $others = 0; |
|
65 | - $did = 0; |
|
58 | + /** |
|
59 | + * Normalizes the report stats. |
|
60 | + * |
|
61 | + */ |
|
62 | + public function normalize_stats( $stats ) { |
|
63 | + $normalized = array(); |
|
64 | + $others = 0; |
|
65 | + $did = 0; |
|
66 | 66 | |
67 | - foreach ( $stats as $stat ) { |
|
67 | + foreach ( $stats as $stat ) { |
|
68 | 68 | |
69 | - if ( $did > 4 ) { |
|
69 | + if ( $did > 4 ) { |
|
70 | 70 | |
71 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
71 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
72 | 72 | |
73 | - } else { |
|
73 | + } else { |
|
74 | 74 | |
75 | - $normalized[] = array( |
|
76 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
77 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
78 | - ); |
|
75 | + $normalized[] = array( |
|
76 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
77 | + 'discount_code' => strip_tags( $stat->discount_code ), |
|
78 | + ); |
|
79 | 79 | |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - $did++; |
|
83 | - } |
|
82 | + $did++; |
|
83 | + } |
|
84 | 84 | |
85 | - if ( $others > 0 ) { |
|
85 | + if ( $others > 0 ) { |
|
86 | 86 | |
87 | - $normalized[] = array( |
|
88 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
89 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
90 | - ); |
|
87 | + $normalized[] = array( |
|
88 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
89 | + 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
90 | + ); |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - return $normalized; |
|
95 | - } |
|
94 | + return $normalized; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Retrieves report data. |
|
99 | - * |
|
100 | - */ |
|
101 | - public function get_data() { |
|
97 | + /** |
|
98 | + * Retrieves report data. |
|
99 | + * |
|
100 | + */ |
|
101 | + public function get_data() { |
|
102 | 102 | |
103 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
104 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
103 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
104 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
105 | 105 | |
106 | - shuffle( $colors ); |
|
106 | + shuffle( $colors ); |
|
107 | 107 | |
108 | - return array( |
|
109 | - 'data' => $data, |
|
110 | - 'backgroundColor' => $colors, |
|
111 | - ); |
|
108 | + return array( |
|
109 | + 'data' => $data, |
|
110 | + 'backgroundColor' => $colors, |
|
111 | + ); |
|
112 | 112 | |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Retrieves report labels. |
|
117 | - * |
|
118 | - */ |
|
119 | - public function get_labels() { |
|
120 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
121 | - } |
|
115 | + /** |
|
116 | + * Retrieves report labels. |
|
117 | + * |
|
118 | + */ |
|
119 | + public function get_labels() { |
|
120 | + return wp_list_pluck( $this->stats, 'discount_code' ); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Displays the actual report. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function display_stats() { |
|
128 | - ?> |
|
123 | + /** |
|
124 | + * Displays the actual report. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function display_stats() { |
|
128 | + ?> |
|
129 | 129 | |
130 | 130 | <canvas id="getpaid-chartjs-earnings-discount_code"></canvas> |
131 | 131 | |
@@ -154,6 +154,6 @@ discard block |
||
154 | 154 | </script> |
155 | 155 | |
156 | 156 | <?php |
157 | - } |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Reports_Report_Items Class. |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | * Retrieves the earning sql. |
17 | 17 | * |
18 | 18 | */ |
19 | - public function get_sql( $range ) { |
|
19 | + public function get_sql($range) { |
|
20 | 20 | global $wpdb; |
21 | 21 | |
22 | 22 | $table = $wpdb->prefix . 'getpaid_invoices'; |
23 | 23 | $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
24 | - $clauses = $this->get_range_sql( $range ); |
|
24 | + $clauses = $this->get_range_sql($range); |
|
25 | 25 | |
26 | 26 | $sql = "SELECT |
27 | 27 | item.item_name AS item_name, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | ORDER BY total DESC |
39 | 39 | "; |
40 | 40 | |
41 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
41 | + return apply_filters('getpaid_items_graphs_get_sql', $sql, $range); |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | |
@@ -48,30 +48,30 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function prepare_stats() { |
50 | 50 | global $wpdb; |
51 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
52 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
51 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
52 | + $this->stats = $this->normalize_stats($this->stats); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Normalizes the report stats. |
57 | 57 | * |
58 | 58 | */ |
59 | - public function normalize_stats( $stats ) { |
|
59 | + public function normalize_stats($stats) { |
|
60 | 60 | $normalized = array(); |
61 | 61 | $others = 0; |
62 | 62 | $did = 0; |
63 | 63 | |
64 | - foreach ( $stats as $stat ) { |
|
64 | + foreach ($stats as $stat) { |
|
65 | 65 | |
66 | - if ( $did > 4 ) { |
|
66 | + if ($did > 4) { |
|
67 | 67 | |
68 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
68 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
69 | 69 | |
70 | 70 | } else { |
71 | 71 | |
72 | 72 | $normalized[] = array( |
73 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
74 | - 'item_name' => strip_tags( $stat->item_name ), |
|
73 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
74 | + 'item_name' => strip_tags($stat->item_name), |
|
75 | 75 | ); |
76 | 76 | |
77 | 77 | } |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | $did++; |
80 | 80 | } |
81 | 81 | |
82 | - if ( $others > 0 ) { |
|
82 | + if ($others > 0) { |
|
83 | 83 | |
84 | 84 | $normalized[] = array( |
85 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
86 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
85 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
86 | + 'item_name' => esc_html__('Others', 'invoicing'), |
|
87 | 87 | ); |
88 | 88 | |
89 | 89 | } |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function get_data() { |
99 | 99 | |
100 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
101 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
100 | + $data = wp_list_pluck($this->stats, 'total'); |
|
101 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
102 | 102 | |
103 | - shuffle( $colors ); |
|
103 | + shuffle($colors); |
|
104 | 104 | |
105 | 105 | return array( |
106 | 106 | 'data' => $data, |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | */ |
116 | 116 | public function get_labels() { |
117 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
117 | + return wp_list_pluck($this->stats, 'item_name'); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | { |
136 | 136 | type: 'doughnut', |
137 | 137 | data: { |
138 | - 'labels': <?php echo wp_json_encode( $this->get_labels() ); ?>, |
|
139 | - 'datasets': [ <?php echo wp_json_encode( $this->get_data() ); ?> ] |
|
138 | + 'labels': <?php echo wp_json_encode($this->get_labels()); ?>, |
|
139 | + 'datasets': [ <?php echo wp_json_encode($this->get_data()); ?> ] |
|
140 | 140 | }, |
141 | 141 | options: { |
142 | 142 | legend: { |
@@ -12,23 +12,23 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - public $field = 'item_name'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Retrieves the earning sql. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function get_sql( $range ) { |
|
25 | - global $wpdb; |
|
26 | - |
|
27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | - $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
29 | - $clauses = $this->get_range_sql( $range ); |
|
30 | - |
|
31 | - $sql = "SELECT |
|
15 | + /** |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + public $field = 'item_name'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Retrieves the earning sql. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function get_sql( $range ) { |
|
25 | + global $wpdb; |
|
26 | + |
|
27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
28 | + $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
29 | + $clauses = $this->get_range_sql( $range ); |
|
30 | + |
|
31 | + $sql = "SELECT |
|
32 | 32 | item.item_name AS item_name, |
33 | 33 | item.item_id AS item_id, |
34 | 34 | SUM(price) as total |
@@ -43,91 +43,91 @@ discard block |
||
43 | 43 | ORDER BY total DESC |
44 | 44 | "; |
45 | 45 | |
46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
46 | + return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
47 | 47 | |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Prepares the report stats. |
|
52 | - * |
|
53 | - */ |
|
54 | - public function prepare_stats() { |
|
55 | - global $wpdb; |
|
56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
58 | - } |
|
50 | + /** |
|
51 | + * Prepares the report stats. |
|
52 | + * |
|
53 | + */ |
|
54 | + public function prepare_stats() { |
|
55 | + global $wpdb; |
|
56 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
57 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Normalizes the report stats. |
|
62 | - * |
|
63 | - */ |
|
64 | - public function normalize_stats( $stats ) { |
|
65 | - $normalized = array(); |
|
66 | - $others = 0; |
|
67 | - $did = 0; |
|
60 | + /** |
|
61 | + * Normalizes the report stats. |
|
62 | + * |
|
63 | + */ |
|
64 | + public function normalize_stats( $stats ) { |
|
65 | + $normalized = array(); |
|
66 | + $others = 0; |
|
67 | + $did = 0; |
|
68 | 68 | |
69 | - foreach ( $stats as $stat ) { |
|
69 | + foreach ( $stats as $stat ) { |
|
70 | 70 | |
71 | - if ( $did > 4 ) { |
|
71 | + if ( $did > 4 ) { |
|
72 | 72 | |
73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
73 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
74 | 74 | |
75 | - } else { |
|
75 | + } else { |
|
76 | 76 | |
77 | - $normalized[] = array( |
|
78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
80 | - ); |
|
77 | + $normalized[] = array( |
|
78 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
79 | + 'item_name' => strip_tags( $stat->item_name ), |
|
80 | + ); |
|
81 | 81 | |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | - $did++; |
|
85 | - } |
|
84 | + $did++; |
|
85 | + } |
|
86 | 86 | |
87 | - if ( $others > 0 ) { |
|
87 | + if ( $others > 0 ) { |
|
88 | 88 | |
89 | - $normalized[] = array( |
|
90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
92 | - ); |
|
89 | + $normalized[] = array( |
|
90 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
91 | + 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
92 | + ); |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - return $normalized; |
|
97 | - } |
|
96 | + return $normalized; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Retrieves report data. |
|
101 | - * |
|
102 | - */ |
|
103 | - public function get_data() { |
|
99 | + /** |
|
100 | + * Retrieves report data. |
|
101 | + * |
|
102 | + */ |
|
103 | + public function get_data() { |
|
104 | 104 | |
105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
106 | - $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
105 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
106 | + $colors = array( '#009688','#4caf50','#8bc34a','#00bcd4','#03a9f4','#2196f3' ); |
|
107 | 107 | |
108 | - shuffle( $colors ); |
|
108 | + shuffle( $colors ); |
|
109 | 109 | |
110 | - return array( |
|
111 | - 'data' => $data, |
|
112 | - 'backgroundColor' => $colors, |
|
113 | - ); |
|
110 | + return array( |
|
111 | + 'data' => $data, |
|
112 | + 'backgroundColor' => $colors, |
|
113 | + ); |
|
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Retrieves report labels. |
|
119 | - * |
|
120 | - */ |
|
121 | - public function get_labels() { |
|
122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
123 | - } |
|
117 | + /** |
|
118 | + * Retrieves report labels. |
|
119 | + * |
|
120 | + */ |
|
121 | + public function get_labels() { |
|
122 | + return wp_list_pluck( $this->stats, 'item_name' ); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Displays the actual report. |
|
127 | - * |
|
128 | - */ |
|
129 | - public function display_stats() { |
|
130 | - ?> |
|
125 | + /** |
|
126 | + * Displays the actual report. |
|
127 | + * |
|
128 | + */ |
|
129 | + public function display_stats() { |
|
130 | + ?> |
|
131 | 131 | |
132 | 132 | <canvas id="getpaid-chartjs-earnings-items"></canvas> |
133 | 133 | |
@@ -156,6 +156,6 @@ discard block |
||
156 | 156 | </script> |
157 | 157 | |
158 | 158 | <?php |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | 161 | } |