@@ -27,186 +27,186 @@ |
||
27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
28 | 28 | { |
29 | 29 | |
30 | - public function __construct() |
|
31 | - { |
|
32 | - global $wpdb; |
|
33 | - $this->_pretty_name = esc_html__('Check-ins', 'event_espresso'); |
|
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | - $this->select_expression = 'att.*, e.event_status'; |
|
36 | - $this->_extra_where_sql = 'AS att |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + global $wpdb; |
|
33 | + $this->_pretty_name = esc_html__('Check-ins', 'event_espresso'); |
|
34 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | + $this->select_expression = 'att.*, e.event_status'; |
|
36 | + $this->_extra_where_sql = 'AS att |
|
37 | 37 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | - parent::__construct(); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @throws EE_Error |
|
46 | - */ |
|
47 | - protected function _migrate_old_row($old_row) |
|
48 | - { |
|
49 | - global $wpdb; |
|
50 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
51 | - |
|
52 | - $num_to_checkin_at_this_time = max([intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])]); |
|
53 | - |
|
54 | - $new_registrations_for_attendee = |
|
55 | - $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
56 | - if (! $new_registrations_for_attendee) { |
|
57 | - $new_registrations_for_attendee = []; |
|
58 | - } |
|
59 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
60 | - |
|
61 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
62 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
63 | - $new_checkin_ids = []; |
|
64 | - for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
65 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
66 | - if (! $new_reg_id) { |
|
67 | - $this->add_error( |
|
68 | - sprintf( |
|
69 | - esc_html__( |
|
70 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check in |
|
39 | + $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | + parent::__construct(); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @throws EE_Error |
|
46 | + */ |
|
47 | + protected function _migrate_old_row($old_row) |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
51 | + |
|
52 | + $num_to_checkin_at_this_time = max([intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])]); |
|
53 | + |
|
54 | + $new_registrations_for_attendee = |
|
55 | + $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
56 | + if (! $new_registrations_for_attendee) { |
|
57 | + $new_registrations_for_attendee = []; |
|
58 | + } |
|
59 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
60 | + |
|
61 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
62 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
63 | + $new_checkin_ids = []; |
|
64 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
65 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
66 | + if (! $new_reg_id) { |
|
67 | + $this->add_error( |
|
68 | + sprintf( |
|
69 | + esc_html__( |
|
70 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check in |
|
71 | 71 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
72 | 72 | */ |
73 | - // @codingStandardsIgnoreStart |
|
74 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
75 | - // @codingStandardsIgnoreEnd |
|
76 | - 'event_espresso' |
|
77 | - ), |
|
78 | - $this->_json_encode($old_row), |
|
79 | - abs($num_to_checkin_at_this_time), |
|
80 | - count($new_registrations_for_attendee), |
|
81 | - $this->_json_encode($new_registrations_for_attendee) |
|
82 | - ) |
|
83 | - ); |
|
84 | - break; |
|
85 | - } |
|
86 | - $existing_checkin_record = $wpdb->get_var( |
|
87 | - $wpdb->prepare( |
|
88 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
89 | - $new_reg_id |
|
90 | - ) |
|
91 | - ); |
|
92 | - if (! $existing_checkin_record) { |
|
93 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
94 | - if ($new_id) { |
|
95 | - $new_checkin_ids[] = $new_id; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - if ($new_checkin_ids) { |
|
100 | - $this->get_migration_script()->set_mapping( |
|
101 | - $this->_old_table, |
|
102 | - $old_row['id'], |
|
103 | - $this->_new_table, |
|
104 | - $new_checkin_ids |
|
105 | - ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
112 | - * (because we know the attendee was for an event as a specific time, and we know |
|
113 | - * the event's OLD ID...) |
|
114 | - * |
|
115 | - * @param array $old_attendee |
|
116 | - * @return array row of datetime from DB |
|
117 | - * @throws EE_Error |
|
118 | - * @global wpdb $wpdb |
|
119 | - */ |
|
120 | - private function _try_to_find_datetime(array $old_attendee): array |
|
121 | - { |
|
122 | - global $wpdb; |
|
123 | - |
|
124 | - $new_event_id = |
|
125 | - $this->get_migration_script()->get_mapping_new_pk( |
|
126 | - $wpdb->prefix . "events_detail", |
|
127 | - $old_attendee['event_id'], |
|
128 | - $wpdb->posts |
|
129 | - ); |
|
130 | - if (! $new_event_id) { |
|
131 | - $this->add_error( |
|
132 | - sprintf( |
|
133 | - esc_html__( |
|
134 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
135 | - // @codingStandardsIgnoreStart |
|
136 | - 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
137 | - // @codingStandardsIgnoreEnd |
|
138 | - 'event_espresso' |
|
139 | - ), |
|
140 | - $old_attendee['event_id'], |
|
141 | - $this->_json_encode($old_attendee) |
|
142 | - ) |
|
143 | - ); |
|
144 | - return []; |
|
145 | - } |
|
146 | - $old_att_start_date = $old_attendee['start_date']; |
|
147 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
148 | - $old_att_datetime = |
|
149 | - $this->get_migration_script()->convert_date_string_to_utc( |
|
150 | - $this, |
|
151 | - $old_attendee, |
|
152 | - "$old_att_start_date $old_att_start_time:00" |
|
153 | - ); |
|
154 | - |
|
155 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
156 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
157 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
158 | - $conditions = [ |
|
159 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
160 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
161 | - ]; |
|
162 | - // start running queries, widening search each time by removing a condition |
|
163 | - do { |
|
164 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
165 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
166 | - array_shift($conditions); |
|
167 | - } while (! $datetime_found && $conditions); |
|
168 | - return $datetime_found; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Adds a new Check-in/checkout record according to $new_reg_id,$new_datetime_id,$checking_in, and $timestamp |
|
174 | - * |
|
175 | - * @param int $new_reg_id |
|
176 | - * @param array $new_datetime |
|
177 | - * @return int new Check-in id |
|
178 | - */ |
|
179 | - private function _insert_checkin_record(int $new_reg_id, array $new_datetime): int |
|
180 | - { |
|
181 | - global $wpdb; |
|
182 | - |
|
183 | - |
|
184 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
185 | - $cols_n_values = [ |
|
186 | - 'REG_ID' => $new_reg_id, |
|
187 | - 'DTT_ID' => $new_datetime['DTT_ID'] ?? 0, |
|
188 | - 'CHK_in' => true, |
|
189 | - 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] ?? null, |
|
190 | - ]; |
|
191 | - $data_types = [ |
|
192 | - '%d',// REG_ID |
|
193 | - '%d',// DTT_ID |
|
194 | - '%d',// CHK_in |
|
195 | - '%s',// CHK_timestamp |
|
196 | - ]; |
|
197 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | - if (! $success) { |
|
199 | - $this->add_error( |
|
200 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
201 | - $this->_old_table, |
|
202 | - [], |
|
203 | - $this->_new_table, |
|
204 | - $cols_n_values, |
|
205 | - $data_types |
|
206 | - ) |
|
207 | - ); |
|
208 | - return 0; |
|
209 | - } |
|
210 | - return $wpdb->insert_id; |
|
211 | - } |
|
73 | + // @codingStandardsIgnoreStart |
|
74 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
75 | + // @codingStandardsIgnoreEnd |
|
76 | + 'event_espresso' |
|
77 | + ), |
|
78 | + $this->_json_encode($old_row), |
|
79 | + abs($num_to_checkin_at_this_time), |
|
80 | + count($new_registrations_for_attendee), |
|
81 | + $this->_json_encode($new_registrations_for_attendee) |
|
82 | + ) |
|
83 | + ); |
|
84 | + break; |
|
85 | + } |
|
86 | + $existing_checkin_record = $wpdb->get_var( |
|
87 | + $wpdb->prepare( |
|
88 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
89 | + $new_reg_id |
|
90 | + ) |
|
91 | + ); |
|
92 | + if (! $existing_checkin_record) { |
|
93 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
94 | + if ($new_id) { |
|
95 | + $new_checkin_ids[] = $new_id; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + if ($new_checkin_ids) { |
|
100 | + $this->get_migration_script()->set_mapping( |
|
101 | + $this->_old_table, |
|
102 | + $old_row['id'], |
|
103 | + $this->_new_table, |
|
104 | + $new_checkin_ids |
|
105 | + ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
112 | + * (because we know the attendee was for an event as a specific time, and we know |
|
113 | + * the event's OLD ID...) |
|
114 | + * |
|
115 | + * @param array $old_attendee |
|
116 | + * @return array row of datetime from DB |
|
117 | + * @throws EE_Error |
|
118 | + * @global wpdb $wpdb |
|
119 | + */ |
|
120 | + private function _try_to_find_datetime(array $old_attendee): array |
|
121 | + { |
|
122 | + global $wpdb; |
|
123 | + |
|
124 | + $new_event_id = |
|
125 | + $this->get_migration_script()->get_mapping_new_pk( |
|
126 | + $wpdb->prefix . "events_detail", |
|
127 | + $old_attendee['event_id'], |
|
128 | + $wpdb->posts |
|
129 | + ); |
|
130 | + if (! $new_event_id) { |
|
131 | + $this->add_error( |
|
132 | + sprintf( |
|
133 | + esc_html__( |
|
134 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
135 | + // @codingStandardsIgnoreStart |
|
136 | + 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
137 | + // @codingStandardsIgnoreEnd |
|
138 | + 'event_espresso' |
|
139 | + ), |
|
140 | + $old_attendee['event_id'], |
|
141 | + $this->_json_encode($old_attendee) |
|
142 | + ) |
|
143 | + ); |
|
144 | + return []; |
|
145 | + } |
|
146 | + $old_att_start_date = $old_attendee['start_date']; |
|
147 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
148 | + $old_att_datetime = |
|
149 | + $this->get_migration_script()->convert_date_string_to_utc( |
|
150 | + $this, |
|
151 | + $old_attendee, |
|
152 | + "$old_att_start_date $old_att_start_time:00" |
|
153 | + ); |
|
154 | + |
|
155 | + $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
156 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
157 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
158 | + $conditions = [ |
|
159 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
160 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
161 | + ]; |
|
162 | + // start running queries, widening search each time by removing a condition |
|
163 | + do { |
|
164 | + $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
165 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
166 | + array_shift($conditions); |
|
167 | + } while (! $datetime_found && $conditions); |
|
168 | + return $datetime_found; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Adds a new Check-in/checkout record according to $new_reg_id,$new_datetime_id,$checking_in, and $timestamp |
|
174 | + * |
|
175 | + * @param int $new_reg_id |
|
176 | + * @param array $new_datetime |
|
177 | + * @return int new Check-in id |
|
178 | + */ |
|
179 | + private function _insert_checkin_record(int $new_reg_id, array $new_datetime): int |
|
180 | + { |
|
181 | + global $wpdb; |
|
182 | + |
|
183 | + |
|
184 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
185 | + $cols_n_values = [ |
|
186 | + 'REG_ID' => $new_reg_id, |
|
187 | + 'DTT_ID' => $new_datetime['DTT_ID'] ?? 0, |
|
188 | + 'CHK_in' => true, |
|
189 | + 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] ?? null, |
|
190 | + ]; |
|
191 | + $data_types = [ |
|
192 | + '%d',// REG_ID |
|
193 | + '%d',// DTT_ID |
|
194 | + '%d',// CHK_in |
|
195 | + '%s',// CHK_timestamp |
|
196 | + ]; |
|
197 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | + if (! $success) { |
|
199 | + $this->add_error( |
|
200 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
201 | + $this->_old_table, |
|
202 | + [], |
|
203 | + $this->_new_table, |
|
204 | + $cols_n_values, |
|
205 | + $data_types |
|
206 | + ) |
|
207 | + ); |
|
208 | + return 0; |
|
209 | + } |
|
210 | + return $wpdb->insert_id; |
|
211 | + } |
|
212 | 212 | } |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | { |
32 | 32 | global $wpdb; |
33 | 33 | $this->_pretty_name = esc_html__('Check-ins', 'event_espresso'); |
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
35 | 35 | $this->select_expression = 'att.*, e.event_status'; |
36 | 36 | $this->_extra_where_sql = 'AS att |
37 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
37 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
39 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
40 | 40 | parent::__construct(); |
41 | 41 | } |
42 | 42 | |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | protected function _migrate_old_row($old_row) |
48 | 48 | { |
49 | 49 | global $wpdb; |
50 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
50 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
51 | 51 | |
52 | 52 | $num_to_checkin_at_this_time = max([intval($old_row['checked_in_quantity']), intval($old_row['checked_in'])]); |
53 | 53 | |
54 | 54 | $new_registrations_for_attendee = |
55 | 55 | $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
56 | - if (! $new_registrations_for_attendee) { |
|
56 | + if ( ! $new_registrations_for_attendee) { |
|
57 | 57 | $new_registrations_for_attendee = []; |
58 | 58 | } |
59 | 59 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
63 | 63 | $new_checkin_ids = []; |
64 | 64 | for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
65 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
66 | - if (! $new_reg_id) { |
|
65 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
66 | + if ( ! $new_reg_id) { |
|
67 | 67 | $this->add_error( |
68 | 68 | sprintf( |
69 | 69 | esc_html__( |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $new_reg_id |
90 | 90 | ) |
91 | 91 | ); |
92 | - if (! $existing_checkin_record) { |
|
92 | + if ( ! $existing_checkin_record) { |
|
93 | 93 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
94 | 94 | if ($new_id) { |
95 | 95 | $new_checkin_ids[] = $new_id; |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | |
124 | 124 | $new_event_id = |
125 | 125 | $this->get_migration_script()->get_mapping_new_pk( |
126 | - $wpdb->prefix . "events_detail", |
|
126 | + $wpdb->prefix."events_detail", |
|
127 | 127 | $old_attendee['event_id'], |
128 | 128 | $wpdb->posts |
129 | 129 | ); |
130 | - if (! $new_event_id) { |
|
130 | + if ( ! $new_event_id) { |
|
131 | 131 | $this->add_error( |
132 | 132 | sprintf( |
133 | 133 | esc_html__( |
@@ -152,19 +152,19 @@ discard block |
||
152 | 152 | "$old_att_start_date $old_att_start_time:00" |
153 | 153 | ); |
154 | 154 | |
155 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
155 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
156 | 156 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
157 | 157 | // the most important condition should be last, as it will be array_shift'ed off last |
158 | 158 | $conditions = [ |
159 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
160 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
159 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
160 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
161 | 161 | ]; |
162 | 162 | // start running queries, widening search each time by removing a condition |
163 | 163 | do { |
164 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
164 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
165 | 165 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
166 | 166 | array_shift($conditions); |
167 | - } while (! $datetime_found && $conditions); |
|
167 | + }while ( ! $datetime_found && $conditions); |
|
168 | 168 | return $datetime_found; |
169 | 169 | } |
170 | 170 | |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | 'CHK_in' => true, |
189 | 189 | 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] ?? null, |
190 | 190 | ]; |
191 | - $data_types = [ |
|
192 | - '%d',// REG_ID |
|
193 | - '%d',// DTT_ID |
|
194 | - '%d',// CHK_in |
|
195 | - '%s',// CHK_timestamp |
|
191 | + $data_types = [ |
|
192 | + '%d', // REG_ID |
|
193 | + '%d', // DTT_ID |
|
194 | + '%d', // CHK_in |
|
195 | + '%s', // CHK_timestamp |
|
196 | 196 | ]; |
197 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | - if (! $success) { |
|
197 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $data_types); |
|
198 | + if ( ! $success) { |
|
199 | 199 | $this->add_error( |
200 | 200 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
201 | 201 | $this->_old_table, |
@@ -19,517 +19,517 @@ |
||
19 | 19 | */ |
20 | 20 | final class EE_Front_Controller |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $_template_path; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - private $_template; |
|
31 | - |
|
32 | - /** |
|
33 | - * @type EE_Registry |
|
34 | - */ |
|
35 | - protected $Registry; |
|
36 | - |
|
37 | - /** |
|
38 | - * @type EE_Request_Handler |
|
39 | - */ |
|
40 | - protected $Request_Handler; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_Module_Request_Router |
|
44 | - */ |
|
45 | - protected $Module_Request_Router; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type CurrentPage |
|
49 | - */ |
|
50 | - protected $current_page; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * class constructor |
|
55 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * @param EE_Registry $Registry |
|
59 | - * @param CurrentPage $EspressoPage |
|
60 | - * @param EE_Module_Request_Router $Module_Request_Router |
|
61 | - */ |
|
62 | - public function __construct( |
|
63 | - EE_Registry $Registry, |
|
64 | - CurrentPage $EspressoPage, |
|
65 | - EE_Module_Request_Router $Module_Request_Router |
|
66 | - ) { |
|
67 | - $this->Registry = $Registry; |
|
68 | - $this->current_page = $EspressoPage; |
|
69 | - $this->Module_Request_Router = $Module_Request_Router; |
|
70 | - // load other resources and begin to actually run shortcodes and modules |
|
71 | - // analyse the incoming WP request |
|
72 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
73 | - // process request with module factory |
|
74 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
75 | - // before headers sent |
|
76 | - add_action('wp', array($this, 'wp'), 5); |
|
77 | - // primarily used to process any content shortcodes |
|
78 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
79 | - // header |
|
80 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
81 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
82 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
83 | - // display errors |
|
84 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
85 | - // the content |
|
86 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
87 | - // exclude our private cpt comments |
|
88 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
89 | - // make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
90 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
91 | - // action hook EE |
|
92 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return EE_Request_Handler |
|
98 | - * @deprecated 4.10.14.p |
|
99 | - */ |
|
100 | - public function Request_Handler() |
|
101 | - { |
|
102 | - if (! $this->Request_Handler instanceof EE_Request_Handler) { |
|
103 | - $this->Request_Handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler'); |
|
104 | - } |
|
105 | - return $this->Request_Handler; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return EE_Module_Request_Router |
|
111 | - */ |
|
112 | - public function Module_Request_Router() |
|
113 | - { |
|
114 | - return $this->Module_Request_Router; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return LegacyShortcodesManager |
|
120 | - * @deprecated 4.10.14.p |
|
121 | - */ |
|
122 | - public function getLegacyShortcodesManager() |
|
123 | - { |
|
124 | - return EE_Config::getLegacyShortcodesManager(); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
132 | - /** |
|
133 | - * filter_wp_comments |
|
134 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
135 | - * widgets/queries done on frontend |
|
136 | - * |
|
137 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
138 | - * @return array array of comment clauses with modifications. |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - public function filter_wp_comments($clauses) |
|
144 | - { |
|
145 | - global $wpdb; |
|
146 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
147 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
148 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
149 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
150 | - ); |
|
151 | - $cpts = $custom_post_types->getPrivateCustomPostTypes(); |
|
152 | - foreach ($cpts as $cpt => $details) { |
|
153 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
154 | - } |
|
155 | - } |
|
156 | - return $clauses; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
162 | - * |
|
163 | - * @param string $url incoming url |
|
164 | - * @return string final assembled url |
|
165 | - */ |
|
166 | - public function maybe_force_admin_ajax_ssl($url) |
|
167 | - { |
|
168 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
169 | - $url = str_replace('http://', 'https://', $url); |
|
170 | - } |
|
171 | - return $url; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
184 | - * default priority init phases have run |
|
185 | - * |
|
186 | - * @access public |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function wp_loaded() |
|
190 | - { |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
198 | - /** |
|
199 | - * _get_request |
|
200 | - * |
|
201 | - * @access public |
|
202 | - * @param WP $WP |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function get_request(WP $WP) |
|
206 | - { |
|
207 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
208 | - $this->current_page->parseQueryVars($WP); |
|
209 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
210 | - remove_action('parse_request', [$this, 'get_request'], 1); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @param WP_Query $WP_Query |
|
219 | - * @return void |
|
220 | - * @throws EE_Error |
|
221 | - * @throws ReflectionException |
|
222 | - */ |
|
223 | - public function pre_get_posts($WP_Query) |
|
224 | - { |
|
225 | - // only load Module_Request_Router if this is the main query |
|
226 | - if ( |
|
227 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
228 | - && $WP_Query->is_main_query() |
|
229 | - ) { |
|
230 | - // cycle thru module routes |
|
231 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
232 | - // determine module and method for route |
|
233 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
234 | - if ($module instanceof EED_Module) { |
|
235 | - // get registered view for route |
|
236 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
237 | - // grab module name |
|
238 | - $module_name = $module->module_name(); |
|
239 | - // map the module to the module objects |
|
240 | - $this->Registry->modules->{$module_name} = $module; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /*********************************************** WP HOOK ***********************************************/ |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * wp - basically last chance to do stuff before headers sent |
|
255 | - * |
|
256 | - * @access public |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function wp() |
|
260 | - { |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * callback for the "template_redirect" hook point |
|
270 | - * checks sidebars for EE widgets |
|
271 | - * loads resources and assets accordingly |
|
272 | - * |
|
273 | - * @return void |
|
274 | - */ |
|
275 | - public function templateRedirect() |
|
276 | - { |
|
277 | - global $wp_query; |
|
278 | - if (empty($wp_query->posts)) { |
|
279 | - return; |
|
280 | - } |
|
281 | - // if we already know this is an espresso page, then load assets |
|
282 | - $load_assets = $this->current_page->isEspressoPage(); |
|
283 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
284 | - $load_assets = $load_assets || $this->espresso_widgets_in_active_sidebars(); |
|
285 | - if ($load_assets) { |
|
286 | - add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
287 | - add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'), 10); |
|
288 | - } |
|
289 | - |
|
290 | - if (is_singular(EspressoPostType::EVENTS)) { |
|
291 | - new FilterNextPreviousEventPostQuery(); |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * builds list of active widgets then scans active sidebars looking for them |
|
298 | - * returns true is an EE widget is found in an active sidebar |
|
299 | - * Please Note: this does NOT mean that the sidebar or widget |
|
300 | - * is actually in use in a given template, as that is unfortunately not known |
|
301 | - * until a sidebar and it's widgets are actually loaded |
|
302 | - * |
|
303 | - * @return boolean |
|
304 | - */ |
|
305 | - private function espresso_widgets_in_active_sidebars() |
|
306 | - { |
|
307 | - $espresso_widgets = array(); |
|
308 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
309 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
310 | - if (is_active_widget(false, false, $id_base)) { |
|
311 | - $espresso_widgets[] = $id_base; |
|
312 | - } |
|
313 | - } |
|
314 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
315 | - foreach ($all_sidebar_widgets as $sidebar_widgets) { |
|
316 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
317 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
318 | - foreach ($espresso_widgets as $espresso_widget) { |
|
319 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
320 | - return true; |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - return false; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * header_meta_tag |
|
332 | - * |
|
333 | - * @access public |
|
334 | - * @return void |
|
335 | - */ |
|
336 | - public function header_meta_tag() |
|
337 | - { |
|
338 | - print( |
|
339 | - apply_filters( |
|
340 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
341 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n" |
|
342 | - ) |
|
343 | - ); |
|
344 | - |
|
345 | - // let's exclude all event type taxonomy term archive pages from search engine indexing |
|
346 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
347 | - // also exclude all critical pages from indexing |
|
348 | - if ( |
|
349 | - ( |
|
350 | - is_tax('espresso_event_type') |
|
351 | - && get_option('blog_public') !== '0' |
|
352 | - ) |
|
353 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
354 | - ) { |
|
355 | - print( |
|
356 | - apply_filters( |
|
357 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
358 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
359 | - ) |
|
360 | - ); |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * wp_print_scripts |
|
367 | - * |
|
368 | - * @return void |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - public function wp_print_scripts() |
|
372 | - { |
|
373 | - global $post; |
|
374 | - if ( |
|
375 | - isset($post->EE_Event) |
|
376 | - && $post->EE_Event instanceof EE_Event |
|
377 | - && get_post_type() === EspressoPostType::EVENTS |
|
378 | - && is_singular() |
|
379 | - ) { |
|
380 | - EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - public function enqueueStyle() |
|
386 | - { |
|
387 | - wp_enqueue_style('espresso_default'); |
|
388 | - wp_enqueue_style('espresso_custom_css'); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
394 | - |
|
395 | - |
|
396 | - public function enqueueScripts() |
|
397 | - { |
|
398 | - wp_enqueue_script('espresso_core'); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * display_errors |
|
404 | - * |
|
405 | - * @access public |
|
406 | - * @return void |
|
407 | - * @throws DomainException |
|
408 | - */ |
|
409 | - public function display_errors() |
|
410 | - { |
|
411 | - static $shown_already = false; |
|
412 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
413 | - if ( |
|
414 | - ! $shown_already |
|
415 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
416 | - && is_main_query() |
|
417 | - && ! is_feed() |
|
418 | - && in_the_loop() |
|
419 | - && $this->current_page->isEspressoPage() |
|
420 | - ) { |
|
421 | - $shown_already = true; |
|
422 | - if (did_action('wp_head')) { |
|
423 | - echo wp_kses($this->printNotices(), AllowedTags::getAllowedTags()); |
|
424 | - } else { |
|
425 | - // block enabled themes run their query loop before headers are sent |
|
426 | - // so we need to add our notices onto the beginning of the content |
|
427 | - add_filter('the_content', [$this, 'prependNotices'], 1, 1); |
|
428 | - } |
|
429 | - } |
|
430 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @param string $the_content |
|
436 | - * @return string |
|
437 | - * @since 4.10.30.p |
|
438 | - */ |
|
439 | - public function prependNotices($the_content) |
|
440 | - { |
|
441 | - $notices = $this->printNotices(); |
|
442 | - return $notices ? $notices . $the_content : $the_content; |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * @return false|string |
|
448 | - * @since 4.10.30.p |
|
449 | - */ |
|
450 | - public function printNotices() |
|
451 | - { |
|
452 | - ob_start(); |
|
453 | - echo wp_kses(EE_Error::get_notices(), AllowedTags::getWithFormTags()); |
|
454 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
455 | - return ob_get_clean(); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - |
|
460 | - /*********************************************** UTILITIES ***********************************************/ |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * @param string $template_include_path |
|
465 | - * @return string |
|
466 | - * @throws EE_Error |
|
467 | - * @throws ReflectionException |
|
468 | - */ |
|
469 | - public function template_include($template_include_path = null) |
|
470 | - { |
|
471 | - if ($this->current_page->isEspressoPage()) { |
|
472 | - // despite all helpers having autoloaders set, we need to manually load the template loader |
|
473 | - // because there are some side effects in that class for triggering template tag functions |
|
474 | - $this->Registry->load_helper('EEH_Template'); |
|
475 | - $this->_template_path = ! empty($this->_template_path) |
|
476 | - ? basename($this->_template_path) |
|
477 | - : basename( |
|
478 | - $template_include_path |
|
479 | - ); |
|
480 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
481 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
482 | - $this->_template = basename($this->_template_path); |
|
483 | - return $this->_template_path; |
|
484 | - } |
|
485 | - return $template_include_path; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @param bool $with_path |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_selected_template($with_path = false) |
|
494 | - { |
|
495 | - return $with_path ? $this->_template_path : $this->_template; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * @param string $shortcode_class |
|
501 | - * @param WP $wp |
|
502 | - * @throws ReflectionException |
|
503 | - * @deprecated 4.9.26 |
|
504 | - */ |
|
505 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
506 | - { |
|
507 | - EE_Error::doing_it_wrong( |
|
508 | - __METHOD__, |
|
509 | - esc_html__( |
|
510 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
511 | - 'event_espresso' |
|
512 | - ), |
|
513 | - '4.9.26' |
|
514 | - ); |
|
515 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * @return void |
|
521 | - * @deprecated 4.9.57.p |
|
522 | - */ |
|
523 | - public function loadPersistentAdminNoticeManager() |
|
524 | - { |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * @return void |
|
530 | - * @deprecated 4.9.64.p |
|
531 | - */ |
|
532 | - public function employ_CPT_Strategy() |
|
533 | - { |
|
534 | - } |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $_template_path; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + private $_template; |
|
31 | + |
|
32 | + /** |
|
33 | + * @type EE_Registry |
|
34 | + */ |
|
35 | + protected $Registry; |
|
36 | + |
|
37 | + /** |
|
38 | + * @type EE_Request_Handler |
|
39 | + */ |
|
40 | + protected $Request_Handler; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_Module_Request_Router |
|
44 | + */ |
|
45 | + protected $Module_Request_Router; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type CurrentPage |
|
49 | + */ |
|
50 | + protected $current_page; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * class constructor |
|
55 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * @param EE_Registry $Registry |
|
59 | + * @param CurrentPage $EspressoPage |
|
60 | + * @param EE_Module_Request_Router $Module_Request_Router |
|
61 | + */ |
|
62 | + public function __construct( |
|
63 | + EE_Registry $Registry, |
|
64 | + CurrentPage $EspressoPage, |
|
65 | + EE_Module_Request_Router $Module_Request_Router |
|
66 | + ) { |
|
67 | + $this->Registry = $Registry; |
|
68 | + $this->current_page = $EspressoPage; |
|
69 | + $this->Module_Request_Router = $Module_Request_Router; |
|
70 | + // load other resources and begin to actually run shortcodes and modules |
|
71 | + // analyse the incoming WP request |
|
72 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
73 | + // process request with module factory |
|
74 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
75 | + // before headers sent |
|
76 | + add_action('wp', array($this, 'wp'), 5); |
|
77 | + // primarily used to process any content shortcodes |
|
78 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
79 | + // header |
|
80 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
81 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
82 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
83 | + // display errors |
|
84 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
85 | + // the content |
|
86 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
87 | + // exclude our private cpt comments |
|
88 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
89 | + // make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
90 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
91 | + // action hook EE |
|
92 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return EE_Request_Handler |
|
98 | + * @deprecated 4.10.14.p |
|
99 | + */ |
|
100 | + public function Request_Handler() |
|
101 | + { |
|
102 | + if (! $this->Request_Handler instanceof EE_Request_Handler) { |
|
103 | + $this->Request_Handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler'); |
|
104 | + } |
|
105 | + return $this->Request_Handler; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return EE_Module_Request_Router |
|
111 | + */ |
|
112 | + public function Module_Request_Router() |
|
113 | + { |
|
114 | + return $this->Module_Request_Router; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return LegacyShortcodesManager |
|
120 | + * @deprecated 4.10.14.p |
|
121 | + */ |
|
122 | + public function getLegacyShortcodesManager() |
|
123 | + { |
|
124 | + return EE_Config::getLegacyShortcodesManager(); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
132 | + /** |
|
133 | + * filter_wp_comments |
|
134 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
135 | + * widgets/queries done on frontend |
|
136 | + * |
|
137 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
138 | + * @return array array of comment clauses with modifications. |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + public function filter_wp_comments($clauses) |
|
144 | + { |
|
145 | + global $wpdb; |
|
146 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
147 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
148 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
149 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
150 | + ); |
|
151 | + $cpts = $custom_post_types->getPrivateCustomPostTypes(); |
|
152 | + foreach ($cpts as $cpt => $details) { |
|
153 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
154 | + } |
|
155 | + } |
|
156 | + return $clauses; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
162 | + * |
|
163 | + * @param string $url incoming url |
|
164 | + * @return string final assembled url |
|
165 | + */ |
|
166 | + public function maybe_force_admin_ajax_ssl($url) |
|
167 | + { |
|
168 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
169 | + $url = str_replace('http://', 'https://', $url); |
|
170 | + } |
|
171 | + return $url; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
184 | + * default priority init phases have run |
|
185 | + * |
|
186 | + * @access public |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function wp_loaded() |
|
190 | + { |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
198 | + /** |
|
199 | + * _get_request |
|
200 | + * |
|
201 | + * @access public |
|
202 | + * @param WP $WP |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function get_request(WP $WP) |
|
206 | + { |
|
207 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
208 | + $this->current_page->parseQueryVars($WP); |
|
209 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
210 | + remove_action('parse_request', [$this, 'get_request'], 1); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @param WP_Query $WP_Query |
|
219 | + * @return void |
|
220 | + * @throws EE_Error |
|
221 | + * @throws ReflectionException |
|
222 | + */ |
|
223 | + public function pre_get_posts($WP_Query) |
|
224 | + { |
|
225 | + // only load Module_Request_Router if this is the main query |
|
226 | + if ( |
|
227 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
228 | + && $WP_Query->is_main_query() |
|
229 | + ) { |
|
230 | + // cycle thru module routes |
|
231 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
232 | + // determine module and method for route |
|
233 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
234 | + if ($module instanceof EED_Module) { |
|
235 | + // get registered view for route |
|
236 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
237 | + // grab module name |
|
238 | + $module_name = $module->module_name(); |
|
239 | + // map the module to the module objects |
|
240 | + $this->Registry->modules->{$module_name} = $module; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /*********************************************** WP HOOK ***********************************************/ |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * wp - basically last chance to do stuff before headers sent |
|
255 | + * |
|
256 | + * @access public |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function wp() |
|
260 | + { |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * callback for the "template_redirect" hook point |
|
270 | + * checks sidebars for EE widgets |
|
271 | + * loads resources and assets accordingly |
|
272 | + * |
|
273 | + * @return void |
|
274 | + */ |
|
275 | + public function templateRedirect() |
|
276 | + { |
|
277 | + global $wp_query; |
|
278 | + if (empty($wp_query->posts)) { |
|
279 | + return; |
|
280 | + } |
|
281 | + // if we already know this is an espresso page, then load assets |
|
282 | + $load_assets = $this->current_page->isEspressoPage(); |
|
283 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
284 | + $load_assets = $load_assets || $this->espresso_widgets_in_active_sidebars(); |
|
285 | + if ($load_assets) { |
|
286 | + add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
287 | + add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'), 10); |
|
288 | + } |
|
289 | + |
|
290 | + if (is_singular(EspressoPostType::EVENTS)) { |
|
291 | + new FilterNextPreviousEventPostQuery(); |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * builds list of active widgets then scans active sidebars looking for them |
|
298 | + * returns true is an EE widget is found in an active sidebar |
|
299 | + * Please Note: this does NOT mean that the sidebar or widget |
|
300 | + * is actually in use in a given template, as that is unfortunately not known |
|
301 | + * until a sidebar and it's widgets are actually loaded |
|
302 | + * |
|
303 | + * @return boolean |
|
304 | + */ |
|
305 | + private function espresso_widgets_in_active_sidebars() |
|
306 | + { |
|
307 | + $espresso_widgets = array(); |
|
308 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
309 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
310 | + if (is_active_widget(false, false, $id_base)) { |
|
311 | + $espresso_widgets[] = $id_base; |
|
312 | + } |
|
313 | + } |
|
314 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
315 | + foreach ($all_sidebar_widgets as $sidebar_widgets) { |
|
316 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
317 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
318 | + foreach ($espresso_widgets as $espresso_widget) { |
|
319 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
320 | + return true; |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + return false; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * header_meta_tag |
|
332 | + * |
|
333 | + * @access public |
|
334 | + * @return void |
|
335 | + */ |
|
336 | + public function header_meta_tag() |
|
337 | + { |
|
338 | + print( |
|
339 | + apply_filters( |
|
340 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
341 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n" |
|
342 | + ) |
|
343 | + ); |
|
344 | + |
|
345 | + // let's exclude all event type taxonomy term archive pages from search engine indexing |
|
346 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
347 | + // also exclude all critical pages from indexing |
|
348 | + if ( |
|
349 | + ( |
|
350 | + is_tax('espresso_event_type') |
|
351 | + && get_option('blog_public') !== '0' |
|
352 | + ) |
|
353 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
354 | + ) { |
|
355 | + print( |
|
356 | + apply_filters( |
|
357 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
358 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
359 | + ) |
|
360 | + ); |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * wp_print_scripts |
|
367 | + * |
|
368 | + * @return void |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + public function wp_print_scripts() |
|
372 | + { |
|
373 | + global $post; |
|
374 | + if ( |
|
375 | + isset($post->EE_Event) |
|
376 | + && $post->EE_Event instanceof EE_Event |
|
377 | + && get_post_type() === EspressoPostType::EVENTS |
|
378 | + && is_singular() |
|
379 | + ) { |
|
380 | + EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + public function enqueueStyle() |
|
386 | + { |
|
387 | + wp_enqueue_style('espresso_default'); |
|
388 | + wp_enqueue_style('espresso_custom_css'); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
394 | + |
|
395 | + |
|
396 | + public function enqueueScripts() |
|
397 | + { |
|
398 | + wp_enqueue_script('espresso_core'); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * display_errors |
|
404 | + * |
|
405 | + * @access public |
|
406 | + * @return void |
|
407 | + * @throws DomainException |
|
408 | + */ |
|
409 | + public function display_errors() |
|
410 | + { |
|
411 | + static $shown_already = false; |
|
412 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
413 | + if ( |
|
414 | + ! $shown_already |
|
415 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
416 | + && is_main_query() |
|
417 | + && ! is_feed() |
|
418 | + && in_the_loop() |
|
419 | + && $this->current_page->isEspressoPage() |
|
420 | + ) { |
|
421 | + $shown_already = true; |
|
422 | + if (did_action('wp_head')) { |
|
423 | + echo wp_kses($this->printNotices(), AllowedTags::getAllowedTags()); |
|
424 | + } else { |
|
425 | + // block enabled themes run their query loop before headers are sent |
|
426 | + // so we need to add our notices onto the beginning of the content |
|
427 | + add_filter('the_content', [$this, 'prependNotices'], 1, 1); |
|
428 | + } |
|
429 | + } |
|
430 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @param string $the_content |
|
436 | + * @return string |
|
437 | + * @since 4.10.30.p |
|
438 | + */ |
|
439 | + public function prependNotices($the_content) |
|
440 | + { |
|
441 | + $notices = $this->printNotices(); |
|
442 | + return $notices ? $notices . $the_content : $the_content; |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * @return false|string |
|
448 | + * @since 4.10.30.p |
|
449 | + */ |
|
450 | + public function printNotices() |
|
451 | + { |
|
452 | + ob_start(); |
|
453 | + echo wp_kses(EE_Error::get_notices(), AllowedTags::getWithFormTags()); |
|
454 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
455 | + return ob_get_clean(); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + |
|
460 | + /*********************************************** UTILITIES ***********************************************/ |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * @param string $template_include_path |
|
465 | + * @return string |
|
466 | + * @throws EE_Error |
|
467 | + * @throws ReflectionException |
|
468 | + */ |
|
469 | + public function template_include($template_include_path = null) |
|
470 | + { |
|
471 | + if ($this->current_page->isEspressoPage()) { |
|
472 | + // despite all helpers having autoloaders set, we need to manually load the template loader |
|
473 | + // because there are some side effects in that class for triggering template tag functions |
|
474 | + $this->Registry->load_helper('EEH_Template'); |
|
475 | + $this->_template_path = ! empty($this->_template_path) |
|
476 | + ? basename($this->_template_path) |
|
477 | + : basename( |
|
478 | + $template_include_path |
|
479 | + ); |
|
480 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
481 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
482 | + $this->_template = basename($this->_template_path); |
|
483 | + return $this->_template_path; |
|
484 | + } |
|
485 | + return $template_include_path; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @param bool $with_path |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_selected_template($with_path = false) |
|
494 | + { |
|
495 | + return $with_path ? $this->_template_path : $this->_template; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * @param string $shortcode_class |
|
501 | + * @param WP $wp |
|
502 | + * @throws ReflectionException |
|
503 | + * @deprecated 4.9.26 |
|
504 | + */ |
|
505 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
506 | + { |
|
507 | + EE_Error::doing_it_wrong( |
|
508 | + __METHOD__, |
|
509 | + esc_html__( |
|
510 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
511 | + 'event_espresso' |
|
512 | + ), |
|
513 | + '4.9.26' |
|
514 | + ); |
|
515 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * @return void |
|
521 | + * @deprecated 4.9.57.p |
|
522 | + */ |
|
523 | + public function loadPersistentAdminNoticeManager() |
|
524 | + { |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * @return void |
|
530 | + * @deprecated 4.9.64.p |
|
531 | + */ |
|
532 | + public function employ_CPT_Strategy() |
|
533 | + { |
|
534 | + } |
|
535 | 535 | } |
@@ -16,343 +16,343 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_CPT_Strategy extends EE_Base |
18 | 18 | { |
19 | - private static ?EE_CPT_Strategy $_instance = null; |
|
20 | - |
|
21 | - protected ?EEM_CPT_Base $CPT_model = null; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var CptQueryModifier[] |
|
25 | - */ |
|
26 | - protected array $query_modifier = []; |
|
27 | - |
|
28 | - /** |
|
29 | - * the current page, if it utilizes CPTs |
|
30 | - */ |
|
31 | - protected array $CPT = []; |
|
32 | - |
|
33 | - /** |
|
34 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
35 | - */ |
|
36 | - protected array $_CPTs = []; |
|
37 | - |
|
38 | - protected array $_CPT_taxonomies = []; |
|
39 | - |
|
40 | - protected array $_CPT_terms = []; |
|
41 | - |
|
42 | - protected array $_CPT_endpoints = []; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @singleton method used to instantiate class object |
|
47 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
48 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
49 | - * @return EE_CPT_Strategy |
|
50 | - */ |
|
51 | - public static function instance( |
|
52 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
53 | - CustomTaxonomyDefinitions $taxonomies = null |
|
54 | - ): EE_CPT_Strategy { |
|
55 | - // check if class object is instantiated |
|
56 | - if ( |
|
57 | - ! self::$_instance instanceof EE_CPT_Strategy |
|
58 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
59 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
60 | - ) { |
|
61 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
62 | - } |
|
63 | - return self::$_instance; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
69 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
70 | - */ |
|
71 | - protected function __construct( |
|
72 | - CustomPostTypeDefinitions $custom_post_types, |
|
73 | - CustomTaxonomyDefinitions $taxonomies |
|
74 | - ) { |
|
75 | - // get CPT data |
|
76 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
77 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
78 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
79 | - add_action('pre_get_posts', [$this, 'pre_get_posts'], 5); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function get_CPT_endpoints(): array |
|
87 | - { |
|
88 | - return $this->_CPT_endpoints; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - public function get_CPT_taxonomies(): array |
|
96 | - { |
|
97 | - return $this->_CPT_taxonomies; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * add CPT "slugs" to array of default espresso "pages" |
|
103 | - * |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - private function _set_CPT_endpoints(): array |
|
107 | - { |
|
108 | - $_CPT_endpoints = []; |
|
109 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
110 | - if (isset($CPT['plural_slug'])) { |
|
111 | - $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
112 | - } |
|
113 | - } |
|
114 | - return $_CPT_endpoints; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - public function wpQueryPostType(WP_Query $wp_query): string |
|
119 | - { |
|
120 | - $post_type = $wp_query->query->post_type ?? ''; |
|
121 | - $post_type = $post_type === '' && isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
122 | - return is_array($post_type) ? (string) reset($post_type) : (string) $post_type; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - public function isEspressoPostType(WP_Query $wp_query): bool |
|
127 | - { |
|
128 | - $post_type = $this->wpQueryPostType($wp_query); |
|
129 | - return isset($this->_CPTs[ $post_type ]); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
135 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
136 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
137 | - * |
|
138 | - * @param WP_Query $wp_query |
|
139 | - * @return void |
|
140 | - * @throws EE_Error |
|
141 | - * @throws ReflectionException |
|
142 | - */ |
|
143 | - public function pre_get_posts(WP_Query $wp_query) |
|
144 | - { |
|
145 | - // check that post-type is one of ours |
|
146 | - if (! $this->isEspressoPostType($wp_query)) { |
|
147 | - return; |
|
148 | - } |
|
149 | - // add our conditionals |
|
150 | - $this->_set_EE_tags_on_WP_Query($wp_query); |
|
151 | - // check for terms |
|
152 | - $this->_set_post_type_for_terms($wp_query); |
|
153 | - // make sure paging is always set |
|
154 | - $this->_set_paging($wp_query); |
|
155 | - // is a taxonomy set ? |
|
156 | - $this->_set_CPT_taxonomies_on_WP_Query($wp_query); |
|
157 | - // loop thru post_types if set |
|
158 | - $this->_process_WP_Query_post_types($wp_query); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param WP_Query $wp_query |
|
164 | - * @return void |
|
165 | - */ |
|
166 | - private function _set_EE_tags_on_WP_Query(WP_Query $wp_query) |
|
167 | - { |
|
168 | - $wp_query->is_espresso_event_single = false; |
|
169 | - $wp_query->is_espresso_event_archive = false; |
|
170 | - $wp_query->is_espresso_event_taxonomy = false; |
|
171 | - $wp_query->is_espresso_venue_single = false; |
|
172 | - $wp_query->is_espresso_venue_archive = false; |
|
173 | - $wp_query->is_espresso_venue_taxonomy = false; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @return void |
|
179 | - * @throws EE_Error |
|
180 | - * @throws ReflectionException |
|
181 | - */ |
|
182 | - private function _set_CPT_terms() |
|
183 | - { |
|
184 | - if (empty($this->_CPT_terms)) { |
|
185 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
186 | - foreach ($terms as $term) { |
|
187 | - if ($term instanceof EE_Term) { |
|
188 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param WP_Query $wp_query |
|
197 | - * @return void |
|
198 | - * @throws EE_Error |
|
199 | - * @throws ReflectionException |
|
200 | - */ |
|
201 | - private function _set_post_type_for_terms(WP_Query $wp_query) |
|
202 | - { |
|
203 | - // is a tag set ? |
|
204 | - if (! isset($wp_query->query['tag'])) { |
|
205 | - return; |
|
206 | - } |
|
207 | - // get term for tag |
|
208 | - $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($wp_query->query['tag']); |
|
209 | - // verify the term |
|
210 | - if (! $term instanceof EE_Term) { |
|
211 | - return; |
|
212 | - } |
|
213 | - $term->post_type = array_merge(['post', 'page'], (array) $term->post_type); |
|
214 | - $term->post_type = apply_filters( |
|
215 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
216 | - $term->post_type, |
|
217 | - $term |
|
218 | - ); |
|
219 | - // if a post type is already set |
|
220 | - if (isset($wp_query->query_vars['post_type'])) { |
|
221 | - // add to existing array |
|
222 | - $term->post_type = array_merge((array) $wp_query->query_vars['post_type'], $term->post_type); |
|
223 | - } |
|
224 | - // just set post_type to our CPT |
|
225 | - $wp_query->set('post_type', array_unique($term->post_type)); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @param WP_Query $wp_query |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function _set_paging(WP_Query $wp_query) |
|
234 | - { |
|
235 | - if ($wp_query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
236 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
237 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
238 | - $wp_query->set('paged', $paged); |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param WP_Query $wp_query |
|
245 | - */ |
|
246 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $wp_query) |
|
247 | - { |
|
248 | - // is a taxonomy set ? |
|
249 | - if (! $wp_query->is_tax) { |
|
250 | - return; |
|
251 | - } |
|
252 | - // loop thru our taxonomies |
|
253 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
254 | - // check if one of our taxonomies is set as a query var |
|
255 | - if (! isset($wp_query->query[ $CPT_taxonomy ])) { |
|
256 | - continue; |
|
257 | - } |
|
258 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
259 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
260 | - // verify our CPT has args, is public and has taxonomies set |
|
261 | - if ( |
|
262 | - ! isset($CPT['args']['public']) |
|
263 | - || ! $CPT['args']['public'] |
|
264 | - || empty($CPT['args']['taxonomies']) |
|
265 | - || ! in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
266 | - ) { |
|
267 | - continue; |
|
268 | - } |
|
269 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
270 | - $wp_query->query_vars['post_type'] = isset($wp_query->query_vars['post_type']) |
|
271 | - ? (array) $wp_query->query_vars['post_type'] |
|
272 | - : []; |
|
273 | - $wp_query->query_vars['post_type'][] = $post_type; |
|
274 | - switch ($post_type) { |
|
275 | - case EspressoPostType::EVENTS: |
|
276 | - $wp_query->is_espresso_event_taxonomy = true; |
|
277 | - break; |
|
278 | - |
|
279 | - case EspressoPostType::VENUES: |
|
280 | - $wp_query->is_espresso_venue_taxonomy = true; |
|
281 | - break; |
|
282 | - |
|
283 | - default: |
|
284 | - do_action( |
|
285 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
286 | - $wp_query, |
|
287 | - $this |
|
288 | - ); |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param WP_Query $wp_query |
|
297 | - */ |
|
298 | - protected function _process_WP_Query_post_types(WP_Query $wp_query) |
|
299 | - { |
|
300 | - if (! isset($wp_query->query_vars['post_type'])) { |
|
301 | - return; |
|
302 | - } |
|
303 | - // loop thru post_types as array |
|
304 | - foreach ((array) $wp_query->query_vars['post_type'] as $post_type) { |
|
305 | - // is current query for an EE CPT ? |
|
306 | - if (! isset($this->_CPTs[ $post_type ])) { |
|
307 | - continue; |
|
308 | - } |
|
309 | - // is EE on or off ? |
|
310 | - if (MaintenanceStatus::isNotDisabled()) { |
|
311 | - // reroute CPT template view to maintenance_mode.template.php |
|
312 | - if (! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) { |
|
313 | - add_filter('template_include', ['EE_Maintenance_Mode', 'template_include'], 99999); |
|
314 | - } |
|
315 | - if (has_filter('the_content', [EE_Maintenance_Mode::instance(), 'the_content'])) { |
|
316 | - add_filter('the_content', [$this, 'inject_EE_shortcode_placeholder'], 1); |
|
317 | - } |
|
318 | - return; |
|
319 | - } |
|
320 | - $this->_generate_CptQueryModifier($wp_query, $post_type); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @param WP_Query $wp_query |
|
327 | - * @param string $post_type |
|
328 | - */ |
|
329 | - protected function _generate_CptQueryModifier(WP_Query $wp_query, string $post_type) |
|
330 | - { |
|
331 | - if ($this->query_modifier[ $post_type ] instanceof CptQueryModifier) { |
|
332 | - return; |
|
333 | - } |
|
334 | - $this->query_modifier[ $post_type ] = LoaderFactory::getLoader()->getShared( |
|
335 | - CptQueryModifier::class, |
|
336 | - [ |
|
337 | - $post_type, |
|
338 | - $this->_CPTs[ $post_type ], |
|
339 | - $wp_query, |
|
340 | - ] |
|
341 | - ); |
|
342 | - $this->_CPT_taxonomies = $this->query_modifier[ $post_type ]->taxonomies(); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * inject_EE_shortcode_placeholder |
|
348 | - * in order to display the M-Mode notice on our CPT routes, |
|
349 | - * we need to first inject what looks like one of our shortcodes, |
|
350 | - * so that it can be replaced with the actual M-Mode notice |
|
351 | - * |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - public function inject_EE_shortcode_placeholder(): string |
|
355 | - { |
|
356 | - return '[ESPRESSO_'; |
|
357 | - } |
|
19 | + private static ?EE_CPT_Strategy $_instance = null; |
|
20 | + |
|
21 | + protected ?EEM_CPT_Base $CPT_model = null; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var CptQueryModifier[] |
|
25 | + */ |
|
26 | + protected array $query_modifier = []; |
|
27 | + |
|
28 | + /** |
|
29 | + * the current page, if it utilizes CPTs |
|
30 | + */ |
|
31 | + protected array $CPT = []; |
|
32 | + |
|
33 | + /** |
|
34 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
35 | + */ |
|
36 | + protected array $_CPTs = []; |
|
37 | + |
|
38 | + protected array $_CPT_taxonomies = []; |
|
39 | + |
|
40 | + protected array $_CPT_terms = []; |
|
41 | + |
|
42 | + protected array $_CPT_endpoints = []; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @singleton method used to instantiate class object |
|
47 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
48 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
49 | + * @return EE_CPT_Strategy |
|
50 | + */ |
|
51 | + public static function instance( |
|
52 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
53 | + CustomTaxonomyDefinitions $taxonomies = null |
|
54 | + ): EE_CPT_Strategy { |
|
55 | + // check if class object is instantiated |
|
56 | + if ( |
|
57 | + ! self::$_instance instanceof EE_CPT_Strategy |
|
58 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
59 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
60 | + ) { |
|
61 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
62 | + } |
|
63 | + return self::$_instance; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
69 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
70 | + */ |
|
71 | + protected function __construct( |
|
72 | + CustomPostTypeDefinitions $custom_post_types, |
|
73 | + CustomTaxonomyDefinitions $taxonomies |
|
74 | + ) { |
|
75 | + // get CPT data |
|
76 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
77 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
78 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
79 | + add_action('pre_get_posts', [$this, 'pre_get_posts'], 5); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function get_CPT_endpoints(): array |
|
87 | + { |
|
88 | + return $this->_CPT_endpoints; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + public function get_CPT_taxonomies(): array |
|
96 | + { |
|
97 | + return $this->_CPT_taxonomies; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * add CPT "slugs" to array of default espresso "pages" |
|
103 | + * |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + private function _set_CPT_endpoints(): array |
|
107 | + { |
|
108 | + $_CPT_endpoints = []; |
|
109 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
110 | + if (isset($CPT['plural_slug'])) { |
|
111 | + $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
112 | + } |
|
113 | + } |
|
114 | + return $_CPT_endpoints; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + public function wpQueryPostType(WP_Query $wp_query): string |
|
119 | + { |
|
120 | + $post_type = $wp_query->query->post_type ?? ''; |
|
121 | + $post_type = $post_type === '' && isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
122 | + return is_array($post_type) ? (string) reset($post_type) : (string) $post_type; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + public function isEspressoPostType(WP_Query $wp_query): bool |
|
127 | + { |
|
128 | + $post_type = $this->wpQueryPostType($wp_query); |
|
129 | + return isset($this->_CPTs[ $post_type ]); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
135 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
136 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
137 | + * |
|
138 | + * @param WP_Query $wp_query |
|
139 | + * @return void |
|
140 | + * @throws EE_Error |
|
141 | + * @throws ReflectionException |
|
142 | + */ |
|
143 | + public function pre_get_posts(WP_Query $wp_query) |
|
144 | + { |
|
145 | + // check that post-type is one of ours |
|
146 | + if (! $this->isEspressoPostType($wp_query)) { |
|
147 | + return; |
|
148 | + } |
|
149 | + // add our conditionals |
|
150 | + $this->_set_EE_tags_on_WP_Query($wp_query); |
|
151 | + // check for terms |
|
152 | + $this->_set_post_type_for_terms($wp_query); |
|
153 | + // make sure paging is always set |
|
154 | + $this->_set_paging($wp_query); |
|
155 | + // is a taxonomy set ? |
|
156 | + $this->_set_CPT_taxonomies_on_WP_Query($wp_query); |
|
157 | + // loop thru post_types if set |
|
158 | + $this->_process_WP_Query_post_types($wp_query); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param WP_Query $wp_query |
|
164 | + * @return void |
|
165 | + */ |
|
166 | + private function _set_EE_tags_on_WP_Query(WP_Query $wp_query) |
|
167 | + { |
|
168 | + $wp_query->is_espresso_event_single = false; |
|
169 | + $wp_query->is_espresso_event_archive = false; |
|
170 | + $wp_query->is_espresso_event_taxonomy = false; |
|
171 | + $wp_query->is_espresso_venue_single = false; |
|
172 | + $wp_query->is_espresso_venue_archive = false; |
|
173 | + $wp_query->is_espresso_venue_taxonomy = false; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + * @throws EE_Error |
|
180 | + * @throws ReflectionException |
|
181 | + */ |
|
182 | + private function _set_CPT_terms() |
|
183 | + { |
|
184 | + if (empty($this->_CPT_terms)) { |
|
185 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
186 | + foreach ($terms as $term) { |
|
187 | + if ($term instanceof EE_Term) { |
|
188 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param WP_Query $wp_query |
|
197 | + * @return void |
|
198 | + * @throws EE_Error |
|
199 | + * @throws ReflectionException |
|
200 | + */ |
|
201 | + private function _set_post_type_for_terms(WP_Query $wp_query) |
|
202 | + { |
|
203 | + // is a tag set ? |
|
204 | + if (! isset($wp_query->query['tag'])) { |
|
205 | + return; |
|
206 | + } |
|
207 | + // get term for tag |
|
208 | + $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($wp_query->query['tag']); |
|
209 | + // verify the term |
|
210 | + if (! $term instanceof EE_Term) { |
|
211 | + return; |
|
212 | + } |
|
213 | + $term->post_type = array_merge(['post', 'page'], (array) $term->post_type); |
|
214 | + $term->post_type = apply_filters( |
|
215 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
216 | + $term->post_type, |
|
217 | + $term |
|
218 | + ); |
|
219 | + // if a post type is already set |
|
220 | + if (isset($wp_query->query_vars['post_type'])) { |
|
221 | + // add to existing array |
|
222 | + $term->post_type = array_merge((array) $wp_query->query_vars['post_type'], $term->post_type); |
|
223 | + } |
|
224 | + // just set post_type to our CPT |
|
225 | + $wp_query->set('post_type', array_unique($term->post_type)); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @param WP_Query $wp_query |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function _set_paging(WP_Query $wp_query) |
|
234 | + { |
|
235 | + if ($wp_query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
236 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
237 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
238 | + $wp_query->set('paged', $paged); |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param WP_Query $wp_query |
|
245 | + */ |
|
246 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $wp_query) |
|
247 | + { |
|
248 | + // is a taxonomy set ? |
|
249 | + if (! $wp_query->is_tax) { |
|
250 | + return; |
|
251 | + } |
|
252 | + // loop thru our taxonomies |
|
253 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
254 | + // check if one of our taxonomies is set as a query var |
|
255 | + if (! isset($wp_query->query[ $CPT_taxonomy ])) { |
|
256 | + continue; |
|
257 | + } |
|
258 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
259 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
260 | + // verify our CPT has args, is public and has taxonomies set |
|
261 | + if ( |
|
262 | + ! isset($CPT['args']['public']) |
|
263 | + || ! $CPT['args']['public'] |
|
264 | + || empty($CPT['args']['taxonomies']) |
|
265 | + || ! in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
266 | + ) { |
|
267 | + continue; |
|
268 | + } |
|
269 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
270 | + $wp_query->query_vars['post_type'] = isset($wp_query->query_vars['post_type']) |
|
271 | + ? (array) $wp_query->query_vars['post_type'] |
|
272 | + : []; |
|
273 | + $wp_query->query_vars['post_type'][] = $post_type; |
|
274 | + switch ($post_type) { |
|
275 | + case EspressoPostType::EVENTS: |
|
276 | + $wp_query->is_espresso_event_taxonomy = true; |
|
277 | + break; |
|
278 | + |
|
279 | + case EspressoPostType::VENUES: |
|
280 | + $wp_query->is_espresso_venue_taxonomy = true; |
|
281 | + break; |
|
282 | + |
|
283 | + default: |
|
284 | + do_action( |
|
285 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
286 | + $wp_query, |
|
287 | + $this |
|
288 | + ); |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param WP_Query $wp_query |
|
297 | + */ |
|
298 | + protected function _process_WP_Query_post_types(WP_Query $wp_query) |
|
299 | + { |
|
300 | + if (! isset($wp_query->query_vars['post_type'])) { |
|
301 | + return; |
|
302 | + } |
|
303 | + // loop thru post_types as array |
|
304 | + foreach ((array) $wp_query->query_vars['post_type'] as $post_type) { |
|
305 | + // is current query for an EE CPT ? |
|
306 | + if (! isset($this->_CPTs[ $post_type ])) { |
|
307 | + continue; |
|
308 | + } |
|
309 | + // is EE on or off ? |
|
310 | + if (MaintenanceStatus::isNotDisabled()) { |
|
311 | + // reroute CPT template view to maintenance_mode.template.php |
|
312 | + if (! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) { |
|
313 | + add_filter('template_include', ['EE_Maintenance_Mode', 'template_include'], 99999); |
|
314 | + } |
|
315 | + if (has_filter('the_content', [EE_Maintenance_Mode::instance(), 'the_content'])) { |
|
316 | + add_filter('the_content', [$this, 'inject_EE_shortcode_placeholder'], 1); |
|
317 | + } |
|
318 | + return; |
|
319 | + } |
|
320 | + $this->_generate_CptQueryModifier($wp_query, $post_type); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @param WP_Query $wp_query |
|
327 | + * @param string $post_type |
|
328 | + */ |
|
329 | + protected function _generate_CptQueryModifier(WP_Query $wp_query, string $post_type) |
|
330 | + { |
|
331 | + if ($this->query_modifier[ $post_type ] instanceof CptQueryModifier) { |
|
332 | + return; |
|
333 | + } |
|
334 | + $this->query_modifier[ $post_type ] = LoaderFactory::getLoader()->getShared( |
|
335 | + CptQueryModifier::class, |
|
336 | + [ |
|
337 | + $post_type, |
|
338 | + $this->_CPTs[ $post_type ], |
|
339 | + $wp_query, |
|
340 | + ] |
|
341 | + ); |
|
342 | + $this->_CPT_taxonomies = $this->query_modifier[ $post_type ]->taxonomies(); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * inject_EE_shortcode_placeholder |
|
348 | + * in order to display the M-Mode notice on our CPT routes, |
|
349 | + * we need to first inject what looks like one of our shortcodes, |
|
350 | + * so that it can be replaced with the actual M-Mode notice |
|
351 | + * |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + public function inject_EE_shortcode_placeholder(): string |
|
355 | + { |
|
356 | + return '[ESPRESSO_'; |
|
357 | + } |
|
358 | 358 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $_CPT_endpoints = []; |
109 | 109 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
110 | 110 | if (isset($CPT['plural_slug'])) { |
111 | - $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
111 | + $_CPT_endpoints [(string) $CPT['plural_slug']] = $CPT_type; |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | return $_CPT_endpoints; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function isEspressoPostType(WP_Query $wp_query): bool |
127 | 127 | { |
128 | 128 | $post_type = $this->wpQueryPostType($wp_query); |
129 | - return isset($this->_CPTs[ $post_type ]); |
|
129 | + return isset($this->_CPTs[$post_type]); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function pre_get_posts(WP_Query $wp_query) |
144 | 144 | { |
145 | 145 | // check that post-type is one of ours |
146 | - if (! $this->isEspressoPostType($wp_query)) { |
|
146 | + if ( ! $this->isEspressoPostType($wp_query)) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | // add our conditionals |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
186 | 186 | foreach ($terms as $term) { |
187 | 187 | if ($term instanceof EE_Term) { |
188 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
188 | + $this->_CPT_terms[$term->slug()] = $term; |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | private function _set_post_type_for_terms(WP_Query $wp_query) |
202 | 202 | { |
203 | 203 | // is a tag set ? |
204 | - if (! isset($wp_query->query['tag'])) { |
|
204 | + if ( ! isset($wp_query->query['tag'])) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 | // get term for tag |
208 | 208 | $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($wp_query->query['tag']); |
209 | 209 | // verify the term |
210 | - if (! $term instanceof EE_Term) { |
|
210 | + if ( ! $term instanceof EE_Term) { |
|
211 | 211 | return; |
212 | 212 | } |
213 | 213 | $term->post_type = array_merge(['post', 'page'], (array) $term->post_type); |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $wp_query) |
247 | 247 | { |
248 | 248 | // is a taxonomy set ? |
249 | - if (! $wp_query->is_tax) { |
|
249 | + if ( ! $wp_query->is_tax) { |
|
250 | 250 | return; |
251 | 251 | } |
252 | 252 | // loop thru our taxonomies |
253 | 253 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
254 | 254 | // check if one of our taxonomies is set as a query var |
255 | - if (! isset($wp_query->query[ $CPT_taxonomy ])) { |
|
255 | + if ( ! isset($wp_query->query[$CPT_taxonomy])) { |
|
256 | 256 | continue; |
257 | 257 | } |
258 | 258 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | |
283 | 283 | default: |
284 | 284 | do_action( |
285 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
285 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
286 | 286 | $wp_query, |
287 | 287 | $this |
288 | 288 | ); |
@@ -297,19 +297,19 @@ discard block |
||
297 | 297 | */ |
298 | 298 | protected function _process_WP_Query_post_types(WP_Query $wp_query) |
299 | 299 | { |
300 | - if (! isset($wp_query->query_vars['post_type'])) { |
|
300 | + if ( ! isset($wp_query->query_vars['post_type'])) { |
|
301 | 301 | return; |
302 | 302 | } |
303 | 303 | // loop thru post_types as array |
304 | 304 | foreach ((array) $wp_query->query_vars['post_type'] as $post_type) { |
305 | 305 | // is current query for an EE CPT ? |
306 | - if (! isset($this->_CPTs[ $post_type ])) { |
|
306 | + if ( ! isset($this->_CPTs[$post_type])) { |
|
307 | 307 | continue; |
308 | 308 | } |
309 | 309 | // is EE on or off ? |
310 | 310 | if (MaintenanceStatus::isNotDisabled()) { |
311 | 311 | // reroute CPT template view to maintenance_mode.template.php |
312 | - if (! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) { |
|
312 | + if ( ! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) { |
|
313 | 313 | add_filter('template_include', ['EE_Maintenance_Mode', 'template_include'], 99999); |
314 | 314 | } |
315 | 315 | if (has_filter('the_content', [EE_Maintenance_Mode::instance(), 'the_content'])) { |
@@ -328,18 +328,18 @@ discard block |
||
328 | 328 | */ |
329 | 329 | protected function _generate_CptQueryModifier(WP_Query $wp_query, string $post_type) |
330 | 330 | { |
331 | - if ($this->query_modifier[ $post_type ] instanceof CptQueryModifier) { |
|
331 | + if ($this->query_modifier[$post_type] instanceof CptQueryModifier) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | - $this->query_modifier[ $post_type ] = LoaderFactory::getLoader()->getShared( |
|
334 | + $this->query_modifier[$post_type] = LoaderFactory::getLoader()->getShared( |
|
335 | 335 | CptQueryModifier::class, |
336 | 336 | [ |
337 | 337 | $post_type, |
338 | - $this->_CPTs[ $post_type ], |
|
338 | + $this->_CPTs[$post_type], |
|
339 | 339 | $wp_query, |
340 | 340 | ] |
341 | 341 | ); |
342 | - $this->_CPT_taxonomies = $this->query_modifier[ $post_type ]->taxonomies(); |
|
342 | + $this->_CPT_taxonomies = $this->query_modifier[$post_type]->taxonomies(); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 |
@@ -9,63 +9,63 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_CPT_Default_Strategy |
11 | 11 | { |
12 | - /** |
|
13 | - * $CPT - the current page, if it utilizes CPTs |
|
14 | - * |
|
15 | - * @var object |
|
16 | - */ |
|
17 | - protected $CPT = null; |
|
12 | + /** |
|
13 | + * $CPT - the current page, if it utilizes CPTs |
|
14 | + * |
|
15 | + * @var object |
|
16 | + */ |
|
17 | + protected $CPT = null; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @param array $arguments |
|
22 | - */ |
|
23 | - public function __construct(array $arguments = []) |
|
24 | - { |
|
25 | - $this->CPT = $arguments['CPT'] ?? null; |
|
26 | - } |
|
20 | + /** |
|
21 | + * @param array $arguments |
|
22 | + */ |
|
23 | + public function __construct(array $arguments = []) |
|
24 | + { |
|
25 | + $this->CPT = $arguments['CPT'] ?? null; |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * pre_get_posts |
|
31 | - * |
|
32 | - * @param WP_Query $wp_query |
|
33 | - * @return WP_Query |
|
34 | - */ |
|
35 | - public function pre_get_posts(WP_Query $wp_query): WP_Query |
|
36 | - { |
|
37 | - return $wp_query; |
|
38 | - } |
|
29 | + /** |
|
30 | + * pre_get_posts |
|
31 | + * |
|
32 | + * @param WP_Query $wp_query |
|
33 | + * @return WP_Query |
|
34 | + */ |
|
35 | + public function pre_get_posts(WP_Query $wp_query): WP_Query |
|
36 | + { |
|
37 | + return $wp_query; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * wp |
|
43 | - * |
|
44 | - * @param WP_Post[] $posts |
|
45 | - * @param WP_Query $wp_query |
|
46 | - * @return WP_Post[] |
|
47 | - */ |
|
48 | - public function the_posts(array $posts, WP_Query $wp_query): array |
|
49 | - { |
|
50 | - return $posts; |
|
51 | - } |
|
41 | + /** |
|
42 | + * wp |
|
43 | + * |
|
44 | + * @param WP_Post[] $posts |
|
45 | + * @param WP_Query $wp_query |
|
46 | + * @return WP_Post[] |
|
47 | + */ |
|
48 | + public function the_posts(array $posts, WP_Query $wp_query): array |
|
49 | + { |
|
50 | + return $posts; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @param mixed $meta_value |
|
56 | - * @param int $object_id |
|
57 | - * @param string $meta_key |
|
58 | - * @param bool $single |
|
59 | - * @param string $meta_type |
|
60 | - * @return mixed |
|
61 | - */ |
|
62 | - public function get_EE_post_type_metadata( |
|
63 | - $meta_value, |
|
64 | - int $object_id, |
|
65 | - string $meta_key, |
|
66 | - bool $single, |
|
67 | - string $meta_type |
|
68 | - ) { |
|
69 | - return $meta_value; |
|
70 | - } |
|
54 | + /** |
|
55 | + * @param mixed $meta_value |
|
56 | + * @param int $object_id |
|
57 | + * @param string $meta_key |
|
58 | + * @param bool $single |
|
59 | + * @param string $meta_type |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | + public function get_EE_post_type_metadata( |
|
63 | + $meta_value, |
|
64 | + int $object_id, |
|
65 | + string $meta_key, |
|
66 | + bool $single, |
|
67 | + string $meta_type |
|
68 | + ) { |
|
69 | + return $meta_value; |
|
70 | + } |
|
71 | 71 | } |
@@ -11,241 +11,241 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_CPT_Event_Strategy |
13 | 13 | { |
14 | - /** |
|
15 | - * the current page, if it utilizes CPTs |
|
16 | - * |
|
17 | - * @var object $CPT |
|
18 | - */ |
|
19 | - protected $CPT; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param array|WP_Query|null $wp_query |
|
24 | - * @param array $CPT |
|
25 | - */ |
|
26 | - public function __construct($wp_query, array $CPT = []) |
|
27 | - { |
|
28 | - if (is_array($wp_query) && $wp_query['WP_Query'] instanceof WP_Query) { |
|
29 | - $this->CPT = $wp_query['CPT'] ?? $CPT; |
|
30 | - $wp_query = $wp_query['WP_Query']; |
|
31 | - } else { |
|
32 | - $this->CPT = $CPT; |
|
33 | - } |
|
34 | - |
|
35 | - // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
36 | - // here's the list of available filters in the WP_Query object |
|
37 | - // 'posts_where' |
|
38 | - // 'posts_where_paged' |
|
39 | - // 'posts_groupby' |
|
40 | - // 'posts_join_paged' |
|
41 | - // 'posts_orderby' |
|
42 | - // 'posts_distinct' |
|
43 | - // 'post_limits' |
|
44 | - // 'posts_fields' |
|
45 | - // 'posts_join' |
|
46 | - $this->_add_filters(); |
|
47 | - if ($wp_query instanceof WP_Query) { |
|
48 | - $wp_query->is_espresso_event_single = is_singular() |
|
49 | - && ( |
|
50 | - (isset($wp_query->query->post_type) && $wp_query->query->post_type === EspressoPostType::EVENTS) |
|
51 | - || (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === EspressoPostType::EVENTS) |
|
52 | - ); |
|
53 | - $wp_query->is_espresso_event_archive = is_post_type_archive(EspressoPostType::EVENTS); |
|
54 | - $wp_query->is_espresso_event_taxonomy = is_tax('espresso_event_categories'); |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * When an instance of this class is created, we add our filters |
|
61 | - * (which will get removed in case the next call to get_posts ISN'T |
|
62 | - * for event CPTs) |
|
63 | - */ |
|
64 | - protected function _add_filters() |
|
65 | - { |
|
66 | - add_filter('posts_fields', [$this, 'posts_fields'], 1, 2); |
|
67 | - add_filter('posts_join', [$this, 'posts_join'], 1, 2); |
|
68 | - add_filter('posts_where', [$this, 'posts_where'], 10, 2); |
|
69 | - // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 ); |
|
70 | - add_filter('posts_orderby', [$this, 'posts_orderby'], 1, 2); |
|
71 | - add_filter('posts_groupby', [$this, 'posts_groupby'], 1, 2); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * public access to _remove_filters() |
|
77 | - * |
|
78 | - * @since 4.9.63.p |
|
79 | - */ |
|
80 | - public function remove_filters() |
|
81 | - { |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $SQL |
|
87 | - * @param WP_Query|null $wp_query |
|
88 | - * @return string |
|
89 | - * @throws EE_Error |
|
90 | - * @throws ReflectionException |
|
91 | - */ |
|
92 | - public function posts_fields(string $SQL, ?WP_Query $wp_query): string |
|
93 | - { |
|
94 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
95 | - return $SQL; |
|
96 | - } |
|
97 | - |
|
98 | - if ( |
|
99 | - $wp_query instanceof WP_Query |
|
100 | - && ( |
|
101 | - $wp_query->is_espresso_event_single |
|
102 | - || $wp_query->is_espresso_event_archive |
|
103 | - || $wp_query->is_espresso_event_taxonomy |
|
104 | - ) |
|
105 | - ) { |
|
106 | - // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
107 | - $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* '; |
|
108 | - if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
|
109 | - // because we only want to retrieve the next upcoming datetime for each event: |
|
110 | - // add something like: |
|
111 | - // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " |
|
112 | - // to WP Query SELECT statement |
|
113 | - $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
114 | - } |
|
115 | - remove_filter('posts_fields', [$this, 'posts_fields'], 1); |
|
116 | - } |
|
117 | - return $SQL; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $SQL |
|
123 | - * @param WP_Query|null $wp_query |
|
124 | - * @return string |
|
125 | - * @throws EE_Error |
|
126 | - * @throws ReflectionException |
|
127 | - */ |
|
128 | - public function posts_join(string $SQL, ?WP_Query $wp_query): string |
|
129 | - { |
|
130 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
131 | - return $SQL; |
|
132 | - } |
|
133 | - if ( |
|
134 | - $wp_query instanceof WP_Query |
|
135 | - && ( |
|
136 | - $wp_query->is_espresso_event_single |
|
137 | - || $wp_query->is_espresso_event_archive |
|
138 | - || $wp_query->is_espresso_event_taxonomy |
|
139 | - ) |
|
140 | - ) { |
|
141 | - // adds something like: |
|
142 | - // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " |
|
143 | - // to WP Query JOIN statement |
|
144 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() |
|
145 | - . '.ID = ' . EEM_Datetime::instance()->table() . '.' |
|
146 | - . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
147 | - remove_filter('posts_join', [$this, 'posts_join'], 1); |
|
148 | - } |
|
149 | - return $SQL; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param string $SQL |
|
155 | - * @param WP_Query|null $wp_query |
|
156 | - * @return string |
|
157 | - * @throws EE_Error |
|
158 | - * @throws ReflectionException |
|
159 | - */ |
|
160 | - public function posts_where(string $SQL, ?WP_Query $wp_query): string |
|
161 | - { |
|
162 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
163 | - return $SQL; |
|
164 | - } |
|
165 | - if ( |
|
166 | - $wp_query instanceof WP_Query |
|
167 | - && ( |
|
168 | - $wp_query->is_espresso_event_archive |
|
169 | - || $wp_query->is_espresso_event_taxonomy |
|
170 | - ) |
|
171 | - ) { |
|
172 | - if ( |
|
173 | - ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) |
|
174 | - || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) |
|
175 | - || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events |
|
176 | - ) { |
|
177 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" |
|
178 | - . current_time('mysql', true) . "' "; |
|
179 | - } |
|
180 | - // exclude trashed datetimes |
|
181 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_deleted = 0'; |
|
182 | - remove_filter('posts_where', [$this, 'posts_where']); |
|
183 | - } |
|
184 | - return $SQL; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @param string $SQL |
|
190 | - * @param WP_Query|null $wp_query |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function posts_orderby(string $SQL, ?WP_Query $wp_query): string |
|
194 | - { |
|
195 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
196 | - return $SQL; |
|
197 | - } |
|
198 | - |
|
199 | - if ( |
|
200 | - $wp_query instanceof WP_Query |
|
201 | - && ( |
|
202 | - $wp_query->is_espresso_event_archive |
|
203 | - || $wp_query->is_espresso_event_taxonomy |
|
204 | - ) |
|
205 | - ) { |
|
206 | - $SQL = ' event_start_date ASC '; |
|
207 | - remove_filter('posts_orderby', [$this, 'posts_orderby'], 1); |
|
208 | - } |
|
209 | - return $SQL; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @param string $SQL |
|
215 | - * @param WP_Query|null $wp_query |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function posts_groupby(string $SQL, ?WP_Query $wp_query): string |
|
219 | - { |
|
220 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
221 | - return $SQL; |
|
222 | - } |
|
223 | - if ( |
|
224 | - $wp_query instanceof WP_Query |
|
225 | - && ( |
|
226 | - $wp_query->is_espresso_event_archive |
|
227 | - || $wp_query->is_espresso_event_taxonomy |
|
228 | - ) |
|
229 | - ) { |
|
230 | - // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default) |
|
231 | - // we're joining to the datetimes table, where there can be MANY datetimes for a single event, |
|
232 | - // but we want to only show each event only once |
|
233 | - // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
|
234 | - global $wpdb; |
|
235 | - $SQL = $wpdb->posts . '.ID '; |
|
236 | - remove_filter('posts_groupby', [$this, 'posts_groupby'], 1); |
|
237 | - } |
|
238 | - return $SQL; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param array $posts |
|
244 | - * @param WP_Query|null $wp_query |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - public function the_posts(array $posts, ?WP_Query $wp_query): array |
|
248 | - { |
|
249 | - return $posts; |
|
250 | - } |
|
14 | + /** |
|
15 | + * the current page, if it utilizes CPTs |
|
16 | + * |
|
17 | + * @var object $CPT |
|
18 | + */ |
|
19 | + protected $CPT; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param array|WP_Query|null $wp_query |
|
24 | + * @param array $CPT |
|
25 | + */ |
|
26 | + public function __construct($wp_query, array $CPT = []) |
|
27 | + { |
|
28 | + if (is_array($wp_query) && $wp_query['WP_Query'] instanceof WP_Query) { |
|
29 | + $this->CPT = $wp_query['CPT'] ?? $CPT; |
|
30 | + $wp_query = $wp_query['WP_Query']; |
|
31 | + } else { |
|
32 | + $this->CPT = $CPT; |
|
33 | + } |
|
34 | + |
|
35 | + // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
36 | + // here's the list of available filters in the WP_Query object |
|
37 | + // 'posts_where' |
|
38 | + // 'posts_where_paged' |
|
39 | + // 'posts_groupby' |
|
40 | + // 'posts_join_paged' |
|
41 | + // 'posts_orderby' |
|
42 | + // 'posts_distinct' |
|
43 | + // 'post_limits' |
|
44 | + // 'posts_fields' |
|
45 | + // 'posts_join' |
|
46 | + $this->_add_filters(); |
|
47 | + if ($wp_query instanceof WP_Query) { |
|
48 | + $wp_query->is_espresso_event_single = is_singular() |
|
49 | + && ( |
|
50 | + (isset($wp_query->query->post_type) && $wp_query->query->post_type === EspressoPostType::EVENTS) |
|
51 | + || (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === EspressoPostType::EVENTS) |
|
52 | + ); |
|
53 | + $wp_query->is_espresso_event_archive = is_post_type_archive(EspressoPostType::EVENTS); |
|
54 | + $wp_query->is_espresso_event_taxonomy = is_tax('espresso_event_categories'); |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * When an instance of this class is created, we add our filters |
|
61 | + * (which will get removed in case the next call to get_posts ISN'T |
|
62 | + * for event CPTs) |
|
63 | + */ |
|
64 | + protected function _add_filters() |
|
65 | + { |
|
66 | + add_filter('posts_fields', [$this, 'posts_fields'], 1, 2); |
|
67 | + add_filter('posts_join', [$this, 'posts_join'], 1, 2); |
|
68 | + add_filter('posts_where', [$this, 'posts_where'], 10, 2); |
|
69 | + // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 ); |
|
70 | + add_filter('posts_orderby', [$this, 'posts_orderby'], 1, 2); |
|
71 | + add_filter('posts_groupby', [$this, 'posts_groupby'], 1, 2); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * public access to _remove_filters() |
|
77 | + * |
|
78 | + * @since 4.9.63.p |
|
79 | + */ |
|
80 | + public function remove_filters() |
|
81 | + { |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $SQL |
|
87 | + * @param WP_Query|null $wp_query |
|
88 | + * @return string |
|
89 | + * @throws EE_Error |
|
90 | + * @throws ReflectionException |
|
91 | + */ |
|
92 | + public function posts_fields(string $SQL, ?WP_Query $wp_query): string |
|
93 | + { |
|
94 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
95 | + return $SQL; |
|
96 | + } |
|
97 | + |
|
98 | + if ( |
|
99 | + $wp_query instanceof WP_Query |
|
100 | + && ( |
|
101 | + $wp_query->is_espresso_event_single |
|
102 | + || $wp_query->is_espresso_event_archive |
|
103 | + || $wp_query->is_espresso_event_taxonomy |
|
104 | + ) |
|
105 | + ) { |
|
106 | + // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
107 | + $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* '; |
|
108 | + if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
|
109 | + // because we only want to retrieve the next upcoming datetime for each event: |
|
110 | + // add something like: |
|
111 | + // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " |
|
112 | + // to WP Query SELECT statement |
|
113 | + $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
114 | + } |
|
115 | + remove_filter('posts_fields', [$this, 'posts_fields'], 1); |
|
116 | + } |
|
117 | + return $SQL; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $SQL |
|
123 | + * @param WP_Query|null $wp_query |
|
124 | + * @return string |
|
125 | + * @throws EE_Error |
|
126 | + * @throws ReflectionException |
|
127 | + */ |
|
128 | + public function posts_join(string $SQL, ?WP_Query $wp_query): string |
|
129 | + { |
|
130 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
131 | + return $SQL; |
|
132 | + } |
|
133 | + if ( |
|
134 | + $wp_query instanceof WP_Query |
|
135 | + && ( |
|
136 | + $wp_query->is_espresso_event_single |
|
137 | + || $wp_query->is_espresso_event_archive |
|
138 | + || $wp_query->is_espresso_event_taxonomy |
|
139 | + ) |
|
140 | + ) { |
|
141 | + // adds something like: |
|
142 | + // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " |
|
143 | + // to WP Query JOIN statement |
|
144 | + $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() |
|
145 | + . '.ID = ' . EEM_Datetime::instance()->table() . '.' |
|
146 | + . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
147 | + remove_filter('posts_join', [$this, 'posts_join'], 1); |
|
148 | + } |
|
149 | + return $SQL; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param string $SQL |
|
155 | + * @param WP_Query|null $wp_query |
|
156 | + * @return string |
|
157 | + * @throws EE_Error |
|
158 | + * @throws ReflectionException |
|
159 | + */ |
|
160 | + public function posts_where(string $SQL, ?WP_Query $wp_query): string |
|
161 | + { |
|
162 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
163 | + return $SQL; |
|
164 | + } |
|
165 | + if ( |
|
166 | + $wp_query instanceof WP_Query |
|
167 | + && ( |
|
168 | + $wp_query->is_espresso_event_archive |
|
169 | + || $wp_query->is_espresso_event_taxonomy |
|
170 | + ) |
|
171 | + ) { |
|
172 | + if ( |
|
173 | + ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) |
|
174 | + || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) |
|
175 | + || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events |
|
176 | + ) { |
|
177 | + $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" |
|
178 | + . current_time('mysql', true) . "' "; |
|
179 | + } |
|
180 | + // exclude trashed datetimes |
|
181 | + $SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_deleted = 0'; |
|
182 | + remove_filter('posts_where', [$this, 'posts_where']); |
|
183 | + } |
|
184 | + return $SQL; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @param string $SQL |
|
190 | + * @param WP_Query|null $wp_query |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function posts_orderby(string $SQL, ?WP_Query $wp_query): string |
|
194 | + { |
|
195 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
196 | + return $SQL; |
|
197 | + } |
|
198 | + |
|
199 | + if ( |
|
200 | + $wp_query instanceof WP_Query |
|
201 | + && ( |
|
202 | + $wp_query->is_espresso_event_archive |
|
203 | + || $wp_query->is_espresso_event_taxonomy |
|
204 | + ) |
|
205 | + ) { |
|
206 | + $SQL = ' event_start_date ASC '; |
|
207 | + remove_filter('posts_orderby', [$this, 'posts_orderby'], 1); |
|
208 | + } |
|
209 | + return $SQL; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @param string $SQL |
|
215 | + * @param WP_Query|null $wp_query |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function posts_groupby(string $SQL, ?WP_Query $wp_query): string |
|
219 | + { |
|
220 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::EVENTS) { |
|
221 | + return $SQL; |
|
222 | + } |
|
223 | + if ( |
|
224 | + $wp_query instanceof WP_Query |
|
225 | + && ( |
|
226 | + $wp_query->is_espresso_event_archive |
|
227 | + || $wp_query->is_espresso_event_taxonomy |
|
228 | + ) |
|
229 | + ) { |
|
230 | + // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default) |
|
231 | + // we're joining to the datetimes table, where there can be MANY datetimes for a single event, |
|
232 | + // but we want to only show each event only once |
|
233 | + // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
|
234 | + global $wpdb; |
|
235 | + $SQL = $wpdb->posts . '.ID '; |
|
236 | + remove_filter('posts_groupby', [$this, 'posts_groupby'], 1); |
|
237 | + } |
|
238 | + return $SQL; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param array $posts |
|
244 | + * @param WP_Query|null $wp_query |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + public function the_posts(array $posts, ?WP_Query $wp_query): array |
|
248 | + { |
|
249 | + return $posts; |
|
250 | + } |
|
251 | 251 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | // 'posts_join' |
46 | 46 | $this->_add_filters(); |
47 | 47 | if ($wp_query instanceof WP_Query) { |
48 | - $wp_query->is_espresso_event_single = is_singular() |
|
48 | + $wp_query->is_espresso_event_single = is_singular() |
|
49 | 49 | && ( |
50 | 50 | (isset($wp_query->query->post_type) && $wp_query->query->post_type === EspressoPostType::EVENTS) |
51 | 51 | || (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === EspressoPostType::EVENTS) |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | ) |
105 | 105 | ) { |
106 | 106 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
107 | - $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* '; |
|
107 | + $SQL .= ', '.EEM_Datetime::instance()->table().'.* '; |
|
108 | 108 | if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
109 | 109 | // because we only want to retrieve the next upcoming datetime for each event: |
110 | 110 | // add something like: |
111 | 111 | // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " |
112 | 112 | // to WP Query SELECT statement |
113 | - $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
113 | + $SQL .= ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
114 | 114 | } |
115 | 115 | remove_filter('posts_fields', [$this, 'posts_fields'], 1); |
116 | 116 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | // adds something like: |
142 | 142 | // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " |
143 | 143 | // to WP Query JOIN statement |
144 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() |
|
145 | - . '.ID = ' . EEM_Datetime::instance()->table() . '.' |
|
146 | - . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
144 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.EEM_Event::instance()->table() |
|
145 | + . '.ID = '.EEM_Datetime::instance()->table().'.' |
|
146 | + . EEM_Event::instance()->primary_key_name().' ) '; |
|
147 | 147 | remove_filter('posts_join', [$this, 'posts_join'], 1); |
148 | 148 | } |
149 | 149 | return $SQL; |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) |
175 | 175 | || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events |
176 | 176 | ) { |
177 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" |
|
178 | - . current_time('mysql', true) . "' "; |
|
177 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().".DTT_EVT_end > '" |
|
178 | + . current_time('mysql', true)."' "; |
|
179 | 179 | } |
180 | 180 | // exclude trashed datetimes |
181 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_deleted = 0'; |
|
181 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_deleted = 0'; |
|
182 | 182 | remove_filter('posts_where', [$this, 'posts_where']); |
183 | 183 | } |
184 | 184 | return $SQL; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | // but we want to only show each event only once |
233 | 233 | // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
234 | 234 | global $wpdb; |
235 | - $SQL = $wpdb->posts . '.ID '; |
|
235 | + $SQL = $wpdb->posts.'.ID '; |
|
236 | 236 | remove_filter('posts_groupby', [$this, 'posts_groupby'], 1); |
237 | 237 | } |
238 | 238 | return $SQL; |
@@ -31,501 +31,501 @@ |
||
31 | 31 | */ |
32 | 32 | class CptQueryModifier |
33 | 33 | { |
34 | - protected CurrentPage $current_page; |
|
34 | + protected CurrentPage $current_page; |
|
35 | 35 | |
36 | - protected LoaderInterface $loader; |
|
37 | - |
|
38 | - protected RequestInterface $request; |
|
39 | - |
|
40 | - protected WP_Query $wp_query; |
|
41 | - |
|
42 | - protected ?EEM_CPT_Base $model = null; |
|
36 | + protected LoaderInterface $loader; |
|
37 | + |
|
38 | + protected RequestInterface $request; |
|
39 | + |
|
40 | + protected WP_Query $wp_query; |
|
41 | + |
|
42 | + protected ?EEM_CPT_Base $model = null; |
|
43 | 43 | |
44 | - /** |
|
45 | - * meta table for the related CPT |
|
46 | - */ |
|
47 | - protected ?EE_Secondary_Table $meta_table = null; |
|
48 | - |
|
49 | - protected ?EE_Request_Handler $request_handler = null; |
|
50 | - |
|
51 | - protected string $post_type = ''; |
|
44 | + /** |
|
45 | + * meta table for the related CPT |
|
46 | + */ |
|
47 | + protected ?EE_Secondary_Table $meta_table = null; |
|
48 | + |
|
49 | + protected ?EE_Request_Handler $request_handler = null; |
|
50 | + |
|
51 | + protected string $post_type = ''; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var EE_CPT_Attendee_Strategy|EE_CPT_Default_Strategy|EE_CPT_Event_Strategy|EE_CPT_Venue_Strategy|null |
|
55 | - */ |
|
56 | - protected $cpt_strategy = null; |
|
57 | - |
|
58 | - /** |
|
59 | - * CPT details from CustomPostTypeDefinitions for specific post type |
|
60 | - * |
|
61 | - * @var array $cpt_details |
|
62 | - */ |
|
63 | - protected array $cpt_details = []; |
|
53 | + /** |
|
54 | + * @var EE_CPT_Attendee_Strategy|EE_CPT_Default_Strategy|EE_CPT_Event_Strategy|EE_CPT_Venue_Strategy|null |
|
55 | + */ |
|
56 | + protected $cpt_strategy = null; |
|
57 | + |
|
58 | + /** |
|
59 | + * CPT details from CustomPostTypeDefinitions for specific post type |
|
60 | + * |
|
61 | + * @var array $cpt_details |
|
62 | + */ |
|
63 | + protected array $cpt_details = []; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var EE_Table_Base[] $model_tables |
|
67 | - */ |
|
68 | - protected array $model_tables = []; |
|
65 | + /** |
|
66 | + * @var EE_Table_Base[] $model_tables |
|
67 | + */ |
|
68 | + protected array $model_tables = []; |
|
69 | 69 | |
70 | - protected array $taxonomies = []; |
|
70 | + protected array $taxonomies = []; |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * CptQueryModifier constructor |
|
75 | - * |
|
76 | - * @param string $post_type |
|
77 | - * @param array $cpt_details |
|
78 | - * @param WP_Query $wp_query |
|
79 | - * @param CurrentPage $current_page |
|
80 | - * @param RequestInterface $request |
|
81 | - * @param LoaderInterface $loader |
|
82 | - * @throws EE_Error |
|
83 | - */ |
|
84 | - public function __construct( |
|
85 | - string $post_type, |
|
86 | - array $cpt_details, |
|
87 | - WP_Query $wp_query, |
|
88 | - CurrentPage $current_page, |
|
89 | - RequestInterface $request, |
|
90 | - LoaderInterface $loader |
|
91 | - ) { |
|
92 | - $this->loader = $loader; |
|
93 | - $this->request = $request; |
|
94 | - $this->current_page = $current_page; |
|
95 | - $this->setWpQuery($wp_query); |
|
96 | - $this->setPostType($post_type); |
|
97 | - $this->setCptDetails($cpt_details); |
|
98 | - $this->init($wp_query); |
|
99 | - } |
|
73 | + /** |
|
74 | + * CptQueryModifier constructor |
|
75 | + * |
|
76 | + * @param string $post_type |
|
77 | + * @param array $cpt_details |
|
78 | + * @param WP_Query $wp_query |
|
79 | + * @param CurrentPage $current_page |
|
80 | + * @param RequestInterface $request |
|
81 | + * @param LoaderInterface $loader |
|
82 | + * @throws EE_Error |
|
83 | + */ |
|
84 | + public function __construct( |
|
85 | + string $post_type, |
|
86 | + array $cpt_details, |
|
87 | + WP_Query $wp_query, |
|
88 | + CurrentPage $current_page, |
|
89 | + RequestInterface $request, |
|
90 | + LoaderInterface $loader |
|
91 | + ) { |
|
92 | + $this->loader = $loader; |
|
93 | + $this->request = $request; |
|
94 | + $this->current_page = $current_page; |
|
95 | + $this->setWpQuery($wp_query); |
|
96 | + $this->setPostType($post_type); |
|
97 | + $this->setCptDetails($cpt_details); |
|
98 | + $this->init($wp_query); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - public function postType(): string |
|
103 | - { |
|
104 | - return $this->post_type; |
|
105 | - } |
|
102 | + public function postType(): string |
|
103 | + { |
|
104 | + return $this->post_type; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - protected function setPostType(string $post_type) |
|
109 | - { |
|
110 | - $this->post_type = $post_type; |
|
111 | - } |
|
108 | + protected function setPostType(string $post_type) |
|
109 | + { |
|
110 | + $this->post_type = $post_type; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - public function cptDetails(): array |
|
115 | - { |
|
116 | - return $this->cpt_details; |
|
117 | - } |
|
114 | + public function cptDetails(): array |
|
115 | + { |
|
116 | + return $this->cpt_details; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | - protected function setCptDetails(array $cpt_details) |
|
121 | - { |
|
122 | - $this->cpt_details = $cpt_details; |
|
123 | - } |
|
120 | + protected function setCptDetails(array $cpt_details) |
|
121 | + { |
|
122 | + $this->cpt_details = $cpt_details; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * @return EE_Table_Base[] |
|
128 | - */ |
|
129 | - public function modelTables(): array |
|
130 | - { |
|
131 | - return $this->model_tables; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param EE_Table_Base[] $model_tables |
|
137 | - */ |
|
138 | - protected function setModelTables(array $model_tables) |
|
139 | - { |
|
140 | - $this->model_tables = $model_tables; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - public function taxonomies(): array |
|
145 | - { |
|
146 | - if (empty($this->taxonomies)) { |
|
147 | - $this->initializeTaxonomies(); |
|
148 | - } |
|
149 | - return $this->taxonomies; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - protected function setTaxonomies(array $taxonomies) |
|
154 | - { |
|
155 | - $this->taxonomies = $taxonomies; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - public function metaTable(): ?EE_Secondary_Table |
|
160 | - { |
|
161 | - return $this->meta_table; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - public function setMetaTable(EE_Secondary_Table $meta_table) |
|
166 | - { |
|
167 | - $this->meta_table = $meta_table; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - public function model(): ?EEM_CPT_Base |
|
172 | - { |
|
173 | - return $this->model; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - protected function setModel(EEM_CPT_Base $CPT_model) |
|
178 | - { |
|
179 | - $this->model = $CPT_model; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return EE_Request_Handler |
|
185 | - * @deprecated 4.9.63.p |
|
186 | - */ |
|
187 | - public function request(): ?EE_Request_Handler |
|
188 | - { |
|
189 | - if (! $this->request_handler instanceof EE_Request_Handler) { |
|
190 | - $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler'); |
|
191 | - } |
|
192 | - return $this->request_handler; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
197 | - |
|
198 | - |
|
199 | - public function WpQuery(): WP_Query |
|
200 | - { |
|
201 | - return $this->wp_query; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - // phpcs:enable |
|
206 | - |
|
207 | - |
|
208 | - public function setWpQuery(WP_Query $wp_query) |
|
209 | - { |
|
210 | - $this->wp_query = $wp_query; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - protected function initializeTaxonomies() |
|
215 | - { |
|
216 | - // check if taxonomies have already been set and that this CPT has taxonomies registered for it |
|
217 | - if ( |
|
218 | - empty($this->taxonomies) |
|
219 | - && isset($this->cpt_details['args']['taxonomies']) |
|
220 | - ) { |
|
221 | - // if so then grab them, but we want the taxonomy name as the key |
|
222 | - $taxonomies = array_flip($this->cpt_details['args']['taxonomies']); |
|
223 | - // then grab the list of ALL taxonomies |
|
224 | - /** @var CustomTaxonomyDefinitions $taxonomy_definitions */ |
|
225 | - $taxonomy_definitions = $this->loader->getShared(CustomTaxonomyDefinitions::class); |
|
226 | - $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions(); |
|
227 | - foreach ($taxonomies as $taxonomy => &$details) { |
|
228 | - // add details to our taxonomies if they exist |
|
229 | - $details = $all_taxonomies[ $taxonomy ] ?? []; |
|
230 | - } |
|
231 | - // ALWAYS unset() variables that were passed by reference |
|
232 | - unset($details); |
|
233 | - $this->setTaxonomies($taxonomies); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @throws EE_Error |
|
240 | - * @since 4.9.63.p |
|
241 | - */ |
|
242 | - protected function init() |
|
243 | - { |
|
244 | - $this->setAdditionalCptDetails(); |
|
245 | - $this->setRequestVarsIfCpt(); |
|
246 | - // convert post_type to model name |
|
247 | - $model_name = str_replace('EE_', '', $this->cpt_details['class_name']); |
|
248 | - // load all tables related to CPT |
|
249 | - $this->setupModelsAndTables($model_name); |
|
250 | - // load and instantiate CPT_*_Strategy |
|
251 | - $this->cpt_strategy = $this->cpt_strategy === null |
|
252 | - ? $this->cptStrategyClass($model_name) |
|
253 | - : $this->cpt_strategy; |
|
254 | - // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
255 | - // here's the list of available filters in the WP_Query object |
|
256 | - // 'posts_where_paged' |
|
257 | - // 'posts_groupby' |
|
258 | - // 'posts_join_paged' |
|
259 | - // 'posts_orderby' |
|
260 | - // 'posts_distinct' |
|
261 | - // 'post_limits' |
|
262 | - // 'posts_fields' |
|
263 | - // 'posts_join' |
|
264 | - add_filter('posts_fields', [$this, 'postsFields'], 10, 2); |
|
265 | - add_filter('posts_join', [$this, 'postsJoin'], 10, 2); |
|
266 | - add_filter('the_posts', [$this, 'thePosts'], 1, 2); |
|
267 | - if ($this->wp_query->is_main_query()) { |
|
268 | - add_filter('get_edit_post_link', [$this, 'getEditPostLink'], 10, 2); |
|
269 | - $this->addTemplateFilters(); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * sets some basic query vars that pertain to the CPT |
|
276 | - * |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - protected function setAdditionalCptDetails() |
|
280 | - { |
|
281 | - // the post or category or term that is triggering EE |
|
282 | - $this->cpt_details['espresso_page'] = $this->current_page->isEspressoPage(); |
|
283 | - // requested post name |
|
284 | - $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name'); |
|
285 | - // add support for viewing 'private', 'draft', or 'pending' posts |
|
286 | - if ( |
|
287 | - isset($this->wp_query->query_vars['p']) |
|
288 | - && $this->wp_query->query_vars['p'] !== 0 |
|
289 | - && is_user_logged_in() |
|
290 | - && current_user_can('edit_post', $this->wp_query->query_vars['p']) |
|
291 | - ) { |
|
292 | - // we can just inject directly into the WP_Query object |
|
293 | - $this->wp_query->query['post_status'] = ['publish', 'private', 'draft', 'pending']; |
|
294 | - // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s) |
|
295 | - $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var. |
|
302 | - * If so, sets the 'ee' request variable |
|
303 | - * so other parts of EE can know what CPT is getting queried. |
|
304 | - * To Mike's knowledge, this must be called from during or after the pre_get_posts hook |
|
305 | - * in order for is_archive() and is_single() methods to work properly. |
|
306 | - * |
|
307 | - * @return void |
|
308 | - */ |
|
309 | - public function setRequestVarsIfCpt() |
|
310 | - { |
|
311 | - // check if ee action var has been set |
|
312 | - if (! $this->request->requestParamIsSet('ee')) { |
|
313 | - // check that route exists for CPT archive slug |
|
314 | - if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) { |
|
315 | - // ie: set "ee" to "events" |
|
316 | - $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']); |
|
317 | - // or does it match a single page CPT like /event/ |
|
318 | - } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) { |
|
319 | - // ie: set "ee" to "event" |
|
320 | - $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * setupModelsAndTables |
|
328 | - * |
|
329 | - * @param string $model_name |
|
330 | - * @throws EE_Error |
|
331 | - */ |
|
332 | - protected function setupModelsAndTables(string $model_name) |
|
333 | - { |
|
334 | - // get CPT table data via CPT Model |
|
335 | - $full_model_name = strpos($model_name, 'EEM_') !== 0 |
|
336 | - ? 'EEM_' . $model_name |
|
337 | - : $model_name; |
|
338 | - $model = $this->loader->getShared($full_model_name); |
|
339 | - if (! $model instanceof EEM_CPT_Base) { |
|
340 | - throw new EE_Error( |
|
341 | - sprintf( |
|
342 | - esc_html__( |
|
343 | - 'The "%1$s" model could not be loaded.', |
|
344 | - 'event_espresso' |
|
345 | - ), |
|
346 | - $full_model_name |
|
347 | - ) |
|
348 | - ); |
|
349 | - } |
|
350 | - $this->setModel($model); |
|
351 | - $this->setModelTables($this->model->get_tables()); |
|
352 | - $meta_model = $model_name . '_Meta'; |
|
353 | - // is there a Meta Table for this CPT? |
|
354 | - if ( |
|
355 | - isset($this->cpt_details['tables'][ $meta_model ]) |
|
356 | - && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table |
|
357 | - ) { |
|
358 | - $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]); |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * cptStrategyClass |
|
365 | - * |
|
366 | - * @param string $model_name |
|
367 | - * @return EE_CPT_Event_Strategy|EE_CPT_Attendee_Strategy|EE_CPT_Default_Strategy|EE_CPT_Venue_Strategy |
|
368 | - */ |
|
369 | - protected function cptStrategyClass(string $model_name) |
|
370 | - { |
|
371 | - // creates classname like: CPT_Event_Strategy |
|
372 | - $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy'; |
|
373 | - // load and instantiate |
|
374 | - $CPT_Strategy = $this->loader->getShared( |
|
375 | - $CPT_Strategy_class_name, |
|
376 | - ['WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details] |
|
377 | - ); |
|
378 | - if ($CPT_Strategy === null) { |
|
379 | - $CPT_Strategy = $this->loader->getShared( |
|
380 | - 'EE_CPT_Default_Strategy', |
|
381 | - ['WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details] |
|
382 | - ); |
|
383 | - } |
|
384 | - return $CPT_Strategy; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * @param string $SQL |
|
390 | - * @param WP_Query $wp_query |
|
391 | - * @return string |
|
392 | - */ |
|
393 | - public function postsFields(string $SQL, WP_Query $wp_query): string |
|
394 | - { |
|
395 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== $this->post_type) { |
|
396 | - return $SQL; |
|
397 | - } |
|
398 | - // does this CPT have a meta table ? |
|
399 | - if ($this->meta_table instanceof EE_Secondary_Table) { |
|
400 | - // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement |
|
401 | - $SQL .= ', ' . $this->meta_table->get_table_name() . '.* '; |
|
402 | - } |
|
403 | - remove_filter('posts_fields', [$this, 'postsFields']); |
|
404 | - return $SQL; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @param string $SQL |
|
410 | - * @param WP_Query $wp_query |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function postsJoin(string $SQL, WP_Query $wp_query): string |
|
414 | - { |
|
415 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== $this->post_type) { |
|
416 | - return $SQL; |
|
417 | - } |
|
418 | - // does this CPT have a meta table ? |
|
419 | - if ($this->meta_table instanceof EE_Secondary_Table) { |
|
420 | - global $wpdb; |
|
421 | - // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement |
|
422 | - $posts_table = $wpdb->posts; |
|
423 | - $meta_table = $this->meta_table->get_table_name(); |
|
424 | - $foreign_key = $this->meta_table->get_fk_on_table(); |
|
425 | - $SQL .= " LEFT JOIN $meta_table ON ( $meta_table.$foreign_key = $posts_table.ID ) "; |
|
426 | - } |
|
427 | - remove_filter('posts_join', [$this, 'postsJoin']); |
|
428 | - return $SQL; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * thePosts |
|
434 | - * |
|
435 | - * @param WP_Post[] $posts |
|
436 | - * @param WP_Query $wp_query |
|
437 | - * @return WP_Post[] |
|
438 | - */ |
|
439 | - public function thePosts(array $posts, WP_Query $wp_query): array |
|
440 | - { |
|
441 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== $this->post_type) { |
|
442 | - return $posts; |
|
443 | - } |
|
444 | - $CPT_class = $this->cpt_details['class_name']; |
|
445 | - // loop thru posts |
|
446 | - if ($this->model instanceof EEM_CPT_Base) { |
|
447 | - foreach ($posts as $post) { |
|
448 | - if ($post->post_type === $this->post_type) { |
|
449 | - $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post); |
|
450 | - } |
|
451 | - } |
|
452 | - } |
|
453 | - remove_filter('the_posts', [$this, 'thePosts'], 1); |
|
454 | - return $posts; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $url |
|
460 | - * @param int $ID |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public function getEditPostLink(string $url, int $ID): string |
|
464 | - { |
|
465 | - // need to make sure we only edit links if our cpt |
|
466 | - global $post; |
|
467 | - // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui |
|
468 | - // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin. |
|
469 | - if ( |
|
470 | - ! $post instanceof WP_Post |
|
471 | - || $post->post_type !== $this->post_type |
|
472 | - || ( |
|
473 | - isset($this->cpt_details['args']['show_ee_ui']) |
|
474 | - && ! $this->cpt_details['args']['show_ee_ui'] |
|
475 | - ) |
|
476 | - ) { |
|
477 | - return $url; |
|
478 | - } |
|
479 | - // k made it here so all is good. |
|
480 | - return wp_nonce_url( |
|
481 | - add_query_arg( |
|
482 | - ['page' => $this->post_type, 'post' => $ID, 'action' => 'edit'], |
|
483 | - admin_url('admin.php') |
|
484 | - ), |
|
485 | - 'edit', |
|
486 | - 'edit_nonce' |
|
487 | - ); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Execute any template filters. |
|
493 | - * This method is only called if in main query. |
|
494 | - * |
|
495 | - * @return void |
|
496 | - */ |
|
497 | - public function addTemplateFilters() |
|
498 | - { |
|
499 | - // if requested cpt supports page_templates and it's the main query |
|
500 | - if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
501 | - // then let's hook into the appropriate query_template hook |
|
502 | - add_filter('single_template', [$this, 'singleCptTemplate']); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * Callback for single_template wp filter. |
|
509 | - * This is used to load the set page_template for a single ee cpt if its set. If "default" then we load the normal |
|
510 | - * hierarchy. |
|
511 | - * |
|
512 | - * @param string $current_template Existing default template path derived for this page call. |
|
513 | - * @return string the path to the full template file. |
|
514 | - */ |
|
515 | - public function singleCptTemplate(string $current_template): string |
|
516 | - { |
|
517 | - $object = get_queried_object(); |
|
518 | - // does this called object HAVE a page template set that is something other than the default. |
|
519 | - $template = get_post_meta($object->ID, '_wp_page_template', true); |
|
520 | - // exit early if default or not set or invalid path (accounts for theme changes) |
|
521 | - if ( |
|
522 | - $template === 'default' |
|
523 | - || empty($template) |
|
524 | - || ! is_readable(get_stylesheet_directory() . '/' . $template) |
|
525 | - ) { |
|
526 | - return $current_template; |
|
527 | - } |
|
528 | - // made it here so we SHOULD be able to just locate the template and then return it. |
|
529 | - return locate_template([$template]); |
|
530 | - } |
|
126 | + /** |
|
127 | + * @return EE_Table_Base[] |
|
128 | + */ |
|
129 | + public function modelTables(): array |
|
130 | + { |
|
131 | + return $this->model_tables; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param EE_Table_Base[] $model_tables |
|
137 | + */ |
|
138 | + protected function setModelTables(array $model_tables) |
|
139 | + { |
|
140 | + $this->model_tables = $model_tables; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + public function taxonomies(): array |
|
145 | + { |
|
146 | + if (empty($this->taxonomies)) { |
|
147 | + $this->initializeTaxonomies(); |
|
148 | + } |
|
149 | + return $this->taxonomies; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + protected function setTaxonomies(array $taxonomies) |
|
154 | + { |
|
155 | + $this->taxonomies = $taxonomies; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + public function metaTable(): ?EE_Secondary_Table |
|
160 | + { |
|
161 | + return $this->meta_table; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + public function setMetaTable(EE_Secondary_Table $meta_table) |
|
166 | + { |
|
167 | + $this->meta_table = $meta_table; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + public function model(): ?EEM_CPT_Base |
|
172 | + { |
|
173 | + return $this->model; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + protected function setModel(EEM_CPT_Base $CPT_model) |
|
178 | + { |
|
179 | + $this->model = $CPT_model; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return EE_Request_Handler |
|
185 | + * @deprecated 4.9.63.p |
|
186 | + */ |
|
187 | + public function request(): ?EE_Request_Handler |
|
188 | + { |
|
189 | + if (! $this->request_handler instanceof EE_Request_Handler) { |
|
190 | + $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler'); |
|
191 | + } |
|
192 | + return $this->request_handler; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
197 | + |
|
198 | + |
|
199 | + public function WpQuery(): WP_Query |
|
200 | + { |
|
201 | + return $this->wp_query; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + // phpcs:enable |
|
206 | + |
|
207 | + |
|
208 | + public function setWpQuery(WP_Query $wp_query) |
|
209 | + { |
|
210 | + $this->wp_query = $wp_query; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + protected function initializeTaxonomies() |
|
215 | + { |
|
216 | + // check if taxonomies have already been set and that this CPT has taxonomies registered for it |
|
217 | + if ( |
|
218 | + empty($this->taxonomies) |
|
219 | + && isset($this->cpt_details['args']['taxonomies']) |
|
220 | + ) { |
|
221 | + // if so then grab them, but we want the taxonomy name as the key |
|
222 | + $taxonomies = array_flip($this->cpt_details['args']['taxonomies']); |
|
223 | + // then grab the list of ALL taxonomies |
|
224 | + /** @var CustomTaxonomyDefinitions $taxonomy_definitions */ |
|
225 | + $taxonomy_definitions = $this->loader->getShared(CustomTaxonomyDefinitions::class); |
|
226 | + $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions(); |
|
227 | + foreach ($taxonomies as $taxonomy => &$details) { |
|
228 | + // add details to our taxonomies if they exist |
|
229 | + $details = $all_taxonomies[ $taxonomy ] ?? []; |
|
230 | + } |
|
231 | + // ALWAYS unset() variables that were passed by reference |
|
232 | + unset($details); |
|
233 | + $this->setTaxonomies($taxonomies); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @throws EE_Error |
|
240 | + * @since 4.9.63.p |
|
241 | + */ |
|
242 | + protected function init() |
|
243 | + { |
|
244 | + $this->setAdditionalCptDetails(); |
|
245 | + $this->setRequestVarsIfCpt(); |
|
246 | + // convert post_type to model name |
|
247 | + $model_name = str_replace('EE_', '', $this->cpt_details['class_name']); |
|
248 | + // load all tables related to CPT |
|
249 | + $this->setupModelsAndTables($model_name); |
|
250 | + // load and instantiate CPT_*_Strategy |
|
251 | + $this->cpt_strategy = $this->cpt_strategy === null |
|
252 | + ? $this->cptStrategyClass($model_name) |
|
253 | + : $this->cpt_strategy; |
|
254 | + // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
255 | + // here's the list of available filters in the WP_Query object |
|
256 | + // 'posts_where_paged' |
|
257 | + // 'posts_groupby' |
|
258 | + // 'posts_join_paged' |
|
259 | + // 'posts_orderby' |
|
260 | + // 'posts_distinct' |
|
261 | + // 'post_limits' |
|
262 | + // 'posts_fields' |
|
263 | + // 'posts_join' |
|
264 | + add_filter('posts_fields', [$this, 'postsFields'], 10, 2); |
|
265 | + add_filter('posts_join', [$this, 'postsJoin'], 10, 2); |
|
266 | + add_filter('the_posts', [$this, 'thePosts'], 1, 2); |
|
267 | + if ($this->wp_query->is_main_query()) { |
|
268 | + add_filter('get_edit_post_link', [$this, 'getEditPostLink'], 10, 2); |
|
269 | + $this->addTemplateFilters(); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * sets some basic query vars that pertain to the CPT |
|
276 | + * |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + protected function setAdditionalCptDetails() |
|
280 | + { |
|
281 | + // the post or category or term that is triggering EE |
|
282 | + $this->cpt_details['espresso_page'] = $this->current_page->isEspressoPage(); |
|
283 | + // requested post name |
|
284 | + $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name'); |
|
285 | + // add support for viewing 'private', 'draft', or 'pending' posts |
|
286 | + if ( |
|
287 | + isset($this->wp_query->query_vars['p']) |
|
288 | + && $this->wp_query->query_vars['p'] !== 0 |
|
289 | + && is_user_logged_in() |
|
290 | + && current_user_can('edit_post', $this->wp_query->query_vars['p']) |
|
291 | + ) { |
|
292 | + // we can just inject directly into the WP_Query object |
|
293 | + $this->wp_query->query['post_status'] = ['publish', 'private', 'draft', 'pending']; |
|
294 | + // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s) |
|
295 | + $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var. |
|
302 | + * If so, sets the 'ee' request variable |
|
303 | + * so other parts of EE can know what CPT is getting queried. |
|
304 | + * To Mike's knowledge, this must be called from during or after the pre_get_posts hook |
|
305 | + * in order for is_archive() and is_single() methods to work properly. |
|
306 | + * |
|
307 | + * @return void |
|
308 | + */ |
|
309 | + public function setRequestVarsIfCpt() |
|
310 | + { |
|
311 | + // check if ee action var has been set |
|
312 | + if (! $this->request->requestParamIsSet('ee')) { |
|
313 | + // check that route exists for CPT archive slug |
|
314 | + if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) { |
|
315 | + // ie: set "ee" to "events" |
|
316 | + $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']); |
|
317 | + // or does it match a single page CPT like /event/ |
|
318 | + } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) { |
|
319 | + // ie: set "ee" to "event" |
|
320 | + $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * setupModelsAndTables |
|
328 | + * |
|
329 | + * @param string $model_name |
|
330 | + * @throws EE_Error |
|
331 | + */ |
|
332 | + protected function setupModelsAndTables(string $model_name) |
|
333 | + { |
|
334 | + // get CPT table data via CPT Model |
|
335 | + $full_model_name = strpos($model_name, 'EEM_') !== 0 |
|
336 | + ? 'EEM_' . $model_name |
|
337 | + : $model_name; |
|
338 | + $model = $this->loader->getShared($full_model_name); |
|
339 | + if (! $model instanceof EEM_CPT_Base) { |
|
340 | + throw new EE_Error( |
|
341 | + sprintf( |
|
342 | + esc_html__( |
|
343 | + 'The "%1$s" model could not be loaded.', |
|
344 | + 'event_espresso' |
|
345 | + ), |
|
346 | + $full_model_name |
|
347 | + ) |
|
348 | + ); |
|
349 | + } |
|
350 | + $this->setModel($model); |
|
351 | + $this->setModelTables($this->model->get_tables()); |
|
352 | + $meta_model = $model_name . '_Meta'; |
|
353 | + // is there a Meta Table for this CPT? |
|
354 | + if ( |
|
355 | + isset($this->cpt_details['tables'][ $meta_model ]) |
|
356 | + && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table |
|
357 | + ) { |
|
358 | + $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]); |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * cptStrategyClass |
|
365 | + * |
|
366 | + * @param string $model_name |
|
367 | + * @return EE_CPT_Event_Strategy|EE_CPT_Attendee_Strategy|EE_CPT_Default_Strategy|EE_CPT_Venue_Strategy |
|
368 | + */ |
|
369 | + protected function cptStrategyClass(string $model_name) |
|
370 | + { |
|
371 | + // creates classname like: CPT_Event_Strategy |
|
372 | + $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy'; |
|
373 | + // load and instantiate |
|
374 | + $CPT_Strategy = $this->loader->getShared( |
|
375 | + $CPT_Strategy_class_name, |
|
376 | + ['WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details] |
|
377 | + ); |
|
378 | + if ($CPT_Strategy === null) { |
|
379 | + $CPT_Strategy = $this->loader->getShared( |
|
380 | + 'EE_CPT_Default_Strategy', |
|
381 | + ['WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details] |
|
382 | + ); |
|
383 | + } |
|
384 | + return $CPT_Strategy; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * @param string $SQL |
|
390 | + * @param WP_Query $wp_query |
|
391 | + * @return string |
|
392 | + */ |
|
393 | + public function postsFields(string $SQL, WP_Query $wp_query): string |
|
394 | + { |
|
395 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== $this->post_type) { |
|
396 | + return $SQL; |
|
397 | + } |
|
398 | + // does this CPT have a meta table ? |
|
399 | + if ($this->meta_table instanceof EE_Secondary_Table) { |
|
400 | + // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement |
|
401 | + $SQL .= ', ' . $this->meta_table->get_table_name() . '.* '; |
|
402 | + } |
|
403 | + remove_filter('posts_fields', [$this, 'postsFields']); |
|
404 | + return $SQL; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @param string $SQL |
|
410 | + * @param WP_Query $wp_query |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function postsJoin(string $SQL, WP_Query $wp_query): string |
|
414 | + { |
|
415 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== $this->post_type) { |
|
416 | + return $SQL; |
|
417 | + } |
|
418 | + // does this CPT have a meta table ? |
|
419 | + if ($this->meta_table instanceof EE_Secondary_Table) { |
|
420 | + global $wpdb; |
|
421 | + // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement |
|
422 | + $posts_table = $wpdb->posts; |
|
423 | + $meta_table = $this->meta_table->get_table_name(); |
|
424 | + $foreign_key = $this->meta_table->get_fk_on_table(); |
|
425 | + $SQL .= " LEFT JOIN $meta_table ON ( $meta_table.$foreign_key = $posts_table.ID ) "; |
|
426 | + } |
|
427 | + remove_filter('posts_join', [$this, 'postsJoin']); |
|
428 | + return $SQL; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * thePosts |
|
434 | + * |
|
435 | + * @param WP_Post[] $posts |
|
436 | + * @param WP_Query $wp_query |
|
437 | + * @return WP_Post[] |
|
438 | + */ |
|
439 | + public function thePosts(array $posts, WP_Query $wp_query): array |
|
440 | + { |
|
441 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== $this->post_type) { |
|
442 | + return $posts; |
|
443 | + } |
|
444 | + $CPT_class = $this->cpt_details['class_name']; |
|
445 | + // loop thru posts |
|
446 | + if ($this->model instanceof EEM_CPT_Base) { |
|
447 | + foreach ($posts as $post) { |
|
448 | + if ($post->post_type === $this->post_type) { |
|
449 | + $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post); |
|
450 | + } |
|
451 | + } |
|
452 | + } |
|
453 | + remove_filter('the_posts', [$this, 'thePosts'], 1); |
|
454 | + return $posts; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $url |
|
460 | + * @param int $ID |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public function getEditPostLink(string $url, int $ID): string |
|
464 | + { |
|
465 | + // need to make sure we only edit links if our cpt |
|
466 | + global $post; |
|
467 | + // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui |
|
468 | + // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin. |
|
469 | + if ( |
|
470 | + ! $post instanceof WP_Post |
|
471 | + || $post->post_type !== $this->post_type |
|
472 | + || ( |
|
473 | + isset($this->cpt_details['args']['show_ee_ui']) |
|
474 | + && ! $this->cpt_details['args']['show_ee_ui'] |
|
475 | + ) |
|
476 | + ) { |
|
477 | + return $url; |
|
478 | + } |
|
479 | + // k made it here so all is good. |
|
480 | + return wp_nonce_url( |
|
481 | + add_query_arg( |
|
482 | + ['page' => $this->post_type, 'post' => $ID, 'action' => 'edit'], |
|
483 | + admin_url('admin.php') |
|
484 | + ), |
|
485 | + 'edit', |
|
486 | + 'edit_nonce' |
|
487 | + ); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Execute any template filters. |
|
493 | + * This method is only called if in main query. |
|
494 | + * |
|
495 | + * @return void |
|
496 | + */ |
|
497 | + public function addTemplateFilters() |
|
498 | + { |
|
499 | + // if requested cpt supports page_templates and it's the main query |
|
500 | + if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
501 | + // then let's hook into the appropriate query_template hook |
|
502 | + add_filter('single_template', [$this, 'singleCptTemplate']); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * Callback for single_template wp filter. |
|
509 | + * This is used to load the set page_template for a single ee cpt if its set. If "default" then we load the normal |
|
510 | + * hierarchy. |
|
511 | + * |
|
512 | + * @param string $current_template Existing default template path derived for this page call. |
|
513 | + * @return string the path to the full template file. |
|
514 | + */ |
|
515 | + public function singleCptTemplate(string $current_template): string |
|
516 | + { |
|
517 | + $object = get_queried_object(); |
|
518 | + // does this called object HAVE a page template set that is something other than the default. |
|
519 | + $template = get_post_meta($object->ID, '_wp_page_template', true); |
|
520 | + // exit early if default or not set or invalid path (accounts for theme changes) |
|
521 | + if ( |
|
522 | + $template === 'default' |
|
523 | + || empty($template) |
|
524 | + || ! is_readable(get_stylesheet_directory() . '/' . $template) |
|
525 | + ) { |
|
526 | + return $current_template; |
|
527 | + } |
|
528 | + // made it here so we SHOULD be able to just locate the template and then return it. |
|
529 | + return locate_template([$template]); |
|
530 | + } |
|
531 | 531 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function request(): ?EE_Request_Handler |
188 | 188 | { |
189 | - if (! $this->request_handler instanceof EE_Request_Handler) { |
|
189 | + if ( ! $this->request_handler instanceof EE_Request_Handler) { |
|
190 | 190 | $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler'); |
191 | 191 | } |
192 | 192 | return $this->request_handler; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions(); |
227 | 227 | foreach ($taxonomies as $taxonomy => &$details) { |
228 | 228 | // add details to our taxonomies if they exist |
229 | - $details = $all_taxonomies[ $taxonomy ] ?? []; |
|
229 | + $details = $all_taxonomies[$taxonomy] ?? []; |
|
230 | 230 | } |
231 | 231 | // ALWAYS unset() variables that were passed by reference |
232 | 232 | unset($details); |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | public function setRequestVarsIfCpt() |
310 | 310 | { |
311 | 311 | // check if ee action var has been set |
312 | - if (! $this->request->requestParamIsSet('ee')) { |
|
312 | + if ( ! $this->request->requestParamIsSet('ee')) { |
|
313 | 313 | // check that route exists for CPT archive slug |
314 | 314 | if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) { |
315 | 315 | // ie: set "ee" to "events" |
@@ -333,10 +333,10 @@ discard block |
||
333 | 333 | { |
334 | 334 | // get CPT table data via CPT Model |
335 | 335 | $full_model_name = strpos($model_name, 'EEM_') !== 0 |
336 | - ? 'EEM_' . $model_name |
|
336 | + ? 'EEM_'.$model_name |
|
337 | 337 | : $model_name; |
338 | 338 | $model = $this->loader->getShared($full_model_name); |
339 | - if (! $model instanceof EEM_CPT_Base) { |
|
339 | + if ( ! $model instanceof EEM_CPT_Base) { |
|
340 | 340 | throw new EE_Error( |
341 | 341 | sprintf( |
342 | 342 | esc_html__( |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | } |
350 | 350 | $this->setModel($model); |
351 | 351 | $this->setModelTables($this->model->get_tables()); |
352 | - $meta_model = $model_name . '_Meta'; |
|
352 | + $meta_model = $model_name.'_Meta'; |
|
353 | 353 | // is there a Meta Table for this CPT? |
354 | 354 | if ( |
355 | - isset($this->cpt_details['tables'][ $meta_model ]) |
|
356 | - && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table |
|
355 | + isset($this->cpt_details['tables'][$meta_model]) |
|
356 | + && $this->cpt_details['tables'][$meta_model] instanceof EE_Secondary_Table |
|
357 | 357 | ) { |
358 | - $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]); |
|
358 | + $this->setMetaTable($this->cpt_details['tables'][$meta_model]); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | protected function cptStrategyClass(string $model_name) |
370 | 370 | { |
371 | 371 | // creates classname like: CPT_Event_Strategy |
372 | - $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy'; |
|
372 | + $CPT_Strategy_class_name = 'EE_CPT_'.$model_name.'_Strategy'; |
|
373 | 373 | // load and instantiate |
374 | 374 | $CPT_Strategy = $this->loader->getShared( |
375 | 375 | $CPT_Strategy_class_name, |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | // does this CPT have a meta table ? |
399 | 399 | if ($this->meta_table instanceof EE_Secondary_Table) { |
400 | 400 | // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement |
401 | - $SQL .= ', ' . $this->meta_table->get_table_name() . '.* '; |
|
401 | + $SQL .= ', '.$this->meta_table->get_table_name().'.* '; |
|
402 | 402 | } |
403 | 403 | remove_filter('posts_fields', [$this, 'postsFields']); |
404 | 404 | return $SQL; |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | public function addTemplateFilters() |
498 | 498 | { |
499 | 499 | // if requested cpt supports page_templates and it's the main query |
500 | - if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
500 | + if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
501 | 501 | // then let's hook into the appropriate query_template hook |
502 | 502 | add_filter('single_template', [$this, 'singleCptTemplate']); |
503 | 503 | } |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | if ( |
522 | 522 | $template === 'default' |
523 | 523 | || empty($template) |
524 | - || ! is_readable(get_stylesheet_directory() . '/' . $template) |
|
524 | + || ! is_readable(get_stylesheet_directory().'/'.$template) |
|
525 | 525 | ) { |
526 | 526 | return $current_template; |
527 | 527 | } |
@@ -9,34 +9,34 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_CPT_Attendee_Strategy |
11 | 11 | { |
12 | - /** |
|
13 | - * $CPT - the current page, if it utilizes CPTs |
|
14 | - * |
|
15 | - * @var array |
|
16 | - * @access protected |
|
17 | - */ |
|
18 | - protected $CPT = null; |
|
12 | + /** |
|
13 | + * $CPT - the current page, if it utilizes CPTs |
|
14 | + * |
|
15 | + * @var array |
|
16 | + * @access protected |
|
17 | + */ |
|
18 | + protected $CPT = null; |
|
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @param array $arguments |
|
23 | - */ |
|
24 | - public function __construct(array $arguments = []) |
|
25 | - { |
|
26 | - $this->CPT = $arguments['CPT'] ?? null; |
|
27 | - } |
|
21 | + /** |
|
22 | + * @param array $arguments |
|
23 | + */ |
|
24 | + public function __construct(array $arguments = []) |
|
25 | + { |
|
26 | + $this->CPT = $arguments['CPT'] ?? null; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * the_posts |
|
32 | - * |
|
33 | - * @access public |
|
34 | - * @param $posts |
|
35 | - * @param WP_Query $wp_query |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function the_posts($posts, WP_Query $wp_query) |
|
39 | - { |
|
40 | - return $posts; |
|
41 | - } |
|
30 | + /** |
|
31 | + * the_posts |
|
32 | + * |
|
33 | + * @access public |
|
34 | + * @param $posts |
|
35 | + * @param WP_Query $wp_query |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function the_posts($posts, WP_Query $wp_query) |
|
39 | + { |
|
40 | + return $posts; |
|
41 | + } |
|
42 | 42 | } |
@@ -11,57 +11,57 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_CPT_Venue_Strategy |
13 | 13 | { |
14 | - /** |
|
15 | - * $CPT - the current page, if it utilizes CPTs |
|
16 | - * |
|
17 | - * @var array|null |
|
18 | - */ |
|
19 | - protected ?array $CPT = null; |
|
14 | + /** |
|
15 | + * $CPT - the current page, if it utilizes CPTs |
|
16 | + * |
|
17 | + * @var array|null |
|
18 | + */ |
|
19 | + protected ?array $CPT = null; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param array|WP_Query|null $wp_query |
|
24 | - * @param array $CPT |
|
25 | - */ |
|
26 | - public function __construct($wp_query, array $CPT = []) |
|
27 | - { |
|
28 | - if (is_array($wp_query) && $wp_query['WP_Query'] instanceof WP_Query) { |
|
29 | - $this->CPT = $wp_query['CPT'] ?? $CPT; |
|
30 | - $wp_query = $wp_query['WP_Query']; |
|
31 | - } else { |
|
32 | - $this->CPT = $CPT; |
|
33 | - } |
|
34 | - if ($wp_query instanceof WP_Query && ! $wp_query->is_tag) { |
|
35 | - $wp_query->is_espresso_venue_single = is_singular() |
|
36 | - && ( |
|
37 | - (isset($wp_query->query->post_type) && $wp_query->query->post_type === EspressoPostType::VENUES) |
|
38 | - || (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === EspressoPostType::VENUES) |
|
39 | - ); |
|
40 | - $wp_query->is_espresso_venue_archive = is_post_type_archive(EspressoPostType::VENUES); |
|
41 | - $wp_query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories'); |
|
42 | - } |
|
43 | - add_filter('the_posts', [$this, 'the_posts'], 1, 2); |
|
44 | - } |
|
22 | + /** |
|
23 | + * @param array|WP_Query|null $wp_query |
|
24 | + * @param array $CPT |
|
25 | + */ |
|
26 | + public function __construct($wp_query, array $CPT = []) |
|
27 | + { |
|
28 | + if (is_array($wp_query) && $wp_query['WP_Query'] instanceof WP_Query) { |
|
29 | + $this->CPT = $wp_query['CPT'] ?? $CPT; |
|
30 | + $wp_query = $wp_query['WP_Query']; |
|
31 | + } else { |
|
32 | + $this->CPT = $CPT; |
|
33 | + } |
|
34 | + if ($wp_query instanceof WP_Query && ! $wp_query->is_tag) { |
|
35 | + $wp_query->is_espresso_venue_single = is_singular() |
|
36 | + && ( |
|
37 | + (isset($wp_query->query->post_type) && $wp_query->query->post_type === EspressoPostType::VENUES) |
|
38 | + || (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === EspressoPostType::VENUES) |
|
39 | + ); |
|
40 | + $wp_query->is_espresso_venue_archive = is_post_type_archive(EspressoPostType::VENUES); |
|
41 | + $wp_query->is_espresso_venue_taxonomy = is_tax('espresso_venue_categories'); |
|
42 | + } |
|
43 | + add_filter('the_posts', [$this, 'the_posts'], 1, 2); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @param array $posts |
|
49 | - * @param WP_Query $wp_query |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - public function the_posts(array $posts, WP_Query $wp_query): array |
|
53 | - { |
|
54 | - if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::VENUES) { |
|
55 | - return $posts; |
|
56 | - } |
|
57 | - // automagically load the EEH_Venue_View helper so that it's functions are available |
|
58 | - if ( |
|
59 | - isset(EE_Registry::instance()->CFG->map_settings->use_google_maps) |
|
60 | - && EE_Registry::instance()->CFG->map_settings->use_google_maps |
|
61 | - ) { |
|
62 | - EEH_Maps::espresso_google_map_js(); |
|
63 | - } |
|
64 | - remove_filter('the_posts', [$this, 'the_posts'], 1); |
|
65 | - return $posts; |
|
66 | - } |
|
47 | + /** |
|
48 | + * @param array $posts |
|
49 | + * @param WP_Query $wp_query |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + public function the_posts(array $posts, WP_Query $wp_query): array |
|
53 | + { |
|
54 | + if (EE_CPT_Strategy::instance()->wpQueryPostType($wp_query) !== EspressoPostType::VENUES) { |
|
55 | + return $posts; |
|
56 | + } |
|
57 | + // automagically load the EEH_Venue_View helper so that it's functions are available |
|
58 | + if ( |
|
59 | + isset(EE_Registry::instance()->CFG->map_settings->use_google_maps) |
|
60 | + && EE_Registry::instance()->CFG->map_settings->use_google_maps |
|
61 | + ) { |
|
62 | + EEH_Maps::espresso_google_map_js(); |
|
63 | + } |
|
64 | + remove_filter('the_posts', [$this, 'the_posts'], 1); |
|
65 | + return $posts; |
|
66 | + } |
|
67 | 67 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | $this->CPT = $CPT; |
33 | 33 | } |
34 | 34 | if ($wp_query instanceof WP_Query && ! $wp_query->is_tag) { |
35 | - $wp_query->is_espresso_venue_single = is_singular() |
|
35 | + $wp_query->is_espresso_venue_single = is_singular() |
|
36 | 36 | && ( |
37 | 37 | (isset($wp_query->query->post_type) && $wp_query->query->post_type === EspressoPostType::VENUES) |
38 | 38 | || (isset($wp_query->query['post_type']) && $wp_query->query['post_type'] === EspressoPostType::VENUES) |
@@ -15,716 +15,716 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class EEH_Debug_Tools |
17 | 17 | { |
18 | - /** |
|
19 | - * instance of the EEH_Autoloader object |
|
20 | - * |
|
21 | - * @var $_instance |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - private static $_instance; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $_memory_usage_points = array(); |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @singleton method used to instantiate class object |
|
35 | - * @access public |
|
36 | - * @return EEH_Debug_Tools |
|
37 | - */ |
|
38 | - public static function instance() |
|
39 | - { |
|
40 | - // check if class object is instantiated, and instantiated properly |
|
41 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
42 | - self::$_instance = new self(); |
|
43 | - } |
|
44 | - return self::$_instance; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * private class constructor |
|
51 | - */ |
|
52 | - private function __construct() |
|
53 | - { |
|
54 | - // load Kint PHP debugging library |
|
55 | - if ( |
|
56 | - defined('EE_LOAD_KINT') |
|
57 | - && ! class_exists('Kint') |
|
58 | - && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
59 | - ) { |
|
60 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
61 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
62 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
63 | - // so we've moved it to our test folder so that it is not included with production releases |
|
64 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
65 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
66 | - } |
|
67 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
68 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
69 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * show_db_name |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public static function show_db_name() |
|
81 | - { |
|
82 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
84 | - . DB_NAME |
|
85 | - . '</p>'; |
|
86 | - } |
|
87 | - if (EE_DEBUG) { |
|
88 | - Benchmark::displayResults(); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * dump EE_Session object at bottom of page after everything else has happened |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function espresso_session_footer_dump() |
|
100 | - { |
|
101 | - if ( |
|
102 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
103 | - && ! defined('DOING_AJAX') |
|
104 | - && class_exists('Kint') |
|
105 | - && function_exists('wp_get_current_user') |
|
106 | - && current_user_can('update_core') |
|
107 | - && class_exists('EE_Registry') |
|
108 | - ) { |
|
109 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
110 | - Kint::dump(EE_Registry::instance()->SSN); |
|
111 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
112 | - $this->espresso_list_hooked_functions(); |
|
113 | - Benchmark::displayResults(); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * List All Hooked Functions |
|
121 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
122 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
123 | - * |
|
124 | - * @param string $tag |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public function espresso_list_hooked_functions($tag = '') |
|
128 | - { |
|
129 | - global $wp_filter; |
|
130 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
131 | - if ($tag) { |
|
132 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
133 | - if (! is_array($hook[ $tag ])) { |
|
134 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
135 | - return; |
|
136 | - } |
|
137 | - echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
138 | - } else { |
|
139 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
140 | - ksort($hook); |
|
141 | - } |
|
142 | - foreach ($hook as $tag_name => $priorities) { |
|
143 | - echo "<br />>>>>>\t<strong>esc_html($tag_name)</strong><br />"; |
|
144 | - ksort($priorities); |
|
145 | - foreach ($priorities as $priority => $function) { |
|
146 | - echo esc_html($priority); |
|
147 | - foreach ($function as $name => $properties) { |
|
148 | - $name = esc_html($name); |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[ $hook_name ])) { |
|
168 | - $filters[ $hook_name ] = array(); |
|
169 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
170 | - $filters[ $hook_name ][ $priority ] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (empty($activation_errors)) { |
|
192 | - return; |
|
193 | - } |
|
194 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
195 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
196 | - if (class_exists('EEH_File')) { |
|
197 | - try { |
|
198 | - EEH_File::ensure_file_exists_and_is_writable( |
|
199 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
200 | - ); |
|
201 | - EEH_File::write_to_file( |
|
202 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
203 | - $activation_errors |
|
204 | - ); |
|
205 | - } catch (EE_Error $e) { |
|
206 | - EE_Error::add_error( |
|
207 | - sprintf( |
|
208 | - esc_html__( |
|
209 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
210 | - 'event_espresso' |
|
211 | - ), |
|
212 | - $e->getMessage() |
|
213 | - ), |
|
214 | - __FILE__, |
|
215 | - __FUNCTION__, |
|
216 | - __LINE__ |
|
217 | - ); |
|
218 | - } |
|
219 | - } else { |
|
220 | - // old school attempt |
|
221 | - file_put_contents( |
|
222 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
223 | - $activation_errors |
|
224 | - ); |
|
225 | - } |
|
226 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
227 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
235 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
236 | - * or we want to make sure they use something the right way. |
|
237 | - * |
|
238 | - * @access public |
|
239 | - * @param string $function The function that was called |
|
240 | - * @param string $message A message explaining what has been done incorrectly |
|
241 | - * @param string $version The version of Event Espresso where the error was added |
|
242 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
243 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
244 | - * but not have any notices appear until a later version. This allows developers |
|
245 | - * extra time to update their code before notices appear. |
|
246 | - * @param int $error_type |
|
247 | - * @uses trigger_error() |
|
248 | - */ |
|
249 | - public function doing_it_wrong( |
|
250 | - $function, |
|
251 | - $message, |
|
252 | - $version, |
|
253 | - $applies_when = '', |
|
254 | - $error_type = null |
|
255 | - ) { |
|
256 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
257 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
258 | - // because we swapped the parameter order around for the last two params, |
|
259 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
260 | - if (is_int($applies_when)) { |
|
261 | - $error_type = $applies_when; |
|
262 | - $applies_when = espresso_version(); |
|
263 | - } |
|
264 | - // if not displaying notices yet, then just leave |
|
265 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
266 | - return; |
|
267 | - } |
|
268 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
269 | - $version = $version === null |
|
270 | - ? '' |
|
271 | - : sprintf( |
|
272 | - esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
273 | - $version |
|
274 | - ); |
|
275 | - $error_message = sprintf( |
|
276 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
277 | - $function, |
|
278 | - '<strong>', |
|
279 | - '</strong>', |
|
280 | - $message, |
|
281 | - $version |
|
282 | - ); |
|
283 | - // don't trigger error if doing ajax, |
|
284 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
285 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
286 | - $error_message .= ' ' . esc_html__( |
|
287 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
288 | - 'event_espresso' |
|
289 | - ); |
|
290 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
291 | - $error_message .= '<ul><li>'; |
|
292 | - $error_message .= implode('</li><li>', $request->requestParams()); |
|
293 | - $error_message .= '</ul>'; |
|
294 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
295 | - // now we set this on the transient so it shows up on the next request. |
|
296 | - EE_Error::get_notices(false, true); |
|
297 | - } else { |
|
298 | - trigger_error($error_message, $error_type); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * Logger helpers |
|
307 | - */ |
|
308 | - /** |
|
309 | - * debug |
|
310 | - * |
|
311 | - * @param string $class |
|
312 | - * @param string $func |
|
313 | - * @param string $line |
|
314 | - * @param array $info |
|
315 | - * @param bool $display_request |
|
316 | - * @param string $debug_index |
|
317 | - * @param string $debug_key |
|
318 | - */ |
|
319 | - public static function log( |
|
320 | - $class = '', |
|
321 | - $func = '', |
|
322 | - $line = '', |
|
323 | - $info = array(), |
|
324 | - $display_request = false, |
|
325 | - $debug_index = '', |
|
326 | - $debug_key = 'EE_DEBUG_SPCO' |
|
327 | - ) { |
|
328 | - if (WP_DEBUG) { |
|
329 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
330 | - $debug_data = get_option($debug_key, array()); |
|
331 | - $default_data = array( |
|
332 | - $class => $func . '() : ' . $line, |
|
333 | - ); |
|
334 | - // don't serialize objects |
|
335 | - $info = self::strip_objects($info); |
|
336 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
337 | - if (! isset($debug_data[ $index ])) { |
|
338 | - $debug_data[ $index ] = array(); |
|
339 | - } |
|
340 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
341 | - update_option($debug_key, $debug_data); |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * strip_objects |
|
349 | - * |
|
350 | - * @param array $info |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public static function strip_objects($info = array()) |
|
354 | - { |
|
355 | - foreach ($info as $key => $value) { |
|
356 | - if (is_array($value)) { |
|
357 | - $info[ $key ] = self::strip_objects($value); |
|
358 | - } elseif (is_object($value)) { |
|
359 | - $object_class = get_class($value); |
|
360 | - $info[ $object_class ] = array(); |
|
361 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
362 | - if (method_exists($value, 'ID')) { |
|
363 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
364 | - } |
|
365 | - if (method_exists($value, 'status')) { |
|
366 | - $info[ $object_class ]['status'] = $value->status(); |
|
367 | - } elseif (method_exists($value, 'status_ID')) { |
|
368 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
369 | - } |
|
370 | - unset($info[ $key ]); |
|
371 | - } |
|
372 | - } |
|
373 | - return (array) $info; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * @param mixed $var |
|
380 | - * @param string $var_name |
|
381 | - * @param string $file |
|
382 | - * @param int|string $line |
|
383 | - * @param int|string $heading_tag |
|
384 | - * @param bool $die |
|
385 | - * @param string $margin |
|
386 | - */ |
|
387 | - public static function printv( |
|
388 | - $var, |
|
389 | - $var_name = '', |
|
390 | - $file = '', |
|
391 | - $line = '', |
|
392 | - $heading_tag = 5, |
|
393 | - $die = false, |
|
394 | - $margin = '' |
|
395 | - ) { |
|
396 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
397 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
398 | - $is_method = method_exists($var_name, $var); |
|
399 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
400 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
401 | - // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
402 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
403 | - $result .= $is_method |
|
404 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
405 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
406 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
407 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
408 | - if ($die) { |
|
409 | - die($result); |
|
410 | - } |
|
411 | - echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - protected static function headingTag($heading_tag) |
|
416 | - { |
|
417 | - $heading_tag = absint($heading_tag); |
|
418 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
419 | - } |
|
420 | - |
|
421 | - protected static function headingSpacer($heading_tag) |
|
422 | - { |
|
423 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
424 | - ? self::lineBreak() |
|
425 | - : ''; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - protected static function plainOutput() |
|
430 | - { |
|
431 | - return defined('EE_TESTS_DIR') |
|
432 | - || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output'])) |
|
433 | - || ( |
|
434 | - isset($_SERVER['REQUEST_URI']) |
|
435 | - && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * @param string $var_name |
|
442 | - * @param string $heading_tag |
|
443 | - * @param string $margin |
|
444 | - * @param int $line |
|
445 | - * @return string |
|
446 | - */ |
|
447 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
448 | - { |
|
449 | - if (EEH_Debug_Tools::plainOutput()) { |
|
450 | - switch ($heading_tag) { |
|
451 | - case 'h1': |
|
452 | - $line_breaks = EEH_Debug_Tools::lineBreak(3); |
|
453 | - break; |
|
454 | - case 'h2': |
|
455 | - $line_breaks = EEH_Debug_Tools::lineBreak(2); |
|
456 | - break; |
|
457 | - default: |
|
458 | - $line_breaks = EEH_Debug_Tools::lineBreak(); |
|
459 | - break; |
|
460 | - } |
|
461 | - return "{$line_breaks}{$line}) {$var_name}"; |
|
462 | - } |
|
463 | - $margin = "1rem 1rem .5rem {$margin}"; |
|
464 | - return ' |
|
18 | + /** |
|
19 | + * instance of the EEH_Autoloader object |
|
20 | + * |
|
21 | + * @var $_instance |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + private static $_instance; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $_memory_usage_points = array(); |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @singleton method used to instantiate class object |
|
35 | + * @access public |
|
36 | + * @return EEH_Debug_Tools |
|
37 | + */ |
|
38 | + public static function instance() |
|
39 | + { |
|
40 | + // check if class object is instantiated, and instantiated properly |
|
41 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
42 | + self::$_instance = new self(); |
|
43 | + } |
|
44 | + return self::$_instance; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * private class constructor |
|
51 | + */ |
|
52 | + private function __construct() |
|
53 | + { |
|
54 | + // load Kint PHP debugging library |
|
55 | + if ( |
|
56 | + defined('EE_LOAD_KINT') |
|
57 | + && ! class_exists('Kint') |
|
58 | + && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
59 | + ) { |
|
60 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
61 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
62 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
63 | + // so we've moved it to our test folder so that it is not included with production releases |
|
64 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
65 | + require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
66 | + } |
|
67 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
68 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
69 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * show_db_name |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public static function show_db_name() |
|
81 | + { |
|
82 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
84 | + . DB_NAME |
|
85 | + . '</p>'; |
|
86 | + } |
|
87 | + if (EE_DEBUG) { |
|
88 | + Benchmark::displayResults(); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * dump EE_Session object at bottom of page after everything else has happened |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function espresso_session_footer_dump() |
|
100 | + { |
|
101 | + if ( |
|
102 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
103 | + && ! defined('DOING_AJAX') |
|
104 | + && class_exists('Kint') |
|
105 | + && function_exists('wp_get_current_user') |
|
106 | + && current_user_can('update_core') |
|
107 | + && class_exists('EE_Registry') |
|
108 | + ) { |
|
109 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
110 | + Kint::dump(EE_Registry::instance()->SSN); |
|
111 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
112 | + $this->espresso_list_hooked_functions(); |
|
113 | + Benchmark::displayResults(); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * List All Hooked Functions |
|
121 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
122 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
123 | + * |
|
124 | + * @param string $tag |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public function espresso_list_hooked_functions($tag = '') |
|
128 | + { |
|
129 | + global $wp_filter; |
|
130 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
131 | + if ($tag) { |
|
132 | + $hook[ $tag ] = $wp_filter[ $tag ]; |
|
133 | + if (! is_array($hook[ $tag ])) { |
|
134 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
135 | + return; |
|
136 | + } |
|
137 | + echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
138 | + } else { |
|
139 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
140 | + ksort($hook); |
|
141 | + } |
|
142 | + foreach ($hook as $tag_name => $priorities) { |
|
143 | + echo "<br />>>>>>\t<strong>esc_html($tag_name)</strong><br />"; |
|
144 | + ksort($priorities); |
|
145 | + foreach ($priorities as $priority => $function) { |
|
146 | + echo esc_html($priority); |
|
147 | + foreach ($function as $name => $properties) { |
|
148 | + $name = esc_html($name); |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[ $hook_name ])) { |
|
168 | + $filters[ $hook_name ] = array(); |
|
169 | + foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
170 | + $filters[ $hook_name ][ $priority ] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (empty($activation_errors)) { |
|
192 | + return; |
|
193 | + } |
|
194 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
195 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
196 | + if (class_exists('EEH_File')) { |
|
197 | + try { |
|
198 | + EEH_File::ensure_file_exists_and_is_writable( |
|
199 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
200 | + ); |
|
201 | + EEH_File::write_to_file( |
|
202 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
203 | + $activation_errors |
|
204 | + ); |
|
205 | + } catch (EE_Error $e) { |
|
206 | + EE_Error::add_error( |
|
207 | + sprintf( |
|
208 | + esc_html__( |
|
209 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
210 | + 'event_espresso' |
|
211 | + ), |
|
212 | + $e->getMessage() |
|
213 | + ), |
|
214 | + __FILE__, |
|
215 | + __FUNCTION__, |
|
216 | + __LINE__ |
|
217 | + ); |
|
218 | + } |
|
219 | + } else { |
|
220 | + // old school attempt |
|
221 | + file_put_contents( |
|
222 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
223 | + $activation_errors |
|
224 | + ); |
|
225 | + } |
|
226 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
227 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
235 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
236 | + * or we want to make sure they use something the right way. |
|
237 | + * |
|
238 | + * @access public |
|
239 | + * @param string $function The function that was called |
|
240 | + * @param string $message A message explaining what has been done incorrectly |
|
241 | + * @param string $version The version of Event Espresso where the error was added |
|
242 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
243 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
244 | + * but not have any notices appear until a later version. This allows developers |
|
245 | + * extra time to update their code before notices appear. |
|
246 | + * @param int $error_type |
|
247 | + * @uses trigger_error() |
|
248 | + */ |
|
249 | + public function doing_it_wrong( |
|
250 | + $function, |
|
251 | + $message, |
|
252 | + $version, |
|
253 | + $applies_when = '', |
|
254 | + $error_type = null |
|
255 | + ) { |
|
256 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
257 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
258 | + // because we swapped the parameter order around for the last two params, |
|
259 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
260 | + if (is_int($applies_when)) { |
|
261 | + $error_type = $applies_when; |
|
262 | + $applies_when = espresso_version(); |
|
263 | + } |
|
264 | + // if not displaying notices yet, then just leave |
|
265 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
266 | + return; |
|
267 | + } |
|
268 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
269 | + $version = $version === null |
|
270 | + ? '' |
|
271 | + : sprintf( |
|
272 | + esc_html__('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
273 | + $version |
|
274 | + ); |
|
275 | + $error_message = sprintf( |
|
276 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
277 | + $function, |
|
278 | + '<strong>', |
|
279 | + '</strong>', |
|
280 | + $message, |
|
281 | + $version |
|
282 | + ); |
|
283 | + // don't trigger error if doing ajax, |
|
284 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
285 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
286 | + $error_message .= ' ' . esc_html__( |
|
287 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
288 | + 'event_espresso' |
|
289 | + ); |
|
290 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
291 | + $error_message .= '<ul><li>'; |
|
292 | + $error_message .= implode('</li><li>', $request->requestParams()); |
|
293 | + $error_message .= '</ul>'; |
|
294 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
295 | + // now we set this on the transient so it shows up on the next request. |
|
296 | + EE_Error::get_notices(false, true); |
|
297 | + } else { |
|
298 | + trigger_error($error_message, $error_type); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * Logger helpers |
|
307 | + */ |
|
308 | + /** |
|
309 | + * debug |
|
310 | + * |
|
311 | + * @param string $class |
|
312 | + * @param string $func |
|
313 | + * @param string $line |
|
314 | + * @param array $info |
|
315 | + * @param bool $display_request |
|
316 | + * @param string $debug_index |
|
317 | + * @param string $debug_key |
|
318 | + */ |
|
319 | + public static function log( |
|
320 | + $class = '', |
|
321 | + $func = '', |
|
322 | + $line = '', |
|
323 | + $info = array(), |
|
324 | + $display_request = false, |
|
325 | + $debug_index = '', |
|
326 | + $debug_key = 'EE_DEBUG_SPCO' |
|
327 | + ) { |
|
328 | + if (WP_DEBUG) { |
|
329 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
330 | + $debug_data = get_option($debug_key, array()); |
|
331 | + $default_data = array( |
|
332 | + $class => $func . '() : ' . $line, |
|
333 | + ); |
|
334 | + // don't serialize objects |
|
335 | + $info = self::strip_objects($info); |
|
336 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
337 | + if (! isset($debug_data[ $index ])) { |
|
338 | + $debug_data[ $index ] = array(); |
|
339 | + } |
|
340 | + $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
341 | + update_option($debug_key, $debug_data); |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * strip_objects |
|
349 | + * |
|
350 | + * @param array $info |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public static function strip_objects($info = array()) |
|
354 | + { |
|
355 | + foreach ($info as $key => $value) { |
|
356 | + if (is_array($value)) { |
|
357 | + $info[ $key ] = self::strip_objects($value); |
|
358 | + } elseif (is_object($value)) { |
|
359 | + $object_class = get_class($value); |
|
360 | + $info[ $object_class ] = array(); |
|
361 | + $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
362 | + if (method_exists($value, 'ID')) { |
|
363 | + $info[ $object_class ]['ID'] = $value->ID(); |
|
364 | + } |
|
365 | + if (method_exists($value, 'status')) { |
|
366 | + $info[ $object_class ]['status'] = $value->status(); |
|
367 | + } elseif (method_exists($value, 'status_ID')) { |
|
368 | + $info[ $object_class ]['status'] = $value->status_ID(); |
|
369 | + } |
|
370 | + unset($info[ $key ]); |
|
371 | + } |
|
372 | + } |
|
373 | + return (array) $info; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * @param mixed $var |
|
380 | + * @param string $var_name |
|
381 | + * @param string $file |
|
382 | + * @param int|string $line |
|
383 | + * @param int|string $heading_tag |
|
384 | + * @param bool $die |
|
385 | + * @param string $margin |
|
386 | + */ |
|
387 | + public static function printv( |
|
388 | + $var, |
|
389 | + $var_name = '', |
|
390 | + $file = '', |
|
391 | + $line = '', |
|
392 | + $heading_tag = 5, |
|
393 | + $die = false, |
|
394 | + $margin = '' |
|
395 | + ) { |
|
396 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
397 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
398 | + $is_method = method_exists($var_name, $var); |
|
399 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
400 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
401 | + // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
402 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
403 | + $result .= $is_method |
|
404 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
405 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
406 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
407 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
408 | + if ($die) { |
|
409 | + die($result); |
|
410 | + } |
|
411 | + echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + protected static function headingTag($heading_tag) |
|
416 | + { |
|
417 | + $heading_tag = absint($heading_tag); |
|
418 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
419 | + } |
|
420 | + |
|
421 | + protected static function headingSpacer($heading_tag) |
|
422 | + { |
|
423 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
424 | + ? self::lineBreak() |
|
425 | + : ''; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + protected static function plainOutput() |
|
430 | + { |
|
431 | + return defined('EE_TESTS_DIR') |
|
432 | + || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output'])) |
|
433 | + || ( |
|
434 | + isset($_SERVER['REQUEST_URI']) |
|
435 | + && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * @param string $var_name |
|
442 | + * @param string $heading_tag |
|
443 | + * @param string $margin |
|
444 | + * @param int $line |
|
445 | + * @return string |
|
446 | + */ |
|
447 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
448 | + { |
|
449 | + if (EEH_Debug_Tools::plainOutput()) { |
|
450 | + switch ($heading_tag) { |
|
451 | + case 'h1': |
|
452 | + $line_breaks = EEH_Debug_Tools::lineBreak(3); |
|
453 | + break; |
|
454 | + case 'h2': |
|
455 | + $line_breaks = EEH_Debug_Tools::lineBreak(2); |
|
456 | + break; |
|
457 | + default: |
|
458 | + $line_breaks = EEH_Debug_Tools::lineBreak(); |
|
459 | + break; |
|
460 | + } |
|
461 | + return "{$line_breaks}{$line}) {$var_name}"; |
|
462 | + } |
|
463 | + $margin = "1rem 1rem .5rem {$margin}"; |
|
464 | + return ' |
|
465 | 465 | <' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . '; position: sticky;"> |
466 | 466 | <b>' . $var_name . '</b>'; |
467 | - } |
|
467 | + } |
|
468 | 468 | |
469 | 469 | |
470 | 470 | |
471 | - /** |
|
472 | - * @param string $heading_tag |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - protected static function headingX($heading_tag = 'h5') |
|
476 | - { |
|
477 | - if (EEH_Debug_Tools::plainOutput()) { |
|
478 | - return ''; |
|
479 | - } |
|
480 | - return ' |
|
471 | + /** |
|
472 | + * @param string $heading_tag |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + protected static function headingX($heading_tag = 'h5') |
|
476 | + { |
|
477 | + if (EEH_Debug_Tools::plainOutput()) { |
|
478 | + return ''; |
|
479 | + } |
|
480 | + return ' |
|
481 | 481 | </' . $heading_tag . '>'; |
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $content |
|
488 | - * @return string |
|
489 | - */ |
|
490 | - protected static function grey_span($content = '') |
|
491 | - { |
|
492 | - if (EEH_Debug_Tools::plainOutput()) { |
|
493 | - return $content; |
|
494 | - } |
|
495 | - return '<span style="color:#999">' . $content . '</span>'; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param string $file |
|
502 | - * @param int $line |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - protected static function file_and_line($file, $line, $heading_tag) |
|
506 | - { |
|
507 | - if ($file === '' || $line === '') { |
|
508 | - return ''; |
|
509 | - } |
|
510 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
511 | - if (EEH_Debug_Tools::plainOutput()) { |
|
512 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
513 | - return " ({$file})" . EEH_Debug_Tools::lineBreak(); |
|
514 | - } |
|
515 | - return ''; |
|
516 | - } |
|
517 | - return EEH_Debug_Tools::lineBreak() |
|
518 | - . '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
519 | - . $file |
|
520 | - . EEH_Debug_Tools::lineBreak() |
|
521 | - . 'line no: ' |
|
522 | - . $line |
|
523 | - . '</span>'; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * @param string $content |
|
530 | - * @return string |
|
531 | - */ |
|
532 | - protected static function orange_span($content = '') |
|
533 | - { |
|
534 | - if (EEH_Debug_Tools::plainOutput()) { |
|
535 | - return $content; |
|
536 | - } |
|
537 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * @param mixed $var |
|
544 | - * @return string |
|
545 | - */ |
|
546 | - protected static function pre_span($var) |
|
547 | - { |
|
548 | - $var = var_export($var, true); |
|
549 | - if (EEH_Debug_Tools::plainOutput()) { |
|
550 | - return str_replace("\n", '', $var); |
|
551 | - } |
|
552 | - $style =[ |
|
553 | - 'background: #334', |
|
554 | - 'color: #9C3', |
|
555 | - 'display: inline-block', |
|
556 | - 'padding: .4em .6em', |
|
557 | - ]; |
|
558 | - return '<pre style="' . implode('; ', $style) . '">' . $var . '</pre>'; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * @param mixed $var |
|
565 | - * @param string $var_name |
|
566 | - * @param string $file |
|
567 | - * @param int|string $line |
|
568 | - * @param int|string $heading_tag |
|
569 | - * @param bool $die |
|
570 | - */ |
|
571 | - public static function printr( |
|
572 | - $var, |
|
573 | - $var_name = '', |
|
574 | - $file = '', |
|
575 | - $line = '', |
|
576 | - $heading_tag = 5, |
|
577 | - $die = false |
|
578 | - ) { |
|
579 | - // return; |
|
580 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
581 | - if (empty($var) && empty($var_name)) { |
|
582 | - $var = $file; |
|
583 | - $var_name = "line $line"; |
|
584 | - $file = ''; |
|
585 | - $line = ''; |
|
586 | - } |
|
587 | - $margin = is_admin() ? '180px' : '2rem'; |
|
588 | - if (is_string($var)) { |
|
589 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
590 | - return; |
|
591 | - } |
|
592 | - if (is_object($var)) { |
|
593 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
594 | - } elseif (is_array($var)) { |
|
595 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
596 | - } elseif (is_numeric($var)) { |
|
597 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
598 | - } elseif ($var === null) { |
|
599 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
600 | - } |
|
601 | - $var_name = EEH_Debug_Tools::trimVarName($var_name); |
|
602 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
603 | - // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
604 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
605 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
606 | - EEH_Debug_Tools::pre_span($var) |
|
607 | - ); |
|
608 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
609 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
610 | - if ($die) { |
|
611 | - die($result); |
|
612 | - } |
|
613 | - echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - private static function trimVarName($var_name): string |
|
618 | - { |
|
619 | - $converted = str_replace(['$', '_', 'this->'], ['', ' ', ''], $var_name); |
|
620 | - $words = explode(' ', $converted); |
|
621 | - $words = array_map( |
|
622 | - function ($word) { |
|
623 | - return $word === 'id' || $word === 'Id' ? 'ID' : $word; |
|
624 | - }, |
|
625 | - $words |
|
626 | - ); |
|
627 | - return ucwords(implode(' ', $words)); |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - private static function lineBreak($lines = 1): string |
|
632 | - { |
|
633 | - $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL; |
|
634 | - return str_repeat($linebreak, $lines); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - public static function shortClassName(string $fqcn): string |
|
639 | - { |
|
640 | - return substr(strrchr($fqcn, '\\'), 1); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - |
|
645 | - /******************** deprecated ********************/ |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * @deprecated 4.9.39.rc.034 |
|
651 | - */ |
|
652 | - public function reset_times() |
|
653 | - { |
|
654 | - Benchmark::resetTimes(); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * @deprecated 4.9.39.rc.034 |
|
661 | - * @param null $timer_name |
|
662 | - */ |
|
663 | - public function start_timer($timer_name = null) |
|
664 | - { |
|
665 | - Benchmark::startTimer($timer_name); |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * @deprecated 4.9.39.rc.034 |
|
672 | - * @param string $timer_name |
|
673 | - */ |
|
674 | - public function stop_timer($timer_name = '') |
|
675 | - { |
|
676 | - Benchmark::stopTimer($timer_name); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * @deprecated 4.9.39.rc.034 |
|
683 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
684 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
685 | - * @return void |
|
686 | - */ |
|
687 | - public function measure_memory($label, $output_now = false) |
|
688 | - { |
|
689 | - Benchmark::measureMemory($label, $output_now); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * @deprecated 4.9.39.rc.034 |
|
696 | - * @param int $size |
|
697 | - * @return string |
|
698 | - */ |
|
699 | - public function convert($size) |
|
700 | - { |
|
701 | - return Benchmark::convert($size); |
|
702 | - } |
|
703 | - |
|
704 | - |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $content |
|
488 | + * @return string |
|
489 | + */ |
|
490 | + protected static function grey_span($content = '') |
|
491 | + { |
|
492 | + if (EEH_Debug_Tools::plainOutput()) { |
|
493 | + return $content; |
|
494 | + } |
|
495 | + return '<span style="color:#999">' . $content . '</span>'; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param string $file |
|
502 | + * @param int $line |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + protected static function file_and_line($file, $line, $heading_tag) |
|
506 | + { |
|
507 | + if ($file === '' || $line === '') { |
|
508 | + return ''; |
|
509 | + } |
|
510 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
511 | + if (EEH_Debug_Tools::plainOutput()) { |
|
512 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
513 | + return " ({$file})" . EEH_Debug_Tools::lineBreak(); |
|
514 | + } |
|
515 | + return ''; |
|
516 | + } |
|
517 | + return EEH_Debug_Tools::lineBreak() |
|
518 | + . '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
519 | + . $file |
|
520 | + . EEH_Debug_Tools::lineBreak() |
|
521 | + . 'line no: ' |
|
522 | + . $line |
|
523 | + . '</span>'; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * @param string $content |
|
530 | + * @return string |
|
531 | + */ |
|
532 | + protected static function orange_span($content = '') |
|
533 | + { |
|
534 | + if (EEH_Debug_Tools::plainOutput()) { |
|
535 | + return $content; |
|
536 | + } |
|
537 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * @param mixed $var |
|
544 | + * @return string |
|
545 | + */ |
|
546 | + protected static function pre_span($var) |
|
547 | + { |
|
548 | + $var = var_export($var, true); |
|
549 | + if (EEH_Debug_Tools::plainOutput()) { |
|
550 | + return str_replace("\n", '', $var); |
|
551 | + } |
|
552 | + $style =[ |
|
553 | + 'background: #334', |
|
554 | + 'color: #9C3', |
|
555 | + 'display: inline-block', |
|
556 | + 'padding: .4em .6em', |
|
557 | + ]; |
|
558 | + return '<pre style="' . implode('; ', $style) . '">' . $var . '</pre>'; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * @param mixed $var |
|
565 | + * @param string $var_name |
|
566 | + * @param string $file |
|
567 | + * @param int|string $line |
|
568 | + * @param int|string $heading_tag |
|
569 | + * @param bool $die |
|
570 | + */ |
|
571 | + public static function printr( |
|
572 | + $var, |
|
573 | + $var_name = '', |
|
574 | + $file = '', |
|
575 | + $line = '', |
|
576 | + $heading_tag = 5, |
|
577 | + $die = false |
|
578 | + ) { |
|
579 | + // return; |
|
580 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
581 | + if (empty($var) && empty($var_name)) { |
|
582 | + $var = $file; |
|
583 | + $var_name = "line $line"; |
|
584 | + $file = ''; |
|
585 | + $line = ''; |
|
586 | + } |
|
587 | + $margin = is_admin() ? '180px' : '2rem'; |
|
588 | + if (is_string($var)) { |
|
589 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
590 | + return; |
|
591 | + } |
|
592 | + if (is_object($var)) { |
|
593 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
594 | + } elseif (is_array($var)) { |
|
595 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
596 | + } elseif (is_numeric($var)) { |
|
597 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
598 | + } elseif ($var === null) { |
|
599 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
600 | + } |
|
601 | + $var_name = EEH_Debug_Tools::trimVarName($var_name); |
|
602 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
603 | + // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
604 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
605 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
606 | + EEH_Debug_Tools::pre_span($var) |
|
607 | + ); |
|
608 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
609 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
610 | + if ($die) { |
|
611 | + die($result); |
|
612 | + } |
|
613 | + echo wp_kses($result, AllowedTags::getWithFormTags()); |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + private static function trimVarName($var_name): string |
|
618 | + { |
|
619 | + $converted = str_replace(['$', '_', 'this->'], ['', ' ', ''], $var_name); |
|
620 | + $words = explode(' ', $converted); |
|
621 | + $words = array_map( |
|
622 | + function ($word) { |
|
623 | + return $word === 'id' || $word === 'Id' ? 'ID' : $word; |
|
624 | + }, |
|
625 | + $words |
|
626 | + ); |
|
627 | + return ucwords(implode(' ', $words)); |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + private static function lineBreak($lines = 1): string |
|
632 | + { |
|
633 | + $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL; |
|
634 | + return str_repeat($linebreak, $lines); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + public static function shortClassName(string $fqcn): string |
|
639 | + { |
|
640 | + return substr(strrchr($fqcn, '\\'), 1); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + |
|
645 | + /******************** deprecated ********************/ |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * @deprecated 4.9.39.rc.034 |
|
651 | + */ |
|
652 | + public function reset_times() |
|
653 | + { |
|
654 | + Benchmark::resetTimes(); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * @deprecated 4.9.39.rc.034 |
|
661 | + * @param null $timer_name |
|
662 | + */ |
|
663 | + public function start_timer($timer_name = null) |
|
664 | + { |
|
665 | + Benchmark::startTimer($timer_name); |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * @deprecated 4.9.39.rc.034 |
|
672 | + * @param string $timer_name |
|
673 | + */ |
|
674 | + public function stop_timer($timer_name = '') |
|
675 | + { |
|
676 | + Benchmark::stopTimer($timer_name); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * @deprecated 4.9.39.rc.034 |
|
683 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
684 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
685 | + * @return void |
|
686 | + */ |
|
687 | + public function measure_memory($label, $output_now = false) |
|
688 | + { |
|
689 | + Benchmark::measureMemory($label, $output_now); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * @deprecated 4.9.39.rc.034 |
|
696 | + * @param int $size |
|
697 | + * @return string |
|
698 | + */ |
|
699 | + public function convert($size) |
|
700 | + { |
|
701 | + return Benchmark::convert($size); |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | 705 | |
706 | - /** |
|
707 | - * @deprecated 4.9.39.rc.034 |
|
708 | - * @param bool $output_now |
|
709 | - * @return string |
|
710 | - */ |
|
711 | - public function show_times($output_now = true) |
|
712 | - { |
|
713 | - return Benchmark::displayResults($output_now); |
|
714 | - } |
|
706 | + /** |
|
707 | + * @deprecated 4.9.39.rc.034 |
|
708 | + * @param bool $output_now |
|
709 | + * @return string |
|
710 | + */ |
|
711 | + public function show_times($output_now = true) |
|
712 | + { |
|
713 | + return Benchmark::displayResults($output_now); |
|
714 | + } |
|
715 | 715 | |
716 | 716 | |
717 | 717 | |
718 | - /** |
|
719 | - * @deprecated 4.9.39.rc.034 |
|
720 | - * @param string $timer_name |
|
721 | - * @param float $total_time |
|
722 | - * @return string |
|
723 | - */ |
|
724 | - public function format_time($timer_name, $total_time) |
|
725 | - { |
|
726 | - return Benchmark::formatTime($timer_name, $total_time); |
|
727 | - } |
|
718 | + /** |
|
719 | + * @deprecated 4.9.39.rc.034 |
|
720 | + * @param string $timer_name |
|
721 | + * @param float $total_time |
|
722 | + * @return string |
|
723 | + */ |
|
724 | + public function format_time($timer_name, $total_time) |
|
725 | + { |
|
726 | + return Benchmark::formatTime($timer_name, $total_time); |
|
727 | + } |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | |
@@ -734,31 +734,31 @@ discard block |
||
734 | 734 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
735 | 735 | */ |
736 | 736 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
737 | - function dump_wp_query() |
|
738 | - { |
|
739 | - global $wp_query; |
|
740 | - d($wp_query); |
|
741 | - } |
|
737 | + function dump_wp_query() |
|
738 | + { |
|
739 | + global $wp_query; |
|
740 | + d($wp_query); |
|
741 | + } |
|
742 | 742 | } |
743 | 743 | /** |
744 | 744 | * borrowed from Kint Debugger |
745 | 745 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
746 | 746 | */ |
747 | 747 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
748 | - function dump_wp() |
|
749 | - { |
|
750 | - global $wp; |
|
751 | - d($wp); |
|
752 | - } |
|
748 | + function dump_wp() |
|
749 | + { |
|
750 | + global $wp; |
|
751 | + d($wp); |
|
752 | + } |
|
753 | 753 | } |
754 | 754 | /** |
755 | 755 | * borrowed from Kint Debugger |
756 | 756 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
757 | 757 | */ |
758 | 758 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
759 | - function dump_post() |
|
760 | - { |
|
761 | - global $post; |
|
762 | - d($post); |
|
763 | - } |
|
759 | + function dump_post() |
|
760 | + { |
|
761 | + global $post; |
|
762 | + d($post); |
|
763 | + } |
|
764 | 764 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public static function instance() |
39 | 39 | { |
40 | 40 | // check if class object is instantiated, and instantiated properly |
41 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
41 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
42 | 42 | self::$_instance = new self(); |
43 | 43 | } |
44 | 44 | return self::$_instance; |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | if ( |
56 | 56 | defined('EE_LOAD_KINT') |
57 | 57 | && ! class_exists('Kint') |
58 | - && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php') |
|
58 | + && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php') |
|
59 | 59 | ) { |
60 | 60 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
61 | 61 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
62 | 62 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
63 | 63 | // so we've moved it to our test folder so that it is not included with production releases |
64 | 64 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
65 | - require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php'); |
|
65 | + require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php'); |
|
66 | 66 | } |
67 | 67 | $plugin = basename(EE_PLUGIN_DIR_PATH); |
68 | 68 | add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public static function show_db_name() |
81 | 81 | { |
82 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
82 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | 83 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
84 | 84 | . DB_NAME |
85 | 85 | . '</p>'; |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | global $wp_filter; |
130 | 130 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
131 | 131 | if ($tag) { |
132 | - $hook[ $tag ] = $wp_filter[ $tag ]; |
|
133 | - if (! is_array($hook[ $tag ])) { |
|
132 | + $hook[$tag] = $wp_filter[$tag]; |
|
133 | + if ( ! is_array($hook[$tag])) { |
|
134 | 134 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
135 | 135 | return; |
136 | 136 | } |
137 | - echo '<h5>For Tag: ' . esc_html($tag) . '</h5>'; |
|
137 | + echo '<h5>For Tag: '.esc_html($tag).'</h5>'; |
|
138 | 138 | } else { |
139 | 139 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
140 | 140 | ksort($hook); |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | { |
165 | 165 | $filters = array(); |
166 | 166 | global $wp_filter; |
167 | - if (isset($wp_filter[ $hook_name ])) { |
|
168 | - $filters[ $hook_name ] = array(); |
|
169 | - foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) { |
|
170 | - $filters[ $hook_name ][ $priority ] = array(); |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | 171 | foreach ($callbacks as $callback) { |
172 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
@@ -191,15 +191,15 @@ discard block |
||
191 | 191 | if (empty($activation_errors)) { |
192 | 192 | return; |
193 | 193 | } |
194 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
195 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
195 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
196 | 196 | if (class_exists('EEH_File')) { |
197 | 197 | try { |
198 | 198 | EEH_File::ensure_file_exists_and_is_writable( |
199 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html' |
|
199 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html' |
|
200 | 200 | ); |
201 | 201 | EEH_File::write_to_file( |
202 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
202 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
203 | 203 | $activation_errors |
204 | 204 | ); |
205 | 205 | } catch (EE_Error $e) { |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | } else { |
220 | 220 | // old school attempt |
221 | 221 | file_put_contents( |
222 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html', |
|
222 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html', |
|
223 | 223 | $activation_errors |
224 | 224 | ); |
225 | 225 | } |
226 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
226 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
227 | 227 | update_option('ee_plugin_activation_errors', $activation_errors); |
228 | 228 | } |
229 | 229 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | // don't trigger error if doing ajax, |
284 | 284 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
285 | 285 | if (defined('DOING_AJAX') && DOING_AJAX) { |
286 | - $error_message .= ' ' . esc_html__( |
|
286 | + $error_message .= ' '.esc_html__( |
|
287 | 287 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
288 | 288 | 'event_espresso' |
289 | 289 | ); |
@@ -326,18 +326,18 @@ discard block |
||
326 | 326 | $debug_key = 'EE_DEBUG_SPCO' |
327 | 327 | ) { |
328 | 328 | if (WP_DEBUG) { |
329 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
329 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
330 | 330 | $debug_data = get_option($debug_key, array()); |
331 | 331 | $default_data = array( |
332 | - $class => $func . '() : ' . $line, |
|
332 | + $class => $func.'() : '.$line, |
|
333 | 333 | ); |
334 | 334 | // don't serialize objects |
335 | 335 | $info = self::strip_objects($info); |
336 | 336 | $index = ! empty($debug_index) ? $debug_index : 0; |
337 | - if (! isset($debug_data[ $index ])) { |
|
338 | - $debug_data[ $index ] = array(); |
|
337 | + if ( ! isset($debug_data[$index])) { |
|
338 | + $debug_data[$index] = array(); |
|
339 | 339 | } |
340 | - $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info); |
|
340 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
341 | 341 | update_option($debug_key, $debug_data); |
342 | 342 | } |
343 | 343 | } |
@@ -354,20 +354,20 @@ discard block |
||
354 | 354 | { |
355 | 355 | foreach ($info as $key => $value) { |
356 | 356 | if (is_array($value)) { |
357 | - $info[ $key ] = self::strip_objects($value); |
|
357 | + $info[$key] = self::strip_objects($value); |
|
358 | 358 | } elseif (is_object($value)) { |
359 | 359 | $object_class = get_class($value); |
360 | - $info[ $object_class ] = array(); |
|
361 | - $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
360 | + $info[$object_class] = array(); |
|
361 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
362 | 362 | if (method_exists($value, 'ID')) { |
363 | - $info[ $object_class ]['ID'] = $value->ID(); |
|
363 | + $info[$object_class]['ID'] = $value->ID(); |
|
364 | 364 | } |
365 | 365 | if (method_exists($value, 'status')) { |
366 | - $info[ $object_class ]['status'] = $value->status(); |
|
366 | + $info[$object_class]['status'] = $value->status(); |
|
367 | 367 | } elseif (method_exists($value, 'status_ID')) { |
368 | - $info[ $object_class ]['status'] = $value->status_ID(); |
|
368 | + $info[$object_class]['status'] = $value->status_ID(); |
|
369 | 369 | } |
370 | - unset($info[ $key ]); |
|
370 | + unset($info[$key]); |
|
371 | 371 | } |
372 | 372 | } |
373 | 373 | return (array) $info; |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
402 | 402 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
403 | 403 | $result .= $is_method |
404 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
405 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
405 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
406 | 406 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
407 | 407 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
408 | 408 | if ($die) { |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | } |
463 | 463 | $margin = "1rem 1rem .5rem {$margin}"; |
464 | 464 | return ' |
465 | - <' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . '; position: sticky;"> |
|
466 | - <b>' . $var_name . '</b>'; |
|
465 | + <' . $heading_tag.' style="color:#2EA2CC; margin:'.$margin.'; position: sticky;"> |
|
466 | + <b>' . $var_name.'</b>'; |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | return ''; |
479 | 479 | } |
480 | 480 | return ' |
481 | - </' . $heading_tag . '>'; |
|
481 | + </' . $heading_tag.'>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | if (EEH_Debug_Tools::plainOutput()) { |
493 | 493 | return $content; |
494 | 494 | } |
495 | - return '<span style="color:#999">' . $content . '</span>'; |
|
495 | + return '<span style="color:#999">'.$content.'</span>'; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
511 | 511 | if (EEH_Debug_Tools::plainOutput()) { |
512 | 512 | if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
513 | - return " ({$file})" . EEH_Debug_Tools::lineBreak(); |
|
513 | + return " ({$file})".EEH_Debug_Tools::lineBreak(); |
|
514 | 514 | } |
515 | 515 | return ''; |
516 | 516 | } |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | if (EEH_Debug_Tools::plainOutput()) { |
535 | 535 | return $content; |
536 | 536 | } |
537 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
537 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | |
@@ -549,13 +549,13 @@ discard block |
||
549 | 549 | if (EEH_Debug_Tools::plainOutput()) { |
550 | 550 | return str_replace("\n", '', $var); |
551 | 551 | } |
552 | - $style =[ |
|
552 | + $style = [ |
|
553 | 553 | 'background: #334', |
554 | 554 | 'color: #9C3', |
555 | 555 | 'display: inline-block', |
556 | 556 | 'padding: .4em .6em', |
557 | 557 | ]; |
558 | - return '<pre style="' . implode('; ', $style) . '">' . $var . '</pre>'; |
|
558 | + return '<pre style="'.implode('; ', $style).'">'.$var.'</pre>'; |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
603 | 603 | // $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
604 | 604 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
605 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
605 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
606 | 606 | EEH_Debug_Tools::pre_span($var) |
607 | 607 | ); |
608 | 608 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | $converted = str_replace(['$', '_', 'this->'], ['', ' ', ''], $var_name); |
620 | 620 | $words = explode(' ', $converted); |
621 | 621 | $words = array_map( |
622 | - function ($word) { |
|
622 | + function($word) { |
|
623 | 623 | return $word === 'id' || $word === 'Id' ? 'ID' : $word; |
624 | 624 | }, |
625 | 625 | $words |