@@ -33,211 +33,211 @@ |
||
33 | 33 | class ShortcodesManager |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
38 | - */ |
|
39 | - private $legacy_shortcodes_manager; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ShortcodeInterface[] $shortcodes |
|
43 | - */ |
|
44 | - private $shortcodes; |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * ShortcodesManager constructor |
|
50 | - * |
|
51 | - * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
52 | - */ |
|
53 | - public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
54 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
55 | - // assemble a list of installed and active shortcodes |
|
56 | - add_action( |
|
57 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
58 | - array($this, 'registerShortcodes'), |
|
59 | - 999 |
|
60 | - ); |
|
61 | - // call add_shortcode() for all installed shortcodes |
|
62 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
63 | - // check content for shortcodes the old way |
|
64 | - add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
65 | - // check content for shortcodes the NEW more efficient way |
|
66 | - add_action('wp_head', array($this, 'wpHead'), 0); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return CollectionInterface|ShortcodeInterface[] |
|
73 | - * @throws InvalidIdentifierException |
|
74 | - * @throws InvalidInterfaceException |
|
75 | - * @throws InvalidFilePathException |
|
76 | - * @throws InvalidEntityException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidClassException |
|
79 | - */ |
|
80 | - public function getShortcodes() |
|
81 | - { |
|
82 | - if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
83 | - $this->shortcodes = $this->loadShortcodesCollection(); |
|
84 | - } |
|
85 | - return $this->shortcodes; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return CollectionInterface|ShortcodeInterface[] |
|
92 | - * @throws InvalidIdentifierException |
|
93 | - * @throws InvalidInterfaceException |
|
94 | - * @throws InvalidFilePathException |
|
95 | - * @throws InvalidEntityException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidClassException |
|
98 | - */ |
|
99 | - protected function loadShortcodesCollection() |
|
100 | - { |
|
101 | - $loader = new CollectionLoader( |
|
102 | - new CollectionDetails( |
|
103 | - // collection name |
|
104 | - 'shortcodes', |
|
105 | - // collection interface |
|
106 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
107 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
108 | - array('EventEspresso\core\domain\entities\shortcodes'), |
|
109 | - // filepaths to classes to add |
|
110 | - array(), |
|
111 | - // filemask to use if parsing folder for files to add |
|
112 | - '', |
|
113 | - // what to use as identifier for collection entities |
|
114 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
115 | - CollectionDetails::ID_CLASS_NAME |
|
116 | - ) |
|
117 | - ); |
|
118 | - return $loader->getCollection(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return void |
|
125 | - * @throws DomainException |
|
126 | - * @throws InvalidInterfaceException |
|
127 | - * @throws InvalidIdentifierException |
|
128 | - * @throws InvalidFilePathException |
|
129 | - * @throws InvalidEntityException |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws InvalidClassException |
|
132 | - */ |
|
133 | - public function registerShortcodes() |
|
134 | - { |
|
135 | - try { |
|
136 | - $this->shortcodes = apply_filters( |
|
137 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
138 | - $this->getShortcodes() |
|
139 | - ); |
|
140 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
141 | - throw new InvalidEntityException( |
|
142 | - $this->shortcodes, |
|
143 | - 'CollectionInterface', |
|
144 | - sprintf( |
|
145 | - esc_html__( |
|
146 | - 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
150 | - ) |
|
151 | - ); |
|
152 | - } |
|
153 | - $this->legacy_shortcodes_manager->registerShortcodes(); |
|
154 | - } catch (Exception $exception) { |
|
155 | - new ExceptionStackTraceDisplay($exception); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public function addShortcodes() |
|
165 | - { |
|
166 | - try { |
|
167 | - // cycle thru shortcode folders |
|
168 | - foreach ($this->shortcodes as $shortcode) { |
|
169 | - /** @var ShortcodeInterface $shortcode */ |
|
170 | - if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
171 | - add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
172 | - add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
173 | - } |
|
174 | - // add_shortcode() if it has not already been added |
|
175 | - if ( ! shortcode_exists($shortcode->getTag())) { |
|
176 | - add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->legacy_shortcodes_manager->addShortcodes(); |
|
180 | - } catch (Exception $exception) { |
|
181 | - new ExceptionStackTraceDisplay($exception); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * callback for the "wp_head" hook point |
|
189 | - * checks posts for EE shortcodes, and initializes them, |
|
190 | - * then toggles filter switch that loads core default assets |
|
191 | - * |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - public function wpHead() |
|
195 | - { |
|
196 | - global $wp_query; |
|
197 | - if (empty($wp_query->posts)) { |
|
198 | - return; |
|
199 | - } |
|
200 | - $load_assets = false; |
|
201 | - // array of posts displayed in current request |
|
202 | - $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
203 | - foreach ($posts as $post) { |
|
204 | - // now check post content and excerpt for EE shortcodes |
|
205 | - $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
206 | - ? true |
|
207 | - : $load_assets; |
|
208 | - } |
|
209 | - if ($load_assets) { |
|
210 | - $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
211 | - add_filter('FHEE_load_css', '__return_true'); |
|
212 | - add_filter('FHEE_load_js', '__return_true'); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * checks supplied content against list of shortcodes, |
|
220 | - * then initializes any found shortcodes, and returns true. |
|
221 | - * returns false if no shortcodes found. |
|
222 | - * |
|
223 | - * @param string $content |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - public function parseContentForShortcodes($content) |
|
227 | - { |
|
228 | - $has_shortcode = false; |
|
229 | - if(empty($this->shortcodes)){ |
|
230 | - return $has_shortcode; |
|
231 | - } |
|
232 | - foreach ($this->shortcodes as $shortcode) { |
|
233 | - /** @var ShortcodeInterface $shortcode */ |
|
234 | - if (has_shortcode($content, $shortcode->getTag())) { |
|
235 | - $shortcode->initializeShortcode(); |
|
236 | - $has_shortcode = true; |
|
237 | - } |
|
238 | - } |
|
239 | - return $has_shortcode; |
|
240 | - } |
|
36 | + /** |
|
37 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
38 | + */ |
|
39 | + private $legacy_shortcodes_manager; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ShortcodeInterface[] $shortcodes |
|
43 | + */ |
|
44 | + private $shortcodes; |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * ShortcodesManager constructor |
|
50 | + * |
|
51 | + * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
52 | + */ |
|
53 | + public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
54 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
55 | + // assemble a list of installed and active shortcodes |
|
56 | + add_action( |
|
57 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
58 | + array($this, 'registerShortcodes'), |
|
59 | + 999 |
|
60 | + ); |
|
61 | + // call add_shortcode() for all installed shortcodes |
|
62 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
63 | + // check content for shortcodes the old way |
|
64 | + add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
65 | + // check content for shortcodes the NEW more efficient way |
|
66 | + add_action('wp_head', array($this, 'wpHead'), 0); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return CollectionInterface|ShortcodeInterface[] |
|
73 | + * @throws InvalidIdentifierException |
|
74 | + * @throws InvalidInterfaceException |
|
75 | + * @throws InvalidFilePathException |
|
76 | + * @throws InvalidEntityException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidClassException |
|
79 | + */ |
|
80 | + public function getShortcodes() |
|
81 | + { |
|
82 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
83 | + $this->shortcodes = $this->loadShortcodesCollection(); |
|
84 | + } |
|
85 | + return $this->shortcodes; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return CollectionInterface|ShortcodeInterface[] |
|
92 | + * @throws InvalidIdentifierException |
|
93 | + * @throws InvalidInterfaceException |
|
94 | + * @throws InvalidFilePathException |
|
95 | + * @throws InvalidEntityException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidClassException |
|
98 | + */ |
|
99 | + protected function loadShortcodesCollection() |
|
100 | + { |
|
101 | + $loader = new CollectionLoader( |
|
102 | + new CollectionDetails( |
|
103 | + // collection name |
|
104 | + 'shortcodes', |
|
105 | + // collection interface |
|
106 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
107 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
108 | + array('EventEspresso\core\domain\entities\shortcodes'), |
|
109 | + // filepaths to classes to add |
|
110 | + array(), |
|
111 | + // filemask to use if parsing folder for files to add |
|
112 | + '', |
|
113 | + // what to use as identifier for collection entities |
|
114 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
115 | + CollectionDetails::ID_CLASS_NAME |
|
116 | + ) |
|
117 | + ); |
|
118 | + return $loader->getCollection(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return void |
|
125 | + * @throws DomainException |
|
126 | + * @throws InvalidInterfaceException |
|
127 | + * @throws InvalidIdentifierException |
|
128 | + * @throws InvalidFilePathException |
|
129 | + * @throws InvalidEntityException |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws InvalidClassException |
|
132 | + */ |
|
133 | + public function registerShortcodes() |
|
134 | + { |
|
135 | + try { |
|
136 | + $this->shortcodes = apply_filters( |
|
137 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
138 | + $this->getShortcodes() |
|
139 | + ); |
|
140 | + if (! $this->shortcodes instanceof CollectionInterface) { |
|
141 | + throw new InvalidEntityException( |
|
142 | + $this->shortcodes, |
|
143 | + 'CollectionInterface', |
|
144 | + sprintf( |
|
145 | + esc_html__( |
|
146 | + 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
150 | + ) |
|
151 | + ); |
|
152 | + } |
|
153 | + $this->legacy_shortcodes_manager->registerShortcodes(); |
|
154 | + } catch (Exception $exception) { |
|
155 | + new ExceptionStackTraceDisplay($exception); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public function addShortcodes() |
|
165 | + { |
|
166 | + try { |
|
167 | + // cycle thru shortcode folders |
|
168 | + foreach ($this->shortcodes as $shortcode) { |
|
169 | + /** @var ShortcodeInterface $shortcode */ |
|
170 | + if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
171 | + add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
172 | + add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
173 | + } |
|
174 | + // add_shortcode() if it has not already been added |
|
175 | + if ( ! shortcode_exists($shortcode->getTag())) { |
|
176 | + add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->legacy_shortcodes_manager->addShortcodes(); |
|
180 | + } catch (Exception $exception) { |
|
181 | + new ExceptionStackTraceDisplay($exception); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * callback for the "wp_head" hook point |
|
189 | + * checks posts for EE shortcodes, and initializes them, |
|
190 | + * then toggles filter switch that loads core default assets |
|
191 | + * |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + public function wpHead() |
|
195 | + { |
|
196 | + global $wp_query; |
|
197 | + if (empty($wp_query->posts)) { |
|
198 | + return; |
|
199 | + } |
|
200 | + $load_assets = false; |
|
201 | + // array of posts displayed in current request |
|
202 | + $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
203 | + foreach ($posts as $post) { |
|
204 | + // now check post content and excerpt for EE shortcodes |
|
205 | + $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
206 | + ? true |
|
207 | + : $load_assets; |
|
208 | + } |
|
209 | + if ($load_assets) { |
|
210 | + $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
211 | + add_filter('FHEE_load_css', '__return_true'); |
|
212 | + add_filter('FHEE_load_js', '__return_true'); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * checks supplied content against list of shortcodes, |
|
220 | + * then initializes any found shortcodes, and returns true. |
|
221 | + * returns false if no shortcodes found. |
|
222 | + * |
|
223 | + * @param string $content |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + public function parseContentForShortcodes($content) |
|
227 | + { |
|
228 | + $has_shortcode = false; |
|
229 | + if(empty($this->shortcodes)){ |
|
230 | + return $has_shortcode; |
|
231 | + } |
|
232 | + foreach ($this->shortcodes as $shortcode) { |
|
233 | + /** @var ShortcodeInterface $shortcode */ |
|
234 | + if (has_shortcode($content, $shortcode->getTag())) { |
|
235 | + $shortcode->initializeShortcode(); |
|
236 | + $has_shortcode = true; |
|
237 | + } |
|
238 | + } |
|
239 | + return $has_shortcode; |
|
240 | + } |
|
241 | 241 | |
242 | 242 | } |
243 | 243 | // End of file ShortcodesManager.php |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -14,740 +14,740 @@ discard block |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @type EE_Messages_Data_Handler_Collection |
|
19 | - */ |
|
20 | - protected $_data_handler_collection; |
|
21 | - |
|
22 | - /** |
|
23 | - * @type EE_Message_Template_Group_Collection |
|
24 | - */ |
|
25 | - protected $_template_collection; |
|
26 | - |
|
27 | - /** |
|
28 | - * This will hold the data handler for the current EE_Message being generated. |
|
29 | - * |
|
30 | - * @type EE_Messages_incoming_data |
|
31 | - */ |
|
32 | - protected $_current_data_handler; |
|
33 | - |
|
34 | - /** |
|
35 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
36 | - * |
|
37 | - * @type EE_Messages_Queue |
|
38 | - */ |
|
39 | - protected $_generation_queue; |
|
40 | - |
|
41 | - /** |
|
42 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
43 | - * |
|
44 | - * @type EE_Messages_Queue |
|
45 | - */ |
|
46 | - protected $_ready_queue; |
|
47 | - |
|
48 | - /** |
|
49 | - * This is a container for any error messages that get created through the generation |
|
50 | - * process. |
|
51 | - * |
|
52 | - * @type array |
|
53 | - */ |
|
54 | - protected $_error_msg = array(); |
|
55 | - |
|
56 | - /** |
|
57 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
58 | - * |
|
59 | - * @type bool |
|
60 | - */ |
|
61 | - protected $_verified = false; |
|
62 | - |
|
63 | - /** |
|
64 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
65 | - * |
|
66 | - * @type EE_messenger |
|
67 | - */ |
|
68 | - protected $_current_messenger; |
|
69 | - |
|
70 | - /** |
|
71 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
72 | - * |
|
73 | - * @type EE_message_type |
|
74 | - */ |
|
75 | - protected $_current_message_type; |
|
76 | - |
|
77 | - /** |
|
78 | - * @type EEH_Parse_Shortcodes |
|
79 | - */ |
|
80 | - protected $_shortcode_parser; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param EE_Messages_Queue $generation_queue |
|
85 | - * @param \EE_Messages_Queue $ready_queue |
|
86 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
87 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
88 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
89 | - */ |
|
90 | - public function __construct( |
|
91 | - EE_Messages_Queue $generation_queue, |
|
92 | - EE_Messages_Queue $ready_queue, |
|
93 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
94 | - EE_Message_Template_Group_Collection $template_collection, |
|
95 | - EEH_Parse_Shortcodes $shortcode_parser |
|
96 | - ) { |
|
97 | - $this->_generation_queue = $generation_queue; |
|
98 | - $this->_ready_queue = $ready_queue; |
|
99 | - $this->_data_handler_collection = $data_handler_collection; |
|
100 | - $this->_template_collection = $template_collection; |
|
101 | - $this->_shortcode_parser = $shortcode_parser; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return EE_Messages_Queue |
|
107 | - */ |
|
108 | - public function generation_queue() |
|
109 | - { |
|
110 | - return $this->_generation_queue; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
116 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
117 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
118 | - * for the caller to decide what to do with it. |
|
119 | - * |
|
120 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
121 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
122 | - */ |
|
123 | - public function generate($save = true) |
|
124 | - { |
|
125 | - //iterate through the messages in the queue, generate, and add to new queue. |
|
126 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | - //reset "current" properties |
|
129 | - $this->_reset_current_properties(); |
|
130 | - |
|
131 | - /** @type EE_Message $msg */ |
|
132 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | - |
|
134 | - /** |
|
135 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | - * an object is removed from the repo then valid for the next object will fail. |
|
137 | - */ |
|
138 | - $this->_generation_queue->get_message_repository()->next(); |
|
139 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | - //restore pointer to current item |
|
141 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | - |
|
143 | - //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | - //we keep this item in the db just remove from the repo. |
|
146 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | - //next item |
|
148 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | - continue; |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->_verify()) { |
|
153 | - //let's get generating! |
|
154 | - $this->_generate(); |
|
155 | - } |
|
156 | - |
|
157 | - //don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | - if ( |
|
159 | - $msg->STS_ID() === EEM_Message::status_debug_only |
|
160 | - && ! EEM_Message::debug() |
|
161 | - ) { |
|
162 | - do_action('AHEE__EE_Messages_Generator__generate__before_debug_delete', $msg, $this->_error_msg, |
|
163 | - $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
164 | - $this->_generation_queue->get_message_repository()->delete(); |
|
165 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
166 | - continue; |
|
167 | - } |
|
168 | - |
|
169 | - //if there are error messages then let's set the status and the error message. |
|
170 | - if ($this->_error_msg) { |
|
171 | - //if the status is already debug only, then let's leave it at that. |
|
172 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
173 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
174 | - } |
|
175 | - do_action('AHEE__EE_Messages_Generator__generate__processing_failed_message', $msg, $this->_error_msg, |
|
176 | - $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
177 | - $msg->set_error_message( |
|
178 | - __('Message failed to generate for the following reasons: ') |
|
179 | - . "\n" |
|
180 | - . implode("\n", $this->_error_msg) |
|
181 | - ); |
|
182 | - $msg->set_modified(time()); |
|
183 | - } else { |
|
184 | - do_action('AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', $msg, |
|
185 | - $this->_error_msg, $this->_current_messenger, $this->_current_message_type, |
|
186 | - $this->_current_data_handler); |
|
187 | - //remove from db |
|
188 | - $this->_generation_queue->get_message_repository()->delete(); |
|
189 | - } |
|
190 | - //next item |
|
191 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
192 | - } |
|
193 | - |
|
194 | - //generation queue is ALWAYS saved to record any errors in the generation process. |
|
195 | - $this->_generation_queue->save(); |
|
196 | - |
|
197 | - /** |
|
198 | - * save _ready_queue if flag set. |
|
199 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
200 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
201 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
202 | - * irrelevant. |
|
203 | - */ |
|
204 | - if ($save) { |
|
205 | - $this->_ready_queue->save(); |
|
206 | - } |
|
207 | - |
|
208 | - //final reset of properties |
|
209 | - $this->_reset_current_properties(); |
|
210 | - |
|
211 | - return $this->_ready_queue; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
217 | - * in the generation queue. |
|
218 | - */ |
|
219 | - protected function _reset_current_properties() |
|
220 | - { |
|
221 | - $this->_verified = false; |
|
222 | - //make sure any _data value in the current message type is reset |
|
223 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
224 | - $this->_current_message_type->reset_data(); |
|
225 | - } |
|
226 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
232 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
233 | - * _generating_queue. |
|
234 | - * |
|
235 | - * @return bool Whether the message was successfully generated or not. |
|
236 | - */ |
|
237 | - protected function _generate() |
|
238 | - { |
|
239 | - //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
|
240 | - if (! $this->_verified) { |
|
241 | - return false; //get out because we don't have a valid setup to work with. |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - try { |
|
246 | - $addressees = $this->_current_message_type->get_addressees( |
|
247 | - $this->_current_data_handler, |
|
248 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
249 | - ); |
|
250 | - } catch (EE_Error $e) { |
|
251 | - $this->_error_msg[] = $e->getMessage(); |
|
252 | - return false; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - //if no addressees then get out because there is nothing to generation (possible bad data). |
|
257 | - if (! $this->_valid_addressees($addressees)) { |
|
258 | - do_action('AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
259 | - $this->_generation_queue->get_message_repository()->current(), $addressees, $this->_current_messenger, |
|
260 | - $this->_current_message_type, $this->_current_data_handler); |
|
261 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID(EEM_Message::status_debug_only); |
|
262 | - $this->_error_msg[] = __('This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. |
|
17 | + /** |
|
18 | + * @type EE_Messages_Data_Handler_Collection |
|
19 | + */ |
|
20 | + protected $_data_handler_collection; |
|
21 | + |
|
22 | + /** |
|
23 | + * @type EE_Message_Template_Group_Collection |
|
24 | + */ |
|
25 | + protected $_template_collection; |
|
26 | + |
|
27 | + /** |
|
28 | + * This will hold the data handler for the current EE_Message being generated. |
|
29 | + * |
|
30 | + * @type EE_Messages_incoming_data |
|
31 | + */ |
|
32 | + protected $_current_data_handler; |
|
33 | + |
|
34 | + /** |
|
35 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
36 | + * |
|
37 | + * @type EE_Messages_Queue |
|
38 | + */ |
|
39 | + protected $_generation_queue; |
|
40 | + |
|
41 | + /** |
|
42 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
43 | + * |
|
44 | + * @type EE_Messages_Queue |
|
45 | + */ |
|
46 | + protected $_ready_queue; |
|
47 | + |
|
48 | + /** |
|
49 | + * This is a container for any error messages that get created through the generation |
|
50 | + * process. |
|
51 | + * |
|
52 | + * @type array |
|
53 | + */ |
|
54 | + protected $_error_msg = array(); |
|
55 | + |
|
56 | + /** |
|
57 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
58 | + * |
|
59 | + * @type bool |
|
60 | + */ |
|
61 | + protected $_verified = false; |
|
62 | + |
|
63 | + /** |
|
64 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
65 | + * |
|
66 | + * @type EE_messenger |
|
67 | + */ |
|
68 | + protected $_current_messenger; |
|
69 | + |
|
70 | + /** |
|
71 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
72 | + * |
|
73 | + * @type EE_message_type |
|
74 | + */ |
|
75 | + protected $_current_message_type; |
|
76 | + |
|
77 | + /** |
|
78 | + * @type EEH_Parse_Shortcodes |
|
79 | + */ |
|
80 | + protected $_shortcode_parser; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param EE_Messages_Queue $generation_queue |
|
85 | + * @param \EE_Messages_Queue $ready_queue |
|
86 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
87 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
88 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
89 | + */ |
|
90 | + public function __construct( |
|
91 | + EE_Messages_Queue $generation_queue, |
|
92 | + EE_Messages_Queue $ready_queue, |
|
93 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
94 | + EE_Message_Template_Group_Collection $template_collection, |
|
95 | + EEH_Parse_Shortcodes $shortcode_parser |
|
96 | + ) { |
|
97 | + $this->_generation_queue = $generation_queue; |
|
98 | + $this->_ready_queue = $ready_queue; |
|
99 | + $this->_data_handler_collection = $data_handler_collection; |
|
100 | + $this->_template_collection = $template_collection; |
|
101 | + $this->_shortcode_parser = $shortcode_parser; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return EE_Messages_Queue |
|
107 | + */ |
|
108 | + public function generation_queue() |
|
109 | + { |
|
110 | + return $this->_generation_queue; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
116 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
117 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
118 | + * for the caller to decide what to do with it. |
|
119 | + * |
|
120 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
121 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
122 | + */ |
|
123 | + public function generate($save = true) |
|
124 | + { |
|
125 | + //iterate through the messages in the queue, generate, and add to new queue. |
|
126 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | + //reset "current" properties |
|
129 | + $this->_reset_current_properties(); |
|
130 | + |
|
131 | + /** @type EE_Message $msg */ |
|
132 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | + |
|
134 | + /** |
|
135 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | + * an object is removed from the repo then valid for the next object will fail. |
|
137 | + */ |
|
138 | + $this->_generation_queue->get_message_repository()->next(); |
|
139 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | + //restore pointer to current item |
|
141 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | + |
|
143 | + //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | + //we keep this item in the db just remove from the repo. |
|
146 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | + //next item |
|
148 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | + continue; |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->_verify()) { |
|
153 | + //let's get generating! |
|
154 | + $this->_generate(); |
|
155 | + } |
|
156 | + |
|
157 | + //don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | + if ( |
|
159 | + $msg->STS_ID() === EEM_Message::status_debug_only |
|
160 | + && ! EEM_Message::debug() |
|
161 | + ) { |
|
162 | + do_action('AHEE__EE_Messages_Generator__generate__before_debug_delete', $msg, $this->_error_msg, |
|
163 | + $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
164 | + $this->_generation_queue->get_message_repository()->delete(); |
|
165 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
166 | + continue; |
|
167 | + } |
|
168 | + |
|
169 | + //if there are error messages then let's set the status and the error message. |
|
170 | + if ($this->_error_msg) { |
|
171 | + //if the status is already debug only, then let's leave it at that. |
|
172 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
173 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
174 | + } |
|
175 | + do_action('AHEE__EE_Messages_Generator__generate__processing_failed_message', $msg, $this->_error_msg, |
|
176 | + $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
177 | + $msg->set_error_message( |
|
178 | + __('Message failed to generate for the following reasons: ') |
|
179 | + . "\n" |
|
180 | + . implode("\n", $this->_error_msg) |
|
181 | + ); |
|
182 | + $msg->set_modified(time()); |
|
183 | + } else { |
|
184 | + do_action('AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', $msg, |
|
185 | + $this->_error_msg, $this->_current_messenger, $this->_current_message_type, |
|
186 | + $this->_current_data_handler); |
|
187 | + //remove from db |
|
188 | + $this->_generation_queue->get_message_repository()->delete(); |
|
189 | + } |
|
190 | + //next item |
|
191 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
192 | + } |
|
193 | + |
|
194 | + //generation queue is ALWAYS saved to record any errors in the generation process. |
|
195 | + $this->_generation_queue->save(); |
|
196 | + |
|
197 | + /** |
|
198 | + * save _ready_queue if flag set. |
|
199 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
200 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
201 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
202 | + * irrelevant. |
|
203 | + */ |
|
204 | + if ($save) { |
|
205 | + $this->_ready_queue->save(); |
|
206 | + } |
|
207 | + |
|
208 | + //final reset of properties |
|
209 | + $this->_reset_current_properties(); |
|
210 | + |
|
211 | + return $this->_ready_queue; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
217 | + * in the generation queue. |
|
218 | + */ |
|
219 | + protected function _reset_current_properties() |
|
220 | + { |
|
221 | + $this->_verified = false; |
|
222 | + //make sure any _data value in the current message type is reset |
|
223 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
224 | + $this->_current_message_type->reset_data(); |
|
225 | + } |
|
226 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
232 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
233 | + * _generating_queue. |
|
234 | + * |
|
235 | + * @return bool Whether the message was successfully generated or not. |
|
236 | + */ |
|
237 | + protected function _generate() |
|
238 | + { |
|
239 | + //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
|
240 | + if (! $this->_verified) { |
|
241 | + return false; //get out because we don't have a valid setup to work with. |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + try { |
|
246 | + $addressees = $this->_current_message_type->get_addressees( |
|
247 | + $this->_current_data_handler, |
|
248 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
249 | + ); |
|
250 | + } catch (EE_Error $e) { |
|
251 | + $this->_error_msg[] = $e->getMessage(); |
|
252 | + return false; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + //if no addressees then get out because there is nothing to generation (possible bad data). |
|
257 | + if (! $this->_valid_addressees($addressees)) { |
|
258 | + do_action('AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
259 | + $this->_generation_queue->get_message_repository()->current(), $addressees, $this->_current_messenger, |
|
260 | + $this->_current_message_type, $this->_current_data_handler); |
|
261 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID(EEM_Message::status_debug_only); |
|
262 | + $this->_error_msg[] = __('This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. |
|
263 | 263 | Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
264 | - 'event_espresso'); |
|
265 | - return false; |
|
266 | - } |
|
267 | - |
|
268 | - $message_template_group = $this->_get_message_template_group(); |
|
269 | - |
|
270 | - //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
271 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
272 | - $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
273 | - 'event_espresso'); |
|
274 | - return false; |
|
275 | - } |
|
276 | - |
|
277 | - //get formatted templates for using to parse and setup EE_Message objects. |
|
278 | - $templates = $this->_get_templates($message_template_group); |
|
279 | - |
|
280 | - |
|
281 | - //setup new EE_Message objects (and add to _ready_queue) |
|
282 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Retrieves the message template group being used for generating messages. |
|
288 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
289 | - * |
|
290 | - * @return EE_Message_Template_Group | null |
|
291 | - */ |
|
292 | - protected function _get_message_template_group() |
|
293 | - { |
|
294 | - //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
295 | - //so let's use that. |
|
296 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
297 | - |
|
298 | - if ($GRP_ID) { |
|
299 | - //attempt to retrieve from repo first |
|
300 | - $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
|
301 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
302 | - return $GRP; //got it! |
|
303 | - } |
|
304 | - |
|
305 | - //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
306 | - //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
307 | - $GRP = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
308 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
309 | - $this->_template_collection->add($GRP); |
|
310 | - return $GRP; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - //whatcha still doing here? Oh, no Message Template Group yet I see. Okay let's see if we can get it for you. |
|
315 | - |
|
316 | - //defaults |
|
317 | - $EVT_ID = 0; |
|
318 | - |
|
319 | - $template_qa = array( |
|
320 | - 'MTP_is_active' => true, |
|
321 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
322 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
323 | - ); |
|
324 | - |
|
325 | - //in vanilla EE we're assuming there's only one event. |
|
326 | - //However, if there are multiple events then we'll just use the default templates instead of different |
|
327 | - // templates per event (which could create problems). |
|
328 | - if (count($this->_current_data_handler->events) === 1) { |
|
329 | - foreach ($this->_current_data_handler->events as $event) { |
|
330 | - $EVT_ID = $event['ID']; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - //before going any further, let's see if its in the queue |
|
335 | - $GRP = $this->_template_collection->get_by_key($this->_template_collection->get_key($this->_current_messenger->name, |
|
336 | - $this->_current_message_type->name, $EVT_ID)); |
|
337 | - |
|
338 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
339 | - return $GRP; |
|
340 | - } |
|
341 | - |
|
342 | - //nope still no GRP? |
|
343 | - //first we get the global template in case it has an override set. |
|
344 | - $global_template_qa = array_merge(array('MTP_is_global' => true), $template_qa); |
|
345 | - $global_GRP = EEM_Message_Template_Group::instance()->get_one(array($global_template_qa)); |
|
346 | - |
|
347 | - //if this is an override, then we just return it. |
|
348 | - if ($global_GRP instanceof EE_Message_Template_Group && $global_GRP->get('MTP_is_override')) { |
|
349 | - $this->_template_collection->add($global_GRP, $EVT_ID); |
|
350 | - return $global_GRP; |
|
351 | - } |
|
352 | - |
|
353 | - //STILL here? Okay that means we want to see if there is event specific group and if there is we return it, |
|
354 | - //otherwise we return the global group we retrieved. |
|
355 | - if ($EVT_ID) { |
|
356 | - $template_qa['Event.EVT_ID'] = $EVT_ID; |
|
357 | - } |
|
358 | - |
|
359 | - $GRP = EEM_Message_Template_Group::instance()->get_one(array($template_qa)); |
|
360 | - $GRP = $GRP instanceof EE_Message_Template_Group ? $GRP : $global_GRP; |
|
361 | - |
|
362 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
363 | - $this->_template_collection->add($GRP, $EVT_ID); |
|
364 | - return $GRP; |
|
365 | - } |
|
366 | - |
|
367 | - //nothing, nada, there ain't no group from what you fed the machine. (Getting here is a very hard thing to do). |
|
368 | - return null; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Retrieves formatted array of template information for each context specific to the given |
|
374 | - * EE_Message_Template_Group |
|
375 | - * |
|
376 | - * @param EE_Message_Template_Group |
|
377 | - * @return array The returned array is in this structure: |
|
378 | - * array( |
|
379 | - * 'field_name' => array( |
|
380 | - * 'context' => 'content' |
|
381 | - * ) |
|
382 | - * ) |
|
383 | - */ |
|
384 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
385 | - { |
|
386 | - $templates = array(); |
|
387 | - $context_templates = $message_template_group->context_templates(); |
|
388 | - foreach ($context_templates as $context => $template_fields) { |
|
389 | - foreach ($template_fields as $template_field => $template_obj) { |
|
390 | - if (! $template_obj instanceof EE_Message_Template) { |
|
391 | - continue; |
|
392 | - } |
|
393 | - $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
394 | - } |
|
395 | - } |
|
396 | - return $templates; |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
402 | - * |
|
403 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
404 | - * context. |
|
405 | - * @param array $templates formatted array of templates used for parsing data. |
|
406 | - * @param EE_Message_Template_Group $message_template_group |
|
407 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
408 | - * method will attempt to generate ALL EE_Message objects and add to the _ready_queue. Successfully |
|
409 | - * generated messages get added to the queue with EEM_Message::status_idle, unsuccessfully generated |
|
410 | - * messages will get added to the queue as EEM_Message::status_failed. Very rarely should "false" |
|
411 | - * be returned from this method. |
|
412 | - */ |
|
413 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
414 | - { |
|
415 | - |
|
416 | - //if templates are empty then get out because we can't generate anything. |
|
417 | - if (! $templates) { |
|
418 | - $this->_error_msg[] = __('Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
419 | - 'event_espresso'); |
|
420 | - return false; |
|
421 | - } |
|
422 | - |
|
423 | - //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
424 | - //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
425 | - $generated_count = 0; |
|
426 | - foreach ($addressees as $context => $recipients) { |
|
427 | - foreach ($recipients as $recipient) { |
|
428 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
429 | - if ($message instanceof EE_Message) { |
|
430 | - $this->_ready_queue->add( |
|
431 | - $message, |
|
432 | - array(), |
|
433 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
434 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
435 | - ); |
|
436 | - $generated_count++; |
|
437 | - } |
|
438 | - |
|
439 | - //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
440 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
441 | - break 2; |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - //if there are no generated messages then something else fatal went wrong. |
|
447 | - return $generated_count > 0; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param string $context The context for the generated message. |
|
453 | - * @param EE_Messages_Addressee $recipient |
|
454 | - * @param array $templates formatted array of templates used for parsing data. |
|
455 | - * @param EE_Message_Template_Group $message_template_group |
|
456 | - * @return EE_Message | bool (false is used when no EE_Message is generated) |
|
457 | - */ |
|
458 | - protected function _setup_message_object( |
|
459 | - $context, |
|
460 | - EE_Messages_Addressee $recipient, |
|
461 | - $templates, |
|
462 | - EE_Message_Template_Group $message_template_group |
|
463 | - ) { |
|
464 | - //stuff we already know |
|
465 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
466 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
467 | - ? $this->_current_data_handler->txn->ID() |
|
468 | - : $transaction_id; |
|
469 | - $message_fields = array( |
|
470 | - 'GRP_ID' => $message_template_group->ID(), |
|
471 | - 'TXN_ID' => $transaction_id, |
|
472 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
473 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
474 | - 'MSG_context' => $context, |
|
475 | - ); |
|
476 | - |
|
477 | - //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab the |
|
478 | - //info from the att_obj found in the EE_Messages_Addressee object. |
|
479 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
480 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
481 | - ? $recipient->att_obj->ID() |
|
482 | - : 0; |
|
483 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
484 | - } else { |
|
485 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
486 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
487 | - } |
|
488 | - $message = EE_Message_Factory::create($message_fields); |
|
489 | - |
|
490 | - //grab valid shortcodes for shortcode parser |
|
491 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
492 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
493 | - |
|
494 | - //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
495 | - //context is turned off) EXCEPT if we're previewing |
|
496 | - if (empty($templates['to'][$context]) |
|
497 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
498 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
499 | - ) { |
|
500 | - //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" field. |
|
501 | - return false; |
|
502 | - } |
|
503 | - $error_msg = array(); |
|
504 | - foreach ($templates as $field => $field_context) { |
|
505 | - $error_msg = array(); |
|
506 | - //let's setup the valid shortcodes for the incoming context. |
|
507 | - $valid_shortcodes = $mt_shortcodes[$context]; |
|
508 | - //merge in valid shortcodes for the field. |
|
509 | - $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
510 | - if (isset($templates[$field][$context])) { |
|
511 | - //prefix field. |
|
512 | - $column_name = 'MSG_' . $field; |
|
513 | - try { |
|
514 | - $content = $this->_shortcode_parser->parse_message_template( |
|
515 | - $templates[$field][$context], |
|
516 | - $recipient, |
|
517 | - $shortcodes, |
|
518 | - $this->_current_message_type, |
|
519 | - $this->_current_messenger, |
|
520 | - $message); |
|
521 | - $message->set_field_or_extra_meta($column_name, $content); |
|
522 | - } catch (EE_Error $e) { |
|
523 | - $error_msg[] = sprintf(__('There was a problem generating the content for the field %s: %s', |
|
524 | - 'event_espresso'), $field, $e->getMessage()); |
|
525 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
526 | - } |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
531 | - $error_msg = __('There were problems generating this message:', 'event_espresso') . "\n" . implode("\n", |
|
532 | - $error_msg); |
|
533 | - $message->set_error_message($error_msg); |
|
534 | - } else { |
|
535 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
536 | - } |
|
537 | - return $message; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
543 | - * error message if either is missing. |
|
544 | - * |
|
545 | - * @return bool true means there were no errors, false means there were errors. |
|
546 | - */ |
|
547 | - protected function _verify() |
|
548 | - { |
|
549 | - //reset error message to an empty array. |
|
550 | - $this->_error_msg = array(); |
|
551 | - $valid = true; |
|
552 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
553 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
554 | - |
|
555 | - //set the verified flag so we know everything has been validated. |
|
556 | - $this->_verified = $valid; |
|
557 | - |
|
558 | - return $valid; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
564 | - * EE_Messages_Addressee objects. |
|
565 | - * |
|
566 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
567 | - * @return bool |
|
568 | - */ |
|
569 | - protected function _valid_addressees($addressees) |
|
570 | - { |
|
571 | - if (! $addressees || ! is_array($addressees)) { |
|
572 | - return false; |
|
573 | - } |
|
574 | - |
|
575 | - foreach ($addressees as $addressee_array) { |
|
576 | - foreach ($addressee_array as $addressee) { |
|
577 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
578 | - return false; |
|
579 | - } |
|
580 | - } |
|
581 | - } |
|
582 | - return true; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
588 | - * queue. This process sets error messages if something is wrong. |
|
589 | - * |
|
590 | - * @return bool true is if there are no errors. false is if there is. |
|
591 | - */ |
|
592 | - protected function _validate_messenger_and_message_type() |
|
593 | - { |
|
594 | - |
|
595 | - //first are there any existing error messages? If so then return. |
|
596 | - if ($this->_error_msg) { |
|
597 | - return false; |
|
598 | - } |
|
599 | - /** @type EE_Message $message */ |
|
600 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
601 | - try { |
|
602 | - $this->_current_messenger = $message->valid_messenger(true) ? $message->messenger_object() : null; |
|
603 | - } catch (Exception $e) { |
|
604 | - $this->_error_msg[] = $e->getMessage(); |
|
605 | - } |
|
606 | - try { |
|
607 | - $this->_current_message_type = $message->valid_message_type(true) ? $message->message_type_object() : null; |
|
608 | - } catch (Exception $e) { |
|
609 | - $this->_error_msg[] = $e->getMessage(); |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Check if there is any generation data, but only if this is not for a preview. |
|
614 | - */ |
|
615 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
616 | - && ( |
|
617 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
618 | - && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data') |
|
619 | - ) { |
|
620 | - $this->_error_msg[] = __('There is no generation data for this message. Unable to generate.'); |
|
621 | - } |
|
622 | - |
|
623 | - return empty($this->_error_msg); |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
629 | - * data handler. |
|
630 | - * |
|
631 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
632 | - */ |
|
633 | - protected function _validate_and_setup_data() |
|
634 | - { |
|
635 | - |
|
636 | - //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
637 | - //be used anyways. |
|
638 | - if ($this->_error_msg) { |
|
639 | - return false; |
|
640 | - } |
|
641 | - |
|
642 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
643 | - |
|
644 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
645 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
646 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
647 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
648 | - |
|
649 | - //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
650 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
651 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
652 | - } |
|
653 | - |
|
654 | - //First get the class name for the data handler (and also verifies it exists. |
|
655 | - if (! class_exists($data_handler_class_name)) { |
|
656 | - $this->_error_msg[] = sprintf( |
|
657 | - __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
658 | - 'event_espresso'), |
|
659 | - $data_handler_class_name |
|
660 | - ); |
|
661 | - return false; |
|
662 | - } |
|
663 | - |
|
664 | - //convert generation_data for data_handler_instantiation. |
|
665 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
666 | - |
|
667 | - //note, this may set error messages as well. |
|
668 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
669 | - |
|
670 | - return empty($this->_error_msg); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
676 | - * adds it to the _data repository. |
|
677 | - * |
|
678 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
679 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
680 | - * instantiated. |
|
681 | - * @return void. |
|
682 | - */ |
|
683 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
684 | - { |
|
685 | - //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
686 | - //is already a ready data handler in the repository. |
|
687 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, |
|
688 | - $generating_data)); |
|
689 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
690 | - //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
691 | - try { |
|
692 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
693 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
694 | - } catch (EE_Error $e) { |
|
695 | - $this->_error_msg[] = $e->get_error(); |
|
696 | - } |
|
697 | - } |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
703 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
704 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
705 | - * and that preps the data for later instantiation when generating. |
|
706 | - * |
|
707 | - * @param EE_Message_To_Generate $message_to_generate |
|
708 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
709 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
710 | - */ |
|
711 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
712 | - { |
|
713 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
714 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
715 | - if (! $message_to_generate->valid()) { |
|
716 | - return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
717 | - } |
|
718 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
724 | - * |
|
725 | - * @param EE_Message_To_Generate $message_to_generate |
|
726 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
727 | - */ |
|
728 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
729 | - { |
|
730 | - //prep data |
|
731 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
732 | - |
|
733 | - $message = $message_to_generate->get_EE_Message(); |
|
734 | - |
|
735 | - //is there a GRP_ID in the request? |
|
736 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
737 | - $message->set_GRP_ID($GRP_ID); |
|
738 | - } |
|
739 | - |
|
740 | - if ($data === false) { |
|
741 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
742 | - $message->set_error_message(__('Unable to prepare data for persistence to the database.', |
|
743 | - 'event_espresso')); |
|
744 | - } else { |
|
745 | - //make sure that the data handler is cached on the message as well |
|
746 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
747 | - } |
|
748 | - |
|
749 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
750 | - } |
|
264 | + 'event_espresso'); |
|
265 | + return false; |
|
266 | + } |
|
267 | + |
|
268 | + $message_template_group = $this->_get_message_template_group(); |
|
269 | + |
|
270 | + //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
271 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
272 | + $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
273 | + 'event_espresso'); |
|
274 | + return false; |
|
275 | + } |
|
276 | + |
|
277 | + //get formatted templates for using to parse and setup EE_Message objects. |
|
278 | + $templates = $this->_get_templates($message_template_group); |
|
279 | + |
|
280 | + |
|
281 | + //setup new EE_Message objects (and add to _ready_queue) |
|
282 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Retrieves the message template group being used for generating messages. |
|
288 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
289 | + * |
|
290 | + * @return EE_Message_Template_Group | null |
|
291 | + */ |
|
292 | + protected function _get_message_template_group() |
|
293 | + { |
|
294 | + //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
295 | + //so let's use that. |
|
296 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
297 | + |
|
298 | + if ($GRP_ID) { |
|
299 | + //attempt to retrieve from repo first |
|
300 | + $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
|
301 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
302 | + return $GRP; //got it! |
|
303 | + } |
|
304 | + |
|
305 | + //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
306 | + //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
307 | + $GRP = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
308 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
309 | + $this->_template_collection->add($GRP); |
|
310 | + return $GRP; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + //whatcha still doing here? Oh, no Message Template Group yet I see. Okay let's see if we can get it for you. |
|
315 | + |
|
316 | + //defaults |
|
317 | + $EVT_ID = 0; |
|
318 | + |
|
319 | + $template_qa = array( |
|
320 | + 'MTP_is_active' => true, |
|
321 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
322 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
323 | + ); |
|
324 | + |
|
325 | + //in vanilla EE we're assuming there's only one event. |
|
326 | + //However, if there are multiple events then we'll just use the default templates instead of different |
|
327 | + // templates per event (which could create problems). |
|
328 | + if (count($this->_current_data_handler->events) === 1) { |
|
329 | + foreach ($this->_current_data_handler->events as $event) { |
|
330 | + $EVT_ID = $event['ID']; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + //before going any further, let's see if its in the queue |
|
335 | + $GRP = $this->_template_collection->get_by_key($this->_template_collection->get_key($this->_current_messenger->name, |
|
336 | + $this->_current_message_type->name, $EVT_ID)); |
|
337 | + |
|
338 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
339 | + return $GRP; |
|
340 | + } |
|
341 | + |
|
342 | + //nope still no GRP? |
|
343 | + //first we get the global template in case it has an override set. |
|
344 | + $global_template_qa = array_merge(array('MTP_is_global' => true), $template_qa); |
|
345 | + $global_GRP = EEM_Message_Template_Group::instance()->get_one(array($global_template_qa)); |
|
346 | + |
|
347 | + //if this is an override, then we just return it. |
|
348 | + if ($global_GRP instanceof EE_Message_Template_Group && $global_GRP->get('MTP_is_override')) { |
|
349 | + $this->_template_collection->add($global_GRP, $EVT_ID); |
|
350 | + return $global_GRP; |
|
351 | + } |
|
352 | + |
|
353 | + //STILL here? Okay that means we want to see if there is event specific group and if there is we return it, |
|
354 | + //otherwise we return the global group we retrieved. |
|
355 | + if ($EVT_ID) { |
|
356 | + $template_qa['Event.EVT_ID'] = $EVT_ID; |
|
357 | + } |
|
358 | + |
|
359 | + $GRP = EEM_Message_Template_Group::instance()->get_one(array($template_qa)); |
|
360 | + $GRP = $GRP instanceof EE_Message_Template_Group ? $GRP : $global_GRP; |
|
361 | + |
|
362 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
363 | + $this->_template_collection->add($GRP, $EVT_ID); |
|
364 | + return $GRP; |
|
365 | + } |
|
366 | + |
|
367 | + //nothing, nada, there ain't no group from what you fed the machine. (Getting here is a very hard thing to do). |
|
368 | + return null; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Retrieves formatted array of template information for each context specific to the given |
|
374 | + * EE_Message_Template_Group |
|
375 | + * |
|
376 | + * @param EE_Message_Template_Group |
|
377 | + * @return array The returned array is in this structure: |
|
378 | + * array( |
|
379 | + * 'field_name' => array( |
|
380 | + * 'context' => 'content' |
|
381 | + * ) |
|
382 | + * ) |
|
383 | + */ |
|
384 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
385 | + { |
|
386 | + $templates = array(); |
|
387 | + $context_templates = $message_template_group->context_templates(); |
|
388 | + foreach ($context_templates as $context => $template_fields) { |
|
389 | + foreach ($template_fields as $template_field => $template_obj) { |
|
390 | + if (! $template_obj instanceof EE_Message_Template) { |
|
391 | + continue; |
|
392 | + } |
|
393 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
394 | + } |
|
395 | + } |
|
396 | + return $templates; |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
402 | + * |
|
403 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
404 | + * context. |
|
405 | + * @param array $templates formatted array of templates used for parsing data. |
|
406 | + * @param EE_Message_Template_Group $message_template_group |
|
407 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
408 | + * method will attempt to generate ALL EE_Message objects and add to the _ready_queue. Successfully |
|
409 | + * generated messages get added to the queue with EEM_Message::status_idle, unsuccessfully generated |
|
410 | + * messages will get added to the queue as EEM_Message::status_failed. Very rarely should "false" |
|
411 | + * be returned from this method. |
|
412 | + */ |
|
413 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
414 | + { |
|
415 | + |
|
416 | + //if templates are empty then get out because we can't generate anything. |
|
417 | + if (! $templates) { |
|
418 | + $this->_error_msg[] = __('Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
419 | + 'event_espresso'); |
|
420 | + return false; |
|
421 | + } |
|
422 | + |
|
423 | + //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
424 | + //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
425 | + $generated_count = 0; |
|
426 | + foreach ($addressees as $context => $recipients) { |
|
427 | + foreach ($recipients as $recipient) { |
|
428 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
429 | + if ($message instanceof EE_Message) { |
|
430 | + $this->_ready_queue->add( |
|
431 | + $message, |
|
432 | + array(), |
|
433 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
434 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
435 | + ); |
|
436 | + $generated_count++; |
|
437 | + } |
|
438 | + |
|
439 | + //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
440 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
441 | + break 2; |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + //if there are no generated messages then something else fatal went wrong. |
|
447 | + return $generated_count > 0; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param string $context The context for the generated message. |
|
453 | + * @param EE_Messages_Addressee $recipient |
|
454 | + * @param array $templates formatted array of templates used for parsing data. |
|
455 | + * @param EE_Message_Template_Group $message_template_group |
|
456 | + * @return EE_Message | bool (false is used when no EE_Message is generated) |
|
457 | + */ |
|
458 | + protected function _setup_message_object( |
|
459 | + $context, |
|
460 | + EE_Messages_Addressee $recipient, |
|
461 | + $templates, |
|
462 | + EE_Message_Template_Group $message_template_group |
|
463 | + ) { |
|
464 | + //stuff we already know |
|
465 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
466 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
467 | + ? $this->_current_data_handler->txn->ID() |
|
468 | + : $transaction_id; |
|
469 | + $message_fields = array( |
|
470 | + 'GRP_ID' => $message_template_group->ID(), |
|
471 | + 'TXN_ID' => $transaction_id, |
|
472 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
473 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
474 | + 'MSG_context' => $context, |
|
475 | + ); |
|
476 | + |
|
477 | + //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab the |
|
478 | + //info from the att_obj found in the EE_Messages_Addressee object. |
|
479 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
480 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
481 | + ? $recipient->att_obj->ID() |
|
482 | + : 0; |
|
483 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
484 | + } else { |
|
485 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
486 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
487 | + } |
|
488 | + $message = EE_Message_Factory::create($message_fields); |
|
489 | + |
|
490 | + //grab valid shortcodes for shortcode parser |
|
491 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
492 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
493 | + |
|
494 | + //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
495 | + //context is turned off) EXCEPT if we're previewing |
|
496 | + if (empty($templates['to'][$context]) |
|
497 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
498 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
499 | + ) { |
|
500 | + //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" field. |
|
501 | + return false; |
|
502 | + } |
|
503 | + $error_msg = array(); |
|
504 | + foreach ($templates as $field => $field_context) { |
|
505 | + $error_msg = array(); |
|
506 | + //let's setup the valid shortcodes for the incoming context. |
|
507 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
508 | + //merge in valid shortcodes for the field. |
|
509 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
510 | + if (isset($templates[$field][$context])) { |
|
511 | + //prefix field. |
|
512 | + $column_name = 'MSG_' . $field; |
|
513 | + try { |
|
514 | + $content = $this->_shortcode_parser->parse_message_template( |
|
515 | + $templates[$field][$context], |
|
516 | + $recipient, |
|
517 | + $shortcodes, |
|
518 | + $this->_current_message_type, |
|
519 | + $this->_current_messenger, |
|
520 | + $message); |
|
521 | + $message->set_field_or_extra_meta($column_name, $content); |
|
522 | + } catch (EE_Error $e) { |
|
523 | + $error_msg[] = sprintf(__('There was a problem generating the content for the field %s: %s', |
|
524 | + 'event_espresso'), $field, $e->getMessage()); |
|
525 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
526 | + } |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
531 | + $error_msg = __('There were problems generating this message:', 'event_espresso') . "\n" . implode("\n", |
|
532 | + $error_msg); |
|
533 | + $message->set_error_message($error_msg); |
|
534 | + } else { |
|
535 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
536 | + } |
|
537 | + return $message; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
543 | + * error message if either is missing. |
|
544 | + * |
|
545 | + * @return bool true means there were no errors, false means there were errors. |
|
546 | + */ |
|
547 | + protected function _verify() |
|
548 | + { |
|
549 | + //reset error message to an empty array. |
|
550 | + $this->_error_msg = array(); |
|
551 | + $valid = true; |
|
552 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
553 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
554 | + |
|
555 | + //set the verified flag so we know everything has been validated. |
|
556 | + $this->_verified = $valid; |
|
557 | + |
|
558 | + return $valid; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
564 | + * EE_Messages_Addressee objects. |
|
565 | + * |
|
566 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
567 | + * @return bool |
|
568 | + */ |
|
569 | + protected function _valid_addressees($addressees) |
|
570 | + { |
|
571 | + if (! $addressees || ! is_array($addressees)) { |
|
572 | + return false; |
|
573 | + } |
|
574 | + |
|
575 | + foreach ($addressees as $addressee_array) { |
|
576 | + foreach ($addressee_array as $addressee) { |
|
577 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
578 | + return false; |
|
579 | + } |
|
580 | + } |
|
581 | + } |
|
582 | + return true; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
588 | + * queue. This process sets error messages if something is wrong. |
|
589 | + * |
|
590 | + * @return bool true is if there are no errors. false is if there is. |
|
591 | + */ |
|
592 | + protected function _validate_messenger_and_message_type() |
|
593 | + { |
|
594 | + |
|
595 | + //first are there any existing error messages? If so then return. |
|
596 | + if ($this->_error_msg) { |
|
597 | + return false; |
|
598 | + } |
|
599 | + /** @type EE_Message $message */ |
|
600 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
601 | + try { |
|
602 | + $this->_current_messenger = $message->valid_messenger(true) ? $message->messenger_object() : null; |
|
603 | + } catch (Exception $e) { |
|
604 | + $this->_error_msg[] = $e->getMessage(); |
|
605 | + } |
|
606 | + try { |
|
607 | + $this->_current_message_type = $message->valid_message_type(true) ? $message->message_type_object() : null; |
|
608 | + } catch (Exception $e) { |
|
609 | + $this->_error_msg[] = $e->getMessage(); |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Check if there is any generation data, but only if this is not for a preview. |
|
614 | + */ |
|
615 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
616 | + && ( |
|
617 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
618 | + && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data') |
|
619 | + ) { |
|
620 | + $this->_error_msg[] = __('There is no generation data for this message. Unable to generate.'); |
|
621 | + } |
|
622 | + |
|
623 | + return empty($this->_error_msg); |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
629 | + * data handler. |
|
630 | + * |
|
631 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
632 | + */ |
|
633 | + protected function _validate_and_setup_data() |
|
634 | + { |
|
635 | + |
|
636 | + //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
637 | + //be used anyways. |
|
638 | + if ($this->_error_msg) { |
|
639 | + return false; |
|
640 | + } |
|
641 | + |
|
642 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
643 | + |
|
644 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
645 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
646 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
647 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
648 | + |
|
649 | + //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
650 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
651 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
652 | + } |
|
653 | + |
|
654 | + //First get the class name for the data handler (and also verifies it exists. |
|
655 | + if (! class_exists($data_handler_class_name)) { |
|
656 | + $this->_error_msg[] = sprintf( |
|
657 | + __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
658 | + 'event_espresso'), |
|
659 | + $data_handler_class_name |
|
660 | + ); |
|
661 | + return false; |
|
662 | + } |
|
663 | + |
|
664 | + //convert generation_data for data_handler_instantiation. |
|
665 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
666 | + |
|
667 | + //note, this may set error messages as well. |
|
668 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
669 | + |
|
670 | + return empty($this->_error_msg); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
676 | + * adds it to the _data repository. |
|
677 | + * |
|
678 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
679 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
680 | + * instantiated. |
|
681 | + * @return void. |
|
682 | + */ |
|
683 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
684 | + { |
|
685 | + //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
686 | + //is already a ready data handler in the repository. |
|
687 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, |
|
688 | + $generating_data)); |
|
689 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
690 | + //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
691 | + try { |
|
692 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
693 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
694 | + } catch (EE_Error $e) { |
|
695 | + $this->_error_msg[] = $e->get_error(); |
|
696 | + } |
|
697 | + } |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
703 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
704 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
705 | + * and that preps the data for later instantiation when generating. |
|
706 | + * |
|
707 | + * @param EE_Message_To_Generate $message_to_generate |
|
708 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
709 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
710 | + */ |
|
711 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
712 | + { |
|
713 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
714 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
715 | + if (! $message_to_generate->valid()) { |
|
716 | + return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
717 | + } |
|
718 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
724 | + * |
|
725 | + * @param EE_Message_To_Generate $message_to_generate |
|
726 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
727 | + */ |
|
728 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
729 | + { |
|
730 | + //prep data |
|
731 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
732 | + |
|
733 | + $message = $message_to_generate->get_EE_Message(); |
|
734 | + |
|
735 | + //is there a GRP_ID in the request? |
|
736 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
737 | + $message->set_GRP_ID($GRP_ID); |
|
738 | + } |
|
739 | + |
|
740 | + if ($data === false) { |
|
741 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
742 | + $message->set_error_message(__('Unable to prepare data for persistence to the database.', |
|
743 | + 'event_espresso')); |
|
744 | + } else { |
|
745 | + //make sure that the data handler is cached on the message as well |
|
746 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
747 | + } |
|
748 | + |
|
749 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
750 | + } |
|
751 | 751 | |
752 | 752 | |
753 | 753 | } //end EE_Messages_Generator |
754 | 754 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | protected function _generate() |
238 | 238 | { |
239 | 239 | //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
240 | - if (! $this->_verified) { |
|
240 | + if ( ! $this->_verified) { |
|
241 | 241 | return false; //get out because we don't have a valid setup to work with. |
242 | 242 | } |
243 | 243 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | |
256 | 256 | //if no addressees then get out because there is nothing to generation (possible bad data). |
257 | - if (! $this->_valid_addressees($addressees)) { |
|
257 | + if ( ! $this->_valid_addressees($addressees)) { |
|
258 | 258 | do_action('AHEE__EE_Messages_Generator___generate__invalid_addressees', |
259 | 259 | $this->_generation_queue->get_message_repository()->current(), $addressees, $this->_current_messenger, |
260 | 260 | $this->_current_message_type, $this->_current_data_handler); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $message_template_group = $this->_get_message_template_group(); |
269 | 269 | |
270 | 270 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
271 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
271 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
272 | 272 | $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
273 | 273 | 'event_espresso'); |
274 | 274 | return false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | //attempt to retrieve from repo first |
300 | 300 | $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
301 | 301 | if ($GRP instanceof EE_Message_Template_Group) { |
302 | - return $GRP; //got it! |
|
302 | + return $GRP; //got it! |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $context_templates = $message_template_group->context_templates(); |
388 | 388 | foreach ($context_templates as $context => $template_fields) { |
389 | 389 | foreach ($template_fields as $template_field => $template_obj) { |
390 | - if (! $template_obj instanceof EE_Message_Template) { |
|
390 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
391 | 391 | continue; |
392 | 392 | } |
393 | 393 | $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | { |
415 | 415 | |
416 | 416 | //if templates are empty then get out because we can't generate anything. |
417 | - if (! $templates) { |
|
417 | + if ( ! $templates) { |
|
418 | 418 | $this->_error_msg[] = __('Unable to assemble messages because there are no templates retrieved for generating the messages with', |
419 | 419 | 'event_espresso'); |
420 | 420 | return false; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
510 | 510 | if (isset($templates[$field][$context])) { |
511 | 511 | //prefix field. |
512 | - $column_name = 'MSG_' . $field; |
|
512 | + $column_name = 'MSG_'.$field; |
|
513 | 513 | try { |
514 | 514 | $content = $this->_shortcode_parser->parse_message_template( |
515 | 515 | $templates[$field][$context], |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | } |
529 | 529 | |
530 | 530 | if ($message->STS_ID() === EEM_Message::status_failed) { |
531 | - $error_msg = __('There were problems generating this message:', 'event_espresso') . "\n" . implode("\n", |
|
531 | + $error_msg = __('There were problems generating this message:', 'event_espresso')."\n".implode("\n", |
|
532 | 532 | $error_msg); |
533 | 533 | $message->set_error_message($error_msg); |
534 | 534 | } else { |
@@ -568,13 +568,13 @@ discard block |
||
568 | 568 | */ |
569 | 569 | protected function _valid_addressees($addressees) |
570 | 570 | { |
571 | - if (! $addressees || ! is_array($addressees)) { |
|
571 | + if ( ! $addressees || ! is_array($addressees)) { |
|
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | 575 | foreach ($addressees as $addressee_array) { |
576 | 576 | foreach ($addressee_array as $addressee) { |
577 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
577 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
578 | 578 | return false; |
579 | 579 | } |
580 | 580 | } |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | /** |
613 | 613 | * Check if there is any generation data, but only if this is not for a preview. |
614 | 614 | */ |
615 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
615 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
616 | 616 | && ( |
617 | 617 | ! $this->_generation_queue->get_message_repository()->is_preview() |
618 | 618 | && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data') |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
645 | 645 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
646 | 646 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
647 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
647 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
648 | 648 | |
649 | 649 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
650 | 650 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | } |
653 | 653 | |
654 | 654 | //First get the class name for the data handler (and also verifies it exists. |
655 | - if (! class_exists($data_handler_class_name)) { |
|
655 | + if ( ! class_exists($data_handler_class_name)) { |
|
656 | 656 | $this->_error_msg[] = sprintf( |
657 | 657 | __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
658 | 658 | 'event_espresso'), |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | //is already a ready data handler in the repository. |
687 | 687 | $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, |
688 | 688 | $generating_data)); |
689 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
689 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
690 | 690 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
691 | 691 | try { |
692 | 692 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | { |
713 | 713 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
714 | 714 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
715 | - if (! $message_to_generate->valid()) { |
|
715 | + if ( ! $message_to_generate->valid()) { |
|
716 | 716 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
717 | 717 | } |
718 | 718 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -47,7 +47,7 @@ |
||
47 | 47 | /** |
48 | 48 | * This retrieves any EE_Message_Template_Group in the repo by its ID. |
49 | 49 | * |
50 | - * @param $GRP_ID |
|
50 | + * @param integer $GRP_ID |
|
51 | 51 | * @return EE_Message_Template_Group | null |
52 | 52 | */ |
53 | 53 | public function get_by_ID($GRP_ID) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -16,89 +16,89 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->interface = 'EE_Message_Template_Group'; |
|
22 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->interface = 'EE_Message_Template_Group'; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Adds the Message Template Group object to the repository. |
|
27 | - * |
|
28 | - * @param $message_template_group |
|
29 | - * @param int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
30 | - * indexing the template by key. |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function add($message_template_group, $EVT_ID = null) |
|
34 | - { |
|
35 | - if ($message_template_group instanceof $this->interface) { |
|
36 | - $data['key'] = $this->get_key( |
|
37 | - $message_template_group->messenger(), |
|
38 | - $message_template_group->message_type(), |
|
39 | - $EVT_ID |
|
40 | - ); |
|
41 | - return parent::add($message_template_group, $data); |
|
42 | - } |
|
43 | - return false; |
|
44 | - } |
|
25 | + /** |
|
26 | + * Adds the Message Template Group object to the repository. |
|
27 | + * |
|
28 | + * @param $message_template_group |
|
29 | + * @param int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
30 | + * indexing the template by key. |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function add($message_template_group, $EVT_ID = null) |
|
34 | + { |
|
35 | + if ($message_template_group instanceof $this->interface) { |
|
36 | + $data['key'] = $this->get_key( |
|
37 | + $message_template_group->messenger(), |
|
38 | + $message_template_group->message_type(), |
|
39 | + $EVT_ID |
|
40 | + ); |
|
41 | + return parent::add($message_template_group, $data); |
|
42 | + } |
|
43 | + return false; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
49 | - * |
|
50 | - * @param $GRP_ID |
|
51 | - * @return EE_Message_Template_Group | null |
|
52 | - */ |
|
53 | - public function get_by_ID($GRP_ID) |
|
54 | - { |
|
55 | - $this->rewind(); |
|
56 | - while ($this->valid()) { |
|
57 | - if ($this->current()->ID() === $GRP_ID) { |
|
58 | - $grp = $this->current(); |
|
59 | - $this->rewind(); |
|
60 | - return $grp; |
|
61 | - } |
|
62 | - $this->next(); |
|
63 | - } |
|
64 | - return null; |
|
65 | - } |
|
47 | + /** |
|
48 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
49 | + * |
|
50 | + * @param $GRP_ID |
|
51 | + * @return EE_Message_Template_Group | null |
|
52 | + */ |
|
53 | + public function get_by_ID($GRP_ID) |
|
54 | + { |
|
55 | + $this->rewind(); |
|
56 | + while ($this->valid()) { |
|
57 | + if ($this->current()->ID() === $GRP_ID) { |
|
58 | + $grp = $this->current(); |
|
59 | + $this->rewind(); |
|
60 | + return $grp; |
|
61 | + } |
|
62 | + $this->next(); |
|
63 | + } |
|
64 | + return null; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Generates a hash used to identify a given Message Template Group. |
|
70 | - * |
|
71 | - * @param string $messenger The EE_messenger->name |
|
72 | - * @param string $message_type The EE_message_type->name |
|
73 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
77 | - { |
|
78 | - return md5($messenger . $message_type . $EVT_ID); |
|
79 | - } |
|
68 | + /** |
|
69 | + * Generates a hash used to identify a given Message Template Group. |
|
70 | + * |
|
71 | + * @param string $messenger The EE_messenger->name |
|
72 | + * @param string $message_type The EE_message_type->name |
|
73 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
77 | + { |
|
78 | + return md5($messenger . $message_type . $EVT_ID); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
84 | - * the given string. |
|
85 | - * |
|
86 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
87 | - * @return null|EE_Message_Template_Group |
|
88 | - */ |
|
89 | - public function get_by_key($key) |
|
90 | - { |
|
91 | - $this->rewind(); |
|
92 | - while ($this->valid()) { |
|
93 | - $data = $this->getInfo(); |
|
94 | - if (isset($data['key']) && $data['key'] === $key) { |
|
95 | - $handler = $this->current(); |
|
96 | - $this->rewind(); |
|
97 | - return $handler; |
|
98 | - } |
|
99 | - $this->next(); |
|
100 | - } |
|
101 | - return null; |
|
102 | - } |
|
82 | + /** |
|
83 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
84 | + * the given string. |
|
85 | + * |
|
86 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
87 | + * @return null|EE_Message_Template_Group |
|
88 | + */ |
|
89 | + public function get_by_key($key) |
|
90 | + { |
|
91 | + $this->rewind(); |
|
92 | + while ($this->valid()) { |
|
93 | + $data = $this->getInfo(); |
|
94 | + if (isset($data['key']) && $data['key'] === $key) { |
|
95 | + $handler = $this->current(); |
|
96 | + $this->rewind(); |
|
97 | + return $handler; |
|
98 | + } |
|
99 | + $this->next(); |
|
100 | + } |
|
101 | + return null; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } //end EE_Message_Template_Group_Collection |
105 | 105 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function get_key($messenger, $message_type, $EVT_ID = 0) |
77 | 77 | { |
78 | - return md5($messenger . $message_type . $EVT_ID); |
|
78 | + return md5($messenger.$message_type.$EVT_ID); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 |
@@ -21,63 +21,63 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * the actual shortcode tag that gets registered with WordPress |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function getTag() |
|
30 | - { |
|
31 | - return 'ESPRESSO_TICKET_SELECTOR'; |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * the time in seconds to cache the results of the processShortcode() method |
|
38 | - * 0 means the processShortcode() results will NOT be cached at all |
|
39 | - * |
|
40 | - * @return int |
|
41 | - */ |
|
42 | - public function cacheExpiration() |
|
43 | - { |
|
44 | - return 0; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
50 | - * this may be required for shortcodes that utilize a corresponding module, |
|
51 | - * and need to enqueue assets for that module |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function initializeShortcode() |
|
56 | - { |
|
57 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
58 | - $this->shortcodeHasBeenInitialized(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * callback that runs when the shortcode is encountered in post content. |
|
65 | - * IMPORTANT !!! |
|
66 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
67 | - * |
|
68 | - * @param array $attributes |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function processShortcode($attributes = array()) |
|
72 | - { |
|
73 | - extract($attributes, EXTR_OVERWRITE); |
|
74 | - $event_id = isset($event_id) ? $event_id : 0; |
|
75 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
76 | - ob_start(); |
|
77 | - do_action('AHEE_event_details_before_post', $event_id); |
|
78 | - espresso_ticket_selector($event); |
|
79 | - do_action('AHEE_event_details_after_post'); |
|
80 | - return ob_get_clean(); } |
|
24 | + /** |
|
25 | + * the actual shortcode tag that gets registered with WordPress |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function getTag() |
|
30 | + { |
|
31 | + return 'ESPRESSO_TICKET_SELECTOR'; |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * the time in seconds to cache the results of the processShortcode() method |
|
38 | + * 0 means the processShortcode() results will NOT be cached at all |
|
39 | + * |
|
40 | + * @return int |
|
41 | + */ |
|
42 | + public function cacheExpiration() |
|
43 | + { |
|
44 | + return 0; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
50 | + * this may be required for shortcodes that utilize a corresponding module, |
|
51 | + * and need to enqueue assets for that module |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function initializeShortcode() |
|
56 | + { |
|
57 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
58 | + $this->shortcodeHasBeenInitialized(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * callback that runs when the shortcode is encountered in post content. |
|
65 | + * IMPORTANT !!! |
|
66 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
67 | + * |
|
68 | + * @param array $attributes |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function processShortcode($attributes = array()) |
|
72 | + { |
|
73 | + extract($attributes, EXTR_OVERWRITE); |
|
74 | + $event_id = isset($event_id) ? $event_id : 0; |
|
75 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
76 | + ob_start(); |
|
77 | + do_action('AHEE_event_details_before_post', $event_id); |
|
78 | + espresso_ticket_selector($event); |
|
79 | + do_action('AHEE_event_details_after_post'); |
|
80 | + return ob_get_clean(); } |
|
81 | 81 | } |
82 | 82 | // End of file EspressoTicketSelector.php |
83 | 83 | // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTicketSelector.php |
84 | 84 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\widgets\EspressoWidget; |
4 | 4 | |
5 | 5 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -26,379 +26,379 @@ discard block |
||
26 | 26 | final class EE_Front_Controller |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_template_path |
|
31 | - */ |
|
32 | - private $_template_path; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $_template |
|
36 | - */ |
|
37 | - private $_template; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_Registry $Registry |
|
41 | - */ |
|
42 | - protected $Registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @type EE_Request_Handler $Request_Handler |
|
46 | - */ |
|
47 | - protected $Request_Handler; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | - */ |
|
52 | - protected $Module_Request_Router; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * class constructor |
|
57 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @param \EE_Registry $Registry |
|
61 | - * @param \EE_Request_Handler $Request_Handler |
|
62 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - EE_Registry $Registry, |
|
66 | - EE_Request_Handler $Request_Handler, |
|
67 | - EE_Module_Request_Router $Module_Request_Router |
|
68 | - ) { |
|
69 | - $this->Registry = $Registry; |
|
70 | - $this->Request_Handler = $Request_Handler; |
|
71 | - $this->Module_Request_Router = $Module_Request_Router; |
|
72 | - // determine how to integrate WP_Query with the EE models |
|
73 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | - // load other resources and begin to actually run shortcodes and modules |
|
75 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | - // analyse the incoming WP request |
|
77 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | - // process request with module factory |
|
79 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | - // before headers sent |
|
81 | - add_action('wp', array($this, 'wp'), 5); |
|
82 | - // after headers sent but before any markup is output, |
|
83 | - // primarily used to process any content shortcodes |
|
84 | - add_action('wp_head', array($this, 'wpHead'), 0); |
|
85 | - // header |
|
86 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | - // display errors |
|
90 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | - // the content |
|
92 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | - //exclude our private cpt comments |
|
94 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | - // action hook EE |
|
98 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | - // for checking that browser cookies are enabled |
|
100 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return EE_Request_Handler |
|
108 | - */ |
|
109 | - public function Request_Handler() |
|
110 | - { |
|
111 | - return $this->Request_Handler; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return EE_Module_Request_Router |
|
117 | - */ |
|
118 | - public function Module_Request_Router() |
|
119 | - { |
|
120 | - return $this->Module_Request_Router; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return LegacyShortcodesManager |
|
127 | - */ |
|
128 | - public function getLegacyShortcodesManager() |
|
129 | - { |
|
130 | - return EE_Config::getLegacyShortcodesManager(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * filter_wp_comments |
|
143 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
144 | - * widgets/queries done on frontend |
|
145 | - * |
|
146 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
147 | - * @return array array of comment clauses with modifications. |
|
148 | - */ |
|
149 | - public function filter_wp_comments($clauses) |
|
150 | - { |
|
151 | - global $wpdb; |
|
152 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
153 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
154 | - foreach ($cpts as $cpt => $details) { |
|
155 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
156 | - } |
|
157 | - } |
|
158 | - return $clauses; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * employ_CPT_Strategy |
|
164 | - * |
|
165 | - * @access public |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function employ_CPT_Strategy() |
|
169 | - { |
|
170 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
171 | - $this->Registry->load_core('CPT_Strategy'); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
178 | - * |
|
179 | - * @param string $url incoming url |
|
180 | - * @return string final assembled url |
|
181 | - */ |
|
182 | - public function maybe_force_admin_ajax_ssl($url) |
|
183 | - { |
|
184 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
185 | - $url = str_replace('http://', 'https://', $url); |
|
186 | - } |
|
187 | - return $url; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
200 | - * default priority init phases have run |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function wp_loaded() |
|
206 | - { |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
214 | - /** |
|
215 | - * _get_request |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @param WP $WP |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public function get_request(WP $WP) |
|
222 | - { |
|
223 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
224 | - $this->Request_Handler->parse_request($WP); |
|
225 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param WP_Query $WP_Query |
|
235 | - * @return void |
|
236 | - */ |
|
237 | - public function pre_get_posts($WP_Query) |
|
238 | - { |
|
239 | - // only load Module_Request_Router if this is the main query |
|
240 | - if ( |
|
241 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
242 | - && $WP_Query->is_main_query() |
|
243 | - ) { |
|
244 | - // cycle thru module routes |
|
245 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
246 | - // determine module and method for route |
|
247 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
248 | - if ($module instanceof EED_Module) { |
|
249 | - // get registered view for route |
|
250 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
251 | - // grab module name |
|
252 | - $module_name = $module->module_name(); |
|
253 | - // map the module to the module objects |
|
254 | - $this->Registry->modules->{$module_name} = $module; |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /*********************************************** WP HOOK ***********************************************/ |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * wp - basically last chance to do stuff before headers sent |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function wp() |
|
274 | - { |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
280 | - |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * callback for the "wp_head" hook point |
|
285 | - * checks sidebars for EE widgets |
|
286 | - * loads resources and assets accordingly |
|
287 | - * |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function wpHead() |
|
291 | - { |
|
292 | - global $wp_query; |
|
293 | - if (empty($wp_query->posts)){ |
|
294 | - return; |
|
295 | - } |
|
296 | - // if we already know this is an espresso page, then load assets |
|
297 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
298 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
299 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
300 | - if ( $load_assets){ |
|
301 | - wp_enqueue_style('espresso_default'); |
|
302 | - wp_enqueue_style('espresso_custom_css'); |
|
303 | - wp_enqueue_script('espresso_core'); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * builds list of active widgets then scans active sidebars looking for them |
|
311 | - * returns true is an EE widget is found in an active sidebar |
|
312 | - * Please Note: this does NOT mean that the sidebar or widget |
|
313 | - * is actually in use in a given template, as that is unfortunately not known |
|
314 | - * until a sidebar and it's widgets are actually loaded |
|
315 | - * |
|
316 | - * @return boolean |
|
317 | - */ |
|
318 | - private function espresso_widgets_in_active_sidebars() |
|
319 | - { |
|
320 | - $espresso_widgets = array(); |
|
321 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
322 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
323 | - if (is_active_widget(false, false, $id_base)) { |
|
324 | - $espresso_widgets[] = $id_base; |
|
325 | - } |
|
326 | - } |
|
327 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
328 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
329 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
330 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
331 | - foreach ($espresso_widgets as $espresso_widget) { |
|
332 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
333 | - return true; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - } |
|
339 | - return false; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * header_meta_tag |
|
347 | - * |
|
348 | - * @access public |
|
349 | - * @return void |
|
350 | - */ |
|
351 | - public function header_meta_tag() |
|
352 | - { |
|
353 | - print( |
|
354 | - apply_filters( |
|
355 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
357 | - ); |
|
358 | - |
|
359 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
360 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
361 | - //also exclude all critical pages from indexing |
|
362 | - if ( |
|
363 | - ( |
|
364 | - is_tax('espresso_event_type') |
|
365 | - && get_option( 'blog_public' ) !== '0' |
|
366 | - ) |
|
367 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
368 | - ) { |
|
369 | - print( |
|
370 | - apply_filters( |
|
371 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
373 | - ) |
|
374 | - ); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * wp_print_scripts |
|
382 | - * |
|
383 | - * @return void |
|
384 | - */ |
|
385 | - public function wp_print_scripts() |
|
386 | - { |
|
387 | - global $post; |
|
388 | - if ( |
|
389 | - isset($post->EE_Event) |
|
390 | - && $post->EE_Event instanceof EE_Event |
|
391 | - && get_post_type() === 'espresso_events' |
|
392 | - && is_singular() |
|
393 | - ) { |
|
394 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - |
|
401 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
29 | + /** |
|
30 | + * @var string $_template_path |
|
31 | + */ |
|
32 | + private $_template_path; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $_template |
|
36 | + */ |
|
37 | + private $_template; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_Registry $Registry |
|
41 | + */ |
|
42 | + protected $Registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @type EE_Request_Handler $Request_Handler |
|
46 | + */ |
|
47 | + protected $Request_Handler; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | + */ |
|
52 | + protected $Module_Request_Router; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * class constructor |
|
57 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @param \EE_Registry $Registry |
|
61 | + * @param \EE_Request_Handler $Request_Handler |
|
62 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + EE_Registry $Registry, |
|
66 | + EE_Request_Handler $Request_Handler, |
|
67 | + EE_Module_Request_Router $Module_Request_Router |
|
68 | + ) { |
|
69 | + $this->Registry = $Registry; |
|
70 | + $this->Request_Handler = $Request_Handler; |
|
71 | + $this->Module_Request_Router = $Module_Request_Router; |
|
72 | + // determine how to integrate WP_Query with the EE models |
|
73 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | + // load other resources and begin to actually run shortcodes and modules |
|
75 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | + // analyse the incoming WP request |
|
77 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | + // process request with module factory |
|
79 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | + // before headers sent |
|
81 | + add_action('wp', array($this, 'wp'), 5); |
|
82 | + // after headers sent but before any markup is output, |
|
83 | + // primarily used to process any content shortcodes |
|
84 | + add_action('wp_head', array($this, 'wpHead'), 0); |
|
85 | + // header |
|
86 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | + // display errors |
|
90 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | + // the content |
|
92 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | + //exclude our private cpt comments |
|
94 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | + // action hook EE |
|
98 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | + // for checking that browser cookies are enabled |
|
100 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
101 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return EE_Request_Handler |
|
108 | + */ |
|
109 | + public function Request_Handler() |
|
110 | + { |
|
111 | + return $this->Request_Handler; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return EE_Module_Request_Router |
|
117 | + */ |
|
118 | + public function Module_Request_Router() |
|
119 | + { |
|
120 | + return $this->Module_Request_Router; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return LegacyShortcodesManager |
|
127 | + */ |
|
128 | + public function getLegacyShortcodesManager() |
|
129 | + { |
|
130 | + return EE_Config::getLegacyShortcodesManager(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * filter_wp_comments |
|
143 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
144 | + * widgets/queries done on frontend |
|
145 | + * |
|
146 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
147 | + * @return array array of comment clauses with modifications. |
|
148 | + */ |
|
149 | + public function filter_wp_comments($clauses) |
|
150 | + { |
|
151 | + global $wpdb; |
|
152 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
153 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
154 | + foreach ($cpts as $cpt => $details) { |
|
155 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
156 | + } |
|
157 | + } |
|
158 | + return $clauses; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * employ_CPT_Strategy |
|
164 | + * |
|
165 | + * @access public |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function employ_CPT_Strategy() |
|
169 | + { |
|
170 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
171 | + $this->Registry->load_core('CPT_Strategy'); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
178 | + * |
|
179 | + * @param string $url incoming url |
|
180 | + * @return string final assembled url |
|
181 | + */ |
|
182 | + public function maybe_force_admin_ajax_ssl($url) |
|
183 | + { |
|
184 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
185 | + $url = str_replace('http://', 'https://', $url); |
|
186 | + } |
|
187 | + return $url; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
200 | + * default priority init phases have run |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function wp_loaded() |
|
206 | + { |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
214 | + /** |
|
215 | + * _get_request |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @param WP $WP |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public function get_request(WP $WP) |
|
222 | + { |
|
223 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
224 | + $this->Request_Handler->parse_request($WP); |
|
225 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param WP_Query $WP_Query |
|
235 | + * @return void |
|
236 | + */ |
|
237 | + public function pre_get_posts($WP_Query) |
|
238 | + { |
|
239 | + // only load Module_Request_Router if this is the main query |
|
240 | + if ( |
|
241 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
242 | + && $WP_Query->is_main_query() |
|
243 | + ) { |
|
244 | + // cycle thru module routes |
|
245 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
246 | + // determine module and method for route |
|
247 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
248 | + if ($module instanceof EED_Module) { |
|
249 | + // get registered view for route |
|
250 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
251 | + // grab module name |
|
252 | + $module_name = $module->module_name(); |
|
253 | + // map the module to the module objects |
|
254 | + $this->Registry->modules->{$module_name} = $module; |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /*********************************************** WP HOOK ***********************************************/ |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * wp - basically last chance to do stuff before headers sent |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function wp() |
|
274 | + { |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * callback for the "wp_head" hook point |
|
285 | + * checks sidebars for EE widgets |
|
286 | + * loads resources and assets accordingly |
|
287 | + * |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function wpHead() |
|
291 | + { |
|
292 | + global $wp_query; |
|
293 | + if (empty($wp_query->posts)){ |
|
294 | + return; |
|
295 | + } |
|
296 | + // if we already know this is an espresso page, then load assets |
|
297 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
298 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
299 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
300 | + if ( $load_assets){ |
|
301 | + wp_enqueue_style('espresso_default'); |
|
302 | + wp_enqueue_style('espresso_custom_css'); |
|
303 | + wp_enqueue_script('espresso_core'); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * builds list of active widgets then scans active sidebars looking for them |
|
311 | + * returns true is an EE widget is found in an active sidebar |
|
312 | + * Please Note: this does NOT mean that the sidebar or widget |
|
313 | + * is actually in use in a given template, as that is unfortunately not known |
|
314 | + * until a sidebar and it's widgets are actually loaded |
|
315 | + * |
|
316 | + * @return boolean |
|
317 | + */ |
|
318 | + private function espresso_widgets_in_active_sidebars() |
|
319 | + { |
|
320 | + $espresso_widgets = array(); |
|
321 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
322 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
323 | + if (is_active_widget(false, false, $id_base)) { |
|
324 | + $espresso_widgets[] = $id_base; |
|
325 | + } |
|
326 | + } |
|
327 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
328 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
329 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
330 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
331 | + foreach ($espresso_widgets as $espresso_widget) { |
|
332 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
333 | + return true; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + } |
|
339 | + return false; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * header_meta_tag |
|
347 | + * |
|
348 | + * @access public |
|
349 | + * @return void |
|
350 | + */ |
|
351 | + public function header_meta_tag() |
|
352 | + { |
|
353 | + print( |
|
354 | + apply_filters( |
|
355 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
356 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
357 | + ); |
|
358 | + |
|
359 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
360 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
361 | + //also exclude all critical pages from indexing |
|
362 | + if ( |
|
363 | + ( |
|
364 | + is_tax('espresso_event_type') |
|
365 | + && get_option( 'blog_public' ) !== '0' |
|
366 | + ) |
|
367 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
368 | + ) { |
|
369 | + print( |
|
370 | + apply_filters( |
|
371 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
372 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
373 | + ) |
|
374 | + ); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * wp_print_scripts |
|
382 | + * |
|
383 | + * @return void |
|
384 | + */ |
|
385 | + public function wp_print_scripts() |
|
386 | + { |
|
387 | + global $post; |
|
388 | + if ( |
|
389 | + isset($post->EE_Event) |
|
390 | + && $post->EE_Event instanceof EE_Event |
|
391 | + && get_post_type() === 'espresso_events' |
|
392 | + && is_singular() |
|
393 | + ) { |
|
394 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + |
|
401 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
402 | 402 | |
403 | 403 | |
404 | 404 | |
@@ -409,99 +409,99 @@ discard block |
||
409 | 409 | // * @param $the_content |
410 | 410 | // * @return string |
411 | 411 | // */ |
412 | - // public function the_content( $the_content ) { |
|
413 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
414 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
415 | - // } |
|
416 | - // return $the_content; |
|
417 | - // } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * display_errors |
|
426 | - * |
|
427 | - * @access public |
|
428 | - * @return void |
|
429 | - */ |
|
430 | - public function display_errors() |
|
431 | - { |
|
432 | - static $shown_already = false; |
|
433 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
434 | - if ( |
|
435 | - ! $shown_already |
|
436 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
437 | - && is_main_query() |
|
438 | - && ! is_feed() |
|
439 | - && in_the_loop() |
|
440 | - && $this->Request_Handler->is_espresso_page() |
|
441 | - ) { |
|
442 | - echo EE_Error::get_notices(); |
|
443 | - $shown_already = true; |
|
444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
445 | - } |
|
446 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /*********************************************** UTILITIES ***********************************************/ |
|
454 | - /** |
|
455 | - * template_include |
|
456 | - * |
|
457 | - * @access public |
|
458 | - * @param string $template_include_path |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function template_include($template_include_path = null) |
|
462 | - { |
|
463 | - if ($this->Request_Handler->is_espresso_page()) { |
|
464 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
465 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
466 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
467 | - $this->_template = basename($this->_template_path); |
|
468 | - return $this->_template_path; |
|
469 | - } |
|
470 | - return $template_include_path; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * get_selected_template |
|
476 | - * |
|
477 | - * @access public |
|
478 | - * @param bool $with_path |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_selected_template($with_path = false) |
|
482 | - { |
|
483 | - return $with_path ? $this->_template_path : $this->_template; |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * @deprecated 4.9.26 |
|
490 | - * @param string $shortcode_class |
|
491 | - * @param \WP $wp |
|
492 | - */ |
|
493 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
494 | - { |
|
495 | - \EE_Error::doing_it_wrong( |
|
496 | - __METHOD__, |
|
497 | - __( |
|
498 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
499 | - 'event_espresso' |
|
500 | - ), |
|
501 | - '4.9.26' |
|
502 | - ); |
|
503 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
504 | - } |
|
412 | + // public function the_content( $the_content ) { |
|
413 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
414 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
415 | + // } |
|
416 | + // return $the_content; |
|
417 | + // } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * display_errors |
|
426 | + * |
|
427 | + * @access public |
|
428 | + * @return void |
|
429 | + */ |
|
430 | + public function display_errors() |
|
431 | + { |
|
432 | + static $shown_already = false; |
|
433 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
434 | + if ( |
|
435 | + ! $shown_already |
|
436 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
437 | + && is_main_query() |
|
438 | + && ! is_feed() |
|
439 | + && in_the_loop() |
|
440 | + && $this->Request_Handler->is_espresso_page() |
|
441 | + ) { |
|
442 | + echo EE_Error::get_notices(); |
|
443 | + $shown_already = true; |
|
444 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
445 | + } |
|
446 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /*********************************************** UTILITIES ***********************************************/ |
|
454 | + /** |
|
455 | + * template_include |
|
456 | + * |
|
457 | + * @access public |
|
458 | + * @param string $template_include_path |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function template_include($template_include_path = null) |
|
462 | + { |
|
463 | + if ($this->Request_Handler->is_espresso_page()) { |
|
464 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
465 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
466 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
467 | + $this->_template = basename($this->_template_path); |
|
468 | + return $this->_template_path; |
|
469 | + } |
|
470 | + return $template_include_path; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * get_selected_template |
|
476 | + * |
|
477 | + * @access public |
|
478 | + * @param bool $with_path |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_selected_template($with_path = false) |
|
482 | + { |
|
483 | + return $with_path ? $this->_template_path : $this->_template; |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * @deprecated 4.9.26 |
|
490 | + * @param string $shortcode_class |
|
491 | + * @param \WP $wp |
|
492 | + */ |
|
493 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
494 | + { |
|
495 | + \EE_Error::doing_it_wrong( |
|
496 | + __METHOD__, |
|
497 | + __( |
|
498 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
499 | + 'event_espresso' |
|
500 | + ), |
|
501 | + '4.9.26' |
|
502 | + ); |
|
503 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
504 | + } |
|
505 | 505 | |
506 | 506 | } |
507 | 507 | // End of file EE_Front_Controller.core.php |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
99 | 99 | // for checking that browser cookies are enabled |
100 | 100 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | public function wpHead() |
291 | 291 | { |
292 | 292 | global $wp_query; |
293 | - if (empty($wp_query->posts)){ |
|
293 | + if (empty($wp_query->posts)) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | // if we already know this is an espresso page, then load assets |
297 | 297 | $load_assets = $this->Request_Handler->is_espresso_page(); |
298 | 298 | // if we are already loading assets then just move along, otherwise check for widgets |
299 | 299 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
300 | - if ( $load_assets){ |
|
300 | + if ($load_assets) { |
|
301 | 301 | wp_enqueue_style('espresso_default'); |
302 | 302 | wp_enqueue_style('espresso_custom_css'); |
303 | 303 | wp_enqueue_script('espresso_core'); |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | print( |
354 | 354 | apply_filters( |
355 | 355 | 'FHEE__EE_Front_Controller__header_meta_tag', |
356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
356 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
357 | 357 | ); |
358 | 358 | |
359 | 359 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -362,14 +362,14 @@ discard block |
||
362 | 362 | if ( |
363 | 363 | ( |
364 | 364 | is_tax('espresso_event_type') |
365 | - && get_option( 'blog_public' ) !== '0' |
|
365 | + && get_option('blog_public') !== '0' |
|
366 | 366 | ) |
367 | 367 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
368 | 368 | ) { |
369 | 369 | print( |
370 | 370 | apply_filters( |
371 | 371 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
372 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
373 | 373 | ) |
374 | 374 | ); |
375 | 375 | } |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | ) { |
442 | 442 | echo EE_Error::get_notices(); |
443 | 443 | $shown_already = true; |
444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
444 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
445 | 445 | } |
446 | 446 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
447 | 447 | } |
@@ -120,7 +120,7 @@ |
||
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
123 | - * @param $field_name |
|
123 | + * @param string $field_name |
|
124 | 124 | * @param int $row_number |
125 | 125 | * @return string |
126 | 126 | */ |
@@ -14,181 +14,181 @@ |
||
14 | 14 | class EventsAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Selector for the Add new Event button in the admin. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Selector for the Event Title field in the event editor |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | - |
|
30 | - /** |
|
31 | - * Selector for the publish submit button in the event editor. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Selector for the view link after publishing an event. |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Selector for the ID of the event in the event editor |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Selector for the search input on the event list table page. |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $additional_params |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
70 | - { |
|
71 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * The selector for the DTTname field for the given row in the event editor. |
|
77 | - * @param int $row_number |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
81 | - { |
|
82 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
88 | - * @param int $row_number |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
92 | - { |
|
93 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
99 | - * |
|
100 | - * @param string $field_name |
|
101 | - * @param int $row_number |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
105 | - { |
|
106 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
112 | - * @param int $row_number |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
116 | - { |
|
117 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
123 | - * @param $field_name |
|
124 | - * @param int $row_number |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
128 | - { |
|
129 | - return "//tr[@id='display-ticketrow-$row_number']" |
|
130 | - . "/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']"; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
136 | - * @param string $event_title |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
140 | - { |
|
141 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Locator for for the ID column in the event list table for a given event title. |
|
147 | - * @param string $event_title |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
151 | - { |
|
152 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
153 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Locator for the view link in the row of an event list table for the given event title. |
|
159 | - * @param string $event_title |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
163 | - { |
|
164 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
165 | - . "//ancestor::td//span[@class='view']/a"; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
171 | - * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
175 | - { |
|
176 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
177 | - . "//a[@rel='ee-tab-$messenger_slug']"; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Locator for the select input within the notifications metabox. |
|
183 | - * Note, this assumes the tab content for the related messenger is already visible. |
|
184 | - * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
188 | - { |
|
189 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
190 | - . "//table[@class='messages-custom-template-switcher']" |
|
191 | - . "//tr/td[contains(.,'Registration Approved')]" |
|
192 | - . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
193 | - } |
|
17 | + /** |
|
18 | + * Selector for the Add new Event button in the admin. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Selector for the Event Title field in the event editor |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | + |
|
30 | + /** |
|
31 | + * Selector for the publish submit button in the event editor. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Selector for the view link after publishing an event. |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Selector for the ID of the event in the event editor |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Selector for the search input on the event list table page. |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $additional_params |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
70 | + { |
|
71 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * The selector for the DTTname field for the given row in the event editor. |
|
77 | + * @param int $row_number |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
81 | + { |
|
82 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
88 | + * @param int $row_number |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
92 | + { |
|
93 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
99 | + * |
|
100 | + * @param string $field_name |
|
101 | + * @param int $row_number |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
105 | + { |
|
106 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
112 | + * @param int $row_number |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
116 | + { |
|
117 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
123 | + * @param $field_name |
|
124 | + * @param int $row_number |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
128 | + { |
|
129 | + return "//tr[@id='display-ticketrow-$row_number']" |
|
130 | + . "/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']"; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
136 | + * @param string $event_title |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
140 | + { |
|
141 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Locator for for the ID column in the event list table for a given event title. |
|
147 | + * @param string $event_title |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
151 | + { |
|
152 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
153 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Locator for the view link in the row of an event list table for the given event title. |
|
159 | + * @param string $event_title |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
163 | + { |
|
164 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
165 | + . "//ancestor::td//span[@class='view']/a"; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
171 | + * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
175 | + { |
|
176 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
177 | + . "//a[@rel='ee-tab-$messenger_slug']"; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Locator for the select input within the notifications metabox. |
|
183 | + * Note, this assumes the tab content for the related messenger is already visible. |
|
184 | + * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
188 | + { |
|
189 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
190 | + . "//table[@class='messages-custom-template-switcher']" |
|
191 | + . "//tr/td[contains(.,'Registration Approved')]" |
|
192 | + . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
193 | + } |
|
194 | 194 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php 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 | - ); ?> |
|
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 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
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.3.9'); |
|
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 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.41.rc.004'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.41.rc.004'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,1400 +19,1400 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | - */ |
|
26 | - const req_type_normal = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * Indicates this is a brand new installation of EE so we should install |
|
30 | - * tables and default data etc |
|
31 | - */ |
|
32 | - const req_type_new_activation = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | - * and that default data is setup too |
|
38 | - */ |
|
39 | - const req_type_reactivation = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates that EE has been upgraded since its previous request. |
|
43 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | - */ |
|
45 | - const req_type_upgrade = 3; |
|
46 | - |
|
47 | - /** |
|
48 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | - */ |
|
50 | - const req_type_downgrade = 4; |
|
51 | - |
|
52 | - /** |
|
53 | - * @deprecated since version 4.6.0.dev.006 |
|
54 | - * Now whenever a new_activation is detected the request type is still just |
|
55 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | - * (Specifically, when the migration manager indicates migrations are finished |
|
59 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | - */ |
|
61 | - const req_type_activation_but_not_installed = 5; |
|
62 | - |
|
63 | - /** |
|
64 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | - */ |
|
66 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * instance of the EE_System object |
|
71 | - * |
|
72 | - * @var $_instance |
|
73 | - * @access private |
|
74 | - */ |
|
75 | - private static $_instance = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * @type EE_Registry $Registry |
|
79 | - * @access protected |
|
80 | - */ |
|
81 | - protected $registry; |
|
82 | - |
|
83 | - /** |
|
84 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - private $_req_type; |
|
90 | - |
|
91 | - /** |
|
92 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | - * |
|
94 | - * @var boolean |
|
95 | - */ |
|
96 | - private $_major_version_change = false; |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @singleton method used to instantiate class object |
|
102 | - * @access public |
|
103 | - * @param \EE_Registry $Registry |
|
104 | - * @return \EE_System |
|
105 | - */ |
|
106 | - public static function instance(EE_Registry $Registry = null) |
|
107 | - { |
|
108 | - // check if class object is instantiated |
|
109 | - if ( ! self::$_instance instanceof EE_System) { |
|
110 | - self::$_instance = new self($Registry); |
|
111 | - } |
|
112 | - return self::$_instance; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * resets the instance and returns it |
|
119 | - * |
|
120 | - * @return EE_System |
|
121 | - */ |
|
122 | - public static function reset() |
|
123 | - { |
|
124 | - self::$_instance->_req_type = null; |
|
125 | - //make sure none of the old hooks are left hanging around |
|
126 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | - EE_Data_Migration_Manager::reset(); |
|
129 | - self::instance()->detect_activations_or_upgrades(); |
|
130 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | - return self::instance(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * sets hooks for running rest of system |
|
138 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | - * starting EE Addons from any other point may lead to problems |
|
140 | - * |
|
141 | - * @access private |
|
142 | - * @param \EE_Registry $Registry |
|
143 | - */ |
|
144 | - private function __construct(EE_Registry $Registry) |
|
145 | - { |
|
146 | - $this->registry = $Registry; |
|
147 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | - // because the newly-activated addon didn't get a chance to run at all |
|
152 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | - // detect whether install or upgrade |
|
154 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | - 3); |
|
156 | - // load EE_Config, EE_Textdomain, etc |
|
157 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | - // load EE_Config, EE_Textdomain, etc |
|
159 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | - // you wanna get going? I wanna get going... let's get going! |
|
162 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | - //other housekeeping |
|
164 | - //exclude EE critical pages from wp_list_pages |
|
165 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * load_espresso_addons |
|
175 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | - * this is hooked into both: |
|
177 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | - * and the WP 'activate_plugin' hookpoint |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function load_espresso_addons() |
|
185 | - { |
|
186 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
190 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
191 | - //We want it for mobile apps. Just include the entire plugin |
|
192 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
193 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
194 | - //and causes a fatal error |
|
195 | - if ( ! function_exists('json_basic_auth_handler') |
|
196 | - && ! function_exists('json_basic_auth_error') |
|
197 | - && ! ( |
|
198 | - isset($_GET['action']) |
|
199 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
200 | - ) |
|
201 | - && ! ( |
|
202 | - isset($_GET['activate']) |
|
203 | - && $_GET['activate'] === 'true' |
|
204 | - ) |
|
205 | - ) { |
|
206 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
207 | - } |
|
208 | - $this->_maybe_brew_regular(); |
|
209 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
210 | - |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
217 | - * that need to be setup before our EE_System launches. |
|
218 | - * |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - private function _maybe_brew_regular() |
|
222 | - { |
|
223 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
224 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * detect_activations_or_upgrades |
|
232 | - * Checks for activation or upgrade of core first; |
|
233 | - * then also checks if any registered addons have been activated or upgraded |
|
234 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
235 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
236 | - * |
|
237 | - * @access public |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function detect_activations_or_upgrades() |
|
241 | - { |
|
242 | - //first off: let's make sure to handle core |
|
243 | - $this->detect_if_activation_or_upgrade(); |
|
244 | - foreach ($this->registry->addons as $addon) { |
|
245 | - //detect teh request type for that addon |
|
246 | - $addon->detect_activation_or_upgrade(); |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * detect_if_activation_or_upgrade |
|
254 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
255 | - * and either setting up the DB or setting up maintenance mode etc. |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @return void |
|
259 | - */ |
|
260 | - public function detect_if_activation_or_upgrade() |
|
261 | - { |
|
262 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
263 | - // load M-Mode class |
|
264 | - $this->registry->load_core('Maintenance_Mode'); |
|
265 | - // check if db has been updated, or if its a brand-new installation |
|
266 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
267 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
268 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
269 | - switch ($request_type) { |
|
270 | - case EE_System::req_type_new_activation: |
|
271 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
272 | - $this->_handle_core_version_change($espresso_db_update); |
|
273 | - break; |
|
274 | - case EE_System::req_type_reactivation: |
|
275 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
276 | - $this->_handle_core_version_change($espresso_db_update); |
|
277 | - break; |
|
278 | - case EE_System::req_type_upgrade: |
|
279 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
280 | - //migrations may be required now that we've upgraded |
|
281 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
282 | - $this->_handle_core_version_change($espresso_db_update); |
|
283 | - // echo "done upgrade";die; |
|
284 | - break; |
|
285 | - case EE_System::req_type_downgrade: |
|
286 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
287 | - //its possible migrations are no longer required |
|
288 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
289 | - $this->_handle_core_version_change($espresso_db_update); |
|
290 | - break; |
|
291 | - case EE_System::req_type_normal: |
|
292 | - default: |
|
293 | - // $this->_maybe_redirect_to_ee_about(); |
|
294 | - break; |
|
295 | - } |
|
296 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Updates the list of installed versions and sets hooks for |
|
303 | - * initializing the database later during the request |
|
304 | - * |
|
305 | - * @param array $espresso_db_update |
|
306 | - */ |
|
307 | - protected function _handle_core_version_change($espresso_db_update) |
|
308 | - { |
|
309 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
310 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
311 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
312 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
319 | - * information about what versions of EE have been installed and activated, |
|
320 | - * NOT necessarily the state of the database |
|
321 | - * |
|
322 | - * @param null $espresso_db_update |
|
323 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
324 | - * from the options table |
|
325 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
326 | - */ |
|
327 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
328 | - { |
|
329 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
330 | - if ( ! $espresso_db_update) { |
|
331 | - $espresso_db_update = get_option('espresso_db_update'); |
|
332 | - } |
|
333 | - // check that option is an array |
|
334 | - if ( ! is_array($espresso_db_update)) { |
|
335 | - // if option is FALSE, then it never existed |
|
336 | - if ($espresso_db_update === false) { |
|
337 | - // make $espresso_db_update an array and save option with autoload OFF |
|
338 | - $espresso_db_update = array(); |
|
339 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
340 | - } else { |
|
341 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
342 | - $espresso_db_update = array($espresso_db_update => array()); |
|
343 | - update_option('espresso_db_update', $espresso_db_update); |
|
344 | - } |
|
345 | - } else { |
|
346 | - $corrected_db_update = array(); |
|
347 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
348 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
349 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
350 | - //the key is an int, and the value IS NOT an array |
|
351 | - //so it must be numerically-indexed, where values are versions installed... |
|
352 | - //fix it! |
|
353 | - $version_string = $should_be_array; |
|
354 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
355 | - } else { |
|
356 | - //ok it checks out |
|
357 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
358 | - } |
|
359 | - } |
|
360 | - $espresso_db_update = $corrected_db_update; |
|
361 | - update_option('espresso_db_update', $espresso_db_update); |
|
362 | - } |
|
363 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
364 | - return $espresso_db_update; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
371 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
372 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
373 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
374 | - * so that it will be done when migrations are finished |
|
375 | - * |
|
376 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
377 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
378 | - * This is a resource-intensive job |
|
379 | - * so we prefer to only do it when necessary |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
383 | - { |
|
384 | - $request_type = $this->detect_req_type(); |
|
385 | - //only initialize system if we're not in maintenance mode. |
|
386 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
387 | - update_option('ee_flush_rewrite_rules', true); |
|
388 | - if ($verify_schema) { |
|
389 | - EEH_Activation::initialize_db_and_folders(); |
|
390 | - } |
|
391 | - EEH_Activation::initialize_db_content(); |
|
392 | - EEH_Activation::system_initialization(); |
|
393 | - if ($initialize_addons_too) { |
|
394 | - $this->initialize_addons(); |
|
395 | - } |
|
396 | - } else { |
|
397 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
398 | - } |
|
399 | - if ($request_type === EE_System::req_type_new_activation |
|
400 | - || $request_type === EE_System::req_type_reactivation |
|
401 | - || ( |
|
402 | - $request_type === EE_System::req_type_upgrade |
|
403 | - && $this->is_major_version_change() |
|
404 | - ) |
|
405 | - ) { |
|
406 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Initializes the db for all registered addons |
|
414 | - */ |
|
415 | - public function initialize_addons() |
|
416 | - { |
|
417 | - //foreach registered addon, make sure its db is up-to-date too |
|
418 | - foreach ($this->registry->addons as $addon) { |
|
419 | - $addon->initialize_db_if_no_migrations_required(); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
427 | - * |
|
428 | - * @param array $version_history |
|
429 | - * @param string $current_version_to_add version to be added to the version history |
|
430 | - * @return boolean success as to whether or not this option was changed |
|
431 | - */ |
|
432 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
433 | - { |
|
434 | - if ( ! $version_history) { |
|
435 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
436 | - } |
|
437 | - if ($current_version_to_add == null) { |
|
438 | - $current_version_to_add = espresso_version(); |
|
439 | - } |
|
440 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
441 | - // re-save |
|
442 | - return update_option('espresso_db_update', $version_history); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Detects if the current version indicated in the has existed in the list of |
|
449 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
450 | - * |
|
451 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
452 | - * If not supplied, fetches it from the options table. |
|
453 | - * Also, caches its result so later parts of the code can also know whether |
|
454 | - * there's been an update or not. This way we can add the current version to |
|
455 | - * espresso_db_update, but still know if this is a new install or not |
|
456 | - * @return int one of the constants on EE_System::req_type_ |
|
457 | - */ |
|
458 | - public function detect_req_type($espresso_db_update = null) |
|
459 | - { |
|
460 | - if ($this->_req_type === null) { |
|
461 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
462 | - : $this->fix_espresso_db_upgrade_option(); |
|
463 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
464 | - 'ee_espresso_activation', espresso_version()); |
|
465 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
466 | - } |
|
467 | - return $this->_req_type; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
474 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
475 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
476 | - * |
|
477 | - * @param $activation_history |
|
478 | - * @return bool |
|
479 | - */ |
|
480 | - protected function _detect_major_version_change($activation_history) |
|
481 | - { |
|
482 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
483 | - $previous_version_parts = explode('.', $previous_version); |
|
484 | - $current_version_parts = explode('.', espresso_version()); |
|
485 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
486 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
487 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * Returns true if either the major or minor version of EE changed during this request. |
|
495 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
496 | - * |
|
497 | - * @return bool |
|
498 | - */ |
|
499 | - public function is_major_version_change() |
|
500 | - { |
|
501 | - return $this->_major_version_change; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
508 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
509 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
510 | - * just activated to (for core that will always be espresso_version()) |
|
511 | - * |
|
512 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
513 | - * ee plugin. for core that's 'espresso_db_update' |
|
514 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
515 | - * indicate that this plugin was just activated |
|
516 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
517 | - * espresso_version()) |
|
518 | - * @return int one of the constants on EE_System::req_type_* |
|
519 | - */ |
|
520 | - public static function detect_req_type_given_activation_history( |
|
521 | - $activation_history_for_addon, |
|
522 | - $activation_indicator_option_name, |
|
523 | - $version_to_upgrade_to |
|
524 | - ) { |
|
525 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
526 | - if ($activation_history_for_addon) { |
|
527 | - //it exists, so this isn't a completely new install |
|
528 | - //check if this version already in that list of previously installed versions |
|
529 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
530 | - //it a version we haven't seen before |
|
531 | - if ($version_is_higher === 1) { |
|
532 | - $req_type = EE_System::req_type_upgrade; |
|
533 | - } else { |
|
534 | - $req_type = EE_System::req_type_downgrade; |
|
535 | - } |
|
536 | - delete_option($activation_indicator_option_name); |
|
537 | - } else { |
|
538 | - // its not an update. maybe a reactivation? |
|
539 | - if (get_option($activation_indicator_option_name, false)) { |
|
540 | - if ($version_is_higher === -1) { |
|
541 | - $req_type = EE_System::req_type_downgrade; |
|
542 | - } elseif ($version_is_higher === 0) { |
|
543 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
544 | - $req_type = EE_System::req_type_reactivation; |
|
545 | - } else {//$version_is_higher === 1 |
|
546 | - $req_type = EE_System::req_type_upgrade; |
|
547 | - } |
|
548 | - delete_option($activation_indicator_option_name); |
|
549 | - } else { |
|
550 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
551 | - if ($version_is_higher === -1) { |
|
552 | - $req_type = EE_System::req_type_downgrade; |
|
553 | - } elseif ($version_is_higher === 0) { |
|
554 | - //we've seen this version before and it's not an activation. its normal request |
|
555 | - $req_type = EE_System::req_type_normal; |
|
556 | - } else {//$version_is_higher === 1 |
|
557 | - $req_type = EE_System::req_type_upgrade; |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - } else { |
|
562 | - //brand new install |
|
563 | - $req_type = EE_System::req_type_new_activation; |
|
564 | - delete_option($activation_indicator_option_name); |
|
565 | - } |
|
566 | - return $req_type; |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
573 | - * the $activation_history_for_addon |
|
574 | - * |
|
575 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
576 | - * sometimes containing 'unknown-date' |
|
577 | - * @param string $version_to_upgrade_to (current version) |
|
578 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
579 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
580 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
581 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
582 | - */ |
|
583 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
584 | - { |
|
585 | - //find the most recently-activated version |
|
586 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
587 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * Gets the most recently active version listed in the activation history, |
|
594 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
595 | - * |
|
596 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
597 | - * sometimes containing 'unknown-date' |
|
598 | - * @return string |
|
599 | - */ |
|
600 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
601 | - { |
|
602 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
603 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
604 | - if (is_array($activation_history)) { |
|
605 | - foreach ($activation_history as $version => $times_activated) { |
|
606 | - //check there is a record of when this version was activated. Otherwise, |
|
607 | - //mark it as unknown |
|
608 | - if ( ! $times_activated) { |
|
609 | - $times_activated = array('unknown-date'); |
|
610 | - } |
|
611 | - if (is_string($times_activated)) { |
|
612 | - $times_activated = array($times_activated); |
|
613 | - } |
|
614 | - foreach ($times_activated as $an_activation) { |
|
615 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
616 | - $most_recently_active_version = $version; |
|
617 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
618 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
619 | - } |
|
620 | - } |
|
621 | - } |
|
622 | - } |
|
623 | - return $most_recently_active_version; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * This redirects to the about EE page after activation |
|
630 | - * |
|
631 | - * @return void |
|
632 | - */ |
|
633 | - public function redirect_to_about_ee() |
|
634 | - { |
|
635 | - $notices = EE_Error::get_notices(false); |
|
636 | - //if current user is an admin and it's not an ajax or rest request |
|
637 | - if ( |
|
638 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
639 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
640 | - && ! isset($notices['errors']) |
|
641 | - && apply_filters( |
|
642 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
643 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
644 | - ) |
|
645 | - ) { |
|
646 | - $query_params = array('page' => 'espresso_about'); |
|
647 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
648 | - $query_params['new_activation'] = true; |
|
649 | - } |
|
650 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
651 | - $query_params['reactivation'] = true; |
|
652 | - } |
|
653 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
654 | - wp_safe_redirect($url); |
|
655 | - exit(); |
|
656 | - } |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * load_core_configuration |
|
663 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
664 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
665 | - * |
|
666 | - * @return void |
|
667 | - */ |
|
668 | - public function load_core_configuration() |
|
669 | - { |
|
670 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
671 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
672 | - //load textdomain |
|
673 | - EE_Load_Textdomain::load_textdomain(); |
|
674 | - // load and setup EE_Config and EE_Network_Config |
|
675 | - $this->registry->load_core('Config'); |
|
676 | - $this->registry->load_core('Network_Config'); |
|
677 | - // setup autoloaders |
|
678 | - // enable logging? |
|
679 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
680 | - $this->registry->load_core('Log'); |
|
681 | - } |
|
682 | - // check for activation errors |
|
683 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
684 | - if ($activation_errors) { |
|
685 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
686 | - update_option('ee_plugin_activation_errors', false); |
|
687 | - } |
|
688 | - // get model names |
|
689 | - $this->_parse_model_names(); |
|
690 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
697 | - * |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - private function _parse_model_names() |
|
701 | - { |
|
702 | - //call the non-abstract db models method, which verifies the model names have been discovered |
|
703 | - //for the sake of unit tests, always re-discover the models. We could probably make this more |
|
704 | - //efficient though (e.g., have unit tests reset the registered models in a different way) |
|
705 | - $this->registry->non_abstract_db_models = array(); |
|
706 | - $this->registry->non_abstract_db_models(); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * register_shortcodes_modules_and_widgets |
|
713 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
714 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
715 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
716 | - * |
|
717 | - * @access public |
|
718 | - * @return void |
|
719 | - */ |
|
720 | - public function register_shortcodes_modules_and_widgets() |
|
721 | - { |
|
722 | - try { |
|
723 | - // load, register, and add shortcodes the new way |
|
724 | - new ShortcodesManager( |
|
725 | - // and the old way, but we'll put it under control of the new system |
|
726 | - EE_Config::getLegacyShortcodesManager() |
|
727 | - ); |
|
728 | - } catch (Exception $exception) { |
|
729 | - new ExceptionStackTraceDisplay($exception); |
|
730 | - } |
|
731 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
732 | - // check for addons using old hookpoint |
|
733 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
734 | - $this->_incompatible_addon_error(); |
|
735 | - } |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * _incompatible_addon_error |
|
742 | - * |
|
743 | - * @access public |
|
744 | - * @return void |
|
745 | - */ |
|
746 | - private function _incompatible_addon_error() |
|
747 | - { |
|
748 | - // get array of classes hooking into here |
|
749 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
750 | - if ( ! empty($class_names)) { |
|
751 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
752 | - 'event_espresso'); |
|
753 | - $msg .= '<ul>'; |
|
754 | - foreach ($class_names as $class_name) { |
|
755 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | - $class_name) . '</b></li>'; |
|
757 | - } |
|
758 | - $msg .= '</ul>'; |
|
759 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
760 | - 'event_espresso'); |
|
761 | - // save list of incompatible addons to wp-options for later use |
|
762 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
763 | - if (is_admin()) { |
|
764 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
765 | - } |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * brew_espresso |
|
773 | - * begins the process of setting hooks for initializing EE in the correct order |
|
774 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
775 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
776 | - * |
|
777 | - * @return void |
|
778 | - */ |
|
779 | - public function brew_espresso() |
|
780 | - { |
|
781 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
782 | - // load some final core systems |
|
783 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
784 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
785 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
786 | - add_action('init', array($this, 'load_controllers'), 7); |
|
787 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
788 | - add_action('init', array($this, 'initialize'), 10); |
|
789 | - add_action('init', array($this, 'initialize_last'), 100); |
|
790 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
791 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
792 | - // pew pew pew |
|
793 | - $this->registry->load_core('PUE'); |
|
794 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
795 | - } |
|
796 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
797 | - } |
|
798 | - |
|
799 | - |
|
800 | - |
|
801 | - /** |
|
802 | - * set_hooks_for_core |
|
803 | - * |
|
804 | - * @access public |
|
805 | - * @return void |
|
806 | - */ |
|
807 | - public function set_hooks_for_core() |
|
808 | - { |
|
809 | - //caps need to be initialized on every request so that capability maps are set. |
|
810 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
811 | - //load and setup EE_Capabilities |
|
812 | - $this->registry->load_core('Capabilities'); |
|
813 | - $this->registry->CAP->init_caps(); |
|
814 | - $this->_deactivate_incompatible_addons(); |
|
815 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
822 | - * deactivates any addons considered incompatible with the current version of EE |
|
823 | - */ |
|
824 | - private function _deactivate_incompatible_addons() |
|
825 | - { |
|
826 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
827 | - if ( ! empty($incompatible_addons)) { |
|
828 | - $active_plugins = get_option('active_plugins', array()); |
|
829 | - foreach ($active_plugins as $active_plugin) { |
|
830 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
831 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
832 | - unset($_GET['activate']); |
|
833 | - espresso_deactivate_plugin($active_plugin); |
|
834 | - } |
|
835 | - } |
|
836 | - } |
|
837 | - } |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - |
|
842 | - /** |
|
843 | - * perform_activations_upgrades_and_migrations |
|
844 | - * |
|
845 | - * @access public |
|
846 | - * @return void |
|
847 | - */ |
|
848 | - public function perform_activations_upgrades_and_migrations() |
|
849 | - { |
|
850 | - //first check if we had previously attempted to setup EE's directories but failed |
|
851 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
852 | - EEH_Activation::create_upload_directories(); |
|
853 | - } |
|
854 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
855 | - } |
|
856 | - |
|
857 | - |
|
858 | - |
|
859 | - /** |
|
860 | - * load_CPTs_and_session |
|
861 | - * |
|
862 | - * @access public |
|
863 | - * @return void |
|
864 | - */ |
|
865 | - public function load_CPTs_and_session() |
|
866 | - { |
|
867 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
868 | - // register Custom Post Types |
|
869 | - $this->registry->load_core('Register_CPTs'); |
|
870 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
871 | - } |
|
872 | - |
|
873 | - |
|
874 | - |
|
875 | - /** |
|
876 | - * load_controllers |
|
877 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
878 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
879 | - * time |
|
880 | - * |
|
881 | - * @access public |
|
882 | - * @return void |
|
883 | - */ |
|
884 | - public function load_controllers() |
|
885 | - { |
|
886 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
887 | - // let's get it started |
|
888 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
889 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
890 | - $this->registry->load_core('Front_Controller'); |
|
891 | - } else if ( ! EE_FRONT_AJAX) { |
|
892 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
893 | - EE_Registry::instance()->load_core('Admin'); |
|
894 | - } |
|
895 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * core_loaded_and_ready |
|
902 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
903 | - * |
|
904 | - * @access public |
|
905 | - * @return void |
|
906 | - */ |
|
907 | - public function core_loaded_and_ready() |
|
908 | - { |
|
909 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
910 | - // load_espresso_template_tags |
|
911 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
912 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
913 | - } |
|
914 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
915 | - $this->registry->load_core('Session'); |
|
916 | - $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
917 | - wp_enqueue_script('espresso_core'); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - |
|
922 | - /** |
|
923 | - * initialize |
|
924 | - * this is the best place to begin initializing client code |
|
925 | - * |
|
926 | - * @access public |
|
927 | - * @return void |
|
928 | - */ |
|
929 | - public function initialize() |
|
930 | - { |
|
931 | - do_action('AHEE__EE_System__initialize'); |
|
932 | - } |
|
933 | - |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * initialize_last |
|
938 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
939 | - * initialize has done so |
|
940 | - * |
|
941 | - * @access public |
|
942 | - * @return void |
|
943 | - */ |
|
944 | - public function initialize_last() |
|
945 | - { |
|
946 | - do_action('AHEE__EE_System__initialize_last'); |
|
947 | - } |
|
948 | - |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * set_hooks_for_shortcodes_modules_and_addons |
|
953 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
954 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
955 | - * |
|
956 | - * @access public |
|
957 | - * @return void |
|
958 | - */ |
|
959 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
960 | - { |
|
961 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
962 | - } |
|
963 | - |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * do_not_cache |
|
968 | - * sets no cache headers and defines no cache constants for WP plugins |
|
969 | - * |
|
970 | - * @access public |
|
971 | - * @return void |
|
972 | - */ |
|
973 | - public static function do_not_cache() |
|
974 | - { |
|
975 | - // set no cache constants |
|
976 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
977 | - define('DONOTCACHEPAGE', true); |
|
978 | - } |
|
979 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
980 | - define('DONOTCACHCEOBJECT', true); |
|
981 | - } |
|
982 | - if ( ! defined('DONOTCACHEDB')) { |
|
983 | - define('DONOTCACHEDB', true); |
|
984 | - } |
|
985 | - // add no cache headers |
|
986 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
987 | - // plus a little extra for nginx and Google Chrome |
|
988 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
989 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
990 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
991 | - } |
|
992 | - |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * extra_nocache_headers |
|
997 | - * |
|
998 | - * @access public |
|
999 | - * @param $headers |
|
1000 | - * @return array |
|
1001 | - */ |
|
1002 | - public static function extra_nocache_headers($headers) |
|
1003 | - { |
|
1004 | - // for NGINX |
|
1005 | - $headers['X-Accel-Expires'] = 0; |
|
1006 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1007 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1008 | - return $headers; |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * nocache_headers |
|
1015 | - * |
|
1016 | - * @access public |
|
1017 | - * @return void |
|
1018 | - */ |
|
1019 | - public static function nocache_headers() |
|
1020 | - { |
|
1021 | - nocache_headers(); |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * espresso_toolbar_items |
|
1028 | - * |
|
1029 | - * @access public |
|
1030 | - * @param WP_Admin_Bar $admin_bar |
|
1031 | - * @return void |
|
1032 | - */ |
|
1033 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1034 | - { |
|
1035 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1036 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1037 | - || defined('DOING_AJAX') |
|
1038 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1039 | - ) { |
|
1040 | - return; |
|
1041 | - } |
|
1042 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1043 | - $menu_class = 'espresso_menu_item_class'; |
|
1044 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1045 | - //because they're only defined in each of their respective constructors |
|
1046 | - //and this might be a frontend request, in which case they aren't available |
|
1047 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1048 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1049 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1050 | - //Top Level |
|
1051 | - $admin_bar->add_menu(array( |
|
1052 | - 'id' => 'espresso-toolbar', |
|
1053 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1054 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1055 | - . '</span>', |
|
1056 | - 'href' => $events_admin_url, |
|
1057 | - 'meta' => array( |
|
1058 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1059 | - 'class' => $menu_class . 'first', |
|
1060 | - ), |
|
1061 | - )); |
|
1062 | - //Events |
|
1063 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1064 | - $admin_bar->add_menu(array( |
|
1065 | - 'id' => 'espresso-toolbar-events', |
|
1066 | - 'parent' => 'espresso-toolbar', |
|
1067 | - 'title' => __('Events', 'event_espresso'), |
|
1068 | - 'href' => $events_admin_url, |
|
1069 | - 'meta' => array( |
|
1070 | - 'title' => __('Events', 'event_espresso'), |
|
1071 | - 'target' => '', |
|
1072 | - 'class' => $menu_class, |
|
1073 | - ), |
|
1074 | - )); |
|
1075 | - } |
|
1076 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1077 | - //Events Add New |
|
1078 | - $admin_bar->add_menu(array( |
|
1079 | - 'id' => 'espresso-toolbar-events-new', |
|
1080 | - 'parent' => 'espresso-toolbar-events', |
|
1081 | - 'title' => __('Add New', 'event_espresso'), |
|
1082 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1083 | - 'meta' => array( |
|
1084 | - 'title' => __('Add New', 'event_espresso'), |
|
1085 | - 'target' => '', |
|
1086 | - 'class' => $menu_class, |
|
1087 | - ), |
|
1088 | - )); |
|
1089 | - } |
|
1090 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1091 | - //Current post |
|
1092 | - global $post; |
|
1093 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1094 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1095 | - ) { |
|
1096 | - //Events Edit Current Event |
|
1097 | - $admin_bar->add_menu(array( |
|
1098 | - 'id' => 'espresso-toolbar-events-edit', |
|
1099 | - 'parent' => 'espresso-toolbar-events', |
|
1100 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1101 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1102 | - $events_admin_url), |
|
1103 | - 'meta' => array( |
|
1104 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1105 | - 'target' => '', |
|
1106 | - 'class' => $menu_class, |
|
1107 | - ), |
|
1108 | - )); |
|
1109 | - } |
|
1110 | - } |
|
1111 | - //Events View |
|
1112 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1113 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1114 | - ) { |
|
1115 | - $admin_bar->add_menu(array( |
|
1116 | - 'id' => 'espresso-toolbar-events-view', |
|
1117 | - 'parent' => 'espresso-toolbar-events', |
|
1118 | - 'title' => __('View', 'event_espresso'), |
|
1119 | - 'href' => $events_admin_url, |
|
1120 | - 'meta' => array( |
|
1121 | - 'title' => __('View', 'event_espresso'), |
|
1122 | - 'target' => '', |
|
1123 | - 'class' => $menu_class, |
|
1124 | - ), |
|
1125 | - )); |
|
1126 | - } |
|
1127 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1128 | - //Events View All |
|
1129 | - $admin_bar->add_menu(array( |
|
1130 | - 'id' => 'espresso-toolbar-events-all', |
|
1131 | - 'parent' => 'espresso-toolbar-events-view', |
|
1132 | - 'title' => __('All', 'event_espresso'), |
|
1133 | - 'href' => $events_admin_url, |
|
1134 | - 'meta' => array( |
|
1135 | - 'title' => __('All', 'event_espresso'), |
|
1136 | - 'target' => '', |
|
1137 | - 'class' => $menu_class, |
|
1138 | - ), |
|
1139 | - )); |
|
1140 | - } |
|
1141 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1142 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1143 | - ) { |
|
1144 | - //Events View Today |
|
1145 | - $admin_bar->add_menu(array( |
|
1146 | - 'id' => 'espresso-toolbar-events-today', |
|
1147 | - 'parent' => 'espresso-toolbar-events-view', |
|
1148 | - 'title' => __('Today', 'event_espresso'), |
|
1149 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1150 | - $events_admin_url), |
|
1151 | - 'meta' => array( |
|
1152 | - 'title' => __('Today', 'event_espresso'), |
|
1153 | - 'target' => '', |
|
1154 | - 'class' => $menu_class, |
|
1155 | - ), |
|
1156 | - )); |
|
1157 | - } |
|
1158 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1159 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1160 | - ) { |
|
1161 | - //Events View This Month |
|
1162 | - $admin_bar->add_menu(array( |
|
1163 | - 'id' => 'espresso-toolbar-events-month', |
|
1164 | - 'parent' => 'espresso-toolbar-events-view', |
|
1165 | - 'title' => __('This Month', 'event_espresso'), |
|
1166 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1167 | - $events_admin_url), |
|
1168 | - 'meta' => array( |
|
1169 | - 'title' => __('This Month', 'event_espresso'), |
|
1170 | - 'target' => '', |
|
1171 | - 'class' => $menu_class, |
|
1172 | - ), |
|
1173 | - )); |
|
1174 | - } |
|
1175 | - //Registration Overview |
|
1176 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1177 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1178 | - ) { |
|
1179 | - $admin_bar->add_menu(array( |
|
1180 | - 'id' => 'espresso-toolbar-registrations', |
|
1181 | - 'parent' => 'espresso-toolbar', |
|
1182 | - 'title' => __('Registrations', 'event_espresso'), |
|
1183 | - 'href' => $reg_admin_url, |
|
1184 | - 'meta' => array( |
|
1185 | - 'title' => __('Registrations', 'event_espresso'), |
|
1186 | - 'target' => '', |
|
1187 | - 'class' => $menu_class, |
|
1188 | - ), |
|
1189 | - )); |
|
1190 | - } |
|
1191 | - //Registration Overview Today |
|
1192 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1193 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1194 | - ) { |
|
1195 | - $admin_bar->add_menu(array( |
|
1196 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1197 | - 'parent' => 'espresso-toolbar-registrations', |
|
1198 | - 'title' => __('Today', 'event_espresso'), |
|
1199 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1200 | - $reg_admin_url), |
|
1201 | - 'meta' => array( |
|
1202 | - 'title' => __('Today', 'event_espresso'), |
|
1203 | - 'target' => '', |
|
1204 | - 'class' => $menu_class, |
|
1205 | - ), |
|
1206 | - )); |
|
1207 | - } |
|
1208 | - //Registration Overview Today Completed |
|
1209 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1210 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1211 | - ) { |
|
1212 | - $admin_bar->add_menu(array( |
|
1213 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1214 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1215 | - 'title' => __('Approved', 'event_espresso'), |
|
1216 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1217 | - 'action' => 'default', |
|
1218 | - 'status' => 'today', |
|
1219 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1220 | - ), $reg_admin_url), |
|
1221 | - 'meta' => array( |
|
1222 | - 'title' => __('Approved', 'event_espresso'), |
|
1223 | - 'target' => '', |
|
1224 | - 'class' => $menu_class, |
|
1225 | - ), |
|
1226 | - )); |
|
1227 | - } |
|
1228 | - //Registration Overview Today Pending\ |
|
1229 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1230 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1231 | - ) { |
|
1232 | - $admin_bar->add_menu(array( |
|
1233 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1234 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1235 | - 'title' => __('Pending', 'event_espresso'), |
|
1236 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1237 | - 'action' => 'default', |
|
1238 | - 'status' => 'today', |
|
1239 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1240 | - ), $reg_admin_url), |
|
1241 | - 'meta' => array( |
|
1242 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1243 | - 'target' => '', |
|
1244 | - 'class' => $menu_class, |
|
1245 | - ), |
|
1246 | - )); |
|
1247 | - } |
|
1248 | - //Registration Overview Today Incomplete |
|
1249 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1250 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1251 | - ) { |
|
1252 | - $admin_bar->add_menu(array( |
|
1253 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1254 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1255 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1256 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1257 | - 'action' => 'default', |
|
1258 | - 'status' => 'today', |
|
1259 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1260 | - ), $reg_admin_url), |
|
1261 | - 'meta' => array( |
|
1262 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1263 | - 'target' => '', |
|
1264 | - 'class' => $menu_class, |
|
1265 | - ), |
|
1266 | - )); |
|
1267 | - } |
|
1268 | - //Registration Overview Today Incomplete |
|
1269 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1270 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1271 | - ) { |
|
1272 | - $admin_bar->add_menu(array( |
|
1273 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1274 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1275 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1276 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1277 | - 'action' => 'default', |
|
1278 | - 'status' => 'today', |
|
1279 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1280 | - ), $reg_admin_url), |
|
1281 | - 'meta' => array( |
|
1282 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1283 | - 'target' => '', |
|
1284 | - 'class' => $menu_class, |
|
1285 | - ), |
|
1286 | - )); |
|
1287 | - } |
|
1288 | - //Registration Overview This Month |
|
1289 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1290 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1291 | - ) { |
|
1292 | - $admin_bar->add_menu(array( |
|
1293 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1294 | - 'parent' => 'espresso-toolbar-registrations', |
|
1295 | - 'title' => __('This Month', 'event_espresso'), |
|
1296 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1297 | - $reg_admin_url), |
|
1298 | - 'meta' => array( |
|
1299 | - 'title' => __('This Month', 'event_espresso'), |
|
1300 | - 'target' => '', |
|
1301 | - 'class' => $menu_class, |
|
1302 | - ), |
|
1303 | - )); |
|
1304 | - } |
|
1305 | - //Registration Overview This Month Approved |
|
1306 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1307 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1308 | - ) { |
|
1309 | - $admin_bar->add_menu(array( |
|
1310 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1311 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1312 | - 'title' => __('Approved', 'event_espresso'), |
|
1313 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1314 | - 'action' => 'default', |
|
1315 | - 'status' => 'month', |
|
1316 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1317 | - ), $reg_admin_url), |
|
1318 | - 'meta' => array( |
|
1319 | - 'title' => __('Approved', 'event_espresso'), |
|
1320 | - 'target' => '', |
|
1321 | - 'class' => $menu_class, |
|
1322 | - ), |
|
1323 | - )); |
|
1324 | - } |
|
1325 | - //Registration Overview This Month Pending |
|
1326 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1327 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1328 | - ) { |
|
1329 | - $admin_bar->add_menu(array( |
|
1330 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1331 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1332 | - 'title' => __('Pending', 'event_espresso'), |
|
1333 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1334 | - 'action' => 'default', |
|
1335 | - 'status' => 'month', |
|
1336 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1337 | - ), $reg_admin_url), |
|
1338 | - 'meta' => array( |
|
1339 | - 'title' => __('Pending', 'event_espresso'), |
|
1340 | - 'target' => '', |
|
1341 | - 'class' => $menu_class, |
|
1342 | - ), |
|
1343 | - )); |
|
1344 | - } |
|
1345 | - //Registration Overview This Month Not Approved |
|
1346 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1347 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1348 | - ) { |
|
1349 | - $admin_bar->add_menu(array( |
|
1350 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1351 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1352 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1353 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1354 | - 'action' => 'default', |
|
1355 | - 'status' => 'month', |
|
1356 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1357 | - ), $reg_admin_url), |
|
1358 | - 'meta' => array( |
|
1359 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1360 | - 'target' => '', |
|
1361 | - 'class' => $menu_class, |
|
1362 | - ), |
|
1363 | - )); |
|
1364 | - } |
|
1365 | - //Registration Overview This Month Cancelled |
|
1366 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1367 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1368 | - ) { |
|
1369 | - $admin_bar->add_menu(array( |
|
1370 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1371 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1372 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1373 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1374 | - 'action' => 'default', |
|
1375 | - 'status' => 'month', |
|
1376 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1377 | - ), $reg_admin_url), |
|
1378 | - 'meta' => array( |
|
1379 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1380 | - 'target' => '', |
|
1381 | - 'class' => $menu_class, |
|
1382 | - ), |
|
1383 | - )); |
|
1384 | - } |
|
1385 | - //Extensions & Services |
|
1386 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1387 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1388 | - ) { |
|
1389 | - $admin_bar->add_menu(array( |
|
1390 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1391 | - 'parent' => 'espresso-toolbar', |
|
1392 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1393 | - 'href' => $extensions_admin_url, |
|
1394 | - 'meta' => array( |
|
1395 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1396 | - 'target' => '', |
|
1397 | - 'class' => $menu_class, |
|
1398 | - ), |
|
1399 | - )); |
|
1400 | - } |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1407 | - * never returned with the function. |
|
1408 | - * |
|
1409 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1410 | - * @return array |
|
1411 | - */ |
|
1412 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1413 | - { |
|
1414 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1415 | - } |
|
22 | + /** |
|
23 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | + */ |
|
26 | + const req_type_normal = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * Indicates this is a brand new installation of EE so we should install |
|
30 | + * tables and default data etc |
|
31 | + */ |
|
32 | + const req_type_new_activation = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | + * and that default data is setup too |
|
38 | + */ |
|
39 | + const req_type_reactivation = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates that EE has been upgraded since its previous request. |
|
43 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | + */ |
|
45 | + const req_type_upgrade = 3; |
|
46 | + |
|
47 | + /** |
|
48 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | + */ |
|
50 | + const req_type_downgrade = 4; |
|
51 | + |
|
52 | + /** |
|
53 | + * @deprecated since version 4.6.0.dev.006 |
|
54 | + * Now whenever a new_activation is detected the request type is still just |
|
55 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | + * (Specifically, when the migration manager indicates migrations are finished |
|
59 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | + */ |
|
61 | + const req_type_activation_but_not_installed = 5; |
|
62 | + |
|
63 | + /** |
|
64 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | + */ |
|
66 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * instance of the EE_System object |
|
71 | + * |
|
72 | + * @var $_instance |
|
73 | + * @access private |
|
74 | + */ |
|
75 | + private static $_instance = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * @type EE_Registry $Registry |
|
79 | + * @access protected |
|
80 | + */ |
|
81 | + protected $registry; |
|
82 | + |
|
83 | + /** |
|
84 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + private $_req_type; |
|
90 | + |
|
91 | + /** |
|
92 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | + * |
|
94 | + * @var boolean |
|
95 | + */ |
|
96 | + private $_major_version_change = false; |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @singleton method used to instantiate class object |
|
102 | + * @access public |
|
103 | + * @param \EE_Registry $Registry |
|
104 | + * @return \EE_System |
|
105 | + */ |
|
106 | + public static function instance(EE_Registry $Registry = null) |
|
107 | + { |
|
108 | + // check if class object is instantiated |
|
109 | + if ( ! self::$_instance instanceof EE_System) { |
|
110 | + self::$_instance = new self($Registry); |
|
111 | + } |
|
112 | + return self::$_instance; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * resets the instance and returns it |
|
119 | + * |
|
120 | + * @return EE_System |
|
121 | + */ |
|
122 | + public static function reset() |
|
123 | + { |
|
124 | + self::$_instance->_req_type = null; |
|
125 | + //make sure none of the old hooks are left hanging around |
|
126 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | + EE_Data_Migration_Manager::reset(); |
|
129 | + self::instance()->detect_activations_or_upgrades(); |
|
130 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | + return self::instance(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * sets hooks for running rest of system |
|
138 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | + * starting EE Addons from any other point may lead to problems |
|
140 | + * |
|
141 | + * @access private |
|
142 | + * @param \EE_Registry $Registry |
|
143 | + */ |
|
144 | + private function __construct(EE_Registry $Registry) |
|
145 | + { |
|
146 | + $this->registry = $Registry; |
|
147 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | + // because the newly-activated addon didn't get a chance to run at all |
|
152 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | + // detect whether install or upgrade |
|
154 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | + 3); |
|
156 | + // load EE_Config, EE_Textdomain, etc |
|
157 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | + // load EE_Config, EE_Textdomain, etc |
|
159 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | + // you wanna get going? I wanna get going... let's get going! |
|
162 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | + //other housekeeping |
|
164 | + //exclude EE critical pages from wp_list_pages |
|
165 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * load_espresso_addons |
|
175 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | + * this is hooked into both: |
|
177 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | + * and the WP 'activate_plugin' hookpoint |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function load_espresso_addons() |
|
185 | + { |
|
186 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
190 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
191 | + //We want it for mobile apps. Just include the entire plugin |
|
192 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
193 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
194 | + //and causes a fatal error |
|
195 | + if ( ! function_exists('json_basic_auth_handler') |
|
196 | + && ! function_exists('json_basic_auth_error') |
|
197 | + && ! ( |
|
198 | + isset($_GET['action']) |
|
199 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
200 | + ) |
|
201 | + && ! ( |
|
202 | + isset($_GET['activate']) |
|
203 | + && $_GET['activate'] === 'true' |
|
204 | + ) |
|
205 | + ) { |
|
206 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
207 | + } |
|
208 | + $this->_maybe_brew_regular(); |
|
209 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
210 | + |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
217 | + * that need to be setup before our EE_System launches. |
|
218 | + * |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + private function _maybe_brew_regular() |
|
222 | + { |
|
223 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
224 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * detect_activations_or_upgrades |
|
232 | + * Checks for activation or upgrade of core first; |
|
233 | + * then also checks if any registered addons have been activated or upgraded |
|
234 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
235 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
236 | + * |
|
237 | + * @access public |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function detect_activations_or_upgrades() |
|
241 | + { |
|
242 | + //first off: let's make sure to handle core |
|
243 | + $this->detect_if_activation_or_upgrade(); |
|
244 | + foreach ($this->registry->addons as $addon) { |
|
245 | + //detect teh request type for that addon |
|
246 | + $addon->detect_activation_or_upgrade(); |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * detect_if_activation_or_upgrade |
|
254 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
255 | + * and either setting up the DB or setting up maintenance mode etc. |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @return void |
|
259 | + */ |
|
260 | + public function detect_if_activation_or_upgrade() |
|
261 | + { |
|
262 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
263 | + // load M-Mode class |
|
264 | + $this->registry->load_core('Maintenance_Mode'); |
|
265 | + // check if db has been updated, or if its a brand-new installation |
|
266 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
267 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
268 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
269 | + switch ($request_type) { |
|
270 | + case EE_System::req_type_new_activation: |
|
271 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
272 | + $this->_handle_core_version_change($espresso_db_update); |
|
273 | + break; |
|
274 | + case EE_System::req_type_reactivation: |
|
275 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
276 | + $this->_handle_core_version_change($espresso_db_update); |
|
277 | + break; |
|
278 | + case EE_System::req_type_upgrade: |
|
279 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
280 | + //migrations may be required now that we've upgraded |
|
281 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
282 | + $this->_handle_core_version_change($espresso_db_update); |
|
283 | + // echo "done upgrade";die; |
|
284 | + break; |
|
285 | + case EE_System::req_type_downgrade: |
|
286 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
287 | + //its possible migrations are no longer required |
|
288 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
289 | + $this->_handle_core_version_change($espresso_db_update); |
|
290 | + break; |
|
291 | + case EE_System::req_type_normal: |
|
292 | + default: |
|
293 | + // $this->_maybe_redirect_to_ee_about(); |
|
294 | + break; |
|
295 | + } |
|
296 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Updates the list of installed versions and sets hooks for |
|
303 | + * initializing the database later during the request |
|
304 | + * |
|
305 | + * @param array $espresso_db_update |
|
306 | + */ |
|
307 | + protected function _handle_core_version_change($espresso_db_update) |
|
308 | + { |
|
309 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
310 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
311 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
312 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
319 | + * information about what versions of EE have been installed and activated, |
|
320 | + * NOT necessarily the state of the database |
|
321 | + * |
|
322 | + * @param null $espresso_db_update |
|
323 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
324 | + * from the options table |
|
325 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
326 | + */ |
|
327 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
328 | + { |
|
329 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
330 | + if ( ! $espresso_db_update) { |
|
331 | + $espresso_db_update = get_option('espresso_db_update'); |
|
332 | + } |
|
333 | + // check that option is an array |
|
334 | + if ( ! is_array($espresso_db_update)) { |
|
335 | + // if option is FALSE, then it never existed |
|
336 | + if ($espresso_db_update === false) { |
|
337 | + // make $espresso_db_update an array and save option with autoload OFF |
|
338 | + $espresso_db_update = array(); |
|
339 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
340 | + } else { |
|
341 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
342 | + $espresso_db_update = array($espresso_db_update => array()); |
|
343 | + update_option('espresso_db_update', $espresso_db_update); |
|
344 | + } |
|
345 | + } else { |
|
346 | + $corrected_db_update = array(); |
|
347 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
348 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
349 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
350 | + //the key is an int, and the value IS NOT an array |
|
351 | + //so it must be numerically-indexed, where values are versions installed... |
|
352 | + //fix it! |
|
353 | + $version_string = $should_be_array; |
|
354 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
355 | + } else { |
|
356 | + //ok it checks out |
|
357 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
358 | + } |
|
359 | + } |
|
360 | + $espresso_db_update = $corrected_db_update; |
|
361 | + update_option('espresso_db_update', $espresso_db_update); |
|
362 | + } |
|
363 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
364 | + return $espresso_db_update; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
371 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
372 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
373 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
374 | + * so that it will be done when migrations are finished |
|
375 | + * |
|
376 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
377 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
378 | + * This is a resource-intensive job |
|
379 | + * so we prefer to only do it when necessary |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
383 | + { |
|
384 | + $request_type = $this->detect_req_type(); |
|
385 | + //only initialize system if we're not in maintenance mode. |
|
386 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
387 | + update_option('ee_flush_rewrite_rules', true); |
|
388 | + if ($verify_schema) { |
|
389 | + EEH_Activation::initialize_db_and_folders(); |
|
390 | + } |
|
391 | + EEH_Activation::initialize_db_content(); |
|
392 | + EEH_Activation::system_initialization(); |
|
393 | + if ($initialize_addons_too) { |
|
394 | + $this->initialize_addons(); |
|
395 | + } |
|
396 | + } else { |
|
397 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
398 | + } |
|
399 | + if ($request_type === EE_System::req_type_new_activation |
|
400 | + || $request_type === EE_System::req_type_reactivation |
|
401 | + || ( |
|
402 | + $request_type === EE_System::req_type_upgrade |
|
403 | + && $this->is_major_version_change() |
|
404 | + ) |
|
405 | + ) { |
|
406 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Initializes the db for all registered addons |
|
414 | + */ |
|
415 | + public function initialize_addons() |
|
416 | + { |
|
417 | + //foreach registered addon, make sure its db is up-to-date too |
|
418 | + foreach ($this->registry->addons as $addon) { |
|
419 | + $addon->initialize_db_if_no_migrations_required(); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
427 | + * |
|
428 | + * @param array $version_history |
|
429 | + * @param string $current_version_to_add version to be added to the version history |
|
430 | + * @return boolean success as to whether or not this option was changed |
|
431 | + */ |
|
432 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
433 | + { |
|
434 | + if ( ! $version_history) { |
|
435 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
436 | + } |
|
437 | + if ($current_version_to_add == null) { |
|
438 | + $current_version_to_add = espresso_version(); |
|
439 | + } |
|
440 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
441 | + // re-save |
|
442 | + return update_option('espresso_db_update', $version_history); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Detects if the current version indicated in the has existed in the list of |
|
449 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
450 | + * |
|
451 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
452 | + * If not supplied, fetches it from the options table. |
|
453 | + * Also, caches its result so later parts of the code can also know whether |
|
454 | + * there's been an update or not. This way we can add the current version to |
|
455 | + * espresso_db_update, but still know if this is a new install or not |
|
456 | + * @return int one of the constants on EE_System::req_type_ |
|
457 | + */ |
|
458 | + public function detect_req_type($espresso_db_update = null) |
|
459 | + { |
|
460 | + if ($this->_req_type === null) { |
|
461 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
462 | + : $this->fix_espresso_db_upgrade_option(); |
|
463 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
464 | + 'ee_espresso_activation', espresso_version()); |
|
465 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
466 | + } |
|
467 | + return $this->_req_type; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
474 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
475 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
476 | + * |
|
477 | + * @param $activation_history |
|
478 | + * @return bool |
|
479 | + */ |
|
480 | + protected function _detect_major_version_change($activation_history) |
|
481 | + { |
|
482 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
483 | + $previous_version_parts = explode('.', $previous_version); |
|
484 | + $current_version_parts = explode('.', espresso_version()); |
|
485 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
486 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
487 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * Returns true if either the major or minor version of EE changed during this request. |
|
495 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
496 | + * |
|
497 | + * @return bool |
|
498 | + */ |
|
499 | + public function is_major_version_change() |
|
500 | + { |
|
501 | + return $this->_major_version_change; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
508 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
509 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
510 | + * just activated to (for core that will always be espresso_version()) |
|
511 | + * |
|
512 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
513 | + * ee plugin. for core that's 'espresso_db_update' |
|
514 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
515 | + * indicate that this plugin was just activated |
|
516 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
517 | + * espresso_version()) |
|
518 | + * @return int one of the constants on EE_System::req_type_* |
|
519 | + */ |
|
520 | + public static function detect_req_type_given_activation_history( |
|
521 | + $activation_history_for_addon, |
|
522 | + $activation_indicator_option_name, |
|
523 | + $version_to_upgrade_to |
|
524 | + ) { |
|
525 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
526 | + if ($activation_history_for_addon) { |
|
527 | + //it exists, so this isn't a completely new install |
|
528 | + //check if this version already in that list of previously installed versions |
|
529 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
530 | + //it a version we haven't seen before |
|
531 | + if ($version_is_higher === 1) { |
|
532 | + $req_type = EE_System::req_type_upgrade; |
|
533 | + } else { |
|
534 | + $req_type = EE_System::req_type_downgrade; |
|
535 | + } |
|
536 | + delete_option($activation_indicator_option_name); |
|
537 | + } else { |
|
538 | + // its not an update. maybe a reactivation? |
|
539 | + if (get_option($activation_indicator_option_name, false)) { |
|
540 | + if ($version_is_higher === -1) { |
|
541 | + $req_type = EE_System::req_type_downgrade; |
|
542 | + } elseif ($version_is_higher === 0) { |
|
543 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
544 | + $req_type = EE_System::req_type_reactivation; |
|
545 | + } else {//$version_is_higher === 1 |
|
546 | + $req_type = EE_System::req_type_upgrade; |
|
547 | + } |
|
548 | + delete_option($activation_indicator_option_name); |
|
549 | + } else { |
|
550 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
551 | + if ($version_is_higher === -1) { |
|
552 | + $req_type = EE_System::req_type_downgrade; |
|
553 | + } elseif ($version_is_higher === 0) { |
|
554 | + //we've seen this version before and it's not an activation. its normal request |
|
555 | + $req_type = EE_System::req_type_normal; |
|
556 | + } else {//$version_is_higher === 1 |
|
557 | + $req_type = EE_System::req_type_upgrade; |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + } else { |
|
562 | + //brand new install |
|
563 | + $req_type = EE_System::req_type_new_activation; |
|
564 | + delete_option($activation_indicator_option_name); |
|
565 | + } |
|
566 | + return $req_type; |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
573 | + * the $activation_history_for_addon |
|
574 | + * |
|
575 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
576 | + * sometimes containing 'unknown-date' |
|
577 | + * @param string $version_to_upgrade_to (current version) |
|
578 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
579 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
580 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
581 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
582 | + */ |
|
583 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
584 | + { |
|
585 | + //find the most recently-activated version |
|
586 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
587 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * Gets the most recently active version listed in the activation history, |
|
594 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
595 | + * |
|
596 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
597 | + * sometimes containing 'unknown-date' |
|
598 | + * @return string |
|
599 | + */ |
|
600 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
601 | + { |
|
602 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
603 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
604 | + if (is_array($activation_history)) { |
|
605 | + foreach ($activation_history as $version => $times_activated) { |
|
606 | + //check there is a record of when this version was activated. Otherwise, |
|
607 | + //mark it as unknown |
|
608 | + if ( ! $times_activated) { |
|
609 | + $times_activated = array('unknown-date'); |
|
610 | + } |
|
611 | + if (is_string($times_activated)) { |
|
612 | + $times_activated = array($times_activated); |
|
613 | + } |
|
614 | + foreach ($times_activated as $an_activation) { |
|
615 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
616 | + $most_recently_active_version = $version; |
|
617 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
618 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
619 | + } |
|
620 | + } |
|
621 | + } |
|
622 | + } |
|
623 | + return $most_recently_active_version; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * This redirects to the about EE page after activation |
|
630 | + * |
|
631 | + * @return void |
|
632 | + */ |
|
633 | + public function redirect_to_about_ee() |
|
634 | + { |
|
635 | + $notices = EE_Error::get_notices(false); |
|
636 | + //if current user is an admin and it's not an ajax or rest request |
|
637 | + if ( |
|
638 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
639 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
640 | + && ! isset($notices['errors']) |
|
641 | + && apply_filters( |
|
642 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
643 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
644 | + ) |
|
645 | + ) { |
|
646 | + $query_params = array('page' => 'espresso_about'); |
|
647 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
648 | + $query_params['new_activation'] = true; |
|
649 | + } |
|
650 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
651 | + $query_params['reactivation'] = true; |
|
652 | + } |
|
653 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
654 | + wp_safe_redirect($url); |
|
655 | + exit(); |
|
656 | + } |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * load_core_configuration |
|
663 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
664 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
665 | + * |
|
666 | + * @return void |
|
667 | + */ |
|
668 | + public function load_core_configuration() |
|
669 | + { |
|
670 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
671 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
672 | + //load textdomain |
|
673 | + EE_Load_Textdomain::load_textdomain(); |
|
674 | + // load and setup EE_Config and EE_Network_Config |
|
675 | + $this->registry->load_core('Config'); |
|
676 | + $this->registry->load_core('Network_Config'); |
|
677 | + // setup autoloaders |
|
678 | + // enable logging? |
|
679 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
680 | + $this->registry->load_core('Log'); |
|
681 | + } |
|
682 | + // check for activation errors |
|
683 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
684 | + if ($activation_errors) { |
|
685 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
686 | + update_option('ee_plugin_activation_errors', false); |
|
687 | + } |
|
688 | + // get model names |
|
689 | + $this->_parse_model_names(); |
|
690 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
697 | + * |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + private function _parse_model_names() |
|
701 | + { |
|
702 | + //call the non-abstract db models method, which verifies the model names have been discovered |
|
703 | + //for the sake of unit tests, always re-discover the models. We could probably make this more |
|
704 | + //efficient though (e.g., have unit tests reset the registered models in a different way) |
|
705 | + $this->registry->non_abstract_db_models = array(); |
|
706 | + $this->registry->non_abstract_db_models(); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * register_shortcodes_modules_and_widgets |
|
713 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
714 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
715 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
716 | + * |
|
717 | + * @access public |
|
718 | + * @return void |
|
719 | + */ |
|
720 | + public function register_shortcodes_modules_and_widgets() |
|
721 | + { |
|
722 | + try { |
|
723 | + // load, register, and add shortcodes the new way |
|
724 | + new ShortcodesManager( |
|
725 | + // and the old way, but we'll put it under control of the new system |
|
726 | + EE_Config::getLegacyShortcodesManager() |
|
727 | + ); |
|
728 | + } catch (Exception $exception) { |
|
729 | + new ExceptionStackTraceDisplay($exception); |
|
730 | + } |
|
731 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
732 | + // check for addons using old hookpoint |
|
733 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
734 | + $this->_incompatible_addon_error(); |
|
735 | + } |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * _incompatible_addon_error |
|
742 | + * |
|
743 | + * @access public |
|
744 | + * @return void |
|
745 | + */ |
|
746 | + private function _incompatible_addon_error() |
|
747 | + { |
|
748 | + // get array of classes hooking into here |
|
749 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
750 | + if ( ! empty($class_names)) { |
|
751 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
752 | + 'event_espresso'); |
|
753 | + $msg .= '<ul>'; |
|
754 | + foreach ($class_names as $class_name) { |
|
755 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | + $class_name) . '</b></li>'; |
|
757 | + } |
|
758 | + $msg .= '</ul>'; |
|
759 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
760 | + 'event_espresso'); |
|
761 | + // save list of incompatible addons to wp-options for later use |
|
762 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
763 | + if (is_admin()) { |
|
764 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
765 | + } |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * brew_espresso |
|
773 | + * begins the process of setting hooks for initializing EE in the correct order |
|
774 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
775 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
776 | + * |
|
777 | + * @return void |
|
778 | + */ |
|
779 | + public function brew_espresso() |
|
780 | + { |
|
781 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
782 | + // load some final core systems |
|
783 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
784 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
785 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
786 | + add_action('init', array($this, 'load_controllers'), 7); |
|
787 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
788 | + add_action('init', array($this, 'initialize'), 10); |
|
789 | + add_action('init', array($this, 'initialize_last'), 100); |
|
790 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
791 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
792 | + // pew pew pew |
|
793 | + $this->registry->load_core('PUE'); |
|
794 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
795 | + } |
|
796 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
797 | + } |
|
798 | + |
|
799 | + |
|
800 | + |
|
801 | + /** |
|
802 | + * set_hooks_for_core |
|
803 | + * |
|
804 | + * @access public |
|
805 | + * @return void |
|
806 | + */ |
|
807 | + public function set_hooks_for_core() |
|
808 | + { |
|
809 | + //caps need to be initialized on every request so that capability maps are set. |
|
810 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
811 | + //load and setup EE_Capabilities |
|
812 | + $this->registry->load_core('Capabilities'); |
|
813 | + $this->registry->CAP->init_caps(); |
|
814 | + $this->_deactivate_incompatible_addons(); |
|
815 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
822 | + * deactivates any addons considered incompatible with the current version of EE |
|
823 | + */ |
|
824 | + private function _deactivate_incompatible_addons() |
|
825 | + { |
|
826 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
827 | + if ( ! empty($incompatible_addons)) { |
|
828 | + $active_plugins = get_option('active_plugins', array()); |
|
829 | + foreach ($active_plugins as $active_plugin) { |
|
830 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
831 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
832 | + unset($_GET['activate']); |
|
833 | + espresso_deactivate_plugin($active_plugin); |
|
834 | + } |
|
835 | + } |
|
836 | + } |
|
837 | + } |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + |
|
842 | + /** |
|
843 | + * perform_activations_upgrades_and_migrations |
|
844 | + * |
|
845 | + * @access public |
|
846 | + * @return void |
|
847 | + */ |
|
848 | + public function perform_activations_upgrades_and_migrations() |
|
849 | + { |
|
850 | + //first check if we had previously attempted to setup EE's directories but failed |
|
851 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
852 | + EEH_Activation::create_upload_directories(); |
|
853 | + } |
|
854 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
855 | + } |
|
856 | + |
|
857 | + |
|
858 | + |
|
859 | + /** |
|
860 | + * load_CPTs_and_session |
|
861 | + * |
|
862 | + * @access public |
|
863 | + * @return void |
|
864 | + */ |
|
865 | + public function load_CPTs_and_session() |
|
866 | + { |
|
867 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
868 | + // register Custom Post Types |
|
869 | + $this->registry->load_core('Register_CPTs'); |
|
870 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
871 | + } |
|
872 | + |
|
873 | + |
|
874 | + |
|
875 | + /** |
|
876 | + * load_controllers |
|
877 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
878 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
879 | + * time |
|
880 | + * |
|
881 | + * @access public |
|
882 | + * @return void |
|
883 | + */ |
|
884 | + public function load_controllers() |
|
885 | + { |
|
886 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
887 | + // let's get it started |
|
888 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
889 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
890 | + $this->registry->load_core('Front_Controller'); |
|
891 | + } else if ( ! EE_FRONT_AJAX) { |
|
892 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
893 | + EE_Registry::instance()->load_core('Admin'); |
|
894 | + } |
|
895 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * core_loaded_and_ready |
|
902 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
903 | + * |
|
904 | + * @access public |
|
905 | + * @return void |
|
906 | + */ |
|
907 | + public function core_loaded_and_ready() |
|
908 | + { |
|
909 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
910 | + // load_espresso_template_tags |
|
911 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
912 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
913 | + } |
|
914 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
915 | + $this->registry->load_core('Session'); |
|
916 | + $this->registry->create('EventEspresso\core\services\assets\Registry'); |
|
917 | + wp_enqueue_script('espresso_core'); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + |
|
922 | + /** |
|
923 | + * initialize |
|
924 | + * this is the best place to begin initializing client code |
|
925 | + * |
|
926 | + * @access public |
|
927 | + * @return void |
|
928 | + */ |
|
929 | + public function initialize() |
|
930 | + { |
|
931 | + do_action('AHEE__EE_System__initialize'); |
|
932 | + } |
|
933 | + |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * initialize_last |
|
938 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
939 | + * initialize has done so |
|
940 | + * |
|
941 | + * @access public |
|
942 | + * @return void |
|
943 | + */ |
|
944 | + public function initialize_last() |
|
945 | + { |
|
946 | + do_action('AHEE__EE_System__initialize_last'); |
|
947 | + } |
|
948 | + |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * set_hooks_for_shortcodes_modules_and_addons |
|
953 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
954 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
955 | + * |
|
956 | + * @access public |
|
957 | + * @return void |
|
958 | + */ |
|
959 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
960 | + { |
|
961 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
962 | + } |
|
963 | + |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * do_not_cache |
|
968 | + * sets no cache headers and defines no cache constants for WP plugins |
|
969 | + * |
|
970 | + * @access public |
|
971 | + * @return void |
|
972 | + */ |
|
973 | + public static function do_not_cache() |
|
974 | + { |
|
975 | + // set no cache constants |
|
976 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
977 | + define('DONOTCACHEPAGE', true); |
|
978 | + } |
|
979 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
980 | + define('DONOTCACHCEOBJECT', true); |
|
981 | + } |
|
982 | + if ( ! defined('DONOTCACHEDB')) { |
|
983 | + define('DONOTCACHEDB', true); |
|
984 | + } |
|
985 | + // add no cache headers |
|
986 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
987 | + // plus a little extra for nginx and Google Chrome |
|
988 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
989 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
990 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
991 | + } |
|
992 | + |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * extra_nocache_headers |
|
997 | + * |
|
998 | + * @access public |
|
999 | + * @param $headers |
|
1000 | + * @return array |
|
1001 | + */ |
|
1002 | + public static function extra_nocache_headers($headers) |
|
1003 | + { |
|
1004 | + // for NGINX |
|
1005 | + $headers['X-Accel-Expires'] = 0; |
|
1006 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1007 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1008 | + return $headers; |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * nocache_headers |
|
1015 | + * |
|
1016 | + * @access public |
|
1017 | + * @return void |
|
1018 | + */ |
|
1019 | + public static function nocache_headers() |
|
1020 | + { |
|
1021 | + nocache_headers(); |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * espresso_toolbar_items |
|
1028 | + * |
|
1029 | + * @access public |
|
1030 | + * @param WP_Admin_Bar $admin_bar |
|
1031 | + * @return void |
|
1032 | + */ |
|
1033 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1034 | + { |
|
1035 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1036 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1037 | + || defined('DOING_AJAX') |
|
1038 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1039 | + ) { |
|
1040 | + return; |
|
1041 | + } |
|
1042 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1043 | + $menu_class = 'espresso_menu_item_class'; |
|
1044 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1045 | + //because they're only defined in each of their respective constructors |
|
1046 | + //and this might be a frontend request, in which case they aren't available |
|
1047 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1048 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1049 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1050 | + //Top Level |
|
1051 | + $admin_bar->add_menu(array( |
|
1052 | + 'id' => 'espresso-toolbar', |
|
1053 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1054 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1055 | + . '</span>', |
|
1056 | + 'href' => $events_admin_url, |
|
1057 | + 'meta' => array( |
|
1058 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1059 | + 'class' => $menu_class . 'first', |
|
1060 | + ), |
|
1061 | + )); |
|
1062 | + //Events |
|
1063 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1064 | + $admin_bar->add_menu(array( |
|
1065 | + 'id' => 'espresso-toolbar-events', |
|
1066 | + 'parent' => 'espresso-toolbar', |
|
1067 | + 'title' => __('Events', 'event_espresso'), |
|
1068 | + 'href' => $events_admin_url, |
|
1069 | + 'meta' => array( |
|
1070 | + 'title' => __('Events', 'event_espresso'), |
|
1071 | + 'target' => '', |
|
1072 | + 'class' => $menu_class, |
|
1073 | + ), |
|
1074 | + )); |
|
1075 | + } |
|
1076 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1077 | + //Events Add New |
|
1078 | + $admin_bar->add_menu(array( |
|
1079 | + 'id' => 'espresso-toolbar-events-new', |
|
1080 | + 'parent' => 'espresso-toolbar-events', |
|
1081 | + 'title' => __('Add New', 'event_espresso'), |
|
1082 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1083 | + 'meta' => array( |
|
1084 | + 'title' => __('Add New', 'event_espresso'), |
|
1085 | + 'target' => '', |
|
1086 | + 'class' => $menu_class, |
|
1087 | + ), |
|
1088 | + )); |
|
1089 | + } |
|
1090 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1091 | + //Current post |
|
1092 | + global $post; |
|
1093 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1094 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1095 | + ) { |
|
1096 | + //Events Edit Current Event |
|
1097 | + $admin_bar->add_menu(array( |
|
1098 | + 'id' => 'espresso-toolbar-events-edit', |
|
1099 | + 'parent' => 'espresso-toolbar-events', |
|
1100 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1101 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1102 | + $events_admin_url), |
|
1103 | + 'meta' => array( |
|
1104 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1105 | + 'target' => '', |
|
1106 | + 'class' => $menu_class, |
|
1107 | + ), |
|
1108 | + )); |
|
1109 | + } |
|
1110 | + } |
|
1111 | + //Events View |
|
1112 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1113 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1114 | + ) { |
|
1115 | + $admin_bar->add_menu(array( |
|
1116 | + 'id' => 'espresso-toolbar-events-view', |
|
1117 | + 'parent' => 'espresso-toolbar-events', |
|
1118 | + 'title' => __('View', 'event_espresso'), |
|
1119 | + 'href' => $events_admin_url, |
|
1120 | + 'meta' => array( |
|
1121 | + 'title' => __('View', 'event_espresso'), |
|
1122 | + 'target' => '', |
|
1123 | + 'class' => $menu_class, |
|
1124 | + ), |
|
1125 | + )); |
|
1126 | + } |
|
1127 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1128 | + //Events View All |
|
1129 | + $admin_bar->add_menu(array( |
|
1130 | + 'id' => 'espresso-toolbar-events-all', |
|
1131 | + 'parent' => 'espresso-toolbar-events-view', |
|
1132 | + 'title' => __('All', 'event_espresso'), |
|
1133 | + 'href' => $events_admin_url, |
|
1134 | + 'meta' => array( |
|
1135 | + 'title' => __('All', 'event_espresso'), |
|
1136 | + 'target' => '', |
|
1137 | + 'class' => $menu_class, |
|
1138 | + ), |
|
1139 | + )); |
|
1140 | + } |
|
1141 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1142 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1143 | + ) { |
|
1144 | + //Events View Today |
|
1145 | + $admin_bar->add_menu(array( |
|
1146 | + 'id' => 'espresso-toolbar-events-today', |
|
1147 | + 'parent' => 'espresso-toolbar-events-view', |
|
1148 | + 'title' => __('Today', 'event_espresso'), |
|
1149 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1150 | + $events_admin_url), |
|
1151 | + 'meta' => array( |
|
1152 | + 'title' => __('Today', 'event_espresso'), |
|
1153 | + 'target' => '', |
|
1154 | + 'class' => $menu_class, |
|
1155 | + ), |
|
1156 | + )); |
|
1157 | + } |
|
1158 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1159 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1160 | + ) { |
|
1161 | + //Events View This Month |
|
1162 | + $admin_bar->add_menu(array( |
|
1163 | + 'id' => 'espresso-toolbar-events-month', |
|
1164 | + 'parent' => 'espresso-toolbar-events-view', |
|
1165 | + 'title' => __('This Month', 'event_espresso'), |
|
1166 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1167 | + $events_admin_url), |
|
1168 | + 'meta' => array( |
|
1169 | + 'title' => __('This Month', 'event_espresso'), |
|
1170 | + 'target' => '', |
|
1171 | + 'class' => $menu_class, |
|
1172 | + ), |
|
1173 | + )); |
|
1174 | + } |
|
1175 | + //Registration Overview |
|
1176 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1177 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1178 | + ) { |
|
1179 | + $admin_bar->add_menu(array( |
|
1180 | + 'id' => 'espresso-toolbar-registrations', |
|
1181 | + 'parent' => 'espresso-toolbar', |
|
1182 | + 'title' => __('Registrations', 'event_espresso'), |
|
1183 | + 'href' => $reg_admin_url, |
|
1184 | + 'meta' => array( |
|
1185 | + 'title' => __('Registrations', 'event_espresso'), |
|
1186 | + 'target' => '', |
|
1187 | + 'class' => $menu_class, |
|
1188 | + ), |
|
1189 | + )); |
|
1190 | + } |
|
1191 | + //Registration Overview Today |
|
1192 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1193 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1194 | + ) { |
|
1195 | + $admin_bar->add_menu(array( |
|
1196 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1197 | + 'parent' => 'espresso-toolbar-registrations', |
|
1198 | + 'title' => __('Today', 'event_espresso'), |
|
1199 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1200 | + $reg_admin_url), |
|
1201 | + 'meta' => array( |
|
1202 | + 'title' => __('Today', 'event_espresso'), |
|
1203 | + 'target' => '', |
|
1204 | + 'class' => $menu_class, |
|
1205 | + ), |
|
1206 | + )); |
|
1207 | + } |
|
1208 | + //Registration Overview Today Completed |
|
1209 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1210 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1211 | + ) { |
|
1212 | + $admin_bar->add_menu(array( |
|
1213 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1214 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1215 | + 'title' => __('Approved', 'event_espresso'), |
|
1216 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1217 | + 'action' => 'default', |
|
1218 | + 'status' => 'today', |
|
1219 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1220 | + ), $reg_admin_url), |
|
1221 | + 'meta' => array( |
|
1222 | + 'title' => __('Approved', 'event_espresso'), |
|
1223 | + 'target' => '', |
|
1224 | + 'class' => $menu_class, |
|
1225 | + ), |
|
1226 | + )); |
|
1227 | + } |
|
1228 | + //Registration Overview Today Pending\ |
|
1229 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1230 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1231 | + ) { |
|
1232 | + $admin_bar->add_menu(array( |
|
1233 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1234 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1235 | + 'title' => __('Pending', 'event_espresso'), |
|
1236 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1237 | + 'action' => 'default', |
|
1238 | + 'status' => 'today', |
|
1239 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1240 | + ), $reg_admin_url), |
|
1241 | + 'meta' => array( |
|
1242 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1243 | + 'target' => '', |
|
1244 | + 'class' => $menu_class, |
|
1245 | + ), |
|
1246 | + )); |
|
1247 | + } |
|
1248 | + //Registration Overview Today Incomplete |
|
1249 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1250 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1251 | + ) { |
|
1252 | + $admin_bar->add_menu(array( |
|
1253 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1254 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1255 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1256 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1257 | + 'action' => 'default', |
|
1258 | + 'status' => 'today', |
|
1259 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1260 | + ), $reg_admin_url), |
|
1261 | + 'meta' => array( |
|
1262 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1263 | + 'target' => '', |
|
1264 | + 'class' => $menu_class, |
|
1265 | + ), |
|
1266 | + )); |
|
1267 | + } |
|
1268 | + //Registration Overview Today Incomplete |
|
1269 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1270 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1271 | + ) { |
|
1272 | + $admin_bar->add_menu(array( |
|
1273 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1274 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1275 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1276 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1277 | + 'action' => 'default', |
|
1278 | + 'status' => 'today', |
|
1279 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1280 | + ), $reg_admin_url), |
|
1281 | + 'meta' => array( |
|
1282 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1283 | + 'target' => '', |
|
1284 | + 'class' => $menu_class, |
|
1285 | + ), |
|
1286 | + )); |
|
1287 | + } |
|
1288 | + //Registration Overview This Month |
|
1289 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1290 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1291 | + ) { |
|
1292 | + $admin_bar->add_menu(array( |
|
1293 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1294 | + 'parent' => 'espresso-toolbar-registrations', |
|
1295 | + 'title' => __('This Month', 'event_espresso'), |
|
1296 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1297 | + $reg_admin_url), |
|
1298 | + 'meta' => array( |
|
1299 | + 'title' => __('This Month', 'event_espresso'), |
|
1300 | + 'target' => '', |
|
1301 | + 'class' => $menu_class, |
|
1302 | + ), |
|
1303 | + )); |
|
1304 | + } |
|
1305 | + //Registration Overview This Month Approved |
|
1306 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1307 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1308 | + ) { |
|
1309 | + $admin_bar->add_menu(array( |
|
1310 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1311 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1312 | + 'title' => __('Approved', 'event_espresso'), |
|
1313 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1314 | + 'action' => 'default', |
|
1315 | + 'status' => 'month', |
|
1316 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1317 | + ), $reg_admin_url), |
|
1318 | + 'meta' => array( |
|
1319 | + 'title' => __('Approved', 'event_espresso'), |
|
1320 | + 'target' => '', |
|
1321 | + 'class' => $menu_class, |
|
1322 | + ), |
|
1323 | + )); |
|
1324 | + } |
|
1325 | + //Registration Overview This Month Pending |
|
1326 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1327 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1328 | + ) { |
|
1329 | + $admin_bar->add_menu(array( |
|
1330 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1331 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1332 | + 'title' => __('Pending', 'event_espresso'), |
|
1333 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1334 | + 'action' => 'default', |
|
1335 | + 'status' => 'month', |
|
1336 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1337 | + ), $reg_admin_url), |
|
1338 | + 'meta' => array( |
|
1339 | + 'title' => __('Pending', 'event_espresso'), |
|
1340 | + 'target' => '', |
|
1341 | + 'class' => $menu_class, |
|
1342 | + ), |
|
1343 | + )); |
|
1344 | + } |
|
1345 | + //Registration Overview This Month Not Approved |
|
1346 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1347 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1348 | + ) { |
|
1349 | + $admin_bar->add_menu(array( |
|
1350 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1351 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1352 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1353 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1354 | + 'action' => 'default', |
|
1355 | + 'status' => 'month', |
|
1356 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1357 | + ), $reg_admin_url), |
|
1358 | + 'meta' => array( |
|
1359 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1360 | + 'target' => '', |
|
1361 | + 'class' => $menu_class, |
|
1362 | + ), |
|
1363 | + )); |
|
1364 | + } |
|
1365 | + //Registration Overview This Month Cancelled |
|
1366 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1367 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1368 | + ) { |
|
1369 | + $admin_bar->add_menu(array( |
|
1370 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1371 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1372 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1373 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1374 | + 'action' => 'default', |
|
1375 | + 'status' => 'month', |
|
1376 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1377 | + ), $reg_admin_url), |
|
1378 | + 'meta' => array( |
|
1379 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1380 | + 'target' => '', |
|
1381 | + 'class' => $menu_class, |
|
1382 | + ), |
|
1383 | + )); |
|
1384 | + } |
|
1385 | + //Extensions & Services |
|
1386 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1387 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1388 | + ) { |
|
1389 | + $admin_bar->add_menu(array( |
|
1390 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1391 | + 'parent' => 'espresso-toolbar', |
|
1392 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1393 | + 'href' => $extensions_admin_url, |
|
1394 | + 'meta' => array( |
|
1395 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1396 | + 'target' => '', |
|
1397 | + 'class' => $menu_class, |
|
1398 | + ), |
|
1399 | + )); |
|
1400 | + } |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1407 | + * never returned with the function. |
|
1408 | + * |
|
1409 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1410 | + * @return array |
|
1411 | + */ |
|
1412 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1413 | + { |
|
1414 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1415 | + } |
|
1416 | 1416 | |
1417 | 1417 | |
1418 | 1418 |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | { |
186 | 186 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
187 | 187 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
189 | 189 | do_action('AHEE__EE_System__load_espresso_addons'); |
190 | 190 | //if the WP API basic auth plugin isn't already loaded, load it now. |
191 | 191 | //We want it for mobile apps. Just include the entire plugin |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | && $_GET['activate'] === 'true' |
204 | 204 | ) |
205 | 205 | ) { |
206 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
206 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
207 | 207 | } |
208 | 208 | $this->_maybe_brew_regular(); |
209 | 209 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | private function _maybe_brew_regular() |
222 | 222 | { |
223 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
224 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
223 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
224 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | 'event_espresso'); |
753 | 753 | $msg .= '<ul>'; |
754 | 754 | foreach ($class_names as $class_name) { |
755 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | - $class_name) . '</b></li>'; |
|
755 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | + $class_name).'</b></li>'; |
|
757 | 757 | } |
758 | 758 | $msg .= '</ul>'; |
759 | 759 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -908,8 +908,8 @@ discard block |
||
908 | 908 | { |
909 | 909 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
910 | 910 | // load_espresso_template_tags |
911 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
912 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
911 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
912 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
913 | 913 | } |
914 | 914 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
915 | 915 | $this->registry->load_core('Session'); |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | 'href' => $events_admin_url, |
1057 | 1057 | 'meta' => array( |
1058 | 1058 | 'title' => __('Event Espresso', 'event_espresso'), |
1059 | - 'class' => $menu_class . 'first', |
|
1059 | + 'class' => $menu_class.'first', |
|
1060 | 1060 | ), |
1061 | 1061 | )); |
1062 | 1062 | //Events |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -17,402 +17,402 @@ discard block |
||
17 | 17 | class EE_Payment_Method_Manager |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EE_Payment_Method_Manager object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | - */ |
|
31 | - protected $_payment_method_types = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EE_Payment_Method_Manager instance |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Resets the instance and returns a new one |
|
54 | - * |
|
55 | - * @return EE_Payment_Method_Manager |
|
56 | - */ |
|
57 | - public static function reset() |
|
58 | - { |
|
59 | - self::$_instance = null; |
|
60 | - return self::instance(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * If necessary, re-register payment methods |
|
67 | - * |
|
68 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | - * we have not yet checked during this request, then we need to check anyways) |
|
71 | - */ |
|
72 | - public function maybe_register_payment_methods($force_recheck = false) |
|
73 | - { |
|
74 | - if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | - $this->_register_payment_methods(); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * register_payment_methods |
|
83 | - * |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function _register_payment_methods() |
|
87 | - { |
|
88 | - // grab list of installed modules |
|
89 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
90 | - // filter list of modules to register |
|
91 | - $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
92 | - $pm_to_register); |
|
93 | - // loop through folders |
|
94 | - foreach ($pm_to_register as $pm_path) { |
|
95 | - $this->register_payment_method($pm_path); |
|
96 | - } |
|
97 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
98 | - // filter list of installed modules |
|
99 | - //keep them organized alphabetically by the payment method type's name |
|
100 | - ksort($this->_payment_method_types); |
|
101 | - return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
102 | - $this->_payment_method_types); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * register_payment_method- makes core aware of this payment method |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function register_payment_method($payment_method_path = '') |
|
115 | - { |
|
116 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
117 | - $module_ext = '.pm.php'; |
|
118 | - // make all separators match |
|
119 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
120 | - // grab and sanitize module name |
|
121 | - $module_dir = basename($payment_method_path); |
|
122 | - // create classname from module directory name |
|
123 | - $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
124 | - // add class prefix |
|
125 | - $module_class = 'EE_PMT_' . $module; |
|
126 | - // does the module exist ? |
|
127 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
128 | - $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
129 | - 'event_espresso'), $module); |
|
130 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
131 | - return false; |
|
132 | - } |
|
133 | - if (WP_DEBUG === true) { |
|
134 | - EEH_Debug_Tools::instance()->start_timer(); |
|
135 | - } |
|
136 | - // load the module class file |
|
137 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
138 | - if (WP_DEBUG === true) { |
|
139 | - EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
140 | - } |
|
141 | - // verify that class exists |
|
142 | - if ( ! class_exists($module_class)) { |
|
143 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
144 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
145 | - return false; |
|
146 | - } |
|
147 | - // add to array of registered modules |
|
148 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
149 | - return true; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Checks if a payment method has been registered, and if so includes it |
|
156 | - * |
|
157 | - * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
158 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
159 | - * @return boolean |
|
160 | - */ |
|
161 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
162 | - { |
|
163 | - if ( |
|
164 | - $force_recheck |
|
165 | - || ! is_array($this->_payment_method_types) |
|
166 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
167 | - ) { |
|
168 | - $this->maybe_register_payment_methods($force_recheck); |
|
169 | - } |
|
170 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
171 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
172 | - return true; |
|
173 | - } else { |
|
174 | - return false; |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns all the classnames of the various payment method types |
|
182 | - * |
|
183 | - * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
184 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
185 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
189 | - { |
|
190 | - $this->maybe_register_payment_methods($force_recheck); |
|
191 | - if ($with_prefixes) { |
|
192 | - $classnames = array_keys($this->_payment_method_types); |
|
193 | - $payment_methods = array(); |
|
194 | - foreach ($classnames as $classname) { |
|
195 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
196 | - } |
|
197 | - return $payment_methods; |
|
198 | - } else { |
|
199 | - return array_keys($this->_payment_method_types); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Gets an object of each payment method type, none of which are bound to a |
|
207 | - * payment method instance |
|
208 | - * |
|
209 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
210 | - * @return EE_PMT_Base[] |
|
211 | - */ |
|
212 | - public function payment_method_types($force_recheck = false) |
|
213 | - { |
|
214 | - $this->maybe_register_payment_methods($force_recheck); |
|
215 | - $pmt_objs = array(); |
|
216 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
217 | - $pmt_objs[] = new $classname; |
|
218 | - } |
|
219 | - return $pmt_objs; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * Changes the payment method's classname into the payment method type's name |
|
226 | - * (as used on the payment method's table's PMD_type field) |
|
227 | - * |
|
228 | - * @param string $classname |
|
229 | - * @return string |
|
230 | - */ |
|
231 | - public function payment_method_type_sans_class_prefix($classname) |
|
232 | - { |
|
233 | - return str_replace("EE_PMT_", "", $classname); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Does the opposite of payment-method_type_sans_prefix |
|
240 | - * |
|
241 | - * @param string $type |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - public function payment_method_class_from_type($type) |
|
245 | - { |
|
246 | - $this->maybe_register_payment_methods(); |
|
247 | - return "EE_PMT_" . $type; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Activates a payment method of the given type. |
|
254 | - * |
|
255 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
256 | - * @return \EE_Payment_Method |
|
257 | - * @throws \EE_Error |
|
258 | - */ |
|
259 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
260 | - { |
|
261 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
262 | - if ( ! $payment_method instanceof EE_Payment_Method) { |
|
263 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
264 | - if (class_exists($pm_type_class)) { |
|
265 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
266 | - $pm_type_obj = new $pm_type_class; |
|
267 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
268 | - if ( ! $payment_method) { |
|
269 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
270 | - } |
|
271 | - $payment_method->set_type($payment_method_type); |
|
272 | - $this->initialize_payment_method($payment_method); |
|
273 | - } else { |
|
274 | - throw new EE_Error( |
|
275 | - sprintf( |
|
276 | - __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
277 | - $pm_type_class) |
|
278 | - ); |
|
279 | - } |
|
280 | - } |
|
281 | - $payment_method->set_active(); |
|
282 | - $payment_method->save(); |
|
283 | - if ($payment_method->type() === 'Invoice') { |
|
284 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
285 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
286 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
287 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
288 | - EE_Error::add_persistent_admin_notice( |
|
289 | - 'invoice_pm_requirements_notice', |
|
290 | - sprintf( |
|
291 | - __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
292 | - 'event_espresso'), |
|
293 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
294 | - '</a>' |
|
295 | - ), |
|
296 | - true |
|
297 | - ); |
|
298 | - } |
|
299 | - return $payment_method; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Creates a payment method of the specified type. Does not save it. |
|
306 | - * |
|
307 | - * @global WP_User $current_user |
|
308 | - * @param EE_PMT_Base $pm_type_obj |
|
309 | - * @return EE_Payment_Method |
|
310 | - * @throws \EE_Error |
|
311 | - */ |
|
312 | - public function create_payment_method_of_type($pm_type_obj) |
|
313 | - { |
|
314 | - global $current_user; |
|
315 | - $payment_method = EE_Payment_Method::new_instance( |
|
316 | - array( |
|
317 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
318 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
319 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
320 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
321 | - 'PMD_wp_user' => $current_user->ID, |
|
322 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
323 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
324 | - ) * 10, |
|
325 | - ) |
|
326 | - ); |
|
327 | - return $payment_method; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Sets the initial payment method properties (including extra meta) |
|
334 | - * |
|
335 | - * @param EE_Payment_Method $payment_method |
|
336 | - * @return EE_Payment_Method |
|
337 | - * @throws \EE_Error |
|
338 | - */ |
|
339 | - public function initialize_payment_method($payment_method) |
|
340 | - { |
|
341 | - $pm_type_obj = $payment_method->type_obj(); |
|
342 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
343 | - if ( ! $payment_method->button_url()) { |
|
344 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
345 | - } |
|
346 | - //now add setup its default extra meta properties |
|
347 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
348 | - if ( ! empty($extra_metas)) { |
|
349 | - //verify the payment method has an ID before adding extra meta |
|
350 | - if ( ! $payment_method->ID()) { |
|
351 | - $payment_method->save(); |
|
352 | - } |
|
353 | - foreach ($extra_metas as $meta_name => $input) { |
|
354 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
355 | - } |
|
356 | - } |
|
357 | - return $payment_method; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * Makes sure the payment method is related to the specified payment method |
|
364 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
365 | - * @param EE_Payment_Method $payment_method |
|
366 | - * @return EE_Payment_Method |
|
367 | - * @throws \EE_Error |
|
368 | - */ |
|
369 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
370 | - { |
|
371 | - EE_Error::doing_it_wrong( |
|
372 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
373 | - esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
374 | - '4.9.40'); |
|
375 | - return $payment_method; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Deactivates a payment method of the given payment method slug. |
|
382 | - * |
|
383 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
384 | - * @return int count of rows updated. |
|
385 | - */ |
|
386 | - public function deactivate_payment_method($payment_method_slug) |
|
387 | - { |
|
388 | - EE_Log::instance()->log( |
|
389 | - __FILE__, |
|
390 | - __FUNCTION__, |
|
391 | - sprintf( |
|
392 | - __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
393 | - $payment_method_slug |
|
394 | - ), |
|
395 | - 'payment_method_change' |
|
396 | - ); |
|
397 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
398 | - array('PMD_scope' => array()), |
|
399 | - array(array('PMD_slug' => $payment_method_slug)) |
|
400 | - ); |
|
401 | - return $count_updated; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
408 | - * access caps. |
|
409 | - * |
|
410 | - * @param array $caps capabilities being filtered |
|
411 | - * @return array |
|
412 | - */ |
|
413 | - public function add_payment_method_caps($caps) |
|
414 | - { |
|
415 | - /* add dynamic caps from payment methods |
|
20 | + /** |
|
21 | + * instance of the EE_Payment_Method_Manager object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | + */ |
|
31 | + protected $_payment_method_types = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EE_Payment_Method_Manager instance |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Resets the instance and returns a new one |
|
54 | + * |
|
55 | + * @return EE_Payment_Method_Manager |
|
56 | + */ |
|
57 | + public static function reset() |
|
58 | + { |
|
59 | + self::$_instance = null; |
|
60 | + return self::instance(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * If necessary, re-register payment methods |
|
67 | + * |
|
68 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | + * we have not yet checked during this request, then we need to check anyways) |
|
71 | + */ |
|
72 | + public function maybe_register_payment_methods($force_recheck = false) |
|
73 | + { |
|
74 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | + $this->_register_payment_methods(); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * register_payment_methods |
|
83 | + * |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function _register_payment_methods() |
|
87 | + { |
|
88 | + // grab list of installed modules |
|
89 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
90 | + // filter list of modules to register |
|
91 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
92 | + $pm_to_register); |
|
93 | + // loop through folders |
|
94 | + foreach ($pm_to_register as $pm_path) { |
|
95 | + $this->register_payment_method($pm_path); |
|
96 | + } |
|
97 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
98 | + // filter list of installed modules |
|
99 | + //keep them organized alphabetically by the payment method type's name |
|
100 | + ksort($this->_payment_method_types); |
|
101 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
102 | + $this->_payment_method_types); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * register_payment_method- makes core aware of this payment method |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function register_payment_method($payment_method_path = '') |
|
115 | + { |
|
116 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
117 | + $module_ext = '.pm.php'; |
|
118 | + // make all separators match |
|
119 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
120 | + // grab and sanitize module name |
|
121 | + $module_dir = basename($payment_method_path); |
|
122 | + // create classname from module directory name |
|
123 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
124 | + // add class prefix |
|
125 | + $module_class = 'EE_PMT_' . $module; |
|
126 | + // does the module exist ? |
|
127 | + if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
128 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
129 | + 'event_espresso'), $module); |
|
130 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
131 | + return false; |
|
132 | + } |
|
133 | + if (WP_DEBUG === true) { |
|
134 | + EEH_Debug_Tools::instance()->start_timer(); |
|
135 | + } |
|
136 | + // load the module class file |
|
137 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
138 | + if (WP_DEBUG === true) { |
|
139 | + EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
140 | + } |
|
141 | + // verify that class exists |
|
142 | + if ( ! class_exists($module_class)) { |
|
143 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
144 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
145 | + return false; |
|
146 | + } |
|
147 | + // add to array of registered modules |
|
148 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
149 | + return true; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Checks if a payment method has been registered, and if so includes it |
|
156 | + * |
|
157 | + * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
158 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
159 | + * @return boolean |
|
160 | + */ |
|
161 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
162 | + { |
|
163 | + if ( |
|
164 | + $force_recheck |
|
165 | + || ! is_array($this->_payment_method_types) |
|
166 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
167 | + ) { |
|
168 | + $this->maybe_register_payment_methods($force_recheck); |
|
169 | + } |
|
170 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
171 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
172 | + return true; |
|
173 | + } else { |
|
174 | + return false; |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns all the classnames of the various payment method types |
|
182 | + * |
|
183 | + * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
184 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
185 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
189 | + { |
|
190 | + $this->maybe_register_payment_methods($force_recheck); |
|
191 | + if ($with_prefixes) { |
|
192 | + $classnames = array_keys($this->_payment_method_types); |
|
193 | + $payment_methods = array(); |
|
194 | + foreach ($classnames as $classname) { |
|
195 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
196 | + } |
|
197 | + return $payment_methods; |
|
198 | + } else { |
|
199 | + return array_keys($this->_payment_method_types); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Gets an object of each payment method type, none of which are bound to a |
|
207 | + * payment method instance |
|
208 | + * |
|
209 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
210 | + * @return EE_PMT_Base[] |
|
211 | + */ |
|
212 | + public function payment_method_types($force_recheck = false) |
|
213 | + { |
|
214 | + $this->maybe_register_payment_methods($force_recheck); |
|
215 | + $pmt_objs = array(); |
|
216 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
217 | + $pmt_objs[] = new $classname; |
|
218 | + } |
|
219 | + return $pmt_objs; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * Changes the payment method's classname into the payment method type's name |
|
226 | + * (as used on the payment method's table's PMD_type field) |
|
227 | + * |
|
228 | + * @param string $classname |
|
229 | + * @return string |
|
230 | + */ |
|
231 | + public function payment_method_type_sans_class_prefix($classname) |
|
232 | + { |
|
233 | + return str_replace("EE_PMT_", "", $classname); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Does the opposite of payment-method_type_sans_prefix |
|
240 | + * |
|
241 | + * @param string $type |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + public function payment_method_class_from_type($type) |
|
245 | + { |
|
246 | + $this->maybe_register_payment_methods(); |
|
247 | + return "EE_PMT_" . $type; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Activates a payment method of the given type. |
|
254 | + * |
|
255 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
256 | + * @return \EE_Payment_Method |
|
257 | + * @throws \EE_Error |
|
258 | + */ |
|
259 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
260 | + { |
|
261 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
262 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
263 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
264 | + if (class_exists($pm_type_class)) { |
|
265 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
266 | + $pm_type_obj = new $pm_type_class; |
|
267 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
268 | + if ( ! $payment_method) { |
|
269 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
270 | + } |
|
271 | + $payment_method->set_type($payment_method_type); |
|
272 | + $this->initialize_payment_method($payment_method); |
|
273 | + } else { |
|
274 | + throw new EE_Error( |
|
275 | + sprintf( |
|
276 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
277 | + $pm_type_class) |
|
278 | + ); |
|
279 | + } |
|
280 | + } |
|
281 | + $payment_method->set_active(); |
|
282 | + $payment_method->save(); |
|
283 | + if ($payment_method->type() === 'Invoice') { |
|
284 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
285 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
286 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
287 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
288 | + EE_Error::add_persistent_admin_notice( |
|
289 | + 'invoice_pm_requirements_notice', |
|
290 | + sprintf( |
|
291 | + __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
292 | + 'event_espresso'), |
|
293 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
294 | + '</a>' |
|
295 | + ), |
|
296 | + true |
|
297 | + ); |
|
298 | + } |
|
299 | + return $payment_method; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Creates a payment method of the specified type. Does not save it. |
|
306 | + * |
|
307 | + * @global WP_User $current_user |
|
308 | + * @param EE_PMT_Base $pm_type_obj |
|
309 | + * @return EE_Payment_Method |
|
310 | + * @throws \EE_Error |
|
311 | + */ |
|
312 | + public function create_payment_method_of_type($pm_type_obj) |
|
313 | + { |
|
314 | + global $current_user; |
|
315 | + $payment_method = EE_Payment_Method::new_instance( |
|
316 | + array( |
|
317 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
318 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
319 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
320 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
321 | + 'PMD_wp_user' => $current_user->ID, |
|
322 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
323 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
324 | + ) * 10, |
|
325 | + ) |
|
326 | + ); |
|
327 | + return $payment_method; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Sets the initial payment method properties (including extra meta) |
|
334 | + * |
|
335 | + * @param EE_Payment_Method $payment_method |
|
336 | + * @return EE_Payment_Method |
|
337 | + * @throws \EE_Error |
|
338 | + */ |
|
339 | + public function initialize_payment_method($payment_method) |
|
340 | + { |
|
341 | + $pm_type_obj = $payment_method->type_obj(); |
|
342 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
343 | + if ( ! $payment_method->button_url()) { |
|
344 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
345 | + } |
|
346 | + //now add setup its default extra meta properties |
|
347 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
348 | + if ( ! empty($extra_metas)) { |
|
349 | + //verify the payment method has an ID before adding extra meta |
|
350 | + if ( ! $payment_method->ID()) { |
|
351 | + $payment_method->save(); |
|
352 | + } |
|
353 | + foreach ($extra_metas as $meta_name => $input) { |
|
354 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
355 | + } |
|
356 | + } |
|
357 | + return $payment_method; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * Makes sure the payment method is related to the specified payment method |
|
364 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
365 | + * @param EE_Payment_Method $payment_method |
|
366 | + * @return EE_Payment_Method |
|
367 | + * @throws \EE_Error |
|
368 | + */ |
|
369 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
370 | + { |
|
371 | + EE_Error::doing_it_wrong( |
|
372 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
373 | + esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
374 | + '4.9.40'); |
|
375 | + return $payment_method; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Deactivates a payment method of the given payment method slug. |
|
382 | + * |
|
383 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
384 | + * @return int count of rows updated. |
|
385 | + */ |
|
386 | + public function deactivate_payment_method($payment_method_slug) |
|
387 | + { |
|
388 | + EE_Log::instance()->log( |
|
389 | + __FILE__, |
|
390 | + __FUNCTION__, |
|
391 | + sprintf( |
|
392 | + __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
393 | + $payment_method_slug |
|
394 | + ), |
|
395 | + 'payment_method_change' |
|
396 | + ); |
|
397 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
398 | + array('PMD_scope' => array()), |
|
399 | + array(array('PMD_slug' => $payment_method_slug)) |
|
400 | + ); |
|
401 | + return $count_updated; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
408 | + * access caps. |
|
409 | + * |
|
410 | + * @param array $caps capabilities being filtered |
|
411 | + * @return array |
|
412 | + */ |
|
413 | + public function add_payment_method_caps($caps) |
|
414 | + { |
|
415 | + /* add dynamic caps from payment methods |
|
416 | 416 | * at the time of writing, october 20 2014, these are the caps added: |
417 | 417 | * ee_payment_method_admin_only |
418 | 418 | * ee_payment_method_aim |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | * their related capability automatically added too, so long as they are |
427 | 427 | * registered properly using EE_Register_Payment_Method::register() |
428 | 428 | */ |
429 | - foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
430 | - $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
431 | - } |
|
432 | - return $caps; |
|
433 | - } |
|
429 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
430 | + $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
431 | + } |
|
432 | + return $caps; |
|
433 | + } |
|
434 | 434 | |
435 | 435 | } |