@@ -6,5 +6,5 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Primary_Key_Index extends EE_Unique_Index |
8 | 8 | { |
9 | - // yep, actually the same as unique index right now |
|
9 | + // yep, actually the same as unique index right now |
|
10 | 10 | } |
@@ -16,230 +16,230 @@ discard block |
||
16 | 16 | class EEM_Transaction extends EEM_Base |
17 | 17 | { |
18 | 18 | |
19 | - // private instance of the Transaction object |
|
20 | - protected static $_instance; |
|
21 | - |
|
22 | - /** |
|
23 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
24 | - * but payment is pending. This is the state for transactions where payment is promised |
|
25 | - * from an offline gateway. |
|
26 | - */ |
|
27 | - // const open_status_code = 'TPN'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
31 | - * either due to a technical reason (server or computer crash during registration), |
|
32 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
33 | - */ |
|
34 | - const failed_status_code = 'TFL'; |
|
35 | - |
|
36 | - /** |
|
37 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
38 | - * either due to a technical reason (server or computer crash during registration), |
|
39 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
40 | - * HOWEVER... |
|
41 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
42 | - * registrant |
|
43 | - */ |
|
44 | - const abandoned_status_code = 'TAB'; |
|
45 | - |
|
46 | - /** |
|
47 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
48 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
49 | - */ |
|
50 | - const incomplete_status_code = 'TIN'; |
|
51 | - |
|
52 | - /** |
|
53 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
54 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
55 | - */ |
|
56 | - const complete_status_code = 'TCM'; |
|
57 | - |
|
58 | - /** |
|
59 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
60 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
61 | - */ |
|
62 | - const overpaid_status_code = 'TOP'; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * private constructor to prevent direct creation |
|
67 | - * |
|
68 | - * @Constructor |
|
69 | - * @access protected |
|
70 | - * |
|
71 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
72 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
73 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
74 | - * timezone in the 'timezone_string' wp option) |
|
75 | - * |
|
76 | - * @return EEM_Transaction |
|
77 | - * @throws \EE_Error |
|
78 | - */ |
|
79 | - protected function __construct($timezone) |
|
80 | - { |
|
81 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
82 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
83 | - |
|
84 | - $this->_tables = array( |
|
85 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
86 | - ); |
|
87 | - $this->_fields = array( |
|
88 | - 'TransactionTable' => array( |
|
89 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
90 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | - 'TXN_timestamp', |
|
92 | - __('date when transaction was created', 'event_espresso'), |
|
93 | - false, |
|
94 | - EE_Datetime_Field::now, |
|
95 | - $timezone |
|
96 | - ), |
|
97 | - 'TXN_total' => new EE_Money_Field( |
|
98 | - 'TXN_total', |
|
99 | - __('Total value of Transaction', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TXN_paid' => new EE_Money_Field( |
|
104 | - 'TXN_paid', |
|
105 | - __('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | - 'STS_ID', |
|
111 | - __('Status ID', 'event_espresso'), |
|
112 | - false, |
|
113 | - EEM_Transaction::failed_status_code, |
|
114 | - 'Status' |
|
115 | - ), |
|
116 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | - 'TXN_session_data', |
|
118 | - __('Serialized session data', 'event_espresso'), |
|
119 | - true, |
|
120 | - '' |
|
121 | - ), |
|
122 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | - 'TXN_hash_salt', |
|
124 | - __('Transaction Hash Salt', 'event_espresso'), |
|
125 | - true, |
|
126 | - '' |
|
127 | - ), |
|
128 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | - 'PMD_ID', |
|
130 | - __("Last Used Payment Method", 'event_espresso'), |
|
131 | - true, |
|
132 | - null, |
|
133 | - 'Payment_Method' |
|
134 | - ), |
|
135 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | - 'TXN_reg_steps', |
|
137 | - __('Registration Steps', 'event_espresso'), |
|
138 | - false, |
|
139 | - array() |
|
140 | - ), |
|
141 | - ) |
|
142 | - ); |
|
143 | - $this->_model_relations = array( |
|
144 | - 'Registration' => new EE_Has_Many_Relation(), |
|
145 | - 'Payment' => new EE_Has_Many_Relation(), |
|
146 | - 'Status' => new EE_Belongs_To_Relation(), |
|
147 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | - // you can delete a transaction without needing to delete its line items |
|
149 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | - 'Message' => new EE_Has_Many_Relation() |
|
151 | - ); |
|
152 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | - parent::__construct($timezone); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * txn_status_array |
|
159 | - * get list of transaction statuses |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public static function txn_status_array() |
|
165 | - { |
|
166 | - return apply_filters( |
|
167 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | - array( |
|
169 | - EEM_Transaction::overpaid_status_code, |
|
170 | - EEM_Transaction::complete_status_code, |
|
171 | - EEM_Transaction::incomplete_status_code, |
|
172 | - EEM_Transaction::abandoned_status_code, |
|
173 | - EEM_Transaction::failed_status_code, |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * |
|
183 | - * @param string $period |
|
184 | - * |
|
185 | - * @return \stdClass[] |
|
186 | - */ |
|
187 | - public function get_revenue_per_day_report($period = '-1 month') |
|
188 | - { |
|
189 | - $sql_date = $this->convert_datetime_for_query( |
|
190 | - 'TXN_timestamp', |
|
191 | - date('Y-m-d H:i:s', strtotime($period)), |
|
192 | - 'Y-m-d H:i:s', |
|
193 | - 'UTC' |
|
194 | - ); |
|
195 | - |
|
196 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | - |
|
198 | - return $this->_get_all_wpdb_results( |
|
199 | - array( |
|
200 | - array( |
|
201 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
202 | - ), |
|
203 | - 'group_by' => 'txnDate', |
|
204 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
205 | - ), |
|
206 | - OBJECT, |
|
207 | - array( |
|
208 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
209 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * |
|
220 | - * @param string $period |
|
221 | - * |
|
222 | - * @throws \EE_Error |
|
223 | - * @return mixed |
|
224 | - */ |
|
225 | - public function get_revenue_per_event_report($period = '-1 month') |
|
226 | - { |
|
227 | - global $wpdb; |
|
228 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
231 | - $event_table = $wpdb->posts; |
|
232 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
233 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
234 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
235 | - $extra_event_on_join = ''; |
|
236 | - // exclude events not authored by user if permissions in effect |
|
237 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
239 | - } |
|
240 | - |
|
241 | - return $wpdb->get_results( |
|
242 | - "SELECT |
|
19 | + // private instance of the Transaction object |
|
20 | + protected static $_instance; |
|
21 | + |
|
22 | + /** |
|
23 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
24 | + * but payment is pending. This is the state for transactions where payment is promised |
|
25 | + * from an offline gateway. |
|
26 | + */ |
|
27 | + // const open_status_code = 'TPN'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
31 | + * either due to a technical reason (server or computer crash during registration), |
|
32 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
33 | + */ |
|
34 | + const failed_status_code = 'TFL'; |
|
35 | + |
|
36 | + /** |
|
37 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
38 | + * either due to a technical reason (server or computer crash during registration), |
|
39 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
40 | + * HOWEVER... |
|
41 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
42 | + * registrant |
|
43 | + */ |
|
44 | + const abandoned_status_code = 'TAB'; |
|
45 | + |
|
46 | + /** |
|
47 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
48 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
49 | + */ |
|
50 | + const incomplete_status_code = 'TIN'; |
|
51 | + |
|
52 | + /** |
|
53 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
54 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
55 | + */ |
|
56 | + const complete_status_code = 'TCM'; |
|
57 | + |
|
58 | + /** |
|
59 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
60 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
61 | + */ |
|
62 | + const overpaid_status_code = 'TOP'; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * private constructor to prevent direct creation |
|
67 | + * |
|
68 | + * @Constructor |
|
69 | + * @access protected |
|
70 | + * |
|
71 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
72 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
73 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
74 | + * timezone in the 'timezone_string' wp option) |
|
75 | + * |
|
76 | + * @return EEM_Transaction |
|
77 | + * @throws \EE_Error |
|
78 | + */ |
|
79 | + protected function __construct($timezone) |
|
80 | + { |
|
81 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
82 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
83 | + |
|
84 | + $this->_tables = array( |
|
85 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
86 | + ); |
|
87 | + $this->_fields = array( |
|
88 | + 'TransactionTable' => array( |
|
89 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
90 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | + 'TXN_timestamp', |
|
92 | + __('date when transaction was created', 'event_espresso'), |
|
93 | + false, |
|
94 | + EE_Datetime_Field::now, |
|
95 | + $timezone |
|
96 | + ), |
|
97 | + 'TXN_total' => new EE_Money_Field( |
|
98 | + 'TXN_total', |
|
99 | + __('Total value of Transaction', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TXN_paid' => new EE_Money_Field( |
|
104 | + 'TXN_paid', |
|
105 | + __('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | + 'STS_ID', |
|
111 | + __('Status ID', 'event_espresso'), |
|
112 | + false, |
|
113 | + EEM_Transaction::failed_status_code, |
|
114 | + 'Status' |
|
115 | + ), |
|
116 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | + 'TXN_session_data', |
|
118 | + __('Serialized session data', 'event_espresso'), |
|
119 | + true, |
|
120 | + '' |
|
121 | + ), |
|
122 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | + 'TXN_hash_salt', |
|
124 | + __('Transaction Hash Salt', 'event_espresso'), |
|
125 | + true, |
|
126 | + '' |
|
127 | + ), |
|
128 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | + 'PMD_ID', |
|
130 | + __("Last Used Payment Method", 'event_espresso'), |
|
131 | + true, |
|
132 | + null, |
|
133 | + 'Payment_Method' |
|
134 | + ), |
|
135 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | + 'TXN_reg_steps', |
|
137 | + __('Registration Steps', 'event_espresso'), |
|
138 | + false, |
|
139 | + array() |
|
140 | + ), |
|
141 | + ) |
|
142 | + ); |
|
143 | + $this->_model_relations = array( |
|
144 | + 'Registration' => new EE_Has_Many_Relation(), |
|
145 | + 'Payment' => new EE_Has_Many_Relation(), |
|
146 | + 'Status' => new EE_Belongs_To_Relation(), |
|
147 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | + // you can delete a transaction without needing to delete its line items |
|
149 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | + 'Message' => new EE_Has_Many_Relation() |
|
151 | + ); |
|
152 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | + parent::__construct($timezone); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * txn_status_array |
|
159 | + * get list of transaction statuses |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public static function txn_status_array() |
|
165 | + { |
|
166 | + return apply_filters( |
|
167 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | + array( |
|
169 | + EEM_Transaction::overpaid_status_code, |
|
170 | + EEM_Transaction::complete_status_code, |
|
171 | + EEM_Transaction::incomplete_status_code, |
|
172 | + EEM_Transaction::abandoned_status_code, |
|
173 | + EEM_Transaction::failed_status_code, |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * |
|
183 | + * @param string $period |
|
184 | + * |
|
185 | + * @return \stdClass[] |
|
186 | + */ |
|
187 | + public function get_revenue_per_day_report($period = '-1 month') |
|
188 | + { |
|
189 | + $sql_date = $this->convert_datetime_for_query( |
|
190 | + 'TXN_timestamp', |
|
191 | + date('Y-m-d H:i:s', strtotime($period)), |
|
192 | + 'Y-m-d H:i:s', |
|
193 | + 'UTC' |
|
194 | + ); |
|
195 | + |
|
196 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | + |
|
198 | + return $this->_get_all_wpdb_results( |
|
199 | + array( |
|
200 | + array( |
|
201 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
202 | + ), |
|
203 | + 'group_by' => 'txnDate', |
|
204 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
205 | + ), |
|
206 | + OBJECT, |
|
207 | + array( |
|
208 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
209 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * |
|
220 | + * @param string $period |
|
221 | + * |
|
222 | + * @throws \EE_Error |
|
223 | + * @return mixed |
|
224 | + */ |
|
225 | + public function get_revenue_per_event_report($period = '-1 month') |
|
226 | + { |
|
227 | + global $wpdb; |
|
228 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
231 | + $event_table = $wpdb->posts; |
|
232 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
233 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
234 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
235 | + $extra_event_on_join = ''; |
|
236 | + // exclude events not authored by user if permissions in effect |
|
237 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
239 | + } |
|
240 | + |
|
241 | + return $wpdb->get_results( |
|
242 | + "SELECT |
|
243 | 243 | Transaction_Event.event_name AS event_name, |
244 | 244 | SUM(Transaction_Event.paid) AS revenue |
245 | 245 | FROM |
@@ -267,229 +267,229 @@ discard block |
||
267 | 267 | $extra_event_on_join |
268 | 268 | ) AS Transaction_Event |
269 | 269 | GROUP BY event_name", |
270 | - OBJECT |
|
271 | - ); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
277 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
278 | - * the registration pointed to by reg_url_link), if not returns null |
|
279 | - * |
|
280 | - * @param string $reg_url_link |
|
281 | - * |
|
282 | - * @return EE_Transaction |
|
283 | - */ |
|
284 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
285 | - { |
|
286 | - return $this->get_one(array( |
|
287 | - array( |
|
288 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get( |
|
289 | - 'e_reg_url_link', |
|
290 | - '' |
|
291 | - ) |
|
292 | - ) |
|
293 | - )); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Updates the provided EE_Transaction with all the applicable payments |
|
299 | - * (or fetch the EE_Transaction from its ID) |
|
300 | - * |
|
301 | - * @deprecated |
|
302 | - * |
|
303 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
304 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
305 | - * |
|
306 | - * @return boolean |
|
307 | - * @throws \EE_Error |
|
308 | - */ |
|
309 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
310 | - { |
|
311 | - EE_Error::doing_it_wrong( |
|
312 | - __CLASS__ . '::' . __FUNCTION__, |
|
313 | - sprintf( |
|
314 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
315 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
316 | - ), |
|
317 | - '4.6.0' |
|
318 | - ); |
|
319 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
320 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
321 | - |
|
322 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
323 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
324 | - ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | - * and so we only use wpdb directly and only do minimal joins. |
|
331 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | - * it, it's probably not junk (regardless of what status it has). |
|
334 | - * The downside to this approach is that is addons are listening for object deletions |
|
335 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | - * to catch these types of deletions. |
|
337 | - * |
|
338 | - * @global WPDB $wpdb |
|
339 | - * @return mixed |
|
340 | - */ |
|
341 | - public function delete_junk_transactions() |
|
342 | - { |
|
343 | - /** @type WPDB $wpdb */ |
|
344 | - global $wpdb; |
|
345 | - $deleted = false; |
|
346 | - $time_to_leave_alone = apply_filters( |
|
347 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | - WEEK_IN_SECONDS |
|
349 | - ); |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | - */ |
|
357 | - $ids_query = apply_filters( |
|
358 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | - array( |
|
360 | - 0 => array( |
|
361 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
363 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
364 | - ) |
|
365 | - ), |
|
366 | - $time_to_leave_alone |
|
367 | - ); |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
372 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
373 | - */ |
|
374 | - $txn_ids = apply_filters( |
|
375 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
376 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
377 | - $time_to_leave_alone |
|
378 | - ); |
|
379 | - // now that we have the ids to delete |
|
380 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
381 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
382 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
383 | - // let's get deletin'... |
|
384 | - // Why no wpdb->prepare? Because the data is trusted. |
|
385 | - // We got the ids from the original query to get them FROM |
|
386 | - // the db (which is sanitized) so no need to prepare them again. |
|
387 | - $query = ' |
|
270 | + OBJECT |
|
271 | + ); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
277 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
278 | + * the registration pointed to by reg_url_link), if not returns null |
|
279 | + * |
|
280 | + * @param string $reg_url_link |
|
281 | + * |
|
282 | + * @return EE_Transaction |
|
283 | + */ |
|
284 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
285 | + { |
|
286 | + return $this->get_one(array( |
|
287 | + array( |
|
288 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get( |
|
289 | + 'e_reg_url_link', |
|
290 | + '' |
|
291 | + ) |
|
292 | + ) |
|
293 | + )); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Updates the provided EE_Transaction with all the applicable payments |
|
299 | + * (or fetch the EE_Transaction from its ID) |
|
300 | + * |
|
301 | + * @deprecated |
|
302 | + * |
|
303 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
304 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
305 | + * |
|
306 | + * @return boolean |
|
307 | + * @throws \EE_Error |
|
308 | + */ |
|
309 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
310 | + { |
|
311 | + EE_Error::doing_it_wrong( |
|
312 | + __CLASS__ . '::' . __FUNCTION__, |
|
313 | + sprintf( |
|
314 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
315 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
316 | + ), |
|
317 | + '4.6.0' |
|
318 | + ); |
|
319 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
320 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
321 | + |
|
322 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
323 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
324 | + ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | + * and so we only use wpdb directly and only do minimal joins. |
|
331 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | + * it, it's probably not junk (regardless of what status it has). |
|
334 | + * The downside to this approach is that is addons are listening for object deletions |
|
335 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | + * to catch these types of deletions. |
|
337 | + * |
|
338 | + * @global WPDB $wpdb |
|
339 | + * @return mixed |
|
340 | + */ |
|
341 | + public function delete_junk_transactions() |
|
342 | + { |
|
343 | + /** @type WPDB $wpdb */ |
|
344 | + global $wpdb; |
|
345 | + $deleted = false; |
|
346 | + $time_to_leave_alone = apply_filters( |
|
347 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | + WEEK_IN_SECONDS |
|
349 | + ); |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | + */ |
|
357 | + $ids_query = apply_filters( |
|
358 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | + array( |
|
360 | + 0 => array( |
|
361 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
363 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
364 | + ) |
|
365 | + ), |
|
366 | + $time_to_leave_alone |
|
367 | + ); |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
372 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
373 | + */ |
|
374 | + $txn_ids = apply_filters( |
|
375 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
376 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
377 | + $time_to_leave_alone |
|
378 | + ); |
|
379 | + // now that we have the ids to delete |
|
380 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
381 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
382 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
383 | + // let's get deletin'... |
|
384 | + // Why no wpdb->prepare? Because the data is trusted. |
|
385 | + // We got the ids from the original query to get them FROM |
|
386 | + // the db (which is sanitized) so no need to prepare them again. |
|
387 | + $query = ' |
|
388 | 388 | DELETE |
389 | 389 | FROM ' . $this->table() . ' |
390 | 390 | WHERE |
391 | 391 | TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
392 | - $deleted = $wpdb->query($query); |
|
393 | - } |
|
394 | - if ($deleted) { |
|
395 | - /** |
|
396 | - * Allows code to do something after the transactions have been deleted. |
|
397 | - */ |
|
398 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
399 | - } |
|
400 | - |
|
401 | - return $deleted; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @param array $transaction_IDs |
|
407 | - * |
|
408 | - * @return bool |
|
409 | - */ |
|
410 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
411 | - { |
|
412 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
413 | - $update = false; |
|
414 | - foreach ($transaction_IDs as $TXN_ID) { |
|
415 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
416 | - unset($locked_transactions[ $TXN_ID ]); |
|
417 | - $update = true; |
|
418 | - } |
|
419 | - } |
|
420 | - if ($update) { |
|
421 | - update_option('ee_locked_transactions', $locked_transactions); |
|
422 | - } |
|
423 | - |
|
424 | - return $update; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
431 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
432 | - * |
|
433 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
434 | - * @throws EE_Error |
|
435 | - * @throws InvalidArgumentException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws InvalidInterfaceException |
|
438 | - */ |
|
439 | - public function get_transactions_in_progress() |
|
440 | - { |
|
441 | - return $this->_get_transactions_in_progress(); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
448 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
449 | - * |
|
450 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
451 | - * @throws EE_Error |
|
452 | - * @throws InvalidArgumentException |
|
453 | - * @throws InvalidDataTypeException |
|
454 | - * @throws InvalidInterfaceException |
|
455 | - */ |
|
456 | - public function get_transactions_not_in_progress() |
|
457 | - { |
|
458 | - return $this->_get_transactions_in_progress('<='); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * @param string $comparison |
|
465 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
466 | - * @throws EE_Error |
|
467 | - * @throws InvalidArgumentException |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - */ |
|
471 | - private function _get_transactions_in_progress($comparison = '>=') |
|
472 | - { |
|
473 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
474 | - ? $comparison |
|
475 | - : '>='; |
|
476 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
477 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
478 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
479 | - ); |
|
480 | - return $this->get_all( |
|
481 | - array( |
|
482 | - array( |
|
483 | - 'TXN_timestamp' => array( |
|
484 | - $comparison, |
|
485 | - $session_lifespan->expiration() |
|
486 | - ), |
|
487 | - 'STS_ID' => array( |
|
488 | - '!=', |
|
489 | - EEM_Transaction::complete_status_code |
|
490 | - ), |
|
491 | - ) |
|
492 | - ) |
|
493 | - ); |
|
494 | - } |
|
392 | + $deleted = $wpdb->query($query); |
|
393 | + } |
|
394 | + if ($deleted) { |
|
395 | + /** |
|
396 | + * Allows code to do something after the transactions have been deleted. |
|
397 | + */ |
|
398 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
399 | + } |
|
400 | + |
|
401 | + return $deleted; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @param array $transaction_IDs |
|
407 | + * |
|
408 | + * @return bool |
|
409 | + */ |
|
410 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
411 | + { |
|
412 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
413 | + $update = false; |
|
414 | + foreach ($transaction_IDs as $TXN_ID) { |
|
415 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
416 | + unset($locked_transactions[ $TXN_ID ]); |
|
417 | + $update = true; |
|
418 | + } |
|
419 | + } |
|
420 | + if ($update) { |
|
421 | + update_option('ee_locked_transactions', $locked_transactions); |
|
422 | + } |
|
423 | + |
|
424 | + return $update; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
431 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
432 | + * |
|
433 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
434 | + * @throws EE_Error |
|
435 | + * @throws InvalidArgumentException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws InvalidInterfaceException |
|
438 | + */ |
|
439 | + public function get_transactions_in_progress() |
|
440 | + { |
|
441 | + return $this->_get_transactions_in_progress(); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
448 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
449 | + * |
|
450 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
451 | + * @throws EE_Error |
|
452 | + * @throws InvalidArgumentException |
|
453 | + * @throws InvalidDataTypeException |
|
454 | + * @throws InvalidInterfaceException |
|
455 | + */ |
|
456 | + public function get_transactions_not_in_progress() |
|
457 | + { |
|
458 | + return $this->_get_transactions_in_progress('<='); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * @param string $comparison |
|
465 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
466 | + * @throws EE_Error |
|
467 | + * @throws InvalidArgumentException |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + */ |
|
471 | + private function _get_transactions_in_progress($comparison = '>=') |
|
472 | + { |
|
473 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
474 | + ? $comparison |
|
475 | + : '>='; |
|
476 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
477 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
478 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
479 | + ); |
|
480 | + return $this->get_all( |
|
481 | + array( |
|
482 | + array( |
|
483 | + 'TXN_timestamp' => array( |
|
484 | + $comparison, |
|
485 | + $session_lifespan->expiration() |
|
486 | + ), |
|
487 | + 'STS_ID' => array( |
|
488 | + '!=', |
|
489 | + EEM_Transaction::complete_status_code |
|
490 | + ), |
|
491 | + ) |
|
492 | + ) |
|
493 | + ); |
|
494 | + } |
|
495 | 495 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | ), |
141 | 141 | ) |
142 | 142 | ); |
143 | - $this->_model_relations = array( |
|
143 | + $this->_model_relations = array( |
|
144 | 144 | 'Registration' => new EE_Has_Many_Relation(), |
145 | 145 | 'Payment' => new EE_Has_Many_Relation(), |
146 | 146 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | ), |
206 | 206 | OBJECT, |
207 | 207 | array( |
208 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
208 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
209 | 209 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
210 | 210 | ) |
211 | 211 | ); |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | public function get_revenue_per_event_report($period = '-1 month') |
226 | 226 | { |
227 | 227 | global $wpdb; |
228 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
228 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
229 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
230 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
231 | 231 | $event_table = $wpdb->posts; |
232 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
232 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
233 | 233 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
234 | 234 | $approved_payment_status = EEM_Payment::status_id_approved; |
235 | 235 | $extra_event_on_join = ''; |
236 | 236 | // exclude events not authored by user if permissions in effect |
237 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | return $wpdb->get_results( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
310 | 310 | { |
311 | 311 | EE_Error::doing_it_wrong( |
312 | - __CLASS__ . '::' . __FUNCTION__, |
|
312 | + __CLASS__.'::'.__FUNCTION__, |
|
313 | 313 | sprintf( |
314 | 314 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
315 | 315 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | array( |
360 | 360 | 0 => array( |
361 | 361 | 'STS_ID' => EEM_Transaction::failed_status_code, |
362 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
362 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
363 | 363 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
364 | 364 | ) |
365 | 365 | ), |
@@ -377,18 +377,18 @@ discard block |
||
377 | 377 | $time_to_leave_alone |
378 | 378 | ); |
379 | 379 | // now that we have the ids to delete |
380 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
380 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
381 | 381 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
382 | 382 | EEM_Transaction::unset_locked_transactions($txn_ids); |
383 | 383 | // let's get deletin'... |
384 | 384 | // Why no wpdb->prepare? Because the data is trusted. |
385 | 385 | // We got the ids from the original query to get them FROM |
386 | 386 | // the db (which is sanitized) so no need to prepare them again. |
387 | - $query = ' |
|
387 | + $query = ' |
|
388 | 388 | DELETE |
389 | - FROM ' . $this->table() . ' |
|
389 | + FROM ' . $this->table().' |
|
390 | 390 | WHERE |
391 | - TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
|
391 | + TXN_ID IN ( ' . implode(",", $txn_ids).')'; |
|
392 | 392 | $deleted = $wpdb->query($query); |
393 | 393 | } |
394 | 394 | if ($deleted) { |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | $locked_transactions = get_option('ee_locked_transactions', array()); |
413 | 413 | $update = false; |
414 | 414 | foreach ($transaction_IDs as $TXN_ID) { |
415 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
416 | - unset($locked_transactions[ $TXN_ID ]); |
|
415 | + if (isset($locked_transactions[$TXN_ID])) { |
|
416 | + unset($locked_transactions[$TXN_ID]); |
|
417 | 417 | $update = true; |
418 | 418 | } |
419 | 419 | } |
@@ -13,27 +13,27 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @deprecated |
|
18 | - * @param EE_Request $request |
|
19 | - * @param EE_Response $response |
|
20 | - * @return EE_Response |
|
21 | - */ |
|
22 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
23 | - { |
|
24 | - EE_Error::doing_it_wrong( |
|
25 | - __METHOD__, |
|
26 | - sprintf( |
|
27 | - esc_html__( |
|
28 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
29 | - 'event_espresso' |
|
30 | - ), |
|
31 | - 'EventEspresso\core\services\request\middleware\DetectLogin', |
|
32 | - '\core\services\request', |
|
33 | - 'EventEspresso\core\services\request' |
|
34 | - ), |
|
35 | - '4.9.52' |
|
36 | - ); |
|
37 | - return $response; |
|
38 | - } |
|
16 | + /** |
|
17 | + * @deprecated |
|
18 | + * @param EE_Request $request |
|
19 | + * @param EE_Response $response |
|
20 | + * @return EE_Response |
|
21 | + */ |
|
22 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
23 | + { |
|
24 | + EE_Error::doing_it_wrong( |
|
25 | + __METHOD__, |
|
26 | + sprintf( |
|
27 | + esc_html__( |
|
28 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
29 | + 'event_espresso' |
|
30 | + ), |
|
31 | + 'EventEspresso\core\services\request\middleware\DetectLogin', |
|
32 | + '\core\services\request', |
|
33 | + 'EventEspresso\core\services\request' |
|
34 | + ), |
|
35 | + '4.9.52' |
|
36 | + ); |
|
37 | + return $response; |
|
38 | + } |
|
39 | 39 | } |
@@ -17,75 +17,75 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @deprecated |
|
22 | - * @param EE_Request $request |
|
23 | - * @param EE_Response $response |
|
24 | - * @return EE_Response |
|
25 | - */ |
|
26 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
27 | - { |
|
28 | - EE_Error::doing_it_wrong( |
|
29 | - __METHOD__, |
|
30 | - sprintf( |
|
31 | - esc_html__( |
|
32 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
33 | - 'event_espresso' |
|
34 | - ), |
|
35 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions', |
|
36 | - '\core\services\request', |
|
37 | - 'EventEspresso\core\services\request' |
|
38 | - ), |
|
39 | - '4.9.52' |
|
40 | - ); |
|
41 | - return $response; |
|
42 | - } |
|
20 | + /** |
|
21 | + * @deprecated |
|
22 | + * @param EE_Request $request |
|
23 | + * @param EE_Response $response |
|
24 | + * @return EE_Response |
|
25 | + */ |
|
26 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
27 | + { |
|
28 | + EE_Error::doing_it_wrong( |
|
29 | + __METHOD__, |
|
30 | + sprintf( |
|
31 | + esc_html__( |
|
32 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
33 | + 'event_espresso' |
|
34 | + ), |
|
35 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions', |
|
36 | + '\core\services\request', |
|
37 | + 'EventEspresso\core\services\request' |
|
38 | + ), |
|
39 | + '4.9.52' |
|
40 | + ); |
|
41 | + return $response; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @deprecated |
|
47 | - * @param string $version_to_check |
|
48 | - * @param string $operator |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
52 | - { |
|
53 | - EE_Error::doing_it_wrong( |
|
54 | - __METHOD__, |
|
55 | - sprintf( |
|
56 | - esc_html__( |
|
57 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
58 | - 'event_espresso' |
|
59 | - ), |
|
60 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions::compareWordPressVersion()', |
|
61 | - '\core\services\request', |
|
62 | - 'EventEspresso\core\services\request' |
|
63 | - ), |
|
64 | - '4.9.52', |
|
65 | - '5.0.0' |
|
66 | - ); |
|
67 | - return RecommendedVersions::compareWordPressVersion($version_to_check, $operator); |
|
68 | - } |
|
45 | + /** |
|
46 | + * @deprecated |
|
47 | + * @param string $version_to_check |
|
48 | + * @param string $operator |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
52 | + { |
|
53 | + EE_Error::doing_it_wrong( |
|
54 | + __METHOD__, |
|
55 | + sprintf( |
|
56 | + esc_html__( |
|
57 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
58 | + 'event_espresso' |
|
59 | + ), |
|
60 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions::compareWordPressVersion()', |
|
61 | + '\core\services\request', |
|
62 | + 'EventEspresso\core\services\request' |
|
63 | + ), |
|
64 | + '4.9.52', |
|
65 | + '5.0.0' |
|
66 | + ); |
|
67 | + return RecommendedVersions::compareWordPressVersion($version_to_check, $operator); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @deprecated |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function minimum_wp_version_error() |
|
76 | - { |
|
77 | - EE_Error::doing_it_wrong( |
|
78 | - __METHOD__, |
|
79 | - sprintf( |
|
80 | - esc_html__( |
|
81 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions::minimumWpVersionError()', |
|
85 | - '\core\services\request', |
|
86 | - 'EventEspresso\core\services\request' |
|
87 | - ), |
|
88 | - '4.9.52' |
|
89 | - ); |
|
90 | - } |
|
71 | + /** |
|
72 | + * @deprecated |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function minimum_wp_version_error() |
|
76 | + { |
|
77 | + EE_Error::doing_it_wrong( |
|
78 | + __METHOD__, |
|
79 | + sprintf( |
|
80 | + esc_html__( |
|
81 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions::minimumWpVersionError()', |
|
85 | + '\core\services\request', |
|
86 | + 'EventEspresso\core\services\request' |
|
87 | + ), |
|
88 | + '4.9.52' |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -20,27 +20,27 @@ |
||
20 | 20 | abstract class EE_Middleware implements EEI_Request_Decorator |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @deprecated |
|
25 | - * @param EE_Request $request |
|
26 | - * @param EE_Response $response |
|
27 | - * @return EE_Response |
|
28 | - */ |
|
29 | - protected function process_request_stack(EE_Request $request, EE_Response $response) |
|
30 | - { |
|
31 | - EE_Error::doing_it_wrong( |
|
32 | - __METHOD__, |
|
33 | - sprintf( |
|
34 | - esc_html__( |
|
35 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - 'EventEspresso\core\services\request\middleware\Middleware', |
|
39 | - '\core\services\request', |
|
40 | - 'EventEspresso\core\services\request' |
|
41 | - ), |
|
42 | - '4.9.52' |
|
43 | - ); |
|
44 | - return $response; |
|
45 | - } |
|
23 | + /** |
|
24 | + * @deprecated |
|
25 | + * @param EE_Request $request |
|
26 | + * @param EE_Response $response |
|
27 | + * @return EE_Response |
|
28 | + */ |
|
29 | + protected function process_request_stack(EE_Request $request, EE_Response $response) |
|
30 | + { |
|
31 | + EE_Error::doing_it_wrong( |
|
32 | + __METHOD__, |
|
33 | + sprintf( |
|
34 | + esc_html__( |
|
35 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + 'EventEspresso\core\services\request\middleware\Middleware', |
|
39 | + '\core\services\request', |
|
40 | + 'EventEspresso\core\services\request' |
|
41 | + ), |
|
42 | + '4.9.52' |
|
43 | + ); |
|
44 | + return $response; |
|
45 | + } |
|
46 | 46 | } |
@@ -14,87 +14,87 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @deprecated 4.9.53 |
|
19 | - * @param EE_Request $request |
|
20 | - * @param EE_Response $response |
|
21 | - * @return EE_Response |
|
22 | - */ |
|
23 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
24 | - { |
|
25 | - $this->_request = $request; |
|
26 | - $this->_response = $response; |
|
27 | - $this->display_alpha_banner_warning(); |
|
28 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
29 | - return $this->_response; |
|
30 | - } |
|
17 | + /** |
|
18 | + * @deprecated 4.9.53 |
|
19 | + * @param EE_Request $request |
|
20 | + * @param EE_Response $response |
|
21 | + * @return EE_Response |
|
22 | + */ |
|
23 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
24 | + { |
|
25 | + $this->_request = $request; |
|
26 | + $this->_response = $response; |
|
27 | + $this->display_alpha_banner_warning(); |
|
28 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
29 | + return $this->_response; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @deprecated |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function display_alpha_banner_warning() |
|
38 | - { |
|
39 | - EE_Error::doing_it_wrong( |
|
40 | - __METHOD__, |
|
41 | - sprintf( |
|
42 | - esc_html__( |
|
43 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::displayPreProductionVersionWarning()', |
|
47 | - '\core\services\request', |
|
48 | - 'EventEspresso\core\services\request' |
|
49 | - ), |
|
50 | - '4.9.52', |
|
51 | - '4.10.0' |
|
52 | - ); |
|
53 | - } |
|
33 | + /** |
|
34 | + * @deprecated |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function display_alpha_banner_warning() |
|
38 | + { |
|
39 | + EE_Error::doing_it_wrong( |
|
40 | + __METHOD__, |
|
41 | + sprintf( |
|
42 | + esc_html__( |
|
43 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::displayPreProductionVersionWarning()', |
|
47 | + '\core\services\request', |
|
48 | + 'EventEspresso\core\services\request' |
|
49 | + ), |
|
50 | + '4.9.52', |
|
51 | + '4.10.0' |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @deprecated |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function alpha_banner_admin_notice() |
|
61 | - { |
|
62 | - EE_Error::doing_it_wrong( |
|
63 | - __METHOD__, |
|
64 | - sprintf( |
|
65 | - esc_html__( |
|
66 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionAdminNotice()', |
|
70 | - '\core\services\request', |
|
71 | - 'EventEspresso\core\services\request' |
|
72 | - ), |
|
73 | - '4.9.52', |
|
74 | - '4.10.0' |
|
75 | - ); |
|
76 | - } |
|
56 | + /** |
|
57 | + * @deprecated |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function alpha_banner_admin_notice() |
|
61 | + { |
|
62 | + EE_Error::doing_it_wrong( |
|
63 | + __METHOD__, |
|
64 | + sprintf( |
|
65 | + esc_html__( |
|
66 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionAdminNotice()', |
|
70 | + '\core\services\request', |
|
71 | + 'EventEspresso\core\services\request' |
|
72 | + ), |
|
73 | + '4.9.52', |
|
74 | + '4.10.0' |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @deprecated |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function alpha_banner_warning_notice() |
|
84 | - { |
|
85 | - EE_Error::doing_it_wrong( |
|
86 | - __METHOD__, |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionWarningNotice()', |
|
93 | - '\core\services\request', |
|
94 | - 'EventEspresso\core\services\request' |
|
95 | - ), |
|
96 | - '4.9.52', |
|
97 | - '4.10.0' |
|
98 | - ); |
|
99 | - } |
|
79 | + /** |
|
80 | + * @deprecated |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function alpha_banner_warning_notice() |
|
84 | + { |
|
85 | + EE_Error::doing_it_wrong( |
|
86 | + __METHOD__, |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'This method is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning::preProductionVersionWarningNotice()', |
|
93 | + '\core\services\request', |
|
94 | + 'EventEspresso\core\services\request' |
|
95 | + ), |
|
96 | + '4.9.52', |
|
97 | + '4.10.0' |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | } |
@@ -15,98 +15,98 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * instance of the EE_Data_Mapper Object |
|
20 | - * |
|
21 | - * @private _instance |
|
22 | - */ |
|
23 | - private static $_instance = null; |
|
24 | - |
|
25 | - |
|
26 | - public $data = array(); |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - *private constructor to prevent direct creation |
|
31 | - * |
|
32 | - * @Constructor |
|
33 | - * @access private |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - private function __construct() |
|
37 | - { |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - *@ singleton method used to instantiate class object |
|
43 | - *@ access public |
|
44 | - *@ return class instance |
|
45 | - */ |
|
46 | - public function &instance() |
|
47 | - { |
|
48 | - // check if class object is instantiated |
|
49 | - if (self::$_instance === null |
|
50 | - || ! is_object(self::$_instance) |
|
51 | - || ! self::$_instance instanceof EE_Data_Mapper |
|
52 | - ) { |
|
53 | - self::$_instance = new self(); |
|
54 | - } |
|
55 | - return self::$_instance; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @ override magic methods |
|
61 | - * @ return void |
|
62 | - */ |
|
63 | - final public function __destruct() |
|
64 | - { |
|
65 | - } |
|
66 | - |
|
67 | - final public function __call($a, $b) |
|
68 | - { |
|
69 | - } |
|
70 | - |
|
71 | - public static function __callStatic($a, $b) |
|
72 | - { |
|
73 | - } |
|
74 | - |
|
75 | - final public function __get($a) |
|
76 | - { |
|
77 | - } |
|
78 | - |
|
79 | - final public function __set($a, $b) |
|
80 | - { |
|
81 | - } |
|
82 | - |
|
83 | - final public function __isset($a) |
|
84 | - { |
|
85 | - } |
|
86 | - |
|
87 | - final public function __unset($a) |
|
88 | - { |
|
89 | - } |
|
90 | - |
|
91 | - final public function __sleep() |
|
92 | - { |
|
93 | - return array(); |
|
94 | - } |
|
95 | - |
|
96 | - final public function __wakeup() |
|
97 | - { |
|
98 | - } |
|
99 | - |
|
100 | - final public function __toString() |
|
101 | - { |
|
102 | - return ''; |
|
103 | - } |
|
104 | - |
|
105 | - final public function __invoke() |
|
106 | - { |
|
107 | - } |
|
108 | - |
|
109 | - final public function __clone() |
|
110 | - { |
|
111 | - } |
|
18 | + /** |
|
19 | + * instance of the EE_Data_Mapper Object |
|
20 | + * |
|
21 | + * @private _instance |
|
22 | + */ |
|
23 | + private static $_instance = null; |
|
24 | + |
|
25 | + |
|
26 | + public $data = array(); |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + *private constructor to prevent direct creation |
|
31 | + * |
|
32 | + * @Constructor |
|
33 | + * @access private |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + private function __construct() |
|
37 | + { |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + *@ singleton method used to instantiate class object |
|
43 | + *@ access public |
|
44 | + *@ return class instance |
|
45 | + */ |
|
46 | + public function &instance() |
|
47 | + { |
|
48 | + // check if class object is instantiated |
|
49 | + if (self::$_instance === null |
|
50 | + || ! is_object(self::$_instance) |
|
51 | + || ! self::$_instance instanceof EE_Data_Mapper |
|
52 | + ) { |
|
53 | + self::$_instance = new self(); |
|
54 | + } |
|
55 | + return self::$_instance; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @ override magic methods |
|
61 | + * @ return void |
|
62 | + */ |
|
63 | + final public function __destruct() |
|
64 | + { |
|
65 | + } |
|
66 | + |
|
67 | + final public function __call($a, $b) |
|
68 | + { |
|
69 | + } |
|
70 | + |
|
71 | + public static function __callStatic($a, $b) |
|
72 | + { |
|
73 | + } |
|
74 | + |
|
75 | + final public function __get($a) |
|
76 | + { |
|
77 | + } |
|
78 | + |
|
79 | + final public function __set($a, $b) |
|
80 | + { |
|
81 | + } |
|
82 | + |
|
83 | + final public function __isset($a) |
|
84 | + { |
|
85 | + } |
|
86 | + |
|
87 | + final public function __unset($a) |
|
88 | + { |
|
89 | + } |
|
90 | + |
|
91 | + final public function __sleep() |
|
92 | + { |
|
93 | + return array(); |
|
94 | + } |
|
95 | + |
|
96 | + final public function __wakeup() |
|
97 | + { |
|
98 | + } |
|
99 | + |
|
100 | + final public function __toString() |
|
101 | + { |
|
102 | + return ''; |
|
103 | + } |
|
104 | + |
|
105 | + final public function __invoke() |
|
106 | + { |
|
107 | + } |
|
108 | + |
|
109 | + final public function __clone() |
|
110 | + { |
|
111 | + } |
|
112 | 112 | } |
@@ -19,790 +19,790 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | - * which will be used to store the plugin's activation history |
|
25 | - */ |
|
26 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var $_version |
|
30 | - * @type string |
|
31 | - */ |
|
32 | - protected $_version = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var $_min_core_version |
|
36 | - * @type string |
|
37 | - */ |
|
38 | - protected $_min_core_version = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * derived from plugin 'main_file_path using plugin_basename() |
|
42 | - * |
|
43 | - * @type string $_plugin_basename |
|
44 | - */ |
|
45 | - protected $_plugin_basename = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | - * |
|
50 | - * @type string $_plugin_slug |
|
51 | - */ |
|
52 | - protected $_plugin_slug = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | - * |
|
57 | - * @type string _addon_name |
|
58 | - */ |
|
59 | - protected $_addon_name = ''; |
|
60 | - |
|
61 | - /** |
|
62 | - * one of the EE_System::req_type_* constants |
|
63 | - * |
|
64 | - * @type int $_req_type |
|
65 | - */ |
|
66 | - protected $_req_type; |
|
67 | - |
|
68 | - /** |
|
69 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | - * |
|
71 | - * @type string $_plugin_action_slug |
|
72 | - */ |
|
73 | - protected $_plugin_action_slug = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | - * that can be used for adding upgrading/marketing info |
|
78 | - * |
|
79 | - * @type array $_plugins_page_row |
|
80 | - */ |
|
81 | - protected $_plugins_page_row = array(); |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | - * |
|
87 | - * @type string |
|
88 | - */ |
|
89 | - protected $_main_plugin_file; |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @var EE_Dependency_Map $dependency_map |
|
94 | - */ |
|
95 | - private $dependency_map; |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @var DomainInterface $domain |
|
100 | - */ |
|
101 | - private $domain; |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param EE_Dependency_Map $dependency_map [optional] |
|
106 | - * @param DomainInterface $domain [optional] |
|
107 | - */ |
|
108 | - public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
109 | - { |
|
110 | - if ($dependency_map instanceof EE_Dependency_Map) { |
|
111 | - $this->setDependencyMap($dependency_map); |
|
112 | - } |
|
113 | - if ($domain instanceof DomainInterface) { |
|
114 | - $this->setDomain($domain); |
|
115 | - } |
|
116 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param EE_Dependency_Map $dependency_map |
|
122 | - */ |
|
123 | - public function setDependencyMap($dependency_map) |
|
124 | - { |
|
125 | - $this->dependency_map = $dependency_map; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @return EE_Dependency_Map |
|
131 | - */ |
|
132 | - public function dependencyMap() |
|
133 | - { |
|
134 | - return $this->dependency_map; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param DomainInterface $domain |
|
140 | - */ |
|
141 | - public function setDomain(DomainInterface $domain) |
|
142 | - { |
|
143 | - $this->domain = $domain; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return DomainInterface |
|
148 | - */ |
|
149 | - public function domain() |
|
150 | - { |
|
151 | - return $this->domain; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param mixed $version |
|
157 | - */ |
|
158 | - public function set_version($version = null) |
|
159 | - { |
|
160 | - $this->_version = $version; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * get__version |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function version() |
|
170 | - { |
|
171 | - return $this->_version; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param mixed $min_core_version |
|
177 | - */ |
|
178 | - public function set_min_core_version($min_core_version = null) |
|
179 | - { |
|
180 | - $this->_min_core_version = $min_core_version; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * get__min_core_version |
|
186 | - * |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function min_core_version() |
|
190 | - { |
|
191 | - return $this->_min_core_version; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Sets addon_name |
|
197 | - * |
|
198 | - * @param string $addon_name |
|
199 | - * @return boolean |
|
200 | - */ |
|
201 | - public function set_name($addon_name) |
|
202 | - { |
|
203 | - return $this->_addon_name = $addon_name; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Gets addon_name |
|
209 | - * |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function name() |
|
213 | - { |
|
214 | - return $this->_addon_name; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function plugin_basename() |
|
222 | - { |
|
223 | - |
|
224 | - return $this->_plugin_basename; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @param string $plugin_basename |
|
230 | - */ |
|
231 | - public function set_plugin_basename($plugin_basename) |
|
232 | - { |
|
233 | - |
|
234 | - $this->_plugin_basename = $plugin_basename; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public function plugin_slug() |
|
242 | - { |
|
243 | - |
|
244 | - return $this->_plugin_slug; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @param string $plugin_slug |
|
250 | - */ |
|
251 | - public function set_plugin_slug($plugin_slug) |
|
252 | - { |
|
253 | - |
|
254 | - $this->_plugin_slug = $plugin_slug; |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * @return string |
|
260 | - */ |
|
261 | - public function plugin_action_slug() |
|
262 | - { |
|
263 | - |
|
264 | - return $this->_plugin_action_slug; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @param string $plugin_action_slug |
|
270 | - */ |
|
271 | - public function set_plugin_action_slug($plugin_action_slug) |
|
272 | - { |
|
273 | - |
|
274 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * @return array |
|
280 | - */ |
|
281 | - public function get_plugins_page_row() |
|
282 | - { |
|
283 | - |
|
284 | - return $this->_plugins_page_row; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @param array $plugins_page_row |
|
290 | - */ |
|
291 | - public function set_plugins_page_row($plugins_page_row = array()) |
|
292 | - { |
|
293 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
294 | - if (! is_array($plugins_page_row) |
|
295 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
296 | - ) { |
|
297 | - $plugins_page_row = array(); |
|
298 | - } |
|
299 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Called when EE core detects this addon has been activated for the first time. |
|
305 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
306 | - * |
|
307 | - * @return void |
|
308 | - */ |
|
309 | - public function new_install() |
|
310 | - { |
|
311 | - $classname = get_class($this); |
|
312 | - do_action("AHEE__{$classname}__new_install"); |
|
313 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
314 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
315 | - add_action( |
|
316 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
317 | - array($this, 'initialize_db_if_no_migrations_required') |
|
318 | - ); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
324 | - * it's good to just check that your data is still intact |
|
325 | - * |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public function reactivation() |
|
329 | - { |
|
330 | - $classname = get_class($this); |
|
331 | - do_action("AHEE__{$classname}__reactivation"); |
|
332 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
333 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
334 | - add_action( |
|
335 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
336 | - array($this, 'initialize_db_if_no_migrations_required') |
|
337 | - ); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * Called when the registered deactivation hook for this addon fires. |
|
343 | - * |
|
344 | - * @throws EE_Error |
|
345 | - */ |
|
346 | - public function deactivation() |
|
347 | - { |
|
348 | - $classname = get_class($this); |
|
349 | - do_action("AHEE__{$classname}__deactivation"); |
|
350 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
351 | - // check if the site no longer needs to be in maintenance mode |
|
352 | - EE_Register_Addon::deregister($this->name()); |
|
353 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * Takes care of double-checking that we're not in maintenance mode, and then |
|
359 | - * initializing this addon's necessary initial data. This is called by default on new activations |
|
360 | - * and reactivations. |
|
361 | - * |
|
362 | - * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
363 | - * This is a resource-intensive job so we prefer to only do it when necessary |
|
364 | - * @return void |
|
365 | - * @throws \EE_Error |
|
366 | - * @throws InvalidInterfaceException |
|
367 | - * @throws InvalidDataTypeException |
|
368 | - * @throws InvalidArgumentException |
|
369 | - */ |
|
370 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
371 | - { |
|
372 | - if ($verify_schema === '') { |
|
373 | - // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
374 | - // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
375 | - // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
376 | - // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
377 | - $verify_schema = true; |
|
378 | - } |
|
379 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
380 | - if ($verify_schema) { |
|
381 | - $this->initialize_db(); |
|
382 | - } |
|
383 | - $this->initialize_default_data(); |
|
384 | - // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
385 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
386 | - array( |
|
387 | - 'slug' => $this->name(), |
|
388 | - 'version' => $this->version(), |
|
389 | - ) |
|
390 | - ); |
|
391 | - /* make sure core's data is a-ok |
|
22 | + /** |
|
23 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | + * which will be used to store the plugin's activation history |
|
25 | + */ |
|
26 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var $_version |
|
30 | + * @type string |
|
31 | + */ |
|
32 | + protected $_version = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var $_min_core_version |
|
36 | + * @type string |
|
37 | + */ |
|
38 | + protected $_min_core_version = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * derived from plugin 'main_file_path using plugin_basename() |
|
42 | + * |
|
43 | + * @type string $_plugin_basename |
|
44 | + */ |
|
45 | + protected $_plugin_basename = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | + * |
|
50 | + * @type string $_plugin_slug |
|
51 | + */ |
|
52 | + protected $_plugin_slug = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | + * |
|
57 | + * @type string _addon_name |
|
58 | + */ |
|
59 | + protected $_addon_name = ''; |
|
60 | + |
|
61 | + /** |
|
62 | + * one of the EE_System::req_type_* constants |
|
63 | + * |
|
64 | + * @type int $_req_type |
|
65 | + */ |
|
66 | + protected $_req_type; |
|
67 | + |
|
68 | + /** |
|
69 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | + * |
|
71 | + * @type string $_plugin_action_slug |
|
72 | + */ |
|
73 | + protected $_plugin_action_slug = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | + * that can be used for adding upgrading/marketing info |
|
78 | + * |
|
79 | + * @type array $_plugins_page_row |
|
80 | + */ |
|
81 | + protected $_plugins_page_row = array(); |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | + * |
|
87 | + * @type string |
|
88 | + */ |
|
89 | + protected $_main_plugin_file; |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @var EE_Dependency_Map $dependency_map |
|
94 | + */ |
|
95 | + private $dependency_map; |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @var DomainInterface $domain |
|
100 | + */ |
|
101 | + private $domain; |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param EE_Dependency_Map $dependency_map [optional] |
|
106 | + * @param DomainInterface $domain [optional] |
|
107 | + */ |
|
108 | + public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
109 | + { |
|
110 | + if ($dependency_map instanceof EE_Dependency_Map) { |
|
111 | + $this->setDependencyMap($dependency_map); |
|
112 | + } |
|
113 | + if ($domain instanceof DomainInterface) { |
|
114 | + $this->setDomain($domain); |
|
115 | + } |
|
116 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param EE_Dependency_Map $dependency_map |
|
122 | + */ |
|
123 | + public function setDependencyMap($dependency_map) |
|
124 | + { |
|
125 | + $this->dependency_map = $dependency_map; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @return EE_Dependency_Map |
|
131 | + */ |
|
132 | + public function dependencyMap() |
|
133 | + { |
|
134 | + return $this->dependency_map; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param DomainInterface $domain |
|
140 | + */ |
|
141 | + public function setDomain(DomainInterface $domain) |
|
142 | + { |
|
143 | + $this->domain = $domain; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return DomainInterface |
|
148 | + */ |
|
149 | + public function domain() |
|
150 | + { |
|
151 | + return $this->domain; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param mixed $version |
|
157 | + */ |
|
158 | + public function set_version($version = null) |
|
159 | + { |
|
160 | + $this->_version = $version; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * get__version |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function version() |
|
170 | + { |
|
171 | + return $this->_version; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param mixed $min_core_version |
|
177 | + */ |
|
178 | + public function set_min_core_version($min_core_version = null) |
|
179 | + { |
|
180 | + $this->_min_core_version = $min_core_version; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * get__min_core_version |
|
186 | + * |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function min_core_version() |
|
190 | + { |
|
191 | + return $this->_min_core_version; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Sets addon_name |
|
197 | + * |
|
198 | + * @param string $addon_name |
|
199 | + * @return boolean |
|
200 | + */ |
|
201 | + public function set_name($addon_name) |
|
202 | + { |
|
203 | + return $this->_addon_name = $addon_name; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Gets addon_name |
|
209 | + * |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function name() |
|
213 | + { |
|
214 | + return $this->_addon_name; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function plugin_basename() |
|
222 | + { |
|
223 | + |
|
224 | + return $this->_plugin_basename; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @param string $plugin_basename |
|
230 | + */ |
|
231 | + public function set_plugin_basename($plugin_basename) |
|
232 | + { |
|
233 | + |
|
234 | + $this->_plugin_basename = $plugin_basename; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public function plugin_slug() |
|
242 | + { |
|
243 | + |
|
244 | + return $this->_plugin_slug; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @param string $plugin_slug |
|
250 | + */ |
|
251 | + public function set_plugin_slug($plugin_slug) |
|
252 | + { |
|
253 | + |
|
254 | + $this->_plugin_slug = $plugin_slug; |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * @return string |
|
260 | + */ |
|
261 | + public function plugin_action_slug() |
|
262 | + { |
|
263 | + |
|
264 | + return $this->_plugin_action_slug; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @param string $plugin_action_slug |
|
270 | + */ |
|
271 | + public function set_plugin_action_slug($plugin_action_slug) |
|
272 | + { |
|
273 | + |
|
274 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * @return array |
|
280 | + */ |
|
281 | + public function get_plugins_page_row() |
|
282 | + { |
|
283 | + |
|
284 | + return $this->_plugins_page_row; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @param array $plugins_page_row |
|
290 | + */ |
|
291 | + public function set_plugins_page_row($plugins_page_row = array()) |
|
292 | + { |
|
293 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
294 | + if (! is_array($plugins_page_row) |
|
295 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
296 | + ) { |
|
297 | + $plugins_page_row = array(); |
|
298 | + } |
|
299 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Called when EE core detects this addon has been activated for the first time. |
|
305 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
306 | + * |
|
307 | + * @return void |
|
308 | + */ |
|
309 | + public function new_install() |
|
310 | + { |
|
311 | + $classname = get_class($this); |
|
312 | + do_action("AHEE__{$classname}__new_install"); |
|
313 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
314 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
315 | + add_action( |
|
316 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
317 | + array($this, 'initialize_db_if_no_migrations_required') |
|
318 | + ); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
324 | + * it's good to just check that your data is still intact |
|
325 | + * |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public function reactivation() |
|
329 | + { |
|
330 | + $classname = get_class($this); |
|
331 | + do_action("AHEE__{$classname}__reactivation"); |
|
332 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
333 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
334 | + add_action( |
|
335 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
336 | + array($this, 'initialize_db_if_no_migrations_required') |
|
337 | + ); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * Called when the registered deactivation hook for this addon fires. |
|
343 | + * |
|
344 | + * @throws EE_Error |
|
345 | + */ |
|
346 | + public function deactivation() |
|
347 | + { |
|
348 | + $classname = get_class($this); |
|
349 | + do_action("AHEE__{$classname}__deactivation"); |
|
350 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
351 | + // check if the site no longer needs to be in maintenance mode |
|
352 | + EE_Register_Addon::deregister($this->name()); |
|
353 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * Takes care of double-checking that we're not in maintenance mode, and then |
|
359 | + * initializing this addon's necessary initial data. This is called by default on new activations |
|
360 | + * and reactivations. |
|
361 | + * |
|
362 | + * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
363 | + * This is a resource-intensive job so we prefer to only do it when necessary |
|
364 | + * @return void |
|
365 | + * @throws \EE_Error |
|
366 | + * @throws InvalidInterfaceException |
|
367 | + * @throws InvalidDataTypeException |
|
368 | + * @throws InvalidArgumentException |
|
369 | + */ |
|
370 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
371 | + { |
|
372 | + if ($verify_schema === '') { |
|
373 | + // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
374 | + // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
375 | + // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
376 | + // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
377 | + $verify_schema = true; |
|
378 | + } |
|
379 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
380 | + if ($verify_schema) { |
|
381 | + $this->initialize_db(); |
|
382 | + } |
|
383 | + $this->initialize_default_data(); |
|
384 | + // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
385 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
386 | + array( |
|
387 | + 'slug' => $this->name(), |
|
388 | + 'version' => $this->version(), |
|
389 | + ) |
|
390 | + ); |
|
391 | + /* make sure core's data is a-ok |
|
392 | 392 | * (at the time of writing, we especially want to verify all the caps are present |
393 | 393 | * because payment method type capabilities are added dynamically, and it's |
394 | 394 | * possible this addon added a payment method. But it's also possible |
395 | 395 | * other data needs to be verified) |
396 | 396 | */ |
397 | - EEH_Activation::initialize_db_content(); |
|
398 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
399 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
400 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
401 | - ); |
|
402 | - $rewrite_rules->flushRewriteRules(); |
|
403 | - // in case there are lots of addons being activated at once, let's force garbage collection |
|
404 | - // to help avoid memory limit errors |
|
405 | - // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
406 | - gc_collect_cycles(); |
|
407 | - } else { |
|
408 | - // ask the data migration manager to init this addon's data |
|
409 | - // when migrations are finished because we can't do it now |
|
410 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * Used to setup this addon's database tables, but not necessarily any default |
|
417 | - * data in them. The default is to actually use the most up-to-date data migration script |
|
418 | - * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
419 | - * methods to setup the db. |
|
420 | - */ |
|
421 | - public function initialize_db() |
|
422 | - { |
|
423 | - // find the migration script that sets the database to be compatible with the code |
|
424 | - $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
425 | - if ($current_dms_name) { |
|
426 | - $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
427 | - $current_data_migration_script->set_migrating(false); |
|
428 | - $current_data_migration_script->schema_changes_before_migration(); |
|
429 | - $current_data_migration_script->schema_changes_after_migration(); |
|
430 | - if ($current_data_migration_script->get_errors()) { |
|
431 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
432 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
433 | - } |
|
434 | - } |
|
435 | - } |
|
436 | - // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
437 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
438 | - array( |
|
439 | - 'slug' => $this->name(), |
|
440 | - 'version' => $this->version(), |
|
441 | - ) |
|
442 | - ); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * If you want to setup default data for the addon, override this method, and call |
|
448 | - * parent::initialize_default_data() from within it. This is normally called |
|
449 | - * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
450 | - * and should verify default data is present (but this is also called |
|
451 | - * on reactivations and just after migrations, so please verify you actually want |
|
452 | - * to ADD default data, because it may already be present). |
|
453 | - * However, please call this parent (currently it just fires a hook which other |
|
454 | - * addons may be depending on) |
|
455 | - */ |
|
456 | - public function initialize_default_data() |
|
457 | - { |
|
458 | - /** |
|
459 | - * Called when an addon is ensuring its default data is set (possibly called |
|
460 | - * on a reactivation, so first check for the absence of other data before setting |
|
461 | - * default data) |
|
462 | - * |
|
463 | - * @param EE_Addon $addon the addon that called this |
|
464 | - */ |
|
465 | - do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
466 | - // override to insert default data. It is safe to use the models here |
|
467 | - // because the site should not be in maintenance mode |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * EE Core detected that this addon has been upgraded. We should check if there |
|
473 | - * are any new migration scripts, and if so put the site into maintenance mode until |
|
474 | - * they're ran |
|
475 | - * |
|
476 | - * @return void |
|
477 | - */ |
|
478 | - public function upgrade() |
|
479 | - { |
|
480 | - $classname = get_class($this); |
|
481 | - do_action("AHEE__{$classname}__upgrade"); |
|
482 | - do_action('AHEE__EE_Addon__upgrade', $this); |
|
483 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
484 | - // also it's possible there is new default data that needs to be added |
|
485 | - add_action( |
|
486 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
487 | - array($this, 'initialize_db_if_no_migrations_required') |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
494 | - */ |
|
495 | - public function downgrade() |
|
496 | - { |
|
497 | - $classname = get_class($this); |
|
498 | - do_action("AHEE__{$classname}__downgrade"); |
|
499 | - do_action('AHEE__EE_Addon__downgrade', $this); |
|
500 | - // it's possible there's old default data that needs to be double-checked |
|
501 | - add_action( |
|
502 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
503 | - array($this, 'initialize_db_if_no_migrations_required') |
|
504 | - ); |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * set_db_update_option_name |
|
510 | - * Until we do something better, we'll just check for migration scripts upon |
|
511 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
512 | - * |
|
513 | - * @return bool |
|
514 | - */ |
|
515 | - public function set_db_update_option_name() |
|
516 | - { |
|
517 | - EE_Error::doing_it_wrong( |
|
518 | - __FUNCTION__, |
|
519 | - esc_html__( |
|
520 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
521 | - 'event_espresso' |
|
522 | - ), |
|
523 | - '4.3.0.alpha.016' |
|
524 | - ); |
|
525 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
526 | - return $this->set_activation_indicator_option(); |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * Returns the name of the activation indicator option |
|
532 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
533 | - * |
|
534 | - * @deprecated since version 4.3.0.alpha.016 |
|
535 | - * @return string |
|
536 | - */ |
|
537 | - public function get_db_update_option_name() |
|
538 | - { |
|
539 | - EE_Error::doing_it_wrong( |
|
540 | - __FUNCTION__, |
|
541 | - esc_html__( |
|
542 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
543 | - 'event_espresso' |
|
544 | - ), |
|
545 | - '4.3.0.alpha.016' |
|
546 | - ); |
|
547 | - return $this->get_activation_indicator_option_name(); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * When the addon is activated, this should be called to set a wordpress option that |
|
553 | - * indicates it was activated. This is especially useful for detecting reactivations. |
|
554 | - * |
|
555 | - * @return bool |
|
556 | - */ |
|
557 | - public function set_activation_indicator_option() |
|
558 | - { |
|
559 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
560 | - return update_option($this->get_activation_indicator_option_name(), true); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
566 | - * |
|
567 | - * @return string |
|
568 | - */ |
|
569 | - public function get_activation_indicator_option_name() |
|
570 | - { |
|
571 | - return 'ee_activation_' . $this->name(); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
577 | - * |
|
578 | - * @param int $req_type |
|
579 | - */ |
|
580 | - public function set_req_type($req_type) |
|
581 | - { |
|
582 | - $this->_req_type = $req_type; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
588 | - * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
589 | - * EE_System when it is checking for new install or upgrades of addons |
|
590 | - */ |
|
591 | - public function detect_req_type() |
|
592 | - { |
|
593 | - if (! $this->_req_type) { |
|
594 | - $this->detect_activation_or_upgrade(); |
|
595 | - } |
|
596 | - return $this->_req_type; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
602 | - * Should only be called once per request |
|
603 | - * |
|
604 | - * @return void |
|
605 | - */ |
|
606 | - public function detect_activation_or_upgrade() |
|
607 | - { |
|
608 | - $activation_history_for_addon = $this->get_activation_history(); |
|
609 | - $request_type = EE_System::detect_req_type_given_activation_history( |
|
610 | - $activation_history_for_addon, |
|
611 | - $this->get_activation_indicator_option_name(), |
|
612 | - $this->version() |
|
613 | - ); |
|
614 | - $this->set_req_type($request_type); |
|
615 | - $classname = get_class($this); |
|
616 | - switch ($request_type) { |
|
617 | - case EE_System::req_type_new_activation: |
|
618 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
619 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
620 | - $this->new_install(); |
|
621 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
622 | - break; |
|
623 | - case EE_System::req_type_reactivation: |
|
624 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
625 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
626 | - $this->reactivation(); |
|
627 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
628 | - break; |
|
629 | - case EE_System::req_type_upgrade: |
|
630 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
631 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
632 | - $this->upgrade(); |
|
633 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
634 | - break; |
|
635 | - case EE_System::req_type_downgrade: |
|
636 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
637 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
638 | - $this->downgrade(); |
|
639 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
640 | - break; |
|
641 | - case EE_System::req_type_normal: |
|
642 | - default: |
|
643 | - break; |
|
644 | - } |
|
645 | - |
|
646 | - do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Updates the version history for this addon |
|
651 | - * |
|
652 | - * @param array $version_history |
|
653 | - * @param string $current_version_to_add |
|
654 | - * @return boolean success |
|
655 | - */ |
|
656 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
657 | - { |
|
658 | - if (! $version_history) { |
|
659 | - $version_history = $this->get_activation_history(); |
|
660 | - } |
|
661 | - if ($current_version_to_add === null) { |
|
662 | - $current_version_to_add = $this->version(); |
|
663 | - } |
|
664 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
665 | - // resave |
|
666 | - return update_option($this->get_activation_history_option_name(), $version_history); |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Gets the name of the wp option that stores the activation history |
|
671 | - * of this addon |
|
672 | - * |
|
673 | - * @return string |
|
674 | - */ |
|
675 | - public function get_activation_history_option_name() |
|
676 | - { |
|
677 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * Gets the wp option which stores the activation history for this addon |
|
683 | - * |
|
684 | - * @return array |
|
685 | - */ |
|
686 | - public function get_activation_history() |
|
687 | - { |
|
688 | - return get_option($this->get_activation_history_option_name(), null); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * @param string $config_section |
|
694 | - */ |
|
695 | - public function set_config_section($config_section = '') |
|
696 | - { |
|
697 | - $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Sets the filepath to the main plugin file |
|
702 | - * |
|
703 | - * @param string $filepath |
|
704 | - */ |
|
705 | - public function set_main_plugin_file($filepath) |
|
706 | - { |
|
707 | - $this->_main_plugin_file = $filepath; |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * gets the filepath to teh main file |
|
712 | - * |
|
713 | - * @return string |
|
714 | - */ |
|
715 | - public function get_main_plugin_file() |
|
716 | - { |
|
717 | - return $this->_main_plugin_file; |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Gets the filename (no path) of the main file (the main file loaded |
|
722 | - * by WP) |
|
723 | - * |
|
724 | - * @return string |
|
725 | - */ |
|
726 | - public function get_main_plugin_file_basename() |
|
727 | - { |
|
728 | - return plugin_basename($this->get_main_plugin_file()); |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Gets the folder name which contains the main plugin file |
|
733 | - * |
|
734 | - * @return string |
|
735 | - */ |
|
736 | - public function get_main_plugin_file_dirname() |
|
737 | - { |
|
738 | - return dirname($this->get_main_plugin_file()); |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * sets hooks used in the admin |
|
744 | - * |
|
745 | - * @return void |
|
746 | - */ |
|
747 | - public function admin_init() |
|
748 | - { |
|
749 | - // is admin and not in M-Mode ? |
|
750 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
751 | - add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
752 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
753 | - } |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * plugin_actions |
|
759 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
760 | - * |
|
761 | - * @param $links |
|
762 | - * @param $file |
|
763 | - * @return array |
|
764 | - */ |
|
765 | - public function plugin_action_links($links, $file) |
|
766 | - { |
|
767 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
768 | - // before other links |
|
769 | - array_unshift( |
|
770 | - $links, |
|
771 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
772 | - . esc_html__('Settings', 'event_espresso') |
|
773 | - . '</a>' |
|
774 | - ); |
|
775 | - } |
|
776 | - return $links; |
|
777 | - } |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * after_plugin_row |
|
782 | - * Add additional content to the plugins page plugin row |
|
783 | - * Inserts another row |
|
784 | - * |
|
785 | - * @param $plugin_file |
|
786 | - * @param $plugin_data |
|
787 | - * @param $status |
|
788 | - * @return void |
|
789 | - */ |
|
790 | - public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
791 | - { |
|
792 | - $after_plugin_row = ''; |
|
793 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
794 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
795 | - $class = $status ? 'active' : 'inactive'; |
|
796 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
797 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
798 | - $description = isset($plugins_page_row['description']) |
|
799 | - ? $plugins_page_row['description'] |
|
800 | - : ''; |
|
801 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
802 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
803 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
804 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
805 | - $after_plugin_row .= '<style> |
|
397 | + EEH_Activation::initialize_db_content(); |
|
398 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
399 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
400 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
401 | + ); |
|
402 | + $rewrite_rules->flushRewriteRules(); |
|
403 | + // in case there are lots of addons being activated at once, let's force garbage collection |
|
404 | + // to help avoid memory limit errors |
|
405 | + // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
406 | + gc_collect_cycles(); |
|
407 | + } else { |
|
408 | + // ask the data migration manager to init this addon's data |
|
409 | + // when migrations are finished because we can't do it now |
|
410 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * Used to setup this addon's database tables, but not necessarily any default |
|
417 | + * data in them. The default is to actually use the most up-to-date data migration script |
|
418 | + * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
419 | + * methods to setup the db. |
|
420 | + */ |
|
421 | + public function initialize_db() |
|
422 | + { |
|
423 | + // find the migration script that sets the database to be compatible with the code |
|
424 | + $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
425 | + if ($current_dms_name) { |
|
426 | + $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
427 | + $current_data_migration_script->set_migrating(false); |
|
428 | + $current_data_migration_script->schema_changes_before_migration(); |
|
429 | + $current_data_migration_script->schema_changes_after_migration(); |
|
430 | + if ($current_data_migration_script->get_errors()) { |
|
431 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
432 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
433 | + } |
|
434 | + } |
|
435 | + } |
|
436 | + // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
437 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
438 | + array( |
|
439 | + 'slug' => $this->name(), |
|
440 | + 'version' => $this->version(), |
|
441 | + ) |
|
442 | + ); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * If you want to setup default data for the addon, override this method, and call |
|
448 | + * parent::initialize_default_data() from within it. This is normally called |
|
449 | + * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
450 | + * and should verify default data is present (but this is also called |
|
451 | + * on reactivations and just after migrations, so please verify you actually want |
|
452 | + * to ADD default data, because it may already be present). |
|
453 | + * However, please call this parent (currently it just fires a hook which other |
|
454 | + * addons may be depending on) |
|
455 | + */ |
|
456 | + public function initialize_default_data() |
|
457 | + { |
|
458 | + /** |
|
459 | + * Called when an addon is ensuring its default data is set (possibly called |
|
460 | + * on a reactivation, so first check for the absence of other data before setting |
|
461 | + * default data) |
|
462 | + * |
|
463 | + * @param EE_Addon $addon the addon that called this |
|
464 | + */ |
|
465 | + do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
466 | + // override to insert default data. It is safe to use the models here |
|
467 | + // because the site should not be in maintenance mode |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * EE Core detected that this addon has been upgraded. We should check if there |
|
473 | + * are any new migration scripts, and if so put the site into maintenance mode until |
|
474 | + * they're ran |
|
475 | + * |
|
476 | + * @return void |
|
477 | + */ |
|
478 | + public function upgrade() |
|
479 | + { |
|
480 | + $classname = get_class($this); |
|
481 | + do_action("AHEE__{$classname}__upgrade"); |
|
482 | + do_action('AHEE__EE_Addon__upgrade', $this); |
|
483 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
484 | + // also it's possible there is new default data that needs to be added |
|
485 | + add_action( |
|
486 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
487 | + array($this, 'initialize_db_if_no_migrations_required') |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
494 | + */ |
|
495 | + public function downgrade() |
|
496 | + { |
|
497 | + $classname = get_class($this); |
|
498 | + do_action("AHEE__{$classname}__downgrade"); |
|
499 | + do_action('AHEE__EE_Addon__downgrade', $this); |
|
500 | + // it's possible there's old default data that needs to be double-checked |
|
501 | + add_action( |
|
502 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
503 | + array($this, 'initialize_db_if_no_migrations_required') |
|
504 | + ); |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * set_db_update_option_name |
|
510 | + * Until we do something better, we'll just check for migration scripts upon |
|
511 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
512 | + * |
|
513 | + * @return bool |
|
514 | + */ |
|
515 | + public function set_db_update_option_name() |
|
516 | + { |
|
517 | + EE_Error::doing_it_wrong( |
|
518 | + __FUNCTION__, |
|
519 | + esc_html__( |
|
520 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
521 | + 'event_espresso' |
|
522 | + ), |
|
523 | + '4.3.0.alpha.016' |
|
524 | + ); |
|
525 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
526 | + return $this->set_activation_indicator_option(); |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * Returns the name of the activation indicator option |
|
532 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
533 | + * |
|
534 | + * @deprecated since version 4.3.0.alpha.016 |
|
535 | + * @return string |
|
536 | + */ |
|
537 | + public function get_db_update_option_name() |
|
538 | + { |
|
539 | + EE_Error::doing_it_wrong( |
|
540 | + __FUNCTION__, |
|
541 | + esc_html__( |
|
542 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
543 | + 'event_espresso' |
|
544 | + ), |
|
545 | + '4.3.0.alpha.016' |
|
546 | + ); |
|
547 | + return $this->get_activation_indicator_option_name(); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * When the addon is activated, this should be called to set a wordpress option that |
|
553 | + * indicates it was activated. This is especially useful for detecting reactivations. |
|
554 | + * |
|
555 | + * @return bool |
|
556 | + */ |
|
557 | + public function set_activation_indicator_option() |
|
558 | + { |
|
559 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
560 | + return update_option($this->get_activation_indicator_option_name(), true); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
566 | + * |
|
567 | + * @return string |
|
568 | + */ |
|
569 | + public function get_activation_indicator_option_name() |
|
570 | + { |
|
571 | + return 'ee_activation_' . $this->name(); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
577 | + * |
|
578 | + * @param int $req_type |
|
579 | + */ |
|
580 | + public function set_req_type($req_type) |
|
581 | + { |
|
582 | + $this->_req_type = $req_type; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
588 | + * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
589 | + * EE_System when it is checking for new install or upgrades of addons |
|
590 | + */ |
|
591 | + public function detect_req_type() |
|
592 | + { |
|
593 | + if (! $this->_req_type) { |
|
594 | + $this->detect_activation_or_upgrade(); |
|
595 | + } |
|
596 | + return $this->_req_type; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
602 | + * Should only be called once per request |
|
603 | + * |
|
604 | + * @return void |
|
605 | + */ |
|
606 | + public function detect_activation_or_upgrade() |
|
607 | + { |
|
608 | + $activation_history_for_addon = $this->get_activation_history(); |
|
609 | + $request_type = EE_System::detect_req_type_given_activation_history( |
|
610 | + $activation_history_for_addon, |
|
611 | + $this->get_activation_indicator_option_name(), |
|
612 | + $this->version() |
|
613 | + ); |
|
614 | + $this->set_req_type($request_type); |
|
615 | + $classname = get_class($this); |
|
616 | + switch ($request_type) { |
|
617 | + case EE_System::req_type_new_activation: |
|
618 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
619 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
620 | + $this->new_install(); |
|
621 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
622 | + break; |
|
623 | + case EE_System::req_type_reactivation: |
|
624 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
625 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
626 | + $this->reactivation(); |
|
627 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
628 | + break; |
|
629 | + case EE_System::req_type_upgrade: |
|
630 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
631 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
632 | + $this->upgrade(); |
|
633 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
634 | + break; |
|
635 | + case EE_System::req_type_downgrade: |
|
636 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
637 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
638 | + $this->downgrade(); |
|
639 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
640 | + break; |
|
641 | + case EE_System::req_type_normal: |
|
642 | + default: |
|
643 | + break; |
|
644 | + } |
|
645 | + |
|
646 | + do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * Updates the version history for this addon |
|
651 | + * |
|
652 | + * @param array $version_history |
|
653 | + * @param string $current_version_to_add |
|
654 | + * @return boolean success |
|
655 | + */ |
|
656 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
657 | + { |
|
658 | + if (! $version_history) { |
|
659 | + $version_history = $this->get_activation_history(); |
|
660 | + } |
|
661 | + if ($current_version_to_add === null) { |
|
662 | + $current_version_to_add = $this->version(); |
|
663 | + } |
|
664 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
665 | + // resave |
|
666 | + return update_option($this->get_activation_history_option_name(), $version_history); |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Gets the name of the wp option that stores the activation history |
|
671 | + * of this addon |
|
672 | + * |
|
673 | + * @return string |
|
674 | + */ |
|
675 | + public function get_activation_history_option_name() |
|
676 | + { |
|
677 | + return self::ee_addon_version_history_option_prefix . $this->name(); |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * Gets the wp option which stores the activation history for this addon |
|
683 | + * |
|
684 | + * @return array |
|
685 | + */ |
|
686 | + public function get_activation_history() |
|
687 | + { |
|
688 | + return get_option($this->get_activation_history_option_name(), null); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * @param string $config_section |
|
694 | + */ |
|
695 | + public function set_config_section($config_section = '') |
|
696 | + { |
|
697 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Sets the filepath to the main plugin file |
|
702 | + * |
|
703 | + * @param string $filepath |
|
704 | + */ |
|
705 | + public function set_main_plugin_file($filepath) |
|
706 | + { |
|
707 | + $this->_main_plugin_file = $filepath; |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * gets the filepath to teh main file |
|
712 | + * |
|
713 | + * @return string |
|
714 | + */ |
|
715 | + public function get_main_plugin_file() |
|
716 | + { |
|
717 | + return $this->_main_plugin_file; |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Gets the filename (no path) of the main file (the main file loaded |
|
722 | + * by WP) |
|
723 | + * |
|
724 | + * @return string |
|
725 | + */ |
|
726 | + public function get_main_plugin_file_basename() |
|
727 | + { |
|
728 | + return plugin_basename($this->get_main_plugin_file()); |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Gets the folder name which contains the main plugin file |
|
733 | + * |
|
734 | + * @return string |
|
735 | + */ |
|
736 | + public function get_main_plugin_file_dirname() |
|
737 | + { |
|
738 | + return dirname($this->get_main_plugin_file()); |
|
739 | + } |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * sets hooks used in the admin |
|
744 | + * |
|
745 | + * @return void |
|
746 | + */ |
|
747 | + public function admin_init() |
|
748 | + { |
|
749 | + // is admin and not in M-Mode ? |
|
750 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
751 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
752 | + add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
753 | + } |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * plugin_actions |
|
759 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
760 | + * |
|
761 | + * @param $links |
|
762 | + * @param $file |
|
763 | + * @return array |
|
764 | + */ |
|
765 | + public function plugin_action_links($links, $file) |
|
766 | + { |
|
767 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
768 | + // before other links |
|
769 | + array_unshift( |
|
770 | + $links, |
|
771 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
772 | + . esc_html__('Settings', 'event_espresso') |
|
773 | + . '</a>' |
|
774 | + ); |
|
775 | + } |
|
776 | + return $links; |
|
777 | + } |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * after_plugin_row |
|
782 | + * Add additional content to the plugins page plugin row |
|
783 | + * Inserts another row |
|
784 | + * |
|
785 | + * @param $plugin_file |
|
786 | + * @param $plugin_data |
|
787 | + * @param $status |
|
788 | + * @return void |
|
789 | + */ |
|
790 | + public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
791 | + { |
|
792 | + $after_plugin_row = ''; |
|
793 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
794 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
795 | + $class = $status ? 'active' : 'inactive'; |
|
796 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
797 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
798 | + $description = isset($plugins_page_row['description']) |
|
799 | + ? $plugins_page_row['description'] |
|
800 | + : ''; |
|
801 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
802 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
803 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
804 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
805 | + $after_plugin_row .= '<style> |
|
806 | 806 | .ee-button, |
807 | 807 | .ee-button:active, |
808 | 808 | .ee-button:visited { |
@@ -839,49 +839,49 @@ discard block |
||
839 | 839 | } |
840 | 840 | .ee-button:active { top:0; } |
841 | 841 | </style>'; |
842 | - $after_plugin_row .= ' |
|
842 | + $after_plugin_row .= ' |
|
843 | 843 | <p class="ee-addon-upsell-info-dv"> |
844 | 844 | <a class="ee-button" href="' . $link_url . '">' |
845 | - . $link_text |
|
846 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
847 | - . '</a> |
|
845 | + . $link_text |
|
846 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
847 | + . '</a> |
|
848 | 848 | </p>'; |
849 | - $after_plugin_row .= '</td>'; |
|
850 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
851 | - $after_plugin_row .= $description; |
|
852 | - $after_plugin_row .= '</td>'; |
|
853 | - $after_plugin_row .= '</tr>'; |
|
854 | - } else { |
|
855 | - $after_plugin_row .= $description; |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - echo $after_plugin_row; |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
865 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
866 | - * for back compat reasons. |
|
867 | - * |
|
868 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
869 | - * |
|
870 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
871 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
872 | - * callback does not get run/set in that request. |
|
873 | - * |
|
874 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
875 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
876 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
877 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
878 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
879 | - * to call `parent::deactivation`. |
|
880 | - * |
|
881 | - * @since 4.9.26 |
|
882 | - */ |
|
883 | - public function after_registration() |
|
884 | - { |
|
885 | - // cricket chirp... cricket chirp... |
|
886 | - } |
|
849 | + $after_plugin_row .= '</td>'; |
|
850 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
851 | + $after_plugin_row .= $description; |
|
852 | + $after_plugin_row .= '</td>'; |
|
853 | + $after_plugin_row .= '</tr>'; |
|
854 | + } else { |
|
855 | + $after_plugin_row .= $description; |
|
856 | + } |
|
857 | + } |
|
858 | + |
|
859 | + echo $after_plugin_row; |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
865 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
866 | + * for back compat reasons. |
|
867 | + * |
|
868 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
869 | + * |
|
870 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
871 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
872 | + * callback does not get run/set in that request. |
|
873 | + * |
|
874 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
875 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
876 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
877 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
878 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
879 | + * to call `parent::deactivation`. |
|
880 | + * |
|
881 | + * @since 4.9.26 |
|
882 | + */ |
|
883 | + public function after_registration() |
|
884 | + { |
|
885 | + // cricket chirp... cricket chirp... |
|
886 | + } |
|
887 | 887 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | public function set_plugins_page_row($plugins_page_row = array()) |
292 | 292 | { |
293 | 293 | // sigh.... check for example content that I stupidly merged to master and remove it if found |
294 | - if (! is_array($plugins_page_row) |
|
294 | + if ( ! is_array($plugins_page_row) |
|
295 | 295 | && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
296 | 296 | ) { |
297 | 297 | $plugins_page_row = array(); |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | */ |
569 | 569 | public function get_activation_indicator_option_name() |
570 | 570 | { |
571 | - return 'ee_activation_' . $this->name(); |
|
571 | + return 'ee_activation_'.$this->name(); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function detect_req_type() |
592 | 592 | { |
593 | - if (! $this->_req_type) { |
|
593 | + if ( ! $this->_req_type) { |
|
594 | 594 | $this->detect_activation_or_upgrade(); |
595 | 595 | } |
596 | 596 | return $this->_req_type; |
@@ -655,13 +655,13 @@ discard block |
||
655 | 655 | */ |
656 | 656 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
657 | 657 | { |
658 | - if (! $version_history) { |
|
658 | + if ( ! $version_history) { |
|
659 | 659 | $version_history = $this->get_activation_history(); |
660 | 660 | } |
661 | 661 | if ($current_version_to_add === null) { |
662 | 662 | $current_version_to_add = $this->version(); |
663 | 663 | } |
664 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
664 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
665 | 665 | // resave |
666 | 666 | return update_option($this->get_activation_history_option_name(), $version_history); |
667 | 667 | } |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | */ |
675 | 675 | public function get_activation_history_option_name() |
676 | 676 | { |
677 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
677 | + return self::ee_addon_version_history_option_prefix.$this->name(); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | // is admin and not in M-Mode ? |
750 | 750 | if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
751 | 751 | add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
752 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
752 | + add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | // before other links |
769 | 769 | array_unshift( |
770 | 770 | $links, |
771 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
771 | + '<a href="admin.php?page='.$this->plugin_action_slug().'">' |
|
772 | 772 | . esc_html__('Settings', 'event_espresso') |
773 | 773 | . '</a>' |
774 | 774 | ); |
@@ -791,15 +791,15 @@ discard block |
||
791 | 791 | { |
792 | 792 | $after_plugin_row = ''; |
793 | 793 | $plugins_page_row = $this->get_plugins_page_row(); |
794 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
794 | + if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
795 | 795 | $class = $status ? 'active' : 'inactive'; |
796 | 796 | $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
797 | 797 | $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
798 | 798 | $description = isset($plugins_page_row['description']) |
799 | 799 | ? $plugins_page_row['description'] |
800 | 800 | : ''; |
801 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
802 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
801 | + if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
802 | + $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">'; |
|
803 | 803 | $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
804 | 804 | $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
805 | 805 | $after_plugin_row .= '<style> |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | </style>'; |
842 | 842 | $after_plugin_row .= ' |
843 | 843 | <p class="ee-addon-upsell-info-dv"> |
844 | - <a class="ee-button" href="' . $link_url . '">' |
|
844 | + <a class="ee-button" href="' . $link_url.'">' |
|
845 | 845 | . $link_text |
846 | 846 | . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
847 | 847 | . '</a> |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <div id="espresso-ajax-loading" style="display:none;"> |
2 | 2 | <span class="ee-spinner ee-spin"></span><span style="display:none;"> |
3 | 3 | <?php _e( |
4 | - 'loading...', |
|
5 | - 'event_espresso' |
|
6 | - ); ?></span> |
|
4 | + 'loading...', |
|
5 | + 'event_espresso' |
|
6 | + ); ?></span> |
|
7 | 7 | </div> |
8 | 8 | |
9 | 9 | <div id="espresso-ajax-notices"> |