@@ -205,7 +205,6 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @access public |
| 207 | 207 | * @uses _initialize_admin_page() |
| 208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 209 | 208 | * @return void |
| 210 | 209 | */ |
| 211 | 210 | public function initialize_admin_page() |
@@ -221,6 +220,9 @@ discard block |
||
| 221 | 220 | |
| 222 | 221 | |
| 223 | 222 | |
| 223 | + /** |
|
| 224 | + * @param string $wp_page_slug |
|
| 225 | + */ |
|
| 224 | 226 | public function set_page_dependencies($wp_page_slug) |
| 225 | 227 | { |
| 226 | 228 | if (! $this->_load_page) { |
@@ -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 | * Event Espresso |
@@ -28,443 +28,443 @@ discard block |
||
| 28 | 28 | abstract class EE_Admin_Page_Init extends EE_Base |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - //identity properties (set in _set_defaults and _set_init_properties) |
|
| 32 | - public $label; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
| 36 | - * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - public $capability; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * This holds the menu map object for this admin page. |
|
| 45 | - * |
|
| 46 | - * @var EE_Admin_Page_Menu_Map |
|
| 47 | - */ |
|
| 48 | - protected $_menu_map; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * deprecated |
|
| 52 | - */ |
|
| 53 | - public $menu_label; |
|
| 54 | - public $menu_slug; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - //set in _set_defaults |
|
| 59 | - protected $_folder_name; |
|
| 60 | - protected $_folder_path; |
|
| 61 | - protected $_file_name; |
|
| 62 | - public $hook_file; |
|
| 63 | - protected $_wp_page_slug; |
|
| 64 | - protected $_routing; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - //will hold page object. |
|
| 68 | - protected $_loaded_page_object; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - //for caf |
|
| 72 | - protected $_files_hooked; |
|
| 73 | - protected $_hook_paths; |
|
| 74 | - |
|
| 75 | - //load_page? |
|
| 76 | - private $_load_page; |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @Constructor |
|
| 82 | - * @access public |
|
| 83 | - * @return void |
|
| 84 | - */ |
|
| 85 | - public function __construct() |
|
| 86 | - { |
|
| 87 | - //set global defaults |
|
| 88 | - $this->_set_defaults(); |
|
| 89 | - //set properties that are always available with objects. |
|
| 90 | - $this->_set_init_properties(); |
|
| 91 | - //global styles/scripts across all wp admin pages |
|
| 92 | - add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
| 93 | - //load initial stuff. |
|
| 94 | - $this->_set_file_and_folder_name(); |
|
| 95 | - $this->_set_menu_map(); |
|
| 96 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 97 | - EE_Error::doing_it_wrong( |
|
| 98 | - get_class($this) . '::$_menu_map', |
|
| 99 | - sprintf( |
|
| 100 | - __( |
|
| 101 | - 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
| 102 | - 'event_espresso' |
|
| 103 | - ), |
|
| 104 | - get_class($this) |
|
| 105 | - ), |
|
| 106 | - '4.4.0' |
|
| 107 | - ); |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - //set default capability |
|
| 111 | - $this->_set_capability(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * _set_init_properties |
|
| 118 | - * Child classes use to set the following properties: |
|
| 119 | - * $label |
|
| 120 | - * |
|
| 121 | - * @abstract |
|
| 122 | - * @access protected |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - abstract protected function _set_init_properties(); |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
| 131 | - * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
| 132 | - * |
|
| 133 | - * @since 4.4.0 |
|
| 134 | - * @ return void. |
|
| 135 | - */ |
|
| 136 | - protected function _set_menu_map() |
|
| 137 | - { |
|
| 138 | - return array(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * returns the menu map for this admin page |
|
| 145 | - * |
|
| 146 | - * @since 4.4.0 |
|
| 147 | - * @return EE_Admin_Page_Menu_Map |
|
| 148 | - */ |
|
| 149 | - public function get_menu_map() |
|
| 150 | - { |
|
| 151 | - return $this->_menu_map; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * This loads scripts and styles for the EE_Admin system |
|
| 158 | - * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
| 159 | - * |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - public function load_wp_global_scripts_styles() |
|
| 163 | - { |
|
| 164 | - wp_register_style( |
|
| 165 | - 'espresso_menu', |
|
| 166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 167 | - array('dashicons'), |
|
| 168 | - EVENT_ESPRESSO_VERSION |
|
| 169 | - ); |
|
| 170 | - wp_enqueue_style('espresso_menu'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * this sets default properties (might be overridden in _set_init_properties); |
|
| 177 | - * |
|
| 178 | - * @access private |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - private function _set_defaults() |
|
| 182 | - { |
|
| 183 | - $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
| 184 | - $this->_routing = true; |
|
| 185 | - $this->_load_page = false; |
|
| 186 | - $this->_files_hooked = $this->_hook_paths = array(); |
|
| 187 | - //menu_map |
|
| 188 | - $this->_menu_map = $this->get_menu_map(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - protected function _set_capability() |
|
| 194 | - { |
|
| 195 | - $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
| 196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * initialize_admin_page |
|
| 203 | - * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
| 204 | - * EE_Admin_Init class. |
|
| 205 | - * |
|
| 206 | - * @access public |
|
| 207 | - * @uses _initialize_admin_page() |
|
| 208 | - * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function initialize_admin_page() |
|
| 212 | - { |
|
| 213 | - //let's check user access first |
|
| 214 | - $this->_check_user_access(); |
|
| 215 | - if (! is_object($this->_loaded_page_object)) { |
|
| 216 | - return; |
|
| 217 | - } |
|
| 218 | - $this->_loaded_page_object->route_admin_request(); |
|
| 219 | - return; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - public function set_page_dependencies($wp_page_slug) |
|
| 225 | - { |
|
| 226 | - if (! $this->_load_page) { |
|
| 227 | - return; |
|
| 228 | - } |
|
| 229 | - if (! is_object($this->_loaded_page_object)) { |
|
| 230 | - $msg[] = __( |
|
| 231 | - 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
| 232 | - 'event_espresso' |
|
| 233 | - ); |
|
| 234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
| 235 | - __( |
|
| 236 | - 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
| 237 | - 'event_espresso' |
|
| 238 | - ), |
|
| 239 | - $this->_file_name, |
|
| 240 | - $this->_file_name, |
|
| 241 | - $this->_folder_path . $this->_file_name, |
|
| 242 | - $this->_menu_map->menu_slug |
|
| 243 | - ); |
|
| 244 | - throw new EE_Error(implode('||', $msg)); |
|
| 245 | - } |
|
| 246 | - $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
| 247 | - $page_hook = 'load-' . $wp_page_slug; |
|
| 248 | - //hook into page load hook so all page specific stuff get's loaded. |
|
| 249 | - if (! empty($wp_page_slug)) { |
|
| 250 | - add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
| 257 | - * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
| 258 | - * |
|
| 259 | - * @return void |
|
| 260 | - */ |
|
| 261 | - public function do_initial_loads() |
|
| 262 | - { |
|
| 263 | - //no loading or initializing if menu map is setup incorrectly. |
|
| 264 | - if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 265 | - return; |
|
| 266 | - } |
|
| 267 | - $this->_initialize_admin_page(); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * all we're doing here is setting the $_file_name property for later use. |
|
| 273 | - * |
|
| 274 | - * @access private |
|
| 275 | - * @return void |
|
| 276 | - */ |
|
| 277 | - private function _set_file_and_folder_name() |
|
| 278 | - { |
|
| 279 | - $bt = debug_backtrace(); |
|
| 280 | - //for more reliable determination of folder name |
|
| 281 | - //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
| 282 | - $class = get_class($this); |
|
| 283 | - foreach ($bt as $index => $values) { |
|
| 284 | - if (isset($values['class']) && $values['class'] == $class) { |
|
| 285 | - $file_index = $index - 1; |
|
| 286 | - $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
| 287 | - if (! empty($this->_folder_name)) { |
|
| 288 | - break; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
| 293 | - $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
| 294 | - $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
| 295 | - $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
| 301 | - * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
| 302 | - * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
| 303 | - * events_Messages_Hooks.class.php |
|
| 304 | - * |
|
| 305 | - * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
| 306 | - * files/classes |
|
| 307 | - * @return array |
|
| 308 | - */ |
|
| 309 | - public function register_hooks($extend = false) |
|
| 310 | - { |
|
| 311 | - |
|
| 312 | - //get a list of files in the directory that have the "Hook" in their name an |
|
| 313 | - //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
| 314 | - if ($extend) { |
|
| 315 | - $hook_files_glob_path = apply_filters( |
|
| 316 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
| 317 | - EE_CORE_CAF_ADMIN_EXTEND |
|
| 318 | - . $this->_folder_name |
|
| 319 | - . DS |
|
| 320 | - . '*' |
|
| 321 | - . $this->_file_name |
|
| 322 | - . '_Hooks_Extend.class.php' |
|
| 323 | - ); |
|
| 324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 325 | - } |
|
| 326 | - //loop through decaf folders |
|
| 327 | - $hook_files_glob_path = apply_filters( |
|
| 328 | - 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
| 329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 330 | - ); |
|
| 331 | - $this->_hook_paths = array_merge( |
|
| 332 | - $this->_register_hook_files($hook_files_glob_path), |
|
| 333 | - $this->_hook_paths |
|
| 334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 335 | - return $this->_hook_paths; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
| 341 | - { |
|
| 342 | - $hook_paths = array(); |
|
| 343 | - if ($hook_files = glob($hook_files_glob_path)) { |
|
| 344 | - if (empty($hook_files)) { |
|
| 345 | - return array(); |
|
| 346 | - } |
|
| 347 | - foreach ($hook_files as $file) { |
|
| 348 | - //lets get the linked admin. |
|
| 349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
| 350 | - : str_replace($this->_folder_path, '', $file); |
|
| 351 | - $replace = $extend |
|
| 352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 353 | - : '_' |
|
| 354 | - . $this->_file_name |
|
| 355 | - . '_Hooks.class.php'; |
|
| 356 | - $rel_admin = str_replace($replace, '', $hook_file); |
|
| 357 | - $rel_admin = strtolower($rel_admin); |
|
| 358 | - $hook_paths[] = $file; |
|
| 359 | - //make sure we haven't already got a hook setup for this page path |
|
| 360 | - if (in_array($rel_admin, $this->_files_hooked)) { |
|
| 361 | - continue; |
|
| 362 | - } |
|
| 363 | - $this->hook_file = $hook_file; |
|
| 364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 365 | - $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
| 366 | - $this->_files_hooked[] = $rel_admin; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - return $hook_paths; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - public function load_admin_hook($registered_pages) |
|
| 375 | - { |
|
| 376 | - $this->hook_file; |
|
| 377 | - $hook_file = (array)$this->hook_file; |
|
| 378 | - return array_merge($hook_file, $registered_pages); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * _initialize_admin_page |
|
| 384 | - * |
|
| 385 | - * @see initialize_admin_page() for info |
|
| 386 | - */ |
|
| 387 | - protected function _initialize_admin_page() |
|
| 388 | - { |
|
| 389 | - |
|
| 390 | - //JUST CHECK WE'RE ON RIGHT PAGE. |
|
| 391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 392 | - return; |
|
| 393 | - } //not on the right page so let's get out. |
|
| 394 | - $this->_load_page = true; |
|
| 395 | - //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
| 396 | - // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
| 397 | - //we don't need to do a page_request check here because it's only called via WP menu system. |
|
| 398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 400 | - $admin_page = apply_filters( |
|
| 401 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
| 402 | - $admin_page |
|
| 403 | - ); |
|
| 404 | - // define requested admin page class name then load the file and instantiate |
|
| 405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
| 406 | - $path_to_file = apply_filters( |
|
| 407 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
| 408 | - $path_to_file |
|
| 409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 410 | - if (is_readable($path_to_file)) { |
|
| 411 | - // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
| 412 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
| 413 | - do_action( |
|
| 414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 415 | - ); |
|
| 416 | - require_once($path_to_file); |
|
| 417 | - $a = new ReflectionClass($admin_page); |
|
| 418 | - $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
| 419 | - } |
|
| 420 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
| 421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - public function get_admin_page_name() |
|
| 427 | - { |
|
| 428 | - return $this->_file_name . '_Admin_Page'; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @return mixed |
|
| 435 | - */ |
|
| 436 | - public function loaded_page_object() |
|
| 437 | - { |
|
| 438 | - return $this->_loaded_page_object; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - // public function set_autoloaders( $className ) { |
|
| 446 | - // $dir_ref = array( |
|
| 447 | - // $this->_folder_path => array('core','class') |
|
| 448 | - // ); |
|
| 449 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 450 | - // } |
|
| 451 | - /** |
|
| 452 | - * _check_user_access |
|
| 453 | - * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
| 454 | - * WordPress die message. |
|
| 455 | - * |
|
| 456 | - * @return bool|die true if pass (or admin) wp_die if fail |
|
| 457 | - */ |
|
| 458 | - private function _check_user_access() |
|
| 459 | - { |
|
| 460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 461 | - $this->_menu_map->capability, |
|
| 462 | - $this->_menu_map->menu_slug |
|
| 463 | - )) { |
|
| 464 | - wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
| 465 | - } |
|
| 466 | - return true; |
|
| 467 | - } |
|
| 31 | + //identity properties (set in _set_defaults and _set_init_properties) |
|
| 32 | + public $label; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Menu map has a capability. However, this allows admin pages to have separate capability requirements for menus |
|
| 36 | + * and accessing pages. If capability is NOT set, then it defaults to the menu_map capability. |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + public $capability; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * This holds the menu map object for this admin page. |
|
| 45 | + * |
|
| 46 | + * @var EE_Admin_Page_Menu_Map |
|
| 47 | + */ |
|
| 48 | + protected $_menu_map; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * deprecated |
|
| 52 | + */ |
|
| 53 | + public $menu_label; |
|
| 54 | + public $menu_slug; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + //set in _set_defaults |
|
| 59 | + protected $_folder_name; |
|
| 60 | + protected $_folder_path; |
|
| 61 | + protected $_file_name; |
|
| 62 | + public $hook_file; |
|
| 63 | + protected $_wp_page_slug; |
|
| 64 | + protected $_routing; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + //will hold page object. |
|
| 68 | + protected $_loaded_page_object; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + //for caf |
|
| 72 | + protected $_files_hooked; |
|
| 73 | + protected $_hook_paths; |
|
| 74 | + |
|
| 75 | + //load_page? |
|
| 76 | + private $_load_page; |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @Constructor |
|
| 82 | + * @access public |
|
| 83 | + * @return void |
|
| 84 | + */ |
|
| 85 | + public function __construct() |
|
| 86 | + { |
|
| 87 | + //set global defaults |
|
| 88 | + $this->_set_defaults(); |
|
| 89 | + //set properties that are always available with objects. |
|
| 90 | + $this->_set_init_properties(); |
|
| 91 | + //global styles/scripts across all wp admin pages |
|
| 92 | + add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
| 93 | + //load initial stuff. |
|
| 94 | + $this->_set_file_and_folder_name(); |
|
| 95 | + $this->_set_menu_map(); |
|
| 96 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 97 | + EE_Error::doing_it_wrong( |
|
| 98 | + get_class($this) . '::$_menu_map', |
|
| 99 | + sprintf( |
|
| 100 | + __( |
|
| 101 | + 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
|
| 102 | + 'event_espresso' |
|
| 103 | + ), |
|
| 104 | + get_class($this) |
|
| 105 | + ), |
|
| 106 | + '4.4.0' |
|
| 107 | + ); |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + //set default capability |
|
| 111 | + $this->_set_capability(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * _set_init_properties |
|
| 118 | + * Child classes use to set the following properties: |
|
| 119 | + * $label |
|
| 120 | + * |
|
| 121 | + * @abstract |
|
| 122 | + * @access protected |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + abstract protected function _set_init_properties(); |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of |
|
| 131 | + * EE_Admin_Page_Menu_Map. Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu. |
|
| 132 | + * |
|
| 133 | + * @since 4.4.0 |
|
| 134 | + * @ return void. |
|
| 135 | + */ |
|
| 136 | + protected function _set_menu_map() |
|
| 137 | + { |
|
| 138 | + return array(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * returns the menu map for this admin page |
|
| 145 | + * |
|
| 146 | + * @since 4.4.0 |
|
| 147 | + * @return EE_Admin_Page_Menu_Map |
|
| 148 | + */ |
|
| 149 | + public function get_menu_map() |
|
| 150 | + { |
|
| 151 | + return $this->_menu_map; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * This loads scripts and styles for the EE_Admin system |
|
| 158 | + * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
| 159 | + * |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + public function load_wp_global_scripts_styles() |
|
| 163 | + { |
|
| 164 | + wp_register_style( |
|
| 165 | + 'espresso_menu', |
|
| 166 | + EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 167 | + array('dashicons'), |
|
| 168 | + EVENT_ESPRESSO_VERSION |
|
| 169 | + ); |
|
| 170 | + wp_enqueue_style('espresso_menu'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * this sets default properties (might be overridden in _set_init_properties); |
|
| 177 | + * |
|
| 178 | + * @access private |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + private function _set_defaults() |
|
| 182 | + { |
|
| 183 | + $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null; |
|
| 184 | + $this->_routing = true; |
|
| 185 | + $this->_load_page = false; |
|
| 186 | + $this->_files_hooked = $this->_hook_paths = array(); |
|
| 187 | + //menu_map |
|
| 188 | + $this->_menu_map = $this->get_menu_map(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + protected function _set_capability() |
|
| 194 | + { |
|
| 195 | + $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
| 196 | + $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * initialize_admin_page |
|
| 203 | + * This method is what executes the loading of the specific page class for the given dir_name as called by the |
|
| 204 | + * EE_Admin_Init class. |
|
| 205 | + * |
|
| 206 | + * @access public |
|
| 207 | + * @uses _initialize_admin_page() |
|
| 208 | + * @param string $dir_name directory name for specific admin_page being loaded. |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function initialize_admin_page() |
|
| 212 | + { |
|
| 213 | + //let's check user access first |
|
| 214 | + $this->_check_user_access(); |
|
| 215 | + if (! is_object($this->_loaded_page_object)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | + $this->_loaded_page_object->route_admin_request(); |
|
| 219 | + return; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + public function set_page_dependencies($wp_page_slug) |
|
| 225 | + { |
|
| 226 | + if (! $this->_load_page) { |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + if (! is_object($this->_loaded_page_object)) { |
|
| 230 | + $msg[] = __( |
|
| 231 | + 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
|
| 232 | + 'event_espresso' |
|
| 233 | + ); |
|
| 234 | + $msg[] = $msg[0] . "\r\n" . sprintf( |
|
| 235 | + __( |
|
| 236 | + 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
|
| 237 | + 'event_espresso' |
|
| 238 | + ), |
|
| 239 | + $this->_file_name, |
|
| 240 | + $this->_file_name, |
|
| 241 | + $this->_folder_path . $this->_file_name, |
|
| 242 | + $this->_menu_map->menu_slug |
|
| 243 | + ); |
|
| 244 | + throw new EE_Error(implode('||', $msg)); |
|
| 245 | + } |
|
| 246 | + $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
|
| 247 | + $page_hook = 'load-' . $wp_page_slug; |
|
| 248 | + //hook into page load hook so all page specific stuff get's loaded. |
|
| 249 | + if (! empty($wp_page_slug)) { |
|
| 250 | + add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run |
|
| 257 | + * before the load-page... hook. Note, the page loads are happening around the wp_init hook. |
|
| 258 | + * |
|
| 259 | + * @return void |
|
| 260 | + */ |
|
| 261 | + public function do_initial_loads() |
|
| 262 | + { |
|
| 263 | + //no loading or initializing if menu map is setup incorrectly. |
|
| 264 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
| 265 | + return; |
|
| 266 | + } |
|
| 267 | + $this->_initialize_admin_page(); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * all we're doing here is setting the $_file_name property for later use. |
|
| 273 | + * |
|
| 274 | + * @access private |
|
| 275 | + * @return void |
|
| 276 | + */ |
|
| 277 | + private function _set_file_and_folder_name() |
|
| 278 | + { |
|
| 279 | + $bt = debug_backtrace(); |
|
| 280 | + //for more reliable determination of folder name |
|
| 281 | + //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
|
| 282 | + $class = get_class($this); |
|
| 283 | + foreach ($bt as $index => $values) { |
|
| 284 | + if (isset($values['class']) && $values['class'] == $class) { |
|
| 285 | + $file_index = $index - 1; |
|
| 286 | + $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
| 287 | + if (! empty($this->_folder_name)) { |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
| 293 | + $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
| 294 | + $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
| 295 | + $this->_file_name = str_replace(' ', '_', $this->_file_name); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * This automatically checks if we have a hook class in the loaded child directory. If we DO then we will register |
|
| 301 | + * it with the appropriate pages. That way all we have to do is make sure the file is named correctly and |
|
| 302 | + * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do: |
|
| 303 | + * events_Messages_Hooks.class.php |
|
| 304 | + * |
|
| 305 | + * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks |
|
| 306 | + * files/classes |
|
| 307 | + * @return array |
|
| 308 | + */ |
|
| 309 | + public function register_hooks($extend = false) |
|
| 310 | + { |
|
| 311 | + |
|
| 312 | + //get a list of files in the directory that have the "Hook" in their name an |
|
| 313 | + //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
|
| 314 | + if ($extend) { |
|
| 315 | + $hook_files_glob_path = apply_filters( |
|
| 316 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', |
|
| 317 | + EE_CORE_CAF_ADMIN_EXTEND |
|
| 318 | + . $this->_folder_name |
|
| 319 | + . DS |
|
| 320 | + . '*' |
|
| 321 | + . $this->_file_name |
|
| 322 | + . '_Hooks_Extend.class.php' |
|
| 323 | + ); |
|
| 324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 325 | + } |
|
| 326 | + //loop through decaf folders |
|
| 327 | + $hook_files_glob_path = apply_filters( |
|
| 328 | + 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
|
| 329 | + $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 330 | + ); |
|
| 331 | + $this->_hook_paths = array_merge( |
|
| 332 | + $this->_register_hook_files($hook_files_glob_path), |
|
| 333 | + $this->_hook_paths |
|
| 334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 335 | + return $this->_hook_paths; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + protected function _register_hook_files($hook_files_glob_path, $extend = false) |
|
| 341 | + { |
|
| 342 | + $hook_paths = array(); |
|
| 343 | + if ($hook_files = glob($hook_files_glob_path)) { |
|
| 344 | + if (empty($hook_files)) { |
|
| 345 | + return array(); |
|
| 346 | + } |
|
| 347 | + foreach ($hook_files as $file) { |
|
| 348 | + //lets get the linked admin. |
|
| 349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
| 350 | + : str_replace($this->_folder_path, '', $file); |
|
| 351 | + $replace = $extend |
|
| 352 | + ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 353 | + : '_' |
|
| 354 | + . $this->_file_name |
|
| 355 | + . '_Hooks.class.php'; |
|
| 356 | + $rel_admin = str_replace($replace, '', $hook_file); |
|
| 357 | + $rel_admin = strtolower($rel_admin); |
|
| 358 | + $hook_paths[] = $file; |
|
| 359 | + //make sure we haven't already got a hook setup for this page path |
|
| 360 | + if (in_array($rel_admin, $this->_files_hooked)) { |
|
| 361 | + continue; |
|
| 362 | + } |
|
| 363 | + $this->hook_file = $hook_file; |
|
| 364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 365 | + $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
| 366 | + $this->_files_hooked[] = $rel_admin; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + return $hook_paths; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + public function load_admin_hook($registered_pages) |
|
| 375 | + { |
|
| 376 | + $this->hook_file; |
|
| 377 | + $hook_file = (array)$this->hook_file; |
|
| 378 | + return array_merge($hook_file, $registered_pages); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * _initialize_admin_page |
|
| 384 | + * |
|
| 385 | + * @see initialize_admin_page() for info |
|
| 386 | + */ |
|
| 387 | + protected function _initialize_admin_page() |
|
| 388 | + { |
|
| 389 | + |
|
| 390 | + //JUST CHECK WE'RE ON RIGHT PAGE. |
|
| 391 | + if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 392 | + return; |
|
| 393 | + } //not on the right page so let's get out. |
|
| 394 | + $this->_load_page = true; |
|
| 395 | + //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
|
| 396 | + // spl_autoload_register(array( $this, 'set_autoloaders') ); |
|
| 397 | + //we don't need to do a page_request check here because it's only called via WP menu system. |
|
| 398 | + $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 399 | + $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 400 | + $admin_page = apply_filters( |
|
| 401 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
|
| 402 | + $admin_page |
|
| 403 | + ); |
|
| 404 | + // define requested admin page class name then load the file and instantiate |
|
| 405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
| 406 | + $path_to_file = apply_filters( |
|
| 407 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
|
| 408 | + $path_to_file |
|
| 409 | + );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 410 | + if (is_readable($path_to_file)) { |
|
| 411 | + // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
|
| 412 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
| 413 | + do_action( |
|
| 414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 415 | + ); |
|
| 416 | + require_once($path_to_file); |
|
| 417 | + $a = new ReflectionClass($admin_page); |
|
| 418 | + $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
| 419 | + } |
|
| 420 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
| 421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + public function get_admin_page_name() |
|
| 427 | + { |
|
| 428 | + return $this->_file_name . '_Admin_Page'; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @return mixed |
|
| 435 | + */ |
|
| 436 | + public function loaded_page_object() |
|
| 437 | + { |
|
| 438 | + return $this->_loaded_page_object; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + // public function set_autoloaders( $className ) { |
|
| 446 | + // $dir_ref = array( |
|
| 447 | + // $this->_folder_path => array('core','class') |
|
| 448 | + // ); |
|
| 449 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 450 | + // } |
|
| 451 | + /** |
|
| 452 | + * _check_user_access |
|
| 453 | + * verifies user access for this admin page. If no user access is available then let's gracefully exit with a |
|
| 454 | + * WordPress die message. |
|
| 455 | + * |
|
| 456 | + * @return bool|die true if pass (or admin) wp_die if fail |
|
| 457 | + */ |
|
| 458 | + private function _check_user_access() |
|
| 459 | + { |
|
| 460 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 461 | + $this->_menu_map->capability, |
|
| 462 | + $this->_menu_map->menu_slug |
|
| 463 | + )) { |
|
| 464 | + wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
| 465 | + } |
|
| 466 | + return true; |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | 469 | } |
| 470 | 470 | // end of file: includes/core/admin/EE_Admin_Page_Init.core.php |
@@ -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 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $this->_set_menu_map(); |
| 96 | 96 | if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
| 97 | 97 | EE_Error::doing_it_wrong( |
| 98 | - get_class($this) . '::$_menu_map', |
|
| 98 | + get_class($this).'::$_menu_map', |
|
| 99 | 99 | sprintf( |
| 100 | 100 | __( |
| 101 | 101 | 'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | wp_register_style( |
| 165 | 165 | 'espresso_menu', |
| 166 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
| 166 | + EE_ADMIN_URL.'assets/admin-menu-styles.css', |
|
| 167 | 167 | array('dashicons'), |
| 168 | 168 | EVENT_ESPRESSO_VERSION |
| 169 | 169 | ); |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | protected function _set_capability() |
| 194 | 194 | { |
| 195 | 195 | $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
| 196 | - $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability); |
|
| 196 | + $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | //let's check user access first |
| 214 | 214 | $this->_check_user_access(); |
| 215 | - if (! is_object($this->_loaded_page_object)) { |
|
| 215 | + if ( ! is_object($this->_loaded_page_object)) { |
|
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | $this->_loaded_page_object->route_admin_request(); |
@@ -223,30 +223,30 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | public function set_page_dependencies($wp_page_slug) |
| 225 | 225 | { |
| 226 | - if (! $this->_load_page) { |
|
| 226 | + if ( ! $this->_load_page) { |
|
| 227 | 227 | return; |
| 228 | 228 | } |
| 229 | - if (! is_object($this->_loaded_page_object)) { |
|
| 229 | + if ( ! is_object($this->_loaded_page_object)) { |
|
| 230 | 230 | $msg[] = __( |
| 231 | 231 | 'We can\'t load the page because we\'re missing a valid page object that tells us what to load', |
| 232 | 232 | 'event_espresso' |
| 233 | 233 | ); |
| 234 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
| 234 | + $msg[] = $msg[0]."\r\n".sprintf( |
|
| 235 | 235 | __( |
| 236 | 236 | 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', |
| 237 | 237 | 'event_espresso' |
| 238 | 238 | ), |
| 239 | 239 | $this->_file_name, |
| 240 | 240 | $this->_file_name, |
| 241 | - $this->_folder_path . $this->_file_name, |
|
| 241 | + $this->_folder_path.$this->_file_name, |
|
| 242 | 242 | $this->_menu_map->menu_slug |
| 243 | 243 | ); |
| 244 | 244 | throw new EE_Error(implode('||', $msg)); |
| 245 | 245 | } |
| 246 | 246 | $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
| 247 | - $page_hook = 'load-' . $wp_page_slug; |
|
| 247 | + $page_hook = 'load-'.$wp_page_slug; |
|
| 248 | 248 | //hook into page load hook so all page specific stuff get's loaded. |
| 249 | - if (! empty($wp_page_slug)) { |
|
| 249 | + if ( ! empty($wp_page_slug)) { |
|
| 250 | 250 | add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | if (isset($values['class']) && $values['class'] == $class) { |
| 285 | 285 | $file_index = $index - 1; |
| 286 | 286 | $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
| 287 | - if (! empty($this->_folder_name)) { |
|
| 287 | + if ( ! empty($this->_folder_name)) { |
|
| 288 | 288 | break; |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
| 292 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.DS; |
|
| 293 | 293 | $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
| 294 | 294 | $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
| 295 | 295 | $this->_file_name = str_replace(' ', '_', $this->_file_name); |
@@ -321,17 +321,17 @@ discard block |
||
| 321 | 321 | . $this->_file_name |
| 322 | 322 | . '_Hooks_Extend.class.php' |
| 323 | 323 | ); |
| 324 | - $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 324 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
| 325 | 325 | } |
| 326 | 326 | //loop through decaf folders |
| 327 | 327 | $hook_files_glob_path = apply_filters( |
| 328 | 328 | 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', |
| 329 | - $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' |
|
| 329 | + $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php' |
|
| 330 | 330 | ); |
| 331 | - $this->_hook_paths = array_merge( |
|
| 331 | + $this->_hook_paths = array_merge( |
|
| 332 | 332 | $this->_register_hook_files($hook_files_glob_path), |
| 333 | 333 | $this->_hook_paths |
| 334 | - ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 334 | + ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
| 335 | 335 | return $this->_hook_paths; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -346,10 +346,10 @@ discard block |
||
| 346 | 346 | } |
| 347 | 347 | foreach ($hook_files as $file) { |
| 348 | 348 | //lets get the linked admin. |
| 349 | - $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file) |
|
| 349 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS, '', $file) |
|
| 350 | 350 | : str_replace($this->_folder_path, '', $file); |
| 351 | 351 | $replace = $extend |
| 352 | - ? '_' . $this->_file_name . '_Hooks_Extend.class.php' |
|
| 352 | + ? '_'.$this->_file_name.'_Hooks_Extend.class.php' |
|
| 353 | 353 | : '_' |
| 354 | 354 | . $this->_file_name |
| 355 | 355 | . '_Hooks.class.php'; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | continue; |
| 362 | 362 | } |
| 363 | 363 | $this->hook_file = $hook_file; |
| 364 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
| 364 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin; |
|
| 365 | 365 | $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
| 366 | 366 | $this->_files_hooked[] = $rel_admin; |
| 367 | 367 | } |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | public function load_admin_hook($registered_pages) |
| 375 | 375 | { |
| 376 | 376 | $this->hook_file; |
| 377 | - $hook_file = (array)$this->hook_file; |
|
| 377 | + $hook_file = (array) $this->hook_file; |
|
| 378 | 378 | return array_merge($hook_file, $registered_pages); |
| 379 | 379 | } |
| 380 | 380 | |
@@ -388,44 +388,44 @@ discard block |
||
| 388 | 388 | { |
| 389 | 389 | |
| 390 | 390 | //JUST CHECK WE'RE ON RIGHT PAGE. |
| 391 | - if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 391 | + if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) { |
|
| 392 | 392 | return; |
| 393 | 393 | } //not on the right page so let's get out. |
| 394 | 394 | $this->_load_page = true; |
| 395 | 395 | //let's set page specific autoloaders. Note that this just sets autoloaders for THIS set of admin pages. |
| 396 | 396 | // spl_autoload_register(array( $this, 'set_autoloaders') ); |
| 397 | 397 | //we don't need to do a page_request check here because it's only called via WP menu system. |
| 398 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
| 399 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
| 398 | + $admin_page = $this->_file_name.'_Admin_Page'; |
|
| 399 | + $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page; |
|
| 400 | 400 | $admin_page = apply_filters( |
| 401 | 401 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", |
| 402 | 402 | $admin_page |
| 403 | 403 | ); |
| 404 | 404 | // define requested admin page class name then load the file and instantiate |
| 405 | - $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php'); |
|
| 405 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path.$admin_page.'.core.php'); |
|
| 406 | 406 | $path_to_file = apply_filters( |
| 407 | 407 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", |
| 408 | 408 | $path_to_file |
| 409 | - );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 409 | + ); //so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
| 410 | 410 | if (is_readable($path_to_file)) { |
| 411 | 411 | // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
| 412 | 412 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
| 413 | 413 | do_action( |
| 414 | - 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug |
|
| 414 | + 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug |
|
| 415 | 415 | ); |
| 416 | 416 | require_once($path_to_file); |
| 417 | 417 | $a = new ReflectionClass($admin_page); |
| 418 | 418 | $this->_loaded_page_object = $a->newInstance($this->_routing); |
| 419 | 419 | } |
| 420 | 420 | do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
| 421 | - do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug); |
|
| 421 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | |
| 425 | 425 | |
| 426 | 426 | public function get_admin_page_name() |
| 427 | 427 | { |
| 428 | - return $this->_file_name . '_Admin_Page'; |
|
| 428 | + return $this->_file_name.'_Admin_Page'; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | private function _check_user_access() |
| 459 | 459 | { |
| 460 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 460 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 461 | 461 | $this->_menu_map->capability, |
| 462 | 462 | $this->_menu_map->menu_slug |
| 463 | 463 | )) { |
@@ -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 | /** |
@@ -12,869 +12,869 @@ discard block |
||
| 12 | 12 | class EE_Message extends EE_Base_Class implements EEI_Admin_Links |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 17 | - * @type null |
|
| 18 | - */ |
|
| 19 | - public $template_pack; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 23 | - * @type null |
|
| 24 | - */ |
|
| 25 | - public $template_variation; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 29 | - * @type string |
|
| 30 | - */ |
|
| 31 | - public $content = ''; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @type EE_messenger $_messenger |
|
| 36 | - */ |
|
| 37 | - protected $_messenger = null; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @type EE_message_type $_message_type |
|
| 41 | - */ |
|
| 42 | - protected $_message_type = null; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param array $props_n_values |
|
| 47 | - * @param string $timezone |
|
| 48 | - * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
| 49 | - * format. |
|
| 50 | - * @return EE_Message |
|
| 51 | - */ |
|
| 52 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 53 | - { |
|
| 54 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 55 | - //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
| 56 | - if ( ! $has_object) { |
|
| 57 | - EE_Registry::instance()->load_helper('URL'); |
|
| 58 | - $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
| 59 | - } |
|
| 60 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param array $props_n_values |
|
| 66 | - * @param string $timezone |
|
| 67 | - * @return EE_Message |
|
| 68 | - */ |
|
| 69 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 70 | - { |
|
| 71 | - return new self($props_n_values, true, $timezone); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Gets MSG_token |
|
| 77 | - * |
|
| 78 | - * @return int |
|
| 79 | - */ |
|
| 80 | - public function MSG_token() |
|
| 81 | - { |
|
| 82 | - return $this->get('MSG_token'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Sets MSG_token |
|
| 88 | - * |
|
| 89 | - * @param int $MSG_token |
|
| 90 | - */ |
|
| 91 | - public function set_MSG_token($MSG_token) |
|
| 92 | - { |
|
| 93 | - $this->set('MSG_token', $MSG_token); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets GRP_ID |
|
| 99 | - * |
|
| 100 | - * @return int |
|
| 101 | - */ |
|
| 102 | - public function GRP_ID() |
|
| 103 | - { |
|
| 104 | - return $this->get('GRP_ID'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Sets GRP_ID |
|
| 110 | - * |
|
| 111 | - * @param int $GRP_ID |
|
| 112 | - */ |
|
| 113 | - public function set_GRP_ID($GRP_ID) |
|
| 114 | - { |
|
| 115 | - $this->set('GRP_ID', $GRP_ID); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Gets TXN_ID |
|
| 121 | - * |
|
| 122 | - * @return int |
|
| 123 | - */ |
|
| 124 | - public function TXN_ID() |
|
| 125 | - { |
|
| 126 | - return $this->get('TXN_ID'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Sets TXN_ID |
|
| 132 | - * |
|
| 133 | - * @param int $TXN_ID |
|
| 134 | - */ |
|
| 135 | - public function set_TXN_ID($TXN_ID) |
|
| 136 | - { |
|
| 137 | - $this->set('TXN_ID', $TXN_ID); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Gets messenger |
|
| 143 | - * |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function messenger() |
|
| 147 | - { |
|
| 148 | - return $this->get('MSG_messenger'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Sets messenger |
|
| 154 | - * |
|
| 155 | - * @param string $messenger |
|
| 156 | - */ |
|
| 157 | - public function set_messenger($messenger) |
|
| 158 | - { |
|
| 159 | - $this->set('MSG_messenger', $messenger); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Returns corresponding messenger object for the set messenger on this message |
|
| 165 | - * |
|
| 166 | - * @return EE_messenger | null |
|
| 167 | - */ |
|
| 168 | - public function messenger_object() |
|
| 169 | - { |
|
| 170 | - return $this->_messenger; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Sets messenger |
|
| 176 | - * |
|
| 177 | - * @param EE_messenger $messenger |
|
| 178 | - */ |
|
| 179 | - public function set_messenger_object(EE_messenger $messenger) |
|
| 180 | - { |
|
| 181 | - $this->_messenger = $messenger; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * validates messenger |
|
| 187 | - * |
|
| 188 | - * @param bool $throw_exceptions |
|
| 189 | - * @return bool |
|
| 190 | - * @throws \EE_Error |
|
| 191 | - */ |
|
| 192 | - public function valid_messenger($throw_exceptions = false) |
|
| 193 | - { |
|
| 194 | - if ($this->_messenger instanceof EE_messenger) { |
|
| 195 | - return true; |
|
| 196 | - } |
|
| 197 | - if ($throw_exceptions) { |
|
| 198 | - throw new EE_Error( |
|
| 199 | - sprintf( |
|
| 200 | - __( |
|
| 201 | - 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ), |
|
| 204 | - $this->messenger() |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * This returns the set localized label for the messenger on this message. |
|
| 214 | - * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
| 215 | - * with this message. |
|
| 216 | - * |
|
| 217 | - * @param bool $plural whether to return the plural label or not. |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public function messenger_label($plural = false) |
|
| 221 | - { |
|
| 222 | - $label_type = $plural ? 'plural' : 'singular'; |
|
| 223 | - $messenger = $this->messenger_object(); |
|
| 224 | - return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Gets message_type |
|
| 230 | - * |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - public function message_type() |
|
| 234 | - { |
|
| 235 | - return $this->get('MSG_message_type'); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Sets message_type |
|
| 241 | - * |
|
| 242 | - * @param string $message_type |
|
| 243 | - */ |
|
| 244 | - public function set_message_type($message_type) |
|
| 245 | - { |
|
| 246 | - $this->set('MSG_message_type', $message_type); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Returns the message type object for the set message type on this message |
|
| 252 | - * |
|
| 253 | - * @return EE_message_type | null |
|
| 254 | - */ |
|
| 255 | - public function message_type_object() |
|
| 256 | - { |
|
| 257 | - return $this->_message_type; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Sets message_type |
|
| 263 | - * |
|
| 264 | - * @param EE_message_type $message_type |
|
| 265 | - * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
| 266 | - * the message type or not. |
|
| 267 | - */ |
|
| 268 | - public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
| 269 | - { |
|
| 270 | - $this->_message_type = $message_type; |
|
| 271 | - if ($set_priority) { |
|
| 272 | - $this->set_priority($this->_message_type->get_priority()); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * validates message_type |
|
| 279 | - * |
|
| 280 | - * @param bool $throw_exceptions |
|
| 281 | - * @return bool |
|
| 282 | - * @throws \EE_Error |
|
| 283 | - */ |
|
| 284 | - public function valid_message_type($throw_exceptions = false) |
|
| 285 | - { |
|
| 286 | - if ($this->_message_type instanceof EE_message_type) { |
|
| 287 | - return true; |
|
| 288 | - } |
|
| 289 | - if ($throw_exceptions) { |
|
| 290 | - throw new EE_Error( |
|
| 291 | - sprintf( |
|
| 292 | - __( |
|
| 293 | - 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 294 | - 'event_espresso' |
|
| 295 | - ), |
|
| 296 | - $this->message_type() |
|
| 297 | - ) |
|
| 298 | - ); |
|
| 299 | - } |
|
| 300 | - return false; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
| 306 | - * |
|
| 307 | - * @param bool $throw_exceptions |
|
| 308 | - * @return bool |
|
| 309 | - * @throws \EE_Error |
|
| 310 | - */ |
|
| 311 | - public function is_valid($throw_exceptions = false) |
|
| 312 | - { |
|
| 313 | - if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
| 314 | - return true; |
|
| 315 | - } |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * This validates whether the internal messenger and message type objects are valid for sending. |
|
| 322 | - * Three checks are done: |
|
| 323 | - * 1. There is a valid messenger object. |
|
| 324 | - * 2. There is a valid message type object. |
|
| 325 | - * 3. The message type object is active for the messenger. |
|
| 326 | - * |
|
| 327 | - * @throws EE_Error But only if $throw_exceptions is set to true. |
|
| 328 | - * @param bool $throw_exceptions |
|
| 329 | - * @return bool |
|
| 330 | - */ |
|
| 331 | - public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
| 332 | - { |
|
| 333 | - $valid = false; |
|
| 334 | - if ($this->is_valid($throw_exceptions)) { |
|
| 335 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 336 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 337 | - $valid = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(), |
|
| 338 | - $this->message_type()); |
|
| 339 | - if ( ! $valid && $throw_exceptions) { |
|
| 340 | - throw new EE_Error( |
|
| 341 | - sprintf( |
|
| 342 | - __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
| 343 | - 'event_espresso'), |
|
| 344 | - $this->message_type(), |
|
| 345 | - $this->messenger() |
|
| 346 | - ) |
|
| 347 | - ); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - return $valid; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * This returns the set localized label for the message type on this message. |
|
| 356 | - * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
| 357 | - * with this message. |
|
| 358 | - * |
|
| 359 | - * @param bool $plural whether to return the plural label or not. |
|
| 360 | - * @return string |
|
| 361 | - */ |
|
| 362 | - public function message_type_label($plural = false) |
|
| 363 | - { |
|
| 364 | - $label_type = $plural ? 'plural' : 'singular'; |
|
| 365 | - $message_type = $this->message_type_object(); |
|
| 366 | - return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace( |
|
| 367 | - '_', |
|
| 368 | - ' ', |
|
| 369 | - $this->message_type() |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Gets context |
|
| 376 | - * |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function context() |
|
| 380 | - { |
|
| 381 | - return $this->get('MSG_context'); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
| 387 | - * types. Otherwise, this will just return the set context slug on this object. |
|
| 388 | - * |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - public function context_label() |
|
| 392 | - { |
|
| 393 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 394 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 395 | - $contexts = $message_resource_manager->get_all_contexts(); |
|
| 396 | - return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Sets context |
|
| 402 | - * |
|
| 403 | - * @param string $context |
|
| 404 | - */ |
|
| 405 | - public function set_context($context) |
|
| 406 | - { |
|
| 407 | - $this->set('MSG_context', $context); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Gets recipient_ID |
|
| 413 | - * |
|
| 414 | - * @return int |
|
| 415 | - */ |
|
| 416 | - public function recipient_ID() |
|
| 417 | - { |
|
| 418 | - return $this->get('MSG_recipient_ID'); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Sets recipient_ID |
|
| 424 | - * |
|
| 425 | - * @param string $recipient_ID |
|
| 426 | - */ |
|
| 427 | - public function set_recipient_ID($recipient_ID) |
|
| 428 | - { |
|
| 429 | - $this->set('MSG_recipient_ID', $recipient_ID); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Gets recipient_type |
|
| 435 | - * |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - public function recipient_type() |
|
| 439 | - { |
|
| 440 | - return $this->get('MSG_recipient_type'); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Return the related object matching the recipient type and ID. |
|
| 446 | - * |
|
| 447 | - * @return EE_Base_Class | null |
|
| 448 | - */ |
|
| 449 | - public function recipient_object() |
|
| 450 | - { |
|
| 451 | - if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
| 452 | - return null; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - return $this->get_first_related($this->recipient_type()); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Sets recipient_type |
|
| 461 | - * |
|
| 462 | - * @param string $recipient_type |
|
| 463 | - */ |
|
| 464 | - public function set_recipient_type($recipient_type) |
|
| 465 | - { |
|
| 466 | - $this->set('MSG_recipient_type', $recipient_type); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Gets content |
|
| 472 | - * |
|
| 473 | - * @return string |
|
| 474 | - */ |
|
| 475 | - public function content() |
|
| 476 | - { |
|
| 477 | - return $this->get('MSG_content'); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Sets content |
|
| 483 | - * |
|
| 484 | - * @param string $content |
|
| 485 | - */ |
|
| 486 | - public function set_content($content) |
|
| 487 | - { |
|
| 488 | - $this->set('MSG_content', $content); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Gets subject |
|
| 494 | - * |
|
| 495 | - * @return string |
|
| 496 | - */ |
|
| 497 | - public function subject() |
|
| 498 | - { |
|
| 499 | - return $this->get('MSG_subject'); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Sets subject |
|
| 505 | - * |
|
| 506 | - * @param string $subject |
|
| 507 | - */ |
|
| 508 | - public function set_subject($subject) |
|
| 509 | - { |
|
| 510 | - $this->set('MSG_subject', $subject); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Gets to |
|
| 516 | - * |
|
| 517 | - * @return string |
|
| 518 | - */ |
|
| 519 | - public function to() |
|
| 520 | - { |
|
| 521 | - $to = $this->get('MSG_to'); |
|
| 522 | - return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Sets to |
|
| 528 | - * |
|
| 529 | - * @param string $to |
|
| 530 | - */ |
|
| 531 | - public function set_to($to) |
|
| 532 | - { |
|
| 533 | - $this->set('MSG_to', $to); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Gets from |
|
| 539 | - * |
|
| 540 | - * @return string |
|
| 541 | - */ |
|
| 542 | - public function from() |
|
| 543 | - { |
|
| 544 | - return $this->get('MSG_from'); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Sets from |
|
| 550 | - * |
|
| 551 | - * @param string $from |
|
| 552 | - */ |
|
| 553 | - public function set_from($from) |
|
| 554 | - { |
|
| 555 | - $this->set('MSG_from', $from); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Gets priority |
|
| 561 | - * |
|
| 562 | - * @return int |
|
| 563 | - */ |
|
| 564 | - public function priority() |
|
| 565 | - { |
|
| 566 | - return $this->get('MSG_priority'); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Sets priority |
|
| 572 | - * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
| 573 | - * this method calls the send_now method to verify that. |
|
| 574 | - * |
|
| 575 | - * @param int $priority |
|
| 576 | - */ |
|
| 577 | - public function set_priority($priority) |
|
| 578 | - { |
|
| 579 | - $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
| 580 | - parent::set('MSG_priority', $priority); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Overrides parent::set method so we can capture any sets for priority. |
|
| 586 | - * |
|
| 587 | - * @see parent::set() for phpdocs |
|
| 588 | - * @param string $field_name |
|
| 589 | - * @param mixed $field_value |
|
| 590 | - * @param bool $use_default |
|
| 591 | - * @throws EE_Error |
|
| 592 | - */ |
|
| 593 | - public function set($field_name, $field_value, $use_default = false) |
|
| 594 | - { |
|
| 595 | - if ($field_name === 'MSG_priority') { |
|
| 596 | - $this->set_priority($field_value); |
|
| 597 | - } |
|
| 598 | - parent::set($field_name, $field_value, $use_default); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * @return bool |
|
| 604 | - * @throws \EE_Error |
|
| 605 | - */ |
|
| 606 | - public function send_now() |
|
| 607 | - { |
|
| 608 | - $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
| 609 | - return $send_now === EEM_Message::priority_high ? true : false; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Gets STS_ID |
|
| 615 | - * |
|
| 616 | - * @return string |
|
| 617 | - */ |
|
| 618 | - public function STS_ID() |
|
| 619 | - { |
|
| 620 | - return $this->get('STS_ID'); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Sets STS_ID |
|
| 626 | - * |
|
| 627 | - * @param string $STS_ID |
|
| 628 | - */ |
|
| 629 | - public function set_STS_ID($STS_ID) |
|
| 630 | - { |
|
| 631 | - $this->set('STS_ID', $STS_ID); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Gets created |
|
| 637 | - * |
|
| 638 | - * @return string |
|
| 639 | - */ |
|
| 640 | - public function created() |
|
| 641 | - { |
|
| 642 | - return $this->get('MSG_created'); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Sets created |
|
| 648 | - * |
|
| 649 | - * @param string $created |
|
| 650 | - */ |
|
| 651 | - public function set_created($created) |
|
| 652 | - { |
|
| 653 | - $this->set('MSG_created', $created); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Gets modified |
|
| 659 | - * |
|
| 660 | - * @return string |
|
| 661 | - */ |
|
| 662 | - public function modified() |
|
| 663 | - { |
|
| 664 | - return $this->get('MSG_modified'); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Sets modified |
|
| 670 | - * |
|
| 671 | - * @param string $modified |
|
| 672 | - */ |
|
| 673 | - public function set_modified($modified) |
|
| 674 | - { |
|
| 675 | - $this->set('MSG_modified', $modified); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Sets generation data for this message. |
|
| 681 | - * |
|
| 682 | - * @param mixed $data |
|
| 683 | - */ |
|
| 684 | - public function set_generation_data($data) |
|
| 685 | - { |
|
| 686 | - $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Returns any set generation data for this message. |
|
| 692 | - * |
|
| 693 | - * @return mixed|null |
|
| 694 | - */ |
|
| 695 | - public function get_generation_data() |
|
| 696 | - { |
|
| 697 | - return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * Gets any error message. |
|
| 703 | - * |
|
| 704 | - * @return mixed|null |
|
| 705 | - */ |
|
| 706 | - public function error_message() |
|
| 707 | - { |
|
| 708 | - return $this->get_field_or_extra_meta('MSG_error'); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * Sets an error message. |
|
| 714 | - * |
|
| 715 | - * @param $message |
|
| 716 | - * @return bool|int |
|
| 717 | - */ |
|
| 718 | - public function set_error_message($message) |
|
| 719 | - { |
|
| 720 | - return $this->set_field_or_extra_meta('MSG_error', $message); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * This retrieves the associated template pack with this message. |
|
| 726 | - * |
|
| 727 | - * @return EE_Messages_Template_Pack | null |
|
| 728 | - */ |
|
| 729 | - public function get_template_pack() |
|
| 730 | - { |
|
| 731 | - /** |
|
| 732 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 733 | - */ |
|
| 734 | - if ( ! empty($this->template_pack)) { |
|
| 735 | - return $this->template_pack; |
|
| 736 | - } |
|
| 737 | - /** @type EE_Message_Template_Group $grp */ |
|
| 738 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
| 739 | - //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 740 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
| 741 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 742 | - array( |
|
| 743 | - array( |
|
| 744 | - 'MTP_messenger' => $this->messenger(), |
|
| 745 | - 'MTP_message_type' => $this->message_type(), |
|
| 746 | - 'MTP_is_global' => true, |
|
| 747 | - ), |
|
| 748 | - ) |
|
| 749 | - ); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Retrieves the variation used for generating this message. |
|
| 758 | - * |
|
| 759 | - * @return string |
|
| 760 | - */ |
|
| 761 | - public function get_template_pack_variation() |
|
| 762 | - { |
|
| 763 | - /** |
|
| 764 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 765 | - */ |
|
| 766 | - if ( ! empty($this->template_variation)) { |
|
| 767 | - return $this->template_variation; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - /** @type EE_Message_Template_Group $grp */ |
|
| 771 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
| 772 | - |
|
| 773 | - //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 774 | - if ( ! $grp instanceof EE_Message_Template_Group) { |
|
| 775 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 776 | - array( |
|
| 777 | - array( |
|
| 778 | - 'MTP_messenger' => $this->messenger(), |
|
| 779 | - 'MTP_message_type' => $this->message_type(), |
|
| 780 | - 'MTP_is_global' => true, |
|
| 781 | - ), |
|
| 782 | - ) |
|
| 783 | - ); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * Return the link to the admin details for the object. |
|
| 791 | - * |
|
| 792 | - * @return string |
|
| 793 | - */ |
|
| 794 | - public function get_admin_details_link() |
|
| 795 | - { |
|
| 796 | - EE_Registry::instance()->load_helper('URL'); |
|
| 797 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 798 | - switch ($this->STS_ID()) { |
|
| 799 | - case EEM_Message::status_failed : |
|
| 800 | - case EEM_Message::status_debug_only : |
|
| 801 | - return EEH_MSG_Template::generate_error_display_trigger($this); |
|
| 802 | - break; |
|
| 803 | - |
|
| 804 | - case EEM_Message::status_sent : |
|
| 805 | - return EEH_MSG_Template::generate_browser_trigger($this); |
|
| 806 | - break; |
|
| 807 | - |
|
| 808 | - default : |
|
| 809 | - return ''; |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 815 | - * |
|
| 816 | - * @return string |
|
| 817 | - */ |
|
| 818 | - public function get_admin_edit_link() |
|
| 819 | - { |
|
| 820 | - return $this->get_admin_details_link(); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Returns the link to a settings page for the object. |
|
| 825 | - * |
|
| 826 | - * @return string |
|
| 827 | - */ |
|
| 828 | - public function get_admin_settings_link() |
|
| 829 | - { |
|
| 830 | - EE_Registry::instance()->load_helper('URL'); |
|
| 831 | - return EEH_URL::add_query_args_and_nonce( |
|
| 832 | - array( |
|
| 833 | - 'page' => 'espresso_messages', |
|
| 834 | - 'action' => 'settings', |
|
| 835 | - ), |
|
| 836 | - admin_url('admin.php') |
|
| 837 | - ); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 842 | - * |
|
| 843 | - * @return string |
|
| 844 | - */ |
|
| 845 | - public function get_admin_overview_link() |
|
| 846 | - { |
|
| 847 | - EE_Registry::instance()->load_helper('URL'); |
|
| 848 | - return EEH_URL::add_query_args_and_nonce( |
|
| 849 | - array( |
|
| 850 | - 'page' => 'espresso_messages', |
|
| 851 | - 'action' => 'default', |
|
| 852 | - ), |
|
| 853 | - admin_url('admin.php') |
|
| 854 | - ); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
| 860 | - * it. |
|
| 861 | - * Note this also SAVES the current message object to the db because it adds an error message to accompany the status. |
|
| 862 | - * |
|
| 863 | - */ |
|
| 864 | - public function set_messenger_is_executing() |
|
| 865 | - { |
|
| 866 | - $this->set_STS_ID( EEM_Message::status_messenger_executing ); |
|
| 867 | - $this->set_error_message( |
|
| 868 | - esc_html__( |
|
| 869 | - 'A message with this status indicates that there was a problem that occurred while the message was being |
|
| 15 | + /** |
|
| 16 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 17 | + * @type null |
|
| 18 | + */ |
|
| 19 | + public $template_pack; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 23 | + * @type null |
|
| 24 | + */ |
|
| 25 | + public $template_variation; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 29 | + * @type string |
|
| 30 | + */ |
|
| 31 | + public $content = ''; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @type EE_messenger $_messenger |
|
| 36 | + */ |
|
| 37 | + protected $_messenger = null; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @type EE_message_type $_message_type |
|
| 41 | + */ |
|
| 42 | + protected $_message_type = null; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param array $props_n_values |
|
| 47 | + * @param string $timezone |
|
| 48 | + * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
| 49 | + * format. |
|
| 50 | + * @return EE_Message |
|
| 51 | + */ |
|
| 52 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 53 | + { |
|
| 54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 55 | + //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
| 56 | + if ( ! $has_object) { |
|
| 57 | + EE_Registry::instance()->load_helper('URL'); |
|
| 58 | + $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
| 59 | + } |
|
| 60 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param array $props_n_values |
|
| 66 | + * @param string $timezone |
|
| 67 | + * @return EE_Message |
|
| 68 | + */ |
|
| 69 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 70 | + { |
|
| 71 | + return new self($props_n_values, true, $timezone); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Gets MSG_token |
|
| 77 | + * |
|
| 78 | + * @return int |
|
| 79 | + */ |
|
| 80 | + public function MSG_token() |
|
| 81 | + { |
|
| 82 | + return $this->get('MSG_token'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Sets MSG_token |
|
| 88 | + * |
|
| 89 | + * @param int $MSG_token |
|
| 90 | + */ |
|
| 91 | + public function set_MSG_token($MSG_token) |
|
| 92 | + { |
|
| 93 | + $this->set('MSG_token', $MSG_token); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets GRP_ID |
|
| 99 | + * |
|
| 100 | + * @return int |
|
| 101 | + */ |
|
| 102 | + public function GRP_ID() |
|
| 103 | + { |
|
| 104 | + return $this->get('GRP_ID'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Sets GRP_ID |
|
| 110 | + * |
|
| 111 | + * @param int $GRP_ID |
|
| 112 | + */ |
|
| 113 | + public function set_GRP_ID($GRP_ID) |
|
| 114 | + { |
|
| 115 | + $this->set('GRP_ID', $GRP_ID); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Gets TXN_ID |
|
| 121 | + * |
|
| 122 | + * @return int |
|
| 123 | + */ |
|
| 124 | + public function TXN_ID() |
|
| 125 | + { |
|
| 126 | + return $this->get('TXN_ID'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Sets TXN_ID |
|
| 132 | + * |
|
| 133 | + * @param int $TXN_ID |
|
| 134 | + */ |
|
| 135 | + public function set_TXN_ID($TXN_ID) |
|
| 136 | + { |
|
| 137 | + $this->set('TXN_ID', $TXN_ID); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Gets messenger |
|
| 143 | + * |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function messenger() |
|
| 147 | + { |
|
| 148 | + return $this->get('MSG_messenger'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Sets messenger |
|
| 154 | + * |
|
| 155 | + * @param string $messenger |
|
| 156 | + */ |
|
| 157 | + public function set_messenger($messenger) |
|
| 158 | + { |
|
| 159 | + $this->set('MSG_messenger', $messenger); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Returns corresponding messenger object for the set messenger on this message |
|
| 165 | + * |
|
| 166 | + * @return EE_messenger | null |
|
| 167 | + */ |
|
| 168 | + public function messenger_object() |
|
| 169 | + { |
|
| 170 | + return $this->_messenger; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Sets messenger |
|
| 176 | + * |
|
| 177 | + * @param EE_messenger $messenger |
|
| 178 | + */ |
|
| 179 | + public function set_messenger_object(EE_messenger $messenger) |
|
| 180 | + { |
|
| 181 | + $this->_messenger = $messenger; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * validates messenger |
|
| 187 | + * |
|
| 188 | + * @param bool $throw_exceptions |
|
| 189 | + * @return bool |
|
| 190 | + * @throws \EE_Error |
|
| 191 | + */ |
|
| 192 | + public function valid_messenger($throw_exceptions = false) |
|
| 193 | + { |
|
| 194 | + if ($this->_messenger instanceof EE_messenger) { |
|
| 195 | + return true; |
|
| 196 | + } |
|
| 197 | + if ($throw_exceptions) { |
|
| 198 | + throw new EE_Error( |
|
| 199 | + sprintf( |
|
| 200 | + __( |
|
| 201 | + 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ), |
|
| 204 | + $this->messenger() |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * This returns the set localized label for the messenger on this message. |
|
| 214 | + * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
| 215 | + * with this message. |
|
| 216 | + * |
|
| 217 | + * @param bool $plural whether to return the plural label or not. |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public function messenger_label($plural = false) |
|
| 221 | + { |
|
| 222 | + $label_type = $plural ? 'plural' : 'singular'; |
|
| 223 | + $messenger = $this->messenger_object(); |
|
| 224 | + return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Gets message_type |
|
| 230 | + * |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + public function message_type() |
|
| 234 | + { |
|
| 235 | + return $this->get('MSG_message_type'); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Sets message_type |
|
| 241 | + * |
|
| 242 | + * @param string $message_type |
|
| 243 | + */ |
|
| 244 | + public function set_message_type($message_type) |
|
| 245 | + { |
|
| 246 | + $this->set('MSG_message_type', $message_type); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Returns the message type object for the set message type on this message |
|
| 252 | + * |
|
| 253 | + * @return EE_message_type | null |
|
| 254 | + */ |
|
| 255 | + public function message_type_object() |
|
| 256 | + { |
|
| 257 | + return $this->_message_type; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Sets message_type |
|
| 263 | + * |
|
| 264 | + * @param EE_message_type $message_type |
|
| 265 | + * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
| 266 | + * the message type or not. |
|
| 267 | + */ |
|
| 268 | + public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
| 269 | + { |
|
| 270 | + $this->_message_type = $message_type; |
|
| 271 | + if ($set_priority) { |
|
| 272 | + $this->set_priority($this->_message_type->get_priority()); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * validates message_type |
|
| 279 | + * |
|
| 280 | + * @param bool $throw_exceptions |
|
| 281 | + * @return bool |
|
| 282 | + * @throws \EE_Error |
|
| 283 | + */ |
|
| 284 | + public function valid_message_type($throw_exceptions = false) |
|
| 285 | + { |
|
| 286 | + if ($this->_message_type instanceof EE_message_type) { |
|
| 287 | + return true; |
|
| 288 | + } |
|
| 289 | + if ($throw_exceptions) { |
|
| 290 | + throw new EE_Error( |
|
| 291 | + sprintf( |
|
| 292 | + __( |
|
| 293 | + 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 294 | + 'event_espresso' |
|
| 295 | + ), |
|
| 296 | + $this->message_type() |
|
| 297 | + ) |
|
| 298 | + ); |
|
| 299 | + } |
|
| 300 | + return false; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
| 306 | + * |
|
| 307 | + * @param bool $throw_exceptions |
|
| 308 | + * @return bool |
|
| 309 | + * @throws \EE_Error |
|
| 310 | + */ |
|
| 311 | + public function is_valid($throw_exceptions = false) |
|
| 312 | + { |
|
| 313 | + if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
| 314 | + return true; |
|
| 315 | + } |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * This validates whether the internal messenger and message type objects are valid for sending. |
|
| 322 | + * Three checks are done: |
|
| 323 | + * 1. There is a valid messenger object. |
|
| 324 | + * 2. There is a valid message type object. |
|
| 325 | + * 3. The message type object is active for the messenger. |
|
| 326 | + * |
|
| 327 | + * @throws EE_Error But only if $throw_exceptions is set to true. |
|
| 328 | + * @param bool $throw_exceptions |
|
| 329 | + * @return bool |
|
| 330 | + */ |
|
| 331 | + public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
| 332 | + { |
|
| 333 | + $valid = false; |
|
| 334 | + if ($this->is_valid($throw_exceptions)) { |
|
| 335 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 336 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 337 | + $valid = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(), |
|
| 338 | + $this->message_type()); |
|
| 339 | + if ( ! $valid && $throw_exceptions) { |
|
| 340 | + throw new EE_Error( |
|
| 341 | + sprintf( |
|
| 342 | + __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
| 343 | + 'event_espresso'), |
|
| 344 | + $this->message_type(), |
|
| 345 | + $this->messenger() |
|
| 346 | + ) |
|
| 347 | + ); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + return $valid; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * This returns the set localized label for the message type on this message. |
|
| 356 | + * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
| 357 | + * with this message. |
|
| 358 | + * |
|
| 359 | + * @param bool $plural whether to return the plural label or not. |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 362 | + public function message_type_label($plural = false) |
|
| 363 | + { |
|
| 364 | + $label_type = $plural ? 'plural' : 'singular'; |
|
| 365 | + $message_type = $this->message_type_object(); |
|
| 366 | + return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace( |
|
| 367 | + '_', |
|
| 368 | + ' ', |
|
| 369 | + $this->message_type() |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Gets context |
|
| 376 | + * |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function context() |
|
| 380 | + { |
|
| 381 | + return $this->get('MSG_context'); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
| 387 | + * types. Otherwise, this will just return the set context slug on this object. |
|
| 388 | + * |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + public function context_label() |
|
| 392 | + { |
|
| 393 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 394 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 395 | + $contexts = $message_resource_manager->get_all_contexts(); |
|
| 396 | + return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Sets context |
|
| 402 | + * |
|
| 403 | + * @param string $context |
|
| 404 | + */ |
|
| 405 | + public function set_context($context) |
|
| 406 | + { |
|
| 407 | + $this->set('MSG_context', $context); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Gets recipient_ID |
|
| 413 | + * |
|
| 414 | + * @return int |
|
| 415 | + */ |
|
| 416 | + public function recipient_ID() |
|
| 417 | + { |
|
| 418 | + return $this->get('MSG_recipient_ID'); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Sets recipient_ID |
|
| 424 | + * |
|
| 425 | + * @param string $recipient_ID |
|
| 426 | + */ |
|
| 427 | + public function set_recipient_ID($recipient_ID) |
|
| 428 | + { |
|
| 429 | + $this->set('MSG_recipient_ID', $recipient_ID); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Gets recipient_type |
|
| 435 | + * |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + public function recipient_type() |
|
| 439 | + { |
|
| 440 | + return $this->get('MSG_recipient_type'); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Return the related object matching the recipient type and ID. |
|
| 446 | + * |
|
| 447 | + * @return EE_Base_Class | null |
|
| 448 | + */ |
|
| 449 | + public function recipient_object() |
|
| 450 | + { |
|
| 451 | + if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
| 452 | + return null; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + return $this->get_first_related($this->recipient_type()); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Sets recipient_type |
|
| 461 | + * |
|
| 462 | + * @param string $recipient_type |
|
| 463 | + */ |
|
| 464 | + public function set_recipient_type($recipient_type) |
|
| 465 | + { |
|
| 466 | + $this->set('MSG_recipient_type', $recipient_type); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Gets content |
|
| 472 | + * |
|
| 473 | + * @return string |
|
| 474 | + */ |
|
| 475 | + public function content() |
|
| 476 | + { |
|
| 477 | + return $this->get('MSG_content'); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Sets content |
|
| 483 | + * |
|
| 484 | + * @param string $content |
|
| 485 | + */ |
|
| 486 | + public function set_content($content) |
|
| 487 | + { |
|
| 488 | + $this->set('MSG_content', $content); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Gets subject |
|
| 494 | + * |
|
| 495 | + * @return string |
|
| 496 | + */ |
|
| 497 | + public function subject() |
|
| 498 | + { |
|
| 499 | + return $this->get('MSG_subject'); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Sets subject |
|
| 505 | + * |
|
| 506 | + * @param string $subject |
|
| 507 | + */ |
|
| 508 | + public function set_subject($subject) |
|
| 509 | + { |
|
| 510 | + $this->set('MSG_subject', $subject); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Gets to |
|
| 516 | + * |
|
| 517 | + * @return string |
|
| 518 | + */ |
|
| 519 | + public function to() |
|
| 520 | + { |
|
| 521 | + $to = $this->get('MSG_to'); |
|
| 522 | + return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Sets to |
|
| 528 | + * |
|
| 529 | + * @param string $to |
|
| 530 | + */ |
|
| 531 | + public function set_to($to) |
|
| 532 | + { |
|
| 533 | + $this->set('MSG_to', $to); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Gets from |
|
| 539 | + * |
|
| 540 | + * @return string |
|
| 541 | + */ |
|
| 542 | + public function from() |
|
| 543 | + { |
|
| 544 | + return $this->get('MSG_from'); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Sets from |
|
| 550 | + * |
|
| 551 | + * @param string $from |
|
| 552 | + */ |
|
| 553 | + public function set_from($from) |
|
| 554 | + { |
|
| 555 | + $this->set('MSG_from', $from); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Gets priority |
|
| 561 | + * |
|
| 562 | + * @return int |
|
| 563 | + */ |
|
| 564 | + public function priority() |
|
| 565 | + { |
|
| 566 | + return $this->get('MSG_priority'); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Sets priority |
|
| 572 | + * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
| 573 | + * this method calls the send_now method to verify that. |
|
| 574 | + * |
|
| 575 | + * @param int $priority |
|
| 576 | + */ |
|
| 577 | + public function set_priority($priority) |
|
| 578 | + { |
|
| 579 | + $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
| 580 | + parent::set('MSG_priority', $priority); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Overrides parent::set method so we can capture any sets for priority. |
|
| 586 | + * |
|
| 587 | + * @see parent::set() for phpdocs |
|
| 588 | + * @param string $field_name |
|
| 589 | + * @param mixed $field_value |
|
| 590 | + * @param bool $use_default |
|
| 591 | + * @throws EE_Error |
|
| 592 | + */ |
|
| 593 | + public function set($field_name, $field_value, $use_default = false) |
|
| 594 | + { |
|
| 595 | + if ($field_name === 'MSG_priority') { |
|
| 596 | + $this->set_priority($field_value); |
|
| 597 | + } |
|
| 598 | + parent::set($field_name, $field_value, $use_default); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * @return bool |
|
| 604 | + * @throws \EE_Error |
|
| 605 | + */ |
|
| 606 | + public function send_now() |
|
| 607 | + { |
|
| 608 | + $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
| 609 | + return $send_now === EEM_Message::priority_high ? true : false; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Gets STS_ID |
|
| 615 | + * |
|
| 616 | + * @return string |
|
| 617 | + */ |
|
| 618 | + public function STS_ID() |
|
| 619 | + { |
|
| 620 | + return $this->get('STS_ID'); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Sets STS_ID |
|
| 626 | + * |
|
| 627 | + * @param string $STS_ID |
|
| 628 | + */ |
|
| 629 | + public function set_STS_ID($STS_ID) |
|
| 630 | + { |
|
| 631 | + $this->set('STS_ID', $STS_ID); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Gets created |
|
| 637 | + * |
|
| 638 | + * @return string |
|
| 639 | + */ |
|
| 640 | + public function created() |
|
| 641 | + { |
|
| 642 | + return $this->get('MSG_created'); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Sets created |
|
| 648 | + * |
|
| 649 | + * @param string $created |
|
| 650 | + */ |
|
| 651 | + public function set_created($created) |
|
| 652 | + { |
|
| 653 | + $this->set('MSG_created', $created); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Gets modified |
|
| 659 | + * |
|
| 660 | + * @return string |
|
| 661 | + */ |
|
| 662 | + public function modified() |
|
| 663 | + { |
|
| 664 | + return $this->get('MSG_modified'); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Sets modified |
|
| 670 | + * |
|
| 671 | + * @param string $modified |
|
| 672 | + */ |
|
| 673 | + public function set_modified($modified) |
|
| 674 | + { |
|
| 675 | + $this->set('MSG_modified', $modified); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Sets generation data for this message. |
|
| 681 | + * |
|
| 682 | + * @param mixed $data |
|
| 683 | + */ |
|
| 684 | + public function set_generation_data($data) |
|
| 685 | + { |
|
| 686 | + $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Returns any set generation data for this message. |
|
| 692 | + * |
|
| 693 | + * @return mixed|null |
|
| 694 | + */ |
|
| 695 | + public function get_generation_data() |
|
| 696 | + { |
|
| 697 | + return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * Gets any error message. |
|
| 703 | + * |
|
| 704 | + * @return mixed|null |
|
| 705 | + */ |
|
| 706 | + public function error_message() |
|
| 707 | + { |
|
| 708 | + return $this->get_field_or_extra_meta('MSG_error'); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * Sets an error message. |
|
| 714 | + * |
|
| 715 | + * @param $message |
|
| 716 | + * @return bool|int |
|
| 717 | + */ |
|
| 718 | + public function set_error_message($message) |
|
| 719 | + { |
|
| 720 | + return $this->set_field_or_extra_meta('MSG_error', $message); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * This retrieves the associated template pack with this message. |
|
| 726 | + * |
|
| 727 | + * @return EE_Messages_Template_Pack | null |
|
| 728 | + */ |
|
| 729 | + public function get_template_pack() |
|
| 730 | + { |
|
| 731 | + /** |
|
| 732 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 733 | + */ |
|
| 734 | + if ( ! empty($this->template_pack)) { |
|
| 735 | + return $this->template_pack; |
|
| 736 | + } |
|
| 737 | + /** @type EE_Message_Template_Group $grp */ |
|
| 738 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
| 739 | + //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 740 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
| 741 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 742 | + array( |
|
| 743 | + array( |
|
| 744 | + 'MTP_messenger' => $this->messenger(), |
|
| 745 | + 'MTP_message_type' => $this->message_type(), |
|
| 746 | + 'MTP_is_global' => true, |
|
| 747 | + ), |
|
| 748 | + ) |
|
| 749 | + ); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Retrieves the variation used for generating this message. |
|
| 758 | + * |
|
| 759 | + * @return string |
|
| 760 | + */ |
|
| 761 | + public function get_template_pack_variation() |
|
| 762 | + { |
|
| 763 | + /** |
|
| 764 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 765 | + */ |
|
| 766 | + if ( ! empty($this->template_variation)) { |
|
| 767 | + return $this->template_variation; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + /** @type EE_Message_Template_Group $grp */ |
|
| 771 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
| 772 | + |
|
| 773 | + //if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 774 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
| 775 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 776 | + array( |
|
| 777 | + array( |
|
| 778 | + 'MTP_messenger' => $this->messenger(), |
|
| 779 | + 'MTP_message_type' => $this->message_type(), |
|
| 780 | + 'MTP_is_global' => true, |
|
| 781 | + ), |
|
| 782 | + ) |
|
| 783 | + ); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * Return the link to the admin details for the object. |
|
| 791 | + * |
|
| 792 | + * @return string |
|
| 793 | + */ |
|
| 794 | + public function get_admin_details_link() |
|
| 795 | + { |
|
| 796 | + EE_Registry::instance()->load_helper('URL'); |
|
| 797 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 798 | + switch ($this->STS_ID()) { |
|
| 799 | + case EEM_Message::status_failed : |
|
| 800 | + case EEM_Message::status_debug_only : |
|
| 801 | + return EEH_MSG_Template::generate_error_display_trigger($this); |
|
| 802 | + break; |
|
| 803 | + |
|
| 804 | + case EEM_Message::status_sent : |
|
| 805 | + return EEH_MSG_Template::generate_browser_trigger($this); |
|
| 806 | + break; |
|
| 807 | + |
|
| 808 | + default : |
|
| 809 | + return ''; |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 815 | + * |
|
| 816 | + * @return string |
|
| 817 | + */ |
|
| 818 | + public function get_admin_edit_link() |
|
| 819 | + { |
|
| 820 | + return $this->get_admin_details_link(); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Returns the link to a settings page for the object. |
|
| 825 | + * |
|
| 826 | + * @return string |
|
| 827 | + */ |
|
| 828 | + public function get_admin_settings_link() |
|
| 829 | + { |
|
| 830 | + EE_Registry::instance()->load_helper('URL'); |
|
| 831 | + return EEH_URL::add_query_args_and_nonce( |
|
| 832 | + array( |
|
| 833 | + 'page' => 'espresso_messages', |
|
| 834 | + 'action' => 'settings', |
|
| 835 | + ), |
|
| 836 | + admin_url('admin.php') |
|
| 837 | + ); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 842 | + * |
|
| 843 | + * @return string |
|
| 844 | + */ |
|
| 845 | + public function get_admin_overview_link() |
|
| 846 | + { |
|
| 847 | + EE_Registry::instance()->load_helper('URL'); |
|
| 848 | + return EEH_URL::add_query_args_and_nonce( |
|
| 849 | + array( |
|
| 850 | + 'page' => 'espresso_messages', |
|
| 851 | + 'action' => 'default', |
|
| 852 | + ), |
|
| 853 | + admin_url('admin.php') |
|
| 854 | + ); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
| 860 | + * it. |
|
| 861 | + * Note this also SAVES the current message object to the db because it adds an error message to accompany the status. |
|
| 862 | + * |
|
| 863 | + */ |
|
| 864 | + public function set_messenger_is_executing() |
|
| 865 | + { |
|
| 866 | + $this->set_STS_ID( EEM_Message::status_messenger_executing ); |
|
| 867 | + $this->set_error_message( |
|
| 868 | + esc_html__( |
|
| 869 | + 'A message with this status indicates that there was a problem that occurred while the message was being |
|
| 870 | 870 | processed by the messenger. It is still possible that the message was sent successfully, but at some |
| 871 | 871 | point during the processing there was a failure. This usually is indicative of a timeout issue with PHP |
| 872 | 872 | or memory limits being reached. If you see this repeatedly you may want to consider upgrading the memory |
| 873 | 873 | available to PHP on your server.', |
| 874 | - 'event_espresso' |
|
| 875 | - ) |
|
| 876 | - ); |
|
| 877 | - } |
|
| 874 | + 'event_espresso' |
|
| 875 | + ) |
|
| 876 | + ); |
|
| 877 | + } |
|
| 878 | 878 | } |
| 879 | 879 | /* End of file EE_Message.class.php */ |
| 880 | 880 | /* Location: /core/db_classes/EE_Message.class.php */ |
| 881 | 881 | \ No newline at end of file |
@@ -13,72 +13,72 @@ |
||
| 13 | 13 | trait BaseCoreAdmin |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Core method for going to an Event Espresso Admin page. |
|
| 18 | - * @param string $page |
|
| 19 | - * @param string $action |
|
| 20 | - * @param string $additional_params |
|
| 21 | - */ |
|
| 22 | - public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
| 23 | - { |
|
| 24 | - $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Core method for going to an Event Espresso Admin page. |
|
| 18 | + * @param string $page |
|
| 19 | + * @param string $action |
|
| 20 | + * @param string $additional_params |
|
| 21 | + */ |
|
| 22 | + public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
| 23 | + { |
|
| 24 | + $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
| 30 | - * @return \EventEspressoAcceptanceTester; |
|
| 31 | - */ |
|
| 32 | - protected function actor() |
|
| 33 | - { |
|
| 34 | - /** @var \EventEspressoAcceptanceTester $this */ |
|
| 35 | - return $this; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
| 30 | + * @return \EventEspressoAcceptanceTester; |
|
| 31 | + */ |
|
| 32 | + protected function actor() |
|
| 33 | + { |
|
| 34 | + /** @var \EventEspressoAcceptanceTester $this */ |
|
| 35 | + return $this; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Use this to set the per page option for a list table page. |
|
| 41 | - * Assumes you are on a page that has this field exposed. |
|
| 42 | - * |
|
| 43 | - * @param int|string $per_page_value |
|
| 44 | - * @throws \Codeception\Exception\TestRuntimeException |
|
| 45 | - */ |
|
| 46 | - public function setPerPageOptionForScreen($per_page_value) |
|
| 47 | - { |
|
| 48 | - $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
| 49 | - $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
| 50 | - $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
| 51 | - $this->actor()->wait(8); |
|
| 52 | - } |
|
| 39 | + /** |
|
| 40 | + * Use this to set the per page option for a list table page. |
|
| 41 | + * Assumes you are on a page that has this field exposed. |
|
| 42 | + * |
|
| 43 | + * @param int|string $per_page_value |
|
| 44 | + * @throws \Codeception\Exception\TestRuntimeException |
|
| 45 | + */ |
|
| 46 | + public function setPerPageOptionForScreen($per_page_value) |
|
| 47 | + { |
|
| 48 | + $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
| 49 | + $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
| 50 | + $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
| 51 | + $this->actor()->wait(8); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Use this to append a given value to a wpEditor instance. |
|
| 58 | - * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
| 59 | - * the value is added to the text area. |
|
| 60 | - * |
|
| 61 | - * @param $field_reference |
|
| 62 | - * @param $value |
|
| 63 | - * @throws \Codeception\Exception\ElementNotFound |
|
| 64 | - */ |
|
| 65 | - public function appendToWPEditorField($field_reference, $value) |
|
| 66 | - { |
|
| 67 | - $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
| 68 | - $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
| 69 | - } |
|
| 56 | + /** |
|
| 57 | + * Use this to append a given value to a wpEditor instance. |
|
| 58 | + * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
| 59 | + * the value is added to the text area. |
|
| 60 | + * |
|
| 61 | + * @param $field_reference |
|
| 62 | + * @param $value |
|
| 63 | + * @throws \Codeception\Exception\ElementNotFound |
|
| 64 | + */ |
|
| 65 | + public function appendToWPEditorField($field_reference, $value) |
|
| 66 | + { |
|
| 67 | + $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
| 68 | + $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Use to select and submit the given bulk action. |
|
| 74 | - * @param string $bulk_action_option |
|
| 75 | - */ |
|
| 76 | - public function submitBulkActionOnListTable($bulk_action_option) |
|
| 77 | - { |
|
| 78 | - $this->actor()->selectOption( |
|
| 79 | - CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
| 80 | - $bulk_action_option |
|
| 81 | - ); |
|
| 82 | - $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
| 83 | - } |
|
| 72 | + /** |
|
| 73 | + * Use to select and submit the given bulk action. |
|
| 74 | + * @param string $bulk_action_option |
|
| 75 | + */ |
|
| 76 | + public function submitBulkActionOnListTable($bulk_action_option) |
|
| 77 | + { |
|
| 78 | + $this->actor()->selectOption( |
|
| 79 | + CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
| 80 | + $bulk_action_option |
|
| 81 | + ); |
|
| 82 | + $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -13,30 +13,30 @@ |
||
| 13 | 13 | trait RegistrationsAdmin |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * This will select all checkboxes on a registration list table for the given array of |
|
| 18 | - * registration ids. |
|
| 19 | - * Assumes the actor is on a list table page for registrations. |
|
| 20 | - * @param $registration_ids |
|
| 21 | - */ |
|
| 22 | - public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
| 23 | - { |
|
| 24 | - foreach ($registration_ids as $registration_id) { |
|
| 25 | - $this->actor()->checkOption( |
|
| 26 | - RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
| 27 | - ); |
|
| 28 | - } |
|
| 29 | - } |
|
| 16 | + /** |
|
| 17 | + * This will select all checkboxes on a registration list table for the given array of |
|
| 18 | + * registration ids. |
|
| 19 | + * Assumes the actor is on a list table page for registrations. |
|
| 20 | + * @param $registration_ids |
|
| 21 | + */ |
|
| 22 | + public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids) |
|
| 23 | + { |
|
| 24 | + foreach ($registration_ids as $registration_id) { |
|
| 25 | + $this->actor()->checkOption( |
|
| 26 | + RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
| 27 | + ); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Navigates the actor to the default registration list table page. |
|
| 34 | - * @param string $additional_params |
|
| 35 | - */ |
|
| 36 | - public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
| 37 | - { |
|
| 38 | - $this->actor()->amOnAdminPage( |
|
| 39 | - RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
| 40 | - ); |
|
| 41 | - } |
|
| 32 | + /** |
|
| 33 | + * Navigates the actor to the default registration list table page. |
|
| 34 | + * @param string $additional_params |
|
| 35 | + */ |
|
| 36 | + public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '') |
|
| 37 | + { |
|
| 38 | + $this->actor()->amOnAdminPage( |
|
| 39 | + RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params) |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -13,70 +13,70 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | trait Checkout |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @param $value |
|
| 18 | - * @param int $attendee_number |
|
| 19 | - */ |
|
| 20 | - public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
| 21 | - { |
|
| 22 | - $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * @param $value |
|
| 18 | + * @param int $attendee_number |
|
| 19 | + */ |
|
| 20 | + public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1) |
|
| 21 | + { |
|
| 22 | + $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param $value |
|
| 27 | - * @param int $attendee_number |
|
| 28 | - */ |
|
| 29 | - public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
| 30 | - { |
|
| 31 | - $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param $value |
|
| 27 | + * @param int $attendee_number |
|
| 28 | + */ |
|
| 29 | + public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1) |
|
| 30 | + { |
|
| 31 | + $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param $value |
|
| 36 | - * @param int $attendee_number |
|
| 37 | - */ |
|
| 38 | - public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
| 39 | - { |
|
| 40 | - $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * @param $value |
|
| 36 | + * @param int $attendee_number |
|
| 37 | + */ |
|
| 38 | + public function fillOutEmailFieldForAttendee($value, $attendee_number = 1) |
|
| 39 | + { |
|
| 40 | + $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Clicks the next registration step button. |
|
| 46 | - */ |
|
| 47 | - public function goToNextRegistrationStep() |
|
| 48 | - { |
|
| 49 | - $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
| 50 | - } |
|
| 44 | + /** |
|
| 45 | + * Clicks the next registration step button. |
|
| 46 | + */ |
|
| 47 | + public function goToNextRegistrationStep() |
|
| 48 | + { |
|
| 49 | + $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Selects the payment option for the given payment method slug. |
|
| 55 | - * |
|
| 56 | - * @param string $payment_method_slug |
|
| 57 | - * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
| 58 | - * payment option select box is complete. Otherwise its up to calling code to |
|
| 59 | - * wait for whatever is needed after selecting the payment method. |
|
| 60 | - */ |
|
| 61 | - public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
| 62 | - { |
|
| 63 | - $this->actor()->selectOption( |
|
| 64 | - CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
| 65 | - $payment_method_slug |
|
| 66 | - ); |
|
| 67 | - if ($verify_selected) { |
|
| 68 | - $this->actor()->waitForText('Important information regarding your payment'); |
|
| 69 | - } |
|
| 70 | - } |
|
| 53 | + /** |
|
| 54 | + * Selects the payment option for the given payment method slug. |
|
| 55 | + * |
|
| 56 | + * @param string $payment_method_slug |
|
| 57 | + * @param bool $verify_selected If true, this will wait for the "Important Information" info box after the |
|
| 58 | + * payment option select box is complete. Otherwise its up to calling code to |
|
| 59 | + * wait for whatever is needed after selecting the payment method. |
|
| 60 | + */ |
|
| 61 | + public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true) |
|
| 62 | + { |
|
| 63 | + $this->actor()->selectOption( |
|
| 64 | + CheckoutPage::PAYMENT_METHOD_STEP_FORM, |
|
| 65 | + $payment_method_slug |
|
| 66 | + ); |
|
| 67 | + if ($verify_selected) { |
|
| 68 | + $this->actor()->waitForText('Important information regarding your payment'); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Submits the payment options step form. |
|
| 75 | - * Assumes the actor is in the context of the payment options SPCO step. |
|
| 76 | - */ |
|
| 77 | - public function submitPaymentOptionsRegistrationStepForm() |
|
| 78 | - { |
|
| 79 | - $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
| 80 | - } |
|
| 73 | + /** |
|
| 74 | + * Submits the payment options step form. |
|
| 75 | + * Assumes the actor is in the context of the payment options SPCO step. |
|
| 76 | + */ |
|
| 77 | + public function submitPaymentOptionsRegistrationStepForm() |
|
| 78 | + { |
|
| 79 | + $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array()); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -10,288 +10,288 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | trait MessagesAdmin |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 15 | - * a string. |
|
| 16 | - */ |
|
| 17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
| 18 | - { |
|
| 19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 24 | - * a string. |
|
| 25 | - */ |
|
| 26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
| 27 | - { |
|
| 28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 34 | - * a string. |
|
| 35 | - */ |
|
| 36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
| 37 | - { |
|
| 38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Directs to message settings page |
|
| 44 | - */ |
|
| 45 | - public function amOnMessageSettingsPage() |
|
| 46 | - { |
|
| 47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
| 52 | - { |
|
| 53 | - $this->actor()->dragAndDrop( |
|
| 54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
| 55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
| 62 | - * @param string $message_type_slug |
|
| 63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
| 64 | - */ |
|
| 65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
| 66 | - { |
|
| 67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
| 73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
| 74 | - * |
|
| 75 | - * @param int $expected_occurence_count |
|
| 76 | - * @param string $text_to_check_for |
|
| 77 | - * @param string $field |
|
| 78 | - * @param string $message_type_label |
|
| 79 | - * @param string $message_status |
|
| 80 | - * @param string $messenger |
|
| 81 | - * @param string $context |
|
| 82 | - */ |
|
| 83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
| 84 | - $expected_occurence_count, |
|
| 85 | - $text_to_check_for, |
|
| 86 | - $field, |
|
| 87 | - $message_type_label, |
|
| 88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 89 | - $messenger = 'Email', |
|
| 90 | - $context = 'Event Admin' |
|
| 91 | - ) { |
|
| 92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 93 | - $field, |
|
| 94 | - $message_type_label, |
|
| 95 | - $message_status, |
|
| 96 | - $messenger, |
|
| 97 | - $context, |
|
| 98 | - $text_to_check_for, |
|
| 99 | - 0 |
|
| 100 | - )); |
|
| 101 | - $actual_count = count($elements); |
|
| 102 | - $this->actor()->assertEquals( |
|
| 103 | - $expected_occurence_count, |
|
| 104 | - $actual_count, |
|
| 105 | - sprintf( |
|
| 106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
| 107 | - $expected_occurence_count, |
|
| 108 | - $text_to_check_for, |
|
| 109 | - $field, |
|
| 110 | - $actual_count |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
| 118 | - * default (global) message template list table. |
|
| 119 | - * Also takes care of verifying the template was created. |
|
| 120 | - * @param string $message_type_label |
|
| 121 | - * @param string $messenger_label |
|
| 122 | - */ |
|
| 123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
| 124 | - { |
|
| 125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
| 126 | - $this->actor()->click( |
|
| 127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
| 128 | - $message_type_label, |
|
| 129 | - $messenger_label |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * This switches the context of the current messages template to the given reference. |
|
| 138 | - * @param string $context_reference This should be the visible label for the option. |
|
| 139 | - */ |
|
| 140 | - public function switchContextTo($context_reference) |
|
| 141 | - { |
|
| 142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
| 143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
| 144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
| 150 | - * toggling. |
|
| 151 | - * |
|
| 152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
| 153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
| 154 | - * (false) |
|
| 155 | - */ |
|
| 156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
| 157 | - { |
|
| 158 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
| 159 | - if ($expected_state_is_active) { |
|
| 160 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
| 161 | - } else { |
|
| 162 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Triggers saving the message template. |
|
| 169 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
| 170 | - */ |
|
| 171 | - public function saveMessageTemplate($and_close = false) |
|
| 172 | - { |
|
| 173 | - if ($and_close) { |
|
| 174 | - $this->actor()->click('Save and Close'); |
|
| 175 | - } else { |
|
| 176 | - $this->actor()->click('Save'); |
|
| 177 | - } |
|
| 178 | - $this->actor()->waitForText('successfully updated'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * This takes care of clicking the View Message icon for the given parameters. |
|
| 184 | - * Assumes you are already viewing the messages activity list table. |
|
| 185 | - * @param $message_type_label |
|
| 186 | - * @param $message_status |
|
| 187 | - * @param string $messenger |
|
| 188 | - * @param string $context |
|
| 189 | - * @param int $number_in_set |
|
| 190 | - */ |
|
| 191 | - public function viewMessageInMessagesListTableFor( |
|
| 192 | - $message_type_label, |
|
| 193 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 194 | - $messenger = 'Email', |
|
| 195 | - $context = 'Event Admin', |
|
| 196 | - $number_in_set = 1 |
|
| 197 | - ) { |
|
| 198 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
| 199 | - $message_type_label, |
|
| 200 | - $message_status, |
|
| 201 | - $messenger, |
|
| 202 | - $context, |
|
| 203 | - $number_in_set |
|
| 204 | - )); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
| 210 | - * Assumes you are already viewing the messages activity list table. |
|
| 211 | - * @param $message_type_label |
|
| 212 | - * @param $message_status |
|
| 213 | - * @param string $messenger |
|
| 214 | - * @param string $context |
|
| 215 | - * @param int $number_in_set |
|
| 216 | - */ |
|
| 217 | - public function deleteMessageInMessagesListTableFor( |
|
| 218 | - $message_type_label, |
|
| 219 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 220 | - $messenger = 'Email', |
|
| 221 | - $context = 'Event Admin', |
|
| 222 | - $number_in_set = 1 |
|
| 223 | - ) { |
|
| 224 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
| 225 | - $message_type_label, |
|
| 226 | - $message_status, |
|
| 227 | - $messenger, |
|
| 228 | - $context, |
|
| 229 | - $number_in_set |
|
| 230 | - ); |
|
| 231 | - $this->actor()->moveMouseOver( |
|
| 232 | - MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 233 | - 'to', |
|
| 234 | - $message_type_label, |
|
| 235 | - $message_status, |
|
| 236 | - $messenger, |
|
| 237 | - $context, |
|
| 238 | - '', |
|
| 239 | - $number_in_set |
|
| 240 | - ), |
|
| 241 | - 5, |
|
| 242 | - 5 |
|
| 243 | - ); |
|
| 244 | - $this->actor()->waitForElementVisible( |
|
| 245 | - $delete_action_selector |
|
| 246 | - ); |
|
| 247 | - $this->actor()->click( |
|
| 248 | - $delete_action_selector |
|
| 249 | - ); |
|
| 250 | - $this->actor()->waitForText('successfully deleted'); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 256 | - * list table, this will take care of validating the given text is in that window. |
|
| 257 | - * @param string $text_to_view |
|
| 258 | - */ |
|
| 259 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
| 260 | - { |
|
| 261 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 262 | - $this->actor()->switchToIframe('message-view-window'); |
|
| 263 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
| 264 | - $this->actor()->switchToIframe(); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * This returns the value for the link at the given selector in the message modal. |
|
| 270 | - * @param string $selector (any selector string accepted by WebDriver) |
|
| 271 | - */ |
|
| 272 | - public function observeLinkAtInMessageModal($selector) |
|
| 273 | - { |
|
| 274 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 275 | - $this->actor()->switchToIframe('message-view-window'); |
|
| 276 | - return $this->actor()->observeLinkUrlAt($selector); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 282 | - * list table, this will take care of validating the given text is NOT that window. |
|
| 283 | - * @param string $text_to_view |
|
| 284 | - */ |
|
| 285 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
| 286 | - { |
|
| 287 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - public function dismissMessageModal() |
|
| 292 | - { |
|
| 293 | - $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
| 294 | - //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
| 295 | - $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
| 296 | - } |
|
| 13 | + /** |
|
| 14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 15 | + * a string. |
|
| 16 | + */ |
|
| 17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
| 18 | + { |
|
| 19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 24 | + * a string. |
|
| 25 | + */ |
|
| 26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
| 27 | + { |
|
| 28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 34 | + * a string. |
|
| 35 | + */ |
|
| 36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
| 37 | + { |
|
| 38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Directs to message settings page |
|
| 44 | + */ |
|
| 45 | + public function amOnMessageSettingsPage() |
|
| 46 | + { |
|
| 47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
| 52 | + { |
|
| 53 | + $this->actor()->dragAndDrop( |
|
| 54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
| 55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
| 62 | + * @param string $message_type_slug |
|
| 63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
| 64 | + */ |
|
| 65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
| 66 | + { |
|
| 67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
| 73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
| 74 | + * |
|
| 75 | + * @param int $expected_occurence_count |
|
| 76 | + * @param string $text_to_check_for |
|
| 77 | + * @param string $field |
|
| 78 | + * @param string $message_type_label |
|
| 79 | + * @param string $message_status |
|
| 80 | + * @param string $messenger |
|
| 81 | + * @param string $context |
|
| 82 | + */ |
|
| 83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
| 84 | + $expected_occurence_count, |
|
| 85 | + $text_to_check_for, |
|
| 86 | + $field, |
|
| 87 | + $message_type_label, |
|
| 88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 89 | + $messenger = 'Email', |
|
| 90 | + $context = 'Event Admin' |
|
| 91 | + ) { |
|
| 92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 93 | + $field, |
|
| 94 | + $message_type_label, |
|
| 95 | + $message_status, |
|
| 96 | + $messenger, |
|
| 97 | + $context, |
|
| 98 | + $text_to_check_for, |
|
| 99 | + 0 |
|
| 100 | + )); |
|
| 101 | + $actual_count = count($elements); |
|
| 102 | + $this->actor()->assertEquals( |
|
| 103 | + $expected_occurence_count, |
|
| 104 | + $actual_count, |
|
| 105 | + sprintf( |
|
| 106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
| 107 | + $expected_occurence_count, |
|
| 108 | + $text_to_check_for, |
|
| 109 | + $field, |
|
| 110 | + $actual_count |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
| 118 | + * default (global) message template list table. |
|
| 119 | + * Also takes care of verifying the template was created. |
|
| 120 | + * @param string $message_type_label |
|
| 121 | + * @param string $messenger_label |
|
| 122 | + */ |
|
| 123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
| 124 | + { |
|
| 125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
| 126 | + $this->actor()->click( |
|
| 127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
| 128 | + $message_type_label, |
|
| 129 | + $messenger_label |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * This switches the context of the current messages template to the given reference. |
|
| 138 | + * @param string $context_reference This should be the visible label for the option. |
|
| 139 | + */ |
|
| 140 | + public function switchContextTo($context_reference) |
|
| 141 | + { |
|
| 142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
| 143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
| 144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
| 150 | + * toggling. |
|
| 151 | + * |
|
| 152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
| 153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
| 154 | + * (false) |
|
| 155 | + */ |
|
| 156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
| 157 | + { |
|
| 158 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
| 159 | + if ($expected_state_is_active) { |
|
| 160 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
| 161 | + } else { |
|
| 162 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Triggers saving the message template. |
|
| 169 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
| 170 | + */ |
|
| 171 | + public function saveMessageTemplate($and_close = false) |
|
| 172 | + { |
|
| 173 | + if ($and_close) { |
|
| 174 | + $this->actor()->click('Save and Close'); |
|
| 175 | + } else { |
|
| 176 | + $this->actor()->click('Save'); |
|
| 177 | + } |
|
| 178 | + $this->actor()->waitForText('successfully updated'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * This takes care of clicking the View Message icon for the given parameters. |
|
| 184 | + * Assumes you are already viewing the messages activity list table. |
|
| 185 | + * @param $message_type_label |
|
| 186 | + * @param $message_status |
|
| 187 | + * @param string $messenger |
|
| 188 | + * @param string $context |
|
| 189 | + * @param int $number_in_set |
|
| 190 | + */ |
|
| 191 | + public function viewMessageInMessagesListTableFor( |
|
| 192 | + $message_type_label, |
|
| 193 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 194 | + $messenger = 'Email', |
|
| 195 | + $context = 'Event Admin', |
|
| 196 | + $number_in_set = 1 |
|
| 197 | + ) { |
|
| 198 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
| 199 | + $message_type_label, |
|
| 200 | + $message_status, |
|
| 201 | + $messenger, |
|
| 202 | + $context, |
|
| 203 | + $number_in_set |
|
| 204 | + )); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
| 210 | + * Assumes you are already viewing the messages activity list table. |
|
| 211 | + * @param $message_type_label |
|
| 212 | + * @param $message_status |
|
| 213 | + * @param string $messenger |
|
| 214 | + * @param string $context |
|
| 215 | + * @param int $number_in_set |
|
| 216 | + */ |
|
| 217 | + public function deleteMessageInMessagesListTableFor( |
|
| 218 | + $message_type_label, |
|
| 219 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 220 | + $messenger = 'Email', |
|
| 221 | + $context = 'Event Admin', |
|
| 222 | + $number_in_set = 1 |
|
| 223 | + ) { |
|
| 224 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
| 225 | + $message_type_label, |
|
| 226 | + $message_status, |
|
| 227 | + $messenger, |
|
| 228 | + $context, |
|
| 229 | + $number_in_set |
|
| 230 | + ); |
|
| 231 | + $this->actor()->moveMouseOver( |
|
| 232 | + MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 233 | + 'to', |
|
| 234 | + $message_type_label, |
|
| 235 | + $message_status, |
|
| 236 | + $messenger, |
|
| 237 | + $context, |
|
| 238 | + '', |
|
| 239 | + $number_in_set |
|
| 240 | + ), |
|
| 241 | + 5, |
|
| 242 | + 5 |
|
| 243 | + ); |
|
| 244 | + $this->actor()->waitForElementVisible( |
|
| 245 | + $delete_action_selector |
|
| 246 | + ); |
|
| 247 | + $this->actor()->click( |
|
| 248 | + $delete_action_selector |
|
| 249 | + ); |
|
| 250 | + $this->actor()->waitForText('successfully deleted'); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 256 | + * list table, this will take care of validating the given text is in that window. |
|
| 257 | + * @param string $text_to_view |
|
| 258 | + */ |
|
| 259 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
| 260 | + { |
|
| 261 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 262 | + $this->actor()->switchToIframe('message-view-window'); |
|
| 263 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
| 264 | + $this->actor()->switchToIframe(); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * This returns the value for the link at the given selector in the message modal. |
|
| 270 | + * @param string $selector (any selector string accepted by WebDriver) |
|
| 271 | + */ |
|
| 272 | + public function observeLinkAtInMessageModal($selector) |
|
| 273 | + { |
|
| 274 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 275 | + $this->actor()->switchToIframe('message-view-window'); |
|
| 276 | + return $this->actor()->observeLinkUrlAt($selector); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 282 | + * list table, this will take care of validating the given text is NOT that window. |
|
| 283 | + * @param string $text_to_view |
|
| 284 | + */ |
|
| 285 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
| 286 | + { |
|
| 287 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + public function dismissMessageModal() |
|
| 292 | + { |
|
| 293 | + $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
| 294 | + //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
| 295 | + $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
| 296 | + } |
|
| 297 | 297 | } |
@@ -13,96 +13,96 @@ |
||
| 13 | 13 | class CoreAdmin |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - const URL_PREFIX = 'admin.php?page='; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * This is the selector for the next page button on list tables. |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * The selector for the search input submit button on list table pages |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Selector for the screen options dropdown. |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Selector for the per page field setting selector (found within screen options dropdown) |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Selector for apply screen options settings. |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Selector for bulk action select field on list tables. |
|
| 59 | - */ |
|
| 60 | - const SELECTOR_LIST_TABLE_BULK_ACTION_FIELD = '#bulk-action-selector-'; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Selector for applying a bulk action. |
|
| 65 | - */ |
|
| 66 | - const SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY = '#doaction'; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get the EE admin url for the given properties. |
|
| 71 | - * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
| 72 | - * with `amOnAdminPage` action. |
|
| 73 | - * |
|
| 74 | - * @param string $page |
|
| 75 | - * @param string $action |
|
| 76 | - * @param string $additional_params |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
| 80 | - { |
|
| 81 | - $url = self::URL_PREFIX . $page; |
|
| 82 | - $url .= $action ? '&action=' . $action : ''; |
|
| 83 | - $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
| 84 | - return $url; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the selector for the text tab switcher for a wp-editor instance. |
|
| 90 | - * @param $field_reference |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public static function wpEditorTextTabSelector($field_reference) |
|
| 94 | - { |
|
| 95 | - return '#content-' . $field_reference . '-content-html'; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance. |
|
| 101 | - * @param $field_reference |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public static function wpEditorTextAreaSelector($field_reference) |
|
| 105 | - { |
|
| 106 | - return '#content-' . $field_reference . '-content'; |
|
| 107 | - } |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + const URL_PREFIX = 'admin.php?page='; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * This is the selector for the next page button on list tables. |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * The selector for the search input submit button on list table pages |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Selector for the screen options dropdown. |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Selector for the per page field setting selector (found within screen options dropdown) |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Selector for apply screen options settings. |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Selector for bulk action select field on list tables. |
|
| 59 | + */ |
|
| 60 | + const SELECTOR_LIST_TABLE_BULK_ACTION_FIELD = '#bulk-action-selector-'; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Selector for applying a bulk action. |
|
| 65 | + */ |
|
| 66 | + const SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY = '#doaction'; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get the EE admin url for the given properties. |
|
| 71 | + * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
| 72 | + * with `amOnAdminPage` action. |
|
| 73 | + * |
|
| 74 | + * @param string $page |
|
| 75 | + * @param string $action |
|
| 76 | + * @param string $additional_params |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
| 80 | + { |
|
| 81 | + $url = self::URL_PREFIX . $page; |
|
| 82 | + $url .= $action ? '&action=' . $action : ''; |
|
| 83 | + $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
| 84 | + return $url; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the selector for the text tab switcher for a wp-editor instance. |
|
| 90 | + * @param $field_reference |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public static function wpEditorTextTabSelector($field_reference) |
|
| 94 | + { |
|
| 95 | + return '#content-' . $field_reference . '-content-html'; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Returns the selector for the textarea exposed when clicing the text tab switcher for a wp-editor instance. |
|
| 101 | + * @param $field_reference |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public static function wpEditorTextAreaSelector($field_reference) |
|
| 105 | + { |
|
| 106 | + return '#content-' . $field_reference . '-content'; |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -11,43 +11,43 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class RegistrationsAdmin extends CoreAdmin |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - const REGISTRATION_STATUS_NOT_APPROVED = 'RNA'; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + const REGISTRATION_STATUS_NOT_APPROVED = 'RNA'; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - const REGISTRATION_STATUS_APPROVED = 'RAP'; |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + const REGISTRATION_STATUS_APPROVED = 'RAP'; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - const REGISTRATION_STATUS_PENDING_PAYMENT = 'RPP'; |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + const REGISTRATION_STATUS_PENDING_PAYMENT = 'RPP'; |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param string $additional_params |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public static function registrationsDefaultAdminListTableUrl($additional_params = '') |
|
| 38 | - { |
|
| 39 | - return self::adminUrl('espresso_registrations', 'default', $additional_params); |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * @param string $additional_params |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public static function registrationsDefaultAdminListTableUrl($additional_params = '') |
|
| 38 | + { |
|
| 39 | + return self::adminUrl('espresso_registrations', 'default', $additional_params); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Given a registration id, this will return the selector for all the checkbox for that id. |
|
| 45 | - * Assumes the view is a Registration list table. |
|
| 46 | - * @param int $registration_id |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public static function listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
| 50 | - { |
|
| 51 | - return "//input[@name='_REG_ID[]' and @value='{$registration_id}']"; |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * Given a registration id, this will return the selector for all the checkbox for that id. |
|
| 45 | + * Assumes the view is a Registration list table. |
|
| 46 | + * @param int $registration_id |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public static function listTableCheckBoxSelectorForRegistrationId($registration_id) |
|
| 50 | + { |
|
| 51 | + return "//input[@name='_REG_ID[]' and @value='{$registration_id}']"; |
|
| 52 | + } |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -14,267 +14,267 @@ |
||
| 14 | 14 | class EventsAdmin extends CoreAdmin |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Selector for the Add new Event button in the admin. |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Selector for the Event Title field in the event editor |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Selector for the publish submit button in the event editor. |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Selector for the save button in the event editor |
|
| 39 | - */ |
|
| 40 | - const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = "#save-post"; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Selector for the view link after publishing an event. |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a"; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Selector for the ID of the event in the event editor |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Selector for the search input on the event list table page. |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param string $additional_params |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
| 76 | - { |
|
| 77 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * The selector for the DTTname field for the given row in the event editor. |
|
| 83 | - * @param int $row_number |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
| 87 | - { |
|
| 88 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
| 94 | - * @param int $row_number |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
| 98 | - { |
|
| 99 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
| 105 | - * |
|
| 106 | - * @param string $field_name |
|
| 107 | - * @param int $row_number |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
| 111 | - { |
|
| 112 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
| 118 | - * @param int $row_number |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
| 122 | - { |
|
| 123 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Selector for the TKT_base_price field for the given display row in the event editor. |
|
| 129 | - * @param int $row_number |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
| 133 | - { |
|
| 134 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Selector for the TKT_qty field for the given display row in the event editor. |
|
| 140 | - * @param int $row_number |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public static function eventEditorTicketQuantityFieldSelector($row_number = 1) |
|
| 144 | - { |
|
| 145 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_qty', $row_number); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Selector for the advanced details toggle for the ticket for the given display row in the event editor. |
|
| 151 | - * @param int $row_number |
|
| 152 | - * @return string |
|
| 153 | - */ |
|
| 154 | - public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
| 155 | - { |
|
| 156 | - return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Selector for the subtotal amount for the given display row of the ticket in the event editor. |
|
| 162 | - * @param int $row_number |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
| 166 | - { |
|
| 167 | - return "//span[@id='price-total-amount-$row_number']"; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Selector for the Total element for the given display row of the ticket in the event editor. |
|
| 173 | - * @param int $row_number |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
| 177 | - { |
|
| 178 | - return "//span[@id='price-total-amount-$row_number']"; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Selector for the taxable selector for the ticket for the given display row in the event editor. |
|
| 184 | - * @param int $row_number |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
| 188 | - { |
|
| 189 | - return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
| 195 | - * given ticket (row) and the given tax id (PRC_ID). |
|
| 196 | - * |
|
| 197 | - * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
| 198 | - * setup on a fresh install. |
|
| 199 | - * @param int $row_number What row representing the ticket you want the locator for. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
| 203 | - { |
|
| 204 | - return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
| 210 | - * @param $field_name |
|
| 211 | - * @param int $row_number |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
| 215 | - { |
|
| 216 | - return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
| 222 | - * @param string $event_title |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
| 226 | - { |
|
| 227 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Locator for for the ID column in the event list table for a given event title. |
|
| 233 | - * @param string $event_title |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
| 237 | - { |
|
| 238 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 239 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Locator for the view link in the row of an event list table for the given event title. |
|
| 245 | - * @param string $event_title |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
| 249 | - { |
|
| 250 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 251 | - . "//ancestor::td//span[@class='view']/a"; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
| 257 | - * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
| 261 | - { |
|
| 262 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 263 | - . "//a[@rel='ee-tab-$messenger_slug']"; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Locator for the select input within the notifications metabox. |
|
| 269 | - * Note, this assumes the tab content for the related messenger is already visible. |
|
| 270 | - * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
| 274 | - { |
|
| 275 | - return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 276 | - . "//table[@class='messages-custom-template-switcher']" |
|
| 277 | - . "//tr/td[contains(.,'Registration Approved')]" |
|
| 278 | - . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
| 279 | - } |
|
| 17 | + /** |
|
| 18 | + * Selector for the Add new Event button in the admin. |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Selector for the Event Title field in the event editor |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Selector for the publish submit button in the event editor. |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Selector for the save button in the event editor |
|
| 39 | + */ |
|
| 40 | + const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = "#save-post"; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Selector for the view link after publishing an event. |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a"; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Selector for the ID of the event in the event editor |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Selector for the search input on the event list table page. |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param string $additional_params |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
| 76 | + { |
|
| 77 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * The selector for the DTTname field for the given row in the event editor. |
|
| 83 | + * @param int $row_number |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
| 87 | + { |
|
| 88 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
| 94 | + * @param int $row_number |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
| 98 | + { |
|
| 99 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
| 105 | + * |
|
| 106 | + * @param string $field_name |
|
| 107 | + * @param int $row_number |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
| 111 | + { |
|
| 112 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
| 118 | + * @param int $row_number |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
| 122 | + { |
|
| 123 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Selector for the TKT_base_price field for the given display row in the event editor. |
|
| 129 | + * @param int $row_number |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public static function eventEditorTicketPriceFieldSelector($row_number = 1) |
|
| 133 | + { |
|
| 134 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Selector for the TKT_qty field for the given display row in the event editor. |
|
| 140 | + * @param int $row_number |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public static function eventEditorTicketQuantityFieldSelector($row_number = 1) |
|
| 144 | + { |
|
| 145 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_qty', $row_number); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Selector for the advanced details toggle for the ticket for the given display row in the event editor. |
|
| 151 | + * @param int $row_number |
|
| 152 | + * @return string |
|
| 153 | + */ |
|
| 154 | + public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1) |
|
| 155 | + { |
|
| 156 | + return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]"; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Selector for the subtotal amount for the given display row of the ticket in the event editor. |
|
| 162 | + * @param int $row_number |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1) |
|
| 166 | + { |
|
| 167 | + return "//span[@id='price-total-amount-$row_number']"; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Selector for the Total element for the given display row of the ticket in the event editor. |
|
| 173 | + * @param int $row_number |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1) |
|
| 177 | + { |
|
| 178 | + return "//span[@id='price-total-amount-$row_number']"; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Selector for the taxable selector for the ticket for the given display row in the event editor. |
|
| 184 | + * @param int $row_number |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1) |
|
| 188 | + { |
|
| 189 | + return "//input[@id='edit-ticket-TKT_taxable-$row_number']"; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * This returns the xpath locater for the Tax amount display container within the advanced settings view for the |
|
| 195 | + * given ticket (row) and the given tax id (PRC_ID). |
|
| 196 | + * |
|
| 197 | + * @param int $tax_id The PRC_ID for the tax you want the locater for. Note, this defaults to the default tax |
|
| 198 | + * setup on a fresh install. |
|
| 199 | + * @param int $row_number What row representing the ticket you want the locator for. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1) |
|
| 203 | + { |
|
| 204 | + return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']"; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
| 210 | + * @param $field_name |
|
| 211 | + * @param int $row_number |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
| 215 | + { |
|
| 216 | + return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]"; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
| 222 | + * @param string $event_title |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
| 226 | + { |
|
| 227 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Locator for for the ID column in the event list table for a given event title. |
|
| 233 | + * @param string $event_title |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
| 237 | + { |
|
| 238 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 239 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Locator for the view link in the row of an event list table for the given event title. |
|
| 245 | + * @param string $event_title |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
| 249 | + { |
|
| 250 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
| 251 | + . "//ancestor::td//span[@class='view']/a"; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Locator for the messenger tab in the Notifications metabox in the event editor. |
|
| 257 | + * @param string $messenger_slug The slug for the messenger (it's reference slug). |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug) |
|
| 261 | + { |
|
| 262 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 263 | + . "//a[@rel='ee-tab-$messenger_slug']"; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Locator for the select input within the notifications metabox. |
|
| 269 | + * Note, this assumes the tab content for the related messenger is already visible. |
|
| 270 | + * @param string $message_type_label The message type label (visible string in the table) you want the selector for. |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label) |
|
| 274 | + { |
|
| 275 | + return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']" |
|
| 276 | + . "//table[@class='messages-custom-template-switcher']" |
|
| 277 | + . "//tr/td[contains(.,'Registration Approved')]" |
|
| 278 | + . "//ancestor::tr//select[contains(@class,'message-template-selector')]"; |
|
| 279 | + } |
|
| 280 | 280 | } |