@@ -12,80 +12,80 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // For default forms, ensure that an item has been set. |
|
38 | + if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | + } |
|
42 | + |
|
43 | + // Process each individual item. |
|
44 | + foreach ( $payment_form->get_items() as $item ) { |
|
45 | + $this->process_item( $item, $selected_items, $submission ); |
|
46 | + } |
|
47 | + |
|
48 | + } |
|
20 | 49 | |
21 | 50 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // For default forms, ensure that an item has been set. |
|
38 | - if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | - } |
|
42 | - |
|
43 | - // Process each individual item. |
|
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items, $submission ); |
|
46 | - } |
|
47 | - |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Process a single item. |
|
52 | - * |
|
53 | - * @param GetPaid_Form_Item $item |
|
54 | - * @param array $selected_items |
|
55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
56 | - */ |
|
57 | - public function process_item( $item, $selected_items, $submission ) { |
|
58 | - |
|
59 | - // Abort if this is an optional item and it has not been selected. |
|
60 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - // (maybe) let customers change the quantities and prices. |
|
65 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
66 | - |
|
67 | - // Maybe change the quantities. |
|
68 | - if ( $item->allows_quantities() ) { |
|
69 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
70 | - } |
|
71 | - |
|
72 | - // Maybe change the price. |
|
73 | - if ( $item->user_can_set_their_price() ) { |
|
74 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
75 | - |
|
76 | - if ( $item->get_minimum_price() > $price ) { |
|
77 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
78 | - } |
|
79 | - |
|
80 | - $item->set_price( $price ); |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - // Save the item. |
|
87 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
88 | - |
|
89 | - } |
|
51 | + * Process a single item. |
|
52 | + * |
|
53 | + * @param GetPaid_Form_Item $item |
|
54 | + * @param array $selected_items |
|
55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
56 | + */ |
|
57 | + public function process_item( $item, $selected_items, $submission ) { |
|
58 | + |
|
59 | + // Abort if this is an optional item and it has not been selected. |
|
60 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + // (maybe) let customers change the quantities and prices. |
|
65 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
66 | + |
|
67 | + // Maybe change the quantities. |
|
68 | + if ( $item->allows_quantities() ) { |
|
69 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
70 | + } |
|
71 | + |
|
72 | + // Maybe change the price. |
|
73 | + if ( $item->user_can_set_their_price() ) { |
|
74 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
75 | + |
|
76 | + if ( $item->get_minimum_price() > $price ) { |
|
77 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
78 | + } |
|
79 | + |
|
80 | + $item->set_price( $price ); |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + // Save the item. |
|
87 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
88 | + |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |
@@ -12,114 +12,114 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data, $submission ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + * @param GetPaid_Payment_Form_Submission $submission |
|
63 | + */ |
|
64 | + public function process_price_input( $element, $data, $submission ) { |
|
65 | + |
|
66 | + // Abort if not passed. |
|
67 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | + |
|
74 | + if ( $amount < $minimum ) { |
|
75 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | + } |
|
77 | + |
|
78 | + $this->fees[ $element['label'] ] = array( |
|
79 | + 'name' => $element['label'], |
|
80 | + 'initial_fee' => $amount, |
|
81 | + 'recurring_fee' => 0, |
|
82 | + ); |
|
83 | + |
|
84 | + } |
|
26 | 85 | |
27 | 86 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - * @param GetPaid_Payment_Form_Submission $submission |
|
63 | - */ |
|
64 | - public function process_price_input( $element, $data, $submission ) { |
|
65 | - |
|
66 | - // Abort if not passed. |
|
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | - |
|
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | - } |
|
77 | - |
|
78 | - $this->fees[ $element['label'] ] = array( |
|
79 | - 'name' => $element['label'], |
|
80 | - 'initial_fee' => $amount, |
|
81 | - 'recurring_fee' => 0, |
|
82 | - ); |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Process a price select field. |
|
88 | - * |
|
89 | - * @param array $element |
|
90 | - * @param array $data |
|
91 | - */ |
|
92 | - public function process_price_select( $element, $data ) { |
|
93 | - |
|
94 | - // Abort if not passed. |
|
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | - $total = 0; |
|
102 | - $sub_labels = array(); |
|
103 | - |
|
104 | - foreach ( $selected as $price ) { |
|
105 | - |
|
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | - } |
|
109 | - |
|
110 | - $price = explode( '|', $price ); |
|
111 | - |
|
112 | - $sub_labels[] = $price[0]; |
|
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | - } |
|
115 | - |
|
116 | - $this->fees[ $element['label'] ] = array( |
|
117 | - 'name' => $element['label'], |
|
118 | - 'initial_fee' => $total, |
|
119 | - 'recurring_fee' => 0, |
|
120 | - 'description' => implode( ', ', $sub_labels ), |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
87 | + * Process a price select field. |
|
88 | + * |
|
89 | + * @param array $element |
|
90 | + * @param array $data |
|
91 | + */ |
|
92 | + public function process_price_select( $element, $data ) { |
|
93 | + |
|
94 | + // Abort if not passed. |
|
95 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | + $total = 0; |
|
102 | + $sub_labels = array(); |
|
103 | + |
|
104 | + foreach ( $selected as $price ) { |
|
105 | + |
|
106 | + if ( ! isset( $options[ $price ] ) ) { |
|
107 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | + } |
|
109 | + |
|
110 | + $price = explode( '|', $price ); |
|
111 | + |
|
112 | + $sub_labels[] = $price[0]; |
|
113 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | + } |
|
115 | + |
|
116 | + $this->fees[ $element['label'] ] = array( |
|
117 | + 'name' => $element['label'], |
|
118 | + 'initial_fee' => $total, |
|
119 | + 'recurring_fee' => 0, |
|
120 | + 'description' => implode( ', ', $sub_labels ), |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -17,397 +17,397 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Add admin menus/screens. |
|
56 | - * |
|
57 | - * @since 2.4.0 |
|
58 | - */ |
|
59 | - public function add_menu() { |
|
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets up the setup wizard. |
|
65 | - * |
|
66 | - * @since 2.4.0 |
|
67 | - */ |
|
68 | - public function setup_wizard() { |
|
69 | - |
|
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | - $this->setup_globals(); |
|
72 | - $this->maybe_save_current_step(); |
|
73 | - $this->display_wizard(); |
|
74 | - exit; |
|
75 | - } |
|
76 | - |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets up class variables. |
|
81 | - * |
|
82 | - * @since 2.4.0 |
|
83 | - */ |
|
84 | - protected function setup_globals() { |
|
85 | - $this->steps = $this->get_setup_steps(); |
|
86 | - $this->step = $this->get_current_step(); |
|
87 | - $this->previous_step = $this->get_previous_step(); |
|
88 | - $this->next_step = $this->get_next_step(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Saves the current step. |
|
93 | - * |
|
94 | - * @since 2.4.0 |
|
95 | - */ |
|
96 | - protected function maybe_save_current_step() { |
|
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the setup steps. |
|
104 | - * |
|
105 | - * @since 2.4.0 |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function get_setup_steps() { |
|
109 | - |
|
110 | - $steps = array( |
|
111 | - |
|
112 | - 'introduction' => array( |
|
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
115 | - 'handler' => '', |
|
116 | - ), |
|
117 | - |
|
118 | - 'business_details' => array( |
|
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
121 | - 'handler' => '', |
|
122 | - ), |
|
123 | - |
|
124 | - 'currency' => array( |
|
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
127 | - 'handler' => '', |
|
128 | - ), |
|
129 | - |
|
130 | - 'payments' => array( |
|
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | - ), |
|
135 | - |
|
136 | - 'recommend' => array( |
|
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
139 | - 'handler' => '', |
|
140 | - ), |
|
141 | - |
|
142 | - 'next_steps' => array( |
|
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
145 | - 'handler' => '', |
|
146 | - ), |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the current step. |
|
156 | - * |
|
157 | - * @since 2.4.0 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function get_current_step() { |
|
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the previous step. |
|
167 | - * |
|
168 | - * @since 2.4.0 |
|
169 | - * @return string|false |
|
170 | - */ |
|
171 | - protected function get_previous_step() { |
|
172 | - |
|
173 | - $previous = false; |
|
174 | - $current = $this->step; |
|
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
177 | - return $previous; |
|
178 | - } |
|
179 | - |
|
180 | - $previous = $step; |
|
181 | - } |
|
182 | - |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the next step. |
|
188 | - * |
|
189 | - * @since 2.4.0 |
|
190 | - * @return string|false |
|
191 | - */ |
|
192 | - protected function get_next_step() { |
|
193 | - |
|
194 | - $on_current = false; |
|
195 | - $current = $this->step; |
|
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | - |
|
198 | - if ( $on_current ) { |
|
199 | - return $step; |
|
200 | - } |
|
201 | - |
|
202 | - if ( $current === $step ) { |
|
203 | - return $on_current = true; |
|
204 | - } |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Displays the setup wizard. |
|
213 | - * |
|
214 | - * @since 2.4.0 |
|
215 | - */ |
|
216 | - public function display_wizard() { |
|
217 | - $this->display_header(); |
|
218 | - $this->display_current_step(); |
|
219 | - $this->display_footer(); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Displays the Wizard Header. |
|
224 | - * |
|
225 | - * @since 2.0.0 |
|
226 | - */ |
|
227 | - public function display_header() { |
|
228 | - $steps = $this->steps; |
|
229 | - $current = $this->step; |
|
230 | - $next_step = $this->next_step; |
|
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Displays the content for the current step. |
|
237 | - * |
|
238 | - * @since 2.4.0 |
|
239 | - */ |
|
240 | - public function display_current_step() { |
|
241 | - ?> |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Add admin menus/screens. |
|
56 | + * |
|
57 | + * @since 2.4.0 |
|
58 | + */ |
|
59 | + public function add_menu() { |
|
60 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets up the setup wizard. |
|
65 | + * |
|
66 | + * @since 2.4.0 |
|
67 | + */ |
|
68 | + public function setup_wizard() { |
|
69 | + |
|
70 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + $this->setup_globals(); |
|
72 | + $this->maybe_save_current_step(); |
|
73 | + $this->display_wizard(); |
|
74 | + exit; |
|
75 | + } |
|
76 | + |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets up class variables. |
|
81 | + * |
|
82 | + * @since 2.4.0 |
|
83 | + */ |
|
84 | + protected function setup_globals() { |
|
85 | + $this->steps = $this->get_setup_steps(); |
|
86 | + $this->step = $this->get_current_step(); |
|
87 | + $this->previous_step = $this->get_previous_step(); |
|
88 | + $this->next_step = $this->get_next_step(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Saves the current step. |
|
93 | + * |
|
94 | + * @since 2.4.0 |
|
95 | + */ |
|
96 | + protected function maybe_save_current_step() { |
|
97 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the setup steps. |
|
104 | + * |
|
105 | + * @since 2.4.0 |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function get_setup_steps() { |
|
109 | + |
|
110 | + $steps = array( |
|
111 | + |
|
112 | + 'introduction' => array( |
|
113 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | + 'view' => array( $this, 'setup_introduction' ), |
|
115 | + 'handler' => '', |
|
116 | + ), |
|
117 | + |
|
118 | + 'business_details' => array( |
|
119 | + 'name' => __( "Business Details", 'invoicing' ), |
|
120 | + 'view' => array( $this, 'setup_business' ), |
|
121 | + 'handler' => '', |
|
122 | + ), |
|
123 | + |
|
124 | + 'currency' => array( |
|
125 | + 'name' => __( 'Currency', 'invoicing' ), |
|
126 | + 'view' => array( $this, 'setup_currency' ), |
|
127 | + 'handler' => '', |
|
128 | + ), |
|
129 | + |
|
130 | + 'payments' => array( |
|
131 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | + 'view' => array( $this, 'setup_payments' ), |
|
133 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | + ), |
|
135 | + |
|
136 | + 'recommend' => array( |
|
137 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | + 'view' => array( $this, 'setup_recommend' ), |
|
139 | + 'handler' => '', |
|
140 | + ), |
|
141 | + |
|
142 | + 'next_steps' => array( |
|
143 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | + 'view' => array( $this, 'setup_ready' ), |
|
145 | + 'handler' => '', |
|
146 | + ), |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the current step. |
|
156 | + * |
|
157 | + * @since 2.4.0 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function get_current_step() { |
|
161 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the previous step. |
|
167 | + * |
|
168 | + * @since 2.4.0 |
|
169 | + * @return string|false |
|
170 | + */ |
|
171 | + protected function get_previous_step() { |
|
172 | + |
|
173 | + $previous = false; |
|
174 | + $current = $this->step; |
|
175 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | + if ( $current === $step ) { |
|
177 | + return $previous; |
|
178 | + } |
|
179 | + |
|
180 | + $previous = $step; |
|
181 | + } |
|
182 | + |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the next step. |
|
188 | + * |
|
189 | + * @since 2.4.0 |
|
190 | + * @return string|false |
|
191 | + */ |
|
192 | + protected function get_next_step() { |
|
193 | + |
|
194 | + $on_current = false; |
|
195 | + $current = $this->step; |
|
196 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | + |
|
198 | + if ( $on_current ) { |
|
199 | + return $step; |
|
200 | + } |
|
201 | + |
|
202 | + if ( $current === $step ) { |
|
203 | + return $on_current = true; |
|
204 | + } |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Displays the setup wizard. |
|
213 | + * |
|
214 | + * @since 2.4.0 |
|
215 | + */ |
|
216 | + public function display_wizard() { |
|
217 | + $this->display_header(); |
|
218 | + $this->display_current_step(); |
|
219 | + $this->display_footer(); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Displays the Wizard Header. |
|
224 | + * |
|
225 | + * @since 2.0.0 |
|
226 | + */ |
|
227 | + public function display_header() { |
|
228 | + $steps = $this->steps; |
|
229 | + $current = $this->step; |
|
230 | + $next_step = $this->next_step; |
|
231 | + array_shift( $steps ); |
|
232 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Displays the content for the current step. |
|
237 | + * |
|
238 | + * @since 2.4.0 |
|
239 | + */ |
|
240 | + public function display_current_step() { |
|
241 | + ?> |
|
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | 244 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Setup Wizard Footer. |
|
252 | - * |
|
253 | - * @since 2.4.0 |
|
254 | - */ |
|
255 | - public function display_footer() { |
|
256 | - |
|
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | - |
|
261 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | - } |
|
263 | - |
|
264 | - echo '</body></html>'; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Introduction step. |
|
269 | - * |
|
270 | - * @since 2.0.0 |
|
271 | - */ |
|
272 | - public function setup_introduction() { |
|
273 | - $next_url = $this->get_next_step_link(); |
|
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get the URL for the next step's screen. |
|
279 | - * |
|
280 | - * @param string step slug (default: current step) |
|
281 | - * |
|
282 | - * @return string URL for next step if a next step exists. |
|
283 | - * Admin URL if it's the last step. |
|
284 | - * Empty string on failure. |
|
285 | - * @since 3.0.0 |
|
286 | - */ |
|
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
289 | - $step = $this->step; |
|
290 | - } |
|
291 | - |
|
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
294 | - return admin_url(); |
|
295 | - } |
|
296 | - |
|
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Setup maps api. |
|
307 | - * |
|
308 | - * @since 2.0.0 |
|
309 | - */ |
|
310 | - public function setup_business() { |
|
311 | - $next_url = $this->get_next_step_link(); |
|
312 | - $wizard = $this; |
|
313 | - $page = 'wpinv_settings_general_main'; |
|
314 | - $section = 'wpinv_settings_general_main'; |
|
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Default Location settings. |
|
320 | - * |
|
321 | - * @since 2.0.0 |
|
322 | - */ |
|
323 | - public function setup_currency() { |
|
324 | - $next_url = $this->get_next_step_link(); |
|
325 | - $wizard = $this; |
|
326 | - $page = 'wpinv_settings_general_currency_section'; |
|
327 | - $section = 'wpinv_settings_general_currency_section'; |
|
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Installation of recommended plugins. |
|
333 | - * |
|
334 | - * @since 1.0.0 |
|
335 | - */ |
|
336 | - public function setup_recommend() { |
|
337 | - $next_url = $this->get_next_step_link(); |
|
338 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * A list of recommended wp.org plugins. |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public static function get_recommend_wp_plugins(){ |
|
347 | - return array( |
|
348 | - 'ayecode-connect' => array( |
|
349 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | - 'slug' => 'ayecode-connect', |
|
352 | - 'name' => 'AyeCode Connect', |
|
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | - ), |
|
355 | - 'invoicing-quotes' => array( |
|
356 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | - 'slug' => 'invoicing-quotes', |
|
359 | - 'name' => 'Customer Quotes', |
|
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | - ), |
|
362 | - 'userswp' => array( |
|
363 | - 'file' => 'userswp/userswp.php', |
|
364 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | - 'slug' => 'userswp', |
|
366 | - 'name' => 'UsersWP', |
|
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | - ), |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Dummy Data setup. |
|
374 | - * |
|
375 | - * @since 2.4.0 |
|
376 | - */ |
|
377 | - public function setup_payments() { |
|
378 | - $next_url = $this->get_next_step_link(); |
|
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Dummy data save. |
|
384 | - * |
|
385 | - * This is done via ajax so we just pass onto the next step. |
|
386 | - * |
|
387 | - * @since 2.0.0 |
|
388 | - */ |
|
389 | - public function setup_payments_save() { |
|
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | - |
|
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | - } |
|
398 | - |
|
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | - exit; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Final step. |
|
405 | - * |
|
406 | - * @since 2.0.0 |
|
407 | - */ |
|
408 | - public function setup_ready() { |
|
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | - } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Setup Wizard Footer. |
|
252 | + * |
|
253 | + * @since 2.4.0 |
|
254 | + */ |
|
255 | + public function display_footer() { |
|
256 | + |
|
257 | + if ( isset( $_GET['step'] ) ) { |
|
258 | + $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | + |
|
261 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | + } |
|
263 | + |
|
264 | + echo '</body></html>'; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Introduction step. |
|
269 | + * |
|
270 | + * @since 2.0.0 |
|
271 | + */ |
|
272 | + public function setup_introduction() { |
|
273 | + $next_url = $this->get_next_step_link(); |
|
274 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get the URL for the next step's screen. |
|
279 | + * |
|
280 | + * @param string step slug (default: current step) |
|
281 | + * |
|
282 | + * @return string URL for next step if a next step exists. |
|
283 | + * Admin URL if it's the last step. |
|
284 | + * Empty string on failure. |
|
285 | + * @since 3.0.0 |
|
286 | + */ |
|
287 | + public function get_next_step_link( $step = '' ) { |
|
288 | + if ( ! $step ) { |
|
289 | + $step = $this->step; |
|
290 | + } |
|
291 | + |
|
292 | + $keys = array_keys( $this->steps ); |
|
293 | + if ( end( $keys ) === $step ) { |
|
294 | + return admin_url(); |
|
295 | + } |
|
296 | + |
|
297 | + $step_index = array_search( $step, $keys ); |
|
298 | + if ( false === $step_index ) { |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Setup maps api. |
|
307 | + * |
|
308 | + * @since 2.0.0 |
|
309 | + */ |
|
310 | + public function setup_business() { |
|
311 | + $next_url = $this->get_next_step_link(); |
|
312 | + $wizard = $this; |
|
313 | + $page = 'wpinv_settings_general_main'; |
|
314 | + $section = 'wpinv_settings_general_main'; |
|
315 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Default Location settings. |
|
320 | + * |
|
321 | + * @since 2.0.0 |
|
322 | + */ |
|
323 | + public function setup_currency() { |
|
324 | + $next_url = $this->get_next_step_link(); |
|
325 | + $wizard = $this; |
|
326 | + $page = 'wpinv_settings_general_currency_section'; |
|
327 | + $section = 'wpinv_settings_general_currency_section'; |
|
328 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Installation of recommended plugins. |
|
333 | + * |
|
334 | + * @since 1.0.0 |
|
335 | + */ |
|
336 | + public function setup_recommend() { |
|
337 | + $next_url = $this->get_next_step_link(); |
|
338 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * A list of recommended wp.org plugins. |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public static function get_recommend_wp_plugins(){ |
|
347 | + return array( |
|
348 | + 'ayecode-connect' => array( |
|
349 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | + 'slug' => 'ayecode-connect', |
|
352 | + 'name' => 'AyeCode Connect', |
|
353 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | + ), |
|
355 | + 'invoicing-quotes' => array( |
|
356 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | + 'slug' => 'invoicing-quotes', |
|
359 | + 'name' => 'Customer Quotes', |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | + ), |
|
362 | + 'userswp' => array( |
|
363 | + 'file' => 'userswp/userswp.php', |
|
364 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | + 'slug' => 'userswp', |
|
366 | + 'name' => 'UsersWP', |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | + ), |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Dummy Data setup. |
|
374 | + * |
|
375 | + * @since 2.4.0 |
|
376 | + */ |
|
377 | + public function setup_payments() { |
|
378 | + $next_url = $this->get_next_step_link(); |
|
379 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Dummy data save. |
|
384 | + * |
|
385 | + * This is done via ajax so we just pass onto the next step. |
|
386 | + * |
|
387 | + * @since 2.0.0 |
|
388 | + */ |
|
389 | + public function setup_payments_save() { |
|
390 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | + |
|
393 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | + wpinv_update_option( 'paypal_active', 1 ); |
|
396 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | + } |
|
398 | + |
|
399 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | + exit; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Final step. |
|
405 | + * |
|
406 | + * @since 2.0.0 |
|
407 | + */ |
|
408 | + public function setup_ready() { |
|
409 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
413 | 413 |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | $name = isset( $option['name'] ) ? $option['name'] : ''; |
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
198 | + $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
199 | 199 | |
200 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
201 | - $tip = wpinv_clean( $option['desc'] ); |
|
202 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
203 | - unset( $option['desc'] ); |
|
204 | - } |
|
200 | + if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
201 | + $tip = wpinv_clean( $option['desc'] ); |
|
202 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
203 | + unset( $option['desc'] ); |
|
204 | + } |
|
205 | 205 | |
206 | 206 | // Loop through all tabs. |
207 | 207 | add_settings_field( |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
229 | 229 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
230 | 230 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
231 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
232 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
233 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
231 | + 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
232 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
233 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
234 | 234 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
235 | 235 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
236 | 236 | ) |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return array |
245 | 245 | */ |
246 | 246 | function wpinv_get_registered_settings() { |
247 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
247 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -263,18 +263,18 @@ discard block |
||
263 | 263 | */ |
264 | 264 | function wpinv_settings_sanitize( $input = array() ) { |
265 | 265 | |
266 | - $wpinv_options = wpinv_get_options(); |
|
267 | - $raw_referrer = wp_get_raw_referer(); |
|
266 | + $wpinv_options = wpinv_get_options(); |
|
267 | + $raw_referrer = wp_get_raw_referer(); |
|
268 | 268 | |
269 | 269 | if ( empty( $raw_referrer ) ) { |
270 | - return array_merge( $wpinv_options, $input ); |
|
270 | + return array_merge( $wpinv_options, $input ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | wp_parse_str( $raw_referrer, $referrer ); |
274 | 274 | |
275 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
276 | - return array_merge( $wpinv_options, $input ); |
|
277 | - } |
|
275 | + if ( in_array( 'gp-setup', $referrer ) ) { |
|
276 | + return array_merge( $wpinv_options, $input ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | $settings = wpinv_get_registered_settings(); |
280 | 280 | $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | } |
297 | 297 | |
298 | 298 | // General filter |
299 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
299 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
300 | 300 | |
301 | - // Key specific filter. |
|
302 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
301 | + // Key specific filter. |
|
302 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -342,14 +342,14 @@ discard block |
||
342 | 342 | |
343 | 343 | foreach ( $new_rates as $rate ) { |
344 | 344 | |
345 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
346 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
347 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
348 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
349 | - $rate['global'] = empty( $rate['state'] ); |
|
350 | - $tax_rates[] = $rate; |
|
345 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
346 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
347 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
348 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
349 | + $rate['global'] = empty( $rate['state'] ); |
|
350 | + $tax_rates[] = $rate; |
|
351 | 351 | |
352 | - } |
|
352 | + } |
|
353 | 353 | |
354 | 354 | update_option( 'wpinv_tax_rates', $tax_rates ); |
355 | 355 | |
@@ -362,11 +362,11 @@ discard block |
||
362 | 362 | $tabs['general'] = __( 'General', 'invoicing' ); |
363 | 363 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
364 | 364 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
365 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
365 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
366 | 366 | |
367 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
368 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
369 | - } |
|
367 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
368 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
369 | + } |
|
370 | 370 | |
371 | 371 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
372 | 372 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | ) ), |
406 | 406 | 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
407 | 407 | 'main' => __( 'Tax Settings', 'invoicing' ), |
408 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
409 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
408 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
409 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ) |
|
410 | 410 | ) ), |
411 | 411 | 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
412 | 412 | 'main' => __( 'Email Settings', 'invoicing' ), |
413 | - ) ), |
|
413 | + ) ), |
|
414 | 414 | |
415 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
415 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
416 | 416 | |
417 | 417 | 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
418 | 418 | 'main' => __( 'Privacy policy', 'invoicing' ), |
@@ -432,48 +432,48 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
435 | - $pages_options = array(); |
|
435 | + $pages_options = array(); |
|
436 | 436 | |
437 | - if( $default_label !== NULL && $default_label !== false ) { |
|
438 | - $pages_options = array( '' => $default_label ); // Blank option |
|
439 | - } |
|
437 | + if( $default_label !== NULL && $default_label !== false ) { |
|
438 | + $pages_options = array( '' => $default_label ); // Blank option |
|
439 | + } |
|
440 | 440 | |
441 | - $pages = get_pages(); |
|
442 | - if ( $pages ) { |
|
443 | - foreach ( $pages as $page ) { |
|
444 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
441 | + $pages = get_pages(); |
|
442 | + if ( $pages ) { |
|
443 | + foreach ( $pages as $page ) { |
|
444 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
445 | 445 | $pages_options[ $page->ID ] = $title; |
446 | - } |
|
447 | - } |
|
446 | + } |
|
447 | + } |
|
448 | 448 | |
449 | - return $pages_options; |
|
449 | + return $pages_options; |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | function wpinv_header_callback( $args ) { |
453 | - if ( !empty( $args['desc'] ) ) { |
|
453 | + if ( !empty( $args['desc'] ) ) { |
|
454 | 454 | echo $args['desc']; |
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
458 | 458 | function wpinv_hidden_callback( $args ) { |
459 | 459 | |
460 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
461 | - $value = wpinv_get_option( $args['id'], $std ); |
|
460 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
461 | + $value = wpinv_get_option( $args['id'], $std ); |
|
462 | 462 | |
463 | - if ( isset( $args['set_value'] ) ) { |
|
464 | - $value = $args['set_value']; |
|
465 | - } |
|
463 | + if ( isset( $args['set_value'] ) ) { |
|
464 | + $value = $args['set_value']; |
|
465 | + } |
|
466 | 466 | |
467 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
468 | - $args['readonly'] = true; |
|
469 | - $name = ''; |
|
470 | - } else { |
|
471 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
472 | - } |
|
467 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
468 | + $args['readonly'] = true; |
|
469 | + $name = ''; |
|
470 | + } else { |
|
471 | + $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
472 | + } |
|
473 | 473 | |
474 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
474 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
475 | 475 | |
476 | - echo $html; |
|
476 | + echo $html; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -481,12 +481,12 @@ discard block |
||
481 | 481 | */ |
482 | 482 | function wpinv_checkbox_callback( $args ) { |
483 | 483 | |
484 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
485 | - $std = wpinv_get_option( $args['id'], $std ); |
|
486 | - $id = esc_attr( $args['id'] ); |
|
484 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
485 | + $std = wpinv_get_option( $args['id'], $std ); |
|
486 | + $id = esc_attr( $args['id'] ); |
|
487 | 487 | |
488 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
489 | - ?> |
|
488 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
489 | + ?> |
|
490 | 490 | <fieldset> |
491 | 491 | <label> |
492 | 492 | <input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
@@ -498,75 +498,75 @@ discard block |
||
498 | 498 | |
499 | 499 | function wpinv_multicheck_callback( $args ) { |
500 | 500 | |
501 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
502 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
501 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
502 | + $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
503 | 503 | |
504 | - if ( ! empty( $args['options'] ) ) { |
|
504 | + if ( ! empty( $args['options'] ) ) { |
|
505 | 505 | |
506 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
507 | - $value = wpinv_get_option( $args['id'], $std ); |
|
506 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
507 | + $value = wpinv_get_option( $args['id'], $std ); |
|
508 | 508 | |
509 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
509 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
|
510 | 510 | foreach( $args['options'] as $key => $option ): |
511 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
512 | - if ( in_array( $sanitize_key, $value ) ) { |
|
513 | - $enabled = $sanitize_key; |
|
514 | - } else { |
|
515 | - $enabled = NULL; |
|
516 | - } |
|
517 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
518 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
519 | - endforeach; |
|
520 | - echo '</div>'; |
|
521 | - echo '<p class="description">' . $args['desc'] . '</p>'; |
|
522 | - } |
|
511 | + $sanitize_key = wpinv_sanitize_key( $key ); |
|
512 | + if ( in_array( $sanitize_key, $value ) ) { |
|
513 | + $enabled = $sanitize_key; |
|
514 | + } else { |
|
515 | + $enabled = NULL; |
|
516 | + } |
|
517 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
518 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
519 | + endforeach; |
|
520 | + echo '</div>'; |
|
521 | + echo '<p class="description">' . $args['desc'] . '</p>'; |
|
522 | + } |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | function wpinv_payment_icons_callback( $args ) { |
526 | 526 | |
527 | 527 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
528 | - $value = wpinv_get_option( $args['id'], false); |
|
528 | + $value = wpinv_get_option( $args['id'], false); |
|
529 | 529 | |
530 | - if ( ! empty( $args['options'] ) ) { |
|
531 | - foreach( $args['options'] as $key => $option ) { |
|
530 | + if ( ! empty( $args['options'] ) ) { |
|
531 | + foreach( $args['options'] as $key => $option ) { |
|
532 | 532 | $sanitize_key = wpinv_sanitize_key( $key ); |
533 | 533 | |
534 | - if( empty( $value ) ) { |
|
535 | - $enabled = $option; |
|
536 | - } else { |
|
537 | - $enabled = NULL; |
|
538 | - } |
|
539 | - |
|
540 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
541 | - |
|
542 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
543 | - |
|
544 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
545 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
546 | - } else { |
|
547 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
548 | - |
|
549 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
550 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
551 | - } else { |
|
552 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
553 | - $content_dir = WP_CONTENT_DIR; |
|
554 | - |
|
555 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
556 | - // Replaces backslashes with forward slashes for Windows systems |
|
557 | - $image = wp_normalize_path( $image ); |
|
558 | - $content_dir = wp_normalize_path( $content_dir ); |
|
559 | - } |
|
560 | - |
|
561 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
562 | - } |
|
563 | - |
|
564 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
565 | - } |
|
566 | - echo $option . '</label>'; |
|
567 | - } |
|
568 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
569 | - } |
|
534 | + if( empty( $value ) ) { |
|
535 | + $enabled = $option; |
|
536 | + } else { |
|
537 | + $enabled = NULL; |
|
538 | + } |
|
539 | + |
|
540 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
541 | + |
|
542 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
543 | + |
|
544 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
545 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
546 | + } else { |
|
547 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
548 | + |
|
549 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
550 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
551 | + } else { |
|
552 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
553 | + $content_dir = WP_CONTENT_DIR; |
|
554 | + |
|
555 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
556 | + // Replaces backslashes with forward slashes for Windows systems |
|
557 | + $image = wp_normalize_path( $image ); |
|
558 | + $content_dir = wp_normalize_path( $content_dir ); |
|
559 | + } |
|
560 | + |
|
561 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
562 | + } |
|
563 | + |
|
564 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
565 | + } |
|
566 | + echo $option . '</label>'; |
|
567 | + } |
|
568 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
569 | + } |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
@@ -574,9 +574,9 @@ discard block |
||
574 | 574 | */ |
575 | 575 | function wpinv_radio_callback( $args ) { |
576 | 576 | |
577 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
578 | - $std = wpinv_get_option( $args['id'], $std ); |
|
579 | - ?> |
|
577 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
578 | + $std = wpinv_get_option( $args['id'], $std ); |
|
579 | + ?> |
|
580 | 580 | <fieldset> |
581 | 581 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
582 | 582 | <?php foreach( $args['options'] as $key => $option ) : ?> |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | </ul> |
591 | 591 | </fieldset> |
592 | 592 | <?php |
593 | - getpaid_settings_description_callback( $args ); |
|
593 | + getpaid_settings_description_callback( $args ); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -598,10 +598,10 @@ discard block |
||
598 | 598 | */ |
599 | 599 | function getpaid_settings_description_callback( $args ) { |
600 | 600 | |
601 | - if ( ! empty( $args['desc'] ) ) { |
|
602 | - $description = wp_kses_post( $args['desc'] ); |
|
603 | - echo "<p class='description'>$description</p>"; |
|
604 | - } |
|
601 | + if ( ! empty( $args['desc'] ) ) { |
|
602 | + $description = wp_kses_post( $args['desc'] ); |
|
603 | + echo "<p class='description'>$description</p>"; |
|
604 | + } |
|
605 | 605 | |
606 | 606 | } |
607 | 607 | |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | */ |
611 | 611 | function wpinv_gateways_callback() { |
612 | 612 | |
613 | - ?> |
|
613 | + ?> |
|
614 | 614 | </td> |
615 | 615 | </tr> |
616 | 616 | <tr class="bsui"> |
@@ -624,22 +624,22 @@ discard block |
||
624 | 624 | |
625 | 625 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
626 | 626 | $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
627 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
628 | - $value = wpinv_get_option( $args['id'], $std ); |
|
627 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
628 | + $value = wpinv_get_option( $args['id'], $std ); |
|
629 | 629 | |
630 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
630 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
631 | 631 | |
632 | - foreach ( $args['options'] as $key => $option ) : |
|
633 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
632 | + foreach ( $args['options'] as $key => $option ) : |
|
633 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
634 | 634 | $selected = selected( $key, $args['selected'], false ); |
635 | 635 | } else { |
636 | 636 | $selected = selected( $key, $value, false ); |
637 | 637 | } |
638 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
639 | - endforeach; |
|
638 | + echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
639 | + endforeach; |
|
640 | 640 | |
641 | - echo '</select>'; |
|
642 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
641 | + echo '</select>'; |
|
642 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -650,29 +650,29 @@ discard block |
||
650 | 650 | */ |
651 | 651 | function wpinv_settings_attrs_helper( $args ) { |
652 | 652 | |
653 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
654 | - $id = esc_attr( $args['id'] ); |
|
655 | - $placeholder = esc_attr( $args['placeholder'] ); |
|
653 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
654 | + $id = esc_attr( $args['id'] ); |
|
655 | + $placeholder = esc_attr( $args['placeholder'] ); |
|
656 | 656 | |
657 | - if ( ! empty( $args['faux'] ) ) { |
|
658 | - $args['readonly'] = true; |
|
659 | - $name = ''; |
|
660 | - } else { |
|
661 | - $value = wpinv_get_option( $args['id'], $value ); |
|
662 | - $name = "wpinv_settings[$id]"; |
|
663 | - } |
|
657 | + if ( ! empty( $args['faux'] ) ) { |
|
658 | + $args['readonly'] = true; |
|
659 | + $name = ''; |
|
660 | + } else { |
|
661 | + $value = wpinv_get_option( $args['id'], $value ); |
|
662 | + $name = "wpinv_settings[$id]"; |
|
663 | + } |
|
664 | 664 | |
665 | - $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
666 | - $class = esc_attr( $args['class'] ); |
|
667 | - $style = esc_attr( $args['style'] ); |
|
668 | - $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
665 | + $value = is_scalar( $value ) ? esc_attr( $value ) : ''; |
|
666 | + $class = esc_attr( $args['class'] ); |
|
667 | + $style = esc_attr( $args['style'] ); |
|
668 | + $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"'; |
|
669 | 669 | |
670 | - $onchange = ''; |
|
670 | + $onchange = ''; |
|
671 | 671 | if ( ! empty( $args['onchange'] ) ) { |
672 | 672 | $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
673 | - } |
|
673 | + } |
|
674 | 674 | |
675 | - return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
|
675 | + return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly"; |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -680,11 +680,11 @@ discard block |
||
680 | 680 | */ |
681 | 681 | function wpinv_text_callback( $args ) { |
682 | 682 | |
683 | - $desc = wp_kses_post( $args['desc'] ); |
|
684 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
685 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
683 | + $desc = wp_kses_post( $args['desc'] ); |
|
684 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
685 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
686 | 686 | |
687 | - ?> |
|
687 | + ?> |
|
688 | 688 | <label style="width: 100%;"> |
689 | 689 | <input type="text" <?php echo $attr; ?>> |
690 | 690 | <?php echo $desc; ?> |
@@ -698,14 +698,14 @@ discard block |
||
698 | 698 | */ |
699 | 699 | function wpinv_number_callback( $args ) { |
700 | 700 | |
701 | - $desc = wp_kses_post( $args['desc'] ); |
|
702 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
703 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
704 | - $max = intval( $args['max'] ); |
|
705 | - $min = intval( $args['min'] ); |
|
706 | - $step = floatval( $args['step'] ); |
|
701 | + $desc = wp_kses_post( $args['desc'] ); |
|
702 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
703 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
704 | + $max = intval( $args['max'] ); |
|
705 | + $min = intval( $args['min'] ); |
|
706 | + $step = floatval( $args['step'] ); |
|
707 | 707 | |
708 | - ?> |
|
708 | + ?> |
|
709 | 709 | <label style="width: 100%;"> |
710 | 710 | <input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>> |
711 | 711 | <?php echo $desc; ?> |
@@ -717,36 +717,36 @@ discard block |
||
717 | 717 | function wpinv_textarea_callback( $args ) { |
718 | 718 | |
719 | 719 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
720 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
721 | - $value = wpinv_get_option( $args['id'], $std ); |
|
720 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
721 | + $value = wpinv_get_option( $args['id'], $std ); |
|
722 | 722 | |
723 | 723 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
724 | 724 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
725 | 725 | |
726 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
727 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
726 | + $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
727 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
728 | 728 | |
729 | - echo $html; |
|
729 | + echo $html; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | function wpinv_password_callback( $args ) { |
733 | 733 | |
734 | 734 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
735 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
736 | - $value = wpinv_get_option( $args['id'], $std ); |
|
735 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
736 | + $value = wpinv_get_option( $args['id'], $std ); |
|
737 | 737 | |
738 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
739 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
740 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
738 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
739 | + $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
740 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
741 | 741 | |
742 | - echo $html; |
|
742 | + echo $html; |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | function wpinv_missing_callback($args) { |
746 | - printf( |
|
747 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
748 | - '<strong>' . $args['id'] . '</strong>' |
|
749 | - ); |
|
746 | + printf( |
|
747 | + __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
748 | + '<strong>' . $args['id'] . '</strong>' |
|
749 | + ); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -754,14 +754,14 @@ discard block |
||
754 | 754 | */ |
755 | 755 | function wpinv_select_callback( $args ) { |
756 | 756 | |
757 | - $desc = wp_kses_post( $args['desc'] ); |
|
758 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
759 | - $attr = wpinv_settings_attrs_helper( $args ); |
|
760 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
761 | - $value = wpinv_get_option( $args['id'], $value ); |
|
762 | - $rand = uniqid( 'random_id' ); |
|
757 | + $desc = wp_kses_post( $args['desc'] ); |
|
758 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
759 | + $attr = wpinv_settings_attrs_helper( $args ); |
|
760 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
761 | + $value = wpinv_get_option( $args['id'], $value ); |
|
762 | + $rand = uniqid( 'random_id' ); |
|
763 | 763 | |
764 | - ?> |
|
764 | + ?> |
|
765 | 765 | <label style="width: 100%;"> |
766 | 766 | <select <?php echo $attr; ?>> |
767 | 767 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -794,104 +794,104 @@ discard block |
||
794 | 794 | function wpinv_color_select_callback( $args ) { |
795 | 795 | |
796 | 796 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
797 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
798 | - $value = wpinv_get_option( $args['id'], $std ); |
|
797 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
798 | + $value = wpinv_get_option( $args['id'], $std ); |
|
799 | 799 | |
800 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
800 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
801 | 801 | |
802 | - foreach ( $args['options'] as $option => $color ) { |
|
803 | - $selected = selected( $option, $value, false ); |
|
804 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
805 | - } |
|
802 | + foreach ( $args['options'] as $option => $color ) { |
|
803 | + $selected = selected( $option, $value, false ); |
|
804 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
805 | + } |
|
806 | 806 | |
807 | - $html .= '</select>'; |
|
808 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
807 | + $html .= '</select>'; |
|
808 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
809 | 809 | |
810 | - echo $html; |
|
810 | + echo $html; |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | function wpinv_rich_editor_callback( $args ) { |
814 | - global $wp_version; |
|
814 | + global $wp_version; |
|
815 | 815 | |
816 | 816 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
817 | 817 | |
818 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
819 | - $value = wpinv_get_option( $args['id'], $std ); |
|
818 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
819 | + $value = wpinv_get_option( $args['id'], $std ); |
|
820 | 820 | |
821 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
822 | - $value = $std; |
|
823 | - } |
|
821 | + if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
822 | + $value = $std; |
|
823 | + } |
|
824 | 824 | |
825 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
825 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
826 | 826 | |
827 | - $html = '<div class="getpaid-settings-editor-input">'; |
|
828 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
829 | - ob_start(); |
|
830 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
831 | - $html .= ob_get_clean(); |
|
832 | - } else { |
|
833 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
834 | - } |
|
827 | + $html = '<div class="getpaid-settings-editor-input">'; |
|
828 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
829 | + ob_start(); |
|
830 | + wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
831 | + $html .= ob_get_clean(); |
|
832 | + } else { |
|
833 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
834 | + } |
|
835 | 835 | |
836 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
836 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
837 | 837 | |
838 | - echo $html; |
|
838 | + echo $html; |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | function wpinv_upload_callback( $args ) { |
842 | 842 | |
843 | 843 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
844 | 844 | |
845 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
846 | - $value = wpinv_get_option( $args['id'], $std ); |
|
845 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
846 | + $value = wpinv_get_option( $args['id'], $std ); |
|
847 | 847 | |
848 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
849 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
850 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
851 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
848 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
849 | + $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
850 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
851 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
852 | 852 | |
853 | - echo $html; |
|
853 | + echo $html; |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | function wpinv_color_callback( $args ) { |
857 | 857 | |
858 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
859 | - $value = wpinv_get_option( $args['id'], $std ); |
|
858 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
859 | + $value = wpinv_get_option( $args['id'], $std ); |
|
860 | 860 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
861 | 861 | |
862 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
863 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
862 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
863 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
864 | 864 | |
865 | - echo $html; |
|
865 | + echo $html; |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | function wpinv_country_states_callback($args) { |
869 | 869 | |
870 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
871 | - $value = wpinv_get_option( $args['id'], $std ); |
|
870 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
871 | + $value = wpinv_get_option( $args['id'], $std ); |
|
872 | 872 | |
873 | 873 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
874 | 874 | |
875 | - if ( isset( $args['placeholder'] ) ) { |
|
876 | - $placeholder = $args['placeholder']; |
|
877 | - } else { |
|
878 | - $placeholder = ''; |
|
879 | - } |
|
875 | + if ( isset( $args['placeholder'] ) ) { |
|
876 | + $placeholder = $args['placeholder']; |
|
877 | + } else { |
|
878 | + $placeholder = ''; |
|
879 | + } |
|
880 | 880 | |
881 | - $states = wpinv_get_country_states(); |
|
881 | + $states = wpinv_get_country_states(); |
|
882 | 882 | |
883 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
883 | + $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
885 | 885 | |
886 | - foreach ( $states as $option => $name ) { |
|
887 | - $selected = selected( $option, $value, false ); |
|
888 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
889 | - } |
|
886 | + foreach ( $states as $option => $name ) { |
|
887 | + $selected = selected( $option, $value, false ); |
|
888 | + $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
889 | + } |
|
890 | 890 | |
891 | - $html .= '</select>'; |
|
892 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
891 | + $html .= '</select>'; |
|
892 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
893 | 893 | |
894 | - echo $html; |
|
894 | + echo $html; |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | */ |
900 | 900 | function wpinv_tax_rates_callback() { |
901 | 901 | |
902 | - ?> |
|
902 | + ?> |
|
903 | 903 | </td> |
904 | 904 | </tr> |
905 | 905 | <tr class="bsui"> |
@@ -914,17 +914,17 @@ discard block |
||
914 | 914 | * Displays a tax rate' edit row. |
915 | 915 | */ |
916 | 916 | function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) { |
917 | - ob_start(); |
|
917 | + ob_start(); |
|
918 | 918 | |
919 | - $key = sanitize_key( $key ); |
|
920 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
921 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
919 | + $key = sanitize_key( $key ); |
|
920 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
921 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
922 | 922 | |
923 | - if ( $echo ) { |
|
924 | - echo ob_get_clean(); |
|
925 | - } else { |
|
926 | - return ob_get_clean(); |
|
927 | - } |
|
923 | + if ( $echo ) { |
|
924 | + echo ob_get_clean(); |
|
925 | + } else { |
|
926 | + return ob_get_clean(); |
|
927 | + } |
|
928 | 928 | |
929 | 929 | } |
930 | 930 | |
@@ -952,14 +952,14 @@ discard block |
||
952 | 952 | </td> |
953 | 953 | <td> |
954 | 954 | <a href="<?php |
955 | - echo esc_url( |
|
956 | - wp_nonce_url( |
|
957 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
958 | - 'getpaid-nonce', |
|
959 | - 'getpaid-nonce' |
|
960 | - ) |
|
961 | - ); |
|
962 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
955 | + echo esc_url( |
|
956 | + wp_nonce_url( |
|
957 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
958 | + 'getpaid-nonce', |
|
959 | + 'getpaid-nonce' |
|
960 | + ) |
|
961 | + ); |
|
962 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
963 | 963 | </td> |
964 | 964 | </tr> |
965 | 965 | <tr> |
@@ -969,14 +969,14 @@ discard block |
||
969 | 969 | </td> |
970 | 970 | <td> |
971 | 971 | <a href="<?php |
972 | - echo esc_url( |
|
973 | - wp_nonce_url( |
|
974 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
975 | - 'getpaid-nonce', |
|
976 | - 'getpaid-nonce' |
|
977 | - ) |
|
978 | - ); |
|
979 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
972 | + echo esc_url( |
|
973 | + wp_nonce_url( |
|
974 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
975 | + 'getpaid-nonce', |
|
976 | + 'getpaid-nonce' |
|
977 | + ) |
|
978 | + ); |
|
979 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
980 | 980 | </td> |
981 | 981 | </tr> |
982 | 982 | <tr> |
@@ -986,14 +986,14 @@ discard block |
||
986 | 986 | </td> |
987 | 987 | <td> |
988 | 988 | <a href="<?php |
989 | - echo esc_url( |
|
990 | - wp_nonce_url( |
|
991 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
992 | - 'getpaid-nonce', |
|
993 | - 'getpaid-nonce' |
|
994 | - ) |
|
995 | - ); |
|
996 | - ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
989 | + echo esc_url( |
|
990 | + wp_nonce_url( |
|
991 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
992 | + 'getpaid-nonce', |
|
993 | + 'getpaid-nonce' |
|
994 | + ) |
|
995 | + ); |
|
996 | + ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a> |
|
997 | 997 | </td> |
998 | 998 | </tr> |
999 | 999 | |
@@ -1004,14 +1004,14 @@ discard block |
||
1004 | 1004 | </td> |
1005 | 1005 | <td> |
1006 | 1006 | <a href="<?php |
1007 | - echo esc_url( |
|
1008 | - wp_nonce_url( |
|
1009 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1010 | - 'getpaid-nonce', |
|
1011 | - 'getpaid-nonce' |
|
1012 | - ) |
|
1013 | - ); |
|
1014 | - ?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a> |
|
1007 | + echo esc_url( |
|
1008 | + wp_nonce_url( |
|
1009 | + add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1010 | + 'getpaid-nonce', |
|
1011 | + 'getpaid-nonce' |
|
1012 | + ) |
|
1013 | + ); |
|
1014 | + ?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a> |
|
1015 | 1015 | </td> |
1016 | 1016 | </tr> |
1017 | 1017 | |
@@ -1022,8 +1022,8 @@ discard block |
||
1022 | 1022 | </td> |
1023 | 1023 | <td> |
1024 | 1024 | <a href="<?php |
1025 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1026 | - ?>" class="button button-primary"><?php _e( 'Launch', 'invoicing' );?></a> |
|
1025 | + echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1026 | + ?>" class="button button-primary"><?php _e( 'Launch', 'invoicing' );?></a> |
|
1027 | 1027 | </td> |
1028 | 1028 | </tr> |
1029 | 1029 | |
@@ -1037,19 +1037,19 @@ discard block |
||
1037 | 1037 | |
1038 | 1038 | |
1039 | 1039 | function wpinv_descriptive_text_callback( $args ) { |
1040 | - echo wp_kses_post( $args['desc'] ); |
|
1040 | + echo wp_kses_post( $args['desc'] ); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | function wpinv_raw_html_callback( $args ) { |
1044 | - echo $args['desc']; |
|
1044 | + echo $args['desc']; |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | function wpinv_hook_callback( $args ) { |
1048 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1048 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | 1051 | function wpinv_set_settings_cap() { |
1052 | - return wpinv_get_capability(); |
|
1052 | + return wpinv_get_capability(); |
|
1053 | 1053 | } |
1054 | 1054 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1055 | 1055 | |
@@ -1073,15 +1073,15 @@ discard block |
||
1073 | 1073 | */ |
1074 | 1074 | function wpinv_get_merge_tags_help_text( $subscription = false ) { |
1075 | 1075 | |
1076 | - $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
1077 | - $link = sprintf( |
|
1078 | - '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
1079 | - $url, |
|
1080 | - esc_html__( 'View available merge tags.', 'wpinv-quotes' ) |
|
1081 | - ); |
|
1076 | + $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
1077 | + $link = sprintf( |
|
1078 | + '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
1079 | + $url, |
|
1080 | + esc_html__( 'View available merge tags.', 'wpinv-quotes' ) |
|
1081 | + ); |
|
1082 | 1082 | |
1083 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1083 | + $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1084 | 1084 | |
1085 | - return "$description $link"; |
|
1085 | + return "$description $link"; |
|
1086 | 1086 | |
1087 | 1087 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | // Load WP_List_Table if not loaded |
11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,367 +21,367 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class WPInv_Customers_Table extends WP_List_Table { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int Number of items per page |
|
26 | - * @since 1.0.19 |
|
27 | - */ |
|
28 | - public $per_page = 10; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var int Number of items |
|
32 | - * @since 1.0.19 |
|
33 | - */ |
|
34 | - public $total = 0; |
|
35 | - |
|
36 | - /** |
|
37 | - * Get things started |
|
38 | - * |
|
39 | - * @since 1.0.19 |
|
40 | - * @see WP_List_Table::__construct() |
|
41 | - */ |
|
42 | - public function __construct() { |
|
43 | - |
|
44 | - // Set parent defaults |
|
45 | - parent::__construct( array( |
|
46 | - 'singular' => 'id', |
|
47 | - 'plural' => 'ids', |
|
48 | - 'ajax' => false, |
|
49 | - ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Gets the name of the primary column. |
|
55 | - * |
|
56 | - * @since 1.0.19 |
|
57 | - * @access protected |
|
58 | - * |
|
59 | - * @return string Name of the primary column. |
|
60 | - */ |
|
61 | - protected function get_primary_column_name() { |
|
62 | - return 'name'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * This function renders most of the columns in the list table. |
|
67 | - * |
|
68 | - * @since 1.0.19 |
|
69 | - * |
|
70 | - * @param WP_User $item |
|
71 | - * @param string $column_name The name of the column |
|
72 | - * |
|
73 | - * @return string Column Name |
|
74 | - */ |
|
75 | - public function column_default( $item, $column_name ) { |
|
76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Displays the country column. |
|
82 | - * |
|
83 | - * @since 1.0.19 |
|
84 | - * |
|
85 | - * @param WP_User $user |
|
86 | - * |
|
87 | - * @return string Column Name |
|
88 | - */ |
|
89 | - public function column_country( $user ) { |
|
90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
91 | - if ( $country ) { |
|
92 | - $country = wpinv_country_name( $country ); |
|
93 | - } |
|
94 | - return sanitize_text_field( $country ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Displays the state column. |
|
99 | - * |
|
100 | - * @since 1.0.19 |
|
101 | - * |
|
102 | - * @param WP_User $user |
|
103 | - * |
|
104 | - * @return string Column Name |
|
105 | - */ |
|
106 | - public function column_state( $user ) { |
|
107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
108 | - $state = $user->_wpinv_state; |
|
109 | - if ( $state ) { |
|
110 | - $state = wpinv_state_name( $state, $country ); |
|
111 | - } |
|
112 | - |
|
113 | - return sanitize_text_field( $state ); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Displays the signup column. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * |
|
121 | - * @param WP_User $user |
|
122 | - * |
|
123 | - * @return string Column Name |
|
124 | - */ |
|
125 | - public function column_signup( $user ) { |
|
126 | - return getpaid_format_date_value( $user->user_registered ); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Displays the total spent column. |
|
131 | - * |
|
132 | - * @since 1.0.19 |
|
133 | - * |
|
134 | - * @param WP_User $user |
|
135 | - * |
|
136 | - * @return string Column Name |
|
137 | - */ |
|
138 | - public function column_total( $user ) { |
|
139 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Displays the total spent column. |
|
144 | - * |
|
145 | - * @since 1.0.19 |
|
146 | - * |
|
147 | - * @param WP_User $user |
|
148 | - * |
|
149 | - * @return float |
|
150 | - */ |
|
151 | - public function column_total_raw( $user ) { |
|
152 | - |
|
153 | - $args = array( |
|
154 | - 'data' => array( |
|
155 | - |
|
156 | - 'total' => array( |
|
157 | - 'type' => 'invoice_data', |
|
158 | - 'function' => 'SUM', |
|
159 | - 'name' => 'total_sales', |
|
160 | - ) |
|
161 | - |
|
162 | - ), |
|
163 | - 'where' => array( |
|
164 | - |
|
165 | - 'author' => array( |
|
166 | - 'type' => 'post_data', |
|
167 | - 'value' => absint( $user->ID ), |
|
168 | - 'key' => 'posts.post_author', |
|
169 | - 'operator' => '=', |
|
170 | - ), |
|
171 | - |
|
172 | - ), |
|
173 | - 'query_type' => 'get_var', |
|
174 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
175 | - ); |
|
176 | - |
|
177 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
178 | - |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Displays the total spent column. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * |
|
186 | - * @param WP_User $user |
|
187 | - * |
|
188 | - * @return string Column Name |
|
189 | - */ |
|
190 | - public function column_invoices( $user ) { |
|
191 | - |
|
192 | - $args = array( |
|
193 | - 'data' => array( |
|
194 | - |
|
195 | - 'ID' => array( |
|
196 | - 'type' => 'post_data', |
|
197 | - 'function' => 'COUNT', |
|
198 | - 'name' => 'count', |
|
199 | - 'distinct' => true, |
|
200 | - ), |
|
201 | - |
|
202 | - ), |
|
203 | - 'where' => array( |
|
204 | - |
|
205 | - 'author' => array( |
|
206 | - 'type' => 'post_data', |
|
207 | - 'value' => absint( $user->ID ), |
|
208 | - 'key' => 'posts.post_author', |
|
209 | - 'operator' => '=', |
|
210 | - ), |
|
211 | - |
|
212 | - ), |
|
213 | - 'query_type' => 'get_var', |
|
214 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
215 | - ); |
|
216 | - |
|
217 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
218 | - |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Generates content for a single row of the table |
|
223 | - * @since 1.0.19 |
|
224 | - * |
|
225 | - * @param int $item The user id. |
|
226 | - */ |
|
227 | - public function single_row( $item ) { |
|
228 | - $item = get_user_by( 'id', $item ); |
|
229 | - |
|
230 | - if ( empty( $item ) ) { |
|
231 | - return; |
|
232 | - } |
|
233 | - |
|
234 | - echo '<tr>'; |
|
235 | - $this->single_row_columns( $item ); |
|
236 | - echo '</tr>'; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Displays the customers name |
|
241 | - * |
|
242 | - * @param WP_User $customer customer. |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - public function column_name( $customer ) { |
|
246 | - |
|
247 | - // Customer view URL. |
|
248 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
249 | - $row_actions = $this->row_actions( |
|
250 | - array( |
|
251 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
252 | - ) |
|
253 | - ); |
|
254 | - |
|
255 | - // Get user's address. |
|
256 | - $address = wpinv_get_user_address( $customer->ID ); |
|
257 | - |
|
258 | - // Customer email address. |
|
259 | - $email = sanitize_email( $customer->user_email ); |
|
260 | - |
|
261 | - // Customer's avatar. |
|
262 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
263 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
264 | - |
|
265 | - // Customer's name. |
|
266 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
267 | - |
|
268 | - if ( ! empty( $name ) ) { |
|
269 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
270 | - } |
|
271 | - |
|
272 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
273 | - |
|
274 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Retrieve the table columns |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return array $columns Array of all the list table columns |
|
283 | - */ |
|
284 | - public function get_columns() { |
|
285 | - |
|
286 | - $columns = array( |
|
287 | - 'name' => __( 'Name', 'invoicing' ), |
|
288 | - 'country' => __( 'Country', 'invoicing' ), |
|
289 | - 'state' => __( 'State', 'invoicing' ), |
|
290 | - 'city' => __( 'City', 'invoicing' ), |
|
291 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
292 | - 'address' => __( 'Address', 'invoicing' ), |
|
293 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
294 | - 'company' => __( 'Company', 'invoicing' ), |
|
295 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
296 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
297 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
298 | - ); |
|
299 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
300 | - |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Retrieve the current page number |
|
305 | - * |
|
306 | - * @since 1.0.19 |
|
307 | - * @return int Current page number |
|
308 | - */ |
|
309 | - public function get_paged() { |
|
310 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns bulk actions. |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @return void |
|
318 | - */ |
|
319 | - public function bulk_actions( $which = '' ) { |
|
320 | - return array(); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Prepares the display query |
|
325 | - */ |
|
326 | - public function prepare_query() { |
|
327 | - global $wpdb; |
|
328 | - |
|
329 | - $post_types = ''; |
|
330 | - |
|
331 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
332 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
333 | - } |
|
334 | - |
|
335 | - $post_types = rtrim( $post_types, ' OR' ); |
|
336 | - |
|
337 | - // Maybe search. |
|
338 | - if ( ! empty( $_POST['s'] ) ) { |
|
339 | - $users = get_users( |
|
340 | - array( |
|
341 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
342 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
343 | - 'fields' => 'ID', |
|
344 | - ) |
|
345 | - ); |
|
346 | - |
|
347 | - $users = implode( ', ', $users ); |
|
348 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
349 | - } |
|
350 | - |
|
351 | - // Users with invoices. |
|
352 | - $customers = $wpdb->get_col( |
|
353 | - $wpdb->prepare( |
|
354 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
355 | - $this->get_paged() * 10 - 10, |
|
356 | - $this->per_page |
|
357 | - ) |
|
358 | - ); |
|
359 | - |
|
360 | - $this->items = $customers; |
|
361 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Setup the final data for the table |
|
367 | - * |
|
368 | - * @since 1.0.19 |
|
369 | - * @return void |
|
370 | - */ |
|
371 | - public function prepare_items() { |
|
372 | - $columns = $this->get_columns(); |
|
373 | - $hidden = array(); // No hidden columns |
|
374 | - $sortable = $this->get_sortable_columns(); |
|
375 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
376 | - $this->prepare_query(); |
|
377 | - |
|
378 | - $this->set_pagination_args( |
|
379 | - array( |
|
380 | - 'total_items' => $this->total, |
|
381 | - 'per_page' => $this->per_page, |
|
382 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
383 | - ) |
|
384 | - ); |
|
385 | - |
|
386 | - } |
|
24 | + /** |
|
25 | + * @var int Number of items per page |
|
26 | + * @since 1.0.19 |
|
27 | + */ |
|
28 | + public $per_page = 10; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var int Number of items |
|
32 | + * @since 1.0.19 |
|
33 | + */ |
|
34 | + public $total = 0; |
|
35 | + |
|
36 | + /** |
|
37 | + * Get things started |
|
38 | + * |
|
39 | + * @since 1.0.19 |
|
40 | + * @see WP_List_Table::__construct() |
|
41 | + */ |
|
42 | + public function __construct() { |
|
43 | + |
|
44 | + // Set parent defaults |
|
45 | + parent::__construct( array( |
|
46 | + 'singular' => 'id', |
|
47 | + 'plural' => 'ids', |
|
48 | + 'ajax' => false, |
|
49 | + ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Gets the name of the primary column. |
|
55 | + * |
|
56 | + * @since 1.0.19 |
|
57 | + * @access protected |
|
58 | + * |
|
59 | + * @return string Name of the primary column. |
|
60 | + */ |
|
61 | + protected function get_primary_column_name() { |
|
62 | + return 'name'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * This function renders most of the columns in the list table. |
|
67 | + * |
|
68 | + * @since 1.0.19 |
|
69 | + * |
|
70 | + * @param WP_User $item |
|
71 | + * @param string $column_name The name of the column |
|
72 | + * |
|
73 | + * @return string Column Name |
|
74 | + */ |
|
75 | + public function column_default( $item, $column_name ) { |
|
76 | + $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
77 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Displays the country column. |
|
82 | + * |
|
83 | + * @since 1.0.19 |
|
84 | + * |
|
85 | + * @param WP_User $user |
|
86 | + * |
|
87 | + * @return string Column Name |
|
88 | + */ |
|
89 | + public function column_country( $user ) { |
|
90 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
91 | + if ( $country ) { |
|
92 | + $country = wpinv_country_name( $country ); |
|
93 | + } |
|
94 | + return sanitize_text_field( $country ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Displays the state column. |
|
99 | + * |
|
100 | + * @since 1.0.19 |
|
101 | + * |
|
102 | + * @param WP_User $user |
|
103 | + * |
|
104 | + * @return string Column Name |
|
105 | + */ |
|
106 | + public function column_state( $user ) { |
|
107 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
108 | + $state = $user->_wpinv_state; |
|
109 | + if ( $state ) { |
|
110 | + $state = wpinv_state_name( $state, $country ); |
|
111 | + } |
|
112 | + |
|
113 | + return sanitize_text_field( $state ); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Displays the signup column. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * |
|
121 | + * @param WP_User $user |
|
122 | + * |
|
123 | + * @return string Column Name |
|
124 | + */ |
|
125 | + public function column_signup( $user ) { |
|
126 | + return getpaid_format_date_value( $user->user_registered ); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Displays the total spent column. |
|
131 | + * |
|
132 | + * @since 1.0.19 |
|
133 | + * |
|
134 | + * @param WP_User $user |
|
135 | + * |
|
136 | + * @return string Column Name |
|
137 | + */ |
|
138 | + public function column_total( $user ) { |
|
139 | + return wpinv_price( $this->column_total_raw( $user ) ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Displays the total spent column. |
|
144 | + * |
|
145 | + * @since 1.0.19 |
|
146 | + * |
|
147 | + * @param WP_User $user |
|
148 | + * |
|
149 | + * @return float |
|
150 | + */ |
|
151 | + public function column_total_raw( $user ) { |
|
152 | + |
|
153 | + $args = array( |
|
154 | + 'data' => array( |
|
155 | + |
|
156 | + 'total' => array( |
|
157 | + 'type' => 'invoice_data', |
|
158 | + 'function' => 'SUM', |
|
159 | + 'name' => 'total_sales', |
|
160 | + ) |
|
161 | + |
|
162 | + ), |
|
163 | + 'where' => array( |
|
164 | + |
|
165 | + 'author' => array( |
|
166 | + 'type' => 'post_data', |
|
167 | + 'value' => absint( $user->ID ), |
|
168 | + 'key' => 'posts.post_author', |
|
169 | + 'operator' => '=', |
|
170 | + ), |
|
171 | + |
|
172 | + ), |
|
173 | + 'query_type' => 'get_var', |
|
174 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
175 | + ); |
|
176 | + |
|
177 | + return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
178 | + |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Displays the total spent column. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * |
|
186 | + * @param WP_User $user |
|
187 | + * |
|
188 | + * @return string Column Name |
|
189 | + */ |
|
190 | + public function column_invoices( $user ) { |
|
191 | + |
|
192 | + $args = array( |
|
193 | + 'data' => array( |
|
194 | + |
|
195 | + 'ID' => array( |
|
196 | + 'type' => 'post_data', |
|
197 | + 'function' => 'COUNT', |
|
198 | + 'name' => 'count', |
|
199 | + 'distinct' => true, |
|
200 | + ), |
|
201 | + |
|
202 | + ), |
|
203 | + 'where' => array( |
|
204 | + |
|
205 | + 'author' => array( |
|
206 | + 'type' => 'post_data', |
|
207 | + 'value' => absint( $user->ID ), |
|
208 | + 'key' => 'posts.post_author', |
|
209 | + 'operator' => '=', |
|
210 | + ), |
|
211 | + |
|
212 | + ), |
|
213 | + 'query_type' => 'get_var', |
|
214 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
215 | + ); |
|
216 | + |
|
217 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
218 | + |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Generates content for a single row of the table |
|
223 | + * @since 1.0.19 |
|
224 | + * |
|
225 | + * @param int $item The user id. |
|
226 | + */ |
|
227 | + public function single_row( $item ) { |
|
228 | + $item = get_user_by( 'id', $item ); |
|
229 | + |
|
230 | + if ( empty( $item ) ) { |
|
231 | + return; |
|
232 | + } |
|
233 | + |
|
234 | + echo '<tr>'; |
|
235 | + $this->single_row_columns( $item ); |
|
236 | + echo '</tr>'; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Displays the customers name |
|
241 | + * |
|
242 | + * @param WP_User $customer customer. |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + public function column_name( $customer ) { |
|
246 | + |
|
247 | + // Customer view URL. |
|
248 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
249 | + $row_actions = $this->row_actions( |
|
250 | + array( |
|
251 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
252 | + ) |
|
253 | + ); |
|
254 | + |
|
255 | + // Get user's address. |
|
256 | + $address = wpinv_get_user_address( $customer->ID ); |
|
257 | + |
|
258 | + // Customer email address. |
|
259 | + $email = sanitize_email( $customer->user_email ); |
|
260 | + |
|
261 | + // Customer's avatar. |
|
262 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
263 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
264 | + |
|
265 | + // Customer's name. |
|
266 | + $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
267 | + |
|
268 | + if ( ! empty( $name ) ) { |
|
269 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
270 | + } |
|
271 | + |
|
272 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
273 | + |
|
274 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Retrieve the table columns |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return array $columns Array of all the list table columns |
|
283 | + */ |
|
284 | + public function get_columns() { |
|
285 | + |
|
286 | + $columns = array( |
|
287 | + 'name' => __( 'Name', 'invoicing' ), |
|
288 | + 'country' => __( 'Country', 'invoicing' ), |
|
289 | + 'state' => __( 'State', 'invoicing' ), |
|
290 | + 'city' => __( 'City', 'invoicing' ), |
|
291 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
292 | + 'address' => __( 'Address', 'invoicing' ), |
|
293 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
294 | + 'company' => __( 'Company', 'invoicing' ), |
|
295 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
296 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
297 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
298 | + ); |
|
299 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
300 | + |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Retrieve the current page number |
|
305 | + * |
|
306 | + * @since 1.0.19 |
|
307 | + * @return int Current page number |
|
308 | + */ |
|
309 | + public function get_paged() { |
|
310 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns bulk actions. |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @return void |
|
318 | + */ |
|
319 | + public function bulk_actions( $which = '' ) { |
|
320 | + return array(); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Prepares the display query |
|
325 | + */ |
|
326 | + public function prepare_query() { |
|
327 | + global $wpdb; |
|
328 | + |
|
329 | + $post_types = ''; |
|
330 | + |
|
331 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
332 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
333 | + } |
|
334 | + |
|
335 | + $post_types = rtrim( $post_types, ' OR' ); |
|
336 | + |
|
337 | + // Maybe search. |
|
338 | + if ( ! empty( $_POST['s'] ) ) { |
|
339 | + $users = get_users( |
|
340 | + array( |
|
341 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
342 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
343 | + 'fields' => 'ID', |
|
344 | + ) |
|
345 | + ); |
|
346 | + |
|
347 | + $users = implode( ', ', $users ); |
|
348 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
349 | + } |
|
350 | + |
|
351 | + // Users with invoices. |
|
352 | + $customers = $wpdb->get_col( |
|
353 | + $wpdb->prepare( |
|
354 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
355 | + $this->get_paged() * 10 - 10, |
|
356 | + $this->per_page |
|
357 | + ) |
|
358 | + ); |
|
359 | + |
|
360 | + $this->items = $customers; |
|
361 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Setup the final data for the table |
|
367 | + * |
|
368 | + * @since 1.0.19 |
|
369 | + * @return void |
|
370 | + */ |
|
371 | + public function prepare_items() { |
|
372 | + $columns = $this->get_columns(); |
|
373 | + $hidden = array(); // No hidden columns |
|
374 | + $sortable = $this->get_sortable_columns(); |
|
375 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
376 | + $this->prepare_query(); |
|
377 | + |
|
378 | + $this->set_pagination_args( |
|
379 | + array( |
|
380 | + 'total_items' => $this->total, |
|
381 | + 'per_page' => $this->per_page, |
|
382 | + 'total_pages' => ceil( $this->total / $this->per_page ) |
|
383 | + ) |
|
384 | + ); |
|
385 | + |
|
386 | + } |
|
387 | 387 | } |
@@ -14,89 +14,89 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct(){ |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct(){ |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
66 | 66 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
67 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
74 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
75 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
76 | - |
|
77 | - // Setup/welcome |
|
78 | - if ( ! empty( $_GET['page'] ) ) { |
|
79 | - switch ( $_GET['page'] ) { |
|
80 | - case 'gp-setup' : |
|
81 | - include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
82 | - break; |
|
83 | - } |
|
84 | - } |
|
67 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
69 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
70 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
74 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
75 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
76 | + |
|
77 | + // Setup/welcome |
|
78 | + if ( ! empty( $_GET['page'] ) ) { |
|
79 | + switch ( $_GET['page'] ) { |
|
80 | + case 'gp-setup' : |
|
81 | + include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' ); |
|
82 | + break; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Register admin scripts |
|
90 | - * |
|
91 | - */ |
|
92 | - public function enqeue_scripts() { |
|
89 | + * Register admin scripts |
|
90 | + * |
|
91 | + */ |
|
92 | + public function enqeue_scripts() { |
|
93 | 93 | global $current_screen, $pagenow; |
94 | 94 | |
95 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
96 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
95 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
96 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
97 | 97 | |
98 | 98 | if ( ! empty( $current_screen->post_type ) ) { |
99 | - $page = $current_screen->post_type; |
|
99 | + $page = $current_screen->post_type; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | // General styles. |
@@ -117,54 +117,54 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | // Payment form scripts. |
120 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
120 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
121 | 121 | $this->load_payment_form_scripts(); |
122 | 122 | } |
123 | 123 | |
124 | - if ( $page == 'wpinv-subscriptions' ) { |
|
125 | - wp_enqueue_script( 'postbox' ); |
|
126 | - } |
|
124 | + if ( $page == 'wpinv-subscriptions' ) { |
|
125 | + wp_enqueue_script( 'postbox' ); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | - * Returns admin js translations. |
|
132 | - * |
|
133 | - */ |
|
134 | - protected function get_admin_i18() { |
|
131 | + * Returns admin js translations. |
|
132 | + * |
|
133 | + */ |
|
134 | + protected function get_admin_i18() { |
|
135 | 135 | global $post; |
136 | 136 | |
137 | - $date_range = array( |
|
138 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
139 | - ); |
|
137 | + $date_range = array( |
|
138 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
139 | + ); |
|
140 | 140 | |
141 | - if ( $date_range['period'] == 'custom' ) { |
|
141 | + if ( $date_range['period'] == 'custom' ) { |
|
142 | 142 | |
143 | - if ( isset( $_GET['from'] ) ) { |
|
144 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
145 | - } |
|
143 | + if ( isset( $_GET['from'] ) ) { |
|
144 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
145 | + } |
|
146 | 146 | |
147 | - if ( isset( $_GET['to'] ) ) { |
|
148 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
149 | - } |
|
147 | + if ( isset( $_GET['to'] ) ) { |
|
148 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
149 | + } |
|
150 | 150 | |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | 153 | $i18n = array( |
154 | 154 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
155 | 155 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
156 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
157 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
158 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
159 | - 'date_range' => $date_range, |
|
156 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
157 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
158 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
159 | + 'date_range' => $date_range, |
|
160 | 160 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
161 | 161 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
162 | 162 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
163 | 163 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
164 | 164 | 'tax' => wpinv_tax_amount(), |
165 | 165 | 'discount' => 0, |
166 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
167 | - 'currency' => wpinv_get_currency(), |
|
166 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
167 | + 'currency' => wpinv_get_currency(), |
|
168 | 168 | 'currency_pos' => wpinv_currency_position(), |
169 | 169 | 'thousand_sep' => wpinv_thousands_separator(), |
170 | 170 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -184,118 +184,118 @@ discard block |
||
184 | 184 | 'item_description' => __( 'Item Description', 'invoicing' ), |
185 | 185 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
186 | 186 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
187 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
188 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
189 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
190 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
187 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
188 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
189 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
190 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
191 | 191 | ); |
192 | 192 | |
193 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
193 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
194 | 194 | |
195 | - $invoice = new WPInv_Invoice( $post ); |
|
196 | - $i18n['save_invoice'] = sprintf( |
|
197 | - __( 'Save %s', 'invoicing' ), |
|
198 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
199 | - ); |
|
195 | + $invoice = new WPInv_Invoice( $post ); |
|
196 | + $i18n['save_invoice'] = sprintf( |
|
197 | + __( 'Save %s', 'invoicing' ), |
|
198 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
199 | + ); |
|
200 | 200 | |
201 | - $i18n['invoice_description'] = sprintf( |
|
202 | - __( '%s Description', 'invoicing' ), |
|
203 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | - ); |
|
201 | + $i18n['invoice_description'] = sprintf( |
|
202 | + __( '%s Description', 'invoicing' ), |
|
203 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | + ); |
|
205 | 205 | |
206 | - } |
|
207 | - return $i18n; |
|
208 | - } |
|
206 | + } |
|
207 | + return $i18n; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * Change the admin footer text on GetPaid admin pages. |
|
212 | - * |
|
213 | - * @since 2.0.0 |
|
214 | - * @param string $footer_text |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - public function admin_footer_text( $footer_text ) { |
|
218 | - global $current_screen; |
|
210 | + /** |
|
211 | + * Change the admin footer text on GetPaid admin pages. |
|
212 | + * |
|
213 | + * @since 2.0.0 |
|
214 | + * @param string $footer_text |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + public function admin_footer_text( $footer_text ) { |
|
218 | + global $current_screen; |
|
219 | 219 | |
220 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
220 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
221 | 221 | |
222 | 222 | if ( ! empty( $current_screen->post_type ) ) { |
223 | - $page = $current_screen->post_type; |
|
223 | + $page = $current_screen->post_type; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // General styles. |
227 | 227 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
228 | 228 | |
229 | - // Change the footer text |
|
230 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
231 | - |
|
232 | - $rating_url = esc_url( |
|
233 | - wp_nonce_url( |
|
234 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
235 | - 'getpaid-nonce', |
|
236 | - 'getpaid-nonce' |
|
237 | - ) |
|
238 | - ); |
|
239 | - |
|
240 | - $footer_text = sprintf( |
|
241 | - /* translators: %s: five stars */ |
|
242 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
243 | - "<a href='$rating_url'>★★★★★</a>" |
|
244 | - ); |
|
245 | - |
|
246 | - } else { |
|
247 | - |
|
248 | - $footer_text = sprintf( |
|
249 | - /* translators: %s: GetPaid */ |
|
250 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
251 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
252 | - ); |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - return $footer_text; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Redirects to wp.org to rate the plugin. |
|
263 | - * |
|
264 | - * @since 2.0.0 |
|
265 | - */ |
|
266 | - public function redirect_to_wordpress_rating_page() { |
|
267 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
268 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
269 | - exit; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Loads payment form js. |
|
274 | - * |
|
275 | - */ |
|
276 | - protected function load_payment_form_scripts() { |
|
229 | + // Change the footer text |
|
230 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
231 | + |
|
232 | + $rating_url = esc_url( |
|
233 | + wp_nonce_url( |
|
234 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
235 | + 'getpaid-nonce', |
|
236 | + 'getpaid-nonce' |
|
237 | + ) |
|
238 | + ); |
|
239 | + |
|
240 | + $footer_text = sprintf( |
|
241 | + /* translators: %s: five stars */ |
|
242 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
243 | + "<a href='$rating_url'>★★★★★</a>" |
|
244 | + ); |
|
245 | + |
|
246 | + } else { |
|
247 | + |
|
248 | + $footer_text = sprintf( |
|
249 | + /* translators: %s: GetPaid */ |
|
250 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
251 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
252 | + ); |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + return $footer_text; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Redirects to wp.org to rate the plugin. |
|
263 | + * |
|
264 | + * @since 2.0.0 |
|
265 | + */ |
|
266 | + public function redirect_to_wordpress_rating_page() { |
|
267 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
268 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
269 | + exit; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Loads payment form js. |
|
274 | + * |
|
275 | + */ |
|
276 | + protected function load_payment_form_scripts() { |
|
277 | 277 | global $post; |
278 | 278 | |
279 | 279 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
280 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
281 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
280 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
281 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
282 | 282 | |
283 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
284 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
283 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
284 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
285 | 285 | |
286 | - wp_localize_script( |
|
286 | + wp_localize_script( |
|
287 | 287 | 'wpinv-admin-payment-form-script', |
288 | 288 | 'wpinvPaymentFormAdmin', |
289 | 289 | array( |
290 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
291 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
292 | - 'currency' => wpinv_currency_symbol(), |
|
293 | - 'position' => wpinv_currency_position(), |
|
294 | - 'decimals' => (int) wpinv_decimals(), |
|
295 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
296 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
297 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
298 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
290 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
291 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
292 | + 'currency' => wpinv_currency_symbol(), |
|
293 | + 'position' => wpinv_currency_position(), |
|
294 | + 'decimals' => (int) wpinv_decimals(), |
|
295 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
296 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
297 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
298 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
299 | 299 | ) |
300 | 300 | ); |
301 | 301 | |
@@ -304,20 +304,20 @@ discard block |
||
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
307 | - * Add our classes to admin pages. |
|
307 | + * Add our classes to admin pages. |
|
308 | 308 | * |
309 | 309 | * @param string $classes |
310 | 310 | * @return string |
311 | - * |
|
312 | - */ |
|
311 | + * |
|
312 | + */ |
|
313 | 313 | public function admin_body_class( $classes ) { |
314 | - global $pagenow, $post, $current_screen; |
|
314 | + global $pagenow, $post, $current_screen; |
|
315 | 315 | |
316 | 316 | |
317 | 317 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
318 | 318 | |
319 | 319 | if ( ! empty( $current_screen->post_type ) ) { |
320 | - $page = $current_screen->post_type; |
|
320 | + $page = $current_screen->post_type; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -326,68 +326,68 @@ discard block |
||
326 | 326 | |
327 | 327 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
328 | 328 | $classes .= ' wpinv-cpt wpinv'; |
329 | - } |
|
329 | + } |
|
330 | 330 | |
331 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
331 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
332 | 332 | $classes .= ' getpaid-is-invoice-cpt'; |
333 | 333 | } |
334 | 334 | |
335 | - return $classes; |
|
335 | + return $classes; |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
339 | - * Maybe show the AyeCode Connect Notice. |
|
340 | - */ |
|
341 | - public function init_ayecode_connect_helper(){ |
|
339 | + * Maybe show the AyeCode Connect Notice. |
|
340 | + */ |
|
341 | + public function init_ayecode_connect_helper(){ |
|
342 | 342 | |
343 | - // Register with the deactivation survey class. |
|
344 | - AyeCode_Deactivation_Survey::instance(array( |
|
345 | - 'slug' => 'invoicing', |
|
346 | - 'version' => WPINV_VERSION, |
|
347 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
348 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
349 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
350 | - )); |
|
343 | + // Register with the deactivation survey class. |
|
344 | + AyeCode_Deactivation_Survey::instance(array( |
|
345 | + 'slug' => 'invoicing', |
|
346 | + 'version' => WPINV_VERSION, |
|
347 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
348 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
349 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
350 | + )); |
|
351 | 351 | |
352 | 352 | new AyeCode_Connect_Helper( |
353 | 353 | array( |
354 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
355 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
356 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
357 | - 'connect_button' => __("Connect Site","invoicing"), |
|
358 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
359 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
360 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
354 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
355 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
356 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
357 | + 'connect_button' => __("Connect Site","invoicing"), |
|
358 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
359 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
360 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
361 | 361 | ), |
362 | 362 | array( 'wpi-addons' ) |
363 | 363 | ); |
364 | 364 | |
365 | 365 | } |
366 | 366 | |
367 | - /** |
|
368 | - * Redirect users to settings on activation. |
|
369 | - * |
|
370 | - * @return void |
|
371 | - */ |
|
372 | - public function activation_redirect() { |
|
367 | + /** |
|
368 | + * Redirect users to settings on activation. |
|
369 | + * |
|
370 | + * @return void |
|
371 | + */ |
|
372 | + public function activation_redirect() { |
|
373 | 373 | |
374 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
374 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
375 | 375 | |
376 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
377 | - return; |
|
378 | - } |
|
376 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
377 | + return; |
|
378 | + } |
|
379 | 379 | |
380 | - // Bail if activating from network, or bulk |
|
381 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
382 | - return; |
|
383 | - } |
|
380 | + // Bail if activating from network, or bulk |
|
381 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
382 | + return; |
|
383 | + } |
|
384 | 384 | |
385 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
385 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
386 | 386 | |
387 | 387 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
388 | 388 | exit; |
389 | 389 | |
390 | - } |
|
390 | + } |
|
391 | 391 | |
392 | 392 | /** |
393 | 393 | * Fires an admin action after verifying that a user can fire them. |
@@ -401,458 +401,458 @@ discard block |
||
401 | 401 | |
402 | 402 | } |
403 | 403 | |
404 | - /** |
|
404 | + /** |
|
405 | 405 | * Sends a payment reminder to a customer. |
406 | - * |
|
407 | - * @param array $args |
|
406 | + * |
|
407 | + * @param array $args |
|
408 | 408 | */ |
409 | 409 | public function send_customer_invoice( $args ) { |
410 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
410 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
411 | 411 | |
412 | - if ( $sent ) { |
|
413 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
414 | - } else { |
|
415 | - $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) ); |
|
416 | - } |
|
412 | + if ( $sent ) { |
|
413 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
414 | + } else { |
|
415 | + $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) ); |
|
416 | + } |
|
417 | 417 | |
418 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
419 | - exit; |
|
420 | - } |
|
418 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
419 | + exit; |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
422 | + /** |
|
423 | 423 | * Sends a payment reminder to a customer. |
424 | - * |
|
425 | - * @param array $args |
|
424 | + * |
|
425 | + * @param array $args |
|
426 | 426 | */ |
427 | 427 | public function send_customer_payment_reminder( $args ) { |
428 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
428 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
429 | 429 | |
430 | - if ( $sent ) { |
|
431 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
432 | - } else { |
|
433 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
434 | - } |
|
430 | + if ( $sent ) { |
|
431 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
432 | + } else { |
|
433 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
434 | + } |
|
435 | 435 | |
436 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
437 | - exit; |
|
438 | - } |
|
436 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
437 | + exit; |
|
438 | + } |
|
439 | 439 | |
440 | - /** |
|
440 | + /** |
|
441 | 441 | * Resets tax rates. |
442 | - * |
|
442 | + * |
|
443 | 443 | */ |
444 | 444 | public function admin_reset_tax_rates() { |
445 | 445 | |
446 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
447 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
448 | - exit; |
|
446 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
447 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
448 | + exit; |
|
449 | 449 | |
450 | - } |
|
450 | + } |
|
451 | 451 | |
452 | - /** |
|
452 | + /** |
|
453 | 453 | * Resets admin pages. |
454 | - * |
|
454 | + * |
|
455 | 455 | */ |
456 | 456 | public function admin_create_missing_pages() { |
457 | - $installer = new GetPaid_Installer(); |
|
458 | - $installer->create_pages(); |
|
459 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
460 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
461 | - exit; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
457 | + $installer = new GetPaid_Installer(); |
|
458 | + $installer->create_pages(); |
|
459 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
460 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
461 | + exit; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | 465 | * Creates an missing admin tables. |
466 | - * |
|
466 | + * |
|
467 | 467 | */ |
468 | 468 | public function admin_create_missing_tables() { |
469 | - global $wpdb; |
|
470 | - $installer = new GetPaid_Installer(); |
|
469 | + global $wpdb; |
|
470 | + $installer = new GetPaid_Installer(); |
|
471 | 471 | |
472 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
473 | - $installer->create_subscriptions_table(); |
|
472 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
473 | + $installer->create_subscriptions_table(); |
|
474 | 474 | |
475 | - if ( $wpdb->last_error !== '' ) { |
|
476 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
477 | - } |
|
478 | - } |
|
475 | + if ( $wpdb->last_error !== '' ) { |
|
476 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
477 | + } |
|
478 | + } |
|
479 | 479 | |
480 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
481 | - $installer->create_invoices_table(); |
|
480 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
481 | + $installer->create_invoices_table(); |
|
482 | 482 | |
483 | - if ( $wpdb->last_error !== '' ) { |
|
484 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
485 | - } |
|
486 | - } |
|
483 | + if ( $wpdb->last_error !== '' ) { |
|
484 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
485 | + } |
|
486 | + } |
|
487 | 487 | |
488 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
489 | - $installer->create_invoice_items_table(); |
|
488 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
489 | + $installer->create_invoice_items_table(); |
|
490 | 490 | |
491 | - if ( $wpdb->last_error !== '' ) { |
|
492 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
493 | - } |
|
494 | - } |
|
491 | + if ( $wpdb->last_error !== '' ) { |
|
492 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
493 | + } |
|
494 | + } |
|
495 | 495 | |
496 | - if ( ! $this->has_notices() ) { |
|
497 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
498 | - } |
|
496 | + if ( ! $this->has_notices() ) { |
|
497 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
498 | + } |
|
499 | 499 | |
500 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
501 | - exit; |
|
502 | - } |
|
500 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
501 | + exit; |
|
502 | + } |
|
503 | 503 | |
504 | - /** |
|
504 | + /** |
|
505 | 505 | * Migrates old invoices to the new database tables. |
506 | - * |
|
506 | + * |
|
507 | 507 | */ |
508 | 508 | public function admin_migrate_old_invoices() { |
509 | 509 | |
510 | - // Migrate the invoices. |
|
511 | - $installer = new GetPaid_Installer(); |
|
512 | - $installer->migrate_old_invoices(); |
|
510 | + // Migrate the invoices. |
|
511 | + $installer = new GetPaid_Installer(); |
|
512 | + $installer->migrate_old_invoices(); |
|
513 | 513 | |
514 | - // Show an admin message. |
|
515 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
514 | + // Show an admin message. |
|
515 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
516 | 516 | |
517 | - // Redirect the admin. |
|
518 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
519 | - exit; |
|
517 | + // Redirect the admin. |
|
518 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
519 | + exit; |
|
520 | 520 | |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | - /** |
|
523 | + /** |
|
524 | 524 | * Download customers. |
525 | - * |
|
525 | + * |
|
526 | 526 | */ |
527 | 527 | public function admin_download_customers() { |
528 | - global $wpdb; |
|
528 | + global $wpdb; |
|
529 | 529 | |
530 | - $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
530 | + $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) ); |
|
531 | 531 | |
532 | - header( "Content-Type:text/csv" ); |
|
533 | - header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
532 | + header( "Content-Type:text/csv" ); |
|
533 | + header( "Content-Disposition:attachment;filename=customers.csv" ); |
|
534 | 534 | |
535 | - $post_types = ''; |
|
535 | + $post_types = ''; |
|
536 | 536 | |
537 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
538 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
539 | - } |
|
537 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
538 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
539 | + } |
|
540 | 540 | |
541 | - $post_types = rtrim( $post_types, ' OR' ); |
|
541 | + $post_types = rtrim( $post_types, ' OR' ); |
|
542 | 542 | |
543 | - $customers = $wpdb->get_col( |
|
544 | - $wpdb->prepare( |
|
545 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
546 | - ) |
|
547 | - ); |
|
543 | + $customers = $wpdb->get_col( |
|
544 | + $wpdb->prepare( |
|
545 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" |
|
546 | + ) |
|
547 | + ); |
|
548 | 548 | |
549 | - $columns = array( |
|
550 | - 'name' => __( 'Name', 'invoicing' ), |
|
551 | - 'email' => __( 'Email', 'invoicing' ), |
|
552 | - 'country' => __( 'Country', 'invoicing' ), |
|
553 | - 'state' => __( 'State', 'invoicing' ), |
|
554 | - 'city' => __( 'City', 'invoicing' ), |
|
555 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
556 | - 'address' => __( 'Address', 'invoicing' ), |
|
557 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
558 | - 'company' => __( 'Company', 'invoicing' ), |
|
559 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
560 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
561 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
562 | - ); |
|
549 | + $columns = array( |
|
550 | + 'name' => __( 'Name', 'invoicing' ), |
|
551 | + 'email' => __( 'Email', 'invoicing' ), |
|
552 | + 'country' => __( 'Country', 'invoicing' ), |
|
553 | + 'state' => __( 'State', 'invoicing' ), |
|
554 | + 'city' => __( 'City', 'invoicing' ), |
|
555 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
556 | + 'address' => __( 'Address', 'invoicing' ), |
|
557 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
558 | + 'company' => __( 'Company', 'invoicing' ), |
|
559 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
560 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
561 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
562 | + ); |
|
563 | 563 | |
564 | - // Output the csv column headers. |
|
565 | - fputcsv( $output, array_values( $columns ) ); |
|
564 | + // Output the csv column headers. |
|
565 | + fputcsv( $output, array_values( $columns ) ); |
|
566 | 566 | |
567 | - // Loop through |
|
568 | - $table = new WPInv_Customers_Table(); |
|
569 | - foreach ( $customers as $customer_id ) { |
|
567 | + // Loop through |
|
568 | + $table = new WPInv_Customers_Table(); |
|
569 | + foreach ( $customers as $customer_id ) { |
|
570 | 570 | |
571 | - $user = get_user_by( 'id', $customer_id ); |
|
572 | - $row = array(); |
|
573 | - if ( empty( $user ) ) { |
|
574 | - continue; |
|
575 | - } |
|
571 | + $user = get_user_by( 'id', $customer_id ); |
|
572 | + $row = array(); |
|
573 | + if ( empty( $user ) ) { |
|
574 | + continue; |
|
575 | + } |
|
576 | 576 | |
577 | - foreach ( array_keys( $columns ) as $column ) { |
|
577 | + foreach ( array_keys( $columns ) as $column ) { |
|
578 | 578 | |
579 | - $method = 'column_' . $column; |
|
579 | + $method = 'column_' . $column; |
|
580 | 580 | |
581 | - if ( 'name' == $column ) { |
|
582 | - $value = sanitize_text_field( $user->display_name ); |
|
583 | - } else if( 'email' == $column ) { |
|
584 | - $value = sanitize_email( $user->user_email ); |
|
585 | - } else if ( is_callable( array( $table, $method ) ) ) { |
|
586 | - $value = strip_tags( $table->$method( $user ) ); |
|
587 | - } |
|
581 | + if ( 'name' == $column ) { |
|
582 | + $value = sanitize_text_field( $user->display_name ); |
|
583 | + } else if( 'email' == $column ) { |
|
584 | + $value = sanitize_email( $user->user_email ); |
|
585 | + } else if ( is_callable( array( $table, $method ) ) ) { |
|
586 | + $value = strip_tags( $table->$method( $user ) ); |
|
587 | + } |
|
588 | 588 | |
589 | - if ( empty( $value ) ) { |
|
590 | - $value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
591 | - } |
|
589 | + if ( empty( $value ) ) { |
|
590 | + $value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
591 | + } |
|
592 | 592 | |
593 | - $row[] = $value; |
|
593 | + $row[] = $value; |
|
594 | 594 | |
595 | - } |
|
595 | + } |
|
596 | 596 | |
597 | - fputcsv( $output, $row ); |
|
598 | - } |
|
597 | + fputcsv( $output, $row ); |
|
598 | + } |
|
599 | 599 | |
600 | - fclose( $output ); |
|
601 | - exit; |
|
600 | + fclose( $output ); |
|
601 | + exit; |
|
602 | 602 | |
603 | - } |
|
603 | + } |
|
604 | 604 | |
605 | - /** |
|
605 | + /** |
|
606 | 606 | * Installs a plugin. |
607 | - * |
|
608 | - * @param array $data |
|
607 | + * |
|
608 | + * @param array $data |
|
609 | 609 | */ |
610 | 610 | public function admin_install_plugin( $data ) { |
611 | 611 | |
612 | - if ( ! empty( $data['plugins'] ) ) { |
|
613 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
614 | - wp_cache_flush(); |
|
612 | + if ( ! empty( $data['plugins'] ) ) { |
|
613 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
614 | + wp_cache_flush(); |
|
615 | 615 | |
616 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
617 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
618 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
619 | - $installed = $upgrader->install( $plugin_zip ); |
|
616 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
617 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
618 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
619 | + $installed = $upgrader->install( $plugin_zip ); |
|
620 | 620 | |
621 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
622 | - activate_plugin( $file, '', false, true ); |
|
623 | - } else { |
|
624 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
625 | - } |
|
621 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
622 | + activate_plugin( $file, '', false, true ); |
|
623 | + } else { |
|
624 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
625 | + } |
|
626 | 626 | |
627 | - } |
|
627 | + } |
|
628 | 628 | |
629 | - } |
|
629 | + } |
|
630 | 630 | |
631 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
632 | - wp_safe_redirect( $redirect ); |
|
633 | - exit; |
|
631 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
632 | + wp_safe_redirect( $redirect ); |
|
633 | + exit; |
|
634 | 634 | |
635 | - } |
|
635 | + } |
|
636 | 636 | |
637 | - /** |
|
637 | + /** |
|
638 | 638 | * Connects a gateway. |
639 | - * |
|
640 | - * @param array $data |
|
639 | + * |
|
640 | + * @param array $data |
|
641 | 641 | */ |
642 | 642 | public function admin_connect_gateway( $data ) { |
643 | 643 | |
644 | - if ( ! empty( $data['plugin'] ) ) { |
|
644 | + if ( ! empty( $data['plugin'] ) ) { |
|
645 | 645 | |
646 | - $gateway = sanitize_key( $data['plugin'] ); |
|
647 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
646 | + $gateway = sanitize_key( $data['plugin'] ); |
|
647 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
648 | 648 | |
649 | - if ( ! empty( $connect_url ) ) { |
|
650 | - wp_redirect( $connect_url ); |
|
651 | - exit; |
|
652 | - } |
|
649 | + if ( ! empty( $connect_url ) ) { |
|
650 | + wp_redirect( $connect_url ); |
|
651 | + exit; |
|
652 | + } |
|
653 | 653 | |
654 | - if ( 'stripe' == $data['plugin'] ) { |
|
655 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
654 | + if ( 'stripe' == $data['plugin'] ) { |
|
655 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
656 | 656 | |
657 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
658 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
659 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
660 | - $upgrader->install( $plugin_zip ); |
|
661 | - } |
|
657 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
658 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
659 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
660 | + $upgrader->install( $plugin_zip ); |
|
661 | + } |
|
662 | 662 | |
663 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
664 | - } |
|
663 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
664 | + } |
|
665 | 665 | |
666 | - if ( ! empty( $connect_url ) ) { |
|
667 | - wp_redirect( $connect_url ); |
|
668 | - exit; |
|
669 | - } |
|
666 | + if ( ! empty( $connect_url ) ) { |
|
667 | + wp_redirect( $connect_url ); |
|
668 | + exit; |
|
669 | + } |
|
670 | 670 | |
671 | - } |
|
671 | + } |
|
672 | 672 | |
673 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
674 | - wp_safe_redirect( $redirect ); |
|
675 | - exit; |
|
673 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
674 | + wp_safe_redirect( $redirect ); |
|
675 | + exit; |
|
676 | 676 | |
677 | - } |
|
677 | + } |
|
678 | 678 | |
679 | - /** |
|
679 | + /** |
|
680 | 680 | * Recalculates discounts. |
681 | - * |
|
681 | + * |
|
682 | 682 | */ |
683 | 683 | public function admin_recalculate_discounts() { |
684 | - global $wpdb; |
|
684 | + global $wpdb; |
|
685 | 685 | |
686 | - // Fetch all invoices that have discount codes. |
|
687 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
688 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
686 | + // Fetch all invoices that have discount codes. |
|
687 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
688 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
689 | 689 | |
690 | - foreach ( $invoices as $invoice ) { |
|
690 | + foreach ( $invoices as $invoice ) { |
|
691 | 691 | |
692 | - $invoice = new WPInv_Invoice( $invoice ); |
|
692 | + $invoice = new WPInv_Invoice( $invoice ); |
|
693 | 693 | |
694 | - if ( ! $invoice->exists() ) { |
|
695 | - continue; |
|
696 | - } |
|
694 | + if ( ! $invoice->exists() ) { |
|
695 | + continue; |
|
696 | + } |
|
697 | 697 | |
698 | - // Abort if the discount does not exist or does not apply here. |
|
699 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
700 | - if ( ! $discount->exists() ) { |
|
701 | - continue; |
|
702 | - } |
|
698 | + // Abort if the discount does not exist or does not apply here. |
|
699 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
700 | + if ( ! $discount->exists() ) { |
|
701 | + continue; |
|
702 | + } |
|
703 | 703 | |
704 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
705 | - $invoice->recalculate_total(); |
|
704 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
705 | + $invoice->recalculate_total(); |
|
706 | 706 | |
707 | - if ( $invoice->get_total_discount() > 0 ) { |
|
708 | - $invoice->save(); |
|
709 | - } |
|
707 | + if ( $invoice->get_total_discount() > 0 ) { |
|
708 | + $invoice->save(); |
|
709 | + } |
|
710 | 710 | |
711 | - } |
|
711 | + } |
|
712 | 712 | |
713 | - // Show an admin message. |
|
714 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
713 | + // Show an admin message. |
|
714 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
715 | 715 | |
716 | - // Redirect the admin. |
|
717 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
718 | - exit; |
|
716 | + // Redirect the admin. |
|
717 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
718 | + exit; |
|
719 | 719 | |
720 | - } |
|
720 | + } |
|
721 | 721 | |
722 | 722 | /** |
723 | - * Returns an array of admin notices. |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
723 | + * Returns an array of admin notices. |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | 726 | * @return array |
727 | - */ |
|
728 | - public function get_notices() { |
|
729 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
727 | + */ |
|
728 | + public function get_notices() { |
|
729 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
730 | 730 | return is_array( $notices ) ? $notices : array(); |
731 | - } |
|
731 | + } |
|
732 | 732 | |
733 | - /** |
|
734 | - * Checks if we have any admin notices. |
|
735 | - * |
|
736 | - * @since 2.0.4 |
|
733 | + /** |
|
734 | + * Checks if we have any admin notices. |
|
735 | + * |
|
736 | + * @since 2.0.4 |
|
737 | 737 | * @return array |
738 | - */ |
|
739 | - public function has_notices() { |
|
740 | - return count( $this->get_notices() ) > 0; |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Clears all admin notices |
|
745 | - * |
|
746 | - * @access public |
|
747 | - * @since 1.0.19 |
|
748 | - */ |
|
749 | - public function clear_notices() { |
|
750 | - delete_option( 'wpinv_admin_notices' ); |
|
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Saves a new admin notice |
|
755 | - * |
|
756 | - * @access public |
|
757 | - * @since 1.0.19 |
|
758 | - */ |
|
759 | - public function save_notice( $type, $message ) { |
|
760 | - $notices = $this->get_notices(); |
|
761 | - |
|
762 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
763 | - $notices[ $type ] = array(); |
|
764 | - } |
|
765 | - |
|
766 | - $notices[ $type ][] = $message; |
|
767 | - |
|
768 | - update_option( 'wpinv_admin_notices', $notices ); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Displays a success notice |
|
773 | - * |
|
774 | - * @param string $msg The message to qeue. |
|
775 | - * @access public |
|
776 | - * @since 1.0.19 |
|
777 | - */ |
|
778 | - public function show_success( $msg ) { |
|
779 | - $this->save_notice( 'success', $msg ); |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Displays a error notice |
|
784 | - * |
|
785 | - * @access public |
|
786 | - * @param string $msg The message to qeue. |
|
787 | - * @since 1.0.19 |
|
788 | - */ |
|
789 | - public function show_error( $msg ) { |
|
790 | - $this->save_notice( 'error', $msg ); |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Displays a warning notice |
|
795 | - * |
|
796 | - * @access public |
|
797 | - * @param string $msg The message to qeue. |
|
798 | - * @since 1.0.19 |
|
799 | - */ |
|
800 | - public function show_warning( $msg ) { |
|
801 | - $this->save_notice( 'warning', $msg ); |
|
802 | - } |
|
803 | - |
|
804 | - /** |
|
805 | - * Displays a info notice |
|
806 | - * |
|
807 | - * @access public |
|
808 | - * @param string $msg The message to qeue. |
|
809 | - * @since 1.0.19 |
|
810 | - */ |
|
811 | - public function show_info( $msg ) { |
|
812 | - $this->save_notice( 'info', $msg ); |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Show notices |
|
817 | - * |
|
818 | - * @access public |
|
819 | - * @since 1.0.19 |
|
820 | - */ |
|
821 | - public function show_notices() { |
|
738 | + */ |
|
739 | + public function has_notices() { |
|
740 | + return count( $this->get_notices() ) > 0; |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Clears all admin notices |
|
745 | + * |
|
746 | + * @access public |
|
747 | + * @since 1.0.19 |
|
748 | + */ |
|
749 | + public function clear_notices() { |
|
750 | + delete_option( 'wpinv_admin_notices' ); |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Saves a new admin notice |
|
755 | + * |
|
756 | + * @access public |
|
757 | + * @since 1.0.19 |
|
758 | + */ |
|
759 | + public function save_notice( $type, $message ) { |
|
760 | + $notices = $this->get_notices(); |
|
761 | + |
|
762 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
763 | + $notices[ $type ] = array(); |
|
764 | + } |
|
765 | + |
|
766 | + $notices[ $type ][] = $message; |
|
767 | + |
|
768 | + update_option( 'wpinv_admin_notices', $notices ); |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Displays a success notice |
|
773 | + * |
|
774 | + * @param string $msg The message to qeue. |
|
775 | + * @access public |
|
776 | + * @since 1.0.19 |
|
777 | + */ |
|
778 | + public function show_success( $msg ) { |
|
779 | + $this->save_notice( 'success', $msg ); |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Displays a error notice |
|
784 | + * |
|
785 | + * @access public |
|
786 | + * @param string $msg The message to qeue. |
|
787 | + * @since 1.0.19 |
|
788 | + */ |
|
789 | + public function show_error( $msg ) { |
|
790 | + $this->save_notice( 'error', $msg ); |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Displays a warning notice |
|
795 | + * |
|
796 | + * @access public |
|
797 | + * @param string $msg The message to qeue. |
|
798 | + * @since 1.0.19 |
|
799 | + */ |
|
800 | + public function show_warning( $msg ) { |
|
801 | + $this->save_notice( 'warning', $msg ); |
|
802 | + } |
|
803 | + |
|
804 | + /** |
|
805 | + * Displays a info notice |
|
806 | + * |
|
807 | + * @access public |
|
808 | + * @param string $msg The message to qeue. |
|
809 | + * @since 1.0.19 |
|
810 | + */ |
|
811 | + public function show_info( $msg ) { |
|
812 | + $this->save_notice( 'info', $msg ); |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Show notices |
|
817 | + * |
|
818 | + * @access public |
|
819 | + * @since 1.0.19 |
|
820 | + */ |
|
821 | + public function show_notices() { |
|
822 | 822 | |
823 | 823 | $notices = $this->get_notices(); |
824 | 824 | $this->clear_notices(); |
825 | 825 | |
826 | - foreach ( $notices as $type => $messages ) { |
|
826 | + foreach ( $notices as $type => $messages ) { |
|
827 | 827 | |
828 | - if ( ! is_array( $messages ) ) { |
|
829 | - continue; |
|
830 | - } |
|
828 | + if ( ! is_array( $messages ) ) { |
|
829 | + continue; |
|
830 | + } |
|
831 | 831 | |
832 | 832 | $type = sanitize_key( $type ); |
833 | - foreach ( $messages as $message ) { |
|
833 | + foreach ( $messages as $message ) { |
|
834 | 834 | $message = wp_kses_post( $message ); |
835 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
835 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
836 | 836 | } |
837 | 837 | |
838 | 838 | } |
839 | 839 | |
840 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
841 | - |
|
842 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
843 | - $url = wp_nonce_url( |
|
844 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
845 | - 'getpaid-nonce', |
|
846 | - 'getpaid-nonce' |
|
847 | - ); |
|
848 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
849 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
850 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
851 | - break; |
|
852 | - } |
|
840 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
841 | + |
|
842 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
843 | + $url = wp_nonce_url( |
|
844 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
845 | + 'getpaid-nonce', |
|
846 | + 'getpaid-nonce' |
|
847 | + ); |
|
848 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
849 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
850 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
851 | + break; |
|
852 | + } |
|
853 | 853 | |
854 | - } |
|
854 | + } |
|
855 | 855 | |
856 | - } |
|
856 | + } |
|
857 | 857 | |
858 | 858 | } |
@@ -15,331 +15,331 @@ |
||
15 | 15 | class GetPaid_Post_Types { |
16 | 16 | |
17 | 17 | /** |
18 | - * Hook in methods. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
21 | - add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | - add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | - add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | - add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | - } |
|
18 | + * Hook in methods. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | + add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | + add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | + add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | + add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Register core post types. |
|
29 | - */ |
|
30 | - public static function register_post_types() { |
|
27 | + /** |
|
28 | + * Register core post types. |
|
29 | + */ |
|
30 | + public static function register_post_types() { |
|
31 | 31 | |
32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | - return; |
|
34 | - } |
|
32 | + if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - $capabilities = wpinv_current_user_can_manage_invoicing(); |
|
36 | + $capabilities = wpinv_current_user_can_manage_invoicing(); |
|
37 | 37 | |
38 | - // Fires before registering post types. |
|
39 | - do_action( 'getpaid_register_post_types' ); |
|
38 | + // Fires before registering post types. |
|
39 | + do_action( 'getpaid_register_post_types' ); |
|
40 | 40 | |
41 | - // Register item post type. |
|
42 | - register_post_type( |
|
43 | - 'wpi_item', |
|
44 | - apply_filters( |
|
45 | - 'wpinv_register_post_type_invoice_item', |
|
46 | - array( |
|
47 | - 'labels' => array( |
|
48 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
49 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
50 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
51 | - 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
52 | - 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
53 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
54 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
55 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
56 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
57 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
58 | - 'search_items' => __( 'Search items', 'invoicing' ), |
|
59 | - 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
60 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
61 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
62 | - ), |
|
63 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
64 | - 'public' => false, |
|
65 | - 'has_archive' => false, |
|
66 | - '_builtin' => false, |
|
67 | - 'show_ui' => true, |
|
68 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
69 | - 'show_in_nav_menus' => false, |
|
70 | - 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
71 | - 'rewrite' => false, |
|
72 | - 'query_var' => false, |
|
73 | - 'map_meta_cap' => true, |
|
74 | - 'show_in_admin_bar' => true, |
|
75 | - 'can_export' => true, |
|
76 | - ) |
|
77 | - ) |
|
78 | - ); |
|
41 | + // Register item post type. |
|
42 | + register_post_type( |
|
43 | + 'wpi_item', |
|
44 | + apply_filters( |
|
45 | + 'wpinv_register_post_type_invoice_item', |
|
46 | + array( |
|
47 | + 'labels' => array( |
|
48 | + 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
49 | + 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
50 | + 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
51 | + 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
52 | + 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
53 | + 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
54 | + 'new_item' => __( 'New Item', 'invoicing' ), |
|
55 | + 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
56 | + 'view_item' => __( 'View Item', 'invoicing' ), |
|
57 | + 'all_items' => __( 'Items', 'invoicing' ), |
|
58 | + 'search_items' => __( 'Search items', 'invoicing' ), |
|
59 | + 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
60 | + 'not_found' => __( 'No items found.', 'invoicing' ), |
|
61 | + 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
62 | + ), |
|
63 | + 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
64 | + 'public' => false, |
|
65 | + 'has_archive' => false, |
|
66 | + '_builtin' => false, |
|
67 | + 'show_ui' => true, |
|
68 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
69 | + 'show_in_nav_menus' => false, |
|
70 | + 'supports' => array( 'title', 'excerpt', 'thumbnail' ), |
|
71 | + 'rewrite' => false, |
|
72 | + 'query_var' => false, |
|
73 | + 'map_meta_cap' => true, |
|
74 | + 'show_in_admin_bar' => true, |
|
75 | + 'can_export' => true, |
|
76 | + ) |
|
77 | + ) |
|
78 | + ); |
|
79 | 79 | |
80 | - // Register payment form post type. |
|
81 | - register_post_type( |
|
82 | - 'wpi_payment_form', |
|
83 | - apply_filters( |
|
84 | - 'wpinv_register_post_type_payment_form', |
|
85 | - array( |
|
86 | - 'labels' => array( |
|
87 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
88 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
89 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
90 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
91 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
92 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
93 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
94 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
95 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
96 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
97 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
98 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
99 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
100 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
101 | - ), |
|
102 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
103 | - 'public' => false, |
|
104 | - 'show_ui' => true, |
|
105 | - 'show_in_menu' => $capabilities ? 'wpinv' : false, |
|
106 | - 'show_in_nav_menus' => false, |
|
107 | - 'query_var' => false, |
|
108 | - 'rewrite' => true, |
|
109 | - 'map_meta_cap' => true, |
|
110 | - 'has_archive' => false, |
|
111 | - 'hierarchical' => false, |
|
112 | - 'menu_position' => null, |
|
113 | - 'supports' => array( 'title' ), |
|
114 | - 'menu_icon' => 'dashicons-media-form', |
|
115 | - 'capabilities' => array( |
|
116 | - 'edit_post' => $capabilities, |
|
117 | - 'read_post' => $capabilities, |
|
118 | - 'delete_post' => $capabilities, |
|
119 | - 'edit_posts' => 'update_core', |
|
120 | - 'edit_others_posts' => 'update_core', |
|
121 | - 'delete_posts' => 'update_core', |
|
122 | - 'publish_posts' => 'update_core', |
|
123 | - 'read_private_posts' => 'update_core' |
|
124 | - ), |
|
125 | - ) |
|
126 | - ) |
|
127 | - ); |
|
80 | + // Register payment form post type. |
|
81 | + register_post_type( |
|
82 | + 'wpi_payment_form', |
|
83 | + apply_filters( |
|
84 | + 'wpinv_register_post_type_payment_form', |
|
85 | + array( |
|
86 | + 'labels' => array( |
|
87 | + 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
88 | + 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
89 | + 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
90 | + 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
91 | + 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
92 | + 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
93 | + 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
94 | + 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
95 | + 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
96 | + 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
97 | + 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
98 | + 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
99 | + 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
100 | + 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
101 | + ), |
|
102 | + 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
103 | + 'public' => false, |
|
104 | + 'show_ui' => true, |
|
105 | + 'show_in_menu' => $capabilities ? 'wpinv' : false, |
|
106 | + 'show_in_nav_menus' => false, |
|
107 | + 'query_var' => false, |
|
108 | + 'rewrite' => true, |
|
109 | + 'map_meta_cap' => true, |
|
110 | + 'has_archive' => false, |
|
111 | + 'hierarchical' => false, |
|
112 | + 'menu_position' => null, |
|
113 | + 'supports' => array( 'title' ), |
|
114 | + 'menu_icon' => 'dashicons-media-form', |
|
115 | + 'capabilities' => array( |
|
116 | + 'edit_post' => $capabilities, |
|
117 | + 'read_post' => $capabilities, |
|
118 | + 'delete_post' => $capabilities, |
|
119 | + 'edit_posts' => 'update_core', |
|
120 | + 'edit_others_posts' => 'update_core', |
|
121 | + 'delete_posts' => 'update_core', |
|
122 | + 'publish_posts' => 'update_core', |
|
123 | + 'read_private_posts' => 'update_core' |
|
124 | + ), |
|
125 | + ) |
|
126 | + ) |
|
127 | + ); |
|
128 | 128 | |
129 | - // Register invoice post type. |
|
130 | - register_post_type( |
|
131 | - 'wpi_invoice', |
|
132 | - apply_filters( |
|
133 | - 'wpinv_register_post_type_invoice', |
|
134 | - array( |
|
135 | - 'labels' => array( |
|
136 | - 'name' => __( 'Invoices', 'invoicing' ), |
|
137 | - 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
138 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
139 | - 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
140 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
141 | - 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
142 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
143 | - 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
144 | - 'new_item' => __( 'New invoice', 'invoicing' ), |
|
145 | - 'view_item' => __( 'View invoice', 'invoicing' ), |
|
146 | - 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
147 | - 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
148 | - 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
149 | - 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
150 | - 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
151 | - 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
152 | - 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
153 | - 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
154 | - 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
155 | - 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
156 | - 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
157 | - 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
158 | - 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
159 | - 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
160 | - ), |
|
161 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
162 | - 'public' => true, |
|
163 | - 'has_archive' => false, |
|
164 | - 'publicly_queryable' => true, |
|
165 | - 'exclude_from_search' => true, |
|
166 | - 'show_ui' => true, |
|
167 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
168 | - 'show_in_nav_menus' => false, |
|
169 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
170 | - 'rewrite' => array( |
|
171 | - 'slug' => 'invoice', |
|
172 | - 'with_front' => false, |
|
173 | - ), |
|
174 | - 'query_var' => false, |
|
175 | - 'map_meta_cap' => true, |
|
176 | - 'show_in_admin_bar' => true, |
|
177 | - 'can_export' => true, |
|
178 | - 'hierarchical' => false, |
|
179 | - 'menu_position' => null, |
|
180 | - 'menu_icon' => 'dashicons-media-spreadsheet', |
|
181 | - ) |
|
182 | - ) |
|
183 | - ); |
|
129 | + // Register invoice post type. |
|
130 | + register_post_type( |
|
131 | + 'wpi_invoice', |
|
132 | + apply_filters( |
|
133 | + 'wpinv_register_post_type_invoice', |
|
134 | + array( |
|
135 | + 'labels' => array( |
|
136 | + 'name' => __( 'Invoices', 'invoicing' ), |
|
137 | + 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
138 | + 'all_items' => __( 'Invoices', 'invoicing' ), |
|
139 | + 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
140 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
141 | + 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
142 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
143 | + 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
144 | + 'new_item' => __( 'New invoice', 'invoicing' ), |
|
145 | + 'view_item' => __( 'View invoice', 'invoicing' ), |
|
146 | + 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
147 | + 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
148 | + 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
149 | + 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
150 | + 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
151 | + 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
152 | + 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
153 | + 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
154 | + 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
155 | + 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
156 | + 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
157 | + 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
158 | + 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
159 | + 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
160 | + ), |
|
161 | + 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
162 | + 'public' => true, |
|
163 | + 'has_archive' => false, |
|
164 | + 'publicly_queryable' => true, |
|
165 | + 'exclude_from_search' => true, |
|
166 | + 'show_ui' => true, |
|
167 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
168 | + 'show_in_nav_menus' => false, |
|
169 | + 'supports' => array( 'title', 'author', 'excerpt' ), |
|
170 | + 'rewrite' => array( |
|
171 | + 'slug' => 'invoice', |
|
172 | + 'with_front' => false, |
|
173 | + ), |
|
174 | + 'query_var' => false, |
|
175 | + 'map_meta_cap' => true, |
|
176 | + 'show_in_admin_bar' => true, |
|
177 | + 'can_export' => true, |
|
178 | + 'hierarchical' => false, |
|
179 | + 'menu_position' => null, |
|
180 | + 'menu_icon' => 'dashicons-media-spreadsheet', |
|
181 | + ) |
|
182 | + ) |
|
183 | + ); |
|
184 | 184 | |
185 | - // Register discount post type. |
|
186 | - register_post_type( |
|
187 | - 'wpi_discount', |
|
188 | - apply_filters( |
|
189 | - 'wpinv_register_post_type_discount', |
|
190 | - array( |
|
191 | - 'labels' => array( |
|
192 | - 'name' => __( 'Discounts', 'invoicing' ), |
|
193 | - 'singular_name' => __( 'Discount', 'invoicing' ), |
|
194 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
195 | - 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
196 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
197 | - 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
198 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
199 | - 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
200 | - 'new_item' => __( 'New discount', 'invoicing' ), |
|
201 | - 'view_item' => __( 'View discount', 'invoicing' ), |
|
202 | - 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
203 | - 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
204 | - 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
205 | - 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
206 | - 'parent' => __( 'Parent discount', 'invoicing' ), |
|
207 | - 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
208 | - 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
209 | - 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
210 | - 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
211 | - 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
212 | - 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
213 | - 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
214 | - 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
215 | - 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
216 | - ), |
|
217 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
218 | - 'public' => false, |
|
219 | - 'can_export' => true, |
|
220 | - '_builtin' => false, |
|
221 | - 'publicly_queryable' => false, |
|
222 | - 'exclude_from_search'=> true, |
|
223 | - 'show_ui' => true, |
|
224 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
225 | - 'query_var' => false, |
|
226 | - 'rewrite' => false, |
|
227 | - 'map_meta_cap' => true, |
|
228 | - 'has_archive' => false, |
|
229 | - 'hierarchical' => false, |
|
230 | - 'supports' => array( 'title', 'excerpt' ), |
|
231 | - 'show_in_nav_menus' => false, |
|
232 | - 'show_in_admin_bar' => true, |
|
233 | - 'menu_position' => null, |
|
234 | - ) |
|
235 | - ) |
|
236 | - ); |
|
185 | + // Register discount post type. |
|
186 | + register_post_type( |
|
187 | + 'wpi_discount', |
|
188 | + apply_filters( |
|
189 | + 'wpinv_register_post_type_discount', |
|
190 | + array( |
|
191 | + 'labels' => array( |
|
192 | + 'name' => __( 'Discounts', 'invoicing' ), |
|
193 | + 'singular_name' => __( 'Discount', 'invoicing' ), |
|
194 | + 'all_items' => __( 'Discounts', 'invoicing' ), |
|
195 | + 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
196 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
197 | + 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
198 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
199 | + 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
200 | + 'new_item' => __( 'New discount', 'invoicing' ), |
|
201 | + 'view_item' => __( 'View discount', 'invoicing' ), |
|
202 | + 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
203 | + 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
204 | + 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
205 | + 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
206 | + 'parent' => __( 'Parent discount', 'invoicing' ), |
|
207 | + 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
208 | + 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
209 | + 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
210 | + 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
211 | + 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
212 | + 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
213 | + 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
214 | + 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
215 | + 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
216 | + ), |
|
217 | + 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
218 | + 'public' => false, |
|
219 | + 'can_export' => true, |
|
220 | + '_builtin' => false, |
|
221 | + 'publicly_queryable' => false, |
|
222 | + 'exclude_from_search'=> true, |
|
223 | + 'show_ui' => true, |
|
224 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
225 | + 'query_var' => false, |
|
226 | + 'rewrite' => false, |
|
227 | + 'map_meta_cap' => true, |
|
228 | + 'has_archive' => false, |
|
229 | + 'hierarchical' => false, |
|
230 | + 'supports' => array( 'title', 'excerpt' ), |
|
231 | + 'show_in_nav_menus' => false, |
|
232 | + 'show_in_admin_bar' => true, |
|
233 | + 'menu_position' => null, |
|
234 | + ) |
|
235 | + ) |
|
236 | + ); |
|
237 | 237 | |
238 | - do_action( 'getpaid_after_register_post_types' ); |
|
239 | - } |
|
238 | + do_action( 'getpaid_after_register_post_types' ); |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Register our custom post statuses. |
|
243 | - */ |
|
244 | - public static function register_post_status() { |
|
241 | + /** |
|
242 | + * Register our custom post statuses. |
|
243 | + */ |
|
244 | + public static function register_post_status() { |
|
245 | 245 | |
246 | - $invoice_statuses = apply_filters( |
|
247 | - 'getpaid_register_invoice_post_statuses', |
|
248 | - array( |
|
246 | + $invoice_statuses = apply_filters( |
|
247 | + 'getpaid_register_invoice_post_statuses', |
|
248 | + array( |
|
249 | 249 | |
250 | - 'wpi-pending' => array( |
|
251 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
252 | - 'public' => true, |
|
253 | - 'exclude_from_search' => true, |
|
254 | - 'show_in_admin_all_list' => true, |
|
255 | - 'show_in_admin_status_list' => true, |
|
256 | - /* translators: %s: number of invoices */ |
|
257 | - 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
258 | - ), |
|
250 | + 'wpi-pending' => array( |
|
251 | + 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
252 | + 'public' => true, |
|
253 | + 'exclude_from_search' => true, |
|
254 | + 'show_in_admin_all_list' => true, |
|
255 | + 'show_in_admin_status_list' => true, |
|
256 | + /* translators: %s: number of invoices */ |
|
257 | + 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
258 | + ), |
|
259 | 259 | |
260 | - 'wpi-processing' => array( |
|
261 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
262 | - 'public' => true, |
|
263 | - 'exclude_from_search' => true, |
|
264 | - 'show_in_admin_all_list' => true, |
|
265 | - 'show_in_admin_status_list' => true, |
|
266 | - /* translators: %s: number of invoices */ |
|
267 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
268 | - ), |
|
260 | + 'wpi-processing' => array( |
|
261 | + 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
262 | + 'public' => true, |
|
263 | + 'exclude_from_search' => true, |
|
264 | + 'show_in_admin_all_list' => true, |
|
265 | + 'show_in_admin_status_list' => true, |
|
266 | + /* translators: %s: number of invoices */ |
|
267 | + 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
268 | + ), |
|
269 | 269 | |
270 | - 'wpi-onhold' => array( |
|
271 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
272 | - 'public' => true, |
|
273 | - 'exclude_from_search' => true, |
|
274 | - 'show_in_admin_all_list' => true, |
|
275 | - 'show_in_admin_status_list' => true, |
|
276 | - /* translators: %s: number of invoices */ |
|
277 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
278 | - ), |
|
270 | + 'wpi-onhold' => array( |
|
271 | + 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
272 | + 'public' => true, |
|
273 | + 'exclude_from_search' => true, |
|
274 | + 'show_in_admin_all_list' => true, |
|
275 | + 'show_in_admin_status_list' => true, |
|
276 | + /* translators: %s: number of invoices */ |
|
277 | + 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
278 | + ), |
|
279 | 279 | |
280 | - 'wpi-cancelled' => array( |
|
281 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
282 | - 'public' => true, |
|
283 | - 'exclude_from_search' => true, |
|
284 | - 'show_in_admin_all_list' => true, |
|
285 | - 'show_in_admin_status_list' => true, |
|
286 | - /* translators: %s: number of invoices */ |
|
287 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
288 | - ), |
|
280 | + 'wpi-cancelled' => array( |
|
281 | + 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
282 | + 'public' => true, |
|
283 | + 'exclude_from_search' => true, |
|
284 | + 'show_in_admin_all_list' => true, |
|
285 | + 'show_in_admin_status_list' => true, |
|
286 | + /* translators: %s: number of invoices */ |
|
287 | + 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
288 | + ), |
|
289 | 289 | |
290 | - 'wpi-refunded' => array( |
|
291 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
292 | - 'public' => true, |
|
293 | - 'exclude_from_search' => true, |
|
294 | - 'show_in_admin_all_list' => true, |
|
295 | - 'show_in_admin_status_list' => true, |
|
296 | - /* translators: %s: number of invoices */ |
|
297 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
298 | - ), |
|
290 | + 'wpi-refunded' => array( |
|
291 | + 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
292 | + 'public' => true, |
|
293 | + 'exclude_from_search' => true, |
|
294 | + 'show_in_admin_all_list' => true, |
|
295 | + 'show_in_admin_status_list' => true, |
|
296 | + /* translators: %s: number of invoices */ |
|
297 | + 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
298 | + ), |
|
299 | 299 | |
300 | - 'wpi-failed' => array( |
|
301 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
302 | - 'public' => true, |
|
303 | - 'exclude_from_search' => true, |
|
304 | - 'show_in_admin_all_list' => true, |
|
305 | - 'show_in_admin_status_list' => true, |
|
306 | - /* translators: %s: number of invoices */ |
|
307 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
308 | - ), |
|
300 | + 'wpi-failed' => array( |
|
301 | + 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
302 | + 'public' => true, |
|
303 | + 'exclude_from_search' => true, |
|
304 | + 'show_in_admin_all_list' => true, |
|
305 | + 'show_in_admin_status_list' => true, |
|
306 | + /* translators: %s: number of invoices */ |
|
307 | + 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
308 | + ), |
|
309 | 309 | |
310 | - 'wpi-renewal' => array( |
|
311 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
312 | - 'public' => true, |
|
313 | - 'exclude_from_search' => true, |
|
314 | - 'show_in_admin_all_list' => true, |
|
315 | - 'show_in_admin_status_list' => true, |
|
316 | - /* translators: %s: number of invoices */ |
|
317 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
318 | - ) |
|
319 | - ) |
|
320 | - ); |
|
310 | + 'wpi-renewal' => array( |
|
311 | + 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
312 | + 'public' => true, |
|
313 | + 'exclude_from_search' => true, |
|
314 | + 'show_in_admin_all_list' => true, |
|
315 | + 'show_in_admin_status_list' => true, |
|
316 | + /* translators: %s: number of invoices */ |
|
317 | + 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
318 | + ) |
|
319 | + ) |
|
320 | + ); |
|
321 | 321 | |
322 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
323 | - register_post_status( $invoice_statuse, $args ); |
|
324 | - } |
|
325 | - } |
|
322 | + foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
323 | + register_post_status( $invoice_statuse, $args ); |
|
324 | + } |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * Flush rewrite rules. |
|
329 | - */ |
|
330 | - public static function flush_rewrite_rules() { |
|
331 | - flush_rewrite_rules(); |
|
332 | - } |
|
327 | + /** |
|
328 | + * Flush rewrite rules. |
|
329 | + */ |
|
330 | + public static function flush_rewrite_rules() { |
|
331 | + flush_rewrite_rules(); |
|
332 | + } |
|
333 | 333 | |
334 | - /** |
|
335 | - * Flush rules to prevent 404. |
|
336 | - * |
|
337 | - */ |
|
338 | - public static function maybe_flush_rewrite_rules() { |
|
339 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
340 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
341 | - self::flush_rewrite_rules(); |
|
342 | - } |
|
343 | - } |
|
334 | + /** |
|
335 | + * Flush rules to prevent 404. |
|
336 | + * |
|
337 | + */ |
|
338 | + public static function maybe_flush_rewrite_rules() { |
|
339 | + if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
340 | + update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
341 | + self::flush_rewrite_rules(); |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | 345 | } |
@@ -14,591 +14,591 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | + |
|
134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load Localisation files. |
|
158 | - * |
|
159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | - * |
|
161 | - * Locales found in: |
|
162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - */ |
|
167 | - public function load_textdomain() { |
|
168 | - |
|
169 | - load_plugin_textdomain( |
|
170 | - 'invoicing', |
|
171 | - false, |
|
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | - ); |
|
174 | - |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Include required core files used in admin and on the frontend. |
|
179 | - */ |
|
180 | - public function includes() { |
|
181 | - |
|
182 | - // Start with the settings. |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | - |
|
185 | - // Packages/libraries. |
|
186 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
188 | - |
|
189 | - // Load functions. |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
205 | - |
|
206 | - // Register autoloader. |
|
207 | - try { |
|
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | - } |
|
212 | - |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | - GetPaid_Post_Types_Admin::init(); |
|
237 | - |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
244 | - // load the user class only on the users.php page |
|
245 | - global $pagenow; |
|
246 | - if($pagenow=='users.php'){ |
|
247 | - new WPInv_Admin_Users(); |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - // Register cli commands |
|
252 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
253 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
254 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
255 | - } |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Class autoloader |
|
261 | - * |
|
262 | - * @param string $class_name The name of the class to load. |
|
263 | - * @access public |
|
264 | - * @since 1.0.19 |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - public function autoload( $class_name ) { |
|
268 | - |
|
269 | - // Normalize the class name... |
|
270 | - $class_name = strtolower( $class_name ); |
|
271 | - |
|
272 | - // ... and make sure it is our class. |
|
273 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | - return; |
|
275 | - } |
|
276 | - |
|
277 | - // Next, prepare the file name from the class. |
|
278 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | - |
|
280 | - // Base path of the classes. |
|
281 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | - |
|
283 | - // And an array of possible locations in order of importance. |
|
284 | - $locations = array( |
|
285 | - "$plugin_path/includes", |
|
286 | - "$plugin_path/includes/data-stores", |
|
287 | - "$plugin_path/includes/gateways", |
|
288 | - "$plugin_path/includes/payments", |
|
289 | - "$plugin_path/includes/geolocation", |
|
290 | - "$plugin_path/includes/reports", |
|
291 | - "$plugin_path/includes/api", |
|
292 | - "$plugin_path/includes/admin", |
|
293 | - "$plugin_path/includes/admin/meta-boxes", |
|
294 | - ); |
|
295 | - |
|
296 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | - |
|
298 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
299 | - include trailingslashit( $location ) . $file_name; |
|
300 | - break; |
|
301 | - } |
|
302 | - |
|
303 | - } |
|
304 | - |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Inits hooks etc. |
|
309 | - */ |
|
310 | - public function init() { |
|
311 | - |
|
312 | - // Fires before getpaid inits. |
|
313 | - do_action( 'before_getpaid_init', $this ); |
|
314 | - |
|
315 | - // Maybe upgrade. |
|
316 | - $this->maybe_upgrade_database(); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | - GetPaid_Installer::rename_gateways_label(); |
|
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | - } |
|
338 | - |
|
339 | - // Fires after getpaid inits. |
|
340 | - do_action( 'getpaid_init', $this ); |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - |
|
349 | - // Ensure that this is an IPN request. |
|
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
355 | - |
|
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | - exit; |
|
359 | - |
|
360 | - } |
|
361 | - |
|
362 | - public function enqueue_scripts() { |
|
363 | - |
|
364 | - // Fires before adding scripts. |
|
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | - |
|
367 | - $localize = array(); |
|
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | - |
|
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | - |
|
380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | - } |
|
384 | - |
|
385 | - public function wpinv_actions() { |
|
386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load Localisation files. |
|
158 | + * |
|
159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | + * |
|
161 | + * Locales found in: |
|
162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + */ |
|
167 | + public function load_textdomain() { |
|
168 | + |
|
169 | + load_plugin_textdomain( |
|
170 | + 'invoicing', |
|
171 | + false, |
|
172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | + ); |
|
174 | + |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Include required core files used in admin and on the frontend. |
|
179 | + */ |
|
180 | + public function includes() { |
|
181 | + |
|
182 | + // Start with the settings. |
|
183 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + |
|
185 | + // Packages/libraries. |
|
186 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
188 | + |
|
189 | + // Load functions. |
|
190 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
205 | + |
|
206 | + // Register autoloader. |
|
207 | + try { |
|
208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | + } catch ( Exception $e ) { |
|
210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | + } |
|
212 | + |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
234 | + |
|
235 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + GetPaid_Post_Types_Admin::init(); |
|
237 | + |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
244 | + // load the user class only on the users.php page |
|
245 | + global $pagenow; |
|
246 | + if($pagenow=='users.php'){ |
|
247 | + new WPInv_Admin_Users(); |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + // Register cli commands |
|
252 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
253 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
254 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
255 | + } |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Class autoloader |
|
261 | + * |
|
262 | + * @param string $class_name The name of the class to load. |
|
263 | + * @access public |
|
264 | + * @since 1.0.19 |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + public function autoload( $class_name ) { |
|
268 | + |
|
269 | + // Normalize the class name... |
|
270 | + $class_name = strtolower( $class_name ); |
|
271 | + |
|
272 | + // ... and make sure it is our class. |
|
273 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + // Next, prepare the file name from the class. |
|
278 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + |
|
280 | + // Base path of the classes. |
|
281 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + |
|
283 | + // And an array of possible locations in order of importance. |
|
284 | + $locations = array( |
|
285 | + "$plugin_path/includes", |
|
286 | + "$plugin_path/includes/data-stores", |
|
287 | + "$plugin_path/includes/gateways", |
|
288 | + "$plugin_path/includes/payments", |
|
289 | + "$plugin_path/includes/geolocation", |
|
290 | + "$plugin_path/includes/reports", |
|
291 | + "$plugin_path/includes/api", |
|
292 | + "$plugin_path/includes/admin", |
|
293 | + "$plugin_path/includes/admin/meta-boxes", |
|
294 | + ); |
|
295 | + |
|
296 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + |
|
298 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
299 | + include trailingslashit( $location ) . $file_name; |
|
300 | + break; |
|
301 | + } |
|
302 | + |
|
303 | + } |
|
304 | + |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Inits hooks etc. |
|
309 | + */ |
|
310 | + public function init() { |
|
311 | + |
|
312 | + // Fires before getpaid inits. |
|
313 | + do_action( 'before_getpaid_init', $this ); |
|
314 | + |
|
315 | + // Maybe upgrade. |
|
316 | + $this->maybe_upgrade_database(); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + GetPaid_Installer::rename_gateways_label(); |
|
336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + } |
|
338 | + |
|
339 | + // Fires after getpaid inits. |
|
340 | + do_action( 'getpaid_init', $this ); |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + |
|
349 | + // Ensure that this is an IPN request. |
|
350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
355 | + |
|
356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | + exit; |
|
359 | + |
|
360 | + } |
|
361 | + |
|
362 | + public function enqueue_scripts() { |
|
363 | + |
|
364 | + // Fires before adding scripts. |
|
365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + |
|
367 | + $localize = array(); |
|
368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + |
|
378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + |
|
380 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | + } |
|
384 | + |
|
385 | + public function wpinv_actions() { |
|
386 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | 392 | * Fires an action after verifying that a user can fire them. |
393 | - * |
|
394 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
395 | - * current user owns the invoice/subscription. |
|
393 | + * |
|
394 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
395 | + * current user owns the invoice/subscription. |
|
396 | 396 | */ |
397 | 397 | public function maybe_do_authenticated_action() { |
398 | 398 | |
399 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
399 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
400 | 400 | |
401 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
402 | - $data = wp_unslash( $_REQUEST ); |
|
403 | - if ( is_user_logged_in() ) { |
|
404 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
405 | - } |
|
401 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
402 | + $data = wp_unslash( $_REQUEST ); |
|
403 | + if ( is_user_logged_in() ) { |
|
404 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
405 | + } |
|
406 | 406 | |
407 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
407 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
408 | 408 | |
409 | - } |
|
409 | + } |
|
410 | 410 | |
411 | 411 | } |
412 | 412 | |
413 | - public function pre_get_posts( $wp_query ) { |
|
414 | - |
|
415 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
416 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
417 | - } |
|
418 | - |
|
419 | - return $wp_query; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Register widgets |
|
424 | - * |
|
425 | - */ |
|
426 | - public function register_widgets() { |
|
427 | - |
|
428 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
429 | - // So we disable our widgets when editing a page with UX Builder. |
|
430 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
431 | - return; |
|
432 | - } |
|
433 | - |
|
434 | - $widgets = apply_filters( |
|
435 | - 'getpaid_widget_classes', |
|
436 | - array( |
|
437 | - 'WPInv_Checkout_Widget', |
|
438 | - 'WPInv_History_Widget', |
|
439 | - 'WPInv_Receipt_Widget', |
|
440 | - 'WPInv_Subscriptions_Widget', |
|
441 | - 'WPInv_Buy_Item_Widget', |
|
442 | - 'WPInv_Messages_Widget', |
|
443 | - 'WPInv_GetPaid_Widget' |
|
444 | - ) |
|
445 | - ); |
|
446 | - |
|
447 | - foreach ( $widgets as $widget ) { |
|
448 | - register_widget( $widget ); |
|
449 | - } |
|
413 | + public function pre_get_posts( $wp_query ) { |
|
414 | + |
|
415 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
416 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
417 | + } |
|
418 | + |
|
419 | + return $wp_query; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Register widgets |
|
424 | + * |
|
425 | + */ |
|
426 | + public function register_widgets() { |
|
427 | + |
|
428 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
429 | + // So we disable our widgets when editing a page with UX Builder. |
|
430 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
431 | + return; |
|
432 | + } |
|
433 | + |
|
434 | + $widgets = apply_filters( |
|
435 | + 'getpaid_widget_classes', |
|
436 | + array( |
|
437 | + 'WPInv_Checkout_Widget', |
|
438 | + 'WPInv_History_Widget', |
|
439 | + 'WPInv_Receipt_Widget', |
|
440 | + 'WPInv_Subscriptions_Widget', |
|
441 | + 'WPInv_Buy_Item_Widget', |
|
442 | + 'WPInv_Messages_Widget', |
|
443 | + 'WPInv_GetPaid_Widget' |
|
444 | + ) |
|
445 | + ); |
|
446 | + |
|
447 | + foreach ( $widgets as $widget ) { |
|
448 | + register_widget( $widget ); |
|
449 | + } |
|
450 | 450 | |
451 | - } |
|
451 | + } |
|
452 | 452 | |
453 | - /** |
|
454 | - * Upgrades the database. |
|
455 | - * |
|
456 | - * @since 2.0.2 |
|
457 | - */ |
|
458 | - public function maybe_upgrade_database() { |
|
453 | + /** |
|
454 | + * Upgrades the database. |
|
455 | + * |
|
456 | + * @since 2.0.2 |
|
457 | + */ |
|
458 | + public function maybe_upgrade_database() { |
|
459 | 459 | |
460 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
460 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
461 | 461 | |
462 | - if ( $wpi_version == WPINV_VERSION ) { |
|
463 | - return; |
|
464 | - } |
|
462 | + if ( $wpi_version == WPINV_VERSION ) { |
|
463 | + return; |
|
464 | + } |
|
465 | 465 | |
466 | - $installer = new GetPaid_Installer(); |
|
466 | + $installer = new GetPaid_Installer(); |
|
467 | 467 | |
468 | - if ( empty( $wpi_version ) ) { |
|
469 | - return $installer->upgrade_db( 0 ); |
|
470 | - } |
|
468 | + if ( empty( $wpi_version ) ) { |
|
469 | + return $installer->upgrade_db( 0 ); |
|
470 | + } |
|
471 | 471 | |
472 | - $upgrades = array( |
|
473 | - '0.0.5' => '004', |
|
474 | - '1.0.3' => '102', |
|
475 | - '2.0.0' => '118', |
|
476 | - '2.0.8' => '207', |
|
477 | - ); |
|
472 | + $upgrades = array( |
|
473 | + '0.0.5' => '004', |
|
474 | + '1.0.3' => '102', |
|
475 | + '2.0.0' => '118', |
|
476 | + '2.0.8' => '207', |
|
477 | + ); |
|
478 | 478 | |
479 | - foreach ( $upgrades as $key => $method ) { |
|
479 | + foreach ( $upgrades as $key => $method ) { |
|
480 | 480 | |
481 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
482 | - return $installer->upgrade_db( $method ); |
|
483 | - } |
|
481 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
482 | + return $installer->upgrade_db( $method ); |
|
483 | + } |
|
484 | 484 | |
485 | - } |
|
485 | + } |
|
486 | 486 | |
487 | - } |
|
487 | + } |
|
488 | 488 | |
489 | - /** |
|
490 | - * Flushes the permalinks if needed. |
|
491 | - * |
|
492 | - * @since 2.0.8 |
|
493 | - */ |
|
494 | - public function maybe_flush_permalinks() { |
|
489 | + /** |
|
490 | + * Flushes the permalinks if needed. |
|
491 | + * |
|
492 | + * @since 2.0.8 |
|
493 | + */ |
|
494 | + public function maybe_flush_permalinks() { |
|
495 | 495 | |
496 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
496 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
497 | 497 | |
498 | - if ( ! empty( $flush ) ) { |
|
499 | - flush_rewrite_rules(); |
|
500 | - delete_option( 'wpinv_flush_permalinks' ); |
|
501 | - } |
|
498 | + if ( ! empty( $flush ) ) { |
|
499 | + flush_rewrite_rules(); |
|
500 | + delete_option( 'wpinv_flush_permalinks' ); |
|
501 | + } |
|
502 | 502 | |
503 | - } |
|
503 | + } |
|
504 | 504 | |
505 | - /** |
|
506 | - * Remove our pages from yoast sitemaps. |
|
507 | - * |
|
508 | - * @since 1.0.19 |
|
509 | - * @param int[] $excluded_posts_ids |
|
510 | - */ |
|
511 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
505 | + /** |
|
506 | + * Remove our pages from yoast sitemaps. |
|
507 | + * |
|
508 | + * @since 1.0.19 |
|
509 | + * @param int[] $excluded_posts_ids |
|
510 | + */ |
|
511 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
512 | 512 | |
513 | - // Ensure that we have an array. |
|
514 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
515 | - $excluded_posts_ids = array(); |
|
516 | - } |
|
513 | + // Ensure that we have an array. |
|
514 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
515 | + $excluded_posts_ids = array(); |
|
516 | + } |
|
517 | 517 | |
518 | - // Prepare our pages. |
|
519 | - $our_pages = array(); |
|
518 | + // Prepare our pages. |
|
519 | + $our_pages = array(); |
|
520 | 520 | |
521 | - // Checkout page. |
|
522 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
521 | + // Checkout page. |
|
522 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
523 | 523 | |
524 | - // Success page. |
|
525 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
524 | + // Success page. |
|
525 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
526 | 526 | |
527 | - // Failure page. |
|
528 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
527 | + // Failure page. |
|
528 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
529 | 529 | |
530 | - // History page. |
|
531 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
530 | + // History page. |
|
531 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
532 | 532 | |
533 | - // Subscriptions page. |
|
534 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
533 | + // Subscriptions page. |
|
534 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
535 | 535 | |
536 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
536 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
537 | 537 | |
538 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
539 | - return array_unique( $excluded_posts_ids ); |
|
538 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
539 | + return array_unique( $excluded_posts_ids ); |
|
540 | 540 | |
541 | - } |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
544 | - * Displays additional footer code. |
|
545 | - * |
|
546 | - * @since 2.0.0 |
|
547 | - */ |
|
548 | - public function wp_footer() { |
|
549 | - wpinv_get_template( 'frontend-footer.php' ); |
|
550 | - } |
|
543 | + /** |
|
544 | + * Displays additional footer code. |
|
545 | + * |
|
546 | + * @since 2.0.0 |
|
547 | + */ |
|
548 | + public function wp_footer() { |
|
549 | + wpinv_get_template( 'frontend-footer.php' ); |
|
550 | + } |
|
551 | 551 | |
552 | - /** |
|
553 | - * Displays additional header code. |
|
554 | - * |
|
555 | - * @since 2.0.0 |
|
556 | - */ |
|
557 | - public function wp_head() { |
|
558 | - wpinv_get_template( 'frontend-head.php' ); |
|
559 | - } |
|
552 | + /** |
|
553 | + * Displays additional header code. |
|
554 | + * |
|
555 | + * @since 2.0.0 |
|
556 | + */ |
|
557 | + public function wp_head() { |
|
558 | + wpinv_get_template( 'frontend-head.php' ); |
|
559 | + } |
|
560 | 560 | |
561 | - /** |
|
562 | - * Custom query vars. |
|
563 | - * |
|
564 | - */ |
|
565 | - public function custom_query_vars( $vars ) { |
|
561 | + /** |
|
562 | + * Custom query vars. |
|
563 | + * |
|
564 | + */ |
|
565 | + public function custom_query_vars( $vars ) { |
|
566 | 566 | $vars[] = 'getpaid-ipn'; |
567 | 567 | return $vars; |
568 | - } |
|
568 | + } |
|
569 | 569 | |
570 | - /** |
|
571 | - * Add rewrite tags and rules. |
|
572 | - * |
|
573 | - */ |
|
574 | - public function add_rewrite_rule() { |
|
570 | + /** |
|
571 | + * Add rewrite tags and rules. |
|
572 | + * |
|
573 | + */ |
|
574 | + public function add_rewrite_rule() { |
|
575 | 575 | $tag = 'getpaid-ipn'; |
576 | 576 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
577 | 577 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' ); |
578 | - } |
|
578 | + } |
|
579 | 579 | |
580 | - /** |
|
581 | - * Processes non-query string ipns. |
|
582 | - * |
|
583 | - */ |
|
584 | - public function maybe_process_new_ipn( $query ) { |
|
580 | + /** |
|
581 | + * Processes non-query string ipns. |
|
582 | + * |
|
583 | + */ |
|
584 | + public function maybe_process_new_ipn( $query ) { |
|
585 | 585 | |
586 | 586 | if ( is_admin() || ! $query->is_main_query() ) { |
587 | 587 | return; |
588 | 588 | } |
589 | 589 | |
590 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
590 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
591 | 591 | |
592 | 592 | if ( ! empty( $gateway ) ){ |
593 | 593 | |
594 | - $gateway = sanitize_text_field( $gateway ); |
|
595 | - nocache_headers(); |
|
596 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
597 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
598 | - exit; |
|
594 | + $gateway = sanitize_text_field( $gateway ); |
|
595 | + nocache_headers(); |
|
596 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
597 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
598 | + exit; |
|
599 | 599 | |
600 | 600 | } |
601 | 601 | |
602 | - } |
|
602 | + } |
|
603 | 603 | |
604 | 604 | } |
@@ -12,145 +12,145 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Expires expired subscriptions. |
|
108 | - * |
|
109 | - */ |
|
110 | - public function maybe_expire_subscriptions() { |
|
111 | - |
|
112 | - // Fetch expired subscriptions (skips those that expire today). |
|
113 | - $args = array( |
|
114 | - 'number' => -1, |
|
115 | - 'count_total' => false, |
|
116 | - 'status' => 'trialling active failing cancelled', |
|
117 | - 'date_expires_query' => array( |
|
118 | - 'before' => 'yesterday', |
|
119 | - 'inclusive' => false, |
|
120 | - ), |
|
121 | - ); |
|
122 | - |
|
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | - |
|
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
128 | - $subscription->save(); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Logs cron runs. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function log_cron_run() { |
|
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Updates GeoIP databases. |
|
144 | - * |
|
145 | - */ |
|
146 | - public function maybe_update_geoip_databases() { |
|
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | - |
|
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
152 | - } |
|
153 | - |
|
154 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | + 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | + 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Expires expired subscriptions. |
|
108 | + * |
|
109 | + */ |
|
110 | + public function maybe_expire_subscriptions() { |
|
111 | + |
|
112 | + // Fetch expired subscriptions (skips those that expire today). |
|
113 | + $args = array( |
|
114 | + 'number' => -1, |
|
115 | + 'count_total' => false, |
|
116 | + 'status' => 'trialling active failing cancelled', |
|
117 | + 'date_expires_query' => array( |
|
118 | + 'before' => 'yesterday', |
|
119 | + 'inclusive' => false, |
|
120 | + ), |
|
121 | + ); |
|
122 | + |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | + |
|
125 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | + $subscription->set_status( 'expired' ); |
|
128 | + $subscription->save(); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Logs cron runs. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function log_cron_run() { |
|
139 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Updates GeoIP databases. |
|
144 | + * |
|
145 | + */ |
|
146 | + public function maybe_update_geoip_databases() { |
|
147 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | + |
|
149 | + if ( false === $updated ) { |
|
150 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | + do_action( 'getpaid_update_geoip_databases' ); |
|
152 | + } |
|
153 | + |
|
154 | + } |
|
155 | 155 | |
156 | 156 | } |