@@ -18,1000 +18,1000 @@ discard block |
||
| 18 | 18 | final class EE_Capabilities extends EE_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the name of the wp option used to store caps previously initialized |
|
| 23 | - */ |
|
| 24 | - const option_name = 'ee_caps_initialized'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * instance of EE_Capabilities object |
|
| 28 | - * |
|
| 29 | - * @var EE_Capabilities |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | - * Array is indexed by Role and values are ee capabilities. |
|
| 37 | - * |
|
| 38 | - * @since 4.5.0 |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $capabilities_map = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | - * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | - * |
|
| 48 | - * @var EE_Meta_Capability_Map[] |
|
| 49 | - */ |
|
| 50 | - private $_meta_caps = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | - * This flag tracks whether that has happened or not. |
|
| 55 | - * But for this to work, we need three states to indicate: |
|
| 56 | - * initialization has not occurred at all |
|
| 57 | - * initialization has started but is not complete |
|
| 58 | - * initialization is complete |
|
| 59 | - * The reason this is needed is because the addCaps() method |
|
| 60 | - * normally requires the $capabilities_map to be initialized, |
|
| 61 | - * but is also used during the initialization process. |
|
| 62 | - * So: |
|
| 63 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | - * |
|
| 67 | - * @var boolean|null $initialized |
|
| 68 | - */ |
|
| 69 | - private $initialized; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var boolean $reset |
|
| 73 | - */ |
|
| 74 | - private $reset = false; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * singleton method used to instantiate class object |
|
| 80 | - * |
|
| 81 | - * @since 4.5.0 |
|
| 82 | - * |
|
| 83 | - * @return EE_Capabilities |
|
| 84 | - */ |
|
| 85 | - public static function instance() |
|
| 86 | - { |
|
| 87 | - //check if instantiated, and if not do so. |
|
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | - self::$_instance = new self(); |
|
| 90 | - } |
|
| 91 | - return self::$_instance; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * private constructor |
|
| 98 | - * |
|
| 99 | - * @since 4.5.0 |
|
| 100 | - */ |
|
| 101 | - private function __construct() |
|
| 102 | - { |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | - * |
|
| 110 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | - * ensures that they are up to date. |
|
| 113 | - * |
|
| 114 | - * @since 4.5.0 |
|
| 115 | - * @return bool |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function init_caps($reset = false) |
|
| 119 | - { |
|
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | - if ($this->reset) { |
|
| 126 | - $this->initialized = null; |
|
| 127 | - $this->capabilities_map = array(); |
|
| 128 | - delete_option(self::option_name); |
|
| 129 | - } |
|
| 130 | - if ($this->initialized === null) { |
|
| 131 | - $this->initialized = false; |
|
| 132 | - do_action( |
|
| 133 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | - $this->reset |
|
| 135 | - ); |
|
| 136 | - $this->addCaps($this->_init_caps_map()); |
|
| 137 | - $this->_set_meta_caps(); |
|
| 138 | - do_action( |
|
| 139 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | - $this->capabilities_map |
|
| 141 | - ); |
|
| 142 | - $this->initialized = true; |
|
| 143 | - } |
|
| 144 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | - $this->reset = false; |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * This sets the meta caps property. |
|
| 154 | - * |
|
| 155 | - * @since 4.5.0 |
|
| 156 | - * @return void |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - private function _set_meta_caps() |
|
| 160 | - { |
|
| 161 | - // get default meta caps and filter the returned array |
|
| 162 | - $this->_meta_caps = apply_filters( |
|
| 163 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 164 | - $this->_get_default_meta_caps_array() |
|
| 165 | - ); |
|
| 166 | - //add filter for map_meta_caps but only if models can query. |
|
| 167 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * This builds and returns the default meta_caps array only once. |
|
| 176 | - * |
|
| 177 | - * @since 4.8.28.rc.012 |
|
| 178 | - * @return array |
|
| 179 | - * @throws EE_Error |
|
| 180 | - */ |
|
| 181 | - private function _get_default_meta_caps_array() |
|
| 182 | - { |
|
| 183 | - static $default_meta_caps = array(); |
|
| 184 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 185 | - if (empty($default_meta_caps)) { |
|
| 186 | - $default_meta_caps = array( |
|
| 187 | - //edits |
|
| 188 | - new EE_Meta_Capability_Map_Edit( |
|
| 189 | - 'ee_edit_event', |
|
| 190 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 191 | - ), |
|
| 192 | - new EE_Meta_Capability_Map_Edit( |
|
| 193 | - 'ee_edit_venue', |
|
| 194 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 195 | - ), |
|
| 196 | - new EE_Meta_Capability_Map_Edit( |
|
| 197 | - 'ee_edit_registration', |
|
| 198 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 199 | - ), |
|
| 200 | - new EE_Meta_Capability_Map_Edit( |
|
| 201 | - 'ee_edit_checkin', |
|
| 202 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 203 | - ), |
|
| 204 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 205 | - 'ee_edit_message', |
|
| 206 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 207 | - ), |
|
| 208 | - new EE_Meta_Capability_Map_Edit( |
|
| 209 | - 'ee_edit_default_ticket', |
|
| 210 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 211 | - ), |
|
| 212 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 213 | - 'ee_edit_question', |
|
| 214 | - array('Question', '', '', 'ee_edit_system_questions') |
|
| 215 | - ), |
|
| 216 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 217 | - 'ee_edit_question_group', |
|
| 218 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 219 | - ), |
|
| 220 | - new EE_Meta_Capability_Map_Edit( |
|
| 221 | - 'ee_edit_payment_method', |
|
| 222 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 223 | - ), |
|
| 224 | - //reads |
|
| 225 | - new EE_Meta_Capability_Map_Read( |
|
| 226 | - 'ee_read_event', |
|
| 227 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 228 | - ), |
|
| 229 | - new EE_Meta_Capability_Map_Read( |
|
| 230 | - 'ee_read_venue', |
|
| 231 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 232 | - ), |
|
| 233 | - new EE_Meta_Capability_Map_Read( |
|
| 234 | - 'ee_read_registration', |
|
| 235 | - array('Registration', '', 'ee_read_others_registrations', '') |
|
| 236 | - ), |
|
| 237 | - new EE_Meta_Capability_Map_Read( |
|
| 238 | - 'ee_read_checkin', |
|
| 239 | - array('Registration', '', 'ee_read_others_checkins', '') |
|
| 240 | - ), |
|
| 241 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 242 | - 'ee_read_message', |
|
| 243 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 244 | - ), |
|
| 245 | - new EE_Meta_Capability_Map_Read( |
|
| 246 | - 'ee_read_default_ticket', |
|
| 247 | - array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 248 | - ), |
|
| 249 | - new EE_Meta_Capability_Map_Read( |
|
| 250 | - 'ee_read_payment_method', |
|
| 251 | - array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 252 | - ), |
|
| 253 | - //deletes |
|
| 254 | - new EE_Meta_Capability_Map_Delete( |
|
| 255 | - 'ee_delete_event', |
|
| 256 | - array( |
|
| 257 | - 'Event', |
|
| 258 | - 'ee_delete_published_events', |
|
| 259 | - 'ee_delete_others_events', |
|
| 260 | - 'ee_delete_private_events', |
|
| 261 | - ) |
|
| 262 | - ), |
|
| 263 | - new EE_Meta_Capability_Map_Delete( |
|
| 264 | - 'ee_delete_venue', |
|
| 265 | - array( |
|
| 266 | - 'Venue', |
|
| 267 | - 'ee_delete_published_venues', |
|
| 268 | - 'ee_delete_others_venues', |
|
| 269 | - 'ee_delete_private_venues', |
|
| 270 | - ) |
|
| 271 | - ), |
|
| 272 | - new EE_Meta_Capability_Map_Delete( |
|
| 273 | - 'ee_delete_registration', |
|
| 274 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 275 | - ), |
|
| 276 | - new EE_Meta_Capability_Map_Delete( |
|
| 277 | - 'ee_delete_checkin', |
|
| 278 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 279 | - ), |
|
| 280 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 281 | - 'ee_delete_message', |
|
| 282 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 283 | - ), |
|
| 284 | - new EE_Meta_Capability_Map_Delete( |
|
| 285 | - 'ee_delete_default_ticket', |
|
| 286 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 287 | - ), |
|
| 288 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 289 | - 'ee_delete_question', |
|
| 290 | - array('Question', '', '', 'delete_system_questions') |
|
| 291 | - ), |
|
| 292 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 293 | - 'ee_delete_question_group', |
|
| 294 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 295 | - ), |
|
| 296 | - new EE_Meta_Capability_Map_Delete( |
|
| 297 | - 'ee_delete_payment_method', |
|
| 298 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 299 | - ), |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - return $default_meta_caps; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 309 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 310 | - * |
|
| 311 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 312 | - * |
|
| 313 | - * @since 4.5.0 |
|
| 314 | - * @see wp-includes/capabilities.php |
|
| 315 | - * |
|
| 316 | - * @param array $caps actual users capabilities |
|
| 317 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 318 | - * @param int $user_id The user id |
|
| 319 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 320 | - * @return array actual users capabilities |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 324 | - { |
|
| 325 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 326 | - //loop through our _meta_caps array |
|
| 327 | - foreach ($this->_meta_caps as $meta_map) { |
|
| 328 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | - continue; |
|
| 330 | - } |
|
| 331 | - // don't load models if there is no object ID in the args |
|
| 332 | - if (! empty($args[0])) { |
|
| 333 | - $meta_map->ensure_is_model(); |
|
| 334 | - } |
|
| 335 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - return $caps; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
| 345 | - * Note this array is filtered. |
|
| 346 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 347 | - * |
|
| 348 | - * @since 4.5.0 |
|
| 349 | - * |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - private function _init_caps_map() |
|
| 353 | - { |
|
| 354 | - return apply_filters( |
|
| 355 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 356 | - array( |
|
| 357 | - 'administrator' => array( |
|
| 358 | - //basic access |
|
| 359 | - 'ee_read_ee', |
|
| 360 | - //gateways |
|
| 361 | - /** |
|
| 362 | - * note that with payment method capabilities, although we've implemented |
|
| 363 | - * capability mapping which will be used for accessing payment methods owned by |
|
| 364 | - * other users. This is not fully implemented yet in the payment method ui. |
|
| 365 | - * Currently only the "plural" caps are in active use. |
|
| 366 | - * (Specific payment method caps are in use as well). |
|
| 367 | - **/ |
|
| 368 | - 'ee_manage_gateways', |
|
| 369 | - 'ee_read_payment_methods', |
|
| 370 | - 'ee_read_others_payment_methods', |
|
| 371 | - 'ee_edit_payment_methods', |
|
| 372 | - 'ee_edit_others_payment_methods', |
|
| 373 | - 'ee_delete_payment_methods', |
|
| 374 | - //events |
|
| 375 | - 'ee_publish_events', |
|
| 376 | - 'ee_read_private_events', |
|
| 377 | - 'ee_read_others_events', |
|
| 378 | - 'ee_read_events', |
|
| 379 | - 'ee_edit_events', |
|
| 380 | - 'ee_edit_published_events', |
|
| 381 | - 'ee_edit_others_events', |
|
| 382 | - 'ee_edit_private_events', |
|
| 383 | - 'ee_delete_published_events', |
|
| 384 | - 'ee_delete_private_events', |
|
| 385 | - 'ee_delete_events', |
|
| 386 | - 'ee_delete_others_events', |
|
| 387 | - //event categories |
|
| 388 | - 'ee_manage_event_categories', |
|
| 389 | - 'ee_edit_event_category', |
|
| 390 | - 'ee_delete_event_category', |
|
| 391 | - 'ee_assign_event_category', |
|
| 392 | - //venues |
|
| 393 | - 'ee_publish_venues', |
|
| 394 | - 'ee_read_venues', |
|
| 395 | - 'ee_read_others_venues', |
|
| 396 | - 'ee_read_private_venues', |
|
| 397 | - 'ee_edit_venues', |
|
| 398 | - 'ee_edit_others_venues', |
|
| 399 | - 'ee_edit_published_venues', |
|
| 400 | - 'ee_edit_private_venues', |
|
| 401 | - 'ee_delete_venues', |
|
| 402 | - 'ee_delete_others_venues', |
|
| 403 | - 'ee_delete_private_venues', |
|
| 404 | - 'ee_delete_published_venues', |
|
| 405 | - //venue categories |
|
| 406 | - 'ee_manage_venue_categories', |
|
| 407 | - 'ee_edit_venue_category', |
|
| 408 | - 'ee_delete_venue_category', |
|
| 409 | - 'ee_assign_venue_category', |
|
| 410 | - //contacts |
|
| 411 | - 'ee_read_contacts', |
|
| 412 | - 'ee_edit_contacts', |
|
| 413 | - 'ee_delete_contacts', |
|
| 414 | - //registrations |
|
| 415 | - 'ee_read_registrations', |
|
| 416 | - 'ee_read_others_registrations', |
|
| 417 | - 'ee_edit_registrations', |
|
| 418 | - 'ee_edit_others_registrations', |
|
| 419 | - 'ee_delete_registrations', |
|
| 420 | - //checkins |
|
| 421 | - 'ee_read_others_checkins', |
|
| 422 | - 'ee_read_checkins', |
|
| 423 | - 'ee_edit_checkins', |
|
| 424 | - 'ee_edit_others_checkins', |
|
| 425 | - 'ee_delete_checkins', |
|
| 426 | - 'ee_delete_others_checkins', |
|
| 427 | - //transactions && payments |
|
| 428 | - 'ee_read_transaction', |
|
| 429 | - 'ee_read_transactions', |
|
| 430 | - 'ee_edit_payments', |
|
| 431 | - 'ee_delete_payments', |
|
| 432 | - //messages |
|
| 433 | - 'ee_read_messages', |
|
| 434 | - 'ee_read_others_messages', |
|
| 435 | - 'ee_read_global_messages', |
|
| 436 | - 'ee_edit_global_messages', |
|
| 437 | - 'ee_edit_messages', |
|
| 438 | - 'ee_edit_others_messages', |
|
| 439 | - 'ee_delete_messages', |
|
| 440 | - 'ee_delete_others_messages', |
|
| 441 | - 'ee_delete_global_messages', |
|
| 442 | - 'ee_send_message', |
|
| 443 | - //tickets |
|
| 444 | - 'ee_read_default_tickets', |
|
| 445 | - 'ee_read_others_default_tickets', |
|
| 446 | - 'ee_edit_default_tickets', |
|
| 447 | - 'ee_edit_others_default_tickets', |
|
| 448 | - 'ee_delete_default_tickets', |
|
| 449 | - 'ee_delete_others_default_tickets', |
|
| 450 | - //prices |
|
| 451 | - 'ee_edit_default_price', |
|
| 452 | - 'ee_edit_default_prices', |
|
| 453 | - 'ee_delete_default_price', |
|
| 454 | - 'ee_delete_default_prices', |
|
| 455 | - 'ee_edit_default_price_type', |
|
| 456 | - 'ee_edit_default_price_types', |
|
| 457 | - 'ee_delete_default_price_type', |
|
| 458 | - 'ee_delete_default_price_types', |
|
| 459 | - 'ee_read_default_prices', |
|
| 460 | - 'ee_read_default_price_types', |
|
| 461 | - //registration form |
|
| 462 | - 'ee_edit_questions', |
|
| 463 | - 'ee_edit_system_questions', |
|
| 464 | - 'ee_read_questions', |
|
| 465 | - 'ee_delete_questions', |
|
| 466 | - 'ee_edit_question_groups', |
|
| 467 | - 'ee_read_question_groups', |
|
| 468 | - 'ee_edit_system_question_groups', |
|
| 469 | - 'ee_delete_question_groups', |
|
| 470 | - //event_type taxonomy |
|
| 471 | - 'ee_assign_event_type', |
|
| 472 | - 'ee_manage_event_types', |
|
| 473 | - 'ee_edit_event_type', |
|
| 474 | - 'ee_delete_event_type', |
|
| 475 | - ), |
|
| 476 | - 'ee_events_administrator' => array( |
|
| 477 | - //core wp caps |
|
| 478 | - 'read', |
|
| 479 | - 'read_private_pages', |
|
| 480 | - 'read_private_posts', |
|
| 481 | - 'edit_users', |
|
| 482 | - 'edit_posts', |
|
| 483 | - 'edit_pages', |
|
| 484 | - 'edit_published_posts', |
|
| 485 | - 'edit_published_pages', |
|
| 486 | - 'edit_private_pages', |
|
| 487 | - 'edit_private_posts', |
|
| 488 | - 'edit_others_posts', |
|
| 489 | - 'edit_others_pages', |
|
| 490 | - 'publish_posts', |
|
| 491 | - 'publish_pages', |
|
| 492 | - 'delete_posts', |
|
| 493 | - 'delete_pages', |
|
| 494 | - 'delete_private_pages', |
|
| 495 | - 'delete_private_posts', |
|
| 496 | - 'delete_published_pages', |
|
| 497 | - 'delete_published_posts', |
|
| 498 | - 'delete_others_posts', |
|
| 499 | - 'delete_others_pages', |
|
| 500 | - 'manage_categories', |
|
| 501 | - 'manage_links', |
|
| 502 | - 'moderate_comments', |
|
| 503 | - 'unfiltered_html', |
|
| 504 | - 'upload_files', |
|
| 505 | - 'export', |
|
| 506 | - 'import', |
|
| 507 | - 'list_users', |
|
| 508 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
| 509 | - //basic ee access |
|
| 510 | - 'ee_read_ee', |
|
| 511 | - //events |
|
| 512 | - 'ee_publish_events', |
|
| 513 | - 'ee_read_private_events', |
|
| 514 | - 'ee_read_others_events', |
|
| 515 | - 'ee_read_event', |
|
| 516 | - 'ee_read_events', |
|
| 517 | - 'ee_edit_event', |
|
| 518 | - 'ee_edit_events', |
|
| 519 | - 'ee_edit_published_events', |
|
| 520 | - 'ee_edit_others_events', |
|
| 521 | - 'ee_edit_private_events', |
|
| 522 | - 'ee_delete_published_events', |
|
| 523 | - 'ee_delete_private_events', |
|
| 524 | - 'ee_delete_event', |
|
| 525 | - 'ee_delete_events', |
|
| 526 | - 'ee_delete_others_events', |
|
| 527 | - //event categories |
|
| 528 | - 'ee_manage_event_categories', |
|
| 529 | - 'ee_edit_event_category', |
|
| 530 | - 'ee_delete_event_category', |
|
| 531 | - 'ee_assign_event_category', |
|
| 532 | - //venues |
|
| 533 | - 'ee_publish_venues', |
|
| 534 | - 'ee_read_venue', |
|
| 535 | - 'ee_read_venues', |
|
| 536 | - 'ee_read_others_venues', |
|
| 537 | - 'ee_read_private_venues', |
|
| 538 | - 'ee_edit_venue', |
|
| 539 | - 'ee_edit_venues', |
|
| 540 | - 'ee_edit_others_venues', |
|
| 541 | - 'ee_edit_published_venues', |
|
| 542 | - 'ee_edit_private_venues', |
|
| 543 | - 'ee_delete_venue', |
|
| 544 | - 'ee_delete_venues', |
|
| 545 | - 'ee_delete_others_venues', |
|
| 546 | - 'ee_delete_private_venues', |
|
| 547 | - 'ee_delete_published_venues', |
|
| 548 | - //venue categories |
|
| 549 | - 'ee_manage_venue_categories', |
|
| 550 | - 'ee_edit_venue_category', |
|
| 551 | - 'ee_delete_venue_category', |
|
| 552 | - 'ee_assign_venue_category', |
|
| 553 | - //contacts |
|
| 554 | - 'ee_read_contacts', |
|
| 555 | - 'ee_edit_contacts', |
|
| 556 | - 'ee_delete_contacts', |
|
| 557 | - //registrations |
|
| 558 | - 'ee_read_registrations', |
|
| 559 | - 'ee_read_others_registrations', |
|
| 560 | - 'ee_edit_registration', |
|
| 561 | - 'ee_edit_registrations', |
|
| 562 | - 'ee_edit_others_registrations', |
|
| 563 | - 'ee_delete_registration', |
|
| 564 | - 'ee_delete_registrations', |
|
| 565 | - //checkins |
|
| 566 | - 'ee_read_others_checkins', |
|
| 567 | - 'ee_read_checkins', |
|
| 568 | - 'ee_edit_checkins', |
|
| 569 | - 'ee_edit_others_checkins', |
|
| 570 | - 'ee_delete_checkins', |
|
| 571 | - 'ee_delete_others_checkins', |
|
| 572 | - //transactions && payments |
|
| 573 | - 'ee_read_transaction', |
|
| 574 | - 'ee_read_transactions', |
|
| 575 | - 'ee_edit_payments', |
|
| 576 | - 'ee_delete_payments', |
|
| 577 | - //messages |
|
| 578 | - 'ee_read_messages', |
|
| 579 | - 'ee_read_others_messages', |
|
| 580 | - 'ee_read_global_messages', |
|
| 581 | - 'ee_edit_global_messages', |
|
| 582 | - 'ee_edit_messages', |
|
| 583 | - 'ee_edit_others_messages', |
|
| 584 | - 'ee_delete_messages', |
|
| 585 | - 'ee_delete_others_messages', |
|
| 586 | - 'ee_delete_global_messages', |
|
| 587 | - 'ee_send_message', |
|
| 588 | - //tickets |
|
| 589 | - 'ee_read_default_tickets', |
|
| 590 | - 'ee_read_others_default_tickets', |
|
| 591 | - 'ee_edit_default_tickets', |
|
| 592 | - 'ee_edit_others_default_tickets', |
|
| 593 | - 'ee_delete_default_tickets', |
|
| 594 | - 'ee_delete_others_default_tickets', |
|
| 595 | - //prices |
|
| 596 | - 'ee_edit_default_price', |
|
| 597 | - 'ee_edit_default_prices', |
|
| 598 | - 'ee_delete_default_price', |
|
| 599 | - 'ee_delete_default_prices', |
|
| 600 | - 'ee_edit_default_price_type', |
|
| 601 | - 'ee_edit_default_price_types', |
|
| 602 | - 'ee_delete_default_price_type', |
|
| 603 | - 'ee_delete_default_price_types', |
|
| 604 | - 'ee_read_default_prices', |
|
| 605 | - 'ee_read_default_price_types', |
|
| 606 | - //registration form |
|
| 607 | - 'ee_edit_questions', |
|
| 608 | - 'ee_edit_system_questions', |
|
| 609 | - 'ee_read_questions', |
|
| 610 | - 'ee_delete_questions', |
|
| 611 | - 'ee_edit_question_groups', |
|
| 612 | - 'ee_read_question_groups', |
|
| 613 | - 'ee_edit_system_question_groups', |
|
| 614 | - 'ee_delete_question_groups', |
|
| 615 | - //event_type taxonomy |
|
| 616 | - 'ee_assign_event_type', |
|
| 617 | - 'ee_manage_event_types', |
|
| 618 | - 'ee_edit_event_type', |
|
| 619 | - 'ee_delete_event_type', |
|
| 620 | - ) |
|
| 621 | - ) |
|
| 622 | - ); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @return bool |
|
| 629 | - * @throws EE_Error |
|
| 630 | - */ |
|
| 631 | - private function setupCapabilitiesMap() |
|
| 632 | - { |
|
| 633 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 634 | - if($this->initialized === null) { |
|
| 635 | - return $this->init_caps(); |
|
| 636 | - } |
|
| 637 | - // unless resetting, get caps from db if we haven't already |
|
| 638 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 639 | - ? $this->capabilities_map |
|
| 640 | - : get_option(self::option_name, array()); |
|
| 641 | - return true; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * @param bool $update |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - private function updateCapabilitiesMap($update = true) |
|
| 651 | - { |
|
| 652 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Adds capabilities to roles. |
|
| 659 | - * |
|
| 660 | - * @since 4.9.42 |
|
| 661 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 662 | - * Note that this should ONLY be called on activation hook |
|
| 663 | - * otherwise the caps will be added on every request. |
|
| 664 | - * @return bool |
|
| 665 | - * @throws \EE_Error |
|
| 666 | - */ |
|
| 667 | - public function addCaps(array $capabilities_to_add) |
|
| 668 | - { |
|
| 669 | - // don't do anything if the capabilities map can not be initialized |
|
| 670 | - if (! $this->setupCapabilitiesMap()) { |
|
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - // and filter the array so others can get in on the fun during resets |
|
| 674 | - $capabilities_to_add = apply_filters( |
|
| 675 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 676 | - $capabilities_to_add, |
|
| 677 | - $this->reset, |
|
| 678 | - $this->capabilities_map |
|
| 679 | - ); |
|
| 680 | - $update_capabilities_map = false; |
|
| 681 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 682 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 683 | - if (is_array($caps_for_role)) { |
|
| 684 | - foreach ($caps_for_role as $cap) { |
|
| 685 | - if ( |
|
| 686 | - ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 687 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
| 688 | - ) { |
|
| 689 | - $update_capabilities_map = true; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - // now let's just save the cap that has been set but only if there's been a change. |
|
| 695 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 696 | - $this->flushWpUser($updated); |
|
| 697 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 698 | - return $updated; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 705 | - * |
|
| 706 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 707 | - * @return bool |
|
| 708 | - * @throws \EE_Error |
|
| 709 | - */ |
|
| 710 | - public function removeCaps($caps_map) |
|
| 711 | - { |
|
| 712 | - // don't do anything if the capabilities map can not be initialized |
|
| 713 | - if (! $this->setupCapabilitiesMap()) { |
|
| 714 | - return false; |
|
| 715 | - } |
|
| 716 | - $update_capabilities_map = false; |
|
| 717 | - foreach ($caps_map as $role => $caps_for_role) { |
|
| 718 | - if (is_array($caps_for_role)) { |
|
| 719 | - foreach ($caps_for_role as $cap) { |
|
| 720 | - if ($this->capHasBeenAddedToRole($role, $cap) |
|
| 721 | - && $this->remove_cap_from_role($role, $cap, false) |
|
| 722 | - ) { |
|
| 723 | - $update_capabilities_map = true; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - // maybe resave the caps |
|
| 729 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 730 | - $this->flushWpUser($updated); |
|
| 731 | - return $updated; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
| 737 | - * the roles on that user. |
|
| 738 | - * |
|
| 739 | - * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
| 740 | - */ |
|
| 741 | - private function flushWpUser($flush = true) |
|
| 742 | - { |
|
| 743 | - if ($flush) { |
|
| 744 | - $user = wp_get_current_user(); |
|
| 745 | - if ($user instanceof WP_User) { |
|
| 746 | - $user->get_role_caps(); |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 755 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 756 | - * this is a wrapper for $wp_role->add_cap() |
|
| 757 | - * |
|
| 758 | - * @see wp-includes/capabilities.php |
|
| 759 | - * @since 4.5.0 |
|
| 760 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 761 | - * @param string $cap The capability being added to the role |
|
| 762 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
| 763 | - * @param bool $update_capabilities_map |
|
| 764 | - * @return bool |
|
| 765 | - * @throws \EE_Error |
|
| 766 | - */ |
|
| 767 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 768 | - { |
|
| 769 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 770 | - $orig_role = $role; |
|
| 771 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 772 | - //if the role isn't available then we create it. |
|
| 773 | - if (! $role instanceof WP_Role) { |
|
| 774 | - // if a plugin wants to create a specific role name then they should create the role before |
|
| 775 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 776 | - // - removes any `ee_` namespacing from the start of the slug. |
|
| 777 | - // - replaces `_` with ` ` (empty space). |
|
| 778 | - // - sentence case on the resulting string. |
|
| 779 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 780 | - $role = add_role($orig_role, $role_label); |
|
| 781 | - } |
|
| 782 | - if ($role instanceof WP_Role) { |
|
| 783 | - // don't do anything if the capabilities map can not be initialized |
|
| 784 | - if (! $this->setupCapabilitiesMap()) { |
|
| 785 | - return false; |
|
| 786 | - } |
|
| 787 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | - $role->add_cap($cap, $grant); |
|
| 789 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 790 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 791 | - return true; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - return false; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 801 | - * Wrapper for $wp_role->remove_cap() |
|
| 802 | - * |
|
| 803 | - * @see wp-includes/capabilities.php |
|
| 804 | - * @since 4.5.0 |
|
| 805 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 806 | - * @param string $cap The capability being removed |
|
| 807 | - * @param bool $update_capabilities_map |
|
| 808 | - * @return bool |
|
| 809 | - * @throws \EE_Error |
|
| 810 | - */ |
|
| 811 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 812 | - { |
|
| 813 | - // don't do anything if the capabilities map can not be initialized |
|
| 814 | - if (! $this->setupCapabilitiesMap()) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 818 | - if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 819 | - $role->remove_cap($cap); |
|
| 820 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 821 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 822 | - return true; |
|
| 823 | - } |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * @param string $role_name |
|
| 831 | - * @param string $cap |
|
| 832 | - * @param bool $get_index |
|
| 833 | - * @return bool|mixed |
|
| 834 | - */ |
|
| 835 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 836 | - { |
|
| 837 | - if ( |
|
| 838 | - isset($this->capabilities_map[$role_name]) |
|
| 839 | - && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 840 | - ) { |
|
| 841 | - return $get_index ? $index : true; |
|
| 842 | - } |
|
| 843 | - return false; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Wrapper for the native WP current_user_can() method. |
|
| 850 | - * This is provided as a handy method for a couple things: |
|
| 851 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 852 | - * write those filters wherever current_user_can is called). |
|
| 853 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 854 | - * |
|
| 855 | - * @since 4.5.0 |
|
| 856 | - * |
|
| 857 | - * @param string $cap The cap being checked. |
|
| 858 | - * @param string $context The context where the current_user_can is being called from. |
|
| 859 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 860 | - * filters. |
|
| 861 | - * |
|
| 862 | - * @return bool Whether user can or not. |
|
| 863 | - */ |
|
| 864 | - public function current_user_can($cap, $context, $id = 0) |
|
| 865 | - { |
|
| 866 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 867 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 868 | - $filtered_cap = apply_filters( |
|
| 869 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 870 | - $filtered_cap, |
|
| 871 | - $context, |
|
| 872 | - $cap, |
|
| 873 | - $id |
|
| 874 | - ); |
|
| 875 | - return ! empty($id) |
|
| 876 | - ? current_user_can($filtered_cap, $id) |
|
| 877 | - : current_user_can($filtered_cap); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 884 | - * |
|
| 885 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 886 | - * @param string $cap The capability string being checked |
|
| 887 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
| 888 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 889 | - * filters) |
|
| 890 | - * |
|
| 891 | - * @return bool Whether user can or not. |
|
| 892 | - */ |
|
| 893 | - public function user_can($user, $cap, $context, $id = 0) |
|
| 894 | - { |
|
| 895 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 896 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 897 | - $filtered_cap = apply_filters( |
|
| 898 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
| 899 | - $filtered_cap, |
|
| 900 | - $context, |
|
| 901 | - $cap, |
|
| 902 | - $user, |
|
| 903 | - $id |
|
| 904 | - ); |
|
| 905 | - return ! empty($id) |
|
| 906 | - ? user_can($user, $filtered_cap, $id) |
|
| 907 | - : user_can($user, $filtered_cap); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 914 | - * This is provided as a handy method for a couple things: |
|
| 915 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 916 | - * write those filters wherever current_user_can is called). |
|
| 917 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 918 | - * |
|
| 919 | - * @since 4.5.0 |
|
| 920 | - * |
|
| 921 | - * @param int $blog_id The blog id that is being checked for. |
|
| 922 | - * @param string $cap The cap being checked. |
|
| 923 | - * @param string $context The context where the current_user_can is being called from. |
|
| 924 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 925 | - * filters. |
|
| 926 | - * |
|
| 927 | - * @return bool Whether user can or not. |
|
| 928 | - */ |
|
| 929 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 930 | - { |
|
| 931 | - $user_can = ! empty($id) |
|
| 932 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 933 | - : current_user_can($blog_id, $cap); |
|
| 934 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 935 | - $user_can = apply_filters( |
|
| 936 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 937 | - $user_can, |
|
| 938 | - $blog_id, |
|
| 939 | - $cap, |
|
| 940 | - $id |
|
| 941 | - ); |
|
| 942 | - $user_can = apply_filters( |
|
| 943 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 944 | - $user_can, |
|
| 945 | - $context, |
|
| 946 | - $blog_id, |
|
| 947 | - $cap, |
|
| 948 | - $id |
|
| 949 | - ); |
|
| 950 | - return $user_can; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * This helper method just returns an array of registered EE capabilities. |
|
| 957 | - * |
|
| 958 | - * @since 4.5.0 |
|
| 959 | - * @param string $role If empty then the entire role/capability map is returned. |
|
| 960 | - * Otherwise just the capabilities for the given role are returned. |
|
| 961 | - * @return array |
|
| 962 | - * @throws EE_Error |
|
| 963 | - */ |
|
| 964 | - public function get_ee_capabilities($role = 'administrator') |
|
| 965 | - { |
|
| 966 | - if (! $this->initialized) { |
|
| 967 | - $this->init_caps(); |
|
| 968 | - } |
|
| 969 | - if (empty($role)) { |
|
| 970 | - return $this->capabilities_map; |
|
| 971 | - } |
|
| 972 | - return isset($this->capabilities_map[ $role ]) |
|
| 973 | - ? $this->capabilities_map[ $role ] |
|
| 974 | - : array(); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * @deprecated 4.9.42 |
|
| 981 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 982 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 983 | - * @param array $caps_map Optional. |
|
| 984 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 985 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
| 986 | - * task otherwise the caps will be added on every request. |
|
| 987 | - * @return void |
|
| 988 | - * @throws EE_Error |
|
| 989 | - */ |
|
| 990 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
| 991 | - { |
|
| 992 | - // If this method is called directly and reset is set as 'true', |
|
| 993 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 994 | - // to guarantee that everything is set up correctly. |
|
| 995 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 996 | - if ($reset) { |
|
| 997 | - EE_Error::doing_it_wrong( |
|
| 998 | - __METHOD__, |
|
| 999 | - sprintf( |
|
| 1000 | - esc_html__( |
|
| 1001 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 1002 | - 'event_espresso' |
|
| 1003 | - ), |
|
| 1004 | - '$reset', |
|
| 1005 | - __METHOD__ . '()', |
|
| 1006 | - 'EE_Capabilities::init_caps()', |
|
| 1007 | - 'true' |
|
| 1008 | - ), |
|
| 1009 | - '4.9.42', |
|
| 1010 | - '5.0.0' |
|
| 1011 | - ); |
|
| 1012 | - } |
|
| 1013 | - $this->addCaps($caps_map); |
|
| 1014 | - } |
|
| 21 | + /** |
|
| 22 | + * the name of the wp option used to store caps previously initialized |
|
| 23 | + */ |
|
| 24 | + const option_name = 'ee_caps_initialized'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * instance of EE_Capabilities object |
|
| 28 | + * |
|
| 29 | + * @var EE_Capabilities |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | + * Array is indexed by Role and values are ee capabilities. |
|
| 37 | + * |
|
| 38 | + * @since 4.5.0 |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $capabilities_map = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | + * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | + * |
|
| 48 | + * @var EE_Meta_Capability_Map[] |
|
| 49 | + */ |
|
| 50 | + private $_meta_caps = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | + * This flag tracks whether that has happened or not. |
|
| 55 | + * But for this to work, we need three states to indicate: |
|
| 56 | + * initialization has not occurred at all |
|
| 57 | + * initialization has started but is not complete |
|
| 58 | + * initialization is complete |
|
| 59 | + * The reason this is needed is because the addCaps() method |
|
| 60 | + * normally requires the $capabilities_map to be initialized, |
|
| 61 | + * but is also used during the initialization process. |
|
| 62 | + * So: |
|
| 63 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | + * |
|
| 67 | + * @var boolean|null $initialized |
|
| 68 | + */ |
|
| 69 | + private $initialized; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var boolean $reset |
|
| 73 | + */ |
|
| 74 | + private $reset = false; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * singleton method used to instantiate class object |
|
| 80 | + * |
|
| 81 | + * @since 4.5.0 |
|
| 82 | + * |
|
| 83 | + * @return EE_Capabilities |
|
| 84 | + */ |
|
| 85 | + public static function instance() |
|
| 86 | + { |
|
| 87 | + //check if instantiated, and if not do so. |
|
| 88 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | + self::$_instance = new self(); |
|
| 90 | + } |
|
| 91 | + return self::$_instance; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * private constructor |
|
| 98 | + * |
|
| 99 | + * @since 4.5.0 |
|
| 100 | + */ |
|
| 101 | + private function __construct() |
|
| 102 | + { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | + * |
|
| 110 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | + * ensures that they are up to date. |
|
| 113 | + * |
|
| 114 | + * @since 4.5.0 |
|
| 115 | + * @return bool |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function init_caps($reset = false) |
|
| 119 | + { |
|
| 120 | + if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | + if ($this->reset) { |
|
| 126 | + $this->initialized = null; |
|
| 127 | + $this->capabilities_map = array(); |
|
| 128 | + delete_option(self::option_name); |
|
| 129 | + } |
|
| 130 | + if ($this->initialized === null) { |
|
| 131 | + $this->initialized = false; |
|
| 132 | + do_action( |
|
| 133 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | + $this->reset |
|
| 135 | + ); |
|
| 136 | + $this->addCaps($this->_init_caps_map()); |
|
| 137 | + $this->_set_meta_caps(); |
|
| 138 | + do_action( |
|
| 139 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | + $this->capabilities_map |
|
| 141 | + ); |
|
| 142 | + $this->initialized = true; |
|
| 143 | + } |
|
| 144 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | + $this->reset = false; |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * This sets the meta caps property. |
|
| 154 | + * |
|
| 155 | + * @since 4.5.0 |
|
| 156 | + * @return void |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + private function _set_meta_caps() |
|
| 160 | + { |
|
| 161 | + // get default meta caps and filter the returned array |
|
| 162 | + $this->_meta_caps = apply_filters( |
|
| 163 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 164 | + $this->_get_default_meta_caps_array() |
|
| 165 | + ); |
|
| 166 | + //add filter for map_meta_caps but only if models can query. |
|
| 167 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 168 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * This builds and returns the default meta_caps array only once. |
|
| 176 | + * |
|
| 177 | + * @since 4.8.28.rc.012 |
|
| 178 | + * @return array |
|
| 179 | + * @throws EE_Error |
|
| 180 | + */ |
|
| 181 | + private function _get_default_meta_caps_array() |
|
| 182 | + { |
|
| 183 | + static $default_meta_caps = array(); |
|
| 184 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 185 | + if (empty($default_meta_caps)) { |
|
| 186 | + $default_meta_caps = array( |
|
| 187 | + //edits |
|
| 188 | + new EE_Meta_Capability_Map_Edit( |
|
| 189 | + 'ee_edit_event', |
|
| 190 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 191 | + ), |
|
| 192 | + new EE_Meta_Capability_Map_Edit( |
|
| 193 | + 'ee_edit_venue', |
|
| 194 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 195 | + ), |
|
| 196 | + new EE_Meta_Capability_Map_Edit( |
|
| 197 | + 'ee_edit_registration', |
|
| 198 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 199 | + ), |
|
| 200 | + new EE_Meta_Capability_Map_Edit( |
|
| 201 | + 'ee_edit_checkin', |
|
| 202 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 203 | + ), |
|
| 204 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 205 | + 'ee_edit_message', |
|
| 206 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 207 | + ), |
|
| 208 | + new EE_Meta_Capability_Map_Edit( |
|
| 209 | + 'ee_edit_default_ticket', |
|
| 210 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 211 | + ), |
|
| 212 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 213 | + 'ee_edit_question', |
|
| 214 | + array('Question', '', '', 'ee_edit_system_questions') |
|
| 215 | + ), |
|
| 216 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 217 | + 'ee_edit_question_group', |
|
| 218 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 219 | + ), |
|
| 220 | + new EE_Meta_Capability_Map_Edit( |
|
| 221 | + 'ee_edit_payment_method', |
|
| 222 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 223 | + ), |
|
| 224 | + //reads |
|
| 225 | + new EE_Meta_Capability_Map_Read( |
|
| 226 | + 'ee_read_event', |
|
| 227 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 228 | + ), |
|
| 229 | + new EE_Meta_Capability_Map_Read( |
|
| 230 | + 'ee_read_venue', |
|
| 231 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 232 | + ), |
|
| 233 | + new EE_Meta_Capability_Map_Read( |
|
| 234 | + 'ee_read_registration', |
|
| 235 | + array('Registration', '', 'ee_read_others_registrations', '') |
|
| 236 | + ), |
|
| 237 | + new EE_Meta_Capability_Map_Read( |
|
| 238 | + 'ee_read_checkin', |
|
| 239 | + array('Registration', '', 'ee_read_others_checkins', '') |
|
| 240 | + ), |
|
| 241 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 242 | + 'ee_read_message', |
|
| 243 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 244 | + ), |
|
| 245 | + new EE_Meta_Capability_Map_Read( |
|
| 246 | + 'ee_read_default_ticket', |
|
| 247 | + array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 248 | + ), |
|
| 249 | + new EE_Meta_Capability_Map_Read( |
|
| 250 | + 'ee_read_payment_method', |
|
| 251 | + array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 252 | + ), |
|
| 253 | + //deletes |
|
| 254 | + new EE_Meta_Capability_Map_Delete( |
|
| 255 | + 'ee_delete_event', |
|
| 256 | + array( |
|
| 257 | + 'Event', |
|
| 258 | + 'ee_delete_published_events', |
|
| 259 | + 'ee_delete_others_events', |
|
| 260 | + 'ee_delete_private_events', |
|
| 261 | + ) |
|
| 262 | + ), |
|
| 263 | + new EE_Meta_Capability_Map_Delete( |
|
| 264 | + 'ee_delete_venue', |
|
| 265 | + array( |
|
| 266 | + 'Venue', |
|
| 267 | + 'ee_delete_published_venues', |
|
| 268 | + 'ee_delete_others_venues', |
|
| 269 | + 'ee_delete_private_venues', |
|
| 270 | + ) |
|
| 271 | + ), |
|
| 272 | + new EE_Meta_Capability_Map_Delete( |
|
| 273 | + 'ee_delete_registration', |
|
| 274 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 275 | + ), |
|
| 276 | + new EE_Meta_Capability_Map_Delete( |
|
| 277 | + 'ee_delete_checkin', |
|
| 278 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 279 | + ), |
|
| 280 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 281 | + 'ee_delete_message', |
|
| 282 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 283 | + ), |
|
| 284 | + new EE_Meta_Capability_Map_Delete( |
|
| 285 | + 'ee_delete_default_ticket', |
|
| 286 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 287 | + ), |
|
| 288 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 289 | + 'ee_delete_question', |
|
| 290 | + array('Question', '', '', 'delete_system_questions') |
|
| 291 | + ), |
|
| 292 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 293 | + 'ee_delete_question_group', |
|
| 294 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 295 | + ), |
|
| 296 | + new EE_Meta_Capability_Map_Delete( |
|
| 297 | + 'ee_delete_payment_method', |
|
| 298 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 299 | + ), |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + return $default_meta_caps; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 309 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 310 | + * |
|
| 311 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 312 | + * |
|
| 313 | + * @since 4.5.0 |
|
| 314 | + * @see wp-includes/capabilities.php |
|
| 315 | + * |
|
| 316 | + * @param array $caps actual users capabilities |
|
| 317 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 318 | + * @param int $user_id The user id |
|
| 319 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 320 | + * @return array actual users capabilities |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 324 | + { |
|
| 325 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 326 | + //loop through our _meta_caps array |
|
| 327 | + foreach ($this->_meta_caps as $meta_map) { |
|
| 328 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 329 | + continue; |
|
| 330 | + } |
|
| 331 | + // don't load models if there is no object ID in the args |
|
| 332 | + if (! empty($args[0])) { |
|
| 333 | + $meta_map->ensure_is_model(); |
|
| 334 | + } |
|
| 335 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + return $caps; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
| 345 | + * Note this array is filtered. |
|
| 346 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 347 | + * |
|
| 348 | + * @since 4.5.0 |
|
| 349 | + * |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + private function _init_caps_map() |
|
| 353 | + { |
|
| 354 | + return apply_filters( |
|
| 355 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 356 | + array( |
|
| 357 | + 'administrator' => array( |
|
| 358 | + //basic access |
|
| 359 | + 'ee_read_ee', |
|
| 360 | + //gateways |
|
| 361 | + /** |
|
| 362 | + * note that with payment method capabilities, although we've implemented |
|
| 363 | + * capability mapping which will be used for accessing payment methods owned by |
|
| 364 | + * other users. This is not fully implemented yet in the payment method ui. |
|
| 365 | + * Currently only the "plural" caps are in active use. |
|
| 366 | + * (Specific payment method caps are in use as well). |
|
| 367 | + **/ |
|
| 368 | + 'ee_manage_gateways', |
|
| 369 | + 'ee_read_payment_methods', |
|
| 370 | + 'ee_read_others_payment_methods', |
|
| 371 | + 'ee_edit_payment_methods', |
|
| 372 | + 'ee_edit_others_payment_methods', |
|
| 373 | + 'ee_delete_payment_methods', |
|
| 374 | + //events |
|
| 375 | + 'ee_publish_events', |
|
| 376 | + 'ee_read_private_events', |
|
| 377 | + 'ee_read_others_events', |
|
| 378 | + 'ee_read_events', |
|
| 379 | + 'ee_edit_events', |
|
| 380 | + 'ee_edit_published_events', |
|
| 381 | + 'ee_edit_others_events', |
|
| 382 | + 'ee_edit_private_events', |
|
| 383 | + 'ee_delete_published_events', |
|
| 384 | + 'ee_delete_private_events', |
|
| 385 | + 'ee_delete_events', |
|
| 386 | + 'ee_delete_others_events', |
|
| 387 | + //event categories |
|
| 388 | + 'ee_manage_event_categories', |
|
| 389 | + 'ee_edit_event_category', |
|
| 390 | + 'ee_delete_event_category', |
|
| 391 | + 'ee_assign_event_category', |
|
| 392 | + //venues |
|
| 393 | + 'ee_publish_venues', |
|
| 394 | + 'ee_read_venues', |
|
| 395 | + 'ee_read_others_venues', |
|
| 396 | + 'ee_read_private_venues', |
|
| 397 | + 'ee_edit_venues', |
|
| 398 | + 'ee_edit_others_venues', |
|
| 399 | + 'ee_edit_published_venues', |
|
| 400 | + 'ee_edit_private_venues', |
|
| 401 | + 'ee_delete_venues', |
|
| 402 | + 'ee_delete_others_venues', |
|
| 403 | + 'ee_delete_private_venues', |
|
| 404 | + 'ee_delete_published_venues', |
|
| 405 | + //venue categories |
|
| 406 | + 'ee_manage_venue_categories', |
|
| 407 | + 'ee_edit_venue_category', |
|
| 408 | + 'ee_delete_venue_category', |
|
| 409 | + 'ee_assign_venue_category', |
|
| 410 | + //contacts |
|
| 411 | + 'ee_read_contacts', |
|
| 412 | + 'ee_edit_contacts', |
|
| 413 | + 'ee_delete_contacts', |
|
| 414 | + //registrations |
|
| 415 | + 'ee_read_registrations', |
|
| 416 | + 'ee_read_others_registrations', |
|
| 417 | + 'ee_edit_registrations', |
|
| 418 | + 'ee_edit_others_registrations', |
|
| 419 | + 'ee_delete_registrations', |
|
| 420 | + //checkins |
|
| 421 | + 'ee_read_others_checkins', |
|
| 422 | + 'ee_read_checkins', |
|
| 423 | + 'ee_edit_checkins', |
|
| 424 | + 'ee_edit_others_checkins', |
|
| 425 | + 'ee_delete_checkins', |
|
| 426 | + 'ee_delete_others_checkins', |
|
| 427 | + //transactions && payments |
|
| 428 | + 'ee_read_transaction', |
|
| 429 | + 'ee_read_transactions', |
|
| 430 | + 'ee_edit_payments', |
|
| 431 | + 'ee_delete_payments', |
|
| 432 | + //messages |
|
| 433 | + 'ee_read_messages', |
|
| 434 | + 'ee_read_others_messages', |
|
| 435 | + 'ee_read_global_messages', |
|
| 436 | + 'ee_edit_global_messages', |
|
| 437 | + 'ee_edit_messages', |
|
| 438 | + 'ee_edit_others_messages', |
|
| 439 | + 'ee_delete_messages', |
|
| 440 | + 'ee_delete_others_messages', |
|
| 441 | + 'ee_delete_global_messages', |
|
| 442 | + 'ee_send_message', |
|
| 443 | + //tickets |
|
| 444 | + 'ee_read_default_tickets', |
|
| 445 | + 'ee_read_others_default_tickets', |
|
| 446 | + 'ee_edit_default_tickets', |
|
| 447 | + 'ee_edit_others_default_tickets', |
|
| 448 | + 'ee_delete_default_tickets', |
|
| 449 | + 'ee_delete_others_default_tickets', |
|
| 450 | + //prices |
|
| 451 | + 'ee_edit_default_price', |
|
| 452 | + 'ee_edit_default_prices', |
|
| 453 | + 'ee_delete_default_price', |
|
| 454 | + 'ee_delete_default_prices', |
|
| 455 | + 'ee_edit_default_price_type', |
|
| 456 | + 'ee_edit_default_price_types', |
|
| 457 | + 'ee_delete_default_price_type', |
|
| 458 | + 'ee_delete_default_price_types', |
|
| 459 | + 'ee_read_default_prices', |
|
| 460 | + 'ee_read_default_price_types', |
|
| 461 | + //registration form |
|
| 462 | + 'ee_edit_questions', |
|
| 463 | + 'ee_edit_system_questions', |
|
| 464 | + 'ee_read_questions', |
|
| 465 | + 'ee_delete_questions', |
|
| 466 | + 'ee_edit_question_groups', |
|
| 467 | + 'ee_read_question_groups', |
|
| 468 | + 'ee_edit_system_question_groups', |
|
| 469 | + 'ee_delete_question_groups', |
|
| 470 | + //event_type taxonomy |
|
| 471 | + 'ee_assign_event_type', |
|
| 472 | + 'ee_manage_event_types', |
|
| 473 | + 'ee_edit_event_type', |
|
| 474 | + 'ee_delete_event_type', |
|
| 475 | + ), |
|
| 476 | + 'ee_events_administrator' => array( |
|
| 477 | + //core wp caps |
|
| 478 | + 'read', |
|
| 479 | + 'read_private_pages', |
|
| 480 | + 'read_private_posts', |
|
| 481 | + 'edit_users', |
|
| 482 | + 'edit_posts', |
|
| 483 | + 'edit_pages', |
|
| 484 | + 'edit_published_posts', |
|
| 485 | + 'edit_published_pages', |
|
| 486 | + 'edit_private_pages', |
|
| 487 | + 'edit_private_posts', |
|
| 488 | + 'edit_others_posts', |
|
| 489 | + 'edit_others_pages', |
|
| 490 | + 'publish_posts', |
|
| 491 | + 'publish_pages', |
|
| 492 | + 'delete_posts', |
|
| 493 | + 'delete_pages', |
|
| 494 | + 'delete_private_pages', |
|
| 495 | + 'delete_private_posts', |
|
| 496 | + 'delete_published_pages', |
|
| 497 | + 'delete_published_posts', |
|
| 498 | + 'delete_others_posts', |
|
| 499 | + 'delete_others_pages', |
|
| 500 | + 'manage_categories', |
|
| 501 | + 'manage_links', |
|
| 502 | + 'moderate_comments', |
|
| 503 | + 'unfiltered_html', |
|
| 504 | + 'upload_files', |
|
| 505 | + 'export', |
|
| 506 | + 'import', |
|
| 507 | + 'list_users', |
|
| 508 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
| 509 | + //basic ee access |
|
| 510 | + 'ee_read_ee', |
|
| 511 | + //events |
|
| 512 | + 'ee_publish_events', |
|
| 513 | + 'ee_read_private_events', |
|
| 514 | + 'ee_read_others_events', |
|
| 515 | + 'ee_read_event', |
|
| 516 | + 'ee_read_events', |
|
| 517 | + 'ee_edit_event', |
|
| 518 | + 'ee_edit_events', |
|
| 519 | + 'ee_edit_published_events', |
|
| 520 | + 'ee_edit_others_events', |
|
| 521 | + 'ee_edit_private_events', |
|
| 522 | + 'ee_delete_published_events', |
|
| 523 | + 'ee_delete_private_events', |
|
| 524 | + 'ee_delete_event', |
|
| 525 | + 'ee_delete_events', |
|
| 526 | + 'ee_delete_others_events', |
|
| 527 | + //event categories |
|
| 528 | + 'ee_manage_event_categories', |
|
| 529 | + 'ee_edit_event_category', |
|
| 530 | + 'ee_delete_event_category', |
|
| 531 | + 'ee_assign_event_category', |
|
| 532 | + //venues |
|
| 533 | + 'ee_publish_venues', |
|
| 534 | + 'ee_read_venue', |
|
| 535 | + 'ee_read_venues', |
|
| 536 | + 'ee_read_others_venues', |
|
| 537 | + 'ee_read_private_venues', |
|
| 538 | + 'ee_edit_venue', |
|
| 539 | + 'ee_edit_venues', |
|
| 540 | + 'ee_edit_others_venues', |
|
| 541 | + 'ee_edit_published_venues', |
|
| 542 | + 'ee_edit_private_venues', |
|
| 543 | + 'ee_delete_venue', |
|
| 544 | + 'ee_delete_venues', |
|
| 545 | + 'ee_delete_others_venues', |
|
| 546 | + 'ee_delete_private_venues', |
|
| 547 | + 'ee_delete_published_venues', |
|
| 548 | + //venue categories |
|
| 549 | + 'ee_manage_venue_categories', |
|
| 550 | + 'ee_edit_venue_category', |
|
| 551 | + 'ee_delete_venue_category', |
|
| 552 | + 'ee_assign_venue_category', |
|
| 553 | + //contacts |
|
| 554 | + 'ee_read_contacts', |
|
| 555 | + 'ee_edit_contacts', |
|
| 556 | + 'ee_delete_contacts', |
|
| 557 | + //registrations |
|
| 558 | + 'ee_read_registrations', |
|
| 559 | + 'ee_read_others_registrations', |
|
| 560 | + 'ee_edit_registration', |
|
| 561 | + 'ee_edit_registrations', |
|
| 562 | + 'ee_edit_others_registrations', |
|
| 563 | + 'ee_delete_registration', |
|
| 564 | + 'ee_delete_registrations', |
|
| 565 | + //checkins |
|
| 566 | + 'ee_read_others_checkins', |
|
| 567 | + 'ee_read_checkins', |
|
| 568 | + 'ee_edit_checkins', |
|
| 569 | + 'ee_edit_others_checkins', |
|
| 570 | + 'ee_delete_checkins', |
|
| 571 | + 'ee_delete_others_checkins', |
|
| 572 | + //transactions && payments |
|
| 573 | + 'ee_read_transaction', |
|
| 574 | + 'ee_read_transactions', |
|
| 575 | + 'ee_edit_payments', |
|
| 576 | + 'ee_delete_payments', |
|
| 577 | + //messages |
|
| 578 | + 'ee_read_messages', |
|
| 579 | + 'ee_read_others_messages', |
|
| 580 | + 'ee_read_global_messages', |
|
| 581 | + 'ee_edit_global_messages', |
|
| 582 | + 'ee_edit_messages', |
|
| 583 | + 'ee_edit_others_messages', |
|
| 584 | + 'ee_delete_messages', |
|
| 585 | + 'ee_delete_others_messages', |
|
| 586 | + 'ee_delete_global_messages', |
|
| 587 | + 'ee_send_message', |
|
| 588 | + //tickets |
|
| 589 | + 'ee_read_default_tickets', |
|
| 590 | + 'ee_read_others_default_tickets', |
|
| 591 | + 'ee_edit_default_tickets', |
|
| 592 | + 'ee_edit_others_default_tickets', |
|
| 593 | + 'ee_delete_default_tickets', |
|
| 594 | + 'ee_delete_others_default_tickets', |
|
| 595 | + //prices |
|
| 596 | + 'ee_edit_default_price', |
|
| 597 | + 'ee_edit_default_prices', |
|
| 598 | + 'ee_delete_default_price', |
|
| 599 | + 'ee_delete_default_prices', |
|
| 600 | + 'ee_edit_default_price_type', |
|
| 601 | + 'ee_edit_default_price_types', |
|
| 602 | + 'ee_delete_default_price_type', |
|
| 603 | + 'ee_delete_default_price_types', |
|
| 604 | + 'ee_read_default_prices', |
|
| 605 | + 'ee_read_default_price_types', |
|
| 606 | + //registration form |
|
| 607 | + 'ee_edit_questions', |
|
| 608 | + 'ee_edit_system_questions', |
|
| 609 | + 'ee_read_questions', |
|
| 610 | + 'ee_delete_questions', |
|
| 611 | + 'ee_edit_question_groups', |
|
| 612 | + 'ee_read_question_groups', |
|
| 613 | + 'ee_edit_system_question_groups', |
|
| 614 | + 'ee_delete_question_groups', |
|
| 615 | + //event_type taxonomy |
|
| 616 | + 'ee_assign_event_type', |
|
| 617 | + 'ee_manage_event_types', |
|
| 618 | + 'ee_edit_event_type', |
|
| 619 | + 'ee_delete_event_type', |
|
| 620 | + ) |
|
| 621 | + ) |
|
| 622 | + ); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @return bool |
|
| 629 | + * @throws EE_Error |
|
| 630 | + */ |
|
| 631 | + private function setupCapabilitiesMap() |
|
| 632 | + { |
|
| 633 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 634 | + if($this->initialized === null) { |
|
| 635 | + return $this->init_caps(); |
|
| 636 | + } |
|
| 637 | + // unless resetting, get caps from db if we haven't already |
|
| 638 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 639 | + ? $this->capabilities_map |
|
| 640 | + : get_option(self::option_name, array()); |
|
| 641 | + return true; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * @param bool $update |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + private function updateCapabilitiesMap($update = true) |
|
| 651 | + { |
|
| 652 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Adds capabilities to roles. |
|
| 659 | + * |
|
| 660 | + * @since 4.9.42 |
|
| 661 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 662 | + * Note that this should ONLY be called on activation hook |
|
| 663 | + * otherwise the caps will be added on every request. |
|
| 664 | + * @return bool |
|
| 665 | + * @throws \EE_Error |
|
| 666 | + */ |
|
| 667 | + public function addCaps(array $capabilities_to_add) |
|
| 668 | + { |
|
| 669 | + // don't do anything if the capabilities map can not be initialized |
|
| 670 | + if (! $this->setupCapabilitiesMap()) { |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + // and filter the array so others can get in on the fun during resets |
|
| 674 | + $capabilities_to_add = apply_filters( |
|
| 675 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 676 | + $capabilities_to_add, |
|
| 677 | + $this->reset, |
|
| 678 | + $this->capabilities_map |
|
| 679 | + ); |
|
| 680 | + $update_capabilities_map = false; |
|
| 681 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 682 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 683 | + if (is_array($caps_for_role)) { |
|
| 684 | + foreach ($caps_for_role as $cap) { |
|
| 685 | + if ( |
|
| 686 | + ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 687 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
| 688 | + ) { |
|
| 689 | + $update_capabilities_map = true; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + // now let's just save the cap that has been set but only if there's been a change. |
|
| 695 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 696 | + $this->flushWpUser($updated); |
|
| 697 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 698 | + return $updated; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 705 | + * |
|
| 706 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 707 | + * @return bool |
|
| 708 | + * @throws \EE_Error |
|
| 709 | + */ |
|
| 710 | + public function removeCaps($caps_map) |
|
| 711 | + { |
|
| 712 | + // don't do anything if the capabilities map can not be initialized |
|
| 713 | + if (! $this->setupCapabilitiesMap()) { |
|
| 714 | + return false; |
|
| 715 | + } |
|
| 716 | + $update_capabilities_map = false; |
|
| 717 | + foreach ($caps_map as $role => $caps_for_role) { |
|
| 718 | + if (is_array($caps_for_role)) { |
|
| 719 | + foreach ($caps_for_role as $cap) { |
|
| 720 | + if ($this->capHasBeenAddedToRole($role, $cap) |
|
| 721 | + && $this->remove_cap_from_role($role, $cap, false) |
|
| 722 | + ) { |
|
| 723 | + $update_capabilities_map = true; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + // maybe resave the caps |
|
| 729 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 730 | + $this->flushWpUser($updated); |
|
| 731 | + return $updated; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
| 737 | + * the roles on that user. |
|
| 738 | + * |
|
| 739 | + * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
| 740 | + */ |
|
| 741 | + private function flushWpUser($flush = true) |
|
| 742 | + { |
|
| 743 | + if ($flush) { |
|
| 744 | + $user = wp_get_current_user(); |
|
| 745 | + if ($user instanceof WP_User) { |
|
| 746 | + $user->get_role_caps(); |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 755 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 756 | + * this is a wrapper for $wp_role->add_cap() |
|
| 757 | + * |
|
| 758 | + * @see wp-includes/capabilities.php |
|
| 759 | + * @since 4.5.0 |
|
| 760 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 761 | + * @param string $cap The capability being added to the role |
|
| 762 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
| 763 | + * @param bool $update_capabilities_map |
|
| 764 | + * @return bool |
|
| 765 | + * @throws \EE_Error |
|
| 766 | + */ |
|
| 767 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 768 | + { |
|
| 769 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 770 | + $orig_role = $role; |
|
| 771 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 772 | + //if the role isn't available then we create it. |
|
| 773 | + if (! $role instanceof WP_Role) { |
|
| 774 | + // if a plugin wants to create a specific role name then they should create the role before |
|
| 775 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 776 | + // - removes any `ee_` namespacing from the start of the slug. |
|
| 777 | + // - replaces `_` with ` ` (empty space). |
|
| 778 | + // - sentence case on the resulting string. |
|
| 779 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 780 | + $role = add_role($orig_role, $role_label); |
|
| 781 | + } |
|
| 782 | + if ($role instanceof WP_Role) { |
|
| 783 | + // don't do anything if the capabilities map can not be initialized |
|
| 784 | + if (! $this->setupCapabilitiesMap()) { |
|
| 785 | + return false; |
|
| 786 | + } |
|
| 787 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 788 | + $role->add_cap($cap, $grant); |
|
| 789 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
| 790 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 791 | + return true; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + return false; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 801 | + * Wrapper for $wp_role->remove_cap() |
|
| 802 | + * |
|
| 803 | + * @see wp-includes/capabilities.php |
|
| 804 | + * @since 4.5.0 |
|
| 805 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 806 | + * @param string $cap The capability being removed |
|
| 807 | + * @param bool $update_capabilities_map |
|
| 808 | + * @return bool |
|
| 809 | + * @throws \EE_Error |
|
| 810 | + */ |
|
| 811 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 812 | + { |
|
| 813 | + // don't do anything if the capabilities map can not be initialized |
|
| 814 | + if (! $this->setupCapabilitiesMap()) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 818 | + if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 819 | + $role->remove_cap($cap); |
|
| 820 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 821 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 822 | + return true; |
|
| 823 | + } |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * @param string $role_name |
|
| 831 | + * @param string $cap |
|
| 832 | + * @param bool $get_index |
|
| 833 | + * @return bool|mixed |
|
| 834 | + */ |
|
| 835 | + private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 836 | + { |
|
| 837 | + if ( |
|
| 838 | + isset($this->capabilities_map[$role_name]) |
|
| 839 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 840 | + ) { |
|
| 841 | + return $get_index ? $index : true; |
|
| 842 | + } |
|
| 843 | + return false; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Wrapper for the native WP current_user_can() method. |
|
| 850 | + * This is provided as a handy method for a couple things: |
|
| 851 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 852 | + * write those filters wherever current_user_can is called). |
|
| 853 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 854 | + * |
|
| 855 | + * @since 4.5.0 |
|
| 856 | + * |
|
| 857 | + * @param string $cap The cap being checked. |
|
| 858 | + * @param string $context The context where the current_user_can is being called from. |
|
| 859 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 860 | + * filters. |
|
| 861 | + * |
|
| 862 | + * @return bool Whether user can or not. |
|
| 863 | + */ |
|
| 864 | + public function current_user_can($cap, $context, $id = 0) |
|
| 865 | + { |
|
| 866 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 867 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 868 | + $filtered_cap = apply_filters( |
|
| 869 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 870 | + $filtered_cap, |
|
| 871 | + $context, |
|
| 872 | + $cap, |
|
| 873 | + $id |
|
| 874 | + ); |
|
| 875 | + return ! empty($id) |
|
| 876 | + ? current_user_can($filtered_cap, $id) |
|
| 877 | + : current_user_can($filtered_cap); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 884 | + * |
|
| 885 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 886 | + * @param string $cap The capability string being checked |
|
| 887 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
| 888 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 889 | + * filters) |
|
| 890 | + * |
|
| 891 | + * @return bool Whether user can or not. |
|
| 892 | + */ |
|
| 893 | + public function user_can($user, $cap, $context, $id = 0) |
|
| 894 | + { |
|
| 895 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 896 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 897 | + $filtered_cap = apply_filters( |
|
| 898 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
| 899 | + $filtered_cap, |
|
| 900 | + $context, |
|
| 901 | + $cap, |
|
| 902 | + $user, |
|
| 903 | + $id |
|
| 904 | + ); |
|
| 905 | + return ! empty($id) |
|
| 906 | + ? user_can($user, $filtered_cap, $id) |
|
| 907 | + : user_can($user, $filtered_cap); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 914 | + * This is provided as a handy method for a couple things: |
|
| 915 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 916 | + * write those filters wherever current_user_can is called). |
|
| 917 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 918 | + * |
|
| 919 | + * @since 4.5.0 |
|
| 920 | + * |
|
| 921 | + * @param int $blog_id The blog id that is being checked for. |
|
| 922 | + * @param string $cap The cap being checked. |
|
| 923 | + * @param string $context The context where the current_user_can is being called from. |
|
| 924 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 925 | + * filters. |
|
| 926 | + * |
|
| 927 | + * @return bool Whether user can or not. |
|
| 928 | + */ |
|
| 929 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 930 | + { |
|
| 931 | + $user_can = ! empty($id) |
|
| 932 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 933 | + : current_user_can($blog_id, $cap); |
|
| 934 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 935 | + $user_can = apply_filters( |
|
| 936 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 937 | + $user_can, |
|
| 938 | + $blog_id, |
|
| 939 | + $cap, |
|
| 940 | + $id |
|
| 941 | + ); |
|
| 942 | + $user_can = apply_filters( |
|
| 943 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 944 | + $user_can, |
|
| 945 | + $context, |
|
| 946 | + $blog_id, |
|
| 947 | + $cap, |
|
| 948 | + $id |
|
| 949 | + ); |
|
| 950 | + return $user_can; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * This helper method just returns an array of registered EE capabilities. |
|
| 957 | + * |
|
| 958 | + * @since 4.5.0 |
|
| 959 | + * @param string $role If empty then the entire role/capability map is returned. |
|
| 960 | + * Otherwise just the capabilities for the given role are returned. |
|
| 961 | + * @return array |
|
| 962 | + * @throws EE_Error |
|
| 963 | + */ |
|
| 964 | + public function get_ee_capabilities($role = 'administrator') |
|
| 965 | + { |
|
| 966 | + if (! $this->initialized) { |
|
| 967 | + $this->init_caps(); |
|
| 968 | + } |
|
| 969 | + if (empty($role)) { |
|
| 970 | + return $this->capabilities_map; |
|
| 971 | + } |
|
| 972 | + return isset($this->capabilities_map[ $role ]) |
|
| 973 | + ? $this->capabilities_map[ $role ] |
|
| 974 | + : array(); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * @deprecated 4.9.42 |
|
| 981 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 982 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 983 | + * @param array $caps_map Optional. |
|
| 984 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 985 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
| 986 | + * task otherwise the caps will be added on every request. |
|
| 987 | + * @return void |
|
| 988 | + * @throws EE_Error |
|
| 989 | + */ |
|
| 990 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
| 991 | + { |
|
| 992 | + // If this method is called directly and reset is set as 'true', |
|
| 993 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 994 | + // to guarantee that everything is set up correctly. |
|
| 995 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 996 | + if ($reset) { |
|
| 997 | + EE_Error::doing_it_wrong( |
|
| 998 | + __METHOD__, |
|
| 999 | + sprintf( |
|
| 1000 | + esc_html__( |
|
| 1001 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 1002 | + 'event_espresso' |
|
| 1003 | + ), |
|
| 1004 | + '$reset', |
|
| 1005 | + __METHOD__ . '()', |
|
| 1006 | + 'EE_Capabilities::init_caps()', |
|
| 1007 | + 'true' |
|
| 1008 | + ), |
|
| 1009 | + '4.9.42', |
|
| 1010 | + '5.0.0' |
|
| 1011 | + ); |
|
| 1012 | + } |
|
| 1013 | + $this->addCaps($caps_map); |
|
| 1014 | + } |
|
| 1015 | 1015 | |
| 1016 | 1016 | |
| 1017 | 1017 | |
@@ -1032,142 +1032,142 @@ discard block |
||
| 1032 | 1032 | abstract class EE_Meta_Capability_Map |
| 1033 | 1033 | { |
| 1034 | 1034 | |
| 1035 | - public $meta_cap; |
|
| 1036 | - |
|
| 1037 | - /** |
|
| 1038 | - * @var EEM_Base |
|
| 1039 | - */ |
|
| 1040 | - protected $_model; |
|
| 1041 | - |
|
| 1042 | - protected $_model_name; |
|
| 1043 | - |
|
| 1044 | - public $published_cap = ''; |
|
| 1045 | - |
|
| 1046 | - public $others_cap = ''; |
|
| 1047 | - |
|
| 1048 | - public $private_cap = ''; |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * constructor. |
|
| 1053 | - * Receives the setup arguments for the map. |
|
| 1054 | - * |
|
| 1055 | - * @since 4.5.0 |
|
| 1056 | - * |
|
| 1057 | - * @param string $meta_cap What meta capability is this mapping. |
|
| 1058 | - * @param array $map_values array { |
|
| 1059 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1060 | - * capabilities that don't get mapped to. |
|
| 1061 | - * |
|
| 1062 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1063 | - * should always be used when Menu Maps are registered via the |
|
| 1064 | - * plugin API as models are not allowed to be instantiated when |
|
| 1065 | - * in maintenance mode 2 (migrations). |
|
| 1066 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1067 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1068 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1069 | - * } |
|
| 1070 | - * @throws EE_Error |
|
| 1071 | - */ |
|
| 1072 | - public function __construct($meta_cap, $map_values) |
|
| 1073 | - { |
|
| 1074 | - $this->meta_cap = $meta_cap; |
|
| 1075 | - //verify there are four args in the $map_values array; |
|
| 1076 | - if (count($map_values) !== 4) { |
|
| 1077 | - throw new EE_Error( |
|
| 1078 | - sprintf( |
|
| 1079 | - __( |
|
| 1080 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1081 | - 'event_espresso' |
|
| 1082 | - ), |
|
| 1083 | - '<br>' . print_r($map_values, true) |
|
| 1084 | - ) |
|
| 1085 | - ); |
|
| 1086 | - } |
|
| 1087 | - //set properties |
|
| 1088 | - $this->_model = null; |
|
| 1089 | - $this->_model_name = $map_values[0]; |
|
| 1090 | - $this->published_cap = (string)$map_values[1]; |
|
| 1091 | - $this->others_cap = (string)$map_values[2]; |
|
| 1092 | - $this->private_cap = (string)$map_values[3]; |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * Makes it so this object stops filtering caps |
|
| 1097 | - */ |
|
| 1098 | - public function remove_filters() |
|
| 1099 | - { |
|
| 1100 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1106 | - * |
|
| 1107 | - * @since 4.5.0 |
|
| 1108 | - * @throws EE_Error |
|
| 1109 | - * |
|
| 1110 | - * @return void |
|
| 1111 | - */ |
|
| 1112 | - public function ensure_is_model() |
|
| 1113 | - { |
|
| 1114 | - //is it already instantiated? |
|
| 1115 | - if ($this->_model instanceof EEM_Base) { |
|
| 1116 | - return; |
|
| 1117 | - } |
|
| 1118 | - //ensure model name is string |
|
| 1119 | - $this->_model_name = (string)$this->_model_name; |
|
| 1120 | - //error proof if the name has EEM in it |
|
| 1121 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1122 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1123 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1124 | - throw new EE_Error( |
|
| 1125 | - sprintf( |
|
| 1126 | - __( |
|
| 1127 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1128 | - 'event_espresso' |
|
| 1129 | - ), |
|
| 1130 | - get_class($this), |
|
| 1131 | - $this->_model |
|
| 1132 | - ) |
|
| 1133 | - ); |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - |
|
| 1138 | - /** |
|
| 1139 | - * |
|
| 1140 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1141 | - * @since 4.6.x |
|
| 1142 | - * |
|
| 1143 | - * @param $caps |
|
| 1144 | - * @param $cap |
|
| 1145 | - * @param $user_id |
|
| 1146 | - * @param $args |
|
| 1147 | - * |
|
| 1148 | - * @return array |
|
| 1149 | - */ |
|
| 1150 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1151 | - { |
|
| 1152 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1158 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1159 | - * |
|
| 1160 | - * @since 4.5.0 |
|
| 1161 | - * @see wp-includes/capabilities.php |
|
| 1162 | - * |
|
| 1163 | - * @param array $caps actual users capabilities |
|
| 1164 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1165 | - * @param int $user_id The user id |
|
| 1166 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1167 | - * |
|
| 1168 | - * @return array actual users capabilities |
|
| 1169 | - */ |
|
| 1170 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1035 | + public $meta_cap; |
|
| 1036 | + |
|
| 1037 | + /** |
|
| 1038 | + * @var EEM_Base |
|
| 1039 | + */ |
|
| 1040 | + protected $_model; |
|
| 1041 | + |
|
| 1042 | + protected $_model_name; |
|
| 1043 | + |
|
| 1044 | + public $published_cap = ''; |
|
| 1045 | + |
|
| 1046 | + public $others_cap = ''; |
|
| 1047 | + |
|
| 1048 | + public $private_cap = ''; |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * constructor. |
|
| 1053 | + * Receives the setup arguments for the map. |
|
| 1054 | + * |
|
| 1055 | + * @since 4.5.0 |
|
| 1056 | + * |
|
| 1057 | + * @param string $meta_cap What meta capability is this mapping. |
|
| 1058 | + * @param array $map_values array { |
|
| 1059 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1060 | + * capabilities that don't get mapped to. |
|
| 1061 | + * |
|
| 1062 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1063 | + * should always be used when Menu Maps are registered via the |
|
| 1064 | + * plugin API as models are not allowed to be instantiated when |
|
| 1065 | + * in maintenance mode 2 (migrations). |
|
| 1066 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1067 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1068 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1069 | + * } |
|
| 1070 | + * @throws EE_Error |
|
| 1071 | + */ |
|
| 1072 | + public function __construct($meta_cap, $map_values) |
|
| 1073 | + { |
|
| 1074 | + $this->meta_cap = $meta_cap; |
|
| 1075 | + //verify there are four args in the $map_values array; |
|
| 1076 | + if (count($map_values) !== 4) { |
|
| 1077 | + throw new EE_Error( |
|
| 1078 | + sprintf( |
|
| 1079 | + __( |
|
| 1080 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1081 | + 'event_espresso' |
|
| 1082 | + ), |
|
| 1083 | + '<br>' . print_r($map_values, true) |
|
| 1084 | + ) |
|
| 1085 | + ); |
|
| 1086 | + } |
|
| 1087 | + //set properties |
|
| 1088 | + $this->_model = null; |
|
| 1089 | + $this->_model_name = $map_values[0]; |
|
| 1090 | + $this->published_cap = (string)$map_values[1]; |
|
| 1091 | + $this->others_cap = (string)$map_values[2]; |
|
| 1092 | + $this->private_cap = (string)$map_values[3]; |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * Makes it so this object stops filtering caps |
|
| 1097 | + */ |
|
| 1098 | + public function remove_filters() |
|
| 1099 | + { |
|
| 1100 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1106 | + * |
|
| 1107 | + * @since 4.5.0 |
|
| 1108 | + * @throws EE_Error |
|
| 1109 | + * |
|
| 1110 | + * @return void |
|
| 1111 | + */ |
|
| 1112 | + public function ensure_is_model() |
|
| 1113 | + { |
|
| 1114 | + //is it already instantiated? |
|
| 1115 | + if ($this->_model instanceof EEM_Base) { |
|
| 1116 | + return; |
|
| 1117 | + } |
|
| 1118 | + //ensure model name is string |
|
| 1119 | + $this->_model_name = (string)$this->_model_name; |
|
| 1120 | + //error proof if the name has EEM in it |
|
| 1121 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1122 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1123 | + if (! $this->_model instanceof EEM_Base) { |
|
| 1124 | + throw new EE_Error( |
|
| 1125 | + sprintf( |
|
| 1126 | + __( |
|
| 1127 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1128 | + 'event_espresso' |
|
| 1129 | + ), |
|
| 1130 | + get_class($this), |
|
| 1131 | + $this->_model |
|
| 1132 | + ) |
|
| 1133 | + ); |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + |
|
| 1138 | + /** |
|
| 1139 | + * |
|
| 1140 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1141 | + * @since 4.6.x |
|
| 1142 | + * |
|
| 1143 | + * @param $caps |
|
| 1144 | + * @param $cap |
|
| 1145 | + * @param $user_id |
|
| 1146 | + * @param $args |
|
| 1147 | + * |
|
| 1148 | + * @return array |
|
| 1149 | + */ |
|
| 1150 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1151 | + { |
|
| 1152 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1158 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1159 | + * |
|
| 1160 | + * @since 4.5.0 |
|
| 1161 | + * @see wp-includes/capabilities.php |
|
| 1162 | + * |
|
| 1163 | + * @param array $caps actual users capabilities |
|
| 1164 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1165 | + * @param int $user_id The user id |
|
| 1166 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1167 | + * |
|
| 1168 | + * @return array actual users capabilities |
|
| 1169 | + */ |
|
| 1170 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | |
@@ -1183,81 +1183,81 @@ discard block |
||
| 1183 | 1183 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
| 1184 | 1184 | { |
| 1185 | 1185 | |
| 1186 | - /** |
|
| 1187 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1188 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1189 | - * |
|
| 1190 | - * @since 4.5.0 |
|
| 1191 | - * @see wp-includes/capabilities.php |
|
| 1192 | - * |
|
| 1193 | - * @param array $caps actual users capabilities |
|
| 1194 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1195 | - * @param int $user_id The user id |
|
| 1196 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1197 | - * |
|
| 1198 | - * @return array actual users capabilities |
|
| 1199 | - */ |
|
| 1200 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1201 | - { |
|
| 1202 | - //only process if we're checking our mapped_cap |
|
| 1203 | - if ($cap !== $this->meta_cap) { |
|
| 1204 | - return $caps; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1208 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1209 | - unset($caps[$key]); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - //cast $user_id to int for later explicit comparisons |
|
| 1213 | - $user_id = (int) $user_id; |
|
| 1214 | - |
|
| 1215 | - /** @var EE_Base_Class $obj */ |
|
| 1216 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1217 | - //if no obj then let's just do cap |
|
| 1218 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1219 | - $caps[] = 'do_not_allow'; |
|
| 1220 | - return $caps; |
|
| 1221 | - } |
|
| 1222 | - $caps[] = $cap . 's'; |
|
| 1223 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1224 | - //if the item author is set and the user is the author... |
|
| 1225 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1226 | - //if obj is published... |
|
| 1227 | - if ($obj->status() === 'publish') { |
|
| 1228 | - $caps[] = $this->published_cap; |
|
| 1229 | - } |
|
| 1230 | - } else { |
|
| 1231 | - //the user is trying to edit someone else's obj |
|
| 1232 | - if (! empty($this->others_cap)) { |
|
| 1233 | - $caps[] = $this->others_cap; |
|
| 1234 | - } |
|
| 1235 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1236 | - $caps[] = $this->published_cap; |
|
| 1237 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1238 | - $caps[] = $this->private_cap; |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - } else { |
|
| 1242 | - //not a cpt object so handled differently |
|
| 1243 | - $has_cap = false; |
|
| 1244 | - try { |
|
| 1245 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1246 | - && $obj->wp_user() |
|
| 1247 | - && $obj->wp_user() === $user_id; |
|
| 1248 | - } catch (Exception $e) { |
|
| 1249 | - if (WP_DEBUG) { |
|
| 1250 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1251 | - } |
|
| 1252 | - } |
|
| 1253 | - if (! $has_cap) { |
|
| 1254 | - if (! empty($this->others_cap)) { |
|
| 1255 | - $caps[] = $this->others_cap; |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - return $caps; |
|
| 1260 | - } |
|
| 1186 | + /** |
|
| 1187 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1188 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1189 | + * |
|
| 1190 | + * @since 4.5.0 |
|
| 1191 | + * @see wp-includes/capabilities.php |
|
| 1192 | + * |
|
| 1193 | + * @param array $caps actual users capabilities |
|
| 1194 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1195 | + * @param int $user_id The user id |
|
| 1196 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1197 | + * |
|
| 1198 | + * @return array actual users capabilities |
|
| 1199 | + */ |
|
| 1200 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1201 | + { |
|
| 1202 | + //only process if we're checking our mapped_cap |
|
| 1203 | + if ($cap !== $this->meta_cap) { |
|
| 1204 | + return $caps; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1208 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1209 | + unset($caps[$key]); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + //cast $user_id to int for later explicit comparisons |
|
| 1213 | + $user_id = (int) $user_id; |
|
| 1214 | + |
|
| 1215 | + /** @var EE_Base_Class $obj */ |
|
| 1216 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1217 | + //if no obj then let's just do cap |
|
| 1218 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1219 | + $caps[] = 'do_not_allow'; |
|
| 1220 | + return $caps; |
|
| 1221 | + } |
|
| 1222 | + $caps[] = $cap . 's'; |
|
| 1223 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1224 | + //if the item author is set and the user is the author... |
|
| 1225 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1226 | + //if obj is published... |
|
| 1227 | + if ($obj->status() === 'publish') { |
|
| 1228 | + $caps[] = $this->published_cap; |
|
| 1229 | + } |
|
| 1230 | + } else { |
|
| 1231 | + //the user is trying to edit someone else's obj |
|
| 1232 | + if (! empty($this->others_cap)) { |
|
| 1233 | + $caps[] = $this->others_cap; |
|
| 1234 | + } |
|
| 1235 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1236 | + $caps[] = $this->published_cap; |
|
| 1237 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1238 | + $caps[] = $this->private_cap; |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + } else { |
|
| 1242 | + //not a cpt object so handled differently |
|
| 1243 | + $has_cap = false; |
|
| 1244 | + try { |
|
| 1245 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1246 | + && $obj->wp_user() |
|
| 1247 | + && $obj->wp_user() === $user_id; |
|
| 1248 | + } catch (Exception $e) { |
|
| 1249 | + if (WP_DEBUG) { |
|
| 1250 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1251 | + } |
|
| 1252 | + } |
|
| 1253 | + if (! $has_cap) { |
|
| 1254 | + if (! empty($this->others_cap)) { |
|
| 1255 | + $caps[] = $this->others_cap; |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + return $caps; |
|
| 1260 | + } |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | |
@@ -1274,24 +1274,24 @@ discard block |
||
| 1274 | 1274 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
| 1275 | 1275 | { |
| 1276 | 1276 | |
| 1277 | - /** |
|
| 1278 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1279 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1280 | - * |
|
| 1281 | - * @since 4.5.0 |
|
| 1282 | - * @see wp-includes/capabilities.php |
|
| 1283 | - * |
|
| 1284 | - * @param array $caps actual users capabilities |
|
| 1285 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1286 | - * @param int $user_id The user id |
|
| 1287 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1288 | - * |
|
| 1289 | - * @return array actual users capabilities |
|
| 1290 | - */ |
|
| 1291 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1292 | - { |
|
| 1293 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1294 | - } |
|
| 1277 | + /** |
|
| 1278 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1279 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1280 | + * |
|
| 1281 | + * @since 4.5.0 |
|
| 1282 | + * @see wp-includes/capabilities.php |
|
| 1283 | + * |
|
| 1284 | + * @param array $caps actual users capabilities |
|
| 1285 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1286 | + * @param int $user_id The user id |
|
| 1287 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1288 | + * |
|
| 1289 | + * @return array actual users capabilities |
|
| 1290 | + */ |
|
| 1291 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1292 | + { |
|
| 1293 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1294 | + } |
|
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | |
@@ -1307,85 +1307,85 @@ discard block |
||
| 1307 | 1307 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
| 1308 | 1308 | { |
| 1309 | 1309 | |
| 1310 | - /** |
|
| 1311 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1312 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1313 | - * |
|
| 1314 | - * @since 4.5.0 |
|
| 1315 | - * @see wp-includes/capabilities.php |
|
| 1316 | - * |
|
| 1317 | - * @param array $caps actual users capabilities |
|
| 1318 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1319 | - * @param int $user_id The user id |
|
| 1320 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1321 | - * |
|
| 1322 | - * @return array actual users capabilities |
|
| 1323 | - */ |
|
| 1324 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1325 | - { |
|
| 1326 | - //only process if we're checking our mapped cap; |
|
| 1327 | - if ($cap !== $this->meta_cap) { |
|
| 1328 | - return $caps; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1332 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1333 | - unset($caps[$key]); |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - //cast $user_id to int for later explicit comparisons |
|
| 1337 | - $user_id = (int) $user_id; |
|
| 1338 | - |
|
| 1339 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1340 | - //if no obj then let's just do cap |
|
| 1341 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1342 | - $caps[] = 'do_not_allow'; |
|
| 1343 | - return $caps; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - $caps[] = $cap . 's'; |
|
| 1347 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1348 | - $status_obj = get_post_status_object($obj->status()); |
|
| 1349 | - if ($status_obj->public) { |
|
| 1350 | - return $caps; |
|
| 1351 | - } |
|
| 1352 | - //if the item author is set and the user is not the author... |
|
| 1353 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1354 | - if (! empty($this->others_cap)) { |
|
| 1355 | - $caps[] = $this->others_cap; |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1358 | - //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1359 | - if ($status_obj->private |
|
| 1360 | - && ! empty($this->private_cap) |
|
| 1361 | - && $obj->wp_user() !== $user_id |
|
| 1362 | - ) { |
|
| 1363 | - //the user is trying to view a private object for an object they don't own. |
|
| 1364 | - $caps[] = $this->private_cap; |
|
| 1365 | - } |
|
| 1366 | - } else { |
|
| 1367 | - //not a cpt object so handled differently |
|
| 1368 | - $has_cap = false; |
|
| 1369 | - try { |
|
| 1370 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1371 | - && $obj->wp_user() |
|
| 1372 | - && $obj->wp_user() === $user_id; |
|
| 1373 | - } catch (Exception $e) { |
|
| 1374 | - if (WP_DEBUG) { |
|
| 1375 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - if (! $has_cap) { |
|
| 1379 | - if (! empty($this->private_cap)) { |
|
| 1380 | - $caps[] = $this->private_cap; |
|
| 1381 | - } |
|
| 1382 | - if (! empty($this->others_cap)) { |
|
| 1383 | - $caps[] = $this->others_cap; |
|
| 1384 | - } |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - return $caps; |
|
| 1388 | - } |
|
| 1310 | + /** |
|
| 1311 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1312 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1313 | + * |
|
| 1314 | + * @since 4.5.0 |
|
| 1315 | + * @see wp-includes/capabilities.php |
|
| 1316 | + * |
|
| 1317 | + * @param array $caps actual users capabilities |
|
| 1318 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1319 | + * @param int $user_id The user id |
|
| 1320 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1321 | + * |
|
| 1322 | + * @return array actual users capabilities |
|
| 1323 | + */ |
|
| 1324 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1325 | + { |
|
| 1326 | + //only process if we're checking our mapped cap; |
|
| 1327 | + if ($cap !== $this->meta_cap) { |
|
| 1328 | + return $caps; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1332 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1333 | + unset($caps[$key]); |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + //cast $user_id to int for later explicit comparisons |
|
| 1337 | + $user_id = (int) $user_id; |
|
| 1338 | + |
|
| 1339 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1340 | + //if no obj then let's just do cap |
|
| 1341 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1342 | + $caps[] = 'do_not_allow'; |
|
| 1343 | + return $caps; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + $caps[] = $cap . 's'; |
|
| 1347 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1348 | + $status_obj = get_post_status_object($obj->status()); |
|
| 1349 | + if ($status_obj->public) { |
|
| 1350 | + return $caps; |
|
| 1351 | + } |
|
| 1352 | + //if the item author is set and the user is not the author... |
|
| 1353 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1354 | + if (! empty($this->others_cap)) { |
|
| 1355 | + $caps[] = $this->others_cap; |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | + //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1359 | + if ($status_obj->private |
|
| 1360 | + && ! empty($this->private_cap) |
|
| 1361 | + && $obj->wp_user() !== $user_id |
|
| 1362 | + ) { |
|
| 1363 | + //the user is trying to view a private object for an object they don't own. |
|
| 1364 | + $caps[] = $this->private_cap; |
|
| 1365 | + } |
|
| 1366 | + } else { |
|
| 1367 | + //not a cpt object so handled differently |
|
| 1368 | + $has_cap = false; |
|
| 1369 | + try { |
|
| 1370 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1371 | + && $obj->wp_user() |
|
| 1372 | + && $obj->wp_user() === $user_id; |
|
| 1373 | + } catch (Exception $e) { |
|
| 1374 | + if (WP_DEBUG) { |
|
| 1375 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + if (! $has_cap) { |
|
| 1379 | + if (! empty($this->private_cap)) { |
|
| 1380 | + $caps[] = $this->private_cap; |
|
| 1381 | + } |
|
| 1382 | + if (! empty($this->others_cap)) { |
|
| 1383 | + $caps[] = $this->others_cap; |
|
| 1384 | + } |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + return $caps; |
|
| 1388 | + } |
|
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | |
@@ -1402,56 +1402,56 @@ discard block |
||
| 1402 | 1402 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
| 1403 | 1403 | { |
| 1404 | 1404 | |
| 1405 | - /** |
|
| 1406 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1407 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1408 | - * |
|
| 1409 | - * @since 4.5.0 |
|
| 1410 | - * @see wp-includes/capabilities.php |
|
| 1411 | - * |
|
| 1412 | - * @param array $caps actual users capabilities |
|
| 1413 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1414 | - * @param int $user_id The user id |
|
| 1415 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1416 | - * |
|
| 1417 | - * @return array actual users capabilities |
|
| 1418 | - */ |
|
| 1419 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1420 | - { |
|
| 1421 | - //only process if we're checking our mapped_cap |
|
| 1422 | - if ($cap !== $this->meta_cap) { |
|
| 1423 | - return $caps; |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1427 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1428 | - unset($caps[$key]); |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - //cast $user_id to int for later explicit comparisons |
|
| 1432 | - $user_id = (int) $user_id; |
|
| 1433 | - |
|
| 1434 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1435 | - //if no obj then let's just do cap |
|
| 1436 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1437 | - $caps[] = 'do_not_allow'; |
|
| 1438 | - return $caps; |
|
| 1439 | - } |
|
| 1440 | - $caps[] = $cap . 's'; |
|
| 1441 | - $is_global = $obj->is_global(); |
|
| 1442 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1443 | - if ($is_global) { |
|
| 1444 | - $caps[] = $this->private_cap; |
|
| 1445 | - } |
|
| 1446 | - } else { |
|
| 1447 | - if ($is_global) { |
|
| 1448 | - $caps[] = $this->private_cap; |
|
| 1449 | - } else { |
|
| 1450 | - $caps[] = $this->others_cap; |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - return $caps; |
|
| 1454 | - } |
|
| 1405 | + /** |
|
| 1406 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1407 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1408 | + * |
|
| 1409 | + * @since 4.5.0 |
|
| 1410 | + * @see wp-includes/capabilities.php |
|
| 1411 | + * |
|
| 1412 | + * @param array $caps actual users capabilities |
|
| 1413 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1414 | + * @param int $user_id The user id |
|
| 1415 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1416 | + * |
|
| 1417 | + * @return array actual users capabilities |
|
| 1418 | + */ |
|
| 1419 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1420 | + { |
|
| 1421 | + //only process if we're checking our mapped_cap |
|
| 1422 | + if ($cap !== $this->meta_cap) { |
|
| 1423 | + return $caps; |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1427 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1428 | + unset($caps[$key]); |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + //cast $user_id to int for later explicit comparisons |
|
| 1432 | + $user_id = (int) $user_id; |
|
| 1433 | + |
|
| 1434 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1435 | + //if no obj then let's just do cap |
|
| 1436 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1437 | + $caps[] = 'do_not_allow'; |
|
| 1438 | + return $caps; |
|
| 1439 | + } |
|
| 1440 | + $caps[] = $cap . 's'; |
|
| 1441 | + $is_global = $obj->is_global(); |
|
| 1442 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1443 | + if ($is_global) { |
|
| 1444 | + $caps[] = $this->private_cap; |
|
| 1445 | + } |
|
| 1446 | + } else { |
|
| 1447 | + if ($is_global) { |
|
| 1448 | + $caps[] = $this->private_cap; |
|
| 1449 | + } else { |
|
| 1450 | + $caps[] = $this->others_cap; |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + return $caps; |
|
| 1454 | + } |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | |
@@ -1468,40 +1468,40 @@ discard block |
||
| 1468 | 1468 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
| 1469 | 1469 | { |
| 1470 | 1470 | |
| 1471 | - /** |
|
| 1472 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1473 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1474 | - * |
|
| 1475 | - * @since 4.5.0 |
|
| 1476 | - * @see wp-includes/capabilities.php |
|
| 1477 | - * @param array $caps actual users capabilities |
|
| 1478 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1479 | - * @param int $user_id The user id |
|
| 1480 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1481 | - * @return array actual users capabilities |
|
| 1482 | - */ |
|
| 1483 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1484 | - { |
|
| 1485 | - //only process if we're checking our mapped_cap |
|
| 1486 | - if ($cap !== $this->meta_cap) { |
|
| 1487 | - return $caps; |
|
| 1488 | - } |
|
| 1489 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1490 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1491 | - unset($caps[$key]); |
|
| 1492 | - } |
|
| 1493 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1494 | - //if no obj then let's just do cap |
|
| 1495 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1496 | - $caps[] = 'do_not_allow'; |
|
| 1497 | - return $caps; |
|
| 1498 | - } |
|
| 1499 | - $caps[] = $cap . 's'; |
|
| 1500 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1501 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1502 | - if ($is_system) { |
|
| 1503 | - $caps[] = $this->private_cap; |
|
| 1504 | - } |
|
| 1505 | - return $caps; |
|
| 1506 | - } |
|
| 1471 | + /** |
|
| 1472 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1473 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1474 | + * |
|
| 1475 | + * @since 4.5.0 |
|
| 1476 | + * @see wp-includes/capabilities.php |
|
| 1477 | + * @param array $caps actual users capabilities |
|
| 1478 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1479 | + * @param int $user_id The user id |
|
| 1480 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1481 | + * @return array actual users capabilities |
|
| 1482 | + */ |
|
| 1483 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1484 | + { |
|
| 1485 | + //only process if we're checking our mapped_cap |
|
| 1486 | + if ($cap !== $this->meta_cap) { |
|
| 1487 | + return $caps; |
|
| 1488 | + } |
|
| 1489 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1490 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1491 | + unset($caps[$key]); |
|
| 1492 | + } |
|
| 1493 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1494 | + //if no obj then let's just do cap |
|
| 1495 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1496 | + $caps[] = 'do_not_allow'; |
|
| 1497 | + return $caps; |
|
| 1498 | + } |
|
| 1499 | + $caps[] = $cap . 's'; |
|
| 1500 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1501 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1502 | + if ($is_system) { |
|
| 1503 | + $caps[] = $this->private_cap; |
|
| 1504 | + } |
|
| 1505 | + return $caps; |
|
| 1506 | + } |
|
| 1507 | 1507 | } |
@@ -22,103 +22,103 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var LoaderDecoratorInterface $new_loader |
|
| 27 | - */ |
|
| 28 | - private $new_loader; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | - */ |
|
| 34 | - private $shared_loader; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Loader constructor. |
|
| 40 | - * |
|
| 41 | - * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | - * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | - * @throws InvalidInterfaceException |
|
| 44 | - * @throws InvalidArgumentException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | - { |
|
| 49 | - $this->new_loader = $new_loader; |
|
| 50 | - $this->shared_loader = $shared_loader; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return LoaderDecoratorInterface |
|
| 57 | - */ |
|
| 58 | - public function getNewLoader() |
|
| 59 | - { |
|
| 60 | - return $this->new_loader; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return LoaderDecoratorInterface |
|
| 67 | - */ |
|
| 68 | - public function getSharedLoader() |
|
| 69 | - { |
|
| 70 | - return $this->shared_loader; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $fqcn |
|
| 77 | - * @param array $arguments |
|
| 78 | - * @param bool $shared |
|
| 79 | - * @return mixed |
|
| 80 | - */ |
|
| 81 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | - { |
|
| 83 | - return $shared |
|
| 84 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $fqcn |
|
| 92 | - * @param array $arguments |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - public function getNew($fqcn, $arguments = array()) |
|
| 96 | - { |
|
| 97 | - return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $fqcn |
|
| 104 | - * @param array $arguments |
|
| 105 | - * @return mixed |
|
| 106 | - */ |
|
| 107 | - public function getShared($fqcn, $arguments = array()) |
|
| 108 | - { |
|
| 109 | - return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * calls reset() on loaders if that method exists |
|
| 116 | - */ |
|
| 117 | - public function reset() |
|
| 118 | - { |
|
| 119 | - $this->new_loader->reset(); |
|
| 120 | - $this->shared_loader->reset(); |
|
| 121 | - } |
|
| 25 | + /** |
|
| 26 | + * @var LoaderDecoratorInterface $new_loader |
|
| 27 | + */ |
|
| 28 | + private $new_loader; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | + */ |
|
| 34 | + private $shared_loader; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Loader constructor. |
|
| 40 | + * |
|
| 41 | + * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | + * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | + * @throws InvalidInterfaceException |
|
| 44 | + * @throws InvalidArgumentException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | + { |
|
| 49 | + $this->new_loader = $new_loader; |
|
| 50 | + $this->shared_loader = $shared_loader; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return LoaderDecoratorInterface |
|
| 57 | + */ |
|
| 58 | + public function getNewLoader() |
|
| 59 | + { |
|
| 60 | + return $this->new_loader; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return LoaderDecoratorInterface |
|
| 67 | + */ |
|
| 68 | + public function getSharedLoader() |
|
| 69 | + { |
|
| 70 | + return $this->shared_loader; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $fqcn |
|
| 77 | + * @param array $arguments |
|
| 78 | + * @param bool $shared |
|
| 79 | + * @return mixed |
|
| 80 | + */ |
|
| 81 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | + { |
|
| 83 | + return $shared |
|
| 84 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $fqcn |
|
| 92 | + * @param array $arguments |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + public function getNew($fqcn, $arguments = array()) |
|
| 96 | + { |
|
| 97 | + return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $fqcn |
|
| 104 | + * @param array $arguments |
|
| 105 | + * @return mixed |
|
| 106 | + */ |
|
| 107 | + public function getShared($fqcn, $arguments = array()) |
|
| 108 | + { |
|
| 109 | + return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * calls reset() on loaders if that method exists |
|
| 116 | + */ |
|
| 117 | + public function reset() |
|
| 118 | + { |
|
| 119 | + $this->new_loader->reset(); |
|
| 120 | + $this->shared_loader->reset(); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | // End of file Loader.php |
@@ -26,67 +26,67 @@ |
||
| 26 | 26 | class CoreLoader implements LoaderDecoratorInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var EE_Registry|CoffeeShop $generator |
|
| 31 | - */ |
|
| 32 | - private $generator; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * CoreLoader constructor. |
|
| 38 | - * |
|
| 39 | - * @param EE_Registry|CoffeeShop $generator |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - */ |
|
| 42 | - public function __construct($generator) |
|
| 43 | - { |
|
| 44 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 45 | - throw new InvalidArgumentException( |
|
| 46 | - esc_html__( |
|
| 47 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 48 | - 'event_espresso' |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - } |
|
| 52 | - $this->generator = $generator; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $fqcn |
|
| 59 | - * @param array $arguments |
|
| 60 | - * @param bool $shared |
|
| 61 | - * @return mixed |
|
| 62 | - * @throws EE_Error |
|
| 63 | - * @throws ServiceNotFoundException |
|
| 64 | - * @throws ReflectionException |
|
| 65 | - */ |
|
| 66 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 67 | - { |
|
| 68 | - if($this->generator instanceof EE_Registry) { |
|
| 69 | - return $this->generator->create($fqcn, $arguments, $shared); |
|
| 70 | - } |
|
| 71 | - $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
|
| 72 | - return $this->generator->brew($fqcn, $arguments, $shared); |
|
| 73 | - |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * calls reset() on generator if method exists |
|
| 80 | - * |
|
| 81 | - * @throws EE_Error |
|
| 82 | - * @throws ReflectionException |
|
| 83 | - */ |
|
| 84 | - public function reset() |
|
| 85 | - { |
|
| 86 | - if (method_exists($this->generator, 'reset')) { |
|
| 87 | - $this->generator->reset(); |
|
| 88 | - } |
|
| 89 | - } |
|
| 29 | + /** |
|
| 30 | + * @var EE_Registry|CoffeeShop $generator |
|
| 31 | + */ |
|
| 32 | + private $generator; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * CoreLoader constructor. |
|
| 38 | + * |
|
| 39 | + * @param EE_Registry|CoffeeShop $generator |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + */ |
|
| 42 | + public function __construct($generator) |
|
| 43 | + { |
|
| 44 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 45 | + throw new InvalidArgumentException( |
|
| 46 | + esc_html__( |
|
| 47 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 48 | + 'event_espresso' |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | + $this->generator = $generator; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $fqcn |
|
| 59 | + * @param array $arguments |
|
| 60 | + * @param bool $shared |
|
| 61 | + * @return mixed |
|
| 62 | + * @throws EE_Error |
|
| 63 | + * @throws ServiceNotFoundException |
|
| 64 | + * @throws ReflectionException |
|
| 65 | + */ |
|
| 66 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 67 | + { |
|
| 68 | + if($this->generator instanceof EE_Registry) { |
|
| 69 | + return $this->generator->create($fqcn, $arguments, $shared); |
|
| 70 | + } |
|
| 71 | + $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW; |
|
| 72 | + return $this->generator->brew($fqcn, $arguments, $shared); |
|
| 73 | + |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * calls reset() on generator if method exists |
|
| 80 | + * |
|
| 81 | + * @throws EE_Error |
|
| 82 | + * @throws ReflectionException |
|
| 83 | + */ |
|
| 84 | + public function reset() |
|
| 85 | + { |
|
| 86 | + if (method_exists($this->generator, 'reset')) { |
|
| 87 | + $this->generator->reset(); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | // End of file CoreLoader.php |
@@ -18,305 +18,305 @@ |
||
| 18 | 18 | class DatetimeOffsetFix extends JobHandler |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Key for the option used to track which models have been processed when doing the batches. |
|
| 23 | - */ |
|
| 24 | - const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
| 31 | - */ |
|
| 32 | - const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * String labelling the datetime offset fix type for change-log entries. |
|
| 37 | - */ |
|
| 38 | - const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * String labelling a datetime offset fix error for change-log entries. |
|
| 43 | - */ |
|
| 44 | - const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EEM_Base[] |
|
| 48 | - */ |
|
| 49 | - protected $models_with_datetime_fields = array(); |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Performs any necessary setup for starting the job. This is also a good |
|
| 54 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 55 | - * when continue_job will be called |
|
| 56 | - * |
|
| 57 | - * @param JobParameters $job_parameters |
|
| 58 | - * @throws BatchRequestException |
|
| 59 | - * @return JobStepResponse |
|
| 60 | - */ |
|
| 61 | - public function create_job(JobParameters $job_parameters) |
|
| 62 | - { |
|
| 63 | - $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
| 64 | - //we'll be doing each model as a batch. |
|
| 65 | - $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
| 66 | - return new JobStepResponse( |
|
| 67 | - $job_parameters, |
|
| 68 | - esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Performs another step of the job |
|
| 74 | - * |
|
| 75 | - * @param JobParameters $job_parameters |
|
| 76 | - * @param int $batch_size |
|
| 77 | - * @return JobStepResponse |
|
| 78 | - * @throws \EE_Error |
|
| 79 | - */ |
|
| 80 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 81 | - { |
|
| 82 | - $models_to_process = $this->getModelsWithDatetimeFields(); |
|
| 83 | - //let's pop off the a model and do the query to apply the offset. |
|
| 84 | - $model_to_process = array_pop($models_to_process); |
|
| 85 | - //update our record |
|
| 86 | - $this->setModelsToProcess($models_to_process); |
|
| 87 | - $this->processModel($model_to_process); |
|
| 88 | - $this->updateCountOfModelsProcessed(); |
|
| 89 | - $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
| 90 | - if (count($models_to_process) > 0) { |
|
| 91 | - $job_parameters->set_status(JobParameters::status_continue); |
|
| 92 | - } else { |
|
| 93 | - $job_parameters->set_status(JobParameters::status_complete); |
|
| 94 | - } |
|
| 95 | - return new JobStepResponse( |
|
| 96 | - $job_parameters, |
|
| 97 | - sprintf( |
|
| 98 | - esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
| 99 | - $model_to_process |
|
| 100 | - ) |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Performs any clean-up logic when we know the job is completed |
|
| 106 | - * |
|
| 107 | - * @param JobParameters $job_parameters |
|
| 108 | - * @return JobStepResponse |
|
| 109 | - * @throws BatchRequestException |
|
| 110 | - */ |
|
| 111 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 112 | - { |
|
| 113 | - //delete important saved options. |
|
| 114 | - delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
| 115 | - delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
| 116 | - return new JobStepResponse($job_parameters, esc_html__( |
|
| 117 | - 'Offset has been applied to all affected fields.', |
|
| 118 | - 'event_espresso' |
|
| 119 | - )); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
| 125 | - * @param string $model_class_name |
|
| 126 | - * @throws \EE_Error |
|
| 127 | - */ |
|
| 128 | - protected function processModel($model_class_name) |
|
| 129 | - { |
|
| 130 | - global $wpdb; |
|
| 131 | - /** @var EEM_Base $model */ |
|
| 132 | - $model = $model_class_name::instance(); |
|
| 133 | - $original_offset = self::getOffset(); |
|
| 134 | - $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
| 135 | - $offset = abs($original_offset) * 60; |
|
| 136 | - //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
| 137 | - foreach ($model->get_tables() as $table) { |
|
| 138 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
| 139 | - $fields_affected = array(); |
|
| 140 | - $inner_query = array(); |
|
| 141 | - foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
| 142 | - if ($model_field instanceof EE_Datetime_Field) { |
|
| 143 | - $inner_query[] = $model_field->get_table_column() . ' = ' |
|
| 144 | - . $sql_date_function . '(' |
|
| 145 | - . $model_field->get_table_column() |
|
| 146 | - . ", INTERVAL $offset MINUTE)"; |
|
| 147 | - $fields_affected[] = $model_field; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if (! $fields_affected) { |
|
| 151 | - continue; |
|
| 152 | - } |
|
| 153 | - //k convert innerquery to string |
|
| 154 | - $query .= ' SET ' . implode(',', $inner_query); |
|
| 155 | - //execute query |
|
| 156 | - $result = $wpdb->query($query); |
|
| 157 | - //record log |
|
| 158 | - if ($result !== false) { |
|
| 159 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
| 160 | - } else { |
|
| 161 | - //record error. |
|
| 162 | - $error_message = $wpdb->last_error; |
|
| 163 | - //handle the edgecases where last_error might be empty. |
|
| 164 | - if (! $error_message) { |
|
| 165 | - $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
| 166 | - } |
|
| 167 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Records a changelog entry using the given information. |
|
| 175 | - * |
|
| 176 | - * @param EEM_Base $model |
|
| 177 | - * @param float $offset |
|
| 178 | - * @param EE_Table_Base $table |
|
| 179 | - * @param EE_Model_Field_Base[] $model_fields_affected |
|
| 180 | - * @param string $error_message If present then there was an error so let's record that instead. |
|
| 181 | - * @throws \EE_Error |
|
| 182 | - */ |
|
| 183 | - private function recordChangeLog( |
|
| 184 | - EEM_Base $model, |
|
| 185 | - $offset, |
|
| 186 | - EE_Table_Base $table, |
|
| 187 | - $model_fields_affected, |
|
| 188 | - $error_message = '' |
|
| 189 | - ) { |
|
| 190 | - //setup $fields list. |
|
| 191 | - $fields = array(); |
|
| 192 | - /** @var EE_Datetime_Field $model_field */ |
|
| 193 | - foreach ($model_fields_affected as $model_field) { |
|
| 194 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
| 195 | - continue; |
|
| 196 | - } |
|
| 197 | - $fields[] = $model_field->get_name(); |
|
| 198 | - } |
|
| 199 | - //setup the message for the changelog entry. |
|
| 200 | - $message = $error_message |
|
| 201 | - ? sprintf( |
|
| 202 | - esc_html__( |
|
| 203 | - 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ), |
|
| 206 | - $table->get_table_name(), |
|
| 207 | - $model->get_this_model_name(), |
|
| 208 | - $offset, |
|
| 209 | - implode(',', $fields), |
|
| 210 | - $error_message |
|
| 211 | - ) |
|
| 212 | - : sprintf( |
|
| 213 | - esc_html__( |
|
| 214 | - 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
| 215 | - 'event_espresso' |
|
| 216 | - ), |
|
| 217 | - $table->get_table_name(), |
|
| 218 | - $model->get_this_model_name(), |
|
| 219 | - $offset, |
|
| 220 | - implode(',', $fields) |
|
| 221 | - ); |
|
| 222 | - //write to the log |
|
| 223 | - $changelog = EE_Change_Log::new_instance(array( |
|
| 224 | - 'LOG_type' => $error_message |
|
| 225 | - ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
| 226 | - : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
| 227 | - 'LOG_message' => $message |
|
| 228 | - )); |
|
| 229 | - $changelog->save(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Returns an array of models that have datetime fields. |
|
| 235 | - * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
| 236 | - * @return array an array of model class names. |
|
| 237 | - */ |
|
| 238 | - private function getModelsWithDatetimeFields() |
|
| 239 | - { |
|
| 240 | - $this->getModelsToProcess(); |
|
| 241 | - if (! empty($this->models_with_datetime_fields)) { |
|
| 242 | - return $this->models_with_datetime_fields; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
| 246 | - foreach ($all_non_abstract_models as $non_abstract_model) { |
|
| 247 | - //get model instance |
|
| 248 | - /** @var EEM_Base $non_abstract_model */ |
|
| 249 | - $non_abstract_model = $non_abstract_model::instance(); |
|
| 250 | - if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
| 251 | - $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - $this->setModelsToProcess($this->models_with_datetime_fields); |
|
| 255 | - return $this->models_with_datetime_fields; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * This simply records the models that have been processed with our tracking option. |
|
| 261 | - * @param array $models_to_set array of model class names. |
|
| 262 | - */ |
|
| 263 | - private function setModelsToProcess($models_to_set) |
|
| 264 | - { |
|
| 265 | - update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Used to keep track of how many models have been processed for the batch |
|
| 271 | - * @param $count |
|
| 272 | - */ |
|
| 273 | - private function updateCountOfModelsProcessed($count = 1) |
|
| 274 | - { |
|
| 275 | - $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
| 276 | - update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Retrieve the tracked number of models processed between requests. |
|
| 282 | - * @return int |
|
| 283 | - */ |
|
| 284 | - private function getCountOfModelsProcessed() |
|
| 285 | - { |
|
| 286 | - return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Returns the models that are left to process. |
|
| 292 | - * @return array an array of model class names. |
|
| 293 | - */ |
|
| 294 | - private function getModelsToProcess() |
|
| 295 | - { |
|
| 296 | - if (empty($this->models_with_datetime_fields)) { |
|
| 297 | - $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
| 298 | - } |
|
| 299 | - return $this->models_with_datetime_fields; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 305 | - * @param float $offset |
|
| 306 | - */ |
|
| 307 | - public static function updateOffset($offset) |
|
| 308 | - { |
|
| 309 | - update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 315 | - * |
|
| 316 | - * @return float |
|
| 317 | - */ |
|
| 318 | - public static function getOffset() |
|
| 319 | - { |
|
| 320 | - return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
| 321 | - } |
|
| 21 | + /** |
|
| 22 | + * Key for the option used to track which models have been processed when doing the batches. |
|
| 23 | + */ |
|
| 24 | + const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
| 31 | + */ |
|
| 32 | + const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * String labelling the datetime offset fix type for change-log entries. |
|
| 37 | + */ |
|
| 38 | + const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * String labelling a datetime offset fix error for change-log entries. |
|
| 43 | + */ |
|
| 44 | + const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EEM_Base[] |
|
| 48 | + */ |
|
| 49 | + protected $models_with_datetime_fields = array(); |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Performs any necessary setup for starting the job. This is also a good |
|
| 54 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 55 | + * when continue_job will be called |
|
| 56 | + * |
|
| 57 | + * @param JobParameters $job_parameters |
|
| 58 | + * @throws BatchRequestException |
|
| 59 | + * @return JobStepResponse |
|
| 60 | + */ |
|
| 61 | + public function create_job(JobParameters $job_parameters) |
|
| 62 | + { |
|
| 63 | + $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
| 64 | + //we'll be doing each model as a batch. |
|
| 65 | + $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
| 66 | + return new JobStepResponse( |
|
| 67 | + $job_parameters, |
|
| 68 | + esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Performs another step of the job |
|
| 74 | + * |
|
| 75 | + * @param JobParameters $job_parameters |
|
| 76 | + * @param int $batch_size |
|
| 77 | + * @return JobStepResponse |
|
| 78 | + * @throws \EE_Error |
|
| 79 | + */ |
|
| 80 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 81 | + { |
|
| 82 | + $models_to_process = $this->getModelsWithDatetimeFields(); |
|
| 83 | + //let's pop off the a model and do the query to apply the offset. |
|
| 84 | + $model_to_process = array_pop($models_to_process); |
|
| 85 | + //update our record |
|
| 86 | + $this->setModelsToProcess($models_to_process); |
|
| 87 | + $this->processModel($model_to_process); |
|
| 88 | + $this->updateCountOfModelsProcessed(); |
|
| 89 | + $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
| 90 | + if (count($models_to_process) > 0) { |
|
| 91 | + $job_parameters->set_status(JobParameters::status_continue); |
|
| 92 | + } else { |
|
| 93 | + $job_parameters->set_status(JobParameters::status_complete); |
|
| 94 | + } |
|
| 95 | + return new JobStepResponse( |
|
| 96 | + $job_parameters, |
|
| 97 | + sprintf( |
|
| 98 | + esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
| 99 | + $model_to_process |
|
| 100 | + ) |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Performs any clean-up logic when we know the job is completed |
|
| 106 | + * |
|
| 107 | + * @param JobParameters $job_parameters |
|
| 108 | + * @return JobStepResponse |
|
| 109 | + * @throws BatchRequestException |
|
| 110 | + */ |
|
| 111 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 112 | + { |
|
| 113 | + //delete important saved options. |
|
| 114 | + delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
| 115 | + delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
| 116 | + return new JobStepResponse($job_parameters, esc_html__( |
|
| 117 | + 'Offset has been applied to all affected fields.', |
|
| 118 | + 'event_espresso' |
|
| 119 | + )); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
| 125 | + * @param string $model_class_name |
|
| 126 | + * @throws \EE_Error |
|
| 127 | + */ |
|
| 128 | + protected function processModel($model_class_name) |
|
| 129 | + { |
|
| 130 | + global $wpdb; |
|
| 131 | + /** @var EEM_Base $model */ |
|
| 132 | + $model = $model_class_name::instance(); |
|
| 133 | + $original_offset = self::getOffset(); |
|
| 134 | + $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
| 135 | + $offset = abs($original_offset) * 60; |
|
| 136 | + //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
| 137 | + foreach ($model->get_tables() as $table) { |
|
| 138 | + $query = 'UPDATE ' . $table->get_table_name(); |
|
| 139 | + $fields_affected = array(); |
|
| 140 | + $inner_query = array(); |
|
| 141 | + foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
| 142 | + if ($model_field instanceof EE_Datetime_Field) { |
|
| 143 | + $inner_query[] = $model_field->get_table_column() . ' = ' |
|
| 144 | + . $sql_date_function . '(' |
|
| 145 | + . $model_field->get_table_column() |
|
| 146 | + . ", INTERVAL $offset MINUTE)"; |
|
| 147 | + $fields_affected[] = $model_field; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if (! $fields_affected) { |
|
| 151 | + continue; |
|
| 152 | + } |
|
| 153 | + //k convert innerquery to string |
|
| 154 | + $query .= ' SET ' . implode(',', $inner_query); |
|
| 155 | + //execute query |
|
| 156 | + $result = $wpdb->query($query); |
|
| 157 | + //record log |
|
| 158 | + if ($result !== false) { |
|
| 159 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
| 160 | + } else { |
|
| 161 | + //record error. |
|
| 162 | + $error_message = $wpdb->last_error; |
|
| 163 | + //handle the edgecases where last_error might be empty. |
|
| 164 | + if (! $error_message) { |
|
| 165 | + $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
| 166 | + } |
|
| 167 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Records a changelog entry using the given information. |
|
| 175 | + * |
|
| 176 | + * @param EEM_Base $model |
|
| 177 | + * @param float $offset |
|
| 178 | + * @param EE_Table_Base $table |
|
| 179 | + * @param EE_Model_Field_Base[] $model_fields_affected |
|
| 180 | + * @param string $error_message If present then there was an error so let's record that instead. |
|
| 181 | + * @throws \EE_Error |
|
| 182 | + */ |
|
| 183 | + private function recordChangeLog( |
|
| 184 | + EEM_Base $model, |
|
| 185 | + $offset, |
|
| 186 | + EE_Table_Base $table, |
|
| 187 | + $model_fields_affected, |
|
| 188 | + $error_message = '' |
|
| 189 | + ) { |
|
| 190 | + //setup $fields list. |
|
| 191 | + $fields = array(); |
|
| 192 | + /** @var EE_Datetime_Field $model_field */ |
|
| 193 | + foreach ($model_fields_affected as $model_field) { |
|
| 194 | + if (! $model_field instanceof EE_Datetime_Field) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 197 | + $fields[] = $model_field->get_name(); |
|
| 198 | + } |
|
| 199 | + //setup the message for the changelog entry. |
|
| 200 | + $message = $error_message |
|
| 201 | + ? sprintf( |
|
| 202 | + esc_html__( |
|
| 203 | + 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ), |
|
| 206 | + $table->get_table_name(), |
|
| 207 | + $model->get_this_model_name(), |
|
| 208 | + $offset, |
|
| 209 | + implode(',', $fields), |
|
| 210 | + $error_message |
|
| 211 | + ) |
|
| 212 | + : sprintf( |
|
| 213 | + esc_html__( |
|
| 214 | + 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
| 215 | + 'event_espresso' |
|
| 216 | + ), |
|
| 217 | + $table->get_table_name(), |
|
| 218 | + $model->get_this_model_name(), |
|
| 219 | + $offset, |
|
| 220 | + implode(',', $fields) |
|
| 221 | + ); |
|
| 222 | + //write to the log |
|
| 223 | + $changelog = EE_Change_Log::new_instance(array( |
|
| 224 | + 'LOG_type' => $error_message |
|
| 225 | + ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
| 226 | + : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
| 227 | + 'LOG_message' => $message |
|
| 228 | + )); |
|
| 229 | + $changelog->save(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Returns an array of models that have datetime fields. |
|
| 235 | + * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
| 236 | + * @return array an array of model class names. |
|
| 237 | + */ |
|
| 238 | + private function getModelsWithDatetimeFields() |
|
| 239 | + { |
|
| 240 | + $this->getModelsToProcess(); |
|
| 241 | + if (! empty($this->models_with_datetime_fields)) { |
|
| 242 | + return $this->models_with_datetime_fields; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
| 246 | + foreach ($all_non_abstract_models as $non_abstract_model) { |
|
| 247 | + //get model instance |
|
| 248 | + /** @var EEM_Base $non_abstract_model */ |
|
| 249 | + $non_abstract_model = $non_abstract_model::instance(); |
|
| 250 | + if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
| 251 | + $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + $this->setModelsToProcess($this->models_with_datetime_fields); |
|
| 255 | + return $this->models_with_datetime_fields; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * This simply records the models that have been processed with our tracking option. |
|
| 261 | + * @param array $models_to_set array of model class names. |
|
| 262 | + */ |
|
| 263 | + private function setModelsToProcess($models_to_set) |
|
| 264 | + { |
|
| 265 | + update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Used to keep track of how many models have been processed for the batch |
|
| 271 | + * @param $count |
|
| 272 | + */ |
|
| 273 | + private function updateCountOfModelsProcessed($count = 1) |
|
| 274 | + { |
|
| 275 | + $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
| 276 | + update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Retrieve the tracked number of models processed between requests. |
|
| 282 | + * @return int |
|
| 283 | + */ |
|
| 284 | + private function getCountOfModelsProcessed() |
|
| 285 | + { |
|
| 286 | + return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Returns the models that are left to process. |
|
| 292 | + * @return array an array of model class names. |
|
| 293 | + */ |
|
| 294 | + private function getModelsToProcess() |
|
| 295 | + { |
|
| 296 | + if (empty($this->models_with_datetime_fields)) { |
|
| 297 | + $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
| 298 | + } |
|
| 299 | + return $this->models_with_datetime_fields; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 305 | + * @param float $offset |
|
| 306 | + */ |
|
| 307 | + public static function updateOffset($offset) |
|
| 308 | + { |
|
| 309 | + update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 315 | + * |
|
| 316 | + * @return float |
|
| 317 | + */ |
|
| 318 | + public static function getOffset() |
|
| 319 | + { |
|
| 320 | + return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
| 321 | + } |
|
| 322 | 322 | } |
@@ -135,23 +135,23 @@ discard block |
||
| 135 | 135 | $offset = abs($original_offset) * 60; |
| 136 | 136 | //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
| 137 | 137 | foreach ($model->get_tables() as $table) { |
| 138 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
| 138 | + $query = 'UPDATE '.$table->get_table_name(); |
|
| 139 | 139 | $fields_affected = array(); |
| 140 | 140 | $inner_query = array(); |
| 141 | 141 | foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
| 142 | 142 | if ($model_field instanceof EE_Datetime_Field) { |
| 143 | - $inner_query[] = $model_field->get_table_column() . ' = ' |
|
| 144 | - . $sql_date_function . '(' |
|
| 143 | + $inner_query[] = $model_field->get_table_column().' = ' |
|
| 144 | + . $sql_date_function.'(' |
|
| 145 | 145 | . $model_field->get_table_column() |
| 146 | 146 | . ", INTERVAL $offset MINUTE)"; |
| 147 | 147 | $fields_affected[] = $model_field; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | - if (! $fields_affected) { |
|
| 150 | + if ( ! $fields_affected) { |
|
| 151 | 151 | continue; |
| 152 | 152 | } |
| 153 | 153 | //k convert innerquery to string |
| 154 | - $query .= ' SET ' . implode(',', $inner_query); |
|
| 154 | + $query .= ' SET '.implode(',', $inner_query); |
|
| 155 | 155 | //execute query |
| 156 | 156 | $result = $wpdb->query($query); |
| 157 | 157 | //record log |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | //record error. |
| 162 | 162 | $error_message = $wpdb->last_error; |
| 163 | 163 | //handle the edgecases where last_error might be empty. |
| 164 | - if (! $error_message) { |
|
| 164 | + if ( ! $error_message) { |
|
| 165 | 165 | $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
| 166 | 166 | } |
| 167 | 167 | $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $fields = array(); |
| 192 | 192 | /** @var EE_Datetime_Field $model_field */ |
| 193 | 193 | foreach ($model_fields_affected as $model_field) { |
| 194 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
| 194 | + if ( ! $model_field instanceof EE_Datetime_Field) { |
|
| 195 | 195 | continue; |
| 196 | 196 | } |
| 197 | 197 | $fields[] = $model_field->get_name(); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | private function getModelsWithDatetimeFields() |
| 239 | 239 | { |
| 240 | 240 | $this->getModelsToProcess(); |
| 241 | - if (! empty($this->models_with_datetime_fields)) { |
|
| 241 | + if ( ! empty($this->models_with_datetime_fields)) { |
|
| 242 | 242 | return $this->models_with_datetime_fields; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -20,159 +20,159 @@ |
||
| 20 | 20 | class EE_Register_Shortcode implements EEI_Plugin_API |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Holds values for registered shortcodes |
|
| 25 | - * |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected static $_settings = array(); |
|
| 23 | + /** |
|
| 24 | + * Holds values for registered shortcodes |
|
| 25 | + * |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected static $_settings = array(); |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Method for registering new EE_Shortcodes |
|
| 33 | - * |
|
| 34 | - * @since 4.3.0 |
|
| 35 | - * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
| 36 | - * @param string $shortcode_id a unique identifier for this set of modules Required. |
|
| 37 | - * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
| 38 | - * @type array shortcode_paths an array of full server paths to folders containing any |
|
| 39 | - * EES_Shortcodes |
|
| 40 | - * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode |
|
| 41 | - * classes to register. Shortcode classes should extend |
|
| 42 | - * EspressoShortcode and be properly namespaced so they are |
|
| 43 | - * autoloaded. |
|
| 44 | - * @throws EE_Error |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public static function register($shortcode_id = null, $setup_args = array()) |
|
| 48 | - { |
|
| 49 | - //required fields MUST be present, so let's make sure they are. |
|
| 50 | - if (empty($shortcode_id) |
|
| 51 | - || ! is_array($setup_args) |
|
| 52 | - || ( |
|
| 53 | - empty($setup_args['shortcode_paths'])) |
|
| 54 | - && empty($setup_args['shortcode_fqcns']) |
|
| 55 | - ) { |
|
| 56 | - throw new EE_Error( |
|
| 57 | - esc_html__( |
|
| 58 | - 'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)', |
|
| 59 | - 'event_espresso' |
|
| 60 | - ) |
|
| 61 | - ); |
|
| 62 | - } |
|
| 31 | + /** |
|
| 32 | + * Method for registering new EE_Shortcodes |
|
| 33 | + * |
|
| 34 | + * @since 4.3.0 |
|
| 35 | + * @since 4.9.46.rc.025 for the new `shortcode_fqcns` array argument. |
|
| 36 | + * @param string $shortcode_id a unique identifier for this set of modules Required. |
|
| 37 | + * @param array $setup_args an array of arguments provided for registering shortcodes Required. |
|
| 38 | + * @type array shortcode_paths an array of full server paths to folders containing any |
|
| 39 | + * EES_Shortcodes |
|
| 40 | + * @type array shortcode_fqcns an array of fully qualified class names for any new shortcode |
|
| 41 | + * classes to register. Shortcode classes should extend |
|
| 42 | + * EspressoShortcode and be properly namespaced so they are |
|
| 43 | + * autoloaded. |
|
| 44 | + * @throws EE_Error |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public static function register($shortcode_id = null, $setup_args = array()) |
|
| 48 | + { |
|
| 49 | + //required fields MUST be present, so let's make sure they are. |
|
| 50 | + if (empty($shortcode_id) |
|
| 51 | + || ! is_array($setup_args) |
|
| 52 | + || ( |
|
| 53 | + empty($setup_args['shortcode_paths'])) |
|
| 54 | + && empty($setup_args['shortcode_fqcns']) |
|
| 55 | + ) { |
|
| 56 | + throw new EE_Error( |
|
| 57 | + esc_html__( |
|
| 58 | + 'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)', |
|
| 59 | + 'event_espresso' |
|
| 60 | + ) |
|
| 61 | + ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //make sure we don't register twice |
|
| 65 | - if (isset(self::$_settings[$shortcode_id])) { |
|
| 66 | - return; |
|
| 67 | - } |
|
| 64 | + //make sure we don't register twice |
|
| 65 | + if (isset(self::$_settings[$shortcode_id])) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - //make sure this was called in the right place! |
|
| 70 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 71 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
| 72 | - ) { |
|
| 73 | - EE_Error::doing_it_wrong( |
|
| 74 | - __METHOD__, |
|
| 75 | - esc_html__( |
|
| 76 | - 'An attempt to register shortcodes has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - '4.3.0' |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - //setup $_settings array from incoming values. |
|
| 83 | - self::$_settings[$shortcode_id] = array( |
|
| 84 | - // array of full server paths to any EES_Shortcodes used by the shortcode |
|
| 85 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 86 | - ? (array) $setup_args['shortcode_paths'] |
|
| 87 | - : array(), |
|
| 88 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 89 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 90 | - : array() |
|
| 91 | - ); |
|
| 92 | - // add to list of shortcodes to be registered |
|
| 93 | - add_filter( |
|
| 94 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 95 | - array('EE_Register_Shortcode', 'add_shortcodes') |
|
| 96 | - ); |
|
| 69 | + //make sure this was called in the right place! |
|
| 70 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 71 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
| 72 | + ) { |
|
| 73 | + EE_Error::doing_it_wrong( |
|
| 74 | + __METHOD__, |
|
| 75 | + esc_html__( |
|
| 76 | + 'An attempt to register shortcodes has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + '4.3.0' |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + //setup $_settings array from incoming values. |
|
| 83 | + self::$_settings[$shortcode_id] = array( |
|
| 84 | + // array of full server paths to any EES_Shortcodes used by the shortcode |
|
| 85 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 86 | + ? (array) $setup_args['shortcode_paths'] |
|
| 87 | + : array(), |
|
| 88 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 89 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 90 | + : array() |
|
| 91 | + ); |
|
| 92 | + // add to list of shortcodes to be registered |
|
| 93 | + add_filter( |
|
| 94 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 95 | + array('EE_Register_Shortcode', 'add_shortcodes') |
|
| 96 | + ); |
|
| 97 | 97 | |
| 98 | - add_filter( |
|
| 99 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
| 100 | - array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection') |
|
| 101 | - ); |
|
| 102 | - } |
|
| 98 | + add_filter( |
|
| 99 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
| 100 | + array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection') |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Filters the list of shortcodes to add ours. |
|
| 107 | - * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
| 108 | - * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...) |
|
| 109 | - * |
|
| 110 | - * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public static function add_shortcodes($shortcodes_to_register) |
|
| 114 | - { |
|
| 115 | - foreach (self::$_settings as $settings) { |
|
| 116 | - $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']); |
|
| 117 | - } |
|
| 118 | - return $shortcodes_to_register; |
|
| 119 | - } |
|
| 105 | + /** |
|
| 106 | + * Filters the list of shortcodes to add ours. |
|
| 107 | + * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
| 108 | + * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...) |
|
| 109 | + * |
|
| 110 | + * @param array $shortcodes_to_register array of paths to all shortcodes that require registering |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public static function add_shortcodes($shortcodes_to_register) |
|
| 114 | + { |
|
| 115 | + foreach (self::$_settings as $settings) { |
|
| 116 | + $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']); |
|
| 117 | + } |
|
| 118 | + return $shortcodes_to_register; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection |
|
| 124 | - * and registers any provided shortcode fully qualified class names. |
|
| 125 | - * @param CollectionInterface $shortcodes_collection |
|
| 126 | - * @return CollectionInterface |
|
| 127 | - * @throws InvalidArgumentException |
|
| 128 | - * @throws InvalidClassException |
|
| 129 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 130 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 131 | - */ |
|
| 132 | - public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
|
| 133 | - { |
|
| 134 | - foreach (self::$_settings as $settings) { |
|
| 135 | - if (! empty($settings['shortcode_fqcns'])) { |
|
| 136 | - foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
| 137 | - if (! class_exists($shortcode_fqcn)) { |
|
| 138 | - throw new InvalidClassException( |
|
| 139 | - sprintf( |
|
| 140 | - esc_html__( |
|
| 141 | - 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
| 142 | - 'event_espresso' |
|
| 143 | - ), |
|
| 144 | - $shortcode_fqcn |
|
| 145 | - ) |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 149 | - //register dependencies |
|
| 150 | - EE_Dependency_Map::register_dependencies( |
|
| 151 | - $shortcode_fqcn, |
|
| 152 | - array( |
|
| 153 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - return $shortcodes_collection; |
|
| 162 | - } |
|
| 122 | + /** |
|
| 123 | + * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection |
|
| 124 | + * and registers any provided shortcode fully qualified class names. |
|
| 125 | + * @param CollectionInterface $shortcodes_collection |
|
| 126 | + * @return CollectionInterface |
|
| 127 | + * @throws InvalidArgumentException |
|
| 128 | + * @throws InvalidClassException |
|
| 129 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 130 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 131 | + */ |
|
| 132 | + public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
|
| 133 | + { |
|
| 134 | + foreach (self::$_settings as $settings) { |
|
| 135 | + if (! empty($settings['shortcode_fqcns'])) { |
|
| 136 | + foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
|
| 137 | + if (! class_exists($shortcode_fqcn)) { |
|
| 138 | + throw new InvalidClassException( |
|
| 139 | + sprintf( |
|
| 140 | + esc_html__( |
|
| 141 | + 'Are you sure %s is the right fully qualified class name for the shortcode class?', |
|
| 142 | + 'event_espresso' |
|
| 143 | + ), |
|
| 144 | + $shortcode_fqcn |
|
| 145 | + ) |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 149 | + //register dependencies |
|
| 150 | + EE_Dependency_Map::register_dependencies( |
|
| 151 | + $shortcode_fqcn, |
|
| 152 | + array( |
|
| 153 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn)); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + return $shortcodes_collection; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * This deregisters a shortcode that was previously registered with a specific $shortcode_id. |
|
| 167 | - * |
|
| 168 | - * @since 4.3.0 |
|
| 169 | - * @param string $shortcode_id the name for the shortcode that was previously registered |
|
| 170 | - * @return void |
|
| 171 | - */ |
|
| 172 | - public static function deregister($shortcode_id = null) |
|
| 173 | - { |
|
| 174 | - if (isset(self::$_settings[$shortcode_id])) { |
|
| 175 | - unset(self::$_settings[$shortcode_id]); |
|
| 176 | - } |
|
| 177 | - } |
|
| 165 | + /** |
|
| 166 | + * This deregisters a shortcode that was previously registered with a specific $shortcode_id. |
|
| 167 | + * |
|
| 168 | + * @since 4.3.0 |
|
| 169 | + * @param string $shortcode_id the name for the shortcode that was previously registered |
|
| 170 | + * @return void |
|
| 171 | + */ |
|
| 172 | + public static function deregister($shortcode_id = null) |
|
| 173 | + { |
|
| 174 | + if (isset(self::$_settings[$shortcode_id])) { |
|
| 175 | + unset(self::$_settings[$shortcode_id]); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | //make sure this was called in the right place! |
| 70 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 70 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 71 | 71 | || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
| 72 | 72 | ) { |
| 73 | 73 | EE_Error::doing_it_wrong( |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection) |
| 133 | 133 | { |
| 134 | 134 | foreach (self::$_settings as $settings) { |
| 135 | - if (! empty($settings['shortcode_fqcns'])) { |
|
| 135 | + if ( ! empty($settings['shortcode_fqcns'])) { |
|
| 136 | 136 | foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) { |
| 137 | - if (! class_exists($shortcode_fqcn)) { |
|
| 137 | + if ( ! class_exists($shortcode_fqcn)) { |
|
| 138 | 138 | throw new InvalidClassException( |
| 139 | 139 | sprintf( |
| 140 | 140 | esc_html__( |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | ) |
| 146 | 146 | ); |
| 147 | 147 | } |
| 148 | - if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 148 | + if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) { |
|
| 149 | 149 | //register dependencies |
| 150 | 150 | EE_Dependency_Map::register_dependencies( |
| 151 | 151 | $shortcode_fqcn, |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('NO direct script access allowed'); |
|
| 2 | + exit('NO direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -17,2222 +17,2222 @@ discard block |
||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | - */ |
|
| 23 | - protected $_message_resource_manager; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @type string $_active_message_type_name |
|
| 27 | - */ |
|
| 28 | - protected $_active_message_type_name = ''; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @type EE_messenger $_active_messenger |
|
| 32 | - */ |
|
| 33 | - protected $_active_messenger; |
|
| 34 | - protected $_activate_state; |
|
| 35 | - protected $_activate_meta_box_type; |
|
| 36 | - protected $_current_message_meta_box; |
|
| 37 | - protected $_current_message_meta_box_object; |
|
| 38 | - protected $_context_switcher; |
|
| 39 | - protected $_shortcodes = array(); |
|
| 40 | - protected $_active_messengers = array(); |
|
| 41 | - protected $_active_message_types = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | - */ |
|
| 46 | - protected $_message_template_group; |
|
| 47 | - protected $_m_mt_settings = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | - * |
|
| 54 | - * @since 4.5.0 |
|
| 55 | - * |
|
| 56 | - * @var EE_Messages_Template_Pack |
|
| 57 | - */ |
|
| 58 | - protected $_template_pack; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | - * group is. If there is no group then it automatically gets set to default. |
|
| 64 | - * |
|
| 65 | - * @since 4.5.0 |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $_variation; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param bool $routing |
|
| 74 | - */ |
|
| 75 | - public function __construct($routing = true) |
|
| 76 | - { |
|
| 77 | - //make sure messages autoloader is running |
|
| 78 | - EED_Messages::set_autoloaders(); |
|
| 79 | - parent::__construct($routing); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - protected function _init_page_props() |
|
| 84 | - { |
|
| 85 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | - $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | - |
|
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | - |
|
| 92 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | - $this->_load_message_resource_manager(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function _load_message_resource_manager() |
|
| 104 | - { |
|
| 105 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated 4.9.9.rc.014 |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_messengers_for_list_table() |
|
| 114 | - { |
|
| 115 | - EE_Error::doing_it_wrong( |
|
| 116 | - __METHOD__, |
|
| 117 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 20 | + /** |
|
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | + */ |
|
| 23 | + protected $_message_resource_manager; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @type string $_active_message_type_name |
|
| 27 | + */ |
|
| 28 | + protected $_active_message_type_name = ''; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @type EE_messenger $_active_messenger |
|
| 32 | + */ |
|
| 33 | + protected $_active_messenger; |
|
| 34 | + protected $_activate_state; |
|
| 35 | + protected $_activate_meta_box_type; |
|
| 36 | + protected $_current_message_meta_box; |
|
| 37 | + protected $_current_message_meta_box_object; |
|
| 38 | + protected $_context_switcher; |
|
| 39 | + protected $_shortcodes = array(); |
|
| 40 | + protected $_active_messengers = array(); |
|
| 41 | + protected $_active_message_types = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | + */ |
|
| 46 | + protected $_message_template_group; |
|
| 47 | + protected $_m_mt_settings = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | + * |
|
| 54 | + * @since 4.5.0 |
|
| 55 | + * |
|
| 56 | + * @var EE_Messages_Template_Pack |
|
| 57 | + */ |
|
| 58 | + protected $_template_pack; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | + * group is. If there is no group then it automatically gets set to default. |
|
| 64 | + * |
|
| 65 | + * @since 4.5.0 |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $_variation; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param bool $routing |
|
| 74 | + */ |
|
| 75 | + public function __construct($routing = true) |
|
| 76 | + { |
|
| 77 | + //make sure messages autoloader is running |
|
| 78 | + EED_Messages::set_autoloaders(); |
|
| 79 | + parent::__construct($routing); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + protected function _init_page_props() |
|
| 84 | + { |
|
| 85 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | + $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | + |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | + |
|
| 92 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | + $this->_load_message_resource_manager(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function _load_message_resource_manager() |
|
| 104 | + { |
|
| 105 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated 4.9.9.rc.014 |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_messengers_for_list_table() |
|
| 114 | + { |
|
| 115 | + EE_Error::doing_it_wrong( |
|
| 116 | + __METHOD__, |
|
| 117 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 118 | 118 | values for use in creating a messenger filter dropdown which is now generated differently via |
| 119 | 119 | Messages_Admin_Page::get_messengers_select_input', 'event_espresso'), |
| 120 | - '4.9.9.rc.014' |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $m_values = array(); |
|
| 124 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | - //setup messengers for selects |
|
| 126 | - $i = 1; |
|
| 127 | - foreach ($active_messengers as $active_messenger) { |
|
| 128 | - if ($active_messenger instanceof EE_Message) { |
|
| 129 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | - $i++; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $m_values; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @deprecated 4.9.9.rc.014 |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function get_message_types_for_list_table() |
|
| 144 | - { |
|
| 145 | - EE_Error::doing_it_wrong( |
|
| 146 | - __METHOD__, |
|
| 147 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 120 | + '4.9.9.rc.014' |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $m_values = array(); |
|
| 124 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | + //setup messengers for selects |
|
| 126 | + $i = 1; |
|
| 127 | + foreach ($active_messengers as $active_messenger) { |
|
| 128 | + if ($active_messenger instanceof EE_Message) { |
|
| 129 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | + $i++; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $m_values; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @deprecated 4.9.9.rc.014 |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function get_message_types_for_list_table() |
|
| 144 | + { |
|
| 145 | + EE_Error::doing_it_wrong( |
|
| 146 | + __METHOD__, |
|
| 147 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 148 | 148 | values for use in creating a message type filter dropdown which is now generated differently via |
| 149 | 149 | Messages_Admin_Page::get_message_types_select_input', 'event_espresso'), |
| 150 | - '4.9.9.rc.014' |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $mt_values = array(); |
|
| 154 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | - $i = 1; |
|
| 156 | - foreach ($active_messages as $active_message) { |
|
| 157 | - if ($active_message instanceof EE_Message) { |
|
| 158 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | - $i++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $mt_values; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @deprecated 4.9.9.rc.014 |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function get_contexts_for_message_types_for_list_table() |
|
| 173 | - { |
|
| 174 | - EE_Error::doing_it_wrong( |
|
| 175 | - __METHOD__, |
|
| 176 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 150 | + '4.9.9.rc.014' |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $mt_values = array(); |
|
| 154 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | + $i = 1; |
|
| 156 | + foreach ($active_messages as $active_message) { |
|
| 157 | + if ($active_message instanceof EE_Message) { |
|
| 158 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | + $i++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $mt_values; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @deprecated 4.9.9.rc.014 |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function get_contexts_for_message_types_for_list_table() |
|
| 173 | + { |
|
| 174 | + EE_Error::doing_it_wrong( |
|
| 175 | + __METHOD__, |
|
| 176 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 177 | 177 | values for use in creating a message type context filter dropdown which is now generated differently via |
| 178 | 178 | Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'), |
| 179 | - '4.9.9.rc.014' |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $contexts = array(); |
|
| 183 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | - foreach ($active_message_contexts as $active_message) { |
|
| 185 | - if ($active_message instanceof EE_Message) { |
|
| 186 | - $message_type = $active_message->message_type_object(); |
|
| 187 | - if ($message_type instanceof EE_message_type) { |
|
| 188 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | - $contexts[$context] = $context_details['label']; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $contexts; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Generate select input with provided messenger options array. |
|
| 202 | - * |
|
| 203 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | - * labels. |
|
| 205 | - * |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function get_messengers_select_input($messenger_options) |
|
| 209 | - { |
|
| 210 | - //if empty or just one value then just return an empty string |
|
| 211 | - if (empty($messenger_options) |
|
| 212 | - || ! is_array($messenger_options) |
|
| 213 | - || count($messenger_options) === 1 |
|
| 214 | - ) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - //merge in default |
|
| 218 | - $messenger_options = array_merge( |
|
| 219 | - array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | - $messenger_options |
|
| 221 | - ); |
|
| 222 | - $input = new EE_Select_Input( |
|
| 223 | - $messenger_options, |
|
| 224 | - array( |
|
| 225 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | - 'html_class' => 'wide', |
|
| 228 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | - : 'none_selected' |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - return $input->get_html_for_input(); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Generate select input with provided message type options array. |
|
| 240 | - * |
|
| 241 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | - * message type labels |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_message_types_select_input($message_type_options) |
|
| 247 | - { |
|
| 248 | - //if empty or count of options is 1 then just return an empty string |
|
| 249 | - if (empty($message_type_options) |
|
| 250 | - || ! is_array($message_type_options) |
|
| 251 | - || count($message_type_options) === 1 |
|
| 252 | - ) { |
|
| 253 | - return ''; |
|
| 254 | - } |
|
| 255 | - //merge in default |
|
| 256 | - $message_type_options = array_merge( |
|
| 257 | - array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | - $message_type_options |
|
| 259 | - ); |
|
| 260 | - $input = new EE_Select_Input( |
|
| 261 | - $message_type_options, |
|
| 262 | - array( |
|
| 263 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | - 'html_class' => 'wide', |
|
| 266 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | - : 'none_selected', |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return $input->get_html_for_input(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Generate select input with provide message type contexts array. |
|
| 278 | - * |
|
| 279 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | - * context label. |
|
| 281 | - * |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | - { |
|
| 286 | - //if empty or count of options is one then just return empty string |
|
| 287 | - if (empty($context_options) |
|
| 288 | - || ! is_array($context_options) |
|
| 289 | - || count($context_options) === 1 |
|
| 290 | - ) { |
|
| 291 | - return ''; |
|
| 292 | - } |
|
| 293 | - //merge in default |
|
| 294 | - $context_options = array_merge( |
|
| 295 | - array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | - $context_options |
|
| 297 | - ); |
|
| 298 | - $input = new EE_Select_Input( |
|
| 299 | - $context_options, |
|
| 300 | - array( |
|
| 301 | - 'html_name' => 'ee_context_filter_by', |
|
| 302 | - 'html_id' => 'ee_context_filter_by', |
|
| 303 | - 'html_class' => 'wide', |
|
| 304 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | - : 'none_selected', |
|
| 307 | - ) |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - return $input->get_html_for_input(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - protected function _ajax_hooks() |
|
| 315 | - { |
|
| 316 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - protected function _define_page_props() |
|
| 325 | - { |
|
| 326 | - $this->_admin_page_title = $this->page_label; |
|
| 327 | - $this->_labels = array( |
|
| 328 | - 'buttons' => array( |
|
| 329 | - 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | - 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | - 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | - ), |
|
| 333 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | - * @access protected |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - protected function _set_page_routes() |
|
| 344 | - { |
|
| 345 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | - ? $this->_req_data['GRP_ID'] |
|
| 347 | - : 0; |
|
| 348 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | - ? $this->_req_data['id'] |
|
| 350 | - : $grp_id; |
|
| 351 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | - ? $this->_req_data['MSG_ID'] |
|
| 353 | - : 0; |
|
| 354 | - |
|
| 355 | - $this->_page_routes = array( |
|
| 356 | - 'default' => array( |
|
| 357 | - 'func' => '_message_queue_list_table', |
|
| 358 | - 'capability' => 'ee_read_global_messages' |
|
| 359 | - ), |
|
| 360 | - 'global_mtps' => array( |
|
| 361 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | - 'capability' => 'ee_read_global_messages' |
|
| 363 | - ), |
|
| 364 | - 'custom_mtps' => array( |
|
| 365 | - 'func' => '_custom_mtps_preview', |
|
| 366 | - 'capability' => 'ee_read_messages' |
|
| 367 | - ), |
|
| 368 | - 'add_new_message_template' => array( |
|
| 369 | - 'func' => '_add_message_template', |
|
| 370 | - 'capability' => 'ee_edit_messages', |
|
| 371 | - 'noheader' => true |
|
| 372 | - ), |
|
| 373 | - 'edit_message_template' => array( |
|
| 374 | - 'func' => '_edit_message_template', |
|
| 375 | - 'capability' => 'ee_edit_message', |
|
| 376 | - 'obj_id' => $grp_id |
|
| 377 | - ), |
|
| 378 | - 'preview_message' => array( |
|
| 379 | - 'func' => '_preview_message', |
|
| 380 | - 'capability' => 'ee_read_message', |
|
| 381 | - 'obj_id' => $grp_id, |
|
| 382 | - 'noheader' => true, |
|
| 383 | - 'headers_sent_route' => 'display_preview_message' |
|
| 384 | - ), |
|
| 385 | - 'display_preview_message' => array( |
|
| 386 | - 'func' => '_display_preview_message', |
|
| 387 | - 'capability' => 'ee_read_message', |
|
| 388 | - 'obj_id' => $grp_id |
|
| 389 | - ), |
|
| 390 | - 'insert_message_template' => array( |
|
| 391 | - 'func' => '_insert_or_update_message_template', |
|
| 392 | - 'capability' => 'ee_edit_messages', |
|
| 393 | - 'args' => array('new_template' => true), |
|
| 394 | - 'noheader' => true |
|
| 395 | - ), |
|
| 396 | - 'update_message_template' => array( |
|
| 397 | - 'func' => '_insert_or_update_message_template', |
|
| 398 | - 'capability' => 'ee_edit_message', |
|
| 399 | - 'obj_id' => $grp_id, |
|
| 400 | - 'args' => array('new_template' => false), |
|
| 401 | - 'noheader' => true |
|
| 402 | - ), |
|
| 403 | - 'trash_message_template' => array( |
|
| 404 | - 'func' => '_trash_or_restore_message_template', |
|
| 405 | - 'capability' => 'ee_delete_message', |
|
| 406 | - 'obj_id' => $grp_id, |
|
| 407 | - 'args' => array('trash' => true, 'all' => true), |
|
| 408 | - 'noheader' => true |
|
| 409 | - ), |
|
| 410 | - 'trash_message_template_context' => array( |
|
| 411 | - 'func' => '_trash_or_restore_message_template', |
|
| 412 | - 'capability' => 'ee_delete_message', |
|
| 413 | - 'obj_id' => $grp_id, |
|
| 414 | - 'args' => array('trash' => true), |
|
| 415 | - 'noheader' => true |
|
| 416 | - ), |
|
| 417 | - 'restore_message_template' => array( |
|
| 418 | - 'func' => '_trash_or_restore_message_template', |
|
| 419 | - 'capability' => 'ee_delete_message', |
|
| 420 | - 'obj_id' => $grp_id, |
|
| 421 | - 'args' => array('trash' => false, 'all' => true), |
|
| 422 | - 'noheader' => true |
|
| 423 | - ), |
|
| 424 | - 'restore_message_template_context' => array( |
|
| 425 | - 'func' => '_trash_or_restore_message_template', |
|
| 426 | - 'capability' => 'ee_delete_message', |
|
| 427 | - 'obj_id' => $grp_id, |
|
| 428 | - 'args' => array('trash' => false), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'delete_message_template' => array( |
|
| 432 | - 'func' => '_delete_message_template', |
|
| 433 | - 'capability' => 'ee_delete_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'reset_to_default' => array( |
|
| 438 | - 'func' => '_reset_to_default_template', |
|
| 439 | - 'capability' => 'ee_edit_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'noheader' => true |
|
| 442 | - ), |
|
| 443 | - 'settings' => array( |
|
| 444 | - 'func' => '_settings', |
|
| 445 | - 'capability' => 'manage_options' |
|
| 446 | - ), |
|
| 447 | - 'update_global_settings' => array( |
|
| 448 | - 'func' => '_update_global_settings', |
|
| 449 | - 'capability' => 'manage_options', |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'generate_now' => array( |
|
| 453 | - 'func' => '_generate_now', |
|
| 454 | - 'capability' => 'ee_send_message', |
|
| 455 | - 'noheader' => true |
|
| 456 | - ), |
|
| 457 | - 'generate_and_send_now' => array( |
|
| 458 | - 'func' => '_generate_and_send_now', |
|
| 459 | - 'capability' => 'ee_send_message', |
|
| 460 | - 'noheader' => true |
|
| 461 | - ), |
|
| 462 | - 'queue_for_resending' => array( |
|
| 463 | - 'func' => '_queue_for_resending', |
|
| 464 | - 'capability' => 'ee_send_message', |
|
| 465 | - 'noheader' => true |
|
| 466 | - ), |
|
| 467 | - 'send_now' => array( |
|
| 468 | - 'func' => '_send_now', |
|
| 469 | - 'capability' => 'ee_send_message', |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'delete_ee_message' => array( |
|
| 473 | - 'func' => '_delete_ee_messages', |
|
| 474 | - 'capability' => 'ee_delete_messages', |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'delete_ee_messages' => array( |
|
| 478 | - 'func' => '_delete_ee_messages', |
|
| 479 | - 'capability' => 'ee_delete_messages', |
|
| 480 | - 'noheader' => true, |
|
| 481 | - 'obj_id' => $msg_id |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - protected function _set_page_config() |
|
| 488 | - { |
|
| 489 | - $this->_page_config = array( |
|
| 490 | - 'default' => array( |
|
| 491 | - 'nav' => array( |
|
| 492 | - 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | - 'order' => 10 |
|
| 494 | - ), |
|
| 495 | - 'list_table' => 'EE_Message_List_Table', |
|
| 496 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | - 'require_nonce' => false |
|
| 498 | - ), |
|
| 499 | - 'global_mtps' => array( |
|
| 500 | - 'nav' => array( |
|
| 501 | - 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | - 'order' => 20 |
|
| 503 | - ), |
|
| 504 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | - 'help_tabs' => array( |
|
| 506 | - 'messages_overview_help_tab' => array( |
|
| 507 | - 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | - 'filename' => 'messages_overview' |
|
| 509 | - ), |
|
| 510 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | - 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | - ), |
|
| 514 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | - 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | - 'filename' => 'messages_overview_filters' |
|
| 517 | - ), |
|
| 518 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | - 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | - 'filename' => 'messages_overview_views' |
|
| 521 | - ), |
|
| 522 | - 'message_overview_message_types_help_tab' => array( |
|
| 523 | - 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | - 'filename' => 'messages_overview_types' |
|
| 525 | - ), |
|
| 526 | - 'messages_overview_messengers_help_tab' => array( |
|
| 527 | - 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | - 'filename' => 'messages_overview_messengers', |
|
| 529 | - ), |
|
| 530 | - ), |
|
| 531 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 532 | - 'require_nonce' => false |
|
| 533 | - ), |
|
| 534 | - 'custom_mtps' => array( |
|
| 535 | - 'nav' => array( |
|
| 536 | - 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 537 | - 'order' => 30 |
|
| 538 | - ), |
|
| 539 | - 'help_tabs' => array(), |
|
| 540 | - 'help_tour' => array(), |
|
| 541 | - 'require_nonce' => false |
|
| 542 | - ), |
|
| 543 | - 'add_new_message_template' => array( |
|
| 544 | - 'nav' => array( |
|
| 545 | - 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 546 | - 'order' => 5, |
|
| 547 | - 'persistent' => false |
|
| 548 | - ), |
|
| 549 | - 'require_nonce' => false |
|
| 550 | - ), |
|
| 551 | - 'edit_message_template' => array( |
|
| 552 | - 'labels' => array( |
|
| 553 | - 'buttons' => array( |
|
| 554 | - 'reset' => __('Reset Templates'), |
|
| 555 | - ), |
|
| 556 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 557 | - ), |
|
| 558 | - 'nav' => array( |
|
| 559 | - 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 560 | - 'order' => 5, |
|
| 561 | - 'persistent' => false, |
|
| 562 | - 'url' => '' |
|
| 563 | - ), |
|
| 564 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 565 | - 'has_metaboxes' => true, |
|
| 566 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 567 | - 'help_tabs' => array( |
|
| 568 | - 'edit_message_template' => array( |
|
| 569 | - 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 570 | - 'callback' => 'edit_message_template_help_tab' |
|
| 571 | - ), |
|
| 572 | - 'message_templates_help_tab' => array( |
|
| 573 | - 'title' => __('Message Templates', 'event_espresso'), |
|
| 574 | - 'filename' => 'messages_templates' |
|
| 575 | - ), |
|
| 576 | - 'message_template_shortcodes' => array( |
|
| 577 | - 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 578 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 579 | - ), |
|
| 580 | - 'message_preview_help_tab' => array( |
|
| 581 | - 'title' => __('Message Preview', 'event_espresso'), |
|
| 582 | - 'filename' => 'messages_preview' |
|
| 583 | - ), |
|
| 584 | - 'messages_overview_other_help_tab' => array( |
|
| 585 | - 'title' => __('Messages Other', 'event_espresso'), |
|
| 586 | - 'filename' => 'messages_overview_other', |
|
| 587 | - ), |
|
| 588 | - ), |
|
| 589 | - 'require_nonce' => false |
|
| 590 | - ), |
|
| 591 | - 'display_preview_message' => array( |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'url' => '', |
|
| 596 | - 'persistent' => false |
|
| 597 | - ), |
|
| 598 | - 'help_tabs' => array( |
|
| 599 | - 'preview_message' => array( |
|
| 600 | - 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | - 'callback' => 'preview_message_help_tab' |
|
| 602 | - ) |
|
| 603 | - ), |
|
| 604 | - 'require_nonce' => false |
|
| 605 | - ), |
|
| 606 | - 'settings' => array( |
|
| 607 | - 'nav' => array( |
|
| 608 | - 'label' => __('Settings', 'event_espresso'), |
|
| 609 | - 'order' => 40 |
|
| 610 | - ), |
|
| 611 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | - 'help_tabs' => array( |
|
| 613 | - 'messages_settings_help_tab' => array( |
|
| 614 | - 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | - 'filename' => 'messages_settings' |
|
| 616 | - ), |
|
| 617 | - 'messages_settings_message_types_help_tab' => array( |
|
| 618 | - 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | - 'filename' => 'messages_settings_message_types' |
|
| 620 | - ), |
|
| 621 | - 'messages_settings_messengers_help_tab' => array( |
|
| 622 | - 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | - 'filename' => 'messages_settings_messengers' |
|
| 624 | - ), |
|
| 625 | - ), |
|
| 626 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | - 'require_nonce' => false |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - protected function _add_screen_options() |
|
| 634 | - { |
|
| 635 | - //todo |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - protected function _add_screen_options_global_mtps() |
|
| 640 | - { |
|
| 641 | - /** |
|
| 642 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | - */ |
|
| 645 | - $page_title = $this->_admin_page_title; |
|
| 646 | - $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | - $this->_per_page_screen_option(); |
|
| 648 | - $this->_admin_page_title = $page_title; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - protected function _add_screen_options_default() |
|
| 653 | - { |
|
| 654 | - $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | - $this->_per_page_screen_option(); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - //none of the below group are currently used for Messages |
|
| 660 | - protected function _add_feature_pointers() |
|
| 661 | - { |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - public function admin_init() |
|
| 665 | - { |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - public function admin_notices() |
|
| 669 | - { |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - public function admin_footer_scripts() |
|
| 673 | - { |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - public function messages_help_tab() |
|
| 678 | - { |
|
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - public function messengers_help_tab() |
|
| 684 | - { |
|
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function message_types_help_tab() |
|
| 690 | - { |
|
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - public function messages_overview_help_tab() |
|
| 696 | - { |
|
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - public function message_templates_help_tab() |
|
| 702 | - { |
|
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - public function edit_message_template_help_tab() |
|
| 708 | - { |
|
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | - $args); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - public function message_template_shortcodes_help_tab() |
|
| 725 | - { |
|
| 726 | - $this->_set_shortcodes(); |
|
| 727 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | - $args); |
|
| 730 | - } |
|
| 179 | + '4.9.9.rc.014' |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $contexts = array(); |
|
| 183 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | + foreach ($active_message_contexts as $active_message) { |
|
| 185 | + if ($active_message instanceof EE_Message) { |
|
| 186 | + $message_type = $active_message->message_type_object(); |
|
| 187 | + if ($message_type instanceof EE_message_type) { |
|
| 188 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | + $contexts[$context] = $context_details['label']; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $contexts; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Generate select input with provided messenger options array. |
|
| 202 | + * |
|
| 203 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | + * labels. |
|
| 205 | + * |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function get_messengers_select_input($messenger_options) |
|
| 209 | + { |
|
| 210 | + //if empty or just one value then just return an empty string |
|
| 211 | + if (empty($messenger_options) |
|
| 212 | + || ! is_array($messenger_options) |
|
| 213 | + || count($messenger_options) === 1 |
|
| 214 | + ) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + //merge in default |
|
| 218 | + $messenger_options = array_merge( |
|
| 219 | + array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | + $messenger_options |
|
| 221 | + ); |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | + $messenger_options, |
|
| 224 | + array( |
|
| 225 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | + 'html_class' => 'wide', |
|
| 228 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | + : 'none_selected' |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + return $input->get_html_for_input(); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Generate select input with provided message type options array. |
|
| 240 | + * |
|
| 241 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | + * message type labels |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_message_types_select_input($message_type_options) |
|
| 247 | + { |
|
| 248 | + //if empty or count of options is 1 then just return an empty string |
|
| 249 | + if (empty($message_type_options) |
|
| 250 | + || ! is_array($message_type_options) |
|
| 251 | + || count($message_type_options) === 1 |
|
| 252 | + ) { |
|
| 253 | + return ''; |
|
| 254 | + } |
|
| 255 | + //merge in default |
|
| 256 | + $message_type_options = array_merge( |
|
| 257 | + array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | + $message_type_options |
|
| 259 | + ); |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | + $message_type_options, |
|
| 262 | + array( |
|
| 263 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | + 'html_class' => 'wide', |
|
| 266 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | + : 'none_selected', |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return $input->get_html_for_input(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Generate select input with provide message type contexts array. |
|
| 278 | + * |
|
| 279 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | + * context label. |
|
| 281 | + * |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | + { |
|
| 286 | + //if empty or count of options is one then just return empty string |
|
| 287 | + if (empty($context_options) |
|
| 288 | + || ! is_array($context_options) |
|
| 289 | + || count($context_options) === 1 |
|
| 290 | + ) { |
|
| 291 | + return ''; |
|
| 292 | + } |
|
| 293 | + //merge in default |
|
| 294 | + $context_options = array_merge( |
|
| 295 | + array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | + $context_options |
|
| 297 | + ); |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | + $context_options, |
|
| 300 | + array( |
|
| 301 | + 'html_name' => 'ee_context_filter_by', |
|
| 302 | + 'html_id' => 'ee_context_filter_by', |
|
| 303 | + 'html_class' => 'wide', |
|
| 304 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | + : 'none_selected', |
|
| 307 | + ) |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + return $input->get_html_for_input(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + protected function _ajax_hooks() |
|
| 315 | + { |
|
| 316 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + protected function _define_page_props() |
|
| 325 | + { |
|
| 326 | + $this->_admin_page_title = $this->page_label; |
|
| 327 | + $this->_labels = array( |
|
| 328 | + 'buttons' => array( |
|
| 329 | + 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | + 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | + 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | + ), |
|
| 333 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | + * @access protected |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + protected function _set_page_routes() |
|
| 344 | + { |
|
| 345 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | + ? $this->_req_data['GRP_ID'] |
|
| 347 | + : 0; |
|
| 348 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | + ? $this->_req_data['id'] |
|
| 350 | + : $grp_id; |
|
| 351 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | + ? $this->_req_data['MSG_ID'] |
|
| 353 | + : 0; |
|
| 354 | + |
|
| 355 | + $this->_page_routes = array( |
|
| 356 | + 'default' => array( |
|
| 357 | + 'func' => '_message_queue_list_table', |
|
| 358 | + 'capability' => 'ee_read_global_messages' |
|
| 359 | + ), |
|
| 360 | + 'global_mtps' => array( |
|
| 361 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | + 'capability' => 'ee_read_global_messages' |
|
| 363 | + ), |
|
| 364 | + 'custom_mtps' => array( |
|
| 365 | + 'func' => '_custom_mtps_preview', |
|
| 366 | + 'capability' => 'ee_read_messages' |
|
| 367 | + ), |
|
| 368 | + 'add_new_message_template' => array( |
|
| 369 | + 'func' => '_add_message_template', |
|
| 370 | + 'capability' => 'ee_edit_messages', |
|
| 371 | + 'noheader' => true |
|
| 372 | + ), |
|
| 373 | + 'edit_message_template' => array( |
|
| 374 | + 'func' => '_edit_message_template', |
|
| 375 | + 'capability' => 'ee_edit_message', |
|
| 376 | + 'obj_id' => $grp_id |
|
| 377 | + ), |
|
| 378 | + 'preview_message' => array( |
|
| 379 | + 'func' => '_preview_message', |
|
| 380 | + 'capability' => 'ee_read_message', |
|
| 381 | + 'obj_id' => $grp_id, |
|
| 382 | + 'noheader' => true, |
|
| 383 | + 'headers_sent_route' => 'display_preview_message' |
|
| 384 | + ), |
|
| 385 | + 'display_preview_message' => array( |
|
| 386 | + 'func' => '_display_preview_message', |
|
| 387 | + 'capability' => 'ee_read_message', |
|
| 388 | + 'obj_id' => $grp_id |
|
| 389 | + ), |
|
| 390 | + 'insert_message_template' => array( |
|
| 391 | + 'func' => '_insert_or_update_message_template', |
|
| 392 | + 'capability' => 'ee_edit_messages', |
|
| 393 | + 'args' => array('new_template' => true), |
|
| 394 | + 'noheader' => true |
|
| 395 | + ), |
|
| 396 | + 'update_message_template' => array( |
|
| 397 | + 'func' => '_insert_or_update_message_template', |
|
| 398 | + 'capability' => 'ee_edit_message', |
|
| 399 | + 'obj_id' => $grp_id, |
|
| 400 | + 'args' => array('new_template' => false), |
|
| 401 | + 'noheader' => true |
|
| 402 | + ), |
|
| 403 | + 'trash_message_template' => array( |
|
| 404 | + 'func' => '_trash_or_restore_message_template', |
|
| 405 | + 'capability' => 'ee_delete_message', |
|
| 406 | + 'obj_id' => $grp_id, |
|
| 407 | + 'args' => array('trash' => true, 'all' => true), |
|
| 408 | + 'noheader' => true |
|
| 409 | + ), |
|
| 410 | + 'trash_message_template_context' => array( |
|
| 411 | + 'func' => '_trash_or_restore_message_template', |
|
| 412 | + 'capability' => 'ee_delete_message', |
|
| 413 | + 'obj_id' => $grp_id, |
|
| 414 | + 'args' => array('trash' => true), |
|
| 415 | + 'noheader' => true |
|
| 416 | + ), |
|
| 417 | + 'restore_message_template' => array( |
|
| 418 | + 'func' => '_trash_or_restore_message_template', |
|
| 419 | + 'capability' => 'ee_delete_message', |
|
| 420 | + 'obj_id' => $grp_id, |
|
| 421 | + 'args' => array('trash' => false, 'all' => true), |
|
| 422 | + 'noheader' => true |
|
| 423 | + ), |
|
| 424 | + 'restore_message_template_context' => array( |
|
| 425 | + 'func' => '_trash_or_restore_message_template', |
|
| 426 | + 'capability' => 'ee_delete_message', |
|
| 427 | + 'obj_id' => $grp_id, |
|
| 428 | + 'args' => array('trash' => false), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'delete_message_template' => array( |
|
| 432 | + 'func' => '_delete_message_template', |
|
| 433 | + 'capability' => 'ee_delete_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'reset_to_default' => array( |
|
| 438 | + 'func' => '_reset_to_default_template', |
|
| 439 | + 'capability' => 'ee_edit_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'noheader' => true |
|
| 442 | + ), |
|
| 443 | + 'settings' => array( |
|
| 444 | + 'func' => '_settings', |
|
| 445 | + 'capability' => 'manage_options' |
|
| 446 | + ), |
|
| 447 | + 'update_global_settings' => array( |
|
| 448 | + 'func' => '_update_global_settings', |
|
| 449 | + 'capability' => 'manage_options', |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'generate_now' => array( |
|
| 453 | + 'func' => '_generate_now', |
|
| 454 | + 'capability' => 'ee_send_message', |
|
| 455 | + 'noheader' => true |
|
| 456 | + ), |
|
| 457 | + 'generate_and_send_now' => array( |
|
| 458 | + 'func' => '_generate_and_send_now', |
|
| 459 | + 'capability' => 'ee_send_message', |
|
| 460 | + 'noheader' => true |
|
| 461 | + ), |
|
| 462 | + 'queue_for_resending' => array( |
|
| 463 | + 'func' => '_queue_for_resending', |
|
| 464 | + 'capability' => 'ee_send_message', |
|
| 465 | + 'noheader' => true |
|
| 466 | + ), |
|
| 467 | + 'send_now' => array( |
|
| 468 | + 'func' => '_send_now', |
|
| 469 | + 'capability' => 'ee_send_message', |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'delete_ee_message' => array( |
|
| 473 | + 'func' => '_delete_ee_messages', |
|
| 474 | + 'capability' => 'ee_delete_messages', |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'delete_ee_messages' => array( |
|
| 478 | + 'func' => '_delete_ee_messages', |
|
| 479 | + 'capability' => 'ee_delete_messages', |
|
| 480 | + 'noheader' => true, |
|
| 481 | + 'obj_id' => $msg_id |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + protected function _set_page_config() |
|
| 488 | + { |
|
| 489 | + $this->_page_config = array( |
|
| 490 | + 'default' => array( |
|
| 491 | + 'nav' => array( |
|
| 492 | + 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | + 'order' => 10 |
|
| 494 | + ), |
|
| 495 | + 'list_table' => 'EE_Message_List_Table', |
|
| 496 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | + 'require_nonce' => false |
|
| 498 | + ), |
|
| 499 | + 'global_mtps' => array( |
|
| 500 | + 'nav' => array( |
|
| 501 | + 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | + 'order' => 20 |
|
| 503 | + ), |
|
| 504 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | + 'help_tabs' => array( |
|
| 506 | + 'messages_overview_help_tab' => array( |
|
| 507 | + 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | + 'filename' => 'messages_overview' |
|
| 509 | + ), |
|
| 510 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | + 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | + ), |
|
| 514 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | + 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | + 'filename' => 'messages_overview_filters' |
|
| 517 | + ), |
|
| 518 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | + 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | + 'filename' => 'messages_overview_views' |
|
| 521 | + ), |
|
| 522 | + 'message_overview_message_types_help_tab' => array( |
|
| 523 | + 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | + 'filename' => 'messages_overview_types' |
|
| 525 | + ), |
|
| 526 | + 'messages_overview_messengers_help_tab' => array( |
|
| 527 | + 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | + 'filename' => 'messages_overview_messengers', |
|
| 529 | + ), |
|
| 530 | + ), |
|
| 531 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 532 | + 'require_nonce' => false |
|
| 533 | + ), |
|
| 534 | + 'custom_mtps' => array( |
|
| 535 | + 'nav' => array( |
|
| 536 | + 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 537 | + 'order' => 30 |
|
| 538 | + ), |
|
| 539 | + 'help_tabs' => array(), |
|
| 540 | + 'help_tour' => array(), |
|
| 541 | + 'require_nonce' => false |
|
| 542 | + ), |
|
| 543 | + 'add_new_message_template' => array( |
|
| 544 | + 'nav' => array( |
|
| 545 | + 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 546 | + 'order' => 5, |
|
| 547 | + 'persistent' => false |
|
| 548 | + ), |
|
| 549 | + 'require_nonce' => false |
|
| 550 | + ), |
|
| 551 | + 'edit_message_template' => array( |
|
| 552 | + 'labels' => array( |
|
| 553 | + 'buttons' => array( |
|
| 554 | + 'reset' => __('Reset Templates'), |
|
| 555 | + ), |
|
| 556 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 557 | + ), |
|
| 558 | + 'nav' => array( |
|
| 559 | + 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 560 | + 'order' => 5, |
|
| 561 | + 'persistent' => false, |
|
| 562 | + 'url' => '' |
|
| 563 | + ), |
|
| 564 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 565 | + 'has_metaboxes' => true, |
|
| 566 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 567 | + 'help_tabs' => array( |
|
| 568 | + 'edit_message_template' => array( |
|
| 569 | + 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 570 | + 'callback' => 'edit_message_template_help_tab' |
|
| 571 | + ), |
|
| 572 | + 'message_templates_help_tab' => array( |
|
| 573 | + 'title' => __('Message Templates', 'event_espresso'), |
|
| 574 | + 'filename' => 'messages_templates' |
|
| 575 | + ), |
|
| 576 | + 'message_template_shortcodes' => array( |
|
| 577 | + 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 578 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 579 | + ), |
|
| 580 | + 'message_preview_help_tab' => array( |
|
| 581 | + 'title' => __('Message Preview', 'event_espresso'), |
|
| 582 | + 'filename' => 'messages_preview' |
|
| 583 | + ), |
|
| 584 | + 'messages_overview_other_help_tab' => array( |
|
| 585 | + 'title' => __('Messages Other', 'event_espresso'), |
|
| 586 | + 'filename' => 'messages_overview_other', |
|
| 587 | + ), |
|
| 588 | + ), |
|
| 589 | + 'require_nonce' => false |
|
| 590 | + ), |
|
| 591 | + 'display_preview_message' => array( |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'url' => '', |
|
| 596 | + 'persistent' => false |
|
| 597 | + ), |
|
| 598 | + 'help_tabs' => array( |
|
| 599 | + 'preview_message' => array( |
|
| 600 | + 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | + 'callback' => 'preview_message_help_tab' |
|
| 602 | + ) |
|
| 603 | + ), |
|
| 604 | + 'require_nonce' => false |
|
| 605 | + ), |
|
| 606 | + 'settings' => array( |
|
| 607 | + 'nav' => array( |
|
| 608 | + 'label' => __('Settings', 'event_espresso'), |
|
| 609 | + 'order' => 40 |
|
| 610 | + ), |
|
| 611 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | + 'help_tabs' => array( |
|
| 613 | + 'messages_settings_help_tab' => array( |
|
| 614 | + 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | + 'filename' => 'messages_settings' |
|
| 616 | + ), |
|
| 617 | + 'messages_settings_message_types_help_tab' => array( |
|
| 618 | + 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | + 'filename' => 'messages_settings_message_types' |
|
| 620 | + ), |
|
| 621 | + 'messages_settings_messengers_help_tab' => array( |
|
| 622 | + 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | + 'filename' => 'messages_settings_messengers' |
|
| 624 | + ), |
|
| 625 | + ), |
|
| 626 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | + 'require_nonce' => false |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + protected function _add_screen_options() |
|
| 634 | + { |
|
| 635 | + //todo |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + protected function _add_screen_options_global_mtps() |
|
| 640 | + { |
|
| 641 | + /** |
|
| 642 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | + */ |
|
| 645 | + $page_title = $this->_admin_page_title; |
|
| 646 | + $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | + $this->_per_page_screen_option(); |
|
| 648 | + $this->_admin_page_title = $page_title; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + protected function _add_screen_options_default() |
|
| 653 | + { |
|
| 654 | + $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | + $this->_per_page_screen_option(); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + //none of the below group are currently used for Messages |
|
| 660 | + protected function _add_feature_pointers() |
|
| 661 | + { |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + public function admin_init() |
|
| 665 | + { |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + public function admin_notices() |
|
| 669 | + { |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + public function admin_footer_scripts() |
|
| 673 | + { |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + public function messages_help_tab() |
|
| 678 | + { |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + public function messengers_help_tab() |
|
| 684 | + { |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function message_types_help_tab() |
|
| 690 | + { |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + public function messages_overview_help_tab() |
|
| 696 | + { |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + public function message_templates_help_tab() |
|
| 702 | + { |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + public function edit_message_template_help_tab() |
|
| 708 | + { |
|
| 709 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso') . '" />'; |
|
| 711 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso') . '" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso') . '" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso') . '" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso') . '" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | + $args); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + public function message_template_shortcodes_help_tab() |
|
| 725 | + { |
|
| 726 | + $this->_set_shortcodes(); |
|
| 727 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | + $args); |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | - public function preview_message_help_tab() |
|
| 734 | - { |
|
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | - } |
|
| 733 | + public function preview_message_help_tab() |
|
| 734 | + { |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - |
|
| 739 | - public function settings_help_tab() |
|
| 740 | - { |
|
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 745 | - $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | - $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | - } |
|
| 738 | + |
|
| 739 | + public function settings_help_tab() |
|
| 740 | + { |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso') . '" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso') . '" />'; |
|
| 745 | + $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | + $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | - public function load_scripts_styles() |
|
| 752 | - { |
|
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 751 | + public function load_scripts_styles() |
|
| 752 | + { |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | - } |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | 762 | |
| 763 | - public function load_scripts_styles_default() |
|
| 764 | - { |
|
| 765 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | - } |
|
| 763 | + public function load_scripts_styles_default() |
|
| 764 | + { |
|
| 765 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | - public function wp_editor_css($mce_css) |
|
| 770 | - { |
|
| 771 | - //if we're on the edit_message_template route |
|
| 772 | - if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | - $message_type_name = $this->_active_message_type_name; |
|
| 769 | + public function wp_editor_css($mce_css) |
|
| 770 | + { |
|
| 771 | + //if we're on the edit_message_template route |
|
| 772 | + if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | + $message_type_name = $this->_active_message_type_name; |
|
| 774 | 774 | |
| 775 | - //we're going to REPLACE the existing mce css |
|
| 776 | - //we need to get the css file location from the active messenger |
|
| 777 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | - 'wpeditor', $this->_variation); |
|
| 779 | - } |
|
| 775 | + //we're going to REPLACE the existing mce css |
|
| 776 | + //we need to get the css file location from the active messenger |
|
| 777 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | + 'wpeditor', $this->_variation); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - return $mce_css; |
|
| 782 | - } |
|
| 781 | + return $mce_css; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | 784 | |
| 785 | - public function load_scripts_styles_edit_message_template() |
|
| 786 | - { |
|
| 785 | + public function load_scripts_styles_edit_message_template() |
|
| 786 | + { |
|
| 787 | 787 | |
| 788 | - $this->_set_shortcodes(); |
|
| 788 | + $this->_set_shortcodes(); |
|
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | - __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | - 'event_espresso'), |
|
| 793 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | - ); |
|
| 796 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | - 'event_espresso'); |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | + __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | + 'event_espresso'), |
|
| 793 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | + ); |
|
| 796 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | + 'event_espresso'); |
|
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | - EVENT_ESPRESSO_VERSION); |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | + EVENT_ESPRESSO_VERSION); |
|
| 801 | 801 | |
| 802 | - wp_enqueue_script('ee_admin_js'); |
|
| 803 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 802 | + wp_enqueue_script('ee_admin_js'); |
|
| 803 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | 804 | |
| 805 | - //add in special css for tiny_mce |
|
| 806 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | - } |
|
| 805 | + //add in special css for tiny_mce |
|
| 806 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | + } |
|
| 808 | 808 | |
| 809 | 809 | |
| 810 | - public function load_scripts_styles_display_preview_message() |
|
| 811 | - { |
|
| 810 | + public function load_scripts_styles_display_preview_message() |
|
| 811 | + { |
|
| 812 | 812 | |
| 813 | - $this->_set_message_template_group(); |
|
| 813 | + $this->_set_message_template_group(); |
|
| 814 | 814 | |
| 815 | - if (isset($this->_req_data['messenger'])) { |
|
| 816 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | - } |
|
| 815 | + if (isset($this->_req_data['messenger'])) { |
|
| 816 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 819 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | 820 | |
| 821 | 821 | |
| 822 | - wp_enqueue_style('espresso_preview_css', |
|
| 823 | - $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | - $this->_variation)); |
|
| 825 | - } |
|
| 822 | + wp_enqueue_style('espresso_preview_css', |
|
| 823 | + $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | + $this->_variation)); |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | 827 | |
| 828 | - public function load_scripts_styles_settings() |
|
| 829 | - { |
|
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | - EVENT_ESPRESSO_VERSION); |
|
| 832 | - wp_enqueue_style('ee-text-links'); |
|
| 833 | - wp_enqueue_style('ee-message-settings'); |
|
| 828 | + public function load_scripts_styles_settings() |
|
| 829 | + { |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | + EVENT_ESPRESSO_VERSION); |
|
| 832 | + wp_enqueue_style('ee-text-links'); |
|
| 833 | + wp_enqueue_style('ee-message-settings'); |
|
| 834 | 834 | |
| 835 | - wp_enqueue_script('ee-messages-settings'); |
|
| 836 | - } |
|
| 835 | + wp_enqueue_script('ee-messages-settings'); |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | 838 | |
| 839 | - /** |
|
| 840 | - * set views array for List Table |
|
| 841 | - */ |
|
| 842 | - public function _set_list_table_views_global_mtps() |
|
| 843 | - { |
|
| 844 | - $this->_views = array( |
|
| 845 | - 'in_use' => array( |
|
| 846 | - 'slug' => 'in_use', |
|
| 847 | - 'label' => __('In Use', 'event_espresso'), |
|
| 848 | - 'count' => 0, |
|
| 849 | - ) |
|
| 850 | - ); |
|
| 851 | - } |
|
| 839 | + /** |
|
| 840 | + * set views array for List Table |
|
| 841 | + */ |
|
| 842 | + public function _set_list_table_views_global_mtps() |
|
| 843 | + { |
|
| 844 | + $this->_views = array( |
|
| 845 | + 'in_use' => array( |
|
| 846 | + 'slug' => 'in_use', |
|
| 847 | + 'label' => __('In Use', 'event_espresso'), |
|
| 848 | + 'count' => 0, |
|
| 849 | + ) |
|
| 850 | + ); |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | 853 | |
| 854 | - /** |
|
| 855 | - * Set views array for the Custom Template List Table |
|
| 856 | - */ |
|
| 857 | - public function _set_list_table_views_custom_mtps() |
|
| 858 | - { |
|
| 859 | - $this->_set_list_table_views_global_mtps(); |
|
| 860 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 861 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 862 | - ); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * set views array for message queue list table |
|
| 868 | - */ |
|
| 869 | - public function _set_list_table_views_default() |
|
| 870 | - { |
|
| 871 | - EE_Registry::instance()->load_helper('Template'); |
|
| 872 | - |
|
| 873 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 874 | - 'message_list_table_bulk_actions') |
|
| 875 | - ? array( |
|
| 876 | - 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 877 | - 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 878 | - 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 879 | - 'send_now' => __('Send Now', 'event_espresso') |
|
| 880 | - ) |
|
| 881 | - : array(); |
|
| 882 | - |
|
| 883 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 884 | - 'message_list_table_bulk_actions') |
|
| 885 | - ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 886 | - : array(); |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - $this->_views = array( |
|
| 890 | - 'all' => array( |
|
| 891 | - 'slug' => 'all', |
|
| 892 | - 'label' => __('All', 'event_espresso'), |
|
| 893 | - 'count' => 0, |
|
| 894 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 895 | - ) |
|
| 896 | - ); |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 900 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 901 | - continue; |
|
| 902 | - } |
|
| 903 | - $status_bulk_actions = $common_bulk_actions; |
|
| 904 | - //unset bulk actions not applying to status |
|
| 905 | - if (! empty($status_bulk_actions)) { |
|
| 906 | - switch ($status) { |
|
| 907 | - case EEM_Message::status_idle: |
|
| 908 | - case EEM_Message::status_resend: |
|
| 909 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 910 | - break; |
|
| 854 | + /** |
|
| 855 | + * Set views array for the Custom Template List Table |
|
| 856 | + */ |
|
| 857 | + public function _set_list_table_views_custom_mtps() |
|
| 858 | + { |
|
| 859 | + $this->_set_list_table_views_global_mtps(); |
|
| 860 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 861 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 862 | + ); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * set views array for message queue list table |
|
| 868 | + */ |
|
| 869 | + public function _set_list_table_views_default() |
|
| 870 | + { |
|
| 871 | + EE_Registry::instance()->load_helper('Template'); |
|
| 872 | + |
|
| 873 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 874 | + 'message_list_table_bulk_actions') |
|
| 875 | + ? array( |
|
| 876 | + 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 877 | + 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 878 | + 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 879 | + 'send_now' => __('Send Now', 'event_espresso') |
|
| 880 | + ) |
|
| 881 | + : array(); |
|
| 882 | + |
|
| 883 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 884 | + 'message_list_table_bulk_actions') |
|
| 885 | + ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 886 | + : array(); |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + $this->_views = array( |
|
| 890 | + 'all' => array( |
|
| 891 | + 'slug' => 'all', |
|
| 892 | + 'label' => __('All', 'event_espresso'), |
|
| 893 | + 'count' => 0, |
|
| 894 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 895 | + ) |
|
| 896 | + ); |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 900 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 901 | + continue; |
|
| 902 | + } |
|
| 903 | + $status_bulk_actions = $common_bulk_actions; |
|
| 904 | + //unset bulk actions not applying to status |
|
| 905 | + if (! empty($status_bulk_actions)) { |
|
| 906 | + switch ($status) { |
|
| 907 | + case EEM_Message::status_idle: |
|
| 908 | + case EEM_Message::status_resend: |
|
| 909 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 910 | + break; |
|
| 911 | 911 | |
| 912 | - case EEM_Message::status_failed: |
|
| 913 | - case EEM_Message::status_debug_only: |
|
| 914 | - case EEM_Message::status_messenger_executing: |
|
| 915 | - $status_bulk_actions = array(); |
|
| 916 | - break; |
|
| 912 | + case EEM_Message::status_failed: |
|
| 913 | + case EEM_Message::status_debug_only: |
|
| 914 | + case EEM_Message::status_messenger_executing: |
|
| 915 | + $status_bulk_actions = array(); |
|
| 916 | + break; |
|
| 917 | 917 | |
| 918 | - case EEM_Message::status_incomplete: |
|
| 919 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 920 | - break; |
|
| 918 | + case EEM_Message::status_incomplete: |
|
| 919 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 920 | + break; |
|
| 921 | 921 | |
| 922 | - case EEM_Message::status_retry: |
|
| 923 | - case EEM_Message::status_sent: |
|
| 924 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 925 | - break; |
|
| 926 | - } |
|
| 927 | - } |
|
| 922 | + case EEM_Message::status_retry: |
|
| 923 | + case EEM_Message::status_sent: |
|
| 924 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 925 | + break; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 930 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 931 | - continue; |
|
| 932 | - } |
|
| 929 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 930 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 931 | + continue; |
|
| 932 | + } |
|
| 933 | 933 | |
| 934 | - $this->_views[strtolower($status)] = array( |
|
| 935 | - 'slug' => strtolower($status), |
|
| 936 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 937 | - 'count' => 0, |
|
| 938 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - |
|
| 944 | - protected function _ee_default_messages_overview_list_table() |
|
| 945 | - { |
|
| 946 | - $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 947 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - protected function _message_queue_list_table() |
|
| 952 | - { |
|
| 953 | - $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 954 | - $this->_template_args['per_column'] = 6; |
|
| 955 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 956 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 957 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - |
|
| 961 | - protected function _message_legend_items() |
|
| 962 | - { |
|
| 963 | - |
|
| 964 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 965 | - $action_items = array(); |
|
| 966 | - |
|
| 967 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 968 | - if ($action_item === 'see_notifications_for') { |
|
| 969 | - continue; |
|
| 970 | - } |
|
| 971 | - $action_items[$action_item] = array( |
|
| 972 | - 'class' => $action_details['css_class'], |
|
| 973 | - 'desc' => $action_details['label'] |
|
| 974 | - ); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - /** @type array $status_items status legend setup */ |
|
| 978 | - $status_items = array( |
|
| 979 | - 'sent_status' => array( |
|
| 980 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 981 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 982 | - ), |
|
| 983 | - 'idle_status' => array( |
|
| 984 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 985 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 986 | - ), |
|
| 987 | - 'failed_status' => array( |
|
| 988 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 989 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 990 | - ), |
|
| 991 | - 'messenger_executing_status' => array( |
|
| 992 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 993 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 994 | - ), |
|
| 995 | - 'resend_status' => array( |
|
| 996 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 997 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 998 | - ), |
|
| 999 | - 'incomplete_status' => array( |
|
| 1000 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1001 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1002 | - ), |
|
| 1003 | - 'retry_status' => array( |
|
| 1004 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1005 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1006 | - ) |
|
| 1007 | - ); |
|
| 1008 | - if (EEM_Message::debug()) { |
|
| 1009 | - $status_items['debug_only_status'] = array( |
|
| 1010 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1011 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1012 | - ); |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - return array_merge($action_items, $status_items); |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - protected function _custom_mtps_preview() |
|
| 1020 | - { |
|
| 1021 | - $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1022 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1023 | - 'event_espresso') . '" />'; |
|
| 1024 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1025 | - 'event_espresso') . '</strong>'; |
|
| 1026 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * get_message_templates |
|
| 1032 | - * This gets all the message templates for listing on the overview list. |
|
| 1033 | - * |
|
| 1034 | - * @access public |
|
| 1035 | - * |
|
| 1036 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1037 | - * @param string $type the current _view we're getting templates for |
|
| 1038 | - * @param bool $count return count? |
|
| 1039 | - * @param bool $all disregard any paging info (get all data); |
|
| 1040 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1041 | - * |
|
| 1042 | - * @return array |
|
| 1043 | - */ |
|
| 1044 | - public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1045 | - { |
|
| 1046 | - |
|
| 1047 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1048 | - |
|
| 1049 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1050 | - $orderby = $this->_req_data['orderby']; |
|
| 1051 | - |
|
| 1052 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1053 | - |
|
| 1054 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1055 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1056 | - |
|
| 1057 | - $offset = ($current_page - 1) * $per_page; |
|
| 1058 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - //options will match what is in the _views array property |
|
| 1062 | - switch ($type) { |
|
| 934 | + $this->_views[strtolower($status)] = array( |
|
| 935 | + 'slug' => strtolower($status), |
|
| 936 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 937 | + 'count' => 0, |
|
| 938 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + |
|
| 944 | + protected function _ee_default_messages_overview_list_table() |
|
| 945 | + { |
|
| 946 | + $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 947 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + protected function _message_queue_list_table() |
|
| 952 | + { |
|
| 953 | + $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 954 | + $this->_template_args['per_column'] = 6; |
|
| 955 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 956 | + $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 957 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + |
|
| 961 | + protected function _message_legend_items() |
|
| 962 | + { |
|
| 963 | + |
|
| 964 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 965 | + $action_items = array(); |
|
| 966 | + |
|
| 967 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 968 | + if ($action_item === 'see_notifications_for') { |
|
| 969 | + continue; |
|
| 970 | + } |
|
| 971 | + $action_items[$action_item] = array( |
|
| 972 | + 'class' => $action_details['css_class'], |
|
| 973 | + 'desc' => $action_details['label'] |
|
| 974 | + ); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + /** @type array $status_items status legend setup */ |
|
| 978 | + $status_items = array( |
|
| 979 | + 'sent_status' => array( |
|
| 980 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 981 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 982 | + ), |
|
| 983 | + 'idle_status' => array( |
|
| 984 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 985 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 986 | + ), |
|
| 987 | + 'failed_status' => array( |
|
| 988 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 989 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 990 | + ), |
|
| 991 | + 'messenger_executing_status' => array( |
|
| 992 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 993 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 994 | + ), |
|
| 995 | + 'resend_status' => array( |
|
| 996 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 997 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 998 | + ), |
|
| 999 | + 'incomplete_status' => array( |
|
| 1000 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1001 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1002 | + ), |
|
| 1003 | + 'retry_status' => array( |
|
| 1004 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1005 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1006 | + ) |
|
| 1007 | + ); |
|
| 1008 | + if (EEM_Message::debug()) { |
|
| 1009 | + $status_items['debug_only_status'] = array( |
|
| 1010 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1011 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1012 | + ); |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + return array_merge($action_items, $status_items); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + protected function _custom_mtps_preview() |
|
| 1020 | + { |
|
| 1021 | + $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1022 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1023 | + 'event_espresso') . '" />'; |
|
| 1024 | + $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1025 | + 'event_espresso') . '</strong>'; |
|
| 1026 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * get_message_templates |
|
| 1032 | + * This gets all the message templates for listing on the overview list. |
|
| 1033 | + * |
|
| 1034 | + * @access public |
|
| 1035 | + * |
|
| 1036 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1037 | + * @param string $type the current _view we're getting templates for |
|
| 1038 | + * @param bool $count return count? |
|
| 1039 | + * @param bool $all disregard any paging info (get all data); |
|
| 1040 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1041 | + * |
|
| 1042 | + * @return array |
|
| 1043 | + */ |
|
| 1044 | + public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1045 | + { |
|
| 1046 | + |
|
| 1047 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1048 | + |
|
| 1049 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1050 | + $orderby = $this->_req_data['orderby']; |
|
| 1051 | + |
|
| 1052 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1053 | + |
|
| 1054 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1055 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1056 | + |
|
| 1057 | + $offset = ($current_page - 1) * $per_page; |
|
| 1058 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + //options will match what is in the _views array property |
|
| 1062 | + switch ($type) { |
|
| 1063 | 1063 | |
| 1064 | - case 'in_use': |
|
| 1065 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1066 | - break; |
|
| 1064 | + case 'in_use': |
|
| 1065 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1066 | + break; |
|
| 1067 | 1067 | |
| 1068 | - default: |
|
| 1069 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1068 | + default: |
|
| 1069 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1070 | 1070 | |
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $templates; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * filters etc might need a list of installed message_types |
|
| 1079 | - * @return array an array of message type objects |
|
| 1080 | - */ |
|
| 1081 | - public function get_installed_message_types() |
|
| 1082 | - { |
|
| 1083 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1084 | - $installed = array(); |
|
| 1085 | - |
|
| 1086 | - foreach ($installed_message_types as $message_type) { |
|
| 1087 | - $installed[$message_type->name] = $message_type; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - return $installed; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * _add_message_template |
|
| 1096 | - * |
|
| 1097 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1098 | - * |
|
| 1099 | - * @param string $message_type |
|
| 1100 | - * @param string $messenger |
|
| 1101 | - * @param string $GRP_ID |
|
| 1102 | - * |
|
| 1103 | - * @throws EE_error |
|
| 1104 | - */ |
|
| 1105 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1106 | - { |
|
| 1107 | - //set values override any request data |
|
| 1108 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1109 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1110 | - |
|
| 1111 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1112 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1113 | - |
|
| 1114 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1115 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1116 | - |
|
| 1117 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1118 | - if (empty($message_type) || empty($messenger)) { |
|
| 1119 | - throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1120 | - 'event_espresso')); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1124 | - if (empty($GRP_ID)) { |
|
| 1125 | - throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1126 | - 'event_espresso')); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - //let's just make sure the template gets generated! |
|
| 1130 | - |
|
| 1131 | - //we need to reassign some variables for what the insert is expecting |
|
| 1132 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1133 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1134 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1135 | - $this->_insert_or_update_message_template(true); |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - |
|
| 1139 | - /** |
|
| 1140 | - * public wrapper for the _add_message_template method |
|
| 1141 | - * |
|
| 1142 | - * @param string $message_type message type slug |
|
| 1143 | - * @param string $messenger messenger slug |
|
| 1144 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1145 | - * off of. |
|
| 1146 | - */ |
|
| 1147 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1148 | - { |
|
| 1149 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - |
|
| 1153 | - /** |
|
| 1154 | - * _edit_message_template |
|
| 1155 | - * |
|
| 1156 | - * @access protected |
|
| 1157 | - * @return void |
|
| 1158 | - */ |
|
| 1159 | - protected function _edit_message_template() |
|
| 1160 | - { |
|
| 1161 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1162 | - $template_fields = ''; |
|
| 1163 | - $sidebar_fields = ''; |
|
| 1164 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1165 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1166 | - |
|
| 1167 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1168 | - ? absint($this->_req_data['id']) |
|
| 1169 | - : false; |
|
| 1170 | - |
|
| 1171 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1172 | - $message_template_group = $this->_message_template_group; |
|
| 1173 | - $c_label = $message_template_group->context_label(); |
|
| 1174 | - $c_config = $message_template_group->contexts_config(); |
|
| 1175 | - |
|
| 1176 | - reset($c_config); |
|
| 1177 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1178 | - ? strtolower($this->_req_data['context']) |
|
| 1179 | - : key($c_config); |
|
| 1180 | - |
|
| 1181 | - |
|
| 1182 | - if (empty($GRP_ID)) { |
|
| 1183 | - $action = 'insert_message_template'; |
|
| 1184 | - //$button_both = false; |
|
| 1185 | - //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1186 | - //$button_actions = array('something_different'); |
|
| 1187 | - //$referrer = false; |
|
| 1188 | - $edit_message_template_form_url = add_query_arg( |
|
| 1189 | - array('action' => $action, 'noheader' => true), |
|
| 1190 | - EE_MSG_ADMIN_URL |
|
| 1191 | - ); |
|
| 1192 | - } else { |
|
| 1193 | - $action = 'update_message_template'; |
|
| 1194 | - //$button_both = true; |
|
| 1195 | - //$button_text = array(); |
|
| 1196 | - //$button_actions = array(); |
|
| 1197 | - //$referrer = $this->_admin_base_url; |
|
| 1198 | - $edit_message_template_form_url = add_query_arg( |
|
| 1199 | - array('action' => $action, 'noheader' => true), |
|
| 1200 | - EE_MSG_ADMIN_URL |
|
| 1201 | - ); |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - //set active messenger for this view |
|
| 1205 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1206 | - $message_template_group->messenger() |
|
| 1207 | - ); |
|
| 1208 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1209 | - |
|
| 1210 | - |
|
| 1211 | - //Do we have any validation errors? |
|
| 1212 | - $validators = $this->_get_transient(); |
|
| 1213 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - //we need to assemble the title from Various details |
|
| 1217 | - $context_label = sprintf( |
|
| 1218 | - __('(%s %s)', 'event_espresso'), |
|
| 1219 | - $c_config[$context]['label'], |
|
| 1220 | - ucwords($c_label['label']) |
|
| 1221 | - ); |
|
| 1222 | - |
|
| 1223 | - $title = sprintf( |
|
| 1224 | - __(' %s %s Template %s', 'event_espresso'), |
|
| 1225 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1226 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1227 | - $context_label |
|
| 1228 | - ); |
|
| 1229 | - |
|
| 1230 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1231 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1232 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1233 | - |
|
| 1234 | - |
|
| 1235 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1236 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1237 | - $message_template_group->messenger(), |
|
| 1238 | - $message_template_group->message_type() |
|
| 1239 | - ); |
|
| 1240 | - |
|
| 1241 | - if ( ! $template_field_structure) { |
|
| 1242 | - $template_field_structure = false; |
|
| 1243 | - $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1244 | - 'event_espresso'); |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - |
|
| 1248 | - $message_templates = $message_template_group->context_templates(); |
|
| 1249 | - |
|
| 1250 | - |
|
| 1251 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1252 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1253 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1254 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1259 | - if ( ! empty($template_field_structure)) { |
|
| 1260 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1261 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1262 | - if ($template_field == 'extra') { |
|
| 1263 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1264 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1265 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1266 | - $content = $message_template instanceof EE_Message_Template |
|
| 1267 | - ? $message_template->get('MTP_content') |
|
| 1268 | - : ''; |
|
| 1269 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1270 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1271 | - $continue = false; |
|
| 1272 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1273 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1274 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1275 | - $continue = true; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - if ($continue) { |
|
| 1279 | - continue; |
|
| 1280 | - } |
|
| 1281 | - } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $templates; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * filters etc might need a list of installed message_types |
|
| 1079 | + * @return array an array of message type objects |
|
| 1080 | + */ |
|
| 1081 | + public function get_installed_message_types() |
|
| 1082 | + { |
|
| 1083 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1084 | + $installed = array(); |
|
| 1085 | + |
|
| 1086 | + foreach ($installed_message_types as $message_type) { |
|
| 1087 | + $installed[$message_type->name] = $message_type; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + return $installed; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * _add_message_template |
|
| 1096 | + * |
|
| 1097 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1098 | + * |
|
| 1099 | + * @param string $message_type |
|
| 1100 | + * @param string $messenger |
|
| 1101 | + * @param string $GRP_ID |
|
| 1102 | + * |
|
| 1103 | + * @throws EE_error |
|
| 1104 | + */ |
|
| 1105 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1106 | + { |
|
| 1107 | + //set values override any request data |
|
| 1108 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1109 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1110 | + |
|
| 1111 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1112 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1113 | + |
|
| 1114 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1115 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1116 | + |
|
| 1117 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1118 | + if (empty($message_type) || empty($messenger)) { |
|
| 1119 | + throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1120 | + 'event_espresso')); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1124 | + if (empty($GRP_ID)) { |
|
| 1125 | + throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1126 | + 'event_espresso')); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + //let's just make sure the template gets generated! |
|
| 1130 | + |
|
| 1131 | + //we need to reassign some variables for what the insert is expecting |
|
| 1132 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1133 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1134 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1135 | + $this->_insert_or_update_message_template(true); |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + |
|
| 1139 | + /** |
|
| 1140 | + * public wrapper for the _add_message_template method |
|
| 1141 | + * |
|
| 1142 | + * @param string $message_type message type slug |
|
| 1143 | + * @param string $messenger messenger slug |
|
| 1144 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1145 | + * off of. |
|
| 1146 | + */ |
|
| 1147 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1148 | + { |
|
| 1149 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + |
|
| 1153 | + /** |
|
| 1154 | + * _edit_message_template |
|
| 1155 | + * |
|
| 1156 | + * @access protected |
|
| 1157 | + * @return void |
|
| 1158 | + */ |
|
| 1159 | + protected function _edit_message_template() |
|
| 1160 | + { |
|
| 1161 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1162 | + $template_fields = ''; |
|
| 1163 | + $sidebar_fields = ''; |
|
| 1164 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1165 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1166 | + |
|
| 1167 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1168 | + ? absint($this->_req_data['id']) |
|
| 1169 | + : false; |
|
| 1170 | + |
|
| 1171 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1172 | + $message_template_group = $this->_message_template_group; |
|
| 1173 | + $c_label = $message_template_group->context_label(); |
|
| 1174 | + $c_config = $message_template_group->contexts_config(); |
|
| 1175 | + |
|
| 1176 | + reset($c_config); |
|
| 1177 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1178 | + ? strtolower($this->_req_data['context']) |
|
| 1179 | + : key($c_config); |
|
| 1180 | + |
|
| 1181 | + |
|
| 1182 | + if (empty($GRP_ID)) { |
|
| 1183 | + $action = 'insert_message_template'; |
|
| 1184 | + //$button_both = false; |
|
| 1185 | + //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1186 | + //$button_actions = array('something_different'); |
|
| 1187 | + //$referrer = false; |
|
| 1188 | + $edit_message_template_form_url = add_query_arg( |
|
| 1189 | + array('action' => $action, 'noheader' => true), |
|
| 1190 | + EE_MSG_ADMIN_URL |
|
| 1191 | + ); |
|
| 1192 | + } else { |
|
| 1193 | + $action = 'update_message_template'; |
|
| 1194 | + //$button_both = true; |
|
| 1195 | + //$button_text = array(); |
|
| 1196 | + //$button_actions = array(); |
|
| 1197 | + //$referrer = $this->_admin_base_url; |
|
| 1198 | + $edit_message_template_form_url = add_query_arg( |
|
| 1199 | + array('action' => $action, 'noheader' => true), |
|
| 1200 | + EE_MSG_ADMIN_URL |
|
| 1201 | + ); |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + //set active messenger for this view |
|
| 1205 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1206 | + $message_template_group->messenger() |
|
| 1207 | + ); |
|
| 1208 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1209 | + |
|
| 1210 | + |
|
| 1211 | + //Do we have any validation errors? |
|
| 1212 | + $validators = $this->_get_transient(); |
|
| 1213 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + //we need to assemble the title from Various details |
|
| 1217 | + $context_label = sprintf( |
|
| 1218 | + __('(%s %s)', 'event_espresso'), |
|
| 1219 | + $c_config[$context]['label'], |
|
| 1220 | + ucwords($c_label['label']) |
|
| 1221 | + ); |
|
| 1222 | + |
|
| 1223 | + $title = sprintf( |
|
| 1224 | + __(' %s %s Template %s', 'event_espresso'), |
|
| 1225 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1226 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1227 | + $context_label |
|
| 1228 | + ); |
|
| 1229 | + |
|
| 1230 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1231 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1232 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1233 | + |
|
| 1234 | + |
|
| 1235 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1236 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1237 | + $message_template_group->messenger(), |
|
| 1238 | + $message_template_group->message_type() |
|
| 1239 | + ); |
|
| 1240 | + |
|
| 1241 | + if ( ! $template_field_structure) { |
|
| 1242 | + $template_field_structure = false; |
|
| 1243 | + $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1244 | + 'event_espresso'); |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + |
|
| 1248 | + $message_templates = $message_template_group->context_templates(); |
|
| 1249 | + |
|
| 1250 | + |
|
| 1251 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1252 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1253 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1254 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1259 | + if ( ! empty($template_field_structure)) { |
|
| 1260 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1261 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1262 | + if ($template_field == 'extra') { |
|
| 1263 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1264 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1265 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1266 | + $content = $message_template instanceof EE_Message_Template |
|
| 1267 | + ? $message_template->get('MTP_content') |
|
| 1268 | + : ''; |
|
| 1269 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1270 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1271 | + $continue = false; |
|
| 1272 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1273 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1274 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1275 | + $continue = true; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + if ($continue) { |
|
| 1279 | + continue; |
|
| 1280 | + } |
|
| 1281 | + } |
|
| 1282 | 1282 | |
| 1283 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1284 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1285 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1286 | - $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1283 | + $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1284 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1285 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1286 | + $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1287 | 1287 | |
| 1288 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1289 | - && in_array($extra_field, $v_fields) |
|
| 1290 | - && |
|
| 1291 | - ( |
|
| 1292 | - is_array($validators[$extra_field]) |
|
| 1293 | - && isset($validators[$extra_field]['msg']) |
|
| 1294 | - ) |
|
| 1295 | - ? 'validate-error ' . $css_class |
|
| 1296 | - : $css_class; |
|
| 1288 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1289 | + && in_array($extra_field, $v_fields) |
|
| 1290 | + && |
|
| 1291 | + ( |
|
| 1292 | + is_array($validators[$extra_field]) |
|
| 1293 | + && isset($validators[$extra_field]['msg']) |
|
| 1294 | + ) |
|
| 1295 | + ? 'validate-error ' . $css_class |
|
| 1296 | + : $css_class; |
|
| 1297 | 1297 | |
| 1298 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1299 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1300 | - : ''; |
|
| 1298 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1299 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1300 | + : ''; |
|
| 1301 | 1301 | |
| 1302 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1303 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1302 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1303 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1304 | 1304 | |
| 1305 | 1305 | |
| 1306 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1306 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1307 | 1307 | |
| 1308 | - //shortcode selector |
|
| 1309 | - $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1310 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1311 | - $field_name_to_use, |
|
| 1312 | - $field_id |
|
| 1313 | - ); |
|
| 1308 | + //shortcode selector |
|
| 1309 | + $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1310 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1311 | + $field_name_to_use, |
|
| 1312 | + $field_id |
|
| 1313 | + ); |
|
| 1314 | 1314 | |
| 1315 | - if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1316 | - //we want to decode the entities |
|
| 1317 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1318 | - html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1319 | - ); |
|
| 1315 | + if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1316 | + //we want to decode the entities |
|
| 1317 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1318 | + html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1319 | + ); |
|
| 1320 | 1320 | |
| 1321 | - }/**/ |
|
| 1322 | - } |
|
| 1323 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1324 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1321 | + }/**/ |
|
| 1322 | + } |
|
| 1323 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1324 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1325 | 1325 | |
| 1326 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1327 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1328 | - 'label' => null, |
|
| 1329 | - 'input' => 'hidden', |
|
| 1330 | - 'type' => 'int', |
|
| 1331 | - 'required' => false, |
|
| 1332 | - 'validation' => false, |
|
| 1333 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1334 | - 'css_class' => '', |
|
| 1335 | - 'format' => '%d', |
|
| 1336 | - 'db-col' => 'MTP_ID' |
|
| 1337 | - ); |
|
| 1326 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1327 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1328 | + 'label' => null, |
|
| 1329 | + 'input' => 'hidden', |
|
| 1330 | + 'type' => 'int', |
|
| 1331 | + 'required' => false, |
|
| 1332 | + 'validation' => false, |
|
| 1333 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1334 | + 'css_class' => '', |
|
| 1335 | + 'format' => '%d', |
|
| 1336 | + 'db-col' => 'MTP_ID' |
|
| 1337 | + ); |
|
| 1338 | 1338 | |
| 1339 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1340 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1341 | - 'label' => null, |
|
| 1342 | - 'input' => 'hidden', |
|
| 1343 | - 'type' => 'string', |
|
| 1344 | - 'required' => false, |
|
| 1345 | - 'validation' => true, |
|
| 1346 | - 'value' => $reference_field, |
|
| 1347 | - 'css_class' => '', |
|
| 1348 | - 'format' => '%s', |
|
| 1349 | - 'db-col' => 'MTP_template_field' |
|
| 1350 | - ); |
|
| 1351 | - } |
|
| 1352 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1353 | - } else { |
|
| 1354 | - $field_id = $template_field . '-content'; |
|
| 1355 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1356 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1357 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1358 | - ? $message_templates[$context][$template_field] |
|
| 1359 | - : null; |
|
| 1360 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1361 | - && is_array($message_templates[$context]) |
|
| 1362 | - && $message_template instanceof EE_Message_Template |
|
| 1363 | - ? $message_template->get('MTP_content') |
|
| 1364 | - : ''; |
|
| 1339 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1340 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1341 | + 'label' => null, |
|
| 1342 | + 'input' => 'hidden', |
|
| 1343 | + 'type' => 'string', |
|
| 1344 | + 'required' => false, |
|
| 1345 | + 'validation' => true, |
|
| 1346 | + 'value' => $reference_field, |
|
| 1347 | + 'css_class' => '', |
|
| 1348 | + 'format' => '%s', |
|
| 1349 | + 'db-col' => 'MTP_template_field' |
|
| 1350 | + ); |
|
| 1351 | + } |
|
| 1352 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1353 | + } else { |
|
| 1354 | + $field_id = $template_field . '-content'; |
|
| 1355 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1356 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1357 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1358 | + ? $message_templates[$context][$template_field] |
|
| 1359 | + : null; |
|
| 1360 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1361 | + && is_array($message_templates[$context]) |
|
| 1362 | + && $message_template instanceof EE_Message_Template |
|
| 1363 | + ? $message_template->get('MTP_content') |
|
| 1364 | + : ''; |
|
| 1365 | 1365 | |
| 1366 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1367 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1368 | - ? $validators[$template_field]['value'] |
|
| 1369 | - : $template_form_fields[$field_id]['value']; |
|
| 1366 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1367 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1368 | + ? $validators[$template_field]['value'] |
|
| 1369 | + : $template_form_fields[$field_id]['value']; |
|
| 1370 | 1370 | |
| 1371 | 1371 | |
| 1372 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1373 | - $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1374 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1375 | - && in_array($template_field, $v_fields) |
|
| 1376 | - && isset($validators[$template_field]['msg']) |
|
| 1377 | - ? 'validate-error ' . $css_class |
|
| 1378 | - : $css_class; |
|
| 1372 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1373 | + $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1374 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1375 | + && in_array($template_field, $v_fields) |
|
| 1376 | + && isset($validators[$template_field]['msg']) |
|
| 1377 | + ? 'validate-error ' . $css_class |
|
| 1378 | + : $css_class; |
|
| 1379 | 1379 | |
| 1380 | - //shortcode selector |
|
| 1381 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1382 | - $template_field, $field_id |
|
| 1383 | - ); |
|
| 1384 | - } |
|
| 1380 | + //shortcode selector |
|
| 1381 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1382 | + $template_field, $field_id |
|
| 1383 | + ); |
|
| 1384 | + } |
|
| 1385 | 1385 | |
| 1386 | - //k took care of content field(s) now let's take care of others. |
|
| 1386 | + //k took care of content field(s) now let's take care of others. |
|
| 1387 | 1387 | |
| 1388 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1389 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1388 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1389 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1390 | 1390 | |
| 1391 | - //foreach template field there are actually two form fields created |
|
| 1392 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1393 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1394 | - 'label' => null, |
|
| 1395 | - 'input' => 'hidden', |
|
| 1396 | - 'type' => 'int', |
|
| 1397 | - 'required' => false, |
|
| 1398 | - 'validation' => true, |
|
| 1399 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1400 | - 'css_class' => '', |
|
| 1401 | - 'format' => '%d', |
|
| 1402 | - 'db-col' => 'MTP_ID' |
|
| 1403 | - ); |
|
| 1391 | + //foreach template field there are actually two form fields created |
|
| 1392 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1393 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1394 | + 'label' => null, |
|
| 1395 | + 'input' => 'hidden', |
|
| 1396 | + 'type' => 'int', |
|
| 1397 | + 'required' => false, |
|
| 1398 | + 'validation' => true, |
|
| 1399 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1400 | + 'css_class' => '', |
|
| 1401 | + 'format' => '%d', |
|
| 1402 | + 'db-col' => 'MTP_ID' |
|
| 1403 | + ); |
|
| 1404 | 1404 | |
| 1405 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1406 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1407 | - 'label' => null, |
|
| 1408 | - 'input' => 'hidden', |
|
| 1409 | - 'type' => 'string', |
|
| 1410 | - 'required' => false, |
|
| 1411 | - 'validation' => true, |
|
| 1412 | - 'value' => $template_field, |
|
| 1413 | - 'css_class' => '', |
|
| 1414 | - 'format' => '%s', |
|
| 1415 | - 'db-col' => 'MTP_template_field' |
|
| 1416 | - ); |
|
| 1405 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1406 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1407 | + 'label' => null, |
|
| 1408 | + 'input' => 'hidden', |
|
| 1409 | + 'type' => 'string', |
|
| 1410 | + 'required' => false, |
|
| 1411 | + 'validation' => true, |
|
| 1412 | + 'value' => $template_field, |
|
| 1413 | + 'css_class' => '', |
|
| 1414 | + 'format' => '%s', |
|
| 1415 | + 'db-col' => 'MTP_template_field' |
|
| 1416 | + ); |
|
| 1417 | 1417 | |
| 1418 | - } |
|
| 1418 | + } |
|
| 1419 | 1419 | |
| 1420 | - //add other fields |
|
| 1421 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1422 | - 'name' => 'MTP_context', |
|
| 1423 | - 'label' => null, |
|
| 1424 | - 'input' => 'hidden', |
|
| 1425 | - 'type' => 'string', |
|
| 1426 | - 'required' => false, |
|
| 1427 | - 'validation' => true, |
|
| 1428 | - 'value' => $context, |
|
| 1429 | - 'css_class' => '', |
|
| 1430 | - 'format' => '%s', |
|
| 1431 | - 'db-col' => 'MTP_context' |
|
| 1432 | - ); |
|
| 1420 | + //add other fields |
|
| 1421 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1422 | + 'name' => 'MTP_context', |
|
| 1423 | + 'label' => null, |
|
| 1424 | + 'input' => 'hidden', |
|
| 1425 | + 'type' => 'string', |
|
| 1426 | + 'required' => false, |
|
| 1427 | + 'validation' => true, |
|
| 1428 | + 'value' => $context, |
|
| 1429 | + 'css_class' => '', |
|
| 1430 | + 'format' => '%s', |
|
| 1431 | + 'db-col' => 'MTP_context' |
|
| 1432 | + ); |
|
| 1433 | 1433 | |
| 1434 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1435 | - 'name' => 'GRP_ID', |
|
| 1436 | - 'label' => null, |
|
| 1437 | - 'input' => 'hidden', |
|
| 1438 | - 'type' => 'int', |
|
| 1439 | - 'required' => false, |
|
| 1440 | - 'validation' => true, |
|
| 1441 | - 'value' => $GRP_ID, |
|
| 1442 | - 'css_class' => '', |
|
| 1443 | - 'format' => '%d', |
|
| 1444 | - 'db-col' => 'GRP_ID' |
|
| 1445 | - ); |
|
| 1434 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1435 | + 'name' => 'GRP_ID', |
|
| 1436 | + 'label' => null, |
|
| 1437 | + 'input' => 'hidden', |
|
| 1438 | + 'type' => 'int', |
|
| 1439 | + 'required' => false, |
|
| 1440 | + 'validation' => true, |
|
| 1441 | + 'value' => $GRP_ID, |
|
| 1442 | + 'css_class' => '', |
|
| 1443 | + 'format' => '%d', |
|
| 1444 | + 'db-col' => 'GRP_ID' |
|
| 1445 | + ); |
|
| 1446 | 1446 | |
| 1447 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1448 | - 'name' => 'MTP_messenger', |
|
| 1449 | - 'label' => null, |
|
| 1450 | - 'input' => 'hidden', |
|
| 1451 | - 'type' => 'string', |
|
| 1452 | - 'required' => false, |
|
| 1453 | - 'validation' => true, |
|
| 1454 | - 'value' => $message_template_group->messenger(), |
|
| 1455 | - 'css_class' => '', |
|
| 1456 | - 'format' => '%s', |
|
| 1457 | - 'db-col' => 'MTP_messenger' |
|
| 1458 | - ); |
|
| 1447 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1448 | + 'name' => 'MTP_messenger', |
|
| 1449 | + 'label' => null, |
|
| 1450 | + 'input' => 'hidden', |
|
| 1451 | + 'type' => 'string', |
|
| 1452 | + 'required' => false, |
|
| 1453 | + 'validation' => true, |
|
| 1454 | + 'value' => $message_template_group->messenger(), |
|
| 1455 | + 'css_class' => '', |
|
| 1456 | + 'format' => '%s', |
|
| 1457 | + 'db-col' => 'MTP_messenger' |
|
| 1458 | + ); |
|
| 1459 | 1459 | |
| 1460 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1461 | - 'name' => 'MTP_message_type', |
|
| 1462 | - 'label' => null, |
|
| 1463 | - 'input' => 'hidden', |
|
| 1464 | - 'type' => 'string', |
|
| 1465 | - 'required' => false, |
|
| 1466 | - 'validation' => true, |
|
| 1467 | - 'value' => $message_template_group->message_type(), |
|
| 1468 | - 'css_class' => '', |
|
| 1469 | - 'format' => '%s', |
|
| 1470 | - 'db-col' => 'MTP_message_type' |
|
| 1471 | - ); |
|
| 1460 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1461 | + 'name' => 'MTP_message_type', |
|
| 1462 | + 'label' => null, |
|
| 1463 | + 'input' => 'hidden', |
|
| 1464 | + 'type' => 'string', |
|
| 1465 | + 'required' => false, |
|
| 1466 | + 'validation' => true, |
|
| 1467 | + 'value' => $message_template_group->message_type(), |
|
| 1468 | + 'css_class' => '', |
|
| 1469 | + 'format' => '%s', |
|
| 1470 | + 'db-col' => 'MTP_message_type' |
|
| 1471 | + ); |
|
| 1472 | 1472 | |
| 1473 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1474 | - 'name' => 'MTP_is_global', |
|
| 1475 | - 'label' => __('Global Template', 'event_espresso'), |
|
| 1476 | - 'input' => 'hidden', |
|
| 1477 | - 'type' => 'int', |
|
| 1478 | - 'required' => false, |
|
| 1479 | - 'validation' => true, |
|
| 1480 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1481 | - 'css_class' => '', |
|
| 1482 | - 'format' => '%d', |
|
| 1483 | - 'db-col' => 'MTP_is_global' |
|
| 1484 | - ); |
|
| 1473 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1474 | + 'name' => 'MTP_is_global', |
|
| 1475 | + 'label' => __('Global Template', 'event_espresso'), |
|
| 1476 | + 'input' => 'hidden', |
|
| 1477 | + 'type' => 'int', |
|
| 1478 | + 'required' => false, |
|
| 1479 | + 'validation' => true, |
|
| 1480 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1481 | + 'css_class' => '', |
|
| 1482 | + 'format' => '%d', |
|
| 1483 | + 'db-col' => 'MTP_is_global' |
|
| 1484 | + ); |
|
| 1485 | 1485 | |
| 1486 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1487 | - 'name' => 'MTP_is_override', |
|
| 1488 | - 'label' => __('Override all custom', 'event_espresso'), |
|
| 1489 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1490 | - 'type' => 'int', |
|
| 1491 | - 'required' => false, |
|
| 1492 | - 'validation' => true, |
|
| 1493 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1494 | - 'css_class' => '', |
|
| 1495 | - 'format' => '%d', |
|
| 1496 | - 'db-col' => 'MTP_is_override' |
|
| 1497 | - ); |
|
| 1486 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1487 | + 'name' => 'MTP_is_override', |
|
| 1488 | + 'label' => __('Override all custom', 'event_espresso'), |
|
| 1489 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1490 | + 'type' => 'int', |
|
| 1491 | + 'required' => false, |
|
| 1492 | + 'validation' => true, |
|
| 1493 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1494 | + 'css_class' => '', |
|
| 1495 | + 'format' => '%d', |
|
| 1496 | + 'db-col' => 'MTP_is_override' |
|
| 1497 | + ); |
|
| 1498 | 1498 | |
| 1499 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1500 | - 'name' => 'MTP_is_active', |
|
| 1501 | - 'label' => __('Active Template', 'event_espresso'), |
|
| 1502 | - 'input' => 'hidden', |
|
| 1503 | - 'type' => 'int', |
|
| 1504 | - 'required' => false, |
|
| 1505 | - 'validation' => true, |
|
| 1506 | - 'value' => $message_template_group->is_active(), |
|
| 1507 | - 'css_class' => '', |
|
| 1508 | - 'format' => '%d', |
|
| 1509 | - 'db-col' => 'MTP_is_active' |
|
| 1510 | - ); |
|
| 1499 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1500 | + 'name' => 'MTP_is_active', |
|
| 1501 | + 'label' => __('Active Template', 'event_espresso'), |
|
| 1502 | + 'input' => 'hidden', |
|
| 1503 | + 'type' => 'int', |
|
| 1504 | + 'required' => false, |
|
| 1505 | + 'validation' => true, |
|
| 1506 | + 'value' => $message_template_group->is_active(), |
|
| 1507 | + 'css_class' => '', |
|
| 1508 | + 'format' => '%d', |
|
| 1509 | + 'db-col' => 'MTP_is_active' |
|
| 1510 | + ); |
|
| 1511 | 1511 | |
| 1512 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1513 | - 'name' => 'MTP_deleted', |
|
| 1514 | - 'label' => null, |
|
| 1515 | - 'input' => 'hidden', |
|
| 1516 | - 'type' => 'int', |
|
| 1517 | - 'required' => false, |
|
| 1518 | - 'validation' => true, |
|
| 1519 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1520 | - 'css_class' => '', |
|
| 1521 | - 'format' => '%d', |
|
| 1522 | - 'db-col' => 'MTP_deleted' |
|
| 1523 | - ); |
|
| 1524 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1525 | - 'name' => 'MTP_user_id', |
|
| 1526 | - 'label' => __('Author', 'event_espresso'), |
|
| 1527 | - 'input' => 'hidden', |
|
| 1528 | - 'type' => 'int', |
|
| 1529 | - 'required' => false, |
|
| 1530 | - 'validation' => false, |
|
| 1531 | - 'value' => $message_template_group->user(), |
|
| 1532 | - 'format' => '%d', |
|
| 1533 | - 'db-col' => 'MTP_user_id' |
|
| 1534 | - ); |
|
| 1512 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1513 | + 'name' => 'MTP_deleted', |
|
| 1514 | + 'label' => null, |
|
| 1515 | + 'input' => 'hidden', |
|
| 1516 | + 'type' => 'int', |
|
| 1517 | + 'required' => false, |
|
| 1518 | + 'validation' => true, |
|
| 1519 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1520 | + 'css_class' => '', |
|
| 1521 | + 'format' => '%d', |
|
| 1522 | + 'db-col' => 'MTP_deleted' |
|
| 1523 | + ); |
|
| 1524 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1525 | + 'name' => 'MTP_user_id', |
|
| 1526 | + 'label' => __('Author', 'event_espresso'), |
|
| 1527 | + 'input' => 'hidden', |
|
| 1528 | + 'type' => 'int', |
|
| 1529 | + 'required' => false, |
|
| 1530 | + 'validation' => false, |
|
| 1531 | + 'value' => $message_template_group->user(), |
|
| 1532 | + 'format' => '%d', |
|
| 1533 | + 'db-col' => 'MTP_user_id' |
|
| 1534 | + ); |
|
| 1535 | 1535 | |
| 1536 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1537 | - 'name' => 'action', |
|
| 1538 | - 'input' => 'hidden', |
|
| 1539 | - 'type' => 'string', |
|
| 1540 | - 'value' => $action |
|
| 1541 | - ); |
|
| 1536 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1537 | + 'name' => 'action', |
|
| 1538 | + 'input' => 'hidden', |
|
| 1539 | + 'type' => 'string', |
|
| 1540 | + 'value' => $action |
|
| 1541 | + ); |
|
| 1542 | 1542 | |
| 1543 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1544 | - 'name' => 'id', |
|
| 1545 | - 'input' => 'hidden', |
|
| 1546 | - 'type' => 'int', |
|
| 1547 | - 'value' => $GRP_ID |
|
| 1548 | - ); |
|
| 1549 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1550 | - 'name' => $action . '_nonce', |
|
| 1551 | - 'input' => 'hidden', |
|
| 1552 | - 'type' => 'string', |
|
| 1553 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1554 | - ); |
|
| 1543 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1544 | + 'name' => 'id', |
|
| 1545 | + 'input' => 'hidden', |
|
| 1546 | + 'type' => 'int', |
|
| 1547 | + 'value' => $GRP_ID |
|
| 1548 | + ); |
|
| 1549 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1550 | + 'name' => $action . '_nonce', |
|
| 1551 | + 'input' => 'hidden', |
|
| 1552 | + 'type' => 'string', |
|
| 1553 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1554 | + ); |
|
| 1555 | 1555 | |
| 1556 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1557 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1558 | - 'name' => 'template_switch', |
|
| 1559 | - 'input' => 'hidden', |
|
| 1560 | - 'type' => 'int', |
|
| 1561 | - 'value' => 1 |
|
| 1562 | - ); |
|
| 1563 | - } |
|
| 1556 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1557 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1558 | + 'name' => 'template_switch', |
|
| 1559 | + 'input' => 'hidden', |
|
| 1560 | + 'type' => 'int', |
|
| 1561 | + 'value' => 1 |
|
| 1562 | + ); |
|
| 1563 | + } |
|
| 1564 | 1564 | |
| 1565 | 1565 | |
| 1566 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1567 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1566 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1567 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1568 | 1568 | |
| 1569 | 1569 | |
| 1570 | - } //end if ( !empty($template_field_structure) ) |
|
| 1570 | + } //end if ( !empty($template_field_structure) ) |
|
| 1571 | 1571 | |
| 1572 | - //set extra content for publish box |
|
| 1573 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1574 | - $this->_set_publish_post_box_vars( |
|
| 1575 | - 'id', |
|
| 1576 | - $GRP_ID, |
|
| 1577 | - false, |
|
| 1578 | - add_query_arg( |
|
| 1579 | - array('action' => 'global_mtps'), |
|
| 1580 | - $this->_admin_base_url |
|
| 1581 | - ) |
|
| 1582 | - ); |
|
| 1583 | - |
|
| 1584 | - //add preview button |
|
| 1585 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1586 | - array( |
|
| 1587 | - 'message_type' => $message_template_group->message_type(), |
|
| 1588 | - 'messenger' => $message_template_group->messenger(), |
|
| 1589 | - 'context' => $context, |
|
| 1590 | - 'GRP_ID' => $GRP_ID, |
|
| 1591 | - 'action' => 'preview_message' |
|
| 1592 | - ), |
|
| 1593 | - $this->_admin_base_url |
|
| 1594 | - ); |
|
| 1595 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1596 | - 'event_espresso') . '</a>'; |
|
| 1597 | - |
|
| 1598 | - |
|
| 1599 | - //setup context switcher |
|
| 1600 | - $context_switcher_args = array( |
|
| 1601 | - 'page' => 'espresso_messages', |
|
| 1602 | - 'action' => 'edit_message_template', |
|
| 1603 | - 'id' => $GRP_ID, |
|
| 1604 | - 'context' => $context, |
|
| 1605 | - 'extra' => $preview_button |
|
| 1606 | - ); |
|
| 1607 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1608 | - |
|
| 1609 | - |
|
| 1610 | - //main box |
|
| 1611 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1612 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1613 | - $this->_template_args['action'] = $action; |
|
| 1614 | - $this->_template_args['context'] = $context; |
|
| 1615 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1616 | - $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1617 | - |
|
| 1618 | - |
|
| 1619 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1620 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1621 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1622 | - |
|
| 1623 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1624 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1625 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1626 | - |
|
| 1627 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1628 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1629 | - |
|
| 1630 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1631 | - $this->_template_args, true); |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - //finally, let's set the admin_page title |
|
| 1635 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1639 | - $this->_set_shortcodes(); |
|
| 1640 | - |
|
| 1641 | - |
|
| 1642 | - //final template wrapper |
|
| 1643 | - $this->display_admin_page_with_sidebar(); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1648 | - { |
|
| 1649 | - return $mceInit; |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - public function add_context_switcher() |
|
| 1654 | - { |
|
| 1655 | - return $this->_context_switcher; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - public function _add_form_element_before() |
|
| 1659 | - { |
|
| 1660 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - public function _add_form_element_after() |
|
| 1664 | - { |
|
| 1665 | - return '</form>'; |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - /** |
|
| 1670 | - * This executes switching the template pack for a message template. |
|
| 1671 | - * |
|
| 1672 | - * @since 4.5.0 |
|
| 1673 | - * |
|
| 1674 | - */ |
|
| 1675 | - public function switch_template_pack() |
|
| 1676 | - { |
|
| 1677 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1678 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1679 | - |
|
| 1680 | - //verify we have needed values. |
|
| 1681 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1682 | - $this->_template_args['error'] = true; |
|
| 1683 | - EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1684 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1685 | - } else { |
|
| 1686 | - //get template, set the new template_pack and then reset to default |
|
| 1687 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1688 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1572 | + //set extra content for publish box |
|
| 1573 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1574 | + $this->_set_publish_post_box_vars( |
|
| 1575 | + 'id', |
|
| 1576 | + $GRP_ID, |
|
| 1577 | + false, |
|
| 1578 | + add_query_arg( |
|
| 1579 | + array('action' => 'global_mtps'), |
|
| 1580 | + $this->_admin_base_url |
|
| 1581 | + ) |
|
| 1582 | + ); |
|
| 1583 | + |
|
| 1584 | + //add preview button |
|
| 1585 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1586 | + array( |
|
| 1587 | + 'message_type' => $message_template_group->message_type(), |
|
| 1588 | + 'messenger' => $message_template_group->messenger(), |
|
| 1589 | + 'context' => $context, |
|
| 1590 | + 'GRP_ID' => $GRP_ID, |
|
| 1591 | + 'action' => 'preview_message' |
|
| 1592 | + ), |
|
| 1593 | + $this->_admin_base_url |
|
| 1594 | + ); |
|
| 1595 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1596 | + 'event_espresso') . '</a>'; |
|
| 1597 | + |
|
| 1598 | + |
|
| 1599 | + //setup context switcher |
|
| 1600 | + $context_switcher_args = array( |
|
| 1601 | + 'page' => 'espresso_messages', |
|
| 1602 | + 'action' => 'edit_message_template', |
|
| 1603 | + 'id' => $GRP_ID, |
|
| 1604 | + 'context' => $context, |
|
| 1605 | + 'extra' => $preview_button |
|
| 1606 | + ); |
|
| 1607 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1608 | + |
|
| 1609 | + |
|
| 1610 | + //main box |
|
| 1611 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1612 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1613 | + $this->_template_args['action'] = $action; |
|
| 1614 | + $this->_template_args['context'] = $context; |
|
| 1615 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1616 | + $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1617 | + |
|
| 1618 | + |
|
| 1619 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1620 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1621 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1622 | + |
|
| 1623 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1624 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1625 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1626 | + |
|
| 1627 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1628 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1629 | + |
|
| 1630 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1631 | + $this->_template_args, true); |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + //finally, let's set the admin_page title |
|
| 1635 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1639 | + $this->_set_shortcodes(); |
|
| 1640 | + |
|
| 1641 | + |
|
| 1642 | + //final template wrapper |
|
| 1643 | + $this->display_admin_page_with_sidebar(); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1648 | + { |
|
| 1649 | + return $mceInit; |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + public function add_context_switcher() |
|
| 1654 | + { |
|
| 1655 | + return $this->_context_switcher; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + public function _add_form_element_before() |
|
| 1659 | + { |
|
| 1660 | + return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + public function _add_form_element_after() |
|
| 1664 | + { |
|
| 1665 | + return '</form>'; |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * This executes switching the template pack for a message template. |
|
| 1671 | + * |
|
| 1672 | + * @since 4.5.0 |
|
| 1673 | + * |
|
| 1674 | + */ |
|
| 1675 | + public function switch_template_pack() |
|
| 1676 | + { |
|
| 1677 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1678 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1679 | + |
|
| 1680 | + //verify we have needed values. |
|
| 1681 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1682 | + $this->_template_args['error'] = true; |
|
| 1683 | + EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1684 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1685 | + } else { |
|
| 1686 | + //get template, set the new template_pack and then reset to default |
|
| 1687 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1688 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1689 | 1689 | |
| 1690 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1691 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1692 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1690 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1691 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1692 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1693 | 1693 | |
| 1694 | - $query_args = $this->_reset_to_default_template(); |
|
| 1694 | + $query_args = $this->_reset_to_default_template(); |
|
| 1695 | 1695 | |
| 1696 | - if (empty($query_args['id'])) { |
|
| 1697 | - EE_Error::add_error( |
|
| 1698 | - __( |
|
| 1699 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1700 | - 'event_espresso' |
|
| 1701 | - ), |
|
| 1702 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1703 | - ); |
|
| 1704 | - $this->_template_args['error'] = true; |
|
| 1705 | - } else { |
|
| 1706 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1707 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1708 | - EE_Error::add_success( |
|
| 1709 | - sprintf( |
|
| 1710 | - __( |
|
| 1711 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1712 | - 'event_espresso' |
|
| 1713 | - ), |
|
| 1714 | - $template_label, |
|
| 1715 | - $template_pack_labels->template_pack |
|
| 1716 | - ) |
|
| 1717 | - ); |
|
| 1718 | - //generate the redirect url for js. |
|
| 1719 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1720 | - $this->_admin_base_url); |
|
| 1721 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1722 | - $this->_template_args['success'] = true; |
|
| 1723 | - } |
|
| 1696 | + if (empty($query_args['id'])) { |
|
| 1697 | + EE_Error::add_error( |
|
| 1698 | + __( |
|
| 1699 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1700 | + 'event_espresso' |
|
| 1701 | + ), |
|
| 1702 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1703 | + ); |
|
| 1704 | + $this->_template_args['error'] = true; |
|
| 1705 | + } else { |
|
| 1706 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1707 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1708 | + EE_Error::add_success( |
|
| 1709 | + sprintf( |
|
| 1710 | + __( |
|
| 1711 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1712 | + 'event_espresso' |
|
| 1713 | + ), |
|
| 1714 | + $template_label, |
|
| 1715 | + $template_pack_labels->template_pack |
|
| 1716 | + ) |
|
| 1717 | + ); |
|
| 1718 | + //generate the redirect url for js. |
|
| 1719 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1720 | + $this->_admin_base_url); |
|
| 1721 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1722 | + $this->_template_args['success'] = true; |
|
| 1723 | + } |
|
| 1724 | 1724 | |
| 1725 | - $this->_return_json(); |
|
| 1725 | + $this->_return_json(); |
|
| 1726 | 1726 | |
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - |
|
| 1731 | - /** |
|
| 1732 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1733 | - * they want. |
|
| 1734 | - * |
|
| 1735 | - * @access protected |
|
| 1736 | - * @return array|null |
|
| 1737 | - */ |
|
| 1738 | - protected function _reset_to_default_template() |
|
| 1739 | - { |
|
| 1740 | - |
|
| 1741 | - $templates = array(); |
|
| 1742 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1743 | - //we need to make sure we've got the info we need. |
|
| 1744 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1745 | - EE_Error::add_error( |
|
| 1746 | - __( |
|
| 1747 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1748 | - 'event_espresso' |
|
| 1749 | - ), |
|
| 1750 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1751 | - ); |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - // all templates will be reset to whatever the defaults are |
|
| 1755 | - // for the global template matching the messenger and message type. |
|
| 1756 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 1757 | - |
|
| 1758 | - if ($success) { |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + |
|
| 1731 | + /** |
|
| 1732 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1733 | + * they want. |
|
| 1734 | + * |
|
| 1735 | + * @access protected |
|
| 1736 | + * @return array|null |
|
| 1737 | + */ |
|
| 1738 | + protected function _reset_to_default_template() |
|
| 1739 | + { |
|
| 1740 | + |
|
| 1741 | + $templates = array(); |
|
| 1742 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1743 | + //we need to make sure we've got the info we need. |
|
| 1744 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1745 | + EE_Error::add_error( |
|
| 1746 | + __( |
|
| 1747 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1748 | + 'event_espresso' |
|
| 1749 | + ), |
|
| 1750 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1751 | + ); |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + // all templates will be reset to whatever the defaults are |
|
| 1755 | + // for the global template matching the messenger and message type. |
|
| 1756 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 1757 | + |
|
| 1758 | + if ($success) { |
|
| 1759 | 1759 | |
| 1760 | - //let's first determine if the incoming template is a global template, |
|
| 1761 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1762 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1760 | + //let's first determine if the incoming template is a global template, |
|
| 1761 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1762 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1763 | 1763 | |
| 1764 | 1764 | |
| 1765 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1766 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1765 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1766 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1767 | 1767 | |
| 1768 | - if ($success) { |
|
| 1769 | - // if successfully deleted, lets generate the new ones. |
|
| 1770 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1771 | - // will use the related global template defaults for regeneration. |
|
| 1772 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1773 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 1774 | - // for the current custom template when resetting. |
|
| 1775 | - $templates = $this->_generate_new_templates( |
|
| 1776 | - $this->_req_data['msgr'], |
|
| 1777 | - $this->_req_data['mt'], |
|
| 1778 | - $GRP_ID, |
|
| 1779 | - true |
|
| 1780 | - ); |
|
| 1781 | - } |
|
| 1768 | + if ($success) { |
|
| 1769 | + // if successfully deleted, lets generate the new ones. |
|
| 1770 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1771 | + // will use the related global template defaults for regeneration. |
|
| 1772 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1773 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 1774 | + // for the current custom template when resetting. |
|
| 1775 | + $templates = $this->_generate_new_templates( |
|
| 1776 | + $this->_req_data['msgr'], |
|
| 1777 | + $this->_req_data['mt'], |
|
| 1778 | + $GRP_ID, |
|
| 1779 | + true |
|
| 1780 | + ); |
|
| 1781 | + } |
|
| 1782 | 1782 | |
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - //any error messages? |
|
| 1786 | - if ( ! $success) { |
|
| 1787 | - EE_Error::add_error( |
|
| 1788 | - __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1789 | - 'event_espresso'), |
|
| 1790 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1791 | - ); |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - //all good, let's add a success message! |
|
| 1795 | - if ($success && ! empty($templates)) { |
|
| 1796 | - $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1797 | - EE_Error::overwrite_success(); |
|
| 1798 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1799 | - } |
|
| 1800 | - |
|
| 1801 | - |
|
| 1802 | - $query_args = array( |
|
| 1803 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1804 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1805 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1806 | - ); |
|
| 1807 | - |
|
| 1808 | - //if called via ajax then we return query args otherwise redirect |
|
| 1809 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1810 | - return $query_args; |
|
| 1811 | - } else { |
|
| 1812 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + //any error messages? |
|
| 1786 | + if ( ! $success) { |
|
| 1787 | + EE_Error::add_error( |
|
| 1788 | + __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1789 | + 'event_espresso'), |
|
| 1790 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1791 | + ); |
|
| 1792 | + } |
|
| 1793 | + |
|
| 1794 | + //all good, let's add a success message! |
|
| 1795 | + if ($success && ! empty($templates)) { |
|
| 1796 | + $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1797 | + EE_Error::overwrite_success(); |
|
| 1798 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1799 | + } |
|
| 1800 | + |
|
| 1801 | + |
|
| 1802 | + $query_args = array( |
|
| 1803 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1804 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1805 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1806 | + ); |
|
| 1807 | + |
|
| 1808 | + //if called via ajax then we return query args otherwise redirect |
|
| 1809 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1810 | + return $query_args; |
|
| 1811 | + } else { |
|
| 1812 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1813 | 1813 | |
| 1814 | - return null; |
|
| 1815 | - } |
|
| 1816 | - } |
|
| 1814 | + return null; |
|
| 1815 | + } |
|
| 1816 | + } |
|
| 1817 | 1817 | |
| 1818 | 1818 | |
| 1819 | - /** |
|
| 1820 | - * Retrieve and set the message preview for display. |
|
| 1821 | - * |
|
| 1822 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1823 | - * @return string |
|
| 1824 | - * @throws EE_Error |
|
| 1825 | - */ |
|
| 1826 | - public function _preview_message($send = false) |
|
| 1827 | - { |
|
| 1828 | - //first make sure we've got the necessary parameters |
|
| 1829 | - if ( |
|
| 1830 | - ! isset( |
|
| 1831 | - $this->_req_data['message_type'], |
|
| 1832 | - $this->_req_data['messenger'], |
|
| 1833 | - $this->_req_data['messenger'], |
|
| 1834 | - $this->_req_data['GRP_ID'] |
|
| 1835 | - ) |
|
| 1836 | - ) { |
|
| 1837 | - EE_Error::add_error( |
|
| 1838 | - __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1839 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1840 | - ); |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1844 | - |
|
| 1845 | - |
|
| 1846 | - //get the preview! |
|
| 1847 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1848 | - $this->_req_data['messenger'], $send); |
|
| 1849 | - |
|
| 1850 | - if ($send) { |
|
| 1851 | - return $preview; |
|
| 1852 | - } |
|
| 1853 | - |
|
| 1854 | - //let's add a button to go back to the edit view |
|
| 1855 | - $query_args = array( |
|
| 1856 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 1857 | - 'context' => $this->_req_data['context'], |
|
| 1858 | - 'action' => 'edit_message_template' |
|
| 1859 | - ); |
|
| 1860 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1861 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1862 | - 'event_espresso') . '</a>'; |
|
| 1863 | - $message_types = $this->get_installed_message_types(); |
|
| 1864 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1865 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1866 | - ? ucwords($active_messenger->label['singular']) |
|
| 1867 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1868 | - //let's provide a helpful title for context |
|
| 1869 | - $preview_title = sprintf( |
|
| 1870 | - __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1871 | - $active_messenger_label, |
|
| 1872 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1873 | - ); |
|
| 1874 | - //setup display of preview. |
|
| 1875 | - $this->_admin_page_title = $preview_title; |
|
| 1876 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1877 | - $this->_template_args['data']['force_json'] = true; |
|
| 1878 | - |
|
| 1879 | - return ''; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1885 | - * gets called automatically. |
|
| 1886 | - * |
|
| 1887 | - * @since 4.5.0 |
|
| 1888 | - * |
|
| 1889 | - * @return string |
|
| 1890 | - */ |
|
| 1891 | - protected function _display_preview_message() |
|
| 1892 | - { |
|
| 1893 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1894 | - } |
|
| 1895 | - |
|
| 1896 | - |
|
| 1897 | - /** |
|
| 1898 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1899 | - * |
|
| 1900 | - * @access protected |
|
| 1901 | - * @return void |
|
| 1902 | - */ |
|
| 1903 | - protected function _register_edit_meta_boxes() |
|
| 1904 | - { |
|
| 1905 | - add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1906 | - array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1907 | - add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1908 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1909 | - add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1910 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1911 | - } |
|
| 1912 | - |
|
| 1913 | - |
|
| 1914 | - /** |
|
| 1915 | - * metabox content for all template pack and variation selection. |
|
| 1916 | - * |
|
| 1917 | - * @since 4.5.0 |
|
| 1918 | - * |
|
| 1919 | - * @return string |
|
| 1920 | - */ |
|
| 1921 | - public function template_pack_meta_box() |
|
| 1922 | - { |
|
| 1923 | - $this->_set_message_template_group(); |
|
| 1924 | - |
|
| 1925 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1926 | - |
|
| 1927 | - $tp_select_values = array(); |
|
| 1928 | - |
|
| 1929 | - foreach ($tp_collection as $tp) { |
|
| 1930 | - //only include template packs that support this messenger and message type! |
|
| 1931 | - $supports = $tp->get_supports(); |
|
| 1932 | - if ( |
|
| 1933 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1934 | - || ! in_array( |
|
| 1935 | - $this->_message_template_group->message_type(), |
|
| 1936 | - $supports[$this->_message_template_group->messenger()] |
|
| 1937 | - ) |
|
| 1938 | - ) { |
|
| 1939 | - //not supported |
|
| 1940 | - continue; |
|
| 1941 | - } |
|
| 1819 | + /** |
|
| 1820 | + * Retrieve and set the message preview for display. |
|
| 1821 | + * |
|
| 1822 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1823 | + * @return string |
|
| 1824 | + * @throws EE_Error |
|
| 1825 | + */ |
|
| 1826 | + public function _preview_message($send = false) |
|
| 1827 | + { |
|
| 1828 | + //first make sure we've got the necessary parameters |
|
| 1829 | + if ( |
|
| 1830 | + ! isset( |
|
| 1831 | + $this->_req_data['message_type'], |
|
| 1832 | + $this->_req_data['messenger'], |
|
| 1833 | + $this->_req_data['messenger'], |
|
| 1834 | + $this->_req_data['GRP_ID'] |
|
| 1835 | + ) |
|
| 1836 | + ) { |
|
| 1837 | + EE_Error::add_error( |
|
| 1838 | + __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1839 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1840 | + ); |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1844 | + |
|
| 1845 | + |
|
| 1846 | + //get the preview! |
|
| 1847 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1848 | + $this->_req_data['messenger'], $send); |
|
| 1849 | + |
|
| 1850 | + if ($send) { |
|
| 1851 | + return $preview; |
|
| 1852 | + } |
|
| 1853 | + |
|
| 1854 | + //let's add a button to go back to the edit view |
|
| 1855 | + $query_args = array( |
|
| 1856 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 1857 | + 'context' => $this->_req_data['context'], |
|
| 1858 | + 'action' => 'edit_message_template' |
|
| 1859 | + ); |
|
| 1860 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1861 | + $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1862 | + 'event_espresso') . '</a>'; |
|
| 1863 | + $message_types = $this->get_installed_message_types(); |
|
| 1864 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1865 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1866 | + ? ucwords($active_messenger->label['singular']) |
|
| 1867 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1868 | + //let's provide a helpful title for context |
|
| 1869 | + $preview_title = sprintf( |
|
| 1870 | + __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1871 | + $active_messenger_label, |
|
| 1872 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1873 | + ); |
|
| 1874 | + //setup display of preview. |
|
| 1875 | + $this->_admin_page_title = $preview_title; |
|
| 1876 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1877 | + $this->_template_args['data']['force_json'] = true; |
|
| 1878 | + |
|
| 1879 | + return ''; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1885 | + * gets called automatically. |
|
| 1886 | + * |
|
| 1887 | + * @since 4.5.0 |
|
| 1888 | + * |
|
| 1889 | + * @return string |
|
| 1890 | + */ |
|
| 1891 | + protected function _display_preview_message() |
|
| 1892 | + { |
|
| 1893 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + |
|
| 1897 | + /** |
|
| 1898 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1899 | + * |
|
| 1900 | + * @access protected |
|
| 1901 | + * @return void |
|
| 1902 | + */ |
|
| 1903 | + protected function _register_edit_meta_boxes() |
|
| 1904 | + { |
|
| 1905 | + add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1906 | + array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1907 | + add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1908 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1909 | + add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1910 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1911 | + } |
|
| 1912 | + |
|
| 1913 | + |
|
| 1914 | + /** |
|
| 1915 | + * metabox content for all template pack and variation selection. |
|
| 1916 | + * |
|
| 1917 | + * @since 4.5.0 |
|
| 1918 | + * |
|
| 1919 | + * @return string |
|
| 1920 | + */ |
|
| 1921 | + public function template_pack_meta_box() |
|
| 1922 | + { |
|
| 1923 | + $this->_set_message_template_group(); |
|
| 1924 | + |
|
| 1925 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1926 | + |
|
| 1927 | + $tp_select_values = array(); |
|
| 1928 | + |
|
| 1929 | + foreach ($tp_collection as $tp) { |
|
| 1930 | + //only include template packs that support this messenger and message type! |
|
| 1931 | + $supports = $tp->get_supports(); |
|
| 1932 | + if ( |
|
| 1933 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1934 | + || ! in_array( |
|
| 1935 | + $this->_message_template_group->message_type(), |
|
| 1936 | + $supports[$this->_message_template_group->messenger()] |
|
| 1937 | + ) |
|
| 1938 | + ) { |
|
| 1939 | + //not supported |
|
| 1940 | + continue; |
|
| 1941 | + } |
|
| 1942 | 1942 | |
| 1943 | - $tp_select_values[] = array( |
|
| 1944 | - 'text' => $tp->label, |
|
| 1945 | - 'id' => $tp->dbref |
|
| 1946 | - ); |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1950 | - if (empty($tp_select_values)) { |
|
| 1951 | - $tp_select_values[] = array( |
|
| 1952 | - 'text' => __('Default', 'event_espresso'), |
|
| 1953 | - 'id' => 'default' |
|
| 1954 | - ); |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - //setup variation select values for the currently selected template. |
|
| 1958 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1959 | - $this->_message_template_group->messenger(), |
|
| 1960 | - $this->_message_template_group->message_type() |
|
| 1961 | - ); |
|
| 1962 | - $variations_select_values = array(); |
|
| 1963 | - foreach ($variations as $variation => $label) { |
|
| 1964 | - $variations_select_values[] = array( |
|
| 1965 | - 'text' => $label, |
|
| 1966 | - 'id' => $variation |
|
| 1967 | - ); |
|
| 1968 | - } |
|
| 1969 | - |
|
| 1970 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1971 | - |
|
| 1972 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1973 | - 'MTP_template_pack', |
|
| 1974 | - $tp_select_values, |
|
| 1975 | - $this->_message_template_group->get_template_pack_name() |
|
| 1976 | - ); |
|
| 1977 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1978 | - 'MTP_template_variation', |
|
| 1979 | - $variations_select_values, |
|
| 1980 | - $this->_message_template_group->get_template_pack_variation() |
|
| 1981 | - ); |
|
| 1982 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1983 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1984 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1985 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1986 | - |
|
| 1987 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1988 | - |
|
| 1989 | - EEH_Template::display_template($template, $template_args); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * This meta box holds any extra actions related to Message Templates |
|
| 1995 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1996 | - * |
|
| 1997 | - * @access public |
|
| 1998 | - * @return void |
|
| 1999 | - * @throws \EE_Error |
|
| 2000 | - */ |
|
| 2001 | - public function extra_actions_meta_box() |
|
| 2002 | - { |
|
| 2003 | - $template_form_fields = array(); |
|
| 2004 | - |
|
| 2005 | - $extra_args = array( |
|
| 2006 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2007 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2008 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2009 | - ); |
|
| 2010 | - //first we need to see if there are any fields |
|
| 2011 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2012 | - |
|
| 2013 | - if ( ! empty($fields)) { |
|
| 2014 | - //yup there be fields |
|
| 2015 | - foreach ($fields as $field => $config) { |
|
| 2016 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2017 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2018 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2019 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 1943 | + $tp_select_values[] = array( |
|
| 1944 | + 'text' => $tp->label, |
|
| 1945 | + 'id' => $tp->dbref |
|
| 1946 | + ); |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1950 | + if (empty($tp_select_values)) { |
|
| 1951 | + $tp_select_values[] = array( |
|
| 1952 | + 'text' => __('Default', 'event_espresso'), |
|
| 1953 | + 'id' => 'default' |
|
| 1954 | + ); |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + //setup variation select values for the currently selected template. |
|
| 1958 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1959 | + $this->_message_template_group->messenger(), |
|
| 1960 | + $this->_message_template_group->message_type() |
|
| 1961 | + ); |
|
| 1962 | + $variations_select_values = array(); |
|
| 1963 | + foreach ($variations as $variation => $label) { |
|
| 1964 | + $variations_select_values[] = array( |
|
| 1965 | + 'text' => $label, |
|
| 1966 | + 'id' => $variation |
|
| 1967 | + ); |
|
| 1968 | + } |
|
| 1969 | + |
|
| 1970 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1971 | + |
|
| 1972 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1973 | + 'MTP_template_pack', |
|
| 1974 | + $tp_select_values, |
|
| 1975 | + $this->_message_template_group->get_template_pack_name() |
|
| 1976 | + ); |
|
| 1977 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1978 | + 'MTP_template_variation', |
|
| 1979 | + $variations_select_values, |
|
| 1980 | + $this->_message_template_group->get_template_pack_variation() |
|
| 1981 | + ); |
|
| 1982 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1983 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1984 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1985 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1986 | + |
|
| 1987 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1988 | + |
|
| 1989 | + EEH_Template::display_template($template, $template_args); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * This meta box holds any extra actions related to Message Templates |
|
| 1995 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1996 | + * |
|
| 1997 | + * @access public |
|
| 1998 | + * @return void |
|
| 1999 | + * @throws \EE_Error |
|
| 2000 | + */ |
|
| 2001 | + public function extra_actions_meta_box() |
|
| 2002 | + { |
|
| 2003 | + $template_form_fields = array(); |
|
| 2004 | + |
|
| 2005 | + $extra_args = array( |
|
| 2006 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2007 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2008 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2009 | + ); |
|
| 2010 | + //first we need to see if there are any fields |
|
| 2011 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2012 | + |
|
| 2013 | + if ( ! empty($fields)) { |
|
| 2014 | + //yup there be fields |
|
| 2015 | + foreach ($fields as $field => $config) { |
|
| 2016 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2017 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2018 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2019 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2020 | 2020 | |
| 2021 | - // if type is hidden and the value is empty |
|
| 2022 | - // something may have gone wrong so let's correct with the defaults |
|
| 2023 | - $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2024 | - ? $default |
|
| 2025 | - : ''; |
|
| 2026 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2027 | - ? $existing[$field] |
|
| 2028 | - : $fix; |
|
| 2021 | + // if type is hidden and the value is empty |
|
| 2022 | + // something may have gone wrong so let's correct with the defaults |
|
| 2023 | + $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2024 | + ? $default |
|
| 2025 | + : ''; |
|
| 2026 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2027 | + ? $existing[$field] |
|
| 2028 | + : $fix; |
|
| 2029 | 2029 | |
| 2030 | - $template_form_fields[$field_id] = array( |
|
| 2031 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2032 | - 'label' => $config['label'], |
|
| 2033 | - 'input' => $config['input'], |
|
| 2034 | - 'type' => $config['type'], |
|
| 2035 | - 'required' => $config['required'], |
|
| 2036 | - 'validation' => $config['validation'], |
|
| 2037 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2038 | - 'css_class' => $config['css_class'], |
|
| 2039 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2040 | - 'default' => $default, |
|
| 2041 | - 'format' => $config['format'] |
|
| 2042 | - ); |
|
| 2043 | - } |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2047 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2048 | - : ''; |
|
| 2049 | - |
|
| 2050 | - $test_settings_html = ''; |
|
| 2051 | - //print out $test_settings_fields |
|
| 2052 | - if ( ! empty($test_settings_fields)) { |
|
| 2053 | - echo $test_settings_fields; |
|
| 2054 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2055 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2056 | - $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2057 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2058 | - } |
|
| 2059 | - |
|
| 2060 | - //and button |
|
| 2061 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2062 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2063 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2064 | - 'reset_to_default', |
|
| 2065 | - 'reset', |
|
| 2066 | - $extra_args, |
|
| 2067 | - 'button-primary reset-default-button' |
|
| 2068 | - ); |
|
| 2069 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2070 | - echo $test_settings_html; |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2076 | - * |
|
| 2077 | - * @since 4.9.rc.000 |
|
| 2078 | - * |
|
| 2079 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2080 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2081 | - * |
|
| 2082 | - * @return string |
|
| 2083 | - */ |
|
| 2084 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2085 | - { |
|
| 2086 | - $template_args = array( |
|
| 2087 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2088 | - 'fieldname' => $field, |
|
| 2089 | - 'linked_input_id' => $linked_input_id |
|
| 2090 | - ); |
|
| 2091 | - |
|
| 2092 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2093 | - $template_args, true); |
|
| 2094 | - } |
|
| 2095 | - |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2099 | - * page) |
|
| 2100 | - * |
|
| 2101 | - * @access public |
|
| 2102 | - * @return void |
|
| 2103 | - */ |
|
| 2104 | - public function shortcode_meta_box() |
|
| 2105 | - { |
|
| 2106 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2107 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2108 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2109 | - if (empty($shortcodes)) { |
|
| 2110 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2111 | - echo $content; |
|
| 2112 | - } else { |
|
| 2113 | - //$alt = 0; |
|
| 2114 | - ?> |
|
| 2030 | + $template_form_fields[$field_id] = array( |
|
| 2031 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2032 | + 'label' => $config['label'], |
|
| 2033 | + 'input' => $config['input'], |
|
| 2034 | + 'type' => $config['type'], |
|
| 2035 | + 'required' => $config['required'], |
|
| 2036 | + 'validation' => $config['validation'], |
|
| 2037 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2038 | + 'css_class' => $config['css_class'], |
|
| 2039 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2040 | + 'default' => $default, |
|
| 2041 | + 'format' => $config['format'] |
|
| 2042 | + ); |
|
| 2043 | + } |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2047 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2048 | + : ''; |
|
| 2049 | + |
|
| 2050 | + $test_settings_html = ''; |
|
| 2051 | + //print out $test_settings_fields |
|
| 2052 | + if ( ! empty($test_settings_fields)) { |
|
| 2053 | + echo $test_settings_fields; |
|
| 2054 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2055 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2056 | + $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2057 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2058 | + } |
|
| 2059 | + |
|
| 2060 | + //and button |
|
| 2061 | + $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2062 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2063 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2064 | + 'reset_to_default', |
|
| 2065 | + 'reset', |
|
| 2066 | + $extra_args, |
|
| 2067 | + 'button-primary reset-default-button' |
|
| 2068 | + ); |
|
| 2069 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2070 | + echo $test_settings_html; |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2076 | + * |
|
| 2077 | + * @since 4.9.rc.000 |
|
| 2078 | + * |
|
| 2079 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2080 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2081 | + * |
|
| 2082 | + * @return string |
|
| 2083 | + */ |
|
| 2084 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2085 | + { |
|
| 2086 | + $template_args = array( |
|
| 2087 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2088 | + 'fieldname' => $field, |
|
| 2089 | + 'linked_input_id' => $linked_input_id |
|
| 2090 | + ); |
|
| 2091 | + |
|
| 2092 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2093 | + $template_args, true); |
|
| 2094 | + } |
|
| 2095 | + |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2099 | + * page) |
|
| 2100 | + * |
|
| 2101 | + * @access public |
|
| 2102 | + * @return void |
|
| 2103 | + */ |
|
| 2104 | + public function shortcode_meta_box() |
|
| 2105 | + { |
|
| 2106 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2107 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2108 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2109 | + if (empty($shortcodes)) { |
|
| 2110 | + $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2111 | + echo $content; |
|
| 2112 | + } else { |
|
| 2113 | + //$alt = 0; |
|
| 2114 | + ?> |
|
| 2115 | 2115 | <div |
| 2116 | 2116 | style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2117 | 2117 | <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
| 2118 | - 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2118 | + 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2119 | 2119 | <?php |
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - |
|
| 2123 | - } |
|
| 2124 | - |
|
| 2125 | - |
|
| 2126 | - /** |
|
| 2127 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2128 | - * |
|
| 2129 | - * @access protected |
|
| 2130 | - * @return void |
|
| 2131 | - */ |
|
| 2132 | - protected function _set_shortcodes() |
|
| 2133 | - { |
|
| 2134 | - |
|
| 2135 | - //no need to run this if the property is already set |
|
| 2136 | - if ( ! empty($this->_shortcodes)) { |
|
| 2137 | - return; |
|
| 2138 | - } |
|
| 2139 | - |
|
| 2140 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - |
|
| 2144 | - /** |
|
| 2145 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2146 | - * property) |
|
| 2147 | - * |
|
| 2148 | - * @access protected |
|
| 2149 | - * |
|
| 2150 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2151 | - * for. Defaults to all (for the given context) |
|
| 2152 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2153 | - * |
|
| 2154 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2155 | - * true just an array of shortcode/label pairs. |
|
| 2156 | - */ |
|
| 2157 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2158 | - { |
|
| 2159 | - $this->_set_message_template_group(); |
|
| 2160 | - |
|
| 2161 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2162 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2163 | - $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2164 | - |
|
| 2165 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2171 | - * |
|
| 2172 | - * @access protected |
|
| 2173 | - * @return void |
|
| 2174 | - */ |
|
| 2175 | - protected function _set_message_template_group() |
|
| 2176 | - { |
|
| 2177 | - |
|
| 2178 | - if ( ! empty($this->_message_template_group)) { |
|
| 2179 | - return; |
|
| 2180 | - } //get out if this is already set. |
|
| 2181 | - |
|
| 2182 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2183 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2184 | - |
|
| 2185 | - //let's get the message templates |
|
| 2186 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2187 | - |
|
| 2188 | - if (empty($GRP_ID)) { |
|
| 2189 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2190 | - } else { |
|
| 2191 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2195 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2196 | - |
|
| 2197 | - } |
|
| 2198 | - |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * sets up a context switcher for edit forms |
|
| 2202 | - * |
|
| 2203 | - * @access protected |
|
| 2204 | - * |
|
| 2205 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2206 | - * @param array $args various things the context switcher needs. |
|
| 2207 | - * |
|
| 2208 | - */ |
|
| 2209 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2210 | - { |
|
| 2211 | - $context_details = $template_group_object->contexts_config(); |
|
| 2212 | - $context_label = $template_group_object->context_label(); |
|
| 2213 | - ob_start(); |
|
| 2214 | - ?> |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + |
|
| 2123 | + } |
|
| 2124 | + |
|
| 2125 | + |
|
| 2126 | + /** |
|
| 2127 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2128 | + * |
|
| 2129 | + * @access protected |
|
| 2130 | + * @return void |
|
| 2131 | + */ |
|
| 2132 | + protected function _set_shortcodes() |
|
| 2133 | + { |
|
| 2134 | + |
|
| 2135 | + //no need to run this if the property is already set |
|
| 2136 | + if ( ! empty($this->_shortcodes)) { |
|
| 2137 | + return; |
|
| 2138 | + } |
|
| 2139 | + |
|
| 2140 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + |
|
| 2144 | + /** |
|
| 2145 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2146 | + * property) |
|
| 2147 | + * |
|
| 2148 | + * @access protected |
|
| 2149 | + * |
|
| 2150 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2151 | + * for. Defaults to all (for the given context) |
|
| 2152 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2153 | + * |
|
| 2154 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2155 | + * true just an array of shortcode/label pairs. |
|
| 2156 | + */ |
|
| 2157 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2158 | + { |
|
| 2159 | + $this->_set_message_template_group(); |
|
| 2160 | + |
|
| 2161 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2162 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2163 | + $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2164 | + |
|
| 2165 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2171 | + * |
|
| 2172 | + * @access protected |
|
| 2173 | + * @return void |
|
| 2174 | + */ |
|
| 2175 | + protected function _set_message_template_group() |
|
| 2176 | + { |
|
| 2177 | + |
|
| 2178 | + if ( ! empty($this->_message_template_group)) { |
|
| 2179 | + return; |
|
| 2180 | + } //get out if this is already set. |
|
| 2181 | + |
|
| 2182 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2183 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2184 | + |
|
| 2185 | + //let's get the message templates |
|
| 2186 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2187 | + |
|
| 2188 | + if (empty($GRP_ID)) { |
|
| 2189 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2190 | + } else { |
|
| 2191 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2195 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2196 | + |
|
| 2197 | + } |
|
| 2198 | + |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * sets up a context switcher for edit forms |
|
| 2202 | + * |
|
| 2203 | + * @access protected |
|
| 2204 | + * |
|
| 2205 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2206 | + * @param array $args various things the context switcher needs. |
|
| 2207 | + * |
|
| 2208 | + */ |
|
| 2209 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2210 | + { |
|
| 2211 | + $context_details = $template_group_object->contexts_config(); |
|
| 2212 | + $context_label = $template_group_object->context_label(); |
|
| 2213 | + ob_start(); |
|
| 2214 | + ?> |
|
| 2215 | 2215 | <div class="ee-msg-switcher-container"> |
| 2216 | 2216 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2217 | 2217 | <?php |
| 2218 | - foreach ($args as $name => $value) { |
|
| 2219 | - if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2220 | - continue; |
|
| 2221 | - } |
|
| 2222 | - ?> |
|
| 2218 | + foreach ($args as $name => $value) { |
|
| 2219 | + if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2220 | + continue; |
|
| 2221 | + } |
|
| 2222 | + ?> |
|
| 2223 | 2223 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2224 | 2224 | <?php |
| 2225 | - } |
|
| 2226 | - //setup nonce_url |
|
| 2227 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2228 | - ?> |
|
| 2225 | + } |
|
| 2226 | + //setup nonce_url |
|
| 2227 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2228 | + ?> |
|
| 2229 | 2229 | <select name="context"> |
| 2230 | 2230 | <?php |
| 2231 | - $context_templates = $template_group_object->context_templates(); |
|
| 2232 | - if (is_array($context_templates)) : |
|
| 2233 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2234 | - $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2235 | - ?> |
|
| 2231 | + $context_templates = $template_group_object->context_templates(); |
|
| 2232 | + if (is_array($context_templates)) : |
|
| 2233 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2234 | + $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2235 | + ?> |
|
| 2236 | 2236 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2237 | 2237 | <?php echo $context_details[$context]['label']; ?> |
| 2238 | 2238 | </option> |
@@ -2245,1608 +2245,1608 @@ discard block |
||
| 2245 | 2245 | <?php echo $args['extra']; ?> |
| 2246 | 2246 | </div> <!-- end .ee-msg-switcher-container --> |
| 2247 | 2247 | <?php |
| 2248 | - $output = ob_get_contents(); |
|
| 2249 | - ob_clean(); |
|
| 2250 | - $this->_context_switcher = $output; |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * utility for sanitizing new values coming in. |
|
| 2256 | - * Note: this is only used when updating a context. |
|
| 2257 | - * |
|
| 2258 | - * @access protected |
|
| 2259 | - * |
|
| 2260 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2261 | - * |
|
| 2262 | - * @return array |
|
| 2263 | - */ |
|
| 2264 | - protected function _set_message_template_column_values($index) |
|
| 2265 | - { |
|
| 2266 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2267 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2268 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2269 | - } |
|
| 2270 | - } /*else { |
|
| 2248 | + $output = ob_get_contents(); |
|
| 2249 | + ob_clean(); |
|
| 2250 | + $this->_context_switcher = $output; |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * utility for sanitizing new values coming in. |
|
| 2256 | + * Note: this is only used when updating a context. |
|
| 2257 | + * |
|
| 2258 | + * @access protected |
|
| 2259 | + * |
|
| 2260 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2261 | + * |
|
| 2262 | + * @return array |
|
| 2263 | + */ |
|
| 2264 | + protected function _set_message_template_column_values($index) |
|
| 2265 | + { |
|
| 2266 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2267 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2268 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2269 | + } |
|
| 2270 | + } /*else { |
|
| 2271 | 2271 | $this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content']; |
| 2272 | 2272 | }*/ |
| 2273 | 2273 | |
| 2274 | 2274 | |
| 2275 | - $set_column_values = array( |
|
| 2276 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2277 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2278 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2279 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2280 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2281 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2282 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2283 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2284 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2285 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2286 | - : 0, |
|
| 2287 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2288 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2289 | - : 0, |
|
| 2290 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2291 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2292 | - ); |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - return $set_column_values; |
|
| 2296 | - } |
|
| 2297 | - |
|
| 2298 | - |
|
| 2299 | - protected function _insert_or_update_message_template($new = false) |
|
| 2300 | - { |
|
| 2301 | - |
|
| 2302 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2303 | - $success = 0; |
|
| 2304 | - $override = false; |
|
| 2305 | - |
|
| 2306 | - //setup notices description |
|
| 2307 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2308 | - |
|
| 2309 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2310 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2311 | - $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2312 | - |
|
| 2313 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2314 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2315 | - |
|
| 2316 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2317 | - ? ucwords($message_type_object->label['singular']) |
|
| 2318 | - : ''; |
|
| 2319 | - |
|
| 2320 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2321 | - ? $this->_req_data['MTP_context'] |
|
| 2322 | - : ''; |
|
| 2323 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2324 | - |
|
| 2325 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2326 | - $item_desc .= 'Message Template'; |
|
| 2327 | - $query_args = array(); |
|
| 2328 | - $edit_array = array(); |
|
| 2329 | - $action_desc = ''; |
|
| 2330 | - |
|
| 2331 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2332 | - if ($new) { |
|
| 2333 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2334 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2335 | - if (empty($edit_array)) { |
|
| 2336 | - $success = 0; |
|
| 2337 | - } else { |
|
| 2338 | - $success = 1; |
|
| 2339 | - $edit_array = $edit_array[0]; |
|
| 2340 | - $query_args = array( |
|
| 2341 | - 'id' => $edit_array['GRP_ID'], |
|
| 2342 | - 'context' => $edit_array['MTP_context'], |
|
| 2343 | - 'action' => 'edit_message_template' |
|
| 2344 | - ); |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - $action_desc = 'created'; |
|
| 2348 | - } else { |
|
| 2349 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2350 | - $MTP = EEM_Message_Template::instance(); |
|
| 2275 | + $set_column_values = array( |
|
| 2276 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2277 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2278 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2279 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2280 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2281 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2282 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2283 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2284 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2285 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2286 | + : 0, |
|
| 2287 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2288 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2289 | + : 0, |
|
| 2290 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2291 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2292 | + ); |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + return $set_column_values; |
|
| 2296 | + } |
|
| 2297 | + |
|
| 2298 | + |
|
| 2299 | + protected function _insert_or_update_message_template($new = false) |
|
| 2300 | + { |
|
| 2301 | + |
|
| 2302 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2303 | + $success = 0; |
|
| 2304 | + $override = false; |
|
| 2305 | + |
|
| 2306 | + //setup notices description |
|
| 2307 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2308 | + |
|
| 2309 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2310 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2311 | + $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2312 | + |
|
| 2313 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2314 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2315 | + |
|
| 2316 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2317 | + ? ucwords($message_type_object->label['singular']) |
|
| 2318 | + : ''; |
|
| 2319 | + |
|
| 2320 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2321 | + ? $this->_req_data['MTP_context'] |
|
| 2322 | + : ''; |
|
| 2323 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2324 | + |
|
| 2325 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2326 | + $item_desc .= 'Message Template'; |
|
| 2327 | + $query_args = array(); |
|
| 2328 | + $edit_array = array(); |
|
| 2329 | + $action_desc = ''; |
|
| 2330 | + |
|
| 2331 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2332 | + if ($new) { |
|
| 2333 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2334 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2335 | + if (empty($edit_array)) { |
|
| 2336 | + $success = 0; |
|
| 2337 | + } else { |
|
| 2338 | + $success = 1; |
|
| 2339 | + $edit_array = $edit_array[0]; |
|
| 2340 | + $query_args = array( |
|
| 2341 | + 'id' => $edit_array['GRP_ID'], |
|
| 2342 | + 'context' => $edit_array['MTP_context'], |
|
| 2343 | + 'action' => 'edit_message_template' |
|
| 2344 | + ); |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + $action_desc = 'created'; |
|
| 2348 | + } else { |
|
| 2349 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2350 | + $MTP = EEM_Message_Template::instance(); |
|
| 2351 | 2351 | |
| 2352 | 2352 | |
| 2353 | - //run update for each template field in displayed context |
|
| 2354 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2355 | - EE_Error::add_error( |
|
| 2356 | - __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2357 | - 'event_espresso'), |
|
| 2358 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2359 | - ); |
|
| 2360 | - $success = 0; |
|
| 2353 | + //run update for each template field in displayed context |
|
| 2354 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2355 | + EE_Error::add_error( |
|
| 2356 | + __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2357 | + 'event_espresso'), |
|
| 2358 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2359 | + ); |
|
| 2360 | + $success = 0; |
|
| 2361 | 2361 | |
| 2362 | - } else { |
|
| 2363 | - //first validate all fields! |
|
| 2364 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2365 | - $message_type_slug); |
|
| 2362 | + } else { |
|
| 2363 | + //first validate all fields! |
|
| 2364 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2365 | + $message_type_slug); |
|
| 2366 | 2366 | |
| 2367 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2368 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2369 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2370 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2367 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2368 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2369 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2370 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2371 | 2371 | |
| 2372 | - $success = 0; |
|
| 2372 | + $success = 0; |
|
| 2373 | 2373 | |
| 2374 | - //setup notices |
|
| 2375 | - foreach ($validates as $field => $error) { |
|
| 2376 | - if (isset($error['msg'])) { |
|
| 2377 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2378 | - } |
|
| 2379 | - } |
|
| 2374 | + //setup notices |
|
| 2375 | + foreach ($validates as $field => $error) { |
|
| 2376 | + if (isset($error['msg'])) { |
|
| 2377 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2378 | + } |
|
| 2379 | + } |
|
| 2380 | 2380 | |
| 2381 | - } else { |
|
| 2382 | - $set_column_values = array(); |
|
| 2383 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2384 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2381 | + } else { |
|
| 2382 | + $set_column_values = array(); |
|
| 2383 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2384 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2385 | 2385 | |
| 2386 | - $where_cols_n_values = array( |
|
| 2387 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2388 | - ); |
|
| 2386 | + $where_cols_n_values = array( |
|
| 2387 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2388 | + ); |
|
| 2389 | 2389 | |
| 2390 | - $message_template_fields = array( |
|
| 2391 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2392 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2393 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2394 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2395 | - ); |
|
| 2396 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2397 | - if ($updated === false) { |
|
| 2398 | - EE_Error::add_error( |
|
| 2399 | - sprintf( |
|
| 2400 | - __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2401 | - $template_field |
|
| 2402 | - ), |
|
| 2403 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2404 | - ); |
|
| 2405 | - } else { |
|
| 2406 | - $success = 1; |
|
| 2407 | - } |
|
| 2408 | - } else { |
|
| 2409 | - //only do this logic if we don't have a MTP_ID for this field |
|
| 2410 | - if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2411 | - //this has already been through the template field validator and sanitized, so it will be |
|
| 2412 | - //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2413 | - //message template field in a messenger/message type and existing users don't have the |
|
| 2414 | - //default setup for it. |
|
| 2415 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2416 | - $updated = $MTP->insert($message_template_fields); |
|
| 2417 | - if (is_wp_error($updated) || ! $updated) { |
|
| 2418 | - EE_Error::add_error( |
|
| 2419 | - sprintf( |
|
| 2420 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2421 | - $template_field |
|
| 2422 | - ), |
|
| 2423 | - __FILE__, |
|
| 2424 | - __FUNCTION__, |
|
| 2425 | - __LINE__ |
|
| 2426 | - ); |
|
| 2427 | - $success = 0; |
|
| 2428 | - } else { |
|
| 2429 | - $success = 1; |
|
| 2430 | - } |
|
| 2431 | - } |
|
| 2432 | - } |
|
| 2433 | - $action_desc = 'updated'; |
|
| 2434 | - } |
|
| 2390 | + $message_template_fields = array( |
|
| 2391 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2392 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2393 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2394 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2395 | + ); |
|
| 2396 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2397 | + if ($updated === false) { |
|
| 2398 | + EE_Error::add_error( |
|
| 2399 | + sprintf( |
|
| 2400 | + __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2401 | + $template_field |
|
| 2402 | + ), |
|
| 2403 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2404 | + ); |
|
| 2405 | + } else { |
|
| 2406 | + $success = 1; |
|
| 2407 | + } |
|
| 2408 | + } else { |
|
| 2409 | + //only do this logic if we don't have a MTP_ID for this field |
|
| 2410 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2411 | + //this has already been through the template field validator and sanitized, so it will be |
|
| 2412 | + //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2413 | + //message template field in a messenger/message type and existing users don't have the |
|
| 2414 | + //default setup for it. |
|
| 2415 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2416 | + $updated = $MTP->insert($message_template_fields); |
|
| 2417 | + if (is_wp_error($updated) || ! $updated) { |
|
| 2418 | + EE_Error::add_error( |
|
| 2419 | + sprintf( |
|
| 2420 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2421 | + $template_field |
|
| 2422 | + ), |
|
| 2423 | + __FILE__, |
|
| 2424 | + __FUNCTION__, |
|
| 2425 | + __LINE__ |
|
| 2426 | + ); |
|
| 2427 | + $success = 0; |
|
| 2428 | + } else { |
|
| 2429 | + $success = 1; |
|
| 2430 | + } |
|
| 2431 | + } |
|
| 2432 | + } |
|
| 2433 | + $action_desc = 'updated'; |
|
| 2434 | + } |
|
| 2435 | 2435 | |
| 2436 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2437 | - $mtpg_fields = array( |
|
| 2438 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2439 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2440 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2441 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2442 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2443 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2444 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2445 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2446 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2447 | - : '', |
|
| 2448 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2449 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2450 | - : '' |
|
| 2451 | - ); |
|
| 2436 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2437 | + $mtpg_fields = array( |
|
| 2438 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2439 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2440 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2441 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2442 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2443 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2444 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2445 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2446 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2447 | + : '', |
|
| 2448 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2449 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2450 | + : '' |
|
| 2451 | + ); |
|
| 2452 | 2452 | |
| 2453 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2454 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2453 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2454 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2455 | 2455 | |
| 2456 | - if ($updated === false) { |
|
| 2457 | - EE_Error::add_error( |
|
| 2458 | - sprintf( |
|
| 2459 | - __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2460 | - $set_column_values['GRP_ID'] |
|
| 2461 | - ), |
|
| 2462 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2463 | - ); |
|
| 2464 | - } else { |
|
| 2465 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2466 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2467 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2468 | - : 'default'; |
|
| 2456 | + if ($updated === false) { |
|
| 2457 | + EE_Error::add_error( |
|
| 2458 | + sprintf( |
|
| 2459 | + __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2460 | + $set_column_values['GRP_ID'] |
|
| 2461 | + ), |
|
| 2462 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2463 | + ); |
|
| 2464 | + } else { |
|
| 2465 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2466 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2467 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2468 | + : 'default'; |
|
| 2469 | 2469 | |
| 2470 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2471 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2472 | - : 'default'; |
|
| 2470 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2471 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2472 | + : 'default'; |
|
| 2473 | 2473 | |
| 2474 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2475 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2476 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2477 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2478 | - } |
|
| 2479 | - $success = 1; |
|
| 2480 | - } |
|
| 2481 | - } |
|
| 2482 | - } |
|
| 2474 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2475 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2476 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2477 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2478 | + } |
|
| 2479 | + $success = 1; |
|
| 2480 | + } |
|
| 2481 | + } |
|
| 2482 | + } |
|
| 2483 | 2483 | |
| 2484 | - } |
|
| 2485 | - |
|
| 2486 | - //we return things differently if doing ajax |
|
| 2487 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2488 | - $this->_template_args['success'] = $success; |
|
| 2489 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2490 | - $this->_template_args['content'] = ''; |
|
| 2491 | - $this->_template_args['data'] = array( |
|
| 2492 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2493 | - 'templateName' => $edit_array['template_name'] |
|
| 2494 | - ); |
|
| 2495 | - if ($success) { |
|
| 2496 | - EE_Error::overwrite_success(); |
|
| 2497 | - EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2498 | - 'event_espresso')); |
|
| 2499 | - } |
|
| 2484 | + } |
|
| 2485 | + |
|
| 2486 | + //we return things differently if doing ajax |
|
| 2487 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2488 | + $this->_template_args['success'] = $success; |
|
| 2489 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2490 | + $this->_template_args['content'] = ''; |
|
| 2491 | + $this->_template_args['data'] = array( |
|
| 2492 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2493 | + 'templateName' => $edit_array['template_name'] |
|
| 2494 | + ); |
|
| 2495 | + if ($success) { |
|
| 2496 | + EE_Error::overwrite_success(); |
|
| 2497 | + EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2498 | + 'event_espresso')); |
|
| 2499 | + } |
|
| 2500 | 2500 | |
| 2501 | - $this->_return_json(); |
|
| 2502 | - } |
|
| 2503 | - |
|
| 2504 | - |
|
| 2505 | - //was a test send triggered? |
|
| 2506 | - if (isset($this->_req_data['test_button'])) { |
|
| 2507 | - EE_Error::overwrite_success(); |
|
| 2508 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2509 | - $override = true; |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - if (empty($query_args)) { |
|
| 2513 | - $query_args = array( |
|
| 2514 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2515 | - 'context' => $context_slug, |
|
| 2516 | - 'action' => 'edit_message_template' |
|
| 2517 | - ); |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2521 | - } |
|
| 2522 | - |
|
| 2523 | - |
|
| 2524 | - /** |
|
| 2525 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2526 | - * |
|
| 2527 | - * @param string $context what context being tested |
|
| 2528 | - * @param string $messenger messenger being tested |
|
| 2529 | - * @param string $message_type message type being tested |
|
| 2530 | - * |
|
| 2531 | - */ |
|
| 2532 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2533 | - { |
|
| 2534 | - //set things up for preview |
|
| 2535 | - $this->_req_data['messenger'] = $messenger; |
|
| 2536 | - $this->_req_data['message_type'] = $message_type; |
|
| 2537 | - $this->_req_data['context'] = $context; |
|
| 2538 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2539 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2540 | - |
|
| 2541 | - //let's save any existing fields that might be required by the messenger |
|
| 2542 | - if ( |
|
| 2543 | - isset($this->_req_data['test_settings_fld']) |
|
| 2544 | - && $active_messenger instanceof EE_messenger |
|
| 2545 | - && apply_filters( |
|
| 2546 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2547 | - true, |
|
| 2548 | - $this->_req_data['test_settings_fld'], |
|
| 2549 | - $active_messenger |
|
| 2550 | - ) |
|
| 2551 | - ) { |
|
| 2552 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - $success = $this->_preview_message(true); |
|
| 2556 | - |
|
| 2557 | - if ($success) { |
|
| 2558 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2559 | - } else { |
|
| 2560 | - EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2561 | - __LINE__); |
|
| 2562 | - } |
|
| 2563 | - } |
|
| 2564 | - |
|
| 2565 | - |
|
| 2566 | - /** |
|
| 2567 | - * _generate_new_templates |
|
| 2568 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2569 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2570 | - * for the event. |
|
| 2571 | - * |
|
| 2572 | - * |
|
| 2573 | - * @param string $messenger the messenger we are generating templates for |
|
| 2574 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2575 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2576 | - * indicate the message_template_group being used as the base. |
|
| 2577 | - * |
|
| 2578 | - * @param bool $global |
|
| 2579 | - * |
|
| 2580 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2581 | - * encountering problems. |
|
| 2582 | - * @throws \EE_Error |
|
| 2583 | - */ |
|
| 2584 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2585 | - { |
|
| 2586 | - |
|
| 2587 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2588 | - if (empty($message_types)) { |
|
| 2589 | - return true; |
|
| 2590 | - } |
|
| 2591 | - |
|
| 2592 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - |
|
| 2596 | - /** |
|
| 2597 | - * [_trash_or_restore_message_template] |
|
| 2598 | - * |
|
| 2599 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2600 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2601 | - * an individual context (FALSE). |
|
| 2602 | - * |
|
| 2603 | - * @return void |
|
| 2604 | - */ |
|
| 2605 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2606 | - { |
|
| 2607 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2608 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2609 | - |
|
| 2610 | - $success = 1; |
|
| 2611 | - |
|
| 2612 | - //incoming GRP_IDs |
|
| 2613 | - if ($all) { |
|
| 2614 | - //Checkboxes |
|
| 2615 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2616 | - //if array has more than one element then success message should be plural. |
|
| 2617 | - //todo: what about nonce? |
|
| 2618 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2501 | + $this->_return_json(); |
|
| 2502 | + } |
|
| 2503 | + |
|
| 2504 | + |
|
| 2505 | + //was a test send triggered? |
|
| 2506 | + if (isset($this->_req_data['test_button'])) { |
|
| 2507 | + EE_Error::overwrite_success(); |
|
| 2508 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2509 | + $override = true; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + if (empty($query_args)) { |
|
| 2513 | + $query_args = array( |
|
| 2514 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2515 | + 'context' => $context_slug, |
|
| 2516 | + 'action' => 'edit_message_template' |
|
| 2517 | + ); |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2521 | + } |
|
| 2522 | + |
|
| 2523 | + |
|
| 2524 | + /** |
|
| 2525 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2526 | + * |
|
| 2527 | + * @param string $context what context being tested |
|
| 2528 | + * @param string $messenger messenger being tested |
|
| 2529 | + * @param string $message_type message type being tested |
|
| 2530 | + * |
|
| 2531 | + */ |
|
| 2532 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2533 | + { |
|
| 2534 | + //set things up for preview |
|
| 2535 | + $this->_req_data['messenger'] = $messenger; |
|
| 2536 | + $this->_req_data['message_type'] = $message_type; |
|
| 2537 | + $this->_req_data['context'] = $context; |
|
| 2538 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2539 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2540 | + |
|
| 2541 | + //let's save any existing fields that might be required by the messenger |
|
| 2542 | + if ( |
|
| 2543 | + isset($this->_req_data['test_settings_fld']) |
|
| 2544 | + && $active_messenger instanceof EE_messenger |
|
| 2545 | + && apply_filters( |
|
| 2546 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2547 | + true, |
|
| 2548 | + $this->_req_data['test_settings_fld'], |
|
| 2549 | + $active_messenger |
|
| 2550 | + ) |
|
| 2551 | + ) { |
|
| 2552 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + $success = $this->_preview_message(true); |
|
| 2556 | + |
|
| 2557 | + if ($success) { |
|
| 2558 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2559 | + } else { |
|
| 2560 | + EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2561 | + __LINE__); |
|
| 2562 | + } |
|
| 2563 | + } |
|
| 2564 | + |
|
| 2565 | + |
|
| 2566 | + /** |
|
| 2567 | + * _generate_new_templates |
|
| 2568 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2569 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2570 | + * for the event. |
|
| 2571 | + * |
|
| 2572 | + * |
|
| 2573 | + * @param string $messenger the messenger we are generating templates for |
|
| 2574 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2575 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2576 | + * indicate the message_template_group being used as the base. |
|
| 2577 | + * |
|
| 2578 | + * @param bool $global |
|
| 2579 | + * |
|
| 2580 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2581 | + * encountering problems. |
|
| 2582 | + * @throws \EE_Error |
|
| 2583 | + */ |
|
| 2584 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2585 | + { |
|
| 2586 | + |
|
| 2587 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2588 | + if (empty($message_types)) { |
|
| 2589 | + return true; |
|
| 2590 | + } |
|
| 2591 | + |
|
| 2592 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + |
|
| 2596 | + /** |
|
| 2597 | + * [_trash_or_restore_message_template] |
|
| 2598 | + * |
|
| 2599 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2600 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2601 | + * an individual context (FALSE). |
|
| 2602 | + * |
|
| 2603 | + * @return void |
|
| 2604 | + */ |
|
| 2605 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2606 | + { |
|
| 2607 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2608 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2609 | + |
|
| 2610 | + $success = 1; |
|
| 2611 | + |
|
| 2612 | + //incoming GRP_IDs |
|
| 2613 | + if ($all) { |
|
| 2614 | + //Checkboxes |
|
| 2615 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2616 | + //if array has more than one element then success message should be plural. |
|
| 2617 | + //todo: what about nonce? |
|
| 2618 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2619 | 2619 | |
| 2620 | - //cycle through checkboxes |
|
| 2621 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2622 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2623 | - if ( ! $trashed_or_restored) { |
|
| 2624 | - $success = 0; |
|
| 2625 | - } |
|
| 2626 | - } |
|
| 2627 | - } else { |
|
| 2628 | - //grab single GRP_ID and handle |
|
| 2629 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2630 | - if ( ! empty($GRP_ID)) { |
|
| 2631 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2632 | - if ( ! $trashed_or_restored) { |
|
| 2633 | - $success = 0; |
|
| 2634 | - } |
|
| 2635 | - } else { |
|
| 2636 | - $success = 0; |
|
| 2637 | - } |
|
| 2638 | - } |
|
| 2620 | + //cycle through checkboxes |
|
| 2621 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2622 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2623 | + if ( ! $trashed_or_restored) { |
|
| 2624 | + $success = 0; |
|
| 2625 | + } |
|
| 2626 | + } |
|
| 2627 | + } else { |
|
| 2628 | + //grab single GRP_ID and handle |
|
| 2629 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2630 | + if ( ! empty($GRP_ID)) { |
|
| 2631 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2632 | + if ( ! $trashed_or_restored) { |
|
| 2633 | + $success = 0; |
|
| 2634 | + } |
|
| 2635 | + } else { |
|
| 2636 | + $success = 0; |
|
| 2637 | + } |
|
| 2638 | + } |
|
| 2639 | 2639 | |
| 2640 | - } |
|
| 2640 | + } |
|
| 2641 | 2641 | |
| 2642 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2642 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2643 | 2643 | |
| 2644 | - $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2644 | + $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2645 | 2645 | |
| 2646 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2647 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2646 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2647 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2648 | 2648 | |
| 2649 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2650 | - 'event_espresso') : $item_desc; |
|
| 2649 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2650 | + 'event_espresso') : $item_desc; |
|
| 2651 | 2651 | |
| 2652 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2652 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2653 | 2653 | |
| 2654 | - } |
|
| 2654 | + } |
|
| 2655 | 2655 | |
| 2656 | 2656 | |
| 2657 | - /** |
|
| 2658 | - * [_delete_message_template] |
|
| 2659 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2660 | - * @return void |
|
| 2661 | - */ |
|
| 2662 | - protected function _delete_message_template() |
|
| 2663 | - { |
|
| 2664 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2657 | + /** |
|
| 2658 | + * [_delete_message_template] |
|
| 2659 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2660 | + * @return void |
|
| 2661 | + */ |
|
| 2662 | + protected function _delete_message_template() |
|
| 2663 | + { |
|
| 2664 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2665 | 2665 | |
| 2666 | - //checkboxes |
|
| 2667 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2668 | - //if array has more than one element then success message should be plural |
|
| 2669 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2666 | + //checkboxes |
|
| 2667 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2668 | + //if array has more than one element then success message should be plural |
|
| 2669 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2670 | 2670 | |
| 2671 | - //cycle through bulk action checkboxes |
|
| 2672 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2673 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2674 | - } |
|
| 2675 | - } else { |
|
| 2676 | - //grab single grp_id and delete |
|
| 2677 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 2678 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2679 | - } |
|
| 2680 | - |
|
| 2681 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2682 | - |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - |
|
| 2686 | - /** |
|
| 2687 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 2688 | - * |
|
| 2689 | - * @param int $GRP_ID The group being deleted |
|
| 2690 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2691 | - * |
|
| 2692 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2693 | - */ |
|
| 2694 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2695 | - { |
|
| 2696 | - $success = 1; |
|
| 2697 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2698 | - //first let's GET this group |
|
| 2699 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2700 | - //then delete permanently all the related Message Templates |
|
| 2701 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2702 | - |
|
| 2703 | - if ($deleted === 0) { |
|
| 2704 | - $success = 0; |
|
| 2705 | - } |
|
| 2706 | - |
|
| 2707 | - //now delete permanently this particular group |
|
| 2708 | - |
|
| 2709 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2710 | - $success = 0; |
|
| 2711 | - } |
|
| 2712 | - |
|
| 2713 | - return $success; |
|
| 2714 | - } |
|
| 2715 | - |
|
| 2716 | - |
|
| 2717 | - /** |
|
| 2718 | - * _learn_more_about_message_templates_link |
|
| 2719 | - * @access protected |
|
| 2720 | - * @return string |
|
| 2721 | - */ |
|
| 2722 | - protected function _learn_more_about_message_templates_link() |
|
| 2723 | - { |
|
| 2724 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2725 | - 'event_espresso') . '</a>'; |
|
| 2726 | - } |
|
| 2727 | - |
|
| 2728 | - |
|
| 2729 | - /** |
|
| 2730 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2731 | - * ajax and other routes. |
|
| 2732 | - * @return void |
|
| 2733 | - */ |
|
| 2734 | - protected function _settings() |
|
| 2735 | - { |
|
| 2736 | - |
|
| 2737 | - |
|
| 2738 | - $this->_set_m_mt_settings(); |
|
| 2739 | - |
|
| 2740 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2741 | - |
|
| 2742 | - //let's setup the messenger tabs |
|
| 2743 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2744 | - 'messenger_links', '|', $selected_messenger); |
|
| 2745 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2746 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2747 | - |
|
| 2748 | - $this->display_admin_page_with_sidebar(); |
|
| 2749 | - |
|
| 2750 | - } |
|
| 2751 | - |
|
| 2752 | - |
|
| 2753 | - /** |
|
| 2754 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2755 | - * |
|
| 2756 | - * @access protected |
|
| 2757 | - * @return void |
|
| 2758 | - */ |
|
| 2759 | - protected function _set_m_mt_settings() |
|
| 2760 | - { |
|
| 2761 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 2762 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 2763 | - return; |
|
| 2764 | - } |
|
| 2765 | - |
|
| 2766 | - //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2767 | - |
|
| 2768 | - //get all installed messengers and message_types |
|
| 2769 | - /** @type EE_messenger[] $messengers */ |
|
| 2770 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2771 | - /** @type EE_message_type[] $message_types */ |
|
| 2772 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2773 | - |
|
| 2774 | - |
|
| 2775 | - //assemble the array for the _tab_text_links helper |
|
| 2776 | - |
|
| 2777 | - foreach ($messengers as $messenger) { |
|
| 2778 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2779 | - 'label' => ucwords($messenger->label['singular']), |
|
| 2780 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2781 | - 'href' => $messenger->name, |
|
| 2782 | - 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2783 | - 'slug' => $messenger->name, |
|
| 2784 | - 'obj' => $messenger |
|
| 2785 | - ); |
|
| 2671 | + //cycle through bulk action checkboxes |
|
| 2672 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2673 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2674 | + } |
|
| 2675 | + } else { |
|
| 2676 | + //grab single grp_id and delete |
|
| 2677 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 2678 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2679 | + } |
|
| 2680 | + |
|
| 2681 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2682 | + |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + |
|
| 2686 | + /** |
|
| 2687 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 2688 | + * |
|
| 2689 | + * @param int $GRP_ID The group being deleted |
|
| 2690 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2691 | + * |
|
| 2692 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 2693 | + */ |
|
| 2694 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2695 | + { |
|
| 2696 | + $success = 1; |
|
| 2697 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2698 | + //first let's GET this group |
|
| 2699 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2700 | + //then delete permanently all the related Message Templates |
|
| 2701 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2702 | + |
|
| 2703 | + if ($deleted === 0) { |
|
| 2704 | + $success = 0; |
|
| 2705 | + } |
|
| 2706 | + |
|
| 2707 | + //now delete permanently this particular group |
|
| 2708 | + |
|
| 2709 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2710 | + $success = 0; |
|
| 2711 | + } |
|
| 2712 | + |
|
| 2713 | + return $success; |
|
| 2714 | + } |
|
| 2715 | + |
|
| 2716 | + |
|
| 2717 | + /** |
|
| 2718 | + * _learn_more_about_message_templates_link |
|
| 2719 | + * @access protected |
|
| 2720 | + * @return string |
|
| 2721 | + */ |
|
| 2722 | + protected function _learn_more_about_message_templates_link() |
|
| 2723 | + { |
|
| 2724 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2725 | + 'event_espresso') . '</a>'; |
|
| 2726 | + } |
|
| 2727 | + |
|
| 2728 | + |
|
| 2729 | + /** |
|
| 2730 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2731 | + * ajax and other routes. |
|
| 2732 | + * @return void |
|
| 2733 | + */ |
|
| 2734 | + protected function _settings() |
|
| 2735 | + { |
|
| 2736 | + |
|
| 2737 | + |
|
| 2738 | + $this->_set_m_mt_settings(); |
|
| 2739 | + |
|
| 2740 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2741 | + |
|
| 2742 | + //let's setup the messenger tabs |
|
| 2743 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2744 | + 'messenger_links', '|', $selected_messenger); |
|
| 2745 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2746 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2747 | + |
|
| 2748 | + $this->display_admin_page_with_sidebar(); |
|
| 2749 | + |
|
| 2750 | + } |
|
| 2751 | + |
|
| 2752 | + |
|
| 2753 | + /** |
|
| 2754 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2755 | + * |
|
| 2756 | + * @access protected |
|
| 2757 | + * @return void |
|
| 2758 | + */ |
|
| 2759 | + protected function _set_m_mt_settings() |
|
| 2760 | + { |
|
| 2761 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 2762 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 2763 | + return; |
|
| 2764 | + } |
|
| 2765 | + |
|
| 2766 | + //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2767 | + |
|
| 2768 | + //get all installed messengers and message_types |
|
| 2769 | + /** @type EE_messenger[] $messengers */ |
|
| 2770 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2771 | + /** @type EE_message_type[] $message_types */ |
|
| 2772 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2773 | + |
|
| 2774 | + |
|
| 2775 | + //assemble the array for the _tab_text_links helper |
|
| 2776 | + |
|
| 2777 | + foreach ($messengers as $messenger) { |
|
| 2778 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2779 | + 'label' => ucwords($messenger->label['singular']), |
|
| 2780 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2781 | + 'href' => $messenger->name, |
|
| 2782 | + 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2783 | + 'slug' => $messenger->name, |
|
| 2784 | + 'obj' => $messenger |
|
| 2785 | + ); |
|
| 2786 | 2786 | |
| 2787 | 2787 | |
| 2788 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2788 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2789 | 2789 | |
| 2790 | - foreach ($message_types as $message_type) { |
|
| 2791 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2792 | - if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2793 | - continue; |
|
| 2794 | - } |
|
| 2790 | + foreach ($message_types as $message_type) { |
|
| 2791 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2792 | + if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2793 | + continue; |
|
| 2794 | + } |
|
| 2795 | 2795 | |
| 2796 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2797 | - $message_type->name) ? 'active' : 'inactive'; |
|
| 2796 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2797 | + $message_type->name) ? 'active' : 'inactive'; |
|
| 2798 | 2798 | |
| 2799 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2800 | - 'label' => ucwords($message_type->label['singular']), |
|
| 2801 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2802 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2803 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2804 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2805 | - 'title' => $a_or_i == 'active' |
|
| 2806 | - ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2807 | - : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2808 | - 'content' => $a_or_i == 'active' |
|
| 2809 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2810 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2811 | - 'slug' => $message_type->name, |
|
| 2812 | - 'active' => $a_or_i == 'active' ? true : false, |
|
| 2813 | - 'obj' => $message_type |
|
| 2814 | - ); |
|
| 2815 | - } |
|
| 2816 | - } |
|
| 2817 | - } |
|
| 2818 | - |
|
| 2819 | - |
|
| 2820 | - /** |
|
| 2821 | - * This just prepares the content for the message type settings |
|
| 2822 | - * |
|
| 2823 | - * @param object $message_type The message type object |
|
| 2824 | - * @param object $messenger The messenger object |
|
| 2825 | - * @param boolean $active Whether the message type is active or not |
|
| 2826 | - * |
|
| 2827 | - * @return string html output for the content |
|
| 2828 | - */ |
|
| 2829 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2830 | - { |
|
| 2831 | - //get message type fields |
|
| 2832 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 2833 | - $settings_template_args['template_form_fields'] = ''; |
|
| 2834 | - |
|
| 2835 | - if ( ! empty($fields) && $active) { |
|
| 2799 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2800 | + 'label' => ucwords($message_type->label['singular']), |
|
| 2801 | + 'class' => 'message-type-' . $a_or_i, |
|
| 2802 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2803 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2804 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2805 | + 'title' => $a_or_i == 'active' |
|
| 2806 | + ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2807 | + : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2808 | + 'content' => $a_or_i == 'active' |
|
| 2809 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2810 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2811 | + 'slug' => $message_type->name, |
|
| 2812 | + 'active' => $a_or_i == 'active' ? true : false, |
|
| 2813 | + 'obj' => $message_type |
|
| 2814 | + ); |
|
| 2815 | + } |
|
| 2816 | + } |
|
| 2817 | + } |
|
| 2818 | + |
|
| 2819 | + |
|
| 2820 | + /** |
|
| 2821 | + * This just prepares the content for the message type settings |
|
| 2822 | + * |
|
| 2823 | + * @param object $message_type The message type object |
|
| 2824 | + * @param object $messenger The messenger object |
|
| 2825 | + * @param boolean $active Whether the message type is active or not |
|
| 2826 | + * |
|
| 2827 | + * @return string html output for the content |
|
| 2828 | + */ |
|
| 2829 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2830 | + { |
|
| 2831 | + //get message type fields |
|
| 2832 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 2833 | + $settings_template_args['template_form_fields'] = ''; |
|
| 2834 | + |
|
| 2835 | + if ( ! empty($fields) && $active) { |
|
| 2836 | 2836 | |
| 2837 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2837 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2838 | 2838 | |
| 2839 | - foreach ($fields as $fldname => $fldprops) { |
|
| 2840 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2841 | - $template_form_field[$field_id] = array( |
|
| 2842 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2843 | - 'label' => $fldprops['label'], |
|
| 2844 | - 'input' => $fldprops['field_type'], |
|
| 2845 | - 'type' => $fldprops['value_type'], |
|
| 2846 | - 'required' => $fldprops['required'], |
|
| 2847 | - 'validation' => $fldprops['validation'], |
|
| 2848 | - 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2849 | - 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2850 | - 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2851 | - 'css_class' => 'no-drag', |
|
| 2852 | - 'format' => $fldprops['format'] |
|
| 2853 | - ); |
|
| 2854 | - } |
|
| 2839 | + foreach ($fields as $fldname => $fldprops) { |
|
| 2840 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2841 | + $template_form_field[$field_id] = array( |
|
| 2842 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2843 | + 'label' => $fldprops['label'], |
|
| 2844 | + 'input' => $fldprops['field_type'], |
|
| 2845 | + 'type' => $fldprops['value_type'], |
|
| 2846 | + 'required' => $fldprops['required'], |
|
| 2847 | + 'validation' => $fldprops['validation'], |
|
| 2848 | + 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2849 | + 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2850 | + 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2851 | + 'css_class' => 'no-drag', |
|
| 2852 | + 'format' => $fldprops['format'] |
|
| 2853 | + ); |
|
| 2854 | + } |
|
| 2855 | 2855 | |
| 2856 | 2856 | |
| 2857 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2858 | - 'string', 'ee_mt_activate_form') : ''; |
|
| 2859 | - } |
|
| 2860 | - |
|
| 2861 | - $settings_template_args['description'] = $message_type->description; |
|
| 2862 | - //we also need some hidden fields |
|
| 2863 | - $settings_template_args['hidden_fields'] = array( |
|
| 2864 | - 'message_type_settings[messenger]' => array( |
|
| 2865 | - 'type' => 'hidden', |
|
| 2866 | - 'value' => $messenger->name |
|
| 2867 | - ), |
|
| 2868 | - 'message_type_settings[message_type]' => array( |
|
| 2869 | - 'type' => 'hidden', |
|
| 2870 | - 'value' => $message_type->name |
|
| 2871 | - ), |
|
| 2872 | - 'type' => array( |
|
| 2873 | - 'type' => 'hidden', |
|
| 2874 | - 'value' => 'message_type' |
|
| 2875 | - ) |
|
| 2876 | - ); |
|
| 2877 | - |
|
| 2878 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2879 | - 'array'); |
|
| 2880 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2881 | - |
|
| 2882 | - |
|
| 2883 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2884 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2885 | - |
|
| 2886 | - return $content; |
|
| 2887 | - } |
|
| 2888 | - |
|
| 2889 | - |
|
| 2890 | - /** |
|
| 2891 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2892 | - * |
|
| 2893 | - * @access protected |
|
| 2894 | - * @return void |
|
| 2895 | - */ |
|
| 2896 | - protected function _messages_settings_metaboxes() |
|
| 2897 | - { |
|
| 2898 | - $this->_set_m_mt_settings(); |
|
| 2899 | - $m_boxes = $mt_boxes = array(); |
|
| 2900 | - $m_template_args = $mt_template_args = array(); |
|
| 2901 | - |
|
| 2902 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2903 | - |
|
| 2904 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2905 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2906 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2907 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2908 | - //messenger meta boxes |
|
| 2909 | - $active = $selected_messenger == $messenger ? true : false; |
|
| 2910 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2911 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2912 | - : ''; |
|
| 2913 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2914 | - __('%s Settings', 'event_espresso'), |
|
| 2915 | - $tab_array['label'] |
|
| 2916 | - ); |
|
| 2917 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2918 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2919 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2920 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2921 | - : '', |
|
| 2922 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2923 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2924 | - 'hide_on_message' => $hide_on_message, |
|
| 2925 | - 'messenger' => $messenger, |
|
| 2926 | - 'active' => $active |
|
| 2927 | - ); |
|
| 2928 | - // message type meta boxes |
|
| 2929 | - // (which is really just the inactive container for each messenger |
|
| 2930 | - // showing inactive message types for that messenger) |
|
| 2931 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2932 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2933 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2934 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2935 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2936 | - : '', |
|
| 2937 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2938 | - 'hide_on_message' => $hide_on_message, |
|
| 2939 | - 'hide_off_message' => $hide_off_message, |
|
| 2940 | - 'messenger' => $messenger, |
|
| 2941 | - 'active' => $active |
|
| 2942 | - ); |
|
| 2943 | - } |
|
| 2944 | - } |
|
| 2945 | - |
|
| 2946 | - |
|
| 2947 | - //register messenger metaboxes |
|
| 2948 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2949 | - foreach ($m_boxes as $box => $label) { |
|
| 2950 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2951 | - $msgr = str_replace('_a_box', '', $box); |
|
| 2952 | - add_meta_box( |
|
| 2953 | - 'espresso_' . $msgr . '_settings', |
|
| 2954 | - $label, |
|
| 2955 | - function ($post, $metabox) { |
|
| 2956 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2957 | - $metabox["args"]["template_args"], true); |
|
| 2958 | - }, |
|
| 2959 | - $this->_current_screen->id, |
|
| 2960 | - 'normal', |
|
| 2961 | - 'high', |
|
| 2962 | - $callback_args |
|
| 2963 | - ); |
|
| 2964 | - } |
|
| 2965 | - |
|
| 2966 | - //register message type metaboxes |
|
| 2967 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2968 | - foreach ($mt_boxes as $box => $label) { |
|
| 2969 | - $callback_args = array( |
|
| 2970 | - 'template_path' => $mt_template_path, |
|
| 2971 | - 'template_args' => $mt_template_args[$box] |
|
| 2972 | - ); |
|
| 2973 | - $mt = str_replace('_i_box', '', $box); |
|
| 2974 | - add_meta_box( |
|
| 2975 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2976 | - $label, |
|
| 2977 | - function ($post, $metabox) { |
|
| 2978 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2979 | - $metabox["args"]["template_args"], true); |
|
| 2980 | - }, |
|
| 2981 | - $this->_current_screen->id, |
|
| 2982 | - 'side', |
|
| 2983 | - 'high', |
|
| 2984 | - $callback_args |
|
| 2985 | - ); |
|
| 2986 | - } |
|
| 2987 | - |
|
| 2988 | - //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2989 | - //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2990 | - if (is_main_site()) { |
|
| 2991 | - add_meta_box( |
|
| 2992 | - 'espresso_global_message_settings', |
|
| 2993 | - __('Global Message Settings', 'event_espresso'), |
|
| 2994 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 2995 | - $this->_current_screen->id, |
|
| 2996 | - 'normal', |
|
| 2997 | - 'low', |
|
| 2998 | - array() |
|
| 2999 | - ); |
|
| 3000 | - } |
|
| 3001 | - |
|
| 3002 | - } |
|
| 3003 | - |
|
| 3004 | - |
|
| 3005 | - /** |
|
| 3006 | - * This generates the content for the global messages settings metabox. |
|
| 3007 | - * @return string |
|
| 3008 | - */ |
|
| 3009 | - public function global_messages_settings_metabox_content() |
|
| 3010 | - { |
|
| 3011 | - $form = $this->_generate_global_settings_form(); |
|
| 3012 | - echo $form->form_open( |
|
| 3013 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3014 | - 'POST' |
|
| 3015 | - ) |
|
| 3016 | - . $form->get_html() |
|
| 3017 | - . $form->form_close(); |
|
| 3018 | - } |
|
| 3019 | - |
|
| 3020 | - |
|
| 3021 | - /** |
|
| 3022 | - * This generates and returns the form object for the global messages settings. |
|
| 3023 | - * @return EE_Form_Section_Proper |
|
| 3024 | - */ |
|
| 3025 | - protected function _generate_global_settings_form() |
|
| 3026 | - { |
|
| 3027 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3028 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3029 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3030 | - |
|
| 3031 | - return new EE_Form_Section_Proper( |
|
| 3032 | - array( |
|
| 3033 | - 'name' => 'global_messages_settings', |
|
| 3034 | - 'html_id' => 'global_messages_settings', |
|
| 3035 | - 'html_class' => 'form-table', |
|
| 3036 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3037 | - 'subsections' => apply_filters( |
|
| 3038 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3039 | - array( |
|
| 3040 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3041 | - array( |
|
| 3042 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3043 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3044 | - ), |
|
| 3045 | - array( |
|
| 3046 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3047 | - 'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'), |
|
| 3048 | - 'html_help_text' => esc_html__('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3049 | - 'event_espresso'), |
|
| 3050 | - ) |
|
| 3051 | - ), |
|
| 3052 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3053 | - array( |
|
| 3054 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3055 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3056 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3057 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3058 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3059 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3060 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3061 | - ), |
|
| 3062 | - array( |
|
| 3063 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3064 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3065 | - 'html_help_text' => esc_html__('You can control how long a record of processed messages is kept |
|
| 2857 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2858 | + 'string', 'ee_mt_activate_form') : ''; |
|
| 2859 | + } |
|
| 2860 | + |
|
| 2861 | + $settings_template_args['description'] = $message_type->description; |
|
| 2862 | + //we also need some hidden fields |
|
| 2863 | + $settings_template_args['hidden_fields'] = array( |
|
| 2864 | + 'message_type_settings[messenger]' => array( |
|
| 2865 | + 'type' => 'hidden', |
|
| 2866 | + 'value' => $messenger->name |
|
| 2867 | + ), |
|
| 2868 | + 'message_type_settings[message_type]' => array( |
|
| 2869 | + 'type' => 'hidden', |
|
| 2870 | + 'value' => $message_type->name |
|
| 2871 | + ), |
|
| 2872 | + 'type' => array( |
|
| 2873 | + 'type' => 'hidden', |
|
| 2874 | + 'value' => 'message_type' |
|
| 2875 | + ) |
|
| 2876 | + ); |
|
| 2877 | + |
|
| 2878 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2879 | + 'array'); |
|
| 2880 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2881 | + |
|
| 2882 | + |
|
| 2883 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2884 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2885 | + |
|
| 2886 | + return $content; |
|
| 2887 | + } |
|
| 2888 | + |
|
| 2889 | + |
|
| 2890 | + /** |
|
| 2891 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2892 | + * |
|
| 2893 | + * @access protected |
|
| 2894 | + * @return void |
|
| 2895 | + */ |
|
| 2896 | + protected function _messages_settings_metaboxes() |
|
| 2897 | + { |
|
| 2898 | + $this->_set_m_mt_settings(); |
|
| 2899 | + $m_boxes = $mt_boxes = array(); |
|
| 2900 | + $m_template_args = $mt_template_args = array(); |
|
| 2901 | + |
|
| 2902 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2903 | + |
|
| 2904 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2905 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2906 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2907 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2908 | + //messenger meta boxes |
|
| 2909 | + $active = $selected_messenger == $messenger ? true : false; |
|
| 2910 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2911 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2912 | + : ''; |
|
| 2913 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2914 | + __('%s Settings', 'event_espresso'), |
|
| 2915 | + $tab_array['label'] |
|
| 2916 | + ); |
|
| 2917 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 2918 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2919 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2920 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2921 | + : '', |
|
| 2922 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2923 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2924 | + 'hide_on_message' => $hide_on_message, |
|
| 2925 | + 'messenger' => $messenger, |
|
| 2926 | + 'active' => $active |
|
| 2927 | + ); |
|
| 2928 | + // message type meta boxes |
|
| 2929 | + // (which is really just the inactive container for each messenger |
|
| 2930 | + // showing inactive message types for that messenger) |
|
| 2931 | + $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2932 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2933 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2934 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2935 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2936 | + : '', |
|
| 2937 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2938 | + 'hide_on_message' => $hide_on_message, |
|
| 2939 | + 'hide_off_message' => $hide_off_message, |
|
| 2940 | + 'messenger' => $messenger, |
|
| 2941 | + 'active' => $active |
|
| 2942 | + ); |
|
| 2943 | + } |
|
| 2944 | + } |
|
| 2945 | + |
|
| 2946 | + |
|
| 2947 | + //register messenger metaboxes |
|
| 2948 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2949 | + foreach ($m_boxes as $box => $label) { |
|
| 2950 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2951 | + $msgr = str_replace('_a_box', '', $box); |
|
| 2952 | + add_meta_box( |
|
| 2953 | + 'espresso_' . $msgr . '_settings', |
|
| 2954 | + $label, |
|
| 2955 | + function ($post, $metabox) { |
|
| 2956 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2957 | + $metabox["args"]["template_args"], true); |
|
| 2958 | + }, |
|
| 2959 | + $this->_current_screen->id, |
|
| 2960 | + 'normal', |
|
| 2961 | + 'high', |
|
| 2962 | + $callback_args |
|
| 2963 | + ); |
|
| 2964 | + } |
|
| 2965 | + |
|
| 2966 | + //register message type metaboxes |
|
| 2967 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2968 | + foreach ($mt_boxes as $box => $label) { |
|
| 2969 | + $callback_args = array( |
|
| 2970 | + 'template_path' => $mt_template_path, |
|
| 2971 | + 'template_args' => $mt_template_args[$box] |
|
| 2972 | + ); |
|
| 2973 | + $mt = str_replace('_i_box', '', $box); |
|
| 2974 | + add_meta_box( |
|
| 2975 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 2976 | + $label, |
|
| 2977 | + function ($post, $metabox) { |
|
| 2978 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2979 | + $metabox["args"]["template_args"], true); |
|
| 2980 | + }, |
|
| 2981 | + $this->_current_screen->id, |
|
| 2982 | + 'side', |
|
| 2983 | + 'high', |
|
| 2984 | + $callback_args |
|
| 2985 | + ); |
|
| 2986 | + } |
|
| 2987 | + |
|
| 2988 | + //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2989 | + //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2990 | + if (is_main_site()) { |
|
| 2991 | + add_meta_box( |
|
| 2992 | + 'espresso_global_message_settings', |
|
| 2993 | + __('Global Message Settings', 'event_espresso'), |
|
| 2994 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 2995 | + $this->_current_screen->id, |
|
| 2996 | + 'normal', |
|
| 2997 | + 'low', |
|
| 2998 | + array() |
|
| 2999 | + ); |
|
| 3000 | + } |
|
| 3001 | + |
|
| 3002 | + } |
|
| 3003 | + |
|
| 3004 | + |
|
| 3005 | + /** |
|
| 3006 | + * This generates the content for the global messages settings metabox. |
|
| 3007 | + * @return string |
|
| 3008 | + */ |
|
| 3009 | + public function global_messages_settings_metabox_content() |
|
| 3010 | + { |
|
| 3011 | + $form = $this->_generate_global_settings_form(); |
|
| 3012 | + echo $form->form_open( |
|
| 3013 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3014 | + 'POST' |
|
| 3015 | + ) |
|
| 3016 | + . $form->get_html() |
|
| 3017 | + . $form->form_close(); |
|
| 3018 | + } |
|
| 3019 | + |
|
| 3020 | + |
|
| 3021 | + /** |
|
| 3022 | + * This generates and returns the form object for the global messages settings. |
|
| 3023 | + * @return EE_Form_Section_Proper |
|
| 3024 | + */ |
|
| 3025 | + protected function _generate_global_settings_form() |
|
| 3026 | + { |
|
| 3027 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3028 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3029 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3030 | + |
|
| 3031 | + return new EE_Form_Section_Proper( |
|
| 3032 | + array( |
|
| 3033 | + 'name' => 'global_messages_settings', |
|
| 3034 | + 'html_id' => 'global_messages_settings', |
|
| 3035 | + 'html_class' => 'form-table', |
|
| 3036 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3037 | + 'subsections' => apply_filters( |
|
| 3038 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3039 | + array( |
|
| 3040 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3041 | + array( |
|
| 3042 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3043 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3044 | + ), |
|
| 3045 | + array( |
|
| 3046 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3047 | + 'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'), |
|
| 3048 | + 'html_help_text' => esc_html__('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3049 | + 'event_espresso'), |
|
| 3050 | + ) |
|
| 3051 | + ), |
|
| 3052 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3053 | + array( |
|
| 3054 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3055 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3056 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3057 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3058 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3059 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3060 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3061 | + ), |
|
| 3062 | + array( |
|
| 3063 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3064 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3065 | + 'html_help_text' => esc_html__('You can control how long a record of processed messages is kept |
|
| 3066 | 3066 | via this option.', 'event_espresso'), |
| 3067 | - ) |
|
| 3068 | - ), |
|
| 3069 | - 'update_settings' => new EE_Submit_Input( |
|
| 3070 | - array( |
|
| 3071 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3072 | - 'html_label_text' => ' ' |
|
| 3073 | - ) |
|
| 3074 | - ) |
|
| 3075 | - ) |
|
| 3076 | - ) |
|
| 3077 | - ) |
|
| 3078 | - ); |
|
| 3079 | - } |
|
| 3080 | - |
|
| 3081 | - |
|
| 3082 | - /** |
|
| 3083 | - * This handles updating the global settings set on the admin page. |
|
| 3084 | - * @throws \EE_Error |
|
| 3085 | - */ |
|
| 3086 | - protected function _update_global_settings() |
|
| 3087 | - { |
|
| 3088 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3089 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3090 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3091 | - $form = $this->_generate_global_settings_form(); |
|
| 3092 | - if ($form->was_submitted()) { |
|
| 3093 | - $form->receive_form_submission(); |
|
| 3094 | - if ($form->is_valid()) { |
|
| 3095 | - $valid_data = $form->valid_data(); |
|
| 3096 | - foreach ($valid_data as $property => $value) { |
|
| 3097 | - $setter = 'set_' . $property; |
|
| 3098 | - if (method_exists($network_config, $setter)) { |
|
| 3099 | - $network_config->{$setter}($value); |
|
| 3100 | - } else if ( |
|
| 3101 | - property_exists($network_config, $property) |
|
| 3102 | - && $network_config->{$property} !== $value |
|
| 3103 | - ) { |
|
| 3104 | - $network_config->{$property} = $value; |
|
| 3105 | - } else if ( |
|
| 3106 | - property_exists($messages_config, $property) |
|
| 3107 | - && $messages_config->{$property} !== $value |
|
| 3108 | - ) { |
|
| 3109 | - $messages_config->{$property} = $value; |
|
| 3110 | - } |
|
| 3111 | - } |
|
| 3112 | - //only update if the form submission was valid! |
|
| 3113 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3114 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3115 | - EE_Error::overwrite_success(); |
|
| 3116 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3117 | - } |
|
| 3118 | - } |
|
| 3119 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3120 | - } |
|
| 3121 | - |
|
| 3122 | - |
|
| 3123 | - /** |
|
| 3124 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3125 | - * |
|
| 3126 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3127 | - * |
|
| 3128 | - * @return string html formatted tabs |
|
| 3129 | - */ |
|
| 3130 | - protected function _get_mt_tabs($tab_array) |
|
| 3131 | - { |
|
| 3132 | - $tab_array = (array)$tab_array; |
|
| 3133 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3134 | - $tabs = ''; |
|
| 3135 | - |
|
| 3136 | - foreach ($tab_array as $tab) { |
|
| 3137 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3138 | - } |
|
| 3139 | - |
|
| 3140 | - return $tabs; |
|
| 3141 | - } |
|
| 3142 | - |
|
| 3143 | - |
|
| 3144 | - /** |
|
| 3145 | - * This prepares the content of the messenger meta box admin settings |
|
| 3146 | - * |
|
| 3147 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3148 | - * |
|
| 3149 | - * @return string html formatted content |
|
| 3150 | - */ |
|
| 3151 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3152 | - { |
|
| 3153 | - |
|
| 3154 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3155 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3156 | - |
|
| 3157 | - //is $messenger active? |
|
| 3158 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3159 | - |
|
| 3160 | - |
|
| 3161 | - if ( ! empty($fields)) { |
|
| 3067 | + ) |
|
| 3068 | + ), |
|
| 3069 | + 'update_settings' => new EE_Submit_Input( |
|
| 3070 | + array( |
|
| 3071 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3072 | + 'html_label_text' => ' ' |
|
| 3073 | + ) |
|
| 3074 | + ) |
|
| 3075 | + ) |
|
| 3076 | + ) |
|
| 3077 | + ) |
|
| 3078 | + ); |
|
| 3079 | + } |
|
| 3080 | + |
|
| 3081 | + |
|
| 3082 | + /** |
|
| 3083 | + * This handles updating the global settings set on the admin page. |
|
| 3084 | + * @throws \EE_Error |
|
| 3085 | + */ |
|
| 3086 | + protected function _update_global_settings() |
|
| 3087 | + { |
|
| 3088 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3089 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3090 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3091 | + $form = $this->_generate_global_settings_form(); |
|
| 3092 | + if ($form->was_submitted()) { |
|
| 3093 | + $form->receive_form_submission(); |
|
| 3094 | + if ($form->is_valid()) { |
|
| 3095 | + $valid_data = $form->valid_data(); |
|
| 3096 | + foreach ($valid_data as $property => $value) { |
|
| 3097 | + $setter = 'set_' . $property; |
|
| 3098 | + if (method_exists($network_config, $setter)) { |
|
| 3099 | + $network_config->{$setter}($value); |
|
| 3100 | + } else if ( |
|
| 3101 | + property_exists($network_config, $property) |
|
| 3102 | + && $network_config->{$property} !== $value |
|
| 3103 | + ) { |
|
| 3104 | + $network_config->{$property} = $value; |
|
| 3105 | + } else if ( |
|
| 3106 | + property_exists($messages_config, $property) |
|
| 3107 | + && $messages_config->{$property} !== $value |
|
| 3108 | + ) { |
|
| 3109 | + $messages_config->{$property} = $value; |
|
| 3110 | + } |
|
| 3111 | + } |
|
| 3112 | + //only update if the form submission was valid! |
|
| 3113 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3114 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3115 | + EE_Error::overwrite_success(); |
|
| 3116 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3117 | + } |
|
| 3118 | + } |
|
| 3119 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3120 | + } |
|
| 3121 | + |
|
| 3122 | + |
|
| 3123 | + /** |
|
| 3124 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3125 | + * |
|
| 3126 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3127 | + * |
|
| 3128 | + * @return string html formatted tabs |
|
| 3129 | + */ |
|
| 3130 | + protected function _get_mt_tabs($tab_array) |
|
| 3131 | + { |
|
| 3132 | + $tab_array = (array)$tab_array; |
|
| 3133 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3134 | + $tabs = ''; |
|
| 3135 | + |
|
| 3136 | + foreach ($tab_array as $tab) { |
|
| 3137 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3138 | + } |
|
| 3139 | + |
|
| 3140 | + return $tabs; |
|
| 3141 | + } |
|
| 3142 | + |
|
| 3143 | + |
|
| 3144 | + /** |
|
| 3145 | + * This prepares the content of the messenger meta box admin settings |
|
| 3146 | + * |
|
| 3147 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3148 | + * |
|
| 3149 | + * @return string html formatted content |
|
| 3150 | + */ |
|
| 3151 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3152 | + { |
|
| 3153 | + |
|
| 3154 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3155 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3156 | + |
|
| 3157 | + //is $messenger active? |
|
| 3158 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3159 | + |
|
| 3160 | + |
|
| 3161 | + if ( ! empty($fields)) { |
|
| 3162 | 3162 | |
| 3163 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3163 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3164 | 3164 | |
| 3165 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3166 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3167 | - $template_form_field[$field_id] = array( |
|
| 3168 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3169 | - 'label' => $fldprops['label'], |
|
| 3170 | - 'input' => $fldprops['field_type'], |
|
| 3171 | - 'type' => $fldprops['value_type'], |
|
| 3172 | - 'required' => $fldprops['required'], |
|
| 3173 | - 'validation' => $fldprops['validation'], |
|
| 3174 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3175 | - ? $existing_settings[$field_id] |
|
| 3176 | - : $fldprops['default'], |
|
| 3177 | - 'css_class' => '', |
|
| 3178 | - 'format' => $fldprops['format'] |
|
| 3179 | - ); |
|
| 3180 | - } |
|
| 3165 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3166 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3167 | + $template_form_field[$field_id] = array( |
|
| 3168 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3169 | + 'label' => $fldprops['label'], |
|
| 3170 | + 'input' => $fldprops['field_type'], |
|
| 3171 | + 'type' => $fldprops['value_type'], |
|
| 3172 | + 'required' => $fldprops['required'], |
|
| 3173 | + 'validation' => $fldprops['validation'], |
|
| 3174 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3175 | + ? $existing_settings[$field_id] |
|
| 3176 | + : $fldprops['default'], |
|
| 3177 | + 'css_class' => '', |
|
| 3178 | + 'format' => $fldprops['format'] |
|
| 3179 | + ); |
|
| 3180 | + } |
|
| 3181 | 3181 | |
| 3182 | 3182 | |
| 3183 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3184 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3185 | - : ''; |
|
| 3186 | - } |
|
| 3187 | - |
|
| 3188 | - //we also need some hidden fields |
|
| 3189 | - $settings_template_args['hidden_fields'] = array( |
|
| 3190 | - 'messenger_settings[messenger]' => array( |
|
| 3191 | - 'type' => 'hidden', |
|
| 3192 | - 'value' => $messenger->name |
|
| 3193 | - ), |
|
| 3194 | - 'type' => array( |
|
| 3195 | - 'type' => 'hidden', |
|
| 3196 | - 'value' => 'messenger' |
|
| 3197 | - ) |
|
| 3198 | - ); |
|
| 3199 | - |
|
| 3200 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3201 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3202 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3203 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3204 | - 'type' => 'hidden', |
|
| 3205 | - 'value' => $mt |
|
| 3206 | - ); |
|
| 3207 | - } |
|
| 3208 | - } |
|
| 3209 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3210 | - $settings_template_args['hidden_fields'], |
|
| 3211 | - 'array' |
|
| 3212 | - ); |
|
| 3213 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3214 | - |
|
| 3215 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3216 | - $settings_template_args['description'] = $messenger->description; |
|
| 3217 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3218 | - |
|
| 3219 | - |
|
| 3220 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3221 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3222 | - : ' hidden'; |
|
| 3223 | - |
|
| 3224 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3225 | - ? ' hidden' |
|
| 3226 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3227 | - |
|
| 3228 | - |
|
| 3229 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3230 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3231 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3232 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3233 | - $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3234 | - true); |
|
| 3235 | - |
|
| 3236 | - return $content; |
|
| 3237 | - } |
|
| 3238 | - |
|
| 3239 | - |
|
| 3240 | - /** |
|
| 3241 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3242 | - */ |
|
| 3243 | - public function activate_messenger_toggle() |
|
| 3244 | - { |
|
| 3245 | - $success = true; |
|
| 3246 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3247 | - //let's check that we have required data |
|
| 3248 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3249 | - EE_Error::add_error( |
|
| 3250 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3251 | - __FILE__, |
|
| 3252 | - __FUNCTION__, |
|
| 3253 | - __LINE__ |
|
| 3254 | - ); |
|
| 3255 | - $success = false; |
|
| 3256 | - } |
|
| 3257 | - |
|
| 3258 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3259 | - $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3260 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3261 | - |
|
| 3262 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3263 | - |
|
| 3264 | - |
|
| 3265 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3266 | - EE_Error::add_error( |
|
| 3267 | - __( |
|
| 3268 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3269 | - 'event_espresso' |
|
| 3270 | - ), |
|
| 3271 | - __FILE__, |
|
| 3272 | - __FUNCTION__, |
|
| 3273 | - __LINE__ |
|
| 3274 | - ); |
|
| 3275 | - $success = false; |
|
| 3276 | - } |
|
| 3277 | - |
|
| 3278 | - //do check to verify we have a valid status. |
|
| 3279 | - $status = $this->_req_data['status']; |
|
| 3280 | - |
|
| 3281 | - if ($status != 'off' && $status != 'on') { |
|
| 3282 | - EE_Error::add_error( |
|
| 3283 | - sprintf( |
|
| 3284 | - __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3285 | - $this->_req_data['status'] |
|
| 3286 | - ), |
|
| 3287 | - __FILE__, |
|
| 3288 | - __FUNCTION__, |
|
| 3289 | - __LINE__ |
|
| 3290 | - ); |
|
| 3291 | - $success = false; |
|
| 3292 | - } |
|
| 3293 | - |
|
| 3294 | - if ($success) { |
|
| 3295 | - //made it here? Stop dawdling then!! |
|
| 3296 | - $success = $status == 'off' |
|
| 3297 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3298 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3299 | - } |
|
| 3300 | - |
|
| 3301 | - $this->_template_args['success'] = $success; |
|
| 3302 | - |
|
| 3303 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3304 | - $this->_return_json(); |
|
| 3305 | - |
|
| 3306 | - } |
|
| 3307 | - |
|
| 3308 | - |
|
| 3309 | - /** |
|
| 3310 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3311 | - * |
|
| 3312 | - */ |
|
| 3313 | - public function activate_mt_toggle() |
|
| 3314 | - { |
|
| 3315 | - $success = true; |
|
| 3316 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3317 | - |
|
| 3318 | - //let's make sure we have the necessary data |
|
| 3319 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3320 | - EE_Error::add_error( |
|
| 3321 | - __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3322 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3323 | - ); |
|
| 3324 | - $success = false; |
|
| 3325 | - } |
|
| 3326 | - |
|
| 3327 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3328 | - EE_Error::add_error( |
|
| 3329 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3330 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3331 | - ); |
|
| 3332 | - $success = false; |
|
| 3333 | - } |
|
| 3334 | - |
|
| 3335 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3336 | - EE_Error::add_error( |
|
| 3337 | - __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3338 | - 'event_espresso'), |
|
| 3339 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3340 | - ); |
|
| 3341 | - $success = false; |
|
| 3342 | - } |
|
| 3343 | - |
|
| 3344 | - |
|
| 3345 | - //do check to verify we have a valid status. |
|
| 3346 | - $status = $this->_req_data['status']; |
|
| 3347 | - |
|
| 3348 | - if ($status != 'activate' && $status != 'deactivate') { |
|
| 3349 | - EE_Error::add_error( |
|
| 3350 | - sprintf( |
|
| 3351 | - __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3352 | - $this->_req_data['status'] |
|
| 3353 | - ), |
|
| 3354 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3355 | - ); |
|
| 3356 | - $success = false; |
|
| 3357 | - } |
|
| 3358 | - |
|
| 3359 | - |
|
| 3360 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3361 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3362 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3363 | - |
|
| 3364 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3365 | - |
|
| 3366 | - if ($success) { |
|
| 3367 | - //made it here? um, what are you waiting for then? |
|
| 3368 | - $success = $status == 'deactivate' |
|
| 3369 | - ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3370 | - $this->_req_data['message_type']) |
|
| 3371 | - : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3372 | - $this->_req_data['message_type']); |
|
| 3373 | - } |
|
| 3374 | - |
|
| 3375 | - $this->_template_args['success'] = $success; |
|
| 3376 | - $this->_return_json(); |
|
| 3377 | - } |
|
| 3378 | - |
|
| 3379 | - |
|
| 3380 | - /** |
|
| 3381 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3382 | - * |
|
| 3383 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3384 | - * |
|
| 3385 | - * @return bool |
|
| 3386 | - */ |
|
| 3387 | - protected function _activate_messenger($messenger_name) |
|
| 3388 | - { |
|
| 3389 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3390 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3391 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3392 | - |
|
| 3393 | - //ensure is active |
|
| 3394 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3395 | - |
|
| 3396 | - //set response_data for reload |
|
| 3397 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3398 | - /** @var EE_message_type $message_type */ |
|
| 3399 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3400 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3401 | - $message_type_name) |
|
| 3402 | - && $message_type instanceof EE_message_type |
|
| 3403 | - ) { |
|
| 3404 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3405 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3406 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3407 | - } |
|
| 3408 | - } |
|
| 3409 | - } |
|
| 3410 | - |
|
| 3411 | - //add success message for activating messenger |
|
| 3412 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3413 | - |
|
| 3414 | - } |
|
| 3415 | - |
|
| 3416 | - |
|
| 3417 | - /** |
|
| 3418 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3419 | - * |
|
| 3420 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3421 | - * |
|
| 3422 | - * @return bool |
|
| 3423 | - */ |
|
| 3424 | - protected function _deactivate_messenger($messenger_name) |
|
| 3425 | - { |
|
| 3426 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3427 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3428 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3429 | - |
|
| 3430 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3431 | - } |
|
| 3432 | - |
|
| 3433 | - |
|
| 3434 | - /** |
|
| 3435 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3436 | - * |
|
| 3437 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3438 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3439 | - * |
|
| 3440 | - * @return bool |
|
| 3441 | - */ |
|
| 3442 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3443 | - { |
|
| 3444 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3445 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3446 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3447 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3448 | - |
|
| 3449 | - //ensure is active |
|
| 3450 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3451 | - |
|
| 3452 | - //set response for load |
|
| 3453 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3454 | - $message_type_name) |
|
| 3455 | - ) { |
|
| 3456 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3457 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3458 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3459 | - } |
|
| 3460 | - } |
|
| 3461 | - |
|
| 3462 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3463 | - $message_type_to_activate); |
|
| 3464 | - } |
|
| 3465 | - |
|
| 3466 | - |
|
| 3467 | - /** |
|
| 3468 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3469 | - * |
|
| 3470 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3471 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3472 | - * |
|
| 3473 | - * @return bool |
|
| 3474 | - */ |
|
| 3475 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3476 | - { |
|
| 3477 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3478 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3479 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3480 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3481 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3482 | - |
|
| 3483 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3484 | - $message_type_to_deactivate); |
|
| 3485 | - } |
|
| 3486 | - |
|
| 3487 | - |
|
| 3488 | - /** |
|
| 3489 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3490 | - */ |
|
| 3491 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3492 | - { |
|
| 3493 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 3494 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 3495 | - } |
|
| 3496 | - |
|
| 3497 | - |
|
| 3498 | - /** |
|
| 3499 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 3500 | - * |
|
| 3501 | - * @param EE_messenger $messenger |
|
| 3502 | - * @param EE_message_type|null $message_type |
|
| 3503 | - * |
|
| 3504 | - * @return bool |
|
| 3505 | - * @throws EE_Error |
|
| 3506 | - */ |
|
| 3507 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3508 | - $messenger, |
|
| 3509 | - EE_Message_Type $message_type = null |
|
| 3510 | - ) { |
|
| 3511 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3512 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3513 | - EE_Error::add_error( |
|
| 3514 | - __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3515 | - __FILE__, |
|
| 3516 | - __FUNCTION__, |
|
| 3517 | - __LINE__ |
|
| 3518 | - ); |
|
| 3183 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3184 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3185 | + : ''; |
|
| 3186 | + } |
|
| 3187 | + |
|
| 3188 | + //we also need some hidden fields |
|
| 3189 | + $settings_template_args['hidden_fields'] = array( |
|
| 3190 | + 'messenger_settings[messenger]' => array( |
|
| 3191 | + 'type' => 'hidden', |
|
| 3192 | + 'value' => $messenger->name |
|
| 3193 | + ), |
|
| 3194 | + 'type' => array( |
|
| 3195 | + 'type' => 'hidden', |
|
| 3196 | + 'value' => 'messenger' |
|
| 3197 | + ) |
|
| 3198 | + ); |
|
| 3199 | + |
|
| 3200 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3201 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3202 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3203 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3204 | + 'type' => 'hidden', |
|
| 3205 | + 'value' => $mt |
|
| 3206 | + ); |
|
| 3207 | + } |
|
| 3208 | + } |
|
| 3209 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3210 | + $settings_template_args['hidden_fields'], |
|
| 3211 | + 'array' |
|
| 3212 | + ); |
|
| 3213 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3214 | + |
|
| 3215 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3216 | + $settings_template_args['description'] = $messenger->description; |
|
| 3217 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3218 | + |
|
| 3219 | + |
|
| 3220 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3221 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3222 | + : ' hidden'; |
|
| 3223 | + |
|
| 3224 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3225 | + ? ' hidden' |
|
| 3226 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3227 | + |
|
| 3228 | + |
|
| 3229 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3230 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3231 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3232 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3233 | + $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3234 | + true); |
|
| 3235 | + |
|
| 3236 | + return $content; |
|
| 3237 | + } |
|
| 3238 | + |
|
| 3239 | + |
|
| 3240 | + /** |
|
| 3241 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3242 | + */ |
|
| 3243 | + public function activate_messenger_toggle() |
|
| 3244 | + { |
|
| 3245 | + $success = true; |
|
| 3246 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3247 | + //let's check that we have required data |
|
| 3248 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3249 | + EE_Error::add_error( |
|
| 3250 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3251 | + __FILE__, |
|
| 3252 | + __FUNCTION__, |
|
| 3253 | + __LINE__ |
|
| 3254 | + ); |
|
| 3255 | + $success = false; |
|
| 3256 | + } |
|
| 3257 | + |
|
| 3258 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3259 | + $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3260 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3261 | + |
|
| 3262 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3263 | + |
|
| 3264 | + |
|
| 3265 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3266 | + EE_Error::add_error( |
|
| 3267 | + __( |
|
| 3268 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3269 | + 'event_espresso' |
|
| 3270 | + ), |
|
| 3271 | + __FILE__, |
|
| 3272 | + __FUNCTION__, |
|
| 3273 | + __LINE__ |
|
| 3274 | + ); |
|
| 3275 | + $success = false; |
|
| 3276 | + } |
|
| 3277 | + |
|
| 3278 | + //do check to verify we have a valid status. |
|
| 3279 | + $status = $this->_req_data['status']; |
|
| 3280 | + |
|
| 3281 | + if ($status != 'off' && $status != 'on') { |
|
| 3282 | + EE_Error::add_error( |
|
| 3283 | + sprintf( |
|
| 3284 | + __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3285 | + $this->_req_data['status'] |
|
| 3286 | + ), |
|
| 3287 | + __FILE__, |
|
| 3288 | + __FUNCTION__, |
|
| 3289 | + __LINE__ |
|
| 3290 | + ); |
|
| 3291 | + $success = false; |
|
| 3292 | + } |
|
| 3293 | + |
|
| 3294 | + if ($success) { |
|
| 3295 | + //made it here? Stop dawdling then!! |
|
| 3296 | + $success = $status == 'off' |
|
| 3297 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3298 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3299 | + } |
|
| 3300 | + |
|
| 3301 | + $this->_template_args['success'] = $success; |
|
| 3302 | + |
|
| 3303 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3304 | + $this->_return_json(); |
|
| 3305 | + |
|
| 3306 | + } |
|
| 3307 | + |
|
| 3308 | + |
|
| 3309 | + /** |
|
| 3310 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3311 | + * |
|
| 3312 | + */ |
|
| 3313 | + public function activate_mt_toggle() |
|
| 3314 | + { |
|
| 3315 | + $success = true; |
|
| 3316 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3317 | + |
|
| 3318 | + //let's make sure we have the necessary data |
|
| 3319 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3320 | + EE_Error::add_error( |
|
| 3321 | + __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3322 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3323 | + ); |
|
| 3324 | + $success = false; |
|
| 3325 | + } |
|
| 3326 | + |
|
| 3327 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3328 | + EE_Error::add_error( |
|
| 3329 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3330 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3331 | + ); |
|
| 3332 | + $success = false; |
|
| 3333 | + } |
|
| 3334 | + |
|
| 3335 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3336 | + EE_Error::add_error( |
|
| 3337 | + __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3338 | + 'event_espresso'), |
|
| 3339 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3340 | + ); |
|
| 3341 | + $success = false; |
|
| 3342 | + } |
|
| 3343 | + |
|
| 3344 | + |
|
| 3345 | + //do check to verify we have a valid status. |
|
| 3346 | + $status = $this->_req_data['status']; |
|
| 3347 | + |
|
| 3348 | + if ($status != 'activate' && $status != 'deactivate') { |
|
| 3349 | + EE_Error::add_error( |
|
| 3350 | + sprintf( |
|
| 3351 | + __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3352 | + $this->_req_data['status'] |
|
| 3353 | + ), |
|
| 3354 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3355 | + ); |
|
| 3356 | + $success = false; |
|
| 3357 | + } |
|
| 3358 | + |
|
| 3359 | + |
|
| 3360 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3361 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3362 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3363 | + |
|
| 3364 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3365 | + |
|
| 3366 | + if ($success) { |
|
| 3367 | + //made it here? um, what are you waiting for then? |
|
| 3368 | + $success = $status == 'deactivate' |
|
| 3369 | + ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3370 | + $this->_req_data['message_type']) |
|
| 3371 | + : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3372 | + $this->_req_data['message_type']); |
|
| 3373 | + } |
|
| 3374 | + |
|
| 3375 | + $this->_template_args['success'] = $success; |
|
| 3376 | + $this->_return_json(); |
|
| 3377 | + } |
|
| 3378 | + |
|
| 3379 | + |
|
| 3380 | + /** |
|
| 3381 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3382 | + * |
|
| 3383 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3384 | + * |
|
| 3385 | + * @return bool |
|
| 3386 | + */ |
|
| 3387 | + protected function _activate_messenger($messenger_name) |
|
| 3388 | + { |
|
| 3389 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3390 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3391 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3392 | + |
|
| 3393 | + //ensure is active |
|
| 3394 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3395 | + |
|
| 3396 | + //set response_data for reload |
|
| 3397 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3398 | + /** @var EE_message_type $message_type */ |
|
| 3399 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3400 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3401 | + $message_type_name) |
|
| 3402 | + && $message_type instanceof EE_message_type |
|
| 3403 | + ) { |
|
| 3404 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3405 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3406 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3407 | + } |
|
| 3408 | + } |
|
| 3409 | + } |
|
| 3410 | + |
|
| 3411 | + //add success message for activating messenger |
|
| 3412 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3413 | + |
|
| 3414 | + } |
|
| 3415 | + |
|
| 3416 | + |
|
| 3417 | + /** |
|
| 3418 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3419 | + * |
|
| 3420 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3421 | + * |
|
| 3422 | + * @return bool |
|
| 3423 | + */ |
|
| 3424 | + protected function _deactivate_messenger($messenger_name) |
|
| 3425 | + { |
|
| 3426 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3427 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3428 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3429 | + |
|
| 3430 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3431 | + } |
|
| 3432 | + |
|
| 3433 | + |
|
| 3434 | + /** |
|
| 3435 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3436 | + * |
|
| 3437 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3438 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3439 | + * |
|
| 3440 | + * @return bool |
|
| 3441 | + */ |
|
| 3442 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3443 | + { |
|
| 3444 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3445 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3446 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3447 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3448 | + |
|
| 3449 | + //ensure is active |
|
| 3450 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3451 | + |
|
| 3452 | + //set response for load |
|
| 3453 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3454 | + $message_type_name) |
|
| 3455 | + ) { |
|
| 3456 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3457 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3458 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3459 | + } |
|
| 3460 | + } |
|
| 3461 | + |
|
| 3462 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3463 | + $message_type_to_activate); |
|
| 3464 | + } |
|
| 3465 | + |
|
| 3466 | + |
|
| 3467 | + /** |
|
| 3468 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3469 | + * |
|
| 3470 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3471 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3472 | + * |
|
| 3473 | + * @return bool |
|
| 3474 | + */ |
|
| 3475 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3476 | + { |
|
| 3477 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3478 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3479 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3480 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3481 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3482 | + |
|
| 3483 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3484 | + $message_type_to_deactivate); |
|
| 3485 | + } |
|
| 3486 | + |
|
| 3487 | + |
|
| 3488 | + /** |
|
| 3489 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3490 | + */ |
|
| 3491 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3492 | + { |
|
| 3493 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 3494 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 3495 | + } |
|
| 3496 | + |
|
| 3497 | + |
|
| 3498 | + /** |
|
| 3499 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 3500 | + * |
|
| 3501 | + * @param EE_messenger $messenger |
|
| 3502 | + * @param EE_message_type|null $message_type |
|
| 3503 | + * |
|
| 3504 | + * @return bool |
|
| 3505 | + * @throws EE_Error |
|
| 3506 | + */ |
|
| 3507 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3508 | + $messenger, |
|
| 3509 | + EE_Message_Type $message_type = null |
|
| 3510 | + ) { |
|
| 3511 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3512 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3513 | + EE_Error::add_error( |
|
| 3514 | + __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3515 | + __FILE__, |
|
| 3516 | + __FUNCTION__, |
|
| 3517 | + __LINE__ |
|
| 3518 | + ); |
|
| 3519 | 3519 | |
| 3520 | - return false; |
|
| 3521 | - } |
|
| 3522 | - //activated |
|
| 3523 | - if ($this->_template_args['data']['active_mts']) { |
|
| 3524 | - EE_Error::overwrite_success(); |
|
| 3525 | - //activated a message type with the messenger |
|
| 3526 | - if ($message_type instanceof EE_message_type) { |
|
| 3527 | - EE_Error::add_success( |
|
| 3528 | - sprintf( |
|
| 3529 | - __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3530 | - ucwords($message_type->label['singular']), |
|
| 3531 | - ucwords($messenger->label['singular']) |
|
| 3532 | - ) |
|
| 3533 | - ); |
|
| 3520 | + return false; |
|
| 3521 | + } |
|
| 3522 | + //activated |
|
| 3523 | + if ($this->_template_args['data']['active_mts']) { |
|
| 3524 | + EE_Error::overwrite_success(); |
|
| 3525 | + //activated a message type with the messenger |
|
| 3526 | + if ($message_type instanceof EE_message_type) { |
|
| 3527 | + EE_Error::add_success( |
|
| 3528 | + sprintf( |
|
| 3529 | + __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3530 | + ucwords($message_type->label['singular']), |
|
| 3531 | + ucwords($messenger->label['singular']) |
|
| 3532 | + ) |
|
| 3533 | + ); |
|
| 3534 | 3534 | |
| 3535 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3536 | - if ($message_type->name == 'invoice') { |
|
| 3537 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3538 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3539 | - if ($pm instanceof EE_Payment_Method) { |
|
| 3540 | - EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3541 | - 'event_espresso')); |
|
| 3542 | - } |
|
| 3543 | - } |
|
| 3544 | - //just toggles the entire messenger |
|
| 3545 | - } else { |
|
| 3546 | - EE_Error::add_success( |
|
| 3547 | - sprintf( |
|
| 3548 | - __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3549 | - ucwords($messenger->label['singular']) |
|
| 3550 | - ) |
|
| 3551 | - ); |
|
| 3552 | - } |
|
| 3535 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3536 | + if ($message_type->name == 'invoice') { |
|
| 3537 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3538 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3539 | + if ($pm instanceof EE_Payment_Method) { |
|
| 3540 | + EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3541 | + 'event_espresso')); |
|
| 3542 | + } |
|
| 3543 | + } |
|
| 3544 | + //just toggles the entire messenger |
|
| 3545 | + } else { |
|
| 3546 | + EE_Error::add_success( |
|
| 3547 | + sprintf( |
|
| 3548 | + __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3549 | + ucwords($messenger->label['singular']) |
|
| 3550 | + ) |
|
| 3551 | + ); |
|
| 3552 | + } |
|
| 3553 | 3553 | |
| 3554 | - return true; |
|
| 3554 | + return true; |
|
| 3555 | 3555 | |
| 3556 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3557 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3558 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 3559 | - } else { |
|
| 3560 | - if ( ! $messenger->get_default_message_types()) { |
|
| 3561 | - //messenger doesn't have any default message types so still a success. |
|
| 3562 | - EE_Error::add_success( |
|
| 3563 | - sprintf( |
|
| 3564 | - __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3565 | - ucwords($messenger->label['singular']) |
|
| 3566 | - ) |
|
| 3567 | - ); |
|
| 3556 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3557 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3558 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 3559 | + } else { |
|
| 3560 | + if ( ! $messenger->get_default_message_types()) { |
|
| 3561 | + //messenger doesn't have any default message types so still a success. |
|
| 3562 | + EE_Error::add_success( |
|
| 3563 | + sprintf( |
|
| 3564 | + __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3565 | + ucwords($messenger->label['singular']) |
|
| 3566 | + ) |
|
| 3567 | + ); |
|
| 3568 | 3568 | |
| 3569 | - return true; |
|
| 3570 | - } else { |
|
| 3571 | - EE_Error::add_error( |
|
| 3572 | - $message_type instanceof EE_message_type |
|
| 3573 | - ? sprintf( |
|
| 3574 | - __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3575 | - ucwords($message_type->label['singular']), |
|
| 3576 | - ucwords($messenger->label['singular']) |
|
| 3577 | - ) |
|
| 3578 | - : sprintf( |
|
| 3579 | - __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3580 | - ucwords($messenger->label['singular']) |
|
| 3581 | - ), |
|
| 3582 | - __FILE__, |
|
| 3583 | - __FUNCTION__, |
|
| 3584 | - __LINE__ |
|
| 3585 | - ); |
|
| 3569 | + return true; |
|
| 3570 | + } else { |
|
| 3571 | + EE_Error::add_error( |
|
| 3572 | + $message_type instanceof EE_message_type |
|
| 3573 | + ? sprintf( |
|
| 3574 | + __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3575 | + ucwords($message_type->label['singular']), |
|
| 3576 | + ucwords($messenger->label['singular']) |
|
| 3577 | + ) |
|
| 3578 | + : sprintf( |
|
| 3579 | + __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3580 | + ucwords($messenger->label['singular']) |
|
| 3581 | + ), |
|
| 3582 | + __FILE__, |
|
| 3583 | + __FUNCTION__, |
|
| 3584 | + __LINE__ |
|
| 3585 | + ); |
|
| 3586 | 3586 | |
| 3587 | - return false; |
|
| 3588 | - } |
|
| 3589 | - } |
|
| 3590 | - } |
|
| 3591 | - |
|
| 3592 | - |
|
| 3593 | - /** |
|
| 3594 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3595 | - * |
|
| 3596 | - * @param EE_messenger $messenger |
|
| 3597 | - * @param EE_message_type|null $message_type |
|
| 3598 | - * |
|
| 3599 | - * @return bool |
|
| 3600 | - */ |
|
| 3601 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3602 | - $messenger, |
|
| 3603 | - EE_message_type $message_type = null |
|
| 3604 | - ) { |
|
| 3605 | - EE_Error::overwrite_success(); |
|
| 3606 | - |
|
| 3607 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3608 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3609 | - EE_Error::add_error( |
|
| 3610 | - __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3611 | - __FILE__, |
|
| 3612 | - __FUNCTION__, |
|
| 3613 | - __LINE__ |
|
| 3614 | - ); |
|
| 3587 | + return false; |
|
| 3588 | + } |
|
| 3589 | + } |
|
| 3590 | + } |
|
| 3591 | + |
|
| 3592 | + |
|
| 3593 | + /** |
|
| 3594 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3595 | + * |
|
| 3596 | + * @param EE_messenger $messenger |
|
| 3597 | + * @param EE_message_type|null $message_type |
|
| 3598 | + * |
|
| 3599 | + * @return bool |
|
| 3600 | + */ |
|
| 3601 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3602 | + $messenger, |
|
| 3603 | + EE_message_type $message_type = null |
|
| 3604 | + ) { |
|
| 3605 | + EE_Error::overwrite_success(); |
|
| 3606 | + |
|
| 3607 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3608 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3609 | + EE_Error::add_error( |
|
| 3610 | + __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3611 | + __FILE__, |
|
| 3612 | + __FUNCTION__, |
|
| 3613 | + __LINE__ |
|
| 3614 | + ); |
|
| 3615 | 3615 | |
| 3616 | - return false; |
|
| 3617 | - } |
|
| 3618 | - |
|
| 3619 | - if ($message_type instanceof EE_message_type) { |
|
| 3620 | - $message_type_name = $message_type->name; |
|
| 3621 | - EE_Error::add_success( |
|
| 3622 | - sprintf( |
|
| 3623 | - __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3624 | - ucwords($message_type->label['singular']), |
|
| 3625 | - ucwords($messenger->label['singular']) |
|
| 3626 | - ) |
|
| 3627 | - ); |
|
| 3628 | - } else { |
|
| 3629 | - $message_type_name = ''; |
|
| 3630 | - EE_Error::add_success( |
|
| 3631 | - sprintf( |
|
| 3632 | - __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3633 | - ucwords($messenger->label['singular']) |
|
| 3634 | - ) |
|
| 3635 | - ); |
|
| 3636 | - } |
|
| 3637 | - |
|
| 3638 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3639 | - if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3640 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3641 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3642 | - if ($count_updated > 0) { |
|
| 3643 | - $msg = $message_type_name == 'invoice' |
|
| 3644 | - ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3645 | - 'event_espresso') |
|
| 3646 | - : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3647 | - 'event_espresso'); |
|
| 3648 | - EE_Error::add_attention($msg); |
|
| 3649 | - } |
|
| 3650 | - } |
|
| 3651 | - |
|
| 3652 | - return true; |
|
| 3653 | - } |
|
| 3654 | - |
|
| 3655 | - |
|
| 3656 | - /** |
|
| 3657 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3658 | - */ |
|
| 3659 | - public function update_mt_form() |
|
| 3660 | - { |
|
| 3661 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3662 | - EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3663 | - __LINE__); |
|
| 3664 | - $this->_return_json(); |
|
| 3665 | - } |
|
| 3666 | - |
|
| 3667 | - $message_types = $this->get_installed_message_types(); |
|
| 3668 | - |
|
| 3669 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3670 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3671 | - |
|
| 3672 | - $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3673 | - $this->_template_args['success'] = true; |
|
| 3674 | - $this->_template_args['content'] = $content; |
|
| 3675 | - $this->_return_json(); |
|
| 3676 | - } |
|
| 3677 | - |
|
| 3678 | - |
|
| 3679 | - /** |
|
| 3680 | - * this handles saving the settings for a messenger or message type |
|
| 3681 | - * |
|
| 3682 | - */ |
|
| 3683 | - public function save_settings() |
|
| 3684 | - { |
|
| 3685 | - if ( ! isset($this->_req_data['type'])) { |
|
| 3686 | - EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3687 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3688 | - $this->_template_args['error'] = true; |
|
| 3689 | - $this->_return_json(); |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - |
|
| 3693 | - if ($this->_req_data['type'] == 'messenger') { |
|
| 3694 | - $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3695 | - $messenger = $settings['messenger']; |
|
| 3696 | - //let's setup the settings data |
|
| 3697 | - foreach ($settings as $key => $value) { |
|
| 3698 | - switch ($key) { |
|
| 3699 | - case 'messenger' : |
|
| 3700 | - unset($settings['messenger']); |
|
| 3701 | - break; |
|
| 3702 | - case 'message_types' : |
|
| 3703 | - unset($settings['message_types']); |
|
| 3704 | - break; |
|
| 3705 | - default : |
|
| 3706 | - $settings[$key] = $value; |
|
| 3707 | - break; |
|
| 3708 | - } |
|
| 3709 | - } |
|
| 3710 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3711 | - } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3712 | - $settings = $this->_req_data['message_type_settings']; |
|
| 3713 | - $messenger = $settings['messenger']; |
|
| 3714 | - $message_type = $settings['message_type']; |
|
| 3616 | + return false; |
|
| 3617 | + } |
|
| 3618 | + |
|
| 3619 | + if ($message_type instanceof EE_message_type) { |
|
| 3620 | + $message_type_name = $message_type->name; |
|
| 3621 | + EE_Error::add_success( |
|
| 3622 | + sprintf( |
|
| 3623 | + __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3624 | + ucwords($message_type->label['singular']), |
|
| 3625 | + ucwords($messenger->label['singular']) |
|
| 3626 | + ) |
|
| 3627 | + ); |
|
| 3628 | + } else { |
|
| 3629 | + $message_type_name = ''; |
|
| 3630 | + EE_Error::add_success( |
|
| 3631 | + sprintf( |
|
| 3632 | + __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3633 | + ucwords($messenger->label['singular']) |
|
| 3634 | + ) |
|
| 3635 | + ); |
|
| 3636 | + } |
|
| 3637 | + |
|
| 3638 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3639 | + if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3640 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3641 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3642 | + if ($count_updated > 0) { |
|
| 3643 | + $msg = $message_type_name == 'invoice' |
|
| 3644 | + ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3645 | + 'event_espresso') |
|
| 3646 | + : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3647 | + 'event_espresso'); |
|
| 3648 | + EE_Error::add_attention($msg); |
|
| 3649 | + } |
|
| 3650 | + } |
|
| 3651 | + |
|
| 3652 | + return true; |
|
| 3653 | + } |
|
| 3654 | + |
|
| 3655 | + |
|
| 3656 | + /** |
|
| 3657 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3658 | + */ |
|
| 3659 | + public function update_mt_form() |
|
| 3660 | + { |
|
| 3661 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3662 | + EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3663 | + __LINE__); |
|
| 3664 | + $this->_return_json(); |
|
| 3665 | + } |
|
| 3666 | + |
|
| 3667 | + $message_types = $this->get_installed_message_types(); |
|
| 3668 | + |
|
| 3669 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3670 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3671 | + |
|
| 3672 | + $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3673 | + $this->_template_args['success'] = true; |
|
| 3674 | + $this->_template_args['content'] = $content; |
|
| 3675 | + $this->_return_json(); |
|
| 3676 | + } |
|
| 3677 | + |
|
| 3678 | + |
|
| 3679 | + /** |
|
| 3680 | + * this handles saving the settings for a messenger or message type |
|
| 3681 | + * |
|
| 3682 | + */ |
|
| 3683 | + public function save_settings() |
|
| 3684 | + { |
|
| 3685 | + if ( ! isset($this->_req_data['type'])) { |
|
| 3686 | + EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3687 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3688 | + $this->_template_args['error'] = true; |
|
| 3689 | + $this->_return_json(); |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + |
|
| 3693 | + if ($this->_req_data['type'] == 'messenger') { |
|
| 3694 | + $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3695 | + $messenger = $settings['messenger']; |
|
| 3696 | + //let's setup the settings data |
|
| 3697 | + foreach ($settings as $key => $value) { |
|
| 3698 | + switch ($key) { |
|
| 3699 | + case 'messenger' : |
|
| 3700 | + unset($settings['messenger']); |
|
| 3701 | + break; |
|
| 3702 | + case 'message_types' : |
|
| 3703 | + unset($settings['message_types']); |
|
| 3704 | + break; |
|
| 3705 | + default : |
|
| 3706 | + $settings[$key] = $value; |
|
| 3707 | + break; |
|
| 3708 | + } |
|
| 3709 | + } |
|
| 3710 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3711 | + } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3712 | + $settings = $this->_req_data['message_type_settings']; |
|
| 3713 | + $messenger = $settings['messenger']; |
|
| 3714 | + $message_type = $settings['message_type']; |
|
| 3715 | 3715 | |
| 3716 | - foreach ($settings as $key => $value) { |
|
| 3717 | - switch ($key) { |
|
| 3718 | - case 'messenger' : |
|
| 3719 | - unset($settings['messenger']); |
|
| 3720 | - break; |
|
| 3721 | - case 'message_type' : |
|
| 3722 | - unset($settings['message_type']); |
|
| 3723 | - break; |
|
| 3724 | - default : |
|
| 3725 | - $settings[$key] = $value; |
|
| 3726 | - break; |
|
| 3727 | - } |
|
| 3728 | - } |
|
| 3716 | + foreach ($settings as $key => $value) { |
|
| 3717 | + switch ($key) { |
|
| 3718 | + case 'messenger' : |
|
| 3719 | + unset($settings['messenger']); |
|
| 3720 | + break; |
|
| 3721 | + case 'message_type' : |
|
| 3722 | + unset($settings['message_type']); |
|
| 3723 | + break; |
|
| 3724 | + default : |
|
| 3725 | + $settings[$key] = $value; |
|
| 3726 | + break; |
|
| 3727 | + } |
|
| 3728 | + } |
|
| 3729 | 3729 | |
| 3730 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3731 | - } |
|
| 3732 | - |
|
| 3733 | - //okay we should have the data all setup. Now we just update! |
|
| 3734 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3735 | - |
|
| 3736 | - if ($success) { |
|
| 3737 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3738 | - } else { |
|
| 3739 | - EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3740 | - } |
|
| 3741 | - |
|
| 3742 | - $this->_template_args['success'] = $success; |
|
| 3743 | - $this->_return_json(); |
|
| 3744 | - } |
|
| 3745 | - |
|
| 3746 | - |
|
| 3747 | - |
|
| 3748 | - |
|
| 3749 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3750 | - |
|
| 3751 | - |
|
| 3752 | - /** |
|
| 3753 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3754 | - * However, this does not send immediately, it just queues for sending. |
|
| 3755 | - * |
|
| 3756 | - * @since 4.9.0 |
|
| 3757 | - */ |
|
| 3758 | - protected function _generate_now() |
|
| 3759 | - { |
|
| 3760 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3761 | - EED_Messages::generate_now($msg_ids); |
|
| 3762 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3763 | - } |
|
| 3764 | - |
|
| 3765 | - |
|
| 3766 | - /** |
|
| 3767 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3768 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3769 | - * |
|
| 3770 | - * @since 4.9.0 |
|
| 3771 | - * |
|
| 3772 | - */ |
|
| 3773 | - protected function _generate_and_send_now() |
|
| 3774 | - { |
|
| 3775 | - $this->_generate_now(); |
|
| 3776 | - $this->_send_now(); |
|
| 3777 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3778 | - } |
|
| 3779 | - |
|
| 3780 | - |
|
| 3781 | - /** |
|
| 3782 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3783 | - * |
|
| 3784 | - * @since 4.9.0 |
|
| 3785 | - */ |
|
| 3786 | - protected function _queue_for_resending() |
|
| 3787 | - { |
|
| 3788 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3789 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 3790 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3791 | - } |
|
| 3792 | - |
|
| 3793 | - |
|
| 3794 | - /** |
|
| 3795 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3796 | - * |
|
| 3797 | - * @since 4.9.0 |
|
| 3798 | - */ |
|
| 3799 | - protected function _send_now() |
|
| 3800 | - { |
|
| 3801 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3802 | - EED_Messages::send_now($msg_ids); |
|
| 3803 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3804 | - } |
|
| 3805 | - |
|
| 3806 | - |
|
| 3807 | - /** |
|
| 3808 | - * Deletes EE_messages for IDs in the request. |
|
| 3809 | - * |
|
| 3810 | - * @since 4.9.0 |
|
| 3811 | - */ |
|
| 3812 | - protected function _delete_ee_messages() |
|
| 3813 | - { |
|
| 3814 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3815 | - $deleted_count = 0; |
|
| 3816 | - foreach ($msg_ids as $msg_id) { |
|
| 3817 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3818 | - $deleted_count++; |
|
| 3819 | - } |
|
| 3820 | - } |
|
| 3821 | - if ($deleted_count) { |
|
| 3822 | - $this->_redirect_after_action( |
|
| 3823 | - true, |
|
| 3824 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3825 | - __('deleted', 'event_espresso') |
|
| 3826 | - ); |
|
| 3827 | - } else { |
|
| 3828 | - EE_Error::add_error( |
|
| 3829 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3830 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3831 | - ); |
|
| 3832 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3833 | - } |
|
| 3834 | - } |
|
| 3835 | - |
|
| 3836 | - |
|
| 3837 | - /** |
|
| 3838 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3839 | - * @since 4.9.0 |
|
| 3840 | - * @return array |
|
| 3841 | - */ |
|
| 3842 | - protected function _get_msg_ids_from_request() |
|
| 3843 | - { |
|
| 3844 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3845 | - return array(); |
|
| 3846 | - } |
|
| 3847 | - |
|
| 3848 | - return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3849 | - } |
|
| 3730 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3731 | + } |
|
| 3732 | + |
|
| 3733 | + //okay we should have the data all setup. Now we just update! |
|
| 3734 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3735 | + |
|
| 3736 | + if ($success) { |
|
| 3737 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3738 | + } else { |
|
| 3739 | + EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3740 | + } |
|
| 3741 | + |
|
| 3742 | + $this->_template_args['success'] = $success; |
|
| 3743 | + $this->_return_json(); |
|
| 3744 | + } |
|
| 3745 | + |
|
| 3746 | + |
|
| 3747 | + |
|
| 3748 | + |
|
| 3749 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3750 | + |
|
| 3751 | + |
|
| 3752 | + /** |
|
| 3753 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3754 | + * However, this does not send immediately, it just queues for sending. |
|
| 3755 | + * |
|
| 3756 | + * @since 4.9.0 |
|
| 3757 | + */ |
|
| 3758 | + protected function _generate_now() |
|
| 3759 | + { |
|
| 3760 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3761 | + EED_Messages::generate_now($msg_ids); |
|
| 3762 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3763 | + } |
|
| 3764 | + |
|
| 3765 | + |
|
| 3766 | + /** |
|
| 3767 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3768 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3769 | + * |
|
| 3770 | + * @since 4.9.0 |
|
| 3771 | + * |
|
| 3772 | + */ |
|
| 3773 | + protected function _generate_and_send_now() |
|
| 3774 | + { |
|
| 3775 | + $this->_generate_now(); |
|
| 3776 | + $this->_send_now(); |
|
| 3777 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3778 | + } |
|
| 3779 | + |
|
| 3780 | + |
|
| 3781 | + /** |
|
| 3782 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3783 | + * |
|
| 3784 | + * @since 4.9.0 |
|
| 3785 | + */ |
|
| 3786 | + protected function _queue_for_resending() |
|
| 3787 | + { |
|
| 3788 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3789 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 3790 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3791 | + } |
|
| 3792 | + |
|
| 3793 | + |
|
| 3794 | + /** |
|
| 3795 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3796 | + * |
|
| 3797 | + * @since 4.9.0 |
|
| 3798 | + */ |
|
| 3799 | + protected function _send_now() |
|
| 3800 | + { |
|
| 3801 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3802 | + EED_Messages::send_now($msg_ids); |
|
| 3803 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3804 | + } |
|
| 3805 | + |
|
| 3806 | + |
|
| 3807 | + /** |
|
| 3808 | + * Deletes EE_messages for IDs in the request. |
|
| 3809 | + * |
|
| 3810 | + * @since 4.9.0 |
|
| 3811 | + */ |
|
| 3812 | + protected function _delete_ee_messages() |
|
| 3813 | + { |
|
| 3814 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3815 | + $deleted_count = 0; |
|
| 3816 | + foreach ($msg_ids as $msg_id) { |
|
| 3817 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3818 | + $deleted_count++; |
|
| 3819 | + } |
|
| 3820 | + } |
|
| 3821 | + if ($deleted_count) { |
|
| 3822 | + $this->_redirect_after_action( |
|
| 3823 | + true, |
|
| 3824 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3825 | + __('deleted', 'event_espresso') |
|
| 3826 | + ); |
|
| 3827 | + } else { |
|
| 3828 | + EE_Error::add_error( |
|
| 3829 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3830 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3831 | + ); |
|
| 3832 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3833 | + } |
|
| 3834 | + } |
|
| 3835 | + |
|
| 3836 | + |
|
| 3837 | + /** |
|
| 3838 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3839 | + * @since 4.9.0 |
|
| 3840 | + * @return array |
|
| 3841 | + */ |
|
| 3842 | + protected function _get_msg_ids_from_request() |
|
| 3843 | + { |
|
| 3844 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3845 | + return array(); |
|
| 3846 | + } |
|
| 3847 | + |
|
| 3848 | + return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3849 | + } |
|
| 3850 | 3850 | |
| 3851 | 3851 | |
| 3852 | 3852 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 88 | 88 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 89 | 89 | |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 91 | 91 | |
| 92 | 92 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 93 | 93 | $this->_load_message_resource_manager(); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | array('none_selected' => __('Show All Messengers', 'event_espresso')), |
| 220 | 220 | $messenger_options |
| 221 | 221 | ); |
| 222 | - $input = new EE_Select_Input( |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | 223 | $messenger_options, |
| 224 | 224 | array( |
| 225 | 225 | 'html_name' => 'ee_messenger_filter_by', |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | array('none_selected' => __('Show All Message Types', 'event_espresso')), |
| 258 | 258 | $message_type_options |
| 259 | 259 | ); |
| 260 | - $input = new EE_Select_Input( |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | 261 | $message_type_options, |
| 262 | 262 | array( |
| 263 | 263 | 'html_name' => 'ee_message_type_filter_by', |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | array('none_selected' => __('Show all Contexts', 'event_espresso')), |
| 296 | 296 | $context_options |
| 297 | 297 | ); |
| 298 | - $input = new EE_Select_Input( |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | 299 | $context_options, |
| 300 | 300 | array( |
| 301 | 301 | 'html_name' => 'ee_context_filter_by', |
@@ -676,47 +676,47 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | public function messages_help_tab() |
| 678 | 678 | { |
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | public function messengers_help_tab() |
| 684 | 684 | { |
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | public function message_types_help_tab() |
| 690 | 690 | { |
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | public function messages_overview_help_tab() |
| 696 | 696 | { |
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | public function message_templates_help_tab() |
| 702 | 702 | { |
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | public function edit_message_template_help_tab() |
| 708 | 708 | { |
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 709 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso').'" />'; |
|
| 711 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso').'" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso').'" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso').'" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso').'" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | 720 | $args); |
| 721 | 721 | } |
| 722 | 722 | |
@@ -725,37 +725,37 @@ discard block |
||
| 725 | 725 | { |
| 726 | 726 | $this->_set_shortcodes(); |
| 727 | 727 | $args['shortcodes'] = $this->_shortcodes; |
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | 729 | $args); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | public function preview_message_help_tab() |
| 734 | 734 | { |
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | public function settings_help_tab() |
| 740 | 740 | { |
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso').'" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso').'" />'; |
|
| 745 | 745 | $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
| 746 | 746 | $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | public function load_scripts_styles() |
| 752 | 752 | { |
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | 754 | wp_enqueue_style('espresso_ee_msg'); |
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 757 | 757 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 759 | 759 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 760 | 760 | } |
| 761 | 761 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | |
| 788 | 788 | $this->_set_shortcodes(); |
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | 791 | __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
| 792 | 792 | 'event_espresso'), |
| 793 | 793 | $this->_message_template_group->messenger_obj()->label['singular'], |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
| 797 | 797 | 'event_espresso'); |
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'), |
|
| 800 | 800 | EVENT_ESPRESSO_VERSION); |
| 801 | 801 | |
| 802 | 802 | wp_enqueue_script('ee_admin_js'); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | public function load_scripts_styles_settings() |
| 829 | 829 | { |
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(), |
|
| 831 | 831 | EVENT_ESPRESSO_VERSION); |
| 832 | 832 | wp_enqueue_style('ee-text-links'); |
| 833 | 833 | wp_enqueue_style('ee-message-settings'); |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | } |
| 894 | 894 | $status_bulk_actions = $common_bulk_actions; |
| 895 | 895 | //unset bulk actions not applying to status |
| 896 | - if (! empty($status_bulk_actions)) { |
|
| 896 | + if ( ! empty($status_bulk_actions)) { |
|
| 897 | 897 | switch ($status) { |
| 898 | 898 | case EEM_Message::status_idle: |
| 899 | 899 | case EEM_Message::status_resend: |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | //skip adding messenger executing status to views because it will be included with the Failed view. |
| 921 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 921 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | 924 | |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
| 945 | 945 | $this->_template_args['per_column'] = 6; |
| 946 | 946 | $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 947 | + $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>'; |
|
| 948 | 948 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 949 | 949 | } |
| 950 | 950 | |
@@ -968,37 +968,37 @@ discard block |
||
| 968 | 968 | /** @type array $status_items status legend setup */ |
| 969 | 969 | $status_items = array( |
| 970 | 970 | 'sent_status' => array( |
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 971 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 972 | 972 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 973 | 973 | ), |
| 974 | 974 | 'idle_status' => array( |
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 975 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 976 | 976 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 977 | 977 | ), |
| 978 | 978 | 'failed_status' => array( |
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 979 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 980 | 980 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 981 | 981 | ), |
| 982 | 982 | 'messenger_executing_status' => array( |
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 983 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 984 | 984 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
| 985 | 985 | ), |
| 986 | 986 | 'resend_status' => array( |
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 987 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 988 | 988 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 989 | 989 | ), |
| 990 | 990 | 'incomplete_status' => array( |
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 992 | 992 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 993 | 993 | ), |
| 994 | 994 | 'retry_status' => array( |
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 995 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 996 | 996 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 997 | 997 | ) |
| 998 | 998 | ); |
| 999 | 999 | if (EEM_Message::debug()) { |
| 1000 | 1000 | $status_items['debug_only_status'] = array( |
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1002 | 1002 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 1003 | 1003 | ); |
| 1004 | 1004 | } |
@@ -1010,10 +1010,10 @@ discard block |
||
| 1010 | 1010 | protected function _custom_mtps_preview() |
| 1011 | 1011 | { |
| 1012 | 1012 | $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
| 1013 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | - 'event_espresso') . '" />'; |
|
| 1015 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | - 'event_espresso') . '</strong>'; |
|
| 1013 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | + 'event_espresso').'" />'; |
|
| 1015 | + $this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | + 'event_espresso').'</strong>'; |
|
| 1017 | 1017 | $this->display_admin_caf_preview_page('custom_message_types', false); |
| 1018 | 1018 | } |
| 1019 | 1019 | |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1262 | 1262 | $continue = false; |
| 1263 | 1263 | if (isset($extra_array['shortcodes_required'])) { |
| 1264 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1264 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | 1265 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1266 | 1266 | $continue = true; |
| 1267 | 1267 | } |
@@ -1271,9 +1271,9 @@ discard block |
||
| 1271 | 1271 | } |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1274 | + $field_id = $reference_field.'-'.$extra_field.'-content'; |
|
| 1275 | 1275 | $template_form_fields[$field_id] = $extra_array; |
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']'; |
|
| 1277 | 1277 | $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
| 1278 | 1278 | |
| 1279 | 1279 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | is_array($validators[$extra_field]) |
| 1284 | 1284 | && isset($validators[$extra_field]['msg']) |
| 1285 | 1285 | ) |
| 1286 | - ? 'validate-error ' . $css_class |
|
| 1286 | + ? 'validate-error '.$css_class |
|
| 1287 | 1287 | : $css_class; |
| 1288 | 1288 | |
| 1289 | 1289 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
@@ -1311,11 +1311,11 @@ discard block |
||
| 1311 | 1311 | |
| 1312 | 1312 | }/**/ |
| 1313 | 1313 | } |
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1314 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1315 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1316 | 1316 | |
| 1317 | 1317 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1318 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1319 | 1319 | 'label' => null, |
| 1320 | 1320 | 'input' => 'hidden', |
| 1321 | 1321 | 'type' => 'int', |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | ); |
| 1329 | 1329 | |
| 1330 | 1330 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1331 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1332 | 1332 | 'label' => null, |
| 1333 | 1333 | 'input' => 'hidden', |
| 1334 | 1334 | 'type' => 'string', |
@@ -1342,9 +1342,9 @@ discard block |
||
| 1342 | 1342 | } |
| 1343 | 1343 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1344 | 1344 | } else { |
| 1345 | - $field_id = $template_field . '-content'; |
|
| 1345 | + $field_id = $template_field.'-content'; |
|
| 1346 | 1346 | $template_form_fields[$field_id] = $field_setup_array; |
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1348 | 1348 | $message_template = isset($message_templates[$context][$template_field]) |
| 1349 | 1349 | ? $message_templates[$context][$template_field] |
| 1350 | 1350 | : null; |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1366 | 1366 | && in_array($template_field, $v_fields) |
| 1367 | 1367 | && isset($validators[$template_field]['msg']) |
| 1368 | - ? 'validate-error ' . $css_class |
|
| 1368 | + ? 'validate-error '.$css_class |
|
| 1369 | 1369 | : $css_class; |
| 1370 | 1370 | |
| 1371 | 1371 | //shortcode selector |
@@ -1376,12 +1376,12 @@ discard block |
||
| 1376 | 1376 | |
| 1377 | 1377 | //k took care of content field(s) now let's take care of others. |
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1379 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1380 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1381 | 1381 | |
| 1382 | 1382 | //foreach template field there are actually two form fields created |
| 1383 | 1383 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1384 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1385 | 1385 | 'label' => null, |
| 1386 | 1386 | 'input' => 'hidden', |
| 1387 | 1387 | 'type' => 'int', |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | ); |
| 1395 | 1395 | |
| 1396 | 1396 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1397 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1398 | 1398 | 'label' => null, |
| 1399 | 1399 | 'input' => 'hidden', |
| 1400 | 1400 | 'type' => 'string', |
@@ -1512,7 +1512,7 @@ discard block |
||
| 1512 | 1512 | 'format' => '%d', |
| 1513 | 1513 | 'db-col' => 'MTP_deleted' |
| 1514 | 1514 | ); |
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | 1516 | 'name' => 'MTP_user_id', |
| 1517 | 1517 | 'label' => __('Author', 'event_espresso'), |
| 1518 | 1518 | 'input' => 'hidden', |
@@ -1531,17 +1531,17 @@ discard block |
||
| 1531 | 1531 | 'value' => $action |
| 1532 | 1532 | ); |
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | 1535 | 'name' => 'id', |
| 1536 | 1536 | 'input' => 'hidden', |
| 1537 | 1537 | 'type' => 'int', |
| 1538 | 1538 | 'value' => $GRP_ID |
| 1539 | 1539 | ); |
| 1540 | 1540 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1541 | - 'name' => $action . '_nonce', |
|
| 1541 | + 'name' => $action.'_nonce', |
|
| 1542 | 1542 | 'input' => 'hidden', |
| 1543 | 1543 | 'type' => 'string', |
| 1544 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1544 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1545 | 1545 | ); |
| 1546 | 1546 | |
| 1547 | 1547 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1573,7 +1573,7 @@ discard block |
||
| 1573 | 1573 | ); |
| 1574 | 1574 | |
| 1575 | 1575 | //add preview button |
| 1576 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1576 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | 1577 | array( |
| 1578 | 1578 | 'message_type' => $message_template_group->message_type(), |
| 1579 | 1579 | 'messenger' => $message_template_group->messenger(), |
@@ -1583,8 +1583,8 @@ discard block |
||
| 1583 | 1583 | ), |
| 1584 | 1584 | $this->_admin_base_url |
| 1585 | 1585 | ); |
| 1586 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | - 'event_espresso') . '</a>'; |
|
| 1586 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview', |
|
| 1587 | + 'event_espresso').'</a>'; |
|
| 1588 | 1588 | |
| 1589 | 1589 | |
| 1590 | 1590 | //setup context switcher |
@@ -1613,7 +1613,7 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1615 | 1615 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1616 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | 1617 | |
| 1618 | 1618 | //send along EE_Message_Template_Group object for further template use. |
| 1619 | 1619 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | |
| 1649 | 1649 | public function _add_form_element_before() |
| 1650 | 1650 | { |
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1651 | + return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">'; |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | public function _add_form_element_after() |
@@ -1843,14 +1843,14 @@ discard block |
||
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | //let's add a button to go back to the edit view |
| 1846 | - $query_args = array( |
|
| 1846 | + $query_args = array( |
|
| 1847 | 1847 | 'id' => $this->_req_data['GRP_ID'], |
| 1848 | 1848 | 'context' => $this->_req_data['context'], |
| 1849 | 1849 | 'action' => 'edit_message_template' |
| 1850 | 1850 | ); |
| 1851 | 1851 | $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
| 1852 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | - 'event_espresso') . '</a>'; |
|
| 1852 | + $preview_button = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit', |
|
| 1853 | + 'event_espresso').'</a>'; |
|
| 1854 | 1854 | $message_types = $this->get_installed_message_types(); |
| 1855 | 1855 | $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 1856 | 1856 | $active_messenger_label = $active_messenger instanceof EE_messenger |
@@ -1864,7 +1864,7 @@ discard block |
||
| 1864 | 1864 | ); |
| 1865 | 1865 | //setup display of preview. |
| 1866 | 1866 | $this->_admin_page_title = $preview_title; |
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 1868 | 1868 | $this->_template_args['data']['force_json'] = true; |
| 1869 | 1869 | |
| 1870 | 1870 | return ''; |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | //setup variation select values for the currently selected template. |
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | 1950 | $this->_message_template_group->messenger(), |
| 1951 | 1951 | $this->_message_template_group->message_type() |
| 1952 | 1952 | ); |
@@ -1960,12 +1960,12 @@ discard block |
||
| 1960 | 1960 | |
| 1961 | 1961 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 1962 | 1962 | |
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | 1964 | 'MTP_template_pack', |
| 1965 | 1965 | $tp_select_values, |
| 1966 | 1966 | $this->_message_template_group->get_template_pack_name() |
| 1967 | 1967 | ); |
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | 1969 | 'MTP_template_variation', |
| 1970 | 1970 | $variations_select_values, |
| 1971 | 1971 | $this->_message_template_group->get_template_pack_variation() |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 1976 | 1976 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 1977 | 1977 | |
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1978 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | 1979 | |
| 1980 | 1980 | EEH_Template::display_template($template, $template_args); |
| 1981 | 1981 | } |
@@ -2004,7 +2004,7 @@ discard block |
||
| 2004 | 2004 | if ( ! empty($fields)) { |
| 2005 | 2005 | //yup there be fields |
| 2006 | 2006 | foreach ($fields as $field => $config) { |
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2007 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2008 | 2008 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2009 | 2009 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2010 | 2010 | $default = isset($config['value']) ? $config['value'] : $default; |
@@ -2019,7 +2019,7 @@ discard block |
||
| 2019 | 2019 | : $fix; |
| 2020 | 2020 | |
| 2021 | 2021 | $template_form_fields[$field_id] = array( |
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2022 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2023 | 2023 | 'label' => $config['label'], |
| 2024 | 2024 | 'input' => $config['input'], |
| 2025 | 2025 | 'type' => $config['type'], |
@@ -2049,7 +2049,7 @@ discard block |
||
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | 2051 | //and button |
| 2052 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2052 | + $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>'; |
|
| 2053 | 2053 | $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
| 2054 | 2054 | $test_settings_html .= $this->get_action_link_or_button( |
| 2055 | 2055 | 'reset_to_default', |
@@ -2080,7 +2080,7 @@ discard block |
||
| 2080 | 2080 | 'linked_input_id' => $linked_input_id |
| 2081 | 2081 | ); |
| 2082 | 2082 | |
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2084 | 2084 | $template_args, true); |
| 2085 | 2085 | } |
| 2086 | 2086 | |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2099 | 2099 | //now let's set the content depending on the status of the shortcodes array |
| 2100 | 2100 | if (empty($shortcodes)) { |
| 2101 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2101 | + $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2102 | 2102 | echo $content; |
| 2103 | 2103 | } else { |
| 2104 | 2104 | //$alt = 0; |
@@ -2215,7 +2215,7 @@ discard block |
||
| 2215 | 2215 | <?php |
| 2216 | 2216 | } |
| 2217 | 2217 | //setup nonce_url |
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2218 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2219 | 2219 | ?> |
| 2220 | 2220 | <select name="context"> |
| 2221 | 2221 | <?php |
@@ -2313,7 +2313,7 @@ discard block |
||
| 2313 | 2313 | : ''; |
| 2314 | 2314 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2315 | 2315 | |
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : ''; |
|
| 2317 | 2317 | $item_desc .= 'Message Template'; |
| 2318 | 2318 | $query_args = array(); |
| 2319 | 2319 | $edit_array = array(); |
@@ -2688,8 +2688,8 @@ discard block |
||
| 2688 | 2688 | */ |
| 2689 | 2689 | protected function _learn_more_about_message_templates_link() |
| 2690 | 2690 | { |
| 2691 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2692 | - 'event_espresso') . '</a>'; |
|
| 2691 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works', |
|
| 2692 | + 'event_espresso').'</a>'; |
|
| 2693 | 2693 | } |
| 2694 | 2694 | |
| 2695 | 2695 | |
@@ -2765,10 +2765,10 @@ discard block |
||
| 2765 | 2765 | |
| 2766 | 2766 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 2767 | 2767 | 'label' => ucwords($message_type->label['singular']), |
| 2768 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2769 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2770 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2771 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2768 | + 'class' => 'message-type-'.$a_or_i, |
|
| 2769 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 2770 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 2771 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 2772 | 2772 | 'title' => $a_or_i == 'active' |
| 2773 | 2773 | ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 2774 | 2774 | : __('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -2804,9 +2804,9 @@ discard block |
||
| 2804 | 2804 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 2805 | 2805 | |
| 2806 | 2806 | foreach ($fields as $fldname => $fldprops) { |
| 2807 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2807 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 2808 | 2808 | $template_form_field[$field_id] = array( |
| 2809 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2809 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 2810 | 2810 | 'label' => $fldprops['label'], |
| 2811 | 2811 | 'input' => $fldprops['field_type'], |
| 2812 | 2812 | 'type' => $fldprops['value_type'], |
@@ -2847,7 +2847,7 @@ discard block |
||
| 2847 | 2847 | $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
| 2848 | 2848 | |
| 2849 | 2849 | |
| 2850 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2850 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 2851 | 2851 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 2852 | 2852 | |
| 2853 | 2853 | return $content; |
@@ -2877,11 +2877,11 @@ discard block |
||
| 2877 | 2877 | $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
| 2878 | 2878 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 2879 | 2879 | : ''; |
| 2880 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2880 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 2881 | 2881 | __('%s Settings', 'event_espresso'), |
| 2882 | 2882 | $tab_array['label'] |
| 2883 | 2883 | ); |
| 2884 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2884 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 2885 | 2885 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2886 | 2886 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2887 | 2887 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2895,8 +2895,8 @@ discard block |
||
| 2895 | 2895 | // message type meta boxes |
| 2896 | 2896 | // (which is really just the inactive container for each messenger |
| 2897 | 2897 | // showing inactive message types for that messenger) |
| 2898 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2898 | + $mt_boxes[$messenger.'_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 2900 | 2900 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2901 | 2901 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2902 | 2902 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2912,14 +2912,14 @@ discard block |
||
| 2912 | 2912 | |
| 2913 | 2913 | |
| 2914 | 2914 | //register messenger metaboxes |
| 2915 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2915 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2916 | 2916 | foreach ($m_boxes as $box => $label) { |
| 2917 | 2917 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 2918 | 2918 | $msgr = str_replace('_a_box', '', $box); |
| 2919 | 2919 | add_meta_box( |
| 2920 | - 'espresso_' . $msgr . '_settings', |
|
| 2920 | + 'espresso_'.$msgr.'_settings', |
|
| 2921 | 2921 | $label, |
| 2922 | - function ($post, $metabox) { |
|
| 2922 | + function($post, $metabox) { |
|
| 2923 | 2923 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2924 | 2924 | $metabox["args"]["template_args"], true); |
| 2925 | 2925 | }, |
@@ -2931,17 +2931,17 @@ discard block |
||
| 2931 | 2931 | } |
| 2932 | 2932 | |
| 2933 | 2933 | //register message type metaboxes |
| 2934 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2934 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2935 | 2935 | foreach ($mt_boxes as $box => $label) { |
| 2936 | 2936 | $callback_args = array( |
| 2937 | 2937 | 'template_path' => $mt_template_path, |
| 2938 | 2938 | 'template_args' => $mt_template_args[$box] |
| 2939 | 2939 | ); |
| 2940 | - $mt = str_replace('_i_box', '', $box); |
|
| 2940 | + $mt = str_replace('_i_box', '', $box); |
|
| 2941 | 2941 | add_meta_box( |
| 2942 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2942 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 2943 | 2943 | $label, |
| 2944 | - function ($post, $metabox) { |
|
| 2944 | + function($post, $metabox) { |
|
| 2945 | 2945 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2946 | 2946 | $metabox["args"]["template_args"], true); |
| 2947 | 2947 | }, |
@@ -3043,7 +3043,7 @@ discard block |
||
| 3043 | 3043 | if ($form->is_valid()) { |
| 3044 | 3044 | $valid_data = $form->valid_data(); |
| 3045 | 3045 | foreach ($valid_data as $property => $value) { |
| 3046 | - $setter = 'set_' . $property; |
|
| 3046 | + $setter = 'set_'.$property; |
|
| 3047 | 3047 | if (method_exists($network_config, $setter)) { |
| 3048 | 3048 | $network_config->{$setter}($value); |
| 3049 | 3049 | } else if ( |
@@ -3072,8 +3072,8 @@ discard block |
||
| 3072 | 3072 | */ |
| 3073 | 3073 | protected function _get_mt_tabs($tab_array) |
| 3074 | 3074 | { |
| 3075 | - $tab_array = (array)$tab_array; |
|
| 3076 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3075 | + $tab_array = (array) $tab_array; |
|
| 3076 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3077 | 3077 | $tabs = ''; |
| 3078 | 3078 | |
| 3079 | 3079 | foreach ($tab_array as $tab) { |
@@ -3106,9 +3106,9 @@ discard block |
||
| 3106 | 3106 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3107 | 3107 | |
| 3108 | 3108 | foreach ($fields as $fldname => $fldprops) { |
| 3109 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3109 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3110 | 3110 | $template_form_field[$field_id] = array( |
| 3111 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3111 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3112 | 3112 | 'label' => $fldprops['label'], |
| 3113 | 3113 | 'input' => $fldprops['field_type'], |
| 3114 | 3114 | 'type' => $fldprops['value_type'], |
@@ -3143,7 +3143,7 @@ discard block |
||
| 3143 | 3143 | //make sure any active message types that are existing are included in the hidden fields |
| 3144 | 3144 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3145 | 3145 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3146 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3146 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3147 | 3147 | 'type' => 'hidden', |
| 3148 | 3148 | 'value' => $mt |
| 3149 | 3149 | ); |
@@ -3153,7 +3153,7 @@ discard block |
||
| 3153 | 3153 | $settings_template_args['hidden_fields'], |
| 3154 | 3154 | 'array' |
| 3155 | 3155 | ); |
| 3156 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3156 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3157 | 3157 | |
| 3158 | 3158 | $settings_template_args['messenger'] = $messenger->name; |
| 3159 | 3159 | $settings_template_args['description'] = $messenger->description; |
@@ -3170,9 +3170,9 @@ discard block |
||
| 3170 | 3170 | |
| 3171 | 3171 | |
| 3172 | 3172 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3173 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3173 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3174 | 3174 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3175 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3175 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3176 | 3176 | $content = EEH_Template::display_template($template, $settings_template_args, |
| 3177 | 3177 | true); |
| 3178 | 3178 | |
@@ -3200,7 +3200,7 @@ discard block |
||
| 3200 | 3200 | |
| 3201 | 3201 | //do a nonce check here since we're not arriving via a normal route |
| 3202 | 3202 | $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
| 3203 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3203 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3204 | 3204 | |
| 3205 | 3205 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3206 | 3206 | |
@@ -3302,7 +3302,7 @@ discard block |
||
| 3302 | 3302 | |
| 3303 | 3303 | //do a nonce check here since we're not arriving via a normal route |
| 3304 | 3304 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3305 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3305 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3306 | 3306 | |
| 3307 | 3307 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3308 | 3308 | |
@@ -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 | |
@@ -19,1064 +19,1064 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * possibly truncated version of the EE core version string |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected static $_core_version = ''; |
|
| 22 | + /** |
|
| 23 | + * possibly truncated version of the EE core version string |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected static $_core_version = ''; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Holds values for registered addons |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected static $_settings = array(); |
|
| 29 | + /** |
|
| 30 | + * Holds values for registered addons |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected static $_settings = array(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 38 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 39 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 40 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 41 | - * EE core with knowledge of ALL the addons out there. |
|
| 42 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 43 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 44 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 45 | - * minimum plugin version. |
|
| 46 | - * @access protected |
|
| 47 | - */ |
|
| 48 | - protected static $_incompatible_addons = array( |
|
| 49 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 50 | - 'Promotions' => '1.0.0.rc.084', |
|
| 51 | - ); |
|
| 36 | + /** |
|
| 37 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 38 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 39 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 40 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 41 | + * EE core with knowledge of ALL the addons out there. |
|
| 42 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 43 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 44 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 45 | + * minimum plugin version. |
|
| 46 | + * @access protected |
|
| 47 | + */ |
|
| 48 | + protected static $_incompatible_addons = array( |
|
| 49 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 50 | + 'Promotions' => '1.0.0.rc.084', |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 56 | - * not just '4.3.0'. |
|
| 57 | - * So if the addon developer doesn't provide that full version string, |
|
| 58 | - * fill in the blanks for them |
|
| 59 | - * |
|
| 60 | - * @param string $min_core_version |
|
| 61 | - * @return string always like '4.3.0.rc.000' |
|
| 62 | - */ |
|
| 63 | - protected static function _effective_version($min_core_version) |
|
| 64 | - { |
|
| 65 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 66 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 67 | - $version_parts = explode('.', $min_core_version); |
|
| 68 | - //check they specified the micro version (after 2nd period) |
|
| 69 | - if (! isset($version_parts[2])) { |
|
| 70 | - $version_parts[2] = '0'; |
|
| 71 | - } |
|
| 72 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 73 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 74 | - if (! isset($version_parts[3])) { |
|
| 75 | - $version_parts[3] = 'dev'; |
|
| 76 | - } |
|
| 77 | - if (! isset($version_parts[4])) { |
|
| 78 | - $version_parts[4] = '000'; |
|
| 79 | - } |
|
| 80 | - return implode('.', $version_parts); |
|
| 81 | - } |
|
| 54 | + /** |
|
| 55 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 56 | + * not just '4.3.0'. |
|
| 57 | + * So if the addon developer doesn't provide that full version string, |
|
| 58 | + * fill in the blanks for them |
|
| 59 | + * |
|
| 60 | + * @param string $min_core_version |
|
| 61 | + * @return string always like '4.3.0.rc.000' |
|
| 62 | + */ |
|
| 63 | + protected static function _effective_version($min_core_version) |
|
| 64 | + { |
|
| 65 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 66 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 67 | + $version_parts = explode('.', $min_core_version); |
|
| 68 | + //check they specified the micro version (after 2nd period) |
|
| 69 | + if (! isset($version_parts[2])) { |
|
| 70 | + $version_parts[2] = '0'; |
|
| 71 | + } |
|
| 72 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 73 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 74 | + if (! isset($version_parts[3])) { |
|
| 75 | + $version_parts[3] = 'dev'; |
|
| 76 | + } |
|
| 77 | + if (! isset($version_parts[4])) { |
|
| 78 | + $version_parts[4] = '000'; |
|
| 79 | + } |
|
| 80 | + return implode('.', $version_parts); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 86 | - * |
|
| 87 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 88 | - * @param string $actual_core_version the actual core version, optional |
|
| 89 | - * @return boolean |
|
| 90 | - */ |
|
| 91 | - public static function _meets_min_core_version_requirement( |
|
| 92 | - $min_core_version, |
|
| 93 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 94 | - ) { |
|
| 95 | - return version_compare( |
|
| 96 | - self::_effective_version($actual_core_version), |
|
| 97 | - self::_effective_version($min_core_version), |
|
| 98 | - '>=' |
|
| 99 | - ); |
|
| 100 | - } |
|
| 84 | + /** |
|
| 85 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 86 | + * |
|
| 87 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 88 | + * @param string $actual_core_version the actual core version, optional |
|
| 89 | + * @return boolean |
|
| 90 | + */ |
|
| 91 | + public static function _meets_min_core_version_requirement( |
|
| 92 | + $min_core_version, |
|
| 93 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 94 | + ) { |
|
| 95 | + return version_compare( |
|
| 96 | + self::_effective_version($actual_core_version), |
|
| 97 | + self::_effective_version($min_core_version), |
|
| 98 | + '>=' |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Method for registering new EE_Addons. |
|
| 105 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 106 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 107 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 108 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 109 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 110 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 111 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 112 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 113 | - * |
|
| 114 | - * @since 4.3.0 |
|
| 115 | - * @param string $addon_name the EE_Addon's name. Required. |
|
| 116 | - * @param array $setup_args { An |
|
| 117 | - * array of arguments provided for registering |
|
| 118 | - * the message type. |
|
| 119 | - * @type string $class_name the addon's main file name. |
|
| 120 | - * If left blank, generated from the addon |
|
| 121 | - * name, changes something like "calendar" to |
|
| 122 | - * "EE_Calendar" |
|
| 123 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 124 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 125 | - * @type string $version the "software" version for the addon. eg |
|
| 126 | - * "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress |
|
| 127 | - * @type string $main_file_path the full server path to the main file |
|
| 128 | - * loaded |
|
| 129 | - * directly by WP |
|
| 130 | - * @type string $admin_path full server path to the folder where the |
|
| 131 | - * addon\'s admin files reside |
|
| 132 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 133 | - * first invoked, can be used for hooking into any admin page |
|
| 134 | - * @type string $config_section the section name for this addon's |
|
| 135 | - * configuration settings section (defaults to "addons") |
|
| 136 | - * @type string $config_class the class name for this addon's |
|
| 137 | - * configuration settings object |
|
| 138 | - * @type string $config_name the class name for this addon's |
|
| 139 | - * configuration settings object |
|
| 140 | - * @type string $autoloader_paths an array of class names and the full server |
|
| 141 | - * paths to those files. Required. |
|
| 142 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 143 | - * folders containing classes that might be invoked by the addon |
|
| 144 | - * @type string $dms_paths an array of full server paths to folders |
|
| 145 | - * that contain data migration scripts. Required. |
|
| 146 | - * @type string $module_paths an array of full server paths to any |
|
| 147 | - * EED_Modules used by the addon |
|
| 148 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 149 | - * that contain EES_Shortcodes |
|
| 150 | - * @type string $widget_paths an array of full server paths to folders |
|
| 151 | - * that contain WP_Widgets |
|
| 152 | - * @type string $pue_options |
|
| 153 | - * @type array $capabilities an array indexed by role name |
|
| 154 | - * (i.e administrator,author ) and the values |
|
| 155 | - * are an array of caps to add to the role. |
|
| 156 | - * 'administrator' => array( |
|
| 157 | - * 'read_addon', 'edit_addon', etc. |
|
| 158 | - * ). |
|
| 159 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 160 | - * for any addons that need to register any special meta mapped capabilities. Should be indexed where the |
|
| 161 | - * key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class. |
|
| 162 | - * @type array $model_paths array of folders containing DB models |
|
| 163 | - * @see EE_Register_Model |
|
| 164 | - * @type array $class_paths array of folders containing DB classes |
|
| 165 | - * @see EE_Register_Model |
|
| 166 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 167 | - * extensions |
|
| 168 | - * @see EE_Register_Model_Extension |
|
| 169 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 170 | - * extensions |
|
| 171 | - * @see EE_Register_Model_Extension |
|
| 172 | - * @type array message_types { |
|
| 173 | - * An array of message types with the key as |
|
| 174 | - * the message type name and the values as |
|
| 175 | - * below: |
|
| 176 | - * @type string $mtfilename The filename of the message type being |
|
| 177 | - * registered. This will be the main EE_{Messagetype_Name}_message_type class. |
|
| 178 | - * (eg. |
|
| 179 | - * EE_Declined_Registration_message_type.class.php) |
|
| 180 | - * Required. |
|
| 181 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
| 182 | - * autoloader for the new message type. |
|
| 183 | - * Required. |
|
| 184 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 185 | - * type should activate with. Each value in |
|
| 186 | - * the |
|
| 187 | - * array |
|
| 188 | - * should match the name property of a |
|
| 189 | - * EE_messenger. Optional. |
|
| 190 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 191 | - * type should validate with. Each value in |
|
| 192 | - * the |
|
| 193 | - * array |
|
| 194 | - * should match the name property of an |
|
| 195 | - * EE_messenger. |
|
| 196 | - * Optional. |
|
| 197 | - * } |
|
| 198 | - * @type array $custom_post_types |
|
| 199 | - * @type array $custom_taxonomies |
|
| 200 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 201 | - * EE_PMT_Base child class |
|
| 202 | - * (eg, |
|
| 203 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 204 | - * which contains the files |
|
| 205 | - * EE_PMT_Payomatic.pm.php) |
|
| 206 | - * @type array $default_terms |
|
| 207 | - * @type array $namespace { |
|
| 208 | - * An array with two items for registering the |
|
| 209 | - * addon's namespace. (If, for some reason, |
|
| 210 | - * you |
|
| 211 | - * require additional namespaces, use |
|
| 212 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 213 | - * directly) |
|
| 214 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 215 | - * @type string $FQNS the namespace prefix |
|
| 216 | - * @type string $DIR a base directory for class files in the |
|
| 217 | - * namespace. |
|
| 218 | - * } |
|
| 219 | - * } |
|
| 220 | - * @throws EE_Error |
|
| 221 | - * @return void |
|
| 222 | - */ |
|
| 223 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 224 | - { |
|
| 225 | - // required fields MUST be present, so let's make sure they are. |
|
| 226 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 227 | - // get class name for addon |
|
| 228 | - $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 229 | - //setup $_settings array from incoming values. |
|
| 230 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 231 | - // setup PUE |
|
| 232 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 233 | - // does this addon work with this version of core or WordPress ? |
|
| 234 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 235 | - return; |
|
| 236 | - } |
|
| 237 | - // register namespaces |
|
| 238 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 239 | - // check if this is an activation request |
|
| 240 | - if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 241 | - // dont bother setting up the rest of the addon atm |
|
| 242 | - return; |
|
| 243 | - } |
|
| 244 | - // we need cars |
|
| 245 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 246 | - // register new models and extensions |
|
| 247 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 248 | - // setup DMS |
|
| 249 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 250 | - // if config_class is present let's register config. |
|
| 251 | - \EE_Register_Addon::_register_config($addon_name); |
|
| 252 | - // register admin pages |
|
| 253 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 254 | - // add to list of modules to be registered |
|
| 255 | - \EE_Register_Addon::_register_modules($addon_name); |
|
| 256 | - // add to list of shortcodes to be registered |
|
| 257 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 258 | - // add to list of widgets to be registered |
|
| 259 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
| 260 | - // register capability related stuff. |
|
| 261 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 262 | - // any message type to register? |
|
| 263 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
| 264 | - // any custom post type/ custom capabilities or default terms to register |
|
| 265 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 266 | - // and any payment methods |
|
| 267 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 268 | - // load and instantiate main addon class |
|
| 269 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 270 | - $addon->after_registration(); |
|
| 271 | - } |
|
| 103 | + /** |
|
| 104 | + * Method for registering new EE_Addons. |
|
| 105 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 106 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 107 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 108 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 109 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 110 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 111 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 112 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 113 | + * |
|
| 114 | + * @since 4.3.0 |
|
| 115 | + * @param string $addon_name the EE_Addon's name. Required. |
|
| 116 | + * @param array $setup_args { An |
|
| 117 | + * array of arguments provided for registering |
|
| 118 | + * the message type. |
|
| 119 | + * @type string $class_name the addon's main file name. |
|
| 120 | + * If left blank, generated from the addon |
|
| 121 | + * name, changes something like "calendar" to |
|
| 122 | + * "EE_Calendar" |
|
| 123 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 124 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 125 | + * @type string $version the "software" version for the addon. eg |
|
| 126 | + * "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress |
|
| 127 | + * @type string $main_file_path the full server path to the main file |
|
| 128 | + * loaded |
|
| 129 | + * directly by WP |
|
| 130 | + * @type string $admin_path full server path to the folder where the |
|
| 131 | + * addon\'s admin files reside |
|
| 132 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 133 | + * first invoked, can be used for hooking into any admin page |
|
| 134 | + * @type string $config_section the section name for this addon's |
|
| 135 | + * configuration settings section (defaults to "addons") |
|
| 136 | + * @type string $config_class the class name for this addon's |
|
| 137 | + * configuration settings object |
|
| 138 | + * @type string $config_name the class name for this addon's |
|
| 139 | + * configuration settings object |
|
| 140 | + * @type string $autoloader_paths an array of class names and the full server |
|
| 141 | + * paths to those files. Required. |
|
| 142 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 143 | + * folders containing classes that might be invoked by the addon |
|
| 144 | + * @type string $dms_paths an array of full server paths to folders |
|
| 145 | + * that contain data migration scripts. Required. |
|
| 146 | + * @type string $module_paths an array of full server paths to any |
|
| 147 | + * EED_Modules used by the addon |
|
| 148 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 149 | + * that contain EES_Shortcodes |
|
| 150 | + * @type string $widget_paths an array of full server paths to folders |
|
| 151 | + * that contain WP_Widgets |
|
| 152 | + * @type string $pue_options |
|
| 153 | + * @type array $capabilities an array indexed by role name |
|
| 154 | + * (i.e administrator,author ) and the values |
|
| 155 | + * are an array of caps to add to the role. |
|
| 156 | + * 'administrator' => array( |
|
| 157 | + * 'read_addon', 'edit_addon', etc. |
|
| 158 | + * ). |
|
| 159 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 160 | + * for any addons that need to register any special meta mapped capabilities. Should be indexed where the |
|
| 161 | + * key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class. |
|
| 162 | + * @type array $model_paths array of folders containing DB models |
|
| 163 | + * @see EE_Register_Model |
|
| 164 | + * @type array $class_paths array of folders containing DB classes |
|
| 165 | + * @see EE_Register_Model |
|
| 166 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 167 | + * extensions |
|
| 168 | + * @see EE_Register_Model_Extension |
|
| 169 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 170 | + * extensions |
|
| 171 | + * @see EE_Register_Model_Extension |
|
| 172 | + * @type array message_types { |
|
| 173 | + * An array of message types with the key as |
|
| 174 | + * the message type name and the values as |
|
| 175 | + * below: |
|
| 176 | + * @type string $mtfilename The filename of the message type being |
|
| 177 | + * registered. This will be the main EE_{Messagetype_Name}_message_type class. |
|
| 178 | + * (eg. |
|
| 179 | + * EE_Declined_Registration_message_type.class.php) |
|
| 180 | + * Required. |
|
| 181 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
| 182 | + * autoloader for the new message type. |
|
| 183 | + * Required. |
|
| 184 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 185 | + * type should activate with. Each value in |
|
| 186 | + * the |
|
| 187 | + * array |
|
| 188 | + * should match the name property of a |
|
| 189 | + * EE_messenger. Optional. |
|
| 190 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 191 | + * type should validate with. Each value in |
|
| 192 | + * the |
|
| 193 | + * array |
|
| 194 | + * should match the name property of an |
|
| 195 | + * EE_messenger. |
|
| 196 | + * Optional. |
|
| 197 | + * } |
|
| 198 | + * @type array $custom_post_types |
|
| 199 | + * @type array $custom_taxonomies |
|
| 200 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 201 | + * EE_PMT_Base child class |
|
| 202 | + * (eg, |
|
| 203 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 204 | + * which contains the files |
|
| 205 | + * EE_PMT_Payomatic.pm.php) |
|
| 206 | + * @type array $default_terms |
|
| 207 | + * @type array $namespace { |
|
| 208 | + * An array with two items for registering the |
|
| 209 | + * addon's namespace. (If, for some reason, |
|
| 210 | + * you |
|
| 211 | + * require additional namespaces, use |
|
| 212 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 213 | + * directly) |
|
| 214 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 215 | + * @type string $FQNS the namespace prefix |
|
| 216 | + * @type string $DIR a base directory for class files in the |
|
| 217 | + * namespace. |
|
| 218 | + * } |
|
| 219 | + * } |
|
| 220 | + * @throws EE_Error |
|
| 221 | + * @return void |
|
| 222 | + */ |
|
| 223 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 224 | + { |
|
| 225 | + // required fields MUST be present, so let's make sure they are. |
|
| 226 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 227 | + // get class name for addon |
|
| 228 | + $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 229 | + //setup $_settings array from incoming values. |
|
| 230 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 231 | + // setup PUE |
|
| 232 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 233 | + // does this addon work with this version of core or WordPress ? |
|
| 234 | + if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 235 | + return; |
|
| 236 | + } |
|
| 237 | + // register namespaces |
|
| 238 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 239 | + // check if this is an activation request |
|
| 240 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 241 | + // dont bother setting up the rest of the addon atm |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | + // we need cars |
|
| 245 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 246 | + // register new models and extensions |
|
| 247 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 248 | + // setup DMS |
|
| 249 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 250 | + // if config_class is present let's register config. |
|
| 251 | + \EE_Register_Addon::_register_config($addon_name); |
|
| 252 | + // register admin pages |
|
| 253 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 254 | + // add to list of modules to be registered |
|
| 255 | + \EE_Register_Addon::_register_modules($addon_name); |
|
| 256 | + // add to list of shortcodes to be registered |
|
| 257 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 258 | + // add to list of widgets to be registered |
|
| 259 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
| 260 | + // register capability related stuff. |
|
| 261 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 262 | + // any message type to register? |
|
| 263 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
| 264 | + // any custom post type/ custom capabilities or default terms to register |
|
| 265 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 266 | + // and any payment methods |
|
| 267 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 268 | + // load and instantiate main addon class |
|
| 269 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 270 | + $addon->after_registration(); |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * @param string $addon_name |
|
| 276 | - * @param array $setup_args |
|
| 277 | - * @return void |
|
| 278 | - * @throws \EE_Error |
|
| 279 | - */ |
|
| 280 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 281 | - { |
|
| 282 | - // required fields MUST be present, so let's make sure they are. |
|
| 283 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 284 | - throw new EE_Error( |
|
| 285 | - __( |
|
| 286 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 287 | - 'event_espresso' |
|
| 288 | - ) |
|
| 289 | - ); |
|
| 290 | - } |
|
| 291 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 292 | - throw new EE_Error( |
|
| 293 | - sprintf( |
|
| 294 | - __( |
|
| 295 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 296 | - 'event_espresso' |
|
| 297 | - ), |
|
| 298 | - implode(',', array_keys($setup_args)) |
|
| 299 | - ) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - // check that addon has not already been registered with that name |
|
| 303 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 304 | - throw new EE_Error( |
|
| 305 | - sprintf( |
|
| 306 | - __( |
|
| 307 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 308 | - 'event_espresso' |
|
| 309 | - ), |
|
| 310 | - $addon_name |
|
| 311 | - ) |
|
| 312 | - ); |
|
| 313 | - } |
|
| 314 | - } |
|
| 274 | + /** |
|
| 275 | + * @param string $addon_name |
|
| 276 | + * @param array $setup_args |
|
| 277 | + * @return void |
|
| 278 | + * @throws \EE_Error |
|
| 279 | + */ |
|
| 280 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 281 | + { |
|
| 282 | + // required fields MUST be present, so let's make sure they are. |
|
| 283 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 284 | + throw new EE_Error( |
|
| 285 | + __( |
|
| 286 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 287 | + 'event_espresso' |
|
| 288 | + ) |
|
| 289 | + ); |
|
| 290 | + } |
|
| 291 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 292 | + throw new EE_Error( |
|
| 293 | + sprintf( |
|
| 294 | + __( |
|
| 295 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 296 | + 'event_espresso' |
|
| 297 | + ), |
|
| 298 | + implode(',', array_keys($setup_args)) |
|
| 299 | + ) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + // check that addon has not already been registered with that name |
|
| 303 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 304 | + throw new EE_Error( |
|
| 305 | + sprintf( |
|
| 306 | + __( |
|
| 307 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 308 | + 'event_espresso' |
|
| 309 | + ), |
|
| 310 | + $addon_name |
|
| 311 | + ) |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | |
| 317 | - /** |
|
| 318 | - * @param string $addon_name |
|
| 319 | - * @param array $setup_args |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 322 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 323 | - { |
|
| 324 | - if (empty($setup_args['class_name'])) { |
|
| 325 | - // generate one by first separating name with spaces |
|
| 326 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 327 | - //capitalize, then replace spaces with underscores |
|
| 328 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 329 | - } else { |
|
| 330 | - $class_name = $setup_args['class_name']; |
|
| 331 | - } |
|
| 332 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 333 | - } |
|
| 317 | + /** |
|
| 318 | + * @param string $addon_name |
|
| 319 | + * @param array $setup_args |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 323 | + { |
|
| 324 | + if (empty($setup_args['class_name'])) { |
|
| 325 | + // generate one by first separating name with spaces |
|
| 326 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 327 | + //capitalize, then replace spaces with underscores |
|
| 328 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 329 | + } else { |
|
| 330 | + $class_name = $setup_args['class_name']; |
|
| 331 | + } |
|
| 332 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * @param string $class_name |
|
| 338 | - * @param array $setup_args |
|
| 339 | - * @return array |
|
| 340 | - */ |
|
| 341 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 342 | - { |
|
| 343 | - //setup $_settings array from incoming values. |
|
| 344 | - $addon_settings = array( |
|
| 345 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 346 | - 'class_name' => $class_name, |
|
| 347 | - // the addon slug for use in URLs, etc |
|
| 348 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 349 | - ? (string)$setup_args['plugin_slug'] |
|
| 350 | - : '', |
|
| 351 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 352 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 353 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 354 | - : '', |
|
| 355 | - // the "software" version for the addon |
|
| 356 | - 'version' => isset($setup_args['version']) |
|
| 357 | - ? (string)$setup_args['version'] |
|
| 358 | - : '', |
|
| 359 | - // the minimum version of EE Core that the addon will work with |
|
| 360 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 361 | - ? (string)$setup_args['min_core_version'] |
|
| 362 | - : '', |
|
| 363 | - // the minimum version of WordPress that the addon will work with |
|
| 364 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 365 | - ? (string)$setup_args['min_wp_version'] |
|
| 366 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 367 | - // full server path to main file (file loaded directly by WP) |
|
| 368 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 369 | - ? (string)$setup_args['main_file_path'] |
|
| 370 | - : '', |
|
| 371 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 372 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 373 | - ? (string)$setup_args['admin_path'] : '', |
|
| 374 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 375 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 376 | - ? (string)$setup_args['admin_callback'] |
|
| 377 | - : '', |
|
| 378 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 379 | - 'config_section' => isset($setup_args['config_section']) |
|
| 380 | - ? (string)$setup_args['config_section'] |
|
| 381 | - : 'addons', |
|
| 382 | - // the class name for this addon's configuration settings object |
|
| 383 | - 'config_class' => isset($setup_args['config_class']) |
|
| 384 | - ? (string)$setup_args['config_class'] : '', |
|
| 385 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 386 | - 'config_name' => isset($setup_args['config_name']) |
|
| 387 | - ? (string)$setup_args['config_name'] : '', |
|
| 388 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 389 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 390 | - ? (array)$setup_args['autoloader_paths'] |
|
| 391 | - : array(), |
|
| 392 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 393 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 394 | - ? (array)$setup_args['autoloader_folders'] |
|
| 395 | - : array(), |
|
| 396 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 397 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 398 | - ? (array)$setup_args['dms_paths'] |
|
| 399 | - : array(), |
|
| 400 | - // array of full server paths to any EED_Modules used by the addon |
|
| 401 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 402 | - ? (array)$setup_args['module_paths'] |
|
| 403 | - : array(), |
|
| 404 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 405 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 406 | - ? (array)$setup_args['shortcode_paths'] |
|
| 407 | - : array(), |
|
| 408 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 409 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 410 | - : array(), |
|
| 411 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 412 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 413 | - ? (array)$setup_args['widget_paths'] |
|
| 414 | - : array(), |
|
| 415 | - // array of PUE options used by the addon |
|
| 416 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 417 | - ? (array)$setup_args['pue_options'] |
|
| 418 | - : array(), |
|
| 419 | - 'message_types' => isset($setup_args['message_types']) |
|
| 420 | - ? (array)$setup_args['message_types'] |
|
| 421 | - : array(), |
|
| 422 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 423 | - ? (array)$setup_args['capabilities'] |
|
| 424 | - : array(), |
|
| 425 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 426 | - ? (array)$setup_args['capability_maps'] |
|
| 427 | - : array(), |
|
| 428 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 429 | - ? (array)$setup_args['model_paths'] |
|
| 430 | - : array(), |
|
| 431 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 432 | - ? (array)$setup_args['class_paths'] |
|
| 433 | - : array(), |
|
| 434 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 435 | - ? (array)$setup_args['model_extension_paths'] |
|
| 436 | - : array(), |
|
| 437 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 438 | - ? (array)$setup_args['class_extension_paths'] |
|
| 439 | - : array(), |
|
| 440 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 441 | - ? (array)$setup_args['custom_post_types'] |
|
| 442 | - : array(), |
|
| 443 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 444 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 445 | - : array(), |
|
| 446 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 447 | - ? (array)$setup_args['payment_method_paths'] |
|
| 448 | - : array(), |
|
| 449 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 450 | - ? (array)$setup_args['default_terms'] |
|
| 451 | - : array(), |
|
| 452 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 453 | - // that can be used for adding upgrading/marketing info |
|
| 454 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 455 | - ? $setup_args['plugins_page_row'] |
|
| 456 | - : '', |
|
| 457 | - 'namespace' => isset( |
|
| 458 | - $setup_args['namespace'], |
|
| 459 | - $setup_args['namespace']['FQNS'], |
|
| 460 | - $setup_args['namespace']['DIR'] |
|
| 461 | - ) |
|
| 462 | - ? (array)$setup_args['namespace'] |
|
| 463 | - : array(), |
|
| 464 | - ); |
|
| 465 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 466 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 467 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 468 | - && ! empty($addon_settings['admin_path']) |
|
| 469 | - ? $addon_settings['plugin_slug'] |
|
| 470 | - : $addon_settings['plugin_action_slug']; |
|
| 471 | - // full server path to main file (file loaded directly by WP) |
|
| 472 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 473 | - return $addon_settings; |
|
| 474 | - } |
|
| 336 | + /** |
|
| 337 | + * @param string $class_name |
|
| 338 | + * @param array $setup_args |
|
| 339 | + * @return array |
|
| 340 | + */ |
|
| 341 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 342 | + { |
|
| 343 | + //setup $_settings array from incoming values. |
|
| 344 | + $addon_settings = array( |
|
| 345 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 346 | + 'class_name' => $class_name, |
|
| 347 | + // the addon slug for use in URLs, etc |
|
| 348 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 349 | + ? (string)$setup_args['plugin_slug'] |
|
| 350 | + : '', |
|
| 351 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 352 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 353 | + ? (string)$setup_args['plugin_action_slug'] |
|
| 354 | + : '', |
|
| 355 | + // the "software" version for the addon |
|
| 356 | + 'version' => isset($setup_args['version']) |
|
| 357 | + ? (string)$setup_args['version'] |
|
| 358 | + : '', |
|
| 359 | + // the minimum version of EE Core that the addon will work with |
|
| 360 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 361 | + ? (string)$setup_args['min_core_version'] |
|
| 362 | + : '', |
|
| 363 | + // the minimum version of WordPress that the addon will work with |
|
| 364 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 365 | + ? (string)$setup_args['min_wp_version'] |
|
| 366 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 367 | + // full server path to main file (file loaded directly by WP) |
|
| 368 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 369 | + ? (string)$setup_args['main_file_path'] |
|
| 370 | + : '', |
|
| 371 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 372 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 373 | + ? (string)$setup_args['admin_path'] : '', |
|
| 374 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 375 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 376 | + ? (string)$setup_args['admin_callback'] |
|
| 377 | + : '', |
|
| 378 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 379 | + 'config_section' => isset($setup_args['config_section']) |
|
| 380 | + ? (string)$setup_args['config_section'] |
|
| 381 | + : 'addons', |
|
| 382 | + // the class name for this addon's configuration settings object |
|
| 383 | + 'config_class' => isset($setup_args['config_class']) |
|
| 384 | + ? (string)$setup_args['config_class'] : '', |
|
| 385 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 386 | + 'config_name' => isset($setup_args['config_name']) |
|
| 387 | + ? (string)$setup_args['config_name'] : '', |
|
| 388 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 389 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 390 | + ? (array)$setup_args['autoloader_paths'] |
|
| 391 | + : array(), |
|
| 392 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 393 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 394 | + ? (array)$setup_args['autoloader_folders'] |
|
| 395 | + : array(), |
|
| 396 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 397 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 398 | + ? (array)$setup_args['dms_paths'] |
|
| 399 | + : array(), |
|
| 400 | + // array of full server paths to any EED_Modules used by the addon |
|
| 401 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 402 | + ? (array)$setup_args['module_paths'] |
|
| 403 | + : array(), |
|
| 404 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 405 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 406 | + ? (array)$setup_args['shortcode_paths'] |
|
| 407 | + : array(), |
|
| 408 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 409 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 410 | + : array(), |
|
| 411 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 412 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 413 | + ? (array)$setup_args['widget_paths'] |
|
| 414 | + : array(), |
|
| 415 | + // array of PUE options used by the addon |
|
| 416 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 417 | + ? (array)$setup_args['pue_options'] |
|
| 418 | + : array(), |
|
| 419 | + 'message_types' => isset($setup_args['message_types']) |
|
| 420 | + ? (array)$setup_args['message_types'] |
|
| 421 | + : array(), |
|
| 422 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 423 | + ? (array)$setup_args['capabilities'] |
|
| 424 | + : array(), |
|
| 425 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 426 | + ? (array)$setup_args['capability_maps'] |
|
| 427 | + : array(), |
|
| 428 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 429 | + ? (array)$setup_args['model_paths'] |
|
| 430 | + : array(), |
|
| 431 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 432 | + ? (array)$setup_args['class_paths'] |
|
| 433 | + : array(), |
|
| 434 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 435 | + ? (array)$setup_args['model_extension_paths'] |
|
| 436 | + : array(), |
|
| 437 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 438 | + ? (array)$setup_args['class_extension_paths'] |
|
| 439 | + : array(), |
|
| 440 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 441 | + ? (array)$setup_args['custom_post_types'] |
|
| 442 | + : array(), |
|
| 443 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 444 | + ? (array)$setup_args['custom_taxonomies'] |
|
| 445 | + : array(), |
|
| 446 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 447 | + ? (array)$setup_args['payment_method_paths'] |
|
| 448 | + : array(), |
|
| 449 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 450 | + ? (array)$setup_args['default_terms'] |
|
| 451 | + : array(), |
|
| 452 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 453 | + // that can be used for adding upgrading/marketing info |
|
| 454 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 455 | + ? $setup_args['plugins_page_row'] |
|
| 456 | + : '', |
|
| 457 | + 'namespace' => isset( |
|
| 458 | + $setup_args['namespace'], |
|
| 459 | + $setup_args['namespace']['FQNS'], |
|
| 460 | + $setup_args['namespace']['DIR'] |
|
| 461 | + ) |
|
| 462 | + ? (array)$setup_args['namespace'] |
|
| 463 | + : array(), |
|
| 464 | + ); |
|
| 465 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 466 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 467 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 468 | + && ! empty($addon_settings['admin_path']) |
|
| 469 | + ? $addon_settings['plugin_slug'] |
|
| 470 | + : $addon_settings['plugin_action_slug']; |
|
| 471 | + // full server path to main file (file loaded directly by WP) |
|
| 472 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 473 | + return $addon_settings; |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | 476 | |
| 477 | - /** |
|
| 478 | - * @param string $addon_name |
|
| 479 | - * @param array $addon_settings |
|
| 480 | - * @return boolean |
|
| 481 | - */ |
|
| 482 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 483 | - { |
|
| 484 | - global $wp_version; |
|
| 485 | - $incompatibility_message = ''; |
|
| 486 | - //check whether this addon version is compatible with EE core |
|
| 487 | - if ( |
|
| 488 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 489 | - && ! self::_meets_min_core_version_requirement( |
|
| 490 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 491 | - $addon_settings['version'] |
|
| 492 | - ) |
|
| 493 | - ) { |
|
| 494 | - $incompatibility_message = sprintf( |
|
| 495 | - __( |
|
| 496 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 497 | - ), |
|
| 498 | - $addon_name, |
|
| 499 | - '<br />', |
|
| 500 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 501 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 502 | - '</span><br />' |
|
| 503 | - ); |
|
| 504 | - } else if ( |
|
| 505 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 506 | - ) { |
|
| 507 | - $incompatibility_message = sprintf( |
|
| 508 | - __( |
|
| 509 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 510 | - 'event_espresso' |
|
| 511 | - ), |
|
| 512 | - $addon_name, |
|
| 513 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 514 | - self::_effective_version(espresso_version()), |
|
| 515 | - '<br />', |
|
| 516 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 517 | - '</span><br />' |
|
| 518 | - ); |
|
| 519 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 520 | - $incompatibility_message = sprintf( |
|
| 521 | - __( |
|
| 522 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 523 | - 'event_espresso' |
|
| 524 | - ), |
|
| 525 | - $addon_name, |
|
| 526 | - $addon_settings['min_wp_version'], |
|
| 527 | - '<br />', |
|
| 528 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 529 | - '</span><br />' |
|
| 530 | - ); |
|
| 531 | - } |
|
| 532 | - if (! empty($incompatibility_message)) { |
|
| 533 | - // remove 'activate' from the REQUEST |
|
| 534 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 535 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 536 | - if (current_user_can('activate_plugins')) { |
|
| 537 | - // show an error message indicating the plugin didn't activate properly |
|
| 538 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 539 | - } |
|
| 540 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 541 | - return false; |
|
| 542 | - } |
|
| 543 | - // addon IS compatible |
|
| 544 | - return true; |
|
| 545 | - } |
|
| 477 | + /** |
|
| 478 | + * @param string $addon_name |
|
| 479 | + * @param array $addon_settings |
|
| 480 | + * @return boolean |
|
| 481 | + */ |
|
| 482 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 483 | + { |
|
| 484 | + global $wp_version; |
|
| 485 | + $incompatibility_message = ''; |
|
| 486 | + //check whether this addon version is compatible with EE core |
|
| 487 | + if ( |
|
| 488 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 489 | + && ! self::_meets_min_core_version_requirement( |
|
| 490 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 491 | + $addon_settings['version'] |
|
| 492 | + ) |
|
| 493 | + ) { |
|
| 494 | + $incompatibility_message = sprintf( |
|
| 495 | + __( |
|
| 496 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 497 | + ), |
|
| 498 | + $addon_name, |
|
| 499 | + '<br />', |
|
| 500 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 501 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 502 | + '</span><br />' |
|
| 503 | + ); |
|
| 504 | + } else if ( |
|
| 505 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 506 | + ) { |
|
| 507 | + $incompatibility_message = sprintf( |
|
| 508 | + __( |
|
| 509 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 510 | + 'event_espresso' |
|
| 511 | + ), |
|
| 512 | + $addon_name, |
|
| 513 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 514 | + self::_effective_version(espresso_version()), |
|
| 515 | + '<br />', |
|
| 516 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 517 | + '</span><br />' |
|
| 518 | + ); |
|
| 519 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 520 | + $incompatibility_message = sprintf( |
|
| 521 | + __( |
|
| 522 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 523 | + 'event_espresso' |
|
| 524 | + ), |
|
| 525 | + $addon_name, |
|
| 526 | + $addon_settings['min_wp_version'], |
|
| 527 | + '<br />', |
|
| 528 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 529 | + '</span><br />' |
|
| 530 | + ); |
|
| 531 | + } |
|
| 532 | + if (! empty($incompatibility_message)) { |
|
| 533 | + // remove 'activate' from the REQUEST |
|
| 534 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 535 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 536 | + if (current_user_can('activate_plugins')) { |
|
| 537 | + // show an error message indicating the plugin didn't activate properly |
|
| 538 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 539 | + } |
|
| 540 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + // addon IS compatible |
|
| 544 | + return true; |
|
| 545 | + } |
|
| 546 | 546 | |
| 547 | 547 | |
| 548 | - /** |
|
| 549 | - * if plugin update engine is being used for auto-updates, |
|
| 550 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 551 | - * (not needed if PUE is not being used) |
|
| 552 | - * |
|
| 553 | - * @param string $addon_name |
|
| 554 | - * @param string $class_name |
|
| 555 | - * @param array $setup_args |
|
| 556 | - * @return void |
|
| 557 | - */ |
|
| 558 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 559 | - { |
|
| 560 | - if (! empty($setup_args['pue_options'])) { |
|
| 561 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
| 562 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 563 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 564 | - : 'espresso_' . strtolower($class_name), |
|
| 565 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 566 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 567 | - : plugin_basename($setup_args['main_file_path']), |
|
| 568 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 569 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 570 | - : '24', |
|
| 571 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 572 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 573 | - : false, |
|
| 574 | - ); |
|
| 575 | - add_action( |
|
| 576 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 577 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 578 | - ); |
|
| 579 | - } |
|
| 580 | - } |
|
| 548 | + /** |
|
| 549 | + * if plugin update engine is being used for auto-updates, |
|
| 550 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 551 | + * (not needed if PUE is not being used) |
|
| 552 | + * |
|
| 553 | + * @param string $addon_name |
|
| 554 | + * @param string $class_name |
|
| 555 | + * @param array $setup_args |
|
| 556 | + * @return void |
|
| 557 | + */ |
|
| 558 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 559 | + { |
|
| 560 | + if (! empty($setup_args['pue_options'])) { |
|
| 561 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 562 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 563 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 564 | + : 'espresso_' . strtolower($class_name), |
|
| 565 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 566 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 567 | + : plugin_basename($setup_args['main_file_path']), |
|
| 568 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 569 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 570 | + : '24', |
|
| 571 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 572 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 573 | + : false, |
|
| 574 | + ); |
|
| 575 | + add_action( |
|
| 576 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 577 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 578 | + ); |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | 582 | |
| 583 | - /** |
|
| 584 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 585 | - * |
|
| 586 | - * @param array $addon_settings |
|
| 587 | - * @return void |
|
| 588 | - */ |
|
| 589 | - private static function _setup_namespaces(array $addon_settings) |
|
| 590 | - { |
|
| 591 | - // |
|
| 592 | - if ( |
|
| 593 | - isset( |
|
| 594 | - $addon_settings['namespace'], |
|
| 595 | - $addon_settings['namespace']['FQNS'], |
|
| 596 | - $addon_settings['namespace']['DIR'] |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 600 | - $addon_settings['namespace']['FQNS'], |
|
| 601 | - $addon_settings['namespace']['DIR'] |
|
| 602 | - ); |
|
| 603 | - } |
|
| 604 | - } |
|
| 583 | + /** |
|
| 584 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 585 | + * |
|
| 586 | + * @param array $addon_settings |
|
| 587 | + * @return void |
|
| 588 | + */ |
|
| 589 | + private static function _setup_namespaces(array $addon_settings) |
|
| 590 | + { |
|
| 591 | + // |
|
| 592 | + if ( |
|
| 593 | + isset( |
|
| 594 | + $addon_settings['namespace'], |
|
| 595 | + $addon_settings['namespace']['FQNS'], |
|
| 596 | + $addon_settings['namespace']['DIR'] |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 600 | + $addon_settings['namespace']['FQNS'], |
|
| 601 | + $addon_settings['namespace']['DIR'] |
|
| 602 | + ); |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | 606 | |
| 607 | - /** |
|
| 608 | - * @param string $addon_name |
|
| 609 | - * @param array $addon_settings |
|
| 610 | - * @return bool |
|
| 611 | - */ |
|
| 612 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 613 | - { |
|
| 614 | - // this is an activation request |
|
| 615 | - if (did_action('activate_plugin')) { |
|
| 616 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 617 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 618 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 619 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 620 | - if (! isset(self::$_settings[$addon_name]) |
|
| 621 | - || (isset(self::$_settings[$addon_name]) |
|
| 622 | - && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 623 | - ) |
|
| 624 | - ) { |
|
| 625 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 626 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 627 | - $addon->set_activation_indicator_option(); |
|
| 628 | - // dont bother setting up the rest of the addon. |
|
| 629 | - // we know it was just activated and the request will end soon |
|
| 630 | - } |
|
| 631 | - return true; |
|
| 632 | - } |
|
| 633 | - // make sure this was called in the right place! |
|
| 634 | - if ( |
|
| 635 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 636 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 637 | - ) { |
|
| 638 | - EE_Error::doing_it_wrong( |
|
| 639 | - __METHOD__, |
|
| 640 | - sprintf( |
|
| 641 | - __( |
|
| 642 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 643 | - 'event_espresso' |
|
| 644 | - ), |
|
| 645 | - $addon_name |
|
| 646 | - ), |
|
| 647 | - '4.3.0' |
|
| 648 | - ); |
|
| 649 | - } |
|
| 650 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 651 | - if (isset(self::$_settings[$addon_name])) { |
|
| 652 | - self::$_settings[$addon_name] += $addon_settings; |
|
| 653 | - } else { |
|
| 654 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 655 | - } |
|
| 656 | - return false; |
|
| 657 | - } |
|
| 607 | + /** |
|
| 608 | + * @param string $addon_name |
|
| 609 | + * @param array $addon_settings |
|
| 610 | + * @return bool |
|
| 611 | + */ |
|
| 612 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 613 | + { |
|
| 614 | + // this is an activation request |
|
| 615 | + if (did_action('activate_plugin')) { |
|
| 616 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 617 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 618 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 619 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 620 | + if (! isset(self::$_settings[$addon_name]) |
|
| 621 | + || (isset(self::$_settings[$addon_name]) |
|
| 622 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 623 | + ) |
|
| 624 | + ) { |
|
| 625 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 626 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 627 | + $addon->set_activation_indicator_option(); |
|
| 628 | + // dont bother setting up the rest of the addon. |
|
| 629 | + // we know it was just activated and the request will end soon |
|
| 630 | + } |
|
| 631 | + return true; |
|
| 632 | + } |
|
| 633 | + // make sure this was called in the right place! |
|
| 634 | + if ( |
|
| 635 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 636 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 637 | + ) { |
|
| 638 | + EE_Error::doing_it_wrong( |
|
| 639 | + __METHOD__, |
|
| 640 | + sprintf( |
|
| 641 | + __( |
|
| 642 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 643 | + 'event_espresso' |
|
| 644 | + ), |
|
| 645 | + $addon_name |
|
| 646 | + ), |
|
| 647 | + '4.3.0' |
|
| 648 | + ); |
|
| 649 | + } |
|
| 650 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 651 | + if (isset(self::$_settings[$addon_name])) { |
|
| 652 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 653 | + } else { |
|
| 654 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 655 | + } |
|
| 656 | + return false; |
|
| 657 | + } |
|
| 658 | 658 | |
| 659 | 659 | |
| 660 | - /** |
|
| 661 | - * @param string $addon_name |
|
| 662 | - * @return void |
|
| 663 | - * @throws \EE_Error |
|
| 664 | - */ |
|
| 665 | - private static function _setup_autoloaders($addon_name) |
|
| 666 | - { |
|
| 667 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 668 | - // setup autoloader for single file |
|
| 669 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 670 | - } |
|
| 671 | - // setup autoloaders for folders |
|
| 672 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 673 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 674 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - } |
|
| 660 | + /** |
|
| 661 | + * @param string $addon_name |
|
| 662 | + * @return void |
|
| 663 | + * @throws \EE_Error |
|
| 664 | + */ |
|
| 665 | + private static function _setup_autoloaders($addon_name) |
|
| 666 | + { |
|
| 667 | + if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 668 | + // setup autoloader for single file |
|
| 669 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 670 | + } |
|
| 671 | + // setup autoloaders for folders |
|
| 672 | + if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 673 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 674 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | 678 | |
| 679 | 679 | |
| 680 | - /** |
|
| 681 | - * register new models and extensions |
|
| 682 | - * |
|
| 683 | - * @param string $addon_name |
|
| 684 | - * @return void |
|
| 685 | - * @throws \EE_Error |
|
| 686 | - */ |
|
| 687 | - private static function _register_models_and_extensions($addon_name) |
|
| 688 | - { |
|
| 689 | - // register new models |
|
| 690 | - if ( |
|
| 691 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 692 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 693 | - ) { |
|
| 694 | - EE_Register_Model::register( |
|
| 695 | - $addon_name, |
|
| 696 | - array( |
|
| 697 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 698 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 699 | - ) |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - // register model extensions |
|
| 703 | - if ( |
|
| 704 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 705 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 706 | - ) { |
|
| 707 | - EE_Register_Model_Extensions::register( |
|
| 708 | - $addon_name, |
|
| 709 | - array( |
|
| 710 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 711 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 712 | - ) |
|
| 713 | - ); |
|
| 714 | - } |
|
| 715 | - } |
|
| 680 | + /** |
|
| 681 | + * register new models and extensions |
|
| 682 | + * |
|
| 683 | + * @param string $addon_name |
|
| 684 | + * @return void |
|
| 685 | + * @throws \EE_Error |
|
| 686 | + */ |
|
| 687 | + private static function _register_models_and_extensions($addon_name) |
|
| 688 | + { |
|
| 689 | + // register new models |
|
| 690 | + if ( |
|
| 691 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 692 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 693 | + ) { |
|
| 694 | + EE_Register_Model::register( |
|
| 695 | + $addon_name, |
|
| 696 | + array( |
|
| 697 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 698 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 699 | + ) |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + // register model extensions |
|
| 703 | + if ( |
|
| 704 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 705 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 706 | + ) { |
|
| 707 | + EE_Register_Model_Extensions::register( |
|
| 708 | + $addon_name, |
|
| 709 | + array( |
|
| 710 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 711 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 712 | + ) |
|
| 713 | + ); |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | |
| 718 | - /** |
|
| 719 | - * @param string $addon_name |
|
| 720 | - * @return void |
|
| 721 | - * @throws \EE_Error |
|
| 722 | - */ |
|
| 723 | - private static function _register_data_migration_scripts($addon_name) |
|
| 724 | - { |
|
| 725 | - // setup DMS |
|
| 726 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 727 | - EE_Register_Data_Migration_Scripts::register( |
|
| 728 | - $addon_name, |
|
| 729 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 730 | - ); |
|
| 731 | - } |
|
| 732 | - } |
|
| 718 | + /** |
|
| 719 | + * @param string $addon_name |
|
| 720 | + * @return void |
|
| 721 | + * @throws \EE_Error |
|
| 722 | + */ |
|
| 723 | + private static function _register_data_migration_scripts($addon_name) |
|
| 724 | + { |
|
| 725 | + // setup DMS |
|
| 726 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 727 | + EE_Register_Data_Migration_Scripts::register( |
|
| 728 | + $addon_name, |
|
| 729 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 730 | + ); |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | 733 | |
| 734 | 734 | |
| 735 | - /** |
|
| 736 | - * @param string $addon_name |
|
| 737 | - * @return void |
|
| 738 | - * @throws \EE_Error |
|
| 739 | - */ |
|
| 740 | - private static function _register_config($addon_name) |
|
| 741 | - { |
|
| 742 | - // if config_class is present let's register config. |
|
| 743 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 744 | - EE_Register_Config::register( |
|
| 745 | - self::$_settings[$addon_name]['config_class'], |
|
| 746 | - array( |
|
| 747 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 748 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 749 | - ) |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - } |
|
| 735 | + /** |
|
| 736 | + * @param string $addon_name |
|
| 737 | + * @return void |
|
| 738 | + * @throws \EE_Error |
|
| 739 | + */ |
|
| 740 | + private static function _register_config($addon_name) |
|
| 741 | + { |
|
| 742 | + // if config_class is present let's register config. |
|
| 743 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 744 | + EE_Register_Config::register( |
|
| 745 | + self::$_settings[$addon_name]['config_class'], |
|
| 746 | + array( |
|
| 747 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 748 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 749 | + ) |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | 753 | |
| 754 | 754 | |
| 755 | - /** |
|
| 756 | - * @param string $addon_name |
|
| 757 | - * @return void |
|
| 758 | - * @throws \EE_Error |
|
| 759 | - */ |
|
| 760 | - private static function _register_admin_pages($addon_name) |
|
| 761 | - { |
|
| 762 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 763 | - EE_Register_Admin_Page::register( |
|
| 764 | - $addon_name, |
|
| 765 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 766 | - ); |
|
| 767 | - } |
|
| 768 | - } |
|
| 755 | + /** |
|
| 756 | + * @param string $addon_name |
|
| 757 | + * @return void |
|
| 758 | + * @throws \EE_Error |
|
| 759 | + */ |
|
| 760 | + private static function _register_admin_pages($addon_name) |
|
| 761 | + { |
|
| 762 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 763 | + EE_Register_Admin_Page::register( |
|
| 764 | + $addon_name, |
|
| 765 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 766 | + ); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | 769 | |
| 770 | 770 | |
| 771 | - /** |
|
| 772 | - * @param string $addon_name |
|
| 773 | - * @return void |
|
| 774 | - * @throws \EE_Error |
|
| 775 | - */ |
|
| 776 | - private static function _register_modules($addon_name) |
|
| 777 | - { |
|
| 778 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 779 | - EE_Register_Module::register( |
|
| 780 | - $addon_name, |
|
| 781 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 782 | - ); |
|
| 783 | - } |
|
| 784 | - } |
|
| 771 | + /** |
|
| 772 | + * @param string $addon_name |
|
| 773 | + * @return void |
|
| 774 | + * @throws \EE_Error |
|
| 775 | + */ |
|
| 776 | + private static function _register_modules($addon_name) |
|
| 777 | + { |
|
| 778 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 779 | + EE_Register_Module::register( |
|
| 780 | + $addon_name, |
|
| 781 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 782 | + ); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | 786 | |
| 787 | - /** |
|
| 788 | - * @param string $addon_name |
|
| 789 | - * @return void |
|
| 790 | - * @throws \EE_Error |
|
| 791 | - */ |
|
| 792 | - private static function _register_shortcodes($addon_name) |
|
| 793 | - { |
|
| 794 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 795 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 796 | - ) { |
|
| 797 | - EE_Register_Shortcode::register( |
|
| 798 | - $addon_name, |
|
| 799 | - array( |
|
| 800 | - 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 801 | - ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 802 | - : array(), |
|
| 803 | - 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 804 | - ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 805 | - : array() |
|
| 806 | - ) |
|
| 807 | - ); |
|
| 808 | - } |
|
| 809 | - } |
|
| 787 | + /** |
|
| 788 | + * @param string $addon_name |
|
| 789 | + * @return void |
|
| 790 | + * @throws \EE_Error |
|
| 791 | + */ |
|
| 792 | + private static function _register_shortcodes($addon_name) |
|
| 793 | + { |
|
| 794 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 795 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 796 | + ) { |
|
| 797 | + EE_Register_Shortcode::register( |
|
| 798 | + $addon_name, |
|
| 799 | + array( |
|
| 800 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 801 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 802 | + : array(), |
|
| 803 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 804 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 805 | + : array() |
|
| 806 | + ) |
|
| 807 | + ); |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | 810 | |
| 811 | 811 | |
| 812 | - /** |
|
| 813 | - * @param string $addon_name |
|
| 814 | - * @return void |
|
| 815 | - * @throws \EE_Error |
|
| 816 | - */ |
|
| 817 | - private static function _register_widgets($addon_name) |
|
| 818 | - { |
|
| 819 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 820 | - EE_Register_Widget::register( |
|
| 821 | - $addon_name, |
|
| 822 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 823 | - ); |
|
| 824 | - } |
|
| 825 | - } |
|
| 812 | + /** |
|
| 813 | + * @param string $addon_name |
|
| 814 | + * @return void |
|
| 815 | + * @throws \EE_Error |
|
| 816 | + */ |
|
| 817 | + private static function _register_widgets($addon_name) |
|
| 818 | + { |
|
| 819 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 820 | + EE_Register_Widget::register( |
|
| 821 | + $addon_name, |
|
| 822 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 823 | + ); |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | 826 | |
| 827 | 827 | |
| 828 | - /** |
|
| 829 | - * @param string $addon_name |
|
| 830 | - * @return void |
|
| 831 | - * @throws \EE_Error |
|
| 832 | - */ |
|
| 833 | - private static function _register_capabilities($addon_name) |
|
| 834 | - { |
|
| 835 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 836 | - EE_Register_Capabilities::register( |
|
| 837 | - $addon_name, |
|
| 838 | - array( |
|
| 839 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 840 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 841 | - ) |
|
| 842 | - ); |
|
| 843 | - } |
|
| 844 | - } |
|
| 828 | + /** |
|
| 829 | + * @param string $addon_name |
|
| 830 | + * @return void |
|
| 831 | + * @throws \EE_Error |
|
| 832 | + */ |
|
| 833 | + private static function _register_capabilities($addon_name) |
|
| 834 | + { |
|
| 835 | + if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 836 | + EE_Register_Capabilities::register( |
|
| 837 | + $addon_name, |
|
| 838 | + array( |
|
| 839 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 840 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 841 | + ) |
|
| 842 | + ); |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | 845 | |
| 846 | 846 | |
| 847 | - /** |
|
| 848 | - * @param string $addon_name |
|
| 849 | - * @return void |
|
| 850 | - * @throws \EE_Error |
|
| 851 | - */ |
|
| 852 | - private static function _register_message_types($addon_name) |
|
| 853 | - { |
|
| 854 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 855 | - add_action( |
|
| 856 | - 'EE_Brewing_Regular___messages_caf', |
|
| 857 | - array('EE_Register_Addon', 'register_message_types') |
|
| 858 | - ); |
|
| 859 | - } |
|
| 860 | - } |
|
| 847 | + /** |
|
| 848 | + * @param string $addon_name |
|
| 849 | + * @return void |
|
| 850 | + * @throws \EE_Error |
|
| 851 | + */ |
|
| 852 | + private static function _register_message_types($addon_name) |
|
| 853 | + { |
|
| 854 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 855 | + add_action( |
|
| 856 | + 'EE_Brewing_Regular___messages_caf', |
|
| 857 | + array('EE_Register_Addon', 'register_message_types') |
|
| 858 | + ); |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | 861 | |
| 862 | 862 | |
| 863 | - /** |
|
| 864 | - * @param string $addon_name |
|
| 865 | - * @return void |
|
| 866 | - * @throws \EE_Error |
|
| 867 | - */ |
|
| 868 | - private static function _register_custom_post_types($addon_name) |
|
| 869 | - { |
|
| 870 | - if ( |
|
| 871 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 872 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 873 | - ) { |
|
| 874 | - EE_Register_CPT::register( |
|
| 875 | - $addon_name, |
|
| 876 | - array( |
|
| 877 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 878 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 879 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 880 | - ) |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - } |
|
| 863 | + /** |
|
| 864 | + * @param string $addon_name |
|
| 865 | + * @return void |
|
| 866 | + * @throws \EE_Error |
|
| 867 | + */ |
|
| 868 | + private static function _register_custom_post_types($addon_name) |
|
| 869 | + { |
|
| 870 | + if ( |
|
| 871 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 872 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 873 | + ) { |
|
| 874 | + EE_Register_CPT::register( |
|
| 875 | + $addon_name, |
|
| 876 | + array( |
|
| 877 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 878 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 879 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 880 | + ) |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | 884 | |
| 885 | 885 | |
| 886 | - /** |
|
| 887 | - * @param string $addon_name |
|
| 888 | - * @return void |
|
| 889 | - * @throws \EE_Error |
|
| 890 | - */ |
|
| 891 | - private static function _register_payment_methods($addon_name) |
|
| 892 | - { |
|
| 893 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 894 | - EE_Register_Payment_Method::register( |
|
| 895 | - $addon_name, |
|
| 896 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 897 | - ); |
|
| 898 | - } |
|
| 899 | - } |
|
| 886 | + /** |
|
| 887 | + * @param string $addon_name |
|
| 888 | + * @return void |
|
| 889 | + * @throws \EE_Error |
|
| 890 | + */ |
|
| 891 | + private static function _register_payment_methods($addon_name) |
|
| 892 | + { |
|
| 893 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 894 | + EE_Register_Payment_Method::register( |
|
| 895 | + $addon_name, |
|
| 896 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 897 | + ); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | 900 | |
| 901 | 901 | |
| 902 | - /** |
|
| 903 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 904 | - * |
|
| 905 | - * @param string $addon_name |
|
| 906 | - * @return EE_Addon |
|
| 907 | - */ |
|
| 908 | - private static function _load_and_init_addon_class($addon_name) |
|
| 909 | - { |
|
| 910 | - $addon = EE_Registry::instance()->load_addon( |
|
| 911 | - dirname(self::$_settings[$addon_name]['main_file_path']), |
|
| 912 | - self::$_settings[$addon_name]['class_name'] |
|
| 913 | - ); |
|
| 914 | - $addon->set_name($addon_name); |
|
| 915 | - $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 916 | - $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 917 | - $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 918 | - $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 919 | - $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 920 | - $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 921 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 922 | - $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 923 | - $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 924 | - $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 925 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 926 | - //the plugin mainfile's path upon construction. |
|
| 927 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 928 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 929 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 930 | - add_action( |
|
| 931 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 932 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 933 | - ); |
|
| 934 | - } |
|
| 935 | - return $addon; |
|
| 936 | - } |
|
| 902 | + /** |
|
| 903 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 904 | + * |
|
| 905 | + * @param string $addon_name |
|
| 906 | + * @return EE_Addon |
|
| 907 | + */ |
|
| 908 | + private static function _load_and_init_addon_class($addon_name) |
|
| 909 | + { |
|
| 910 | + $addon = EE_Registry::instance()->load_addon( |
|
| 911 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
| 912 | + self::$_settings[$addon_name]['class_name'] |
|
| 913 | + ); |
|
| 914 | + $addon->set_name($addon_name); |
|
| 915 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 916 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 917 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 918 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 919 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 920 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 921 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 922 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 923 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 924 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 925 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 926 | + //the plugin mainfile's path upon construction. |
|
| 927 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 928 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 929 | + if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 930 | + add_action( |
|
| 931 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 932 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 933 | + ); |
|
| 934 | + } |
|
| 935 | + return $addon; |
|
| 936 | + } |
|
| 937 | 937 | |
| 938 | 938 | |
| 939 | - /** |
|
| 940 | - * load_pue_update - Update notifications |
|
| 941 | - * |
|
| 942 | - * @return void |
|
| 943 | - */ |
|
| 944 | - public static function load_pue_update() |
|
| 945 | - { |
|
| 946 | - // load PUE client |
|
| 947 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 948 | - // cycle thru settings |
|
| 949 | - foreach (self::$_settings as $settings) { |
|
| 950 | - if (! empty($settings['pue_options'])) { |
|
| 951 | - // initiate the class and start the plugin update engine! |
|
| 952 | - new PluginUpdateEngineChecker( |
|
| 953 | - // host file URL |
|
| 954 | - 'https://eventespresso.com', |
|
| 955 | - // plugin slug(s) |
|
| 956 | - array( |
|
| 957 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 958 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 959 | - ), |
|
| 960 | - // options |
|
| 961 | - array( |
|
| 962 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 963 | - 'lang_domain' => 'event_espresso', |
|
| 964 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 965 | - 'option_key' => 'site_license_key', |
|
| 966 | - 'options_page_slug' => 'event_espresso', |
|
| 967 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 968 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 969 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 970 | - ) |
|
| 971 | - ); |
|
| 972 | - } |
|
| 973 | - } |
|
| 974 | - } |
|
| 939 | + /** |
|
| 940 | + * load_pue_update - Update notifications |
|
| 941 | + * |
|
| 942 | + * @return void |
|
| 943 | + */ |
|
| 944 | + public static function load_pue_update() |
|
| 945 | + { |
|
| 946 | + // load PUE client |
|
| 947 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 948 | + // cycle thru settings |
|
| 949 | + foreach (self::$_settings as $settings) { |
|
| 950 | + if (! empty($settings['pue_options'])) { |
|
| 951 | + // initiate the class and start the plugin update engine! |
|
| 952 | + new PluginUpdateEngineChecker( |
|
| 953 | + // host file URL |
|
| 954 | + 'https://eventespresso.com', |
|
| 955 | + // plugin slug(s) |
|
| 956 | + array( |
|
| 957 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 958 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 959 | + ), |
|
| 960 | + // options |
|
| 961 | + array( |
|
| 962 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 963 | + 'lang_domain' => 'event_espresso', |
|
| 964 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 965 | + 'option_key' => 'site_license_key', |
|
| 966 | + 'options_page_slug' => 'event_espresso', |
|
| 967 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 968 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 969 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 970 | + ) |
|
| 971 | + ); |
|
| 972 | + } |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | 975 | |
| 976 | 976 | |
| 977 | - /** |
|
| 978 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 979 | - * |
|
| 980 | - * @since 4.4.0 |
|
| 981 | - * @return void |
|
| 982 | - * @throws \EE_Error |
|
| 983 | - */ |
|
| 984 | - public static function register_message_types() |
|
| 985 | - { |
|
| 986 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 987 | - if (! empty($settings['message_types'])) { |
|
| 988 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 989 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 977 | + /** |
|
| 978 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 979 | + * |
|
| 980 | + * @since 4.4.0 |
|
| 981 | + * @return void |
|
| 982 | + * @throws \EE_Error |
|
| 983 | + */ |
|
| 984 | + public static function register_message_types() |
|
| 985 | + { |
|
| 986 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 987 | + if (! empty($settings['message_types'])) { |
|
| 988 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 989 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | 994 | |
| 995 | 995 | |
| 996 | - /** |
|
| 997 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 998 | - * |
|
| 999 | - * @since 4.3.0 |
|
| 1000 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1001 | - * @throws EE_Error |
|
| 1002 | - * @return void |
|
| 1003 | - */ |
|
| 1004 | - public static function deregister($addon_name = null) |
|
| 1005 | - { |
|
| 1006 | - if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
| 1007 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1008 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1009 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1010 | - // setup DMS |
|
| 1011 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1012 | - } |
|
| 1013 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1014 | - // register admin page |
|
| 1015 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1016 | - } |
|
| 1017 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1018 | - // add to list of modules to be registered |
|
| 1019 | - EE_Register_Module::deregister($addon_name); |
|
| 1020 | - } |
|
| 1021 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1022 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1023 | - ) { |
|
| 1024 | - // add to list of shortcodes to be registered |
|
| 1025 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1026 | - } |
|
| 1027 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1028 | - // if config_class present let's register config. |
|
| 1029 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1030 | - } |
|
| 1031 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1032 | - // add to list of widgets to be registered |
|
| 1033 | - EE_Register_Widget::deregister($addon_name); |
|
| 1034 | - } |
|
| 1035 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1036 | - || |
|
| 1037 | - ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1038 | - ) { |
|
| 1039 | - // add to list of shortcodes to be registered |
|
| 1040 | - EE_Register_Model::deregister($addon_name); |
|
| 1041 | - } |
|
| 1042 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1043 | - || |
|
| 1044 | - ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1045 | - ) { |
|
| 1046 | - // add to list of shortcodes to be registered |
|
| 1047 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1048 | - } |
|
| 1049 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1050 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1051 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - //deregister capabilities for addon |
|
| 1055 | - if ( |
|
| 1056 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1057 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1058 | - ) { |
|
| 1059 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1060 | - } |
|
| 1061 | - //deregister custom_post_types for addon |
|
| 1062 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1063 | - EE_Register_CPT::deregister($addon_name); |
|
| 1064 | - } |
|
| 1065 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1066 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1067 | - } |
|
| 1068 | - remove_action( |
|
| 1069 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1070 | - array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
| 1071 | - ); |
|
| 1072 | - remove_action( |
|
| 1073 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1074 | - array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
| 1075 | - ); |
|
| 1076 | - unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
| 1077 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 996 | + /** |
|
| 997 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 998 | + * |
|
| 999 | + * @since 4.3.0 |
|
| 1000 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1001 | + * @throws EE_Error |
|
| 1002 | + * @return void |
|
| 1003 | + */ |
|
| 1004 | + public static function deregister($addon_name = null) |
|
| 1005 | + { |
|
| 1006 | + if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
| 1007 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1008 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1009 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1010 | + // setup DMS |
|
| 1011 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1012 | + } |
|
| 1013 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1014 | + // register admin page |
|
| 1015 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1016 | + } |
|
| 1017 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1018 | + // add to list of modules to be registered |
|
| 1019 | + EE_Register_Module::deregister($addon_name); |
|
| 1020 | + } |
|
| 1021 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1022 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1023 | + ) { |
|
| 1024 | + // add to list of shortcodes to be registered |
|
| 1025 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1026 | + } |
|
| 1027 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1028 | + // if config_class present let's register config. |
|
| 1029 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1030 | + } |
|
| 1031 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1032 | + // add to list of widgets to be registered |
|
| 1033 | + EE_Register_Widget::deregister($addon_name); |
|
| 1034 | + } |
|
| 1035 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1036 | + || |
|
| 1037 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1038 | + ) { |
|
| 1039 | + // add to list of shortcodes to be registered |
|
| 1040 | + EE_Register_Model::deregister($addon_name); |
|
| 1041 | + } |
|
| 1042 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1043 | + || |
|
| 1044 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1045 | + ) { |
|
| 1046 | + // add to list of shortcodes to be registered |
|
| 1047 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1048 | + } |
|
| 1049 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1050 | + foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1051 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + //deregister capabilities for addon |
|
| 1055 | + if ( |
|
| 1056 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1057 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1058 | + ) { |
|
| 1059 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1060 | + } |
|
| 1061 | + //deregister custom_post_types for addon |
|
| 1062 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1063 | + EE_Register_CPT::deregister($addon_name); |
|
| 1064 | + } |
|
| 1065 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1066 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1067 | + } |
|
| 1068 | + remove_action( |
|
| 1069 | + 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1070 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
| 1071 | + ); |
|
| 1072 | + remove_action( |
|
| 1073 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1074 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
| 1075 | + ); |
|
| 1076 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
| 1077 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | 1080 | |
| 1081 | 1081 | |
| 1082 | 1082 | } |
@@ -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 | |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 67 | 67 | $version_parts = explode('.', $min_core_version); |
| 68 | 68 | //check they specified the micro version (after 2nd period) |
| 69 | - if (! isset($version_parts[2])) { |
|
| 69 | + if ( ! isset($version_parts[2])) { |
|
| 70 | 70 | $version_parts[2] = '0'; |
| 71 | 71 | } |
| 72 | 72 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 73 | 73 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 74 | - if (! isset($version_parts[3])) { |
|
| 74 | + if ( ! isset($version_parts[3])) { |
|
| 75 | 75 | $version_parts[3] = 'dev'; |
| 76 | 76 | } |
| 77 | - if (! isset($version_parts[4])) { |
|
| 77 | + if ( ! isset($version_parts[4])) { |
|
| 78 | 78 | $version_parts[4] = '000'; |
| 79 | 79 | } |
| 80 | 80 | return implode('.', $version_parts); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // setup PUE |
| 232 | 232 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 233 | 233 | // does this addon work with this version of core or WordPress ? |
| 234 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 234 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 235 | 235 | return; |
| 236 | 236 | } |
| 237 | 237 | // register namespaces |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | ) |
| 289 | 289 | ); |
| 290 | 290 | } |
| 291 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 291 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 292 | 292 | throw new EE_Error( |
| 293 | 293 | sprintf( |
| 294 | 294 | __( |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } else { |
| 330 | 330 | $class_name = $setup_args['class_name']; |
| 331 | 331 | } |
| 332 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 332 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -346,108 +346,108 @@ discard block |
||
| 346 | 346 | 'class_name' => $class_name, |
| 347 | 347 | // the addon slug for use in URLs, etc |
| 348 | 348 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
| 349 | - ? (string)$setup_args['plugin_slug'] |
|
| 349 | + ? (string) $setup_args['plugin_slug'] |
|
| 350 | 350 | : '', |
| 351 | 351 | // page slug to be used when generating the "Settings" link on the WP plugin page |
| 352 | 352 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
| 353 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 353 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 354 | 354 | : '', |
| 355 | 355 | // the "software" version for the addon |
| 356 | 356 | 'version' => isset($setup_args['version']) |
| 357 | - ? (string)$setup_args['version'] |
|
| 357 | + ? (string) $setup_args['version'] |
|
| 358 | 358 | : '', |
| 359 | 359 | // the minimum version of EE Core that the addon will work with |
| 360 | 360 | 'min_core_version' => isset($setup_args['min_core_version']) |
| 361 | - ? (string)$setup_args['min_core_version'] |
|
| 361 | + ? (string) $setup_args['min_core_version'] |
|
| 362 | 362 | : '', |
| 363 | 363 | // the minimum version of WordPress that the addon will work with |
| 364 | 364 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
| 365 | - ? (string)$setup_args['min_wp_version'] |
|
| 365 | + ? (string) $setup_args['min_wp_version'] |
|
| 366 | 366 | : EE_MIN_WP_VER_REQUIRED, |
| 367 | 367 | // full server path to main file (file loaded directly by WP) |
| 368 | 368 | 'main_file_path' => isset($setup_args['main_file_path']) |
| 369 | - ? (string)$setup_args['main_file_path'] |
|
| 369 | + ? (string) $setup_args['main_file_path'] |
|
| 370 | 370 | : '', |
| 371 | 371 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
| 372 | 372 | 'admin_path' => isset($setup_args['admin_path']) |
| 373 | - ? (string)$setup_args['admin_path'] : '', |
|
| 373 | + ? (string) $setup_args['admin_path'] : '', |
|
| 374 | 374 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
| 375 | 375 | 'admin_callback' => isset($setup_args['admin_callback']) |
| 376 | - ? (string)$setup_args['admin_callback'] |
|
| 376 | + ? (string) $setup_args['admin_callback'] |
|
| 377 | 377 | : '', |
| 378 | 378 | // the section name for this addon's configuration settings section (defaults to "addons") |
| 379 | 379 | 'config_section' => isset($setup_args['config_section']) |
| 380 | - ? (string)$setup_args['config_section'] |
|
| 380 | + ? (string) $setup_args['config_section'] |
|
| 381 | 381 | : 'addons', |
| 382 | 382 | // the class name for this addon's configuration settings object |
| 383 | 383 | 'config_class' => isset($setup_args['config_class']) |
| 384 | - ? (string)$setup_args['config_class'] : '', |
|
| 384 | + ? (string) $setup_args['config_class'] : '', |
|
| 385 | 385 | //the name given to the config for this addons' configuration settings object (optional) |
| 386 | 386 | 'config_name' => isset($setup_args['config_name']) |
| 387 | - ? (string)$setup_args['config_name'] : '', |
|
| 387 | + ? (string) $setup_args['config_name'] : '', |
|
| 388 | 388 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
| 389 | 389 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
| 390 | - ? (array)$setup_args['autoloader_paths'] |
|
| 390 | + ? (array) $setup_args['autoloader_paths'] |
|
| 391 | 391 | : array(), |
| 392 | 392 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
| 393 | 393 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
| 394 | - ? (array)$setup_args['autoloader_folders'] |
|
| 394 | + ? (array) $setup_args['autoloader_folders'] |
|
| 395 | 395 | : array(), |
| 396 | 396 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
| 397 | 397 | 'dms_paths' => isset($setup_args['dms_paths']) |
| 398 | - ? (array)$setup_args['dms_paths'] |
|
| 398 | + ? (array) $setup_args['dms_paths'] |
|
| 399 | 399 | : array(), |
| 400 | 400 | // array of full server paths to any EED_Modules used by the addon |
| 401 | 401 | 'module_paths' => isset($setup_args['module_paths']) |
| 402 | - ? (array)$setup_args['module_paths'] |
|
| 402 | + ? (array) $setup_args['module_paths'] |
|
| 403 | 403 | : array(), |
| 404 | 404 | // array of full server paths to any EES_Shortcodes used by the addon |
| 405 | 405 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
| 406 | - ? (array)$setup_args['shortcode_paths'] |
|
| 406 | + ? (array) $setup_args['shortcode_paths'] |
|
| 407 | 407 | : array(), |
| 408 | 408 | 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
| 409 | 409 | ? (array) $setup_args['shortcode_fqcns'] |
| 410 | 410 | : array(), |
| 411 | 411 | // array of full server paths to any WP_Widgets used by the addon |
| 412 | 412 | 'widget_paths' => isset($setup_args['widget_paths']) |
| 413 | - ? (array)$setup_args['widget_paths'] |
|
| 413 | + ? (array) $setup_args['widget_paths'] |
|
| 414 | 414 | : array(), |
| 415 | 415 | // array of PUE options used by the addon |
| 416 | 416 | 'pue_options' => isset($setup_args['pue_options']) |
| 417 | - ? (array)$setup_args['pue_options'] |
|
| 417 | + ? (array) $setup_args['pue_options'] |
|
| 418 | 418 | : array(), |
| 419 | 419 | 'message_types' => isset($setup_args['message_types']) |
| 420 | - ? (array)$setup_args['message_types'] |
|
| 420 | + ? (array) $setup_args['message_types'] |
|
| 421 | 421 | : array(), |
| 422 | 422 | 'capabilities' => isset($setup_args['capabilities']) |
| 423 | - ? (array)$setup_args['capabilities'] |
|
| 423 | + ? (array) $setup_args['capabilities'] |
|
| 424 | 424 | : array(), |
| 425 | 425 | 'capability_maps' => isset($setup_args['capability_maps']) |
| 426 | - ? (array)$setup_args['capability_maps'] |
|
| 426 | + ? (array) $setup_args['capability_maps'] |
|
| 427 | 427 | : array(), |
| 428 | 428 | 'model_paths' => isset($setup_args['model_paths']) |
| 429 | - ? (array)$setup_args['model_paths'] |
|
| 429 | + ? (array) $setup_args['model_paths'] |
|
| 430 | 430 | : array(), |
| 431 | 431 | 'class_paths' => isset($setup_args['class_paths']) |
| 432 | - ? (array)$setup_args['class_paths'] |
|
| 432 | + ? (array) $setup_args['class_paths'] |
|
| 433 | 433 | : array(), |
| 434 | 434 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
| 435 | - ? (array)$setup_args['model_extension_paths'] |
|
| 435 | + ? (array) $setup_args['model_extension_paths'] |
|
| 436 | 436 | : array(), |
| 437 | 437 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
| 438 | - ? (array)$setup_args['class_extension_paths'] |
|
| 438 | + ? (array) $setup_args['class_extension_paths'] |
|
| 439 | 439 | : array(), |
| 440 | 440 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
| 441 | - ? (array)$setup_args['custom_post_types'] |
|
| 441 | + ? (array) $setup_args['custom_post_types'] |
|
| 442 | 442 | : array(), |
| 443 | 443 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
| 444 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 444 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 445 | 445 | : array(), |
| 446 | 446 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
| 447 | - ? (array)$setup_args['payment_method_paths'] |
|
| 447 | + ? (array) $setup_args['payment_method_paths'] |
|
| 448 | 448 | : array(), |
| 449 | 449 | 'default_terms' => isset($setup_args['default_terms']) |
| 450 | - ? (array)$setup_args['default_terms'] |
|
| 450 | + ? (array) $setup_args['default_terms'] |
|
| 451 | 451 | : array(), |
| 452 | 452 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
| 453 | 453 | // that can be used for adding upgrading/marketing info |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $setup_args['namespace']['FQNS'], |
| 460 | 460 | $setup_args['namespace']['DIR'] |
| 461 | 461 | ) |
| 462 | - ? (array)$setup_args['namespace'] |
|
| 462 | + ? (array) $setup_args['namespace'] |
|
| 463 | 463 | : array(), |
| 464 | 464 | ); |
| 465 | 465 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | '</span><br />' |
| 530 | 530 | ); |
| 531 | 531 | } |
| 532 | - if (! empty($incompatibility_message)) { |
|
| 532 | + if ( ! empty($incompatibility_message)) { |
|
| 533 | 533 | // remove 'activate' from the REQUEST |
| 534 | 534 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 535 | 535 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -557,19 +557,19 @@ discard block |
||
| 557 | 557 | */ |
| 558 | 558 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 559 | 559 | { |
| 560 | - if (! empty($setup_args['pue_options'])) { |
|
| 560 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 561 | 561 | self::$_settings[$addon_name]['pue_options'] = array( |
| 562 | 562 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 563 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 564 | - : 'espresso_' . strtolower($class_name), |
|
| 563 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 564 | + : 'espresso_'.strtolower($class_name), |
|
| 565 | 565 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 566 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 566 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 567 | 567 | : plugin_basename($setup_args['main_file_path']), |
| 568 | 568 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
| 569 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 569 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 570 | 570 | : '24', |
| 571 | 571 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
| 572 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 572 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 573 | 573 | : false, |
| 574 | 574 | ); |
| 575 | 575 | add_action( |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 618 | 618 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 619 | 619 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 620 | - if (! isset(self::$_settings[$addon_name]) |
|
| 620 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 621 | 621 | || (isset(self::$_settings[$addon_name]) |
| 622 | 622 | && ! isset(self::$_settings[$addon_name]['class_name']) |
| 623 | 623 | ) |
@@ -664,13 +664,13 @@ discard block |
||
| 664 | 664 | */ |
| 665 | 665 | private static function _setup_autoloaders($addon_name) |
| 666 | 666 | { |
| 667 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 667 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 668 | 668 | // setup autoloader for single file |
| 669 | 669 | EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
| 670 | 670 | } |
| 671 | 671 | // setup autoloaders for folders |
| 672 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 673 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 672 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 673 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 674 | 674 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 675 | 675 | } |
| 676 | 676 | } |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | private static function _register_data_migration_scripts($addon_name) |
| 724 | 724 | { |
| 725 | 725 | // setup DMS |
| 726 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 726 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 727 | 727 | EE_Register_Data_Migration_Scripts::register( |
| 728 | 728 | $addon_name, |
| 729 | 729 | array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | private static function _register_config($addon_name) |
| 741 | 741 | { |
| 742 | 742 | // if config_class is present let's register config. |
| 743 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 743 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 744 | 744 | EE_Register_Config::register( |
| 745 | 745 | self::$_settings[$addon_name]['config_class'], |
| 746 | 746 | array( |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | */ |
| 760 | 760 | private static function _register_admin_pages($addon_name) |
| 761 | 761 | { |
| 762 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 762 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 763 | 763 | EE_Register_Admin_Page::register( |
| 764 | 764 | $addon_name, |
| 765 | 765 | array('page_path' => self::$_settings[$addon_name]['admin_path']) |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | */ |
| 776 | 776 | private static function _register_modules($addon_name) |
| 777 | 777 | { |
| 778 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 778 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 779 | 779 | EE_Register_Module::register( |
| 780 | 780 | $addon_name, |
| 781 | 781 | array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | */ |
| 792 | 792 | private static function _register_shortcodes($addon_name) |
| 793 | 793 | { |
| 794 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 794 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 795 | 795 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
| 796 | 796 | ) { |
| 797 | 797 | EE_Register_Shortcode::register( |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | */ |
| 817 | 817 | private static function _register_widgets($addon_name) |
| 818 | 818 | { |
| 819 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 819 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 820 | 820 | EE_Register_Widget::register( |
| 821 | 821 | $addon_name, |
| 822 | 822 | array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | */ |
| 833 | 833 | private static function _register_capabilities($addon_name) |
| 834 | 834 | { |
| 835 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 835 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 836 | 836 | EE_Register_Capabilities::register( |
| 837 | 837 | $addon_name, |
| 838 | 838 | array( |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | */ |
| 852 | 852 | private static function _register_message_types($addon_name) |
| 853 | 853 | { |
| 854 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 854 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 855 | 855 | add_action( |
| 856 | 856 | 'EE_Brewing_Regular___messages_caf', |
| 857 | 857 | array('EE_Register_Addon', 'register_message_types') |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | private static function _register_payment_methods($addon_name) |
| 892 | 892 | { |
| 893 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 893 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 894 | 894 | EE_Register_Payment_Method::register( |
| 895 | 895 | $addon_name, |
| 896 | 896 | array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | //the plugin mainfile's path upon construction. |
| 927 | 927 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 928 | 928 | // call any additional admin_callback functions during load_admin_controller hook |
| 929 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 929 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 930 | 930 | add_action( |
| 931 | 931 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 932 | 932 | array($addon, self::$_settings[$addon_name]['admin_callback']) |
@@ -944,10 +944,10 @@ discard block |
||
| 944 | 944 | public static function load_pue_update() |
| 945 | 945 | { |
| 946 | 946 | // load PUE client |
| 947 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 947 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 948 | 948 | // cycle thru settings |
| 949 | 949 | foreach (self::$_settings as $settings) { |
| 950 | - if (! empty($settings['pue_options'])) { |
|
| 950 | + if ( ! empty($settings['pue_options'])) { |
|
| 951 | 951 | // initiate the class and start the plugin update engine! |
| 952 | 952 | new PluginUpdateEngineChecker( |
| 953 | 953 | // host file URL |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | // plugin slug(s) |
| 956 | 956 | array( |
| 957 | 957 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 958 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 958 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 959 | 959 | ), |
| 960 | 960 | // options |
| 961 | 961 | array( |
@@ -984,8 +984,8 @@ discard block |
||
| 984 | 984 | public static function register_message_types() |
| 985 | 985 | { |
| 986 | 986 | foreach (self::$_settings as $addon_name => $settings) { |
| 987 | - if (! empty($settings['message_types'])) { |
|
| 988 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 987 | + if ( ! empty($settings['message_types'])) { |
|
| 988 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 989 | 989 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 990 | 990 | } |
| 991 | 991 | } |
@@ -1006,48 +1006,48 @@ discard block |
||
| 1006 | 1006 | if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
| 1007 | 1007 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1008 | 1008 | $class_name = self::$_settings[$addon_name]['class_name']; |
| 1009 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1009 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1010 | 1010 | // setup DMS |
| 1011 | 1011 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1012 | 1012 | } |
| 1013 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1013 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1014 | 1014 | // register admin page |
| 1015 | 1015 | EE_Register_Admin_Page::deregister($addon_name); |
| 1016 | 1016 | } |
| 1017 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1017 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1018 | 1018 | // add to list of modules to be registered |
| 1019 | 1019 | EE_Register_Module::deregister($addon_name); |
| 1020 | 1020 | } |
| 1021 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1021 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1022 | 1022 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
| 1023 | 1023 | ) { |
| 1024 | 1024 | // add to list of shortcodes to be registered |
| 1025 | 1025 | EE_Register_Shortcode::deregister($addon_name); |
| 1026 | 1026 | } |
| 1027 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1027 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1028 | 1028 | // if config_class present let's register config. |
| 1029 | 1029 | EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
| 1030 | 1030 | } |
| 1031 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1031 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1032 | 1032 | // add to list of widgets to be registered |
| 1033 | 1033 | EE_Register_Widget::deregister($addon_name); |
| 1034 | 1034 | } |
| 1035 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1035 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1036 | 1036 | || |
| 1037 | 1037 | ! empty(self::$_settings[$addon_name]['class_paths']) |
| 1038 | 1038 | ) { |
| 1039 | 1039 | // add to list of shortcodes to be registered |
| 1040 | 1040 | EE_Register_Model::deregister($addon_name); |
| 1041 | 1041 | } |
| 1042 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1042 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1043 | 1043 | || |
| 1044 | 1044 | ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
| 1045 | 1045 | ) { |
| 1046 | 1046 | // add to list of shortcodes to be registered |
| 1047 | 1047 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1048 | 1048 | } |
| 1049 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1050 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1049 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1050 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1051 | 1051 | EE_Register_Message_Type::deregister($message_type); |
| 1052 | 1052 | } |
| 1053 | 1053 | } |
@@ -1059,14 +1059,14 @@ discard block |
||
| 1059 | 1059 | EE_Register_Capabilities::deregister($addon_name); |
| 1060 | 1060 | } |
| 1061 | 1061 | //deregister custom_post_types for addon |
| 1062 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1062 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1063 | 1063 | EE_Register_CPT::deregister($addon_name); |
| 1064 | 1064 | } |
| 1065 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1065 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1066 | 1066 | EE_Register_Payment_Method::deregister($addon_name); |
| 1067 | 1067 | } |
| 1068 | 1068 | remove_action( |
| 1069 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1069 | + 'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1070 | 1070 | array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
| 1071 | 1071 | ); |
| 1072 | 1072 | remove_action( |
@@ -14,249 +14,249 @@ |
||
| 14 | 14 | class EEH_URL |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * _add_query_arg |
|
| 19 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 20 | - * |
|
| 21 | - * @access public |
|
| 22 | - * @param array $args |
|
| 23 | - * @param string $url |
|
| 24 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 28 | - { |
|
| 29 | - if (empty($url)) { |
|
| 30 | - $user_msg = esc_html__( |
|
| 31 | - 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
| 32 | - 'event_espresso' |
|
| 33 | - ); |
|
| 34 | - $dev_msg = $user_msg . "\n" |
|
| 35 | - . sprintf( |
|
| 36 | - esc_html__( |
|
| 37 | - 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
| 38 | - 'event_espresso' |
|
| 39 | - ), |
|
| 40 | - __CLASS__ . '::add_query_args_and_nonce' |
|
| 41 | - ); |
|
| 42 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 43 | - } |
|
| 44 | - // check that an action exists and add nonce |
|
| 45 | - if (! $exclude_nonce) { |
|
| 46 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
| 47 | - $args = array_merge( |
|
| 48 | - $args, |
|
| 49 | - array( |
|
| 50 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - } else { |
|
| 54 | - $args = array_merge( |
|
| 55 | - $args, |
|
| 56 | - array( |
|
| 57 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - } |
|
| 17 | + /** |
|
| 18 | + * _add_query_arg |
|
| 19 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 20 | + * |
|
| 21 | + * @access public |
|
| 22 | + * @param array $args |
|
| 23 | + * @param string $url |
|
| 24 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 28 | + { |
|
| 29 | + if (empty($url)) { |
|
| 30 | + $user_msg = esc_html__( |
|
| 31 | + 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
| 32 | + 'event_espresso' |
|
| 33 | + ); |
|
| 34 | + $dev_msg = $user_msg . "\n" |
|
| 35 | + . sprintf( |
|
| 36 | + esc_html__( |
|
| 37 | + 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
| 38 | + 'event_espresso' |
|
| 39 | + ), |
|
| 40 | + __CLASS__ . '::add_query_args_and_nonce' |
|
| 41 | + ); |
|
| 42 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 43 | + } |
|
| 44 | + // check that an action exists and add nonce |
|
| 45 | + if (! $exclude_nonce) { |
|
| 46 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 47 | + $args = array_merge( |
|
| 48 | + $args, |
|
| 49 | + array( |
|
| 50 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + } else { |
|
| 54 | + $args = array_merge( |
|
| 55 | + $args, |
|
| 56 | + array( |
|
| 57 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - //finally, let's always add a return address (if present) :) |
|
| 64 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 65 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 66 | - : $args; |
|
| 63 | + //finally, let's always add a return address (if present) :) |
|
| 64 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 65 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 66 | + : $args; |
|
| 67 | 67 | |
| 68 | - return add_query_arg($args, $url); |
|
| 69 | - } |
|
| 68 | + return add_query_arg($args, $url); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns whether not the remote file exists. |
|
| 74 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 75 | - * |
|
| 76 | - * @param string $url |
|
| 77 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - public static function remote_file_exists($url, $args = array()) |
|
| 81 | - { |
|
| 82 | - $results = wp_remote_request( |
|
| 83 | - $url, |
|
| 84 | - array_merge( |
|
| 85 | - array( |
|
| 86 | - 'method' => 'GET', |
|
| 87 | - 'redirection' => 1, |
|
| 88 | - ), |
|
| 89 | - $args |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 92 | - if (! $results instanceof WP_Error && |
|
| 93 | - isset($results['response']) && |
|
| 94 | - isset($results['response']['code']) && |
|
| 95 | - $results['response']['code'] == '200') { |
|
| 96 | - return true; |
|
| 97 | - } else { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - } |
|
| 72 | + /** |
|
| 73 | + * Returns whether not the remote file exists. |
|
| 74 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 75 | + * |
|
| 76 | + * @param string $url |
|
| 77 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + public static function remote_file_exists($url, $args = array()) |
|
| 81 | + { |
|
| 82 | + $results = wp_remote_request( |
|
| 83 | + $url, |
|
| 84 | + array_merge( |
|
| 85 | + array( |
|
| 86 | + 'method' => 'GET', |
|
| 87 | + 'redirection' => 1, |
|
| 88 | + ), |
|
| 89 | + $args |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | + if (! $results instanceof WP_Error && |
|
| 93 | + isset($results['response']) && |
|
| 94 | + isset($results['response']['code']) && |
|
| 95 | + $results['response']['code'] == '200') { |
|
| 96 | + return true; |
|
| 97 | + } else { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * refactor_url |
|
| 105 | - * primarily used for removing the query string from a URL |
|
| 106 | - * |
|
| 107 | - * @param string $url |
|
| 108 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 109 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 113 | - { |
|
| 114 | - // break apart incoming URL |
|
| 115 | - $url_bits = parse_url($url); |
|
| 116 | - // HTTP or HTTPS ? |
|
| 117 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 118 | - // domain |
|
| 119 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 120 | - // if only the base URL is requested, then return that now |
|
| 121 | - if ($base_url_only) { |
|
| 122 | - return $scheme . $host; |
|
| 123 | - } |
|
| 124 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 125 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 126 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 127 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 128 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 129 | - // if the query string is not required, then return what we have so far |
|
| 130 | - if ($remove_query) { |
|
| 131 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 132 | - } |
|
| 133 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 134 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 135 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 136 | - } |
|
| 103 | + /** |
|
| 104 | + * refactor_url |
|
| 105 | + * primarily used for removing the query string from a URL |
|
| 106 | + * |
|
| 107 | + * @param string $url |
|
| 108 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 109 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 113 | + { |
|
| 114 | + // break apart incoming URL |
|
| 115 | + $url_bits = parse_url($url); |
|
| 116 | + // HTTP or HTTPS ? |
|
| 117 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 118 | + // domain |
|
| 119 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 120 | + // if only the base URL is requested, then return that now |
|
| 121 | + if ($base_url_only) { |
|
| 122 | + return $scheme . $host; |
|
| 123 | + } |
|
| 124 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 125 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 126 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 127 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 128 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 129 | + // if the query string is not required, then return what we have so far |
|
| 130 | + if ($remove_query) { |
|
| 131 | + return $scheme . $user . $pass . $host . $port . $path; |
|
| 132 | + } |
|
| 133 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 134 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 135 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * get_query_string |
|
| 141 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 142 | - * |
|
| 143 | - * @param string $url |
|
| 144 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 145 | - * simply return the query string |
|
| 146 | - * @return string|array |
|
| 147 | - */ |
|
| 148 | - public static function get_query_string($url = '', $as_array = true) |
|
| 149 | - { |
|
| 150 | - // decode, then break apart incoming URL |
|
| 151 | - $url_bits = parse_url(html_entity_decode($url)); |
|
| 152 | - // grab query string from URL |
|
| 153 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 154 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 155 | - if (! $as_array) { |
|
| 156 | - return $query; |
|
| 157 | - } |
|
| 158 | - // if no query string exists then just return an empty array now |
|
| 159 | - if (empty($query)) { |
|
| 160 | - return array(); |
|
| 161 | - } |
|
| 162 | - // empty array to hold results |
|
| 163 | - $query_params = array(); |
|
| 164 | - // now break apart the query string into separate params |
|
| 165 | - $query = explode('&', $query); |
|
| 166 | - // loop thru our query params |
|
| 167 | - foreach ($query as $query_args) { |
|
| 168 | - // break apart the key value pairs |
|
| 169 | - $query_args = explode('=', $query_args); |
|
| 170 | - // and add to our results array |
|
| 171 | - $query_params[$query_args[0]] = $query_args[1]; |
|
| 172 | - } |
|
| 173 | - return $query_params; |
|
| 174 | - } |
|
| 139 | + /** |
|
| 140 | + * get_query_string |
|
| 141 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 142 | + * |
|
| 143 | + * @param string $url |
|
| 144 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 145 | + * simply return the query string |
|
| 146 | + * @return string|array |
|
| 147 | + */ |
|
| 148 | + public static function get_query_string($url = '', $as_array = true) |
|
| 149 | + { |
|
| 150 | + // decode, then break apart incoming URL |
|
| 151 | + $url_bits = parse_url(html_entity_decode($url)); |
|
| 152 | + // grab query string from URL |
|
| 153 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 154 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 155 | + if (! $as_array) { |
|
| 156 | + return $query; |
|
| 157 | + } |
|
| 158 | + // if no query string exists then just return an empty array now |
|
| 159 | + if (empty($query)) { |
|
| 160 | + return array(); |
|
| 161 | + } |
|
| 162 | + // empty array to hold results |
|
| 163 | + $query_params = array(); |
|
| 164 | + // now break apart the query string into separate params |
|
| 165 | + $query = explode('&', $query); |
|
| 166 | + // loop thru our query params |
|
| 167 | + foreach ($query as $query_args) { |
|
| 168 | + // break apart the key value pairs |
|
| 169 | + $query_args = explode('=', $query_args); |
|
| 170 | + // and add to our results array |
|
| 171 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 172 | + } |
|
| 173 | + return $query_params; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * prevent_prefetching |
|
| 179 | - * |
|
| 180 | - * @return void |
|
| 181 | - */ |
|
| 182 | - public static function prevent_prefetching() |
|
| 183 | - { |
|
| 184 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 185 | - // with the registration process |
|
| 186 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 187 | - } |
|
| 177 | + /** |
|
| 178 | + * prevent_prefetching |
|
| 179 | + * |
|
| 180 | + * @return void |
|
| 181 | + */ |
|
| 182 | + public static function prevent_prefetching() |
|
| 183 | + { |
|
| 184 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 185 | + // with the registration process |
|
| 186 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * This generates a unique site-specific string. |
|
| 192 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 193 | - * urls. |
|
| 194 | - * |
|
| 195 | - * @param string $prefix Use this to prefix the string with something. |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 198 | - public static function generate_unique_token($prefix = '') |
|
| 199 | - { |
|
| 200 | - $token = md5(uniqid() . mt_rand()); |
|
| 201 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 202 | - } |
|
| 190 | + /** |
|
| 191 | + * This generates a unique site-specific string. |
|
| 192 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 193 | + * urls. |
|
| 194 | + * |
|
| 195 | + * @param string $prefix Use this to prefix the string with something. |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | + public static function generate_unique_token($prefix = '') |
|
| 199 | + { |
|
| 200 | + $token = md5(uniqid() . mt_rand()); |
|
| 201 | + return $prefix ? $prefix . '_' . $token : $token; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * filter_input_server_url |
|
| 207 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 208 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 209 | - * |
|
| 210 | - * @param string $server_variable |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 214 | - { |
|
| 215 | - $URL = ''; |
|
| 216 | - $server_variables = array( |
|
| 217 | - 'REQUEST_URI' => 1, |
|
| 218 | - 'HTTP_HOST' => 1, |
|
| 219 | - 'PHP_SELF' => 1, |
|
| 220 | - ); |
|
| 221 | - $server_variable = strtoupper($server_variable); |
|
| 222 | - // whitelist INPUT_SERVER var |
|
| 223 | - if (isset($server_variables[$server_variable])) { |
|
| 224 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 225 | - if (empty($URL)) { |
|
| 226 | - // fallback sanitization if the above fails |
|
| 227 | - $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - return $URL; |
|
| 231 | - } |
|
| 205 | + /** |
|
| 206 | + * filter_input_server_url |
|
| 207 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 208 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 209 | + * |
|
| 210 | + * @param string $server_variable |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 214 | + { |
|
| 215 | + $URL = ''; |
|
| 216 | + $server_variables = array( |
|
| 217 | + 'REQUEST_URI' => 1, |
|
| 218 | + 'HTTP_HOST' => 1, |
|
| 219 | + 'PHP_SELF' => 1, |
|
| 220 | + ); |
|
| 221 | + $server_variable = strtoupper($server_variable); |
|
| 222 | + // whitelist INPUT_SERVER var |
|
| 223 | + if (isset($server_variables[$server_variable])) { |
|
| 224 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 225 | + if (empty($URL)) { |
|
| 226 | + // fallback sanitization if the above fails |
|
| 227 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + return $URL; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Gets the current page's full URL. |
|
| 236 | - * |
|
| 237 | - * @return string |
|
| 238 | - */ |
|
| 239 | - public static function current_url() |
|
| 240 | - { |
|
| 241 | - $url = ''; |
|
| 242 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 243 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
| 244 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 245 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 246 | - } |
|
| 247 | - return $url; |
|
| 248 | - } |
|
| 234 | + /** |
|
| 235 | + * Gets the current page's full URL. |
|
| 236 | + * |
|
| 237 | + * @return string |
|
| 238 | + */ |
|
| 239 | + public static function current_url() |
|
| 240 | + { |
|
| 241 | + $url = ''; |
|
| 242 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 243 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
| 244 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 245 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 246 | + } |
|
| 247 | + return $url; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 253 | - * |
|
| 254 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 255 | - * @since 4.9.46.rc.029 |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 259 | - { |
|
| 260 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 261 | - } |
|
| 251 | + /** |
|
| 252 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 253 | + * |
|
| 254 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 255 | + * @since 4.9.46.rc.029 |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 259 | + { |
|
| 260 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 261 | + } |
|
| 262 | 262 | } |
@@ -31,23 +31,23 @@ discard block |
||
| 31 | 31 | 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
| 32 | 32 | 'event_espresso' |
| 33 | 33 | ); |
| 34 | - $dev_msg = $user_msg . "\n" |
|
| 34 | + $dev_msg = $user_msg."\n" |
|
| 35 | 35 | . sprintf( |
| 36 | 36 | esc_html__( |
| 37 | 37 | 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
| 38 | 38 | 'event_espresso' |
| 39 | 39 | ), |
| 40 | - __CLASS__ . '::add_query_args_and_nonce' |
|
| 40 | + __CLASS__.'::add_query_args_and_nonce' |
|
| 41 | 41 | ); |
| 42 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 42 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 43 | 43 | } |
| 44 | 44 | // check that an action exists and add nonce |
| 45 | - if (! $exclude_nonce) { |
|
| 45 | + if ( ! $exclude_nonce) { |
|
| 46 | 46 | if (isset($args['action']) && ! empty($args['action'])) { |
| 47 | 47 | $args = array_merge( |
| 48 | 48 | $args, |
| 49 | 49 | array( |
| 50 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 50 | + $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce') |
|
| 51 | 51 | ) |
| 52 | 52 | ); |
| 53 | 53 | } else { |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $args |
| 90 | 90 | ) |
| 91 | 91 | ); |
| 92 | - if (! $results instanceof WP_Error && |
|
| 92 | + if ( ! $results instanceof WP_Error && |
|
| 93 | 93 | isset($results['response']) && |
| 94 | 94 | isset($results['response']['code']) && |
| 95 | 95 | $results['response']['code'] == '200') { |
@@ -114,25 +114,25 @@ discard block |
||
| 114 | 114 | // break apart incoming URL |
| 115 | 115 | $url_bits = parse_url($url); |
| 116 | 116 | // HTTP or HTTPS ? |
| 117 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 117 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 118 | 118 | // domain |
| 119 | 119 | $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
| 120 | 120 | // if only the base URL is requested, then return that now |
| 121 | 121 | if ($base_url_only) { |
| 122 | - return $scheme . $host; |
|
| 122 | + return $scheme.$host; |
|
| 123 | 123 | } |
| 124 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 124 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 125 | 125 | $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
| 126 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 127 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 126 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 127 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 128 | 128 | $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
| 129 | 129 | // if the query string is not required, then return what we have so far |
| 130 | 130 | if ($remove_query) { |
| 131 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 131 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 132 | 132 | } |
| 133 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 134 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 135 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 133 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 134 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 135 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // grab query string from URL |
| 153 | 153 | $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
| 154 | 154 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 155 | - if (! $as_array) { |
|
| 155 | + if ( ! $as_array) { |
|
| 156 | 156 | return $query; |
| 157 | 157 | } |
| 158 | 158 | // if no query string exists then just return an empty array now |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public static function generate_unique_token($prefix = '') |
| 199 | 199 | { |
| 200 | - $token = md5(uniqid() . mt_rand()); |
|
| 201 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 200 | + $token = md5(uniqid().mt_rand()); |
|
| 201 | + return $prefix ? $prefix.'_'.$token : $token; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | 'HTTP_HOST' => 1, |
| 219 | 219 | 'PHP_SELF' => 1, |
| 220 | 220 | ); |
| 221 | - $server_variable = strtoupper($server_variable); |
|
| 221 | + $server_variable = strtoupper($server_variable); |
|
| 222 | 222 | // whitelist INPUT_SERVER var |
| 223 | 223 | if (isset($server_variables[$server_variable])) { |
| 224 | 224 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | EE_Maintenance_Mode $maintenance_mode = null |
| 133 | 133 | ) { |
| 134 | 134 | // check if class object is instantiated |
| 135 | - if (! self::$_instance instanceof EE_System) { |
|
| 135 | + if ( ! self::$_instance instanceof EE_System) { |
|
| 136 | 136 | self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
| 137 | 137 | } |
| 138 | 138 | return self::$_instance; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | { |
| 300 | 300 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
| 301 | 301 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
| 302 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 302 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
| 337 | 337 | ) |
| 338 | 338 | ) { |
| 339 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 339 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
| 340 | 340 | } |
| 341 | 341 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
| 342 | 342 | } |
@@ -444,11 +444,11 @@ discard block |
||
| 444 | 444 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
| 445 | 445 | { |
| 446 | 446 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
| 447 | - if (! $espresso_db_update) { |
|
| 447 | + if ( ! $espresso_db_update) { |
|
| 448 | 448 | $espresso_db_update = get_option('espresso_db_update'); |
| 449 | 449 | } |
| 450 | 450 | // check that option is an array |
| 451 | - if (! is_array($espresso_db_update)) { |
|
| 451 | + if ( ! is_array($espresso_db_update)) { |
|
| 452 | 452 | // if option is FALSE, then it never existed |
| 453 | 453 | if ($espresso_db_update === false) { |
| 454 | 454 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
| 555 | 555 | { |
| 556 | - if (! $version_history) { |
|
| 556 | + if ( ! $version_history) { |
|
| 557 | 557 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
| 558 | 558 | } |
| 559 | 559 | if ($current_version_to_add === null) { |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | if ($activation_history_for_addon) { |
| 652 | 652 | //it exists, so this isn't a completely new install |
| 653 | 653 | //check if this version already in that list of previously installed versions |
| 654 | - if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 654 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 655 | 655 | //it a version we haven't seen before |
| 656 | 656 | if ($version_is_higher === 1) { |
| 657 | 657 | $req_type = EE_System::req_type_upgrade; |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | foreach ($activation_history as $version => $times_activated) { |
| 732 | 732 | //check there is a record of when this version was activated. Otherwise, |
| 733 | 733 | //mark it as unknown |
| 734 | - if (! $times_activated) { |
|
| 734 | + if ( ! $times_activated) { |
|
| 735 | 735 | $times_activated = array('unknown-date'); |
| 736 | 736 | } |
| 737 | 737 | if (is_string($times_activated)) { |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | private function _parse_model_names() |
| 832 | 832 | { |
| 833 | 833 | //get all the files in the EE_MODELS folder that end in .model.php |
| 834 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 834 | + $models = glob(EE_MODELS.'*.model.php'); |
|
| 835 | 835 | $model_names = array(); |
| 836 | 836 | $non_abstract_db_models = array(); |
| 837 | 837 | foreach ($models as $model) { |
@@ -861,8 +861,8 @@ discard block |
||
| 861 | 861 | */ |
| 862 | 862 | private function _maybe_brew_regular() |
| 863 | 863 | { |
| 864 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 865 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 864 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
| 865 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | |
@@ -910,17 +910,17 @@ discard block |
||
| 910 | 910 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
| 911 | 911 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
| 912 | 912 | ); |
| 913 | - if (! empty($class_names)) { |
|
| 913 | + if ( ! empty($class_names)) { |
|
| 914 | 914 | $msg = __( |
| 915 | 915 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
| 916 | 916 | 'event_espresso' |
| 917 | 917 | ); |
| 918 | 918 | $msg .= '<ul>'; |
| 919 | 919 | foreach ($class_names as $class_name) { |
| 920 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
| 920 | + $msg .= '<li><b>Event Espresso - '.str_replace( |
|
| 921 | 921 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
| 922 | 922 | $class_name |
| 923 | - ) . '</b></li>'; |
|
| 923 | + ).'</b></li>'; |
|
| 924 | 924 | } |
| 925 | 925 | $msg .= '</ul>'; |
| 926 | 926 | $msg .= __( |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | private function _deactivate_incompatible_addons() |
| 992 | 992 | { |
| 993 | 993 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
| 994 | - if (! empty($incompatible_addons)) { |
|
| 994 | + if ( ! empty($incompatible_addons)) { |
|
| 995 | 995 | $active_plugins = get_option('active_plugins', array()); |
| 996 | 996 | foreach ($active_plugins as $active_plugin) { |
| 997 | 997 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -1052,10 +1052,10 @@ discard block |
||
| 1052 | 1052 | { |
| 1053 | 1053 | do_action('AHEE__EE_System__load_controllers__start'); |
| 1054 | 1054 | // let's get it started |
| 1055 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1055 | + if ( ! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1056 | 1056 | do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
| 1057 | 1057 | $this->loader->getShared('EE_Front_Controller'); |
| 1058 | - } else if (! EE_FRONT_AJAX) { |
|
| 1058 | + } else if ( ! EE_FRONT_AJAX) { |
|
| 1059 | 1059 | do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
| 1060 | 1060 | $this->loader->getShared('EE_Admin'); |
| 1061 | 1061 | } |
@@ -1076,8 +1076,8 @@ discard block |
||
| 1076 | 1076 | $this->loader->getShared('EE_Session'); |
| 1077 | 1077 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
| 1078 | 1078 | // load_espresso_template_tags |
| 1079 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1080 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1079 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
| 1080 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
| 1083 | 1083 | $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
@@ -1139,13 +1139,13 @@ discard block |
||
| 1139 | 1139 | public static function do_not_cache() |
| 1140 | 1140 | { |
| 1141 | 1141 | // set no cache constants |
| 1142 | - if (! defined('DONOTCACHEPAGE')) { |
|
| 1142 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
| 1143 | 1143 | define('DONOTCACHEPAGE', true); |
| 1144 | 1144 | } |
| 1145 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1145 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 1146 | 1146 | define('DONOTCACHCEOBJECT', true); |
| 1147 | 1147 | } |
| 1148 | - if (! defined('DONOTCACHEDB')) { |
|
| 1148 | + if ( ! defined('DONOTCACHEDB')) { |
|
| 1149 | 1149 | define('DONOTCACHEDB', true); |
| 1150 | 1150 | } |
| 1151 | 1151 | // add no cache headers |
@@ -21,1188 +21,1188 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 26 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 27 | - */ |
|
| 28 | - const req_type_normal = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Indicates this is a brand new installation of EE so we should install |
|
| 32 | - * tables and default data etc |
|
| 33 | - */ |
|
| 34 | - const req_type_new_activation = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 38 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 39 | - * and that default data is setup too |
|
| 40 | - */ |
|
| 41 | - const req_type_reactivation = 2; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * indicates that EE has been upgraded since its previous request. |
|
| 45 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 46 | - */ |
|
| 47 | - const req_type_upgrade = 3; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 51 | - */ |
|
| 52 | - const req_type_downgrade = 4; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @deprecated since version 4.6.0.dev.006 |
|
| 56 | - * Now whenever a new_activation is detected the request type is still just |
|
| 57 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 58 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 59 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 60 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 61 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 62 | - */ |
|
| 63 | - const req_type_activation_but_not_installed = 5; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 67 | - */ |
|
| 68 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_System $_instance |
|
| 73 | - */ |
|
| 74 | - private static $_instance; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Registry $registry |
|
| 78 | - */ |
|
| 79 | - private $registry; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var LoaderInterface $loader |
|
| 83 | - */ |
|
| 84 | - private $loader; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @var EE_Capabilities $capabilities |
|
| 88 | - */ |
|
| 89 | - private $capabilities; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var EE_Request $request |
|
| 93 | - */ |
|
| 94 | - private $request; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
| 98 | - */ |
|
| 99 | - private $maintenance_mode; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 103 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 104 | - * |
|
| 105 | - * @var int $_req_type |
|
| 106 | - */ |
|
| 107 | - private $_req_type; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 111 | - * |
|
| 112 | - * @var boolean $_major_version_change |
|
| 113 | - */ |
|
| 114 | - private $_major_version_change = false; |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @singleton method used to instantiate class object |
|
| 120 | - * @param EE_Registry|null $registry |
|
| 121 | - * @param LoaderInterface|null $loader |
|
| 122 | - * @param EE_Capabilities|null $capabilities |
|
| 123 | - * @param EE_Request|null $request |
|
| 124 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 125 | - * @return EE_System |
|
| 126 | - */ |
|
| 127 | - public static function instance( |
|
| 128 | - EE_Registry $registry = null, |
|
| 129 | - LoaderInterface $loader = null, |
|
| 130 | - EE_Capabilities $capabilities = null, |
|
| 131 | - EE_Request $request = null, |
|
| 132 | - EE_Maintenance_Mode $maintenance_mode = null |
|
| 133 | - ) { |
|
| 134 | - // check if class object is instantiated |
|
| 135 | - if (! self::$_instance instanceof EE_System) { |
|
| 136 | - self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
| 137 | - } |
|
| 138 | - return self::$_instance; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * resets the instance and returns it |
|
| 145 | - * |
|
| 146 | - * @return EE_System |
|
| 147 | - */ |
|
| 148 | - public static function reset() |
|
| 149 | - { |
|
| 150 | - self::$_instance->_req_type = null; |
|
| 151 | - //make sure none of the old hooks are left hanging around |
|
| 152 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 153 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 154 | - EE_Data_Migration_Manager::reset(); |
|
| 155 | - self::instance()->detect_activations_or_upgrades(); |
|
| 156 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 157 | - return self::instance(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * sets hooks for running rest of system |
|
| 164 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 165 | - * starting EE Addons from any other point may lead to problems |
|
| 166 | - * |
|
| 167 | - * @param EE_Registry $registry |
|
| 168 | - * @param LoaderInterface $loader |
|
| 169 | - * @param EE_Capabilities $capabilities |
|
| 170 | - * @param EE_Request $request |
|
| 171 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
| 172 | - */ |
|
| 173 | - private function __construct( |
|
| 174 | - EE_Registry $registry, |
|
| 175 | - LoaderInterface $loader, |
|
| 176 | - EE_Capabilities $capabilities, |
|
| 177 | - EE_Request $request, |
|
| 178 | - EE_Maintenance_Mode $maintenance_mode |
|
| 179 | - ) { |
|
| 180 | - $this->registry = $registry; |
|
| 181 | - $this->loader = $loader; |
|
| 182 | - $this->capabilities = $capabilities; |
|
| 183 | - $this->request = $request; |
|
| 184 | - $this->maintenance_mode = $maintenance_mode; |
|
| 185 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 186 | - add_action( |
|
| 187 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 188 | - array($this, 'loadCapabilities'), |
|
| 189 | - 5 |
|
| 190 | - ); |
|
| 191 | - add_action( |
|
| 192 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 193 | - array($this, 'loadCommandBus'), |
|
| 194 | - 7 |
|
| 195 | - ); |
|
| 196 | - add_action( |
|
| 197 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 198 | - array($this, 'loadPluginApi'), |
|
| 199 | - 9 |
|
| 200 | - ); |
|
| 201 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 202 | - add_action( |
|
| 203 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 204 | - array($this, 'load_espresso_addons') |
|
| 205 | - ); |
|
| 206 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 207 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 208 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 209 | - // detect whether install or upgrade |
|
| 210 | - add_action( |
|
| 211 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 212 | - array($this, 'detect_activations_or_upgrades'), |
|
| 213 | - 3 |
|
| 214 | - ); |
|
| 215 | - // load EE_Config, EE_Textdomain, etc |
|
| 216 | - add_action( |
|
| 217 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 218 | - array($this, 'load_core_configuration'), |
|
| 219 | - 5 |
|
| 220 | - ); |
|
| 221 | - // load EE_Config, EE_Textdomain, etc |
|
| 222 | - add_action( |
|
| 223 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 224 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 225 | - 7 |
|
| 226 | - ); |
|
| 227 | - // you wanna get going? I wanna get going... let's get going! |
|
| 228 | - add_action( |
|
| 229 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 230 | - array($this, 'brew_espresso'), |
|
| 231 | - 9 |
|
| 232 | - ); |
|
| 233 | - //other housekeeping |
|
| 234 | - //exclude EE critical pages from wp_list_pages |
|
| 235 | - add_filter( |
|
| 236 | - 'wp_list_pages_excludes', |
|
| 237 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
| 238 | - 10 |
|
| 239 | - ); |
|
| 240 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 241 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 242 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * load and setup EE_Capabilities |
|
| 249 | - * |
|
| 250 | - * @return void |
|
| 251 | - * @throws EE_Error |
|
| 252 | - */ |
|
| 253 | - public function loadCapabilities() |
|
| 254 | - { |
|
| 255 | - $this->loader->getShared('EE_Capabilities'); |
|
| 256 | - add_action( |
|
| 257 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 258 | - function() { |
|
| 259 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
| 260 | - } |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * create and cache the CommandBus, and also add middleware |
|
| 268 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
| 269 | - * which is why we need to load the CommandBus after Caps are set up |
|
| 270 | - * |
|
| 271 | - * @return void |
|
| 272 | - * @throws EE_Error |
|
| 273 | - */ |
|
| 274 | - public function loadCommandBus() |
|
| 275 | - { |
|
| 276 | - $this->loader->getShared( |
|
| 277 | - 'CommandBusInterface', |
|
| 278 | - array( |
|
| 279 | - null, |
|
| 280 | - apply_filters( |
|
| 281 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 282 | - array( |
|
| 283 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 284 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 285 | - ) |
|
| 286 | - ), |
|
| 287 | - ) |
|
| 288 | - ); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @return void |
|
| 295 | - * @throws EE_Error |
|
| 296 | - */ |
|
| 297 | - public function loadPluginApi() |
|
| 298 | - { |
|
| 299 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 300 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 301 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * load_espresso_addons |
|
| 308 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 309 | - * this is hooked into both: |
|
| 310 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 311 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 312 | - * and the WP 'activate_plugin' hook point |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @return void |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public function load_espresso_addons() |
|
| 319 | - { |
|
| 320 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 321 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 322 | - //We want it for mobile apps. Just include the entire plugin |
|
| 323 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
| 324 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 325 | - //and causes a fatal error |
|
| 326 | - if ( |
|
| 327 | - ! ( |
|
| 328 | - isset($_GET['activate']) |
|
| 329 | - && $_GET['activate'] === 'true' |
|
| 330 | - ) |
|
| 331 | - && ! function_exists('json_basic_auth_handler') |
|
| 332 | - && ! function_exists('json_basic_auth_error') |
|
| 333 | - && ! ( |
|
| 334 | - isset($_GET['action']) |
|
| 335 | - && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
| 336 | - ) |
|
| 337 | - ) { |
|
| 338 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 339 | - } |
|
| 340 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * detect_activations_or_upgrades |
|
| 347 | - * Checks for activation or upgrade of core first; |
|
| 348 | - * then also checks if any registered addons have been activated or upgraded |
|
| 349 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 350 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 351 | - * |
|
| 352 | - * @access public |
|
| 353 | - * @return void |
|
| 354 | - */ |
|
| 355 | - public function detect_activations_or_upgrades() |
|
| 356 | - { |
|
| 357 | - //first off: let's make sure to handle core |
|
| 358 | - $this->detect_if_activation_or_upgrade(); |
|
| 359 | - foreach ($this->registry->addons as $addon) { |
|
| 360 | - if ($addon instanceof EE_Addon) { |
|
| 361 | - //detect teh request type for that addon |
|
| 362 | - $addon->detect_activation_or_upgrade(); |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * detect_if_activation_or_upgrade |
|
| 371 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 372 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 373 | - * |
|
| 374 | - * @access public |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - public function detect_if_activation_or_upgrade() |
|
| 378 | - { |
|
| 379 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 380 | - // check if db has been updated, or if its a brand-new installation |
|
| 381 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 382 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 383 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 384 | - switch ($request_type) { |
|
| 385 | - case EE_System::req_type_new_activation: |
|
| 386 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 387 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 388 | - break; |
|
| 389 | - case EE_System::req_type_reactivation: |
|
| 390 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 391 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 392 | - break; |
|
| 393 | - case EE_System::req_type_upgrade: |
|
| 394 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 395 | - //migrations may be required now that we've upgraded |
|
| 396 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 397 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 398 | - // echo "done upgrade";die; |
|
| 399 | - break; |
|
| 400 | - case EE_System::req_type_downgrade: |
|
| 401 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 402 | - //its possible migrations are no longer required |
|
| 403 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 404 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 405 | - break; |
|
| 406 | - case EE_System::req_type_normal: |
|
| 407 | - default: |
|
| 408 | - // $this->_maybe_redirect_to_ee_about(); |
|
| 409 | - break; |
|
| 410 | - } |
|
| 411 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Updates the list of installed versions and sets hooks for |
|
| 418 | - * initializing the database later during the request |
|
| 419 | - * |
|
| 420 | - * @param array $espresso_db_update |
|
| 421 | - */ |
|
| 422 | - private function _handle_core_version_change($espresso_db_update) |
|
| 423 | - { |
|
| 424 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 425 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 426 | - add_action( |
|
| 427 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 428 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 429 | - ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 436 | - * information about what versions of EE have been installed and activated, |
|
| 437 | - * NOT necessarily the state of the database |
|
| 438 | - * |
|
| 439 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 440 | - * If not supplied, fetches it from the options table |
|
| 441 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 442 | - */ |
|
| 443 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 444 | - { |
|
| 445 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 446 | - if (! $espresso_db_update) { |
|
| 447 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 448 | - } |
|
| 449 | - // check that option is an array |
|
| 450 | - if (! is_array($espresso_db_update)) { |
|
| 451 | - // if option is FALSE, then it never existed |
|
| 452 | - if ($espresso_db_update === false) { |
|
| 453 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 454 | - $espresso_db_update = array(); |
|
| 455 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 456 | - } else { |
|
| 457 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 458 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 459 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 460 | - } |
|
| 461 | - } else { |
|
| 462 | - $corrected_db_update = array(); |
|
| 463 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 464 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 465 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 466 | - //the key is an int, and the value IS NOT an array |
|
| 467 | - //so it must be numerically-indexed, where values are versions installed... |
|
| 468 | - //fix it! |
|
| 469 | - $version_string = $should_be_array; |
|
| 470 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 471 | - } else { |
|
| 472 | - //ok it checks out |
|
| 473 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - $espresso_db_update = $corrected_db_update; |
|
| 477 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 478 | - } |
|
| 479 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 480 | - return $espresso_db_update; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 487 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 488 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 489 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 490 | - * so that it will be done when migrations are finished |
|
| 491 | - * |
|
| 492 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 493 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 494 | - * This is a resource-intensive job |
|
| 495 | - * so we prefer to only do it when necessary |
|
| 496 | - * @return void |
|
| 497 | - * @throws EE_Error |
|
| 498 | - */ |
|
| 499 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 500 | - { |
|
| 501 | - $request_type = $this->detect_req_type(); |
|
| 502 | - //only initialize system if we're not in maintenance mode. |
|
| 503 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 504 | - update_option('ee_flush_rewrite_rules', true); |
|
| 505 | - if ($verify_schema) { |
|
| 506 | - EEH_Activation::initialize_db_and_folders(); |
|
| 507 | - } |
|
| 508 | - EEH_Activation::initialize_db_content(); |
|
| 509 | - EEH_Activation::system_initialization(); |
|
| 510 | - if ($initialize_addons_too) { |
|
| 511 | - $this->initialize_addons(); |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 515 | - } |
|
| 516 | - if ($request_type === EE_System::req_type_new_activation |
|
| 517 | - || $request_type === EE_System::req_type_reactivation |
|
| 518 | - || ( |
|
| 519 | - $request_type === EE_System::req_type_upgrade |
|
| 520 | - && $this->is_major_version_change() |
|
| 521 | - ) |
|
| 522 | - ) { |
|
| 523 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Initializes the db for all registered addons |
|
| 531 | - * |
|
| 532 | - * @throws EE_Error |
|
| 533 | - */ |
|
| 534 | - public function initialize_addons() |
|
| 535 | - { |
|
| 536 | - //foreach registered addon, make sure its db is up-to-date too |
|
| 537 | - foreach ($this->registry->addons as $addon) { |
|
| 538 | - if ($addon instanceof EE_Addon) { |
|
| 539 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 548 | - * |
|
| 549 | - * @param array $version_history |
|
| 550 | - * @param string $current_version_to_add version to be added to the version history |
|
| 551 | - * @return boolean success as to whether or not this option was changed |
|
| 552 | - */ |
|
| 553 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 554 | - { |
|
| 555 | - if (! $version_history) { |
|
| 556 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 557 | - } |
|
| 558 | - if ($current_version_to_add === null) { |
|
| 559 | - $current_version_to_add = espresso_version(); |
|
| 560 | - } |
|
| 561 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 562 | - // re-save |
|
| 563 | - return update_option('espresso_db_update', $version_history); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Detects if the current version indicated in the has existed in the list of |
|
| 570 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 571 | - * |
|
| 572 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 573 | - * If not supplied, fetches it from the options table. |
|
| 574 | - * Also, caches its result so later parts of the code can also know whether |
|
| 575 | - * there's been an update or not. This way we can add the current version to |
|
| 576 | - * espresso_db_update, but still know if this is a new install or not |
|
| 577 | - * @return int one of the constants on EE_System::req_type_ |
|
| 578 | - */ |
|
| 579 | - public function detect_req_type($espresso_db_update = null) |
|
| 580 | - { |
|
| 581 | - if ($this->_req_type === null) { |
|
| 582 | - $espresso_db_update = ! empty($espresso_db_update) |
|
| 583 | - ? $espresso_db_update |
|
| 584 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 585 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 586 | - $espresso_db_update, |
|
| 587 | - 'ee_espresso_activation', espresso_version() |
|
| 588 | - ); |
|
| 589 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 590 | - } |
|
| 591 | - return $this->_req_type; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 598 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 599 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 600 | - * |
|
| 601 | - * @param $activation_history |
|
| 602 | - * @return bool |
|
| 603 | - */ |
|
| 604 | - private function _detect_major_version_change($activation_history) |
|
| 605 | - { |
|
| 606 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 607 | - $previous_version_parts = explode('.', $previous_version); |
|
| 608 | - $current_version_parts = explode('.', espresso_version()); |
|
| 609 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 610 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 611 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 619 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 620 | - * |
|
| 621 | - * @return bool |
|
| 622 | - */ |
|
| 623 | - public function is_major_version_change() |
|
| 624 | - { |
|
| 625 | - return $this->_major_version_change; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 632 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 633 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 634 | - * just activated to (for core that will always be espresso_version()) |
|
| 635 | - * |
|
| 636 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 637 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 638 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 639 | - * indicate that this plugin was just activated |
|
| 640 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 641 | - * espresso_version()) |
|
| 642 | - * @return int one of the constants on EE_System::req_type_* |
|
| 643 | - */ |
|
| 644 | - public static function detect_req_type_given_activation_history( |
|
| 645 | - $activation_history_for_addon, |
|
| 646 | - $activation_indicator_option_name, |
|
| 647 | - $version_to_upgrade_to |
|
| 648 | - ) { |
|
| 649 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 650 | - if ($activation_history_for_addon) { |
|
| 651 | - //it exists, so this isn't a completely new install |
|
| 652 | - //check if this version already in that list of previously installed versions |
|
| 653 | - if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 654 | - //it a version we haven't seen before |
|
| 655 | - if ($version_is_higher === 1) { |
|
| 656 | - $req_type = EE_System::req_type_upgrade; |
|
| 657 | - } else { |
|
| 658 | - $req_type = EE_System::req_type_downgrade; |
|
| 659 | - } |
|
| 660 | - delete_option($activation_indicator_option_name); |
|
| 661 | - } else { |
|
| 662 | - // its not an update. maybe a reactivation? |
|
| 663 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 664 | - if ($version_is_higher === -1) { |
|
| 665 | - $req_type = EE_System::req_type_downgrade; |
|
| 666 | - } else if ($version_is_higher === 0) { |
|
| 667 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
| 668 | - $req_type = EE_System::req_type_reactivation; |
|
| 669 | - } else {//$version_is_higher === 1 |
|
| 670 | - $req_type = EE_System::req_type_upgrade; |
|
| 671 | - } |
|
| 672 | - delete_option($activation_indicator_option_name); |
|
| 673 | - } else { |
|
| 674 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 675 | - if ($version_is_higher === -1) { |
|
| 676 | - $req_type = EE_System::req_type_downgrade; |
|
| 677 | - } else if ($version_is_higher === 0) { |
|
| 678 | - //we've seen this version before and it's not an activation. its normal request |
|
| 679 | - $req_type = EE_System::req_type_normal; |
|
| 680 | - } else {//$version_is_higher === 1 |
|
| 681 | - $req_type = EE_System::req_type_upgrade; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - } else { |
|
| 686 | - //brand new install |
|
| 687 | - $req_type = EE_System::req_type_new_activation; |
|
| 688 | - delete_option($activation_indicator_option_name); |
|
| 689 | - } |
|
| 690 | - return $req_type; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 697 | - * the $activation_history_for_addon |
|
| 698 | - * |
|
| 699 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 700 | - * sometimes containing 'unknown-date' |
|
| 701 | - * @param string $version_to_upgrade_to (current version) |
|
| 702 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 703 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 704 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 705 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 706 | - */ |
|
| 707 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 708 | - { |
|
| 709 | - //find the most recently-activated version |
|
| 710 | - $most_recently_active_version = |
|
| 711 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 712 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * Gets the most recently active version listed in the activation history, |
|
| 719 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 720 | - * |
|
| 721 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 722 | - * sometimes containing 'unknown-date' |
|
| 723 | - * @return string |
|
| 724 | - */ |
|
| 725 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 726 | - { |
|
| 727 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 728 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 729 | - if (is_array($activation_history)) { |
|
| 730 | - foreach ($activation_history as $version => $times_activated) { |
|
| 731 | - //check there is a record of when this version was activated. Otherwise, |
|
| 732 | - //mark it as unknown |
|
| 733 | - if (! $times_activated) { |
|
| 734 | - $times_activated = array('unknown-date'); |
|
| 735 | - } |
|
| 736 | - if (is_string($times_activated)) { |
|
| 737 | - $times_activated = array($times_activated); |
|
| 738 | - } |
|
| 739 | - foreach ($times_activated as $an_activation) { |
|
| 740 | - if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 741 | - $most_recently_active_version = $version; |
|
| 742 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 743 | - ? '1970-01-01 00:00:00' |
|
| 744 | - : $an_activation; |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - return $most_recently_active_version; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * This redirects to the about EE page after activation |
|
| 756 | - * |
|
| 757 | - * @return void |
|
| 758 | - */ |
|
| 759 | - public function redirect_to_about_ee() |
|
| 760 | - { |
|
| 761 | - $notices = EE_Error::get_notices(false); |
|
| 762 | - //if current user is an admin and it's not an ajax or rest request |
|
| 763 | - if ( |
|
| 764 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 765 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 766 | - && ! isset($notices['errors']) |
|
| 767 | - && apply_filters( |
|
| 768 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 769 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 770 | - ) |
|
| 771 | - ) { |
|
| 772 | - $query_params = array('page' => 'espresso_about'); |
|
| 773 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 774 | - $query_params['new_activation'] = true; |
|
| 775 | - } |
|
| 776 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 777 | - $query_params['reactivation'] = true; |
|
| 778 | - } |
|
| 779 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 780 | - wp_safe_redirect($url); |
|
| 781 | - exit(); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * load_core_configuration |
|
| 789 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 790 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 791 | - * |
|
| 792 | - * @return void |
|
| 793 | - * @throws ReflectionException |
|
| 794 | - */ |
|
| 795 | - public function load_core_configuration() |
|
| 796 | - { |
|
| 797 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 798 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
| 799 | - //load textdomain |
|
| 800 | - EE_Load_Textdomain::load_textdomain(); |
|
| 801 | - // load and setup EE_Config and EE_Network_Config |
|
| 802 | - $config = $this->loader->getShared('EE_Config'); |
|
| 803 | - $this->loader->getShared('EE_Network_Config'); |
|
| 804 | - // setup autoloaders |
|
| 805 | - // enable logging? |
|
| 806 | - if ($config->admin->use_full_logging) { |
|
| 807 | - $this->loader->getShared('EE_Log'); |
|
| 808 | - } |
|
| 809 | - // check for activation errors |
|
| 810 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 811 | - if ($activation_errors) { |
|
| 812 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 813 | - update_option('ee_plugin_activation_errors', false); |
|
| 814 | - } |
|
| 815 | - // get model names |
|
| 816 | - $this->_parse_model_names(); |
|
| 817 | - //load caf stuff a chance to play during the activation process too. |
|
| 818 | - $this->_maybe_brew_regular(); |
|
| 819 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 826 | - * |
|
| 827 | - * @return void |
|
| 828 | - * @throws ReflectionException |
|
| 829 | - */ |
|
| 830 | - private function _parse_model_names() |
|
| 831 | - { |
|
| 832 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
| 833 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 834 | - $model_names = array(); |
|
| 835 | - $non_abstract_db_models = array(); |
|
| 836 | - foreach ($models as $model) { |
|
| 837 | - // get model classname |
|
| 838 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 839 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 840 | - $reflectionClass = new ReflectionClass($classname); |
|
| 841 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 842 | - $non_abstract_db_models[$short_name] = $classname; |
|
| 843 | - } |
|
| 844 | - $model_names[$short_name] = $classname; |
|
| 845 | - } |
|
| 846 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 847 | - $this->registry->non_abstract_db_models = apply_filters( |
|
| 848 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
| 849 | - $non_abstract_db_models |
|
| 850 | - ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 857 | - * that need to be setup before our EE_System launches. |
|
| 858 | - * |
|
| 859 | - * @return void |
|
| 860 | - */ |
|
| 861 | - private function _maybe_brew_regular() |
|
| 862 | - { |
|
| 863 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 864 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * register_shortcodes_modules_and_widgets |
|
| 872 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 873 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 874 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 875 | - * |
|
| 876 | - * @access public |
|
| 877 | - * @return void |
|
| 878 | - * @throws Exception |
|
| 879 | - */ |
|
| 880 | - public function register_shortcodes_modules_and_widgets() |
|
| 881 | - { |
|
| 882 | - try { |
|
| 883 | - // load, register, and add shortcodes the new way |
|
| 884 | - $this->loader->getShared( |
|
| 885 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
| 886 | - array( |
|
| 887 | - // and the old way, but we'll put it under control of the new system |
|
| 888 | - EE_Config::getLegacyShortcodesManager() |
|
| 889 | - ) |
|
| 890 | - ); |
|
| 891 | - } catch (Exception $exception) { |
|
| 892 | - new ExceptionStackTraceDisplay($exception); |
|
| 893 | - } |
|
| 894 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 895 | - // check for addons using old hook point |
|
| 896 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 897 | - $this->_incompatible_addon_error(); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * _incompatible_addon_error |
|
| 905 | - * |
|
| 906 | - * @access public |
|
| 907 | - * @return void |
|
| 908 | - */ |
|
| 909 | - private function _incompatible_addon_error() |
|
| 910 | - { |
|
| 911 | - // get array of classes hooking into here |
|
| 912 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 913 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 914 | - ); |
|
| 915 | - if (! empty($class_names)) { |
|
| 916 | - $msg = __( |
|
| 917 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 918 | - 'event_espresso' |
|
| 919 | - ); |
|
| 920 | - $msg .= '<ul>'; |
|
| 921 | - foreach ($class_names as $class_name) { |
|
| 922 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
| 923 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 924 | - $class_name |
|
| 925 | - ) . '</b></li>'; |
|
| 926 | - } |
|
| 927 | - $msg .= '</ul>'; |
|
| 928 | - $msg .= __( |
|
| 929 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 930 | - 'event_espresso' |
|
| 931 | - ); |
|
| 932 | - // save list of incompatible addons to wp-options for later use |
|
| 933 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 934 | - if (is_admin()) { |
|
| 935 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 936 | - } |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * brew_espresso |
|
| 944 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 945 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 946 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 947 | - * |
|
| 948 | - * @return void |
|
| 949 | - */ |
|
| 950 | - public function brew_espresso() |
|
| 951 | - { |
|
| 952 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 953 | - // load some final core systems |
|
| 954 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 955 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 956 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 957 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 958 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 959 | - add_action('init', array($this, 'initialize'), 10); |
|
| 960 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 961 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 962 | - // pew pew pew |
|
| 963 | - $this->loader->getShared('EE_PUE'); |
|
| 964 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 965 | - } |
|
| 966 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * set_hooks_for_core |
|
| 973 | - * |
|
| 974 | - * @access public |
|
| 975 | - * @return void |
|
| 976 | - * @throws EE_Error |
|
| 977 | - */ |
|
| 978 | - public function set_hooks_for_core() |
|
| 979 | - { |
|
| 980 | - $this->_deactivate_incompatible_addons(); |
|
| 981 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 982 | - //caps need to be initialized on every request so that capability maps are set. |
|
| 983 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 984 | - $this->registry->CAP->init_caps(); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 991 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 992 | - */ |
|
| 993 | - private function _deactivate_incompatible_addons() |
|
| 994 | - { |
|
| 995 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 996 | - if (! empty($incompatible_addons)) { |
|
| 997 | - $active_plugins = get_option('active_plugins', array()); |
|
| 998 | - foreach ($active_plugins as $active_plugin) { |
|
| 999 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 1000 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 1001 | - unset($_GET['activate']); |
|
| 1002 | - espresso_deactivate_plugin($active_plugin); |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * perform_activations_upgrades_and_migrations |
|
| 1013 | - * |
|
| 1014 | - * @access public |
|
| 1015 | - * @return void |
|
| 1016 | - */ |
|
| 1017 | - public function perform_activations_upgrades_and_migrations() |
|
| 1018 | - { |
|
| 1019 | - //first check if we had previously attempted to setup EE's directories but failed |
|
| 1020 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
| 1021 | - EEH_Activation::create_upload_directories(); |
|
| 1022 | - } |
|
| 1023 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * load_CPTs_and_session |
|
| 1030 | - * |
|
| 1031 | - * @access public |
|
| 1032 | - * @return void |
|
| 1033 | - */ |
|
| 1034 | - public function load_CPTs_and_session() |
|
| 1035 | - { |
|
| 1036 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1037 | - // register Custom Post Types |
|
| 1038 | - $this->loader->getShared('EE_Register_CPTs'); |
|
| 1039 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * load_controllers |
|
| 1046 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1047 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1048 | - * time |
|
| 1049 | - * |
|
| 1050 | - * @access public |
|
| 1051 | - * @return void |
|
| 1052 | - */ |
|
| 1053 | - public function load_controllers() |
|
| 1054 | - { |
|
| 1055 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1056 | - // let's get it started |
|
| 1057 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1058 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 1059 | - $this->loader->getShared('EE_Front_Controller'); |
|
| 1060 | - } else if (! EE_FRONT_AJAX) { |
|
| 1061 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1062 | - $this->loader->getShared('EE_Admin'); |
|
| 1063 | - } |
|
| 1064 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * core_loaded_and_ready |
|
| 1071 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1072 | - * |
|
| 1073 | - * @access public |
|
| 1074 | - * @return void |
|
| 1075 | - */ |
|
| 1076 | - public function core_loaded_and_ready() |
|
| 1077 | - { |
|
| 1078 | - $this->loader->getShared('EE_Session'); |
|
| 1079 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1080 | - // load_espresso_template_tags |
|
| 1081 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1082 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1083 | - } |
|
| 1084 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1085 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * initialize |
|
| 1092 | - * this is the best place to begin initializing client code |
|
| 1093 | - * |
|
| 1094 | - * @access public |
|
| 1095 | - * @return void |
|
| 1096 | - */ |
|
| 1097 | - public function initialize() |
|
| 1098 | - { |
|
| 1099 | - do_action('AHEE__EE_System__initialize'); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * initialize_last |
|
| 1106 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1107 | - * initialize has done so |
|
| 1108 | - * |
|
| 1109 | - * @access public |
|
| 1110 | - * @return void |
|
| 1111 | - */ |
|
| 1112 | - public function initialize_last() |
|
| 1113 | - { |
|
| 1114 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 1115 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * @return void |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - */ |
|
| 1124 | - public function addEspressoToolbar() |
|
| 1125 | - { |
|
| 1126 | - $this->loader->getShared( |
|
| 1127 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1128 | - array($this->registry->CAP) |
|
| 1129 | - ); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * do_not_cache |
|
| 1136 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 1137 | - * |
|
| 1138 | - * @access public |
|
| 1139 | - * @return void |
|
| 1140 | - */ |
|
| 1141 | - public static function do_not_cache() |
|
| 1142 | - { |
|
| 1143 | - // set no cache constants |
|
| 1144 | - if (! defined('DONOTCACHEPAGE')) { |
|
| 1145 | - define('DONOTCACHEPAGE', true); |
|
| 1146 | - } |
|
| 1147 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1148 | - define('DONOTCACHCEOBJECT', true); |
|
| 1149 | - } |
|
| 1150 | - if (! defined('DONOTCACHEDB')) { |
|
| 1151 | - define('DONOTCACHEDB', true); |
|
| 1152 | - } |
|
| 1153 | - // add no cache headers |
|
| 1154 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1155 | - // plus a little extra for nginx and Google Chrome |
|
| 1156 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1157 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1158 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * extra_nocache_headers |
|
| 1165 | - * |
|
| 1166 | - * @access public |
|
| 1167 | - * @param $headers |
|
| 1168 | - * @return array |
|
| 1169 | - */ |
|
| 1170 | - public static function extra_nocache_headers($headers) |
|
| 1171 | - { |
|
| 1172 | - // for NGINX |
|
| 1173 | - $headers['X-Accel-Expires'] = 0; |
|
| 1174 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1175 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1176 | - return $headers; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * nocache_headers |
|
| 1183 | - * |
|
| 1184 | - * @access public |
|
| 1185 | - * @return void |
|
| 1186 | - */ |
|
| 1187 | - public static function nocache_headers() |
|
| 1188 | - { |
|
| 1189 | - nocache_headers(); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - /** |
|
| 1196 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1197 | - * never returned with the function. |
|
| 1198 | - * |
|
| 1199 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1200 | - * @return array |
|
| 1201 | - */ |
|
| 1202 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1203 | - { |
|
| 1204 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1205 | - } |
|
| 24 | + /** |
|
| 25 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 26 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 27 | + */ |
|
| 28 | + const req_type_normal = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Indicates this is a brand new installation of EE so we should install |
|
| 32 | + * tables and default data etc |
|
| 33 | + */ |
|
| 34 | + const req_type_new_activation = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 38 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 39 | + * and that default data is setup too |
|
| 40 | + */ |
|
| 41 | + const req_type_reactivation = 2; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * indicates that EE has been upgraded since its previous request. |
|
| 45 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 46 | + */ |
|
| 47 | + const req_type_upgrade = 3; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 51 | + */ |
|
| 52 | + const req_type_downgrade = 4; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @deprecated since version 4.6.0.dev.006 |
|
| 56 | + * Now whenever a new_activation is detected the request type is still just |
|
| 57 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 58 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 59 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 60 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 61 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 62 | + */ |
|
| 63 | + const req_type_activation_but_not_installed = 5; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 67 | + */ |
|
| 68 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_System $_instance |
|
| 73 | + */ |
|
| 74 | + private static $_instance; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Registry $registry |
|
| 78 | + */ |
|
| 79 | + private $registry; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var LoaderInterface $loader |
|
| 83 | + */ |
|
| 84 | + private $loader; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @var EE_Capabilities $capabilities |
|
| 88 | + */ |
|
| 89 | + private $capabilities; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var EE_Request $request |
|
| 93 | + */ |
|
| 94 | + private $request; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
| 98 | + */ |
|
| 99 | + private $maintenance_mode; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 103 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 104 | + * |
|
| 105 | + * @var int $_req_type |
|
| 106 | + */ |
|
| 107 | + private $_req_type; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 111 | + * |
|
| 112 | + * @var boolean $_major_version_change |
|
| 113 | + */ |
|
| 114 | + private $_major_version_change = false; |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @singleton method used to instantiate class object |
|
| 120 | + * @param EE_Registry|null $registry |
|
| 121 | + * @param LoaderInterface|null $loader |
|
| 122 | + * @param EE_Capabilities|null $capabilities |
|
| 123 | + * @param EE_Request|null $request |
|
| 124 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 125 | + * @return EE_System |
|
| 126 | + */ |
|
| 127 | + public static function instance( |
|
| 128 | + EE_Registry $registry = null, |
|
| 129 | + LoaderInterface $loader = null, |
|
| 130 | + EE_Capabilities $capabilities = null, |
|
| 131 | + EE_Request $request = null, |
|
| 132 | + EE_Maintenance_Mode $maintenance_mode = null |
|
| 133 | + ) { |
|
| 134 | + // check if class object is instantiated |
|
| 135 | + if (! self::$_instance instanceof EE_System) { |
|
| 136 | + self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
| 137 | + } |
|
| 138 | + return self::$_instance; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * resets the instance and returns it |
|
| 145 | + * |
|
| 146 | + * @return EE_System |
|
| 147 | + */ |
|
| 148 | + public static function reset() |
|
| 149 | + { |
|
| 150 | + self::$_instance->_req_type = null; |
|
| 151 | + //make sure none of the old hooks are left hanging around |
|
| 152 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 153 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 154 | + EE_Data_Migration_Manager::reset(); |
|
| 155 | + self::instance()->detect_activations_or_upgrades(); |
|
| 156 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 157 | + return self::instance(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * sets hooks for running rest of system |
|
| 164 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 165 | + * starting EE Addons from any other point may lead to problems |
|
| 166 | + * |
|
| 167 | + * @param EE_Registry $registry |
|
| 168 | + * @param LoaderInterface $loader |
|
| 169 | + * @param EE_Capabilities $capabilities |
|
| 170 | + * @param EE_Request $request |
|
| 171 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
| 172 | + */ |
|
| 173 | + private function __construct( |
|
| 174 | + EE_Registry $registry, |
|
| 175 | + LoaderInterface $loader, |
|
| 176 | + EE_Capabilities $capabilities, |
|
| 177 | + EE_Request $request, |
|
| 178 | + EE_Maintenance_Mode $maintenance_mode |
|
| 179 | + ) { |
|
| 180 | + $this->registry = $registry; |
|
| 181 | + $this->loader = $loader; |
|
| 182 | + $this->capabilities = $capabilities; |
|
| 183 | + $this->request = $request; |
|
| 184 | + $this->maintenance_mode = $maintenance_mode; |
|
| 185 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 186 | + add_action( |
|
| 187 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 188 | + array($this, 'loadCapabilities'), |
|
| 189 | + 5 |
|
| 190 | + ); |
|
| 191 | + add_action( |
|
| 192 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 193 | + array($this, 'loadCommandBus'), |
|
| 194 | + 7 |
|
| 195 | + ); |
|
| 196 | + add_action( |
|
| 197 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 198 | + array($this, 'loadPluginApi'), |
|
| 199 | + 9 |
|
| 200 | + ); |
|
| 201 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 202 | + add_action( |
|
| 203 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 204 | + array($this, 'load_espresso_addons') |
|
| 205 | + ); |
|
| 206 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 207 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 208 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 209 | + // detect whether install or upgrade |
|
| 210 | + add_action( |
|
| 211 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 212 | + array($this, 'detect_activations_or_upgrades'), |
|
| 213 | + 3 |
|
| 214 | + ); |
|
| 215 | + // load EE_Config, EE_Textdomain, etc |
|
| 216 | + add_action( |
|
| 217 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 218 | + array($this, 'load_core_configuration'), |
|
| 219 | + 5 |
|
| 220 | + ); |
|
| 221 | + // load EE_Config, EE_Textdomain, etc |
|
| 222 | + add_action( |
|
| 223 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 224 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 225 | + 7 |
|
| 226 | + ); |
|
| 227 | + // you wanna get going? I wanna get going... let's get going! |
|
| 228 | + add_action( |
|
| 229 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 230 | + array($this, 'brew_espresso'), |
|
| 231 | + 9 |
|
| 232 | + ); |
|
| 233 | + //other housekeeping |
|
| 234 | + //exclude EE critical pages from wp_list_pages |
|
| 235 | + add_filter( |
|
| 236 | + 'wp_list_pages_excludes', |
|
| 237 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
| 238 | + 10 |
|
| 239 | + ); |
|
| 240 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 241 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 242 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * load and setup EE_Capabilities |
|
| 249 | + * |
|
| 250 | + * @return void |
|
| 251 | + * @throws EE_Error |
|
| 252 | + */ |
|
| 253 | + public function loadCapabilities() |
|
| 254 | + { |
|
| 255 | + $this->loader->getShared('EE_Capabilities'); |
|
| 256 | + add_action( |
|
| 257 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 258 | + function() { |
|
| 259 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
| 260 | + } |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * create and cache the CommandBus, and also add middleware |
|
| 268 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
| 269 | + * which is why we need to load the CommandBus after Caps are set up |
|
| 270 | + * |
|
| 271 | + * @return void |
|
| 272 | + * @throws EE_Error |
|
| 273 | + */ |
|
| 274 | + public function loadCommandBus() |
|
| 275 | + { |
|
| 276 | + $this->loader->getShared( |
|
| 277 | + 'CommandBusInterface', |
|
| 278 | + array( |
|
| 279 | + null, |
|
| 280 | + apply_filters( |
|
| 281 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 282 | + array( |
|
| 283 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 284 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 285 | + ) |
|
| 286 | + ), |
|
| 287 | + ) |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @return void |
|
| 295 | + * @throws EE_Error |
|
| 296 | + */ |
|
| 297 | + public function loadPluginApi() |
|
| 298 | + { |
|
| 299 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 300 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 301 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * load_espresso_addons |
|
| 308 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 309 | + * this is hooked into both: |
|
| 310 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 311 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 312 | + * and the WP 'activate_plugin' hook point |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @return void |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public function load_espresso_addons() |
|
| 319 | + { |
|
| 320 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 321 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 322 | + //We want it for mobile apps. Just include the entire plugin |
|
| 323 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
| 324 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 325 | + //and causes a fatal error |
|
| 326 | + if ( |
|
| 327 | + ! ( |
|
| 328 | + isset($_GET['activate']) |
|
| 329 | + && $_GET['activate'] === 'true' |
|
| 330 | + ) |
|
| 331 | + && ! function_exists('json_basic_auth_handler') |
|
| 332 | + && ! function_exists('json_basic_auth_error') |
|
| 333 | + && ! ( |
|
| 334 | + isset($_GET['action']) |
|
| 335 | + && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
| 336 | + ) |
|
| 337 | + ) { |
|
| 338 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 339 | + } |
|
| 340 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * detect_activations_or_upgrades |
|
| 347 | + * Checks for activation or upgrade of core first; |
|
| 348 | + * then also checks if any registered addons have been activated or upgraded |
|
| 349 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 350 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 351 | + * |
|
| 352 | + * @access public |
|
| 353 | + * @return void |
|
| 354 | + */ |
|
| 355 | + public function detect_activations_or_upgrades() |
|
| 356 | + { |
|
| 357 | + //first off: let's make sure to handle core |
|
| 358 | + $this->detect_if_activation_or_upgrade(); |
|
| 359 | + foreach ($this->registry->addons as $addon) { |
|
| 360 | + if ($addon instanceof EE_Addon) { |
|
| 361 | + //detect teh request type for that addon |
|
| 362 | + $addon->detect_activation_or_upgrade(); |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * detect_if_activation_or_upgrade |
|
| 371 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 372 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 373 | + * |
|
| 374 | + * @access public |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + public function detect_if_activation_or_upgrade() |
|
| 378 | + { |
|
| 379 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 380 | + // check if db has been updated, or if its a brand-new installation |
|
| 381 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 382 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 383 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 384 | + switch ($request_type) { |
|
| 385 | + case EE_System::req_type_new_activation: |
|
| 386 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 387 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 388 | + break; |
|
| 389 | + case EE_System::req_type_reactivation: |
|
| 390 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 391 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 392 | + break; |
|
| 393 | + case EE_System::req_type_upgrade: |
|
| 394 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 395 | + //migrations may be required now that we've upgraded |
|
| 396 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 397 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 398 | + // echo "done upgrade";die; |
|
| 399 | + break; |
|
| 400 | + case EE_System::req_type_downgrade: |
|
| 401 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 402 | + //its possible migrations are no longer required |
|
| 403 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 404 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 405 | + break; |
|
| 406 | + case EE_System::req_type_normal: |
|
| 407 | + default: |
|
| 408 | + // $this->_maybe_redirect_to_ee_about(); |
|
| 409 | + break; |
|
| 410 | + } |
|
| 411 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Updates the list of installed versions and sets hooks for |
|
| 418 | + * initializing the database later during the request |
|
| 419 | + * |
|
| 420 | + * @param array $espresso_db_update |
|
| 421 | + */ |
|
| 422 | + private function _handle_core_version_change($espresso_db_update) |
|
| 423 | + { |
|
| 424 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 425 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 426 | + add_action( |
|
| 427 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 428 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 429 | + ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 436 | + * information about what versions of EE have been installed and activated, |
|
| 437 | + * NOT necessarily the state of the database |
|
| 438 | + * |
|
| 439 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 440 | + * If not supplied, fetches it from the options table |
|
| 441 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 442 | + */ |
|
| 443 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 444 | + { |
|
| 445 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 446 | + if (! $espresso_db_update) { |
|
| 447 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 448 | + } |
|
| 449 | + // check that option is an array |
|
| 450 | + if (! is_array($espresso_db_update)) { |
|
| 451 | + // if option is FALSE, then it never existed |
|
| 452 | + if ($espresso_db_update === false) { |
|
| 453 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 454 | + $espresso_db_update = array(); |
|
| 455 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 456 | + } else { |
|
| 457 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 458 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 459 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 460 | + } |
|
| 461 | + } else { |
|
| 462 | + $corrected_db_update = array(); |
|
| 463 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 464 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 465 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 466 | + //the key is an int, and the value IS NOT an array |
|
| 467 | + //so it must be numerically-indexed, where values are versions installed... |
|
| 468 | + //fix it! |
|
| 469 | + $version_string = $should_be_array; |
|
| 470 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 471 | + } else { |
|
| 472 | + //ok it checks out |
|
| 473 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + $espresso_db_update = $corrected_db_update; |
|
| 477 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 478 | + } |
|
| 479 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 480 | + return $espresso_db_update; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 487 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 488 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 489 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 490 | + * so that it will be done when migrations are finished |
|
| 491 | + * |
|
| 492 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 493 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 494 | + * This is a resource-intensive job |
|
| 495 | + * so we prefer to only do it when necessary |
|
| 496 | + * @return void |
|
| 497 | + * @throws EE_Error |
|
| 498 | + */ |
|
| 499 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 500 | + { |
|
| 501 | + $request_type = $this->detect_req_type(); |
|
| 502 | + //only initialize system if we're not in maintenance mode. |
|
| 503 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 504 | + update_option('ee_flush_rewrite_rules', true); |
|
| 505 | + if ($verify_schema) { |
|
| 506 | + EEH_Activation::initialize_db_and_folders(); |
|
| 507 | + } |
|
| 508 | + EEH_Activation::initialize_db_content(); |
|
| 509 | + EEH_Activation::system_initialization(); |
|
| 510 | + if ($initialize_addons_too) { |
|
| 511 | + $this->initialize_addons(); |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 515 | + } |
|
| 516 | + if ($request_type === EE_System::req_type_new_activation |
|
| 517 | + || $request_type === EE_System::req_type_reactivation |
|
| 518 | + || ( |
|
| 519 | + $request_type === EE_System::req_type_upgrade |
|
| 520 | + && $this->is_major_version_change() |
|
| 521 | + ) |
|
| 522 | + ) { |
|
| 523 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Initializes the db for all registered addons |
|
| 531 | + * |
|
| 532 | + * @throws EE_Error |
|
| 533 | + */ |
|
| 534 | + public function initialize_addons() |
|
| 535 | + { |
|
| 536 | + //foreach registered addon, make sure its db is up-to-date too |
|
| 537 | + foreach ($this->registry->addons as $addon) { |
|
| 538 | + if ($addon instanceof EE_Addon) { |
|
| 539 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 548 | + * |
|
| 549 | + * @param array $version_history |
|
| 550 | + * @param string $current_version_to_add version to be added to the version history |
|
| 551 | + * @return boolean success as to whether or not this option was changed |
|
| 552 | + */ |
|
| 553 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 554 | + { |
|
| 555 | + if (! $version_history) { |
|
| 556 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 557 | + } |
|
| 558 | + if ($current_version_to_add === null) { |
|
| 559 | + $current_version_to_add = espresso_version(); |
|
| 560 | + } |
|
| 561 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 562 | + // re-save |
|
| 563 | + return update_option('espresso_db_update', $version_history); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Detects if the current version indicated in the has existed in the list of |
|
| 570 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 571 | + * |
|
| 572 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 573 | + * If not supplied, fetches it from the options table. |
|
| 574 | + * Also, caches its result so later parts of the code can also know whether |
|
| 575 | + * there's been an update or not. This way we can add the current version to |
|
| 576 | + * espresso_db_update, but still know if this is a new install or not |
|
| 577 | + * @return int one of the constants on EE_System::req_type_ |
|
| 578 | + */ |
|
| 579 | + public function detect_req_type($espresso_db_update = null) |
|
| 580 | + { |
|
| 581 | + if ($this->_req_type === null) { |
|
| 582 | + $espresso_db_update = ! empty($espresso_db_update) |
|
| 583 | + ? $espresso_db_update |
|
| 584 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 585 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 586 | + $espresso_db_update, |
|
| 587 | + 'ee_espresso_activation', espresso_version() |
|
| 588 | + ); |
|
| 589 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 590 | + } |
|
| 591 | + return $this->_req_type; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 598 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 599 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 600 | + * |
|
| 601 | + * @param $activation_history |
|
| 602 | + * @return bool |
|
| 603 | + */ |
|
| 604 | + private function _detect_major_version_change($activation_history) |
|
| 605 | + { |
|
| 606 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 607 | + $previous_version_parts = explode('.', $previous_version); |
|
| 608 | + $current_version_parts = explode('.', espresso_version()); |
|
| 609 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 610 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 611 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 619 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 620 | + * |
|
| 621 | + * @return bool |
|
| 622 | + */ |
|
| 623 | + public function is_major_version_change() |
|
| 624 | + { |
|
| 625 | + return $this->_major_version_change; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 632 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 633 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 634 | + * just activated to (for core that will always be espresso_version()) |
|
| 635 | + * |
|
| 636 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 637 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 638 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 639 | + * indicate that this plugin was just activated |
|
| 640 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 641 | + * espresso_version()) |
|
| 642 | + * @return int one of the constants on EE_System::req_type_* |
|
| 643 | + */ |
|
| 644 | + public static function detect_req_type_given_activation_history( |
|
| 645 | + $activation_history_for_addon, |
|
| 646 | + $activation_indicator_option_name, |
|
| 647 | + $version_to_upgrade_to |
|
| 648 | + ) { |
|
| 649 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 650 | + if ($activation_history_for_addon) { |
|
| 651 | + //it exists, so this isn't a completely new install |
|
| 652 | + //check if this version already in that list of previously installed versions |
|
| 653 | + if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 654 | + //it a version we haven't seen before |
|
| 655 | + if ($version_is_higher === 1) { |
|
| 656 | + $req_type = EE_System::req_type_upgrade; |
|
| 657 | + } else { |
|
| 658 | + $req_type = EE_System::req_type_downgrade; |
|
| 659 | + } |
|
| 660 | + delete_option($activation_indicator_option_name); |
|
| 661 | + } else { |
|
| 662 | + // its not an update. maybe a reactivation? |
|
| 663 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 664 | + if ($version_is_higher === -1) { |
|
| 665 | + $req_type = EE_System::req_type_downgrade; |
|
| 666 | + } else if ($version_is_higher === 0) { |
|
| 667 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
| 668 | + $req_type = EE_System::req_type_reactivation; |
|
| 669 | + } else {//$version_is_higher === 1 |
|
| 670 | + $req_type = EE_System::req_type_upgrade; |
|
| 671 | + } |
|
| 672 | + delete_option($activation_indicator_option_name); |
|
| 673 | + } else { |
|
| 674 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 675 | + if ($version_is_higher === -1) { |
|
| 676 | + $req_type = EE_System::req_type_downgrade; |
|
| 677 | + } else if ($version_is_higher === 0) { |
|
| 678 | + //we've seen this version before and it's not an activation. its normal request |
|
| 679 | + $req_type = EE_System::req_type_normal; |
|
| 680 | + } else {//$version_is_higher === 1 |
|
| 681 | + $req_type = EE_System::req_type_upgrade; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + } else { |
|
| 686 | + //brand new install |
|
| 687 | + $req_type = EE_System::req_type_new_activation; |
|
| 688 | + delete_option($activation_indicator_option_name); |
|
| 689 | + } |
|
| 690 | + return $req_type; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 697 | + * the $activation_history_for_addon |
|
| 698 | + * |
|
| 699 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 700 | + * sometimes containing 'unknown-date' |
|
| 701 | + * @param string $version_to_upgrade_to (current version) |
|
| 702 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 703 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 704 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 705 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 706 | + */ |
|
| 707 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 708 | + { |
|
| 709 | + //find the most recently-activated version |
|
| 710 | + $most_recently_active_version = |
|
| 711 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 712 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * Gets the most recently active version listed in the activation history, |
|
| 719 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 720 | + * |
|
| 721 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 722 | + * sometimes containing 'unknown-date' |
|
| 723 | + * @return string |
|
| 724 | + */ |
|
| 725 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 726 | + { |
|
| 727 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 728 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 729 | + if (is_array($activation_history)) { |
|
| 730 | + foreach ($activation_history as $version => $times_activated) { |
|
| 731 | + //check there is a record of when this version was activated. Otherwise, |
|
| 732 | + //mark it as unknown |
|
| 733 | + if (! $times_activated) { |
|
| 734 | + $times_activated = array('unknown-date'); |
|
| 735 | + } |
|
| 736 | + if (is_string($times_activated)) { |
|
| 737 | + $times_activated = array($times_activated); |
|
| 738 | + } |
|
| 739 | + foreach ($times_activated as $an_activation) { |
|
| 740 | + if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 741 | + $most_recently_active_version = $version; |
|
| 742 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 743 | + ? '1970-01-01 00:00:00' |
|
| 744 | + : $an_activation; |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + return $most_recently_active_version; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * This redirects to the about EE page after activation |
|
| 756 | + * |
|
| 757 | + * @return void |
|
| 758 | + */ |
|
| 759 | + public function redirect_to_about_ee() |
|
| 760 | + { |
|
| 761 | + $notices = EE_Error::get_notices(false); |
|
| 762 | + //if current user is an admin and it's not an ajax or rest request |
|
| 763 | + if ( |
|
| 764 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 765 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 766 | + && ! isset($notices['errors']) |
|
| 767 | + && apply_filters( |
|
| 768 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 769 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 770 | + ) |
|
| 771 | + ) { |
|
| 772 | + $query_params = array('page' => 'espresso_about'); |
|
| 773 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 774 | + $query_params['new_activation'] = true; |
|
| 775 | + } |
|
| 776 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 777 | + $query_params['reactivation'] = true; |
|
| 778 | + } |
|
| 779 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 780 | + wp_safe_redirect($url); |
|
| 781 | + exit(); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * load_core_configuration |
|
| 789 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 790 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 791 | + * |
|
| 792 | + * @return void |
|
| 793 | + * @throws ReflectionException |
|
| 794 | + */ |
|
| 795 | + public function load_core_configuration() |
|
| 796 | + { |
|
| 797 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 798 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
| 799 | + //load textdomain |
|
| 800 | + EE_Load_Textdomain::load_textdomain(); |
|
| 801 | + // load and setup EE_Config and EE_Network_Config |
|
| 802 | + $config = $this->loader->getShared('EE_Config'); |
|
| 803 | + $this->loader->getShared('EE_Network_Config'); |
|
| 804 | + // setup autoloaders |
|
| 805 | + // enable logging? |
|
| 806 | + if ($config->admin->use_full_logging) { |
|
| 807 | + $this->loader->getShared('EE_Log'); |
|
| 808 | + } |
|
| 809 | + // check for activation errors |
|
| 810 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 811 | + if ($activation_errors) { |
|
| 812 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 813 | + update_option('ee_plugin_activation_errors', false); |
|
| 814 | + } |
|
| 815 | + // get model names |
|
| 816 | + $this->_parse_model_names(); |
|
| 817 | + //load caf stuff a chance to play during the activation process too. |
|
| 818 | + $this->_maybe_brew_regular(); |
|
| 819 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 826 | + * |
|
| 827 | + * @return void |
|
| 828 | + * @throws ReflectionException |
|
| 829 | + */ |
|
| 830 | + private function _parse_model_names() |
|
| 831 | + { |
|
| 832 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
| 833 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 834 | + $model_names = array(); |
|
| 835 | + $non_abstract_db_models = array(); |
|
| 836 | + foreach ($models as $model) { |
|
| 837 | + // get model classname |
|
| 838 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 839 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 840 | + $reflectionClass = new ReflectionClass($classname); |
|
| 841 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 842 | + $non_abstract_db_models[$short_name] = $classname; |
|
| 843 | + } |
|
| 844 | + $model_names[$short_name] = $classname; |
|
| 845 | + } |
|
| 846 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 847 | + $this->registry->non_abstract_db_models = apply_filters( |
|
| 848 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
| 849 | + $non_abstract_db_models |
|
| 850 | + ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 857 | + * that need to be setup before our EE_System launches. |
|
| 858 | + * |
|
| 859 | + * @return void |
|
| 860 | + */ |
|
| 861 | + private function _maybe_brew_regular() |
|
| 862 | + { |
|
| 863 | + if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 864 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * register_shortcodes_modules_and_widgets |
|
| 872 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 873 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 874 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 875 | + * |
|
| 876 | + * @access public |
|
| 877 | + * @return void |
|
| 878 | + * @throws Exception |
|
| 879 | + */ |
|
| 880 | + public function register_shortcodes_modules_and_widgets() |
|
| 881 | + { |
|
| 882 | + try { |
|
| 883 | + // load, register, and add shortcodes the new way |
|
| 884 | + $this->loader->getShared( |
|
| 885 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
| 886 | + array( |
|
| 887 | + // and the old way, but we'll put it under control of the new system |
|
| 888 | + EE_Config::getLegacyShortcodesManager() |
|
| 889 | + ) |
|
| 890 | + ); |
|
| 891 | + } catch (Exception $exception) { |
|
| 892 | + new ExceptionStackTraceDisplay($exception); |
|
| 893 | + } |
|
| 894 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 895 | + // check for addons using old hook point |
|
| 896 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 897 | + $this->_incompatible_addon_error(); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * _incompatible_addon_error |
|
| 905 | + * |
|
| 906 | + * @access public |
|
| 907 | + * @return void |
|
| 908 | + */ |
|
| 909 | + private function _incompatible_addon_error() |
|
| 910 | + { |
|
| 911 | + // get array of classes hooking into here |
|
| 912 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 913 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 914 | + ); |
|
| 915 | + if (! empty($class_names)) { |
|
| 916 | + $msg = __( |
|
| 917 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 918 | + 'event_espresso' |
|
| 919 | + ); |
|
| 920 | + $msg .= '<ul>'; |
|
| 921 | + foreach ($class_names as $class_name) { |
|
| 922 | + $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
| 923 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 924 | + $class_name |
|
| 925 | + ) . '</b></li>'; |
|
| 926 | + } |
|
| 927 | + $msg .= '</ul>'; |
|
| 928 | + $msg .= __( |
|
| 929 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 930 | + 'event_espresso' |
|
| 931 | + ); |
|
| 932 | + // save list of incompatible addons to wp-options for later use |
|
| 933 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 934 | + if (is_admin()) { |
|
| 935 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 936 | + } |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * brew_espresso |
|
| 944 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 945 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 946 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 947 | + * |
|
| 948 | + * @return void |
|
| 949 | + */ |
|
| 950 | + public function brew_espresso() |
|
| 951 | + { |
|
| 952 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 953 | + // load some final core systems |
|
| 954 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 955 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 956 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 957 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 958 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 959 | + add_action('init', array($this, 'initialize'), 10); |
|
| 960 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 961 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 962 | + // pew pew pew |
|
| 963 | + $this->loader->getShared('EE_PUE'); |
|
| 964 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 965 | + } |
|
| 966 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * set_hooks_for_core |
|
| 973 | + * |
|
| 974 | + * @access public |
|
| 975 | + * @return void |
|
| 976 | + * @throws EE_Error |
|
| 977 | + */ |
|
| 978 | + public function set_hooks_for_core() |
|
| 979 | + { |
|
| 980 | + $this->_deactivate_incompatible_addons(); |
|
| 981 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 982 | + //caps need to be initialized on every request so that capability maps are set. |
|
| 983 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 984 | + $this->registry->CAP->init_caps(); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 991 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 992 | + */ |
|
| 993 | + private function _deactivate_incompatible_addons() |
|
| 994 | + { |
|
| 995 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 996 | + if (! empty($incompatible_addons)) { |
|
| 997 | + $active_plugins = get_option('active_plugins', array()); |
|
| 998 | + foreach ($active_plugins as $active_plugin) { |
|
| 999 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 1000 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 1001 | + unset($_GET['activate']); |
|
| 1002 | + espresso_deactivate_plugin($active_plugin); |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * perform_activations_upgrades_and_migrations |
|
| 1013 | + * |
|
| 1014 | + * @access public |
|
| 1015 | + * @return void |
|
| 1016 | + */ |
|
| 1017 | + public function perform_activations_upgrades_and_migrations() |
|
| 1018 | + { |
|
| 1019 | + //first check if we had previously attempted to setup EE's directories but failed |
|
| 1020 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
| 1021 | + EEH_Activation::create_upload_directories(); |
|
| 1022 | + } |
|
| 1023 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * load_CPTs_and_session |
|
| 1030 | + * |
|
| 1031 | + * @access public |
|
| 1032 | + * @return void |
|
| 1033 | + */ |
|
| 1034 | + public function load_CPTs_and_session() |
|
| 1035 | + { |
|
| 1036 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1037 | + // register Custom Post Types |
|
| 1038 | + $this->loader->getShared('EE_Register_CPTs'); |
|
| 1039 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * load_controllers |
|
| 1046 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1047 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1048 | + * time |
|
| 1049 | + * |
|
| 1050 | + * @access public |
|
| 1051 | + * @return void |
|
| 1052 | + */ |
|
| 1053 | + public function load_controllers() |
|
| 1054 | + { |
|
| 1055 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1056 | + // let's get it started |
|
| 1057 | + if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
| 1058 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 1059 | + $this->loader->getShared('EE_Front_Controller'); |
|
| 1060 | + } else if (! EE_FRONT_AJAX) { |
|
| 1061 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1062 | + $this->loader->getShared('EE_Admin'); |
|
| 1063 | + } |
|
| 1064 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * core_loaded_and_ready |
|
| 1071 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1072 | + * |
|
| 1073 | + * @access public |
|
| 1074 | + * @return void |
|
| 1075 | + */ |
|
| 1076 | + public function core_loaded_and_ready() |
|
| 1077 | + { |
|
| 1078 | + $this->loader->getShared('EE_Session'); |
|
| 1079 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1080 | + // load_espresso_template_tags |
|
| 1081 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1082 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1083 | + } |
|
| 1084 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1085 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * initialize |
|
| 1092 | + * this is the best place to begin initializing client code |
|
| 1093 | + * |
|
| 1094 | + * @access public |
|
| 1095 | + * @return void |
|
| 1096 | + */ |
|
| 1097 | + public function initialize() |
|
| 1098 | + { |
|
| 1099 | + do_action('AHEE__EE_System__initialize'); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * initialize_last |
|
| 1106 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1107 | + * initialize has done so |
|
| 1108 | + * |
|
| 1109 | + * @access public |
|
| 1110 | + * @return void |
|
| 1111 | + */ |
|
| 1112 | + public function initialize_last() |
|
| 1113 | + { |
|
| 1114 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 1115 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * @return void |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + */ |
|
| 1124 | + public function addEspressoToolbar() |
|
| 1125 | + { |
|
| 1126 | + $this->loader->getShared( |
|
| 1127 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1128 | + array($this->registry->CAP) |
|
| 1129 | + ); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * do_not_cache |
|
| 1136 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 1137 | + * |
|
| 1138 | + * @access public |
|
| 1139 | + * @return void |
|
| 1140 | + */ |
|
| 1141 | + public static function do_not_cache() |
|
| 1142 | + { |
|
| 1143 | + // set no cache constants |
|
| 1144 | + if (! defined('DONOTCACHEPAGE')) { |
|
| 1145 | + define('DONOTCACHEPAGE', true); |
|
| 1146 | + } |
|
| 1147 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1148 | + define('DONOTCACHCEOBJECT', true); |
|
| 1149 | + } |
|
| 1150 | + if (! defined('DONOTCACHEDB')) { |
|
| 1151 | + define('DONOTCACHEDB', true); |
|
| 1152 | + } |
|
| 1153 | + // add no cache headers |
|
| 1154 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1155 | + // plus a little extra for nginx and Google Chrome |
|
| 1156 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1157 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1158 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * extra_nocache_headers |
|
| 1165 | + * |
|
| 1166 | + * @access public |
|
| 1167 | + * @param $headers |
|
| 1168 | + * @return array |
|
| 1169 | + */ |
|
| 1170 | + public static function extra_nocache_headers($headers) |
|
| 1171 | + { |
|
| 1172 | + // for NGINX |
|
| 1173 | + $headers['X-Accel-Expires'] = 0; |
|
| 1174 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1175 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1176 | + return $headers; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * nocache_headers |
|
| 1183 | + * |
|
| 1184 | + * @access public |
|
| 1185 | + * @return void |
|
| 1186 | + */ |
|
| 1187 | + public static function nocache_headers() |
|
| 1188 | + { |
|
| 1189 | + nocache_headers(); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + /** |
|
| 1196 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1197 | + * never returned with the function. |
|
| 1198 | + * |
|
| 1199 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1200 | + * @return array |
|
| 1201 | + */ |
|
| 1202 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1203 | + { |
|
| 1204 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | 1207 | |
| 1208 | 1208 | |