@@ -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 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
| 2 | 2 | |
| 3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -19,407 +19,407 @@ discard block |
||
| 19 | 19 | class EE_Payment_Method_Manager implements ResettableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * instance of the EE_Payment_Method_Manager object |
|
| 24 | - * |
|
| 25 | - * @var $_instance |
|
| 26 | - * @access private |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
| 32 | - */ |
|
| 33 | - protected $_payment_method_types = array(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @singleton method used to instantiate class object |
|
| 39 | - * @access public |
|
| 40 | - * @return EE_Payment_Method_Manager instance |
|
| 41 | - */ |
|
| 42 | - public static function instance() |
|
| 43 | - { |
|
| 44 | - // check if class object is instantiated, and instantiated properly |
|
| 45 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 46 | - self::$_instance = new self(); |
|
| 47 | - } |
|
| 48 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
| 49 | - return self::$_instance; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Resets the instance and returns a new one |
|
| 56 | - * |
|
| 57 | - * @return EE_Payment_Method_Manager |
|
| 58 | - */ |
|
| 59 | - public static function reset() |
|
| 60 | - { |
|
| 61 | - self::$_instance = null; |
|
| 62 | - return self::instance(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * If necessary, re-register payment methods |
|
| 69 | - * |
|
| 70 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
| 71 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
| 72 | - * we have not yet checked during this request, then we need to check anyways) |
|
| 73 | - */ |
|
| 74 | - public function maybe_register_payment_methods($force_recheck = false) |
|
| 75 | - { |
|
| 76 | - if ( ! $this->_payment_method_types || $force_recheck) { |
|
| 77 | - $this->_register_payment_methods(); |
|
| 78 | - //if in admin lets ensure caps are set. |
|
| 79 | - if (is_admin()) { |
|
| 80 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
| 81 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * register_payment_methods |
|
| 90 | - * |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - protected function _register_payment_methods() |
|
| 94 | - { |
|
| 95 | - // grab list of installed modules |
|
| 96 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 97 | - // filter list of modules to register |
|
| 98 | - $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 99 | - $pm_to_register); |
|
| 100 | - // loop through folders |
|
| 101 | - foreach ($pm_to_register as $pm_path) { |
|
| 102 | - $this->register_payment_method($pm_path); |
|
| 103 | - } |
|
| 104 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
| 105 | - // filter list of installed modules |
|
| 106 | - //keep them organized alphabetically by the payment method type's name |
|
| 107 | - ksort($this->_payment_method_types); |
|
| 108 | - return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
| 109 | - $this->_payment_method_types); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * register_payment_method- makes core aware of this payment method |
|
| 116 | - * |
|
| 117 | - * @access public |
|
| 118 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
| 119 | - * @return boolean |
|
| 120 | - */ |
|
| 121 | - public function register_payment_method($payment_method_path = '') |
|
| 122 | - { |
|
| 123 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
| 124 | - $module_ext = '.pm.php'; |
|
| 125 | - // make all separators match |
|
| 126 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
| 127 | - // grab and sanitize module name |
|
| 128 | - $module_dir = basename($payment_method_path); |
|
| 129 | - // create classname from module directory name |
|
| 130 | - $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
| 131 | - // add class prefix |
|
| 132 | - $module_class = 'EE_PMT_' . $module; |
|
| 133 | - // does the module exist ? |
|
| 134 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 135 | - $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
| 136 | - 'event_espresso'), $module); |
|
| 137 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - if (WP_DEBUG === true) { |
|
| 141 | - EEH_Debug_Tools::instance()->start_timer(); |
|
| 142 | - } |
|
| 143 | - // load the module class file |
|
| 144 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 145 | - if (WP_DEBUG === true) { |
|
| 146 | - EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
| 147 | - } |
|
| 148 | - // verify that class exists |
|
| 149 | - if ( ! class_exists($module_class)) { |
|
| 150 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 154 | - // add to array of registered modules |
|
| 155 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 156 | - return true; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Checks if a payment method has been registered, and if so includes it |
|
| 163 | - * |
|
| 164 | - * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
| 165 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 166 | - * @return boolean |
|
| 167 | - */ |
|
| 168 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
| 169 | - { |
|
| 170 | - if ( |
|
| 171 | - $force_recheck |
|
| 172 | - || ! is_array($this->_payment_method_types) |
|
| 173 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
| 174 | - ) { |
|
| 175 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 176 | - } |
|
| 177 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
| 178 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
| 179 | - return true; |
|
| 180 | - } else { |
|
| 181 | - return false; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Returns all the classnames of the various payment method types |
|
| 189 | - * |
|
| 190 | - * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
| 191 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
| 192 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
| 196 | - { |
|
| 197 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 198 | - if ($with_prefixes) { |
|
| 199 | - $classnames = array_keys($this->_payment_method_types); |
|
| 200 | - $payment_methods = array(); |
|
| 201 | - foreach ($classnames as $classname) { |
|
| 202 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
| 203 | - } |
|
| 204 | - return $payment_methods; |
|
| 205 | - } else { |
|
| 206 | - return array_keys($this->_payment_method_types); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Gets an object of each payment method type, none of which are bound to a |
|
| 214 | - * payment method instance |
|
| 215 | - * |
|
| 216 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 217 | - * @return EE_PMT_Base[] |
|
| 218 | - */ |
|
| 219 | - public function payment_method_types($force_recheck = false) |
|
| 220 | - { |
|
| 221 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 222 | - $pmt_objs = array(); |
|
| 223 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
| 224 | - $pmt_objs[] = new $classname; |
|
| 225 | - } |
|
| 226 | - return $pmt_objs; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Changes the payment method's classname into the payment method type's name |
|
| 233 | - * (as used on the payment method's table's PMD_type field) |
|
| 234 | - * |
|
| 235 | - * @param string $classname |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function payment_method_type_sans_class_prefix($classname) |
|
| 239 | - { |
|
| 240 | - return str_replace("EE_PMT_", "", $classname); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Does the opposite of payment-method_type_sans_prefix |
|
| 247 | - * |
|
| 248 | - * @param string $type |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function payment_method_class_from_type($type) |
|
| 252 | - { |
|
| 253 | - $this->maybe_register_payment_methods(); |
|
| 254 | - return "EE_PMT_" . $type; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Activates a payment method of the given type. |
|
| 261 | - * |
|
| 262 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
| 263 | - * @return \EE_Payment_Method |
|
| 264 | - * @throws \EE_Error |
|
| 265 | - */ |
|
| 266 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
| 267 | - { |
|
| 268 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
| 269 | - if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 270 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
| 271 | - if (class_exists($pm_type_class)) { |
|
| 272 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
| 273 | - $pm_type_obj = new $pm_type_class; |
|
| 274 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
| 275 | - if ( ! $payment_method) { |
|
| 276 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
| 277 | - } |
|
| 278 | - $payment_method->set_type($payment_method_type); |
|
| 279 | - $this->initialize_payment_method($payment_method); |
|
| 280 | - } else { |
|
| 281 | - throw new EE_Error( |
|
| 282 | - sprintf( |
|
| 283 | - __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
| 284 | - $pm_type_class) |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - $payment_method->set_active(); |
|
| 289 | - $payment_method->save(); |
|
| 290 | - if ($payment_method->type() === 'Invoice') { |
|
| 291 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 292 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 293 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
| 294 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
| 295 | - EE_Error::add_persistent_admin_notice( |
|
| 296 | - 'invoice_pm_requirements_notice', |
|
| 297 | - sprintf( |
|
| 298 | - __('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.', |
|
| 299 | - 'event_espresso'), |
|
| 300 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 301 | - '</a>' |
|
| 302 | - ), |
|
| 303 | - true |
|
| 304 | - ); |
|
| 305 | - } |
|
| 306 | - return $payment_method; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Creates a payment method of the specified type. Does not save it. |
|
| 313 | - * |
|
| 314 | - * @global WP_User $current_user |
|
| 315 | - * @param EE_PMT_Base $pm_type_obj |
|
| 316 | - * @return EE_Payment_Method |
|
| 317 | - * @throws \EE_Error |
|
| 318 | - */ |
|
| 319 | - public function create_payment_method_of_type($pm_type_obj) |
|
| 320 | - { |
|
| 321 | - global $current_user; |
|
| 322 | - $payment_method = EE_Payment_Method::new_instance( |
|
| 323 | - array( |
|
| 324 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
| 325 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
| 326 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
| 327 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 328 | - 'PMD_wp_user' => $current_user->ID, |
|
| 329 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
| 330 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
| 331 | - ) * 10, |
|
| 332 | - ) |
|
| 333 | - ); |
|
| 334 | - return $payment_method; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Sets the initial payment method properties (including extra meta) |
|
| 341 | - * |
|
| 342 | - * @param EE_Payment_Method $payment_method |
|
| 343 | - * @return EE_Payment_Method |
|
| 344 | - * @throws \EE_Error |
|
| 345 | - */ |
|
| 346 | - public function initialize_payment_method($payment_method) |
|
| 347 | - { |
|
| 348 | - $pm_type_obj = $payment_method->type_obj(); |
|
| 349 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
| 350 | - if ( ! $payment_method->button_url()) { |
|
| 351 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
| 352 | - } |
|
| 353 | - //now add setup its default extra meta properties |
|
| 354 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
| 355 | - if ( ! empty($extra_metas)) { |
|
| 356 | - //verify the payment method has an ID before adding extra meta |
|
| 357 | - if ( ! $payment_method->ID()) { |
|
| 358 | - $payment_method->save(); |
|
| 359 | - } |
|
| 360 | - foreach ($extra_metas as $meta_name => $input) { |
|
| 361 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - return $payment_method; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Makes sure the payment method is related to the specified payment method |
|
| 371 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
| 372 | - * @param EE_Payment_Method $payment_method |
|
| 373 | - * @return EE_Payment_Method |
|
| 374 | - * @throws \EE_Error |
|
| 375 | - */ |
|
| 376 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
| 377 | - { |
|
| 378 | - EE_Error::doing_it_wrong( |
|
| 379 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
| 380 | - esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
| 381 | - '4.9.40'); |
|
| 382 | - return $payment_method; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Deactivates a payment method of the given payment method slug. |
|
| 389 | - * |
|
| 390 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
| 391 | - * @return int count of rows updated. |
|
| 392 | - */ |
|
| 393 | - public function deactivate_payment_method($payment_method_slug) |
|
| 394 | - { |
|
| 395 | - EE_Log::instance()->log( |
|
| 396 | - __FILE__, |
|
| 397 | - __FUNCTION__, |
|
| 398 | - sprintf( |
|
| 399 | - __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
| 400 | - $payment_method_slug |
|
| 401 | - ), |
|
| 402 | - 'payment_method_change' |
|
| 403 | - ); |
|
| 404 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
| 405 | - array('PMD_scope' => array()), |
|
| 406 | - array(array('PMD_slug' => $payment_method_slug)) |
|
| 407 | - ); |
|
| 408 | - return $count_updated; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
| 415 | - * access caps. |
|
| 416 | - * |
|
| 417 | - * @param array $caps capabilities being filtered |
|
| 418 | - * @return array |
|
| 419 | - */ |
|
| 420 | - public function add_payment_method_caps($caps) |
|
| 421 | - { |
|
| 422 | - /* add dynamic caps from payment methods |
|
| 22 | + /** |
|
| 23 | + * instance of the EE_Payment_Method_Manager object |
|
| 24 | + * |
|
| 25 | + * @var $_instance |
|
| 26 | + * @access private |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
| 32 | + */ |
|
| 33 | + protected $_payment_method_types = array(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @singleton method used to instantiate class object |
|
| 39 | + * @access public |
|
| 40 | + * @return EE_Payment_Method_Manager instance |
|
| 41 | + */ |
|
| 42 | + public static function instance() |
|
| 43 | + { |
|
| 44 | + // check if class object is instantiated, and instantiated properly |
|
| 45 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 46 | + self::$_instance = new self(); |
|
| 47 | + } |
|
| 48 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
| 49 | + return self::$_instance; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Resets the instance and returns a new one |
|
| 56 | + * |
|
| 57 | + * @return EE_Payment_Method_Manager |
|
| 58 | + */ |
|
| 59 | + public static function reset() |
|
| 60 | + { |
|
| 61 | + self::$_instance = null; |
|
| 62 | + return self::instance(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * If necessary, re-register payment methods |
|
| 69 | + * |
|
| 70 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
| 71 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
| 72 | + * we have not yet checked during this request, then we need to check anyways) |
|
| 73 | + */ |
|
| 74 | + public function maybe_register_payment_methods($force_recheck = false) |
|
| 75 | + { |
|
| 76 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
| 77 | + $this->_register_payment_methods(); |
|
| 78 | + //if in admin lets ensure caps are set. |
|
| 79 | + if (is_admin()) { |
|
| 80 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
| 81 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * register_payment_methods |
|
| 90 | + * |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + protected function _register_payment_methods() |
|
| 94 | + { |
|
| 95 | + // grab list of installed modules |
|
| 96 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 97 | + // filter list of modules to register |
|
| 98 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 99 | + $pm_to_register); |
|
| 100 | + // loop through folders |
|
| 101 | + foreach ($pm_to_register as $pm_path) { |
|
| 102 | + $this->register_payment_method($pm_path); |
|
| 103 | + } |
|
| 104 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
| 105 | + // filter list of installed modules |
|
| 106 | + //keep them organized alphabetically by the payment method type's name |
|
| 107 | + ksort($this->_payment_method_types); |
|
| 108 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
| 109 | + $this->_payment_method_types); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * register_payment_method- makes core aware of this payment method |
|
| 116 | + * |
|
| 117 | + * @access public |
|
| 118 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
| 119 | + * @return boolean |
|
| 120 | + */ |
|
| 121 | + public function register_payment_method($payment_method_path = '') |
|
| 122 | + { |
|
| 123 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
| 124 | + $module_ext = '.pm.php'; |
|
| 125 | + // make all separators match |
|
| 126 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
| 127 | + // grab and sanitize module name |
|
| 128 | + $module_dir = basename($payment_method_path); |
|
| 129 | + // create classname from module directory name |
|
| 130 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
| 131 | + // add class prefix |
|
| 132 | + $module_class = 'EE_PMT_' . $module; |
|
| 133 | + // does the module exist ? |
|
| 134 | + if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 135 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
| 136 | + 'event_espresso'), $module); |
|
| 137 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + if (WP_DEBUG === true) { |
|
| 141 | + EEH_Debug_Tools::instance()->start_timer(); |
|
| 142 | + } |
|
| 143 | + // load the module class file |
|
| 144 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 145 | + if (WP_DEBUG === true) { |
|
| 146 | + EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
| 147 | + } |
|
| 148 | + // verify that class exists |
|
| 149 | + if ( ! class_exists($module_class)) { |
|
| 150 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 151 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | + // add to array of registered modules |
|
| 155 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 156 | + return true; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Checks if a payment method has been registered, and if so includes it |
|
| 163 | + * |
|
| 164 | + * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
| 165 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 166 | + * @return boolean |
|
| 167 | + */ |
|
| 168 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
| 169 | + { |
|
| 170 | + if ( |
|
| 171 | + $force_recheck |
|
| 172 | + || ! is_array($this->_payment_method_types) |
|
| 173 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
| 174 | + ) { |
|
| 175 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 176 | + } |
|
| 177 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
| 178 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
| 179 | + return true; |
|
| 180 | + } else { |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Returns all the classnames of the various payment method types |
|
| 189 | + * |
|
| 190 | + * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
| 191 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
| 192 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
| 196 | + { |
|
| 197 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 198 | + if ($with_prefixes) { |
|
| 199 | + $classnames = array_keys($this->_payment_method_types); |
|
| 200 | + $payment_methods = array(); |
|
| 201 | + foreach ($classnames as $classname) { |
|
| 202 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
| 203 | + } |
|
| 204 | + return $payment_methods; |
|
| 205 | + } else { |
|
| 206 | + return array_keys($this->_payment_method_types); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Gets an object of each payment method type, none of which are bound to a |
|
| 214 | + * payment method instance |
|
| 215 | + * |
|
| 216 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 217 | + * @return EE_PMT_Base[] |
|
| 218 | + */ |
|
| 219 | + public function payment_method_types($force_recheck = false) |
|
| 220 | + { |
|
| 221 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 222 | + $pmt_objs = array(); |
|
| 223 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
| 224 | + $pmt_objs[] = new $classname; |
|
| 225 | + } |
|
| 226 | + return $pmt_objs; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Changes the payment method's classname into the payment method type's name |
|
| 233 | + * (as used on the payment method's table's PMD_type field) |
|
| 234 | + * |
|
| 235 | + * @param string $classname |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function payment_method_type_sans_class_prefix($classname) |
|
| 239 | + { |
|
| 240 | + return str_replace("EE_PMT_", "", $classname); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Does the opposite of payment-method_type_sans_prefix |
|
| 247 | + * |
|
| 248 | + * @param string $type |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function payment_method_class_from_type($type) |
|
| 252 | + { |
|
| 253 | + $this->maybe_register_payment_methods(); |
|
| 254 | + return "EE_PMT_" . $type; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Activates a payment method of the given type. |
|
| 261 | + * |
|
| 262 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
| 263 | + * @return \EE_Payment_Method |
|
| 264 | + * @throws \EE_Error |
|
| 265 | + */ |
|
| 266 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
| 267 | + { |
|
| 268 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
| 269 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 270 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
| 271 | + if (class_exists($pm_type_class)) { |
|
| 272 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
| 273 | + $pm_type_obj = new $pm_type_class; |
|
| 274 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
| 275 | + if ( ! $payment_method) { |
|
| 276 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
| 277 | + } |
|
| 278 | + $payment_method->set_type($payment_method_type); |
|
| 279 | + $this->initialize_payment_method($payment_method); |
|
| 280 | + } else { |
|
| 281 | + throw new EE_Error( |
|
| 282 | + sprintf( |
|
| 283 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
| 284 | + $pm_type_class) |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + $payment_method->set_active(); |
|
| 289 | + $payment_method->save(); |
|
| 290 | + if ($payment_method->type() === 'Invoice') { |
|
| 291 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 292 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 293 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
| 294 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
| 295 | + EE_Error::add_persistent_admin_notice( |
|
| 296 | + 'invoice_pm_requirements_notice', |
|
| 297 | + sprintf( |
|
| 298 | + __('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.', |
|
| 299 | + 'event_espresso'), |
|
| 300 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 301 | + '</a>' |
|
| 302 | + ), |
|
| 303 | + true |
|
| 304 | + ); |
|
| 305 | + } |
|
| 306 | + return $payment_method; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Creates a payment method of the specified type. Does not save it. |
|
| 313 | + * |
|
| 314 | + * @global WP_User $current_user |
|
| 315 | + * @param EE_PMT_Base $pm_type_obj |
|
| 316 | + * @return EE_Payment_Method |
|
| 317 | + * @throws \EE_Error |
|
| 318 | + */ |
|
| 319 | + public function create_payment_method_of_type($pm_type_obj) |
|
| 320 | + { |
|
| 321 | + global $current_user; |
|
| 322 | + $payment_method = EE_Payment_Method::new_instance( |
|
| 323 | + array( |
|
| 324 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
| 325 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
| 326 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
| 327 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 328 | + 'PMD_wp_user' => $current_user->ID, |
|
| 329 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
| 330 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
| 331 | + ) * 10, |
|
| 332 | + ) |
|
| 333 | + ); |
|
| 334 | + return $payment_method; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Sets the initial payment method properties (including extra meta) |
|
| 341 | + * |
|
| 342 | + * @param EE_Payment_Method $payment_method |
|
| 343 | + * @return EE_Payment_Method |
|
| 344 | + * @throws \EE_Error |
|
| 345 | + */ |
|
| 346 | + public function initialize_payment_method($payment_method) |
|
| 347 | + { |
|
| 348 | + $pm_type_obj = $payment_method->type_obj(); |
|
| 349 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
| 350 | + if ( ! $payment_method->button_url()) { |
|
| 351 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
| 352 | + } |
|
| 353 | + //now add setup its default extra meta properties |
|
| 354 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
| 355 | + if ( ! empty($extra_metas)) { |
|
| 356 | + //verify the payment method has an ID before adding extra meta |
|
| 357 | + if ( ! $payment_method->ID()) { |
|
| 358 | + $payment_method->save(); |
|
| 359 | + } |
|
| 360 | + foreach ($extra_metas as $meta_name => $input) { |
|
| 361 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + return $payment_method; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Makes sure the payment method is related to the specified payment method |
|
| 371 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
| 372 | + * @param EE_Payment_Method $payment_method |
|
| 373 | + * @return EE_Payment_Method |
|
| 374 | + * @throws \EE_Error |
|
| 375 | + */ |
|
| 376 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
| 377 | + { |
|
| 378 | + EE_Error::doing_it_wrong( |
|
| 379 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
| 380 | + esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
| 381 | + '4.9.40'); |
|
| 382 | + return $payment_method; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Deactivates a payment method of the given payment method slug. |
|
| 389 | + * |
|
| 390 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
| 391 | + * @return int count of rows updated. |
|
| 392 | + */ |
|
| 393 | + public function deactivate_payment_method($payment_method_slug) |
|
| 394 | + { |
|
| 395 | + EE_Log::instance()->log( |
|
| 396 | + __FILE__, |
|
| 397 | + __FUNCTION__, |
|
| 398 | + sprintf( |
|
| 399 | + __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
| 400 | + $payment_method_slug |
|
| 401 | + ), |
|
| 402 | + 'payment_method_change' |
|
| 403 | + ); |
|
| 404 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
| 405 | + array('PMD_scope' => array()), |
|
| 406 | + array(array('PMD_slug' => $payment_method_slug)) |
|
| 407 | + ); |
|
| 408 | + return $count_updated; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
| 415 | + * access caps. |
|
| 416 | + * |
|
| 417 | + * @param array $caps capabilities being filtered |
|
| 418 | + * @return array |
|
| 419 | + */ |
|
| 420 | + public function add_payment_method_caps($caps) |
|
| 421 | + { |
|
| 422 | + /* add dynamic caps from payment methods |
|
| 423 | 423 | * at the time of writing, october 20 2014, these are the caps added: |
| 424 | 424 | * ee_payment_method_admin_only |
| 425 | 425 | * ee_payment_method_aim |
@@ -433,10 +433,10 @@ discard block |
||
| 433 | 433 | * their related capability automatically added too, so long as they are |
| 434 | 434 | * registered properly using EE_Register_Payment_Method::register() |
| 435 | 435 | */ |
| 436 | - foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
| 437 | - $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
| 438 | - } |
|
| 439 | - return $caps; |
|
| 440 | - } |
|
| 436 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
| 437 | + $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
| 438 | + } |
|
| 439 | + return $caps; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | } |
@@ -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.002'); |
|
| 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.002'); |
|
| 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 |