@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <p class="about-description"> |
2 | 2 | <?php esc_html_e( |
3 | - 'Event Espresso is created by an international team of passionate individuals with a drive to empower your events!', |
|
4 | - 'event_espresso' |
|
5 | - ); ?></p> |
|
3 | + 'Event Espresso is created by an international team of passionate individuals with a drive to empower your events!', |
|
4 | + 'event_espresso' |
|
5 | + ); ?></p> |
|
6 | 6 | <h3 class="wp-people-group"><?php esc_html_e('Founders', 'event_espresso'); ?></h3> |
7 | 7 | <ul class="wp-people-group" id="ee-people-group-owners"> |
8 | 8 | <li class="wp-person" id="ee-person-sshoultes"> |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | <h3 class="wp-people-group"><?php esc_html_e('Contributor Recognition', 'event_espresso'); ?></h3> |
86 | 86 | <p class="description"> |
87 | 87 | <?php printf( |
88 | - esc_html__( |
|
89 | - 'For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', |
|
93 | - '</a>' |
|
94 | - ); ?> |
|
88 | + esc_html__( |
|
89 | + 'For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', |
|
93 | + '</a>' |
|
94 | + ); ?> |
|
95 | 95 | </p> |
96 | 96 | <p class="wp-credits-list"> |
97 | 97 | <ul> |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | <h3 class="wp-people-group"><?php esc_html_e('External Libraries', 'event_espresso'); ?></h3> |
107 | 107 | <p class="description"> |
108 | 108 | <?php printf( |
109 | - esc_html__( |
|
110 | - 'Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', |
|
111 | - 'event_espresso' |
|
112 | - ), |
|
113 | - '<a href="credits.php">', |
|
114 | - '</a>' |
|
115 | - ); ?> |
|
109 | + esc_html__( |
|
110 | + 'Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', |
|
111 | + 'event_espresso' |
|
112 | + ), |
|
113 | + '<a href="credits.php">', |
|
114 | + '</a>' |
|
115 | + ); ?> |
|
116 | 116 | </p> |
117 | 117 | <p class="wp-credits-list"> |
118 | 118 | <a href="https://openexchangerates.github.io/accounting.js/">accounting.js</a>, |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | <?php |
130 | 130 | function esp_gravatar_profile($email) |
131 | 131 | { |
132 | - echo 'https://www.gravatar.com/' . md5($email); |
|
132 | + echo 'https://www.gravatar.com/' . md5($email); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | function esp_gravatar_image($email, $name) |
136 | 136 | { |
137 | - echo '<img src="https://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
137 | + echo '<img src="https://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | ?> |
@@ -129,12 +129,12 @@ |
||
129 | 129 | <?php |
130 | 130 | function esp_gravatar_profile($email) |
131 | 131 | { |
132 | - echo 'https://www.gravatar.com/' . md5($email); |
|
132 | + echo 'https://www.gravatar.com/'.md5($email); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | function esp_gravatar_image($email, $name) |
136 | 136 | { |
137 | - echo '<img src="https://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
137 | + echo '<img src="https://0.gravatar.com/avatar/'.md5($email).'?s=60" class="gravatar" alt="'.$name.'"/>'; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | ?> |
@@ -1,225 +1,225 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EE_Default_Line_Item_Display_Strategy |
|
5 | - * |
|
6 | - * Description |
|
7 | - * |
|
8 | - * @package Event Espresso |
|
9 | - * @subpackage core |
|
10 | - * @author Brent Christensen |
|
11 | - * |
|
12 | - * |
|
13 | - */ |
|
3 | + * |
|
4 | + * Class EE_Default_Line_Item_Display_Strategy |
|
5 | + * |
|
6 | + * Description |
|
7 | + * |
|
8 | + * @package Event Espresso |
|
9 | + * @subpackage core |
|
10 | + * @author Brent Christensen |
|
11 | + * |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | |
15 | 15 | class EE_Default_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * total amount of tax to apply |
|
20 | - * @type float $_tax_rate |
|
21 | - */ |
|
22 | - private $_tax_rate = 0; |
|
23 | - |
|
24 | - /** |
|
25 | - * total amount including tax we can bill for at this time |
|
26 | - * @type float $_grand_total |
|
27 | - */ |
|
28 | - private $_grand_total = 0.00; |
|
29 | - |
|
30 | - /** |
|
31 | - * total number of items being billed for |
|
32 | - * @type int $_total_items |
|
33 | - */ |
|
34 | - private $_total_items = 0; |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @return float |
|
40 | - */ |
|
41 | - public function grand_total() |
|
42 | - { |
|
43 | - return $this->_grand_total; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - public function total_items() |
|
52 | - { |
|
53 | - return $this->_total_items; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param EE_Line_Item $line_item |
|
60 | - * @param array $options |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
64 | - { |
|
65 | - |
|
66 | - $html = ''; |
|
67 | - // set some default options and merge with incoming |
|
68 | - $default_options = array( |
|
69 | - 'show_desc' => true, // TRUE FALSE |
|
70 | - 'odd' => false |
|
71 | - ); |
|
72 | - $options = array_merge($default_options, (array) $options); |
|
73 | - |
|
74 | - switch ($line_item->type()) { |
|
75 | - case EEM_Line_Item::type_line_item: |
|
76 | - // item row |
|
77 | - $html .= $this->_item_row($line_item, $options); |
|
78 | - // got any kids? |
|
79 | - foreach ($line_item->children() as $child_line_item) { |
|
80 | - $this->display_line_item($child_line_item, $options); |
|
81 | - } |
|
82 | - break; |
|
83 | - |
|
84 | - case EEM_Line_Item::type_sub_line_item: |
|
85 | - $html .= $this->_sub_item_row($line_item, $options); |
|
86 | - break; |
|
87 | - |
|
88 | - case EEM_Line_Item::type_sub_total: |
|
89 | - break; |
|
90 | - |
|
91 | - case EEM_Line_Item::type_tax: |
|
92 | - $this->_tax_rate += $line_item->percent(); |
|
93 | - break; |
|
94 | - |
|
95 | - case EEM_Line_Item::type_tax_sub_total: |
|
96 | - foreach ($line_item->children() as $child_line_item) { |
|
97 | - if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
98 | - // recursively feed children back into this method |
|
99 | - $this->display_line_item($child_line_item, $options); |
|
100 | - } |
|
101 | - } |
|
102 | - break; |
|
103 | - |
|
104 | - case EEM_Line_Item::type_total: |
|
105 | - // get all child line items |
|
106 | - $children = $line_item->children(); |
|
107 | - if ($options['set_tax_rate'] === true) { |
|
108 | - // loop thru tax child line items just to determine tax rate |
|
109 | - foreach ($children as $child_line_item) { |
|
110 | - if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { |
|
111 | - // recursively feed children back into this method |
|
112 | - $this->display_line_item($child_line_item, $options); |
|
113 | - } |
|
114 | - } |
|
115 | - } else { |
|
116 | - // now loop thru all non-tax child line items |
|
117 | - foreach ($children as $child_line_item) { |
|
118 | - if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { |
|
119 | - // recursively feed children back into this method |
|
120 | - $html .= $this->display_line_item($child_line_item, $options); |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - break; |
|
125 | - } |
|
126 | - |
|
127 | - return $html; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * _total_row |
|
134 | - * |
|
135 | - * @param EE_Line_Item $line_item |
|
136 | - * @param array $options |
|
137 | - * @return mixed |
|
138 | - */ |
|
139 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
140 | - { |
|
141 | - // start of row |
|
142 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
143 | - $html = EEH_HTML::tr('', '', $row_class); |
|
144 | - // name && desc |
|
145 | - $name_and_desc = apply_filters( |
|
146 | - 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name', |
|
147 | - $line_item->name(), |
|
148 | - $line_item |
|
149 | - ); |
|
150 | - $name_and_desc .= apply_filters( |
|
151 | - 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc', |
|
152 | - ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ), |
|
153 | - $line_item, |
|
154 | - $options |
|
155 | - ); |
|
156 | - if ($line_item->is_taxable()) { |
|
157 | - $ticket_price_includes_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes |
|
158 | - ? esc_html__('* price includes taxes', 'event_espresso') |
|
159 | - : esc_html__('* price does not include taxes', 'event_espresso'); |
|
160 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
161 | - . $ticket_price_includes_taxes |
|
162 | - . '</span>'; |
|
163 | - } |
|
164 | - |
|
165 | - // name td |
|
166 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
167 | - // quantity td |
|
168 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
169 | - $tax_rate = $line_item->is_taxable() |
|
170 | - && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes |
|
171 | - ? 1 + ( $this->_tax_rate / 100 ) |
|
172 | - : 1; |
|
173 | - // price td |
|
174 | - $unit_price = apply_filters( |
|
175 | - 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price', |
|
176 | - EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false), |
|
177 | - $line_item, |
|
178 | - $tax_rate |
|
179 | - ); |
|
180 | - $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght'); |
|
181 | - // total td |
|
182 | - $total = apply_filters( |
|
183 | - 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total', |
|
184 | - EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false), |
|
185 | - $line_item, |
|
186 | - $tax_rate |
|
187 | - ); |
|
188 | - $html .= EEH_HTML::td($total, '', 'item_r jst-rght'); |
|
189 | - // end of row |
|
190 | - $html .= EEH_HTML::trx(); |
|
191 | - |
|
192 | - return $html; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * _sub_item_row |
|
199 | - * |
|
200 | - * @param EE_Line_Item $line_item |
|
201 | - * @param array $options |
|
202 | - * @return mixed |
|
203 | - */ |
|
204 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
205 | - { |
|
206 | - // start of row |
|
207 | - $html = EEH_HTML::tr('', 'item sub-item-row'); |
|
208 | - // name && desc |
|
209 | - $name_and_desc = $line_item->name(); |
|
210 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : ''; |
|
211 | - // name td |
|
212 | - $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item'); |
|
213 | - // discount/surcharge td |
|
214 | - if ($line_item->is_percent()) { |
|
215 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c'); |
|
216 | - } else { |
|
217 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
218 | - } |
|
219 | - // total td |
|
220 | - $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght'); |
|
221 | - // end of row |
|
222 | - $html .= EEH_HTML::trx(); |
|
223 | - return $html; |
|
224 | - } |
|
18 | + /** |
|
19 | + * total amount of tax to apply |
|
20 | + * @type float $_tax_rate |
|
21 | + */ |
|
22 | + private $_tax_rate = 0; |
|
23 | + |
|
24 | + /** |
|
25 | + * total amount including tax we can bill for at this time |
|
26 | + * @type float $_grand_total |
|
27 | + */ |
|
28 | + private $_grand_total = 0.00; |
|
29 | + |
|
30 | + /** |
|
31 | + * total number of items being billed for |
|
32 | + * @type int $_total_items |
|
33 | + */ |
|
34 | + private $_total_items = 0; |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @return float |
|
40 | + */ |
|
41 | + public function grand_total() |
|
42 | + { |
|
43 | + return $this->_grand_total; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + public function total_items() |
|
52 | + { |
|
53 | + return $this->_total_items; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param EE_Line_Item $line_item |
|
60 | + * @param array $options |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
64 | + { |
|
65 | + |
|
66 | + $html = ''; |
|
67 | + // set some default options and merge with incoming |
|
68 | + $default_options = array( |
|
69 | + 'show_desc' => true, // TRUE FALSE |
|
70 | + 'odd' => false |
|
71 | + ); |
|
72 | + $options = array_merge($default_options, (array) $options); |
|
73 | + |
|
74 | + switch ($line_item->type()) { |
|
75 | + case EEM_Line_Item::type_line_item: |
|
76 | + // item row |
|
77 | + $html .= $this->_item_row($line_item, $options); |
|
78 | + // got any kids? |
|
79 | + foreach ($line_item->children() as $child_line_item) { |
|
80 | + $this->display_line_item($child_line_item, $options); |
|
81 | + } |
|
82 | + break; |
|
83 | + |
|
84 | + case EEM_Line_Item::type_sub_line_item: |
|
85 | + $html .= $this->_sub_item_row($line_item, $options); |
|
86 | + break; |
|
87 | + |
|
88 | + case EEM_Line_Item::type_sub_total: |
|
89 | + break; |
|
90 | + |
|
91 | + case EEM_Line_Item::type_tax: |
|
92 | + $this->_tax_rate += $line_item->percent(); |
|
93 | + break; |
|
94 | + |
|
95 | + case EEM_Line_Item::type_tax_sub_total: |
|
96 | + foreach ($line_item->children() as $child_line_item) { |
|
97 | + if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
98 | + // recursively feed children back into this method |
|
99 | + $this->display_line_item($child_line_item, $options); |
|
100 | + } |
|
101 | + } |
|
102 | + break; |
|
103 | + |
|
104 | + case EEM_Line_Item::type_total: |
|
105 | + // get all child line items |
|
106 | + $children = $line_item->children(); |
|
107 | + if ($options['set_tax_rate'] === true) { |
|
108 | + // loop thru tax child line items just to determine tax rate |
|
109 | + foreach ($children as $child_line_item) { |
|
110 | + if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { |
|
111 | + // recursively feed children back into this method |
|
112 | + $this->display_line_item($child_line_item, $options); |
|
113 | + } |
|
114 | + } |
|
115 | + } else { |
|
116 | + // now loop thru all non-tax child line items |
|
117 | + foreach ($children as $child_line_item) { |
|
118 | + if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { |
|
119 | + // recursively feed children back into this method |
|
120 | + $html .= $this->display_line_item($child_line_item, $options); |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + break; |
|
125 | + } |
|
126 | + |
|
127 | + return $html; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * _total_row |
|
134 | + * |
|
135 | + * @param EE_Line_Item $line_item |
|
136 | + * @param array $options |
|
137 | + * @return mixed |
|
138 | + */ |
|
139 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
140 | + { |
|
141 | + // start of row |
|
142 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
143 | + $html = EEH_HTML::tr('', '', $row_class); |
|
144 | + // name && desc |
|
145 | + $name_and_desc = apply_filters( |
|
146 | + 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name', |
|
147 | + $line_item->name(), |
|
148 | + $line_item |
|
149 | + ); |
|
150 | + $name_and_desc .= apply_filters( |
|
151 | + 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc', |
|
152 | + ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ), |
|
153 | + $line_item, |
|
154 | + $options |
|
155 | + ); |
|
156 | + if ($line_item->is_taxable()) { |
|
157 | + $ticket_price_includes_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes |
|
158 | + ? esc_html__('* price includes taxes', 'event_espresso') |
|
159 | + : esc_html__('* price does not include taxes', 'event_espresso'); |
|
160 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
161 | + . $ticket_price_includes_taxes |
|
162 | + . '</span>'; |
|
163 | + } |
|
164 | + |
|
165 | + // name td |
|
166 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
167 | + // quantity td |
|
168 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
169 | + $tax_rate = $line_item->is_taxable() |
|
170 | + && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes |
|
171 | + ? 1 + ( $this->_tax_rate / 100 ) |
|
172 | + : 1; |
|
173 | + // price td |
|
174 | + $unit_price = apply_filters( |
|
175 | + 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price', |
|
176 | + EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false), |
|
177 | + $line_item, |
|
178 | + $tax_rate |
|
179 | + ); |
|
180 | + $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght'); |
|
181 | + // total td |
|
182 | + $total = apply_filters( |
|
183 | + 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total', |
|
184 | + EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false), |
|
185 | + $line_item, |
|
186 | + $tax_rate |
|
187 | + ); |
|
188 | + $html .= EEH_HTML::td($total, '', 'item_r jst-rght'); |
|
189 | + // end of row |
|
190 | + $html .= EEH_HTML::trx(); |
|
191 | + |
|
192 | + return $html; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * _sub_item_row |
|
199 | + * |
|
200 | + * @param EE_Line_Item $line_item |
|
201 | + * @param array $options |
|
202 | + * @return mixed |
|
203 | + */ |
|
204 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
205 | + { |
|
206 | + // start of row |
|
207 | + $html = EEH_HTML::tr('', 'item sub-item-row'); |
|
208 | + // name && desc |
|
209 | + $name_and_desc = $line_item->name(); |
|
210 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : ''; |
|
211 | + // name td |
|
212 | + $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item'); |
|
213 | + // discount/surcharge td |
|
214 | + if ($line_item->is_percent()) { |
|
215 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c'); |
|
216 | + } else { |
|
217 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
218 | + } |
|
219 | + // total td |
|
220 | + $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght'); |
|
221 | + // end of row |
|
222 | + $html .= EEH_HTML::trx(); |
|
223 | + return $html; |
|
224 | + } |
|
225 | 225 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $html = ''; |
67 | 67 | // set some default options and merge with incoming |
68 | 68 | $default_options = array( |
69 | - 'show_desc' => true, // TRUE FALSE |
|
69 | + 'show_desc' => true, // TRUE FALSE |
|
70 | 70 | 'odd' => false |
71 | 71 | ); |
72 | 72 | $options = array_merge($default_options, (array) $options); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | ); |
150 | 150 | $name_and_desc .= apply_filters( |
151 | 151 | 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc', |
152 | - ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ), |
|
152 | + ($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''), |
|
153 | 153 | $line_item, |
154 | 154 | $options |
155 | 155 | ); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
169 | 169 | $tax_rate = $line_item->is_taxable() |
170 | 170 | && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes |
171 | - ? 1 + ( $this->_tax_rate / 100 ) |
|
171 | + ? 1 + ($this->_tax_rate / 100) |
|
172 | 172 | : 1; |
173 | 173 | // price td |
174 | 174 | $unit_price = apply_filters( |
@@ -207,12 +207,12 @@ discard block |
||
207 | 207 | $html = EEH_HTML::tr('', 'item sub-item-row'); |
208 | 208 | // name && desc |
209 | 209 | $name_and_desc = $line_item->name(); |
210 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : ''; |
|
210 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''; |
|
211 | 211 | // name td |
212 | 212 | $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item'); |
213 | 213 | // discount/surcharge td |
214 | 214 | if ($line_item->is_percent()) { |
215 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c'); |
|
215 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c'); |
|
216 | 216 | } else { |
217 | 217 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
218 | 218 | } |
@@ -27,474 +27,474 @@ discard block |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * This gets set in _setup_cpt |
|
32 | - * It will contain the object for the custom post type. |
|
33 | - * |
|
34 | - * @var EE_CPT_Base |
|
35 | - */ |
|
36 | - protected $_cpt_object; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
41 | - * |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - protected $_cpt_route = false; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
49 | - * //in this array we define what the custom post type for this route is. |
|
50 | - * array( |
|
51 | - * 'route_name' => 'custom_post_type_slug' |
|
52 | - * ) |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $_cpt_routes = array(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
61 | - * in this format: |
|
62 | - * array( |
|
63 | - * 'post_type_slug' => 'edit_route' |
|
64 | - * ) |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $_cpt_edit_routes = array(); |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
73 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
74 | - * _cpt_model_names property should be in the following format: array( |
|
75 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
76 | - * |
|
77 | - * @var array $_cpt_model_names |
|
78 | - */ |
|
79 | - protected $_cpt_model_names = array(); |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @var EE_CPT_Base |
|
84 | - */ |
|
85 | - protected $_cpt_model_obj = false; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
90 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
91 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
92 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
93 | - * |
|
94 | - * @var array() |
|
95 | - */ |
|
96 | - protected $_autosave_containers = array(); |
|
97 | - protected $_autosave_fields = array(); |
|
98 | - |
|
99 | - /** |
|
100 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
101 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
102 | - * |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - protected $_pagenow_map; |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
110 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
111 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
112 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
113 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
114 | - * |
|
115 | - * @access protected |
|
116 | - * @abstract |
|
117 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
118 | - * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
126 | - * |
|
127 | - * @abstract |
|
128 | - * @access public |
|
129 | - * @param string $post_id The ID of the cpt that was trashed |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - abstract public function trash_cpt_item($post_id); |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
137 | - * |
|
138 | - * @param string $post_id theID of the cpt that was untrashed |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - abstract public function restore_cpt_item($post_id); |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
146 | - * from the db |
|
147 | - * |
|
148 | - * @param string $post_id the ID of the cpt that was deleted |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - abstract public function delete_cpt_item($post_id); |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
156 | - * |
|
157 | - * @access protected |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - protected function _before_page_setup() |
|
161 | - { |
|
162 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
163 | - $this->_cpt_routes = array_merge( |
|
164 | - array( |
|
165 | - 'create_new' => $this->page_slug, |
|
166 | - 'edit' => $this->page_slug, |
|
167 | - 'trash' => $this->page_slug, |
|
168 | - ), |
|
169 | - $this->_cpt_routes |
|
170 | - ); |
|
171 | - // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
172 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
173 | - ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
174 | - : get_post_type_object($page); |
|
175 | - // tweak pagenow for page loading. |
|
176 | - if (! $this->_pagenow_map) { |
|
177 | - $this->_pagenow_map = array( |
|
178 | - 'create_new' => 'post-new.php', |
|
179 | - 'edit' => 'post.php', |
|
180 | - 'trash' => 'post.php', |
|
181 | - ); |
|
182 | - } |
|
183 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
184 | - // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
185 | - // get current page from autosave |
|
186 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
187 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
188 | - : null; |
|
189 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
190 | - ? $this->_req_data['current_page'] |
|
191 | - : $current_page; |
|
192 | - // autosave... make sure its only for the correct page |
|
193 | - // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
194 | - // setup autosave ajax hook |
|
195 | - // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
196 | - // } |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
202 | - * |
|
203 | - * @param WP_Screen $current_screen |
|
204 | - * @return void |
|
205 | - */ |
|
206 | - public function modify_pagenow($current_screen) |
|
207 | - { |
|
208 | - global $pagenow, $hook_suffix; |
|
209 | - // possibly reset pagenow. |
|
210 | - if (! empty($this->_req_data['page']) |
|
211 | - && $this->_req_data['page'] == $this->page_slug |
|
212 | - && ! empty($this->_req_data['action']) |
|
213 | - && isset($this->_pagenow_map[ $this->_req_data['action'] ]) |
|
214 | - ) { |
|
215 | - $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ]; |
|
216 | - $hook_suffix = $pagenow; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
223 | - * |
|
224 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
225 | - * automatically register the id for the post metabox as a container. |
|
226 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
227 | - * you would send along the id of a metabox container. |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - protected function _register_autosave_containers($ids) |
|
231 | - { |
|
232 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
238 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
239 | - */ |
|
240 | - protected function _set_autosave_containers() |
|
241 | - { |
|
242 | - global $wp_meta_boxes; |
|
243 | - $containers = array(); |
|
244 | - if (empty($wp_meta_boxes)) { |
|
245 | - return; |
|
246 | - } |
|
247 | - $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array(); |
|
248 | - foreach ($current_metaboxes as $box_context) { |
|
249 | - foreach ($box_context as $box_details) { |
|
250 | - foreach ($box_details as $box) { |
|
251 | - if (is_array($box['callback']) |
|
252 | - && ( |
|
253 | - $box['callback'][0] instanceof EE_Admin_Page |
|
254 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
255 | - ) |
|
256 | - ) { |
|
257 | - $containers[] = $box['id']; |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
263 | - // add hidden inputs container |
|
264 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - protected function _load_autosave_scripts_styles() |
|
269 | - { |
|
270 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
30 | + /** |
|
31 | + * This gets set in _setup_cpt |
|
32 | + * It will contain the object for the custom post type. |
|
33 | + * |
|
34 | + * @var EE_CPT_Base |
|
35 | + */ |
|
36 | + protected $_cpt_object; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
41 | + * |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + protected $_cpt_route = false; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
49 | + * //in this array we define what the custom post type for this route is. |
|
50 | + * array( |
|
51 | + * 'route_name' => 'custom_post_type_slug' |
|
52 | + * ) |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $_cpt_routes = array(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
61 | + * in this format: |
|
62 | + * array( |
|
63 | + * 'post_type_slug' => 'edit_route' |
|
64 | + * ) |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $_cpt_edit_routes = array(); |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
73 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
74 | + * _cpt_model_names property should be in the following format: array( |
|
75 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
76 | + * |
|
77 | + * @var array $_cpt_model_names |
|
78 | + */ |
|
79 | + protected $_cpt_model_names = array(); |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @var EE_CPT_Base |
|
84 | + */ |
|
85 | + protected $_cpt_model_obj = false; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
90 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
91 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
92 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
93 | + * |
|
94 | + * @var array() |
|
95 | + */ |
|
96 | + protected $_autosave_containers = array(); |
|
97 | + protected $_autosave_fields = array(); |
|
98 | + |
|
99 | + /** |
|
100 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
101 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
102 | + * |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + protected $_pagenow_map; |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
110 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
111 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
112 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
113 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
114 | + * |
|
115 | + * @access protected |
|
116 | + * @abstract |
|
117 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
118 | + * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
126 | + * |
|
127 | + * @abstract |
|
128 | + * @access public |
|
129 | + * @param string $post_id The ID of the cpt that was trashed |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + abstract public function trash_cpt_item($post_id); |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
137 | + * |
|
138 | + * @param string $post_id theID of the cpt that was untrashed |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + abstract public function restore_cpt_item($post_id); |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
146 | + * from the db |
|
147 | + * |
|
148 | + * @param string $post_id the ID of the cpt that was deleted |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + abstract public function delete_cpt_item($post_id); |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
156 | + * |
|
157 | + * @access protected |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + protected function _before_page_setup() |
|
161 | + { |
|
162 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
163 | + $this->_cpt_routes = array_merge( |
|
164 | + array( |
|
165 | + 'create_new' => $this->page_slug, |
|
166 | + 'edit' => $this->page_slug, |
|
167 | + 'trash' => $this->page_slug, |
|
168 | + ), |
|
169 | + $this->_cpt_routes |
|
170 | + ); |
|
171 | + // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
172 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
173 | + ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
174 | + : get_post_type_object($page); |
|
175 | + // tweak pagenow for page loading. |
|
176 | + if (! $this->_pagenow_map) { |
|
177 | + $this->_pagenow_map = array( |
|
178 | + 'create_new' => 'post-new.php', |
|
179 | + 'edit' => 'post.php', |
|
180 | + 'trash' => 'post.php', |
|
181 | + ); |
|
182 | + } |
|
183 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
184 | + // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
185 | + // get current page from autosave |
|
186 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
187 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
188 | + : null; |
|
189 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
190 | + ? $this->_req_data['current_page'] |
|
191 | + : $current_page; |
|
192 | + // autosave... make sure its only for the correct page |
|
193 | + // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
194 | + // setup autosave ajax hook |
|
195 | + // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
196 | + // } |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
202 | + * |
|
203 | + * @param WP_Screen $current_screen |
|
204 | + * @return void |
|
205 | + */ |
|
206 | + public function modify_pagenow($current_screen) |
|
207 | + { |
|
208 | + global $pagenow, $hook_suffix; |
|
209 | + // possibly reset pagenow. |
|
210 | + if (! empty($this->_req_data['page']) |
|
211 | + && $this->_req_data['page'] == $this->page_slug |
|
212 | + && ! empty($this->_req_data['action']) |
|
213 | + && isset($this->_pagenow_map[ $this->_req_data['action'] ]) |
|
214 | + ) { |
|
215 | + $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ]; |
|
216 | + $hook_suffix = $pagenow; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
223 | + * |
|
224 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
225 | + * automatically register the id for the post metabox as a container. |
|
226 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
227 | + * you would send along the id of a metabox container. |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + protected function _register_autosave_containers($ids) |
|
231 | + { |
|
232 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
238 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
239 | + */ |
|
240 | + protected function _set_autosave_containers() |
|
241 | + { |
|
242 | + global $wp_meta_boxes; |
|
243 | + $containers = array(); |
|
244 | + if (empty($wp_meta_boxes)) { |
|
245 | + return; |
|
246 | + } |
|
247 | + $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array(); |
|
248 | + foreach ($current_metaboxes as $box_context) { |
|
249 | + foreach ($box_context as $box_details) { |
|
250 | + foreach ($box_details as $box) { |
|
251 | + if (is_array($box['callback']) |
|
252 | + && ( |
|
253 | + $box['callback'][0] instanceof EE_Admin_Page |
|
254 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
255 | + ) |
|
256 | + ) { |
|
257 | + $containers[] = $box['id']; |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
263 | + // add hidden inputs container |
|
264 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + protected function _load_autosave_scripts_styles() |
|
269 | + { |
|
270 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
271 | 271 | wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2 |
272 | 272 | |
273 | - // filter _autosave_containers |
|
274 | - $containers = apply_filters( |
|
275 | - 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
276 | - $this->_autosave_containers, |
|
277 | - $this |
|
278 | - ); |
|
279 | - $containers = apply_filters( |
|
280 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
281 | - $containers, |
|
282 | - $this |
|
283 | - ); |
|
284 | - |
|
285 | - wp_localize_script( |
|
286 | - 'event_editor_js', |
|
287 | - 'EE_AUTOSAVE_IDS', |
|
288 | - $containers |
|
289 | - ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
290 | - |
|
291 | - $unsaved_data_msg = array( |
|
292 | - 'eventmsg' => sprintf( |
|
293 | - __( |
|
294 | - "The changes you made to this %s will be lost if you navigate away from this page.", |
|
295 | - 'event_espresso' |
|
296 | - ), |
|
297 | - $this->_cpt_object->labels->singular_name |
|
298 | - ), |
|
299 | - 'inputChanged' => 0, |
|
300 | - ); |
|
301 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - public function load_page_dependencies() |
|
306 | - { |
|
307 | - try { |
|
308 | - $this->_load_page_dependencies(); |
|
309 | - } catch (EE_Error $e) { |
|
310 | - $e->get_error(); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
317 | - * |
|
318 | - * @access protected |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - protected function _load_page_dependencies() |
|
322 | - { |
|
323 | - // we only add stuff if this is a cpt_route! |
|
324 | - if (! $this->_cpt_route) { |
|
325 | - parent::_load_page_dependencies(); |
|
326 | - return; |
|
327 | - } |
|
328 | - // now let's do some automatic filters into the wp_system |
|
329 | - // and we'll check to make sure the CHILD class |
|
330 | - // automatically has the required methods in place. |
|
331 | - // the following filters are for setting all the redirects |
|
332 | - // on DEFAULT WP custom post type actions |
|
333 | - // let's add a hidden input to the post-edit form |
|
334 | - // so we know when we have to trigger our custom redirects! |
|
335 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
336 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
337 | - // inject our Admin page nav tabs... |
|
338 | - // let's make sure the nav tabs are set if they aren't already |
|
339 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
340 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
341 | - // modify the post_updated messages array |
|
342 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
343 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
344 | - // cpts use the same format for shortlinks as posts! |
|
345 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
346 | - // This basically allows us to change the title of the "publish" metabox area |
|
347 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
348 | - if (! empty($this->_labels['publishbox'])) { |
|
349 | - $box_label = is_array($this->_labels['publishbox']) |
|
350 | - && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
351 | - ? $this->_labels['publishbox'][ $this->_req_action ] |
|
352 | - : $this->_labels['publishbox']; |
|
353 | - add_meta_box( |
|
354 | - 'submitdiv', |
|
355 | - $box_label, |
|
356 | - 'post_submit_meta_box', |
|
357 | - $this->_cpt_routes[ $this->_req_action ], |
|
358 | - 'side', |
|
359 | - 'core' |
|
360 | - ); |
|
361 | - } |
|
362 | - // let's add page_templates metabox if this cpt added support for it. |
|
363 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
364 | - add_meta_box( |
|
365 | - 'page_templates', |
|
366 | - __('Page Template', 'event_espresso'), |
|
367 | - array($this, 'page_template_meta_box'), |
|
368 | - $this->_cpt_routes[ $this->_req_action ], |
|
369 | - 'side', |
|
370 | - 'default' |
|
371 | - ); |
|
372 | - } |
|
373 | - // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
374 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
375 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
376 | - } |
|
377 | - // add preview button |
|
378 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
379 | - // insert our own post_stati dropdown |
|
380 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
381 | - // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
382 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
383 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
384 | - } |
|
385 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
386 | - // This is also before the wp_editor for post description field. |
|
387 | - if (method_exists($this, 'edit_form_after_title')) { |
|
388 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
389 | - } |
|
390 | - /** |
|
391 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
392 | - */ |
|
393 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
394 | - parent::_load_page_dependencies(); |
|
395 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
396 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
397 | - // This is for any plugins that are doing things properly |
|
398 | - // and hooking into the load page hook for core wp cpt routes. |
|
399 | - global $pagenow; |
|
400 | - add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20); |
|
401 | - do_action('load-' . $pagenow); |
|
402 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
403 | - // we route REALLY early. |
|
404 | - try { |
|
405 | - $this->_route_admin_request(); |
|
406 | - } catch (EE_Error $e) { |
|
407 | - $e->get_error(); |
|
408 | - } |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
414 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
415 | - * route instead. |
|
416 | - * |
|
417 | - * @param string $good_protocol_url The escaped url. |
|
418 | - * @param string $original_url The original url. |
|
419 | - * @param string $_context The context sent to the esc_url method. |
|
420 | - * @return string possibly a new url for our route. |
|
421 | - */ |
|
422 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
423 | - { |
|
424 | - $routes_to_match = array( |
|
425 | - 0 => array( |
|
426 | - 'edit.php?post_type=espresso_attendees', |
|
427 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
428 | - ), |
|
429 | - 1 => array( |
|
430 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | - ), |
|
433 | - ); |
|
434 | - foreach ($routes_to_match as $route_matches) { |
|
435 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
436 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
437 | - } |
|
438 | - } |
|
439 | - return $good_protocol_url; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * Determine whether the current cpt supports page templates or not. |
|
445 | - * |
|
446 | - * @since %VER% |
|
447 | - * @param string $cpt_name The cpt slug we're checking on. |
|
448 | - * @return bool True supported, false not. |
|
449 | - * @throws InvalidArgumentException |
|
450 | - * @throws InvalidDataTypeException |
|
451 | - * @throws InvalidInterfaceException |
|
452 | - */ |
|
453 | - private function _supports_page_templates($cpt_name) |
|
454 | - { |
|
455 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
456 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
457 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
458 | - ); |
|
459 | - $cpt_args = $custom_post_types->getDefinitions(); |
|
460 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array(); |
|
461 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
462 | - |
|
463 | - // if the installed version of WP is > 4.7 we do some additional checks. |
|
464 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
465 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
466 | - // if there are $post_templates for this cpt, then we return false for this method because |
|
467 | - // that means we aren't going to load our page template manager and leave that up to the native |
|
468 | - // cpt template manager. |
|
469 | - $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
470 | - } |
|
471 | - |
|
472 | - return $cpt_has_support; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Callback for the page_templates metabox selector. |
|
478 | - * |
|
479 | - * @since %VER% |
|
480 | - * @return void |
|
481 | - */ |
|
482 | - public function page_template_meta_box() |
|
483 | - { |
|
484 | - global $post; |
|
485 | - $template = ''; |
|
486 | - |
|
487 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
488 | - $page_template_count = count(get_page_templates()); |
|
489 | - } else { |
|
490 | - $page_template_count = count(get_page_templates($post)); |
|
491 | - }; |
|
492 | - |
|
493 | - if ($page_template_count) { |
|
494 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
495 | - $template = ! empty($page_template) ? $page_template : ''; |
|
496 | - } |
|
497 | - ?> |
|
273 | + // filter _autosave_containers |
|
274 | + $containers = apply_filters( |
|
275 | + 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
276 | + $this->_autosave_containers, |
|
277 | + $this |
|
278 | + ); |
|
279 | + $containers = apply_filters( |
|
280 | + 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
281 | + $containers, |
|
282 | + $this |
|
283 | + ); |
|
284 | + |
|
285 | + wp_localize_script( |
|
286 | + 'event_editor_js', |
|
287 | + 'EE_AUTOSAVE_IDS', |
|
288 | + $containers |
|
289 | + ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
290 | + |
|
291 | + $unsaved_data_msg = array( |
|
292 | + 'eventmsg' => sprintf( |
|
293 | + __( |
|
294 | + "The changes you made to this %s will be lost if you navigate away from this page.", |
|
295 | + 'event_espresso' |
|
296 | + ), |
|
297 | + $this->_cpt_object->labels->singular_name |
|
298 | + ), |
|
299 | + 'inputChanged' => 0, |
|
300 | + ); |
|
301 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + public function load_page_dependencies() |
|
306 | + { |
|
307 | + try { |
|
308 | + $this->_load_page_dependencies(); |
|
309 | + } catch (EE_Error $e) { |
|
310 | + $e->get_error(); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
317 | + * |
|
318 | + * @access protected |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + protected function _load_page_dependencies() |
|
322 | + { |
|
323 | + // we only add stuff if this is a cpt_route! |
|
324 | + if (! $this->_cpt_route) { |
|
325 | + parent::_load_page_dependencies(); |
|
326 | + return; |
|
327 | + } |
|
328 | + // now let's do some automatic filters into the wp_system |
|
329 | + // and we'll check to make sure the CHILD class |
|
330 | + // automatically has the required methods in place. |
|
331 | + // the following filters are for setting all the redirects |
|
332 | + // on DEFAULT WP custom post type actions |
|
333 | + // let's add a hidden input to the post-edit form |
|
334 | + // so we know when we have to trigger our custom redirects! |
|
335 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
336 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
337 | + // inject our Admin page nav tabs... |
|
338 | + // let's make sure the nav tabs are set if they aren't already |
|
339 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
340 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
341 | + // modify the post_updated messages array |
|
342 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
343 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
344 | + // cpts use the same format for shortlinks as posts! |
|
345 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
346 | + // This basically allows us to change the title of the "publish" metabox area |
|
347 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
348 | + if (! empty($this->_labels['publishbox'])) { |
|
349 | + $box_label = is_array($this->_labels['publishbox']) |
|
350 | + && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
351 | + ? $this->_labels['publishbox'][ $this->_req_action ] |
|
352 | + : $this->_labels['publishbox']; |
|
353 | + add_meta_box( |
|
354 | + 'submitdiv', |
|
355 | + $box_label, |
|
356 | + 'post_submit_meta_box', |
|
357 | + $this->_cpt_routes[ $this->_req_action ], |
|
358 | + 'side', |
|
359 | + 'core' |
|
360 | + ); |
|
361 | + } |
|
362 | + // let's add page_templates metabox if this cpt added support for it. |
|
363 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
364 | + add_meta_box( |
|
365 | + 'page_templates', |
|
366 | + __('Page Template', 'event_espresso'), |
|
367 | + array($this, 'page_template_meta_box'), |
|
368 | + $this->_cpt_routes[ $this->_req_action ], |
|
369 | + 'side', |
|
370 | + 'default' |
|
371 | + ); |
|
372 | + } |
|
373 | + // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
374 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
375 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
376 | + } |
|
377 | + // add preview button |
|
378 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
379 | + // insert our own post_stati dropdown |
|
380 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
381 | + // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
382 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
383 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
384 | + } |
|
385 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
386 | + // This is also before the wp_editor for post description field. |
|
387 | + if (method_exists($this, 'edit_form_after_title')) { |
|
388 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
389 | + } |
|
390 | + /** |
|
391 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
392 | + */ |
|
393 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
394 | + parent::_load_page_dependencies(); |
|
395 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
396 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
397 | + // This is for any plugins that are doing things properly |
|
398 | + // and hooking into the load page hook for core wp cpt routes. |
|
399 | + global $pagenow; |
|
400 | + add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20); |
|
401 | + do_action('load-' . $pagenow); |
|
402 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
403 | + // we route REALLY early. |
|
404 | + try { |
|
405 | + $this->_route_admin_request(); |
|
406 | + } catch (EE_Error $e) { |
|
407 | + $e->get_error(); |
|
408 | + } |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
414 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
415 | + * route instead. |
|
416 | + * |
|
417 | + * @param string $good_protocol_url The escaped url. |
|
418 | + * @param string $original_url The original url. |
|
419 | + * @param string $_context The context sent to the esc_url method. |
|
420 | + * @return string possibly a new url for our route. |
|
421 | + */ |
|
422 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
423 | + { |
|
424 | + $routes_to_match = array( |
|
425 | + 0 => array( |
|
426 | + 'edit.php?post_type=espresso_attendees', |
|
427 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
428 | + ), |
|
429 | + 1 => array( |
|
430 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | + ), |
|
433 | + ); |
|
434 | + foreach ($routes_to_match as $route_matches) { |
|
435 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
436 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
437 | + } |
|
438 | + } |
|
439 | + return $good_protocol_url; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * Determine whether the current cpt supports page templates or not. |
|
445 | + * |
|
446 | + * @since %VER% |
|
447 | + * @param string $cpt_name The cpt slug we're checking on. |
|
448 | + * @return bool True supported, false not. |
|
449 | + * @throws InvalidArgumentException |
|
450 | + * @throws InvalidDataTypeException |
|
451 | + * @throws InvalidInterfaceException |
|
452 | + */ |
|
453 | + private function _supports_page_templates($cpt_name) |
|
454 | + { |
|
455 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
456 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
457 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
458 | + ); |
|
459 | + $cpt_args = $custom_post_types->getDefinitions(); |
|
460 | + $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array(); |
|
461 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
462 | + |
|
463 | + // if the installed version of WP is > 4.7 we do some additional checks. |
|
464 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
465 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
466 | + // if there are $post_templates for this cpt, then we return false for this method because |
|
467 | + // that means we aren't going to load our page template manager and leave that up to the native |
|
468 | + // cpt template manager. |
|
469 | + $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
470 | + } |
|
471 | + |
|
472 | + return $cpt_has_support; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Callback for the page_templates metabox selector. |
|
478 | + * |
|
479 | + * @since %VER% |
|
480 | + * @return void |
|
481 | + */ |
|
482 | + public function page_template_meta_box() |
|
483 | + { |
|
484 | + global $post; |
|
485 | + $template = ''; |
|
486 | + |
|
487 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
488 | + $page_template_count = count(get_page_templates()); |
|
489 | + } else { |
|
490 | + $page_template_count = count(get_page_templates($post)); |
|
491 | + }; |
|
492 | + |
|
493 | + if ($page_template_count) { |
|
494 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
495 | + $template = ! empty($page_template) ? $page_template : ''; |
|
496 | + } |
|
497 | + ?> |
|
498 | 498 | <p><strong><?php _e('Template', 'event_espresso') ?></strong></p> |
499 | 499 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select |
500 | 500 | name="page_template" id="page_template"> |
@@ -502,468 +502,468 @@ discard block |
||
502 | 502 | <?php page_template_dropdown($template); ?> |
503 | 503 | </select> |
504 | 504 | <?php |
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
510 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
511 | - * |
|
512 | - * @param string $return the current html |
|
513 | - * @param int $id the post id for the page |
|
514 | - * @param string $new_title What the title is |
|
515 | - * @param string $new_slug what the slug is |
|
516 | - * @return string The new html string for the permalink area |
|
517 | - */ |
|
518 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
519 | - { |
|
520 | - $post = get_post($id); |
|
521 | - if ('publish' !== get_post_status($post)) { |
|
522 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
523 | - . get_preview_post_link($id) |
|
524 | - . '" class="button button-small">' |
|
525 | - . __('Preview', 'event_espresso') |
|
526 | - . '</a></span>' |
|
527 | - . "\n"; |
|
528 | - } |
|
529 | - return $return; |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
535 | - * |
|
536 | - * @return void |
|
537 | - */ |
|
538 | - public function custom_post_stati_dropdown() |
|
539 | - { |
|
540 | - |
|
541 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
542 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
543 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
544 | - : ''; |
|
545 | - $template_args = array( |
|
546 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
547 | - 'statuses' => $statuses, |
|
548 | - 'cur_status_label' => $cur_status_label, |
|
549 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
550 | - ); |
|
551 | - // we'll add a trash post status (WP doesn't add one for some reason) |
|
552 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
553 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
554 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
555 | - $template_args['statuses'] = $statuses; |
|
556 | - } |
|
557 | - |
|
558 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
559 | - EEH_Template::display_template($template, $template_args); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - public function setup_autosave_hooks() |
|
564 | - { |
|
565 | - $this->_set_autosave_containers(); |
|
566 | - $this->_load_autosave_scripts_styles(); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
572 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
573 | - * for the nonce in here, but then this method looks for two things: |
|
574 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
575 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
576 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
577 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
578 | - * template args. |
|
579 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
580 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
581 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
582 | - * $this->_template_args['data']['items'] = array( |
|
583 | - * 'event-datetime-ids' => '1,2,3'; |
|
584 | - * ); |
|
585 | - * Keep in mind the following things: |
|
586 | - * - "where" index is for the input with the id as that string. |
|
587 | - * - "what" index is what will be used for the value of that input. |
|
588 | - * |
|
589 | - * @return void |
|
590 | - */ |
|
591 | - public function do_extra_autosave_stuff() |
|
592 | - { |
|
593 | - // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
594 | - $nonce = isset($this->_req_data['autosavenonce']) |
|
595 | - ? $this->_req_data['autosavenonce'] |
|
596 | - : null; |
|
597 | - $this->_verify_nonce($nonce, 'autosave'); |
|
598 | - // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
599 | - if (! defined('DOING_AUTOSAVE')) { |
|
600 | - define('DOING_AUTOSAVE', true); |
|
601 | - } |
|
602 | - // if we made it here then the nonce checked out. Let's run our methods and actions |
|
603 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
604 | - if (method_exists($this, $autosave)) { |
|
605 | - $this->$autosave(); |
|
606 | - } else { |
|
607 | - $this->_template_args['success'] = true; |
|
608 | - } |
|
609 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
610 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
611 | - // now let's return json |
|
612 | - $this->_return_json(); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
618 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
619 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
620 | - * |
|
621 | - * @access protected |
|
622 | - * @throws EE_Error |
|
623 | - * @return void |
|
624 | - */ |
|
625 | - protected function _extend_page_config_for_cpt() |
|
626 | - { |
|
627 | - // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
628 | - if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
629 | - return; |
|
630 | - } |
|
631 | - // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
632 | - if (! empty($this->_cpt_object)) { |
|
633 | - $this->_page_routes = array_merge( |
|
634 | - array( |
|
635 | - 'create_new' => '_create_new_cpt_item', |
|
636 | - 'edit' => '_edit_cpt_item', |
|
637 | - ), |
|
638 | - $this->_page_routes |
|
639 | - ); |
|
640 | - $this->_page_config = array_merge( |
|
641 | - array( |
|
642 | - 'create_new' => array( |
|
643 | - 'nav' => array( |
|
644 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
645 | - 'order' => 5, |
|
646 | - ), |
|
647 | - 'require_nonce' => false, |
|
648 | - ), |
|
649 | - 'edit' => array( |
|
650 | - 'nav' => array( |
|
651 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
652 | - 'order' => 5, |
|
653 | - 'persistent' => false, |
|
654 | - 'url' => '', |
|
655 | - ), |
|
656 | - 'require_nonce' => false, |
|
657 | - ), |
|
658 | - ), |
|
659 | - $this->_page_config |
|
660 | - ); |
|
661 | - } |
|
662 | - // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
663 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
664 | - return; |
|
665 | - } |
|
666 | - $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false; |
|
667 | - // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
668 | - if (empty($this->_cpt_object)) { |
|
669 | - $msg = sprintf( |
|
670 | - __( |
|
671 | - 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
672 | - 'event_espresso' |
|
673 | - ), |
|
674 | - $this->page_slug, |
|
675 | - $this->_req_action, |
|
676 | - get_class($this) |
|
677 | - ); |
|
678 | - throw new EE_Error($msg); |
|
679 | - } |
|
680 | - if ($this->_cpt_route) { |
|
681 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
682 | - $this->_set_model_object($id); |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
689 | - * |
|
690 | - * @access protected |
|
691 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
692 | - * @param bool $ignore_route_check |
|
693 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
694 | - * @throws EE_Error |
|
695 | - * @throws InvalidArgumentException |
|
696 | - * @throws InvalidDataTypeException |
|
697 | - * @throws InvalidInterfaceException |
|
698 | - * @throws ReflectionException |
|
699 | - */ |
|
700 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
701 | - { |
|
702 | - $model = null; |
|
703 | - if (empty($this->_cpt_model_names) |
|
704 | - || ( |
|
705 | - ! $ignore_route_check |
|
706 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
707 | - ) || ( |
|
708 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
709 | - && $this->_cpt_model_obj->ID() === $id |
|
710 | - ) |
|
711 | - ) { |
|
712 | - // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
713 | - return; |
|
714 | - } |
|
715 | - // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
716 | - if ($ignore_route_check) { |
|
717 | - $post_type = get_post_type($id); |
|
718 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
719 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
720 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
721 | - ); |
|
722 | - $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
723 | - if (isset($model_names[ $post_type ])) { |
|
724 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
725 | - } |
|
726 | - } else { |
|
727 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
728 | - } |
|
729 | - if ($model instanceof EEM_Base) { |
|
730 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
731 | - } |
|
732 | - do_action( |
|
733 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
734 | - $this->_cpt_model_obj, |
|
735 | - $req_type |
|
736 | - ); |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * admin_init_global |
|
742 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
743 | - * This method executes for ALL EE Admin pages. |
|
744 | - * |
|
745 | - * @access public |
|
746 | - * @return void |
|
747 | - */ |
|
748 | - public function admin_init_global() |
|
749 | - { |
|
750 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
751 | - // its possible this is a new save so let's catch that instead |
|
752 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
753 | - $post_type = $post ? $post->post_type : false; |
|
754 | - $current_route = isset($this->_req_data['current_route']) |
|
755 | - ? $this->_req_data['current_route'] |
|
756 | - : 'shouldneverwork'; |
|
757 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
758 | - ? $this->_cpt_routes[ $current_route ] |
|
759 | - : ''; |
|
760 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
761 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
762 | - if ($post_type === $route_to_check) { |
|
763 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
764 | - } |
|
765 | - // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
766 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
767 | - if (! empty($revision)) { |
|
768 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
769 | - // doing a restore? |
|
770 | - if (! empty($action) && $action === 'restore') { |
|
771 | - // get post for revision |
|
772 | - $rev_post = get_post($revision); |
|
773 | - $rev_parent = get_post($rev_post->post_parent); |
|
774 | - // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
775 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
776 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
777 | - // restores of revisions |
|
778 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
779 | - } |
|
780 | - } |
|
781 | - } |
|
782 | - // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
783 | - if ($post_type && $post_type === $route_to_check) { |
|
784 | - // $post_id, $post |
|
785 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
786 | - // $post_id |
|
787 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
788 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
789 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
790 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
791 | - } |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * Callback for the WordPress trashed_post hook. |
|
797 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
798 | - * |
|
799 | - * @param int $post_id |
|
800 | - * @throws \EE_Error |
|
801 | - */ |
|
802 | - public function before_trash_cpt_item($post_id) |
|
803 | - { |
|
804 | - $this->_set_model_object($post_id, true, 'trash'); |
|
805 | - // if our cpt object isn't existent then get out immediately. |
|
806 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
807 | - return; |
|
808 | - } |
|
809 | - $this->trash_cpt_item($post_id); |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - /** |
|
814 | - * Callback for the WordPress untrashed_post hook. |
|
815 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
816 | - * |
|
817 | - * @param $post_id |
|
818 | - * @throws \EE_Error |
|
819 | - */ |
|
820 | - public function before_restore_cpt_item($post_id) |
|
821 | - { |
|
822 | - $this->_set_model_object($post_id, true, 'restore'); |
|
823 | - // if our cpt object isn't existent then get out immediately. |
|
824 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
825 | - return; |
|
826 | - } |
|
827 | - $this->restore_cpt_item($post_id); |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * Callback for the WordPress after_delete_post hook. |
|
833 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
834 | - * |
|
835 | - * @param $post_id |
|
836 | - * @throws \EE_Error |
|
837 | - */ |
|
838 | - public function before_delete_cpt_item($post_id) |
|
839 | - { |
|
840 | - $this->_set_model_object($post_id, true, 'delete'); |
|
841 | - // if our cpt object isn't existent then get out immediately. |
|
842 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
843 | - return; |
|
844 | - } |
|
845 | - $this->delete_cpt_item($post_id); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
851 | - * accordingly. |
|
852 | - * |
|
853 | - * @access public |
|
854 | - * @throws EE_Error |
|
855 | - * @return void |
|
856 | - */ |
|
857 | - public function verify_cpt_object() |
|
858 | - { |
|
859 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
860 | - // verify event object |
|
861 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
862 | - throw new EE_Error( |
|
863 | - sprintf( |
|
864 | - __( |
|
865 | - 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
866 | - 'event_espresso' |
|
867 | - ), |
|
868 | - $label |
|
869 | - ) |
|
870 | - ); |
|
871 | - } |
|
872 | - // if auto-draft then throw an error |
|
873 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
874 | - EE_Error::overwrite_errors(); |
|
875 | - EE_Error::add_error( |
|
876 | - sprintf( |
|
877 | - __( |
|
878 | - 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
879 | - 'event_espresso' |
|
880 | - ), |
|
881 | - $label |
|
882 | - ), |
|
883 | - __FILE__, |
|
884 | - __FUNCTION__, |
|
885 | - __LINE__ |
|
886 | - ); |
|
887 | - } |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * admin_footer_scripts_global |
|
893 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
894 | - * will apply on ALL EE_Admin pages. |
|
895 | - * |
|
896 | - * @access public |
|
897 | - * @return void |
|
898 | - */ |
|
899 | - public function admin_footer_scripts_global() |
|
900 | - { |
|
901 | - $this->_add_admin_page_ajax_loading_img(); |
|
902 | - $this->_add_admin_page_overlay(); |
|
903 | - } |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * add in any global scripts for cpt routes |
|
908 | - * |
|
909 | - * @return void |
|
910 | - */ |
|
911 | - public function load_global_scripts_styles() |
|
912 | - { |
|
913 | - parent::load_global_scripts_styles(); |
|
914 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
915 | - // setup custom post status object for localize script but only if we've got a cpt object |
|
916 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
917 | - if (! empty($statuses)) { |
|
918 | - // get ALL statuses! |
|
919 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
920 | - // setup object |
|
921 | - $ee_cpt_statuses = array(); |
|
922 | - foreach ($statuses as $status => $label) { |
|
923 | - $ee_cpt_statuses[ $status ] = array( |
|
924 | - 'label' => $label, |
|
925 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
926 | - ); |
|
927 | - } |
|
928 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
929 | - } |
|
930 | - } |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
936 | - * insert/updates |
|
937 | - * |
|
938 | - * @param int $post_id ID of post being updated |
|
939 | - * @param WP_Post $post Post object from WP |
|
940 | - * @param bool $update Whether this is an update or a new save. |
|
941 | - * @return void |
|
942 | - * @throws \EE_Error |
|
943 | - */ |
|
944 | - public function insert_update($post_id, $post, $update) |
|
945 | - { |
|
946 | - // make sure that if this is a revision OR trash action that we don't do any updates! |
|
947 | - if (isset($this->_req_data['action']) |
|
948 | - && ( |
|
949 | - $this->_req_data['action'] === 'restore' |
|
950 | - || $this->_req_data['action'] === 'trash' |
|
951 | - ) |
|
952 | - ) { |
|
953 | - return; |
|
954 | - } |
|
955 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
956 | - // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
957 | - if ($update |
|
958 | - && ( |
|
959 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
960 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
961 | - ) |
|
962 | - ) { |
|
963 | - return; |
|
964 | - } |
|
965 | - // check for autosave and update our req_data property accordingly. |
|
966 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
510 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
511 | + * |
|
512 | + * @param string $return the current html |
|
513 | + * @param int $id the post id for the page |
|
514 | + * @param string $new_title What the title is |
|
515 | + * @param string $new_slug what the slug is |
|
516 | + * @return string The new html string for the permalink area |
|
517 | + */ |
|
518 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
519 | + { |
|
520 | + $post = get_post($id); |
|
521 | + if ('publish' !== get_post_status($post)) { |
|
522 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
523 | + . get_preview_post_link($id) |
|
524 | + . '" class="button button-small">' |
|
525 | + . __('Preview', 'event_espresso') |
|
526 | + . '</a></span>' |
|
527 | + . "\n"; |
|
528 | + } |
|
529 | + return $return; |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
535 | + * |
|
536 | + * @return void |
|
537 | + */ |
|
538 | + public function custom_post_stati_dropdown() |
|
539 | + { |
|
540 | + |
|
541 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
542 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
543 | + ? $statuses[ $this->_cpt_model_obj->status() ] |
|
544 | + : ''; |
|
545 | + $template_args = array( |
|
546 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
547 | + 'statuses' => $statuses, |
|
548 | + 'cur_status_label' => $cur_status_label, |
|
549 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
550 | + ); |
|
551 | + // we'll add a trash post status (WP doesn't add one for some reason) |
|
552 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
553 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
554 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
555 | + $template_args['statuses'] = $statuses; |
|
556 | + } |
|
557 | + |
|
558 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
559 | + EEH_Template::display_template($template, $template_args); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + public function setup_autosave_hooks() |
|
564 | + { |
|
565 | + $this->_set_autosave_containers(); |
|
566 | + $this->_load_autosave_scripts_styles(); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
572 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
573 | + * for the nonce in here, but then this method looks for two things: |
|
574 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
575 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
576 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
577 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
578 | + * template args. |
|
579 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
580 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
581 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
582 | + * $this->_template_args['data']['items'] = array( |
|
583 | + * 'event-datetime-ids' => '1,2,3'; |
|
584 | + * ); |
|
585 | + * Keep in mind the following things: |
|
586 | + * - "where" index is for the input with the id as that string. |
|
587 | + * - "what" index is what will be used for the value of that input. |
|
588 | + * |
|
589 | + * @return void |
|
590 | + */ |
|
591 | + public function do_extra_autosave_stuff() |
|
592 | + { |
|
593 | + // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
594 | + $nonce = isset($this->_req_data['autosavenonce']) |
|
595 | + ? $this->_req_data['autosavenonce'] |
|
596 | + : null; |
|
597 | + $this->_verify_nonce($nonce, 'autosave'); |
|
598 | + // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
599 | + if (! defined('DOING_AUTOSAVE')) { |
|
600 | + define('DOING_AUTOSAVE', true); |
|
601 | + } |
|
602 | + // if we made it here then the nonce checked out. Let's run our methods and actions |
|
603 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
604 | + if (method_exists($this, $autosave)) { |
|
605 | + $this->$autosave(); |
|
606 | + } else { |
|
607 | + $this->_template_args['success'] = true; |
|
608 | + } |
|
609 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
610 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
611 | + // now let's return json |
|
612 | + $this->_return_json(); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
618 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
619 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
620 | + * |
|
621 | + * @access protected |
|
622 | + * @throws EE_Error |
|
623 | + * @return void |
|
624 | + */ |
|
625 | + protected function _extend_page_config_for_cpt() |
|
626 | + { |
|
627 | + // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
628 | + if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
629 | + return; |
|
630 | + } |
|
631 | + // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
632 | + if (! empty($this->_cpt_object)) { |
|
633 | + $this->_page_routes = array_merge( |
|
634 | + array( |
|
635 | + 'create_new' => '_create_new_cpt_item', |
|
636 | + 'edit' => '_edit_cpt_item', |
|
637 | + ), |
|
638 | + $this->_page_routes |
|
639 | + ); |
|
640 | + $this->_page_config = array_merge( |
|
641 | + array( |
|
642 | + 'create_new' => array( |
|
643 | + 'nav' => array( |
|
644 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
645 | + 'order' => 5, |
|
646 | + ), |
|
647 | + 'require_nonce' => false, |
|
648 | + ), |
|
649 | + 'edit' => array( |
|
650 | + 'nav' => array( |
|
651 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
652 | + 'order' => 5, |
|
653 | + 'persistent' => false, |
|
654 | + 'url' => '', |
|
655 | + ), |
|
656 | + 'require_nonce' => false, |
|
657 | + ), |
|
658 | + ), |
|
659 | + $this->_page_config |
|
660 | + ); |
|
661 | + } |
|
662 | + // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
663 | + if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
664 | + return; |
|
665 | + } |
|
666 | + $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false; |
|
667 | + // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
668 | + if (empty($this->_cpt_object)) { |
|
669 | + $msg = sprintf( |
|
670 | + __( |
|
671 | + 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
672 | + 'event_espresso' |
|
673 | + ), |
|
674 | + $this->page_slug, |
|
675 | + $this->_req_action, |
|
676 | + get_class($this) |
|
677 | + ); |
|
678 | + throw new EE_Error($msg); |
|
679 | + } |
|
680 | + if ($this->_cpt_route) { |
|
681 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
682 | + $this->_set_model_object($id); |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
689 | + * |
|
690 | + * @access protected |
|
691 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
692 | + * @param bool $ignore_route_check |
|
693 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
694 | + * @throws EE_Error |
|
695 | + * @throws InvalidArgumentException |
|
696 | + * @throws InvalidDataTypeException |
|
697 | + * @throws InvalidInterfaceException |
|
698 | + * @throws ReflectionException |
|
699 | + */ |
|
700 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
701 | + { |
|
702 | + $model = null; |
|
703 | + if (empty($this->_cpt_model_names) |
|
704 | + || ( |
|
705 | + ! $ignore_route_check |
|
706 | + && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
707 | + ) || ( |
|
708 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
709 | + && $this->_cpt_model_obj->ID() === $id |
|
710 | + ) |
|
711 | + ) { |
|
712 | + // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
713 | + return; |
|
714 | + } |
|
715 | + // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
716 | + if ($ignore_route_check) { |
|
717 | + $post_type = get_post_type($id); |
|
718 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
719 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
720 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
721 | + ); |
|
722 | + $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
723 | + if (isset($model_names[ $post_type ])) { |
|
724 | + $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
725 | + } |
|
726 | + } else { |
|
727 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
728 | + } |
|
729 | + if ($model instanceof EEM_Base) { |
|
730 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
731 | + } |
|
732 | + do_action( |
|
733 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
734 | + $this->_cpt_model_obj, |
|
735 | + $req_type |
|
736 | + ); |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * admin_init_global |
|
742 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
743 | + * This method executes for ALL EE Admin pages. |
|
744 | + * |
|
745 | + * @access public |
|
746 | + * @return void |
|
747 | + */ |
|
748 | + public function admin_init_global() |
|
749 | + { |
|
750 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
751 | + // its possible this is a new save so let's catch that instead |
|
752 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
753 | + $post_type = $post ? $post->post_type : false; |
|
754 | + $current_route = isset($this->_req_data['current_route']) |
|
755 | + ? $this->_req_data['current_route'] |
|
756 | + : 'shouldneverwork'; |
|
757 | + $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
758 | + ? $this->_cpt_routes[ $current_route ] |
|
759 | + : ''; |
|
760 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
761 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
762 | + if ($post_type === $route_to_check) { |
|
763 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
764 | + } |
|
765 | + // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
766 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
767 | + if (! empty($revision)) { |
|
768 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
769 | + // doing a restore? |
|
770 | + if (! empty($action) && $action === 'restore') { |
|
771 | + // get post for revision |
|
772 | + $rev_post = get_post($revision); |
|
773 | + $rev_parent = get_post($rev_post->post_parent); |
|
774 | + // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
775 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
776 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
777 | + // restores of revisions |
|
778 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
779 | + } |
|
780 | + } |
|
781 | + } |
|
782 | + // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
783 | + if ($post_type && $post_type === $route_to_check) { |
|
784 | + // $post_id, $post |
|
785 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
786 | + // $post_id |
|
787 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
788 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
789 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
790 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
791 | + } |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * Callback for the WordPress trashed_post hook. |
|
797 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
798 | + * |
|
799 | + * @param int $post_id |
|
800 | + * @throws \EE_Error |
|
801 | + */ |
|
802 | + public function before_trash_cpt_item($post_id) |
|
803 | + { |
|
804 | + $this->_set_model_object($post_id, true, 'trash'); |
|
805 | + // if our cpt object isn't existent then get out immediately. |
|
806 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
807 | + return; |
|
808 | + } |
|
809 | + $this->trash_cpt_item($post_id); |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + /** |
|
814 | + * Callback for the WordPress untrashed_post hook. |
|
815 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
816 | + * |
|
817 | + * @param $post_id |
|
818 | + * @throws \EE_Error |
|
819 | + */ |
|
820 | + public function before_restore_cpt_item($post_id) |
|
821 | + { |
|
822 | + $this->_set_model_object($post_id, true, 'restore'); |
|
823 | + // if our cpt object isn't existent then get out immediately. |
|
824 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
825 | + return; |
|
826 | + } |
|
827 | + $this->restore_cpt_item($post_id); |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * Callback for the WordPress after_delete_post hook. |
|
833 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
834 | + * |
|
835 | + * @param $post_id |
|
836 | + * @throws \EE_Error |
|
837 | + */ |
|
838 | + public function before_delete_cpt_item($post_id) |
|
839 | + { |
|
840 | + $this->_set_model_object($post_id, true, 'delete'); |
|
841 | + // if our cpt object isn't existent then get out immediately. |
|
842 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
843 | + return; |
|
844 | + } |
|
845 | + $this->delete_cpt_item($post_id); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
851 | + * accordingly. |
|
852 | + * |
|
853 | + * @access public |
|
854 | + * @throws EE_Error |
|
855 | + * @return void |
|
856 | + */ |
|
857 | + public function verify_cpt_object() |
|
858 | + { |
|
859 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
860 | + // verify event object |
|
861 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
862 | + throw new EE_Error( |
|
863 | + sprintf( |
|
864 | + __( |
|
865 | + 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
866 | + 'event_espresso' |
|
867 | + ), |
|
868 | + $label |
|
869 | + ) |
|
870 | + ); |
|
871 | + } |
|
872 | + // if auto-draft then throw an error |
|
873 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
874 | + EE_Error::overwrite_errors(); |
|
875 | + EE_Error::add_error( |
|
876 | + sprintf( |
|
877 | + __( |
|
878 | + 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
879 | + 'event_espresso' |
|
880 | + ), |
|
881 | + $label |
|
882 | + ), |
|
883 | + __FILE__, |
|
884 | + __FUNCTION__, |
|
885 | + __LINE__ |
|
886 | + ); |
|
887 | + } |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * admin_footer_scripts_global |
|
893 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
894 | + * will apply on ALL EE_Admin pages. |
|
895 | + * |
|
896 | + * @access public |
|
897 | + * @return void |
|
898 | + */ |
|
899 | + public function admin_footer_scripts_global() |
|
900 | + { |
|
901 | + $this->_add_admin_page_ajax_loading_img(); |
|
902 | + $this->_add_admin_page_overlay(); |
|
903 | + } |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * add in any global scripts for cpt routes |
|
908 | + * |
|
909 | + * @return void |
|
910 | + */ |
|
911 | + public function load_global_scripts_styles() |
|
912 | + { |
|
913 | + parent::load_global_scripts_styles(); |
|
914 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
915 | + // setup custom post status object for localize script but only if we've got a cpt object |
|
916 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
917 | + if (! empty($statuses)) { |
|
918 | + // get ALL statuses! |
|
919 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
920 | + // setup object |
|
921 | + $ee_cpt_statuses = array(); |
|
922 | + foreach ($statuses as $status => $label) { |
|
923 | + $ee_cpt_statuses[ $status ] = array( |
|
924 | + 'label' => $label, |
|
925 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
926 | + ); |
|
927 | + } |
|
928 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
929 | + } |
|
930 | + } |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
936 | + * insert/updates |
|
937 | + * |
|
938 | + * @param int $post_id ID of post being updated |
|
939 | + * @param WP_Post $post Post object from WP |
|
940 | + * @param bool $update Whether this is an update or a new save. |
|
941 | + * @return void |
|
942 | + * @throws \EE_Error |
|
943 | + */ |
|
944 | + public function insert_update($post_id, $post, $update) |
|
945 | + { |
|
946 | + // make sure that if this is a revision OR trash action that we don't do any updates! |
|
947 | + if (isset($this->_req_data['action']) |
|
948 | + && ( |
|
949 | + $this->_req_data['action'] === 'restore' |
|
950 | + || $this->_req_data['action'] === 'trash' |
|
951 | + ) |
|
952 | + ) { |
|
953 | + return; |
|
954 | + } |
|
955 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
956 | + // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
957 | + if ($update |
|
958 | + && ( |
|
959 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
960 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
961 | + ) |
|
962 | + ) { |
|
963 | + return; |
|
964 | + } |
|
965 | + // check for autosave and update our req_data property accordingly. |
|
966 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
967 | 967 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
968 | 968 | |
969 | 969 | foreach ( (array) $values as $key => $value ) { |
@@ -973,532 +973,532 @@ discard block |
||
973 | 973 | |
974 | 974 | }/**/ // TODO reactivate after autosave is implemented in 4.2 |
975 | 975 | |
976 | - // take care of updating any selected page_template IF this cpt supports it. |
|
977 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
978 | - // wp version aware. |
|
979 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
980 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
981 | - } else { |
|
982 | - $post->page_template = $this->_req_data['page_template']; |
|
983 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
984 | - } |
|
985 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) { |
|
986 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
987 | - } else { |
|
988 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
989 | - } |
|
990 | - } |
|
991 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
992 | - return; |
|
993 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
994 | - $this->_insert_update_cpt_item($post_id, $post); |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
1000 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
1001 | - * so we don't have to check for our CPT. |
|
1002 | - * |
|
1003 | - * @param int $post_id ID of the post |
|
1004 | - * @return void |
|
1005 | - */ |
|
1006 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
1007 | - { |
|
1008 | - // only do this if we're actually processing one of our CPTs |
|
1009 | - // if our cpt object isn't existent then get out immediately. |
|
1010 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1011 | - return; |
|
1012 | - } |
|
1013 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
1014 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
1015 | - // our cpts may have comments so let's take care of that too |
|
1016 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1017 | - } |
|
1018 | - |
|
1019 | - |
|
1020 | - /** |
|
1021 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1022 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1023 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1024 | - * |
|
1025 | - * @param int $post_id ID of cpt item |
|
1026 | - * @param int $revision_id ID of revision being restored |
|
1027 | - * @return void |
|
1028 | - */ |
|
1029 | - public function restore_revision($post_id, $revision_id) |
|
1030 | - { |
|
1031 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1032 | - // global action |
|
1033 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1034 | - // class specific action so you can limit hooking into a specific page. |
|
1035 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1036 | - } |
|
1037 | - |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * @see restore_revision() for details |
|
1041 | - * @param int $post_id ID of cpt item |
|
1042 | - * @param int $revision_id ID of revision for item |
|
1043 | - * @return void |
|
1044 | - */ |
|
1045 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1046 | - |
|
1047 | - |
|
1048 | - /** |
|
1049 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1050 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1051 | - * To fix we have to reset the current_screen using the page_slug |
|
1052 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1053 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1054 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1055 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1056 | - * |
|
1057 | - * @return void |
|
1058 | - */ |
|
1059 | - public function modify_current_screen() |
|
1060 | - { |
|
1061 | - // ONLY do this if the current page_route IS a cpt route |
|
1062 | - if (! $this->_cpt_route) { |
|
1063 | - return; |
|
1064 | - } |
|
1065 | - // routing things REALLY early b/c this is a cpt admin page |
|
1066 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1067 | - $this->_current_screen = get_current_screen(); |
|
1068 | - $this->_current_screen->base = 'event-espresso'; |
|
1069 | - $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
1070 | - /*try { |
|
976 | + // take care of updating any selected page_template IF this cpt supports it. |
|
977 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
978 | + // wp version aware. |
|
979 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
980 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
981 | + } else { |
|
982 | + $post->page_template = $this->_req_data['page_template']; |
|
983 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
984 | + } |
|
985 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) { |
|
986 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
987 | + } else { |
|
988 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
989 | + } |
|
990 | + } |
|
991 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
992 | + return; |
|
993 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
994 | + $this->_insert_update_cpt_item($post_id, $post); |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
1000 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
1001 | + * so we don't have to check for our CPT. |
|
1002 | + * |
|
1003 | + * @param int $post_id ID of the post |
|
1004 | + * @return void |
|
1005 | + */ |
|
1006 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
1007 | + { |
|
1008 | + // only do this if we're actually processing one of our CPTs |
|
1009 | + // if our cpt object isn't existent then get out immediately. |
|
1010 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1011 | + return; |
|
1012 | + } |
|
1013 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
1014 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
1015 | + // our cpts may have comments so let's take care of that too |
|
1016 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1017 | + } |
|
1018 | + |
|
1019 | + |
|
1020 | + /** |
|
1021 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1022 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1023 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1024 | + * |
|
1025 | + * @param int $post_id ID of cpt item |
|
1026 | + * @param int $revision_id ID of revision being restored |
|
1027 | + * @return void |
|
1028 | + */ |
|
1029 | + public function restore_revision($post_id, $revision_id) |
|
1030 | + { |
|
1031 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1032 | + // global action |
|
1033 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1034 | + // class specific action so you can limit hooking into a specific page. |
|
1035 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1036 | + } |
|
1037 | + |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * @see restore_revision() for details |
|
1041 | + * @param int $post_id ID of cpt item |
|
1042 | + * @param int $revision_id ID of revision for item |
|
1043 | + * @return void |
|
1044 | + */ |
|
1045 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1046 | + |
|
1047 | + |
|
1048 | + /** |
|
1049 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1050 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1051 | + * To fix we have to reset the current_screen using the page_slug |
|
1052 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1053 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1054 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1055 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1056 | + * |
|
1057 | + * @return void |
|
1058 | + */ |
|
1059 | + public function modify_current_screen() |
|
1060 | + { |
|
1061 | + // ONLY do this if the current page_route IS a cpt route |
|
1062 | + if (! $this->_cpt_route) { |
|
1063 | + return; |
|
1064 | + } |
|
1065 | + // routing things REALLY early b/c this is a cpt admin page |
|
1066 | + set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1067 | + $this->_current_screen = get_current_screen(); |
|
1068 | + $this->_current_screen->base = 'event-espresso'; |
|
1069 | + $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
1070 | + /*try { |
|
1071 | 1071 | $this->_route_admin_request(); |
1072 | 1072 | } catch ( EE_Error $e ) { |
1073 | 1073 | $e->get_error(); |
1074 | 1074 | }/**/ |
1075 | - } |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1080 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1081 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1082 | - * default to be. |
|
1083 | - * |
|
1084 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1085 | - * @return string |
|
1086 | - */ |
|
1087 | - public function add_custom_editor_default_title($title) |
|
1088 | - { |
|
1089 | - return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
1090 | - ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1091 | - : $title; |
|
1092 | - } |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1097 | - * |
|
1098 | - * @param string $shortlink The already generated shortlink |
|
1099 | - * @param int $id Post ID for this item |
|
1100 | - * @param string $context The context for the link |
|
1101 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1102 | - * @return string |
|
1103 | - */ |
|
1104 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1105 | - { |
|
1106 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
1107 | - $post = get_post($id); |
|
1108 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1109 | - $shortlink = home_url('?p=' . $post->ID); |
|
1110 | - } |
|
1111 | - } |
|
1112 | - return $shortlink; |
|
1113 | - } |
|
1114 | - |
|
1115 | - |
|
1116 | - /** |
|
1117 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1118 | - * already run in modify_current_screen()) |
|
1119 | - * |
|
1120 | - * @return void |
|
1121 | - */ |
|
1122 | - public function route_admin_request() |
|
1123 | - { |
|
1124 | - if ($this->_cpt_route) { |
|
1125 | - return; |
|
1126 | - } |
|
1127 | - try { |
|
1128 | - $this->_route_admin_request(); |
|
1129 | - } catch (EE_Error $e) { |
|
1130 | - $e->get_error(); |
|
1131 | - } |
|
1132 | - } |
|
1133 | - |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1137 | - * |
|
1138 | - * @return void |
|
1139 | - */ |
|
1140 | - public function cpt_post_form_hidden_input() |
|
1141 | - { |
|
1142 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1143 | - // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1144 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
1145 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1146 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1147 | - echo '</div>'; |
|
1148 | - } |
|
1149 | - |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1153 | - * |
|
1154 | - * @param string $location Original location url |
|
1155 | - * @param int $status Status for http header |
|
1156 | - * @return string new (or original) url to redirect to. |
|
1157 | - */ |
|
1158 | - public function revision_redirect($location, $status) |
|
1159 | - { |
|
1160 | - // get revision |
|
1161 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1162 | - // can't do anything without revision so let's get out if not present |
|
1163 | - if (empty($rev_id)) { |
|
1164 | - return $location; |
|
1165 | - } |
|
1166 | - // get rev_post_data |
|
1167 | - $rev = get_post($rev_id); |
|
1168 | - $admin_url = $this->_admin_base_url; |
|
1169 | - $query_args = array( |
|
1170 | - 'action' => 'edit', |
|
1171 | - 'post' => $rev->post_parent, |
|
1172 | - 'revision' => $rev_id, |
|
1173 | - 'message' => 5, |
|
1174 | - ); |
|
1175 | - $this->_process_notices($query_args, true); |
|
1176 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1177 | - } |
|
1178 | - |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1182 | - * |
|
1183 | - * @param string $link the original generated link |
|
1184 | - * @param int $id post id |
|
1185 | - * @param string $context optional, defaults to display. How to write the '&' |
|
1186 | - * @return string the link |
|
1187 | - */ |
|
1188 | - public function modify_edit_post_link($link, $id, $context) |
|
1189 | - { |
|
1190 | - $post = get_post($id); |
|
1191 | - if (! isset($this->_req_data['action']) |
|
1192 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1193 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1194 | - ) { |
|
1195 | - return $link; |
|
1196 | - } |
|
1197 | - $query_args = array( |
|
1198 | - 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
1199 | - ? $this->_cpt_edit_routes[ $post->post_type ] |
|
1200 | - : 'edit', |
|
1201 | - 'post' => $id, |
|
1202 | - ); |
|
1203 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1209 | - * our routes. |
|
1210 | - * |
|
1211 | - * @param string $delete_link original delete link |
|
1212 | - * @param int $post_id id of cpt object |
|
1213 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1214 | - * @return string new delete link |
|
1215 | - * @throws EE_Error |
|
1216 | - */ |
|
1217 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1218 | - { |
|
1219 | - $post = get_post($post_id); |
|
1220 | - |
|
1221 | - if (empty($this->_req_data['action']) |
|
1222 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1223 | - || ! $post instanceof WP_Post |
|
1224 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1225 | - ) { |
|
1226 | - return $delete_link; |
|
1227 | - } |
|
1228 | - $this->_set_model_object($post->ID, true); |
|
1229 | - |
|
1230 | - // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1231 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1232 | - |
|
1233 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1234 | - array( |
|
1235 | - 'page' => $this->_req_data['page'], |
|
1236 | - 'action' => $action, |
|
1237 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1238 | - => $post->ID, |
|
1239 | - ), |
|
1240 | - admin_url() |
|
1241 | - ); |
|
1242 | - } |
|
1243 | - |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1247 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1248 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1249 | - * |
|
1250 | - * @param string $location This is the incoming currently set redirect location |
|
1251 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1252 | - * @return string the new location to redirect to |
|
1253 | - */ |
|
1254 | - public function cpt_post_location_redirect($location, $post_id) |
|
1255 | - { |
|
1256 | - // we DO have a match so let's setup the url |
|
1257 | - // we have to get the post to determine our route |
|
1258 | - $post = get_post($post_id); |
|
1259 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1260 | - // shared query_args |
|
1261 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1262 | - $admin_url = $this->_admin_base_url; |
|
1263 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1264 | - $status = get_post_status($post_id); |
|
1265 | - if (isset($this->_req_data['publish'])) { |
|
1266 | - switch ($status) { |
|
1267 | - case 'pending': |
|
1268 | - $message = 8; |
|
1269 | - break; |
|
1270 | - case 'future': |
|
1271 | - $message = 9; |
|
1272 | - break; |
|
1273 | - default: |
|
1274 | - $message = 6; |
|
1275 | - } |
|
1276 | - } else { |
|
1277 | - $message = 'draft' === $status ? 10 : 1; |
|
1278 | - } |
|
1279 | - } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1280 | - $message = 2; |
|
1281 | - } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1282 | - $message = 3; |
|
1283 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1284 | - $message = 7; |
|
1285 | - } else { |
|
1286 | - $message = 4; |
|
1287 | - } |
|
1288 | - // change the message if the post type is not viewable on the frontend |
|
1289 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1290 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1291 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
1292 | - $this->_process_notices($query_args, true); |
|
1293 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1294 | - } |
|
1295 | - |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1299 | - * |
|
1300 | - * @access public |
|
1301 | - * @return void |
|
1302 | - */ |
|
1303 | - public function inject_nav_tabs() |
|
1304 | - { |
|
1305 | - // can we hijack and insert the nav_tabs? |
|
1306 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
1307 | - // first close off existing form tag |
|
1308 | - $html = '>'; |
|
1309 | - $html .= $nav_tabs; |
|
1310 | - // now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1311 | - $html .= '<span></span'; |
|
1312 | - echo $html; |
|
1313 | - } |
|
1314 | - |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * This just sets up the post update messages when an update form is loaded |
|
1318 | - * |
|
1319 | - * @access public |
|
1320 | - * @param array $messages the original messages array |
|
1321 | - * @return array the new messages array |
|
1322 | - */ |
|
1323 | - public function post_update_messages($messages) |
|
1324 | - { |
|
1325 | - global $post; |
|
1326 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1327 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1328 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1075 | + } |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1080 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1081 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1082 | + * default to be. |
|
1083 | + * |
|
1084 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1085 | + * @return string |
|
1086 | + */ |
|
1087 | + public function add_custom_editor_default_title($title) |
|
1088 | + { |
|
1089 | + return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
1090 | + ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1091 | + : $title; |
|
1092 | + } |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1097 | + * |
|
1098 | + * @param string $shortlink The already generated shortlink |
|
1099 | + * @param int $id Post ID for this item |
|
1100 | + * @param string $context The context for the link |
|
1101 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1102 | + * @return string |
|
1103 | + */ |
|
1104 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1105 | + { |
|
1106 | + if (! empty($id) && get_option('permalink_structure') !== '') { |
|
1107 | + $post = get_post($id); |
|
1108 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1109 | + $shortlink = home_url('?p=' . $post->ID); |
|
1110 | + } |
|
1111 | + } |
|
1112 | + return $shortlink; |
|
1113 | + } |
|
1114 | + |
|
1115 | + |
|
1116 | + /** |
|
1117 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1118 | + * already run in modify_current_screen()) |
|
1119 | + * |
|
1120 | + * @return void |
|
1121 | + */ |
|
1122 | + public function route_admin_request() |
|
1123 | + { |
|
1124 | + if ($this->_cpt_route) { |
|
1125 | + return; |
|
1126 | + } |
|
1127 | + try { |
|
1128 | + $this->_route_admin_request(); |
|
1129 | + } catch (EE_Error $e) { |
|
1130 | + $e->get_error(); |
|
1131 | + } |
|
1132 | + } |
|
1133 | + |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1137 | + * |
|
1138 | + * @return void |
|
1139 | + */ |
|
1140 | + public function cpt_post_form_hidden_input() |
|
1141 | + { |
|
1142 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1143 | + // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1144 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
1145 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1146 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1147 | + echo '</div>'; |
|
1148 | + } |
|
1149 | + |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1153 | + * |
|
1154 | + * @param string $location Original location url |
|
1155 | + * @param int $status Status for http header |
|
1156 | + * @return string new (or original) url to redirect to. |
|
1157 | + */ |
|
1158 | + public function revision_redirect($location, $status) |
|
1159 | + { |
|
1160 | + // get revision |
|
1161 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1162 | + // can't do anything without revision so let's get out if not present |
|
1163 | + if (empty($rev_id)) { |
|
1164 | + return $location; |
|
1165 | + } |
|
1166 | + // get rev_post_data |
|
1167 | + $rev = get_post($rev_id); |
|
1168 | + $admin_url = $this->_admin_base_url; |
|
1169 | + $query_args = array( |
|
1170 | + 'action' => 'edit', |
|
1171 | + 'post' => $rev->post_parent, |
|
1172 | + 'revision' => $rev_id, |
|
1173 | + 'message' => 5, |
|
1174 | + ); |
|
1175 | + $this->_process_notices($query_args, true); |
|
1176 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1177 | + } |
|
1178 | + |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1182 | + * |
|
1183 | + * @param string $link the original generated link |
|
1184 | + * @param int $id post id |
|
1185 | + * @param string $context optional, defaults to display. How to write the '&' |
|
1186 | + * @return string the link |
|
1187 | + */ |
|
1188 | + public function modify_edit_post_link($link, $id, $context) |
|
1189 | + { |
|
1190 | + $post = get_post($id); |
|
1191 | + if (! isset($this->_req_data['action']) |
|
1192 | + || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1193 | + || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1194 | + ) { |
|
1195 | + return $link; |
|
1196 | + } |
|
1197 | + $query_args = array( |
|
1198 | + 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
1199 | + ? $this->_cpt_edit_routes[ $post->post_type ] |
|
1200 | + : 'edit', |
|
1201 | + 'post' => $id, |
|
1202 | + ); |
|
1203 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1209 | + * our routes. |
|
1210 | + * |
|
1211 | + * @param string $delete_link original delete link |
|
1212 | + * @param int $post_id id of cpt object |
|
1213 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1214 | + * @return string new delete link |
|
1215 | + * @throws EE_Error |
|
1216 | + */ |
|
1217 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1218 | + { |
|
1219 | + $post = get_post($post_id); |
|
1220 | + |
|
1221 | + if (empty($this->_req_data['action']) |
|
1222 | + || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1223 | + || ! $post instanceof WP_Post |
|
1224 | + || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1225 | + ) { |
|
1226 | + return $delete_link; |
|
1227 | + } |
|
1228 | + $this->_set_model_object($post->ID, true); |
|
1229 | + |
|
1230 | + // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1231 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1232 | + |
|
1233 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1234 | + array( |
|
1235 | + 'page' => $this->_req_data['page'], |
|
1236 | + 'action' => $action, |
|
1237 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1238 | + => $post->ID, |
|
1239 | + ), |
|
1240 | + admin_url() |
|
1241 | + ); |
|
1242 | + } |
|
1243 | + |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1247 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1248 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1249 | + * |
|
1250 | + * @param string $location This is the incoming currently set redirect location |
|
1251 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1252 | + * @return string the new location to redirect to |
|
1253 | + */ |
|
1254 | + public function cpt_post_location_redirect($location, $post_id) |
|
1255 | + { |
|
1256 | + // we DO have a match so let's setup the url |
|
1257 | + // we have to get the post to determine our route |
|
1258 | + $post = get_post($post_id); |
|
1259 | + $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1260 | + // shared query_args |
|
1261 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1262 | + $admin_url = $this->_admin_base_url; |
|
1263 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1264 | + $status = get_post_status($post_id); |
|
1265 | + if (isset($this->_req_data['publish'])) { |
|
1266 | + switch ($status) { |
|
1267 | + case 'pending': |
|
1268 | + $message = 8; |
|
1269 | + break; |
|
1270 | + case 'future': |
|
1271 | + $message = 9; |
|
1272 | + break; |
|
1273 | + default: |
|
1274 | + $message = 6; |
|
1275 | + } |
|
1276 | + } else { |
|
1277 | + $message = 'draft' === $status ? 10 : 1; |
|
1278 | + } |
|
1279 | + } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1280 | + $message = 2; |
|
1281 | + } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1282 | + $message = 3; |
|
1283 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1284 | + $message = 7; |
|
1285 | + } else { |
|
1286 | + $message = 4; |
|
1287 | + } |
|
1288 | + // change the message if the post type is not viewable on the frontend |
|
1289 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1290 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1291 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
1292 | + $this->_process_notices($query_args, true); |
|
1293 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1294 | + } |
|
1295 | + |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1299 | + * |
|
1300 | + * @access public |
|
1301 | + * @return void |
|
1302 | + */ |
|
1303 | + public function inject_nav_tabs() |
|
1304 | + { |
|
1305 | + // can we hijack and insert the nav_tabs? |
|
1306 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
1307 | + // first close off existing form tag |
|
1308 | + $html = '>'; |
|
1309 | + $html .= $nav_tabs; |
|
1310 | + // now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1311 | + $html .= '<span></span'; |
|
1312 | + echo $html; |
|
1313 | + } |
|
1314 | + |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * This just sets up the post update messages when an update form is loaded |
|
1318 | + * |
|
1319 | + * @access public |
|
1320 | + * @param array $messages the original messages array |
|
1321 | + * @return array the new messages array |
|
1322 | + */ |
|
1323 | + public function post_update_messages($messages) |
|
1324 | + { |
|
1325 | + global $post; |
|
1326 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1327 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1328 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1329 | 1329 | |
1330 | 1330 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1331 | - $messages[ $post->post_type ] = array( |
|
1332 | - 0 => '', // Unused. Messages start at index 1. |
|
1333 | - 1 => sprintf( |
|
1334 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1335 | - $this->_cpt_object->labels->singular_name, |
|
1336 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1337 | - '</a>' |
|
1338 | - ), |
|
1339 | - 2 => __('Custom field updated', 'event_espresso'), |
|
1340 | - 3 => __('Custom field deleted.', 'event_espresso'), |
|
1341 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1342 | - 5 => isset($_GET['revision']) ? sprintf( |
|
1343 | - __('%s restored to revision from %s', 'event_espresso'), |
|
1344 | - $this->_cpt_object->labels->singular_name, |
|
1345 | - wp_post_revision_title((int) $_GET['revision'], false) |
|
1346 | - ) |
|
1347 | - : false, |
|
1348 | - 6 => sprintf( |
|
1349 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1350 | - $this->_cpt_object->labels->singular_name, |
|
1351 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1352 | - '</a>' |
|
1353 | - ), |
|
1354 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1355 | - 8 => sprintf( |
|
1356 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1357 | - $this->_cpt_object->labels->singular_name, |
|
1358 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1359 | - '</a>' |
|
1360 | - ), |
|
1361 | - 9 => sprintf( |
|
1362 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1363 | - $this->_cpt_object->labels->singular_name, |
|
1364 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1365 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1366 | - '</a>' |
|
1367 | - ), |
|
1368 | - 10 => sprintf( |
|
1369 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1370 | - $this->_cpt_object->labels->singular_name, |
|
1371 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1372 | - '</a>' |
|
1373 | - ), |
|
1374 | - ); |
|
1375 | - return $messages; |
|
1376 | - } |
|
1377 | - |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * default method for the 'create_new' route for cpt admin pages. |
|
1381 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1382 | - * |
|
1383 | - * @access protected |
|
1384 | - * @return void |
|
1385 | - */ |
|
1386 | - protected function _create_new_cpt_item() |
|
1387 | - { |
|
1388 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1389 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1390 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1391 | - $post_type_object = $this->_cpt_object; |
|
1392 | - $title = $post_type_object->labels->add_new_item; |
|
1393 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1394 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1395 | - // modify the default editor title field with default title. |
|
1396 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1397 | - $this->loadEditorTemplate(true); |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * Enqueues auto-save and loads the editor template |
|
1403 | - * |
|
1404 | - * @param bool $creating |
|
1405 | - */ |
|
1406 | - private function loadEditorTemplate($creating = true) |
|
1407 | - { |
|
1408 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1409 | - // these vars are used by the template |
|
1410 | - $editing = true; |
|
1411 | - $post_ID = $post->ID; |
|
1412 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1413 | - // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1414 | - // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1415 | - if ($creating) { |
|
1416 | - wp_enqueue_script('autosave'); |
|
1417 | - } else { |
|
1418 | - if (isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1419 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
1420 | - ) { |
|
1421 | - $create_new_action = apply_filters( |
|
1422 | - 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1423 | - 'create_new', |
|
1424 | - $this |
|
1425 | - ); |
|
1426 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
1427 | - array( |
|
1428 | - 'action' => $create_new_action, |
|
1429 | - 'page' => $this->page_slug, |
|
1430 | - ), |
|
1431 | - 'admin.php' |
|
1432 | - ); |
|
1433 | - } |
|
1434 | - } |
|
1435 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1436 | - } |
|
1437 | - } |
|
1438 | - |
|
1439 | - |
|
1440 | - public function add_new_admin_page_global() |
|
1441 | - { |
|
1442 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1443 | - ?> |
|
1331 | + $messages[ $post->post_type ] = array( |
|
1332 | + 0 => '', // Unused. Messages start at index 1. |
|
1333 | + 1 => sprintf( |
|
1334 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1335 | + $this->_cpt_object->labels->singular_name, |
|
1336 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1337 | + '</a>' |
|
1338 | + ), |
|
1339 | + 2 => __('Custom field updated', 'event_espresso'), |
|
1340 | + 3 => __('Custom field deleted.', 'event_espresso'), |
|
1341 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1342 | + 5 => isset($_GET['revision']) ? sprintf( |
|
1343 | + __('%s restored to revision from %s', 'event_espresso'), |
|
1344 | + $this->_cpt_object->labels->singular_name, |
|
1345 | + wp_post_revision_title((int) $_GET['revision'], false) |
|
1346 | + ) |
|
1347 | + : false, |
|
1348 | + 6 => sprintf( |
|
1349 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1350 | + $this->_cpt_object->labels->singular_name, |
|
1351 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1352 | + '</a>' |
|
1353 | + ), |
|
1354 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1355 | + 8 => sprintf( |
|
1356 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1357 | + $this->_cpt_object->labels->singular_name, |
|
1358 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1359 | + '</a>' |
|
1360 | + ), |
|
1361 | + 9 => sprintf( |
|
1362 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1363 | + $this->_cpt_object->labels->singular_name, |
|
1364 | + '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1365 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1366 | + '</a>' |
|
1367 | + ), |
|
1368 | + 10 => sprintf( |
|
1369 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1370 | + $this->_cpt_object->labels->singular_name, |
|
1371 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1372 | + '</a>' |
|
1373 | + ), |
|
1374 | + ); |
|
1375 | + return $messages; |
|
1376 | + } |
|
1377 | + |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * default method for the 'create_new' route for cpt admin pages. |
|
1381 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1382 | + * |
|
1383 | + * @access protected |
|
1384 | + * @return void |
|
1385 | + */ |
|
1386 | + protected function _create_new_cpt_item() |
|
1387 | + { |
|
1388 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1389 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1390 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1391 | + $post_type_object = $this->_cpt_object; |
|
1392 | + $title = $post_type_object->labels->add_new_item; |
|
1393 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1394 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1395 | + // modify the default editor title field with default title. |
|
1396 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1397 | + $this->loadEditorTemplate(true); |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * Enqueues auto-save and loads the editor template |
|
1403 | + * |
|
1404 | + * @param bool $creating |
|
1405 | + */ |
|
1406 | + private function loadEditorTemplate($creating = true) |
|
1407 | + { |
|
1408 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1409 | + // these vars are used by the template |
|
1410 | + $editing = true; |
|
1411 | + $post_ID = $post->ID; |
|
1412 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1413 | + // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1414 | + // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1415 | + if ($creating) { |
|
1416 | + wp_enqueue_script('autosave'); |
|
1417 | + } else { |
|
1418 | + if (isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1419 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
1420 | + ) { |
|
1421 | + $create_new_action = apply_filters( |
|
1422 | + 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1423 | + 'create_new', |
|
1424 | + $this |
|
1425 | + ); |
|
1426 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
1427 | + array( |
|
1428 | + 'action' => $create_new_action, |
|
1429 | + 'page' => $this->page_slug, |
|
1430 | + ), |
|
1431 | + 'admin.php' |
|
1432 | + ); |
|
1433 | + } |
|
1434 | + } |
|
1435 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1436 | + } |
|
1437 | + } |
|
1438 | + |
|
1439 | + |
|
1440 | + public function add_new_admin_page_global() |
|
1441 | + { |
|
1442 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1443 | + ?> |
|
1444 | 1444 | <script type="text/javascript"> |
1445 | 1445 | adminpage = '<?php echo $admin_page; ?>'; |
1446 | 1446 | </script> |
1447 | 1447 | <?php |
1448 | - } |
|
1449 | - |
|
1450 | - |
|
1451 | - /** |
|
1452 | - * default method for the 'edit' route for cpt admin pages |
|
1453 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1454 | - * |
|
1455 | - * @access protected |
|
1456 | - * @return string template for edit cpt form |
|
1457 | - */ |
|
1458 | - protected function _edit_cpt_item() |
|
1459 | - { |
|
1460 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1461 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1462 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1463 | - if (empty($post)) { |
|
1464 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', 'event_espresso')); |
|
1465 | - } |
|
1466 | - if (! empty($_GET['get-post-lock'])) { |
|
1467 | - wp_set_post_lock($post_id); |
|
1468 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1469 | - exit(); |
|
1470 | - } |
|
1471 | - |
|
1472 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1473 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1474 | - $post_type_object = $this->_cpt_object; |
|
1475 | - |
|
1476 | - if (! wp_check_post_lock($post->ID)) { |
|
1477 | - wp_set_post_lock($post->ID); |
|
1478 | - } |
|
1479 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1480 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1481 | - wp_enqueue_script('admin-comments'); |
|
1482 | - enqueue_comment_hotkeys_js(); |
|
1483 | - } |
|
1484 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1485 | - // modify the default editor title field with default title. |
|
1486 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1487 | - $this->loadEditorTemplate(false); |
|
1488 | - } |
|
1489 | - |
|
1490 | - |
|
1491 | - |
|
1492 | - /** |
|
1493 | - * some getters |
|
1494 | - */ |
|
1495 | - /** |
|
1496 | - * This returns the protected _cpt_model_obj property |
|
1497 | - * |
|
1498 | - * @return EE_CPT_Base |
|
1499 | - */ |
|
1500 | - public function get_cpt_model_obj() |
|
1501 | - { |
|
1502 | - return $this->_cpt_model_obj; |
|
1503 | - } |
|
1448 | + } |
|
1449 | + |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * default method for the 'edit' route for cpt admin pages |
|
1453 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1454 | + * |
|
1455 | + * @access protected |
|
1456 | + * @return string template for edit cpt form |
|
1457 | + */ |
|
1458 | + protected function _edit_cpt_item() |
|
1459 | + { |
|
1460 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1461 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1462 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1463 | + if (empty($post)) { |
|
1464 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', 'event_espresso')); |
|
1465 | + } |
|
1466 | + if (! empty($_GET['get-post-lock'])) { |
|
1467 | + wp_set_post_lock($post_id); |
|
1468 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1469 | + exit(); |
|
1470 | + } |
|
1471 | + |
|
1472 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1473 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1474 | + $post_type_object = $this->_cpt_object; |
|
1475 | + |
|
1476 | + if (! wp_check_post_lock($post->ID)) { |
|
1477 | + wp_set_post_lock($post->ID); |
|
1478 | + } |
|
1479 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1480 | + if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1481 | + wp_enqueue_script('admin-comments'); |
|
1482 | + enqueue_comment_hotkeys_js(); |
|
1483 | + } |
|
1484 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1485 | + // modify the default editor title field with default title. |
|
1486 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1487 | + $this->loadEditorTemplate(false); |
|
1488 | + } |
|
1489 | + |
|
1490 | + |
|
1491 | + |
|
1492 | + /** |
|
1493 | + * some getters |
|
1494 | + */ |
|
1495 | + /** |
|
1496 | + * This returns the protected _cpt_model_obj property |
|
1497 | + * |
|
1498 | + * @return EE_CPT_Base |
|
1499 | + */ |
|
1500 | + public function get_cpt_model_obj() |
|
1501 | + { |
|
1502 | + return $this->_cpt_model_obj; |
|
1503 | + } |
|
1504 | 1504 | } |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | $this->_cpt_routes |
170 | 170 | ); |
171 | 171 | // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
172 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
173 | - ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
172 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
173 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
174 | 174 | : get_post_type_object($page); |
175 | 175 | // tweak pagenow for page loading. |
176 | - if (! $this->_pagenow_map) { |
|
176 | + if ( ! $this->_pagenow_map) { |
|
177 | 177 | $this->_pagenow_map = array( |
178 | 178 | 'create_new' => 'post-new.php', |
179 | 179 | 'edit' => 'post.php', |
@@ -207,12 +207,12 @@ discard block |
||
207 | 207 | { |
208 | 208 | global $pagenow, $hook_suffix; |
209 | 209 | // possibly reset pagenow. |
210 | - if (! empty($this->_req_data['page']) |
|
210 | + if ( ! empty($this->_req_data['page']) |
|
211 | 211 | && $this->_req_data['page'] == $this->page_slug |
212 | 212 | && ! empty($this->_req_data['action']) |
213 | - && isset($this->_pagenow_map[ $this->_req_data['action'] ]) |
|
213 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
214 | 214 | ) { |
215 | - $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ]; |
|
215 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
216 | 216 | $hook_suffix = $pagenow; |
217 | 217 | } |
218 | 218 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | if (empty($wp_meta_boxes)) { |
245 | 245 | return; |
246 | 246 | } |
247 | - $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array(); |
|
247 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
248 | 248 | foreach ($current_metaboxes as $box_context) { |
249 | 249 | foreach ($box_context as $box_details) { |
250 | 250 | foreach ($box_details as $box) { |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $this |
278 | 278 | ); |
279 | 279 | $containers = apply_filters( |
280 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
280 | + 'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
281 | 281 | $containers, |
282 | 282 | $this |
283 | 283 | ); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | protected function _load_page_dependencies() |
322 | 322 | { |
323 | 323 | // we only add stuff if this is a cpt_route! |
324 | - if (! $this->_cpt_route) { |
|
324 | + if ( ! $this->_cpt_route) { |
|
325 | 325 | parent::_load_page_dependencies(); |
326 | 326 | return; |
327 | 327 | } |
@@ -345,16 +345,16 @@ discard block |
||
345 | 345 | add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
346 | 346 | // This basically allows us to change the title of the "publish" metabox area |
347 | 347 | // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
348 | - if (! empty($this->_labels['publishbox'])) { |
|
348 | + if ( ! empty($this->_labels['publishbox'])) { |
|
349 | 349 | $box_label = is_array($this->_labels['publishbox']) |
350 | - && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
351 | - ? $this->_labels['publishbox'][ $this->_req_action ] |
|
350 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
351 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
352 | 352 | : $this->_labels['publishbox']; |
353 | 353 | add_meta_box( |
354 | 354 | 'submitdiv', |
355 | 355 | $box_label, |
356 | 356 | 'post_submit_meta_box', |
357 | - $this->_cpt_routes[ $this->_req_action ], |
|
357 | + $this->_cpt_routes[$this->_req_action], |
|
358 | 358 | 'side', |
359 | 359 | 'core' |
360 | 360 | ); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | 'page_templates', |
366 | 366 | __('Page Template', 'event_espresso'), |
367 | 367 | array($this, 'page_template_meta_box'), |
368 | - $this->_cpt_routes[ $this->_req_action ], |
|
368 | + $this->_cpt_routes[$this->_req_action], |
|
369 | 369 | 'side', |
370 | 370 | 'default' |
371 | 371 | ); |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | // This is for any plugins that are doing things properly |
398 | 398 | // and hooking into the load page hook for core wp cpt routes. |
399 | 399 | global $pagenow; |
400 | - add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20); |
|
401 | - do_action('load-' . $pagenow); |
|
400 | + add_action('load-'.$pagenow, array($this, 'modify_current_screen'), 20); |
|
401 | + do_action('load-'.$pagenow); |
|
402 | 402 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
403 | 403 | // we route REALLY early. |
404 | 404 | try { |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | 'admin.php?page=espresso_registrations&action=contact_list', |
428 | 428 | ), |
429 | 429 | 1 => array( |
430 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
430 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
431 | + 'admin.php?page='.$this->_cpt_object->name, |
|
432 | 432 | ), |
433 | 433 | ); |
434 | 434 | foreach ($routes_to_match as $route_matches) { |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
458 | 458 | ); |
459 | 459 | $cpt_args = $custom_post_types->getDefinitions(); |
460 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array(); |
|
460 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
461 | 461 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
462 | 462 | |
463 | 463 | // if the installed version of WP is > 4.7 we do some additional checks. |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | // if there are $post_templates for this cpt, then we return false for this method because |
467 | 467 | // that means we aren't going to load our page template manager and leave that up to the native |
468 | 468 | // cpt template manager. |
469 | - $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
469 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | return $cpt_has_support; |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | |
541 | 541 | $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
542 | 542 | $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
543 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
543 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
544 | 544 | : ''; |
545 | 545 | $template_args = array( |
546 | 546 | 'cur_status' => $this->_cpt_model_obj->status(), |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | $template_args['statuses'] = $statuses; |
556 | 556 | } |
557 | 557 | |
558 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
558 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
559 | 559 | EEH_Template::display_template($template, $template_args); |
560 | 560 | } |
561 | 561 | |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | : null; |
597 | 597 | $this->_verify_nonce($nonce, 'autosave'); |
598 | 598 | // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
599 | - if (! defined('DOING_AUTOSAVE')) { |
|
599 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
600 | 600 | define('DOING_AUTOSAVE', true); |
601 | 601 | } |
602 | 602 | // if we made it here then the nonce checked out. Let's run our methods and actions |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | $this->_template_args['success'] = true; |
608 | 608 | } |
609 | 609 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
610 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
610 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
611 | 611 | // now let's return json |
612 | 612 | $this->_return_json(); |
613 | 613 | } |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | return; |
630 | 630 | } |
631 | 631 | // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
632 | - if (! empty($this->_cpt_object)) { |
|
632 | + if ( ! empty($this->_cpt_object)) { |
|
633 | 633 | $this->_page_routes = array_merge( |
634 | 634 | array( |
635 | 635 | 'create_new' => '_create_new_cpt_item', |
@@ -660,10 +660,10 @@ discard block |
||
660 | 660 | ); |
661 | 661 | } |
662 | 662 | // load the next section only if this is a matching cpt route as set in the cpt routes array. |
663 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
663 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
664 | 664 | return; |
665 | 665 | } |
666 | - $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false; |
|
666 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
667 | 667 | // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
668 | 668 | if (empty($this->_cpt_object)) { |
669 | 669 | $msg = sprintf( |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | if (empty($this->_cpt_model_names) |
704 | 704 | || ( |
705 | 705 | ! $ignore_route_check |
706 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
706 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
707 | 707 | ) || ( |
708 | 708 | $this->_cpt_model_obj instanceof EE_CPT_Base |
709 | 709 | && $this->_cpt_model_obj->ID() === $id |
@@ -720,11 +720,11 @@ discard block |
||
720 | 720 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
721 | 721 | ); |
722 | 722 | $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
723 | - if (isset($model_names[ $post_type ])) { |
|
724 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
723 | + if (isset($model_names[$post_type])) { |
|
724 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
725 | 725 | } |
726 | 726 | } else { |
727 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
727 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
728 | 728 | } |
729 | 729 | if ($model instanceof EEM_Base) { |
730 | 730 | $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
@@ -754,8 +754,8 @@ discard block |
||
754 | 754 | $current_route = isset($this->_req_data['current_route']) |
755 | 755 | ? $this->_req_data['current_route'] |
756 | 756 | : 'shouldneverwork'; |
757 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
758 | - ? $this->_cpt_routes[ $current_route ] |
|
757 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
758 | + ? $this->_cpt_routes[$current_route] |
|
759 | 759 | : ''; |
760 | 760 | add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
761 | 761 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
@@ -764,10 +764,10 @@ discard block |
||
764 | 764 | } |
765 | 765 | // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
766 | 766 | $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
767 | - if (! empty($revision)) { |
|
767 | + if ( ! empty($revision)) { |
|
768 | 768 | $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
769 | 769 | // doing a restore? |
770 | - if (! empty($action) && $action === 'restore') { |
|
770 | + if ( ! empty($action) && $action === 'restore') { |
|
771 | 771 | // get post for revision |
772 | 772 | $rev_post = get_post($revision); |
773 | 773 | $rev_parent = get_post($rev_post->post_parent); |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | { |
804 | 804 | $this->_set_model_object($post_id, true, 'trash'); |
805 | 805 | // if our cpt object isn't existent then get out immediately. |
806 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
806 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
807 | 807 | return; |
808 | 808 | } |
809 | 809 | $this->trash_cpt_item($post_id); |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | { |
822 | 822 | $this->_set_model_object($post_id, true, 'restore'); |
823 | 823 | // if our cpt object isn't existent then get out immediately. |
824 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
824 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
825 | 825 | return; |
826 | 826 | } |
827 | 827 | $this->restore_cpt_item($post_id); |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | { |
840 | 840 | $this->_set_model_object($post_id, true, 'delete'); |
841 | 841 | // if our cpt object isn't existent then get out immediately. |
842 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
842 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
843 | 843 | return; |
844 | 844 | } |
845 | 845 | $this->delete_cpt_item($post_id); |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | { |
859 | 859 | $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
860 | 860 | // verify event object |
861 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
861 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
862 | 862 | throw new EE_Error( |
863 | 863 | sprintf( |
864 | 864 | __( |
@@ -914,13 +914,13 @@ discard block |
||
914 | 914 | if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
915 | 915 | // setup custom post status object for localize script but only if we've got a cpt object |
916 | 916 | $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
917 | - if (! empty($statuses)) { |
|
917 | + if ( ! empty($statuses)) { |
|
918 | 918 | // get ALL statuses! |
919 | 919 | $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
920 | 920 | // setup object |
921 | 921 | $ee_cpt_statuses = array(); |
922 | 922 | foreach ($statuses as $status => $label) { |
923 | - $ee_cpt_statuses[ $status ] = array( |
|
923 | + $ee_cpt_statuses[$status] = array( |
|
924 | 924 | 'label' => $label, |
925 | 925 | 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
926 | 926 | ); |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | $post->page_template = $this->_req_data['page_template']; |
983 | 983 | $page_templates = wp_get_theme()->get_page_templates($post); |
984 | 984 | } |
985 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) { |
|
985 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
986 | 986 | EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
987 | 987 | } else { |
988 | 988 | update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | { |
1008 | 1008 | // only do this if we're actually processing one of our CPTs |
1009 | 1009 | // if our cpt object isn't existent then get out immediately. |
1010 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1010 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1011 | 1011 | return; |
1012 | 1012 | } |
1013 | 1013 | delete_post_meta($post_id, '_wp_trash_meta_status'); |
@@ -1032,7 +1032,7 @@ discard block |
||
1032 | 1032 | // global action |
1033 | 1033 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
1034 | 1034 | // class specific action so you can limit hooking into a specific page. |
1035 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1035 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | |
@@ -1059,11 +1059,11 @@ discard block |
||
1059 | 1059 | public function modify_current_screen() |
1060 | 1060 | { |
1061 | 1061 | // ONLY do this if the current page_route IS a cpt route |
1062 | - if (! $this->_cpt_route) { |
|
1062 | + if ( ! $this->_cpt_route) { |
|
1063 | 1063 | return; |
1064 | 1064 | } |
1065 | 1065 | // routing things REALLY early b/c this is a cpt admin page |
1066 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1066 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1067 | 1067 | $this->_current_screen = get_current_screen(); |
1068 | 1068 | $this->_current_screen->base = 'event-espresso'; |
1069 | 1069 | $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
@@ -1086,8 +1086,8 @@ discard block |
||
1086 | 1086 | */ |
1087 | 1087 | public function add_custom_editor_default_title($title) |
1088 | 1088 | { |
1089 | - return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
1090 | - ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1089 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1090 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1091 | 1091 | : $title; |
1092 | 1092 | } |
1093 | 1093 | |
@@ -1103,10 +1103,10 @@ discard block |
||
1103 | 1103 | */ |
1104 | 1104 | public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
1105 | 1105 | { |
1106 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
1106 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1107 | 1107 | $post = get_post($id); |
1108 | 1108 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
1109 | - $shortlink = home_url('?p=' . $post->ID); |
|
1109 | + $shortlink = home_url('?p='.$post->ID); |
|
1110 | 1110 | } |
1111 | 1111 | } |
1112 | 1112 | return $shortlink; |
@@ -1139,11 +1139,11 @@ discard block |
||
1139 | 1139 | */ |
1140 | 1140 | public function cpt_post_form_hidden_input() |
1141 | 1141 | { |
1142 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1142 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
1143 | 1143 | // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
1144 | 1144 | echo '<div id="ee-cpt-hidden-inputs">'; |
1145 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1146 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1145 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
1146 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
1147 | 1147 | echo '</div>'; |
1148 | 1148 | } |
1149 | 1149 | |
@@ -1188,15 +1188,15 @@ discard block |
||
1188 | 1188 | public function modify_edit_post_link($link, $id, $context) |
1189 | 1189 | { |
1190 | 1190 | $post = get_post($id); |
1191 | - if (! isset($this->_req_data['action']) |
|
1192 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1193 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1191 | + if ( ! isset($this->_req_data['action']) |
|
1192 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1193 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1194 | 1194 | ) { |
1195 | 1195 | return $link; |
1196 | 1196 | } |
1197 | 1197 | $query_args = array( |
1198 | - 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
1199 | - ? $this->_cpt_edit_routes[ $post->post_type ] |
|
1198 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1199 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
1200 | 1200 | : 'edit', |
1201 | 1201 | 'post' => $id, |
1202 | 1202 | ); |
@@ -1219,16 +1219,16 @@ discard block |
||
1219 | 1219 | $post = get_post($post_id); |
1220 | 1220 | |
1221 | 1221 | if (empty($this->_req_data['action']) |
1222 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1222 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1223 | 1223 | || ! $post instanceof WP_Post |
1224 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1224 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1225 | 1225 | ) { |
1226 | 1226 | return $delete_link; |
1227 | 1227 | } |
1228 | 1228 | $this->_set_model_object($post->ID, true); |
1229 | 1229 | |
1230 | 1230 | // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
1231 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1231 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1232 | 1232 | |
1233 | 1233 | return EE_Admin_Page::add_query_args_and_nonce( |
1234 | 1234 | array( |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | // we DO have a match so let's setup the url |
1257 | 1257 | // we have to get the post to determine our route |
1258 | 1258 | $post = get_post($post_id); |
1259 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1259 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1260 | 1260 | // shared query_args |
1261 | 1261 | $query_args = array('action' => $edit_route, 'post' => $post_id); |
1262 | 1262 | $admin_url = $this->_admin_base_url; |
@@ -1328,12 +1328,12 @@ discard block |
||
1328 | 1328 | /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
1329 | 1329 | |
1330 | 1330 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1331 | - $messages[ $post->post_type ] = array( |
|
1331 | + $messages[$post->post_type] = array( |
|
1332 | 1332 | 0 => '', // Unused. Messages start at index 1. |
1333 | 1333 | 1 => sprintf( |
1334 | 1334 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
1335 | 1335 | $this->_cpt_object->labels->singular_name, |
1336 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1336 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1337 | 1337 | '</a>' |
1338 | 1338 | ), |
1339 | 1339 | 2 => __('Custom field updated', 'event_espresso'), |
@@ -1348,27 +1348,27 @@ discard block |
||
1348 | 1348 | 6 => sprintf( |
1349 | 1349 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
1350 | 1350 | $this->_cpt_object->labels->singular_name, |
1351 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1351 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1352 | 1352 | '</a>' |
1353 | 1353 | ), |
1354 | 1354 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1355 | 1355 | 8 => sprintf( |
1356 | 1356 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
1357 | 1357 | $this->_cpt_object->labels->singular_name, |
1358 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1358 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
1359 | 1359 | '</a>' |
1360 | 1360 | ), |
1361 | 1361 | 9 => sprintf( |
1362 | 1362 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
1363 | 1363 | $this->_cpt_object->labels->singular_name, |
1364 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1365 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1364 | + '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>', |
|
1365 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
1366 | 1366 | '</a>' |
1367 | 1367 | ), |
1368 | 1368 | 10 => sprintf( |
1369 | 1369 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
1370 | 1370 | $this->_cpt_object->labels->singular_name, |
1371 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1371 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1372 | 1372 | '</a>' |
1373 | 1373 | ), |
1374 | 1374 | ); |
@@ -1387,10 +1387,10 @@ discard block |
||
1387 | 1387 | { |
1388 | 1388 | // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
1389 | 1389 | global $post, $title, $is_IE, $post_type, $post_type_object; |
1390 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1390 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1391 | 1391 | $post_type_object = $this->_cpt_object; |
1392 | 1392 | $title = $post_type_object->labels->add_new_item; |
1393 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1393 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1394 | 1394 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1395 | 1395 | // modify the default editor title field with default title. |
1396 | 1396 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
@@ -1415,8 +1415,8 @@ discard block |
||
1415 | 1415 | if ($creating) { |
1416 | 1416 | wp_enqueue_script('autosave'); |
1417 | 1417 | } else { |
1418 | - if (isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1419 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
1418 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1419 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1420 | 1420 | ) { |
1421 | 1421 | $create_new_action = apply_filters( |
1422 | 1422 | 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | ); |
1433 | 1433 | } |
1434 | 1434 | } |
1435 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1435 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1436 | 1436 | } |
1437 | 1437 | } |
1438 | 1438 | |
@@ -1463,21 +1463,21 @@ discard block |
||
1463 | 1463 | if (empty($post)) { |
1464 | 1464 | wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', 'event_espresso')); |
1465 | 1465 | } |
1466 | - if (! empty($_GET['get-post-lock'])) { |
|
1466 | + if ( ! empty($_GET['get-post-lock'])) { |
|
1467 | 1467 | wp_set_post_lock($post_id); |
1468 | 1468 | wp_redirect(get_edit_post_link($post_id, 'url')); |
1469 | 1469 | exit(); |
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
1473 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1473 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1474 | 1474 | $post_type_object = $this->_cpt_object; |
1475 | 1475 | |
1476 | - if (! wp_check_post_lock($post->ID)) { |
|
1476 | + if ( ! wp_check_post_lock($post->ID)) { |
|
1477 | 1477 | wp_set_post_lock($post->ID); |
1478 | 1478 | } |
1479 | 1479 | add_action('admin_footer', '_admin_notice_post_locked'); |
1480 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1480 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1481 | 1481 | wp_enqueue_script('admin-comments'); |
1482 | 1482 | enqueue_comment_hotkeys_js(); |
1483 | 1483 | } |
@@ -12,645 +12,645 @@ |
||
12 | 12 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * array of events |
|
17 | - * |
|
18 | - * @type EE_Line_Item[] $_events |
|
19 | - */ |
|
20 | - private $_events = array(); |
|
21 | - |
|
22 | - /** |
|
23 | - * whether to display the taxes row or not |
|
24 | - * |
|
25 | - * @type bool $_show_taxes |
|
26 | - */ |
|
27 | - private $_show_taxes = false; |
|
28 | - |
|
29 | - /** |
|
30 | - * html for any tax rows |
|
31 | - * |
|
32 | - * @type string $_show_taxes |
|
33 | - */ |
|
34 | - private $_taxes_html = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * total amount including tax we can bill for at this time |
|
38 | - * |
|
39 | - * @type float $_grand_total |
|
40 | - */ |
|
41 | - private $_grand_total = 0.00; |
|
42 | - |
|
43 | - /** |
|
44 | - * total number of items being billed for |
|
45 | - * |
|
46 | - * @type int $_total_items |
|
47 | - */ |
|
48 | - private $_total_items = 0; |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return float |
|
54 | - */ |
|
55 | - public function grand_total() |
|
56 | - { |
|
57 | - return $this->_grand_total; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function total_items() |
|
66 | - { |
|
67 | - return $this->_total_items; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param EE_Line_Item $line_item |
|
74 | - * @param array $options |
|
75 | - * @param EE_Line_Item $parent_line_item |
|
76 | - * @return mixed |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - public function display_line_item( |
|
80 | - EE_Line_Item $line_item, |
|
81 | - $options = array(), |
|
82 | - EE_Line_Item $parent_line_item = null |
|
83 | - ) { |
|
84 | - $html = ''; |
|
85 | - // set some default options and merge with incoming |
|
86 | - $default_options = array( |
|
87 | - 'show_desc' => true, // true false |
|
88 | - 'odd' => false, |
|
89 | - ); |
|
90 | - $options = array_merge($default_options, (array) $options); |
|
91 | - switch ($line_item->type()) { |
|
92 | - case EEM_Line_Item::type_line_item: |
|
93 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
94 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
95 | - // item row |
|
96 | - $html .= $this->_ticket_row($line_item, $options); |
|
97 | - } else { |
|
98 | - // item row |
|
99 | - $html .= $this->_item_row($line_item, $options); |
|
100 | - } |
|
101 | - if (apply_filters( |
|
102 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
103 | - true |
|
104 | - ) |
|
105 | - ) { |
|
106 | - // got any kids? |
|
107 | - foreach ($line_item->children() as $child_line_item) { |
|
108 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
109 | - } |
|
110 | - } |
|
111 | - break; |
|
112 | - case EEM_Line_Item::type_sub_line_item: |
|
113 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
114 | - break; |
|
115 | - case EEM_Line_Item::type_sub_total: |
|
116 | - static $sub_total = 0; |
|
117 | - $event_sub_total = 0; |
|
118 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
119 | - if ($line_item->OBJ_type() === 'Event') { |
|
120 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
121 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
122 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
123 | - // if event has default reg status of Not Approved, then don't display info on it |
|
124 | - if ($event instanceof EE_Event |
|
125 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
126 | - ) { |
|
127 | - $display_event = false; |
|
128 | - // unless there are registrations for it that are returning to pay |
|
129 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
130 | - foreach ($options['registrations'] as $registration) { |
|
131 | - if (! $registration instanceof EE_Registration) { |
|
132 | - continue; |
|
133 | - } |
|
134 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
135 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
136 | - ? true |
|
137 | - : $display_event; |
|
138 | - } |
|
139 | - } |
|
140 | - if (! $display_event) { |
|
141 | - return ''; |
|
142 | - } |
|
143 | - } |
|
144 | - $this->_events[ $options['event_id'] ] = 0; |
|
145 | - $html .= $this->_event_row($line_item); |
|
146 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
147 | - } |
|
148 | - } |
|
149 | - $child_line_items = $line_item->children(); |
|
150 | - // loop thru children |
|
151 | - foreach ($child_line_items as $child_line_item) { |
|
152 | - // recursively feed children back into this method |
|
153 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
154 | - } |
|
155 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
156 | - $sub_total += $event_sub_total; |
|
157 | - if (( |
|
158 | - // event subtotals |
|
159 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
160 | - ) |
|
161 | - || ( |
|
162 | - // pre-tax subtotals |
|
163 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
164 | - ) |
|
165 | - ) { |
|
166 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
167 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
168 | - } |
|
169 | - break; |
|
170 | - case EEM_Line_Item::type_tax: |
|
171 | - if ($this->_show_taxes) { |
|
172 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
173 | - } |
|
174 | - break; |
|
175 | - case EEM_Line_Item::type_tax_sub_total: |
|
176 | - if ($this->_show_taxes) { |
|
177 | - $child_line_items = $line_item->children(); |
|
178 | - // loop thru children |
|
179 | - foreach ($child_line_items as $child_line_item) { |
|
180 | - // recursively feed children back into this method |
|
181 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
182 | - } |
|
183 | - if (count($child_line_items) > 1) { |
|
184 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
185 | - } |
|
186 | - } |
|
187 | - break; |
|
188 | - case EEM_Line_Item::type_total: |
|
189 | - // get all child line items |
|
190 | - $children = $line_item->children(); |
|
191 | - // loop thru all non-tax child line items |
|
192 | - foreach ($children as $child_line_item) { |
|
193 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
194 | - // recursively feed children back into this method |
|
195 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
196 | - } |
|
197 | - } |
|
198 | - // now loop thru tax child line items |
|
199 | - foreach ($children as $child_line_item) { |
|
200 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
201 | - // recursively feed children back into this method |
|
202 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | - } |
|
204 | - } |
|
205 | - $html .= $this->_taxes_html; |
|
206 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
207 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
208 | - break; |
|
209 | - } |
|
210 | - return $html; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
217 | - * |
|
218 | - * @param EE_Line_Item $line_item |
|
219 | - * @return mixed |
|
220 | - */ |
|
221 | - private function _event_row(EE_Line_Item $line_item) |
|
222 | - { |
|
223 | - // start of row |
|
224 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
225 | - // event name td |
|
226 | - $html .= EEH_HTML::td( |
|
227 | - EEH_HTML::strong($line_item->name()), |
|
228 | - '', |
|
229 | - 'event-header', |
|
230 | - '', |
|
231 | - ' colspan="4"' |
|
232 | - ); |
|
233 | - // end of row |
|
234 | - $html .= EEH_HTML::trx(); |
|
235 | - return $html; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * _ticket_row |
|
242 | - * |
|
243 | - * @param EE_Line_Item $line_item |
|
244 | - * @param array $options |
|
245 | - * @return mixed |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
249 | - { |
|
250 | - // start of row |
|
251 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
252 | - $html = EEH_HTML::tr('', '', $row_class); |
|
253 | - // name && desc |
|
254 | - $name_and_desc = apply_filters( |
|
255 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
256 | - $line_item->name(), |
|
257 | - $line_item |
|
258 | - ); |
|
259 | - $name_and_desc .= apply_filters( |
|
260 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
261 | - ( |
|
262 | - $options['show_desc'] |
|
263 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
264 | - : '' |
|
265 | - ), |
|
266 | - $line_item, |
|
267 | - $options |
|
268 | - ); |
|
269 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
270 | - // name td |
|
271 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
272 | - $name_and_desc, |
|
273 | - '', |
|
274 | - 'item_l' |
|
275 | - ); |
|
276 | - // price td |
|
277 | - $price = apply_filters( |
|
278 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
279 | - $line_item->unit_price_no_code(), |
|
280 | - $line_item |
|
281 | - ); |
|
282 | - $html .= EEH_HTML::td($price, '', 'item_c jst-rght'); |
|
283 | - // quantity td |
|
284 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
285 | - $this->_total_items += $line_item->quantity(); |
|
286 | - // determine total for line item |
|
287 | - $total = apply_filters( |
|
288 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
289 | - $line_item->total(), |
|
290 | - $line_item |
|
291 | - ); |
|
292 | - $this->_events[ $options['event_id'] ] += $total; |
|
293 | - // total td |
|
294 | - $html .= EEH_HTML::td( |
|
295 | - EEH_Template::format_currency($total, false, false), |
|
296 | - '', |
|
297 | - 'item_r jst-rght' |
|
298 | - ); |
|
299 | - // end of row |
|
300 | - $html .= EEH_HTML::trx(); |
|
301 | - return $html; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * _item_row |
|
308 | - * |
|
309 | - * @param EE_Line_Item $line_item |
|
310 | - * @param array $options |
|
311 | - * @return mixed |
|
312 | - * @throws EE_Error |
|
313 | - */ |
|
314 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
315 | - { |
|
316 | - // start of row |
|
317 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
318 | - $html = EEH_HTML::tr('', '', $row_class); |
|
319 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
320 | - // name && desc |
|
321 | - $name_and_desc = apply_filters( |
|
322 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
323 | - $obj_name . $line_item->name(), |
|
324 | - $line_item |
|
325 | - ); |
|
326 | - $name_and_desc .= apply_filters( |
|
327 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
328 | - ( |
|
329 | - $options['show_desc'] |
|
330 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
331 | - : '' |
|
332 | - ), |
|
333 | - $line_item, |
|
334 | - $options |
|
335 | - ); |
|
336 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
337 | - // name td |
|
338 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
339 | - // price td |
|
340 | - if ($line_item->is_percent()) { |
|
341 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
342 | - } else { |
|
343 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
344 | - } |
|
345 | - // quantity td |
|
346 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
347 | - // $total = $line_item->total() * $line_item->quantity(); |
|
348 | - $total = $line_item->total(); |
|
349 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
350 | - $this->_events[ $options['event_id'] ] += $total; |
|
351 | - } |
|
352 | - // total td |
|
353 | - $html .= EEH_HTML::td( |
|
354 | - EEH_Template::format_currency($total, false, false), |
|
355 | - '', |
|
356 | - 'item_r jst-rght' |
|
357 | - ); |
|
358 | - // end of row |
|
359 | - $html .= EEH_HTML::trx(); |
|
360 | - return $html; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * _sub_item_row |
|
367 | - * |
|
368 | - * @param EE_Line_Item $line_item |
|
369 | - * @param array $options |
|
370 | - * @param EE_Line_Item $parent_line_item |
|
371 | - * @return mixed |
|
372 | - * @throws EE_Error |
|
373 | - */ |
|
374 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
375 | - { |
|
376 | - if ($parent_line_item instanceof EE_Line_Item |
|
377 | - && $line_item->children() === array() |
|
378 | - && $line_item->name() === $parent_line_item->name() |
|
379 | - && apply_filters( |
|
380 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
381 | - true |
|
382 | - ) |
|
383 | - ) { |
|
384 | - return ''; |
|
385 | - } |
|
386 | - // start of row |
|
387 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
388 | - // name && desc |
|
389 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
390 | - . $line_item->name(); |
|
391 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
392 | - . $line_item->desc() |
|
393 | - . '</span>' : ''; |
|
394 | - // name td |
|
395 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
396 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
397 | - // discount/surcharge td |
|
398 | - if ($line_item->is_percent()) { |
|
399 | - $html .= EEH_HTML::td( |
|
400 | - EEH_Template::format_currency( |
|
401 | - $line_item->total() / $qty, |
|
402 | - false, |
|
403 | - false |
|
404 | - ), |
|
405 | - '', |
|
406 | - 'item_c jst-rght' |
|
407 | - ); |
|
408 | - } else { |
|
409 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
410 | - } |
|
411 | - // no quantity td |
|
412 | - $html .= EEH_HTML::td(); |
|
413 | - // no total td |
|
414 | - $html .= EEH_HTML::td(); |
|
415 | - // end of row |
|
416 | - $html .= EEH_HTML::trx(); |
|
417 | - $html = apply_filters( |
|
418 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
419 | - $html, |
|
420 | - $line_item, |
|
421 | - $options, |
|
422 | - $parent_line_item |
|
423 | - ); |
|
424 | - return $html; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * _tax_row |
|
431 | - * |
|
432 | - * @param EE_Line_Item $line_item |
|
433 | - * @param array $options |
|
434 | - * @return mixed |
|
435 | - * @throws EE_Error |
|
436 | - */ |
|
437 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
438 | - { |
|
439 | - // start of row |
|
440 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
441 | - // name && desc |
|
442 | - $name_and_desc = $line_item->name(); |
|
443 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
444 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
445 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
446 | - // name td |
|
447 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
448 | - $name_and_desc, |
|
449 | - '', |
|
450 | - 'item_l sub-item' |
|
451 | - ); |
|
452 | - // percent td |
|
453 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
454 | - // empty td (price) |
|
455 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
456 | - // total td |
|
457 | - $html .= EEH_HTML::td( |
|
458 | - EEH_Template::format_currency( |
|
459 | - $line_item->total(), |
|
460 | - false, |
|
461 | - false |
|
462 | - ), |
|
463 | - '', |
|
464 | - 'item_r jst-rght' |
|
465 | - ); |
|
466 | - // end of row |
|
467 | - $html .= EEH_HTML::trx(); |
|
468 | - return $html; |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * _total_row |
|
475 | - * |
|
476 | - * @param EE_Line_Item $line_item |
|
477 | - * @param string $text |
|
478 | - * @return mixed |
|
479 | - * @throws EE_Error |
|
480 | - */ |
|
481 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
482 | - { |
|
483 | - $html = ''; |
|
484 | - if ($line_item->total()) { |
|
485 | - // start of row |
|
486 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
487 | - // total td |
|
488 | - $html .= EEH_HTML::td( |
|
489 | - $text, |
|
490 | - '', |
|
491 | - 'total_currency total jst-rght', |
|
492 | - '', |
|
493 | - ' colspan="2"' |
|
494 | - ); |
|
495 | - // empty td (price) |
|
496 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
497 | - // total td |
|
498 | - $html .= EEH_HTML::td( |
|
499 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
500 | - '', |
|
501 | - 'total jst-rght' |
|
502 | - ); |
|
503 | - // end of row |
|
504 | - $html .= EEH_HTML::trx(); |
|
505 | - } |
|
506 | - return $html; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * _total_row |
|
513 | - * |
|
514 | - * @param EE_Line_Item $line_item |
|
515 | - * @param string $text |
|
516 | - * @param array $options |
|
517 | - * @return mixed |
|
518 | - * @throws EE_Error |
|
519 | - */ |
|
520 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
521 | - { |
|
522 | - $html = ''; |
|
523 | - if ($line_item->total()) { |
|
524 | - // start of row |
|
525 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
526 | - // total td |
|
527 | - $html .= EEH_HTML::td( |
|
528 | - $text, |
|
529 | - '', |
|
530 | - 'total_currency total jst-rght', |
|
531 | - '', |
|
532 | - ' colspan="3"' |
|
533 | - ); |
|
534 | - // total td |
|
535 | - $html .= EEH_HTML::td( |
|
536 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
537 | - '', |
|
538 | - 'total jst-rght' |
|
539 | - ); |
|
540 | - // end of row |
|
541 | - $html .= EEH_HTML::trx(); |
|
542 | - } |
|
543 | - return $html; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * _total_row |
|
550 | - * |
|
551 | - * @param EE_Line_Item $line_item |
|
552 | - * @param string $text |
|
553 | - * @return mixed |
|
554 | - * @throws EE_Error |
|
555 | - */ |
|
556 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
557 | - { |
|
558 | - // start of row |
|
559 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
560 | - // total td |
|
561 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
562 | - // total td |
|
563 | - $html .= EEH_HTML::td( |
|
564 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
565 | - '', |
|
566 | - 'total jst-rght' |
|
567 | - ); |
|
568 | - // end of row |
|
569 | - $html .= EEH_HTML::trx(); |
|
570 | - return $html; |
|
571 | - } |
|
572 | - |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * _payments_and_amount_owing_rows |
|
577 | - * |
|
578 | - * @param EE_Line_Item $line_item |
|
579 | - * @param array $options |
|
580 | - * @return mixed |
|
581 | - * @throws EE_Error |
|
582 | - */ |
|
583 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
584 | - { |
|
585 | - $html = ''; |
|
586 | - $owing = $line_item->total(); |
|
587 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
588 | - if ($transaction instanceof EE_Transaction) { |
|
589 | - $registration_payments = array(); |
|
590 | - $registrations = ! empty($options['registrations']) |
|
591 | - ? $options['registrations'] |
|
592 | - : $transaction->registrations(); |
|
593 | - foreach ($registrations as $registration) { |
|
594 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
595 | - $registration_payments += $registration->registration_payments(); |
|
596 | - } |
|
597 | - } |
|
598 | - if (! empty($registration_payments)) { |
|
599 | - foreach ($registration_payments as $registration_payment) { |
|
600 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
601 | - $owing -= $registration_payment->amount(); |
|
602 | - $payment = $registration_payment->payment(); |
|
603 | - $payment_desc = ''; |
|
604 | - if ($payment instanceof EE_Payment) { |
|
605 | - $payment_desc = sprintf( |
|
606 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
607 | - $payment->txn_id_chq_nmbr() !== '' |
|
608 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
609 | - : '', |
|
610 | - $payment->timestamp() |
|
611 | - ); |
|
612 | - } |
|
613 | - // start of row |
|
614 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
615 | - // payment desc |
|
616 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
617 | - // total td |
|
618 | - $html .= EEH_HTML::td( |
|
619 | - EEH_Template::format_currency( |
|
620 | - $registration_payment->amount(), |
|
621 | - false, |
|
622 | - false |
|
623 | - ), |
|
624 | - '', |
|
625 | - 'total jst-rght' |
|
626 | - ); |
|
627 | - // end of row |
|
628 | - $html .= EEH_HTML::trx(); |
|
629 | - } |
|
630 | - } |
|
631 | - if ($line_item->total()) { |
|
632 | - // start of row |
|
633 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
634 | - // total td |
|
635 | - $html .= EEH_HTML::td( |
|
636 | - esc_html__('Amount Owing', 'event_espresso'), |
|
637 | - '', |
|
638 | - 'total_currency total jst-rght', |
|
639 | - '', |
|
640 | - ' colspan="3"' |
|
641 | - ); |
|
642 | - // total td |
|
643 | - $html .= EEH_HTML::td( |
|
644 | - EEH_Template::format_currency($owing, false, false), |
|
645 | - '', |
|
646 | - 'total jst-rght' |
|
647 | - ); |
|
648 | - // end of row |
|
649 | - $html .= EEH_HTML::trx(); |
|
650 | - } |
|
651 | - } |
|
652 | - } |
|
653 | - $this->_grand_total = $owing; |
|
654 | - return $html; |
|
655 | - } |
|
15 | + /** |
|
16 | + * array of events |
|
17 | + * |
|
18 | + * @type EE_Line_Item[] $_events |
|
19 | + */ |
|
20 | + private $_events = array(); |
|
21 | + |
|
22 | + /** |
|
23 | + * whether to display the taxes row or not |
|
24 | + * |
|
25 | + * @type bool $_show_taxes |
|
26 | + */ |
|
27 | + private $_show_taxes = false; |
|
28 | + |
|
29 | + /** |
|
30 | + * html for any tax rows |
|
31 | + * |
|
32 | + * @type string $_show_taxes |
|
33 | + */ |
|
34 | + private $_taxes_html = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * total amount including tax we can bill for at this time |
|
38 | + * |
|
39 | + * @type float $_grand_total |
|
40 | + */ |
|
41 | + private $_grand_total = 0.00; |
|
42 | + |
|
43 | + /** |
|
44 | + * total number of items being billed for |
|
45 | + * |
|
46 | + * @type int $_total_items |
|
47 | + */ |
|
48 | + private $_total_items = 0; |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return float |
|
54 | + */ |
|
55 | + public function grand_total() |
|
56 | + { |
|
57 | + return $this->_grand_total; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function total_items() |
|
66 | + { |
|
67 | + return $this->_total_items; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param EE_Line_Item $line_item |
|
74 | + * @param array $options |
|
75 | + * @param EE_Line_Item $parent_line_item |
|
76 | + * @return mixed |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + public function display_line_item( |
|
80 | + EE_Line_Item $line_item, |
|
81 | + $options = array(), |
|
82 | + EE_Line_Item $parent_line_item = null |
|
83 | + ) { |
|
84 | + $html = ''; |
|
85 | + // set some default options and merge with incoming |
|
86 | + $default_options = array( |
|
87 | + 'show_desc' => true, // true false |
|
88 | + 'odd' => false, |
|
89 | + ); |
|
90 | + $options = array_merge($default_options, (array) $options); |
|
91 | + switch ($line_item->type()) { |
|
92 | + case EEM_Line_Item::type_line_item: |
|
93 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
94 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
95 | + // item row |
|
96 | + $html .= $this->_ticket_row($line_item, $options); |
|
97 | + } else { |
|
98 | + // item row |
|
99 | + $html .= $this->_item_row($line_item, $options); |
|
100 | + } |
|
101 | + if (apply_filters( |
|
102 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
103 | + true |
|
104 | + ) |
|
105 | + ) { |
|
106 | + // got any kids? |
|
107 | + foreach ($line_item->children() as $child_line_item) { |
|
108 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
109 | + } |
|
110 | + } |
|
111 | + break; |
|
112 | + case EEM_Line_Item::type_sub_line_item: |
|
113 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
114 | + break; |
|
115 | + case EEM_Line_Item::type_sub_total: |
|
116 | + static $sub_total = 0; |
|
117 | + $event_sub_total = 0; |
|
118 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
119 | + if ($line_item->OBJ_type() === 'Event') { |
|
120 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
121 | + if (! isset($this->_events[ $options['event_id'] ])) { |
|
122 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
123 | + // if event has default reg status of Not Approved, then don't display info on it |
|
124 | + if ($event instanceof EE_Event |
|
125 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
126 | + ) { |
|
127 | + $display_event = false; |
|
128 | + // unless there are registrations for it that are returning to pay |
|
129 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
130 | + foreach ($options['registrations'] as $registration) { |
|
131 | + if (! $registration instanceof EE_Registration) { |
|
132 | + continue; |
|
133 | + } |
|
134 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
135 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
136 | + ? true |
|
137 | + : $display_event; |
|
138 | + } |
|
139 | + } |
|
140 | + if (! $display_event) { |
|
141 | + return ''; |
|
142 | + } |
|
143 | + } |
|
144 | + $this->_events[ $options['event_id'] ] = 0; |
|
145 | + $html .= $this->_event_row($line_item); |
|
146 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
147 | + } |
|
148 | + } |
|
149 | + $child_line_items = $line_item->children(); |
|
150 | + // loop thru children |
|
151 | + foreach ($child_line_items as $child_line_item) { |
|
152 | + // recursively feed children back into this method |
|
153 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
154 | + } |
|
155 | + $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
156 | + $sub_total += $event_sub_total; |
|
157 | + if (( |
|
158 | + // event subtotals |
|
159 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
160 | + ) |
|
161 | + || ( |
|
162 | + // pre-tax subtotals |
|
163 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
164 | + ) |
|
165 | + ) { |
|
166 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
167 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
168 | + } |
|
169 | + break; |
|
170 | + case EEM_Line_Item::type_tax: |
|
171 | + if ($this->_show_taxes) { |
|
172 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
173 | + } |
|
174 | + break; |
|
175 | + case EEM_Line_Item::type_tax_sub_total: |
|
176 | + if ($this->_show_taxes) { |
|
177 | + $child_line_items = $line_item->children(); |
|
178 | + // loop thru children |
|
179 | + foreach ($child_line_items as $child_line_item) { |
|
180 | + // recursively feed children back into this method |
|
181 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
182 | + } |
|
183 | + if (count($child_line_items) > 1) { |
|
184 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
185 | + } |
|
186 | + } |
|
187 | + break; |
|
188 | + case EEM_Line_Item::type_total: |
|
189 | + // get all child line items |
|
190 | + $children = $line_item->children(); |
|
191 | + // loop thru all non-tax child line items |
|
192 | + foreach ($children as $child_line_item) { |
|
193 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
194 | + // recursively feed children back into this method |
|
195 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
196 | + } |
|
197 | + } |
|
198 | + // now loop thru tax child line items |
|
199 | + foreach ($children as $child_line_item) { |
|
200 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
201 | + // recursively feed children back into this method |
|
202 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | + } |
|
204 | + } |
|
205 | + $html .= $this->_taxes_html; |
|
206 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
207 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
208 | + break; |
|
209 | + } |
|
210 | + return $html; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
217 | + * |
|
218 | + * @param EE_Line_Item $line_item |
|
219 | + * @return mixed |
|
220 | + */ |
|
221 | + private function _event_row(EE_Line_Item $line_item) |
|
222 | + { |
|
223 | + // start of row |
|
224 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
225 | + // event name td |
|
226 | + $html .= EEH_HTML::td( |
|
227 | + EEH_HTML::strong($line_item->name()), |
|
228 | + '', |
|
229 | + 'event-header', |
|
230 | + '', |
|
231 | + ' colspan="4"' |
|
232 | + ); |
|
233 | + // end of row |
|
234 | + $html .= EEH_HTML::trx(); |
|
235 | + return $html; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * _ticket_row |
|
242 | + * |
|
243 | + * @param EE_Line_Item $line_item |
|
244 | + * @param array $options |
|
245 | + * @return mixed |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
249 | + { |
|
250 | + // start of row |
|
251 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
252 | + $html = EEH_HTML::tr('', '', $row_class); |
|
253 | + // name && desc |
|
254 | + $name_and_desc = apply_filters( |
|
255 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
256 | + $line_item->name(), |
|
257 | + $line_item |
|
258 | + ); |
|
259 | + $name_and_desc .= apply_filters( |
|
260 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
261 | + ( |
|
262 | + $options['show_desc'] |
|
263 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
264 | + : '' |
|
265 | + ), |
|
266 | + $line_item, |
|
267 | + $options |
|
268 | + ); |
|
269 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
270 | + // name td |
|
271 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
272 | + $name_and_desc, |
|
273 | + '', |
|
274 | + 'item_l' |
|
275 | + ); |
|
276 | + // price td |
|
277 | + $price = apply_filters( |
|
278 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
279 | + $line_item->unit_price_no_code(), |
|
280 | + $line_item |
|
281 | + ); |
|
282 | + $html .= EEH_HTML::td($price, '', 'item_c jst-rght'); |
|
283 | + // quantity td |
|
284 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
285 | + $this->_total_items += $line_item->quantity(); |
|
286 | + // determine total for line item |
|
287 | + $total = apply_filters( |
|
288 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
289 | + $line_item->total(), |
|
290 | + $line_item |
|
291 | + ); |
|
292 | + $this->_events[ $options['event_id'] ] += $total; |
|
293 | + // total td |
|
294 | + $html .= EEH_HTML::td( |
|
295 | + EEH_Template::format_currency($total, false, false), |
|
296 | + '', |
|
297 | + 'item_r jst-rght' |
|
298 | + ); |
|
299 | + // end of row |
|
300 | + $html .= EEH_HTML::trx(); |
|
301 | + return $html; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * _item_row |
|
308 | + * |
|
309 | + * @param EE_Line_Item $line_item |
|
310 | + * @param array $options |
|
311 | + * @return mixed |
|
312 | + * @throws EE_Error |
|
313 | + */ |
|
314 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
315 | + { |
|
316 | + // start of row |
|
317 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
318 | + $html = EEH_HTML::tr('', '', $row_class); |
|
319 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
320 | + // name && desc |
|
321 | + $name_and_desc = apply_filters( |
|
322 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
323 | + $obj_name . $line_item->name(), |
|
324 | + $line_item |
|
325 | + ); |
|
326 | + $name_and_desc .= apply_filters( |
|
327 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
328 | + ( |
|
329 | + $options['show_desc'] |
|
330 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
331 | + : '' |
|
332 | + ), |
|
333 | + $line_item, |
|
334 | + $options |
|
335 | + ); |
|
336 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
337 | + // name td |
|
338 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
339 | + // price td |
|
340 | + if ($line_item->is_percent()) { |
|
341 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
342 | + } else { |
|
343 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
344 | + } |
|
345 | + // quantity td |
|
346 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
347 | + // $total = $line_item->total() * $line_item->quantity(); |
|
348 | + $total = $line_item->total(); |
|
349 | + if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
350 | + $this->_events[ $options['event_id'] ] += $total; |
|
351 | + } |
|
352 | + // total td |
|
353 | + $html .= EEH_HTML::td( |
|
354 | + EEH_Template::format_currency($total, false, false), |
|
355 | + '', |
|
356 | + 'item_r jst-rght' |
|
357 | + ); |
|
358 | + // end of row |
|
359 | + $html .= EEH_HTML::trx(); |
|
360 | + return $html; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * _sub_item_row |
|
367 | + * |
|
368 | + * @param EE_Line_Item $line_item |
|
369 | + * @param array $options |
|
370 | + * @param EE_Line_Item $parent_line_item |
|
371 | + * @return mixed |
|
372 | + * @throws EE_Error |
|
373 | + */ |
|
374 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
375 | + { |
|
376 | + if ($parent_line_item instanceof EE_Line_Item |
|
377 | + && $line_item->children() === array() |
|
378 | + && $line_item->name() === $parent_line_item->name() |
|
379 | + && apply_filters( |
|
380 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
381 | + true |
|
382 | + ) |
|
383 | + ) { |
|
384 | + return ''; |
|
385 | + } |
|
386 | + // start of row |
|
387 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
388 | + // name && desc |
|
389 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
390 | + . $line_item->name(); |
|
391 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
392 | + . $line_item->desc() |
|
393 | + . '</span>' : ''; |
|
394 | + // name td |
|
395 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
396 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
397 | + // discount/surcharge td |
|
398 | + if ($line_item->is_percent()) { |
|
399 | + $html .= EEH_HTML::td( |
|
400 | + EEH_Template::format_currency( |
|
401 | + $line_item->total() / $qty, |
|
402 | + false, |
|
403 | + false |
|
404 | + ), |
|
405 | + '', |
|
406 | + 'item_c jst-rght' |
|
407 | + ); |
|
408 | + } else { |
|
409 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
410 | + } |
|
411 | + // no quantity td |
|
412 | + $html .= EEH_HTML::td(); |
|
413 | + // no total td |
|
414 | + $html .= EEH_HTML::td(); |
|
415 | + // end of row |
|
416 | + $html .= EEH_HTML::trx(); |
|
417 | + $html = apply_filters( |
|
418 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
419 | + $html, |
|
420 | + $line_item, |
|
421 | + $options, |
|
422 | + $parent_line_item |
|
423 | + ); |
|
424 | + return $html; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * _tax_row |
|
431 | + * |
|
432 | + * @param EE_Line_Item $line_item |
|
433 | + * @param array $options |
|
434 | + * @return mixed |
|
435 | + * @throws EE_Error |
|
436 | + */ |
|
437 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
438 | + { |
|
439 | + // start of row |
|
440 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
441 | + // name && desc |
|
442 | + $name_and_desc = $line_item->name(); |
|
443 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
444 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
445 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
446 | + // name td |
|
447 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
448 | + $name_and_desc, |
|
449 | + '', |
|
450 | + 'item_l sub-item' |
|
451 | + ); |
|
452 | + // percent td |
|
453 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
454 | + // empty td (price) |
|
455 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
456 | + // total td |
|
457 | + $html .= EEH_HTML::td( |
|
458 | + EEH_Template::format_currency( |
|
459 | + $line_item->total(), |
|
460 | + false, |
|
461 | + false |
|
462 | + ), |
|
463 | + '', |
|
464 | + 'item_r jst-rght' |
|
465 | + ); |
|
466 | + // end of row |
|
467 | + $html .= EEH_HTML::trx(); |
|
468 | + return $html; |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * _total_row |
|
475 | + * |
|
476 | + * @param EE_Line_Item $line_item |
|
477 | + * @param string $text |
|
478 | + * @return mixed |
|
479 | + * @throws EE_Error |
|
480 | + */ |
|
481 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
482 | + { |
|
483 | + $html = ''; |
|
484 | + if ($line_item->total()) { |
|
485 | + // start of row |
|
486 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
487 | + // total td |
|
488 | + $html .= EEH_HTML::td( |
|
489 | + $text, |
|
490 | + '', |
|
491 | + 'total_currency total jst-rght', |
|
492 | + '', |
|
493 | + ' colspan="2"' |
|
494 | + ); |
|
495 | + // empty td (price) |
|
496 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
497 | + // total td |
|
498 | + $html .= EEH_HTML::td( |
|
499 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
500 | + '', |
|
501 | + 'total jst-rght' |
|
502 | + ); |
|
503 | + // end of row |
|
504 | + $html .= EEH_HTML::trx(); |
|
505 | + } |
|
506 | + return $html; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * _total_row |
|
513 | + * |
|
514 | + * @param EE_Line_Item $line_item |
|
515 | + * @param string $text |
|
516 | + * @param array $options |
|
517 | + * @return mixed |
|
518 | + * @throws EE_Error |
|
519 | + */ |
|
520 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
521 | + { |
|
522 | + $html = ''; |
|
523 | + if ($line_item->total()) { |
|
524 | + // start of row |
|
525 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
526 | + // total td |
|
527 | + $html .= EEH_HTML::td( |
|
528 | + $text, |
|
529 | + '', |
|
530 | + 'total_currency total jst-rght', |
|
531 | + '', |
|
532 | + ' colspan="3"' |
|
533 | + ); |
|
534 | + // total td |
|
535 | + $html .= EEH_HTML::td( |
|
536 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
537 | + '', |
|
538 | + 'total jst-rght' |
|
539 | + ); |
|
540 | + // end of row |
|
541 | + $html .= EEH_HTML::trx(); |
|
542 | + } |
|
543 | + return $html; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * _total_row |
|
550 | + * |
|
551 | + * @param EE_Line_Item $line_item |
|
552 | + * @param string $text |
|
553 | + * @return mixed |
|
554 | + * @throws EE_Error |
|
555 | + */ |
|
556 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
557 | + { |
|
558 | + // start of row |
|
559 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
560 | + // total td |
|
561 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
562 | + // total td |
|
563 | + $html .= EEH_HTML::td( |
|
564 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
565 | + '', |
|
566 | + 'total jst-rght' |
|
567 | + ); |
|
568 | + // end of row |
|
569 | + $html .= EEH_HTML::trx(); |
|
570 | + return $html; |
|
571 | + } |
|
572 | + |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * _payments_and_amount_owing_rows |
|
577 | + * |
|
578 | + * @param EE_Line_Item $line_item |
|
579 | + * @param array $options |
|
580 | + * @return mixed |
|
581 | + * @throws EE_Error |
|
582 | + */ |
|
583 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
584 | + { |
|
585 | + $html = ''; |
|
586 | + $owing = $line_item->total(); |
|
587 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
588 | + if ($transaction instanceof EE_Transaction) { |
|
589 | + $registration_payments = array(); |
|
590 | + $registrations = ! empty($options['registrations']) |
|
591 | + ? $options['registrations'] |
|
592 | + : $transaction->registrations(); |
|
593 | + foreach ($registrations as $registration) { |
|
594 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
595 | + $registration_payments += $registration->registration_payments(); |
|
596 | + } |
|
597 | + } |
|
598 | + if (! empty($registration_payments)) { |
|
599 | + foreach ($registration_payments as $registration_payment) { |
|
600 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
601 | + $owing -= $registration_payment->amount(); |
|
602 | + $payment = $registration_payment->payment(); |
|
603 | + $payment_desc = ''; |
|
604 | + if ($payment instanceof EE_Payment) { |
|
605 | + $payment_desc = sprintf( |
|
606 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
607 | + $payment->txn_id_chq_nmbr() !== '' |
|
608 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
609 | + : '', |
|
610 | + $payment->timestamp() |
|
611 | + ); |
|
612 | + } |
|
613 | + // start of row |
|
614 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
615 | + // payment desc |
|
616 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
617 | + // total td |
|
618 | + $html .= EEH_HTML::td( |
|
619 | + EEH_Template::format_currency( |
|
620 | + $registration_payment->amount(), |
|
621 | + false, |
|
622 | + false |
|
623 | + ), |
|
624 | + '', |
|
625 | + 'total jst-rght' |
|
626 | + ); |
|
627 | + // end of row |
|
628 | + $html .= EEH_HTML::trx(); |
|
629 | + } |
|
630 | + } |
|
631 | + if ($line_item->total()) { |
|
632 | + // start of row |
|
633 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
634 | + // total td |
|
635 | + $html .= EEH_HTML::td( |
|
636 | + esc_html__('Amount Owing', 'event_espresso'), |
|
637 | + '', |
|
638 | + 'total_currency total jst-rght', |
|
639 | + '', |
|
640 | + ' colspan="3"' |
|
641 | + ); |
|
642 | + // total td |
|
643 | + $html .= EEH_HTML::td( |
|
644 | + EEH_Template::format_currency($owing, false, false), |
|
645 | + '', |
|
646 | + 'total jst-rght' |
|
647 | + ); |
|
648 | + // end of row |
|
649 | + $html .= EEH_HTML::trx(); |
|
650 | + } |
|
651 | + } |
|
652 | + } |
|
653 | + $this->_grand_total = $owing; |
|
654 | + return $html; |
|
655 | + } |
|
656 | 656 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $html = ''; |
85 | 85 | // set some default options and merge with incoming |
86 | 86 | $default_options = array( |
87 | - 'show_desc' => true, // true false |
|
87 | + 'show_desc' => true, // true false |
|
88 | 88 | 'odd' => false, |
89 | 89 | ); |
90 | 90 | $options = array_merge($default_options, (array) $options); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $text = esc_html__('Sub-Total', 'event_espresso'); |
119 | 119 | if ($line_item->OBJ_type() === 'Event') { |
120 | 120 | $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
121 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
121 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
122 | 122 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
123 | 123 | // if event has default reg status of Not Approved, then don't display info on it |
124 | 124 | if ($event instanceof EE_Event |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | // unless there are registrations for it that are returning to pay |
129 | 129 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
130 | 130 | foreach ($options['registrations'] as $registration) { |
131 | - if (! $registration instanceof EE_Registration) { |
|
131 | + if ( ! $registration instanceof EE_Registration) { |
|
132 | 132 | continue; |
133 | 133 | } |
134 | 134 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | : $display_event; |
138 | 138 | } |
139 | 139 | } |
140 | - if (! $display_event) { |
|
140 | + if ( ! $display_event) { |
|
141 | 141 | return ''; |
142 | 142 | } |
143 | 143 | } |
144 | - $this->_events[ $options['event_id'] ] = 0; |
|
144 | + $this->_events[$options['event_id']] = 0; |
|
145 | 145 | $html .= $this->_event_row($line_item); |
146 | 146 | $text = esc_html__('Event Sub-Total', 'event_espresso'); |
147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | // recursively feed children back into this method |
153 | 153 | $html .= $this->display_line_item($child_line_item, $options, $line_item); |
154 | 154 | } |
155 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
155 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
156 | 156 | $sub_total += $event_sub_total; |
157 | 157 | if (( |
158 | 158 | // event subtotals |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
261 | 261 | ( |
262 | 262 | $options['show_desc'] |
263 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
263 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
264 | 264 | : '' |
265 | 265 | ), |
266 | 266 | $line_item, |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $line_item->total(), |
290 | 290 | $line_item |
291 | 291 | ); |
292 | - $this->_events[ $options['event_id'] ] += $total; |
|
292 | + $this->_events[$options['event_id']] += $total; |
|
293 | 293 | // total td |
294 | 294 | $html .= EEH_HTML::td( |
295 | 295 | EEH_Template::format_currency($total, false, false), |
@@ -316,18 +316,18 @@ discard block |
||
316 | 316 | // start of row |
317 | 317 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
318 | 318 | $html = EEH_HTML::tr('', '', $row_class); |
319 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
319 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
320 | 320 | // name && desc |
321 | 321 | $name_and_desc = apply_filters( |
322 | 322 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
323 | - $obj_name . $line_item->name(), |
|
323 | + $obj_name.$line_item->name(), |
|
324 | 324 | $line_item |
325 | 325 | ); |
326 | 326 | $name_and_desc .= apply_filters( |
327 | 327 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
328 | 328 | ( |
329 | 329 | $options['show_desc'] |
330 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
330 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
331 | 331 | : '' |
332 | 332 | ), |
333 | 333 | $line_item, |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
339 | 339 | // price td |
340 | 340 | if ($line_item->is_percent()) { |
341 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
341 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght'); |
|
342 | 342 | } else { |
343 | 343 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
344 | 344 | } |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
347 | 347 | // $total = $line_item->total() * $line_item->quantity(); |
348 | 348 | $total = $line_item->total(); |
349 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
350 | - $this->_events[ $options['event_id'] ] += $total; |
|
349 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
350 | + $this->_events[$options['event_id']] += $total; |
|
351 | 351 | } |
352 | 352 | // total td |
353 | 353 | $html .= EEH_HTML::td( |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | // name && desc |
442 | 442 | $name_and_desc = $line_item->name(); |
443 | 443 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
444 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
445 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
444 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
445 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
446 | 446 | // name td |
447 | 447 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
448 | 448 | $name_and_desc, |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | 'item_l sub-item' |
451 | 451 | ); |
452 | 452 | // percent td |
453 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
453 | + $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', ''); |
|
454 | 454 | // empty td (price) |
455 | 455 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
456 | 456 | // total td |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | $registration_payments += $registration->registration_payments(); |
596 | 596 | } |
597 | 597 | } |
598 | - if (! empty($registration_payments)) { |
|
598 | + if ( ! empty($registration_payments)) { |
|
599 | 599 | foreach ($registration_payments as $registration_payment) { |
600 | 600 | if ($registration_payment instanceof EE_Registration_Payment) { |
601 | 601 | $owing -= $registration_payment->amount(); |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | $payment_desc = sprintf( |
606 | 606 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
607 | 607 | $payment->txn_id_chq_nmbr() !== '' |
608 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
608 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
609 | 609 | : '', |
610 | 610 | $payment->timestamp() |
611 | 611 | ); |
@@ -10,19 +10,19 @@ discard block |
||
10 | 10 | ?> |
11 | 11 | <div id="admin-side-mbox-primary-registrant-dv" class="admin-side-mbox-dv"> |
12 | 12 | <?php |
13 | - if (! empty($no_attendee_message)) : ?> |
|
13 | + if (! empty($no_attendee_message)) : ?> |
|
14 | 14 | <p class="clearfix"> |
15 | 15 | <?php echo $no_attendee_message; ?> |
16 | 16 | </p> |
17 | 17 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
18 | 18 | <?php |
19 | - else : ?> |
|
19 | + else : ?> |
|
20 | 20 | <p class="clearfix"> |
21 | 21 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
22 | 22 | <?php esc_html_e( |
23 | - 'Name', |
|
24 | - 'event_espresso' |
|
25 | - ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
23 | + 'Name', |
|
24 | + 'event_espresso' |
|
25 | + ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
26 | 26 | </p> |
27 | 27 | <p class="clearfix"> |
28 | 28 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php esc_html_e('Email', 'event_espresso'); ?></span><a |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | <p class="clearfix"> |
32 | 32 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
33 | 33 | <?php esc_html_e( |
34 | - 'Phone #', |
|
35 | - 'event_espresso' |
|
36 | - ); ?> |
|
34 | + 'Phone #', |
|
35 | + 'event_espresso' |
|
36 | + ); ?> |
|
37 | 37 | </span> |
38 | 38 | <?php if (! empty($prime_reg_phone)) : ?> |
39 | 39 | <a href="tel:<?php echo $prime_reg_phone; ?>"> |
@@ -50,22 +50,22 @@ discard block |
||
50 | 50 | </div> <!-- end #admin-side-mbox-primary-registrant-dv --> |
51 | 51 | |
52 | 52 | <?php |
53 | - /** only show if logged in user has access */ |
|
54 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
55 | - 'ee_edit_contact', |
|
56 | - 'view_or_edit_contact_button', |
|
57 | - $ATT_ID |
|
58 | - ) |
|
59 | - ) : ?> |
|
53 | + /** only show if logged in user has access */ |
|
54 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
55 | + 'ee_edit_contact', |
|
56 | + 'view_or_edit_contact_button', |
|
57 | + $ATT_ID |
|
58 | + ) |
|
59 | + ) : ?> |
|
60 | 60 | <p style="text-align:right;"> |
61 | 61 | <a class="button button-small" href="<?php echo $edit_attendee_url; ?>" |
62 | 62 | title="<?php esc_attr_e('View details for this contact.', 'event_espresso'); ?>"> |
63 | 63 | <span class="ee-icon ee-icon-user-edit"></span> |
64 | 64 | <?php _e( |
65 | - 'View / Edit this Contact', |
|
66 | - 'event_espresso' |
|
67 | - ); ?> |
|
65 | + 'View / Edit this Contact', |
|
66 | + 'event_espresso' |
|
67 | + ); ?> |
|
68 | 68 | </a> |
69 | 69 | </p> |
70 | 70 | <?php endif; |
71 | - endif; |
|
71 | + endif; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | ?> |
11 | 11 | <div id="admin-side-mbox-primary-registrant-dv" class="admin-side-mbox-dv"> |
12 | 12 | <?php |
13 | - if (! empty($no_attendee_message)) : ?> |
|
13 | + if ( ! empty($no_attendee_message)) : ?> |
|
14 | 14 | <p class="clearfix"> |
15 | 15 | <?php echo $no_attendee_message; ?> |
16 | 16 | </p> |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | <?php esc_html_e( |
23 | 23 | 'Name', |
24 | 24 | 'event_espresso' |
25 | - ); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?> |
|
25 | + ); ?></span><?php echo $prime_reg_fname.' '.$prime_reg_lname; ?> |
|
26 | 26 | </p> |
27 | 27 | <p class="clearfix"> |
28 | 28 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php esc_html_e('Email', 'event_espresso'); ?></span><a |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | 'event_espresso' |
36 | 36 | ); ?> |
37 | 37 | </span> |
38 | - <?php if (! empty($prime_reg_phone)) : ?> |
|
38 | + <?php if ( ! empty($prime_reg_phone)) : ?> |
|
39 | 39 | <a href="tel:<?php echo $prime_reg_phone; ?>"> |
40 | 40 | <?php echo $prime_reg_phone; ?> |
41 | 41 | </a> |
@@ -16,230 +16,230 @@ discard block |
||
16 | 16 | class EEM_Transaction extends EEM_Base |
17 | 17 | { |
18 | 18 | |
19 | - // private instance of the Transaction object |
|
20 | - protected static $_instance; |
|
21 | - |
|
22 | - /** |
|
23 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
24 | - * but payment is pending. This is the state for transactions where payment is promised |
|
25 | - * from an offline gateway. |
|
26 | - */ |
|
27 | - // const open_status_code = 'TPN'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
31 | - * either due to a technical reason (server or computer crash during registration), |
|
32 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
33 | - */ |
|
34 | - const failed_status_code = 'TFL'; |
|
35 | - |
|
36 | - /** |
|
37 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
38 | - * either due to a technical reason (server or computer crash during registration), |
|
39 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
40 | - * HOWEVER... |
|
41 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
42 | - * registrant |
|
43 | - */ |
|
44 | - const abandoned_status_code = 'TAB'; |
|
45 | - |
|
46 | - /** |
|
47 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
48 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
49 | - */ |
|
50 | - const incomplete_status_code = 'TIN'; |
|
51 | - |
|
52 | - /** |
|
53 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
54 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
55 | - */ |
|
56 | - const complete_status_code = 'TCM'; |
|
57 | - |
|
58 | - /** |
|
59 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
60 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
61 | - */ |
|
62 | - const overpaid_status_code = 'TOP'; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * private constructor to prevent direct creation |
|
67 | - * |
|
68 | - * @Constructor |
|
69 | - * @access protected |
|
70 | - * |
|
71 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
72 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
73 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
74 | - * timezone in the 'timezone_string' wp option) |
|
75 | - * |
|
76 | - * @return EEM_Transaction |
|
77 | - * @throws \EE_Error |
|
78 | - */ |
|
79 | - protected function __construct($timezone) |
|
80 | - { |
|
81 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
82 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
83 | - |
|
84 | - $this->_tables = array( |
|
85 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
86 | - ); |
|
87 | - $this->_fields = array( |
|
88 | - 'TransactionTable' => array( |
|
89 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
90 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | - 'TXN_timestamp', |
|
92 | - __('date when transaction was created', 'event_espresso'), |
|
93 | - false, |
|
94 | - EE_Datetime_Field::now, |
|
95 | - $timezone |
|
96 | - ), |
|
97 | - 'TXN_total' => new EE_Money_Field( |
|
98 | - 'TXN_total', |
|
99 | - __('Total value of Transaction', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TXN_paid' => new EE_Money_Field( |
|
104 | - 'TXN_paid', |
|
105 | - __('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | - 'STS_ID', |
|
111 | - __('Status ID', 'event_espresso'), |
|
112 | - false, |
|
113 | - EEM_Transaction::failed_status_code, |
|
114 | - 'Status' |
|
115 | - ), |
|
116 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | - 'TXN_session_data', |
|
118 | - __('Serialized session data', 'event_espresso'), |
|
119 | - true, |
|
120 | - '' |
|
121 | - ), |
|
122 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | - 'TXN_hash_salt', |
|
124 | - __('Transaction Hash Salt', 'event_espresso'), |
|
125 | - true, |
|
126 | - '' |
|
127 | - ), |
|
128 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | - 'PMD_ID', |
|
130 | - __("Last Used Payment Method", 'event_espresso'), |
|
131 | - true, |
|
132 | - null, |
|
133 | - 'Payment_Method' |
|
134 | - ), |
|
135 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | - 'TXN_reg_steps', |
|
137 | - __('Registration Steps', 'event_espresso'), |
|
138 | - false, |
|
139 | - array() |
|
140 | - ), |
|
141 | - ) |
|
142 | - ); |
|
143 | - $this->_model_relations = array( |
|
144 | - 'Registration' => new EE_Has_Many_Relation(), |
|
145 | - 'Payment' => new EE_Has_Many_Relation(), |
|
146 | - 'Status' => new EE_Belongs_To_Relation(), |
|
147 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | - // you can delete a transaction without needing to delete its line items |
|
149 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | - 'Message' => new EE_Has_Many_Relation() |
|
151 | - ); |
|
152 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | - parent::__construct($timezone); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * txn_status_array |
|
159 | - * get list of transaction statuses |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public static function txn_status_array() |
|
165 | - { |
|
166 | - return apply_filters( |
|
167 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | - array( |
|
169 | - EEM_Transaction::overpaid_status_code, |
|
170 | - EEM_Transaction::complete_status_code, |
|
171 | - EEM_Transaction::incomplete_status_code, |
|
172 | - EEM_Transaction::abandoned_status_code, |
|
173 | - EEM_Transaction::failed_status_code, |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * |
|
183 | - * @param string $period |
|
184 | - * |
|
185 | - * @return \stdClass[] |
|
186 | - */ |
|
187 | - public function get_revenue_per_day_report($period = '-1 month') |
|
188 | - { |
|
189 | - $sql_date = $this->convert_datetime_for_query( |
|
190 | - 'TXN_timestamp', |
|
191 | - date('Y-m-d H:i:s', strtotime($period)), |
|
192 | - 'Y-m-d H:i:s', |
|
193 | - 'UTC' |
|
194 | - ); |
|
195 | - |
|
196 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | - |
|
198 | - return $this->_get_all_wpdb_results( |
|
199 | - array( |
|
200 | - array( |
|
201 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
202 | - ), |
|
203 | - 'group_by' => 'txnDate', |
|
204 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
205 | - ), |
|
206 | - OBJECT, |
|
207 | - array( |
|
208 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
209 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * |
|
220 | - * @param string $period |
|
221 | - * |
|
222 | - * @throws \EE_Error |
|
223 | - * @return mixed |
|
224 | - */ |
|
225 | - public function get_revenue_per_event_report($period = '-1 month') |
|
226 | - { |
|
227 | - global $wpdb; |
|
228 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
231 | - $event_table = $wpdb->posts; |
|
232 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
233 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
234 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
235 | - $extra_event_on_join = ''; |
|
236 | - // exclude events not authored by user if permissions in effect |
|
237 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
239 | - } |
|
240 | - |
|
241 | - return $wpdb->get_results( |
|
242 | - "SELECT |
|
19 | + // private instance of the Transaction object |
|
20 | + protected static $_instance; |
|
21 | + |
|
22 | + /** |
|
23 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
24 | + * but payment is pending. This is the state for transactions where payment is promised |
|
25 | + * from an offline gateway. |
|
26 | + */ |
|
27 | + // const open_status_code = 'TPN'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
31 | + * either due to a technical reason (server or computer crash during registration), |
|
32 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
33 | + */ |
|
34 | + const failed_status_code = 'TFL'; |
|
35 | + |
|
36 | + /** |
|
37 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
38 | + * either due to a technical reason (server or computer crash during registration), |
|
39 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
40 | + * HOWEVER... |
|
41 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
42 | + * registrant |
|
43 | + */ |
|
44 | + const abandoned_status_code = 'TAB'; |
|
45 | + |
|
46 | + /** |
|
47 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
48 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
49 | + */ |
|
50 | + const incomplete_status_code = 'TIN'; |
|
51 | + |
|
52 | + /** |
|
53 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
54 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
55 | + */ |
|
56 | + const complete_status_code = 'TCM'; |
|
57 | + |
|
58 | + /** |
|
59 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
60 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
61 | + */ |
|
62 | + const overpaid_status_code = 'TOP'; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * private constructor to prevent direct creation |
|
67 | + * |
|
68 | + * @Constructor |
|
69 | + * @access protected |
|
70 | + * |
|
71 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
72 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
73 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
74 | + * timezone in the 'timezone_string' wp option) |
|
75 | + * |
|
76 | + * @return EEM_Transaction |
|
77 | + * @throws \EE_Error |
|
78 | + */ |
|
79 | + protected function __construct($timezone) |
|
80 | + { |
|
81 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
82 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
83 | + |
|
84 | + $this->_tables = array( |
|
85 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
86 | + ); |
|
87 | + $this->_fields = array( |
|
88 | + 'TransactionTable' => array( |
|
89 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
90 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | + 'TXN_timestamp', |
|
92 | + __('date when transaction was created', 'event_espresso'), |
|
93 | + false, |
|
94 | + EE_Datetime_Field::now, |
|
95 | + $timezone |
|
96 | + ), |
|
97 | + 'TXN_total' => new EE_Money_Field( |
|
98 | + 'TXN_total', |
|
99 | + __('Total value of Transaction', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TXN_paid' => new EE_Money_Field( |
|
104 | + 'TXN_paid', |
|
105 | + __('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | + 'STS_ID', |
|
111 | + __('Status ID', 'event_espresso'), |
|
112 | + false, |
|
113 | + EEM_Transaction::failed_status_code, |
|
114 | + 'Status' |
|
115 | + ), |
|
116 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | + 'TXN_session_data', |
|
118 | + __('Serialized session data', 'event_espresso'), |
|
119 | + true, |
|
120 | + '' |
|
121 | + ), |
|
122 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | + 'TXN_hash_salt', |
|
124 | + __('Transaction Hash Salt', 'event_espresso'), |
|
125 | + true, |
|
126 | + '' |
|
127 | + ), |
|
128 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | + 'PMD_ID', |
|
130 | + __("Last Used Payment Method", 'event_espresso'), |
|
131 | + true, |
|
132 | + null, |
|
133 | + 'Payment_Method' |
|
134 | + ), |
|
135 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | + 'TXN_reg_steps', |
|
137 | + __('Registration Steps', 'event_espresso'), |
|
138 | + false, |
|
139 | + array() |
|
140 | + ), |
|
141 | + ) |
|
142 | + ); |
|
143 | + $this->_model_relations = array( |
|
144 | + 'Registration' => new EE_Has_Many_Relation(), |
|
145 | + 'Payment' => new EE_Has_Many_Relation(), |
|
146 | + 'Status' => new EE_Belongs_To_Relation(), |
|
147 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | + // you can delete a transaction without needing to delete its line items |
|
149 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | + 'Message' => new EE_Has_Many_Relation() |
|
151 | + ); |
|
152 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | + parent::__construct($timezone); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * txn_status_array |
|
159 | + * get list of transaction statuses |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public static function txn_status_array() |
|
165 | + { |
|
166 | + return apply_filters( |
|
167 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | + array( |
|
169 | + EEM_Transaction::overpaid_status_code, |
|
170 | + EEM_Transaction::complete_status_code, |
|
171 | + EEM_Transaction::incomplete_status_code, |
|
172 | + EEM_Transaction::abandoned_status_code, |
|
173 | + EEM_Transaction::failed_status_code, |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * |
|
183 | + * @param string $period |
|
184 | + * |
|
185 | + * @return \stdClass[] |
|
186 | + */ |
|
187 | + public function get_revenue_per_day_report($period = '-1 month') |
|
188 | + { |
|
189 | + $sql_date = $this->convert_datetime_for_query( |
|
190 | + 'TXN_timestamp', |
|
191 | + date('Y-m-d H:i:s', strtotime($period)), |
|
192 | + 'Y-m-d H:i:s', |
|
193 | + 'UTC' |
|
194 | + ); |
|
195 | + |
|
196 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | + |
|
198 | + return $this->_get_all_wpdb_results( |
|
199 | + array( |
|
200 | + array( |
|
201 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
202 | + ), |
|
203 | + 'group_by' => 'txnDate', |
|
204 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
205 | + ), |
|
206 | + OBJECT, |
|
207 | + array( |
|
208 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
209 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * |
|
220 | + * @param string $period |
|
221 | + * |
|
222 | + * @throws \EE_Error |
|
223 | + * @return mixed |
|
224 | + */ |
|
225 | + public function get_revenue_per_event_report($period = '-1 month') |
|
226 | + { |
|
227 | + global $wpdb; |
|
228 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
231 | + $event_table = $wpdb->posts; |
|
232 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
233 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
234 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
235 | + $extra_event_on_join = ''; |
|
236 | + // exclude events not authored by user if permissions in effect |
|
237 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
239 | + } |
|
240 | + |
|
241 | + return $wpdb->get_results( |
|
242 | + "SELECT |
|
243 | 243 | Transaction_Event.event_name AS event_name, |
244 | 244 | SUM(Transaction_Event.paid) AS revenue |
245 | 245 | FROM |
@@ -267,231 +267,231 @@ discard block |
||
267 | 267 | $extra_event_on_join |
268 | 268 | ) AS Transaction_Event |
269 | 269 | GROUP BY event_name", |
270 | - OBJECT |
|
271 | - ); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
277 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
278 | - * the registration pointed to by reg_url_link), if not returns null |
|
279 | - * |
|
280 | - * @param string $reg_url_link |
|
281 | - * |
|
282 | - * @return EE_Transaction |
|
283 | - */ |
|
284 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
285 | - { |
|
286 | - return $this->get_one(array( |
|
287 | - array( |
|
288 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get( |
|
289 | - 'e_reg_url_link', |
|
290 | - '' |
|
291 | - ) |
|
292 | - ) |
|
293 | - )); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Updates the provided EE_Transaction with all the applicable payments |
|
299 | - * (or fetch the EE_Transaction from its ID) |
|
300 | - * |
|
301 | - * @deprecated |
|
302 | - * |
|
303 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
304 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
305 | - * |
|
306 | - * @return boolean |
|
307 | - * @throws \EE_Error |
|
308 | - */ |
|
309 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
310 | - { |
|
311 | - EE_Error::doing_it_wrong( |
|
312 | - __CLASS__ . '::' . __FUNCTION__, |
|
313 | - sprintf( |
|
314 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
315 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
316 | - ), |
|
317 | - '4.6.0' |
|
318 | - ); |
|
319 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
320 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
321 | - |
|
322 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
323 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
324 | - ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | - * and so we only use wpdb directly and only do minimal joins. |
|
331 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | - * it, it's probably not junk (regardless of what status it has). |
|
334 | - * The downside to this approach is that is addons are listening for object deletions |
|
335 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | - * to catch these types of deletions. |
|
337 | - * |
|
338 | - * @global WPDB $wpdb |
|
339 | - * @return mixed |
|
340 | - */ |
|
341 | - public function delete_junk_transactions() |
|
342 | - { |
|
343 | - /** @type WPDB $wpdb */ |
|
344 | - global $wpdb; |
|
345 | - $deleted = false; |
|
346 | - $time_to_leave_alone = apply_filters( |
|
347 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | - WEEK_IN_SECONDS |
|
349 | - ); |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | - */ |
|
357 | - $ids_query = apply_filters( |
|
358 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | - array( |
|
360 | - 0 => array( |
|
361 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
363 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
364 | - ) |
|
365 | - ), |
|
366 | - $time_to_leave_alone |
|
367 | - ); |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
372 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
373 | - */ |
|
374 | - $txn_ids = apply_filters( |
|
375 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
376 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
377 | - $time_to_leave_alone |
|
378 | - ); |
|
379 | - // now that we have the ids to delete |
|
380 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
381 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
382 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
383 | - |
|
384 | - // Create IDs placeholder. |
|
385 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
270 | + OBJECT |
|
271 | + ); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
277 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
278 | + * the registration pointed to by reg_url_link), if not returns null |
|
279 | + * |
|
280 | + * @param string $reg_url_link |
|
281 | + * |
|
282 | + * @return EE_Transaction |
|
283 | + */ |
|
284 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
285 | + { |
|
286 | + return $this->get_one(array( |
|
287 | + array( |
|
288 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get( |
|
289 | + 'e_reg_url_link', |
|
290 | + '' |
|
291 | + ) |
|
292 | + ) |
|
293 | + )); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Updates the provided EE_Transaction with all the applicable payments |
|
299 | + * (or fetch the EE_Transaction from its ID) |
|
300 | + * |
|
301 | + * @deprecated |
|
302 | + * |
|
303 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
304 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
305 | + * |
|
306 | + * @return boolean |
|
307 | + * @throws \EE_Error |
|
308 | + */ |
|
309 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
310 | + { |
|
311 | + EE_Error::doing_it_wrong( |
|
312 | + __CLASS__ . '::' . __FUNCTION__, |
|
313 | + sprintf( |
|
314 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
315 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
316 | + ), |
|
317 | + '4.6.0' |
|
318 | + ); |
|
319 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
320 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
321 | + |
|
322 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
323 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
324 | + ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | + * and so we only use wpdb directly and only do minimal joins. |
|
331 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | + * it, it's probably not junk (regardless of what status it has). |
|
334 | + * The downside to this approach is that is addons are listening for object deletions |
|
335 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | + * to catch these types of deletions. |
|
337 | + * |
|
338 | + * @global WPDB $wpdb |
|
339 | + * @return mixed |
|
340 | + */ |
|
341 | + public function delete_junk_transactions() |
|
342 | + { |
|
343 | + /** @type WPDB $wpdb */ |
|
344 | + global $wpdb; |
|
345 | + $deleted = false; |
|
346 | + $time_to_leave_alone = apply_filters( |
|
347 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | + WEEK_IN_SECONDS |
|
349 | + ); |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | + */ |
|
357 | + $ids_query = apply_filters( |
|
358 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | + array( |
|
360 | + 0 => array( |
|
361 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
363 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
364 | + ) |
|
365 | + ), |
|
366 | + $time_to_leave_alone |
|
367 | + ); |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
372 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
373 | + */ |
|
374 | + $txn_ids = apply_filters( |
|
375 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
376 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
377 | + $time_to_leave_alone |
|
378 | + ); |
|
379 | + // now that we have the ids to delete |
|
380 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
381 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
382 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
383 | + |
|
384 | + // Create IDs placeholder. |
|
385 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
386 | 386 | |
387 | - // Glue it together to use inside $wpdb->prepare. |
|
388 | - $format = implode(', ', $placeholders); |
|
389 | - |
|
390 | - // let's get deletin'... |
|
391 | - // We got the ids from the original query to get them FROM |
|
392 | - // the db (which is sanitized) so no need to prepare them again. |
|
393 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
394 | - $deleted = $wpdb->query($query); |
|
395 | - } |
|
396 | - if ($deleted) { |
|
397 | - /** |
|
398 | - * Allows code to do something after the transactions have been deleted. |
|
399 | - */ |
|
400 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
401 | - } |
|
402 | - |
|
403 | - return $deleted; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @param array $transaction_IDs |
|
409 | - * |
|
410 | - * @return bool |
|
411 | - */ |
|
412 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
413 | - { |
|
414 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
415 | - $update = false; |
|
416 | - foreach ($transaction_IDs as $TXN_ID) { |
|
417 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
418 | - unset($locked_transactions[ $TXN_ID ]); |
|
419 | - $update = true; |
|
420 | - } |
|
421 | - } |
|
422 | - if ($update) { |
|
423 | - update_option('ee_locked_transactions', $locked_transactions); |
|
424 | - } |
|
425 | - |
|
426 | - return $update; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
433 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
434 | - * |
|
435 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
436 | - * @throws EE_Error |
|
437 | - * @throws InvalidArgumentException |
|
438 | - * @throws InvalidDataTypeException |
|
439 | - * @throws InvalidInterfaceException |
|
440 | - */ |
|
441 | - public function get_transactions_in_progress() |
|
442 | - { |
|
443 | - return $this->_get_transactions_in_progress(); |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
450 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
451 | - * |
|
452 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
453 | - * @throws EE_Error |
|
454 | - * @throws InvalidArgumentException |
|
455 | - * @throws InvalidDataTypeException |
|
456 | - * @throws InvalidInterfaceException |
|
457 | - */ |
|
458 | - public function get_transactions_not_in_progress() |
|
459 | - { |
|
460 | - return $this->_get_transactions_in_progress('<='); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * @param string $comparison |
|
467 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
468 | - * @throws EE_Error |
|
469 | - * @throws InvalidArgumentException |
|
470 | - * @throws InvalidDataTypeException |
|
471 | - * @throws InvalidInterfaceException |
|
472 | - */ |
|
473 | - private function _get_transactions_in_progress($comparison = '>=') |
|
474 | - { |
|
475 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
476 | - ? $comparison |
|
477 | - : '>='; |
|
478 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
479 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
480 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
481 | - ); |
|
482 | - return $this->get_all( |
|
483 | - array( |
|
484 | - array( |
|
485 | - 'TXN_timestamp' => array( |
|
486 | - $comparison, |
|
487 | - $session_lifespan->expiration() |
|
488 | - ), |
|
489 | - 'STS_ID' => array( |
|
490 | - '!=', |
|
491 | - EEM_Transaction::complete_status_code |
|
492 | - ), |
|
493 | - ) |
|
494 | - ) |
|
495 | - ); |
|
496 | - } |
|
387 | + // Glue it together to use inside $wpdb->prepare. |
|
388 | + $format = implode(', ', $placeholders); |
|
389 | + |
|
390 | + // let's get deletin'... |
|
391 | + // We got the ids from the original query to get them FROM |
|
392 | + // the db (which is sanitized) so no need to prepare them again. |
|
393 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
394 | + $deleted = $wpdb->query($query); |
|
395 | + } |
|
396 | + if ($deleted) { |
|
397 | + /** |
|
398 | + * Allows code to do something after the transactions have been deleted. |
|
399 | + */ |
|
400 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
401 | + } |
|
402 | + |
|
403 | + return $deleted; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @param array $transaction_IDs |
|
409 | + * |
|
410 | + * @return bool |
|
411 | + */ |
|
412 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
413 | + { |
|
414 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
415 | + $update = false; |
|
416 | + foreach ($transaction_IDs as $TXN_ID) { |
|
417 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
418 | + unset($locked_transactions[ $TXN_ID ]); |
|
419 | + $update = true; |
|
420 | + } |
|
421 | + } |
|
422 | + if ($update) { |
|
423 | + update_option('ee_locked_transactions', $locked_transactions); |
|
424 | + } |
|
425 | + |
|
426 | + return $update; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
433 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
434 | + * |
|
435 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
436 | + * @throws EE_Error |
|
437 | + * @throws InvalidArgumentException |
|
438 | + * @throws InvalidDataTypeException |
|
439 | + * @throws InvalidInterfaceException |
|
440 | + */ |
|
441 | + public function get_transactions_in_progress() |
|
442 | + { |
|
443 | + return $this->_get_transactions_in_progress(); |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
450 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
451 | + * |
|
452 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
453 | + * @throws EE_Error |
|
454 | + * @throws InvalidArgumentException |
|
455 | + * @throws InvalidDataTypeException |
|
456 | + * @throws InvalidInterfaceException |
|
457 | + */ |
|
458 | + public function get_transactions_not_in_progress() |
|
459 | + { |
|
460 | + return $this->_get_transactions_in_progress('<='); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * @param string $comparison |
|
467 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
468 | + * @throws EE_Error |
|
469 | + * @throws InvalidArgumentException |
|
470 | + * @throws InvalidDataTypeException |
|
471 | + * @throws InvalidInterfaceException |
|
472 | + */ |
|
473 | + private function _get_transactions_in_progress($comparison = '>=') |
|
474 | + { |
|
475 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
476 | + ? $comparison |
|
477 | + : '>='; |
|
478 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
479 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
480 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
481 | + ); |
|
482 | + return $this->get_all( |
|
483 | + array( |
|
484 | + array( |
|
485 | + 'TXN_timestamp' => array( |
|
486 | + $comparison, |
|
487 | + $session_lifespan->expiration() |
|
488 | + ), |
|
489 | + 'STS_ID' => array( |
|
490 | + '!=', |
|
491 | + EEM_Transaction::complete_status_code |
|
492 | + ), |
|
493 | + ) |
|
494 | + ) |
|
495 | + ); |
|
496 | + } |
|
497 | 497 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | ), |
141 | 141 | ) |
142 | 142 | ); |
143 | - $this->_model_relations = array( |
|
143 | + $this->_model_relations = array( |
|
144 | 144 | 'Registration' => new EE_Has_Many_Relation(), |
145 | 145 | 'Payment' => new EE_Has_Many_Relation(), |
146 | 146 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | ), |
206 | 206 | OBJECT, |
207 | 207 | array( |
208 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
208 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
209 | 209 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
210 | 210 | ) |
211 | 211 | ); |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | public function get_revenue_per_event_report($period = '-1 month') |
226 | 226 | { |
227 | 227 | global $wpdb; |
228 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
228 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
229 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
230 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
231 | 231 | $event_table = $wpdb->posts; |
232 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
232 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
233 | 233 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
234 | 234 | $approved_payment_status = EEM_Payment::status_id_approved; |
235 | 235 | $extra_event_on_join = ''; |
236 | 236 | // exclude events not authored by user if permissions in effect |
237 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | return $wpdb->get_results( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
310 | 310 | { |
311 | 311 | EE_Error::doing_it_wrong( |
312 | - __CLASS__ . '::' . __FUNCTION__, |
|
312 | + __CLASS__.'::'.__FUNCTION__, |
|
313 | 313 | sprintf( |
314 | 314 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
315 | 315 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | array( |
360 | 360 | 0 => array( |
361 | 361 | 'STS_ID' => EEM_Transaction::failed_status_code, |
362 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
362 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
363 | 363 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
364 | 364 | ) |
365 | 365 | ), |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | $time_to_leave_alone |
378 | 378 | ); |
379 | 379 | // now that we have the ids to delete |
380 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
380 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
381 | 381 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
382 | 382 | EEM_Transaction::unset_locked_transactions($txn_ids); |
383 | 383 | |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | // let's get deletin'... |
391 | 391 | // We got the ids from the original query to get them FROM |
392 | 392 | // the db (which is sanitized) so no need to prepare them again. |
393 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
393 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
394 | 394 | $deleted = $wpdb->query($query); |
395 | 395 | } |
396 | 396 | if ($deleted) { |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | $locked_transactions = get_option('ee_locked_transactions', array()); |
415 | 415 | $update = false; |
416 | 416 | foreach ($transaction_IDs as $TXN_ID) { |
417 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
418 | - unset($locked_transactions[ $TXN_ID ]); |
|
417 | + if (isset($locked_transactions[$TXN_ID])) { |
|
418 | + unset($locked_transactions[$TXN_ID]); |
|
419 | 419 | $update = true; |
420 | 420 | } |
421 | 421 | } |
@@ -16,314 +16,314 @@ |
||
16 | 16 | class StatsGatherer |
17 | 17 | { |
18 | 18 | |
19 | - const COUNT_ALL_EVENTS = 'event'; |
|
20 | - const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
21 | - const COUNT_DATETIMES = 'datetime'; |
|
22 | - const COUNT_TICKETS = 'ticket'; |
|
23 | - const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
24 | - const COUNT_TICKETS_FREE = 'free_ticket'; |
|
25 | - const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
26 | - const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
27 | - const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
28 | - const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
29 | - const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
30 | - const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
31 | - const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
32 | - const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
33 | - const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
34 | - const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
35 | - const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
36 | - const INFO_SITE_CURRENCY = 'site_currency'; |
|
19 | + const COUNT_ALL_EVENTS = 'event'; |
|
20 | + const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
21 | + const COUNT_DATETIMES = 'datetime'; |
|
22 | + const COUNT_TICKETS = 'ticket'; |
|
23 | + const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
24 | + const COUNT_TICKETS_FREE = 'free_ticket'; |
|
25 | + const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
26 | + const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
27 | + const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
28 | + const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
29 | + const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
30 | + const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
31 | + const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
32 | + const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
33 | + const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
34 | + const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
35 | + const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
36 | + const INFO_SITE_CURRENCY = 'site_currency'; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @var EEM_Payment_Method |
|
41 | - */ |
|
42 | - private $payment_method_model; |
|
39 | + /** |
|
40 | + * @var EEM_Payment_Method |
|
41 | + */ |
|
42 | + private $payment_method_model; |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @var EEM_Event |
|
47 | - */ |
|
48 | - private $event_model; |
|
45 | + /** |
|
46 | + * @var EEM_Event |
|
47 | + */ |
|
48 | + private $event_model; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var EEM_Datetime |
|
52 | - */ |
|
53 | - private $datetime_model; |
|
50 | + /** |
|
51 | + * @var EEM_Datetime |
|
52 | + */ |
|
53 | + private $datetime_model; |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @var EEM_Ticket |
|
58 | - */ |
|
59 | - private $ticket_model; |
|
56 | + /** |
|
57 | + * @var EEM_Ticket |
|
58 | + */ |
|
59 | + private $ticket_model; |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * @var EEM_Registration |
|
64 | - */ |
|
65 | - private $registration_model; |
|
62 | + /** |
|
63 | + * @var EEM_Registration |
|
64 | + */ |
|
65 | + private $registration_model; |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @var EEM_Transaction |
|
70 | - */ |
|
71 | - private $transaction_model; |
|
68 | + /** |
|
69 | + * @var EEM_Transaction |
|
70 | + */ |
|
71 | + private $transaction_model; |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @var EE_Config |
|
76 | - */ |
|
77 | - private $config; |
|
74 | + /** |
|
75 | + * @var EE_Config |
|
76 | + */ |
|
77 | + private $config; |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * StatsGatherer constructor. |
|
82 | - * |
|
83 | - * @param EEM_Payment_Method $payment_method_model |
|
84 | - * @param EEM_Event $event_model |
|
85 | - * @param EEM_Datetime $datetime_model |
|
86 | - * @param EEM_Ticket $ticket_model |
|
87 | - * @param EEM_Registration $registration_model |
|
88 | - * @param EEM_Transaction $transaction_model |
|
89 | - * @param EE_Config $config |
|
90 | - */ |
|
91 | - public function __construct( |
|
92 | - EEM_Payment_Method $payment_method_model, |
|
93 | - EEM_Event $event_model, |
|
94 | - EEM_Datetime $datetime_model, |
|
95 | - EEM_Ticket $ticket_model, |
|
96 | - EEM_Registration $registration_model, |
|
97 | - EEM_Transaction $transaction_model, |
|
98 | - EE_Config $config |
|
99 | - ) { |
|
100 | - $this->payment_method_model = $payment_method_model; |
|
101 | - $this->event_model = $event_model; |
|
102 | - $this->datetime_model = $datetime_model; |
|
103 | - $this->ticket_model = $ticket_model; |
|
104 | - $this->registration_model = $registration_model; |
|
105 | - $this->transaction_model = $transaction_model; |
|
106 | - $this->config = $config; |
|
107 | - } |
|
80 | + /** |
|
81 | + * StatsGatherer constructor. |
|
82 | + * |
|
83 | + * @param EEM_Payment_Method $payment_method_model |
|
84 | + * @param EEM_Event $event_model |
|
85 | + * @param EEM_Datetime $datetime_model |
|
86 | + * @param EEM_Ticket $ticket_model |
|
87 | + * @param EEM_Registration $registration_model |
|
88 | + * @param EEM_Transaction $transaction_model |
|
89 | + * @param EE_Config $config |
|
90 | + */ |
|
91 | + public function __construct( |
|
92 | + EEM_Payment_Method $payment_method_model, |
|
93 | + EEM_Event $event_model, |
|
94 | + EEM_Datetime $datetime_model, |
|
95 | + EEM_Ticket $ticket_model, |
|
96 | + EEM_Registration $registration_model, |
|
97 | + EEM_Transaction $transaction_model, |
|
98 | + EE_Config $config |
|
99 | + ) { |
|
100 | + $this->payment_method_model = $payment_method_model; |
|
101 | + $this->event_model = $event_model; |
|
102 | + $this->datetime_model = $datetime_model; |
|
103 | + $this->ticket_model = $ticket_model; |
|
104 | + $this->registration_model = $registration_model; |
|
105 | + $this->transaction_model = $transaction_model; |
|
106 | + $this->config = $config; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * Return the stats array for PUE UXIP stats. |
|
112 | - * |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public function stats() |
|
116 | - { |
|
117 | - global $wp_version; |
|
118 | - $stats = $this->paymentMethodStats(); |
|
119 | - // a-ok so let's setup our stats. |
|
120 | - $stats = array_merge($stats, array( |
|
121 | - 'is_multisite' => is_multisite() && is_main_site(), |
|
122 | - 'active_theme' => $this->getActiveThemeStat(), |
|
123 | - 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
124 | - 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
125 | - 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
126 | - 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
127 | - 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
128 | - 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
129 | - 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
130 | - 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
131 | - 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
132 | - 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
133 | - 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
134 | - 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
135 | - 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
136 | - 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
137 | - 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
138 | - 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
139 | - 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
140 | - self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
141 | - ? $this->config->currency->code |
|
142 | - : 'unknown', |
|
143 | - 'phpversion' => implode( |
|
144 | - '.', |
|
145 | - array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION) |
|
146 | - ), |
|
147 | - 'wpversion' => $wp_version, |
|
148 | - 'active_addons' => $this->getActiveAddons(), |
|
149 | - )); |
|
150 | - // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
151 | - return array_filter($stats, function ($value) { |
|
152 | - return $value !== null; |
|
153 | - }); |
|
154 | - } |
|
110 | + /** |
|
111 | + * Return the stats array for PUE UXIP stats. |
|
112 | + * |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public function stats() |
|
116 | + { |
|
117 | + global $wp_version; |
|
118 | + $stats = $this->paymentMethodStats(); |
|
119 | + // a-ok so let's setup our stats. |
|
120 | + $stats = array_merge($stats, array( |
|
121 | + 'is_multisite' => is_multisite() && is_main_site(), |
|
122 | + 'active_theme' => $this->getActiveThemeStat(), |
|
123 | + 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
124 | + 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
125 | + 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
126 | + 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
127 | + 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
128 | + 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
129 | + 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
130 | + 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
131 | + 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
132 | + 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
133 | + 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
134 | + 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
135 | + 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
136 | + 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
137 | + 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
138 | + 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
139 | + 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
140 | + self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
141 | + ? $this->config->currency->code |
|
142 | + : 'unknown', |
|
143 | + 'phpversion' => implode( |
|
144 | + '.', |
|
145 | + array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION) |
|
146 | + ), |
|
147 | + 'wpversion' => $wp_version, |
|
148 | + 'active_addons' => $this->getActiveAddons(), |
|
149 | + )); |
|
150 | + // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
151 | + return array_filter($stats, function ($value) { |
|
152 | + return $value !== null; |
|
153 | + }); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param string $which enum (@see constants prefixed with COUNT) |
|
158 | - * @return int|null |
|
159 | - */ |
|
160 | - private function getCountFor($which) |
|
161 | - { |
|
162 | - try { |
|
163 | - switch ($which) { |
|
164 | - case self::COUNT_ALL_EVENTS: |
|
165 | - $count = $this->event_model->count(); |
|
166 | - break; |
|
167 | - case self::COUNT_TICKETS: |
|
168 | - $count = $this->ticket_model->count(); |
|
169 | - break; |
|
170 | - case self::COUNT_DATETIMES: |
|
171 | - $count = $this->datetime_model->count(); |
|
172 | - break; |
|
173 | - case self::COUNT_ACTIVE_EVENTS: |
|
174 | - $count = $this->event_model->get_active_events(array(), true); |
|
175 | - break; |
|
176 | - case self::COUNT_DATETIMES_SOLD: |
|
177 | - $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
|
178 | - break; |
|
179 | - case self::COUNT_TICKETS_FREE: |
|
180 | - $count = $this->ticket_model->count(array( |
|
181 | - array( |
|
182 | - 'TKT_price' => 0, |
|
183 | - ), |
|
184 | - )); |
|
185 | - break; |
|
186 | - case self::COUNT_TICKETS_PAID: |
|
187 | - $count = $this->ticket_model->count(array( |
|
188 | - array( |
|
189 | - 'TKT_price' => array('>', 0), |
|
190 | - ), |
|
191 | - )); |
|
192 | - break; |
|
193 | - case self::COUNT_TICKETS_SOLD: |
|
194 | - $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
|
195 | - break; |
|
196 | - case self::COUNT_REGISTRATIONS_ALL: |
|
197 | - $count = $this->registration_model->count(); |
|
198 | - break; |
|
199 | - case self::COUNT_REGISTRATIONS_CANCELLED: |
|
200 | - $count = $this->registration_model->count( |
|
201 | - array( |
|
202 | - array( |
|
203 | - 'STS_ID' => EEM_Registration::status_id_cancelled, |
|
204 | - ), |
|
205 | - ) |
|
206 | - ); |
|
207 | - break; |
|
208 | - case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
209 | - $count = $this->registration_model->count( |
|
210 | - array( |
|
211 | - array( |
|
212 | - 'STS_ID' => EEM_Registration::status_id_incomplete, |
|
213 | - ), |
|
214 | - ) |
|
215 | - ); |
|
216 | - break; |
|
217 | - case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
218 | - $count = $this->registration_model->count( |
|
219 | - array( |
|
220 | - array( |
|
221 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
222 | - ), |
|
223 | - ) |
|
224 | - ); |
|
225 | - break; |
|
226 | - case self::COUNT_REGISTRATIONS_DECLINED: |
|
227 | - $count = $this->registration_model->count( |
|
228 | - array( |
|
229 | - array( |
|
230 | - 'STS_ID' => EEM_Registration::status_id_declined, |
|
231 | - ), |
|
232 | - ) |
|
233 | - ); |
|
234 | - break; |
|
235 | - case self::COUNT_REGISTRATIONS_PENDING: |
|
236 | - $count = $this->registration_model->count( |
|
237 | - array( |
|
238 | - array( |
|
239 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
240 | - ), |
|
241 | - ) |
|
242 | - ); |
|
243 | - break; |
|
244 | - case self::COUNT_REGISTRATIONS_APPROVED: |
|
245 | - $count = $this->registration_model->count( |
|
246 | - array( |
|
247 | - array( |
|
248 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
249 | - ), |
|
250 | - ) |
|
251 | - ); |
|
252 | - break; |
|
253 | - case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
254 | - $count = $this->transaction_model->sum( |
|
255 | - array( |
|
256 | - array( |
|
257 | - 'STS_ID' => EEM_Transaction::complete_status_code, |
|
258 | - ), |
|
259 | - ), |
|
260 | - 'TXN_total' |
|
261 | - ); |
|
262 | - break; |
|
263 | - case self::SUM_TRANSACTIONS_ALL_PAID: |
|
264 | - $count = $this->transaction_model->sum( |
|
265 | - array(), |
|
266 | - 'TXN_paid' |
|
267 | - ); |
|
268 | - break; |
|
269 | - default: |
|
270 | - $count = null; |
|
271 | - break; |
|
272 | - } |
|
273 | - } catch (Exception $e) { |
|
274 | - $count = null; |
|
275 | - } |
|
276 | - return $count; |
|
277 | - } |
|
156 | + /** |
|
157 | + * @param string $which enum (@see constants prefixed with COUNT) |
|
158 | + * @return int|null |
|
159 | + */ |
|
160 | + private function getCountFor($which) |
|
161 | + { |
|
162 | + try { |
|
163 | + switch ($which) { |
|
164 | + case self::COUNT_ALL_EVENTS: |
|
165 | + $count = $this->event_model->count(); |
|
166 | + break; |
|
167 | + case self::COUNT_TICKETS: |
|
168 | + $count = $this->ticket_model->count(); |
|
169 | + break; |
|
170 | + case self::COUNT_DATETIMES: |
|
171 | + $count = $this->datetime_model->count(); |
|
172 | + break; |
|
173 | + case self::COUNT_ACTIVE_EVENTS: |
|
174 | + $count = $this->event_model->get_active_events(array(), true); |
|
175 | + break; |
|
176 | + case self::COUNT_DATETIMES_SOLD: |
|
177 | + $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
|
178 | + break; |
|
179 | + case self::COUNT_TICKETS_FREE: |
|
180 | + $count = $this->ticket_model->count(array( |
|
181 | + array( |
|
182 | + 'TKT_price' => 0, |
|
183 | + ), |
|
184 | + )); |
|
185 | + break; |
|
186 | + case self::COUNT_TICKETS_PAID: |
|
187 | + $count = $this->ticket_model->count(array( |
|
188 | + array( |
|
189 | + 'TKT_price' => array('>', 0), |
|
190 | + ), |
|
191 | + )); |
|
192 | + break; |
|
193 | + case self::COUNT_TICKETS_SOLD: |
|
194 | + $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
|
195 | + break; |
|
196 | + case self::COUNT_REGISTRATIONS_ALL: |
|
197 | + $count = $this->registration_model->count(); |
|
198 | + break; |
|
199 | + case self::COUNT_REGISTRATIONS_CANCELLED: |
|
200 | + $count = $this->registration_model->count( |
|
201 | + array( |
|
202 | + array( |
|
203 | + 'STS_ID' => EEM_Registration::status_id_cancelled, |
|
204 | + ), |
|
205 | + ) |
|
206 | + ); |
|
207 | + break; |
|
208 | + case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
209 | + $count = $this->registration_model->count( |
|
210 | + array( |
|
211 | + array( |
|
212 | + 'STS_ID' => EEM_Registration::status_id_incomplete, |
|
213 | + ), |
|
214 | + ) |
|
215 | + ); |
|
216 | + break; |
|
217 | + case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
218 | + $count = $this->registration_model->count( |
|
219 | + array( |
|
220 | + array( |
|
221 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
222 | + ), |
|
223 | + ) |
|
224 | + ); |
|
225 | + break; |
|
226 | + case self::COUNT_REGISTRATIONS_DECLINED: |
|
227 | + $count = $this->registration_model->count( |
|
228 | + array( |
|
229 | + array( |
|
230 | + 'STS_ID' => EEM_Registration::status_id_declined, |
|
231 | + ), |
|
232 | + ) |
|
233 | + ); |
|
234 | + break; |
|
235 | + case self::COUNT_REGISTRATIONS_PENDING: |
|
236 | + $count = $this->registration_model->count( |
|
237 | + array( |
|
238 | + array( |
|
239 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
240 | + ), |
|
241 | + ) |
|
242 | + ); |
|
243 | + break; |
|
244 | + case self::COUNT_REGISTRATIONS_APPROVED: |
|
245 | + $count = $this->registration_model->count( |
|
246 | + array( |
|
247 | + array( |
|
248 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
249 | + ), |
|
250 | + ) |
|
251 | + ); |
|
252 | + break; |
|
253 | + case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
254 | + $count = $this->transaction_model->sum( |
|
255 | + array( |
|
256 | + array( |
|
257 | + 'STS_ID' => EEM_Transaction::complete_status_code, |
|
258 | + ), |
|
259 | + ), |
|
260 | + 'TXN_total' |
|
261 | + ); |
|
262 | + break; |
|
263 | + case self::SUM_TRANSACTIONS_ALL_PAID: |
|
264 | + $count = $this->transaction_model->sum( |
|
265 | + array(), |
|
266 | + 'TXN_paid' |
|
267 | + ); |
|
268 | + break; |
|
269 | + default: |
|
270 | + $count = null; |
|
271 | + break; |
|
272 | + } |
|
273 | + } catch (Exception $e) { |
|
274 | + $count = null; |
|
275 | + } |
|
276 | + return $count; |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * Return the active theme. |
|
281 | - * |
|
282 | - * @return false|string |
|
283 | - */ |
|
284 | - private function getActiveThemeStat() |
|
285 | - { |
|
286 | - $theme = wp_get_theme(); |
|
287 | - return $theme->get('Name'); |
|
288 | - } |
|
279 | + /** |
|
280 | + * Return the active theme. |
|
281 | + * |
|
282 | + * @return false|string |
|
283 | + */ |
|
284 | + private function getActiveThemeStat() |
|
285 | + { |
|
286 | + $theme = wp_get_theme(); |
|
287 | + return $theme->get('Name'); |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - private function paymentMethodStats() |
|
294 | - { |
|
295 | - $payment_method_stats = array(); |
|
296 | - try { |
|
297 | - $active_payment_methods = $this->payment_method_model->get_all_active( |
|
298 | - null, |
|
299 | - array('group_by' => 'PMD_type') |
|
300 | - ); |
|
301 | - if ($active_payment_methods) { |
|
302 | - foreach ($active_payment_methods as $payment_method) { |
|
303 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
304 | - } |
|
305 | - } |
|
306 | - } catch (Exception $e) { |
|
307 | - // do nothing just prevents fatals. |
|
308 | - } |
|
309 | - return $payment_method_stats; |
|
310 | - } |
|
290 | + /** |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + private function paymentMethodStats() |
|
294 | + { |
|
295 | + $payment_method_stats = array(); |
|
296 | + try { |
|
297 | + $active_payment_methods = $this->payment_method_model->get_all_active( |
|
298 | + null, |
|
299 | + array('group_by' => 'PMD_type') |
|
300 | + ); |
|
301 | + if ($active_payment_methods) { |
|
302 | + foreach ($active_payment_methods as $payment_method) { |
|
303 | + $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
304 | + } |
|
305 | + } |
|
306 | + } catch (Exception $e) { |
|
307 | + // do nothing just prevents fatals. |
|
308 | + } |
|
309 | + return $payment_method_stats; |
|
310 | + } |
|
311 | 311 | |
312 | 312 | |
313 | - /** |
|
314 | - * Return a list of active EE add-ons and their versions. |
|
315 | - * |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - private function getActiveAddons() |
|
319 | - { |
|
320 | - $activeAddons = []; |
|
321 | - $addOns = EE_Registry::instance()->addons; |
|
322 | - if (! empty($addOns)) { |
|
323 | - foreach ($addOns as $addon) { |
|
324 | - $activeAddons[] = $addon->name() . '@' . $addon->version(); |
|
325 | - } |
|
326 | - } |
|
327 | - return implode(',', $activeAddons); |
|
328 | - } |
|
313 | + /** |
|
314 | + * Return a list of active EE add-ons and their versions. |
|
315 | + * |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + private function getActiveAddons() |
|
319 | + { |
|
320 | + $activeAddons = []; |
|
321 | + $addOns = EE_Registry::instance()->addons; |
|
322 | + if (! empty($addOns)) { |
|
323 | + foreach ($addOns as $addon) { |
|
324 | + $activeAddons[] = $addon->name() . '@' . $addon->version(); |
|
325 | + } |
|
326 | + } |
|
327 | + return implode(',', $activeAddons); |
|
328 | + } |
|
329 | 329 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | 'active_addons' => $this->getActiveAddons(), |
149 | 149 | )); |
150 | 150 | // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
151 | - return array_filter($stats, function ($value) { |
|
151 | + return array_filter($stats, function($value) { |
|
152 | 152 | return $value !== null; |
153 | 153 | }); |
154 | 154 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ); |
301 | 301 | if ($active_payment_methods) { |
302 | 302 | foreach ($active_payment_methods as $payment_method) { |
303 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
303 | + $payment_method_stats[$payment_method->name().'_active_payment_method'] = 1; |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | } catch (Exception $e) { |
@@ -319,9 +319,9 @@ discard block |
||
319 | 319 | { |
320 | 320 | $activeAddons = []; |
321 | 321 | $addOns = EE_Registry::instance()->addons; |
322 | - if (! empty($addOns)) { |
|
322 | + if ( ! empty($addOns)) { |
|
323 | 323 | foreach ($addOns as $addon) { |
324 | - $activeAddons[] = $addon->name() . '@' . $addon->version(); |
|
324 | + $activeAddons[] = $addon->name().'@'.$addon->version(); |
|
325 | 325 | } |
326 | 326 | } |
327 | 327 | return implode(',', $activeAddons); |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.1.rc.060'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.1.rc.060'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |