@@ -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_Discounts Class. |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | * Retrieves the discounts sql. |
22 | 22 | * |
23 | 23 | */ |
24 | - public function get_sql( $range ) { |
|
24 | + public function get_sql($range) { |
|
25 | 25 | global $wpdb; |
26 | 26 | |
27 | 27 | $table = $wpdb->prefix . 'getpaid_invoices'; |
28 | - $clauses = $this->get_range_sql( $range ); |
|
28 | + $clauses = $this->get_range_sql($range); |
|
29 | 29 | |
30 | 30 | $sql = "SELECT |
31 | 31 | meta.discount_code AS discount_code, |
@@ -41,7 +41,7 @@ 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 | |
@@ -51,30 +51,30 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function prepare_stats() { |
53 | 53 | global $wpdb; |
54 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
55 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
54 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
55 | + $this->stats = $this->normalize_stats($this->stats); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Normalizes the report stats. |
60 | 60 | * |
61 | 61 | */ |
62 | - public function normalize_stats( $stats ) { |
|
62 | + public function normalize_stats($stats) { |
|
63 | 63 | $normalized = array(); |
64 | 64 | $others = 0; |
65 | 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 | 73 | } else { |
74 | 74 | |
75 | 75 | $normalized[] = array( |
76 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
77 | - 'discount_code' => strip_tags( $stat->discount_code ), |
|
76 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
77 | + 'discount_code' => strip_tags($stat->discount_code), |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | $did++; |
83 | 83 | } |
84 | 84 | |
85 | - if ( $others > 0 ) { |
|
85 | + if ($others > 0) { |
|
86 | 86 | |
87 | 87 | $normalized[] = array( |
88 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
89 | - 'discount_code' => esc_html__( 'Others', 'invoicing' ), |
|
88 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
89 | + 'discount_code' => esc_html__('Others', 'invoicing'), |
|
90 | 90 | ); |
91 | 91 | |
92 | 92 | } |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | */ |
101 | 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 | 108 | return array( |
109 | 109 | 'data' => $data, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * |
118 | 118 | */ |
119 | 119 | public function get_labels() { |
120 | - return wp_list_pluck( $this->stats, 'discount_code' ); |
|
120 | + return wp_list_pluck($this->stats, 'discount_code'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | { |
139 | 139 | type: 'doughnut', |
140 | 140 | data: { |
141 | - 'labels': <?php echo wp_json_encode( wpinv_clean( $this->get_labels() ) ); ?>, |
|
142 | - 'datasets': [ <?php echo wp_json_encode( wpinv_clean( $this->get_data() ) ); ?> ] |
|
141 | + 'labels': <?php echo wp_json_encode(wpinv_clean($this->get_labels())); ?>, |
|
142 | + 'datasets': [ <?php echo wp_json_encode(wpinv_clean($this->get_data())); ?> ] |
|
143 | 143 | }, |
144 | 144 | options: { |
145 | 145 | legend: { |
@@ -12,88 +12,88 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Report { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $views; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $views; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
30 | - 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | - ), |
|
29 | + 'label' => __( 'Items', 'invoicing' ), |
|
30 | + 'class' => 'GetPaid_Reports_Report_Items', |
|
31 | + ), |
|
32 | 32 | |
33 | - 'gateways' => array( |
|
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | - 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | - ), |
|
33 | + 'gateways' => array( |
|
34 | + 'label' => __( 'Payment Methods', 'invoicing' ), |
|
35 | + 'class' => 'GetPaid_Reports_Report_Gateways', |
|
36 | + ), |
|
37 | 37 | |
38 | - 'discounts' => array( |
|
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | - 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | - ), |
|
38 | + 'discounts' => array( |
|
39 | + 'label' => __( 'Discount Codes', 'invoicing' ), |
|
40 | + 'class' => 'GetPaid_Reports_Report_Discounts', |
|
41 | + ), |
|
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Retrieves the current range. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function get_range() { |
|
54 | - $valid_ranges = $this->get_periods(); |
|
55 | - |
|
56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57 | - return sanitize_key( $_GET['date_range'] ); |
|
58 | - } |
|
59 | - |
|
60 | - return '7_days'; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns an array of date ranges. |
|
65 | - * |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function get_periods() { |
|
69 | - |
|
70 | - $periods = array( |
|
71 | - 'today' => __( 'Today', 'invoicing' ), |
|
72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73 | - 'week' => __( 'This week', 'invoicing' ), |
|
74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76 | - 'month' => __( 'This month', 'invoicing' ), |
|
77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
81 | - 'year' => __( 'This year', 'invoicing' ), |
|
82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
84 | - ); |
|
85 | - |
|
86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Displays the range selector. |
|
91 | - * |
|
92 | - */ |
|
93 | - public function display_range_selector() { |
|
94 | - |
|
95 | - $range = $this->get_range(); |
|
96 | - ?> |
|
45 | + $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Retrieves the current range. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function get_range() { |
|
54 | + $valid_ranges = $this->get_periods(); |
|
55 | + |
|
56 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57 | + return sanitize_key( $_GET['date_range'] ); |
|
58 | + } |
|
59 | + |
|
60 | + return '7_days'; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns an array of date ranges. |
|
65 | + * |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function get_periods() { |
|
69 | + |
|
70 | + $periods = array( |
|
71 | + 'today' => __( 'Today', 'invoicing' ), |
|
72 | + 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73 | + 'week' => __( 'This week', 'invoicing' ), |
|
74 | + 'last_week' => __( 'Last week', 'invoicing' ), |
|
75 | + '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76 | + 'month' => __( 'This month', 'invoicing' ), |
|
77 | + 'last_month' => __( 'Last month', 'invoicing' ), |
|
78 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79 | + 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
80 | + 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
81 | + 'year' => __( 'This year', 'invoicing' ), |
|
82 | + 'last_year' => __( 'Last Year', 'invoicing' ), |
|
83 | + 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
84 | + ); |
|
85 | + |
|
86 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Displays the range selector. |
|
91 | + * |
|
92 | + */ |
|
93 | + public function display_range_selector() { |
|
94 | + |
|
95 | + $range = $this->get_range(); |
|
96 | + ?> |
|
97 | 97 | |
98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
99 | 99 | <?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' ); ?> |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | </form> |
116 | 116 | |
117 | 117 | <?php |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Displays the reports tab. |
|
122 | - * |
|
123 | - */ |
|
124 | - public function display() { |
|
125 | - ?> |
|
120 | + /** |
|
121 | + * Displays the reports tab. |
|
122 | + * |
|
123 | + */ |
|
124 | + public function display() { |
|
125 | + ?> |
|
126 | 126 | |
127 | 127 | <div class="mt-4"> |
128 | 128 | |
@@ -202,16 +202,16 @@ discard block |
||
202 | 202 | |
203 | 203 | <?php |
204 | 204 | |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Displays the left side. |
|
209 | - * |
|
210 | - */ |
|
211 | - public function display_left() { |
|
212 | - $graphs = wpinv_get_report_graphs(); |
|
207 | + /** |
|
208 | + * Displays the left side. |
|
209 | + * |
|
210 | + */ |
|
211 | + public function display_left() { |
|
212 | + $graphs = wpinv_get_report_graphs(); |
|
213 | 213 | |
214 | - ?> |
|
214 | + ?> |
|
215 | 215 | |
216 | 216 | <?php foreach ( $graphs as $key => $graph ) : ?> |
217 | 217 | <div class="row mb-4"> |
@@ -230,35 +230,35 @@ discard block |
||
230 | 230 | |
231 | 231 | <?php |
232 | 232 | |
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Retrieves the download url. |
|
237 | - * |
|
238 | - */ |
|
239 | - public function get_download_url( $graph, $file_type ) { |
|
240 | - |
|
241 | - return wp_nonce_url( |
|
242 | - add_query_arg( |
|
243 | - array( |
|
244 | - 'getpaid-admin-action' => 'download_graph', |
|
245 | - 'file_type' => urlencode( $file_type ), |
|
246 | - 'graph' => urlencode( $graph ), |
|
247 | - ) |
|
248 | - ), |
|
249 | - 'getpaid-nonce', |
|
250 | - 'getpaid-nonce' |
|
251 | - ); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Retrieves the download url. |
|
237 | + * |
|
238 | + */ |
|
239 | + public function get_download_url( $graph, $file_type ) { |
|
240 | + |
|
241 | + return wp_nonce_url( |
|
242 | + add_query_arg( |
|
243 | + array( |
|
244 | + 'getpaid-admin-action' => 'download_graph', |
|
245 | + 'file_type' => urlencode( $file_type ), |
|
246 | + 'graph' => urlencode( $graph ), |
|
247 | + ) |
|
248 | + ), |
|
249 | + 'getpaid-nonce', |
|
250 | + 'getpaid-nonce' |
|
251 | + ); |
|
252 | 252 | |
253 | - } |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Displays the right side. |
|
257 | - * |
|
258 | - */ |
|
259 | - public function display_right() { |
|
255 | + /** |
|
256 | + * Displays the right side. |
|
257 | + * |
|
258 | + */ |
|
259 | + public function display_right() { |
|
260 | 260 | |
261 | - ?> |
|
261 | + ?> |
|
262 | 262 | |
263 | 263 | <?php foreach ( $this->views as $key => $view ) : ?> |
264 | 264 | <div class="row mb-4"> |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | </div> |
288 | 288 | <div class="card-body"> |
289 | 289 | <?php |
290 | - $class = $view['class']; |
|
291 | - $class = new $class(); |
|
292 | - $class->display_stats(); |
|
293 | - ?> |
|
290 | + $class = $view['class']; |
|
291 | + $class = new $class(); |
|
292 | + $class->display_stats(); |
|
293 | + ?> |
|
294 | 294 | </div> |
295 | 295 | </div> |
296 | 296 | </div> |
@@ -299,68 +299,68 @@ discard block |
||
299 | 299 | |
300 | 300 | <?php |
301 | 301 | |
302 | - do_action( 'getpaid_reports_display_right', $this ); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Returns a list of report cards. |
|
307 | - * |
|
308 | - */ |
|
309 | - public function get_cards() { |
|
310 | - |
|
311 | - $cards = array( |
|
312 | - 'total_sales' => array( |
|
313 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
314 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
315 | - ), |
|
316 | - 'net_sales' => array( |
|
317 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
318 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
319 | - ), |
|
320 | - 'average_sales' => array( |
|
321 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
322 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
323 | - ), |
|
324 | - 'average_total_sales' => array( |
|
325 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
326 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
327 | - ), |
|
328 | - 'total_invoices' => array( |
|
329 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
330 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
331 | - ), |
|
332 | - 'total_items' => array( |
|
333 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
334 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
335 | - ), |
|
336 | - 'refunded_items' => array( |
|
337 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
338 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
339 | - ), |
|
340 | - 'total_tax' => array( |
|
341 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
342 | - 'label' => __( 'Tax', 'invoicing' ), |
|
343 | - ), |
|
344 | - 'total_refunded_tax' => array( |
|
345 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
346 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
347 | - ), |
|
348 | - 'total_fees' => array( |
|
349 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
350 | - 'label' => __( 'Fees', 'invoicing' ), |
|
351 | - ), |
|
352 | - 'total_refunds' => array( |
|
353 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
354 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
355 | - ), |
|
356 | - 'total_discount' => array( |
|
357 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
358 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
359 | - ), |
|
360 | - ); |
|
361 | - |
|
362 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
363 | - } |
|
302 | + do_action( 'getpaid_reports_display_right', $this ); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Returns a list of report cards. |
|
307 | + * |
|
308 | + */ |
|
309 | + public function get_cards() { |
|
310 | + |
|
311 | + $cards = array( |
|
312 | + 'total_sales' => array( |
|
313 | + 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
314 | + 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
315 | + ), |
|
316 | + 'net_sales' => array( |
|
317 | + 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
318 | + 'label' => __( 'Net Revenue', 'invoicing' ), |
|
319 | + ), |
|
320 | + 'average_sales' => array( |
|
321 | + 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
322 | + 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
323 | + ), |
|
324 | + 'average_total_sales' => array( |
|
325 | + 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
326 | + 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
327 | + ), |
|
328 | + 'total_invoices' => array( |
|
329 | + 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
330 | + 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
331 | + ), |
|
332 | + 'total_items' => array( |
|
333 | + 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
334 | + 'label' => __( 'Purchased Items', 'invoicing' ), |
|
335 | + ), |
|
336 | + 'refunded_items' => array( |
|
337 | + 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
338 | + 'label' => __( 'Refunded Items', 'invoicing' ), |
|
339 | + ), |
|
340 | + 'total_tax' => array( |
|
341 | + 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
342 | + 'label' => __( 'Tax', 'invoicing' ), |
|
343 | + ), |
|
344 | + 'total_refunded_tax' => array( |
|
345 | + 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
346 | + 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
347 | + ), |
|
348 | + 'total_fees' => array( |
|
349 | + 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
350 | + 'label' => __( 'Fees', 'invoicing' ), |
|
351 | + ), |
|
352 | + 'total_refunds' => array( |
|
353 | + 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
354 | + 'label' => __( 'Refunded', 'invoicing' ), |
|
355 | + ), |
|
356 | + 'total_discount' => array( |
|
357 | + 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
358 | + 'label' => __( 'Discounted', 'invoicing' ), |
|
359 | + ), |
|
360 | + ); |
|
361 | + |
|
362 | + return apply_filters( 'wpinv_report_cards', $cards ); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | 366 |
@@ -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 Class. |
@@ -23,26 +23,26 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | 25 | |
26 | - $this->views = array( |
|
26 | + $this->views = array( |
|
27 | 27 | |
28 | 28 | 'items' => array( |
29 | - 'label' => __( 'Items', 'invoicing' ), |
|
29 | + 'label' => __('Items', 'invoicing'), |
|
30 | 30 | 'class' => 'GetPaid_Reports_Report_Items', |
31 | 31 | ), |
32 | 32 | |
33 | 33 | 'gateways' => array( |
34 | - 'label' => __( 'Payment Methods', 'invoicing' ), |
|
34 | + 'label' => __('Payment Methods', 'invoicing'), |
|
35 | 35 | 'class' => 'GetPaid_Reports_Report_Gateways', |
36 | 36 | ), |
37 | 37 | |
38 | 38 | 'discounts' => array( |
39 | - 'label' => __( 'Discount Codes', 'invoicing' ), |
|
39 | + 'label' => __('Discount Codes', 'invoicing'), |
|
40 | 40 | 'class' => 'GetPaid_Reports_Report_Discounts', |
41 | 41 | ), |
42 | 42 | |
43 | 43 | ); |
44 | 44 | |
45 | - $this->views = apply_filters( 'wpinv_report_views', $this->views ); |
|
45 | + $this->views = apply_filters('wpinv_report_views', $this->views); |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | public function get_range() { |
54 | 54 | $valid_ranges = $this->get_periods(); |
55 | 55 | |
56 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
57 | - return sanitize_key( $_GET['date_range'] ); |
|
56 | + if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) { |
|
57 | + return sanitize_key($_GET['date_range']); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return '7_days'; |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | public function get_periods() { |
69 | 69 | |
70 | 70 | $periods = array( |
71 | - 'today' => __( 'Today', 'invoicing' ), |
|
72 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
73 | - 'week' => __( 'This week', 'invoicing' ), |
|
74 | - 'last_week' => __( 'Last week', 'invoicing' ), |
|
75 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
76 | - 'month' => __( 'This month', 'invoicing' ), |
|
77 | - 'last_month' => __( 'Last month', 'invoicing' ), |
|
78 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
79 | - 'quarter' => __( 'This Quarter', 'invoicing' ), |
|
80 | - 'last_quarter' => __( 'Last Quarter', 'invoicing' ), |
|
81 | - 'year' => __( 'This year', 'invoicing' ), |
|
82 | - 'last_year' => __( 'Last Year', 'invoicing' ), |
|
83 | - 'custom' => __( 'Custom Date Range', 'invoicing' ), |
|
71 | + 'today' => __('Today', 'invoicing'), |
|
72 | + 'yesterday' => __('Yesterday', 'invoicing'), |
|
73 | + 'week' => __('This week', 'invoicing'), |
|
74 | + 'last_week' => __('Last week', 'invoicing'), |
|
75 | + '7_days' => __('Last 7 days', 'invoicing'), |
|
76 | + 'month' => __('This month', 'invoicing'), |
|
77 | + 'last_month' => __('Last month', 'invoicing'), |
|
78 | + '30_days' => __('Last 30 days', 'invoicing'), |
|
79 | + 'quarter' => __('This Quarter', 'invoicing'), |
|
80 | + 'last_quarter' => __('Last Quarter', 'invoicing'), |
|
81 | + 'year' => __('This year', 'invoicing'), |
|
82 | + 'last_year' => __('Last Year', 'invoicing'), |
|
83 | + 'custom' => __('Custom Date Range', 'invoicing'), |
|
84 | 84 | ); |
85 | 85 | |
86 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
86 | + return apply_filters('getpaid_earning_periods', $periods); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -96,21 +96,21 @@ discard block |
||
96 | 96 | ?> |
97 | 97 | |
98 | 98 | <form method="get" class="getpaid-filter-earnings float-right"> |
99 | - <?php getpaid_hidden_field( 'page', isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'wpinv-reports' ); ?> |
|
100 | - <?php getpaid_hidden_field( 'tab', 'reports' ); ?> |
|
99 | + <?php getpaid_hidden_field('page', isset($_GET['page']) ? sanitize_text_field($_GET['page']) : 'wpinv-reports'); ?> |
|
100 | + <?php getpaid_hidden_field('tab', 'reports'); ?> |
|
101 | 101 | <select name='date_range'> |
102 | - <?php foreach ( $this->get_periods() as $key => $label ) : ?> |
|
103 | - <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $range ); ?>><?php echo esc_html( $label ); ?></option> |
|
102 | + <?php foreach ($this->get_periods() as $key => $label) : ?> |
|
103 | + <option value="<?php echo esc_attr($key); ?>" <?php selected($key, $range); ?>><?php echo esc_html($label); ?></option> |
|
104 | 104 | <?php endforeach; ?> |
105 | 105 | </select> |
106 | 106 | <span class="getpaid-date-range-picker <?php echo 'custom' == $range ? '' : 'd-none'; ?>"> |
107 | 107 | <input type="text" name="from" class="getpaid-from align-middle" /> |
108 | - <?php esc_html_e( 'to', 'invoicing' ); ?> |
|
108 | + <?php esc_html_e('to', 'invoicing'); ?> |
|
109 | 109 | <input type="text" name="to" class="getpaid-to align-middle" /> |
110 | 110 | </span> |
111 | 111 | <button type="submit" class="button button-primary"> |
112 | 112 | <i class="fa fa-chevron-right fa-lg"></i> |
113 | - <span class="screen-reader-text"><?php esc_html_e( 'View Reports', 'invoicing' ); ?></span> |
|
113 | + <span class="screen-reader-text"><?php esc_html_e('View Reports', 'invoicing'); ?></span> |
|
114 | 114 | </button> |
115 | 115 | </form> |
116 | 116 | |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | |
160 | 160 | <div class="col-12 col-md-4"> |
161 | 161 | <div class="row getpaid-report-cards"> |
162 | - <?php foreach ( $this->get_cards() as $key => $card ) : ?> |
|
162 | + <?php foreach ($this->get_cards() as $key => $card) : ?> |
|
163 | 163 | <div class="col-12 mb-4"> |
164 | 164 | |
165 | - <!-- <?php echo esc_html( $card['label'] ); ?> Card --> |
|
166 | - <div class="card p-0 m-0 shadow-none <?php echo esc_attr( $key ); ?>"> |
|
165 | + <!-- <?php echo esc_html($card['label']); ?> Card --> |
|
166 | + <div class="card p-0 m-0 shadow-none <?php echo esc_attr($key); ?>"> |
|
167 | 167 | |
168 | 168 | <div class="card-body"> |
169 | 169 | |
170 | 170 | <p class="getpaid-current text-uppercase small mb-2"> |
171 | - <strong><?php echo esc_html( $card['label'] ); ?></strong> |
|
172 | - <span title="<?php echo esc_attr( $card['description'] ); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
171 | + <strong><?php echo esc_html($card['label']); ?></strong> |
|
172 | + <span title="<?php echo esc_attr($card['description']); ?>" class="wpi-help-tip dashicons dashicons-editor-help text-muted" style="margin-top: -2px;"></span> |
|
173 | 173 | </p> |
174 | 174 | <h5 class="font-weight-bold mb-0"> |
175 | 175 | <span class="getpaid-report-card-value"> |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | <hr> |
182 | 182 | |
183 | - <p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php esc_html_e( 'Previous Period', 'invoicing' ); ?></strong></p> |
|
183 | + <p class="getpaid-previous text-uppercase text-muted small mb-2"><strong><?php esc_html_e('Previous Period', 'invoicing'); ?></strong></p> |
|
184 | 184 | <h5 class="getpaid-report-card-previous-value font-weight-bold text-muted mb-0"> |
185 | 185 | <span class="spinner is-active float-none"></span> |
186 | 186 | </h5> |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | </div> |
189 | 189 | |
190 | 190 | </div> |
191 | - <!-- <?php echo esc_html( $card['label'] ); ?> Card --> |
|
191 | + <!-- <?php echo esc_html($card['label']); ?> Card --> |
|
192 | 192 | |
193 | 193 | </div> |
194 | 194 | <?php endforeach; ?> |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | |
214 | 214 | ?> |
215 | 215 | |
216 | - <?php foreach ( $graphs as $key => $graph ) : ?> |
|
216 | + <?php foreach ($graphs as $key => $graph) : ?> |
|
217 | 217 | <div class="row mb-4"> |
218 | 218 | <div class="col-12"> |
219 | 219 | <div class="card m-0 p-0 single-report-card" style="max-width:100%"> |
220 | 220 | <div class="card-header"> |
221 | - <strong><?php echo esc_html( $graph ); ?></strong> |
|
221 | + <strong><?php echo esc_html($graph); ?></strong> |
|
222 | 222 | </div> |
223 | 223 | <div class="card-body"> |
224 | - <canvas id="getpaid-chartjs-<?php echo esc_attr( $key ); ?>"></canvas> |
|
224 | + <canvas id="getpaid-chartjs-<?php echo esc_attr($key); ?>"></canvas> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | 227 | </div> |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | * Retrieves the download url. |
237 | 237 | * |
238 | 238 | */ |
239 | - public function get_download_url( $graph, $file_type ) { |
|
239 | + public function get_download_url($graph, $file_type) { |
|
240 | 240 | |
241 | 241 | return wp_nonce_url( |
242 | 242 | add_query_arg( |
243 | 243 | array( |
244 | 244 | 'getpaid-admin-action' => 'download_graph', |
245 | - 'file_type' => urlencode( $file_type ), |
|
246 | - 'graph' => urlencode( $graph ), |
|
245 | + 'file_type' => urlencode($file_type), |
|
246 | + 'graph' => urlencode($graph), |
|
247 | 247 | ) |
248 | 248 | ), |
249 | 249 | 'getpaid-nonce', |
@@ -260,27 +260,27 @@ discard block |
||
260 | 260 | |
261 | 261 | ?> |
262 | 262 | |
263 | - <?php foreach ( $this->views as $key => $view ) : ?> |
|
263 | + <?php foreach ($this->views as $key => $view) : ?> |
|
264 | 264 | <div class="row mb-4"> |
265 | 265 | <div class="col-12"> |
266 | 266 | <div class="card m-0 p-0" style="max-width:100%"> |
267 | 267 | <div class="card-header"> |
268 | 268 | <div class="row"> |
269 | - <div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-9' : 'col-12'; ?>"> |
|
270 | - <strong><?php echo esc_html( $view['label'] ); ?></strong> |
|
269 | + <div class="<?php echo empty($view['disable-downloads']) ? 'col-9' : 'col-12'; ?>"> |
|
270 | + <strong><?php echo esc_html($view['label']); ?></strong> |
|
271 | 271 | </div> |
272 | - <div class="<?php echo empty( $view['disable-downloads'] ) ? 'col-3' : 'd-none'; ?>"> |
|
273 | - <a title="<?php esc_attr_e( 'Download JSON', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'json' ) ); ?>"> |
|
272 | + <div class="<?php echo empty($view['disable-downloads']) ? 'col-3' : 'd-none'; ?>"> |
|
273 | + <a title="<?php esc_attr_e('Download JSON', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'json')); ?>"> |
|
274 | 274 | <i class="fa fa-download text-dark" style="font-size: 16px" aria-hidden="true"></i> |
275 | - <span class="screen-reader-text"><?php esc_html_e( 'Download JSON', 'invoicing' ); ?></span> |
|
275 | + <span class="screen-reader-text"><?php esc_html_e('Download JSON', 'invoicing'); ?></span> |
|
276 | 276 | </a> |
277 | - <a title="<?php esc_attr_e( 'Download CSV', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'csv' ) ); ?>"> |
|
277 | + <a title="<?php esc_attr_e('Download CSV', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'csv')); ?>"> |
|
278 | 278 | <i class="fa fa-file-csv text-dark" style="font-size: 16px" aria-hidden="true"></i> |
279 | - <span class="screen-reader-text"><?php esc_html_e( 'Download CSV', 'invoicing' ); ?></span> |
|
279 | + <span class="screen-reader-text"><?php esc_html_e('Download CSV', 'invoicing'); ?></span> |
|
280 | 280 | </a> |
281 | - <a title="<?php esc_attr_e( 'Download XML', 'invoicing' ); ?>" href="<?php echo esc_url( $this->get_download_url( $key, 'xml' ) ); ?>"> |
|
281 | + <a title="<?php esc_attr_e('Download XML', 'invoicing'); ?>" href="<?php echo esc_url($this->get_download_url($key, 'xml')); ?>"> |
|
282 | 282 | <i class="fa fa-file-code text-dark" style="font-size: 16px" aria-hidden="true"></i> |
283 | - <span class="screen-reader-text"><?php esc_html_e( 'Download XML', 'invoicing' ); ?></span> |
|
283 | + <span class="screen-reader-text"><?php esc_html_e('Download XML', 'invoicing'); ?></span> |
|
284 | 284 | </a> |
285 | 285 | </div> |
286 | 286 | </div> |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | |
300 | 300 | <?php |
301 | 301 | |
302 | - do_action( 'getpaid_reports_display_right', $this ); |
|
302 | + do_action('getpaid_reports_display_right', $this); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -310,56 +310,56 @@ discard block |
||
310 | 310 | |
311 | 311 | $cards = array( |
312 | 312 | 'total_sales' => array( |
313 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
314 | - 'label' => __( 'Gross Revenue', 'invoicing' ), |
|
313 | + 'description' => __('Gross sales in the period.', 'invoicing'), |
|
314 | + 'label' => __('Gross Revenue', 'invoicing'), |
|
315 | 315 | ), |
316 | 316 | 'net_sales' => array( |
317 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
318 | - 'label' => __( 'Net Revenue', 'invoicing' ), |
|
317 | + 'description' => __('Net sales in the period.', 'invoicing'), |
|
318 | + 'label' => __('Net Revenue', 'invoicing'), |
|
319 | 319 | ), |
320 | 320 | 'average_sales' => array( |
321 | - 'description' => __( 'Average net daily/monthly sales.', 'invoicing' ), |
|
322 | - 'label' => __( 'Avg. Net Sales', 'invoicing' ), |
|
321 | + 'description' => __('Average net daily/monthly sales.', 'invoicing'), |
|
322 | + 'label' => __('Avg. Net Sales', 'invoicing'), |
|
323 | 323 | ), |
324 | 324 | 'average_total_sales' => array( |
325 | - 'description' => __( 'Average gross daily/monthly sales.', 'invoicing' ), |
|
326 | - 'label' => __( 'Avg. Gross Sales', 'invoicing' ), |
|
325 | + 'description' => __('Average gross daily/monthly sales.', 'invoicing'), |
|
326 | + 'label' => __('Avg. Gross Sales', 'invoicing'), |
|
327 | 327 | ), |
328 | 328 | 'total_invoices' => array( |
329 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
330 | - 'label' => __( 'Paid Invoices', 'invoicing' ), |
|
329 | + 'description' => __('Number of paid invoices.', 'invoicing'), |
|
330 | + 'label' => __('Paid Invoices', 'invoicing'), |
|
331 | 331 | ), |
332 | 332 | 'total_items' => array( |
333 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
334 | - 'label' => __( 'Purchased Items', 'invoicing' ), |
|
333 | + 'description' => __('Number of items purchased.', 'invoicing'), |
|
334 | + 'label' => __('Purchased Items', 'invoicing'), |
|
335 | 335 | ), |
336 | 336 | 'refunded_items' => array( |
337 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
338 | - 'label' => __( 'Refunded Items', 'invoicing' ), |
|
337 | + 'description' => __('Number of items refunded.', 'invoicing'), |
|
338 | + 'label' => __('Refunded Items', 'invoicing'), |
|
339 | 339 | ), |
340 | 340 | 'total_tax' => array( |
341 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
342 | - 'label' => __( 'Tax', 'invoicing' ), |
|
341 | + 'description' => __('Total charged for taxes.', 'invoicing'), |
|
342 | + 'label' => __('Tax', 'invoicing'), |
|
343 | 343 | ), |
344 | 344 | 'total_refunded_tax' => array( |
345 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
346 | - 'label' => __( 'Refunded Tax', 'invoicing' ), |
|
345 | + 'description' => __('Total refunded for taxes.', 'invoicing'), |
|
346 | + 'label' => __('Refunded Tax', 'invoicing'), |
|
347 | 347 | ), |
348 | 348 | 'total_fees' => array( |
349 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
350 | - 'label' => __( 'Fees', 'invoicing' ), |
|
349 | + 'description' => __('Total fees charged.', 'invoicing'), |
|
350 | + 'label' => __('Fees', 'invoicing'), |
|
351 | 351 | ), |
352 | 352 | 'total_refunds' => array( |
353 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
354 | - 'label' => __( 'Refunded', 'invoicing' ), |
|
353 | + 'description' => __('Total of refunded invoices.', 'invoicing'), |
|
354 | + 'label' => __('Refunded', 'invoicing'), |
|
355 | 355 | ), |
356 | 356 | 'total_discount' => array( |
357 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
358 | - 'label' => __( 'Discounted', 'invoicing' ), |
|
357 | + 'description' => __('Total of discounts used.', 'invoicing'), |
|
358 | + 'label' => __('Discounted', 'invoicing'), |
|
359 | 359 | ), |
360 | 360 | ); |
361 | 361 | |
362 | - return apply_filters( 'wpinv_report_cards', $cards ); |
|
362 | + return apply_filters('wpinv_report_cards', $cards); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 |
@@ -12,176 +12,176 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves subscription query args. |
|
17 | - * |
|
18 | - * @param array $args Args to search for. |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function get_subscription_query_args( $args ) { |
|
22 | - |
|
23 | - $query_args = array( |
|
24 | - 'status' => 'all', |
|
25 | - 'number' => -1, |
|
26 | - 'count_total' => false, |
|
27 | - 'fields' => 'all', |
|
28 | - ); |
|
29 | - |
|
30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
32 | - } |
|
33 | - |
|
34 | - $date_query = array(); |
|
35 | - if ( ! empty( $args['to_date'] ) ) { |
|
36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
37 | - } |
|
38 | - |
|
39 | - if ( ! empty( $args['from_date'] ) ) { |
|
40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
41 | - } |
|
42 | - |
|
43 | - if ( ! empty( $date_query ) ) { |
|
44 | - $date_query['inclusive'] = true; |
|
45 | - $query_args['date_created_query'] = array( $date_query ); |
|
46 | - } |
|
47 | - |
|
48 | - return $query_args; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves subscriptions. |
|
53 | - * |
|
54 | - * @param array $query_args GetPaid_Subscriptions_Query args. |
|
55 | - * @return WPInv_Subscription[] |
|
56 | - */ |
|
57 | - public function get_subscriptions( $query_args ) { |
|
58 | - |
|
59 | - // Get subscriptions. |
|
60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
61 | - |
|
62 | - // Prepare the results. |
|
63 | - return $subscriptions->get_results(); |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Handles the actual download. |
|
69 | - * |
|
70 | - */ |
|
71 | - public function export( $post_type, $args ) { |
|
72 | - |
|
73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
74 | - $stream = $this->prepare_output(); |
|
75 | - $headers = $this->get_export_fields(); |
|
76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
77 | - |
|
78 | - if ( 'csv' == $file_type ) { |
|
79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | - } elseif ( 'xml' == $file_type ) { |
|
81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
82 | - } else { |
|
83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
84 | - } |
|
85 | - |
|
86 | - fclose( $stream ); |
|
87 | - exit; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Prepares a single subscription for download. |
|
92 | - * |
|
93 | - * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
94 | - * @param array $fields The fields to stream. |
|
95 | - * @since 1.0.19 |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function prepare_row( $subscription, $fields ) { |
|
99 | - |
|
100 | - $prepared = array(); |
|
101 | - $amount_fields = $this->get_amount_fields(); |
|
102 | - $invoice = $subscription->get_parent_payment(); |
|
103 | - |
|
104 | - foreach ( $fields as $field ) { |
|
105 | - |
|
106 | - $value = ''; |
|
107 | - $method = "get_$field"; |
|
108 | - |
|
109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } |
|
15 | + /** |
|
16 | + * Retrieves subscription query args. |
|
17 | + * |
|
18 | + * @param array $args Args to search for. |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function get_subscription_query_args( $args ) { |
|
22 | + |
|
23 | + $query_args = array( |
|
24 | + 'status' => 'all', |
|
25 | + 'number' => -1, |
|
26 | + 'count_total' => false, |
|
27 | + 'fields' => 'all', |
|
28 | + ); |
|
29 | + |
|
30 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | + $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
32 | + } |
|
33 | + |
|
34 | + $date_query = array(); |
|
35 | + if ( ! empty( $args['to_date'] ) ) { |
|
36 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
37 | + } |
|
38 | + |
|
39 | + if ( ! empty( $args['from_date'] ) ) { |
|
40 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
41 | + } |
|
42 | + |
|
43 | + if ( ! empty( $date_query ) ) { |
|
44 | + $date_query['inclusive'] = true; |
|
45 | + $query_args['date_created_query'] = array( $date_query ); |
|
46 | + } |
|
47 | + |
|
48 | + return $query_args; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves subscriptions. |
|
53 | + * |
|
54 | + * @param array $query_args GetPaid_Subscriptions_Query args. |
|
55 | + * @return WPInv_Subscription[] |
|
56 | + */ |
|
57 | + public function get_subscriptions( $query_args ) { |
|
58 | + |
|
59 | + // Get subscriptions. |
|
60 | + $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
61 | + |
|
62 | + // Prepare the results. |
|
63 | + return $subscriptions->get_results(); |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Handles the actual download. |
|
69 | + * |
|
70 | + */ |
|
71 | + public function export( $post_type, $args ) { |
|
72 | + |
|
73 | + $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
74 | + $stream = $this->prepare_output(); |
|
75 | + $headers = $this->get_export_fields(); |
|
76 | + $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
77 | + |
|
78 | + if ( 'csv' == $file_type ) { |
|
79 | + $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | + } elseif ( 'xml' == $file_type ) { |
|
81 | + $this->download_xml( $subscriptions, $stream, $headers ); |
|
82 | + } else { |
|
83 | + $this->download_json( $subscriptions, $stream, $headers ); |
|
84 | + } |
|
85 | + |
|
86 | + fclose( $stream ); |
|
87 | + exit; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Prepares a single subscription for download. |
|
92 | + * |
|
93 | + * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
94 | + * @param array $fields The fields to stream. |
|
95 | + * @since 1.0.19 |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function prepare_row( $subscription, $fields ) { |
|
99 | + |
|
100 | + $prepared = array(); |
|
101 | + $amount_fields = $this->get_amount_fields(); |
|
102 | + $invoice = $subscription->get_parent_payment(); |
|
103 | + |
|
104 | + foreach ( $fields as $field ) { |
|
105 | + |
|
106 | + $value = ''; |
|
107 | + $method = "get_$field"; |
|
108 | + |
|
109 | + if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } |
|
114 | 114 | } elseif ( method_exists( $subscription, $method ) ) { |
115 | - $value = $subscription->$method(); |
|
116 | - } |
|
117 | - |
|
118 | - if ( in_array( $field, $amount_fields ) ) { |
|
119 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
120 | - } |
|
121 | - |
|
122 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
123 | - |
|
124 | - } |
|
125 | - |
|
126 | - return $prepared; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Retrieves export fields. |
|
131 | - * |
|
132 | - * @since 1.0.19 |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_export_fields() { |
|
136 | - |
|
137 | - $fields = array( |
|
138 | - 'id', |
|
139 | - 'currency', |
|
140 | - 'initial_amount', |
|
141 | - 'recurring_amount', |
|
142 | - 'trial_period', |
|
143 | - 'frequency', |
|
144 | - 'period', |
|
145 | - 'bill_times', |
|
146 | - 'parent_payment_id', |
|
147 | - 'profile_id', |
|
148 | - 'product_id', |
|
149 | - 'status', |
|
150 | - 'date_created', |
|
151 | - 'date_expires', |
|
152 | - |
|
153 | - 'customer_id', |
|
154 | - 'customer_first_name', |
|
155 | - 'customer_last_name', |
|
156 | - 'customer_phone', |
|
157 | - 'customer_email', |
|
158 | - 'customer_country', |
|
159 | - 'customer_city', |
|
160 | - 'customer_state', |
|
161 | - 'customer_zip', |
|
162 | - 'customer_company', |
|
163 | - 'customer_vat_number', |
|
164 | - 'customer_address', |
|
165 | - |
|
166 | - ); |
|
167 | - |
|
168 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Retrieves amount fields. |
|
173 | - * |
|
174 | - * @since 1.0.19 |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - public function get_amount_fields() { |
|
178 | - |
|
179 | - $fields = array( |
|
180 | - 'initial_amount', |
|
181 | - 'recurring_amount', |
|
182 | - ); |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
185 | - } |
|
115 | + $value = $subscription->$method(); |
|
116 | + } |
|
117 | + |
|
118 | + if ( in_array( $field, $amount_fields ) ) { |
|
119 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
120 | + } |
|
121 | + |
|
122 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
123 | + |
|
124 | + } |
|
125 | + |
|
126 | + return $prepared; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Retrieves export fields. |
|
131 | + * |
|
132 | + * @since 1.0.19 |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_export_fields() { |
|
136 | + |
|
137 | + $fields = array( |
|
138 | + 'id', |
|
139 | + 'currency', |
|
140 | + 'initial_amount', |
|
141 | + 'recurring_amount', |
|
142 | + 'trial_period', |
|
143 | + 'frequency', |
|
144 | + 'period', |
|
145 | + 'bill_times', |
|
146 | + 'parent_payment_id', |
|
147 | + 'profile_id', |
|
148 | + 'product_id', |
|
149 | + 'status', |
|
150 | + 'date_created', |
|
151 | + 'date_expires', |
|
152 | + |
|
153 | + 'customer_id', |
|
154 | + 'customer_first_name', |
|
155 | + 'customer_last_name', |
|
156 | + 'customer_phone', |
|
157 | + 'customer_email', |
|
158 | + 'customer_country', |
|
159 | + 'customer_city', |
|
160 | + 'customer_state', |
|
161 | + 'customer_zip', |
|
162 | + 'customer_company', |
|
163 | + 'customer_vat_number', |
|
164 | + 'customer_address', |
|
165 | + |
|
166 | + ); |
|
167 | + |
|
168 | + return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Retrieves amount fields. |
|
173 | + * |
|
174 | + * @since 1.0.19 |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + public function get_amount_fields() { |
|
178 | + |
|
179 | + $fields = array( |
|
180 | + 'initial_amount', |
|
181 | + 'recurring_amount', |
|
182 | + ); |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | } |
@@ -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_Subscription_Exporter Class. |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param array $args Args to search for. |
19 | 19 | * @return array |
20 | 20 | */ |
21 | - public function get_subscription_query_args( $args ) { |
|
21 | + public function get_subscription_query_args($args) { |
|
22 | 22 | |
23 | 23 | $query_args = array( |
24 | 24 | 'status' => 'all', |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | 'fields' => 'all', |
28 | 28 | ); |
29 | 29 | |
30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
30 | + if (!empty($args['status']) && in_array($args['status'], array_keys(getpaid_get_subscription_statuses()), true)) { |
|
31 | + $query_args['status'] = wpinv_clean(wpinv_parse_list($args['status'])); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $date_query = array(); |
35 | - if ( ! empty( $args['to_date'] ) ) { |
|
36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
35 | + if (!empty($args['to_date'])) { |
|
36 | + $date_query['before'] = wpinv_clean($args['to_date']); |
|
37 | 37 | } |
38 | 38 | |
39 | - if ( ! empty( $args['from_date'] ) ) { |
|
40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
39 | + if (!empty($args['from_date'])) { |
|
40 | + $date_query['after'] = wpinv_clean($args['from_date']); |
|
41 | 41 | } |
42 | 42 | |
43 | - if ( ! empty( $date_query ) ) { |
|
43 | + if (!empty($date_query)) { |
|
44 | 44 | $date_query['inclusive'] = true; |
45 | - $query_args['date_created_query'] = array( $date_query ); |
|
45 | + $query_args['date_created_query'] = array($date_query); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return $query_args; |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @param array $query_args GetPaid_Subscriptions_Query args. |
55 | 55 | * @return WPInv_Subscription[] |
56 | 56 | */ |
57 | - public function get_subscriptions( $query_args ) { |
|
57 | + public function get_subscriptions($query_args) { |
|
58 | 58 | |
59 | 59 | // Get subscriptions. |
60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
60 | + $subscriptions = new GetPaid_Subscriptions_Query($query_args); |
|
61 | 61 | |
62 | 62 | // Prepare the results. |
63 | 63 | return $subscriptions->get_results(); |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | * Handles the actual download. |
69 | 69 | * |
70 | 70 | */ |
71 | - public function export( $post_type, $args ) { |
|
71 | + public function export($post_type, $args) { |
|
72 | 72 | |
73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
73 | + $subscriptions = $this->get_subscriptions($this->get_subscription_query_args($args)); |
|
74 | 74 | $stream = $this->prepare_output(); |
75 | 75 | $headers = $this->get_export_fields(); |
76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
76 | + $file_type = $this->prepare_file_type('subscriptions'); |
|
77 | 77 | |
78 | - if ( 'csv' == $file_type ) { |
|
79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | - } elseif ( 'xml' == $file_type ) { |
|
81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
78 | + if ('csv' == $file_type) { |
|
79 | + $this->download_csv($subscriptions, $stream, $headers); |
|
80 | + } elseif ('xml' == $file_type) { |
|
81 | + $this->download_xml($subscriptions, $stream, $headers); |
|
82 | 82 | } else { |
83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
83 | + $this->download_json($subscriptions, $stream, $headers); |
|
84 | 84 | } |
85 | 85 | |
86 | - fclose( $stream ); |
|
86 | + fclose($stream); |
|
87 | 87 | exit; |
88 | 88 | } |
89 | 89 | |
@@ -95,31 +95,31 @@ discard block |
||
95 | 95 | * @since 1.0.19 |
96 | 96 | * @return array |
97 | 97 | */ |
98 | - public function prepare_row( $subscription, $fields ) { |
|
98 | + public function prepare_row($subscription, $fields) { |
|
99 | 99 | |
100 | 100 | $prepared = array(); |
101 | 101 | $amount_fields = $this->get_amount_fields(); |
102 | 102 | $invoice = $subscription->get_parent_payment(); |
103 | 103 | |
104 | - foreach ( $fields as $field ) { |
|
104 | + foreach ($fields as $field) { |
|
105 | 105 | |
106 | 106 | $value = ''; |
107 | 107 | $method = "get_$field"; |
108 | 108 | |
109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
109 | + if (0 === stripos($field, 'customer') || 'currency' === $field) { |
|
110 | 110 | |
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
111 | + if (method_exists($invoice, $method)) { |
|
112 | + $value = $invoice->$method(); |
|
113 | 113 | } |
114 | -} elseif ( method_exists( $subscription, $method ) ) { |
|
115 | - $value = $subscription->$method(); |
|
114 | +} elseif (method_exists($subscription, $method)) { |
|
115 | + $value = $subscription->$method(); |
|
116 | 116 | } |
117 | 117 | |
118 | - if ( in_array( $field, $amount_fields ) ) { |
|
119 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
118 | + if (in_array($field, $amount_fields)) { |
|
119 | + $value = wpinv_round_amount(wpinv_sanitize_amount($value)); |
|
120 | 120 | } |
121 | 121 | |
122 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | + $prepared[$field] = wpinv_clean($value); |
|
123 | 123 | |
124 | 124 | } |
125 | 125 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | ); |
167 | 167 | |
168 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
168 | + return apply_filters('getpaid_subscription_exporter_get_fields', $fields); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | 'recurring_amount', |
182 | 182 | ); |
183 | 183 | |
184 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
184 | + return apply_filters('getpaid_subscription_exporter_get_amount_fields', $fields); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | } |
@@ -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_Items Class. |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | * Retrieves the earning sql. |
22 | 22 | * |
23 | 23 | */ |
24 | - public function get_sql( $range ) { |
|
24 | + public function get_sql($range) { |
|
25 | 25 | global $wpdb; |
26 | 26 | |
27 | 27 | $table = $wpdb->prefix . 'getpaid_invoices'; |
28 | - $clauses = $this->get_range_sql( $range ); |
|
28 | + $clauses = $this->get_range_sql($range); |
|
29 | 29 | |
30 | 30 | $sql = "SELECT |
31 | 31 | meta.gateway AS gateway, |
@@ -40,7 +40,7 @@ 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 | |
@@ -50,30 +50,30 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function prepare_stats() { |
52 | 52 | global $wpdb; |
53 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
54 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
53 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
54 | + $this->stats = $this->normalize_stats($this->stats); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Normalizes the report stats. |
59 | 59 | * |
60 | 60 | */ |
61 | - public function normalize_stats( $stats ) { |
|
61 | + public function normalize_stats($stats) { |
|
62 | 62 | $normalized = array(); |
63 | 63 | $others = 0; |
64 | 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 | 72 | } else { |
73 | 73 | |
74 | 74 | $normalized[] = array( |
75 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
76 | - 'gateway' => strip_tags( wpinv_get_gateway_admin_label( $stat->gateway ) ), |
|
75 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
76 | + 'gateway' => strip_tags(wpinv_get_gateway_admin_label($stat->gateway)), |
|
77 | 77 | ); |
78 | 78 | |
79 | 79 | } |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | $did++; |
82 | 82 | } |
83 | 83 | |
84 | - if ( $others > 0 ) { |
|
84 | + if ($others > 0) { |
|
85 | 85 | |
86 | 86 | $normalized[] = array( |
87 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
88 | - 'gateway' => esc_html__( 'Others', 'invoicing' ), |
|
87 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
88 | + 'gateway' => esc_html__('Others', 'invoicing'), |
|
89 | 89 | ); |
90 | 90 | |
91 | 91 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | */ |
100 | 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 | 107 | return array( |
108 | 108 | 'data' => $data, |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * |
117 | 117 | */ |
118 | 118 | public function get_labels() { |
119 | - return wp_list_pluck( $this->stats, 'gateway' ); |
|
119 | + return wp_list_pluck($this->stats, 'gateway'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | { |
138 | 138 | type: 'doughnut', |
139 | 139 | data: { |
140 | - 'labels': <?php echo wp_json_encode( wp_kses_post_deep( $this->get_labels() ) ); ?>, |
|
141 | - 'datasets': [ <?php echo wp_json_encode( wp_kses_post_deep( $this->get_data() ) ); ?> ] |
|
140 | + 'labels': <?php echo wp_json_encode(wp_kses_post_deep($this->get_labels())); ?>, |
|
141 | + 'datasets': [ <?php echo wp_json_encode(wp_kses_post_deep($this->get_data())); ?> ] |
|
142 | 142 | }, |
143 | 143 | options: { |
144 | 144 | legend: { |
@@ -13,261 +13,261 @@ |
||
13 | 13 | */ |
14 | 14 | class GetPaid_Geolocation { |
15 | 15 | |
16 | - /** |
|
17 | - * Holds the current user's IP Address. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public static $current_user_ip; |
|
22 | - |
|
23 | - /** |
|
24 | - * API endpoints for looking up a user IP address. |
|
25 | - * |
|
26 | - * For example, in case a user is on localhost. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected static $ip_lookup_apis = array( |
|
31 | - 'ipify' => 'http://api.ipify.org/', |
|
32 | - 'ipecho' => 'http://ipecho.net/plain', |
|
33 | - 'ident' => 'http://ident.me', |
|
34 | - 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * API endpoints for geolocating an IP address |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected static $geoip_apis = array( |
|
43 | - 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
44 | - 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Get current user IP Address. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public static function get_ip_address() { |
|
53 | - return wpinv_get_ip(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get user IP Address using an external service. |
|
58 | - * This can be used as a fallback for users on localhost where |
|
59 | - * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function get_external_ip_address() { |
|
64 | - |
|
65 | - $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | - |
|
67 | - if ( '' !== self::get_ip_address() ) { |
|
68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | - } |
|
70 | - |
|
71 | - // Try retrieving from cache. |
|
72 | - $external_ip_address = get_transient( $transient_name ); |
|
73 | - |
|
74 | - if ( false === $external_ip_address ) { |
|
75 | - $external_ip_address = '0.0.0.0'; |
|
76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | - shuffle( $ip_lookup_services_keys ); |
|
79 | - |
|
80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | - |
|
84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | - break; |
|
87 | - } |
|
16 | + /** |
|
17 | + * Holds the current user's IP Address. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public static $current_user_ip; |
|
22 | + |
|
23 | + /** |
|
24 | + * API endpoints for looking up a user IP address. |
|
25 | + * |
|
26 | + * For example, in case a user is on localhost. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected static $ip_lookup_apis = array( |
|
31 | + 'ipify' => 'http://api.ipify.org/', |
|
32 | + 'ipecho' => 'http://ipecho.net/plain', |
|
33 | + 'ident' => 'http://ident.me', |
|
34 | + 'whatismyipaddress' => 'http://bot.whatismyipaddress.com', |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * API endpoints for geolocating an IP address |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected static $geoip_apis = array( |
|
43 | + 'ip-api.com' => 'http://ip-api.com/json/%s', |
|
44 | + 'ipinfo.io' => 'https://ipinfo.io/%s/json', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Get current user IP Address. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public static function get_ip_address() { |
|
53 | + return wpinv_get_ip(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get user IP Address using an external service. |
|
58 | + * This can be used as a fallback for users on localhost where |
|
59 | + * get_ip_address() will be a local IP and non-geolocatable. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function get_external_ip_address() { |
|
64 | + |
|
65 | + $transient_name = 'external_ip_address_0.0.0.0'; |
|
66 | + |
|
67 | + if ( '' !== self::get_ip_address() ) { |
|
68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | + } |
|
70 | + |
|
71 | + // Try retrieving from cache. |
|
72 | + $external_ip_address = get_transient( $transient_name ); |
|
73 | + |
|
74 | + if ( false === $external_ip_address ) { |
|
75 | + $external_ip_address = '0.0.0.0'; |
|
76 | + $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | + $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | + shuffle( $ip_lookup_services_keys ); |
|
79 | + |
|
80 | + foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | + $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | + $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
83 | + |
|
84 | + if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | + $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
86 | + break; |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | |
90 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
91 | - } |
|
92 | - |
|
93 | - return $external_ip_address; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Geolocate an IP address. |
|
98 | - * |
|
99 | - * @param string $ip_address IP Address. |
|
100 | - * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
101 | - * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
105 | - |
|
106 | - if ( empty( $ip_address ) ) { |
|
107 | - $ip_address = self::get_ip_address(); |
|
108 | - } |
|
109 | - |
|
110 | - // Update the current user's IP Address. |
|
111 | - self::$current_user_ip = $ip_address; |
|
112 | - |
|
113 | - // Filter to allow custom geolocation of the IP address. |
|
114 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
115 | - |
|
116 | - if ( false !== $country_code ) { |
|
117 | - |
|
118 | - return array( |
|
119 | - 'country' => $country_code, |
|
120 | - 'state' => '', |
|
121 | - 'city' => '', |
|
122 | - 'postcode' => '', |
|
123 | - ); |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - $country_code = self::get_country_code_from_headers(); |
|
128 | - |
|
129 | - /** |
|
130 | - * Get geolocation filter. |
|
131 | - * |
|
132 | - * @since 1.0.19 |
|
133 | - * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
134 | - * @param string $ip_address IP Address. |
|
135 | - */ |
|
136 | - $geolocation = apply_filters( |
|
137 | - 'getpaid_get_geolocation', |
|
138 | - array( |
|
139 | - 'country' => $country_code, |
|
140 | - 'state' => '', |
|
141 | - 'city' => '', |
|
142 | - 'postcode' => '', |
|
143 | - ), |
|
144 | - $ip_address |
|
145 | - ); |
|
146 | - |
|
147 | - // If we still haven't found a country code, let's consider doing an API lookup. |
|
148 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
149 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
150 | - } |
|
151 | - |
|
152 | - // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
153 | - // external address. |
|
154 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
155 | - $external_ip_address = self::get_external_ip_address(); |
|
156 | - |
|
157 | - // Only bother with this if the external IP differs. |
|
158 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
159 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
160 | - } |
|
90 | + set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
91 | + } |
|
92 | + |
|
93 | + return $external_ip_address; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Geolocate an IP address. |
|
98 | + * |
|
99 | + * @param string $ip_address IP Address. |
|
100 | + * @param bool $fallback If true, fallbacks to alternative IP detection (can be slower). |
|
101 | + * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
105 | + |
|
106 | + if ( empty( $ip_address ) ) { |
|
107 | + $ip_address = self::get_ip_address(); |
|
108 | + } |
|
109 | + |
|
110 | + // Update the current user's IP Address. |
|
111 | + self::$current_user_ip = $ip_address; |
|
112 | + |
|
113 | + // Filter to allow custom geolocation of the IP address. |
|
114 | + $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
115 | + |
|
116 | + if ( false !== $country_code ) { |
|
117 | + |
|
118 | + return array( |
|
119 | + 'country' => $country_code, |
|
120 | + 'state' => '', |
|
121 | + 'city' => '', |
|
122 | + 'postcode' => '', |
|
123 | + ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + $country_code = self::get_country_code_from_headers(); |
|
128 | + |
|
129 | + /** |
|
130 | + * Get geolocation filter. |
|
131 | + * |
|
132 | + * @since 1.0.19 |
|
133 | + * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
|
134 | + * @param string $ip_address IP Address. |
|
135 | + */ |
|
136 | + $geolocation = apply_filters( |
|
137 | + 'getpaid_get_geolocation', |
|
138 | + array( |
|
139 | + 'country' => $country_code, |
|
140 | + 'state' => '', |
|
141 | + 'city' => '', |
|
142 | + 'postcode' => '', |
|
143 | + ), |
|
144 | + $ip_address |
|
145 | + ); |
|
146 | + |
|
147 | + // If we still haven't found a country code, let's consider doing an API lookup. |
|
148 | + if ( '' === $geolocation['country'] && $api_fallback ) { |
|
149 | + $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
150 | + } |
|
151 | + |
|
152 | + // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
|
153 | + // external address. |
|
154 | + if ( '' === $geolocation['country'] && $fallback ) { |
|
155 | + $external_ip_address = self::get_external_ip_address(); |
|
156 | + |
|
157 | + // Only bother with this if the external IP differs. |
|
158 | + if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
159 | + return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
160 | + } |
|
161 | 161 | } |
162 | 162 | |
163 | - return array( |
|
164 | - 'country' => $geolocation['country'], |
|
165 | - 'state' => $geolocation['state'], |
|
166 | - 'city' => $geolocation['city'], |
|
167 | - 'postcode' => $geolocation['postcode'], |
|
168 | - ); |
|
169 | - |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Fetches the country code from the request headers, if one is available. |
|
174 | - * |
|
175 | - * @since 1.0.19 |
|
176 | - * @return string The country code pulled from the headers, or empty string if one was not found. |
|
177 | - */ |
|
178 | - protected static function get_country_code_from_headers() { |
|
179 | - $country_code = ''; |
|
180 | - |
|
181 | - $headers = array( |
|
182 | - 'MM_COUNTRY_CODE', |
|
183 | - 'GEOIP_COUNTRY_CODE', |
|
184 | - 'HTTP_CF_IPCOUNTRY', |
|
185 | - 'HTTP_X_COUNTRY_CODE', |
|
186 | - ); |
|
187 | - |
|
188 | - foreach ( $headers as $header ) { |
|
189 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
190 | - continue; |
|
191 | - } |
|
192 | - |
|
193 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
194 | - break; |
|
195 | - } |
|
196 | - |
|
197 | - return $country_code; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Use APIs to Geolocate the user. |
|
202 | - * |
|
203 | - * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
204 | - * Provide a name=>value pair for service-slug=>endpoint. |
|
205 | - * |
|
206 | - * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
207 | - * will be cached in a transient. |
|
208 | - * |
|
209 | - * @param string $ip_address IP address. |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - protected static function geolocate_via_api( $ip_address ) { |
|
213 | - |
|
214 | - // Retrieve from cache... |
|
215 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
216 | - |
|
217 | - // If missing, retrieve from the API. |
|
218 | - if ( false === $country_code ) { |
|
219 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
220 | - |
|
221 | - if ( empty( $geoip_services ) ) { |
|
222 | - return ''; |
|
223 | - } |
|
224 | - |
|
225 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
226 | - |
|
227 | - shuffle( $geoip_services_keys ); |
|
228 | - |
|
229 | - foreach ( $geoip_services_keys as $service_name ) { |
|
230 | - |
|
231 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
232 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
233 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
234 | - |
|
235 | - if ( ! empty( $country_code ) ) { |
|
236 | - break; |
|
237 | - } |
|
163 | + return array( |
|
164 | + 'country' => $geolocation['country'], |
|
165 | + 'state' => $geolocation['state'], |
|
166 | + 'city' => $geolocation['city'], |
|
167 | + 'postcode' => $geolocation['postcode'], |
|
168 | + ); |
|
169 | + |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Fetches the country code from the request headers, if one is available. |
|
174 | + * |
|
175 | + * @since 1.0.19 |
|
176 | + * @return string The country code pulled from the headers, or empty string if one was not found. |
|
177 | + */ |
|
178 | + protected static function get_country_code_from_headers() { |
|
179 | + $country_code = ''; |
|
180 | + |
|
181 | + $headers = array( |
|
182 | + 'MM_COUNTRY_CODE', |
|
183 | + 'GEOIP_COUNTRY_CODE', |
|
184 | + 'HTTP_CF_IPCOUNTRY', |
|
185 | + 'HTTP_X_COUNTRY_CODE', |
|
186 | + ); |
|
187 | + |
|
188 | + foreach ( $headers as $header ) { |
|
189 | + if ( empty( $_SERVER[ $header ] ) ) { |
|
190 | + continue; |
|
191 | + } |
|
192 | + |
|
193 | + $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
194 | + break; |
|
195 | + } |
|
196 | + |
|
197 | + return $country_code; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Use APIs to Geolocate the user. |
|
202 | + * |
|
203 | + * Geolocation APIs can be added through the use of the getpaid_geolocation_geoip_apis filter. |
|
204 | + * Provide a name=>value pair for service-slug=>endpoint. |
|
205 | + * |
|
206 | + * If APIs are defined, one will be chosen at random to fulfil the request. After completing, the result |
|
207 | + * will be cached in a transient. |
|
208 | + * |
|
209 | + * @param string $ip_address IP address. |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + protected static function geolocate_via_api( $ip_address ) { |
|
213 | + |
|
214 | + // Retrieve from cache... |
|
215 | + $country_code = get_transient( 'geoip_' . $ip_address ); |
|
216 | + |
|
217 | + // If missing, retrieve from the API. |
|
218 | + if ( false === $country_code ) { |
|
219 | + $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
220 | + |
|
221 | + if ( empty( $geoip_services ) ) { |
|
222 | + return ''; |
|
223 | + } |
|
224 | + |
|
225 | + $geoip_services_keys = array_keys( $geoip_services ); |
|
226 | + |
|
227 | + shuffle( $geoip_services_keys ); |
|
228 | + |
|
229 | + foreach ( $geoip_services_keys as $service_name ) { |
|
230 | + |
|
231 | + $service_endpoint = $geoip_services[ $service_name ]; |
|
232 | + $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
233 | + $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
234 | + |
|
235 | + if ( ! empty( $country_code ) ) { |
|
236 | + break; |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | |
240 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
241 | - } |
|
240 | + set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
241 | + } |
|
242 | 242 | |
243 | - return $country_code; |
|
244 | - } |
|
243 | + return $country_code; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Handles geolocation response |
|
248 | - * |
|
249 | - * @param WP_Error|String $geolocation_response |
|
250 | - * @param String $geolocation_service |
|
251 | - * @return string Country code |
|
252 | - */ |
|
253 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
246 | + /** |
|
247 | + * Handles geolocation response |
|
248 | + * |
|
249 | + * @param WP_Error|String $geolocation_response |
|
250 | + * @param String $geolocation_service |
|
251 | + * @return string Country code |
|
252 | + */ |
|
253 | + protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
254 | 254 | |
255 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
256 | - return ''; |
|
257 | - } |
|
255 | + if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
256 | + return ''; |
|
257 | + } |
|
258 | 258 | |
259 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
260 | - $data = json_decode( $geolocation_response['body'] ); |
|
261 | - return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
262 | - } |
|
259 | + if ( $geolocation_service === 'ipinfo.io' ) { |
|
260 | + $data = json_decode( $geolocation_response['body'] ); |
|
261 | + return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
262 | + } |
|
263 | 263 | |
264 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
265 | - $data = json_decode( $geolocation_response['body'] ); |
|
266 | - return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
267 | - } |
|
264 | + if ( $geolocation_service === 'ip-api.com' ) { |
|
265 | + $data = json_decode( $geolocation_response['body'] ); |
|
266 | + return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
267 | + } |
|
268 | 268 | |
269 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
269 | + return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
270 | 270 | |
271 | - } |
|
271 | + } |
|
272 | 272 | |
273 | 273 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * GetPaid_Geolocation Class. |
@@ -64,30 +64,30 @@ discard block |
||
64 | 64 | |
65 | 65 | $transient_name = 'external_ip_address_0.0.0.0'; |
66 | 66 | |
67 | - if ( '' !== self::get_ip_address() ) { |
|
68 | - $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
67 | + if ('' !== self::get_ip_address()) { |
|
68 | + $transient_name = 'external_ip_address_' . self::get_ip_address(); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Try retrieving from cache. |
72 | - $external_ip_address = get_transient( $transient_name ); |
|
72 | + $external_ip_address = get_transient($transient_name); |
|
73 | 73 | |
74 | - if ( false === $external_ip_address ) { |
|
74 | + if (false === $external_ip_address) { |
|
75 | 75 | $external_ip_address = '0.0.0.0'; |
76 | - $ip_lookup_services = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis ); |
|
77 | - $ip_lookup_services_keys = array_keys( $ip_lookup_services ); |
|
78 | - shuffle( $ip_lookup_services_keys ); |
|
76 | + $ip_lookup_services = apply_filters('getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis); |
|
77 | + $ip_lookup_services_keys = array_keys($ip_lookup_services); |
|
78 | + shuffle($ip_lookup_services_keys); |
|
79 | 79 | |
80 | - foreach ( $ip_lookup_services_keys as $service_name ) { |
|
81 | - $service_endpoint = $ip_lookup_services[ $service_name ]; |
|
82 | - $response = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) ); |
|
80 | + foreach ($ip_lookup_services_keys as $service_name) { |
|
81 | + $service_endpoint = $ip_lookup_services[$service_name]; |
|
82 | + $response = wp_safe_remote_get($service_endpoint, array('timeout' => 2)); |
|
83 | 83 | |
84 | - if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) { |
|
85 | - $external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name ); |
|
84 | + if (!is_wp_error($response) && rest_is_ip_address($response['body'])) { |
|
85 | + $external_ip_address = apply_filters('getpaid_geolocation_ip_lookup_api_response', wpinv_clean($response['body']), $service_name); |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS ); |
|
90 | + set_transient($transient_name, $external_ip_address, WEEK_IN_SECONDS); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $external_ip_address; |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param bool $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower). |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) { |
|
104 | + public static function geolocate_ip($ip_address = '', $fallback = false, $api_fallback = true) { |
|
105 | 105 | |
106 | - if ( empty( $ip_address ) ) { |
|
106 | + if (empty($ip_address)) { |
|
107 | 107 | $ip_address = self::get_ip_address(); |
108 | 108 | } |
109 | 109 | |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | self::$current_user_ip = $ip_address; |
112 | 112 | |
113 | 113 | // Filter to allow custom geolocation of the IP address. |
114 | - $country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback ); |
|
114 | + $country_code = apply_filters('getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback); |
|
115 | 115 | |
116 | - if ( false !== $country_code ) { |
|
116 | + if (false !== $country_code) { |
|
117 | 117 | |
118 | 118 | return array( |
119 | 119 | 'country' => $country_code, |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param array $geolocation Geolocation data, including country, state, city, and postcode. |
134 | 134 | * @param string $ip_address IP Address. |
135 | 135 | */ |
136 | - $geolocation = apply_filters( |
|
136 | + $geolocation = apply_filters( |
|
137 | 137 | 'getpaid_get_geolocation', |
138 | 138 | array( |
139 | 139 | 'country' => $country_code, |
@@ -145,18 +145,18 @@ discard block |
||
145 | 145 | ); |
146 | 146 | |
147 | 147 | // If we still haven't found a country code, let's consider doing an API lookup. |
148 | - if ( '' === $geolocation['country'] && $api_fallback ) { |
|
149 | - $geolocation['country'] = self::geolocate_via_api( $ip_address ); |
|
148 | + if ('' === $geolocation['country'] && $api_fallback) { |
|
149 | + $geolocation['country'] = self::geolocate_via_api($ip_address); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | // It's possible that we're in a local environment, in which case the geolocation needs to be done from the |
153 | 153 | // external address. |
154 | - if ( '' === $geolocation['country'] && $fallback ) { |
|
154 | + if ('' === $geolocation['country'] && $fallback) { |
|
155 | 155 | $external_ip_address = self::get_external_ip_address(); |
156 | 156 | |
157 | 157 | // Only bother with this if the external IP differs. |
158 | - if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) { |
|
159 | - return self::geolocate_ip( $external_ip_address, false, $api_fallback ); |
|
158 | + if ('0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address) { |
|
159 | + return self::geolocate_ip($external_ip_address, false, $api_fallback); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | 'HTTP_X_COUNTRY_CODE', |
186 | 186 | ); |
187 | 187 | |
188 | - foreach ( $headers as $header ) { |
|
189 | - if ( empty( $_SERVER[ $header ] ) ) { |
|
188 | + foreach ($headers as $header) { |
|
189 | + if (empty($_SERVER[$header])) { |
|
190 | 190 | continue; |
191 | 191 | } |
192 | 192 | |
193 | - $country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) ); |
|
193 | + $country_code = strtoupper(sanitize_text_field(wp_unslash($_SERVER[$header]))); |
|
194 | 194 | break; |
195 | 195 | } |
196 | 196 | |
@@ -209,35 +209,35 @@ discard block |
||
209 | 209 | * @param string $ip_address IP address. |
210 | 210 | * @return string |
211 | 211 | */ |
212 | - protected static function geolocate_via_api( $ip_address ) { |
|
212 | + protected static function geolocate_via_api($ip_address) { |
|
213 | 213 | |
214 | 214 | // Retrieve from cache... |
215 | - $country_code = get_transient( 'geoip_' . $ip_address ); |
|
215 | + $country_code = get_transient('geoip_' . $ip_address); |
|
216 | 216 | |
217 | 217 | // If missing, retrieve from the API. |
218 | - if ( false === $country_code ) { |
|
219 | - $geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis ); |
|
218 | + if (false === $country_code) { |
|
219 | + $geoip_services = apply_filters('getpaid_geolocation_geoip_apis', self::$geoip_apis); |
|
220 | 220 | |
221 | - if ( empty( $geoip_services ) ) { |
|
221 | + if (empty($geoip_services)) { |
|
222 | 222 | return ''; |
223 | 223 | } |
224 | 224 | |
225 | - $geoip_services_keys = array_keys( $geoip_services ); |
|
225 | + $geoip_services_keys = array_keys($geoip_services); |
|
226 | 226 | |
227 | - shuffle( $geoip_services_keys ); |
|
227 | + shuffle($geoip_services_keys); |
|
228 | 228 | |
229 | - foreach ( $geoip_services_keys as $service_name ) { |
|
229 | + foreach ($geoip_services_keys as $service_name) { |
|
230 | 230 | |
231 | - $service_endpoint = $geoip_services[ $service_name ]; |
|
232 | - $response = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) ); |
|
233 | - $country_code = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) ); |
|
231 | + $service_endpoint = $geoip_services[$service_name]; |
|
232 | + $response = wp_safe_remote_get(sprintf($service_endpoint, $ip_address), array('timeout' => 2)); |
|
233 | + $country_code = sanitize_text_field(strtoupper(self::handle_geolocation_response($response, $service_name))); |
|
234 | 234 | |
235 | - if ( ! empty( $country_code ) ) { |
|
235 | + if (!empty($country_code)) { |
|
236 | 236 | break; |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS ); |
|
240 | + set_transient('geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | return $country_code; |
@@ -250,23 +250,23 @@ discard block |
||
250 | 250 | * @param String $geolocation_service |
251 | 251 | * @return string Country code |
252 | 252 | */ |
253 | - protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) { |
|
253 | + protected static function handle_geolocation_response($geolocation_response, $geolocation_service) { |
|
254 | 254 | |
255 | - if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) { |
|
255 | + if (is_wp_error($geolocation_response) || empty($geolocation_response['body'])) { |
|
256 | 256 | return ''; |
257 | 257 | } |
258 | 258 | |
259 | - if ( $geolocation_service === 'ipinfo.io' ) { |
|
260 | - $data = json_decode( $geolocation_response['body'] ); |
|
261 | - return empty( $data ) || empty( $data->country ) ? '' : $data->country; |
|
259 | + if ($geolocation_service === 'ipinfo.io') { |
|
260 | + $data = json_decode($geolocation_response['body']); |
|
261 | + return empty($data) || empty($data->country) ? '' : $data->country; |
|
262 | 262 | } |
263 | 263 | |
264 | - if ( $geolocation_service === 'ip-api.com' ) { |
|
265 | - $data = json_decode( $geolocation_response['body'] ); |
|
266 | - return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode; |
|
264 | + if ($geolocation_service === 'ip-api.com') { |
|
265 | + $data = json_decode($geolocation_response['body']); |
|
266 | + return empty($data) || empty($data->countryCode) ? '' : $data->countryCode; |
|
267 | 267 | } |
268 | 268 | |
269 | - return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] ); |
|
269 | + return apply_filters('getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body']); |
|
270 | 270 | |
271 | 271 | } |
272 | 272 |
@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Discount extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'discount'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'discount'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Discount Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'status' => 'draft', |
|
40 | - 'version' => '', |
|
41 | - 'date_created' => null, |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'discount'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Discount Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'status' => 'draft', |
|
40 | + 'version' => '', |
|
41 | + 'date_created' => null, |
|
42 | 42 | 'date_modified' => null, |
43 | 43 | 'name' => 'no-name', |
44 | 44 | 'description' => '', |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | 'start' => null, |
50 | 50 | 'items' => array(), |
51 | 51 | 'excluded_items' => array(), |
52 | - 'required_items' => array(), |
|
52 | + 'required_items' => array(), |
|
53 | 53 | 'uses' => 0, |
54 | 54 | 'max_uses' => null, |
55 | 55 | 'is_recurring' => null, |
@@ -59,147 +59,147 @@ discard block |
||
59 | 59 | 'amount' => null, |
60 | 60 | ); |
61 | 61 | |
62 | - /** |
|
63 | - * Stores meta in cache for future reads. |
|
64 | - * |
|
65 | - * A group must be set to to enable caching. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - protected $cache_group = 'getpaid_discounts'; |
|
62 | + /** |
|
63 | + * Stores meta in cache for future reads. |
|
64 | + * |
|
65 | + * A group must be set to to enable caching. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + protected $cache_group = 'getpaid_discounts'; |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Stores a reference to the original WP_Post object |
73 | 73 | * |
74 | 74 | * @var WP_Post |
75 | 75 | */ |
76 | - protected $post = null; |
|
77 | - |
|
78 | - /** |
|
79 | - * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
80 | - * |
|
81 | - * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
82 | - */ |
|
83 | - public function __construct( $discount = 0 ) { |
|
84 | - parent::__construct( $discount ); |
|
85 | - |
|
86 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
87 | - $this->set_id( $discount ); |
|
88 | - } elseif ( $discount instanceof self ) { |
|
89 | - $this->set_id( $discount->get_id() ); |
|
90 | - } elseif ( ! empty( $discount->ID ) ) { |
|
91 | - $this->set_id( $discount->ID ); |
|
92 | - } elseif ( is_array( $discount ) ) { |
|
93 | - $this->set_props( $discount ); |
|
94 | - |
|
95 | - if ( isset( $discount['ID'] ) ) { |
|
96 | - $this->set_id( $discount['ID'] ); |
|
97 | - } |
|
76 | + protected $post = null; |
|
77 | + |
|
78 | + /** |
|
79 | + * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
80 | + * |
|
81 | + * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
82 | + */ |
|
83 | + public function __construct( $discount = 0 ) { |
|
84 | + parent::__construct( $discount ); |
|
85 | + |
|
86 | + if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
87 | + $this->set_id( $discount ); |
|
88 | + } elseif ( $discount instanceof self ) { |
|
89 | + $this->set_id( $discount->get_id() ); |
|
90 | + } elseif ( ! empty( $discount->ID ) ) { |
|
91 | + $this->set_id( $discount->ID ); |
|
92 | + } elseif ( is_array( $discount ) ) { |
|
93 | + $this->set_props( $discount ); |
|
94 | + |
|
95 | + if ( isset( $discount['ID'] ) ) { |
|
96 | + $this->set_id( $discount['ID'] ); |
|
97 | + } |
|
98 | 98 | } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
99 | - $this->set_id( $discount ); |
|
100 | - } else { |
|
101 | - $this->set_object_read( true ); |
|
102 | - } |
|
99 | + $this->set_id( $discount ); |
|
100 | + } else { |
|
101 | + $this->set_object_read( true ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | // Load the datastore. |
105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
105 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
106 | 106 | |
107 | - if ( $this->get_id() > 0 ) { |
|
107 | + if ( $this->get_id() > 0 ) { |
|
108 | 108 | $this->post = get_post( $this->get_id() ); |
109 | 109 | $this->ID = $this->get_id(); |
110 | - $this->data_store->read( $this ); |
|
110 | + $this->data_store->read( $this ); |
|
111 | 111 | } |
112 | 112 | |
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Fetch a discount from the db/cache |
|
117 | - * |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | - * @param string|int $value The field value |
|
122 | - * @deprecated |
|
123 | - * @since 1.0.15 |
|
124 | - * @return array|bool array of discount details on success. False otherwise. |
|
125 | - */ |
|
126 | - public static function get_data_by( $field, $value ) { |
|
127 | - |
|
128 | - if ( 'id' == strtolower( $field ) ) { |
|
129 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | - // to int 1. |
|
131 | - if ( ! is_numeric( $value ) ) { |
|
132 | - return false; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Fetch a discount from the db/cache |
|
117 | + * |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
121 | + * @param string|int $value The field value |
|
122 | + * @deprecated |
|
123 | + * @since 1.0.15 |
|
124 | + * @return array|bool array of discount details on success. False otherwise. |
|
125 | + */ |
|
126 | + public static function get_data_by( $field, $value ) { |
|
127 | + |
|
128 | + if ( 'id' == strtolower( $field ) ) { |
|
129 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
130 | + // to int 1. |
|
131 | + if ( ! is_numeric( $value ) ) { |
|
132 | + return false; |
|
133 | 133 | } |
134 | - $value = intval( $value ); |
|
135 | - if ( $value < 1 ) { |
|
136 | - return false; |
|
134 | + $value = intval( $value ); |
|
135 | + if ( $value < 1 ) { |
|
136 | + return false; |
|
137 | 137 | } |
138 | - } |
|
139 | - |
|
140 | - if ( ! $value || ! is_string( $field ) ) { |
|
141 | - return false; |
|
142 | - } |
|
143 | - |
|
144 | - $field = trim( $field ); |
|
145 | - |
|
146 | - // prepare query args |
|
147 | - switch ( strtolower( $field ) ) { |
|
148 | - case 'id': |
|
149 | - $discount_id = $value; |
|
150 | - $args = array( 'include' => array( $value ) ); |
|
151 | - break; |
|
152 | - case 'discount_code': |
|
153 | - case 'code': |
|
154 | - $value = trim( $value ); |
|
155 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
156 | - $args = array( |
|
157 | - 'meta_key' => '_wpi_discount_code', |
|
158 | - 'meta_value' => $value, |
|
159 | - ); |
|
160 | - break; |
|
161 | - case 'name': |
|
162 | - $discount_id = 0; |
|
163 | - $args = array( 'name' => trim( $value ) ); |
|
164 | - break; |
|
165 | - default: |
|
166 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
167 | - if ( ! is_array( $args ) ) { |
|
168 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
169 | - } |
|
138 | + } |
|
139 | + |
|
140 | + if ( ! $value || ! is_string( $field ) ) { |
|
141 | + return false; |
|
142 | + } |
|
143 | + |
|
144 | + $field = trim( $field ); |
|
145 | + |
|
146 | + // prepare query args |
|
147 | + switch ( strtolower( $field ) ) { |
|
148 | + case 'id': |
|
149 | + $discount_id = $value; |
|
150 | + $args = array( 'include' => array( $value ) ); |
|
151 | + break; |
|
152 | + case 'discount_code': |
|
153 | + case 'code': |
|
154 | + $value = trim( $value ); |
|
155 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
156 | + $args = array( |
|
157 | + 'meta_key' => '_wpi_discount_code', |
|
158 | + 'meta_value' => $value, |
|
159 | + ); |
|
160 | + break; |
|
161 | + case 'name': |
|
162 | + $discount_id = 0; |
|
163 | + $args = array( 'name' => trim( $value ) ); |
|
164 | + break; |
|
165 | + default: |
|
166 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
167 | + if ( ! is_array( $args ) ) { |
|
168 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
169 | + } |
|
170 | 170 | } |
171 | 171 | |
172 | - // Check if there is a cached value. |
|
173 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
174 | - return $discount; |
|
175 | - } |
|
172 | + // Check if there is a cached value. |
|
173 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
174 | + return $discount; |
|
175 | + } |
|
176 | 176 | |
177 | - $args = array_merge( |
|
178 | - $args, |
|
179 | - array( |
|
180 | - 'post_type' => 'wpi_discount', |
|
181 | - 'posts_per_page' => 1, |
|
182 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
183 | - ) |
|
184 | - ); |
|
177 | + $args = array_merge( |
|
178 | + $args, |
|
179 | + array( |
|
180 | + 'post_type' => 'wpi_discount', |
|
181 | + 'posts_per_page' => 1, |
|
182 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
183 | + ) |
|
184 | + ); |
|
185 | 185 | |
186 | - $discount = get_posts( $args ); |
|
186 | + $discount = get_posts( $args ); |
|
187 | 187 | |
188 | - if ( empty( $discount ) ) { |
|
189 | - return false; |
|
190 | - } |
|
188 | + if ( empty( $discount ) ) { |
|
189 | + return false; |
|
190 | + } |
|
191 | 191 | |
192 | - $discount = $discount[0]; |
|
192 | + $discount = $discount[0]; |
|
193 | 193 | |
194 | - // Prepare the return data. |
|
195 | - $return = array( |
|
194 | + // Prepare the return data. |
|
195 | + $return = array( |
|
196 | 196 | 'ID' => $discount->ID, |
197 | 197 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
198 | 198 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
199 | 199 | 'date_created' => $discount->post_date, |
200 | - 'date_modified' => $discount->post_modified, |
|
201 | - 'status' => $discount->post_status, |
|
202 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
200 | + 'date_modified' => $discount->post_modified, |
|
201 | + 'status' => $discount->post_status, |
|
202 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
203 | 203 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
204 | 204 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
205 | 205 | 'description' => $discount->post_excerpt, |
@@ -207,84 +207,84 @@ discard block |
||
207 | 207 | 'is_single_use' => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ), |
208 | 208 | 'items' => get_post_meta( $discount->ID, '_wpi_discount_items', true ), |
209 | 209 | 'excluded_items' => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ), |
210 | - 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
210 | + 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
211 | 211 | 'max_uses' => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ), |
212 | 212 | 'is_recurring' => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ), |
213 | 213 | 'min_total' => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ), |
214 | 214 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
215 | 215 | ); |
216 | 216 | |
217 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
218 | - |
|
219 | - // Update the cache with our data |
|
220 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
222 | - |
|
223 | - return $return; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Given a discount code, it returns a discount id. |
|
228 | - * |
|
229 | - * |
|
230 | - * @static |
|
231 | - * @param string $discount_code |
|
232 | - * @since 1.0.15 |
|
233 | - * @return int |
|
234 | - */ |
|
235 | - public static function get_discount_id_by_code( $discount_code ) { |
|
236 | - |
|
237 | - // Trim the code. |
|
238 | - $discount_code = trim( $discount_code ); |
|
239 | - |
|
240 | - // Ensure a value has been passed. |
|
241 | - if ( empty( $discount_code ) ) { |
|
242 | - return 0; |
|
243 | - } |
|
244 | - |
|
245 | - // Maybe retrieve from the cache. |
|
246 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
247 | - if ( ! empty( $discount_id ) ) { |
|
248 | - return $discount_id; |
|
249 | - } |
|
250 | - |
|
251 | - // Fetch the first discount codes. |
|
252 | - $discounts = get_posts( |
|
253 | - array( |
|
254 | - 'meta_key' => '_wpi_discount_code', |
|
255 | - 'meta_value' => $discount_code, |
|
256 | - 'post_type' => 'wpi_discount', |
|
257 | - 'posts_per_page' => 1, |
|
258 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
259 | - 'fields' => 'ids', |
|
260 | - ) |
|
261 | - ); |
|
262 | - |
|
263 | - if ( empty( $discounts ) ) { |
|
264 | - return 0; |
|
265 | - } |
|
266 | - |
|
267 | - $discount_id = $discounts[0]; |
|
268 | - |
|
269 | - // Update the cache with our data |
|
270 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
271 | - |
|
272 | - return $discount_id; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Magic method for checking the existence of a certain custom field. |
|
277 | - * |
|
278 | - * @since 1.0.15 |
|
279 | - * @access public |
|
280 | - * |
|
281 | - * @return bool Whether the given discount field is set. |
|
282 | - */ |
|
283 | - public function __isset( $key ) { |
|
284 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
285 | - } |
|
286 | - |
|
287 | - /* |
|
217 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
218 | + |
|
219 | + // Update the cache with our data |
|
220 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
222 | + |
|
223 | + return $return; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Given a discount code, it returns a discount id. |
|
228 | + * |
|
229 | + * |
|
230 | + * @static |
|
231 | + * @param string $discount_code |
|
232 | + * @since 1.0.15 |
|
233 | + * @return int |
|
234 | + */ |
|
235 | + public static function get_discount_id_by_code( $discount_code ) { |
|
236 | + |
|
237 | + // Trim the code. |
|
238 | + $discount_code = trim( $discount_code ); |
|
239 | + |
|
240 | + // Ensure a value has been passed. |
|
241 | + if ( empty( $discount_code ) ) { |
|
242 | + return 0; |
|
243 | + } |
|
244 | + |
|
245 | + // Maybe retrieve from the cache. |
|
246 | + $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
247 | + if ( ! empty( $discount_id ) ) { |
|
248 | + return $discount_id; |
|
249 | + } |
|
250 | + |
|
251 | + // Fetch the first discount codes. |
|
252 | + $discounts = get_posts( |
|
253 | + array( |
|
254 | + 'meta_key' => '_wpi_discount_code', |
|
255 | + 'meta_value' => $discount_code, |
|
256 | + 'post_type' => 'wpi_discount', |
|
257 | + 'posts_per_page' => 1, |
|
258 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
259 | + 'fields' => 'ids', |
|
260 | + ) |
|
261 | + ); |
|
262 | + |
|
263 | + if ( empty( $discounts ) ) { |
|
264 | + return 0; |
|
265 | + } |
|
266 | + |
|
267 | + $discount_id = $discounts[0]; |
|
268 | + |
|
269 | + // Update the cache with our data |
|
270 | + wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
271 | + |
|
272 | + return $discount_id; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Magic method for checking the existence of a certain custom field. |
|
277 | + * |
|
278 | + * @since 1.0.15 |
|
279 | + * @access public |
|
280 | + * |
|
281 | + * @return bool Whether the given discount field is set. |
|
282 | + */ |
|
283 | + public function __isset( $key ) { |
|
284 | + return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
285 | + } |
|
286 | + |
|
287 | + /* |
|
288 | 288 | |-------------------------------------------------------------------------- |
289 | 289 | | CRUD methods |
290 | 290 | |-------------------------------------------------------------------------- |
@@ -299,441 +299,441 @@ discard block |
||
299 | 299 | |-------------------------------------------------------------------------- |
300 | 300 | */ |
301 | 301 | |
302 | - /** |
|
303 | - * Get discount status. |
|
304 | - * |
|
305 | - * @since 1.0.19 |
|
306 | - * @param string $context View or edit context. |
|
307 | - * @return string |
|
308 | - */ |
|
309 | - public function get_status( $context = 'view' ) { |
|
310 | - return $this->get_prop( 'status', $context ); |
|
302 | + /** |
|
303 | + * Get discount status. |
|
304 | + * |
|
305 | + * @since 1.0.19 |
|
306 | + * @param string $context View or edit context. |
|
307 | + * @return string |
|
308 | + */ |
|
309 | + public function get_status( $context = 'view' ) { |
|
310 | + return $this->get_prop( 'status', $context ); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
314 | - * Get plugin version when the discount was created. |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @param string $context View or edit context. |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public function get_version( $context = 'view' ) { |
|
321 | - return $this->get_prop( 'version', $context ); |
|
314 | + * Get plugin version when the discount was created. |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @param string $context View or edit context. |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public function get_version( $context = 'view' ) { |
|
321 | + return $this->get_prop( 'version', $context ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
325 | - * Get date when the discount was created. |
|
326 | - * |
|
327 | - * @since 1.0.19 |
|
328 | - * @param string $context View or edit context. |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - public function get_date_created( $context = 'view' ) { |
|
332 | - return $this->get_prop( 'date_created', $context ); |
|
325 | + * Get date when the discount was created. |
|
326 | + * |
|
327 | + * @since 1.0.19 |
|
328 | + * @param string $context View or edit context. |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + public function get_date_created( $context = 'view' ) { |
|
332 | + return $this->get_prop( 'date_created', $context ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Get GMT date when the discount was created. |
|
337 | - * |
|
338 | - * @since 1.0.19 |
|
339 | - * @param string $context View or edit context. |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function get_date_created_gmt( $context = 'view' ) { |
|
336 | + * Get GMT date when the discount was created. |
|
337 | + * |
|
338 | + * @since 1.0.19 |
|
339 | + * @param string $context View or edit context. |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function get_date_created_gmt( $context = 'view' ) { |
|
343 | 343 | $date = $this->get_date_created( $context ); |
344 | 344 | |
345 | 345 | if ( $date ) { |
346 | 346 | $date = get_gmt_from_date( $date ); |
347 | 347 | } |
348 | - return $date; |
|
348 | + return $date; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
352 | - * Get date when the discount was last modified. |
|
353 | - * |
|
354 | - * @since 1.0.19 |
|
355 | - * @param string $context View or edit context. |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function get_date_modified( $context = 'view' ) { |
|
359 | - return $this->get_prop( 'date_modified', $context ); |
|
352 | + * Get date when the discount was last modified. |
|
353 | + * |
|
354 | + * @since 1.0.19 |
|
355 | + * @param string $context View or edit context. |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function get_date_modified( $context = 'view' ) { |
|
359 | + return $this->get_prop( 'date_modified', $context ); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
363 | - * Get GMT date when the discount was last modified. |
|
364 | - * |
|
365 | - * @since 1.0.19 |
|
366 | - * @param string $context View or edit context. |
|
367 | - * @return string |
|
368 | - */ |
|
369 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
363 | + * Get GMT date when the discount was last modified. |
|
364 | + * |
|
365 | + * @since 1.0.19 |
|
366 | + * @param string $context View or edit context. |
|
367 | + * @return string |
|
368 | + */ |
|
369 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
370 | 370 | $date = $this->get_date_modified( $context ); |
371 | 371 | |
372 | 372 | if ( $date ) { |
373 | 373 | $date = get_gmt_from_date( $date ); |
374 | 374 | } |
375 | - return $date; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Get the discount name. |
|
380 | - * |
|
381 | - * @since 1.0.19 |
|
382 | - * @param string $context View or edit context. |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public function get_name( $context = 'view' ) { |
|
386 | - return $this->get_prop( 'name', $context ); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Alias of self::get_name(). |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $context View or edit context. |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public function get_title( $context = 'view' ) { |
|
397 | - return $this->get_name( $context ); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Get the discount description. |
|
402 | - * |
|
403 | - * @since 1.0.19 |
|
404 | - * @param string $context View or edit context. |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - public function get_description( $context = 'view' ) { |
|
408 | - return $this->get_prop( 'description', $context ); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Alias of self::get_description(). |
|
413 | - * |
|
414 | - * @since 1.0.19 |
|
415 | - * @param string $context View or edit context. |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function get_excerpt( $context = 'view' ) { |
|
419 | - return $this->get_description( $context ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Alias of self::get_description(). |
|
424 | - * |
|
425 | - * @since 1.0.19 |
|
426 | - * @param string $context View or edit context. |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function get_summary( $context = 'view' ) { |
|
430 | - return $this->get_description( $context ); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Get the owner of the discount. |
|
435 | - * |
|
436 | - * @since 1.0.19 |
|
437 | - * @param string $context View or edit context. |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - public function get_author( $context = 'view' ) { |
|
441 | - return (int) $this->get_prop( 'author', $context ); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Get the discount code. |
|
446 | - * |
|
447 | - * @since 1.0.19 |
|
448 | - * @param string $context View or edit context. |
|
449 | - * @return string |
|
450 | - */ |
|
451 | - public function get_code( $context = 'view' ) { |
|
452 | - return $this->get_prop( 'code', $context ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Alias for self::get_code(). |
|
457 | - * |
|
458 | - * @since 1.0.19 |
|
459 | - * @param string $context View or edit context. |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - public function get_coupon_code( $context = 'view' ) { |
|
463 | - return $this->get_code( $context ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Alias for self::get_code(). |
|
468 | - * |
|
469 | - * @since 1.0.19 |
|
470 | - * @param string $context View or edit context. |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public function get_discount_code( $context = 'view' ) { |
|
474 | - return $this->get_code( $context ); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Get the discount's amount. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - * @param string $context View or edit context. |
|
482 | - * @return float |
|
483 | - */ |
|
484 | - public function get_amount( $context = 'view' ) { |
|
485 | - return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Get the discount's formated amount/rate. |
|
490 | - * |
|
491 | - * @since 1.0.19 |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_formatted_amount() { |
|
495 | - |
|
496 | - if ( $this->is_type( 'flat' ) ) { |
|
497 | - $rate = wpinv_price( $this->get_amount() ); |
|
498 | - } else { |
|
499 | - $rate = $this->get_amount() . '%'; |
|
500 | - } |
|
501 | - |
|
502 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Get the discount's start date. |
|
507 | - * |
|
508 | - * @since 1.0.19 |
|
509 | - * @param string $context View or edit context. |
|
510 | - * @return string |
|
511 | - */ |
|
512 | - public function get_start( $context = 'view' ) { |
|
513 | - return $this->get_prop( 'start', $context ); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Alias for self::get_start(). |
|
518 | - * |
|
519 | - * @since 1.0.19 |
|
520 | - * @param string $context View or edit context. |
|
521 | - * @return string |
|
522 | - */ |
|
523 | - public function get_start_date( $context = 'view' ) { |
|
524 | - return $this->get_start( $context ); |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Get the discount's expiration date. |
|
529 | - * |
|
530 | - * @since 1.0.19 |
|
531 | - * @param string $context View or edit context. |
|
532 | - * @return string |
|
533 | - */ |
|
534 | - public function get_expiration( $context = 'view' ) { |
|
535 | - return $this->get_prop( 'expiration', $context ); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Alias for self::get_expiration(). |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - * @param string $context View or edit context. |
|
543 | - * @return string |
|
544 | - */ |
|
545 | - public function get_expiration_date( $context = 'view' ) { |
|
546 | - return $this->get_expiration( $context ); |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * Alias for self::get_expiration(). |
|
551 | - * |
|
552 | - * @since 1.0.19 |
|
553 | - * @param string $context View or edit context. |
|
554 | - * @return string |
|
555 | - */ |
|
556 | - public function get_end_date( $context = 'view' ) { |
|
557 | - return $this->get_expiration( $context ); |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Get the discount's type. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @param string $context View or edit context. |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - public function get_type( $context = 'view' ) { |
|
568 | - return $this->get_prop( 'type', $context ); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Get the number of times a discount has been used. |
|
573 | - * |
|
574 | - * @since 1.0.19 |
|
575 | - * @param string $context View or edit context. |
|
576 | - * @return int |
|
577 | - */ |
|
578 | - public function get_uses( $context = 'view' ) { |
|
579 | - return (int) $this->get_prop( 'uses', $context ); |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * Get the discount's usage, i.e uses / max uses. |
|
584 | - * |
|
585 | - * @since 1.0.19 |
|
586 | - * @return string |
|
587 | - */ |
|
588 | - public function get_usage() { |
|
589 | - |
|
590 | - if ( ! $this->has_limit() ) { |
|
591 | - return $this->get_uses() . ' / ' . ' ∞'; |
|
592 | - } |
|
593 | - |
|
594 | - return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
595 | - |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Get the maximum number of time a discount can be used. |
|
600 | - * |
|
601 | - * @since 1.0.19 |
|
602 | - * @param string $context View or edit context. |
|
603 | - * @return int |
|
604 | - */ |
|
605 | - public function get_max_uses( $context = 'view' ) { |
|
606 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
607 | - return empty( $max_uses ) ? null : $max_uses; |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * Checks if this is a single use discount or not. |
|
612 | - * |
|
613 | - * @since 1.0.19 |
|
614 | - * @param string $context View or edit context. |
|
615 | - * @return bool |
|
616 | - */ |
|
617 | - public function get_is_single_use( $context = 'view' ) { |
|
618 | - return $this->get_prop( 'is_single_use', $context ); |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Get the items that can be used with this discount. |
|
623 | - * |
|
624 | - * @since 1.0.19 |
|
625 | - * @param string $context View or edit context. |
|
626 | - * @return array |
|
627 | - */ |
|
628 | - public function get_items( $context = 'view' ) { |
|
629 | - return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Alias for self::get_items(). |
|
634 | - * |
|
635 | - * @since 1.0.19 |
|
636 | - * @param string $context View or edit context. |
|
637 | - * @return array |
|
638 | - */ |
|
639 | - public function get_allowed_items( $context = 'view' ) { |
|
640 | - return $this->get_items( $context ); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Get the items that are not allowed to use this discount. |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - * @param string $context View or edit context. |
|
648 | - * @return array |
|
649 | - */ |
|
650 | - public function get_excluded_items( $context = 'view' ) { |
|
651 | - return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * Get the items that are required to be in the cart before using this discount. |
|
656 | - * |
|
657 | - * @since 1.0.19 |
|
658 | - * @param string $context View or edit context. |
|
659 | - * @return array |
|
660 | - */ |
|
661 | - public function get_required_items( $context = 'view' ) { |
|
662 | - return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Checks if this is a recurring discount or not. |
|
667 | - * |
|
668 | - * @since 1.0.19 |
|
669 | - * @param string $context View or edit context. |
|
670 | - * @return int|string|bool |
|
671 | - */ |
|
672 | - public function get_is_recurring( $context = 'view' ) { |
|
673 | - return $this->get_prop( 'is_recurring', $context ); |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Get's the minimum total amount allowed for this discount. |
|
678 | - * |
|
679 | - * @since 1.0.19 |
|
680 | - * @param string $context View or edit context. |
|
681 | - * @return float |
|
682 | - */ |
|
683 | - public function get_min_total( $context = 'view' ) { |
|
684 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
685 | - return empty( $minimum ) ? null : $minimum; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Alias for self::get_min_total(). |
|
690 | - * |
|
691 | - * @since 1.0.19 |
|
692 | - * @param string $context View or edit context. |
|
693 | - * @return float |
|
694 | - */ |
|
695 | - public function get_minimum_total( $context = 'view' ) { |
|
696 | - return $this->get_min_total( $context ); |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Get's the maximum total amount allowed for this discount. |
|
701 | - * |
|
702 | - * @since 1.0.19 |
|
703 | - * @param string $context View or edit context. |
|
704 | - * @return float |
|
705 | - */ |
|
706 | - public function get_max_total( $context = 'view' ) { |
|
707 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
708 | - return empty( $maximum ) ? null : $maximum; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Alias for self::get_max_total(). |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - * @param string $context View or edit context. |
|
716 | - * @return float |
|
717 | - */ |
|
718 | - public function get_maximum_total( $context = 'view' ) { |
|
719 | - return $this->get_max_total( $context ); |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * Magic method for accessing discount properties. |
|
724 | - * |
|
725 | - * @since 1.0.15 |
|
726 | - * @access public |
|
727 | - * |
|
728 | - * @param string $key Discount data to retrieve |
|
729 | - * @param string $context View or edit context. |
|
730 | - * @return mixed Value of the given discount property (if set). |
|
731 | - */ |
|
732 | - public function get( $key, $context = 'view' ) { |
|
375 | + return $date; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Get the discount name. |
|
380 | + * |
|
381 | + * @since 1.0.19 |
|
382 | + * @param string $context View or edit context. |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public function get_name( $context = 'view' ) { |
|
386 | + return $this->get_prop( 'name', $context ); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Alias of self::get_name(). |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $context View or edit context. |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public function get_title( $context = 'view' ) { |
|
397 | + return $this->get_name( $context ); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Get the discount description. |
|
402 | + * |
|
403 | + * @since 1.0.19 |
|
404 | + * @param string $context View or edit context. |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + public function get_description( $context = 'view' ) { |
|
408 | + return $this->get_prop( 'description', $context ); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Alias of self::get_description(). |
|
413 | + * |
|
414 | + * @since 1.0.19 |
|
415 | + * @param string $context View or edit context. |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function get_excerpt( $context = 'view' ) { |
|
419 | + return $this->get_description( $context ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Alias of self::get_description(). |
|
424 | + * |
|
425 | + * @since 1.0.19 |
|
426 | + * @param string $context View or edit context. |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function get_summary( $context = 'view' ) { |
|
430 | + return $this->get_description( $context ); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Get the owner of the discount. |
|
435 | + * |
|
436 | + * @since 1.0.19 |
|
437 | + * @param string $context View or edit context. |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + public function get_author( $context = 'view' ) { |
|
441 | + return (int) $this->get_prop( 'author', $context ); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Get the discount code. |
|
446 | + * |
|
447 | + * @since 1.0.19 |
|
448 | + * @param string $context View or edit context. |
|
449 | + * @return string |
|
450 | + */ |
|
451 | + public function get_code( $context = 'view' ) { |
|
452 | + return $this->get_prop( 'code', $context ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Alias for self::get_code(). |
|
457 | + * |
|
458 | + * @since 1.0.19 |
|
459 | + * @param string $context View or edit context. |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + public function get_coupon_code( $context = 'view' ) { |
|
463 | + return $this->get_code( $context ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Alias for self::get_code(). |
|
468 | + * |
|
469 | + * @since 1.0.19 |
|
470 | + * @param string $context View or edit context. |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public function get_discount_code( $context = 'view' ) { |
|
474 | + return $this->get_code( $context ); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Get the discount's amount. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + * @param string $context View or edit context. |
|
482 | + * @return float |
|
483 | + */ |
|
484 | + public function get_amount( $context = 'view' ) { |
|
485 | + return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Get the discount's formated amount/rate. |
|
490 | + * |
|
491 | + * @since 1.0.19 |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_formatted_amount() { |
|
495 | + |
|
496 | + if ( $this->is_type( 'flat' ) ) { |
|
497 | + $rate = wpinv_price( $this->get_amount() ); |
|
498 | + } else { |
|
499 | + $rate = $this->get_amount() . '%'; |
|
500 | + } |
|
501 | + |
|
502 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Get the discount's start date. |
|
507 | + * |
|
508 | + * @since 1.0.19 |
|
509 | + * @param string $context View or edit context. |
|
510 | + * @return string |
|
511 | + */ |
|
512 | + public function get_start( $context = 'view' ) { |
|
513 | + return $this->get_prop( 'start', $context ); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Alias for self::get_start(). |
|
518 | + * |
|
519 | + * @since 1.0.19 |
|
520 | + * @param string $context View or edit context. |
|
521 | + * @return string |
|
522 | + */ |
|
523 | + public function get_start_date( $context = 'view' ) { |
|
524 | + return $this->get_start( $context ); |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Get the discount's expiration date. |
|
529 | + * |
|
530 | + * @since 1.0.19 |
|
531 | + * @param string $context View or edit context. |
|
532 | + * @return string |
|
533 | + */ |
|
534 | + public function get_expiration( $context = 'view' ) { |
|
535 | + return $this->get_prop( 'expiration', $context ); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Alias for self::get_expiration(). |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + * @param string $context View or edit context. |
|
543 | + * @return string |
|
544 | + */ |
|
545 | + public function get_expiration_date( $context = 'view' ) { |
|
546 | + return $this->get_expiration( $context ); |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * Alias for self::get_expiration(). |
|
551 | + * |
|
552 | + * @since 1.0.19 |
|
553 | + * @param string $context View or edit context. |
|
554 | + * @return string |
|
555 | + */ |
|
556 | + public function get_end_date( $context = 'view' ) { |
|
557 | + return $this->get_expiration( $context ); |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Get the discount's type. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @param string $context View or edit context. |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + public function get_type( $context = 'view' ) { |
|
568 | + return $this->get_prop( 'type', $context ); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Get the number of times a discount has been used. |
|
573 | + * |
|
574 | + * @since 1.0.19 |
|
575 | + * @param string $context View or edit context. |
|
576 | + * @return int |
|
577 | + */ |
|
578 | + public function get_uses( $context = 'view' ) { |
|
579 | + return (int) $this->get_prop( 'uses', $context ); |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * Get the discount's usage, i.e uses / max uses. |
|
584 | + * |
|
585 | + * @since 1.0.19 |
|
586 | + * @return string |
|
587 | + */ |
|
588 | + public function get_usage() { |
|
589 | + |
|
590 | + if ( ! $this->has_limit() ) { |
|
591 | + return $this->get_uses() . ' / ' . ' ∞'; |
|
592 | + } |
|
593 | + |
|
594 | + return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
595 | + |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Get the maximum number of time a discount can be used. |
|
600 | + * |
|
601 | + * @since 1.0.19 |
|
602 | + * @param string $context View or edit context. |
|
603 | + * @return int |
|
604 | + */ |
|
605 | + public function get_max_uses( $context = 'view' ) { |
|
606 | + $max_uses = $this->get_prop( 'max_uses', $context ); |
|
607 | + return empty( $max_uses ) ? null : $max_uses; |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * Checks if this is a single use discount or not. |
|
612 | + * |
|
613 | + * @since 1.0.19 |
|
614 | + * @param string $context View or edit context. |
|
615 | + * @return bool |
|
616 | + */ |
|
617 | + public function get_is_single_use( $context = 'view' ) { |
|
618 | + return $this->get_prop( 'is_single_use', $context ); |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Get the items that can be used with this discount. |
|
623 | + * |
|
624 | + * @since 1.0.19 |
|
625 | + * @param string $context View or edit context. |
|
626 | + * @return array |
|
627 | + */ |
|
628 | + public function get_items( $context = 'view' ) { |
|
629 | + return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Alias for self::get_items(). |
|
634 | + * |
|
635 | + * @since 1.0.19 |
|
636 | + * @param string $context View or edit context. |
|
637 | + * @return array |
|
638 | + */ |
|
639 | + public function get_allowed_items( $context = 'view' ) { |
|
640 | + return $this->get_items( $context ); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Get the items that are not allowed to use this discount. |
|
645 | + * |
|
646 | + * @since 1.0.19 |
|
647 | + * @param string $context View or edit context. |
|
648 | + * @return array |
|
649 | + */ |
|
650 | + public function get_excluded_items( $context = 'view' ) { |
|
651 | + return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * Get the items that are required to be in the cart before using this discount. |
|
656 | + * |
|
657 | + * @since 1.0.19 |
|
658 | + * @param string $context View or edit context. |
|
659 | + * @return array |
|
660 | + */ |
|
661 | + public function get_required_items( $context = 'view' ) { |
|
662 | + return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Checks if this is a recurring discount or not. |
|
667 | + * |
|
668 | + * @since 1.0.19 |
|
669 | + * @param string $context View or edit context. |
|
670 | + * @return int|string|bool |
|
671 | + */ |
|
672 | + public function get_is_recurring( $context = 'view' ) { |
|
673 | + return $this->get_prop( 'is_recurring', $context ); |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Get's the minimum total amount allowed for this discount. |
|
678 | + * |
|
679 | + * @since 1.0.19 |
|
680 | + * @param string $context View or edit context. |
|
681 | + * @return float |
|
682 | + */ |
|
683 | + public function get_min_total( $context = 'view' ) { |
|
684 | + $minimum = $this->get_prop( 'min_total', $context ); |
|
685 | + return empty( $minimum ) ? null : $minimum; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Alias for self::get_min_total(). |
|
690 | + * |
|
691 | + * @since 1.0.19 |
|
692 | + * @param string $context View or edit context. |
|
693 | + * @return float |
|
694 | + */ |
|
695 | + public function get_minimum_total( $context = 'view' ) { |
|
696 | + return $this->get_min_total( $context ); |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Get's the maximum total amount allowed for this discount. |
|
701 | + * |
|
702 | + * @since 1.0.19 |
|
703 | + * @param string $context View or edit context. |
|
704 | + * @return float |
|
705 | + */ |
|
706 | + public function get_max_total( $context = 'view' ) { |
|
707 | + $maximum = $this->get_prop( 'max_total', $context ); |
|
708 | + return empty( $maximum ) ? null : $maximum; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Alias for self::get_max_total(). |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + * @param string $context View or edit context. |
|
716 | + * @return float |
|
717 | + */ |
|
718 | + public function get_maximum_total( $context = 'view' ) { |
|
719 | + return $this->get_max_total( $context ); |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * Magic method for accessing discount properties. |
|
724 | + * |
|
725 | + * @since 1.0.15 |
|
726 | + * @access public |
|
727 | + * |
|
728 | + * @param string $key Discount data to retrieve |
|
729 | + * @param string $context View or edit context. |
|
730 | + * @return mixed Value of the given discount property (if set). |
|
731 | + */ |
|
732 | + public function get( $key, $context = 'view' ) { |
|
733 | 733 | return $this->get_prop( $key, $context ); |
734 | - } |
|
734 | + } |
|
735 | 735 | |
736 | - /* |
|
736 | + /* |
|
737 | 737 | |-------------------------------------------------------------------------- |
738 | 738 | | Setters |
739 | 739 | |-------------------------------------------------------------------------- |
@@ -743,41 +743,41 @@ discard block |
||
743 | 743 | | object. |
744 | 744 | */ |
745 | 745 | |
746 | - /** |
|
747 | - * Sets discount status. |
|
748 | - * |
|
749 | - * @since 1.0.19 |
|
750 | - * @param string $status New status. |
|
751 | - * @return array details of change. |
|
752 | - */ |
|
753 | - public function set_status( $status ) { |
|
746 | + /** |
|
747 | + * Sets discount status. |
|
748 | + * |
|
749 | + * @since 1.0.19 |
|
750 | + * @param string $status New status. |
|
751 | + * @return array details of change. |
|
752 | + */ |
|
753 | + public function set_status( $status ) { |
|
754 | 754 | $old_status = $this->get_status(); |
755 | 755 | |
756 | 756 | $this->set_prop( 'status', $status ); |
757 | 757 | |
758 | - return array( |
|
759 | - 'from' => $old_status, |
|
760 | - 'to' => $status, |
|
761 | - ); |
|
758 | + return array( |
|
759 | + 'from' => $old_status, |
|
760 | + 'to' => $status, |
|
761 | + ); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | /** |
765 | - * Set plugin version when the discount was created. |
|
766 | - * |
|
767 | - * @since 1.0.19 |
|
768 | - */ |
|
769 | - public function set_version( $value ) { |
|
770 | - $this->set_prop( 'version', $value ); |
|
765 | + * Set plugin version when the discount was created. |
|
766 | + * |
|
767 | + * @since 1.0.19 |
|
768 | + */ |
|
769 | + public function set_version( $value ) { |
|
770 | + $this->set_prop( 'version', $value ); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
774 | - * Set date when the discount was created. |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - * @param string $value Value to set. |
|
774 | + * Set date when the discount was created. |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + * @param string $value Value to set. |
|
778 | 778 | * @return bool Whether or not the date was set. |
779 | - */ |
|
780 | - public function set_date_created( $value ) { |
|
779 | + */ |
|
780 | + public function set_date_created( $value ) { |
|
781 | 781 | $date = strtotime( $value ); |
782 | 782 | |
783 | 783 | if ( $date ) { |
@@ -790,13 +790,13 @@ discard block |
||
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
793 | - * Set date when the discount was last modified. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - * @param string $value Value to set. |
|
793 | + * Set date when the discount was last modified. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + * @param string $value Value to set. |
|
797 | 797 | * @return bool Whether or not the date was set. |
798 | - */ |
|
799 | - public function set_date_modified( $value ) { |
|
798 | + */ |
|
799 | + public function set_date_modified( $value ) { |
|
800 | 800 | $date = strtotime( $value ); |
801 | 801 | |
802 | 802 | if ( $date ) { |
@@ -809,334 +809,334 @@ discard block |
||
809 | 809 | } |
810 | 810 | |
811 | 811 | /** |
812 | - * Set the discount name. |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - * @param string $value New name. |
|
816 | - */ |
|
817 | - public function set_name( $value ) { |
|
812 | + * Set the discount name. |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + * @param string $value New name. |
|
816 | + */ |
|
817 | + public function set_name( $value ) { |
|
818 | 818 | $name = sanitize_text_field( $value ); |
819 | - $this->set_prop( 'name', $name ); |
|
819 | + $this->set_prop( 'name', $name ); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | /** |
823 | - * Alias of self::set_name(). |
|
824 | - * |
|
825 | - * @since 1.0.19 |
|
826 | - * @param string $value New name. |
|
827 | - */ |
|
828 | - public function set_title( $value ) { |
|
829 | - $this->set_name( $value ); |
|
823 | + * Alias of self::set_name(). |
|
824 | + * |
|
825 | + * @since 1.0.19 |
|
826 | + * @param string $value New name. |
|
827 | + */ |
|
828 | + public function set_title( $value ) { |
|
829 | + $this->set_name( $value ); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
833 | - * Set the discount description. |
|
834 | - * |
|
835 | - * @since 1.0.19 |
|
836 | - * @param string $value New description. |
|
837 | - */ |
|
838 | - public function set_description( $value ) { |
|
833 | + * Set the discount description. |
|
834 | + * |
|
835 | + * @since 1.0.19 |
|
836 | + * @param string $value New description. |
|
837 | + */ |
|
838 | + public function set_description( $value ) { |
|
839 | 839 | $description = wp_kses_post( $value ); |
840 | - return $this->set_prop( 'description', $description ); |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Alias of self::set_description(). |
|
845 | - * |
|
846 | - * @since 1.0.19 |
|
847 | - * @param string $value New description. |
|
848 | - */ |
|
849 | - public function set_excerpt( $value ) { |
|
850 | - $this->set_description( $value ); |
|
851 | - } |
|
852 | - |
|
853 | - /** |
|
854 | - * Alias of self::set_description(). |
|
855 | - * |
|
856 | - * @since 1.0.19 |
|
857 | - * @param string $value New description. |
|
858 | - */ |
|
859 | - public function set_summary( $value ) { |
|
860 | - $this->set_description( $value ); |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * Set the owner of the discount. |
|
865 | - * |
|
866 | - * @since 1.0.19 |
|
867 | - * @param int $value New author. |
|
868 | - */ |
|
869 | - public function set_author( $value ) { |
|
870 | - $this->set_prop( 'author', (int) $value ); |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * Sets the discount code. |
|
875 | - * |
|
876 | - * @since 1.0.19 |
|
877 | - * @param string $value New discount code. |
|
878 | - */ |
|
879 | - public function set_code( $value ) { |
|
880 | - $code = sanitize_text_field( $value ); |
|
881 | - $this->set_prop( 'code', $code ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Alias of self::set_code(). |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - * @param string $value New discount code. |
|
889 | - */ |
|
890 | - public function set_coupon_code( $value ) { |
|
891 | - $this->set_code( $value ); |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Alias of self::set_code(). |
|
896 | - * |
|
897 | - * @since 1.0.19 |
|
898 | - * @param string $value New discount code. |
|
899 | - */ |
|
900 | - public function set_discount_code( $value ) { |
|
901 | - $this->set_code( $value ); |
|
902 | - } |
|
903 | - |
|
904 | - /** |
|
905 | - * Sets the discount amount. |
|
906 | - * |
|
907 | - * @since 1.0.19 |
|
908 | - * @param float $value New discount code. |
|
909 | - */ |
|
910 | - public function set_amount( $value ) { |
|
911 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
912 | - $this->set_prop( 'amount', $amount ); |
|
913 | - } |
|
914 | - |
|
915 | - /** |
|
916 | - * Sets the discount's start date. |
|
917 | - * |
|
918 | - * @since 1.0.19 |
|
919 | - * @param float $value New start date. |
|
920 | - */ |
|
921 | - public function set_start( $value ) { |
|
922 | - $date = strtotime( $value ); |
|
840 | + return $this->set_prop( 'description', $description ); |
|
841 | + } |
|
842 | + |
|
843 | + /** |
|
844 | + * Alias of self::set_description(). |
|
845 | + * |
|
846 | + * @since 1.0.19 |
|
847 | + * @param string $value New description. |
|
848 | + */ |
|
849 | + public function set_excerpt( $value ) { |
|
850 | + $this->set_description( $value ); |
|
851 | + } |
|
852 | + |
|
853 | + /** |
|
854 | + * Alias of self::set_description(). |
|
855 | + * |
|
856 | + * @since 1.0.19 |
|
857 | + * @param string $value New description. |
|
858 | + */ |
|
859 | + public function set_summary( $value ) { |
|
860 | + $this->set_description( $value ); |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * Set the owner of the discount. |
|
865 | + * |
|
866 | + * @since 1.0.19 |
|
867 | + * @param int $value New author. |
|
868 | + */ |
|
869 | + public function set_author( $value ) { |
|
870 | + $this->set_prop( 'author', (int) $value ); |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * Sets the discount code. |
|
875 | + * |
|
876 | + * @since 1.0.19 |
|
877 | + * @param string $value New discount code. |
|
878 | + */ |
|
879 | + public function set_code( $value ) { |
|
880 | + $code = sanitize_text_field( $value ); |
|
881 | + $this->set_prop( 'code', $code ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Alias of self::set_code(). |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + * @param string $value New discount code. |
|
889 | + */ |
|
890 | + public function set_coupon_code( $value ) { |
|
891 | + $this->set_code( $value ); |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Alias of self::set_code(). |
|
896 | + * |
|
897 | + * @since 1.0.19 |
|
898 | + * @param string $value New discount code. |
|
899 | + */ |
|
900 | + public function set_discount_code( $value ) { |
|
901 | + $this->set_code( $value ); |
|
902 | + } |
|
903 | + |
|
904 | + /** |
|
905 | + * Sets the discount amount. |
|
906 | + * |
|
907 | + * @since 1.0.19 |
|
908 | + * @param float $value New discount code. |
|
909 | + */ |
|
910 | + public function set_amount( $value ) { |
|
911 | + $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
912 | + $this->set_prop( 'amount', $amount ); |
|
913 | + } |
|
914 | + |
|
915 | + /** |
|
916 | + * Sets the discount's start date. |
|
917 | + * |
|
918 | + * @since 1.0.19 |
|
919 | + * @param float $value New start date. |
|
920 | + */ |
|
921 | + public function set_start( $value ) { |
|
922 | + $date = strtotime( $value ); |
|
923 | 923 | |
924 | 924 | if ( $date ) { |
925 | 925 | $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
926 | 926 | return true; |
927 | - } |
|
927 | + } |
|
928 | 928 | |
929 | - $this->set_prop( 'start', '' ); |
|
929 | + $this->set_prop( 'start', '' ); |
|
930 | 930 | |
931 | 931 | return false; |
932 | - } |
|
933 | - |
|
934 | - /** |
|
935 | - * Alias of self::set_start(). |
|
936 | - * |
|
937 | - * @since 1.0.19 |
|
938 | - * @param string $value New start date. |
|
939 | - */ |
|
940 | - public function set_start_date( $value ) { |
|
941 | - $this->set_start( $value ); |
|
942 | - } |
|
943 | - |
|
944 | - /** |
|
945 | - * Sets the discount's expiration date. |
|
946 | - * |
|
947 | - * @since 1.0.19 |
|
948 | - * @param float $value New expiration date. |
|
949 | - */ |
|
950 | - public function set_expiration( $value ) { |
|
951 | - $date = strtotime( $value ); |
|
932 | + } |
|
933 | + |
|
934 | + /** |
|
935 | + * Alias of self::set_start(). |
|
936 | + * |
|
937 | + * @since 1.0.19 |
|
938 | + * @param string $value New start date. |
|
939 | + */ |
|
940 | + public function set_start_date( $value ) { |
|
941 | + $this->set_start( $value ); |
|
942 | + } |
|
943 | + |
|
944 | + /** |
|
945 | + * Sets the discount's expiration date. |
|
946 | + * |
|
947 | + * @since 1.0.19 |
|
948 | + * @param float $value New expiration date. |
|
949 | + */ |
|
950 | + public function set_expiration( $value ) { |
|
951 | + $date = strtotime( $value ); |
|
952 | 952 | |
953 | 953 | if ( $date ) { |
954 | 954 | $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
955 | 955 | return true; |
956 | 956 | } |
957 | 957 | |
958 | - $this->set_prop( 'expiration', '' ); |
|
958 | + $this->set_prop( 'expiration', '' ); |
|
959 | 959 | return false; |
960 | - } |
|
961 | - |
|
962 | - /** |
|
963 | - * Alias of self::set_expiration(). |
|
964 | - * |
|
965 | - * @since 1.0.19 |
|
966 | - * @param string $value New expiration date. |
|
967 | - */ |
|
968 | - public function set_expiration_date( $value ) { |
|
969 | - $this->set_expiration( $value ); |
|
970 | - } |
|
971 | - |
|
972 | - /** |
|
973 | - * Alias of self::set_expiration(). |
|
974 | - * |
|
975 | - * @since 1.0.19 |
|
976 | - * @param string $value New expiration date. |
|
977 | - */ |
|
978 | - public function set_end_date( $value ) { |
|
979 | - $this->set_expiration( $value ); |
|
980 | - } |
|
981 | - |
|
982 | - /** |
|
983 | - * Sets the discount type. |
|
984 | - * |
|
985 | - * @since 1.0.19 |
|
986 | - * @param string $value New discount type. |
|
987 | - */ |
|
988 | - public function set_type( $value ) { |
|
989 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
990 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
991 | - } |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * Sets the number of times a discount has been used. |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @param int $value usage count. |
|
999 | - */ |
|
1000 | - public function set_uses( $value ) { |
|
1001 | - |
|
1002 | - $value = (int) $value; |
|
1003 | - |
|
1004 | - if ( $value < 0 ) { |
|
1005 | - $value = 0; |
|
1006 | - } |
|
1007 | - |
|
1008 | - $this->set_prop( 'uses', (int) $value ); |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Sets the maximum number of times a discount can be used. |
|
1013 | - * |
|
1014 | - * @since 1.0.19 |
|
1015 | - * @param int $value maximum usage count. |
|
1016 | - */ |
|
1017 | - public function set_max_uses( $value ) { |
|
1018 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Sets if this is a single use discount or not. |
|
1023 | - * |
|
1024 | - * @since 1.0.19 |
|
1025 | - * @param int|bool $value is single use. |
|
1026 | - */ |
|
1027 | - public function set_is_single_use( $value ) { |
|
1028 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1029 | - } |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * Sets the items that can be used with this discount. |
|
1033 | - * |
|
1034 | - * @since 1.0.19 |
|
1035 | - * @param array $value items. |
|
1036 | - */ |
|
1037 | - public function set_items( $value ) { |
|
1038 | - $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1039 | - } |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * Alias for self::set_items(). |
|
1043 | - * |
|
1044 | - * @since 1.0.19 |
|
1045 | - * @param array $value items. |
|
1046 | - */ |
|
1047 | - public function set_allowed_items( $value ) { |
|
1048 | - $this->set_items( $value ); |
|
1049 | - } |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * Sets the items that can not be used with this discount. |
|
1053 | - * |
|
1054 | - * @since 1.0.19 |
|
1055 | - * @param array $value items. |
|
1056 | - */ |
|
1057 | - public function set_excluded_items( $value ) { |
|
1058 | - $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1059 | - } |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * Sets the items that are required to be in the cart before using this discount. |
|
1063 | - * |
|
1064 | - * @since 1.0.19 |
|
1065 | - * @param array $value items. |
|
1066 | - */ |
|
1067 | - public function set_required_items( $value ) { |
|
1068 | - $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1069 | - } |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * Sets if this is a recurring discounts or not. |
|
1073 | - * |
|
1074 | - * @since 1.0.19 |
|
1075 | - * @param int|bool $value is recurring. |
|
1076 | - */ |
|
1077 | - public function set_is_recurring( $value ) { |
|
1078 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1079 | - } |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * Sets the minimum total that can not be used with this discount. |
|
1083 | - * |
|
1084 | - * @since 1.0.19 |
|
1085 | - * @param float $value minimum total. |
|
1086 | - */ |
|
1087 | - public function set_min_total( $value ) { |
|
1088 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1089 | - } |
|
1090 | - |
|
1091 | - /** |
|
1092 | - * Alias for self::set_min_total(). |
|
1093 | - * |
|
1094 | - * @since 1.0.19 |
|
1095 | - * @param float $value minimum total. |
|
1096 | - */ |
|
1097 | - public function set_minimum_total( $value ) { |
|
1098 | - $this->set_min_total( $value ); |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Sets the maximum total that can not be used with this discount. |
|
1103 | - * |
|
1104 | - * @since 1.0.19 |
|
1105 | - * @param float $value maximum total. |
|
1106 | - */ |
|
1107 | - public function set_max_total( $value ) { |
|
1108 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1109 | - } |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * Alias for self::set_max_total(). |
|
1113 | - * |
|
1114 | - * @since 1.0.19 |
|
1115 | - * @param float $value maximum total. |
|
1116 | - */ |
|
1117 | - public function set_maximum_total( $value ) { |
|
1118 | - $this->set_max_total( $value ); |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * @deprecated |
|
1123 | - */ |
|
1124 | - public function refresh(){} |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * @deprecated |
|
1128 | - * |
|
1129 | - */ |
|
1130 | - public function update_status( $status = 'publish' ) { |
|
1131 | - |
|
1132 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1133 | - $this->set_status( $status ); |
|
1134 | - $this->save(); |
|
1135 | - } |
|
1136 | - |
|
1137 | - } |
|
1138 | - |
|
1139 | - /* |
|
960 | + } |
|
961 | + |
|
962 | + /** |
|
963 | + * Alias of self::set_expiration(). |
|
964 | + * |
|
965 | + * @since 1.0.19 |
|
966 | + * @param string $value New expiration date. |
|
967 | + */ |
|
968 | + public function set_expiration_date( $value ) { |
|
969 | + $this->set_expiration( $value ); |
|
970 | + } |
|
971 | + |
|
972 | + /** |
|
973 | + * Alias of self::set_expiration(). |
|
974 | + * |
|
975 | + * @since 1.0.19 |
|
976 | + * @param string $value New expiration date. |
|
977 | + */ |
|
978 | + public function set_end_date( $value ) { |
|
979 | + $this->set_expiration( $value ); |
|
980 | + } |
|
981 | + |
|
982 | + /** |
|
983 | + * Sets the discount type. |
|
984 | + * |
|
985 | + * @since 1.0.19 |
|
986 | + * @param string $value New discount type. |
|
987 | + */ |
|
988 | + public function set_type( $value ) { |
|
989 | + if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
990 | + $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
991 | + } |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Sets the number of times a discount has been used. |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @param int $value usage count. |
|
999 | + */ |
|
1000 | + public function set_uses( $value ) { |
|
1001 | + |
|
1002 | + $value = (int) $value; |
|
1003 | + |
|
1004 | + if ( $value < 0 ) { |
|
1005 | + $value = 0; |
|
1006 | + } |
|
1007 | + |
|
1008 | + $this->set_prop( 'uses', (int) $value ); |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Sets the maximum number of times a discount can be used. |
|
1013 | + * |
|
1014 | + * @since 1.0.19 |
|
1015 | + * @param int $value maximum usage count. |
|
1016 | + */ |
|
1017 | + public function set_max_uses( $value ) { |
|
1018 | + $this->set_prop( 'max_uses', absint( $value ) ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Sets if this is a single use discount or not. |
|
1023 | + * |
|
1024 | + * @since 1.0.19 |
|
1025 | + * @param int|bool $value is single use. |
|
1026 | + */ |
|
1027 | + public function set_is_single_use( $value ) { |
|
1028 | + $this->set_prop( 'is_single_use', (bool) $value ); |
|
1029 | + } |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * Sets the items that can be used with this discount. |
|
1033 | + * |
|
1034 | + * @since 1.0.19 |
|
1035 | + * @param array $value items. |
|
1036 | + */ |
|
1037 | + public function set_items( $value ) { |
|
1038 | + $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1039 | + } |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * Alias for self::set_items(). |
|
1043 | + * |
|
1044 | + * @since 1.0.19 |
|
1045 | + * @param array $value items. |
|
1046 | + */ |
|
1047 | + public function set_allowed_items( $value ) { |
|
1048 | + $this->set_items( $value ); |
|
1049 | + } |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * Sets the items that can not be used with this discount. |
|
1053 | + * |
|
1054 | + * @since 1.0.19 |
|
1055 | + * @param array $value items. |
|
1056 | + */ |
|
1057 | + public function set_excluded_items( $value ) { |
|
1058 | + $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1059 | + } |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * Sets the items that are required to be in the cart before using this discount. |
|
1063 | + * |
|
1064 | + * @since 1.0.19 |
|
1065 | + * @param array $value items. |
|
1066 | + */ |
|
1067 | + public function set_required_items( $value ) { |
|
1068 | + $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1069 | + } |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * Sets if this is a recurring discounts or not. |
|
1073 | + * |
|
1074 | + * @since 1.0.19 |
|
1075 | + * @param int|bool $value is recurring. |
|
1076 | + */ |
|
1077 | + public function set_is_recurring( $value ) { |
|
1078 | + $this->set_prop( 'is_recurring', (bool) $value ); |
|
1079 | + } |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * Sets the minimum total that can not be used with this discount. |
|
1083 | + * |
|
1084 | + * @since 1.0.19 |
|
1085 | + * @param float $value minimum total. |
|
1086 | + */ |
|
1087 | + public function set_min_total( $value ) { |
|
1088 | + $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1089 | + } |
|
1090 | + |
|
1091 | + /** |
|
1092 | + * Alias for self::set_min_total(). |
|
1093 | + * |
|
1094 | + * @since 1.0.19 |
|
1095 | + * @param float $value minimum total. |
|
1096 | + */ |
|
1097 | + public function set_minimum_total( $value ) { |
|
1098 | + $this->set_min_total( $value ); |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Sets the maximum total that can not be used with this discount. |
|
1103 | + * |
|
1104 | + * @since 1.0.19 |
|
1105 | + * @param float $value maximum total. |
|
1106 | + */ |
|
1107 | + public function set_max_total( $value ) { |
|
1108 | + $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1109 | + } |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * Alias for self::set_max_total(). |
|
1113 | + * |
|
1114 | + * @since 1.0.19 |
|
1115 | + * @param float $value maximum total. |
|
1116 | + */ |
|
1117 | + public function set_maximum_total( $value ) { |
|
1118 | + $this->set_max_total( $value ); |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * @deprecated |
|
1123 | + */ |
|
1124 | + public function refresh(){} |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * @deprecated |
|
1128 | + * |
|
1129 | + */ |
|
1130 | + public function update_status( $status = 'publish' ) { |
|
1131 | + |
|
1132 | + if ( $this->exists() && $this->get_status() != $status ) { |
|
1133 | + $this->set_status( $status ); |
|
1134 | + $this->save(); |
|
1135 | + } |
|
1136 | + |
|
1137 | + } |
|
1138 | + |
|
1139 | + /* |
|
1140 | 1140 | |-------------------------------------------------------------------------- |
1141 | 1141 | | Conditionals |
1142 | 1142 | |-------------------------------------------------------------------------- |
@@ -1145,290 +1145,290 @@ discard block |
||
1145 | 1145 | | |
1146 | 1146 | */ |
1147 | 1147 | |
1148 | - /** |
|
1149 | - * Checks whether a discount exists in the database or not |
|
1150 | - * |
|
1151 | - * @since 1.0.15 |
|
1152 | - */ |
|
1153 | - public function exists() { |
|
1154 | - $id = $this->get_id(); |
|
1155 | - return ! empty( $id ); |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * Checks the discount type. |
|
1160 | - * |
|
1161 | - * |
|
1162 | - * @param string $type the discount type to check against |
|
1163 | - * @since 1.0.15 |
|
1164 | - * @return bool |
|
1165 | - */ |
|
1166 | - public function is_type( $type ) { |
|
1167 | - return $this->get_type() == $type; |
|
1168 | - } |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * Checks whether the discount is published or not |
|
1172 | - * |
|
1173 | - * @since 1.0.15 |
|
1174 | - * @return bool |
|
1175 | - */ |
|
1176 | - public function is_active() { |
|
1177 | - return $this->get_status() == 'publish'; |
|
1178 | - } |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * Checks whether the discount has max uses |
|
1182 | - * |
|
1183 | - * @since 1.0.15 |
|
1184 | - * @return bool |
|
1185 | - */ |
|
1186 | - public function has_limit() { |
|
1187 | - $limit = $this->get_max_uses(); |
|
1188 | - return ! empty( $limit ); |
|
1189 | - } |
|
1190 | - |
|
1191 | - /** |
|
1192 | - * Checks whether the discount has ever been used. |
|
1193 | - * |
|
1194 | - * @since 1.0.15 |
|
1195 | - * @return bool |
|
1196 | - */ |
|
1197 | - public function has_uses() { |
|
1198 | - return $this->get_uses() > 0; |
|
1199 | - } |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Checks whether the discount is has exided the usage limit or not |
|
1203 | - * |
|
1204 | - * @since 1.0.15 |
|
1205 | - * @return bool |
|
1206 | - */ |
|
1207 | - public function has_exceeded_limit() { |
|
1208 | - |
|
1209 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1210 | - $exceeded = false; |
|
1211 | - } else { |
|
1212 | - $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
|
1213 | - } |
|
1214 | - |
|
1215 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1216 | - } |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * Checks whether the discount has an expiration date. |
|
1220 | - * |
|
1221 | - * @since 1.0.15 |
|
1222 | - * @return bool |
|
1223 | - */ |
|
1224 | - public function has_expiration_date() { |
|
1225 | - $date = $this->get_expiration_date(); |
|
1226 | - return ! empty( $date ); |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * Checks if the discount is expired |
|
1231 | - * |
|
1232 | - * @since 1.0.15 |
|
1233 | - * @return bool |
|
1234 | - */ |
|
1235 | - public function is_expired() { |
|
1236 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1237 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Checks whether the discount has a start date. |
|
1242 | - * |
|
1243 | - * @since 1.0.15 |
|
1244 | - * @return bool |
|
1245 | - */ |
|
1246 | - public function has_start_date() { |
|
1247 | - $date = $this->get_start_date(); |
|
1248 | - return ! empty( $date ); |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Checks the discount start date. |
|
1253 | - * |
|
1254 | - * @since 1.0.15 |
|
1255 | - * @return bool |
|
1256 | - */ |
|
1257 | - public function has_started() { |
|
1258 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1259 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1260 | - } |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Checks the discount has allowed items or not. |
|
1264 | - * |
|
1265 | - * @since 1.0.15 |
|
1266 | - * @return bool |
|
1267 | - */ |
|
1268 | - public function has_allowed_items() { |
|
1269 | - $allowed_items = $this->get_allowed_items(); |
|
1270 | - return ! empty( $allowed_items ); |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * Checks the discount has excluded items or not. |
|
1275 | - * |
|
1276 | - * @since 1.0.15 |
|
1277 | - * @return bool |
|
1278 | - */ |
|
1279 | - public function has_excluded_items() { |
|
1280 | - $excluded_items = $this->get_excluded_items(); |
|
1281 | - return ! empty( $excluded_items ); |
|
1282 | - } |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * Check if a discount is valid for a given item id. |
|
1286 | - * |
|
1287 | - * @param int|int[] $item_ids |
|
1288 | - * @since 1.0.15 |
|
1289 | - * @return boolean |
|
1290 | - */ |
|
1291 | - public function is_valid_for_items( $item_ids ) { |
|
1292 | - |
|
1293 | - $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1294 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1295 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1296 | - |
|
1297 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1298 | - return false; |
|
1299 | - } |
|
1300 | - |
|
1301 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1302 | - return false; |
|
1303 | - } |
|
1304 | - |
|
1305 | - return true; |
|
1306 | - } |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * Checks the discount has required items or not. |
|
1310 | - * |
|
1311 | - * @since 1.0.15 |
|
1312 | - * @return bool |
|
1313 | - */ |
|
1314 | - public function has_required_items() { |
|
1315 | - $required_items = $this->get_required_items(); |
|
1316 | - return ! empty( $required_items ); |
|
1317 | - } |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * Checks if the required items are met |
|
1321 | - * |
|
1322 | - * @param int|int[] $item_ids |
|
1323 | - * @since 1.0.15 |
|
1324 | - * @return boolean |
|
1325 | - */ |
|
1326 | - public function is_required_items_met( $item_ids ) { |
|
1327 | - |
|
1328 | - if ( ! $this->has_required_items() ) { |
|
1329 | - return true; |
|
1330 | - } |
|
1331 | - |
|
1332 | - return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1333 | - } |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * Check if a discount is valid for the given amount |
|
1337 | - * |
|
1338 | - * @param float $amount The amount to check against |
|
1339 | - * @since 1.0.15 |
|
1340 | - * @return boolean |
|
1341 | - */ |
|
1342 | - public function is_valid_for_amount( $amount ) { |
|
1343 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1344 | - } |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * Checks if the minimum amount is set |
|
1348 | - * |
|
1349 | - * @since 1.0.15 |
|
1350 | - * @return boolean |
|
1351 | - */ |
|
1352 | - public function has_minimum_amount() { |
|
1353 | - $minimum = $this->get_minimum_total(); |
|
1354 | - return ! empty( $minimum ); |
|
1355 | - } |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * Checks if the minimum amount is met |
|
1359 | - * |
|
1360 | - * @param float $amount The amount to check against |
|
1361 | - * @since 1.0.15 |
|
1362 | - * @return boolean |
|
1363 | - */ |
|
1364 | - public function is_minimum_amount_met( $amount ) { |
|
1365 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1366 | - $min_met = ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1367 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Checks if the maximum amount is set |
|
1372 | - * |
|
1373 | - * @since 1.0.15 |
|
1374 | - * @return boolean |
|
1375 | - */ |
|
1376 | - public function has_maximum_amount() { |
|
1377 | - $maximum = $this->get_maximum_total(); |
|
1378 | - return ! empty( $maximum ); |
|
1379 | - } |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Checks if the maximum amount is met |
|
1383 | - * |
|
1384 | - * @param float $amount The amount to check against |
|
1385 | - * @since 1.0.15 |
|
1386 | - * @return boolean |
|
1387 | - */ |
|
1388 | - public function is_maximum_amount_met( $amount ) { |
|
1389 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1390 | - $max_met = ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1391 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1392 | - } |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Checks if the discount is recurring. |
|
1396 | - * |
|
1397 | - * @since 1.0.15 |
|
1398 | - * @return boolean |
|
1399 | - */ |
|
1400 | - public function is_recurring() { |
|
1401 | - $recurring = $this->get_is_recurring(); |
|
1402 | - return ! empty( $recurring ); |
|
1403 | - } |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * Checks if the discount is single use. |
|
1407 | - * |
|
1408 | - * @since 1.0.15 |
|
1409 | - * @return boolean |
|
1410 | - */ |
|
1411 | - public function is_single_use() { |
|
1412 | - $usage = $this->get_is_single_use(); |
|
1413 | - return ! empty( $usage ); |
|
1414 | - } |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * Check if a discount is valid for the given user |
|
1418 | - * |
|
1419 | - * @param int|string $user |
|
1420 | - * @since 1.0.15 |
|
1421 | - * @return boolean |
|
1422 | - */ |
|
1423 | - public function is_valid_for_user( $user ) { |
|
1424 | - |
|
1425 | - // Ensure that the discount is single use. |
|
1426 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1427 | - return true; |
|
1428 | - } |
|
1429 | - |
|
1430 | - // Prepare the user id. |
|
1431 | - $user_id = 0; |
|
1148 | + /** |
|
1149 | + * Checks whether a discount exists in the database or not |
|
1150 | + * |
|
1151 | + * @since 1.0.15 |
|
1152 | + */ |
|
1153 | + public function exists() { |
|
1154 | + $id = $this->get_id(); |
|
1155 | + return ! empty( $id ); |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * Checks the discount type. |
|
1160 | + * |
|
1161 | + * |
|
1162 | + * @param string $type the discount type to check against |
|
1163 | + * @since 1.0.15 |
|
1164 | + * @return bool |
|
1165 | + */ |
|
1166 | + public function is_type( $type ) { |
|
1167 | + return $this->get_type() == $type; |
|
1168 | + } |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * Checks whether the discount is published or not |
|
1172 | + * |
|
1173 | + * @since 1.0.15 |
|
1174 | + * @return bool |
|
1175 | + */ |
|
1176 | + public function is_active() { |
|
1177 | + return $this->get_status() == 'publish'; |
|
1178 | + } |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * Checks whether the discount has max uses |
|
1182 | + * |
|
1183 | + * @since 1.0.15 |
|
1184 | + * @return bool |
|
1185 | + */ |
|
1186 | + public function has_limit() { |
|
1187 | + $limit = $this->get_max_uses(); |
|
1188 | + return ! empty( $limit ); |
|
1189 | + } |
|
1190 | + |
|
1191 | + /** |
|
1192 | + * Checks whether the discount has ever been used. |
|
1193 | + * |
|
1194 | + * @since 1.0.15 |
|
1195 | + * @return bool |
|
1196 | + */ |
|
1197 | + public function has_uses() { |
|
1198 | + return $this->get_uses() > 0; |
|
1199 | + } |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Checks whether the discount is has exided the usage limit or not |
|
1203 | + * |
|
1204 | + * @since 1.0.15 |
|
1205 | + * @return bool |
|
1206 | + */ |
|
1207 | + public function has_exceeded_limit() { |
|
1208 | + |
|
1209 | + if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1210 | + $exceeded = false; |
|
1211 | + } else { |
|
1212 | + $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
|
1213 | + } |
|
1214 | + |
|
1215 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1216 | + } |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * Checks whether the discount has an expiration date. |
|
1220 | + * |
|
1221 | + * @since 1.0.15 |
|
1222 | + * @return bool |
|
1223 | + */ |
|
1224 | + public function has_expiration_date() { |
|
1225 | + $date = $this->get_expiration_date(); |
|
1226 | + return ! empty( $date ); |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * Checks if the discount is expired |
|
1231 | + * |
|
1232 | + * @since 1.0.15 |
|
1233 | + * @return bool |
|
1234 | + */ |
|
1235 | + public function is_expired() { |
|
1236 | + $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1237 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Checks whether the discount has a start date. |
|
1242 | + * |
|
1243 | + * @since 1.0.15 |
|
1244 | + * @return bool |
|
1245 | + */ |
|
1246 | + public function has_start_date() { |
|
1247 | + $date = $this->get_start_date(); |
|
1248 | + return ! empty( $date ); |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Checks the discount start date. |
|
1253 | + * |
|
1254 | + * @since 1.0.15 |
|
1255 | + * @return bool |
|
1256 | + */ |
|
1257 | + public function has_started() { |
|
1258 | + $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1259 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1260 | + } |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Checks the discount has allowed items or not. |
|
1264 | + * |
|
1265 | + * @since 1.0.15 |
|
1266 | + * @return bool |
|
1267 | + */ |
|
1268 | + public function has_allowed_items() { |
|
1269 | + $allowed_items = $this->get_allowed_items(); |
|
1270 | + return ! empty( $allowed_items ); |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * Checks the discount has excluded items or not. |
|
1275 | + * |
|
1276 | + * @since 1.0.15 |
|
1277 | + * @return bool |
|
1278 | + */ |
|
1279 | + public function has_excluded_items() { |
|
1280 | + $excluded_items = $this->get_excluded_items(); |
|
1281 | + return ! empty( $excluded_items ); |
|
1282 | + } |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * Check if a discount is valid for a given item id. |
|
1286 | + * |
|
1287 | + * @param int|int[] $item_ids |
|
1288 | + * @since 1.0.15 |
|
1289 | + * @return boolean |
|
1290 | + */ |
|
1291 | + public function is_valid_for_items( $item_ids ) { |
|
1292 | + |
|
1293 | + $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1294 | + $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1295 | + $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1296 | + |
|
1297 | + if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1298 | + return false; |
|
1299 | + } |
|
1300 | + |
|
1301 | + if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1302 | + return false; |
|
1303 | + } |
|
1304 | + |
|
1305 | + return true; |
|
1306 | + } |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * Checks the discount has required items or not. |
|
1310 | + * |
|
1311 | + * @since 1.0.15 |
|
1312 | + * @return bool |
|
1313 | + */ |
|
1314 | + public function has_required_items() { |
|
1315 | + $required_items = $this->get_required_items(); |
|
1316 | + return ! empty( $required_items ); |
|
1317 | + } |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * Checks if the required items are met |
|
1321 | + * |
|
1322 | + * @param int|int[] $item_ids |
|
1323 | + * @since 1.0.15 |
|
1324 | + * @return boolean |
|
1325 | + */ |
|
1326 | + public function is_required_items_met( $item_ids ) { |
|
1327 | + |
|
1328 | + if ( ! $this->has_required_items() ) { |
|
1329 | + return true; |
|
1330 | + } |
|
1331 | + |
|
1332 | + return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1333 | + } |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * Check if a discount is valid for the given amount |
|
1337 | + * |
|
1338 | + * @param float $amount The amount to check against |
|
1339 | + * @since 1.0.15 |
|
1340 | + * @return boolean |
|
1341 | + */ |
|
1342 | + public function is_valid_for_amount( $amount ) { |
|
1343 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1344 | + } |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * Checks if the minimum amount is set |
|
1348 | + * |
|
1349 | + * @since 1.0.15 |
|
1350 | + * @return boolean |
|
1351 | + */ |
|
1352 | + public function has_minimum_amount() { |
|
1353 | + $minimum = $this->get_minimum_total(); |
|
1354 | + return ! empty( $minimum ); |
|
1355 | + } |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * Checks if the minimum amount is met |
|
1359 | + * |
|
1360 | + * @param float $amount The amount to check against |
|
1361 | + * @since 1.0.15 |
|
1362 | + * @return boolean |
|
1363 | + */ |
|
1364 | + public function is_minimum_amount_met( $amount ) { |
|
1365 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1366 | + $min_met = ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1367 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Checks if the maximum amount is set |
|
1372 | + * |
|
1373 | + * @since 1.0.15 |
|
1374 | + * @return boolean |
|
1375 | + */ |
|
1376 | + public function has_maximum_amount() { |
|
1377 | + $maximum = $this->get_maximum_total(); |
|
1378 | + return ! empty( $maximum ); |
|
1379 | + } |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Checks if the maximum amount is met |
|
1383 | + * |
|
1384 | + * @param float $amount The amount to check against |
|
1385 | + * @since 1.0.15 |
|
1386 | + * @return boolean |
|
1387 | + */ |
|
1388 | + public function is_maximum_amount_met( $amount ) { |
|
1389 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1390 | + $max_met = ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1391 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1392 | + } |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Checks if the discount is recurring. |
|
1396 | + * |
|
1397 | + * @since 1.0.15 |
|
1398 | + * @return boolean |
|
1399 | + */ |
|
1400 | + public function is_recurring() { |
|
1401 | + $recurring = $this->get_is_recurring(); |
|
1402 | + return ! empty( $recurring ); |
|
1403 | + } |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * Checks if the discount is single use. |
|
1407 | + * |
|
1408 | + * @since 1.0.15 |
|
1409 | + * @return boolean |
|
1410 | + */ |
|
1411 | + public function is_single_use() { |
|
1412 | + $usage = $this->get_is_single_use(); |
|
1413 | + return ! empty( $usage ); |
|
1414 | + } |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * Check if a discount is valid for the given user |
|
1418 | + * |
|
1419 | + * @param int|string $user |
|
1420 | + * @since 1.0.15 |
|
1421 | + * @return boolean |
|
1422 | + */ |
|
1423 | + public function is_valid_for_user( $user ) { |
|
1424 | + |
|
1425 | + // Ensure that the discount is single use. |
|
1426 | + if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1427 | + return true; |
|
1428 | + } |
|
1429 | + |
|
1430 | + // Prepare the user id. |
|
1431 | + $user_id = 0; |
|
1432 | 1432 | if ( is_numeric( $user ) ) { |
1433 | 1433 | $user_id = absint( $user ); |
1434 | 1434 | } elseif ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -1437,122 +1437,122 @@ discard block |
||
1437 | 1437 | $user_id = $user_data->ID; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - // Ensure that we have a user. |
|
1441 | - if ( empty( $user_id ) ) { |
|
1442 | - return true; |
|
1443 | - } |
|
1440 | + // Ensure that we have a user. |
|
1441 | + if ( empty( $user_id ) ) { |
|
1442 | + return true; |
|
1443 | + } |
|
1444 | 1444 | |
1445 | - // Get all payments with matching user id. |
|
1445 | + // Get all payments with matching user id. |
|
1446 | 1446 | $payments = wpinv_get_invoices( |
1447 | 1447 | array( |
1448 | - 'user' => $user_id, |
|
1449 | - 'limit' => false, |
|
1450 | - 'paginate' => false, |
|
1448 | + 'user' => $user_id, |
|
1449 | + 'limit' => false, |
|
1450 | + 'paginate' => false, |
|
1451 | 1451 | ) |
1452 | 1452 | ); |
1453 | - $code = strtolower( $this->get_code() ); |
|
1453 | + $code = strtolower( $this->get_code() ); |
|
1454 | 1454 | |
1455 | - // For each payment... |
|
1456 | - foreach ( $payments as $payment ) { |
|
1455 | + // For each payment... |
|
1456 | + foreach ( $payments as $payment ) { |
|
1457 | 1457 | |
1458 | - // Only check for paid invoices. |
|
1459 | - if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1460 | - return false; |
|
1461 | - } |
|
1458 | + // Only check for paid invoices. |
|
1459 | + if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1460 | + return false; |
|
1461 | + } |
|
1462 | 1462 | } |
1463 | 1463 | |
1464 | - return true; |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Deletes the discount from the database |
|
1469 | - * |
|
1470 | - * @since 1.0.15 |
|
1471 | - * @return boolean |
|
1472 | - */ |
|
1473 | - public function remove() { |
|
1474 | - return $this->delete(); |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * Increases a discount's usage. |
|
1479 | - * |
|
1480 | - * @since 1.0.15 |
|
1481 | - * @param int $by The number of usages to increas by. |
|
1482 | - * @return int |
|
1483 | - */ |
|
1484 | - public function increase_usage( $by = 1 ) { |
|
1485 | - |
|
1486 | - // Abort if zero. |
|
1487 | - if ( empty( $by ) ) { |
|
1488 | - return; |
|
1489 | - } |
|
1490 | - |
|
1491 | - // Increase the usage. |
|
1492 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1493 | - |
|
1494 | - // Save the discount. |
|
1495 | - $this->save(); |
|
1496 | - |
|
1497 | - // Fire relevant hooks. |
|
1498 | - if ( (int) $by > 0 ) { |
|
1499 | - do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1500 | - } else { |
|
1501 | - do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1502 | - } |
|
1503 | - |
|
1504 | - // Return the number of times the discount has been used. |
|
1505 | - return $this->get_uses(); |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * Alias of self::__toString() |
|
1510 | - * |
|
1511 | - * @since 1.0.15 |
|
1512 | - * @return string|false |
|
1513 | - */ |
|
1514 | - public function get_data_as_json() { |
|
1515 | - return $this->__toString(); |
|
1516 | - } |
|
1517 | - |
|
1518 | - /** |
|
1519 | - * Returns a discount's discounted amount. |
|
1520 | - * |
|
1521 | - * @since 1.0.15 |
|
1522 | - * @param float $amount |
|
1523 | - * @return float |
|
1524 | - */ |
|
1525 | - public function get_discounted_amount( $amount ) { |
|
1526 | - |
|
1527 | - // Convert amount to float. |
|
1528 | - $amount = (float) $amount; |
|
1529 | - |
|
1530 | - // Get discount amount. |
|
1531 | - $discount_amount = $this->get_amount(); |
|
1532 | - |
|
1533 | - if ( empty( $discount_amount ) ) { |
|
1534 | - return 0; |
|
1535 | - } |
|
1536 | - |
|
1537 | - // Format the amount. |
|
1538 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1539 | - |
|
1540 | - // If this is a percentage discount. |
|
1541 | - if ( $this->is_type( 'percent' ) ) { |
|
1464 | + return true; |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Deletes the discount from the database |
|
1469 | + * |
|
1470 | + * @since 1.0.15 |
|
1471 | + * @return boolean |
|
1472 | + */ |
|
1473 | + public function remove() { |
|
1474 | + return $this->delete(); |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * Increases a discount's usage. |
|
1479 | + * |
|
1480 | + * @since 1.0.15 |
|
1481 | + * @param int $by The number of usages to increas by. |
|
1482 | + * @return int |
|
1483 | + */ |
|
1484 | + public function increase_usage( $by = 1 ) { |
|
1485 | + |
|
1486 | + // Abort if zero. |
|
1487 | + if ( empty( $by ) ) { |
|
1488 | + return; |
|
1489 | + } |
|
1490 | + |
|
1491 | + // Increase the usage. |
|
1492 | + $this->set_uses( $this->get_uses() + (int) $by ); |
|
1493 | + |
|
1494 | + // Save the discount. |
|
1495 | + $this->save(); |
|
1496 | + |
|
1497 | + // Fire relevant hooks. |
|
1498 | + if ( (int) $by > 0 ) { |
|
1499 | + do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1500 | + } else { |
|
1501 | + do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1502 | + } |
|
1503 | + |
|
1504 | + // Return the number of times the discount has been used. |
|
1505 | + return $this->get_uses(); |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * Alias of self::__toString() |
|
1510 | + * |
|
1511 | + * @since 1.0.15 |
|
1512 | + * @return string|false |
|
1513 | + */ |
|
1514 | + public function get_data_as_json() { |
|
1515 | + return $this->__toString(); |
|
1516 | + } |
|
1517 | + |
|
1518 | + /** |
|
1519 | + * Returns a discount's discounted amount. |
|
1520 | + * |
|
1521 | + * @since 1.0.15 |
|
1522 | + * @param float $amount |
|
1523 | + * @return float |
|
1524 | + */ |
|
1525 | + public function get_discounted_amount( $amount ) { |
|
1526 | + |
|
1527 | + // Convert amount to float. |
|
1528 | + $amount = (float) $amount; |
|
1529 | + |
|
1530 | + // Get discount amount. |
|
1531 | + $discount_amount = $this->get_amount(); |
|
1532 | + |
|
1533 | + if ( empty( $discount_amount ) ) { |
|
1534 | + return 0; |
|
1535 | + } |
|
1536 | + |
|
1537 | + // Format the amount. |
|
1538 | + $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1539 | + |
|
1540 | + // If this is a percentage discount. |
|
1541 | + if ( $this->is_type( 'percent' ) ) { |
|
1542 | 1542 | $discount_amount = $amount * ( $discount_amount / 100 ); |
1543 | - } |
|
1543 | + } |
|
1544 | 1544 | |
1545 | - // Discount can not be less than zero... |
|
1546 | - if ( $discount_amount < 0 ) { |
|
1547 | - $discount_amount = 0; |
|
1548 | - } |
|
1545 | + // Discount can not be less than zero... |
|
1546 | + if ( $discount_amount < 0 ) { |
|
1547 | + $discount_amount = 0; |
|
1548 | + } |
|
1549 | 1549 | |
1550 | - // ... or more than the amount. |
|
1551 | - if ( $discount_amount > $amount ) { |
|
1552 | - $discount_amount = $amount; |
|
1553 | - } |
|
1550 | + // ... or more than the amount. |
|
1551 | + if ( $discount_amount > $amount ) { |
|
1552 | + $discount_amount = $amount; |
|
1553 | + } |
|
1554 | 1554 | |
1555 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1556 | - } |
|
1555 | + return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1556 | + } |
|
1557 | 1557 | |
1558 | 1558 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @since 1.0.15 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Discount class. |
@@ -80,34 +80,34 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
82 | 82 | */ |
83 | - public function __construct( $discount = 0 ) { |
|
84 | - parent::__construct( $discount ); |
|
83 | + public function __construct($discount = 0) { |
|
84 | + parent::__construct($discount); |
|
85 | 85 | |
86 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
87 | - $this->set_id( $discount ); |
|
88 | - } elseif ( $discount instanceof self ) { |
|
89 | - $this->set_id( $discount->get_id() ); |
|
90 | - } elseif ( ! empty( $discount->ID ) ) { |
|
91 | - $this->set_id( $discount->ID ); |
|
92 | - } elseif ( is_array( $discount ) ) { |
|
93 | - $this->set_props( $discount ); |
|
86 | + if (is_numeric($discount) && 'wpi_discount' === get_post_type($discount)) { |
|
87 | + $this->set_id($discount); |
|
88 | + } elseif ($discount instanceof self) { |
|
89 | + $this->set_id($discount->get_id()); |
|
90 | + } elseif (!empty($discount->ID)) { |
|
91 | + $this->set_id($discount->ID); |
|
92 | + } elseif (is_array($discount)) { |
|
93 | + $this->set_props($discount); |
|
94 | 94 | |
95 | - if ( isset( $discount['ID'] ) ) { |
|
96 | - $this->set_id( $discount['ID'] ); |
|
95 | + if (isset($discount['ID'])) { |
|
96 | + $this->set_id($discount['ID']); |
|
97 | 97 | } |
98 | -} elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
99 | - $this->set_id( $discount ); |
|
98 | +} elseif (is_scalar($discount) && $discount = self::get_discount_id_by_code($discount)) { |
|
99 | + $this->set_id($discount); |
|
100 | 100 | } else { |
101 | - $this->set_object_read( true ); |
|
101 | + $this->set_object_read(true); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // Load the datastore. |
105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
105 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
106 | 106 | |
107 | - if ( $this->get_id() > 0 ) { |
|
108 | - $this->post = get_post( $this->get_id() ); |
|
107 | + if ($this->get_id() > 0) { |
|
108 | + $this->post = get_post($this->get_id()); |
|
109 | 109 | $this->ID = $this->get_id(); |
110 | - $this->data_store->read( $this ); |
|
110 | + $this->data_store->read($this); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -123,36 +123,36 @@ discard block |
||
123 | 123 | * @since 1.0.15 |
124 | 124 | * @return array|bool array of discount details on success. False otherwise. |
125 | 125 | */ |
126 | - public static function get_data_by( $field, $value ) { |
|
126 | + public static function get_data_by($field, $value) { |
|
127 | 127 | |
128 | - if ( 'id' == strtolower( $field ) ) { |
|
128 | + if ('id' == strtolower($field)) { |
|
129 | 129 | // Make sure the value is numeric to avoid casting objects, for example, |
130 | 130 | // to int 1. |
131 | - if ( ! is_numeric( $value ) ) { |
|
131 | + if (!is_numeric($value)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | - $value = intval( $value ); |
|
135 | - if ( $value < 1 ) { |
|
134 | + $value = intval($value); |
|
135 | + if ($value < 1) { |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - if ( ! $value || ! is_string( $field ) ) { |
|
140 | + if (!$value || !is_string($field)) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | - $field = trim( $field ); |
|
144 | + $field = trim($field); |
|
145 | 145 | |
146 | 146 | // prepare query args |
147 | - switch ( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | case 'id': |
149 | 149 | $discount_id = $value; |
150 | - $args = array( 'include' => array( $value ) ); |
|
150 | + $args = array('include' => array($value)); |
|
151 | 151 | break; |
152 | 152 | case 'discount_code': |
153 | 153 | case 'code': |
154 | - $value = trim( $value ); |
|
155 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
154 | + $value = trim($value); |
|
155 | + $discount_id = wp_cache_get($value, 'WPInv_Discount_Codes'); |
|
156 | 156 | $args = array( |
157 | 157 | 'meta_key' => '_wpi_discount_code', |
158 | 158 | 'meta_value' => $value, |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | break; |
161 | 161 | case 'name': |
162 | 162 | $discount_id = 0; |
163 | - $args = array( 'name' => trim( $value ) ); |
|
163 | + $args = array('name' => trim($value)); |
|
164 | 164 | break; |
165 | 165 | default: |
166 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
167 | - if ( ! is_array( $args ) ) { |
|
168 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
166 | + $args = apply_filters("wpinv_discount_get_data_by_{$field}_args", null, $value); |
|
167 | + if (!is_array($args)) { |
|
168 | + return apply_filters("wpinv_discount_get_data_by_$field", false, $value); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | // Check if there is a cached value. |
173 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
173 | + if (!empty($discount_id) && $discount = wp_cache_get((int) $discount_id, 'WPInv_Discounts')) { |
|
174 | 174 | return $discount; |
175 | 175 | } |
176 | 176 | |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | array( |
180 | 180 | 'post_type' => 'wpi_discount', |
181 | 181 | 'posts_per_page' => 1, |
182 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
182 | + 'post_status' => array('publish', 'pending', 'draft', 'expired'), |
|
183 | 183 | ) |
184 | 184 | ); |
185 | 185 | |
186 | - $discount = get_posts( $args ); |
|
186 | + $discount = get_posts($args); |
|
187 | 187 | |
188 | - if ( empty( $discount ) ) { |
|
188 | + if (empty($discount)) { |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
@@ -194,31 +194,31 @@ discard block |
||
194 | 194 | // Prepare the return data. |
195 | 195 | $return = array( |
196 | 196 | 'ID' => $discount->ID, |
197 | - 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
|
198 | - 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
|
197 | + 'code' => get_post_meta($discount->ID, '_wpi_discount_code', true), |
|
198 | + 'amount' => get_post_meta($discount->ID, '_wpi_discount_amount', true), |
|
199 | 199 | 'date_created' => $discount->post_date, |
200 | 200 | 'date_modified' => $discount->post_modified, |
201 | 201 | 'status' => $discount->post_status, |
202 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
203 | - 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
|
204 | - 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
|
202 | + 'start' => get_post_meta($discount->ID, '_wpi_discount_start', true), |
|
203 | + 'expiration' => get_post_meta($discount->ID, '_wpi_discount_expiration', true), |
|
204 | + 'type' => get_post_meta($discount->ID, '_wpi_discount_type', true), |
|
205 | 205 | 'description' => $discount->post_excerpt, |
206 | - 'uses' => get_post_meta( $discount->ID, '_wpi_discount_uses', true ), |
|
207 | - 'is_single_use' => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ), |
|
208 | - 'items' => get_post_meta( $discount->ID, '_wpi_discount_items', true ), |
|
209 | - 'excluded_items' => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ), |
|
210 | - 'required_items' => get_post_meta( $discount->ID, '_wpi_discount_required_items', true ), |
|
211 | - 'max_uses' => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ), |
|
212 | - 'is_recurring' => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ), |
|
213 | - 'min_total' => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ), |
|
214 | - 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
|
206 | + 'uses' => get_post_meta($discount->ID, '_wpi_discount_uses', true), |
|
207 | + 'is_single_use' => get_post_meta($discount->ID, '_wpi_discount_is_single_use', true), |
|
208 | + 'items' => get_post_meta($discount->ID, '_wpi_discount_items', true), |
|
209 | + 'excluded_items' => get_post_meta($discount->ID, '_wpi_discount_excluded_items', true), |
|
210 | + 'required_items' => get_post_meta($discount->ID, '_wpi_discount_required_items', true), |
|
211 | + 'max_uses' => get_post_meta($discount->ID, '_wpi_discount_max_uses', true), |
|
212 | + 'is_recurring' => get_post_meta($discount->ID, '_wpi_discount_is_recurring', true), |
|
213 | + 'min_total' => get_post_meta($discount->ID, '_wpi_discount_min_total', true), |
|
214 | + 'max_total' => get_post_meta($discount->ID, '_wpi_discount_max_total', true), |
|
215 | 215 | ); |
216 | 216 | |
217 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
217 | + $return = apply_filters('wpinv_discount_properties', $return); |
|
218 | 218 | |
219 | 219 | // Update the cache with our data |
220 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
221 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
220 | + wp_cache_add($discount->ID, $return, 'WPInv_Discounts'); |
|
221 | + wp_cache_add($return['code'], $discount->ID, 'WPInv_Discount_Codes'); |
|
222 | 222 | |
223 | 223 | return $return; |
224 | 224 | } |
@@ -232,19 +232,19 @@ discard block |
||
232 | 232 | * @since 1.0.15 |
233 | 233 | * @return int |
234 | 234 | */ |
235 | - public static function get_discount_id_by_code( $discount_code ) { |
|
235 | + public static function get_discount_id_by_code($discount_code) { |
|
236 | 236 | |
237 | 237 | // Trim the code. |
238 | - $discount_code = trim( $discount_code ); |
|
238 | + $discount_code = trim($discount_code); |
|
239 | 239 | |
240 | 240 | // Ensure a value has been passed. |
241 | - if ( empty( $discount_code ) ) { |
|
241 | + if (empty($discount_code)) { |
|
242 | 242 | return 0; |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Maybe retrieve from the cache. |
246 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
247 | - if ( ! empty( $discount_id ) ) { |
|
246 | + $discount_id = wp_cache_get($discount_code, 'getpaid_discount_codes'); |
|
247 | + if (!empty($discount_id)) { |
|
248 | 248 | return $discount_id; |
249 | 249 | } |
250 | 250 | |
@@ -255,19 +255,19 @@ discard block |
||
255 | 255 | 'meta_value' => $discount_code, |
256 | 256 | 'post_type' => 'wpi_discount', |
257 | 257 | 'posts_per_page' => 1, |
258 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
258 | + 'post_status' => array('publish', 'pending', 'draft', 'expired'), |
|
259 | 259 | 'fields' => 'ids', |
260 | 260 | ) |
261 | 261 | ); |
262 | 262 | |
263 | - if ( empty( $discounts ) ) { |
|
263 | + if (empty($discounts)) { |
|
264 | 264 | return 0; |
265 | 265 | } |
266 | 266 | |
267 | 267 | $discount_id = $discounts[0]; |
268 | 268 | |
269 | 269 | // Update the cache with our data |
270 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
270 | + wp_cache_add(get_post_meta($discount_id, '_wpi_discount_code', true), $discount_id, 'getpaid_discount_codes'); |
|
271 | 271 | |
272 | 272 | return $discount_id; |
273 | 273 | } |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return bool Whether the given discount field is set. |
282 | 282 | */ |
283 | - public function __isset( $key ) { |
|
284 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
283 | + public function __isset($key) { |
|
284 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /* |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param string $context View or edit context. |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - public function get_status( $context = 'view' ) { |
|
310 | - return $this->get_prop( 'status', $context ); |
|
309 | + public function get_status($context = 'view') { |
|
310 | + return $this->get_prop('status', $context); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | * @param string $context View or edit context. |
318 | 318 | * @return string |
319 | 319 | */ |
320 | - public function get_version( $context = 'view' ) { |
|
321 | - return $this->get_prop( 'version', $context ); |
|
320 | + public function get_version($context = 'view') { |
|
321 | + return $this->get_prop('version', $context); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * @param string $context View or edit context. |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - public function get_date_created( $context = 'view' ) { |
|
332 | - return $this->get_prop( 'date_created', $context ); |
|
331 | + public function get_date_created($context = 'view') { |
|
332 | + return $this->get_prop('date_created', $context); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | * @param string $context View or edit context. |
340 | 340 | * @return string |
341 | 341 | */ |
342 | - public function get_date_created_gmt( $context = 'view' ) { |
|
343 | - $date = $this->get_date_created( $context ); |
|
342 | + public function get_date_created_gmt($context = 'view') { |
|
343 | + $date = $this->get_date_created($context); |
|
344 | 344 | |
345 | - if ( $date ) { |
|
346 | - $date = get_gmt_from_date( $date ); |
|
345 | + if ($date) { |
|
346 | + $date = get_gmt_from_date($date); |
|
347 | 347 | } |
348 | 348 | return $date; |
349 | 349 | } |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | * @param string $context View or edit context. |
356 | 356 | * @return string |
357 | 357 | */ |
358 | - public function get_date_modified( $context = 'view' ) { |
|
359 | - return $this->get_prop( 'date_modified', $context ); |
|
358 | + public function get_date_modified($context = 'view') { |
|
359 | + return $this->get_prop('date_modified', $context); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -366,11 +366,11 @@ discard block |
||
366 | 366 | * @param string $context View or edit context. |
367 | 367 | * @return string |
368 | 368 | */ |
369 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
370 | - $date = $this->get_date_modified( $context ); |
|
369 | + public function get_date_modified_gmt($context = 'view') { |
|
370 | + $date = $this->get_date_modified($context); |
|
371 | 371 | |
372 | - if ( $date ) { |
|
373 | - $date = get_gmt_from_date( $date ); |
|
372 | + if ($date) { |
|
373 | + $date = get_gmt_from_date($date); |
|
374 | 374 | } |
375 | 375 | return $date; |
376 | 376 | } |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param string $context View or edit context. |
383 | 383 | * @return string |
384 | 384 | */ |
385 | - public function get_name( $context = 'view' ) { |
|
386 | - return $this->get_prop( 'name', $context ); |
|
385 | + public function get_name($context = 'view') { |
|
386 | + return $this->get_prop('name', $context); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,8 +393,8 @@ discard block |
||
393 | 393 | * @param string $context View or edit context. |
394 | 394 | * @return string |
395 | 395 | */ |
396 | - public function get_title( $context = 'view' ) { |
|
397 | - return $this->get_name( $context ); |
|
396 | + public function get_title($context = 'view') { |
|
397 | + return $this->get_name($context); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | * @param string $context View or edit context. |
405 | 405 | * @return string |
406 | 406 | */ |
407 | - public function get_description( $context = 'view' ) { |
|
408 | - return $this->get_prop( 'description', $context ); |
|
407 | + public function get_description($context = 'view') { |
|
408 | + return $this->get_prop('description', $context); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | * @param string $context View or edit context. |
416 | 416 | * @return string |
417 | 417 | */ |
418 | - public function get_excerpt( $context = 'view' ) { |
|
419 | - return $this->get_description( $context ); |
|
418 | + public function get_excerpt($context = 'view') { |
|
419 | + return $this->get_description($context); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | * @param string $context View or edit context. |
427 | 427 | * @return string |
428 | 428 | */ |
429 | - public function get_summary( $context = 'view' ) { |
|
430 | - return $this->get_description( $context ); |
|
429 | + public function get_summary($context = 'view') { |
|
430 | + return $this->get_description($context); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | * @param string $context View or edit context. |
438 | 438 | * @return string |
439 | 439 | */ |
440 | - public function get_author( $context = 'view' ) { |
|
441 | - return (int) $this->get_prop( 'author', $context ); |
|
440 | + public function get_author($context = 'view') { |
|
441 | + return (int) $this->get_prop('author', $context); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | /** |
@@ -448,8 +448,8 @@ discard block |
||
448 | 448 | * @param string $context View or edit context. |
449 | 449 | * @return string |
450 | 450 | */ |
451 | - public function get_code( $context = 'view' ) { |
|
452 | - return $this->get_prop( 'code', $context ); |
|
451 | + public function get_code($context = 'view') { |
|
452 | + return $this->get_prop('code', $context); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -459,8 +459,8 @@ discard block |
||
459 | 459 | * @param string $context View or edit context. |
460 | 460 | * @return string |
461 | 461 | */ |
462 | - public function get_coupon_code( $context = 'view' ) { |
|
463 | - return $this->get_code( $context ); |
|
462 | + public function get_coupon_code($context = 'view') { |
|
463 | + return $this->get_code($context); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -470,8 +470,8 @@ discard block |
||
470 | 470 | * @param string $context View or edit context. |
471 | 471 | * @return string |
472 | 472 | */ |
473 | - public function get_discount_code( $context = 'view' ) { |
|
474 | - return $this->get_code( $context ); |
|
473 | + public function get_discount_code($context = 'view') { |
|
474 | + return $this->get_code($context); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * @param string $context View or edit context. |
482 | 482 | * @return float |
483 | 483 | */ |
484 | - public function get_amount( $context = 'view' ) { |
|
485 | - return $context == 'view' ? floatval( $this->get_prop( 'amount', $context ) ) : $this->get_prop( 'amount', $context ); |
|
484 | + public function get_amount($context = 'view') { |
|
485 | + return $context == 'view' ? floatval($this->get_prop('amount', $context)) : $this->get_prop('amount', $context); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
@@ -493,13 +493,13 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function get_formatted_amount() { |
495 | 495 | |
496 | - if ( $this->is_type( 'flat' ) ) { |
|
497 | - $rate = wpinv_price( $this->get_amount() ); |
|
496 | + if ($this->is_type('flat')) { |
|
497 | + $rate = wpinv_price($this->get_amount()); |
|
498 | 498 | } else { |
499 | 499 | $rate = $this->get_amount() . '%'; |
500 | 500 | } |
501 | 501 | |
502 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
502 | + return apply_filters('wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount()); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * @param string $context View or edit context. |
510 | 510 | * @return string |
511 | 511 | */ |
512 | - public function get_start( $context = 'view' ) { |
|
513 | - return $this->get_prop( 'start', $context ); |
|
512 | + public function get_start($context = 'view') { |
|
513 | + return $this->get_prop('start', $context); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | * @param string $context View or edit context. |
521 | 521 | * @return string |
522 | 522 | */ |
523 | - public function get_start_date( $context = 'view' ) { |
|
524 | - return $this->get_start( $context ); |
|
523 | + public function get_start_date($context = 'view') { |
|
524 | + return $this->get_start($context); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | * @param string $context View or edit context. |
532 | 532 | * @return string |
533 | 533 | */ |
534 | - public function get_expiration( $context = 'view' ) { |
|
535 | - return $this->get_prop( 'expiration', $context ); |
|
534 | + public function get_expiration($context = 'view') { |
|
535 | + return $this->get_prop('expiration', $context); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -542,8 +542,8 @@ discard block |
||
542 | 542 | * @param string $context View or edit context. |
543 | 543 | * @return string |
544 | 544 | */ |
545 | - public function get_expiration_date( $context = 'view' ) { |
|
546 | - return $this->get_expiration( $context ); |
|
545 | + public function get_expiration_date($context = 'view') { |
|
546 | + return $this->get_expiration($context); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | * @param string $context View or edit context. |
554 | 554 | * @return string |
555 | 555 | */ |
556 | - public function get_end_date( $context = 'view' ) { |
|
557 | - return $this->get_expiration( $context ); |
|
556 | + public function get_end_date($context = 'view') { |
|
557 | + return $this->get_expiration($context); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -564,8 +564,8 @@ discard block |
||
564 | 564 | * @param string $context View or edit context. |
565 | 565 | * @return string |
566 | 566 | */ |
567 | - public function get_type( $context = 'view' ) { |
|
568 | - return $this->get_prop( 'type', $context ); |
|
567 | + public function get_type($context = 'view') { |
|
568 | + return $this->get_prop('type', $context); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -575,8 +575,8 @@ discard block |
||
575 | 575 | * @param string $context View or edit context. |
576 | 576 | * @return int |
577 | 577 | */ |
578 | - public function get_uses( $context = 'view' ) { |
|
579 | - return (int) $this->get_prop( 'uses', $context ); |
|
578 | + public function get_uses($context = 'view') { |
|
579 | + return (int) $this->get_prop('uses', $context); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function get_usage() { |
589 | 589 | |
590 | - if ( ! $this->has_limit() ) { |
|
590 | + if (!$this->has_limit()) { |
|
591 | 591 | return $this->get_uses() . ' / ' . ' ∞'; |
592 | 592 | } |
593 | 593 | |
@@ -602,9 +602,9 @@ discard block |
||
602 | 602 | * @param string $context View or edit context. |
603 | 603 | * @return int |
604 | 604 | */ |
605 | - public function get_max_uses( $context = 'view' ) { |
|
606 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
607 | - return empty( $max_uses ) ? null : $max_uses; |
|
605 | + public function get_max_uses($context = 'view') { |
|
606 | + $max_uses = $this->get_prop('max_uses', $context); |
|
607 | + return empty($max_uses) ? null : $max_uses; |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -614,8 +614,8 @@ discard block |
||
614 | 614 | * @param string $context View or edit context. |
615 | 615 | * @return bool |
616 | 616 | */ |
617 | - public function get_is_single_use( $context = 'view' ) { |
|
618 | - return $this->get_prop( 'is_single_use', $context ); |
|
617 | + public function get_is_single_use($context = 'view') { |
|
618 | + return $this->get_prop('is_single_use', $context); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -625,8 +625,8 @@ discard block |
||
625 | 625 | * @param string $context View or edit context. |
626 | 626 | * @return array |
627 | 627 | */ |
628 | - public function get_items( $context = 'view' ) { |
|
629 | - return array_filter( wp_parse_id_list( $this->get_prop( 'items', $context ) ) ); |
|
628 | + public function get_items($context = 'view') { |
|
629 | + return array_filter(wp_parse_id_list($this->get_prop('items', $context))); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
@@ -636,8 +636,8 @@ discard block |
||
636 | 636 | * @param string $context View or edit context. |
637 | 637 | * @return array |
638 | 638 | */ |
639 | - public function get_allowed_items( $context = 'view' ) { |
|
640 | - return $this->get_items( $context ); |
|
639 | + public function get_allowed_items($context = 'view') { |
|
640 | + return $this->get_items($context); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -647,8 +647,8 @@ discard block |
||
647 | 647 | * @param string $context View or edit context. |
648 | 648 | * @return array |
649 | 649 | */ |
650 | - public function get_excluded_items( $context = 'view' ) { |
|
651 | - return array_filter( wp_parse_id_list( $this->get_prop( 'excluded_items', $context ) ) ); |
|
650 | + public function get_excluded_items($context = 'view') { |
|
651 | + return array_filter(wp_parse_id_list($this->get_prop('excluded_items', $context))); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
@@ -658,8 +658,8 @@ discard block |
||
658 | 658 | * @param string $context View or edit context. |
659 | 659 | * @return array |
660 | 660 | */ |
661 | - public function get_required_items( $context = 'view' ) { |
|
662 | - return array_filter( wp_parse_id_list( $this->get_prop( 'required_items', $context ) ) ); |
|
661 | + public function get_required_items($context = 'view') { |
|
662 | + return array_filter(wp_parse_id_list($this->get_prop('required_items', $context))); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
@@ -669,8 +669,8 @@ discard block |
||
669 | 669 | * @param string $context View or edit context. |
670 | 670 | * @return int|string|bool |
671 | 671 | */ |
672 | - public function get_is_recurring( $context = 'view' ) { |
|
673 | - return $this->get_prop( 'is_recurring', $context ); |
|
672 | + public function get_is_recurring($context = 'view') { |
|
673 | + return $this->get_prop('is_recurring', $context); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
@@ -680,9 +680,9 @@ discard block |
||
680 | 680 | * @param string $context View or edit context. |
681 | 681 | * @return float |
682 | 682 | */ |
683 | - public function get_min_total( $context = 'view' ) { |
|
684 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
685 | - return empty( $minimum ) ? null : $minimum; |
|
683 | + public function get_min_total($context = 'view') { |
|
684 | + $minimum = $this->get_prop('min_total', $context); |
|
685 | + return empty($minimum) ? null : $minimum; |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | /** |
@@ -692,8 +692,8 @@ discard block |
||
692 | 692 | * @param string $context View or edit context. |
693 | 693 | * @return float |
694 | 694 | */ |
695 | - public function get_minimum_total( $context = 'view' ) { |
|
696 | - return $this->get_min_total( $context ); |
|
695 | + public function get_minimum_total($context = 'view') { |
|
696 | + return $this->get_min_total($context); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
@@ -703,9 +703,9 @@ discard block |
||
703 | 703 | * @param string $context View or edit context. |
704 | 704 | * @return float |
705 | 705 | */ |
706 | - public function get_max_total( $context = 'view' ) { |
|
707 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
708 | - return empty( $maximum ) ? null : $maximum; |
|
706 | + public function get_max_total($context = 'view') { |
|
707 | + $maximum = $this->get_prop('max_total', $context); |
|
708 | + return empty($maximum) ? null : $maximum; |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
@@ -715,8 +715,8 @@ discard block |
||
715 | 715 | * @param string $context View or edit context. |
716 | 716 | * @return float |
717 | 717 | */ |
718 | - public function get_maximum_total( $context = 'view' ) { |
|
719 | - return $this->get_max_total( $context ); |
|
718 | + public function get_maximum_total($context = 'view') { |
|
719 | + return $this->get_max_total($context); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -729,8 +729,8 @@ discard block |
||
729 | 729 | * @param string $context View or edit context. |
730 | 730 | * @return mixed Value of the given discount property (if set). |
731 | 731 | */ |
732 | - public function get( $key, $context = 'view' ) { |
|
733 | - return $this->get_prop( $key, $context ); |
|
732 | + public function get($key, $context = 'view') { |
|
733 | + return $this->get_prop($key, $context); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | /* |
@@ -750,10 +750,10 @@ discard block |
||
750 | 750 | * @param string $status New status. |
751 | 751 | * @return array details of change. |
752 | 752 | */ |
753 | - public function set_status( $status ) { |
|
753 | + public function set_status($status) { |
|
754 | 754 | $old_status = $this->get_status(); |
755 | 755 | |
756 | - $this->set_prop( 'status', $status ); |
|
756 | + $this->set_prop('status', $status); |
|
757 | 757 | |
758 | 758 | return array( |
759 | 759 | 'from' => $old_status, |
@@ -766,8 +766,8 @@ discard block |
||
766 | 766 | * |
767 | 767 | * @since 1.0.19 |
768 | 768 | */ |
769 | - public function set_version( $value ) { |
|
770 | - $this->set_prop( 'version', $value ); |
|
769 | + public function set_version($value) { |
|
770 | + $this->set_prop('version', $value); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
@@ -777,11 +777,11 @@ discard block |
||
777 | 777 | * @param string $value Value to set. |
778 | 778 | * @return bool Whether or not the date was set. |
779 | 779 | */ |
780 | - public function set_date_created( $value ) { |
|
781 | - $date = strtotime( $value ); |
|
780 | + public function set_date_created($value) { |
|
781 | + $date = strtotime($value); |
|
782 | 782 | |
783 | - if ( $date ) { |
|
784 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
783 | + if ($date) { |
|
784 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
785 | 785 | return true; |
786 | 786 | } |
787 | 787 | |
@@ -796,11 +796,11 @@ discard block |
||
796 | 796 | * @param string $value Value to set. |
797 | 797 | * @return bool Whether or not the date was set. |
798 | 798 | */ |
799 | - public function set_date_modified( $value ) { |
|
800 | - $date = strtotime( $value ); |
|
799 | + public function set_date_modified($value) { |
|
800 | + $date = strtotime($value); |
|
801 | 801 | |
802 | - if ( $date ) { |
|
803 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
802 | + if ($date) { |
|
803 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
804 | 804 | return true; |
805 | 805 | } |
806 | 806 | |
@@ -814,9 +814,9 @@ discard block |
||
814 | 814 | * @since 1.0.19 |
815 | 815 | * @param string $value New name. |
816 | 816 | */ |
817 | - public function set_name( $value ) { |
|
818 | - $name = sanitize_text_field( $value ); |
|
819 | - $this->set_prop( 'name', $name ); |
|
817 | + public function set_name($value) { |
|
818 | + $name = sanitize_text_field($value); |
|
819 | + $this->set_prop('name', $name); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | /** |
@@ -825,8 +825,8 @@ discard block |
||
825 | 825 | * @since 1.0.19 |
826 | 826 | * @param string $value New name. |
827 | 827 | */ |
828 | - public function set_title( $value ) { |
|
829 | - $this->set_name( $value ); |
|
828 | + public function set_title($value) { |
|
829 | + $this->set_name($value); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -835,9 +835,9 @@ discard block |
||
835 | 835 | * @since 1.0.19 |
836 | 836 | * @param string $value New description. |
837 | 837 | */ |
838 | - public function set_description( $value ) { |
|
839 | - $description = wp_kses_post( $value ); |
|
840 | - return $this->set_prop( 'description', $description ); |
|
838 | + public function set_description($value) { |
|
839 | + $description = wp_kses_post($value); |
|
840 | + return $this->set_prop('description', $description); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -846,8 +846,8 @@ discard block |
||
846 | 846 | * @since 1.0.19 |
847 | 847 | * @param string $value New description. |
848 | 848 | */ |
849 | - public function set_excerpt( $value ) { |
|
850 | - $this->set_description( $value ); |
|
849 | + public function set_excerpt($value) { |
|
850 | + $this->set_description($value); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -856,8 +856,8 @@ discard block |
||
856 | 856 | * @since 1.0.19 |
857 | 857 | * @param string $value New description. |
858 | 858 | */ |
859 | - public function set_summary( $value ) { |
|
860 | - $this->set_description( $value ); |
|
859 | + public function set_summary($value) { |
|
860 | + $this->set_description($value); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | /** |
@@ -866,8 +866,8 @@ discard block |
||
866 | 866 | * @since 1.0.19 |
867 | 867 | * @param int $value New author. |
868 | 868 | */ |
869 | - public function set_author( $value ) { |
|
870 | - $this->set_prop( 'author', (int) $value ); |
|
869 | + public function set_author($value) { |
|
870 | + $this->set_prop('author', (int) $value); |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | /** |
@@ -876,9 +876,9 @@ discard block |
||
876 | 876 | * @since 1.0.19 |
877 | 877 | * @param string $value New discount code. |
878 | 878 | */ |
879 | - public function set_code( $value ) { |
|
880 | - $code = sanitize_text_field( $value ); |
|
881 | - $this->set_prop( 'code', $code ); |
|
879 | + public function set_code($value) { |
|
880 | + $code = sanitize_text_field($value); |
|
881 | + $this->set_prop('code', $code); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -887,8 +887,8 @@ discard block |
||
887 | 887 | * @since 1.0.19 |
888 | 888 | * @param string $value New discount code. |
889 | 889 | */ |
890 | - public function set_coupon_code( $value ) { |
|
891 | - $this->set_code( $value ); |
|
890 | + public function set_coupon_code($value) { |
|
891 | + $this->set_code($value); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
@@ -897,8 +897,8 @@ discard block |
||
897 | 897 | * @since 1.0.19 |
898 | 898 | * @param string $value New discount code. |
899 | 899 | */ |
900 | - public function set_discount_code( $value ) { |
|
901 | - $this->set_code( $value ); |
|
900 | + public function set_discount_code($value) { |
|
901 | + $this->set_code($value); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | /** |
@@ -907,9 +907,9 @@ discard block |
||
907 | 907 | * @since 1.0.19 |
908 | 908 | * @param float $value New discount code. |
909 | 909 | */ |
910 | - public function set_amount( $value ) { |
|
911 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
912 | - $this->set_prop( 'amount', $amount ); |
|
910 | + public function set_amount($value) { |
|
911 | + $amount = floatval(wpinv_sanitize_amount($value)); |
|
912 | + $this->set_prop('amount', $amount); |
|
913 | 913 | } |
914 | 914 | |
915 | 915 | /** |
@@ -918,15 +918,15 @@ discard block |
||
918 | 918 | * @since 1.0.19 |
919 | 919 | * @param float $value New start date. |
920 | 920 | */ |
921 | - public function set_start( $value ) { |
|
922 | - $date = strtotime( $value ); |
|
921 | + public function set_start($value) { |
|
922 | + $date = strtotime($value); |
|
923 | 923 | |
924 | - if ( $date ) { |
|
925 | - $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
924 | + if ($date) { |
|
925 | + $this->set_prop('start', date('Y-m-d H:i', $date)); |
|
926 | 926 | return true; |
927 | 927 | } |
928 | 928 | |
929 | - $this->set_prop( 'start', '' ); |
|
929 | + $this->set_prop('start', ''); |
|
930 | 930 | |
931 | 931 | return false; |
932 | 932 | } |
@@ -937,8 +937,8 @@ discard block |
||
937 | 937 | * @since 1.0.19 |
938 | 938 | * @param string $value New start date. |
939 | 939 | */ |
940 | - public function set_start_date( $value ) { |
|
941 | - $this->set_start( $value ); |
|
940 | + public function set_start_date($value) { |
|
941 | + $this->set_start($value); |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | /** |
@@ -947,15 +947,15 @@ discard block |
||
947 | 947 | * @since 1.0.19 |
948 | 948 | * @param float $value New expiration date. |
949 | 949 | */ |
950 | - public function set_expiration( $value ) { |
|
951 | - $date = strtotime( $value ); |
|
950 | + public function set_expiration($value) { |
|
951 | + $date = strtotime($value); |
|
952 | 952 | |
953 | - if ( $date ) { |
|
954 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
|
953 | + if ($date) { |
|
954 | + $this->set_prop('expiration', date('Y-m-d H:i', $date)); |
|
955 | 955 | return true; |
956 | 956 | } |
957 | 957 | |
958 | - $this->set_prop( 'expiration', '' ); |
|
958 | + $this->set_prop('expiration', ''); |
|
959 | 959 | return false; |
960 | 960 | } |
961 | 961 | |
@@ -965,8 +965,8 @@ discard block |
||
965 | 965 | * @since 1.0.19 |
966 | 966 | * @param string $value New expiration date. |
967 | 967 | */ |
968 | - public function set_expiration_date( $value ) { |
|
969 | - $this->set_expiration( $value ); |
|
968 | + public function set_expiration_date($value) { |
|
969 | + $this->set_expiration($value); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
@@ -975,8 +975,8 @@ discard block |
||
975 | 975 | * @since 1.0.19 |
976 | 976 | * @param string $value New expiration date. |
977 | 977 | */ |
978 | - public function set_end_date( $value ) { |
|
979 | - $this->set_expiration( $value ); |
|
978 | + public function set_end_date($value) { |
|
979 | + $this->set_expiration($value); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
@@ -985,9 +985,9 @@ discard block |
||
985 | 985 | * @since 1.0.19 |
986 | 986 | * @param string $value New discount type. |
987 | 987 | */ |
988 | - public function set_type( $value ) { |
|
989 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
990 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
988 | + public function set_type($value) { |
|
989 | + if ($value && array_key_exists(sanitize_text_field($value), wpinv_get_discount_types())) { |
|
990 | + $this->set_prop('type', sanitize_text_field($value)); |
|
991 | 991 | } |
992 | 992 | } |
993 | 993 | |
@@ -997,15 +997,15 @@ discard block |
||
997 | 997 | * @since 1.0.19 |
998 | 998 | * @param int $value usage count. |
999 | 999 | */ |
1000 | - public function set_uses( $value ) { |
|
1000 | + public function set_uses($value) { |
|
1001 | 1001 | |
1002 | 1002 | $value = (int) $value; |
1003 | 1003 | |
1004 | - if ( $value < 0 ) { |
|
1004 | + if ($value < 0) { |
|
1005 | 1005 | $value = 0; |
1006 | 1006 | } |
1007 | 1007 | |
1008 | - $this->set_prop( 'uses', (int) $value ); |
|
1008 | + $this->set_prop('uses', (int) $value); |
|
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | /** |
@@ -1014,8 +1014,8 @@ discard block |
||
1014 | 1014 | * @since 1.0.19 |
1015 | 1015 | * @param int $value maximum usage count. |
1016 | 1016 | */ |
1017 | - public function set_max_uses( $value ) { |
|
1018 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
1017 | + public function set_max_uses($value) { |
|
1018 | + $this->set_prop('max_uses', absint($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 is single use. |
1026 | 1026 | */ |
1027 | - public function set_is_single_use( $value ) { |
|
1028 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
1027 | + public function set_is_single_use($value) { |
|
1028 | + $this->set_prop('is_single_use', (bool) $value); |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | /** |
@@ -1034,8 +1034,8 @@ discard block |
||
1034 | 1034 | * @since 1.0.19 |
1035 | 1035 | * @param array $value items. |
1036 | 1036 | */ |
1037 | - public function set_items( $value ) { |
|
1038 | - $this->set_prop( 'items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1037 | + public function set_items($value) { |
|
1038 | + $this->set_prop('items', array_filter(wp_parse_id_list($value))); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
@@ -1044,8 +1044,8 @@ discard block |
||
1044 | 1044 | * @since 1.0.19 |
1045 | 1045 | * @param array $value items. |
1046 | 1046 | */ |
1047 | - public function set_allowed_items( $value ) { |
|
1048 | - $this->set_items( $value ); |
|
1047 | + public function set_allowed_items($value) { |
|
1048 | + $this->set_items($value); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | /** |
@@ -1054,8 +1054,8 @@ discard block |
||
1054 | 1054 | * @since 1.0.19 |
1055 | 1055 | * @param array $value items. |
1056 | 1056 | */ |
1057 | - public function set_excluded_items( $value ) { |
|
1058 | - $this->set_prop( 'excluded_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1057 | + public function set_excluded_items($value) { |
|
1058 | + $this->set_prop('excluded_items', array_filter(wp_parse_id_list($value))); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | /** |
@@ -1064,8 +1064,8 @@ discard block |
||
1064 | 1064 | * @since 1.0.19 |
1065 | 1065 | * @param array $value items. |
1066 | 1066 | */ |
1067 | - public function set_required_items( $value ) { |
|
1068 | - $this->set_prop( 'required_items', array_filter( wp_parse_id_list( $value ) ) ); |
|
1067 | + public function set_required_items($value) { |
|
1068 | + $this->set_prop('required_items', array_filter(wp_parse_id_list($value))); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | /** |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @since 1.0.19 |
1075 | 1075 | * @param int|bool $value is recurring. |
1076 | 1076 | */ |
1077 | - public function set_is_recurring( $value ) { |
|
1078 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
1077 | + public function set_is_recurring($value) { |
|
1078 | + $this->set_prop('is_recurring', (bool) $value); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1084,8 +1084,8 @@ discard block |
||
1084 | 1084 | * @since 1.0.19 |
1085 | 1085 | * @param float $value minimum total. |
1086 | 1086 | */ |
1087 | - public function set_min_total( $value ) { |
|
1088 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1087 | + public function set_min_total($value) { |
|
1088 | + $this->set_prop('min_total', (float) wpinv_sanitize_amount($value)); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | /** |
@@ -1094,8 +1094,8 @@ discard block |
||
1094 | 1094 | * @since 1.0.19 |
1095 | 1095 | * @param float $value minimum total. |
1096 | 1096 | */ |
1097 | - public function set_minimum_total( $value ) { |
|
1098 | - $this->set_min_total( $value ); |
|
1097 | + public function set_minimum_total($value) { |
|
1098 | + $this->set_min_total($value); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | /** |
@@ -1104,8 +1104,8 @@ discard block |
||
1104 | 1104 | * @since 1.0.19 |
1105 | 1105 | * @param float $value maximum total. |
1106 | 1106 | */ |
1107 | - public function set_max_total( $value ) { |
|
1108 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
1107 | + public function set_max_total($value) { |
|
1108 | + $this->set_prop('max_total', (float) wpinv_sanitize_amount($value)); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
@@ -1114,23 +1114,23 @@ discard block |
||
1114 | 1114 | * @since 1.0.19 |
1115 | 1115 | * @param float $value maximum total. |
1116 | 1116 | */ |
1117 | - public function set_maximum_total( $value ) { |
|
1118 | - $this->set_max_total( $value ); |
|
1117 | + public function set_maximum_total($value) { |
|
1118 | + $this->set_max_total($value); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | /** |
1122 | 1122 | * @deprecated |
1123 | 1123 | */ |
1124 | - public function refresh(){} |
|
1124 | + public function refresh() {} |
|
1125 | 1125 | |
1126 | 1126 | /** |
1127 | 1127 | * @deprecated |
1128 | 1128 | * |
1129 | 1129 | */ |
1130 | - public function update_status( $status = 'publish' ) { |
|
1130 | + public function update_status($status = 'publish') { |
|
1131 | 1131 | |
1132 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
1133 | - $this->set_status( $status ); |
|
1132 | + if ($this->exists() && $this->get_status() != $status) { |
|
1133 | + $this->set_status($status); |
|
1134 | 1134 | $this->save(); |
1135 | 1135 | } |
1136 | 1136 | |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function exists() { |
1154 | 1154 | $id = $this->get_id(); |
1155 | - return ! empty( $id ); |
|
1155 | + return !empty($id); |
|
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | * @since 1.0.15 |
1164 | 1164 | * @return bool |
1165 | 1165 | */ |
1166 | - public function is_type( $type ) { |
|
1166 | + public function is_type($type) { |
|
1167 | 1167 | return $this->get_type() == $type; |
1168 | 1168 | } |
1169 | 1169 | |
@@ -1185,7 +1185,7 @@ discard block |
||
1185 | 1185 | */ |
1186 | 1186 | public function has_limit() { |
1187 | 1187 | $limit = $this->get_max_uses(); |
1188 | - return ! empty( $limit ); |
|
1188 | + return !empty($limit); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | /** |
@@ -1206,13 +1206,13 @@ discard block |
||
1206 | 1206 | */ |
1207 | 1207 | public function has_exceeded_limit() { |
1208 | 1208 | |
1209 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
1209 | + if (!$this->has_limit() || !$this->has_uses()) { |
|
1210 | 1210 | $exceeded = false; |
1211 | 1211 | } else { |
1212 | 1212 | $exceeded = (int) $this->get_max_uses() <= $this->get_uses(); |
1213 | 1213 | } |
1214 | 1214 | |
1215 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
1215 | + return apply_filters('wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code()); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | /** |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | */ |
1224 | 1224 | public function has_expiration_date() { |
1225 | 1225 | $date = $this->get_expiration_date(); |
1226 | - return ! empty( $date ); |
|
1226 | + return !empty($date); |
|
1227 | 1227 | } |
1228 | 1228 | |
1229 | 1229 | /** |
@@ -1233,8 +1233,8 @@ discard block |
||
1233 | 1233 | * @return bool |
1234 | 1234 | */ |
1235 | 1235 | public function is_expired() { |
1236 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
1237 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
1236 | + $expired = $this->has_expiration_date() ? current_time('timestamp') > strtotime($this->get_expiration_date()) : false; |
|
1237 | + return apply_filters('wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code()); |
|
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | /** |
@@ -1245,7 +1245,7 @@ discard block |
||
1245 | 1245 | */ |
1246 | 1246 | public function has_start_date() { |
1247 | 1247 | $date = $this->get_start_date(); |
1248 | - return ! empty( $date ); |
|
1248 | + return !empty($date); |
|
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | /** |
@@ -1255,8 +1255,8 @@ discard block |
||
1255 | 1255 | * @return bool |
1256 | 1256 | */ |
1257 | 1257 | public function has_started() { |
1258 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
1259 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
1258 | + $started = $this->has_start_date() ? true : current_time('timestamp') > strtotime($this->get_start_date()); |
|
1259 | + return apply_filters('wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code()); |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | /** |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | */ |
1268 | 1268 | public function has_allowed_items() { |
1269 | 1269 | $allowed_items = $this->get_allowed_items(); |
1270 | - return ! empty( $allowed_items ); |
|
1270 | + return !empty($allowed_items); |
|
1271 | 1271 | } |
1272 | 1272 | |
1273 | 1273 | /** |
@@ -1278,7 +1278,7 @@ discard block |
||
1278 | 1278 | */ |
1279 | 1279 | public function has_excluded_items() { |
1280 | 1280 | $excluded_items = $this->get_excluded_items(); |
1281 | - return ! empty( $excluded_items ); |
|
1281 | + return !empty($excluded_items); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | 1284 | /** |
@@ -1288,17 +1288,17 @@ discard block |
||
1288 | 1288 | * @since 1.0.15 |
1289 | 1289 | * @return boolean |
1290 | 1290 | */ |
1291 | - public function is_valid_for_items( $item_ids ) { |
|
1291 | + public function is_valid_for_items($item_ids) { |
|
1292 | 1292 | |
1293 | - $item_ids = array_filter( wp_parse_id_list( $item_ids ) ); |
|
1294 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
1295 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
1293 | + $item_ids = array_filter(wp_parse_id_list($item_ids)); |
|
1294 | + $included = array_intersect($item_ids, $this->get_allowed_items()); |
|
1295 | + $excluded = array_intersect($item_ids, $this->get_excluded_items()); |
|
1296 | 1296 | |
1297 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
1297 | + if ($this->has_excluded_items() && !empty($excluded)) { |
|
1298 | 1298 | return false; |
1299 | 1299 | } |
1300 | 1300 | |
1301 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
1301 | + if ($this->has_allowed_items() && empty($included)) { |
|
1302 | 1302 | return false; |
1303 | 1303 | } |
1304 | 1304 | |
@@ -1313,7 +1313,7 @@ discard block |
||
1313 | 1313 | */ |
1314 | 1314 | public function has_required_items() { |
1315 | 1315 | $required_items = $this->get_required_items(); |
1316 | - return ! empty( $required_items ); |
|
1316 | + return !empty($required_items); |
|
1317 | 1317 | } |
1318 | 1318 | |
1319 | 1319 | /** |
@@ -1323,13 +1323,13 @@ discard block |
||
1323 | 1323 | * @since 1.0.15 |
1324 | 1324 | * @return boolean |
1325 | 1325 | */ |
1326 | - public function is_required_items_met( $item_ids ) { |
|
1326 | + public function is_required_items_met($item_ids) { |
|
1327 | 1327 | |
1328 | - if ( ! $this->has_required_items() ) { |
|
1328 | + if (!$this->has_required_items()) { |
|
1329 | 1329 | return true; |
1330 | 1330 | } |
1331 | 1331 | |
1332 | - return ! array_diff( $this->get_required_items(), array_filter( wp_parse_id_list( $item_ids ) ) ); |
|
1332 | + return !array_diff($this->get_required_items(), array_filter(wp_parse_id_list($item_ids))); |
|
1333 | 1333 | } |
1334 | 1334 | |
1335 | 1335 | /** |
@@ -1339,8 +1339,8 @@ discard block |
||
1339 | 1339 | * @since 1.0.15 |
1340 | 1340 | * @return boolean |
1341 | 1341 | */ |
1342 | - public function is_valid_for_amount( $amount ) { |
|
1343 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
1342 | + public function is_valid_for_amount($amount) { |
|
1343 | + return $this->is_minimum_amount_met($amount) && $this->is_maximum_amount_met($amount); |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | 1346 | /** |
@@ -1351,7 +1351,7 @@ discard block |
||
1351 | 1351 | */ |
1352 | 1352 | public function has_minimum_amount() { |
1353 | 1353 | $minimum = $this->get_minimum_total(); |
1354 | - return ! empty( $minimum ); |
|
1354 | + return !empty($minimum); |
|
1355 | 1355 | } |
1356 | 1356 | |
1357 | 1357 | /** |
@@ -1361,10 +1361,10 @@ discard block |
||
1361 | 1361 | * @since 1.0.15 |
1362 | 1362 | * @return boolean |
1363 | 1363 | */ |
1364 | - public function is_minimum_amount_met( $amount ) { |
|
1365 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1366 | - $min_met = ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
1367 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1364 | + public function is_minimum_amount_met($amount) { |
|
1365 | + $amount = floatval(wpinv_sanitize_amount($amount)); |
|
1366 | + $min_met = !($this->has_minimum_amount() && $amount < floatval(wpinv_sanitize_amount($this->get_minimum_total()))); |
|
1367 | + return apply_filters('wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount); |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | /** |
@@ -1375,7 +1375,7 @@ discard block |
||
1375 | 1375 | */ |
1376 | 1376 | public function has_maximum_amount() { |
1377 | 1377 | $maximum = $this->get_maximum_total(); |
1378 | - return ! empty( $maximum ); |
|
1378 | + return !empty($maximum); |
|
1379 | 1379 | } |
1380 | 1380 | |
1381 | 1381 | /** |
@@ -1385,10 +1385,10 @@ discard block |
||
1385 | 1385 | * @since 1.0.15 |
1386 | 1386 | * @return boolean |
1387 | 1387 | */ |
1388 | - public function is_maximum_amount_met( $amount ) { |
|
1389 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
1390 | - $max_met = ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
1391 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
1388 | + public function is_maximum_amount_met($amount) { |
|
1389 | + $amount = floatval(wpinv_sanitize_amount($amount)); |
|
1390 | + $max_met = !($this->has_maximum_amount() && $amount > floatval(wpinv_sanitize_amount($this->get_maximum_total()))); |
|
1391 | + return apply_filters('wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount); |
|
1392 | 1392 | } |
1393 | 1393 | |
1394 | 1394 | /** |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | */ |
1400 | 1400 | public function is_recurring() { |
1401 | 1401 | $recurring = $this->get_is_recurring(); |
1402 | - return ! empty( $recurring ); |
|
1402 | + return !empty($recurring); |
|
1403 | 1403 | } |
1404 | 1404 | |
1405 | 1405 | /** |
@@ -1410,7 +1410,7 @@ discard block |
||
1410 | 1410 | */ |
1411 | 1411 | public function is_single_use() { |
1412 | 1412 | $usage = $this->get_is_single_use(); |
1413 | - return ! empty( $usage ); |
|
1413 | + return !empty($usage); |
|
1414 | 1414 | } |
1415 | 1415 | |
1416 | 1416 | /** |
@@ -1420,25 +1420,25 @@ discard block |
||
1420 | 1420 | * @since 1.0.15 |
1421 | 1421 | * @return boolean |
1422 | 1422 | */ |
1423 | - public function is_valid_for_user( $user ) { |
|
1423 | + public function is_valid_for_user($user) { |
|
1424 | 1424 | |
1425 | 1425 | // Ensure that the discount is single use. |
1426 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
1426 | + if (empty($user) || !$this->is_single_use()) { |
|
1427 | 1427 | return true; |
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | // Prepare the user id. |
1431 | 1431 | $user_id = 0; |
1432 | - if ( is_numeric( $user ) ) { |
|
1433 | - $user_id = absint( $user ); |
|
1434 | - } elseif ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
1432 | + if (is_numeric($user)) { |
|
1433 | + $user_id = absint($user); |
|
1434 | + } elseif (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
1435 | 1435 | $user_id = $user_data->ID; |
1436 | - } elseif ( $user_data = get_user_by( 'login', $user ) ) { |
|
1436 | + } elseif ($user_data = get_user_by('login', $user)) { |
|
1437 | 1437 | $user_id = $user_data->ID; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | // Ensure that we have a user. |
1441 | - if ( empty( $user_id ) ) { |
|
1441 | + if (empty($user_id)) { |
|
1442 | 1442 | return true; |
1443 | 1443 | } |
1444 | 1444 | |
@@ -1450,13 +1450,13 @@ discard block |
||
1450 | 1450 | 'paginate' => false, |
1451 | 1451 | ) |
1452 | 1452 | ); |
1453 | - $code = strtolower( $this->get_code() ); |
|
1453 | + $code = strtolower($this->get_code()); |
|
1454 | 1454 | |
1455 | 1455 | // For each payment... |
1456 | - foreach ( $payments as $payment ) { |
|
1456 | + foreach ($payments as $payment) { |
|
1457 | 1457 | |
1458 | 1458 | // Only check for paid invoices. |
1459 | - if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
1459 | + if ($payment->is_paid() && strtolower($payment->get_discount_code()) == $code) { |
|
1460 | 1460 | return false; |
1461 | 1461 | } |
1462 | 1462 | } |
@@ -1481,24 +1481,24 @@ discard block |
||
1481 | 1481 | * @param int $by The number of usages to increas by. |
1482 | 1482 | * @return int |
1483 | 1483 | */ |
1484 | - public function increase_usage( $by = 1 ) { |
|
1484 | + public function increase_usage($by = 1) { |
|
1485 | 1485 | |
1486 | 1486 | // Abort if zero. |
1487 | - if ( empty( $by ) ) { |
|
1487 | + if (empty($by)) { |
|
1488 | 1488 | return; |
1489 | 1489 | } |
1490 | 1490 | |
1491 | 1491 | // Increase the usage. |
1492 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
1492 | + $this->set_uses($this->get_uses() + (int) $by); |
|
1493 | 1493 | |
1494 | 1494 | // Save the discount. |
1495 | 1495 | $this->save(); |
1496 | 1496 | |
1497 | 1497 | // Fire relevant hooks. |
1498 | - if ( (int) $by > 0 ) { |
|
1499 | - do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1498 | + if ((int) $by > 0) { |
|
1499 | + do_action('wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint($by)); |
|
1500 | 1500 | } else { |
1501 | - do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
1501 | + do_action('wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint($by)); |
|
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | // Return the number of times the discount has been used. |
@@ -1522,7 +1522,7 @@ discard block |
||
1522 | 1522 | * @param float $amount |
1523 | 1523 | * @return float |
1524 | 1524 | */ |
1525 | - public function get_discounted_amount( $amount ) { |
|
1525 | + public function get_discounted_amount($amount) { |
|
1526 | 1526 | |
1527 | 1527 | // Convert amount to float. |
1528 | 1528 | $amount = (float) $amount; |
@@ -1530,29 +1530,29 @@ discard block |
||
1530 | 1530 | // Get discount amount. |
1531 | 1531 | $discount_amount = $this->get_amount(); |
1532 | 1532 | |
1533 | - if ( empty( $discount_amount ) ) { |
|
1533 | + if (empty($discount_amount)) { |
|
1534 | 1534 | return 0; |
1535 | 1535 | } |
1536 | 1536 | |
1537 | 1537 | // Format the amount. |
1538 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
1538 | + $discount_amount = floatval(wpinv_sanitize_amount($discount_amount)); |
|
1539 | 1539 | |
1540 | 1540 | // If this is a percentage discount. |
1541 | - if ( $this->is_type( 'percent' ) ) { |
|
1542 | - $discount_amount = $amount * ( $discount_amount / 100 ); |
|
1541 | + if ($this->is_type('percent')) { |
|
1542 | + $discount_amount = $amount * ($discount_amount / 100); |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | 1545 | // Discount can not be less than zero... |
1546 | - if ( $discount_amount < 0 ) { |
|
1546 | + if ($discount_amount < 0) { |
|
1547 | 1547 | $discount_amount = 0; |
1548 | 1548 | } |
1549 | 1549 | |
1550 | 1550 | // ... or more than the amount. |
1551 | - if ( $discount_amount > $amount ) { |
|
1551 | + if ($discount_amount > $amount) { |
|
1552 | 1552 | $discount_amount = $amount; |
1553 | 1553 | } |
1554 | 1554 | |
1555 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
1555 | + return apply_filters('wpinv_discount_total_discount_amount', $discount_amount, $amount, $this); |
|
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | } |
@@ -775,10 +775,10 @@ discard block |
||
775 | 775 | $allowed_fee_keys = apply_filters( |
776 | 776 | 'wpinv_fee_keys', |
777 | 777 | array( |
778 | - 'index', |
|
779 | - 'label', |
|
780 | - 'amount', |
|
781 | - 'type', |
|
778 | + 'index', |
|
779 | + 'label', |
|
780 | + 'amount', |
|
781 | + 'type', |
|
782 | 782 | ) |
783 | 783 | ); |
784 | 784 | |
@@ -850,19 +850,19 @@ discard block |
||
850 | 850 | $note_id = wp_insert_comment( |
851 | 851 | wp_filter_comment( |
852 | 852 | array( |
853 | - 'comment_post_ID' => $this->ID, |
|
854 | - 'comment_content' => $note, |
|
855 | - 'comment_agent' => 'WPInvoicing', |
|
856 | - 'user_id' => is_admin() ? get_current_user_id() : 0, |
|
857 | - 'comment_date' => current_time( 'mysql' ), |
|
858 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
859 | - 'comment_approved' => 1, |
|
860 | - 'comment_parent' => 0, |
|
861 | - 'comment_author' => $comment_author, |
|
862 | - 'comment_author_IP' => wpinv_get_ip(), |
|
863 | - 'comment_author_url' => '', |
|
864 | - 'comment_author_email' => $comment_author_email, |
|
865 | - 'comment_type' => 'wpinv_note', |
|
853 | + 'comment_post_ID' => $this->ID, |
|
854 | + 'comment_content' => $note, |
|
855 | + 'comment_agent' => 'WPInvoicing', |
|
856 | + 'user_id' => is_admin() ? get_current_user_id() : 0, |
|
857 | + 'comment_date' => current_time( 'mysql' ), |
|
858 | + 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
859 | + 'comment_approved' => 1, |
|
860 | + 'comment_parent' => 0, |
|
861 | + 'comment_author' => $comment_author, |
|
862 | + 'comment_author_IP' => wpinv_get_ip(), |
|
863 | + 'comment_author_url' => '', |
|
864 | + 'comment_author_email' => $comment_author_email, |
|
865 | + 'comment_type' => 'wpinv_note', |
|
866 | 866 | ) |
867 | 867 | ) |
868 | 868 | ); |
@@ -875,8 +875,8 @@ discard block |
||
875 | 875 | do_action( |
876 | 876 | 'wpinv_new_customer_note', |
877 | 877 | array( |
878 | - 'invoice_id' => $this->ID, |
|
879 | - 'user_note' => $note, |
|
878 | + 'invoice_id' => $this->ID, |
|
879 | + 'user_note' => $note, |
|
880 | 880 | ) |
881 | 881 | ); |
882 | 882 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * Invoice id. |
21 | 21 | */ |
22 | - public $ID = 0; |
|
22 | + public $ID = 0; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * The title of the invoice. Usually the invoice number. |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * The invoice status. |
137 | 137 | */ |
138 | - public $status = 'wpi-pending'; |
|
138 | + public $status = 'wpi-pending'; |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Same as self::$status. |
@@ -262,17 +262,17 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public $parent_invoice = 0; |
264 | 264 | |
265 | - public function __construct( $invoice_id = false ) { |
|
266 | - if ( empty( $invoice_id ) ) { |
|
265 | + public function __construct($invoice_id = false) { |
|
266 | + if (empty($invoice_id)) { |
|
267 | 267 | return false; |
268 | 268 | } |
269 | 269 | |
270 | - $this->setup_invoice( $invoice_id ); |
|
270 | + $this->setup_invoice($invoice_id); |
|
271 | 271 | } |
272 | 272 | |
273 | - public function get( $key ) { |
|
274 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
275 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
273 | + public function get($key) { |
|
274 | + if (method_exists($this, 'get_' . $key)) { |
|
275 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
276 | 276 | } else { |
277 | 277 | $value = $this->$key; |
278 | 278 | } |
@@ -280,43 +280,43 @@ discard block |
||
280 | 280 | return $value; |
281 | 281 | } |
282 | 282 | |
283 | - public function set( $key, $value ) { |
|
284 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
283 | + public function set($key, $value) { |
|
284 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
285 | 285 | |
286 | - if ( $key === 'status' ) { |
|
286 | + if ($key === 'status') { |
|
287 | 287 | $this->old_status = $this->status; |
288 | 288 | } |
289 | 289 | |
290 | - if ( ! in_array( $key, $ignore ) ) { |
|
291 | - $this->pending[ $key ] = $value; |
|
290 | + if (!in_array($key, $ignore)) { |
|
291 | + $this->pending[$key] = $value; |
|
292 | 292 | } |
293 | 293 | |
294 | - if ( '_ID' !== $key ) { |
|
294 | + if ('_ID' !== $key) { |
|
295 | 295 | $this->$key = $value; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | - public function _isset( $name ) { |
|
300 | - if ( property_exists( $this, $name ) ) { |
|
301 | - return false === empty( $this->$name ); |
|
299 | + public function _isset($name) { |
|
300 | + if (property_exists($this, $name)) { |
|
301 | + return false === empty($this->$name); |
|
302 | 302 | } else { |
303 | 303 | return null; |
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - private function setup_invoice( $invoice_id ) { |
|
307 | + private function setup_invoice($invoice_id) { |
|
308 | 308 | $this->pending = array(); |
309 | 309 | |
310 | - $invoice = get_post( $invoice_id ); |
|
310 | + $invoice = get_post($invoice_id); |
|
311 | 311 | |
312 | - if ( ! $invoice || is_wp_error( $invoice ) ) { |
|
312 | + if (!$invoice || is_wp_error($invoice)) { |
|
313 | 313 | return false; |
314 | 314 | } |
315 | 315 | |
316 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
316 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
317 | 317 | |
318 | 318 | // Primary Identifier |
319 | - $this->ID = absint( $invoice_id ); |
|
319 | + $this->ID = absint($invoice_id); |
|
320 | 320 | $this->post_type = $invoice->post_type; |
321 | 321 | |
322 | 322 | // We have a payment, get the generic payment_meta item to reduce calls to it |
@@ -326,15 +326,15 @@ discard block |
||
326 | 326 | $this->completed_date = $this->setup_completed_date(); |
327 | 327 | $this->status = $invoice->post_status; |
328 | 328 | |
329 | - if ( 'future' == $this->status ) { |
|
329 | + if ('future' == $this->status) { |
|
330 | 330 | $this->status = 'publish'; |
331 | 331 | } |
332 | 332 | |
333 | 333 | $this->post_status = $this->status; |
334 | 334 | $this->mode = $this->setup_mode(); |
335 | 335 | $this->parent_invoice = $invoice->post_parent; |
336 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
337 | - $this->status_nicename = $this->setup_status_nicename( $invoice->post_status ); |
|
336 | + $this->post_name = $this->setup_post_name($invoice); |
|
337 | + $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
|
338 | 338 | |
339 | 339 | // Items |
340 | 340 | $this->fees = $this->setup_fees(); |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | |
357 | 357 | // User based |
358 | 358 | $this->ip = $this->setup_ip(); |
359 | - $this->user_id = ! empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
360 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
359 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
360 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
361 | 361 | |
362 | 362 | $this->user_info = $this->setup_user_info(); |
363 | 363 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $this->company = $this->user_info['company']; |
367 | 367 | $this->vat_number = $this->user_info['vat_number']; |
368 | 368 | $this->vat_rate = $this->user_info['vat_rate']; |
369 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
369 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
370 | 370 | $this->address = $this->user_info['address']; |
371 | 371 | $this->city = $this->user_info['city']; |
372 | 372 | $this->country = $this->user_info['country']; |
@@ -381,31 +381,31 @@ discard block |
||
381 | 381 | // Other Identifiers |
382 | 382 | $this->key = $this->setup_invoice_key(); |
383 | 383 | $this->number = $this->setup_invoice_number(); |
384 | - $this->title = ! empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
384 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
385 | 385 | |
386 | - $this->full_name = trim( $this->first_name . ' ' . $this->last_name ); |
|
386 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
387 | 387 | |
388 | 388 | // Allow extensions to add items to this object via hook |
389 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
389 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
390 | 390 | |
391 | 391 | return true; |
392 | 392 | } |
393 | 393 | |
394 | - private function setup_status_nicename( $status ) { |
|
394 | + private function setup_status_nicename($status) { |
|
395 | 395 | return $status; |
396 | 396 | } |
397 | 397 | |
398 | - private function setup_post_name( $post ) { |
|
398 | + private function setup_post_name($post) { |
|
399 | 399 | $this->post_name = $post->post_name; |
400 | 400 | } |
401 | 401 | |
402 | 402 | private function setup_due_date() { |
403 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
403 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
404 | 404 | |
405 | - if ( empty( $due_date ) ) { |
|
406 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days', 0 ) ) ); |
|
407 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
408 | - } elseif ( $due_date == 'none' ) { |
|
405 | + if (empty($due_date)) { |
|
406 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days', 0))); |
|
407 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
408 | + } elseif ($due_date == 'none') { |
|
409 | 409 | $due_date = ''; |
410 | 410 | } |
411 | 411 | |
@@ -413,67 +413,67 @@ discard block |
||
413 | 413 | } |
414 | 414 | |
415 | 415 | private function setup_completed_date() { |
416 | - $invoice = get_post( $this->ID ); |
|
416 | + $invoice = get_post($this->ID); |
|
417 | 417 | |
418 | - if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
418 | + if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
419 | 419 | return false; // This invoice was never paid |
420 | 420 | } |
421 | 421 | |
422 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
422 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
423 | 423 | |
424 | 424 | return $date; |
425 | 425 | } |
426 | 426 | |
427 | 427 | private function setup_cart_details() { |
428 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
428 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
429 | 429 | return $cart_details; |
430 | 430 | } |
431 | 431 | |
432 | 432 | public function array_convert() { |
433 | - return get_object_vars( $this ); |
|
433 | + return get_object_vars($this); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | private function setup_items() { |
437 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
437 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
438 | 438 | return $items; |
439 | 439 | } |
440 | 440 | |
441 | 441 | private function setup_fees() { |
442 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
442 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
443 | 443 | return $payment_fees; |
444 | 444 | } |
445 | 445 | |
446 | 446 | private function setup_currency() { |
447 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
447 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
448 | 448 | return $currency; |
449 | 449 | } |
450 | 450 | |
451 | 451 | private function setup_discount() { |
452 | 452 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
453 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total ); |
|
454 | - if ( $discount < 0 ) { |
|
453 | + $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total); |
|
454 | + if ($discount < 0) { |
|
455 | 455 | $discount = 0; |
456 | 456 | } |
457 | - $discount = wpinv_round_amount( $discount ); |
|
457 | + $discount = wpinv_round_amount($discount); |
|
458 | 458 | |
459 | 459 | return $discount; |
460 | 460 | } |
461 | 461 | |
462 | 462 | private function setup_discount_code() { |
463 | - $discount_code = ! empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
463 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
464 | 464 | return $discount_code; |
465 | 465 | } |
466 | 466 | |
467 | 467 | private function setup_tax() { |
468 | 468 | |
469 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
469 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
470 | 470 | |
471 | 471 | // We don't have tax as it's own meta and no meta was passed |
472 | - if ( '' === $tax ) { |
|
473 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
472 | + if ('' === $tax) { |
|
473 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
474 | 474 | } |
475 | 475 | |
476 | - if ( $tax < 0 || ! $this->is_taxable() ) { |
|
476 | + if ($tax < 0 || !$this->is_taxable()) { |
|
477 | 477 | $tax = 0; |
478 | 478 | } |
479 | 479 | |
@@ -484,16 +484,16 @@ discard block |
||
484 | 484 | * If taxes are enabled, allow users to enable/disable taxes per invoice. |
485 | 485 | */ |
486 | 486 | private function setup_is_taxable() { |
487 | - return (int) $this->get_meta( '_wpinv_disable_taxes', true ); |
|
487 | + return (int) $this->get_meta('_wpinv_disable_taxes', true); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | private function setup_subtotal() { |
491 | 491 | $subtotal = 0; |
492 | 492 | $cart_details = $this->cart_details; |
493 | 493 | |
494 | - if ( is_array( $cart_details ) ) { |
|
495 | - foreach ( $cart_details as $item ) { |
|
496 | - if ( isset( $item['subtotal'] ) ) { |
|
494 | + if (is_array($cart_details)) { |
|
495 | + foreach ($cart_details as $item) { |
|
496 | + if (isset($item['subtotal'])) { |
|
497 | 497 | $subtotal += $item['subtotal']; |
498 | 498 | } |
499 | 499 | } |
@@ -507,23 +507,23 @@ discard block |
||
507 | 507 | } |
508 | 508 | |
509 | 509 | private function setup_discounts() { |
510 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
510 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
511 | 511 | return $discounts; |
512 | 512 | } |
513 | 513 | |
514 | 514 | private function setup_total() { |
515 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
515 | + $amount = $this->get_meta('_wpinv_total', true); |
|
516 | 516 | |
517 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
518 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
519 | - $meta = maybe_unserialize( $meta ); |
|
517 | + if (empty($amount) && '0.00' != $amount) { |
|
518 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
519 | + $meta = maybe_unserialize($meta); |
|
520 | 520 | |
521 | - if ( isset( $meta['amount'] ) ) { |
|
521 | + if (isset($meta['amount'])) { |
|
522 | 522 | $amount = $meta['amount']; |
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | - if ( $amount < 0 ) { |
|
526 | + if ($amount < 0) { |
|
527 | 527 | $amount = 0; |
528 | 528 | } |
529 | 529 | |
@@ -531,13 +531,13 @@ discard block |
||
531 | 531 | } |
532 | 532 | |
533 | 533 | private function setup_mode() { |
534 | - return $this->get_meta( '_wpinv_mode' ); |
|
534 | + return $this->get_meta('_wpinv_mode'); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | private function setup_gateway() { |
538 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
538 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
539 | 539 | |
540 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
540 | + if (empty($gateway) && 'publish' === $this->status) { |
|
541 | 541 | $gateway = 'manual'; |
542 | 542 | } |
543 | 543 | |
@@ -545,23 +545,23 @@ discard block |
||
545 | 545 | } |
546 | 546 | |
547 | 547 | private function setup_gateway_title() { |
548 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
548 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
549 | 549 | return $gateway_title; |
550 | 550 | } |
551 | 551 | |
552 | 552 | private function setup_transaction_id() { |
553 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
553 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
554 | 554 | |
555 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
555 | + if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) { |
|
556 | 556 | $gateway = $this->gateway; |
557 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
557 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | return $transaction_id; |
561 | 561 | } |
562 | 562 | |
563 | 563 | private function setup_ip() { |
564 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
564 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
565 | 565 | return $ip; |
566 | 566 | } |
567 | 567 | |
@@ -571,62 +571,62 @@ discard block |
||
571 | 571 | ///} |
572 | 572 | |
573 | 573 | private function setup_first_name() { |
574 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
574 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
575 | 575 | return $first_name; |
576 | 576 | } |
577 | 577 | |
578 | 578 | private function setup_last_name() { |
579 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
579 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
580 | 580 | return $last_name; |
581 | 581 | } |
582 | 582 | |
583 | 583 | private function setup_company() { |
584 | - $company = $this->get_meta( '_wpinv_company' ); |
|
584 | + $company = $this->get_meta('_wpinv_company'); |
|
585 | 585 | return $company; |
586 | 586 | } |
587 | 587 | |
588 | 588 | private function setup_vat_number() { |
589 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
589 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
590 | 590 | return $vat_number; |
591 | 591 | } |
592 | 592 | |
593 | 593 | private function setup_vat_rate() { |
594 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
594 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
595 | 595 | return $vat_rate; |
596 | 596 | } |
597 | 597 | |
598 | 598 | private function setup_adddress_confirmed() { |
599 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
599 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
600 | 600 | return $adddress_confirmed; |
601 | 601 | } |
602 | 602 | |
603 | 603 | private function setup_phone() { |
604 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
604 | + $phone = $this->get_meta('_wpinv_phone'); |
|
605 | 605 | return $phone; |
606 | 606 | } |
607 | 607 | |
608 | 608 | private function setup_address() { |
609 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
609 | + $address = $this->get_meta('_wpinv_address', true); |
|
610 | 610 | return $address; |
611 | 611 | } |
612 | 612 | |
613 | 613 | private function setup_city() { |
614 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
614 | + $city = $this->get_meta('_wpinv_city', true); |
|
615 | 615 | return $city; |
616 | 616 | } |
617 | 617 | |
618 | 618 | private function setup_country() { |
619 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
619 | + $country = $this->get_meta('_wpinv_country', true); |
|
620 | 620 | return $country; |
621 | 621 | } |
622 | 622 | |
623 | 623 | private function setup_state() { |
624 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
624 | + $state = $this->get_meta('_wpinv_state', true); |
|
625 | 625 | return $state; |
626 | 626 | } |
627 | 627 | |
628 | 628 | private function setup_zip() { |
629 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
629 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
630 | 630 | return $zip; |
631 | 631 | } |
632 | 632 | |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | 'user_id' => $this->user_id, |
636 | 636 | 'first_name' => $this->first_name, |
637 | 637 | 'last_name' => $this->last_name, |
638 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
638 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
639 | 639 | 'phone' => $this->phone, |
640 | 640 | 'address' => $this->address, |
641 | 641 | 'city' => $this->city, |
@@ -650,12 +650,12 @@ discard block |
||
650 | 650 | ); |
651 | 651 | |
652 | 652 | $user_info = array(); |
653 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
654 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
653 | + if (isset($this->payment_meta['user_info'])) { |
|
654 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
655 | 655 | |
656 | - if ( ! empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
656 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
657 | 657 | $this->user_id = $post->post_author; |
658 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
658 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
659 | 659 | |
660 | 660 | $user_info['user_id'] = $this->user_id; |
661 | 661 | $user_info['email'] = $this->email; |
@@ -664,13 +664,13 @@ discard block |
||
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
667 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
667 | + $user_info = wp_parse_args($user_info, $defaults); |
|
668 | 668 | |
669 | 669 | // Get the user, but only if it's been created |
670 | - $user = get_userdata( $this->user_id ); |
|
670 | + $user = get_userdata($this->user_id); |
|
671 | 671 | |
672 | - if ( ! empty( $user ) && $user->ID > 0 ) { |
|
673 | - if ( empty( $user_info ) ) { |
|
672 | + if (!empty($user) && $user->ID > 0) { |
|
673 | + if (empty($user_info)) { |
|
674 | 674 | $user_info = array( |
675 | 675 | 'user_id' => $user->ID, |
676 | 676 | 'first_name' => $user->first_name, |
@@ -679,23 +679,23 @@ discard block |
||
679 | 679 | 'discount' => '', |
680 | 680 | ); |
681 | 681 | } else { |
682 | - foreach ( $user_info as $key => $value ) { |
|
683 | - if ( ! empty( $value ) ) { |
|
682 | + foreach ($user_info as $key => $value) { |
|
683 | + if (!empty($value)) { |
|
684 | 684 | continue; |
685 | 685 | } |
686 | 686 | |
687 | - switch ( $key ) { |
|
687 | + switch ($key) { |
|
688 | 688 | case 'user_id': |
689 | - $user_info[ $key ] = $user->ID; |
|
689 | + $user_info[$key] = $user->ID; |
|
690 | 690 | break; |
691 | 691 | case 'first_name': |
692 | - $user_info[ $key ] = $user->first_name; |
|
692 | + $user_info[$key] = $user->first_name; |
|
693 | 693 | break; |
694 | 694 | case 'last_name': |
695 | - $user_info[ $key ] = $user->last_name; |
|
695 | + $user_info[$key] = $user->last_name; |
|
696 | 696 | break; |
697 | 697 | case 'email': |
698 | - $user_info[ $key ] = $user->user_email; |
|
698 | + $user_info[$key] = $user->user_email; |
|
699 | 699 | break; |
700 | 700 | } |
701 | 701 | } |
@@ -706,25 +706,25 @@ discard block |
||
706 | 706 | } |
707 | 707 | |
708 | 708 | private function setup_invoice_key() { |
709 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
709 | + $key = $this->get_meta('_wpinv_key', true); |
|
710 | 710 | |
711 | 711 | return $key; |
712 | 712 | } |
713 | 713 | |
714 | 714 | private function setup_invoice_number() { |
715 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
715 | + $number = $this->get_meta('_wpinv_number', true); |
|
716 | 716 | |
717 | - if ( ! $number ) { |
|
717 | + if (!$number) { |
|
718 | 718 | $number = $this->ID; |
719 | 719 | |
720 | - if ( $this->status == 'auto-draft' ) { |
|
721 | - if ( wpinv_sequential_number_active( $this->post_type ) ) { |
|
722 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
720 | + if ($this->status == 'auto-draft') { |
|
721 | + if (wpinv_sequential_number_active($this->post_type)) { |
|
722 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
723 | 723 | $number = $next_number; |
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
727 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | return $number; |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | |
733 | 733 | public function save() {} |
734 | 734 | |
735 | - public function add_fee( $args ) { |
|
735 | + public function add_fee($args) { |
|
736 | 736 | $default_args = array( |
737 | 737 | 'label' => '', |
738 | 738 | 'amount' => 0, |
@@ -742,36 +742,36 @@ discard block |
||
742 | 742 | 'item_id' => 0, |
743 | 743 | ); |
744 | 744 | |
745 | - $fee = wp_parse_args( $args, $default_args ); |
|
745 | + $fee = wp_parse_args($args, $default_args); |
|
746 | 746 | |
747 | - if ( empty( $fee['label'] ) ) { |
|
747 | + if (empty($fee['label'])) { |
|
748 | 748 | return false; |
749 | 749 | } |
750 | 750 | |
751 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
751 | + $fee['id'] = sanitize_title($fee['label']); |
|
752 | 752 | |
753 | - $this->fees[] = $fee; |
|
753 | + $this->fees[] = $fee; |
|
754 | 754 | |
755 | 755 | $added_fee = $fee; |
756 | 756 | $added_fee['action'] = 'add'; |
757 | 757 | $this->pending['fees'][] = $added_fee; |
758 | - reset( $this->fees ); |
|
758 | + reset($this->fees); |
|
759 | 759 | |
760 | - $this->increase_fees( $fee['amount'] ); |
|
760 | + $this->increase_fees($fee['amount']); |
|
761 | 761 | return true; |
762 | 762 | } |
763 | 763 | |
764 | - public function remove_fee( $key ) { |
|
764 | + public function remove_fee($key) { |
|
765 | 765 | $removed = false; |
766 | 766 | |
767 | - if ( is_numeric( $key ) ) { |
|
768 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
767 | + if (is_numeric($key)) { |
|
768 | + $removed = $this->remove_fee_by('index', $key); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | return $removed; |
772 | 772 | } |
773 | 773 | |
774 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
774 | + public function remove_fee_by($key, $value, $global = false) { |
|
775 | 775 | $allowed_fee_keys = apply_filters( |
776 | 776 | 'wpinv_fee_keys', |
777 | 777 | array( |
@@ -782,41 +782,41 @@ discard block |
||
782 | 782 | ) |
783 | 783 | ); |
784 | 784 | |
785 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
785 | + if (!in_array($key, $allowed_fee_keys)) { |
|
786 | 786 | return false; |
787 | 787 | } |
788 | 788 | |
789 | 789 | $removed = false; |
790 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
791 | - $removed_fee = $this->fees[ $value ]; |
|
790 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
791 | + $removed_fee = $this->fees[$value]; |
|
792 | 792 | $removed_fee['action'] = 'remove'; |
793 | 793 | $this->pending['fees'][] = $removed_fee; |
794 | 794 | |
795 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
795 | + $this->decrease_fees($removed_fee['amount']); |
|
796 | 796 | |
797 | - unset( $this->fees[ $value ] ); |
|
797 | + unset($this->fees[$value]); |
|
798 | 798 | $removed = true; |
799 | - } elseif ( 'index' !== $key ) { |
|
800 | - foreach ( $this->fees as $index => $fee ) { |
|
801 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
799 | + } elseif ('index' !== $key) { |
|
800 | + foreach ($this->fees as $index => $fee) { |
|
801 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
802 | 802 | $removed_fee = $fee; |
803 | 803 | $removed_fee['action'] = 'remove'; |
804 | 804 | $this->pending['fees'][] = $removed_fee; |
805 | 805 | |
806 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
806 | + $this->decrease_fees($removed_fee['amount']); |
|
807 | 807 | |
808 | - unset( $this->fees[ $index ] ); |
|
808 | + unset($this->fees[$index]); |
|
809 | 809 | $removed = true; |
810 | 810 | |
811 | - if ( false === $global ) { |
|
811 | + if (false === $global) { |
|
812 | 812 | break; |
813 | 813 | } |
814 | 814 | } |
815 | 815 | } |
816 | 816 | } |
817 | 817 | |
818 | - if ( true === $removed ) { |
|
819 | - $this->fees = array_values( $this->fees ); |
|
818 | + if (true === $removed) { |
|
819 | + $this->fees = array_values($this->fees); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | return $removed; |
@@ -824,28 +824,28 @@ discard block |
||
824 | 824 | |
825 | 825 | |
826 | 826 | |
827 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
827 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
828 | 828 | // Bail if no note specified |
829 | - if ( ! $note ) { |
|
829 | + if (!$note) { |
|
830 | 830 | return false; |
831 | 831 | } |
832 | 832 | |
833 | - if ( empty( $this->ID ) ) { |
|
833 | + if (empty($this->ID)) { |
|
834 | 834 | return false; |
835 | 835 | } |
836 | 836 | |
837 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && ! $system ) { |
|
838 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
837 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
838 | + $user = get_user_by('id', get_current_user_id()); |
|
839 | 839 | $comment_author = $user->display_name; |
840 | 840 | $comment_author_email = $user->user_email; |
841 | 841 | } else { |
842 | 842 | $comment_author = 'System'; |
843 | 843 | $comment_author_email = 'system@'; |
844 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
845 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
844 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
845 | + $comment_author_email = sanitize_email($comment_author_email); |
|
846 | 846 | } |
847 | 847 | |
848 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
848 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
849 | 849 | |
850 | 850 | $note_id = wp_insert_comment( |
851 | 851 | wp_filter_comment( |
@@ -854,8 +854,8 @@ discard block |
||
854 | 854 | 'comment_content' => $note, |
855 | 855 | 'comment_agent' => 'WPInvoicing', |
856 | 856 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
857 | - 'comment_date' => current_time( 'mysql' ), |
|
858 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
857 | + 'comment_date' => current_time('mysql'), |
|
858 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
859 | 859 | 'comment_approved' => 1, |
860 | 860 | 'comment_parent' => 0, |
861 | 861 | 'comment_author' => $comment_author, |
@@ -867,10 +867,10 @@ discard block |
||
867 | 867 | ) |
868 | 868 | ); |
869 | 869 | |
870 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
870 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
871 | 871 | |
872 | - if ( $customer_type ) { |
|
873 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
872 | + if ($customer_type) { |
|
873 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
874 | 874 | |
875 | 875 | do_action( |
876 | 876 | 'wpinv_new_customer_note', |
@@ -884,40 +884,40 @@ discard block |
||
884 | 884 | return $note_id; |
885 | 885 | } |
886 | 886 | |
887 | - private function increase_subtotal( $amount = 0.00 ) { |
|
887 | + private function increase_subtotal($amount = 0.00) { |
|
888 | 888 | $amount = (float) $amount; |
889 | 889 | $this->subtotal += $amount; |
890 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
890 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
891 | 891 | |
892 | 892 | $this->recalculate_total(); |
893 | 893 | } |
894 | 894 | |
895 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
895 | + private function decrease_subtotal($amount = 0.00) { |
|
896 | 896 | $amount = (float) $amount; |
897 | 897 | $this->subtotal -= $amount; |
898 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
898 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
899 | 899 | |
900 | - if ( $this->subtotal < 0 ) { |
|
900 | + if ($this->subtotal < 0) { |
|
901 | 901 | $this->subtotal = 0; |
902 | 902 | } |
903 | 903 | |
904 | 904 | $this->recalculate_total(); |
905 | 905 | } |
906 | 906 | |
907 | - private function increase_fees( $amount = 0.00 ) { |
|
908 | - $amount = (float)$amount; |
|
907 | + private function increase_fees($amount = 0.00) { |
|
908 | + $amount = (float) $amount; |
|
909 | 909 | $this->fees_total += $amount; |
910 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
910 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
911 | 911 | |
912 | 912 | $this->recalculate_total(); |
913 | 913 | } |
914 | 914 | |
915 | - private function decrease_fees( $amount = 0.00 ) { |
|
915 | + private function decrease_fees($amount = 0.00) { |
|
916 | 916 | $amount = (float) $amount; |
917 | 917 | $this->fees_total -= $amount; |
918 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
918 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
919 | 919 | |
920 | - if ( $this->fees_total < 0 ) { |
|
920 | + if ($this->fees_total < 0) { |
|
921 | 921 | $this->fees_total = 0; |
922 | 922 | } |
923 | 923 | |
@@ -928,56 +928,56 @@ discard block |
||
928 | 928 | global $wpi_nosave; |
929 | 929 | |
930 | 930 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
931 | - $this->total = wpinv_round_amount( $this->total ); |
|
931 | + $this->total = wpinv_round_amount($this->total); |
|
932 | 932 | |
933 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
933 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
934 | 934 | } |
935 | 935 | |
936 | - public function increase_tax( $amount = 0.00 ) { |
|
936 | + public function increase_tax($amount = 0.00) { |
|
937 | 937 | $amount = (float) $amount; |
938 | 938 | $this->tax += $amount; |
939 | 939 | |
940 | 940 | $this->recalculate_total(); |
941 | 941 | } |
942 | 942 | |
943 | - public function decrease_tax( $amount = 0.00 ) { |
|
943 | + public function decrease_tax($amount = 0.00) { |
|
944 | 944 | $amount = (float) $amount; |
945 | 945 | $this->tax -= $amount; |
946 | 946 | |
947 | - if ( $this->tax < 0 ) { |
|
947 | + if ($this->tax < 0) { |
|
948 | 948 | $this->tax = 0; |
949 | 949 | } |
950 | 950 | |
951 | 951 | $this->recalculate_total(); |
952 | 952 | } |
953 | 953 | |
954 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
955 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
954 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
955 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
956 | 956 | |
957 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
957 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
958 | 958 | return false; // Don't permit status changes that aren't changes |
959 | 959 | } |
960 | 960 | |
961 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
961 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
962 | 962 | $updated = false; |
963 | 963 | |
964 | - if ( $do_change ) { |
|
965 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
964 | + if ($do_change) { |
|
965 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
966 | 966 | |
967 | 967 | $update_post_data = array(); |
968 | 968 | $update_post_data['ID'] = $this->ID; |
969 | 969 | $update_post_data['post_status'] = $new_status; |
970 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
971 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
970 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
971 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
972 | 972 | |
973 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
973 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
974 | 974 | |
975 | - $updated = wp_update_post( $update_post_data ); |
|
975 | + $updated = wp_update_post($update_post_data); |
|
976 | 976 | |
977 | 977 | // Status was changed. |
978 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
979 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
980 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
978 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
979 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
980 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | return $updated; |
@@ -994,114 +994,114 @@ discard block |
||
994 | 994 | public function update_meta() {} |
995 | 995 | |
996 | 996 | // get data |
997 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
998 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
997 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
998 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
999 | 999 | |
1000 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1000 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1001 | 1001 | |
1002 | - if ( ! is_array( $meta ) ) { |
|
1003 | -$meta = array();} // we need this to be an array so make sure it is. |
|
1002 | + if (!is_array($meta)) { |
|
1003 | +$meta = array(); } // we need this to be an array so make sure it is. |
|
1004 | 1004 | |
1005 | - if ( empty( $meta['key'] ) ) { |
|
1005 | + if (empty($meta['key'])) { |
|
1006 | 1006 | $meta['key'] = $this->setup_invoice_key(); |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if ( empty( $meta['date'] ) ) { |
|
1010 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1009 | + if (empty($meta['date'])) { |
|
1010 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1011 | 1011 | } |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1014 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1015 | 1015 | |
1016 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1016 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | public function get_description() { |
1020 | - $post = get_post( $this->ID ); |
|
1020 | + $post = get_post($this->ID); |
|
1021 | 1021 | |
1022 | - $description = ! empty( $post ) ? $post->post_content : ''; |
|
1023 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1022 | + $description = !empty($post) ? $post->post_content : ''; |
|
1023 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | - public function get_status( $nicename = false ) { |
|
1027 | - if ( ! $nicename ) { |
|
1026 | + public function get_status($nicename = false) { |
|
1027 | + if (!$nicename) { |
|
1028 | 1028 | $status = $this->status; |
1029 | 1029 | } else { |
1030 | 1030 | $status = $this->status_nicename; |
1031 | 1031 | } |
1032 | 1032 | |
1033 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1033 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | public function get_cart_details() { |
1037 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1037 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | - public function get_subtotal( $currency = false ) { |
|
1041 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
1040 | + public function get_subtotal($currency = false) { |
|
1041 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
1042 | 1042 | |
1043 | - if ( $currency ) { |
|
1044 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, null, ! $currency ), $this->get_currency() ); |
|
1043 | + if ($currency) { |
|
1044 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, null, !$currency), $this->get_currency()); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1047 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | - public function get_total( $currency = false ) { |
|
1051 | - if ( $this->is_free_trial() ) { |
|
1052 | - $total = wpinv_round_amount( 0 ); |
|
1050 | + public function get_total($currency = false) { |
|
1051 | + if ($this->is_free_trial()) { |
|
1052 | + $total = wpinv_round_amount(0); |
|
1053 | 1053 | } else { |
1054 | - $total = wpinv_round_amount( $this->total ); |
|
1054 | + $total = wpinv_round_amount($this->total); |
|
1055 | 1055 | } |
1056 | - if ( $currency ) { |
|
1057 | - $total = wpinv_price( wpinv_format_amount( $total, null, ! $currency ), $this->get_currency() ); |
|
1056 | + if ($currency) { |
|
1057 | + $total = wpinv_price(wpinv_format_amount($total, null, !$currency), $this->get_currency()); |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1060 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | public function get_recurring_details() {} |
1064 | 1064 | |
1065 | - public function get_final_tax( $currency = false ) { |
|
1066 | - $final_total = wpinv_round_amount( $this->tax ); |
|
1067 | - if ( $currency ) { |
|
1068 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, null, ! $currency ), $this->get_currency() ); |
|
1065 | + public function get_final_tax($currency = false) { |
|
1066 | + $final_total = wpinv_round_amount($this->tax); |
|
1067 | + if ($currency) { |
|
1068 | + $final_total = wpinv_price(wpinv_format_amount($final_total, null, !$currency), $this->get_currency()); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1071 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | - public function get_discounts( $array = false ) { |
|
1074 | + public function get_discounts($array = false) { |
|
1075 | 1075 | $discounts = $this->discounts; |
1076 | - if ( $array && $discounts ) { |
|
1077 | - $discounts = explode( ',', $discounts ); |
|
1076 | + if ($array && $discounts) { |
|
1077 | + $discounts = explode(',', $discounts); |
|
1078 | 1078 | } |
1079 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1079 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | - public function get_discount( $currency = false, $dash = false ) { |
|
1083 | - if ( ! empty( $this->discounts ) ) { |
|
1082 | + public function get_discount($currency = false, $dash = false) { |
|
1083 | + if (!empty($this->discounts)) { |
|
1084 | 1084 | global $ajax_cart_details; |
1085 | 1085 | $ajax_cart_details = $this->get_cart_details(); |
1086 | 1086 | |
1087 | - if ( ! empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
1087 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
1088 | 1088 | $cart_items = $ajax_cart_details; |
1089 | 1089 | } else { |
1090 | 1090 | $cart_items = $this->items; |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items, $this->discounts ); |
|
1093 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
1094 | 1094 | } |
1095 | - $discount = wpinv_round_amount( $this->discount ); |
|
1095 | + $discount = wpinv_round_amount($this->discount); |
|
1096 | 1096 | $dash = $dash && $discount > 0 ? '–' : ''; |
1097 | 1097 | |
1098 | - if ( $currency ) { |
|
1099 | - $discount = wpinv_price( wpinv_format_amount( $discount, null, ! $currency ), $this->get_currency() ); |
|
1098 | + if ($currency) { |
|
1099 | + $discount = wpinv_price(wpinv_format_amount($discount, null, !$currency), $this->get_currency()); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | - $discount = $dash . $discount; |
|
1102 | + $discount = $dash . $discount; |
|
1103 | 1103 | |
1104 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1104 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1105 | 1105 | } |
1106 | 1106 | |
1107 | 1107 | public function get_discount_code() { |
@@ -1113,150 +1113,150 @@ discard block |
||
1113 | 1113 | return (int) $this->disable_taxes === 0; |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - public function get_tax( $currency = false ) { |
|
1117 | - $tax = wpinv_round_amount( $this->tax ); |
|
1116 | + public function get_tax($currency = false) { |
|
1117 | + $tax = wpinv_round_amount($this->tax); |
|
1118 | 1118 | |
1119 | - if ( $currency ) { |
|
1120 | - $tax = wpinv_price( wpinv_format_amount( $tax, null, ! $currency ), $this->get_currency() ); |
|
1119 | + if ($currency) { |
|
1120 | + $tax = wpinv_price(wpinv_format_amount($tax, null, !$currency), $this->get_currency()); |
|
1121 | 1121 | } |
1122 | 1122 | |
1123 | - if ( ! $this->is_taxable() ) { |
|
1124 | - $tax = wpinv_round_amount( 0.00 ); |
|
1123 | + if (!$this->is_taxable()) { |
|
1124 | + $tax = wpinv_round_amount(0.00); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1127 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | - public function get_fees( $type = 'all' ) { |
|
1131 | - $fees = array(); |
|
1130 | + public function get_fees($type = 'all') { |
|
1131 | + $fees = array(); |
|
1132 | 1132 | |
1133 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1134 | - foreach ( $this->fees as $fee ) { |
|
1135 | - if ( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1133 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1134 | + foreach ($this->fees as $fee) { |
|
1135 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1136 | 1136 | continue; |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1140 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1141 | - $fees[] = $fee; |
|
1139 | + $fee['label'] = stripslashes($fee['label']); |
|
1140 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1141 | + $fees[] = $fee; |
|
1142 | 1142 | } |
1143 | 1143 | } |
1144 | 1144 | |
1145 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1145 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1146 | 1146 | } |
1147 | 1147 | |
1148 | 1148 | public function get_fees_total() { |
1149 | 1149 | $fees_total = (float) 0.00; |
1150 | 1150 | |
1151 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1152 | - if ( ! empty( $payment_fees ) ) { |
|
1153 | - foreach ( $payment_fees as $fee ) { |
|
1151 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1152 | + if (!empty($payment_fees)) { |
|
1153 | + foreach ($payment_fees as $fee) { |
|
1154 | 1154 | $fees_total += (float) $fee['amount']; |
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1158 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1159 | 1159 | |
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | public function get_user_id() { |
1163 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1163 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | public function get_first_name() { |
1167 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1167 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | public function get_last_name() { |
1171 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1171 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | public function get_user_full_name() { |
1175 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1175 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | public function get_user_info() { |
1179 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1179 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | public function get_email() { |
1183 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1183 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | public function get_address() { |
1187 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1187 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | public function get_phone() { |
1191 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1191 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1192 | 1192 | } |
1193 | 1193 | |
1194 | 1194 | public function get_number() { |
1195 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1195 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | public function get_items() { |
1199 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1199 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1200 | 1200 | } |
1201 | 1201 | |
1202 | 1202 | public function get_key() { |
1203 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1203 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1204 | 1204 | } |
1205 | 1205 | |
1206 | 1206 | public function get_transaction_id() { |
1207 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1207 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | public function get_gateway() { |
1211 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1211 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | public function get_gateway_title() {} |
1215 | 1215 | |
1216 | 1216 | public function get_currency() { |
1217 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1217 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | public function get_created_date() { |
1221 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1221 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | - public function get_due_date( $display = false ) { |
|
1225 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1224 | + public function get_due_date($display = false) { |
|
1225 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1226 | 1226 | |
1227 | - if ( ! $display ) { |
|
1227 | + if (!$display) { |
|
1228 | 1228 | return $due_date; |
1229 | 1229 | } |
1230 | 1230 | |
1231 | - return getpaid_format_date( $this->due_date ); |
|
1231 | + return getpaid_format_date($this->due_date); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | public function get_completed_date() { |
1235 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1235 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | - public function get_invoice_date( $formatted = true ) { |
|
1238 | + public function get_invoice_date($formatted = true) { |
|
1239 | 1239 | $date_completed = $this->completed_date; |
1240 | 1240 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1241 | 1241 | |
1242 | - if ( $invoice_date == '' ) { |
|
1242 | + if ($invoice_date == '') { |
|
1243 | 1243 | $date_created = $this->date; |
1244 | 1244 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1245 | 1245 | } |
1246 | 1246 | |
1247 | - if ( $formatted && $invoice_date ) { |
|
1248 | - $invoice_date = getpaid_format_date( $invoice_date ); |
|
1247 | + if ($formatted && $invoice_date) { |
|
1248 | + $invoice_date = getpaid_format_date($invoice_date); |
|
1249 | 1249 | } |
1250 | 1250 | |
1251 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1251 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | public function get_ip() { |
1255 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1255 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | - public function has_status( $status ) { |
|
1259 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1258 | + public function has_status($status) { |
|
1259 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | public function add_item() {} |
@@ -1273,66 +1273,66 @@ discard block |
||
1273 | 1273 | |
1274 | 1274 | public function get_view_url() {} |
1275 | 1275 | |
1276 | - public function generate_key( $string = '' ) { |
|
1277 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
1278 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
1276 | + public function generate_key($string = '') { |
|
1277 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
1278 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | 1281 | public function is_recurring() { |
1282 | - if ( empty( $this->cart_details ) ) { |
|
1282 | + if (empty($this->cart_details)) { |
|
1283 | 1283 | return false; |
1284 | 1284 | } |
1285 | 1285 | |
1286 | 1286 | $has_subscription = false; |
1287 | - foreach ( $this->cart_details as $cart_item ) { |
|
1288 | - if ( ! empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
1287 | + foreach ($this->cart_details as $cart_item) { |
|
1288 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
1289 | 1289 | $has_subscription = true; |
1290 | 1290 | break; |
1291 | 1291 | } |
1292 | 1292 | } |
1293 | 1293 | |
1294 | - if ( count( $this->cart_details ) > 1 ) { |
|
1294 | + if (count($this->cart_details) > 1) { |
|
1295 | 1295 | $has_subscription = false; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
1298 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | 1301 | public function is_free_trial() { |
1302 | 1302 | $is_free_trial = false; |
1303 | 1303 | |
1304 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
1305 | - if ( ! empty( $item ) && $item->has_free_trial() ) { |
|
1304 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
1305 | + if (!empty($item) && $item->has_free_trial()) { |
|
1306 | 1306 | $is_free_trial = true; |
1307 | 1307 | } |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
1310 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | 1313 | public function is_initial_free() {} |
1314 | 1314 | |
1315 | - public function get_recurring( $object = false ) { |
|
1315 | + public function get_recurring($object = false) { |
|
1316 | 1316 | $item = null; |
1317 | 1317 | |
1318 | - if ( empty( $this->cart_details ) ) { |
|
1318 | + if (empty($this->cart_details)) { |
|
1319 | 1319 | return $item; |
1320 | 1320 | } |
1321 | 1321 | |
1322 | - foreach ( $this->cart_details as $cart_item ) { |
|
1323 | - if ( ! empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
1322 | + foreach ($this->cart_details as $cart_item) { |
|
1323 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
1324 | 1324 | $item = $cart_item['id']; |
1325 | 1325 | break; |
1326 | 1326 | } |
1327 | 1327 | } |
1328 | 1328 | |
1329 | - if ( $object ) { |
|
1330 | - $item = $item ? new WPInv_Item( $item ) : null; |
|
1329 | + if ($object) { |
|
1330 | + $item = $item ? new WPInv_Item($item) : null; |
|
1331 | 1331 | |
1332 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
1332 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
1333 | 1333 | } |
1334 | 1334 | |
1335 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
1335 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | public function get_subscription_name() {} |
@@ -1340,7 +1340,7 @@ discard block |
||
1340 | 1340 | public function get_subscription_id() {} |
1341 | 1341 | |
1342 | 1342 | public function is_parent() { |
1343 | - return ! empty( $this->parent_invoice ); |
|
1343 | + return !empty($this->parent_invoice); |
|
1344 | 1344 | } |
1345 | 1345 | |
1346 | 1346 | public function is_renewal() {} |
@@ -1354,8 +1354,8 @@ discard block |
||
1354 | 1354 | public function is_refunded() {} |
1355 | 1355 | |
1356 | 1356 | public function is_free() { |
1357 | - $total = (float) wpinv_round_amount( $this->get_total() ); |
|
1358 | - return $total > 0 && ! $this->is_recurring(); |
|
1357 | + $total = (float) wpinv_round_amount($this->get_total()); |
|
1358 | + return $total > 0 && !$this->is_recurring(); |
|
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | public function has_vat() {} |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | ?> |
12 | 12 | |
13 | 13 | <hr class="featurette-divider" /> |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | <p> |
4 | 4 | <?php |
5 | 5 | echo wp_sprintf( |
6 | - wp_kses_post( __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ) ), |
|
7 | - esc_url_raw( remove_query_arg( 'payment-confirm' ) ) |
|
6 | + wp_kses_post(__('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing')), |
|
7 | + esc_url_raw(remove_query_arg('payment-confirm')) |
|
8 | 8 | ); |
9 | 9 | ?> |
10 | 10 | <i class="fa fa-spin fa-refresh"></i> |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | <script type="text/javascript"> |
14 | 14 | setTimeout( |
15 | 15 | function(){ |
16 | - window.location.href = '<?php echo esc_url_raw( remove_query_arg( 'payment-confirm' ) ); ?>'; |
|
16 | + window.location.href = '<?php echo esc_url_raw(remove_query_arg('payment-confirm')); ?>'; |
|
17 | 17 | }, |
18 | 18 | 10000 |
19 | 19 | ); |