@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
| 3 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
| 4 | 3 | |
| 5 | 4 | if (!defined('EVENT_ESPRESSO_VERSION') ) |
| 6 | 5 | exit('NO direct script access allowed'); |
@@ -2,8 +2,9 @@ |
||
| 2 | 2 | use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
| 3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 4 | 4 | |
| 5 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 5 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
| 6 | 6 | exit('NO direct script access allowed'); |
| 7 | +} |
|
| 7 | 8 | |
| 8 | 9 | |
| 9 | 10 | |
@@ -28,748 +28,748 @@ |
||
| 28 | 28 | class EE_Admin_Page_Loader |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * _installed_pages |
|
| 33 | - * objects for page_init objects detected and loaded |
|
| 34 | - * |
|
| 35 | - * @access private |
|
| 36 | - * @var \EE_Admin_Page_Init[] |
|
| 37 | - */ |
|
| 38 | - private $_installed_pages = array(); |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private $_menu_slugs = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * _caffeinated_extends |
|
| 52 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
| 53 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - private $_caffeinated_extends = array(); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * _current_caf_extend_slug |
|
| 63 | - * This property is used for holding the page slug that is required for referencing the correct |
|
| 64 | - * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
| 65 | - * |
|
| 66 | - * @var array |
|
| 67 | - */ |
|
| 68 | - private $_current_caf_extend_slug; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * _caf_autoloader |
|
| 74 | - * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the |
|
| 75 | - * caffeinated/new directory. This array is then used to setup a corresponding dynamic autoloader for these pages |
|
| 76 | - * classes. |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - // private $_caf_autoloader = array(); |
|
| 81 | - /** |
|
| 82 | - * _prepped_menu_maps |
|
| 83 | - * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
| 84 | - * |
|
| 85 | - * @since 4.4.0 |
|
| 86 | - * @var EE_Admin_Page_Menu_Map[] |
|
| 87 | - */ |
|
| 88 | - private $_prepped_menu_maps = array(); |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * _admin_menu_groups |
|
| 94 | - * array that holds the group headings and details for |
|
| 95 | - * |
|
| 96 | - * @access private |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - private $_admin_menu_groups = array(); |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
| 105 | - * pages. |
|
| 106 | - * |
|
| 107 | - * @var string |
|
| 108 | - */ |
|
| 109 | - public $hook_file; |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * constructor |
|
| 115 | - * |
|
| 116 | - * @access public |
|
| 117 | - * @return \EE_Admin_Page_Loader |
|
| 118 | - */ |
|
| 119 | - public function __construct() |
|
| 120 | - { |
|
| 121 | - //load menu_map classes |
|
| 122 | - EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
| 123 | - //define the default "groups" for the admin_pages |
|
| 124 | - $this->_set_menu_groups(); |
|
| 125 | - //let's set default autoloaders. Note that this just sets autoloaders for root admin files. |
|
| 126 | - // spl_autoload_register( array( $this, 'init_autoloaders') ); |
|
| 127 | - //let's do a scan and see what installed pages we have |
|
| 128 | - $this->_get_installed_pages(); |
|
| 129 | - //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
| 130 | - add_action('admin_menu', array($this, 'set_menus')); |
|
| 131 | - add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
| 138 | - * files in the caffeinated folder. |
|
| 139 | - * |
|
| 140 | - * @access private |
|
| 141 | - * @return void |
|
| 142 | - */ |
|
| 143 | - private function _define_caffeinated_constants() |
|
| 144 | - { |
|
| 145 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 146 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 147 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 148 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 149 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 150 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 151 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * _set_menu_groups |
|
| 159 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
| 160 | - * |
|
| 161 | - * @access private |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - private function _set_menu_groups() |
|
| 165 | - { |
|
| 166 | - |
|
| 167 | - //set array of EE_Admin_Page_Menu_Group objects |
|
| 168 | - $groups = array( |
|
| 169 | - 'main' => new EE_Admin_Page_Menu_Group( |
|
| 170 | - array( |
|
| 171 | - 'menu_label' => __('Main', 'event_espresso'), |
|
| 172 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
| 173 | - 'menu_slug' => 'main', |
|
| 174 | - 'capability' => 'ee_read_ee', |
|
| 175 | - 'menu_order' => 0, |
|
| 176 | - 'parent_slug' => 'espresso_events', |
|
| 177 | - ) |
|
| 178 | - ), |
|
| 179 | - 'management' => new EE_Admin_Page_Menu_Group( |
|
| 180 | - array( |
|
| 181 | - 'menu_label' => __('Management', 'event_espresso'), |
|
| 182 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 183 | - 'menu_slug' => 'management', |
|
| 184 | - 'capability' => 'ee_read_ee', |
|
| 185 | - 'menu_order' => 10, |
|
| 186 | - 'parent_slug' => 'espresso_events', |
|
| 187 | - ) |
|
| 188 | - ), |
|
| 189 | - 'settings' => new EE_Admin_Page_Menu_Group( |
|
| 190 | - array( |
|
| 191 | - 'menu_label' => __('Settings', 'event_espresso'), |
|
| 192 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 193 | - 'menu_slug' => 'settings', |
|
| 194 | - 'capability' => 'ee_read_ee', |
|
| 195 | - 'menu_order' => 30, |
|
| 196 | - 'parent_slug' => 'espresso_events', |
|
| 197 | - ) |
|
| 198 | - ), |
|
| 199 | - 'templates' => new EE_Admin_Page_Menu_Group( |
|
| 200 | - array( |
|
| 201 | - 'menu_label' => __('Templates', 'event_espresso'), |
|
| 202 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 203 | - 'menu_slug' => 'templates', |
|
| 204 | - 'capability' => 'ee_read_ee', |
|
| 205 | - 'menu_order' => 40, |
|
| 206 | - 'parent_slug' => 'espresso_events', |
|
| 207 | - ) |
|
| 208 | - ), |
|
| 209 | - 'extras' => new EE_Admin_Page_Menu_Group( |
|
| 210 | - array( |
|
| 211 | - 'menu_label' => __('Extras', 'event_espresso'), |
|
| 212 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 213 | - 'menu_slug' => 'extras', |
|
| 214 | - 'capability' => 'ee_read_ee', |
|
| 215 | - 'menu_order' => 50, |
|
| 216 | - 'parent_slug' => 'espresso_events', |
|
| 217 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 218 | - ) |
|
| 219 | - ), |
|
| 220 | - 'tools' => new EE_Admin_Page_Menu_Group( |
|
| 221 | - array( |
|
| 222 | - 'menu_label' => __("Tools", "event_espresso"), |
|
| 223 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 224 | - 'menu_slug' => 'tools', |
|
| 225 | - 'capability' => 'ee_read_ee', |
|
| 226 | - 'menu_order' => 60, |
|
| 227 | - 'parent_slug' => 'espresso_events', |
|
| 228 | - ) |
|
| 229 | - ), |
|
| 230 | - 'addons' => new EE_Admin_Page_Menu_Group( |
|
| 231 | - array( |
|
| 232 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 233 | - 'menu_label' => __('Add-ons', 'event_espresso'), |
|
| 234 | - 'menu_slug' => 'addons', |
|
| 235 | - 'capability' => 'ee_read_ee', |
|
| 236 | - 'menu_order' => 20, |
|
| 237 | - 'parent_slug' => 'espresso_events', |
|
| 238 | - ) |
|
| 239 | - ), |
|
| 240 | - ); |
|
| 241 | - $this->_admin_menu_groups = apply_filters( |
|
| 242 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
| 243 | - $groups |
|
| 244 | - ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
| 251 | - * slug. The other utility with this function is it validates that all the groups are instances of |
|
| 252 | - * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
| 253 | - * |
|
| 254 | - * @since 4.4.0 |
|
| 255 | - * @throws \EE_Error |
|
| 256 | - * @return EE_Admin_Page_Menu_Group[] |
|
| 257 | - */ |
|
| 258 | - private function _rearrange_menu_groups() |
|
| 259 | - { |
|
| 260 | - $groups = array(); |
|
| 261 | - //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
| 262 | - usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
| 263 | - foreach ($this->_admin_menu_groups as $group) { |
|
| 264 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 265 | - throw new EE_Error( |
|
| 266 | - sprintf( |
|
| 267 | - __( |
|
| 268 | - 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ), |
|
| 271 | - print_r($group, true) |
|
| 272 | - ) |
|
| 273 | - ); |
|
| 274 | - } |
|
| 275 | - $groups[$group->menu_slug] = $group; |
|
| 276 | - } |
|
| 277 | - return $groups; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * _get_installed_pages |
|
| 284 | - * This just gets the list of installed EE_Admin_pages. |
|
| 285 | - * |
|
| 286 | - * @access private |
|
| 287 | - * @throws EE_Error |
|
| 288 | - * @return void |
|
| 289 | - */ |
|
| 290 | - private function _get_installed_pages() |
|
| 291 | - { |
|
| 292 | - $installed_refs = array(); |
|
| 293 | - $exclude = array('assets', 'templates'); |
|
| 294 | - // grab everything in the admin core directory |
|
| 295 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
| 296 | - if ($admin_screens) { |
|
| 297 | - foreach ($admin_screens as $admin_screen) { |
|
| 298 | - // files and anything in the exclude array need not apply |
|
| 299 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 300 | - // these folders represent the different EE admin pages |
|
| 301 | - $installed_refs[basename($admin_screen)] = $admin_screen; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - if (empty($installed_refs)) { |
|
| 306 | - $error_msg[] = __( |
|
| 307 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
| 308 | - 'event_espresso' |
|
| 309 | - ); |
|
| 310 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 311 | - __( |
|
| 312 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
| 313 | - 'event_espresso' |
|
| 314 | - ), |
|
| 315 | - EE_ADMIN_PAGES |
|
| 316 | - ); |
|
| 317 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 318 | - } |
|
| 319 | - //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
| 320 | - $installed_refs = $this->_set_caffeinated($installed_refs); |
|
| 321 | - //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
| 322 | - $installed_refs = apply_filters( |
|
| 323 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
| 324 | - $installed_refs |
|
| 325 | - ); |
|
| 326 | - $this->_caffeinated_extends = apply_filters( |
|
| 327 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
| 328 | - $this->_caffeinated_extends |
|
| 329 | - ); |
|
| 330 | - //loop through admin pages and setup the $_installed_pages array. |
|
| 331 | - $hooks_ref = array(); |
|
| 332 | - foreach ($installed_refs as $page => $path) { |
|
| 333 | - // set autoloaders for our admin page classes based on included path information |
|
| 334 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
| 335 | - // build list of installed pages |
|
| 336 | - $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
| 337 | - // verify returned object |
|
| 338 | - if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
| 339 | - if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 340 | - continue; |
|
| 341 | - } |
|
| 342 | - //skip if in full maintenance mode and maintenance_mode_parent is set |
|
| 343 | - $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
| 344 | - if (empty($maintenance_mode_parent) |
|
| 345 | - && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 346 | - ) { |
|
| 347 | - unset($installed_refs[$page]); |
|
| 348 | - continue; |
|
| 349 | - } |
|
| 350 | - $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug; |
|
| 351 | - $this->_menu_slugs[$menu_slug] = $page; |
|
| 352 | - //flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
| 353 | - $extend = false; |
|
| 354 | - //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
| 355 | - if (isset($this->_caffeinated_extends[$page])) { |
|
| 356 | - $this->_current_caf_extend_slug = $page; |
|
| 357 | - $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name(); |
|
| 358 | - $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path']; |
|
| 359 | - $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page']; |
|
| 360 | - add_filter( |
|
| 361 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
| 362 | - function($path_to_file) use ($caf_path) { |
|
| 363 | - return $caf_path; |
|
| 364 | - } |
|
| 365 | - ); |
|
| 366 | - add_filter( |
|
| 367 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
| 368 | - function ($admin_page) use ($caf_admin_page) |
|
| 369 | - { |
|
| 370 | - return $caf_admin_page; |
|
| 371 | - } |
|
| 372 | - ); |
|
| 373 | - $extend = true; |
|
| 374 | - } |
|
| 375 | - //let's do the registered hooks |
|
| 376 | - $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
| 377 | - $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
| 381 | - //first make sure we've got unique values |
|
| 382 | - $hooks_ref = array_unique($hooks_ref); |
|
| 383 | - //now let's loop and require! |
|
| 384 | - foreach ($hooks_ref as $path) { |
|
| 385 | - require_once($path); |
|
| 386 | - } |
|
| 387 | - //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
| 388 | - global $ee_menu_slugs; |
|
| 389 | - $ee_menu_slugs = $this->_menu_slugs; |
|
| 390 | - //we need to loop again to run any early code |
|
| 391 | - foreach ($installed_refs as $page => $path) { |
|
| 392 | - if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
| 393 | - $this->_installed_pages[$page]->do_initial_loads(); |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * get_admin_page_object |
|
| 403 | - * |
|
| 404 | - * @param string $page_slug |
|
| 405 | - * @return EE_Admin_Page |
|
| 406 | - */ |
|
| 407 | - public function get_admin_page_object($page_slug = '') |
|
| 408 | - { |
|
| 409 | - if (isset($this->_installed_pages[$page_slug])) { |
|
| 410 | - return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
| 411 | - } |
|
| 412 | - return null; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * _get_classname_for_admin_page |
|
| 419 | - * generates an "Admin Page" class based on the directory name |
|
| 420 | - * |
|
| 421 | - * @param $dir_name |
|
| 422 | - * @return string |
|
| 423 | - */ |
|
| 424 | - private function _get_classname_for_admin_page($dir_name = '') |
|
| 425 | - { |
|
| 426 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 427 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * _get_classname_for_admin_init_page |
|
| 434 | - * generates an "Admin Page Init" class based on the directory name |
|
| 435 | - * |
|
| 436 | - * @param $dir_name |
|
| 437 | - * @return string |
|
| 438 | - */ |
|
| 439 | - private function _get_classname_for_admin_init_page($dir_name = '') |
|
| 440 | - { |
|
| 441 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 442 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * _load_admin_page |
|
| 449 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
| 450 | - * |
|
| 451 | - * @param string $page page_reference |
|
| 452 | - * @param string $path |
|
| 453 | - * @throws EE_Error |
|
| 454 | - * @return object|bool return page object if valid, bool false if not. |
|
| 455 | - */ |
|
| 456 | - private function _load_admin_page($page = '', $path = '') |
|
| 457 | - { |
|
| 458 | - $class_name = $this->_get_classname_for_admin_init_page($page); |
|
| 459 | - EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
| 460 | - if (! class_exists($class_name)) { |
|
| 461 | - $inner_error_msg = '<br />' . sprintf( |
|
| 462 | - esc_html__( |
|
| 463 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 464 | - 'event_espresso' |
|
| 465 | - ), |
|
| 466 | - '<strong>' . $class_name . '</strong>' |
|
| 467 | - ); |
|
| 468 | - $error_msg[] = sprintf( |
|
| 469 | - __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
| 470 | - $page |
|
| 471 | - ); |
|
| 472 | - $error_msg[] = $error_msg[0] |
|
| 473 | - . "\r\n" |
|
| 474 | - . sprintf( |
|
| 475 | - esc_html__( |
|
| 476 | - 'There is no Init class in place for the %s admin page.', |
|
| 477 | - 'event_espresso' |
|
| 478 | - ), |
|
| 479 | - $page |
|
| 480 | - ) |
|
| 481 | - . $inner_error_msg; |
|
| 482 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 483 | - } |
|
| 484 | - $a = new ReflectionClass($class_name); |
|
| 485 | - return $a->newInstance(); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * set_menus |
|
| 492 | - * This method sets up the menus for EE Admin Pages |
|
| 493 | - * |
|
| 494 | - * @access private |
|
| 495 | - * @return void |
|
| 496 | - */ |
|
| 497 | - public function set_menus() |
|
| 498 | - { |
|
| 499 | - //prep the menu pages (sort, group.) |
|
| 500 | - $this->_prep_pages(); |
|
| 501 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 502 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 503 | - $menu_map->add_menu_page(false); |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * set_network_menus |
|
| 511 | - * This method sets up the menus for network EE Admin Pages. |
|
| 512 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
| 513 | - * are only added to the menu map if they are intended for the admin menu |
|
| 514 | - * |
|
| 515 | - * @return void |
|
| 516 | - */ |
|
| 517 | - public function set_network_menus() |
|
| 518 | - { |
|
| 519 | - $this->_prep_pages(); |
|
| 520 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 521 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 522 | - $menu_map->add_menu_page(true); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * _prep_pages |
|
| 531 | - * sets the _prepped_menu_maps property |
|
| 532 | - * |
|
| 533 | - * @access private |
|
| 534 | - * @throws EE_Error |
|
| 535 | - * @return void |
|
| 536 | - */ |
|
| 537 | - private function _prep_pages() |
|
| 538 | - { |
|
| 539 | - $pages_array = array(); |
|
| 540 | - //rearrange _admin_menu_groups to be indexed by group slug. |
|
| 541 | - $menu_groups = $this->_rearrange_menu_groups(); |
|
| 542 | - foreach ($this->_installed_pages as $page) { |
|
| 543 | - if ($page instanceof EE_Admin_page_Init) { |
|
| 544 | - $page_map = $page->get_menu_map(); |
|
| 545 | - //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
| 546 | - if (is_array($page_map) || empty($page_map)) { |
|
| 547 | - new PersistentAdminNotice( |
|
| 548 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
| 549 | - sprintf( |
|
| 550 | - __( |
|
| 551 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
| 552 | - 'event_espresso' |
|
| 553 | - ), |
|
| 554 | - $page->label |
|
| 555 | - ) |
|
| 556 | - ); |
|
| 557 | - continue; |
|
| 558 | - } |
|
| 559 | - //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
| 560 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __( |
|
| 564 | - 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
| 565 | - 'event_espresso' |
|
| 566 | - ), |
|
| 567 | - $page->label, |
|
| 568 | - $page_map |
|
| 569 | - ) |
|
| 570 | - ); |
|
| 571 | - } |
|
| 572 | - //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
| 573 | - if (empty($page_map->maintenance_mode_parent) |
|
| 574 | - && EE_Maintenance_Mode::instance()->level() |
|
| 575 | - == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 576 | - continue; |
|
| 577 | - } |
|
| 578 | - //assign to group (remember $page_map has the admin page stored in it). |
|
| 579 | - $pages_array[$page_map->menu_group][] = $page_map; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - if (empty($pages_array)) { |
|
| 583 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
| 584 | - } |
|
| 585 | - //let's sort the groups, make sure it's a valid group, add header (if to show). |
|
| 586 | - foreach ($pages_array as $group => $menu_maps) { |
|
| 587 | - //valid_group? |
|
| 588 | - if (! array_key_exists($group, $menu_groups)) { |
|
| 589 | - continue; |
|
| 590 | - } |
|
| 591 | - //sort pages. |
|
| 592 | - usort($menu_maps, array($this, '_sort_menu_maps')); |
|
| 593 | - //prepend header |
|
| 594 | - array_unshift($menu_maps, $menu_groups[$group]); |
|
| 595 | - //reset $pages_array with prepped data |
|
| 596 | - $pages_array[$group] = $menu_maps; |
|
| 597 | - } |
|
| 598 | - //now let's setup the _prepped_menu_maps property |
|
| 599 | - foreach ($menu_groups as $group => $group_objs) { |
|
| 600 | - if (isset($pages_array[$group])) { |
|
| 601 | - $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
| 602 | - } |
|
| 603 | - }/**/ |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
| 609 | - * In this method there are three checks being done: |
|
| 610 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
| 611 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
| 612 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
| 613 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
| 614 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
| 615 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
| 616 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
| 617 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
| 618 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
| 619 | - * admin_pages) |
|
| 620 | - * |
|
| 621 | - * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
| 622 | - * loaded. |
|
| 623 | - * @return array |
|
| 624 | - */ |
|
| 625 | - private function _set_caffeinated($installed_refs) |
|
| 626 | - { |
|
| 627 | - |
|
| 628 | - //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
| 629 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 630 | - return $installed_refs; |
|
| 631 | - } |
|
| 632 | - $this->_define_caffeinated_constants(); |
|
| 633 | - $exclude = array('tickets'); |
|
| 634 | - //okay let's setup an "New" pages first (we'll return installed refs later) |
|
| 635 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
| 636 | - if ($new_admin_screens) { |
|
| 637 | - foreach ($new_admin_screens as $admin_screen) { |
|
| 638 | - // files and anything in the exclude array need not apply |
|
| 639 | - if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 640 | - // these folders represent the different NEW EE admin pages |
|
| 641 | - $installed_refs[basename($admin_screen)] = $admin_screen; |
|
| 642 | - // set autoloaders for our admin page classes based on included path information |
|
| 643 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
| 644 | - // $this->_caf_autoloader[] = array( |
|
| 645 | - // 'dir' => 'new', |
|
| 646 | - // 'folder' => basename( $admin_screen ) |
|
| 647 | - // ); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
| 652 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
| 653 | - if ($extends) { |
|
| 654 | - foreach ($extends as $extend) { |
|
| 655 | - if (is_dir($extend)) { |
|
| 656 | - $extend_ref = basename($extend); |
|
| 657 | - //now let's make sure there is a file that matches the expected format |
|
| 658 | - $filename = str_replace( |
|
| 659 | - ' ', |
|
| 660 | - '_', |
|
| 661 | - ucwords( |
|
| 662 | - str_replace( |
|
| 663 | - '_', |
|
| 664 | - ' ', |
|
| 665 | - $extend_ref |
|
| 666 | - ) |
|
| 667 | - ) |
|
| 668 | - ); |
|
| 669 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
| 670 | - $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
| 671 | - array('\\', '/'), |
|
| 672 | - DS, |
|
| 673 | - EE_CORE_CAF_ADMIN |
|
| 674 | - . 'extend' |
|
| 675 | - . DS |
|
| 676 | - . $extend_ref |
|
| 677 | - . DS |
|
| 678 | - . $filename |
|
| 679 | - . '.core.php' |
|
| 680 | - ); |
|
| 681 | - $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
| 682 | - // set autoloaders for our admin page classes based on included path information |
|
| 683 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
| 684 | - // $this->_caf_autoloader[] = array( |
|
| 685 | - // 'dir' => 'extend', |
|
| 686 | - // 'folder' => $extend_ref |
|
| 687 | - // ); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
| 692 | - $ee_admin_hooks = array(); |
|
| 693 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
| 694 | - if ($hooks) { |
|
| 695 | - foreach ($hooks as $hook) { |
|
| 696 | - if (is_readable($hook)) { |
|
| 697 | - require_once $hook; |
|
| 698 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
| 699 | - $classname = str_replace('.class.php', '', $classname); |
|
| 700 | - if (class_exists($classname)) { |
|
| 701 | - $a = new ReflectionClass($classname); |
|
| 702 | - $ee_admin_hooks[] = $a->newInstance(); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - }/**/ |
|
| 707 | - $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
| 708 | - return $installed_refs; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * Initial autoloader registration |
|
| 717 | - * This just sets up the autoloader for the root admin files |
|
| 718 | - * |
|
| 719 | - * @param string $className incoming classname to check for autoload |
|
| 720 | - * @return void |
|
| 721 | - */ |
|
| 722 | - // public function init_autoloaders( $className ) { |
|
| 723 | - // $dir_ref = array( |
|
| 724 | - // EE_ADMIN => array('core', 'class') |
|
| 725 | - // ); |
|
| 726 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 727 | - // } |
|
| 728 | - /** |
|
| 729 | - * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the |
|
| 730 | - * caffeinated folders. |
|
| 731 | - * |
|
| 732 | - * @access public |
|
| 733 | - * @param string $className in coming classname being called |
|
| 734 | - * @return void |
|
| 735 | - */ |
|
| 736 | - // public function caffeinated_autoloaders( $className ) { |
|
| 737 | - // //let's setup an array of paths to check (for each subsystem) |
|
| 738 | - // $dir_ref = array(); |
|
| 739 | - // foreach ( $this->_caf_autoloader as $pathinfo) { |
|
| 740 | - // $dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class'); |
|
| 741 | - // } |
|
| 742 | - // |
|
| 743 | - // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 744 | - // } |
|
| 745 | - /** |
|
| 746 | - * Utility method for sorting the _menu_maps (callback for usort php function) |
|
| 747 | - * |
|
| 748 | - * @since 4.4.0 |
|
| 749 | - * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
| 750 | - * @param EE_Admin_Page_Menu_Map $b being compared to |
|
| 751 | - * @return int sort order |
|
| 752 | - */ |
|
| 753 | - private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
| 754 | - { |
|
| 755 | - if ($a->menu_order == $b->menu_order) { |
|
| 756 | - return 0; |
|
| 757 | - } |
|
| 758 | - return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - |
|
| 763 | - /** |
|
| 764 | - * _default_header_link |
|
| 765 | - * This is just a dummy method to use with header submenu items |
|
| 766 | - * |
|
| 767 | - * @return bool false |
|
| 768 | - */ |
|
| 769 | - public function _default_header_link() |
|
| 770 | - { |
|
| 771 | - return false; |
|
| 772 | - } |
|
| 31 | + /** |
|
| 32 | + * _installed_pages |
|
| 33 | + * objects for page_init objects detected and loaded |
|
| 34 | + * |
|
| 35 | + * @access private |
|
| 36 | + * @var \EE_Admin_Page_Init[] |
|
| 37 | + */ |
|
| 38 | + private $_installed_pages = array(); |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private $_menu_slugs = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * _caffeinated_extends |
|
| 52 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
| 53 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + private $_caffeinated_extends = array(); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * _current_caf_extend_slug |
|
| 63 | + * This property is used for holding the page slug that is required for referencing the correct |
|
| 64 | + * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
| 65 | + * |
|
| 66 | + * @var array |
|
| 67 | + */ |
|
| 68 | + private $_current_caf_extend_slug; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * _caf_autoloader |
|
| 74 | + * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the |
|
| 75 | + * caffeinated/new directory. This array is then used to setup a corresponding dynamic autoloader for these pages |
|
| 76 | + * classes. |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + // private $_caf_autoloader = array(); |
|
| 81 | + /** |
|
| 82 | + * _prepped_menu_maps |
|
| 83 | + * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
| 84 | + * |
|
| 85 | + * @since 4.4.0 |
|
| 86 | + * @var EE_Admin_Page_Menu_Map[] |
|
| 87 | + */ |
|
| 88 | + private $_prepped_menu_maps = array(); |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * _admin_menu_groups |
|
| 94 | + * array that holds the group headings and details for |
|
| 95 | + * |
|
| 96 | + * @access private |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + private $_admin_menu_groups = array(); |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
| 105 | + * pages. |
|
| 106 | + * |
|
| 107 | + * @var string |
|
| 108 | + */ |
|
| 109 | + public $hook_file; |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * constructor |
|
| 115 | + * |
|
| 116 | + * @access public |
|
| 117 | + * @return \EE_Admin_Page_Loader |
|
| 118 | + */ |
|
| 119 | + public function __construct() |
|
| 120 | + { |
|
| 121 | + //load menu_map classes |
|
| 122 | + EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
| 123 | + //define the default "groups" for the admin_pages |
|
| 124 | + $this->_set_menu_groups(); |
|
| 125 | + //let's set default autoloaders. Note that this just sets autoloaders for root admin files. |
|
| 126 | + // spl_autoload_register( array( $this, 'init_autoloaders') ); |
|
| 127 | + //let's do a scan and see what installed pages we have |
|
| 128 | + $this->_get_installed_pages(); |
|
| 129 | + //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
| 130 | + add_action('admin_menu', array($this, 'set_menus')); |
|
| 131 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
| 138 | + * files in the caffeinated folder. |
|
| 139 | + * |
|
| 140 | + * @access private |
|
| 141 | + * @return void |
|
| 142 | + */ |
|
| 143 | + private function _define_caffeinated_constants() |
|
| 144 | + { |
|
| 145 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 146 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 147 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 148 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 149 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 150 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 151 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * _set_menu_groups |
|
| 159 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
| 160 | + * |
|
| 161 | + * @access private |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + private function _set_menu_groups() |
|
| 165 | + { |
|
| 166 | + |
|
| 167 | + //set array of EE_Admin_Page_Menu_Group objects |
|
| 168 | + $groups = array( |
|
| 169 | + 'main' => new EE_Admin_Page_Menu_Group( |
|
| 170 | + array( |
|
| 171 | + 'menu_label' => __('Main', 'event_espresso'), |
|
| 172 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
| 173 | + 'menu_slug' => 'main', |
|
| 174 | + 'capability' => 'ee_read_ee', |
|
| 175 | + 'menu_order' => 0, |
|
| 176 | + 'parent_slug' => 'espresso_events', |
|
| 177 | + ) |
|
| 178 | + ), |
|
| 179 | + 'management' => new EE_Admin_Page_Menu_Group( |
|
| 180 | + array( |
|
| 181 | + 'menu_label' => __('Management', 'event_espresso'), |
|
| 182 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 183 | + 'menu_slug' => 'management', |
|
| 184 | + 'capability' => 'ee_read_ee', |
|
| 185 | + 'menu_order' => 10, |
|
| 186 | + 'parent_slug' => 'espresso_events', |
|
| 187 | + ) |
|
| 188 | + ), |
|
| 189 | + 'settings' => new EE_Admin_Page_Menu_Group( |
|
| 190 | + array( |
|
| 191 | + 'menu_label' => __('Settings', 'event_espresso'), |
|
| 192 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 193 | + 'menu_slug' => 'settings', |
|
| 194 | + 'capability' => 'ee_read_ee', |
|
| 195 | + 'menu_order' => 30, |
|
| 196 | + 'parent_slug' => 'espresso_events', |
|
| 197 | + ) |
|
| 198 | + ), |
|
| 199 | + 'templates' => new EE_Admin_Page_Menu_Group( |
|
| 200 | + array( |
|
| 201 | + 'menu_label' => __('Templates', 'event_espresso'), |
|
| 202 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 203 | + 'menu_slug' => 'templates', |
|
| 204 | + 'capability' => 'ee_read_ee', |
|
| 205 | + 'menu_order' => 40, |
|
| 206 | + 'parent_slug' => 'espresso_events', |
|
| 207 | + ) |
|
| 208 | + ), |
|
| 209 | + 'extras' => new EE_Admin_Page_Menu_Group( |
|
| 210 | + array( |
|
| 211 | + 'menu_label' => __('Extras', 'event_espresso'), |
|
| 212 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 213 | + 'menu_slug' => 'extras', |
|
| 214 | + 'capability' => 'ee_read_ee', |
|
| 215 | + 'menu_order' => 50, |
|
| 216 | + 'parent_slug' => 'espresso_events', |
|
| 217 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
| 218 | + ) |
|
| 219 | + ), |
|
| 220 | + 'tools' => new EE_Admin_Page_Menu_Group( |
|
| 221 | + array( |
|
| 222 | + 'menu_label' => __("Tools", "event_espresso"), |
|
| 223 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
| 224 | + 'menu_slug' => 'tools', |
|
| 225 | + 'capability' => 'ee_read_ee', |
|
| 226 | + 'menu_order' => 60, |
|
| 227 | + 'parent_slug' => 'espresso_events', |
|
| 228 | + ) |
|
| 229 | + ), |
|
| 230 | + 'addons' => new EE_Admin_Page_Menu_Group( |
|
| 231 | + array( |
|
| 232 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
| 233 | + 'menu_label' => __('Add-ons', 'event_espresso'), |
|
| 234 | + 'menu_slug' => 'addons', |
|
| 235 | + 'capability' => 'ee_read_ee', |
|
| 236 | + 'menu_order' => 20, |
|
| 237 | + 'parent_slug' => 'espresso_events', |
|
| 238 | + ) |
|
| 239 | + ), |
|
| 240 | + ); |
|
| 241 | + $this->_admin_menu_groups = apply_filters( |
|
| 242 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
| 243 | + $groups |
|
| 244 | + ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
| 251 | + * slug. The other utility with this function is it validates that all the groups are instances of |
|
| 252 | + * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
| 253 | + * |
|
| 254 | + * @since 4.4.0 |
|
| 255 | + * @throws \EE_Error |
|
| 256 | + * @return EE_Admin_Page_Menu_Group[] |
|
| 257 | + */ |
|
| 258 | + private function _rearrange_menu_groups() |
|
| 259 | + { |
|
| 260 | + $groups = array(); |
|
| 261 | + //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
| 262 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
| 263 | + foreach ($this->_admin_menu_groups as $group) { |
|
| 264 | + if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 265 | + throw new EE_Error( |
|
| 266 | + sprintf( |
|
| 267 | + __( |
|
| 268 | + 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ), |
|
| 271 | + print_r($group, true) |
|
| 272 | + ) |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | + $groups[$group->menu_slug] = $group; |
|
| 276 | + } |
|
| 277 | + return $groups; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * _get_installed_pages |
|
| 284 | + * This just gets the list of installed EE_Admin_pages. |
|
| 285 | + * |
|
| 286 | + * @access private |
|
| 287 | + * @throws EE_Error |
|
| 288 | + * @return void |
|
| 289 | + */ |
|
| 290 | + private function _get_installed_pages() |
|
| 291 | + { |
|
| 292 | + $installed_refs = array(); |
|
| 293 | + $exclude = array('assets', 'templates'); |
|
| 294 | + // grab everything in the admin core directory |
|
| 295 | + $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
| 296 | + if ($admin_screens) { |
|
| 297 | + foreach ($admin_screens as $admin_screen) { |
|
| 298 | + // files and anything in the exclude array need not apply |
|
| 299 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 300 | + // these folders represent the different EE admin pages |
|
| 301 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + if (empty($installed_refs)) { |
|
| 306 | + $error_msg[] = __( |
|
| 307 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
| 308 | + 'event_espresso' |
|
| 309 | + ); |
|
| 310 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 311 | + __( |
|
| 312 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
| 313 | + 'event_espresso' |
|
| 314 | + ), |
|
| 315 | + EE_ADMIN_PAGES |
|
| 316 | + ); |
|
| 317 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 318 | + } |
|
| 319 | + //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
| 320 | + $installed_refs = $this->_set_caffeinated($installed_refs); |
|
| 321 | + //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
| 322 | + $installed_refs = apply_filters( |
|
| 323 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
| 324 | + $installed_refs |
|
| 325 | + ); |
|
| 326 | + $this->_caffeinated_extends = apply_filters( |
|
| 327 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
| 328 | + $this->_caffeinated_extends |
|
| 329 | + ); |
|
| 330 | + //loop through admin pages and setup the $_installed_pages array. |
|
| 331 | + $hooks_ref = array(); |
|
| 332 | + foreach ($installed_refs as $page => $path) { |
|
| 333 | + // set autoloaders for our admin page classes based on included path information |
|
| 334 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path); |
|
| 335 | + // build list of installed pages |
|
| 336 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
| 337 | + // verify returned object |
|
| 338 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
| 339 | + if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 340 | + continue; |
|
| 341 | + } |
|
| 342 | + //skip if in full maintenance mode and maintenance_mode_parent is set |
|
| 343 | + $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
| 344 | + if (empty($maintenance_mode_parent) |
|
| 345 | + && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 346 | + ) { |
|
| 347 | + unset($installed_refs[$page]); |
|
| 348 | + continue; |
|
| 349 | + } |
|
| 350 | + $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug; |
|
| 351 | + $this->_menu_slugs[$menu_slug] = $page; |
|
| 352 | + //flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
| 353 | + $extend = false; |
|
| 354 | + //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
| 355 | + if (isset($this->_caffeinated_extends[$page])) { |
|
| 356 | + $this->_current_caf_extend_slug = $page; |
|
| 357 | + $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name(); |
|
| 358 | + $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path']; |
|
| 359 | + $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page']; |
|
| 360 | + add_filter( |
|
| 361 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
| 362 | + function($path_to_file) use ($caf_path) { |
|
| 363 | + return $caf_path; |
|
| 364 | + } |
|
| 365 | + ); |
|
| 366 | + add_filter( |
|
| 367 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
| 368 | + function ($admin_page) use ($caf_admin_page) |
|
| 369 | + { |
|
| 370 | + return $caf_admin_page; |
|
| 371 | + } |
|
| 372 | + ); |
|
| 373 | + $extend = true; |
|
| 374 | + } |
|
| 375 | + //let's do the registered hooks |
|
| 376 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
| 377 | + $hooks_ref = array_merge($hooks_ref, $extended_hooks); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
| 381 | + //first make sure we've got unique values |
|
| 382 | + $hooks_ref = array_unique($hooks_ref); |
|
| 383 | + //now let's loop and require! |
|
| 384 | + foreach ($hooks_ref as $path) { |
|
| 385 | + require_once($path); |
|
| 386 | + } |
|
| 387 | + //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
| 388 | + global $ee_menu_slugs; |
|
| 389 | + $ee_menu_slugs = $this->_menu_slugs; |
|
| 390 | + //we need to loop again to run any early code |
|
| 391 | + foreach ($installed_refs as $page => $path) { |
|
| 392 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
| 393 | + $this->_installed_pages[$page]->do_initial_loads(); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * get_admin_page_object |
|
| 403 | + * |
|
| 404 | + * @param string $page_slug |
|
| 405 | + * @return EE_Admin_Page |
|
| 406 | + */ |
|
| 407 | + public function get_admin_page_object($page_slug = '') |
|
| 408 | + { |
|
| 409 | + if (isset($this->_installed_pages[$page_slug])) { |
|
| 410 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
| 411 | + } |
|
| 412 | + return null; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * _get_classname_for_admin_page |
|
| 419 | + * generates an "Admin Page" class based on the directory name |
|
| 420 | + * |
|
| 421 | + * @param $dir_name |
|
| 422 | + * @return string |
|
| 423 | + */ |
|
| 424 | + private function _get_classname_for_admin_page($dir_name = '') |
|
| 425 | + { |
|
| 426 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 427 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * _get_classname_for_admin_init_page |
|
| 434 | + * generates an "Admin Page Init" class based on the directory name |
|
| 435 | + * |
|
| 436 | + * @param $dir_name |
|
| 437 | + * @return string |
|
| 438 | + */ |
|
| 439 | + private function _get_classname_for_admin_init_page($dir_name = '') |
|
| 440 | + { |
|
| 441 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 442 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * _load_admin_page |
|
| 449 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
| 450 | + * |
|
| 451 | + * @param string $page page_reference |
|
| 452 | + * @param string $path |
|
| 453 | + * @throws EE_Error |
|
| 454 | + * @return object|bool return page object if valid, bool false if not. |
|
| 455 | + */ |
|
| 456 | + private function _load_admin_page($page = '', $path = '') |
|
| 457 | + { |
|
| 458 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
| 459 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
| 460 | + if (! class_exists($class_name)) { |
|
| 461 | + $inner_error_msg = '<br />' . sprintf( |
|
| 462 | + esc_html__( |
|
| 463 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 464 | + 'event_espresso' |
|
| 465 | + ), |
|
| 466 | + '<strong>' . $class_name . '</strong>' |
|
| 467 | + ); |
|
| 468 | + $error_msg[] = sprintf( |
|
| 469 | + __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
| 470 | + $page |
|
| 471 | + ); |
|
| 472 | + $error_msg[] = $error_msg[0] |
|
| 473 | + . "\r\n" |
|
| 474 | + . sprintf( |
|
| 475 | + esc_html__( |
|
| 476 | + 'There is no Init class in place for the %s admin page.', |
|
| 477 | + 'event_espresso' |
|
| 478 | + ), |
|
| 479 | + $page |
|
| 480 | + ) |
|
| 481 | + . $inner_error_msg; |
|
| 482 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 483 | + } |
|
| 484 | + $a = new ReflectionClass($class_name); |
|
| 485 | + return $a->newInstance(); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * set_menus |
|
| 492 | + * This method sets up the menus for EE Admin Pages |
|
| 493 | + * |
|
| 494 | + * @access private |
|
| 495 | + * @return void |
|
| 496 | + */ |
|
| 497 | + public function set_menus() |
|
| 498 | + { |
|
| 499 | + //prep the menu pages (sort, group.) |
|
| 500 | + $this->_prep_pages(); |
|
| 501 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 502 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 503 | + $menu_map->add_menu_page(false); |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * set_network_menus |
|
| 511 | + * This method sets up the menus for network EE Admin Pages. |
|
| 512 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
| 513 | + * are only added to the menu map if they are intended for the admin menu |
|
| 514 | + * |
|
| 515 | + * @return void |
|
| 516 | + */ |
|
| 517 | + public function set_network_menus() |
|
| 518 | + { |
|
| 519 | + $this->_prep_pages(); |
|
| 520 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
| 521 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
| 522 | + $menu_map->add_menu_page(true); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * _prep_pages |
|
| 531 | + * sets the _prepped_menu_maps property |
|
| 532 | + * |
|
| 533 | + * @access private |
|
| 534 | + * @throws EE_Error |
|
| 535 | + * @return void |
|
| 536 | + */ |
|
| 537 | + private function _prep_pages() |
|
| 538 | + { |
|
| 539 | + $pages_array = array(); |
|
| 540 | + //rearrange _admin_menu_groups to be indexed by group slug. |
|
| 541 | + $menu_groups = $this->_rearrange_menu_groups(); |
|
| 542 | + foreach ($this->_installed_pages as $page) { |
|
| 543 | + if ($page instanceof EE_Admin_page_Init) { |
|
| 544 | + $page_map = $page->get_menu_map(); |
|
| 545 | + //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
| 546 | + if (is_array($page_map) || empty($page_map)) { |
|
| 547 | + new PersistentAdminNotice( |
|
| 548 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
| 549 | + sprintf( |
|
| 550 | + __( |
|
| 551 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
| 552 | + 'event_espresso' |
|
| 553 | + ), |
|
| 554 | + $page->label |
|
| 555 | + ) |
|
| 556 | + ); |
|
| 557 | + continue; |
|
| 558 | + } |
|
| 559 | + //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
| 560 | + if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __( |
|
| 564 | + 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
| 565 | + 'event_espresso' |
|
| 566 | + ), |
|
| 567 | + $page->label, |
|
| 568 | + $page_map |
|
| 569 | + ) |
|
| 570 | + ); |
|
| 571 | + } |
|
| 572 | + //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
| 573 | + if (empty($page_map->maintenance_mode_parent) |
|
| 574 | + && EE_Maintenance_Mode::instance()->level() |
|
| 575 | + == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 576 | + continue; |
|
| 577 | + } |
|
| 578 | + //assign to group (remember $page_map has the admin page stored in it). |
|
| 579 | + $pages_array[$page_map->menu_group][] = $page_map; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + if (empty($pages_array)) { |
|
| 583 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
| 584 | + } |
|
| 585 | + //let's sort the groups, make sure it's a valid group, add header (if to show). |
|
| 586 | + foreach ($pages_array as $group => $menu_maps) { |
|
| 587 | + //valid_group? |
|
| 588 | + if (! array_key_exists($group, $menu_groups)) { |
|
| 589 | + continue; |
|
| 590 | + } |
|
| 591 | + //sort pages. |
|
| 592 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
| 593 | + //prepend header |
|
| 594 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
| 595 | + //reset $pages_array with prepped data |
|
| 596 | + $pages_array[$group] = $menu_maps; |
|
| 597 | + } |
|
| 598 | + //now let's setup the _prepped_menu_maps property |
|
| 599 | + foreach ($menu_groups as $group => $group_objs) { |
|
| 600 | + if (isset($pages_array[$group])) { |
|
| 601 | + $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]); |
|
| 602 | + } |
|
| 603 | + }/**/ |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
| 609 | + * In this method there are three checks being done: |
|
| 610 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
| 611 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
| 612 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
| 613 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
| 614 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
| 615 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
| 616 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
| 617 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
| 618 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
| 619 | + * admin_pages) |
|
| 620 | + * |
|
| 621 | + * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
| 622 | + * loaded. |
|
| 623 | + * @return array |
|
| 624 | + */ |
|
| 625 | + private function _set_caffeinated($installed_refs) |
|
| 626 | + { |
|
| 627 | + |
|
| 628 | + //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
| 629 | + if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 630 | + return $installed_refs; |
|
| 631 | + } |
|
| 632 | + $this->_define_caffeinated_constants(); |
|
| 633 | + $exclude = array('tickets'); |
|
| 634 | + //okay let's setup an "New" pages first (we'll return installed refs later) |
|
| 635 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
| 636 | + if ($new_admin_screens) { |
|
| 637 | + foreach ($new_admin_screens as $admin_screen) { |
|
| 638 | + // files and anything in the exclude array need not apply |
|
| 639 | + if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) { |
|
| 640 | + // these folders represent the different NEW EE admin pages |
|
| 641 | + $installed_refs[basename($admin_screen)] = $admin_screen; |
|
| 642 | + // set autoloaders for our admin page classes based on included path information |
|
| 643 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen); |
|
| 644 | + // $this->_caf_autoloader[] = array( |
|
| 645 | + // 'dir' => 'new', |
|
| 646 | + // 'folder' => basename( $admin_screen ) |
|
| 647 | + // ); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
| 652 | + $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
| 653 | + if ($extends) { |
|
| 654 | + foreach ($extends as $extend) { |
|
| 655 | + if (is_dir($extend)) { |
|
| 656 | + $extend_ref = basename($extend); |
|
| 657 | + //now let's make sure there is a file that matches the expected format |
|
| 658 | + $filename = str_replace( |
|
| 659 | + ' ', |
|
| 660 | + '_', |
|
| 661 | + ucwords( |
|
| 662 | + str_replace( |
|
| 663 | + '_', |
|
| 664 | + ' ', |
|
| 665 | + $extend_ref |
|
| 666 | + ) |
|
| 667 | + ) |
|
| 668 | + ); |
|
| 669 | + $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
| 670 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
| 671 | + array('\\', '/'), |
|
| 672 | + DS, |
|
| 673 | + EE_CORE_CAF_ADMIN |
|
| 674 | + . 'extend' |
|
| 675 | + . DS |
|
| 676 | + . $extend_ref |
|
| 677 | + . DS |
|
| 678 | + . $filename |
|
| 679 | + . '.core.php' |
|
| 680 | + ); |
|
| 681 | + $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
| 682 | + // set autoloaders for our admin page classes based on included path information |
|
| 683 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend); |
|
| 684 | + // $this->_caf_autoloader[] = array( |
|
| 685 | + // 'dir' => 'extend', |
|
| 686 | + // 'folder' => $extend_ref |
|
| 687 | + // ); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
| 692 | + $ee_admin_hooks = array(); |
|
| 693 | + $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
| 694 | + if ($hooks) { |
|
| 695 | + foreach ($hooks as $hook) { |
|
| 696 | + if (is_readable($hook)) { |
|
| 697 | + require_once $hook; |
|
| 698 | + $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
| 699 | + $classname = str_replace('.class.php', '', $classname); |
|
| 700 | + if (class_exists($classname)) { |
|
| 701 | + $a = new ReflectionClass($classname); |
|
| 702 | + $ee_admin_hooks[] = $a->newInstance(); |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | + }/**/ |
|
| 707 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
| 708 | + return $installed_refs; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * Initial autoloader registration |
|
| 717 | + * This just sets up the autoloader for the root admin files |
|
| 718 | + * |
|
| 719 | + * @param string $className incoming classname to check for autoload |
|
| 720 | + * @return void |
|
| 721 | + */ |
|
| 722 | + // public function init_autoloaders( $className ) { |
|
| 723 | + // $dir_ref = array( |
|
| 724 | + // EE_ADMIN => array('core', 'class') |
|
| 725 | + // ); |
|
| 726 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 727 | + // } |
|
| 728 | + /** |
|
| 729 | + * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the |
|
| 730 | + * caffeinated folders. |
|
| 731 | + * |
|
| 732 | + * @access public |
|
| 733 | + * @param string $className in coming classname being called |
|
| 734 | + * @return void |
|
| 735 | + */ |
|
| 736 | + // public function caffeinated_autoloaders( $className ) { |
|
| 737 | + // //let's setup an array of paths to check (for each subsystem) |
|
| 738 | + // $dir_ref = array(); |
|
| 739 | + // foreach ( $this->_caf_autoloader as $pathinfo) { |
|
| 740 | + // $dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class'); |
|
| 741 | + // } |
|
| 742 | + // |
|
| 743 | + // EEH_Autoloader::try_autoload($dir_ref, $className ); |
|
| 744 | + // } |
|
| 745 | + /** |
|
| 746 | + * Utility method for sorting the _menu_maps (callback for usort php function) |
|
| 747 | + * |
|
| 748 | + * @since 4.4.0 |
|
| 749 | + * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
| 750 | + * @param EE_Admin_Page_Menu_Map $b being compared to |
|
| 751 | + * @return int sort order |
|
| 752 | + */ |
|
| 753 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
| 754 | + { |
|
| 755 | + if ($a->menu_order == $b->menu_order) { |
|
| 756 | + return 0; |
|
| 757 | + } |
|
| 758 | + return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + |
|
| 763 | + /** |
|
| 764 | + * _default_header_link |
|
| 765 | + * This is just a dummy method to use with header submenu items |
|
| 766 | + * |
|
| 767 | + * @return bool false |
|
| 768 | + */ |
|
| 769 | + public function _default_header_link() |
|
| 770 | + { |
|
| 771 | + return false; |
|
| 772 | + } |
|
| 773 | 773 | |
| 774 | 774 | |
| 775 | 775 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
| 3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 4 | 4 | |
| 5 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 6 | 6 | exit('NO direct script access allowed'); |
| 7 | 7 | |
| 8 | 8 | |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | private function _define_caffeinated_constants() |
| 144 | 144 | { |
| 145 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 146 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 147 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 148 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 149 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 150 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 151 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 145 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
| 146 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
| 147 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
| 148 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
| 149 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
| 150 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
| 151 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
| 262 | 262 | usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
| 263 | 263 | foreach ($this->_admin_menu_groups as $group) { |
| 264 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 264 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) { |
|
| 265 | 265 | throw new EE_Error( |
| 266 | 266 | sprintf( |
| 267 | 267 | __( |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | $installed_refs = array(); |
| 293 | 293 | $exclude = array('assets', 'templates'); |
| 294 | 294 | // grab everything in the admin core directory |
| 295 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
| 295 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
| 296 | 296 | if ($admin_screens) { |
| 297 | 297 | foreach ($admin_screens as $admin_screen) { |
| 298 | 298 | // files and anything in the exclude array need not apply |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
| 308 | 308 | 'event_espresso' |
| 309 | 309 | ); |
| 310 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 310 | + $error_msg[] = $error_msg[0]."\r\n".sprintf( |
|
| 311 | 311 | __( |
| 312 | 312 | 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
| 313 | 313 | 'event_espresso' |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
| 320 | 320 | $installed_refs = $this->_set_caffeinated($installed_refs); |
| 321 | 321 | //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
| 322 | - $installed_refs = apply_filters( |
|
| 322 | + $installed_refs = apply_filters( |
|
| 323 | 323 | 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
| 324 | 324 | $installed_refs |
| 325 | 325 | ); |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
| 337 | 337 | // verify returned object |
| 338 | 338 | if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
| 339 | - if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 339 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
| 340 | 340 | continue; |
| 341 | 341 | } |
| 342 | 342 | //skip if in full maintenance mode and maintenance_mode_parent is set |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | ); |
| 366 | 366 | add_filter( |
| 367 | 367 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
| 368 | - function ($admin_page) use ($caf_admin_page) |
|
| 368 | + function($admin_page) use ($caf_admin_page) |
|
| 369 | 369 | { |
| 370 | 370 | return $caf_admin_page; |
| 371 | 371 | } |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | private function _get_classname_for_admin_page($dir_name = '') |
| 425 | 425 | { |
| 426 | 426 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
| 427 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
| 427 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | private function _get_classname_for_admin_init_page($dir_name = '') |
| 440 | 440 | { |
| 441 | 441 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
| 442 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 442 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -457,19 +457,19 @@ discard block |
||
| 457 | 457 | { |
| 458 | 458 | $class_name = $this->_get_classname_for_admin_init_page($page); |
| 459 | 459 | EE_Registry::instance()->load_file($path, $class_name, 'core'); |
| 460 | - if (! class_exists($class_name)) { |
|
| 461 | - $inner_error_msg = '<br />' . sprintf( |
|
| 460 | + if ( ! class_exists($class_name)) { |
|
| 461 | + $inner_error_msg = '<br />'.sprintf( |
|
| 462 | 462 | esc_html__( |
| 463 | 463 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
| 464 | 464 | 'event_espresso' |
| 465 | 465 | ), |
| 466 | - '<strong>' . $class_name . '</strong>' |
|
| 466 | + '<strong>'.$class_name.'</strong>' |
|
| 467 | 467 | ); |
| 468 | - $error_msg[] = sprintf( |
|
| 468 | + $error_msg[] = sprintf( |
|
| 469 | 469 | __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
| 470 | 470 | $page |
| 471 | 471 | ); |
| 472 | - $error_msg[] = $error_msg[0] |
|
| 472 | + $error_msg[] = $error_msg[0] |
|
| 473 | 473 | . "\r\n" |
| 474 | 474 | . sprintf( |
| 475 | 475 | esc_html__( |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
| 546 | 546 | if (is_array($page_map) || empty($page_map)) { |
| 547 | 547 | new PersistentAdminNotice( |
| 548 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
| 548 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
| 549 | 549 | sprintf( |
| 550 | 550 | __( |
| 551 | 551 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | continue; |
| 558 | 558 | } |
| 559 | 559 | //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
| 560 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 560 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
| 561 | 561 | throw new EE_Error( |
| 562 | 562 | sprintf( |
| 563 | 563 | __( |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | //let's sort the groups, make sure it's a valid group, add header (if to show). |
| 586 | 586 | foreach ($pages_array as $group => $menu_maps) { |
| 587 | 587 | //valid_group? |
| 588 | - if (! array_key_exists($group, $menu_groups)) { |
|
| 588 | + if ( ! array_key_exists($group, $menu_groups)) { |
|
| 589 | 589 | continue; |
| 590 | 590 | } |
| 591 | 591 | //sort pages. |
@@ -626,13 +626,13 @@ discard block |
||
| 626 | 626 | { |
| 627 | 627 | |
| 628 | 628 | //first let's check if there IS a caffeinated folder. If there is not then lets get out. |
| 629 | - if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 629 | + if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) { |
|
| 630 | 630 | return $installed_refs; |
| 631 | 631 | } |
| 632 | 632 | $this->_define_caffeinated_constants(); |
| 633 | 633 | $exclude = array('tickets'); |
| 634 | 634 | //okay let's setup an "New" pages first (we'll return installed refs later) |
| 635 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
| 635 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
| 636 | 636 | if ($new_admin_screens) { |
| 637 | 637 | foreach ($new_admin_screens as $admin_screen) { |
| 638 | 638 | // files and anything in the exclude array need not apply |
@@ -649,13 +649,13 @@ discard block |
||
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
| 652 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
| 652 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
| 653 | 653 | if ($extends) { |
| 654 | 654 | foreach ($extends as $extend) { |
| 655 | 655 | if (is_dir($extend)) { |
| 656 | 656 | $extend_ref = basename($extend); |
| 657 | 657 | //now let's make sure there is a file that matches the expected format |
| 658 | - $filename = str_replace( |
|
| 658 | + $filename = str_replace( |
|
| 659 | 659 | ' ', |
| 660 | 660 | '_', |
| 661 | 661 | ucwords( |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | ) |
| 667 | 667 | ) |
| 668 | 668 | ); |
| 669 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
| 669 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
| 670 | 670 | $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
| 671 | 671 | array('\\', '/'), |
| 672 | 672 | DS, |
@@ -690,12 +690,12 @@ discard block |
||
| 690 | 690 | } |
| 691 | 691 | //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
| 692 | 692 | $ee_admin_hooks = array(); |
| 693 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
| 693 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
| 694 | 694 | if ($hooks) { |
| 695 | 695 | foreach ($hooks as $hook) { |
| 696 | 696 | if (is_readable($hook)) { |
| 697 | 697 | require_once $hook; |
| 698 | - $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook); |
|
| 698 | + $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook); |
|
| 699 | 699 | $classname = str_replace('.class.php', '', $classname); |
| 700 | 700 | if (class_exists($classname)) { |
| 701 | 701 | $a = new ReflectionClass($classname); |
@@ -21,132 +21,132 @@ |
||
| 21 | 21 | class RegistryContainer implements ArrayAccess, CountableTraversableAggregate |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array $container |
|
| 26 | - */ |
|
| 27 | - private $container; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * RegistryContainer constructor. |
|
| 31 | - * Container data can be seeded by passing parameters to constructor. |
|
| 32 | - * Each parameter will become its own element in the container |
|
| 33 | - */ |
|
| 34 | - public function __construct() |
|
| 35 | - { |
|
| 36 | - $this->container = func_get_args(); |
|
| 37 | - if (func_num_args() === 0) { |
|
| 38 | - $this->container = array(); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param mixed $offset |
|
| 45 | - * @param mixed $value |
|
| 46 | - */ |
|
| 47 | - public function offsetSet($offset, $value) |
|
| 48 | - { |
|
| 49 | - $this->container[$offset] = $value; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param mixed $offset |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function offsetExists($offset) |
|
| 58 | - { |
|
| 59 | - return isset($this->container[$offset]); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param mixed $offset |
|
| 65 | - */ |
|
| 66 | - public function offsetUnset($offset) |
|
| 67 | - { |
|
| 68 | - unset($this->container[$offset]); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param mixed $offset |
|
| 74 | - * @return mixed|null |
|
| 75 | - */ |
|
| 76 | - public function offsetGet($offset) |
|
| 77 | - { |
|
| 78 | - return isset($this->container[$offset]) ? $this->container[$offset] : null; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function count() |
|
| 86 | - { |
|
| 87 | - return count($this->container); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return ArrayIterator |
|
| 93 | - */ |
|
| 94 | - public function getIterator() |
|
| 95 | - { |
|
| 96 | - return new ArrayIterator($this->container); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param $offset |
|
| 102 | - * @param $value |
|
| 103 | - */ |
|
| 104 | - public function __set($offset, $value) |
|
| 105 | - { |
|
| 106 | - $this->container[$offset] = $value; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param $offset |
|
| 112 | - * @return mixed |
|
| 113 | - * @throws OutOfBoundsException |
|
| 114 | - */ |
|
| 115 | - public function __get($offset) |
|
| 116 | - { |
|
| 117 | - if (array_key_exists($offset, $this->container)) { |
|
| 118 | - return $this->container[$offset]; |
|
| 119 | - } |
|
| 120 | - $trace = debug_backtrace(); |
|
| 121 | - throw new OutOfBoundsException( |
|
| 122 | - sprintf( |
|
| 123 | - esc_html__('Invalid offset: %1$s %2$sCalled from %3$s on line %4$d', 'event_espresso'), |
|
| 124 | - $offset, |
|
| 125 | - '<br />', |
|
| 126 | - $trace[0]['file'], |
|
| 127 | - $trace[0]['line'] |
|
| 128 | - ) |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param $offset |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function __isset($offset) |
|
| 138 | - { |
|
| 139 | - return isset($this->container[$offset]); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param $offset |
|
| 145 | - */ |
|
| 146 | - public function __unset($offset) |
|
| 147 | - { |
|
| 148 | - unset($this->container[$offset]); |
|
| 149 | - } |
|
| 24 | + /** |
|
| 25 | + * @var array $container |
|
| 26 | + */ |
|
| 27 | + private $container; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * RegistryContainer constructor. |
|
| 31 | + * Container data can be seeded by passing parameters to constructor. |
|
| 32 | + * Each parameter will become its own element in the container |
|
| 33 | + */ |
|
| 34 | + public function __construct() |
|
| 35 | + { |
|
| 36 | + $this->container = func_get_args(); |
|
| 37 | + if (func_num_args() === 0) { |
|
| 38 | + $this->container = array(); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param mixed $offset |
|
| 45 | + * @param mixed $value |
|
| 46 | + */ |
|
| 47 | + public function offsetSet($offset, $value) |
|
| 48 | + { |
|
| 49 | + $this->container[$offset] = $value; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param mixed $offset |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function offsetExists($offset) |
|
| 58 | + { |
|
| 59 | + return isset($this->container[$offset]); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param mixed $offset |
|
| 65 | + */ |
|
| 66 | + public function offsetUnset($offset) |
|
| 67 | + { |
|
| 68 | + unset($this->container[$offset]); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param mixed $offset |
|
| 74 | + * @return mixed|null |
|
| 75 | + */ |
|
| 76 | + public function offsetGet($offset) |
|
| 77 | + { |
|
| 78 | + return isset($this->container[$offset]) ? $this->container[$offset] : null; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function count() |
|
| 86 | + { |
|
| 87 | + return count($this->container); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return ArrayIterator |
|
| 93 | + */ |
|
| 94 | + public function getIterator() |
|
| 95 | + { |
|
| 96 | + return new ArrayIterator($this->container); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param $offset |
|
| 102 | + * @param $value |
|
| 103 | + */ |
|
| 104 | + public function __set($offset, $value) |
|
| 105 | + { |
|
| 106 | + $this->container[$offset] = $value; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param $offset |
|
| 112 | + * @return mixed |
|
| 113 | + * @throws OutOfBoundsException |
|
| 114 | + */ |
|
| 115 | + public function __get($offset) |
|
| 116 | + { |
|
| 117 | + if (array_key_exists($offset, $this->container)) { |
|
| 118 | + return $this->container[$offset]; |
|
| 119 | + } |
|
| 120 | + $trace = debug_backtrace(); |
|
| 121 | + throw new OutOfBoundsException( |
|
| 122 | + sprintf( |
|
| 123 | + esc_html__('Invalid offset: %1$s %2$sCalled from %3$s on line %4$d', 'event_espresso'), |
|
| 124 | + $offset, |
|
| 125 | + '<br />', |
|
| 126 | + $trace[0]['file'], |
|
| 127 | + $trace[0]['line'] |
|
| 128 | + ) |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param $offset |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function __isset($offset) |
|
| 138 | + { |
|
| 139 | + return isset($this->container[$offset]); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param $offset |
|
| 145 | + */ |
|
| 146 | + public function __unset($offset) |
|
| 147 | + { |
|
| 148 | + unset($this->container[$offset]); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | // Location: RegistryContainer.php |
@@ -22,102 +22,102 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var LoaderDecoratorInterface $new_loader |
|
| 27 | - */ |
|
| 28 | - private $new_loader; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | - */ |
|
| 34 | - private $shared_loader; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Loader constructor. |
|
| 40 | - * |
|
| 41 | - * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | - * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | - * @throws InvalidInterfaceException |
|
| 44 | - * @throws InvalidArgumentException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | - { |
|
| 49 | - $this->new_loader = $new_loader; |
|
| 50 | - $this->shared_loader = $shared_loader; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return LoaderDecoratorInterface |
|
| 57 | - */ |
|
| 58 | - public function getNewLoader() |
|
| 59 | - { |
|
| 60 | - return $this->new_loader; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return LoaderDecoratorInterface |
|
| 67 | - */ |
|
| 68 | - public function getSharedLoader() |
|
| 69 | - { |
|
| 70 | - return $this->shared_loader; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $fqcn |
|
| 77 | - * @param array $arguments |
|
| 78 | - * @param bool $shared |
|
| 79 | - * @return mixed |
|
| 80 | - */ |
|
| 81 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | - { |
|
| 83 | - return $shared |
|
| 84 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $fqcn |
|
| 92 | - * @param array $arguments |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - public function getNew($fqcn, $arguments = array()) |
|
| 96 | - { |
|
| 97 | - return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $fqcn |
|
| 104 | - * @param array $arguments |
|
| 105 | - * @return mixed |
|
| 106 | - */ |
|
| 107 | - public function getShared($fqcn, $arguments = array()) |
|
| 108 | - { |
|
| 109 | - return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * calls reset() on loaders if that method exists |
|
| 116 | - */ |
|
| 117 | - public function reset() |
|
| 118 | - { |
|
| 119 | - $this->shared_loader->reset(); |
|
| 120 | - } |
|
| 25 | + /** |
|
| 26 | + * @var LoaderDecoratorInterface $new_loader |
|
| 27 | + */ |
|
| 28 | + private $new_loader; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var LoaderDecoratorInterface $shared_loader |
|
| 33 | + */ |
|
| 34 | + private $shared_loader; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Loader constructor. |
|
| 40 | + * |
|
| 41 | + * @param LoaderDecoratorInterface|null $new_loader |
|
| 42 | + * @param LoaderDecoratorInterface|null $shared_loader |
|
| 43 | + * @throws InvalidInterfaceException |
|
| 44 | + * @throws InvalidArgumentException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader) |
|
| 48 | + { |
|
| 49 | + $this->new_loader = $new_loader; |
|
| 50 | + $this->shared_loader = $shared_loader; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return LoaderDecoratorInterface |
|
| 57 | + */ |
|
| 58 | + public function getNewLoader() |
|
| 59 | + { |
|
| 60 | + return $this->new_loader; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return LoaderDecoratorInterface |
|
| 67 | + */ |
|
| 68 | + public function getSharedLoader() |
|
| 69 | + { |
|
| 70 | + return $this->shared_loader; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $fqcn |
|
| 77 | + * @param array $arguments |
|
| 78 | + * @param bool $shared |
|
| 79 | + * @return mixed |
|
| 80 | + */ |
|
| 81 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 82 | + { |
|
| 83 | + return $shared |
|
| 84 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
| 85 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $fqcn |
|
| 92 | + * @param array $arguments |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + public function getNew($fqcn, $arguments = array()) |
|
| 96 | + { |
|
| 97 | + return $this->getNewLoader()->load($fqcn, $arguments, false); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $fqcn |
|
| 104 | + * @param array $arguments |
|
| 105 | + * @return mixed |
|
| 106 | + */ |
|
| 107 | + public function getShared($fqcn, $arguments = array()) |
|
| 108 | + { |
|
| 109 | + return $this->getSharedLoader()->load($fqcn, $arguments, true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * calls reset() on loaders if that method exists |
|
| 116 | + */ |
|
| 117 | + public function reset() |
|
| 118 | + { |
|
| 119 | + $this->shared_loader->reset(); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | // End of file Loader.php |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
| 898 | 898 | * |
| 899 | 899 | * @param string $route the route name we're verifying |
| 900 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 900 | + * @return boolean (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 901 | 901 | * @throws EE_Error |
| 902 | 902 | */ |
| 903 | 903 | protected function _verify_route($route) |
@@ -4039,7 +4039,7 @@ discard block |
||
| 4039 | 4039 | |
| 4040 | 4040 | |
| 4041 | 4041 | /** |
| 4042 | - * @return mixed |
|
| 4042 | + * @return string[] |
|
| 4043 | 4043 | */ |
| 4044 | 4044 | public function default_espresso_metaboxes() |
| 4045 | 4045 | { |
@@ -4059,7 +4059,7 @@ discard block |
||
| 4059 | 4059 | |
| 4060 | 4060 | |
| 4061 | 4061 | /** |
| 4062 | - * @return mixed |
|
| 4062 | + * @return string |
|
| 4063 | 4063 | */ |
| 4064 | 4064 | public function wp_page_slug() |
| 4065 | 4065 | { |
@@ -512,8 +512,8 @@ discard block |
||
| 512 | 512 | str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
| 513 | 513 | ); |
| 514 | 514 | global $ee_menu_slugs; |
| 515 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 516 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 515 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 516 | + if ( ! defined('DOING_AJAX') && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 517 | 517 | return; |
| 518 | 518 | } |
| 519 | 519 | // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | ? $this->_req_data['route'] |
| 538 | 538 | : $this->_req_action; |
| 539 | 539 | $this->_current_view = $this->_req_action; |
| 540 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 540 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 541 | 541 | $this->_define_page_props(); |
| 542 | 542 | $this->_current_page_view_url = add_query_arg( |
| 543 | 543 | array('page' => $this->_current_page, 'action' => $this->_current_view), |
@@ -571,23 +571,23 @@ discard block |
||
| 571 | 571 | } |
| 572 | 572 | //filter routes and page_config so addons can add their stuff. Filtering done per class |
| 573 | 573 | $this->_page_routes = apply_filters( |
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 574 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 575 | 575 | $this->_page_routes, |
| 576 | 576 | $this |
| 577 | 577 | ); |
| 578 | 578 | $this->_page_config = apply_filters( |
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 579 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 580 | 580 | $this->_page_config, |
| 581 | 581 | $this |
| 582 | 582 | ); |
| 583 | 583 | //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 584 | 584 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 585 | 585 | if ( |
| 586 | - method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 586 | + method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view) |
|
| 587 | 587 | ) { |
| 588 | 588 | add_action( |
| 589 | 589 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 590 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 590 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), |
|
| 591 | 591 | 10, |
| 592 | 592 | 2 |
| 593 | 593 | ); |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | if ($this->_is_UI_request) { |
| 601 | 601 | //admin_init stuff - global, all views for this page class, specific view |
| 602 | 602 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 603 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 604 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 603 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 604 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 605 | 605 | } |
| 606 | 606 | } else { |
| 607 | 607 | //hijack regular WP loading and route admin request immediately |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | private function _do_other_page_hooks() |
| 624 | 624 | { |
| 625 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 625 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 626 | 626 | foreach ($registered_pages as $page) { |
| 627 | 627 | //now let's setup the file name and class that should be present |
| 628 | 628 | $classname = str_replace('.class.php', '', $page); |
| 629 | 629 | //autoloaders should take care of loading file |
| 630 | - if (! class_exists($classname)) { |
|
| 630 | + if ( ! class_exists($classname)) { |
|
| 631 | 631 | $error_msg[] = sprintf( |
| 632 | 632 | esc_html__( |
| 633 | 633 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | ), |
| 645 | 645 | $page, |
| 646 | 646 | '<br />', |
| 647 | - '<strong>' . $classname . '</strong>' |
|
| 647 | + '<strong>'.$classname.'</strong>' |
|
| 648 | 648 | ); |
| 649 | 649 | throw new EE_Error(implode('||', $error_msg)); |
| 650 | 650 | } |
@@ -686,13 +686,13 @@ discard block |
||
| 686 | 686 | //load admin_notices - global, page class, and view specific |
| 687 | 687 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 688 | 688 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 689 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 690 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 689 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 690 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 691 | 691 | } |
| 692 | 692 | //load network admin_notices - global, page class, and view specific |
| 693 | 693 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 694 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 695 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 694 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 695 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 696 | 696 | } |
| 697 | 697 | //this will save any per_page screen options if they are present |
| 698 | 698 | $this->_set_per_page_screen_options(); |
@@ -705,8 +705,8 @@ discard block |
||
| 705 | 705 | //add screen options - global, page child class, and view specific |
| 706 | 706 | $this->_add_global_screen_options(); |
| 707 | 707 | $this->_add_screen_options(); |
| 708 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 709 | - if (method_exists($this, $add_screen_options )) { |
|
| 708 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 709 | + if (method_exists($this, $add_screen_options)) { |
|
| 710 | 710 | $this->{$add_screen_options}(); |
| 711 | 711 | } |
| 712 | 712 | //add help tab(s) and tours- set via page_config and qtips. |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | $this->_add_feature_pointers(); |
| 718 | 718 | $this->_add_global_feature_pointers(); |
| 719 | 719 | $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
| 720 | - if (method_exists($this, $add_feature_pointer )) { |
|
| 720 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 721 | 721 | $this->{$add_feature_pointer}(); |
| 722 | 722 | } |
| 723 | 723 | //enqueue scripts/styles - global, page class, and view specific |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | protected function _verify_routes() |
| 820 | 820 | { |
| 821 | 821 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 822 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 822 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 823 | 823 | return false; |
| 824 | 824 | } |
| 825 | 825 | $this->_route = false; |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | $this->_admin_page_title |
| 832 | 832 | ); |
| 833 | 833 | // developer error msg |
| 834 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 834 | + $error_msg .= '||'.$error_msg.esc_html__( |
|
| 835 | 835 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 836 | 836 | 'event_espresso' |
| 837 | 837 | ); |
@@ -852,7 +852,7 @@ discard block |
||
| 852 | 852 | $this->_admin_page_title |
| 853 | 853 | ); |
| 854 | 854 | // developer error msg |
| 855 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 855 | + $error_msg .= '||'.$error_msg.sprintf( |
|
| 856 | 856 | esc_html__( |
| 857 | 857 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
| 858 | 858 | 'event_espresso' |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | throw new EE_Error($error_msg); |
| 863 | 863 | } |
| 864 | 864 | // and that a default route exists |
| 865 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 865 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 866 | 866 | // user error msg |
| 867 | 867 | $error_msg = sprintf( |
| 868 | 868 | esc_html__( |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | $this->_admin_page_title |
| 873 | 873 | ); |
| 874 | 874 | // developer error msg |
| 875 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 875 | + $error_msg .= '||'.$error_msg.esc_html__( |
|
| 876 | 876 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 877 | 877 | 'event_espresso' |
| 878 | 878 | ); |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | $this->_admin_page_title |
| 912 | 912 | ); |
| 913 | 913 | // developer error msg |
| 914 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 914 | + $error_msg .= '||'.$error_msg.sprintf( |
|
| 915 | 915 | esc_html__( |
| 916 | 916 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
| 917 | 917 | 'event_espresso' |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | protected function _verify_nonce($nonce, $nonce_ref) |
| 937 | 937 | { |
| 938 | 938 | // verify nonce against expected value |
| 939 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 939 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 940 | 940 | // these are not the droids you are looking for !!! |
| 941 | 941 | $msg = sprintf( |
| 942 | 942 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | '</a>' |
| 945 | 945 | ); |
| 946 | 946 | if (WP_DEBUG) { |
| 947 | - $msg .= "\n " . sprintf( |
|
| 947 | + $msg .= "\n ".sprintf( |
|
| 948 | 948 | esc_html__( |
| 949 | 949 | 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
| 950 | 950 | 'event_espresso' |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | __CLASS__ |
| 953 | 953 | ); |
| 954 | 954 | } |
| 955 | - if (! defined('DOING_AJAX')) { |
|
| 955 | + if ( ! defined('DOING_AJAX')) { |
|
| 956 | 956 | wp_die($msg); |
| 957 | 957 | } else { |
| 958 | 958 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | */ |
| 979 | 979 | protected function _route_admin_request() |
| 980 | 980 | { |
| 981 | - if (! $this->_is_UI_request) { |
|
| 981 | + if ( ! $this->_is_UI_request) { |
|
| 982 | 982 | $this->_verify_routes(); |
| 983 | 983 | } |
| 984 | 984 | $nonce_check = isset($this->_route_config['require_nonce']) |
@@ -1002,7 +1002,7 @@ discard block |
||
| 1002 | 1002 | $error_msg = ''; |
| 1003 | 1003 | // action right before calling route |
| 1004 | 1004 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 1005 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1005 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1006 | 1006 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 1007 | 1007 | } |
| 1008 | 1008 | // right before calling the route, let's remove _wp_http_referer from the |
@@ -1011,7 +1011,7 @@ discard block |
||
| 1011 | 1011 | '_wp_http_referer', |
| 1012 | 1012 | wp_unslash($_SERVER['REQUEST_URI']) |
| 1013 | 1013 | ); |
| 1014 | - if (! empty($func)) { |
|
| 1014 | + if ( ! empty($func)) { |
|
| 1015 | 1015 | if (is_array($func)) { |
| 1016 | 1016 | list($class, $method) = $func; |
| 1017 | 1017 | } elseif (strpos($func, '::') !== false) { |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | $class = $this; |
| 1021 | 1021 | $method = $func; |
| 1022 | 1022 | } |
| 1023 | - if (! (is_object($class) && $class === $this)) { |
|
| 1023 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1024 | 1024 | // send along this admin page object for access by addons. |
| 1025 | 1025 | $args['admin_page_object'] = $this; |
| 1026 | 1026 | } |
@@ -1061,7 +1061,7 @@ discard block |
||
| 1061 | 1061 | $method |
| 1062 | 1062 | ); |
| 1063 | 1063 | } |
| 1064 | - if (! empty($error_msg)) { |
|
| 1064 | + if ( ! empty($error_msg)) { |
|
| 1065 | 1065 | throw new EE_Error($error_msg); |
| 1066 | 1066 | } |
| 1067 | 1067 | } |
@@ -1147,7 +1147,7 @@ discard block |
||
| 1147 | 1147 | if (strpos($key, 'nonce') !== false) { |
| 1148 | 1148 | continue; |
| 1149 | 1149 | } |
| 1150 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 1150 | + $args['wp_referer['.$key.']'] = $value; |
|
| 1151 | 1151 | } |
| 1152 | 1152 | } |
| 1153 | 1153 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1212,7 +1212,7 @@ discard block |
||
| 1212 | 1212 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1213 | 1213 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1214 | 1214 | //check that the callback given is valid |
| 1215 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1215 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1216 | 1216 | throw new EE_Error( |
| 1217 | 1217 | sprintf( |
| 1218 | 1218 | esc_html__( |
@@ -1225,7 +1225,7 @@ discard block |
||
| 1225 | 1225 | ); |
| 1226 | 1226 | } |
| 1227 | 1227 | $content = apply_filters( |
| 1228 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1228 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1229 | 1229 | $this->{$config['help_sidebar']}() |
| 1230 | 1230 | ); |
| 1231 | 1231 | $content .= $tour_buttons; //add help tour buttons. |
@@ -1233,26 +1233,26 @@ discard block |
||
| 1233 | 1233 | $this->_current_screen->set_help_sidebar($content); |
| 1234 | 1234 | } |
| 1235 | 1235 | //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
| 1236 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1236 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1237 | 1237 | $this->_current_screen->set_help_sidebar($tour_buttons); |
| 1238 | 1238 | } |
| 1239 | 1239 | //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
| 1240 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1240 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1241 | 1241 | $_ht['id'] = $this->page_slug; |
| 1242 | 1242 | $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
| 1243 | - $_ht['content'] = '<p>' . esc_html__( |
|
| 1243 | + $_ht['content'] = '<p>'.esc_html__( |
|
| 1244 | 1244 | 'The buttons to the right allow you to start/restart any help tours available for this page', |
| 1245 | 1245 | 'event_espresso' |
| 1246 | - ) . '</p>'; |
|
| 1246 | + ).'</p>'; |
|
| 1247 | 1247 | $this->_current_screen->add_help_tab($_ht); |
| 1248 | 1248 | } |
| 1249 | - if (! isset($config['help_tabs'])) { |
|
| 1249 | + if ( ! isset($config['help_tabs'])) { |
|
| 1250 | 1250 | return; |
| 1251 | 1251 | } //no help tabs for this route |
| 1252 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1252 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1253 | 1253 | //we're here so there ARE help tabs! |
| 1254 | 1254 | //make sure we've got what we need |
| 1255 | - if (! isset($cfg['title'])) { |
|
| 1255 | + if ( ! isset($cfg['title'])) { |
|
| 1256 | 1256 | throw new EE_Error( |
| 1257 | 1257 | esc_html__( |
| 1258 | 1258 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | ) |
| 1261 | 1261 | ); |
| 1262 | 1262 | } |
| 1263 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1263 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1264 | 1264 | throw new EE_Error( |
| 1265 | 1265 | esc_html__( |
| 1266 | 1266 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1269,11 +1269,11 @@ discard block |
||
| 1269 | 1269 | ); |
| 1270 | 1270 | } |
| 1271 | 1271 | //first priority goes to content. |
| 1272 | - if (! empty($cfg['content'])) { |
|
| 1272 | + if ( ! empty($cfg['content'])) { |
|
| 1273 | 1273 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1274 | 1274 | //second priority goes to filename |
| 1275 | - } elseif (! empty($cfg['filename'])) { |
|
| 1276 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1275 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1276 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1277 | 1277 | //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
| 1278 | 1278 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1279 | 1279 | . basename($this->_get_dir()) |
@@ -1281,7 +1281,7 @@ discard block |
||
| 1281 | 1281 | . $cfg['filename'] |
| 1282 | 1282 | . '.help_tab.php' : $file_path; |
| 1283 | 1283 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1284 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1284 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1285 | 1285 | EE_Error::add_error( |
| 1286 | 1286 | sprintf( |
| 1287 | 1287 | esc_html__( |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | return; |
| 1329 | 1329 | } |
| 1330 | 1330 | //setup config array for help tab method |
| 1331 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1331 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1332 | 1332 | $_ht = array( |
| 1333 | 1333 | 'id' => $id, |
| 1334 | 1334 | 'title' => $cfg['title'], |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | } |
| 1374 | 1374 | if (isset($config['help_tour'])) { |
| 1375 | 1375 | foreach ($config['help_tour'] as $tour) { |
| 1376 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1376 | + $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php'; |
|
| 1377 | 1377 | // let's see if we can get that file... |
| 1378 | 1378 | // if not its possible this is a decaf route not set in caffeinated |
| 1379 | 1379 | // so lets try and get the caffeinated equivalent |
@@ -1383,7 +1383,7 @@ discard block |
||
| 1383 | 1383 | . $tour |
| 1384 | 1384 | . '.class.php' : $file_path; |
| 1385 | 1385 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1386 | - if (! is_readable($file_path)) { |
|
| 1386 | + if ( ! is_readable($file_path)) { |
|
| 1387 | 1387 | EE_Error::add_error( |
| 1388 | 1388 | sprintf( |
| 1389 | 1389 | esc_html__( |
@@ -1400,12 +1400,12 @@ discard block |
||
| 1400 | 1400 | return; |
| 1401 | 1401 | } |
| 1402 | 1402 | require_once $file_path; |
| 1403 | - if (! class_exists($tour)) { |
|
| 1403 | + if ( ! class_exists($tour)) { |
|
| 1404 | 1404 | $error_msg[] = sprintf( |
| 1405 | 1405 | esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
| 1406 | 1406 | $tour |
| 1407 | 1407 | ); |
| 1408 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1408 | + $error_msg[] = $error_msg[0]."\r\n".sprintf( |
|
| 1409 | 1409 | esc_html__( |
| 1410 | 1410 | 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
| 1411 | 1411 | 'event_espresso' |
@@ -1428,7 +1428,7 @@ discard block |
||
| 1428 | 1428 | $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
| 1429 | 1429 | } |
| 1430 | 1430 | } |
| 1431 | - if (! empty($tours)) { |
|
| 1431 | + if ( ! empty($tours)) { |
|
| 1432 | 1432 | $this->_help_tour['tours'] = $tours; |
| 1433 | 1433 | } |
| 1434 | 1434 | // that's it! Now that the $_help_tours property is set (or not) |
@@ -1445,11 +1445,11 @@ discard block |
||
| 1445 | 1445 | protected function _add_qtips() |
| 1446 | 1446 | { |
| 1447 | 1447 | if (isset($this->_route_config['qtips'])) { |
| 1448 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1448 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1449 | 1449 | //load qtip loader |
| 1450 | 1450 | $path = array( |
| 1451 | - $this->_get_dir() . '/qtips/', |
|
| 1452 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1451 | + $this->_get_dir().'/qtips/', |
|
| 1452 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1453 | 1453 | ); |
| 1454 | 1454 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1455 | 1455 | } |
@@ -1490,11 +1490,11 @@ discard block |
||
| 1490 | 1490 | // nav tab is only to appear when route requested. |
| 1491 | 1491 | continue; |
| 1492 | 1492 | } |
| 1493 | - if (! $this->check_user_access($slug, true)) { |
|
| 1493 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1494 | 1494 | // no nav tab because current user does not have access. |
| 1495 | 1495 | continue; |
| 1496 | 1496 | } |
| 1497 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1497 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1498 | 1498 | $this->_nav_tabs[$slug] = array( |
| 1499 | 1499 | 'url' => isset($config['nav']['url']) |
| 1500 | 1500 | ? $config['nav']['url'] |
@@ -1507,7 +1507,7 @@ discard block |
||
| 1507 | 1507 | : ucwords( |
| 1508 | 1508 | str_replace('_', ' ', $slug) |
| 1509 | 1509 | ), |
| 1510 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1510 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1511 | 1511 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1512 | 1512 | ); |
| 1513 | 1513 | $i++; |
@@ -1690,7 +1690,7 @@ discard block |
||
| 1690 | 1690 | public function admin_footer_global() |
| 1691 | 1691 | { |
| 1692 | 1692 | //dialog container for dialog helper |
| 1693 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1693 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1694 | 1694 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1695 | 1695 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1696 | 1696 | $d_cont .= '</div>'; |
@@ -1700,7 +1700,7 @@ discard block |
||
| 1700 | 1700 | echo implode('<br />', $this->_help_tour[$this->_req_action]); |
| 1701 | 1701 | } |
| 1702 | 1702 | //current set timezone for timezone js |
| 1703 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1703 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | |
@@ -1735,7 +1735,7 @@ discard block |
||
| 1735 | 1735 | //loop through the array and setup content |
| 1736 | 1736 | foreach ($help_array as $trigger => $help) { |
| 1737 | 1737 | //make sure the array is setup properly |
| 1738 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1738 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1739 | 1739 | throw new EE_Error( |
| 1740 | 1740 | esc_html__( |
| 1741 | 1741 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1749,8 +1749,8 @@ discard block |
||
| 1749 | 1749 | 'help_popup_title' => $help['title'], |
| 1750 | 1750 | 'help_popup_content' => $help['content'], |
| 1751 | 1751 | ); |
| 1752 | - $content .= EEH_Template::display_template( |
|
| 1753 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1752 | + $content .= EEH_Template::display_template( |
|
| 1753 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1754 | 1754 | $template_args, |
| 1755 | 1755 | true |
| 1756 | 1756 | ); |
@@ -1773,15 +1773,15 @@ discard block |
||
| 1773 | 1773 | private function _get_help_content() |
| 1774 | 1774 | { |
| 1775 | 1775 | //what is the method we're looking for? |
| 1776 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1776 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1777 | 1777 | //if method doesn't exist let's get out. |
| 1778 | - if (! method_exists($this, $method_name)) { |
|
| 1778 | + if ( ! method_exists($this, $method_name)) { |
|
| 1779 | 1779 | return array(); |
| 1780 | 1780 | } |
| 1781 | 1781 | //k we're good to go let's retrieve the help array |
| 1782 | 1782 | $help_array = call_user_func(array($this, $method_name)); |
| 1783 | 1783 | //make sure we've got an array! |
| 1784 | - if (! is_array($help_array)) { |
|
| 1784 | + if ( ! is_array($help_array)) { |
|
| 1785 | 1785 | throw new EE_Error( |
| 1786 | 1786 | esc_html__( |
| 1787 | 1787 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | 'event_espresso' |
| 1823 | 1823 | ), |
| 1824 | 1824 | ); |
| 1825 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1825 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1826 | 1826 | } |
| 1827 | 1827 | //let's setup the trigger |
| 1828 | 1828 | $content = '<a class="ee-dialog" href="?height=' |
@@ -1894,15 +1894,15 @@ discard block |
||
| 1894 | 1894 | // register all styles |
| 1895 | 1895 | wp_register_style( |
| 1896 | 1896 | 'espresso-ui-theme', |
| 1897 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1897 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1898 | 1898 | array(), |
| 1899 | 1899 | EVENT_ESPRESSO_VERSION |
| 1900 | 1900 | ); |
| 1901 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1901 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1902 | 1902 | //helpers styles |
| 1903 | 1903 | wp_register_style( |
| 1904 | 1904 | 'ee-text-links', |
| 1905 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1905 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
| 1906 | 1906 | array(), |
| 1907 | 1907 | EVENT_ESPRESSO_VERSION |
| 1908 | 1908 | ); |
@@ -1910,21 +1910,21 @@ discard block |
||
| 1910 | 1910 | //register all scripts |
| 1911 | 1911 | wp_register_script( |
| 1912 | 1912 | 'ee-dialog', |
| 1913 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1913 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 1914 | 1914 | array('jquery', 'jquery-ui-draggable'), |
| 1915 | 1915 | EVENT_ESPRESSO_VERSION, |
| 1916 | 1916 | true |
| 1917 | 1917 | ); |
| 1918 | 1918 | wp_register_script( |
| 1919 | 1919 | 'ee_admin_js', |
| 1920 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1920 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 1921 | 1921 | array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
| 1922 | 1922 | EVENT_ESPRESSO_VERSION, |
| 1923 | 1923 | true |
| 1924 | 1924 | ); |
| 1925 | 1925 | wp_register_script( |
| 1926 | 1926 | 'jquery-ui-timepicker-addon', |
| 1927 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1927 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
| 1928 | 1928 | array('jquery-ui-datepicker', 'jquery-ui-slider'), |
| 1929 | 1929 | EVENT_ESPRESSO_VERSION, |
| 1930 | 1930 | true |
@@ -1933,7 +1933,7 @@ discard block |
||
| 1933 | 1933 | //script for sorting tables |
| 1934 | 1934 | wp_register_script( |
| 1935 | 1935 | 'espresso_ajax_table_sorting', |
| 1936 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1936 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 1937 | 1937 | array('ee_admin_js', 'jquery-ui-sortable'), |
| 1938 | 1938 | EVENT_ESPRESSO_VERSION, |
| 1939 | 1939 | true |
@@ -1941,7 +1941,7 @@ discard block |
||
| 1941 | 1941 | //script for parsing uri's |
| 1942 | 1942 | wp_register_script( |
| 1943 | 1943 | 'ee-parse-uri', |
| 1944 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1944 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
| 1945 | 1945 | array(), |
| 1946 | 1946 | EVENT_ESPRESSO_VERSION, |
| 1947 | 1947 | true |
@@ -1949,7 +1949,7 @@ discard block |
||
| 1949 | 1949 | //and parsing associative serialized form elements |
| 1950 | 1950 | wp_register_script( |
| 1951 | 1951 | 'ee-serialize-full-array', |
| 1952 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1952 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 1953 | 1953 | array('jquery'), |
| 1954 | 1954 | EVENT_ESPRESSO_VERSION, |
| 1955 | 1955 | true |
@@ -1957,28 +1957,28 @@ discard block |
||
| 1957 | 1957 | //helpers scripts |
| 1958 | 1958 | wp_register_script( |
| 1959 | 1959 | 'ee-text-links', |
| 1960 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1960 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 1961 | 1961 | array('jquery'), |
| 1962 | 1962 | EVENT_ESPRESSO_VERSION, |
| 1963 | 1963 | true |
| 1964 | 1964 | ); |
| 1965 | 1965 | wp_register_script( |
| 1966 | 1966 | 'ee-moment-core', |
| 1967 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1967 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
| 1968 | 1968 | array(), |
| 1969 | 1969 | EVENT_ESPRESSO_VERSION, |
| 1970 | 1970 | true |
| 1971 | 1971 | ); |
| 1972 | 1972 | wp_register_script( |
| 1973 | 1973 | 'ee-moment', |
| 1974 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1974 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 1975 | 1975 | array('ee-moment-core'), |
| 1976 | 1976 | EVENT_ESPRESSO_VERSION, |
| 1977 | 1977 | true |
| 1978 | 1978 | ); |
| 1979 | 1979 | wp_register_script( |
| 1980 | 1980 | 'ee-datepicker', |
| 1981 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1981 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 1982 | 1982 | array('jquery-ui-timepicker-addon', 'ee-moment'), |
| 1983 | 1983 | EVENT_ESPRESSO_VERSION, |
| 1984 | 1984 | true |
@@ -2013,11 +2013,11 @@ discard block |
||
| 2013 | 2013 | /** |
| 2014 | 2014 | * help tour stuff |
| 2015 | 2015 | */ |
| 2016 | - if (! empty($this->_help_tour)) { |
|
| 2016 | + if ( ! empty($this->_help_tour)) { |
|
| 2017 | 2017 | //register the js for kicking things off |
| 2018 | 2018 | wp_enqueue_script( |
| 2019 | 2019 | 'ee-help-tour', |
| 2020 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2020 | + EE_ADMIN_URL.'assets/ee-help-tour.js', |
|
| 2021 | 2021 | array('jquery-joyride'), |
| 2022 | 2022 | EVENT_ESPRESSO_VERSION, |
| 2023 | 2023 | true |
@@ -2116,19 +2116,19 @@ discard block |
||
| 2116 | 2116 | protected function _set_list_table() |
| 2117 | 2117 | { |
| 2118 | 2118 | //first is this a list_table view? |
| 2119 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2119 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 2120 | 2120 | return; |
| 2121 | 2121 | } //not a list_table view so get out. |
| 2122 | 2122 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 2123 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2124 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2123 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 2124 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2125 | 2125 | //user error msg |
| 2126 | 2126 | $error_msg = esc_html__( |
| 2127 | 2127 | 'An error occurred. The requested list table views could not be found.', |
| 2128 | 2128 | 'event_espresso' |
| 2129 | 2129 | ); |
| 2130 | 2130 | //developer error msg |
| 2131 | - $error_msg .= '||' . sprintf( |
|
| 2131 | + $error_msg .= '||'.sprintf( |
|
| 2132 | 2132 | esc_html__( |
| 2133 | 2133 | 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
| 2134 | 2134 | 'event_espresso' |
@@ -2140,10 +2140,10 @@ discard block |
||
| 2140 | 2140 | } |
| 2141 | 2141 | //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2142 | 2142 | $this->_views = apply_filters( |
| 2143 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2143 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2144 | 2144 | $this->_views |
| 2145 | 2145 | ); |
| 2146 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2146 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2147 | 2147 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2148 | 2148 | $this->_set_list_table_view(); |
| 2149 | 2149 | $this->_set_list_table_object(); |
@@ -2160,7 +2160,7 @@ discard block |
||
| 2160 | 2160 | { |
| 2161 | 2161 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2162 | 2162 | // looking at active items or dumpster diving ? |
| 2163 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2163 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2164 | 2164 | $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
| 2165 | 2165 | } else { |
| 2166 | 2166 | $this->_view = sanitize_key($this->_req_data['status']); |
@@ -2178,7 +2178,7 @@ discard block |
||
| 2178 | 2178 | protected function _set_list_table_object() |
| 2179 | 2179 | { |
| 2180 | 2180 | if (isset($this->_route_config['list_table'])) { |
| 2181 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2181 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2182 | 2182 | throw new EE_Error( |
| 2183 | 2183 | sprintf( |
| 2184 | 2184 | esc_html__( |
@@ -2217,7 +2217,7 @@ discard block |
||
| 2217 | 2217 | // check for current view |
| 2218 | 2218 | $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
| 2219 | 2219 | $query_args['action'] = $this->_req_action; |
| 2220 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2220 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2221 | 2221 | $query_args['status'] = $view['slug']; |
| 2222 | 2222 | //merge any other arguments sent in. |
| 2223 | 2223 | if (isset($extra_query_args[$view['slug']])) { |
@@ -2243,7 +2243,7 @@ discard block |
||
| 2243 | 2243 | { |
| 2244 | 2244 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2245 | 2245 | $values = array(10, 25, 50, 100); |
| 2246 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2246 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2247 | 2247 | if ($max_entries) { |
| 2248 | 2248 | $values[] = $max_entries; |
| 2249 | 2249 | sort($values); |
@@ -2255,14 +2255,14 @@ discard block |
||
| 2255 | 2255 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2256 | 2256 | foreach ($values as $value) { |
| 2257 | 2257 | if ($value < $max_entries) { |
| 2258 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2258 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2259 | 2259 | $entries_per_page_dropdown .= ' |
| 2260 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2260 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2261 | 2261 | } |
| 2262 | 2262 | } |
| 2263 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2263 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2264 | 2264 | $entries_per_page_dropdown .= ' |
| 2265 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2265 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2266 | 2266 | $entries_per_page_dropdown .= ' |
| 2267 | 2267 | </select> |
| 2268 | 2268 | entries |
@@ -2287,7 +2287,7 @@ discard block |
||
| 2287 | 2287 | empty($this->_search_btn_label) ? $this->page_label |
| 2288 | 2288 | : $this->_search_btn_label |
| 2289 | 2289 | ); |
| 2290 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2290 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2291 | 2291 | } |
| 2292 | 2292 | |
| 2293 | 2293 | |
@@ -2332,7 +2332,7 @@ discard block |
||
| 2332 | 2332 | 'event_espresso' |
| 2333 | 2333 | ); |
| 2334 | 2334 | // developer error msg |
| 2335 | - $error_msg .= '||' . sprintf( |
|
| 2335 | + $error_msg .= '||'.sprintf( |
|
| 2336 | 2336 | esc_html__( |
| 2337 | 2337 | 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
| 2338 | 2338 | 'event_espresso' |
@@ -2365,17 +2365,17 @@ discard block |
||
| 2365 | 2365 | add_screen_option( |
| 2366 | 2366 | 'layout_columns', |
| 2367 | 2367 | array( |
| 2368 | - 'max' => (int)$this->_route_config['columns'][0], |
|
| 2369 | - 'default' => (int)$this->_route_config['columns'][1], |
|
| 2368 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2369 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2370 | 2370 | ) |
| 2371 | 2371 | ); |
| 2372 | 2372 | $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
| 2373 | 2373 | $screen_id = $this->_current_screen->id; |
| 2374 | - $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2374 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2375 | 2375 | $total_columns = ! empty($screen_columns) |
| 2376 | 2376 | ? $screen_columns |
| 2377 | 2377 | : $this->_route_config['columns'][1]; |
| 2378 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2378 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2379 | 2379 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2380 | 2380 | $this->_template_args['screen'] = $this->_current_screen; |
| 2381 | 2381 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2421,7 +2421,7 @@ discard block |
||
| 2421 | 2421 | */ |
| 2422 | 2422 | protected function _espresso_ratings_request() |
| 2423 | 2423 | { |
| 2424 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2424 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2425 | 2425 | return; |
| 2426 | 2426 | } |
| 2427 | 2427 | $ratings_box_title = apply_filters( |
@@ -2450,7 +2450,7 @@ discard block |
||
| 2450 | 2450 | public function espresso_ratings_request() |
| 2451 | 2451 | { |
| 2452 | 2452 | EEH_Template::display_template( |
| 2453 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2453 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
| 2454 | 2454 | array() |
| 2455 | 2455 | ); |
| 2456 | 2456 | } |
@@ -2459,22 +2459,22 @@ discard block |
||
| 2459 | 2459 | |
| 2460 | 2460 | public static function cached_rss_display($rss_id, $url) |
| 2461 | 2461 | { |
| 2462 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2462 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2463 | 2463 | . __('Loading…') |
| 2464 | 2464 | . '</p><p class="hide-if-js">' |
| 2465 | 2465 | . esc_html__('This widget requires JavaScript.') |
| 2466 | 2466 | . '</p>'; |
| 2467 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2468 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2469 | - $post = '</div>' . "\n"; |
|
| 2470 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2467 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2468 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 2469 | + $post = '</div>'."\n"; |
|
| 2470 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2471 | 2471 | $output = get_transient($cache_key); |
| 2472 | 2472 | if ($output !== false) { |
| 2473 | - echo $pre . $output . $post; |
|
| 2473 | + echo $pre.$output.$post; |
|
| 2474 | 2474 | return true; |
| 2475 | 2475 | } |
| 2476 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2477 | - echo $pre . $loading . $post; |
|
| 2476 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2477 | + echo $pre.$loading.$post; |
|
| 2478 | 2478 | return false; |
| 2479 | 2479 | } |
| 2480 | 2480 | ob_start(); |
@@ -2546,7 +2546,7 @@ discard block |
||
| 2546 | 2546 | public function espresso_sponsors_post_box() |
| 2547 | 2547 | { |
| 2548 | 2548 | EEH_Template::display_template( |
| 2549 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2549 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2550 | 2550 | ); |
| 2551 | 2551 | } |
| 2552 | 2552 | |
@@ -2554,11 +2554,11 @@ discard block |
||
| 2554 | 2554 | |
| 2555 | 2555 | private function _publish_post_box() |
| 2556 | 2556 | { |
| 2557 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2557 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2558 | 2558 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2559 | 2559 | // then we'll use that for the metabox label. |
| 2560 | 2560 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2561 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2561 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2562 | 2562 | $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
| 2563 | 2563 | : $this->_labels['publishbox']; |
| 2564 | 2564 | } else { |
@@ -2589,7 +2589,7 @@ discard block |
||
| 2589 | 2589 | ? $this->_template_args['publish_box_extra_content'] |
| 2590 | 2590 | : ''; |
| 2591 | 2591 | echo EEH_Template::display_template( |
| 2592 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2592 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2593 | 2593 | $this->_template_args, |
| 2594 | 2594 | true |
| 2595 | 2595 | ); |
@@ -2683,12 +2683,12 @@ discard block |
||
| 2683 | 2683 | ); |
| 2684 | 2684 | } |
| 2685 | 2685 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2686 | - if (! empty($name) && ! empty($id)) { |
|
| 2686 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2687 | 2687 | $hidden_field_arr[$name] = array( |
| 2688 | 2688 | 'type' => 'hidden', |
| 2689 | 2689 | 'value' => $id, |
| 2690 | 2690 | ); |
| 2691 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2691 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2692 | 2692 | } else { |
| 2693 | 2693 | $hf = ''; |
| 2694 | 2694 | } |
@@ -2803,7 +2803,7 @@ discard block |
||
| 2803 | 2803 | } |
| 2804 | 2804 | //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
| 2805 | 2805 | $call_back_func = $create_func |
| 2806 | - ? function ($post, $metabox) |
|
| 2806 | + ? function($post, $metabox) |
|
| 2807 | 2807 | { |
| 2808 | 2808 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2809 | 2809 | echo EEH_Template::display_template( |
@@ -2814,7 +2814,7 @@ discard block |
||
| 2814 | 2814 | } |
| 2815 | 2815 | : $callback; |
| 2816 | 2816 | add_meta_box( |
| 2817 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2817 | + str_replace('_', '-', $action).'-mbox', |
|
| 2818 | 2818 | $title, |
| 2819 | 2819 | $call_back_func, |
| 2820 | 2820 | $this->_wp_page_slug, |
@@ -2911,9 +2911,9 @@ discard block |
||
| 2911 | 2911 | : 'espresso-default-admin'; |
| 2912 | 2912 | $template_path = $sidebar |
| 2913 | 2913 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2914 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2914 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2915 | 2915 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2916 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2916 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2917 | 2917 | } |
| 2918 | 2918 | $template_path = ! empty($this->_column_template_path) |
| 2919 | 2919 | ? $this->_column_template_path : $template_path; |
@@ -2954,11 +2954,11 @@ discard block |
||
| 2954 | 2954 | public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
| 2955 | 2955 | { |
| 2956 | 2956 | //let's generate a default preview action button if there isn't one already present. |
| 2957 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2957 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2958 | 2958 | 'Upgrade to Event Espresso 4 Right Now', |
| 2959 | 2959 | 'event_espresso' |
| 2960 | 2960 | ); |
| 2961 | - $buy_now_url = add_query_arg( |
|
| 2961 | + $buy_now_url = add_query_arg( |
|
| 2962 | 2962 | array( |
| 2963 | 2963 | 'ee_ver' => 'ee4', |
| 2964 | 2964 | 'utm_source' => 'ee4_plugin_admin', |
@@ -2978,8 +2978,8 @@ discard block |
||
| 2978 | 2978 | true |
| 2979 | 2979 | ) |
| 2980 | 2980 | : $this->_template_args['preview_action_button']; |
| 2981 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2982 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2981 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2982 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2983 | 2983 | $this->_template_args, |
| 2984 | 2984 | true |
| 2985 | 2985 | ); |
@@ -3031,7 +3031,7 @@ discard block |
||
| 3031 | 3031 | //setup search attributes |
| 3032 | 3032 | $this->_set_search_attributes(); |
| 3033 | 3033 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 3034 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3034 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 3035 | 3035 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 3036 | 3036 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 3037 | 3037 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -3039,10 +3039,10 @@ discard block |
||
| 3039 | 3039 | $this->_template_args['current_route'] = $this->_req_action; |
| 3040 | 3040 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 3041 | 3041 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 3042 | - if (! empty($ajax_sorting_callback)) { |
|
| 3042 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 3043 | 3043 | $sortable_list_table_form_fields = wp_nonce_field( |
| 3044 | - $ajax_sorting_callback . '_nonce', |
|
| 3045 | - $ajax_sorting_callback . '_nonce', |
|
| 3044 | + $ajax_sorting_callback.'_nonce', |
|
| 3045 | + $ajax_sorting_callback.'_nonce', |
|
| 3046 | 3046 | false, |
| 3047 | 3047 | false |
| 3048 | 3048 | ); |
@@ -3061,19 +3061,19 @@ discard block |
||
| 3061 | 3061 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
| 3062 | 3062 | ? $this->_template_args['list_table_hidden_fields'] |
| 3063 | 3063 | : ''; |
| 3064 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3065 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3064 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 3065 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3066 | 3066 | . $nonce_ref |
| 3067 | 3067 | . '" value="' |
| 3068 | 3068 | . wp_create_nonce($nonce_ref) |
| 3069 | 3069 | . '">'; |
| 3070 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3070 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3071 | 3071 | //display message about search results? |
| 3072 | 3072 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 3073 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3073 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 3074 | 3074 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 3075 | 3075 | trim($this->_req_data['s'], '%') |
| 3076 | - ) . '</p>' |
|
| 3076 | + ).'</p>' |
|
| 3077 | 3077 | : ''; |
| 3078 | 3078 | // filter before_list_table template arg |
| 3079 | 3079 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3088,9 +3088,9 @@ discard block |
||
| 3088 | 3088 | // but would not be backwards compatible, so we have to add a new filter |
| 3089 | 3089 | $this->_template_args['before_list_table'] = implode( |
| 3090 | 3090 | " \n", |
| 3091 | - (array)apply_filters( |
|
| 3091 | + (array) apply_filters( |
|
| 3092 | 3092 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
| 3093 | - (array)$this->_template_args['before_list_table'], |
|
| 3093 | + (array) $this->_template_args['before_list_table'], |
|
| 3094 | 3094 | $this->page_slug, |
| 3095 | 3095 | $this->_req_data, |
| 3096 | 3096 | $this->_req_action |
@@ -3107,11 +3107,11 @@ discard block |
||
| 3107 | 3107 | // convert to array and filter again |
| 3108 | 3108 | // arrays are easier to inject new items in a specific location, |
| 3109 | 3109 | // but would not be backwards compatible, so we have to add a new filter |
| 3110 | - $this->_template_args['after_list_table'] = implode( |
|
| 3110 | + $this->_template_args['after_list_table'] = implode( |
|
| 3111 | 3111 | " \n", |
| 3112 | - (array)apply_filters( |
|
| 3112 | + (array) apply_filters( |
|
| 3113 | 3113 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
| 3114 | - (array)$this->_template_args['after_list_table'], |
|
| 3114 | + (array) $this->_template_args['after_list_table'], |
|
| 3115 | 3115 | $this->page_slug, |
| 3116 | 3116 | $this->_req_data, |
| 3117 | 3117 | $this->_req_action |
@@ -3151,11 +3151,11 @@ discard block |
||
| 3151 | 3151 | { |
| 3152 | 3152 | $this->_template_args['items'] = apply_filters( |
| 3153 | 3153 | 'FHEE__EE_Admin_Page___display_legend__items', |
| 3154 | - (array)$items, |
|
| 3154 | + (array) $items, |
|
| 3155 | 3155 | $this |
| 3156 | 3156 | ); |
| 3157 | 3157 | return EEH_Template::display_template( |
| 3158 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3158 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3159 | 3159 | $this->_template_args, |
| 3160 | 3160 | true |
| 3161 | 3161 | ); |
@@ -3265,13 +3265,13 @@ discard block |
||
| 3265 | 3265 | ? $this->_template_args['before_admin_page_content'] |
| 3266 | 3266 | : '' |
| 3267 | 3267 | ); |
| 3268 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3268 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3269 | 3269 | "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
| 3270 | 3270 | isset($this->_template_args['after_admin_page_content']) |
| 3271 | 3271 | ? $this->_template_args['after_admin_page_content'] |
| 3272 | 3272 | : '' |
| 3273 | 3273 | ); |
| 3274 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3274 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3275 | 3275 | // load settings page wrapper template |
| 3276 | 3276 | $template_path = ! defined('DOING_AJAX') |
| 3277 | 3277 | ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
@@ -3366,8 +3366,8 @@ discard block |
||
| 3366 | 3366 | protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
| 3367 | 3367 | { |
| 3368 | 3368 | //make sure $text and $actions are in an array |
| 3369 | - $text = (array)$text; |
|
| 3370 | - $actions = (array)$actions; |
|
| 3369 | + $text = (array) $text; |
|
| 3370 | + $actions = (array) $actions; |
|
| 3371 | 3371 | $referrer_url = empty($referrer) |
| 3372 | 3372 | ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
| 3373 | 3373 | . $_SERVER['REQUEST_URI'] |
@@ -3375,7 +3375,7 @@ discard block |
||
| 3375 | 3375 | : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
| 3376 | 3376 | . $referrer |
| 3377 | 3377 | . '" />'; |
| 3378 | - $button_text = ! empty($text) |
|
| 3378 | + $button_text = ! empty($text) |
|
| 3379 | 3379 | ? $text |
| 3380 | 3380 | : array( |
| 3381 | 3381 | esc_html__('Save', 'event_espresso'), |
@@ -3385,17 +3385,17 @@ discard block |
||
| 3385 | 3385 | //add in a hidden index for the current page (so save and close redirects properly) |
| 3386 | 3386 | $this->_template_args['save_buttons'] = $referrer_url; |
| 3387 | 3387 | foreach ($button_text as $key => $button) { |
| 3388 | - $ref = $default_names[$key]; |
|
| 3388 | + $ref = $default_names[$key]; |
|
| 3389 | 3389 | $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
| 3390 | 3390 | . $ref |
| 3391 | 3391 | . '" value="' |
| 3392 | 3392 | . $button |
| 3393 | 3393 | . '" name="' |
| 3394 | - . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3394 | + . ( ! empty($actions) ? $actions[$key] : $ref) |
|
| 3395 | 3395 | . '" id="' |
| 3396 | - . $this->_current_view . '_' . $ref |
|
| 3396 | + . $this->_current_view.'_'.$ref |
|
| 3397 | 3397 | . '" />'; |
| 3398 | - if (! $both) { |
|
| 3398 | + if ( ! $both) { |
|
| 3399 | 3399 | break; |
| 3400 | 3400 | } |
| 3401 | 3401 | } |
@@ -3432,12 +3432,12 @@ discard block |
||
| 3432 | 3432 | 'An error occurred. No action was set for this page\'s form.', |
| 3433 | 3433 | 'event_espresso' |
| 3434 | 3434 | ); |
| 3435 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3435 | + $dev_msg = $user_msg."\n".sprintf( |
|
| 3436 | 3436 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3437 | 3437 | __FUNCTION__, |
| 3438 | 3438 | __CLASS__ |
| 3439 | 3439 | ); |
| 3440 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3440 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3441 | 3441 | } |
| 3442 | 3442 | // open form |
| 3443 | 3443 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3446,9 +3446,9 @@ discard block |
||
| 3446 | 3446 | . $route |
| 3447 | 3447 | . '_event_form" >'; |
| 3448 | 3448 | // add nonce |
| 3449 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3449 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3450 | 3450 | // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
| 3451 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3451 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3452 | 3452 | // add REQUIRED form action |
| 3453 | 3453 | $hidden_fields = array( |
| 3454 | 3454 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -3460,8 +3460,8 @@ discard block |
||
| 3460 | 3460 | // generate form fields |
| 3461 | 3461 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3462 | 3462 | // add fields to form |
| 3463 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3464 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3463 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3464 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3465 | 3465 | } |
| 3466 | 3466 | // close form |
| 3467 | 3467 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3529,10 +3529,10 @@ discard block |
||
| 3529 | 3529 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3530 | 3530 | $notices = EE_Error::get_notices(false); |
| 3531 | 3531 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3532 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3532 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3533 | 3533 | EE_Error::overwrite_success(); |
| 3534 | 3534 | } |
| 3535 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3535 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3536 | 3536 | // how many records affected ? more than one record ? or just one ? |
| 3537 | 3537 | if ($success > 1) { |
| 3538 | 3538 | // set plural msg |
@@ -3561,7 +3561,7 @@ discard block |
||
| 3561 | 3561 | } |
| 3562 | 3562 | } |
| 3563 | 3563 | // check that $query_args isn't something crazy |
| 3564 | - if (! is_array($query_args)) { |
|
| 3564 | + if ( ! is_array($query_args)) { |
|
| 3565 | 3565 | $query_args = array(); |
| 3566 | 3566 | } |
| 3567 | 3567 | /** |
@@ -3586,12 +3586,12 @@ discard block |
||
| 3586 | 3586 | $redirect_url = admin_url('admin.php'); |
| 3587 | 3587 | } |
| 3588 | 3588 | //merge any default query_args set in _default_route_query_args property |
| 3589 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3589 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | 3590 | $args_to_merge = array(); |
| 3591 | 3591 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3592 | 3592 | //is there a wp_referer array in our _default_route_query_args property? |
| 3593 | 3593 | if ($query_param === 'wp_referer') { |
| 3594 | - $query_value = (array)$query_value; |
|
| 3594 | + $query_value = (array) $query_value; |
|
| 3595 | 3595 | foreach ($query_value as $reference => $value) { |
| 3596 | 3596 | if (strpos($reference, 'nonce') !== false) { |
| 3597 | 3597 | continue; |
@@ -3618,19 +3618,19 @@ discard block |
||
| 3618 | 3618 | if (isset($query_args['action'])) { |
| 3619 | 3619 | // manually generate wp_nonce and merge that with the query vars |
| 3620 | 3620 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3621 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3621 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3622 | 3622 | } |
| 3623 | 3623 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3624 | 3624 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3625 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3625 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3626 | 3626 | $redirect_url = apply_filters( |
| 3627 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3627 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3628 | 3628 | self::add_query_args_and_nonce($query_args, $redirect_url), |
| 3629 | 3629 | $query_args |
| 3630 | 3630 | ); |
| 3631 | 3631 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 3632 | 3632 | if (defined('DOING_AJAX')) { |
| 3633 | - $default_data = array( |
|
| 3633 | + $default_data = array( |
|
| 3634 | 3634 | 'close' => true, |
| 3635 | 3635 | 'redirect_url' => $redirect_url, |
| 3636 | 3636 | 'where' => 'main', |
@@ -3678,7 +3678,7 @@ discard block |
||
| 3678 | 3678 | } |
| 3679 | 3679 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3680 | 3680 | //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3681 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3681 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3682 | 3682 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3683 | 3683 | $this->_add_transient( |
| 3684 | 3684 | $route, |
@@ -3730,7 +3730,7 @@ discard block |
||
| 3730 | 3730 | ) |
| 3731 | 3731 | ); |
| 3732 | 3732 | } |
| 3733 | - if (! isset($this->_labels['buttons'][$type])) { |
|
| 3733 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3734 | 3734 | throw new EE_Error( |
| 3735 | 3735 | sprintf( |
| 3736 | 3736 | __( |
@@ -3743,7 +3743,7 @@ discard block |
||
| 3743 | 3743 | } |
| 3744 | 3744 | //finally check user access for this button. |
| 3745 | 3745 | $has_access = $this->check_user_access($action, true); |
| 3746 | - if (! $has_access) { |
|
| 3746 | + if ( ! $has_access) { |
|
| 3747 | 3747 | return ''; |
| 3748 | 3748 | } |
| 3749 | 3749 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3751,7 +3751,7 @@ discard block |
||
| 3751 | 3751 | 'action' => $action, |
| 3752 | 3752 | ); |
| 3753 | 3753 | //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3754 | - if (! empty($extra_request)) { |
|
| 3754 | + if ( ! empty($extra_request)) { |
|
| 3755 | 3755 | $query_args = array_merge($extra_request, $query_args); |
| 3756 | 3756 | } |
| 3757 | 3757 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
@@ -3784,7 +3784,7 @@ discard block |
||
| 3784 | 3784 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3785 | 3785 | 10 |
| 3786 | 3786 | ), |
| 3787 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3787 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3788 | 3788 | ); |
| 3789 | 3789 | //ONLY add the screen option if the user has access to it. |
| 3790 | 3790 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3806,7 +3806,7 @@ discard block |
||
| 3806 | 3806 | { |
| 3807 | 3807 | if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
| 3808 | 3808 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3809 | - if (! $user = wp_get_current_user()) { |
|
| 3809 | + if ( ! $user = wp_get_current_user()) { |
|
| 3810 | 3810 | return; |
| 3811 | 3811 | } |
| 3812 | 3812 | $option = $_POST['wp_screen_options']['option']; |
@@ -3817,8 +3817,8 @@ discard block |
||
| 3817 | 3817 | $map_option = $option; |
| 3818 | 3818 | $option = str_replace('-', '_', $option); |
| 3819 | 3819 | switch ($map_option) { |
| 3820 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3821 | - $value = (int)$value; |
|
| 3820 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3821 | + $value = (int) $value; |
|
| 3822 | 3822 | $max_value = apply_filters( |
| 3823 | 3823 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
| 3824 | 3824 | 999, |
@@ -3856,7 +3856,7 @@ discard block |
||
| 3856 | 3856 | */ |
| 3857 | 3857 | public function set_template_args($data) |
| 3858 | 3858 | { |
| 3859 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3859 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3860 | 3860 | } |
| 3861 | 3861 | |
| 3862 | 3862 | |
@@ -3876,20 +3876,20 @@ discard block |
||
| 3876 | 3876 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3877 | 3877 | { |
| 3878 | 3878 | $user_id = get_current_user_id(); |
| 3879 | - if (! $skip_route_verify) { |
|
| 3879 | + if ( ! $skip_route_verify) { |
|
| 3880 | 3880 | $this->_verify_route($route); |
| 3881 | 3881 | } |
| 3882 | 3882 | //now let's set the string for what kind of transient we're setting |
| 3883 | 3883 | $transient = $notices |
| 3884 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3885 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3884 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3885 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3886 | 3886 | $data = $notices ? array('notices' => $data) : $data; |
| 3887 | 3887 | //is there already a transient for this route? If there is then let's ADD to that transient |
| 3888 | 3888 | $existing = is_multisite() && is_network_admin() |
| 3889 | 3889 | ? get_site_transient($transient) |
| 3890 | 3890 | : get_transient($transient); |
| 3891 | 3891 | if ($existing) { |
| 3892 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3892 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3893 | 3893 | } |
| 3894 | 3894 | if (is_multisite() && is_network_admin()) { |
| 3895 | 3895 | set_site_transient($transient, $data, 8); |
@@ -3912,8 +3912,8 @@ discard block |
||
| 3912 | 3912 | $user_id = get_current_user_id(); |
| 3913 | 3913 | $route = ! $route ? $this->_req_action : $route; |
| 3914 | 3914 | $transient = $notices |
| 3915 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3916 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3915 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3916 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3917 | 3917 | $data = is_multisite() && is_network_admin() |
| 3918 | 3918 | ? get_site_transient($transient) |
| 3919 | 3919 | : get_transient($transient); |
@@ -4150,7 +4150,7 @@ discard block |
||
| 4150 | 4150 | */ |
| 4151 | 4151 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 4152 | 4152 | { |
| 4153 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4153 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4154 | 4154 | } |
| 4155 | 4155 | |
| 4156 | 4156 | |
@@ -4164,7 +4164,7 @@ discard block |
||
| 4164 | 4164 | */ |
| 4165 | 4165 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 4166 | 4166 | { |
| 4167 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4167 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4168 | 4168 | } |
| 4169 | 4169 | |
| 4170 | 4170 | |
@@ -20,4204 +20,4204 @@ |
||
| 20 | 20 | { |
| 21 | 21 | |
| 22 | 22 | |
| 23 | - //set in _init_page_props() |
|
| 24 | - public $page_slug; |
|
| 23 | + //set in _init_page_props() |
|
| 24 | + public $page_slug; |
|
| 25 | 25 | |
| 26 | - public $page_label; |
|
| 26 | + public $page_label; |
|
| 27 | 27 | |
| 28 | - public $page_folder; |
|
| 28 | + public $page_folder; |
|
| 29 | 29 | |
| 30 | - //set in define_page_props() |
|
| 31 | - protected $_admin_base_url; |
|
| 30 | + //set in define_page_props() |
|
| 31 | + protected $_admin_base_url; |
|
| 32 | 32 | |
| 33 | - protected $_admin_base_path; |
|
| 33 | + protected $_admin_base_path; |
|
| 34 | 34 | |
| 35 | - protected $_admin_page_title; |
|
| 35 | + protected $_admin_page_title; |
|
| 36 | 36 | |
| 37 | - protected $_labels; |
|
| 37 | + protected $_labels; |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - //set early within EE_Admin_Init |
|
| 41 | - protected $_wp_page_slug; |
|
| 40 | + //set early within EE_Admin_Init |
|
| 41 | + protected $_wp_page_slug; |
|
| 42 | 42 | |
| 43 | - //navtabs |
|
| 44 | - protected $_nav_tabs; |
|
| 43 | + //navtabs |
|
| 44 | + protected $_nav_tabs; |
|
| 45 | 45 | |
| 46 | - protected $_default_nav_tab_name; |
|
| 46 | + protected $_default_nav_tab_name; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var array $_help_tour |
|
| 50 | - */ |
|
| 51 | - protected $_help_tour = array(); |
|
| 48 | + /** |
|
| 49 | + * @var array $_help_tour |
|
| 50 | + */ |
|
| 51 | + protected $_help_tour = array(); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - //template variables (used by templates) |
|
| 55 | - protected $_template_path; |
|
| 54 | + //template variables (used by templates) |
|
| 55 | + protected $_template_path; |
|
| 56 | 56 | |
| 57 | - protected $_column_template_path; |
|
| 57 | + protected $_column_template_path; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var array $_template_args |
|
| 61 | - */ |
|
| 62 | - protected $_template_args = array(); |
|
| 59 | + /** |
|
| 60 | + * @var array $_template_args |
|
| 61 | + */ |
|
| 62 | + protected $_template_args = array(); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * this will hold the list table object for a given view. |
|
| 66 | - * |
|
| 67 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 68 | - */ |
|
| 69 | - protected $_list_table_object; |
|
| 64 | + /** |
|
| 65 | + * this will hold the list table object for a given view. |
|
| 66 | + * |
|
| 67 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 68 | + */ |
|
| 69 | + protected $_list_table_object; |
|
| 70 | 70 | |
| 71 | - //bools |
|
| 72 | - protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 71 | + //bools |
|
| 72 | + protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 73 | 73 | |
| 74 | - protected $_routing; |
|
| 74 | + protected $_routing; |
|
| 75 | 75 | |
| 76 | - //list table args |
|
| 77 | - protected $_view; |
|
| 76 | + //list table args |
|
| 77 | + protected $_view; |
|
| 78 | 78 | |
| 79 | - protected $_views; |
|
| 79 | + protected $_views; |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - //action => method pairs used for routing incoming requests |
|
| 83 | - protected $_page_routes; |
|
| 82 | + //action => method pairs used for routing incoming requests |
|
| 83 | + protected $_page_routes; |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @var array $_page_config |
|
| 87 | - */ |
|
| 88 | - protected $_page_config; |
|
| 85 | + /** |
|
| 86 | + * @var array $_page_config |
|
| 87 | + */ |
|
| 88 | + protected $_page_config; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * the current page route and route config |
|
| 92 | - * |
|
| 93 | - * @var string $_route |
|
| 94 | - */ |
|
| 95 | - protected $_route; |
|
| 90 | + /** |
|
| 91 | + * the current page route and route config |
|
| 92 | + * |
|
| 93 | + * @var string $_route |
|
| 94 | + */ |
|
| 95 | + protected $_route; |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @var string $_cpt_route |
|
| 99 | - */ |
|
| 100 | - protected $_cpt_route; |
|
| 97 | + /** |
|
| 98 | + * @var string $_cpt_route |
|
| 99 | + */ |
|
| 100 | + protected $_cpt_route; |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @var array $_route_config |
|
| 104 | - */ |
|
| 105 | - protected $_route_config; |
|
| 102 | + /** |
|
| 103 | + * @var array $_route_config |
|
| 104 | + */ |
|
| 105 | + protected $_route_config; |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 109 | - * actions. |
|
| 110 | - * |
|
| 111 | - * @since 4.6.x |
|
| 112 | - * @var array. |
|
| 113 | - */ |
|
| 114 | - protected $_default_route_query_args; |
|
| 115 | - |
|
| 116 | - //set via request page and action args. |
|
| 117 | - protected $_current_page; |
|
| 107 | + /** |
|
| 108 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 109 | + * actions. |
|
| 110 | + * |
|
| 111 | + * @since 4.6.x |
|
| 112 | + * @var array. |
|
| 113 | + */ |
|
| 114 | + protected $_default_route_query_args; |
|
| 115 | + |
|
| 116 | + //set via request page and action args. |
|
| 117 | + protected $_current_page; |
|
| 118 | 118 | |
| 119 | - protected $_current_view; |
|
| 119 | + protected $_current_view; |
|
| 120 | 120 | |
| 121 | - protected $_current_page_view_url; |
|
| 121 | + protected $_current_page_view_url; |
|
| 122 | 122 | |
| 123 | - //sanitized request action (and nonce) |
|
| 123 | + //sanitized request action (and nonce) |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @var string $_req_action |
|
| 127 | - */ |
|
| 128 | - protected $_req_action; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var string $_req_nonce |
|
| 132 | - */ |
|
| 133 | - protected $_req_nonce; |
|
| 134 | - |
|
| 135 | - //search related |
|
| 136 | - protected $_search_btn_label; |
|
| 137 | - |
|
| 138 | - protected $_search_box_callback; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * WP Current Screen object |
|
| 142 | - * |
|
| 143 | - * @var WP_Screen |
|
| 144 | - */ |
|
| 145 | - protected $_current_screen; |
|
| 146 | - |
|
| 147 | - //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 148 | - protected $_hook_obj; |
|
| 149 | - |
|
| 150 | - //for holding incoming request data |
|
| 151 | - protected $_req_data; |
|
| 152 | - |
|
| 153 | - // yes / no array for admin form fields |
|
| 154 | - protected $_yes_no_values = array(); |
|
| 155 | - |
|
| 156 | - //some default things shared by all child classes |
|
| 157 | - protected $_default_espresso_metaboxes; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * EE_Registry Object |
|
| 161 | - * |
|
| 162 | - * @var EE_Registry |
|
| 163 | - */ |
|
| 164 | - protected $EE = null; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 170 | - * |
|
| 171 | - * @var boolean |
|
| 172 | - */ |
|
| 173 | - protected $_is_caf = false; |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @Constructor |
|
| 179 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 180 | - * @throws EE_Error |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - * @throws InvalidDataTypeException |
|
| 184 | - * @throws InvalidInterfaceException |
|
| 185 | - */ |
|
| 186 | - public function __construct($routing = true) |
|
| 187 | - { |
|
| 188 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 189 | - $this->_is_caf = true; |
|
| 190 | - } |
|
| 191 | - $this->_yes_no_values = array( |
|
| 192 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 193 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 194 | - ); |
|
| 195 | - //set the _req_data property. |
|
| 196 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 197 | - //routing enabled? |
|
| 198 | - $this->_routing = $routing; |
|
| 199 | - //set initial page props (child method) |
|
| 200 | - $this->_init_page_props(); |
|
| 201 | - //set global defaults |
|
| 202 | - $this->_set_defaults(); |
|
| 203 | - //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 204 | - $this->_global_ajax_hooks(); |
|
| 205 | - $this->_ajax_hooks(); |
|
| 206 | - //other_page_hooks have to be early too. |
|
| 207 | - $this->_do_other_page_hooks(); |
|
| 208 | - //This just allows us to have extending classes do something specific |
|
| 209 | - // before the parent constructor runs _page_setup(). |
|
| 210 | - if (method_exists($this, '_before_page_setup')) { |
|
| 211 | - $this->_before_page_setup(); |
|
| 212 | - } |
|
| 213 | - //set up page dependencies |
|
| 214 | - $this->_page_setup(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * _init_page_props |
|
| 221 | - * Child classes use to set at least the following properties: |
|
| 222 | - * $page_slug. |
|
| 223 | - * $page_label. |
|
| 224 | - * |
|
| 225 | - * @abstract |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - abstract protected function _init_page_props(); |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * _ajax_hooks |
|
| 234 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 235 | - * Note: within the ajax callback methods. |
|
| 236 | - * |
|
| 237 | - * @abstract |
|
| 238 | - * @return void |
|
| 239 | - */ |
|
| 240 | - abstract protected function _ajax_hooks(); |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * _define_page_props |
|
| 246 | - * child classes define page properties in here. Must include at least: |
|
| 247 | - * $_admin_base_url = base_url for all admin pages |
|
| 248 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 249 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 250 | - * array( |
|
| 251 | - * 'buttons' => array( |
|
| 252 | - * 'add' => esc_html__('label for add new button'), |
|
| 253 | - * 'edit' => esc_html__('label for edit button'), |
|
| 254 | - * 'delete' => esc_html__('label for delete button') |
|
| 255 | - * ) |
|
| 256 | - * ) |
|
| 257 | - * |
|
| 258 | - * @abstract |
|
| 259 | - * @return void |
|
| 260 | - */ |
|
| 261 | - abstract protected function _define_page_props(); |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * _set_page_routes |
|
| 267 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 268 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 269 | - * have a 'default' route. Here's the format |
|
| 270 | - * $this->_page_routes = array( |
|
| 271 | - * 'default' => array( |
|
| 272 | - * 'func' => '_default_method_handling_route', |
|
| 273 | - * 'args' => array('array','of','args'), |
|
| 274 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 275 | - * ajax request, backend processing) |
|
| 276 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 277 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 278 | - * headers sent route. |
|
| 279 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 280 | - * this route. |
|
| 281 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 282 | - * checks). |
|
| 283 | - * ), |
|
| 284 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 285 | - * handling method. |
|
| 286 | - * ) |
|
| 287 | - * ) |
|
| 288 | - * |
|
| 289 | - * @abstract |
|
| 290 | - * @return void |
|
| 291 | - */ |
|
| 292 | - abstract protected function _set_page_routes(); |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * _set_page_config |
|
| 298 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 299 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 300 | - * $this->_page_config = array( |
|
| 301 | - * 'default' => array( |
|
| 302 | - * 'labels' => array( |
|
| 303 | - * 'buttons' => array( |
|
| 304 | - * 'add' => esc_html__('label for adding item'), |
|
| 305 | - * 'edit' => esc_html__('label for editing item'), |
|
| 306 | - * 'delete' => esc_html__('label for deleting item') |
|
| 307 | - * ), |
|
| 308 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 309 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 310 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 311 | - * _define_page_props() method |
|
| 312 | - * 'nav' => array( |
|
| 313 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 314 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 315 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 316 | - * 'order' => 10, //required to indicate tab position. |
|
| 317 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 318 | - * displayed then add this parameter. |
|
| 319 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 320 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 321 | - * metaboxes set for eventespresso admin pages. |
|
| 322 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 323 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 324 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 325 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 326 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 327 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 328 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 329 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 330 | - * want to display. |
|
| 331 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 332 | - * 'tab_id' => array( |
|
| 333 | - * 'title' => 'tab_title', |
|
| 334 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 335 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 336 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 337 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 338 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 339 | - * attempt to use the callback which should match the name of a method in the class |
|
| 340 | - * ), |
|
| 341 | - * 'tab2_id' => array( |
|
| 342 | - * 'title' => 'tab2 title', |
|
| 343 | - * 'filename' => 'file_name_2' |
|
| 344 | - * 'callback' => 'callback_method_for_content', |
|
| 345 | - * ), |
|
| 346 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 347 | - * help tab area on an admin page. @link |
|
| 348 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 349 | - * 'help_tour' => array( |
|
| 350 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 351 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 352 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 353 | - * ), |
|
| 354 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 355 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 356 | - * just set |
|
| 357 | - * 'require_nonce' to FALSE |
|
| 358 | - * ) |
|
| 359 | - * ) |
|
| 360 | - * |
|
| 361 | - * @abstract |
|
| 362 | - * @return void |
|
| 363 | - */ |
|
| 364 | - abstract protected function _set_page_config(); |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** end sample help_tour methods **/ |
|
| 371 | - /** |
|
| 372 | - * _add_screen_options |
|
| 373 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 374 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 375 | - * to a particular view. |
|
| 376 | - * |
|
| 377 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 378 | - * see also WP_Screen object documents... |
|
| 379 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 380 | - * @abstract |
|
| 381 | - * @return void |
|
| 382 | - */ |
|
| 383 | - abstract protected function _add_screen_options(); |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * _add_feature_pointers |
|
| 389 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 390 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 391 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 392 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 393 | - * extended) also see: |
|
| 394 | - * |
|
| 395 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 396 | - * @abstract |
|
| 397 | - * @return void |
|
| 398 | - */ |
|
| 399 | - abstract protected function _add_feature_pointers(); |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * load_scripts_styles |
|
| 405 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 406 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 407 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 408 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 409 | - * |
|
| 410 | - * @abstract |
|
| 411 | - * @return void |
|
| 412 | - */ |
|
| 413 | - abstract public function load_scripts_styles(); |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * admin_init |
|
| 419 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 420 | - * all pages/views loaded by child class. |
|
| 421 | - * |
|
| 422 | - * @abstract |
|
| 423 | - * @return void |
|
| 424 | - */ |
|
| 425 | - abstract public function admin_init(); |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * admin_notices |
|
| 431 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 432 | - * all pages/views loaded by child class. |
|
| 433 | - * |
|
| 434 | - * @abstract |
|
| 435 | - * @return void |
|
| 436 | - */ |
|
| 437 | - abstract public function admin_notices(); |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * admin_footer_scripts |
|
| 443 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 444 | - * will apply to all pages/views loaded by child class. |
|
| 445 | - * |
|
| 446 | - * @return void |
|
| 447 | - */ |
|
| 448 | - abstract public function admin_footer_scripts(); |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * admin_footer |
|
| 454 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 455 | - * apply to all pages/views loaded by child class. |
|
| 456 | - * |
|
| 457 | - * @return void |
|
| 458 | - */ |
|
| 459 | - public function admin_footer() |
|
| 460 | - { |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * _global_ajax_hooks |
|
| 467 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 468 | - * Note: within the ajax callback methods. |
|
| 469 | - * |
|
| 470 | - * @abstract |
|
| 471 | - * @return void |
|
| 472 | - */ |
|
| 473 | - protected function _global_ajax_hooks() |
|
| 474 | - { |
|
| 475 | - //for lazy loading of metabox content |
|
| 476 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - public function ajax_metabox_content() |
|
| 482 | - { |
|
| 483 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 484 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 485 | - self::cached_rss_display($contentid, $url); |
|
| 486 | - wp_die(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * _page_setup |
|
| 493 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 494 | - * doesn't match the object. |
|
| 495 | - * |
|
| 496 | - * @final |
|
| 497 | - * @return void |
|
| 498 | - * @throws EE_Error |
|
| 499 | - * @throws InvalidArgumentException |
|
| 500 | - * @throws ReflectionException |
|
| 501 | - * @throws InvalidDataTypeException |
|
| 502 | - * @throws InvalidInterfaceException |
|
| 503 | - */ |
|
| 504 | - final protected function _page_setup() |
|
| 505 | - { |
|
| 506 | - //requires? |
|
| 507 | - //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 508 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 509 | - //next verify if we need to load anything... |
|
| 510 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 511 | - $this->page_folder = strtolower( |
|
| 512 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 513 | - ); |
|
| 514 | - global $ee_menu_slugs; |
|
| 515 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 516 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 517 | - return; |
|
| 518 | - } |
|
| 519 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 520 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 521 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 522 | - ? $this->_req_data['action2'] |
|
| 523 | - : $this->_req_data['action']; |
|
| 524 | - } |
|
| 525 | - // then set blank or -1 action values to 'default' |
|
| 526 | - $this->_req_action = isset($this->_req_data['action']) |
|
| 527 | - && ! empty($this->_req_data['action']) |
|
| 528 | - && $this->_req_data['action'] !== '-1' |
|
| 529 | - ? sanitize_key($this->_req_data['action']) |
|
| 530 | - : 'default'; |
|
| 531 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 532 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 533 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 534 | - ? $this->_req_data['route'] : $this->_req_action; |
|
| 535 | - //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 536 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 537 | - ? $this->_req_data['route'] |
|
| 538 | - : $this->_req_action; |
|
| 539 | - $this->_current_view = $this->_req_action; |
|
| 540 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 541 | - $this->_define_page_props(); |
|
| 542 | - $this->_current_page_view_url = add_query_arg( |
|
| 543 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 544 | - $this->_admin_base_url |
|
| 545 | - ); |
|
| 546 | - //default things |
|
| 547 | - $this->_default_espresso_metaboxes = array( |
|
| 548 | - '_espresso_news_post_box', |
|
| 549 | - '_espresso_links_post_box', |
|
| 550 | - '_espresso_ratings_request', |
|
| 551 | - '_espresso_sponsors_post_box', |
|
| 552 | - ); |
|
| 553 | - //set page configs |
|
| 554 | - $this->_set_page_routes(); |
|
| 555 | - $this->_set_page_config(); |
|
| 556 | - //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 557 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 558 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 559 | - } |
|
| 560 | - //for caffeinated and other extended functionality. |
|
| 561 | - // If there is a _extend_page_config method |
|
| 562 | - // then let's run that to modify the all the various page configuration arrays |
|
| 563 | - if (method_exists($this, '_extend_page_config')) { |
|
| 564 | - $this->_extend_page_config(); |
|
| 565 | - } |
|
| 566 | - //for CPT and other extended functionality. |
|
| 567 | - // If there is an _extend_page_config_for_cpt |
|
| 568 | - // then let's run that to modify all the various page configuration arrays. |
|
| 569 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | - $this->_extend_page_config_for_cpt(); |
|
| 571 | - } |
|
| 572 | - //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | - $this->_page_routes = apply_filters( |
|
| 574 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | - $this->_page_routes, |
|
| 576 | - $this |
|
| 577 | - ); |
|
| 578 | - $this->_page_config = apply_filters( |
|
| 579 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | - $this->_page_config, |
|
| 581 | - $this |
|
| 582 | - ); |
|
| 583 | - //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | - if ( |
|
| 586 | - method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 587 | - ) { |
|
| 588 | - add_action( |
|
| 589 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 590 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 591 | - 10, |
|
| 592 | - 2 |
|
| 593 | - ); |
|
| 594 | - } |
|
| 595 | - //next route only if routing enabled |
|
| 596 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 597 | - $this->_verify_routes(); |
|
| 598 | - //next let's just check user_access and kill if no access |
|
| 599 | - $this->check_user_access(); |
|
| 600 | - if ($this->_is_UI_request) { |
|
| 601 | - //admin_init stuff - global, all views for this page class, specific view |
|
| 602 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 603 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 604 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 605 | - } |
|
| 606 | - } else { |
|
| 607 | - //hijack regular WP loading and route admin request immediately |
|
| 608 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 609 | - $this->route_admin_request(); |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 618 | - * |
|
| 619 | - * @return void |
|
| 620 | - * @throws ReflectionException |
|
| 621 | - * @throws EE_Error |
|
| 622 | - */ |
|
| 623 | - private function _do_other_page_hooks() |
|
| 624 | - { |
|
| 625 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 626 | - foreach ($registered_pages as $page) { |
|
| 627 | - //now let's setup the file name and class that should be present |
|
| 628 | - $classname = str_replace('.class.php', '', $page); |
|
| 629 | - //autoloaders should take care of loading file |
|
| 630 | - if (! class_exists($classname)) { |
|
| 631 | - $error_msg[] = sprintf( |
|
| 632 | - esc_html__( |
|
| 633 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 634 | - 'event_espresso' |
|
| 635 | - ), |
|
| 636 | - $page |
|
| 637 | - ); |
|
| 638 | - $error_msg[] = $error_msg[0] |
|
| 639 | - . "\r\n" |
|
| 640 | - . sprintf( |
|
| 641 | - esc_html__( |
|
| 642 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 643 | - 'event_espresso' |
|
| 644 | - ), |
|
| 645 | - $page, |
|
| 646 | - '<br />', |
|
| 647 | - '<strong>' . $classname . '</strong>' |
|
| 648 | - ); |
|
| 649 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 650 | - } |
|
| 651 | - $a = new ReflectionClass($classname); |
|
| 652 | - //notice we are passing the instance of this class to the hook object. |
|
| 653 | - $hookobj[] = $a->newInstance($this); |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - public function load_page_dependencies() |
|
| 660 | - { |
|
| 661 | - try { |
|
| 662 | - $this->_load_page_dependencies(); |
|
| 663 | - } catch (EE_Error $e) { |
|
| 664 | - $e->get_error(); |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * load_page_dependencies |
|
| 672 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 673 | - * |
|
| 674 | - * @return void |
|
| 675 | - * @throws DomainException |
|
| 676 | - * @throws EE_Error |
|
| 677 | - * @throws InvalidArgumentException |
|
| 678 | - * @throws InvalidDataTypeException |
|
| 679 | - * @throws InvalidInterfaceException |
|
| 680 | - * @throws ReflectionException |
|
| 681 | - */ |
|
| 682 | - protected function _load_page_dependencies() |
|
| 683 | - { |
|
| 684 | - //let's set the current_screen and screen options to override what WP set |
|
| 685 | - $this->_current_screen = get_current_screen(); |
|
| 686 | - //load admin_notices - global, page class, and view specific |
|
| 687 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 688 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 689 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 690 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 691 | - } |
|
| 692 | - //load network admin_notices - global, page class, and view specific |
|
| 693 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 694 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 695 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 696 | - } |
|
| 697 | - //this will save any per_page screen options if they are present |
|
| 698 | - $this->_set_per_page_screen_options(); |
|
| 699 | - //setup list table properties |
|
| 700 | - $this->_set_list_table(); |
|
| 701 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 702 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 703 | - $this->_add_registered_meta_boxes(); |
|
| 704 | - $this->_add_screen_columns(); |
|
| 705 | - //add screen options - global, page child class, and view specific |
|
| 706 | - $this->_add_global_screen_options(); |
|
| 707 | - $this->_add_screen_options(); |
|
| 708 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 709 | - if (method_exists($this, $add_screen_options )) { |
|
| 710 | - $this->{$add_screen_options}(); |
|
| 711 | - } |
|
| 712 | - //add help tab(s) and tours- set via page_config and qtips. |
|
| 713 | - $this->_add_help_tour(); |
|
| 714 | - $this->_add_help_tabs(); |
|
| 715 | - $this->_add_qtips(); |
|
| 716 | - //add feature_pointers - global, page child class, and view specific |
|
| 717 | - $this->_add_feature_pointers(); |
|
| 718 | - $this->_add_global_feature_pointers(); |
|
| 719 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 720 | - if (method_exists($this, $add_feature_pointer )) { |
|
| 721 | - $this->{$add_feature_pointer}(); |
|
| 722 | - } |
|
| 723 | - //enqueue scripts/styles - global, page class, and view specific |
|
| 724 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 725 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 726 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 727 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 728 | - } |
|
| 729 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 730 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 731 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 732 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 733 | - // is a good use case. Notice the late priority we're giving these |
|
| 734 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 735 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 736 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 737 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 738 | - } |
|
| 739 | - //admin footer scripts |
|
| 740 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 741 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 742 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 743 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 744 | - } |
|
| 745 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 746 | - //targeted hook |
|
| 747 | - do_action( |
|
| 748 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 749 | - |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * _set_defaults |
|
| 757 | - * This sets some global defaults for class properties. |
|
| 758 | - */ |
|
| 759 | - private function _set_defaults() |
|
| 760 | - { |
|
| 761 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 762 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 763 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 764 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
| 765 | - $this->_default_nav_tab_name = 'overview'; |
|
| 766 | - //init template args |
|
| 767 | - $this->_template_args = array( |
|
| 768 | - 'admin_page_header' => '', |
|
| 769 | - 'admin_page_content' => '', |
|
| 770 | - 'post_body_content' => '', |
|
| 771 | - 'before_list_table' => '', |
|
| 772 | - 'after_list_table' => '', |
|
| 773 | - ); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * route_admin_request |
|
| 780 | - * |
|
| 781 | - * @see _route_admin_request() |
|
| 782 | - * @return exception|void error |
|
| 783 | - * @throws InvalidArgumentException |
|
| 784 | - * @throws InvalidInterfaceException |
|
| 785 | - * @throws InvalidDataTypeException |
|
| 786 | - * @throws EE_Error |
|
| 787 | - * @throws ReflectionException |
|
| 788 | - */ |
|
| 789 | - public function route_admin_request() |
|
| 790 | - { |
|
| 791 | - try { |
|
| 792 | - $this->_route_admin_request(); |
|
| 793 | - } catch (EE_Error $e) { |
|
| 794 | - $e->get_error(); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - public function set_wp_page_slug($wp_page_slug) |
|
| 801 | - { |
|
| 802 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 803 | - //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 804 | - if (is_network_admin()) { |
|
| 805 | - $this->_wp_page_slug .= '-network'; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * _verify_routes |
|
| 813 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 814 | - * we know if we need to drop out. |
|
| 815 | - * |
|
| 816 | - * @return bool |
|
| 817 | - * @throws EE_Error |
|
| 818 | - */ |
|
| 819 | - protected function _verify_routes() |
|
| 820 | - { |
|
| 821 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 822 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - $this->_route = false; |
|
| 826 | - // check that the page_routes array is not empty |
|
| 827 | - if (empty($this->_page_routes)) { |
|
| 828 | - // user error msg |
|
| 829 | - $error_msg = sprintf( |
|
| 830 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 831 | - $this->_admin_page_title |
|
| 832 | - ); |
|
| 833 | - // developer error msg |
|
| 834 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 835 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 836 | - 'event_espresso' |
|
| 837 | - ); |
|
| 838 | - throw new EE_Error($error_msg); |
|
| 839 | - } |
|
| 840 | - // and that the requested page route exists |
|
| 841 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 842 | - $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 843 | - $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 844 | - ? $this->_page_config[$this->_req_action] : array(); |
|
| 845 | - } else { |
|
| 846 | - // user error msg |
|
| 847 | - $error_msg = sprintf( |
|
| 848 | - esc_html__( |
|
| 849 | - 'The requested page route does not exist for the %s admin page.', |
|
| 850 | - 'event_espresso' |
|
| 851 | - ), |
|
| 852 | - $this->_admin_page_title |
|
| 853 | - ); |
|
| 854 | - // developer error msg |
|
| 855 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 856 | - esc_html__( |
|
| 857 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 858 | - 'event_espresso' |
|
| 859 | - ), |
|
| 860 | - $this->_req_action |
|
| 861 | - ); |
|
| 862 | - throw new EE_Error($error_msg); |
|
| 863 | - } |
|
| 864 | - // and that a default route exists |
|
| 865 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 866 | - // user error msg |
|
| 867 | - $error_msg = sprintf( |
|
| 868 | - esc_html__( |
|
| 869 | - 'A default page route has not been set for the % admin page.', |
|
| 870 | - 'event_espresso' |
|
| 871 | - ), |
|
| 872 | - $this->_admin_page_title |
|
| 873 | - ); |
|
| 874 | - // developer error msg |
|
| 875 | - $error_msg .= '||' . $error_msg . esc_html__( |
|
| 876 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 877 | - 'event_espresso' |
|
| 878 | - ); |
|
| 879 | - throw new EE_Error($error_msg); |
|
| 880 | - } |
|
| 881 | - //first lets' catch if the UI request has EVER been set. |
|
| 882 | - if ($this->_is_UI_request === null) { |
|
| 883 | - //lets set if this is a UI request or not. |
|
| 884 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 885 | - //wait a minute... we might have a noheader in the route array |
|
| 886 | - $this->_is_UI_request = is_array($this->_route) |
|
| 887 | - && isset($this->_route['noheader']) |
|
| 888 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 889 | - } |
|
| 890 | - $this->_set_current_labels(); |
|
| 891 | - return true; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - |
|
| 896 | - /** |
|
| 897 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 898 | - * |
|
| 899 | - * @param string $route the route name we're verifying |
|
| 900 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 901 | - * @throws EE_Error |
|
| 902 | - */ |
|
| 903 | - protected function _verify_route($route) |
|
| 904 | - { |
|
| 905 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 906 | - return true; |
|
| 907 | - } |
|
| 908 | - // user error msg |
|
| 909 | - $error_msg = sprintf( |
|
| 910 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 911 | - $this->_admin_page_title |
|
| 912 | - ); |
|
| 913 | - // developer error msg |
|
| 914 | - $error_msg .= '||' . $error_msg . sprintf( |
|
| 915 | - esc_html__( |
|
| 916 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 917 | - 'event_espresso' |
|
| 918 | - ), |
|
| 919 | - $route |
|
| 920 | - ); |
|
| 921 | - throw new EE_Error($error_msg); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * perform nonce verification |
|
| 928 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 929 | - * using this method (and save retyping!) |
|
| 930 | - * |
|
| 931 | - * @param string $nonce The nonce sent |
|
| 932 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 933 | - * @return void |
|
| 934 | - * @throws EE_Error |
|
| 935 | - */ |
|
| 936 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 937 | - { |
|
| 938 | - // verify nonce against expected value |
|
| 939 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 940 | - // these are not the droids you are looking for !!! |
|
| 941 | - $msg = sprintf( |
|
| 942 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 943 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 944 | - '</a>' |
|
| 945 | - ); |
|
| 946 | - if (WP_DEBUG) { |
|
| 947 | - $msg .= "\n " . sprintf( |
|
| 948 | - esc_html__( |
|
| 949 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 950 | - 'event_espresso' |
|
| 951 | - ), |
|
| 952 | - __CLASS__ |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - if (! defined('DOING_AJAX')) { |
|
| 956 | - wp_die($msg); |
|
| 957 | - } else { |
|
| 958 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 959 | - $this->_return_json(); |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * _route_admin_request() |
|
| 968 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 969 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 970 | - * in the page routes and then will try to load the corresponding method. |
|
| 971 | - * |
|
| 972 | - * @return void |
|
| 973 | - * @throws EE_Error |
|
| 974 | - * @throws InvalidArgumentException |
|
| 975 | - * @throws InvalidDataTypeException |
|
| 976 | - * @throws InvalidInterfaceException |
|
| 977 | - * @throws ReflectionException |
|
| 978 | - */ |
|
| 979 | - protected function _route_admin_request() |
|
| 980 | - { |
|
| 981 | - if (! $this->_is_UI_request) { |
|
| 982 | - $this->_verify_routes(); |
|
| 983 | - } |
|
| 984 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 985 | - ? $this->_route_config['require_nonce'] |
|
| 986 | - : true; |
|
| 987 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 988 | - // set nonce from post data |
|
| 989 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 990 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 991 | - : ''; |
|
| 992 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 993 | - } |
|
| 994 | - //set the nav_tabs array but ONLY if this is UI_request |
|
| 995 | - if ($this->_is_UI_request) { |
|
| 996 | - $this->_set_nav_tabs(); |
|
| 997 | - } |
|
| 998 | - // grab callback function |
|
| 999 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1000 | - // check if callback has args |
|
| 1001 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1002 | - $error_msg = ''; |
|
| 1003 | - // action right before calling route |
|
| 1004 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1005 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1006 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1007 | - } |
|
| 1008 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 1009 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1010 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1011 | - '_wp_http_referer', |
|
| 1012 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1013 | - ); |
|
| 1014 | - if (! empty($func)) { |
|
| 1015 | - if (is_array($func)) { |
|
| 1016 | - list($class, $method) = $func; |
|
| 1017 | - } elseif (strpos($func, '::') !== false) { |
|
| 1018 | - list($class, $method) = explode('::', $func); |
|
| 1019 | - } else { |
|
| 1020 | - $class = $this; |
|
| 1021 | - $method = $func; |
|
| 1022 | - } |
|
| 1023 | - if (! (is_object($class) && $class === $this)) { |
|
| 1024 | - // send along this admin page object for access by addons. |
|
| 1025 | - $args['admin_page_object'] = $this; |
|
| 1026 | - } |
|
| 1027 | - if ( |
|
| 1028 | - //is it a method on a class that doesn't work? |
|
| 1029 | - ( |
|
| 1030 | - ( |
|
| 1031 | - method_exists($class, $method) |
|
| 1032 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 1033 | - ) |
|
| 1034 | - && ( |
|
| 1035 | - //is it a standalone function that doesn't work? |
|
| 1036 | - function_exists($method) |
|
| 1037 | - && call_user_func_array( |
|
| 1038 | - $func, |
|
| 1039 | - array_merge(array('admin_page_object' => $this), $args) |
|
| 1040 | - ) === false |
|
| 1041 | - ) |
|
| 1042 | - ) |
|
| 1043 | - || ( |
|
| 1044 | - //is it neither a class method NOR a standalone function? |
|
| 1045 | - ! method_exists($class, $method) |
|
| 1046 | - && ! function_exists($method) |
|
| 1047 | - ) |
|
| 1048 | - ) { |
|
| 1049 | - // user error msg |
|
| 1050 | - $error_msg = esc_html__( |
|
| 1051 | - 'An error occurred. The requested page route could not be found.', |
|
| 1052 | - 'event_espresso' |
|
| 1053 | - ); |
|
| 1054 | - // developer error msg |
|
| 1055 | - $error_msg .= '||'; |
|
| 1056 | - $error_msg .= sprintf( |
|
| 1057 | - esc_html__( |
|
| 1058 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1059 | - 'event_espresso' |
|
| 1060 | - ), |
|
| 1061 | - $method |
|
| 1062 | - ); |
|
| 1063 | - } |
|
| 1064 | - if (! empty($error_msg)) { |
|
| 1065 | - throw new EE_Error($error_msg); |
|
| 1066 | - } |
|
| 1067 | - } |
|
| 1068 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1069 | - // then we need to reset the routing properties to the new route. |
|
| 1070 | - //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1071 | - if ($this->_is_UI_request === false |
|
| 1072 | - && is_array($this->_route) |
|
| 1073 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1074 | - ) { |
|
| 1075 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1083 | - * route redirects to a headers route in its route config. |
|
| 1084 | - * |
|
| 1085 | - * @since 4.3.0 |
|
| 1086 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1087 | - * @return void |
|
| 1088 | - * @throws ReflectionException |
|
| 1089 | - * @throws InvalidArgumentException |
|
| 1090 | - * @throws InvalidInterfaceException |
|
| 1091 | - * @throws InvalidDataTypeException |
|
| 1092 | - * @throws EE_Error |
|
| 1093 | - */ |
|
| 1094 | - protected function _reset_routing_properties($new_route) |
|
| 1095 | - { |
|
| 1096 | - $this->_is_UI_request = true; |
|
| 1097 | - //now we set the current route to whatever the headers_sent_route is set at |
|
| 1098 | - $this->_req_data['action'] = $new_route; |
|
| 1099 | - //rerun page setup |
|
| 1100 | - $this->_page_setup(); |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _add_query_arg |
|
| 1107 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1108 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1109 | - * |
|
| 1110 | - * @param array $args |
|
| 1111 | - * @param string $url |
|
| 1112 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1113 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1114 | - * Example usage: If the current page is: |
|
| 1115 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1116 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1117 | - * &_wpnonce=5467821 |
|
| 1118 | - * and you call: |
|
| 1119 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1120 | - * array( |
|
| 1121 | - * 'action' => 'resend_something', |
|
| 1122 | - * 'page=>espresso_registrations' |
|
| 1123 | - * ), |
|
| 1124 | - * $some_url, |
|
| 1125 | - * true |
|
| 1126 | - * ); |
|
| 1127 | - * It will produce a url in this structure: |
|
| 1128 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1129 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1130 | - * month_range]=March%202015 |
|
| 1131 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1132 | - * @return string |
|
| 1133 | - */ |
|
| 1134 | - public static function add_query_args_and_nonce( |
|
| 1135 | - $args = array(), |
|
| 1136 | - $url = false, |
|
| 1137 | - $sticky = false, |
|
| 1138 | - $exclude_nonce = false |
|
| 1139 | - ) { |
|
| 1140 | - //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1141 | - if ($sticky) { |
|
| 1142 | - $request = $_REQUEST; |
|
| 1143 | - unset($request['_wp_http_referer']); |
|
| 1144 | - unset($request['wp_referer']); |
|
| 1145 | - foreach ($request as $key => $value) { |
|
| 1146 | - //do not add nonces |
|
| 1147 | - if (strpos($key, 'nonce') !== false) { |
|
| 1148 | - continue; |
|
| 1149 | - } |
|
| 1150 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 1151 | - } |
|
| 1152 | - } |
|
| 1153 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * This returns a generated link that will load the related help tab. |
|
| 1160 | - * |
|
| 1161 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1162 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1163 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1164 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1165 | - * @return string generated link |
|
| 1166 | - */ |
|
| 1167 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1168 | - { |
|
| 1169 | - return EEH_Template::get_help_tab_link( |
|
| 1170 | - $help_tab_id, |
|
| 1171 | - $this->page_slug, |
|
| 1172 | - $this->_req_action, |
|
| 1173 | - $icon_style, |
|
| 1174 | - $help_text |
|
| 1175 | - ); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * _add_help_tabs |
|
| 1182 | - * Note child classes define their help tabs within the page_config array. |
|
| 1183 | - * |
|
| 1184 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1185 | - * @return void |
|
| 1186 | - * @throws DomainException |
|
| 1187 | - * @throws EE_Error |
|
| 1188 | - */ |
|
| 1189 | - protected function _add_help_tabs() |
|
| 1190 | - { |
|
| 1191 | - $tour_buttons = ''; |
|
| 1192 | - if (isset($this->_page_config[$this->_req_action])) { |
|
| 1193 | - $config = $this->_page_config[$this->_req_action]; |
|
| 1194 | - //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1195 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1196 | - $tb = array(); |
|
| 1197 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1198 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1199 | - //if this is the end tour then we don't need to setup a button |
|
| 1200 | - if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1201 | - continue; |
|
| 1202 | - } |
|
| 1203 | - $tb[] = '<button id="trigger-tour-' |
|
| 1204 | - . $tour->get_slug() |
|
| 1205 | - . '" class="button-primary trigger-ee-help-tour">' |
|
| 1206 | - . $tour->get_label() |
|
| 1207 | - . '</button>'; |
|
| 1208 | - } |
|
| 1209 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1210 | - $tour_buttons .= '</div></div>'; |
|
| 1211 | - } |
|
| 1212 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1213 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1214 | - //check that the callback given is valid |
|
| 1215 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1216 | - throw new EE_Error( |
|
| 1217 | - sprintf( |
|
| 1218 | - esc_html__( |
|
| 1219 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1220 | - 'event_espresso' |
|
| 1221 | - ), |
|
| 1222 | - $config['help_sidebar'], |
|
| 1223 | - get_class($this) |
|
| 1224 | - ) |
|
| 1225 | - ); |
|
| 1226 | - } |
|
| 1227 | - $content = apply_filters( |
|
| 1228 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1229 | - $this->{$config['help_sidebar']}() |
|
| 1230 | - ); |
|
| 1231 | - $content .= $tour_buttons; //add help tour buttons. |
|
| 1232 | - //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1233 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1234 | - } |
|
| 1235 | - //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1236 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1237 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1238 | - } |
|
| 1239 | - //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1240 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1241 | - $_ht['id'] = $this->page_slug; |
|
| 1242 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1243 | - $_ht['content'] = '<p>' . esc_html__( |
|
| 1244 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1245 | - 'event_espresso' |
|
| 1246 | - ) . '</p>'; |
|
| 1247 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1248 | - } |
|
| 1249 | - if (! isset($config['help_tabs'])) { |
|
| 1250 | - return; |
|
| 1251 | - } //no help tabs for this route |
|
| 1252 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1253 | - //we're here so there ARE help tabs! |
|
| 1254 | - //make sure we've got what we need |
|
| 1255 | - if (! isset($cfg['title'])) { |
|
| 1256 | - throw new EE_Error( |
|
| 1257 | - esc_html__( |
|
| 1258 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1259 | - 'event_espresso' |
|
| 1260 | - ) |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1264 | - throw new EE_Error( |
|
| 1265 | - esc_html__( |
|
| 1266 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1267 | - 'event_espresso' |
|
| 1268 | - ) |
|
| 1269 | - ); |
|
| 1270 | - } |
|
| 1271 | - //first priority goes to content. |
|
| 1272 | - if (! empty($cfg['content'])) { |
|
| 1273 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1274 | - //second priority goes to filename |
|
| 1275 | - } elseif (! empty($cfg['filename'])) { |
|
| 1276 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1277 | - //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1278 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1279 | - . basename($this->_get_dir()) |
|
| 1280 | - . '/help_tabs/' |
|
| 1281 | - . $cfg['filename'] |
|
| 1282 | - . '.help_tab.php' : $file_path; |
|
| 1283 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1284 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1285 | - EE_Error::add_error( |
|
| 1286 | - sprintf( |
|
| 1287 | - esc_html__( |
|
| 1288 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1289 | - 'event_espresso' |
|
| 1290 | - ), |
|
| 1291 | - $tab_id, |
|
| 1292 | - key($config), |
|
| 1293 | - $file_path |
|
| 1294 | - ), |
|
| 1295 | - __FILE__, |
|
| 1296 | - __FUNCTION__, |
|
| 1297 | - __LINE__ |
|
| 1298 | - ); |
|
| 1299 | - return; |
|
| 1300 | - } |
|
| 1301 | - $template_args['admin_page_obj'] = $this; |
|
| 1302 | - $content = EEH_Template::display_template( |
|
| 1303 | - $file_path, |
|
| 1304 | - $template_args, |
|
| 1305 | - true |
|
| 1306 | - ); |
|
| 1307 | - } else { |
|
| 1308 | - $content = ''; |
|
| 1309 | - } |
|
| 1310 | - //check if callback is valid |
|
| 1311 | - if ( |
|
| 1312 | - empty($content) && ( |
|
| 1313 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1314 | - ) |
|
| 1315 | - ) { |
|
| 1316 | - EE_Error::add_error( |
|
| 1317 | - sprintf( |
|
| 1318 | - esc_html__( |
|
| 1319 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1320 | - 'event_espresso' |
|
| 1321 | - ), |
|
| 1322 | - $cfg['title'] |
|
| 1323 | - ), |
|
| 1324 | - __FILE__, |
|
| 1325 | - __FUNCTION__, |
|
| 1326 | - __LINE__ |
|
| 1327 | - ); |
|
| 1328 | - return; |
|
| 1329 | - } |
|
| 1330 | - //setup config array for help tab method |
|
| 1331 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1332 | - $_ht = array( |
|
| 1333 | - 'id' => $id, |
|
| 1334 | - 'title' => $cfg['title'], |
|
| 1335 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1336 | - 'content' => $content, |
|
| 1337 | - ); |
|
| 1338 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1339 | - } |
|
| 1340 | - } |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1347 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1348 | - * |
|
| 1349 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1350 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1351 | - * _set_page_config() comments |
|
| 1352 | - * @return void |
|
| 1353 | - * @throws EE_Error |
|
| 1354 | - * @throws InvalidArgumentException |
|
| 1355 | - * @throws InvalidDataTypeException |
|
| 1356 | - * @throws InvalidInterfaceException |
|
| 1357 | - */ |
|
| 1358 | - protected function _add_help_tour() |
|
| 1359 | - { |
|
| 1360 | - $tours = array(); |
|
| 1361 | - $this->_help_tour = array(); |
|
| 1362 | - //exit early if help tours are turned off globally |
|
| 1363 | - if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1364 | - || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1365 | - ) { |
|
| 1366 | - return; |
|
| 1367 | - } |
|
| 1368 | - //loop through _page_config to find any help_tour defined |
|
| 1369 | - foreach ($this->_page_config as $route => $config) { |
|
| 1370 | - //we're only going to set things up for this route |
|
| 1371 | - if ($route !== $this->_req_action) { |
|
| 1372 | - continue; |
|
| 1373 | - } |
|
| 1374 | - if (isset($config['help_tour'])) { |
|
| 1375 | - foreach ($config['help_tour'] as $tour) { |
|
| 1376 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1377 | - // let's see if we can get that file... |
|
| 1378 | - // if not its possible this is a decaf route not set in caffeinated |
|
| 1379 | - // so lets try and get the caffeinated equivalent |
|
| 1380 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1381 | - . basename($this->_get_dir()) |
|
| 1382 | - . '/help_tours/' |
|
| 1383 | - . $tour |
|
| 1384 | - . '.class.php' : $file_path; |
|
| 1385 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1386 | - if (! is_readable($file_path)) { |
|
| 1387 | - EE_Error::add_error( |
|
| 1388 | - sprintf( |
|
| 1389 | - esc_html__( |
|
| 1390 | - 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1391 | - 'event_espresso' |
|
| 1392 | - ), |
|
| 1393 | - $file_path, |
|
| 1394 | - $tour |
|
| 1395 | - ), |
|
| 1396 | - __FILE__, |
|
| 1397 | - __FUNCTION__, |
|
| 1398 | - __LINE__ |
|
| 1399 | - ); |
|
| 1400 | - return; |
|
| 1401 | - } |
|
| 1402 | - require_once $file_path; |
|
| 1403 | - if (! class_exists($tour)) { |
|
| 1404 | - $error_msg[] = sprintf( |
|
| 1405 | - esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1406 | - $tour |
|
| 1407 | - ); |
|
| 1408 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1409 | - esc_html__( |
|
| 1410 | - 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1411 | - 'event_espresso' |
|
| 1412 | - ), |
|
| 1413 | - $tour, |
|
| 1414 | - '<br />', |
|
| 1415 | - $tour, |
|
| 1416 | - $this->_req_action, |
|
| 1417 | - get_class($this) |
|
| 1418 | - ); |
|
| 1419 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1420 | - } |
|
| 1421 | - $tour_obj = new $tour($this->_is_caf); |
|
| 1422 | - $tours[] = $tour_obj; |
|
| 1423 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1424 | - } |
|
| 1425 | - //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1426 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1427 | - $tours[] = $end_stop_tour; |
|
| 1428 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1429 | - } |
|
| 1430 | - } |
|
| 1431 | - if (! empty($tours)) { |
|
| 1432 | - $this->_help_tour['tours'] = $tours; |
|
| 1433 | - } |
|
| 1434 | - // that's it! Now that the $_help_tours property is set (or not) |
|
| 1435 | - // the scripts and html should be taken care of automatically. |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - |
|
| 1439 | - |
|
| 1440 | - /** |
|
| 1441 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1442 | - * |
|
| 1443 | - * @return void |
|
| 1444 | - */ |
|
| 1445 | - protected function _add_qtips() |
|
| 1446 | - { |
|
| 1447 | - if (isset($this->_route_config['qtips'])) { |
|
| 1448 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1449 | - //load qtip loader |
|
| 1450 | - $path = array( |
|
| 1451 | - $this->_get_dir() . '/qtips/', |
|
| 1452 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1453 | - ); |
|
| 1454 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1455 | - } |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - /** |
|
| 1461 | - * _set_nav_tabs |
|
| 1462 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1463 | - * wish to add additional tabs or modify accordingly. |
|
| 1464 | - * |
|
| 1465 | - * @return void |
|
| 1466 | - * @throws InvalidArgumentException |
|
| 1467 | - * @throws InvalidInterfaceException |
|
| 1468 | - * @throws InvalidDataTypeException |
|
| 1469 | - */ |
|
| 1470 | - protected function _set_nav_tabs() |
|
| 1471 | - { |
|
| 1472 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1473 | - $i = 0; |
|
| 1474 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1475 | - if ( |
|
| 1476 | - ! is_array($config) |
|
| 1477 | - || ( |
|
| 1478 | - is_array($config) |
|
| 1479 | - && ( |
|
| 1480 | - (isset($config['nav']) && ! $config['nav']) |
|
| 1481 | - || ! isset($config['nav']) |
|
| 1482 | - ) |
|
| 1483 | - ) |
|
| 1484 | - ) { |
|
| 1485 | - continue; |
|
| 1486 | - } |
|
| 1487 | - //no nav tab for this config |
|
| 1488 | - //check for persistent flag |
|
| 1489 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1490 | - // nav tab is only to appear when route requested. |
|
| 1491 | - continue; |
|
| 1492 | - } |
|
| 1493 | - if (! $this->check_user_access($slug, true)) { |
|
| 1494 | - // no nav tab because current user does not have access. |
|
| 1495 | - continue; |
|
| 1496 | - } |
|
| 1497 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1498 | - $this->_nav_tabs[$slug] = array( |
|
| 1499 | - 'url' => isset($config['nav']['url']) |
|
| 1500 | - ? $config['nav']['url'] |
|
| 1501 | - : self::add_query_args_and_nonce( |
|
| 1502 | - array('action' => $slug), |
|
| 1503 | - $this->_admin_base_url |
|
| 1504 | - ), |
|
| 1505 | - 'link_text' => isset($config['nav']['label']) |
|
| 1506 | - ? $config['nav']['label'] |
|
| 1507 | - : ucwords( |
|
| 1508 | - str_replace('_', ' ', $slug) |
|
| 1509 | - ), |
|
| 1510 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1511 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1512 | - ); |
|
| 1513 | - $i++; |
|
| 1514 | - } |
|
| 1515 | - //if $this->_nav_tabs is empty then lets set the default |
|
| 1516 | - if (empty($this->_nav_tabs)) { |
|
| 1517 | - $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1518 | - 'url' => $this->_admin_base_url, |
|
| 1519 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1520 | - 'css_class' => 'nav-tab-active', |
|
| 1521 | - 'order' => 10, |
|
| 1522 | - ); |
|
| 1523 | - } |
|
| 1524 | - //now let's sort the tabs according to order |
|
| 1525 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * _set_current_labels |
|
| 1532 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1533 | - * property array |
|
| 1534 | - * |
|
| 1535 | - * @return void |
|
| 1536 | - */ |
|
| 1537 | - private function _set_current_labels() |
|
| 1538 | - { |
|
| 1539 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1540 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1541 | - if (is_array($text)) { |
|
| 1542 | - foreach ($text as $sublabel => $subtext) { |
|
| 1543 | - $this->_labels[$label][$sublabel] = $subtext; |
|
| 1544 | - } |
|
| 1545 | - } else { |
|
| 1546 | - $this->_labels[$label] = $text; |
|
| 1547 | - } |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - |
|
| 1553 | - |
|
| 1554 | - /** |
|
| 1555 | - * verifies user access for this admin page |
|
| 1556 | - * |
|
| 1557 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1558 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1559 | - * return false if verify fail. |
|
| 1560 | - * @return bool |
|
| 1561 | - * @throws InvalidArgumentException |
|
| 1562 | - * @throws InvalidDataTypeException |
|
| 1563 | - * @throws InvalidInterfaceException |
|
| 1564 | - */ |
|
| 1565 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1566 | - { |
|
| 1567 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1568 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1569 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1570 | - && is_array( |
|
| 1571 | - $this->_page_routes[$route_to_check] |
|
| 1572 | - ) |
|
| 1573 | - && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1574 | - ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1575 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1576 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1577 | - : $this->_route['capability']; |
|
| 1578 | - } else { |
|
| 1579 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1580 | - } |
|
| 1581 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1582 | - if ( |
|
| 1583 | - ! defined('DOING_AJAX') |
|
| 1584 | - && ( |
|
| 1585 | - ! function_exists('is_admin') |
|
| 1586 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1587 | - $capability, |
|
| 1588 | - $this->page_slug |
|
| 1589 | - . '_' |
|
| 1590 | - . $route_to_check, |
|
| 1591 | - $id |
|
| 1592 | - ) |
|
| 1593 | - ) |
|
| 1594 | - ) { |
|
| 1595 | - if ($verify_only) { |
|
| 1596 | - return false; |
|
| 1597 | - } |
|
| 1598 | - if (is_user_logged_in()) { |
|
| 1599 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1600 | - } else { |
|
| 1601 | - return false; |
|
| 1602 | - } |
|
| 1603 | - } |
|
| 1604 | - return true; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * admin_init_global |
|
| 1611 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1612 | - * This method executes for ALL EE Admin pages. |
|
| 1613 | - * |
|
| 1614 | - * @return void |
|
| 1615 | - */ |
|
| 1616 | - public function admin_init_global() |
|
| 1617 | - { |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * wp_loaded_global |
|
| 1624 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1625 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1626 | - * |
|
| 1627 | - * @return void |
|
| 1628 | - */ |
|
| 1629 | - public function wp_loaded() |
|
| 1630 | - { |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * admin_notices |
|
| 1637 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1638 | - * ALL EE_Admin pages. |
|
| 1639 | - * |
|
| 1640 | - * @return void |
|
| 1641 | - */ |
|
| 1642 | - public function admin_notices_global() |
|
| 1643 | - { |
|
| 1644 | - $this->_display_no_javascript_warning(); |
|
| 1645 | - $this->_display_espresso_notices(); |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - |
|
| 1649 | - |
|
| 1650 | - public function network_admin_notices_global() |
|
| 1651 | - { |
|
| 1652 | - $this->_display_no_javascript_warning(); |
|
| 1653 | - $this->_display_espresso_notices(); |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | - /** |
|
| 1659 | - * admin_footer_scripts_global |
|
| 1660 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1661 | - * will apply on ALL EE_Admin pages. |
|
| 1662 | - * |
|
| 1663 | - * @return void |
|
| 1664 | - */ |
|
| 1665 | - public function admin_footer_scripts_global() |
|
| 1666 | - { |
|
| 1667 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1668 | - $this->_add_admin_page_overlay(); |
|
| 1669 | - //if metaboxes are present we need to add the nonce field |
|
| 1670 | - if ( |
|
| 1671 | - isset($this->_route_config['metaboxes']) |
|
| 1672 | - || isset($this->_route_config['list_table']) |
|
| 1673 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1674 | - ) { |
|
| 1675 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1676 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1677 | - } |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * admin_footer_global |
|
| 1684 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1685 | - * ALL EE_Admin Pages. |
|
| 1686 | - * |
|
| 1687 | - * @return void |
|
| 1688 | - * @throws EE_Error |
|
| 1689 | - */ |
|
| 1690 | - public function admin_footer_global() |
|
| 1691 | - { |
|
| 1692 | - //dialog container for dialog helper |
|
| 1693 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1694 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1695 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1696 | - $d_cont .= '</div>'; |
|
| 1697 | - echo $d_cont; |
|
| 1698 | - //help tour stuff? |
|
| 1699 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1700 | - echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1701 | - } |
|
| 1702 | - //current set timezone for timezone js |
|
| 1703 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1704 | - } |
|
| 1705 | - |
|
| 1706 | - |
|
| 1707 | - |
|
| 1708 | - /** |
|
| 1709 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1710 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1711 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1712 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1713 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1714 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1715 | - * for the |
|
| 1716 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1717 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1718 | - * 'help_trigger_id' => array( |
|
| 1719 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1720 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1721 | - * ) |
|
| 1722 | - * ); |
|
| 1723 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1724 | - * |
|
| 1725 | - * @param array $help_array |
|
| 1726 | - * @param bool $display |
|
| 1727 | - * @return string content |
|
| 1728 | - * @throws DomainException |
|
| 1729 | - * @throws EE_Error |
|
| 1730 | - */ |
|
| 1731 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1732 | - { |
|
| 1733 | - $content = ''; |
|
| 1734 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1735 | - //loop through the array and setup content |
|
| 1736 | - foreach ($help_array as $trigger => $help) { |
|
| 1737 | - //make sure the array is setup properly |
|
| 1738 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1739 | - throw new EE_Error( |
|
| 1740 | - esc_html__( |
|
| 1741 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1742 | - 'event_espresso' |
|
| 1743 | - ) |
|
| 1744 | - ); |
|
| 1745 | - } |
|
| 1746 | - //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1747 | - $template_args = array( |
|
| 1748 | - 'help_popup_id' => $trigger, |
|
| 1749 | - 'help_popup_title' => $help['title'], |
|
| 1750 | - 'help_popup_content' => $help['content'], |
|
| 1751 | - ); |
|
| 1752 | - $content .= EEH_Template::display_template( |
|
| 1753 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1754 | - $template_args, |
|
| 1755 | - true |
|
| 1756 | - ); |
|
| 1757 | - } |
|
| 1758 | - if ($display) { |
|
| 1759 | - echo $content; |
|
| 1760 | - return ''; |
|
| 1761 | - } |
|
| 1762 | - return $content; |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - /** |
|
| 1768 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1769 | - * |
|
| 1770 | - * @return array properly formatted array for help popup content |
|
| 1771 | - * @throws EE_Error |
|
| 1772 | - */ |
|
| 1773 | - private function _get_help_content() |
|
| 1774 | - { |
|
| 1775 | - //what is the method we're looking for? |
|
| 1776 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1777 | - //if method doesn't exist let's get out. |
|
| 1778 | - if (! method_exists($this, $method_name)) { |
|
| 1779 | - return array(); |
|
| 1780 | - } |
|
| 1781 | - //k we're good to go let's retrieve the help array |
|
| 1782 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1783 | - //make sure we've got an array! |
|
| 1784 | - if (! is_array($help_array)) { |
|
| 1785 | - throw new EE_Error( |
|
| 1786 | - esc_html__( |
|
| 1787 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1788 | - 'event_espresso' |
|
| 1789 | - ) |
|
| 1790 | - ); |
|
| 1791 | - } |
|
| 1792 | - return $help_array; |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - |
|
| 1797 | - /** |
|
| 1798 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1799 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1800 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1801 | - * |
|
| 1802 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1803 | - * @param boolean $display if false then we return the trigger string |
|
| 1804 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1805 | - * @return string |
|
| 1806 | - * @throws DomainException |
|
| 1807 | - * @throws EE_Error |
|
| 1808 | - */ |
|
| 1809 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1810 | - { |
|
| 1811 | - if (defined('DOING_AJAX')) { |
|
| 1812 | - return ''; |
|
| 1813 | - } |
|
| 1814 | - //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1815 | - $help_array = $this->_get_help_content(); |
|
| 1816 | - $help_content = ''; |
|
| 1817 | - if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1818 | - $help_array[$trigger_id] = array( |
|
| 1819 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1820 | - 'content' => esc_html__( |
|
| 1821 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1822 | - 'event_espresso' |
|
| 1823 | - ), |
|
| 1824 | - ); |
|
| 1825 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1826 | - } |
|
| 1827 | - //let's setup the trigger |
|
| 1828 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1829 | - . $dimensions[0] |
|
| 1830 | - . '&width=' |
|
| 1831 | - . $dimensions[1] |
|
| 1832 | - . '&inlineId=' |
|
| 1833 | - . $trigger_id |
|
| 1834 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1835 | - $content .= $help_content; |
|
| 1836 | - if ($display) { |
|
| 1837 | - echo $content; |
|
| 1838 | - return ''; |
|
| 1839 | - } |
|
| 1840 | - return $content; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * _add_global_screen_options |
|
| 1847 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1848 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1849 | - * |
|
| 1850 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1851 | - * see also WP_Screen object documents... |
|
| 1852 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1853 | - * @abstract |
|
| 1854 | - * @return void |
|
| 1855 | - */ |
|
| 1856 | - private function _add_global_screen_options() |
|
| 1857 | - { |
|
| 1858 | - } |
|
| 1859 | - |
|
| 1860 | - |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * _add_global_feature_pointers |
|
| 1864 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1865 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1866 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1867 | - * |
|
| 1868 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1869 | - * extended) also see: |
|
| 1870 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1871 | - * @abstract |
|
| 1872 | - * @return void |
|
| 1873 | - */ |
|
| 1874 | - private function _add_global_feature_pointers() |
|
| 1875 | - { |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * load_global_scripts_styles |
|
| 1882 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1883 | - * |
|
| 1884 | - * @return void |
|
| 1885 | - * @throws EE_Error |
|
| 1886 | - */ |
|
| 1887 | - public function load_global_scripts_styles() |
|
| 1888 | - { |
|
| 1889 | - /** STYLES **/ |
|
| 1890 | - // add debugging styles |
|
| 1891 | - if (WP_DEBUG) { |
|
| 1892 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1893 | - } |
|
| 1894 | - // register all styles |
|
| 1895 | - wp_register_style( |
|
| 1896 | - 'espresso-ui-theme', |
|
| 1897 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1898 | - array(), |
|
| 1899 | - EVENT_ESPRESSO_VERSION |
|
| 1900 | - ); |
|
| 1901 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1902 | - //helpers styles |
|
| 1903 | - wp_register_style( |
|
| 1904 | - 'ee-text-links', |
|
| 1905 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1906 | - array(), |
|
| 1907 | - EVENT_ESPRESSO_VERSION |
|
| 1908 | - ); |
|
| 1909 | - /** SCRIPTS **/ |
|
| 1910 | - //register all scripts |
|
| 1911 | - wp_register_script( |
|
| 1912 | - 'ee-dialog', |
|
| 1913 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1914 | - array('jquery', 'jquery-ui-draggable'), |
|
| 1915 | - EVENT_ESPRESSO_VERSION, |
|
| 1916 | - true |
|
| 1917 | - ); |
|
| 1918 | - wp_register_script( |
|
| 1919 | - 'ee_admin_js', |
|
| 1920 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1921 | - array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1922 | - EVENT_ESPRESSO_VERSION, |
|
| 1923 | - true |
|
| 1924 | - ); |
|
| 1925 | - wp_register_script( |
|
| 1926 | - 'jquery-ui-timepicker-addon', |
|
| 1927 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1928 | - array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1929 | - EVENT_ESPRESSO_VERSION, |
|
| 1930 | - true |
|
| 1931 | - ); |
|
| 1932 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1933 | - //script for sorting tables |
|
| 1934 | - wp_register_script( |
|
| 1935 | - 'espresso_ajax_table_sorting', |
|
| 1936 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1937 | - array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1938 | - EVENT_ESPRESSO_VERSION, |
|
| 1939 | - true |
|
| 1940 | - ); |
|
| 1941 | - //script for parsing uri's |
|
| 1942 | - wp_register_script( |
|
| 1943 | - 'ee-parse-uri', |
|
| 1944 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1945 | - array(), |
|
| 1946 | - EVENT_ESPRESSO_VERSION, |
|
| 1947 | - true |
|
| 1948 | - ); |
|
| 1949 | - //and parsing associative serialized form elements |
|
| 1950 | - wp_register_script( |
|
| 1951 | - 'ee-serialize-full-array', |
|
| 1952 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1953 | - array('jquery'), |
|
| 1954 | - EVENT_ESPRESSO_VERSION, |
|
| 1955 | - true |
|
| 1956 | - ); |
|
| 1957 | - //helpers scripts |
|
| 1958 | - wp_register_script( |
|
| 1959 | - 'ee-text-links', |
|
| 1960 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1961 | - array('jquery'), |
|
| 1962 | - EVENT_ESPRESSO_VERSION, |
|
| 1963 | - true |
|
| 1964 | - ); |
|
| 1965 | - wp_register_script( |
|
| 1966 | - 'ee-moment-core', |
|
| 1967 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1968 | - array(), |
|
| 1969 | - EVENT_ESPRESSO_VERSION, |
|
| 1970 | - true |
|
| 1971 | - ); |
|
| 1972 | - wp_register_script( |
|
| 1973 | - 'ee-moment', |
|
| 1974 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1975 | - array('ee-moment-core'), |
|
| 1976 | - EVENT_ESPRESSO_VERSION, |
|
| 1977 | - true |
|
| 1978 | - ); |
|
| 1979 | - wp_register_script( |
|
| 1980 | - 'ee-datepicker', |
|
| 1981 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1982 | - array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1983 | - EVENT_ESPRESSO_VERSION, |
|
| 1984 | - true |
|
| 1985 | - ); |
|
| 1986 | - //google charts |
|
| 1987 | - wp_register_script( |
|
| 1988 | - 'google-charts', |
|
| 1989 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1990 | - array(), |
|
| 1991 | - EVENT_ESPRESSO_VERSION, |
|
| 1992 | - false |
|
| 1993 | - ); |
|
| 1994 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1995 | - wp_enqueue_style('ee-admin-css'); |
|
| 1996 | - wp_enqueue_script('ee_admin_js'); |
|
| 1997 | - wp_enqueue_script('ee-accounting'); |
|
| 1998 | - wp_enqueue_script('jquery-validate'); |
|
| 1999 | - //taking care of metaboxes |
|
| 2000 | - if ( |
|
| 2001 | - empty($this->_cpt_route) |
|
| 2002 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2003 | - ) { |
|
| 2004 | - wp_enqueue_script('dashboard'); |
|
| 2005 | - } |
|
| 2006 | - // LOCALIZED DATA |
|
| 2007 | - //localize script for ajax lazy loading |
|
| 2008 | - $lazy_loader_container_ids = apply_filters( |
|
| 2009 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2010 | - array('espresso_news_post_box_content') |
|
| 2011 | - ); |
|
| 2012 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2013 | - /** |
|
| 2014 | - * help tour stuff |
|
| 2015 | - */ |
|
| 2016 | - if (! empty($this->_help_tour)) { |
|
| 2017 | - //register the js for kicking things off |
|
| 2018 | - wp_enqueue_script( |
|
| 2019 | - 'ee-help-tour', |
|
| 2020 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2021 | - array('jquery-joyride'), |
|
| 2022 | - EVENT_ESPRESSO_VERSION, |
|
| 2023 | - true |
|
| 2024 | - ); |
|
| 2025 | - $tours = array(); |
|
| 2026 | - //setup tours for the js tour object |
|
| 2027 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2028 | - if ($tour instanceof EE_Help_Tour) { |
|
| 2029 | - $tours[] = array( |
|
| 2030 | - 'id' => $tour->get_slug(), |
|
| 2031 | - 'options' => $tour->get_options(), |
|
| 2032 | - ); |
|
| 2033 | - } |
|
| 2034 | - } |
|
| 2035 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2036 | - //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2037 | - } |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * admin_footer_scripts_eei18n_js_strings |
|
| 2044 | - * |
|
| 2045 | - * @return void |
|
| 2046 | - */ |
|
| 2047 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2048 | - { |
|
| 2049 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2050 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2051 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2052 | - 'event_espresso' |
|
| 2053 | - ); |
|
| 2054 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2055 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2056 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2057 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2058 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2059 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2060 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2061 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2062 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2063 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2064 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2065 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2066 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2067 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2068 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2069 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2070 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2071 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2072 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2073 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2074 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2075 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2076 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2077 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2078 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2079 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2080 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2081 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2082 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2083 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2084 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2085 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2086 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2087 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2088 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2089 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2090 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2091 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - |
|
| 2095 | - |
|
| 2096 | - /** |
|
| 2097 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2098 | - * |
|
| 2099 | - * @return void |
|
| 2100 | - */ |
|
| 2101 | - public function add_xdebug_style() |
|
| 2102 | - { |
|
| 2103 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - |
|
| 2107 | - /************************/ |
|
| 2108 | - /** LIST TABLE METHODS **/ |
|
| 2109 | - /************************/ |
|
| 2110 | - /** |
|
| 2111 | - * this sets up the list table if the current view requires it. |
|
| 2112 | - * |
|
| 2113 | - * @return void |
|
| 2114 | - * @throws EE_Error |
|
| 2115 | - */ |
|
| 2116 | - protected function _set_list_table() |
|
| 2117 | - { |
|
| 2118 | - //first is this a list_table view? |
|
| 2119 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2120 | - return; |
|
| 2121 | - } //not a list_table view so get out. |
|
| 2122 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2123 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2124 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2125 | - //user error msg |
|
| 2126 | - $error_msg = esc_html__( |
|
| 2127 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2128 | - 'event_espresso' |
|
| 2129 | - ); |
|
| 2130 | - //developer error msg |
|
| 2131 | - $error_msg .= '||' . sprintf( |
|
| 2132 | - esc_html__( |
|
| 2133 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2134 | - 'event_espresso' |
|
| 2135 | - ), |
|
| 2136 | - $this->_req_action, |
|
| 2137 | - $list_table_view |
|
| 2138 | - ); |
|
| 2139 | - throw new EE_Error($error_msg); |
|
| 2140 | - } |
|
| 2141 | - //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2142 | - $this->_views = apply_filters( |
|
| 2143 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2144 | - $this->_views |
|
| 2145 | - ); |
|
| 2146 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2147 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2148 | - $this->_set_list_table_view(); |
|
| 2149 | - $this->_set_list_table_object(); |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - |
|
| 2153 | - |
|
| 2154 | - /** |
|
| 2155 | - * set current view for List Table |
|
| 2156 | - * |
|
| 2157 | - * @return void |
|
| 2158 | - */ |
|
| 2159 | - protected function _set_list_table_view() |
|
| 2160 | - { |
|
| 2161 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2162 | - // looking at active items or dumpster diving ? |
|
| 2163 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2164 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2165 | - } else { |
|
| 2166 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2167 | - } |
|
| 2168 | - } |
|
| 2169 | - |
|
| 2170 | - |
|
| 2171 | - |
|
| 2172 | - /** |
|
| 2173 | - * _set_list_table_object |
|
| 2174 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2175 | - * |
|
| 2176 | - * @throws EE_Error |
|
| 2177 | - */ |
|
| 2178 | - protected function _set_list_table_object() |
|
| 2179 | - { |
|
| 2180 | - if (isset($this->_route_config['list_table'])) { |
|
| 2181 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2182 | - throw new EE_Error( |
|
| 2183 | - sprintf( |
|
| 2184 | - esc_html__( |
|
| 2185 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2186 | - 'event_espresso' |
|
| 2187 | - ), |
|
| 2188 | - $this->_route_config['list_table'], |
|
| 2189 | - get_class($this) |
|
| 2190 | - ) |
|
| 2191 | - ); |
|
| 2192 | - } |
|
| 2193 | - $list_table = $this->_route_config['list_table']; |
|
| 2194 | - $this->_list_table_object = new $list_table($this); |
|
| 2195 | - } |
|
| 2196 | - } |
|
| 2197 | - |
|
| 2198 | - |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2202 | - * |
|
| 2203 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2204 | - * urls. The array should be indexed by the view it is being |
|
| 2205 | - * added to. |
|
| 2206 | - * @return array |
|
| 2207 | - */ |
|
| 2208 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2209 | - { |
|
| 2210 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2211 | - if (empty($this->_views)) { |
|
| 2212 | - $this->_views = array(); |
|
| 2213 | - } |
|
| 2214 | - // cycle thru views |
|
| 2215 | - foreach ($this->_views as $key => $view) { |
|
| 2216 | - $query_args = array(); |
|
| 2217 | - // check for current view |
|
| 2218 | - $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2219 | - $query_args['action'] = $this->_req_action; |
|
| 2220 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2221 | - $query_args['status'] = $view['slug']; |
|
| 2222 | - //merge any other arguments sent in. |
|
| 2223 | - if (isset($extra_query_args[$view['slug']])) { |
|
| 2224 | - $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2225 | - } |
|
| 2226 | - $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2227 | - } |
|
| 2228 | - return $this->_views; |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * _entries_per_page_dropdown |
|
| 2235 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2236 | - * |
|
| 2237 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2238 | - * WP does it. |
|
| 2239 | - * @param int $max_entries total number of rows in the table |
|
| 2240 | - * @return string |
|
| 2241 | - */ |
|
| 2242 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2243 | - { |
|
| 2244 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2245 | - $values = array(10, 25, 50, 100); |
|
| 2246 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2247 | - if ($max_entries) { |
|
| 2248 | - $values[] = $max_entries; |
|
| 2249 | - sort($values); |
|
| 2250 | - } |
|
| 2251 | - $entries_per_page_dropdown = ' |
|
| 125 | + /** |
|
| 126 | + * @var string $_req_action |
|
| 127 | + */ |
|
| 128 | + protected $_req_action; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var string $_req_nonce |
|
| 132 | + */ |
|
| 133 | + protected $_req_nonce; |
|
| 134 | + |
|
| 135 | + //search related |
|
| 136 | + protected $_search_btn_label; |
|
| 137 | + |
|
| 138 | + protected $_search_box_callback; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * WP Current Screen object |
|
| 142 | + * |
|
| 143 | + * @var WP_Screen |
|
| 144 | + */ |
|
| 145 | + protected $_current_screen; |
|
| 146 | + |
|
| 147 | + //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 148 | + protected $_hook_obj; |
|
| 149 | + |
|
| 150 | + //for holding incoming request data |
|
| 151 | + protected $_req_data; |
|
| 152 | + |
|
| 153 | + // yes / no array for admin form fields |
|
| 154 | + protected $_yes_no_values = array(); |
|
| 155 | + |
|
| 156 | + //some default things shared by all child classes |
|
| 157 | + protected $_default_espresso_metaboxes; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * EE_Registry Object |
|
| 161 | + * |
|
| 162 | + * @var EE_Registry |
|
| 163 | + */ |
|
| 164 | + protected $EE = null; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 170 | + * |
|
| 171 | + * @var boolean |
|
| 172 | + */ |
|
| 173 | + protected $_is_caf = false; |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @Constructor |
|
| 179 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 180 | + * @throws EE_Error |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + * @throws InvalidDataTypeException |
|
| 184 | + * @throws InvalidInterfaceException |
|
| 185 | + */ |
|
| 186 | + public function __construct($routing = true) |
|
| 187 | + { |
|
| 188 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 189 | + $this->_is_caf = true; |
|
| 190 | + } |
|
| 191 | + $this->_yes_no_values = array( |
|
| 192 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 193 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 194 | + ); |
|
| 195 | + //set the _req_data property. |
|
| 196 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 197 | + //routing enabled? |
|
| 198 | + $this->_routing = $routing; |
|
| 199 | + //set initial page props (child method) |
|
| 200 | + $this->_init_page_props(); |
|
| 201 | + //set global defaults |
|
| 202 | + $this->_set_defaults(); |
|
| 203 | + //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 204 | + $this->_global_ajax_hooks(); |
|
| 205 | + $this->_ajax_hooks(); |
|
| 206 | + //other_page_hooks have to be early too. |
|
| 207 | + $this->_do_other_page_hooks(); |
|
| 208 | + //This just allows us to have extending classes do something specific |
|
| 209 | + // before the parent constructor runs _page_setup(). |
|
| 210 | + if (method_exists($this, '_before_page_setup')) { |
|
| 211 | + $this->_before_page_setup(); |
|
| 212 | + } |
|
| 213 | + //set up page dependencies |
|
| 214 | + $this->_page_setup(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * _init_page_props |
|
| 221 | + * Child classes use to set at least the following properties: |
|
| 222 | + * $page_slug. |
|
| 223 | + * $page_label. |
|
| 224 | + * |
|
| 225 | + * @abstract |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + abstract protected function _init_page_props(); |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * _ajax_hooks |
|
| 234 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 235 | + * Note: within the ajax callback methods. |
|
| 236 | + * |
|
| 237 | + * @abstract |
|
| 238 | + * @return void |
|
| 239 | + */ |
|
| 240 | + abstract protected function _ajax_hooks(); |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * _define_page_props |
|
| 246 | + * child classes define page properties in here. Must include at least: |
|
| 247 | + * $_admin_base_url = base_url for all admin pages |
|
| 248 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 249 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 250 | + * array( |
|
| 251 | + * 'buttons' => array( |
|
| 252 | + * 'add' => esc_html__('label for add new button'), |
|
| 253 | + * 'edit' => esc_html__('label for edit button'), |
|
| 254 | + * 'delete' => esc_html__('label for delete button') |
|
| 255 | + * ) |
|
| 256 | + * ) |
|
| 257 | + * |
|
| 258 | + * @abstract |
|
| 259 | + * @return void |
|
| 260 | + */ |
|
| 261 | + abstract protected function _define_page_props(); |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * _set_page_routes |
|
| 267 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 268 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 269 | + * have a 'default' route. Here's the format |
|
| 270 | + * $this->_page_routes = array( |
|
| 271 | + * 'default' => array( |
|
| 272 | + * 'func' => '_default_method_handling_route', |
|
| 273 | + * 'args' => array('array','of','args'), |
|
| 274 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 275 | + * ajax request, backend processing) |
|
| 276 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 277 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 278 | + * headers sent route. |
|
| 279 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 280 | + * this route. |
|
| 281 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 282 | + * checks). |
|
| 283 | + * ), |
|
| 284 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 285 | + * handling method. |
|
| 286 | + * ) |
|
| 287 | + * ) |
|
| 288 | + * |
|
| 289 | + * @abstract |
|
| 290 | + * @return void |
|
| 291 | + */ |
|
| 292 | + abstract protected function _set_page_routes(); |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * _set_page_config |
|
| 298 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 299 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 300 | + * $this->_page_config = array( |
|
| 301 | + * 'default' => array( |
|
| 302 | + * 'labels' => array( |
|
| 303 | + * 'buttons' => array( |
|
| 304 | + * 'add' => esc_html__('label for adding item'), |
|
| 305 | + * 'edit' => esc_html__('label for editing item'), |
|
| 306 | + * 'delete' => esc_html__('label for deleting item') |
|
| 307 | + * ), |
|
| 308 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 309 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 310 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 311 | + * _define_page_props() method |
|
| 312 | + * 'nav' => array( |
|
| 313 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 314 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 315 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 316 | + * 'order' => 10, //required to indicate tab position. |
|
| 317 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 318 | + * displayed then add this parameter. |
|
| 319 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 320 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 321 | + * metaboxes set for eventespresso admin pages. |
|
| 322 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 323 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 324 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 325 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 326 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 327 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 328 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 329 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 330 | + * want to display. |
|
| 331 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 332 | + * 'tab_id' => array( |
|
| 333 | + * 'title' => 'tab_title', |
|
| 334 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 335 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 336 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 337 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 338 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 339 | + * attempt to use the callback which should match the name of a method in the class |
|
| 340 | + * ), |
|
| 341 | + * 'tab2_id' => array( |
|
| 342 | + * 'title' => 'tab2 title', |
|
| 343 | + * 'filename' => 'file_name_2' |
|
| 344 | + * 'callback' => 'callback_method_for_content', |
|
| 345 | + * ), |
|
| 346 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 347 | + * help tab area on an admin page. @link |
|
| 348 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 349 | + * 'help_tour' => array( |
|
| 350 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 351 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 352 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 353 | + * ), |
|
| 354 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 355 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 356 | + * just set |
|
| 357 | + * 'require_nonce' to FALSE |
|
| 358 | + * ) |
|
| 359 | + * ) |
|
| 360 | + * |
|
| 361 | + * @abstract |
|
| 362 | + * @return void |
|
| 363 | + */ |
|
| 364 | + abstract protected function _set_page_config(); |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** end sample help_tour methods **/ |
|
| 371 | + /** |
|
| 372 | + * _add_screen_options |
|
| 373 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 374 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 375 | + * to a particular view. |
|
| 376 | + * |
|
| 377 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 378 | + * see also WP_Screen object documents... |
|
| 379 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 380 | + * @abstract |
|
| 381 | + * @return void |
|
| 382 | + */ |
|
| 383 | + abstract protected function _add_screen_options(); |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * _add_feature_pointers |
|
| 389 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 390 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 391 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 392 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 393 | + * extended) also see: |
|
| 394 | + * |
|
| 395 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 396 | + * @abstract |
|
| 397 | + * @return void |
|
| 398 | + */ |
|
| 399 | + abstract protected function _add_feature_pointers(); |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * load_scripts_styles |
|
| 405 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 406 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 407 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 408 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 409 | + * |
|
| 410 | + * @abstract |
|
| 411 | + * @return void |
|
| 412 | + */ |
|
| 413 | + abstract public function load_scripts_styles(); |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * admin_init |
|
| 419 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 420 | + * all pages/views loaded by child class. |
|
| 421 | + * |
|
| 422 | + * @abstract |
|
| 423 | + * @return void |
|
| 424 | + */ |
|
| 425 | + abstract public function admin_init(); |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * admin_notices |
|
| 431 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 432 | + * all pages/views loaded by child class. |
|
| 433 | + * |
|
| 434 | + * @abstract |
|
| 435 | + * @return void |
|
| 436 | + */ |
|
| 437 | + abstract public function admin_notices(); |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * admin_footer_scripts |
|
| 443 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 444 | + * will apply to all pages/views loaded by child class. |
|
| 445 | + * |
|
| 446 | + * @return void |
|
| 447 | + */ |
|
| 448 | + abstract public function admin_footer_scripts(); |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * admin_footer |
|
| 454 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 455 | + * apply to all pages/views loaded by child class. |
|
| 456 | + * |
|
| 457 | + * @return void |
|
| 458 | + */ |
|
| 459 | + public function admin_footer() |
|
| 460 | + { |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * _global_ajax_hooks |
|
| 467 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 468 | + * Note: within the ajax callback methods. |
|
| 469 | + * |
|
| 470 | + * @abstract |
|
| 471 | + * @return void |
|
| 472 | + */ |
|
| 473 | + protected function _global_ajax_hooks() |
|
| 474 | + { |
|
| 475 | + //for lazy loading of metabox content |
|
| 476 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + public function ajax_metabox_content() |
|
| 482 | + { |
|
| 483 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 484 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 485 | + self::cached_rss_display($contentid, $url); |
|
| 486 | + wp_die(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * _page_setup |
|
| 493 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 494 | + * doesn't match the object. |
|
| 495 | + * |
|
| 496 | + * @final |
|
| 497 | + * @return void |
|
| 498 | + * @throws EE_Error |
|
| 499 | + * @throws InvalidArgumentException |
|
| 500 | + * @throws ReflectionException |
|
| 501 | + * @throws InvalidDataTypeException |
|
| 502 | + * @throws InvalidInterfaceException |
|
| 503 | + */ |
|
| 504 | + final protected function _page_setup() |
|
| 505 | + { |
|
| 506 | + //requires? |
|
| 507 | + //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 508 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 509 | + //next verify if we need to load anything... |
|
| 510 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 511 | + $this->page_folder = strtolower( |
|
| 512 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 513 | + ); |
|
| 514 | + global $ee_menu_slugs; |
|
| 515 | + $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 516 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 517 | + return; |
|
| 518 | + } |
|
| 519 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 520 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 521 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 522 | + ? $this->_req_data['action2'] |
|
| 523 | + : $this->_req_data['action']; |
|
| 524 | + } |
|
| 525 | + // then set blank or -1 action values to 'default' |
|
| 526 | + $this->_req_action = isset($this->_req_data['action']) |
|
| 527 | + && ! empty($this->_req_data['action']) |
|
| 528 | + && $this->_req_data['action'] !== '-1' |
|
| 529 | + ? sanitize_key($this->_req_data['action']) |
|
| 530 | + : 'default'; |
|
| 531 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 532 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 533 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 534 | + ? $this->_req_data['route'] : $this->_req_action; |
|
| 535 | + //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 536 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 537 | + ? $this->_req_data['route'] |
|
| 538 | + : $this->_req_action; |
|
| 539 | + $this->_current_view = $this->_req_action; |
|
| 540 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 541 | + $this->_define_page_props(); |
|
| 542 | + $this->_current_page_view_url = add_query_arg( |
|
| 543 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 544 | + $this->_admin_base_url |
|
| 545 | + ); |
|
| 546 | + //default things |
|
| 547 | + $this->_default_espresso_metaboxes = array( |
|
| 548 | + '_espresso_news_post_box', |
|
| 549 | + '_espresso_links_post_box', |
|
| 550 | + '_espresso_ratings_request', |
|
| 551 | + '_espresso_sponsors_post_box', |
|
| 552 | + ); |
|
| 553 | + //set page configs |
|
| 554 | + $this->_set_page_routes(); |
|
| 555 | + $this->_set_page_config(); |
|
| 556 | + //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 557 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 558 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 559 | + } |
|
| 560 | + //for caffeinated and other extended functionality. |
|
| 561 | + // If there is a _extend_page_config method |
|
| 562 | + // then let's run that to modify the all the various page configuration arrays |
|
| 563 | + if (method_exists($this, '_extend_page_config')) { |
|
| 564 | + $this->_extend_page_config(); |
|
| 565 | + } |
|
| 566 | + //for CPT and other extended functionality. |
|
| 567 | + // If there is an _extend_page_config_for_cpt |
|
| 568 | + // then let's run that to modify all the various page configuration arrays. |
|
| 569 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 570 | + $this->_extend_page_config_for_cpt(); |
|
| 571 | + } |
|
| 572 | + //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 573 | + $this->_page_routes = apply_filters( |
|
| 574 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 575 | + $this->_page_routes, |
|
| 576 | + $this |
|
| 577 | + ); |
|
| 578 | + $this->_page_config = apply_filters( |
|
| 579 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 580 | + $this->_page_config, |
|
| 581 | + $this |
|
| 582 | + ); |
|
| 583 | + //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 584 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 585 | + if ( |
|
| 586 | + method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view) |
|
| 587 | + ) { |
|
| 588 | + add_action( |
|
| 589 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 590 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 591 | + 10, |
|
| 592 | + 2 |
|
| 593 | + ); |
|
| 594 | + } |
|
| 595 | + //next route only if routing enabled |
|
| 596 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 597 | + $this->_verify_routes(); |
|
| 598 | + //next let's just check user_access and kill if no access |
|
| 599 | + $this->check_user_access(); |
|
| 600 | + if ($this->_is_UI_request) { |
|
| 601 | + //admin_init stuff - global, all views for this page class, specific view |
|
| 602 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 603 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 604 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 605 | + } |
|
| 606 | + } else { |
|
| 607 | + //hijack regular WP loading and route admin request immediately |
|
| 608 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 609 | + $this->route_admin_request(); |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 618 | + * |
|
| 619 | + * @return void |
|
| 620 | + * @throws ReflectionException |
|
| 621 | + * @throws EE_Error |
|
| 622 | + */ |
|
| 623 | + private function _do_other_page_hooks() |
|
| 624 | + { |
|
| 625 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 626 | + foreach ($registered_pages as $page) { |
|
| 627 | + //now let's setup the file name and class that should be present |
|
| 628 | + $classname = str_replace('.class.php', '', $page); |
|
| 629 | + //autoloaders should take care of loading file |
|
| 630 | + if (! class_exists($classname)) { |
|
| 631 | + $error_msg[] = sprintf( |
|
| 632 | + esc_html__( |
|
| 633 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 634 | + 'event_espresso' |
|
| 635 | + ), |
|
| 636 | + $page |
|
| 637 | + ); |
|
| 638 | + $error_msg[] = $error_msg[0] |
|
| 639 | + . "\r\n" |
|
| 640 | + . sprintf( |
|
| 641 | + esc_html__( |
|
| 642 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 643 | + 'event_espresso' |
|
| 644 | + ), |
|
| 645 | + $page, |
|
| 646 | + '<br />', |
|
| 647 | + '<strong>' . $classname . '</strong>' |
|
| 648 | + ); |
|
| 649 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 650 | + } |
|
| 651 | + $a = new ReflectionClass($classname); |
|
| 652 | + //notice we are passing the instance of this class to the hook object. |
|
| 653 | + $hookobj[] = $a->newInstance($this); |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + public function load_page_dependencies() |
|
| 660 | + { |
|
| 661 | + try { |
|
| 662 | + $this->_load_page_dependencies(); |
|
| 663 | + } catch (EE_Error $e) { |
|
| 664 | + $e->get_error(); |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * load_page_dependencies |
|
| 672 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 673 | + * |
|
| 674 | + * @return void |
|
| 675 | + * @throws DomainException |
|
| 676 | + * @throws EE_Error |
|
| 677 | + * @throws InvalidArgumentException |
|
| 678 | + * @throws InvalidDataTypeException |
|
| 679 | + * @throws InvalidInterfaceException |
|
| 680 | + * @throws ReflectionException |
|
| 681 | + */ |
|
| 682 | + protected function _load_page_dependencies() |
|
| 683 | + { |
|
| 684 | + //let's set the current_screen and screen options to override what WP set |
|
| 685 | + $this->_current_screen = get_current_screen(); |
|
| 686 | + //load admin_notices - global, page class, and view specific |
|
| 687 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 688 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 689 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 690 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 691 | + } |
|
| 692 | + //load network admin_notices - global, page class, and view specific |
|
| 693 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 694 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 695 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 696 | + } |
|
| 697 | + //this will save any per_page screen options if they are present |
|
| 698 | + $this->_set_per_page_screen_options(); |
|
| 699 | + //setup list table properties |
|
| 700 | + $this->_set_list_table(); |
|
| 701 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 702 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 703 | + $this->_add_registered_meta_boxes(); |
|
| 704 | + $this->_add_screen_columns(); |
|
| 705 | + //add screen options - global, page child class, and view specific |
|
| 706 | + $this->_add_global_screen_options(); |
|
| 707 | + $this->_add_screen_options(); |
|
| 708 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 709 | + if (method_exists($this, $add_screen_options )) { |
|
| 710 | + $this->{$add_screen_options}(); |
|
| 711 | + } |
|
| 712 | + //add help tab(s) and tours- set via page_config and qtips. |
|
| 713 | + $this->_add_help_tour(); |
|
| 714 | + $this->_add_help_tabs(); |
|
| 715 | + $this->_add_qtips(); |
|
| 716 | + //add feature_pointers - global, page child class, and view specific |
|
| 717 | + $this->_add_feature_pointers(); |
|
| 718 | + $this->_add_global_feature_pointers(); |
|
| 719 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 720 | + if (method_exists($this, $add_feature_pointer )) { |
|
| 721 | + $this->{$add_feature_pointer}(); |
|
| 722 | + } |
|
| 723 | + //enqueue scripts/styles - global, page class, and view specific |
|
| 724 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 725 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 726 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 727 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 728 | + } |
|
| 729 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 730 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 731 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 732 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 733 | + // is a good use case. Notice the late priority we're giving these |
|
| 734 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 735 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 736 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 737 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 738 | + } |
|
| 739 | + //admin footer scripts |
|
| 740 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 741 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 742 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 743 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 744 | + } |
|
| 745 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 746 | + //targeted hook |
|
| 747 | + do_action( |
|
| 748 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 749 | + |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * _set_defaults |
|
| 757 | + * This sets some global defaults for class properties. |
|
| 758 | + */ |
|
| 759 | + private function _set_defaults() |
|
| 760 | + { |
|
| 761 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 762 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 763 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 764 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
| 765 | + $this->_default_nav_tab_name = 'overview'; |
|
| 766 | + //init template args |
|
| 767 | + $this->_template_args = array( |
|
| 768 | + 'admin_page_header' => '', |
|
| 769 | + 'admin_page_content' => '', |
|
| 770 | + 'post_body_content' => '', |
|
| 771 | + 'before_list_table' => '', |
|
| 772 | + 'after_list_table' => '', |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * route_admin_request |
|
| 780 | + * |
|
| 781 | + * @see _route_admin_request() |
|
| 782 | + * @return exception|void error |
|
| 783 | + * @throws InvalidArgumentException |
|
| 784 | + * @throws InvalidInterfaceException |
|
| 785 | + * @throws InvalidDataTypeException |
|
| 786 | + * @throws EE_Error |
|
| 787 | + * @throws ReflectionException |
|
| 788 | + */ |
|
| 789 | + public function route_admin_request() |
|
| 790 | + { |
|
| 791 | + try { |
|
| 792 | + $this->_route_admin_request(); |
|
| 793 | + } catch (EE_Error $e) { |
|
| 794 | + $e->get_error(); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + public function set_wp_page_slug($wp_page_slug) |
|
| 801 | + { |
|
| 802 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 803 | + //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 804 | + if (is_network_admin()) { |
|
| 805 | + $this->_wp_page_slug .= '-network'; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * _verify_routes |
|
| 813 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 814 | + * we know if we need to drop out. |
|
| 815 | + * |
|
| 816 | + * @return bool |
|
| 817 | + * @throws EE_Error |
|
| 818 | + */ |
|
| 819 | + protected function _verify_routes() |
|
| 820 | + { |
|
| 821 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 822 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + $this->_route = false; |
|
| 826 | + // check that the page_routes array is not empty |
|
| 827 | + if (empty($this->_page_routes)) { |
|
| 828 | + // user error msg |
|
| 829 | + $error_msg = sprintf( |
|
| 830 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 831 | + $this->_admin_page_title |
|
| 832 | + ); |
|
| 833 | + // developer error msg |
|
| 834 | + $error_msg .= '||' . $error_msg . esc_html__( |
|
| 835 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 836 | + 'event_espresso' |
|
| 837 | + ); |
|
| 838 | + throw new EE_Error($error_msg); |
|
| 839 | + } |
|
| 840 | + // and that the requested page route exists |
|
| 841 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 842 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 843 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 844 | + ? $this->_page_config[$this->_req_action] : array(); |
|
| 845 | + } else { |
|
| 846 | + // user error msg |
|
| 847 | + $error_msg = sprintf( |
|
| 848 | + esc_html__( |
|
| 849 | + 'The requested page route does not exist for the %s admin page.', |
|
| 850 | + 'event_espresso' |
|
| 851 | + ), |
|
| 852 | + $this->_admin_page_title |
|
| 853 | + ); |
|
| 854 | + // developer error msg |
|
| 855 | + $error_msg .= '||' . $error_msg . sprintf( |
|
| 856 | + esc_html__( |
|
| 857 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 858 | + 'event_espresso' |
|
| 859 | + ), |
|
| 860 | + $this->_req_action |
|
| 861 | + ); |
|
| 862 | + throw new EE_Error($error_msg); |
|
| 863 | + } |
|
| 864 | + // and that a default route exists |
|
| 865 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 866 | + // user error msg |
|
| 867 | + $error_msg = sprintf( |
|
| 868 | + esc_html__( |
|
| 869 | + 'A default page route has not been set for the % admin page.', |
|
| 870 | + 'event_espresso' |
|
| 871 | + ), |
|
| 872 | + $this->_admin_page_title |
|
| 873 | + ); |
|
| 874 | + // developer error msg |
|
| 875 | + $error_msg .= '||' . $error_msg . esc_html__( |
|
| 876 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 877 | + 'event_espresso' |
|
| 878 | + ); |
|
| 879 | + throw new EE_Error($error_msg); |
|
| 880 | + } |
|
| 881 | + //first lets' catch if the UI request has EVER been set. |
|
| 882 | + if ($this->_is_UI_request === null) { |
|
| 883 | + //lets set if this is a UI request or not. |
|
| 884 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 885 | + //wait a minute... we might have a noheader in the route array |
|
| 886 | + $this->_is_UI_request = is_array($this->_route) |
|
| 887 | + && isset($this->_route['noheader']) |
|
| 888 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 889 | + } |
|
| 890 | + $this->_set_current_labels(); |
|
| 891 | + return true; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + |
|
| 896 | + /** |
|
| 897 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 898 | + * |
|
| 899 | + * @param string $route the route name we're verifying |
|
| 900 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 901 | + * @throws EE_Error |
|
| 902 | + */ |
|
| 903 | + protected function _verify_route($route) |
|
| 904 | + { |
|
| 905 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 906 | + return true; |
|
| 907 | + } |
|
| 908 | + // user error msg |
|
| 909 | + $error_msg = sprintf( |
|
| 910 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 911 | + $this->_admin_page_title |
|
| 912 | + ); |
|
| 913 | + // developer error msg |
|
| 914 | + $error_msg .= '||' . $error_msg . sprintf( |
|
| 915 | + esc_html__( |
|
| 916 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 917 | + 'event_espresso' |
|
| 918 | + ), |
|
| 919 | + $route |
|
| 920 | + ); |
|
| 921 | + throw new EE_Error($error_msg); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * perform nonce verification |
|
| 928 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 929 | + * using this method (and save retyping!) |
|
| 930 | + * |
|
| 931 | + * @param string $nonce The nonce sent |
|
| 932 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 933 | + * @return void |
|
| 934 | + * @throws EE_Error |
|
| 935 | + */ |
|
| 936 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 937 | + { |
|
| 938 | + // verify nonce against expected value |
|
| 939 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 940 | + // these are not the droids you are looking for !!! |
|
| 941 | + $msg = sprintf( |
|
| 942 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 943 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 944 | + '</a>' |
|
| 945 | + ); |
|
| 946 | + if (WP_DEBUG) { |
|
| 947 | + $msg .= "\n " . sprintf( |
|
| 948 | + esc_html__( |
|
| 949 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 950 | + 'event_espresso' |
|
| 951 | + ), |
|
| 952 | + __CLASS__ |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + if (! defined('DOING_AJAX')) { |
|
| 956 | + wp_die($msg); |
|
| 957 | + } else { |
|
| 958 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 959 | + $this->_return_json(); |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * _route_admin_request() |
|
| 968 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 969 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 970 | + * in the page routes and then will try to load the corresponding method. |
|
| 971 | + * |
|
| 972 | + * @return void |
|
| 973 | + * @throws EE_Error |
|
| 974 | + * @throws InvalidArgumentException |
|
| 975 | + * @throws InvalidDataTypeException |
|
| 976 | + * @throws InvalidInterfaceException |
|
| 977 | + * @throws ReflectionException |
|
| 978 | + */ |
|
| 979 | + protected function _route_admin_request() |
|
| 980 | + { |
|
| 981 | + if (! $this->_is_UI_request) { |
|
| 982 | + $this->_verify_routes(); |
|
| 983 | + } |
|
| 984 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 985 | + ? $this->_route_config['require_nonce'] |
|
| 986 | + : true; |
|
| 987 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 988 | + // set nonce from post data |
|
| 989 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 990 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 991 | + : ''; |
|
| 992 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 993 | + } |
|
| 994 | + //set the nav_tabs array but ONLY if this is UI_request |
|
| 995 | + if ($this->_is_UI_request) { |
|
| 996 | + $this->_set_nav_tabs(); |
|
| 997 | + } |
|
| 998 | + // grab callback function |
|
| 999 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1000 | + // check if callback has args |
|
| 1001 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1002 | + $error_msg = ''; |
|
| 1003 | + // action right before calling route |
|
| 1004 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1005 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1006 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1007 | + } |
|
| 1008 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 1009 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1010 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1011 | + '_wp_http_referer', |
|
| 1012 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1013 | + ); |
|
| 1014 | + if (! empty($func)) { |
|
| 1015 | + if (is_array($func)) { |
|
| 1016 | + list($class, $method) = $func; |
|
| 1017 | + } elseif (strpos($func, '::') !== false) { |
|
| 1018 | + list($class, $method) = explode('::', $func); |
|
| 1019 | + } else { |
|
| 1020 | + $class = $this; |
|
| 1021 | + $method = $func; |
|
| 1022 | + } |
|
| 1023 | + if (! (is_object($class) && $class === $this)) { |
|
| 1024 | + // send along this admin page object for access by addons. |
|
| 1025 | + $args['admin_page_object'] = $this; |
|
| 1026 | + } |
|
| 1027 | + if ( |
|
| 1028 | + //is it a method on a class that doesn't work? |
|
| 1029 | + ( |
|
| 1030 | + ( |
|
| 1031 | + method_exists($class, $method) |
|
| 1032 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 1033 | + ) |
|
| 1034 | + && ( |
|
| 1035 | + //is it a standalone function that doesn't work? |
|
| 1036 | + function_exists($method) |
|
| 1037 | + && call_user_func_array( |
|
| 1038 | + $func, |
|
| 1039 | + array_merge(array('admin_page_object' => $this), $args) |
|
| 1040 | + ) === false |
|
| 1041 | + ) |
|
| 1042 | + ) |
|
| 1043 | + || ( |
|
| 1044 | + //is it neither a class method NOR a standalone function? |
|
| 1045 | + ! method_exists($class, $method) |
|
| 1046 | + && ! function_exists($method) |
|
| 1047 | + ) |
|
| 1048 | + ) { |
|
| 1049 | + // user error msg |
|
| 1050 | + $error_msg = esc_html__( |
|
| 1051 | + 'An error occurred. The requested page route could not be found.', |
|
| 1052 | + 'event_espresso' |
|
| 1053 | + ); |
|
| 1054 | + // developer error msg |
|
| 1055 | + $error_msg .= '||'; |
|
| 1056 | + $error_msg .= sprintf( |
|
| 1057 | + esc_html__( |
|
| 1058 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1059 | + 'event_espresso' |
|
| 1060 | + ), |
|
| 1061 | + $method |
|
| 1062 | + ); |
|
| 1063 | + } |
|
| 1064 | + if (! empty($error_msg)) { |
|
| 1065 | + throw new EE_Error($error_msg); |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1069 | + // then we need to reset the routing properties to the new route. |
|
| 1070 | + //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1071 | + if ($this->_is_UI_request === false |
|
| 1072 | + && is_array($this->_route) |
|
| 1073 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1074 | + ) { |
|
| 1075 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1083 | + * route redirects to a headers route in its route config. |
|
| 1084 | + * |
|
| 1085 | + * @since 4.3.0 |
|
| 1086 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1087 | + * @return void |
|
| 1088 | + * @throws ReflectionException |
|
| 1089 | + * @throws InvalidArgumentException |
|
| 1090 | + * @throws InvalidInterfaceException |
|
| 1091 | + * @throws InvalidDataTypeException |
|
| 1092 | + * @throws EE_Error |
|
| 1093 | + */ |
|
| 1094 | + protected function _reset_routing_properties($new_route) |
|
| 1095 | + { |
|
| 1096 | + $this->_is_UI_request = true; |
|
| 1097 | + //now we set the current route to whatever the headers_sent_route is set at |
|
| 1098 | + $this->_req_data['action'] = $new_route; |
|
| 1099 | + //rerun page setup |
|
| 1100 | + $this->_page_setup(); |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _add_query_arg |
|
| 1107 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1108 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1109 | + * |
|
| 1110 | + * @param array $args |
|
| 1111 | + * @param string $url |
|
| 1112 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1113 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1114 | + * Example usage: If the current page is: |
|
| 1115 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1116 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1117 | + * &_wpnonce=5467821 |
|
| 1118 | + * and you call: |
|
| 1119 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1120 | + * array( |
|
| 1121 | + * 'action' => 'resend_something', |
|
| 1122 | + * 'page=>espresso_registrations' |
|
| 1123 | + * ), |
|
| 1124 | + * $some_url, |
|
| 1125 | + * true |
|
| 1126 | + * ); |
|
| 1127 | + * It will produce a url in this structure: |
|
| 1128 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1129 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1130 | + * month_range]=March%202015 |
|
| 1131 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1132 | + * @return string |
|
| 1133 | + */ |
|
| 1134 | + public static function add_query_args_and_nonce( |
|
| 1135 | + $args = array(), |
|
| 1136 | + $url = false, |
|
| 1137 | + $sticky = false, |
|
| 1138 | + $exclude_nonce = false |
|
| 1139 | + ) { |
|
| 1140 | + //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1141 | + if ($sticky) { |
|
| 1142 | + $request = $_REQUEST; |
|
| 1143 | + unset($request['_wp_http_referer']); |
|
| 1144 | + unset($request['wp_referer']); |
|
| 1145 | + foreach ($request as $key => $value) { |
|
| 1146 | + //do not add nonces |
|
| 1147 | + if (strpos($key, 'nonce') !== false) { |
|
| 1148 | + continue; |
|
| 1149 | + } |
|
| 1150 | + $args['wp_referer[' . $key . ']'] = $value; |
|
| 1151 | + } |
|
| 1152 | + } |
|
| 1153 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * This returns a generated link that will load the related help tab. |
|
| 1160 | + * |
|
| 1161 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1162 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1163 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1164 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1165 | + * @return string generated link |
|
| 1166 | + */ |
|
| 1167 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1168 | + { |
|
| 1169 | + return EEH_Template::get_help_tab_link( |
|
| 1170 | + $help_tab_id, |
|
| 1171 | + $this->page_slug, |
|
| 1172 | + $this->_req_action, |
|
| 1173 | + $icon_style, |
|
| 1174 | + $help_text |
|
| 1175 | + ); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * _add_help_tabs |
|
| 1182 | + * Note child classes define their help tabs within the page_config array. |
|
| 1183 | + * |
|
| 1184 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1185 | + * @return void |
|
| 1186 | + * @throws DomainException |
|
| 1187 | + * @throws EE_Error |
|
| 1188 | + */ |
|
| 1189 | + protected function _add_help_tabs() |
|
| 1190 | + { |
|
| 1191 | + $tour_buttons = ''; |
|
| 1192 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1193 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1194 | + //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1195 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1196 | + $tb = array(); |
|
| 1197 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1198 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1199 | + //if this is the end tour then we don't need to setup a button |
|
| 1200 | + if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1201 | + continue; |
|
| 1202 | + } |
|
| 1203 | + $tb[] = '<button id="trigger-tour-' |
|
| 1204 | + . $tour->get_slug() |
|
| 1205 | + . '" class="button-primary trigger-ee-help-tour">' |
|
| 1206 | + . $tour->get_label() |
|
| 1207 | + . '</button>'; |
|
| 1208 | + } |
|
| 1209 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1210 | + $tour_buttons .= '</div></div>'; |
|
| 1211 | + } |
|
| 1212 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1213 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1214 | + //check that the callback given is valid |
|
| 1215 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1216 | + throw new EE_Error( |
|
| 1217 | + sprintf( |
|
| 1218 | + esc_html__( |
|
| 1219 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1220 | + 'event_espresso' |
|
| 1221 | + ), |
|
| 1222 | + $config['help_sidebar'], |
|
| 1223 | + get_class($this) |
|
| 1224 | + ) |
|
| 1225 | + ); |
|
| 1226 | + } |
|
| 1227 | + $content = apply_filters( |
|
| 1228 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1229 | + $this->{$config['help_sidebar']}() |
|
| 1230 | + ); |
|
| 1231 | + $content .= $tour_buttons; //add help tour buttons. |
|
| 1232 | + //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1233 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1234 | + } |
|
| 1235 | + //if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1236 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1237 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1238 | + } |
|
| 1239 | + //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1240 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1241 | + $_ht['id'] = $this->page_slug; |
|
| 1242 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1243 | + $_ht['content'] = '<p>' . esc_html__( |
|
| 1244 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1245 | + 'event_espresso' |
|
| 1246 | + ) . '</p>'; |
|
| 1247 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1248 | + } |
|
| 1249 | + if (! isset($config['help_tabs'])) { |
|
| 1250 | + return; |
|
| 1251 | + } //no help tabs for this route |
|
| 1252 | + foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1253 | + //we're here so there ARE help tabs! |
|
| 1254 | + //make sure we've got what we need |
|
| 1255 | + if (! isset($cfg['title'])) { |
|
| 1256 | + throw new EE_Error( |
|
| 1257 | + esc_html__( |
|
| 1258 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1259 | + 'event_espresso' |
|
| 1260 | + ) |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1264 | + throw new EE_Error( |
|
| 1265 | + esc_html__( |
|
| 1266 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1267 | + 'event_espresso' |
|
| 1268 | + ) |
|
| 1269 | + ); |
|
| 1270 | + } |
|
| 1271 | + //first priority goes to content. |
|
| 1272 | + if (! empty($cfg['content'])) { |
|
| 1273 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1274 | + //second priority goes to filename |
|
| 1275 | + } elseif (! empty($cfg['filename'])) { |
|
| 1276 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1277 | + //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1278 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1279 | + . basename($this->_get_dir()) |
|
| 1280 | + . '/help_tabs/' |
|
| 1281 | + . $cfg['filename'] |
|
| 1282 | + . '.help_tab.php' : $file_path; |
|
| 1283 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1284 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1285 | + EE_Error::add_error( |
|
| 1286 | + sprintf( |
|
| 1287 | + esc_html__( |
|
| 1288 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1289 | + 'event_espresso' |
|
| 1290 | + ), |
|
| 1291 | + $tab_id, |
|
| 1292 | + key($config), |
|
| 1293 | + $file_path |
|
| 1294 | + ), |
|
| 1295 | + __FILE__, |
|
| 1296 | + __FUNCTION__, |
|
| 1297 | + __LINE__ |
|
| 1298 | + ); |
|
| 1299 | + return; |
|
| 1300 | + } |
|
| 1301 | + $template_args['admin_page_obj'] = $this; |
|
| 1302 | + $content = EEH_Template::display_template( |
|
| 1303 | + $file_path, |
|
| 1304 | + $template_args, |
|
| 1305 | + true |
|
| 1306 | + ); |
|
| 1307 | + } else { |
|
| 1308 | + $content = ''; |
|
| 1309 | + } |
|
| 1310 | + //check if callback is valid |
|
| 1311 | + if ( |
|
| 1312 | + empty($content) && ( |
|
| 1313 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1314 | + ) |
|
| 1315 | + ) { |
|
| 1316 | + EE_Error::add_error( |
|
| 1317 | + sprintf( |
|
| 1318 | + esc_html__( |
|
| 1319 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1320 | + 'event_espresso' |
|
| 1321 | + ), |
|
| 1322 | + $cfg['title'] |
|
| 1323 | + ), |
|
| 1324 | + __FILE__, |
|
| 1325 | + __FUNCTION__, |
|
| 1326 | + __LINE__ |
|
| 1327 | + ); |
|
| 1328 | + return; |
|
| 1329 | + } |
|
| 1330 | + //setup config array for help tab method |
|
| 1331 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1332 | + $_ht = array( |
|
| 1333 | + 'id' => $id, |
|
| 1334 | + 'title' => $cfg['title'], |
|
| 1335 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1336 | + 'content' => $content, |
|
| 1337 | + ); |
|
| 1338 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1339 | + } |
|
| 1340 | + } |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1347 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1348 | + * |
|
| 1349 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1350 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1351 | + * _set_page_config() comments |
|
| 1352 | + * @return void |
|
| 1353 | + * @throws EE_Error |
|
| 1354 | + * @throws InvalidArgumentException |
|
| 1355 | + * @throws InvalidDataTypeException |
|
| 1356 | + * @throws InvalidInterfaceException |
|
| 1357 | + */ |
|
| 1358 | + protected function _add_help_tour() |
|
| 1359 | + { |
|
| 1360 | + $tours = array(); |
|
| 1361 | + $this->_help_tour = array(); |
|
| 1362 | + //exit early if help tours are turned off globally |
|
| 1363 | + if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1364 | + || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1365 | + ) { |
|
| 1366 | + return; |
|
| 1367 | + } |
|
| 1368 | + //loop through _page_config to find any help_tour defined |
|
| 1369 | + foreach ($this->_page_config as $route => $config) { |
|
| 1370 | + //we're only going to set things up for this route |
|
| 1371 | + if ($route !== $this->_req_action) { |
|
| 1372 | + continue; |
|
| 1373 | + } |
|
| 1374 | + if (isset($config['help_tour'])) { |
|
| 1375 | + foreach ($config['help_tour'] as $tour) { |
|
| 1376 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1377 | + // let's see if we can get that file... |
|
| 1378 | + // if not its possible this is a decaf route not set in caffeinated |
|
| 1379 | + // so lets try and get the caffeinated equivalent |
|
| 1380 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1381 | + . basename($this->_get_dir()) |
|
| 1382 | + . '/help_tours/' |
|
| 1383 | + . $tour |
|
| 1384 | + . '.class.php' : $file_path; |
|
| 1385 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1386 | + if (! is_readable($file_path)) { |
|
| 1387 | + EE_Error::add_error( |
|
| 1388 | + sprintf( |
|
| 1389 | + esc_html__( |
|
| 1390 | + 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1391 | + 'event_espresso' |
|
| 1392 | + ), |
|
| 1393 | + $file_path, |
|
| 1394 | + $tour |
|
| 1395 | + ), |
|
| 1396 | + __FILE__, |
|
| 1397 | + __FUNCTION__, |
|
| 1398 | + __LINE__ |
|
| 1399 | + ); |
|
| 1400 | + return; |
|
| 1401 | + } |
|
| 1402 | + require_once $file_path; |
|
| 1403 | + if (! class_exists($tour)) { |
|
| 1404 | + $error_msg[] = sprintf( |
|
| 1405 | + esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1406 | + $tour |
|
| 1407 | + ); |
|
| 1408 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf( |
|
| 1409 | + esc_html__( |
|
| 1410 | + 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1411 | + 'event_espresso' |
|
| 1412 | + ), |
|
| 1413 | + $tour, |
|
| 1414 | + '<br />', |
|
| 1415 | + $tour, |
|
| 1416 | + $this->_req_action, |
|
| 1417 | + get_class($this) |
|
| 1418 | + ); |
|
| 1419 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1420 | + } |
|
| 1421 | + $tour_obj = new $tour($this->_is_caf); |
|
| 1422 | + $tours[] = $tour_obj; |
|
| 1423 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1424 | + } |
|
| 1425 | + //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1426 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1427 | + $tours[] = $end_stop_tour; |
|
| 1428 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1429 | + } |
|
| 1430 | + } |
|
| 1431 | + if (! empty($tours)) { |
|
| 1432 | + $this->_help_tour['tours'] = $tours; |
|
| 1433 | + } |
|
| 1434 | + // that's it! Now that the $_help_tours property is set (or not) |
|
| 1435 | + // the scripts and html should be taken care of automatically. |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + |
|
| 1439 | + |
|
| 1440 | + /** |
|
| 1441 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1442 | + * |
|
| 1443 | + * @return void |
|
| 1444 | + */ |
|
| 1445 | + protected function _add_qtips() |
|
| 1446 | + { |
|
| 1447 | + if (isset($this->_route_config['qtips'])) { |
|
| 1448 | + $qtips = (array)$this->_route_config['qtips']; |
|
| 1449 | + //load qtip loader |
|
| 1450 | + $path = array( |
|
| 1451 | + $this->_get_dir() . '/qtips/', |
|
| 1452 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1453 | + ); |
|
| 1454 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1455 | + } |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + /** |
|
| 1461 | + * _set_nav_tabs |
|
| 1462 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1463 | + * wish to add additional tabs or modify accordingly. |
|
| 1464 | + * |
|
| 1465 | + * @return void |
|
| 1466 | + * @throws InvalidArgumentException |
|
| 1467 | + * @throws InvalidInterfaceException |
|
| 1468 | + * @throws InvalidDataTypeException |
|
| 1469 | + */ |
|
| 1470 | + protected function _set_nav_tabs() |
|
| 1471 | + { |
|
| 1472 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1473 | + $i = 0; |
|
| 1474 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1475 | + if ( |
|
| 1476 | + ! is_array($config) |
|
| 1477 | + || ( |
|
| 1478 | + is_array($config) |
|
| 1479 | + && ( |
|
| 1480 | + (isset($config['nav']) && ! $config['nav']) |
|
| 1481 | + || ! isset($config['nav']) |
|
| 1482 | + ) |
|
| 1483 | + ) |
|
| 1484 | + ) { |
|
| 1485 | + continue; |
|
| 1486 | + } |
|
| 1487 | + //no nav tab for this config |
|
| 1488 | + //check for persistent flag |
|
| 1489 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1490 | + // nav tab is only to appear when route requested. |
|
| 1491 | + continue; |
|
| 1492 | + } |
|
| 1493 | + if (! $this->check_user_access($slug, true)) { |
|
| 1494 | + // no nav tab because current user does not have access. |
|
| 1495 | + continue; |
|
| 1496 | + } |
|
| 1497 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1498 | + $this->_nav_tabs[$slug] = array( |
|
| 1499 | + 'url' => isset($config['nav']['url']) |
|
| 1500 | + ? $config['nav']['url'] |
|
| 1501 | + : self::add_query_args_and_nonce( |
|
| 1502 | + array('action' => $slug), |
|
| 1503 | + $this->_admin_base_url |
|
| 1504 | + ), |
|
| 1505 | + 'link_text' => isset($config['nav']['label']) |
|
| 1506 | + ? $config['nav']['label'] |
|
| 1507 | + : ucwords( |
|
| 1508 | + str_replace('_', ' ', $slug) |
|
| 1509 | + ), |
|
| 1510 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1511 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1512 | + ); |
|
| 1513 | + $i++; |
|
| 1514 | + } |
|
| 1515 | + //if $this->_nav_tabs is empty then lets set the default |
|
| 1516 | + if (empty($this->_nav_tabs)) { |
|
| 1517 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1518 | + 'url' => $this->_admin_base_url, |
|
| 1519 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1520 | + 'css_class' => 'nav-tab-active', |
|
| 1521 | + 'order' => 10, |
|
| 1522 | + ); |
|
| 1523 | + } |
|
| 1524 | + //now let's sort the tabs according to order |
|
| 1525 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * _set_current_labels |
|
| 1532 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1533 | + * property array |
|
| 1534 | + * |
|
| 1535 | + * @return void |
|
| 1536 | + */ |
|
| 1537 | + private function _set_current_labels() |
|
| 1538 | + { |
|
| 1539 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1540 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1541 | + if (is_array($text)) { |
|
| 1542 | + foreach ($text as $sublabel => $subtext) { |
|
| 1543 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1544 | + } |
|
| 1545 | + } else { |
|
| 1546 | + $this->_labels[$label] = $text; |
|
| 1547 | + } |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + |
|
| 1553 | + |
|
| 1554 | + /** |
|
| 1555 | + * verifies user access for this admin page |
|
| 1556 | + * |
|
| 1557 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1558 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1559 | + * return false if verify fail. |
|
| 1560 | + * @return bool |
|
| 1561 | + * @throws InvalidArgumentException |
|
| 1562 | + * @throws InvalidDataTypeException |
|
| 1563 | + * @throws InvalidInterfaceException |
|
| 1564 | + */ |
|
| 1565 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1566 | + { |
|
| 1567 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1568 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1569 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1570 | + && is_array( |
|
| 1571 | + $this->_page_routes[$route_to_check] |
|
| 1572 | + ) |
|
| 1573 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1574 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1575 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1576 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1577 | + : $this->_route['capability']; |
|
| 1578 | + } else { |
|
| 1579 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1580 | + } |
|
| 1581 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1582 | + if ( |
|
| 1583 | + ! defined('DOING_AJAX') |
|
| 1584 | + && ( |
|
| 1585 | + ! function_exists('is_admin') |
|
| 1586 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1587 | + $capability, |
|
| 1588 | + $this->page_slug |
|
| 1589 | + . '_' |
|
| 1590 | + . $route_to_check, |
|
| 1591 | + $id |
|
| 1592 | + ) |
|
| 1593 | + ) |
|
| 1594 | + ) { |
|
| 1595 | + if ($verify_only) { |
|
| 1596 | + return false; |
|
| 1597 | + } |
|
| 1598 | + if (is_user_logged_in()) { |
|
| 1599 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1600 | + } else { |
|
| 1601 | + return false; |
|
| 1602 | + } |
|
| 1603 | + } |
|
| 1604 | + return true; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * admin_init_global |
|
| 1611 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1612 | + * This method executes for ALL EE Admin pages. |
|
| 1613 | + * |
|
| 1614 | + * @return void |
|
| 1615 | + */ |
|
| 1616 | + public function admin_init_global() |
|
| 1617 | + { |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * wp_loaded_global |
|
| 1624 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1625 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1626 | + * |
|
| 1627 | + * @return void |
|
| 1628 | + */ |
|
| 1629 | + public function wp_loaded() |
|
| 1630 | + { |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * admin_notices |
|
| 1637 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1638 | + * ALL EE_Admin pages. |
|
| 1639 | + * |
|
| 1640 | + * @return void |
|
| 1641 | + */ |
|
| 1642 | + public function admin_notices_global() |
|
| 1643 | + { |
|
| 1644 | + $this->_display_no_javascript_warning(); |
|
| 1645 | + $this->_display_espresso_notices(); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + |
|
| 1649 | + |
|
| 1650 | + public function network_admin_notices_global() |
|
| 1651 | + { |
|
| 1652 | + $this->_display_no_javascript_warning(); |
|
| 1653 | + $this->_display_espresso_notices(); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + |
|
| 1657 | + |
|
| 1658 | + /** |
|
| 1659 | + * admin_footer_scripts_global |
|
| 1660 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1661 | + * will apply on ALL EE_Admin pages. |
|
| 1662 | + * |
|
| 1663 | + * @return void |
|
| 1664 | + */ |
|
| 1665 | + public function admin_footer_scripts_global() |
|
| 1666 | + { |
|
| 1667 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1668 | + $this->_add_admin_page_overlay(); |
|
| 1669 | + //if metaboxes are present we need to add the nonce field |
|
| 1670 | + if ( |
|
| 1671 | + isset($this->_route_config['metaboxes']) |
|
| 1672 | + || isset($this->_route_config['list_table']) |
|
| 1673 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1674 | + ) { |
|
| 1675 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1676 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1677 | + } |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * admin_footer_global |
|
| 1684 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1685 | + * ALL EE_Admin Pages. |
|
| 1686 | + * |
|
| 1687 | + * @return void |
|
| 1688 | + * @throws EE_Error |
|
| 1689 | + */ |
|
| 1690 | + public function admin_footer_global() |
|
| 1691 | + { |
|
| 1692 | + //dialog container for dialog helper |
|
| 1693 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1694 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1695 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1696 | + $d_cont .= '</div>'; |
|
| 1697 | + echo $d_cont; |
|
| 1698 | + //help tour stuff? |
|
| 1699 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1700 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1701 | + } |
|
| 1702 | + //current set timezone for timezone js |
|
| 1703 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1704 | + } |
|
| 1705 | + |
|
| 1706 | + |
|
| 1707 | + |
|
| 1708 | + /** |
|
| 1709 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1710 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1711 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1712 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1713 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1714 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1715 | + * for the |
|
| 1716 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1717 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1718 | + * 'help_trigger_id' => array( |
|
| 1719 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1720 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1721 | + * ) |
|
| 1722 | + * ); |
|
| 1723 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1724 | + * |
|
| 1725 | + * @param array $help_array |
|
| 1726 | + * @param bool $display |
|
| 1727 | + * @return string content |
|
| 1728 | + * @throws DomainException |
|
| 1729 | + * @throws EE_Error |
|
| 1730 | + */ |
|
| 1731 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1732 | + { |
|
| 1733 | + $content = ''; |
|
| 1734 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1735 | + //loop through the array and setup content |
|
| 1736 | + foreach ($help_array as $trigger => $help) { |
|
| 1737 | + //make sure the array is setup properly |
|
| 1738 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1739 | + throw new EE_Error( |
|
| 1740 | + esc_html__( |
|
| 1741 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1742 | + 'event_espresso' |
|
| 1743 | + ) |
|
| 1744 | + ); |
|
| 1745 | + } |
|
| 1746 | + //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1747 | + $template_args = array( |
|
| 1748 | + 'help_popup_id' => $trigger, |
|
| 1749 | + 'help_popup_title' => $help['title'], |
|
| 1750 | + 'help_popup_content' => $help['content'], |
|
| 1751 | + ); |
|
| 1752 | + $content .= EEH_Template::display_template( |
|
| 1753 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1754 | + $template_args, |
|
| 1755 | + true |
|
| 1756 | + ); |
|
| 1757 | + } |
|
| 1758 | + if ($display) { |
|
| 1759 | + echo $content; |
|
| 1760 | + return ''; |
|
| 1761 | + } |
|
| 1762 | + return $content; |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + /** |
|
| 1768 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1769 | + * |
|
| 1770 | + * @return array properly formatted array for help popup content |
|
| 1771 | + * @throws EE_Error |
|
| 1772 | + */ |
|
| 1773 | + private function _get_help_content() |
|
| 1774 | + { |
|
| 1775 | + //what is the method we're looking for? |
|
| 1776 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1777 | + //if method doesn't exist let's get out. |
|
| 1778 | + if (! method_exists($this, $method_name)) { |
|
| 1779 | + return array(); |
|
| 1780 | + } |
|
| 1781 | + //k we're good to go let's retrieve the help array |
|
| 1782 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1783 | + //make sure we've got an array! |
|
| 1784 | + if (! is_array($help_array)) { |
|
| 1785 | + throw new EE_Error( |
|
| 1786 | + esc_html__( |
|
| 1787 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1788 | + 'event_espresso' |
|
| 1789 | + ) |
|
| 1790 | + ); |
|
| 1791 | + } |
|
| 1792 | + return $help_array; |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + |
|
| 1797 | + /** |
|
| 1798 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1799 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1800 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1801 | + * |
|
| 1802 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1803 | + * @param boolean $display if false then we return the trigger string |
|
| 1804 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1805 | + * @return string |
|
| 1806 | + * @throws DomainException |
|
| 1807 | + * @throws EE_Error |
|
| 1808 | + */ |
|
| 1809 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1810 | + { |
|
| 1811 | + if (defined('DOING_AJAX')) { |
|
| 1812 | + return ''; |
|
| 1813 | + } |
|
| 1814 | + //let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1815 | + $help_array = $this->_get_help_content(); |
|
| 1816 | + $help_content = ''; |
|
| 1817 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1818 | + $help_array[$trigger_id] = array( |
|
| 1819 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1820 | + 'content' => esc_html__( |
|
| 1821 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1822 | + 'event_espresso' |
|
| 1823 | + ), |
|
| 1824 | + ); |
|
| 1825 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1826 | + } |
|
| 1827 | + //let's setup the trigger |
|
| 1828 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1829 | + . $dimensions[0] |
|
| 1830 | + . '&width=' |
|
| 1831 | + . $dimensions[1] |
|
| 1832 | + . '&inlineId=' |
|
| 1833 | + . $trigger_id |
|
| 1834 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1835 | + $content .= $help_content; |
|
| 1836 | + if ($display) { |
|
| 1837 | + echo $content; |
|
| 1838 | + return ''; |
|
| 1839 | + } |
|
| 1840 | + return $content; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * _add_global_screen_options |
|
| 1847 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1848 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1849 | + * |
|
| 1850 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1851 | + * see also WP_Screen object documents... |
|
| 1852 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1853 | + * @abstract |
|
| 1854 | + * @return void |
|
| 1855 | + */ |
|
| 1856 | + private function _add_global_screen_options() |
|
| 1857 | + { |
|
| 1858 | + } |
|
| 1859 | + |
|
| 1860 | + |
|
| 1861 | + |
|
| 1862 | + /** |
|
| 1863 | + * _add_global_feature_pointers |
|
| 1864 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1865 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1866 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1867 | + * |
|
| 1868 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1869 | + * extended) also see: |
|
| 1870 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1871 | + * @abstract |
|
| 1872 | + * @return void |
|
| 1873 | + */ |
|
| 1874 | + private function _add_global_feature_pointers() |
|
| 1875 | + { |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * load_global_scripts_styles |
|
| 1882 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1883 | + * |
|
| 1884 | + * @return void |
|
| 1885 | + * @throws EE_Error |
|
| 1886 | + */ |
|
| 1887 | + public function load_global_scripts_styles() |
|
| 1888 | + { |
|
| 1889 | + /** STYLES **/ |
|
| 1890 | + // add debugging styles |
|
| 1891 | + if (WP_DEBUG) { |
|
| 1892 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1893 | + } |
|
| 1894 | + // register all styles |
|
| 1895 | + wp_register_style( |
|
| 1896 | + 'espresso-ui-theme', |
|
| 1897 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1898 | + array(), |
|
| 1899 | + EVENT_ESPRESSO_VERSION |
|
| 1900 | + ); |
|
| 1901 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1902 | + //helpers styles |
|
| 1903 | + wp_register_style( |
|
| 1904 | + 'ee-text-links', |
|
| 1905 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1906 | + array(), |
|
| 1907 | + EVENT_ESPRESSO_VERSION |
|
| 1908 | + ); |
|
| 1909 | + /** SCRIPTS **/ |
|
| 1910 | + //register all scripts |
|
| 1911 | + wp_register_script( |
|
| 1912 | + 'ee-dialog', |
|
| 1913 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1914 | + array('jquery', 'jquery-ui-draggable'), |
|
| 1915 | + EVENT_ESPRESSO_VERSION, |
|
| 1916 | + true |
|
| 1917 | + ); |
|
| 1918 | + wp_register_script( |
|
| 1919 | + 'ee_admin_js', |
|
| 1920 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1921 | + array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1922 | + EVENT_ESPRESSO_VERSION, |
|
| 1923 | + true |
|
| 1924 | + ); |
|
| 1925 | + wp_register_script( |
|
| 1926 | + 'jquery-ui-timepicker-addon', |
|
| 1927 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1928 | + array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1929 | + EVENT_ESPRESSO_VERSION, |
|
| 1930 | + true |
|
| 1931 | + ); |
|
| 1932 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1933 | + //script for sorting tables |
|
| 1934 | + wp_register_script( |
|
| 1935 | + 'espresso_ajax_table_sorting', |
|
| 1936 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1937 | + array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1938 | + EVENT_ESPRESSO_VERSION, |
|
| 1939 | + true |
|
| 1940 | + ); |
|
| 1941 | + //script for parsing uri's |
|
| 1942 | + wp_register_script( |
|
| 1943 | + 'ee-parse-uri', |
|
| 1944 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1945 | + array(), |
|
| 1946 | + EVENT_ESPRESSO_VERSION, |
|
| 1947 | + true |
|
| 1948 | + ); |
|
| 1949 | + //and parsing associative serialized form elements |
|
| 1950 | + wp_register_script( |
|
| 1951 | + 'ee-serialize-full-array', |
|
| 1952 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1953 | + array('jquery'), |
|
| 1954 | + EVENT_ESPRESSO_VERSION, |
|
| 1955 | + true |
|
| 1956 | + ); |
|
| 1957 | + //helpers scripts |
|
| 1958 | + wp_register_script( |
|
| 1959 | + 'ee-text-links', |
|
| 1960 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1961 | + array('jquery'), |
|
| 1962 | + EVENT_ESPRESSO_VERSION, |
|
| 1963 | + true |
|
| 1964 | + ); |
|
| 1965 | + wp_register_script( |
|
| 1966 | + 'ee-moment-core', |
|
| 1967 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1968 | + array(), |
|
| 1969 | + EVENT_ESPRESSO_VERSION, |
|
| 1970 | + true |
|
| 1971 | + ); |
|
| 1972 | + wp_register_script( |
|
| 1973 | + 'ee-moment', |
|
| 1974 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1975 | + array('ee-moment-core'), |
|
| 1976 | + EVENT_ESPRESSO_VERSION, |
|
| 1977 | + true |
|
| 1978 | + ); |
|
| 1979 | + wp_register_script( |
|
| 1980 | + 'ee-datepicker', |
|
| 1981 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1982 | + array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1983 | + EVENT_ESPRESSO_VERSION, |
|
| 1984 | + true |
|
| 1985 | + ); |
|
| 1986 | + //google charts |
|
| 1987 | + wp_register_script( |
|
| 1988 | + 'google-charts', |
|
| 1989 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1990 | + array(), |
|
| 1991 | + EVENT_ESPRESSO_VERSION, |
|
| 1992 | + false |
|
| 1993 | + ); |
|
| 1994 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1995 | + wp_enqueue_style('ee-admin-css'); |
|
| 1996 | + wp_enqueue_script('ee_admin_js'); |
|
| 1997 | + wp_enqueue_script('ee-accounting'); |
|
| 1998 | + wp_enqueue_script('jquery-validate'); |
|
| 1999 | + //taking care of metaboxes |
|
| 2000 | + if ( |
|
| 2001 | + empty($this->_cpt_route) |
|
| 2002 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2003 | + ) { |
|
| 2004 | + wp_enqueue_script('dashboard'); |
|
| 2005 | + } |
|
| 2006 | + // LOCALIZED DATA |
|
| 2007 | + //localize script for ajax lazy loading |
|
| 2008 | + $lazy_loader_container_ids = apply_filters( |
|
| 2009 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2010 | + array('espresso_news_post_box_content') |
|
| 2011 | + ); |
|
| 2012 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2013 | + /** |
|
| 2014 | + * help tour stuff |
|
| 2015 | + */ |
|
| 2016 | + if (! empty($this->_help_tour)) { |
|
| 2017 | + //register the js for kicking things off |
|
| 2018 | + wp_enqueue_script( |
|
| 2019 | + 'ee-help-tour', |
|
| 2020 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2021 | + array('jquery-joyride'), |
|
| 2022 | + EVENT_ESPRESSO_VERSION, |
|
| 2023 | + true |
|
| 2024 | + ); |
|
| 2025 | + $tours = array(); |
|
| 2026 | + //setup tours for the js tour object |
|
| 2027 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2028 | + if ($tour instanceof EE_Help_Tour) { |
|
| 2029 | + $tours[] = array( |
|
| 2030 | + 'id' => $tour->get_slug(), |
|
| 2031 | + 'options' => $tour->get_options(), |
|
| 2032 | + ); |
|
| 2033 | + } |
|
| 2034 | + } |
|
| 2035 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2036 | + //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2037 | + } |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * admin_footer_scripts_eei18n_js_strings |
|
| 2044 | + * |
|
| 2045 | + * @return void |
|
| 2046 | + */ |
|
| 2047 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2048 | + { |
|
| 2049 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2050 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2051 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2052 | + 'event_espresso' |
|
| 2053 | + ); |
|
| 2054 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2055 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2056 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2057 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2058 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2059 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2060 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2061 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2062 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2063 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2064 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2065 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2066 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2067 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2068 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2069 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2070 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2071 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2072 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2073 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2074 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2075 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2076 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2077 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2078 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2079 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2080 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2081 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2082 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2083 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2084 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2085 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2086 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2087 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2088 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2089 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2090 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2091 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + |
|
| 2095 | + |
|
| 2096 | + /** |
|
| 2097 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2098 | + * |
|
| 2099 | + * @return void |
|
| 2100 | + */ |
|
| 2101 | + public function add_xdebug_style() |
|
| 2102 | + { |
|
| 2103 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + |
|
| 2107 | + /************************/ |
|
| 2108 | + /** LIST TABLE METHODS **/ |
|
| 2109 | + /************************/ |
|
| 2110 | + /** |
|
| 2111 | + * this sets up the list table if the current view requires it. |
|
| 2112 | + * |
|
| 2113 | + * @return void |
|
| 2114 | + * @throws EE_Error |
|
| 2115 | + */ |
|
| 2116 | + protected function _set_list_table() |
|
| 2117 | + { |
|
| 2118 | + //first is this a list_table view? |
|
| 2119 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2120 | + return; |
|
| 2121 | + } //not a list_table view so get out. |
|
| 2122 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2123 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2124 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2125 | + //user error msg |
|
| 2126 | + $error_msg = esc_html__( |
|
| 2127 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2128 | + 'event_espresso' |
|
| 2129 | + ); |
|
| 2130 | + //developer error msg |
|
| 2131 | + $error_msg .= '||' . sprintf( |
|
| 2132 | + esc_html__( |
|
| 2133 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2134 | + 'event_espresso' |
|
| 2135 | + ), |
|
| 2136 | + $this->_req_action, |
|
| 2137 | + $list_table_view |
|
| 2138 | + ); |
|
| 2139 | + throw new EE_Error($error_msg); |
|
| 2140 | + } |
|
| 2141 | + //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2142 | + $this->_views = apply_filters( |
|
| 2143 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2144 | + $this->_views |
|
| 2145 | + ); |
|
| 2146 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2147 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2148 | + $this->_set_list_table_view(); |
|
| 2149 | + $this->_set_list_table_object(); |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + |
|
| 2153 | + |
|
| 2154 | + /** |
|
| 2155 | + * set current view for List Table |
|
| 2156 | + * |
|
| 2157 | + * @return void |
|
| 2158 | + */ |
|
| 2159 | + protected function _set_list_table_view() |
|
| 2160 | + { |
|
| 2161 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2162 | + // looking at active items or dumpster diving ? |
|
| 2163 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2164 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2165 | + } else { |
|
| 2166 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2167 | + } |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + |
|
| 2171 | + |
|
| 2172 | + /** |
|
| 2173 | + * _set_list_table_object |
|
| 2174 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2175 | + * |
|
| 2176 | + * @throws EE_Error |
|
| 2177 | + */ |
|
| 2178 | + protected function _set_list_table_object() |
|
| 2179 | + { |
|
| 2180 | + if (isset($this->_route_config['list_table'])) { |
|
| 2181 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2182 | + throw new EE_Error( |
|
| 2183 | + sprintf( |
|
| 2184 | + esc_html__( |
|
| 2185 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2186 | + 'event_espresso' |
|
| 2187 | + ), |
|
| 2188 | + $this->_route_config['list_table'], |
|
| 2189 | + get_class($this) |
|
| 2190 | + ) |
|
| 2191 | + ); |
|
| 2192 | + } |
|
| 2193 | + $list_table = $this->_route_config['list_table']; |
|
| 2194 | + $this->_list_table_object = new $list_table($this); |
|
| 2195 | + } |
|
| 2196 | + } |
|
| 2197 | + |
|
| 2198 | + |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2202 | + * |
|
| 2203 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2204 | + * urls. The array should be indexed by the view it is being |
|
| 2205 | + * added to. |
|
| 2206 | + * @return array |
|
| 2207 | + */ |
|
| 2208 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2209 | + { |
|
| 2210 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2211 | + if (empty($this->_views)) { |
|
| 2212 | + $this->_views = array(); |
|
| 2213 | + } |
|
| 2214 | + // cycle thru views |
|
| 2215 | + foreach ($this->_views as $key => $view) { |
|
| 2216 | + $query_args = array(); |
|
| 2217 | + // check for current view |
|
| 2218 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2219 | + $query_args['action'] = $this->_req_action; |
|
| 2220 | + $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2221 | + $query_args['status'] = $view['slug']; |
|
| 2222 | + //merge any other arguments sent in. |
|
| 2223 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2224 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2225 | + } |
|
| 2226 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2227 | + } |
|
| 2228 | + return $this->_views; |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * _entries_per_page_dropdown |
|
| 2235 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2236 | + * |
|
| 2237 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2238 | + * WP does it. |
|
| 2239 | + * @param int $max_entries total number of rows in the table |
|
| 2240 | + * @return string |
|
| 2241 | + */ |
|
| 2242 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2243 | + { |
|
| 2244 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2245 | + $values = array(10, 25, 50, 100); |
|
| 2246 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2247 | + if ($max_entries) { |
|
| 2248 | + $values[] = $max_entries; |
|
| 2249 | + sort($values); |
|
| 2250 | + } |
|
| 2251 | + $entries_per_page_dropdown = ' |
|
| 2252 | 2252 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2253 | 2253 | <label class="hide-if-no-js"> |
| 2254 | 2254 | Show |
| 2255 | 2255 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2256 | - foreach ($values as $value) { |
|
| 2257 | - if ($value < $max_entries) { |
|
| 2258 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2259 | - $entries_per_page_dropdown .= ' |
|
| 2256 | + foreach ($values as $value) { |
|
| 2257 | + if ($value < $max_entries) { |
|
| 2258 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2259 | + $entries_per_page_dropdown .= ' |
|
| 2260 | 2260 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2261 | - } |
|
| 2262 | - } |
|
| 2263 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2264 | - $entries_per_page_dropdown .= ' |
|
| 2261 | + } |
|
| 2262 | + } |
|
| 2263 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2264 | + $entries_per_page_dropdown .= ' |
|
| 2265 | 2265 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2266 | - $entries_per_page_dropdown .= ' |
|
| 2266 | + $entries_per_page_dropdown .= ' |
|
| 2267 | 2267 | </select> |
| 2268 | 2268 | entries |
| 2269 | 2269 | </label> |
| 2270 | 2270 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2271 | 2271 | </div> |
| 2272 | 2272 | '; |
| 2273 | - return $entries_per_page_dropdown; |
|
| 2274 | - } |
|
| 2275 | - |
|
| 2276 | - |
|
| 2277 | - |
|
| 2278 | - /** |
|
| 2279 | - * _set_search_attributes |
|
| 2280 | - * |
|
| 2281 | - * @return void |
|
| 2282 | - */ |
|
| 2283 | - public function _set_search_attributes() |
|
| 2284 | - { |
|
| 2285 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2286 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2287 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2288 | - : $this->_search_btn_label |
|
| 2289 | - ); |
|
| 2290 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2291 | - } |
|
| 2292 | - |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - /*** END LIST TABLE METHODS **/ |
|
| 2296 | - |
|
| 2297 | - |
|
| 2298 | - |
|
| 2299 | - /** |
|
| 2300 | - * _add_registered_metaboxes |
|
| 2301 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2302 | - * |
|
| 2303 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2304 | - * @return void |
|
| 2305 | - * @throws EE_Error |
|
| 2306 | - */ |
|
| 2307 | - private function _add_registered_meta_boxes() |
|
| 2308 | - { |
|
| 2309 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2310 | - //we only add meta boxes if the page_route calls for it |
|
| 2311 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2312 | - && is_array( |
|
| 2313 | - $this->_route_config['metaboxes'] |
|
| 2314 | - ) |
|
| 2315 | - ) { |
|
| 2316 | - // this simply loops through the callbacks provided |
|
| 2317 | - // and checks if there is a corresponding callback registered by the child |
|
| 2318 | - // if there is then we go ahead and process the metabox loader. |
|
| 2319 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2320 | - // first check for Closures |
|
| 2321 | - if ($metabox_callback instanceof Closure) { |
|
| 2322 | - $result = $metabox_callback(); |
|
| 2323 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2324 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2325 | - } else { |
|
| 2326 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2327 | - } |
|
| 2328 | - if ($result === false) { |
|
| 2329 | - // user error msg |
|
| 2330 | - $error_msg = esc_html__( |
|
| 2331 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2332 | - 'event_espresso' |
|
| 2333 | - ); |
|
| 2334 | - // developer error msg |
|
| 2335 | - $error_msg .= '||' . sprintf( |
|
| 2336 | - esc_html__( |
|
| 2337 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2338 | - 'event_espresso' |
|
| 2339 | - ), |
|
| 2340 | - $metabox_callback |
|
| 2341 | - ); |
|
| 2342 | - throw new EE_Error($error_msg); |
|
| 2343 | - } |
|
| 2344 | - } |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - |
|
| 2348 | - |
|
| 2349 | - |
|
| 2350 | - /** |
|
| 2351 | - * _add_screen_columns |
|
| 2352 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2353 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2354 | - * |
|
| 2355 | - * @return void |
|
| 2356 | - */ |
|
| 2357 | - private function _add_screen_columns() |
|
| 2358 | - { |
|
| 2359 | - if ( |
|
| 2360 | - is_array($this->_route_config) |
|
| 2361 | - && isset($this->_route_config['columns']) |
|
| 2362 | - && is_array($this->_route_config['columns']) |
|
| 2363 | - && count($this->_route_config['columns']) === 2 |
|
| 2364 | - ) { |
|
| 2365 | - add_screen_option( |
|
| 2366 | - 'layout_columns', |
|
| 2367 | - array( |
|
| 2368 | - 'max' => (int)$this->_route_config['columns'][0], |
|
| 2369 | - 'default' => (int)$this->_route_config['columns'][1], |
|
| 2370 | - ) |
|
| 2371 | - ); |
|
| 2372 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2373 | - $screen_id = $this->_current_screen->id; |
|
| 2374 | - $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2375 | - $total_columns = ! empty($screen_columns) |
|
| 2376 | - ? $screen_columns |
|
| 2377 | - : $this->_route_config['columns'][1]; |
|
| 2378 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2379 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2380 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2381 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2382 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2383 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2384 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2385 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2386 | - } |
|
| 2387 | - } |
|
| 2388 | - |
|
| 2389 | - |
|
| 2390 | - |
|
| 2391 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - /** |
|
| 2395 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2396 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2397 | - * these get loaded on. |
|
| 2398 | - */ |
|
| 2399 | - private function _espresso_news_post_box() |
|
| 2400 | - { |
|
| 2401 | - $news_box_title = apply_filters( |
|
| 2402 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2403 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2404 | - ); |
|
| 2405 | - add_meta_box( |
|
| 2406 | - 'espresso_news_post_box', |
|
| 2407 | - $news_box_title, |
|
| 2408 | - array( |
|
| 2409 | - $this, |
|
| 2410 | - 'espresso_news_post_box', |
|
| 2411 | - ), |
|
| 2412 | - $this->_wp_page_slug, |
|
| 2413 | - 'side' |
|
| 2414 | - ); |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - /** |
|
| 2420 | - * Code for setting up espresso ratings request metabox. |
|
| 2421 | - */ |
|
| 2422 | - protected function _espresso_ratings_request() |
|
| 2423 | - { |
|
| 2424 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2425 | - return; |
|
| 2426 | - } |
|
| 2427 | - $ratings_box_title = apply_filters( |
|
| 2428 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2429 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2430 | - ); |
|
| 2431 | - add_meta_box( |
|
| 2432 | - 'espresso_ratings_request', |
|
| 2433 | - $ratings_box_title, |
|
| 2434 | - array( |
|
| 2435 | - $this, |
|
| 2436 | - 'espresso_ratings_request', |
|
| 2437 | - ), |
|
| 2438 | - $this->_wp_page_slug, |
|
| 2439 | - 'side' |
|
| 2440 | - ); |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - |
|
| 2444 | - |
|
| 2445 | - /** |
|
| 2446 | - * Code for setting up espresso ratings request metabox content. |
|
| 2447 | - * |
|
| 2448 | - * @throws DomainException |
|
| 2449 | - */ |
|
| 2450 | - public function espresso_ratings_request() |
|
| 2451 | - { |
|
| 2452 | - EEH_Template::display_template( |
|
| 2453 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2454 | - array() |
|
| 2455 | - ); |
|
| 2456 | - } |
|
| 2457 | - |
|
| 2458 | - |
|
| 2459 | - |
|
| 2460 | - public static function cached_rss_display($rss_id, $url) |
|
| 2461 | - { |
|
| 2462 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2463 | - . __('Loading…') |
|
| 2464 | - . '</p><p class="hide-if-js">' |
|
| 2465 | - . esc_html__('This widget requires JavaScript.') |
|
| 2466 | - . '</p>'; |
|
| 2467 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2468 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2469 | - $post = '</div>' . "\n"; |
|
| 2470 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2471 | - $output = get_transient($cache_key); |
|
| 2472 | - if ($output !== false) { |
|
| 2473 | - echo $pre . $output . $post; |
|
| 2474 | - return true; |
|
| 2475 | - } |
|
| 2476 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2477 | - echo $pre . $loading . $post; |
|
| 2478 | - return false; |
|
| 2479 | - } |
|
| 2480 | - ob_start(); |
|
| 2481 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2482 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2483 | - return true; |
|
| 2484 | - } |
|
| 2485 | - |
|
| 2486 | - |
|
| 2487 | - |
|
| 2488 | - public function espresso_news_post_box() |
|
| 2489 | - { |
|
| 2490 | - ?> |
|
| 2273 | + return $entries_per_page_dropdown; |
|
| 2274 | + } |
|
| 2275 | + |
|
| 2276 | + |
|
| 2277 | + |
|
| 2278 | + /** |
|
| 2279 | + * _set_search_attributes |
|
| 2280 | + * |
|
| 2281 | + * @return void |
|
| 2282 | + */ |
|
| 2283 | + public function _set_search_attributes() |
|
| 2284 | + { |
|
| 2285 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2286 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2287 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2288 | + : $this->_search_btn_label |
|
| 2289 | + ); |
|
| 2290 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2291 | + } |
|
| 2292 | + |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + /*** END LIST TABLE METHODS **/ |
|
| 2296 | + |
|
| 2297 | + |
|
| 2298 | + |
|
| 2299 | + /** |
|
| 2300 | + * _add_registered_metaboxes |
|
| 2301 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2302 | + * |
|
| 2303 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2304 | + * @return void |
|
| 2305 | + * @throws EE_Error |
|
| 2306 | + */ |
|
| 2307 | + private function _add_registered_meta_boxes() |
|
| 2308 | + { |
|
| 2309 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2310 | + //we only add meta boxes if the page_route calls for it |
|
| 2311 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2312 | + && is_array( |
|
| 2313 | + $this->_route_config['metaboxes'] |
|
| 2314 | + ) |
|
| 2315 | + ) { |
|
| 2316 | + // this simply loops through the callbacks provided |
|
| 2317 | + // and checks if there is a corresponding callback registered by the child |
|
| 2318 | + // if there is then we go ahead and process the metabox loader. |
|
| 2319 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2320 | + // first check for Closures |
|
| 2321 | + if ($metabox_callback instanceof Closure) { |
|
| 2322 | + $result = $metabox_callback(); |
|
| 2323 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2324 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2325 | + } else { |
|
| 2326 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2327 | + } |
|
| 2328 | + if ($result === false) { |
|
| 2329 | + // user error msg |
|
| 2330 | + $error_msg = esc_html__( |
|
| 2331 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2332 | + 'event_espresso' |
|
| 2333 | + ); |
|
| 2334 | + // developer error msg |
|
| 2335 | + $error_msg .= '||' . sprintf( |
|
| 2336 | + esc_html__( |
|
| 2337 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2338 | + 'event_espresso' |
|
| 2339 | + ), |
|
| 2340 | + $metabox_callback |
|
| 2341 | + ); |
|
| 2342 | + throw new EE_Error($error_msg); |
|
| 2343 | + } |
|
| 2344 | + } |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + |
|
| 2348 | + |
|
| 2349 | + |
|
| 2350 | + /** |
|
| 2351 | + * _add_screen_columns |
|
| 2352 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2353 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2354 | + * |
|
| 2355 | + * @return void |
|
| 2356 | + */ |
|
| 2357 | + private function _add_screen_columns() |
|
| 2358 | + { |
|
| 2359 | + if ( |
|
| 2360 | + is_array($this->_route_config) |
|
| 2361 | + && isset($this->_route_config['columns']) |
|
| 2362 | + && is_array($this->_route_config['columns']) |
|
| 2363 | + && count($this->_route_config['columns']) === 2 |
|
| 2364 | + ) { |
|
| 2365 | + add_screen_option( |
|
| 2366 | + 'layout_columns', |
|
| 2367 | + array( |
|
| 2368 | + 'max' => (int)$this->_route_config['columns'][0], |
|
| 2369 | + 'default' => (int)$this->_route_config['columns'][1], |
|
| 2370 | + ) |
|
| 2371 | + ); |
|
| 2372 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2373 | + $screen_id = $this->_current_screen->id; |
|
| 2374 | + $screen_columns = (int)get_user_option("screen_layout_{$screen_id}"); |
|
| 2375 | + $total_columns = ! empty($screen_columns) |
|
| 2376 | + ? $screen_columns |
|
| 2377 | + : $this->_route_config['columns'][1]; |
|
| 2378 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2379 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2380 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2381 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2382 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2383 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2384 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2385 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2386 | + } |
|
| 2387 | + } |
|
| 2388 | + |
|
| 2389 | + |
|
| 2390 | + |
|
| 2391 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2396 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2397 | + * these get loaded on. |
|
| 2398 | + */ |
|
| 2399 | + private function _espresso_news_post_box() |
|
| 2400 | + { |
|
| 2401 | + $news_box_title = apply_filters( |
|
| 2402 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2403 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2404 | + ); |
|
| 2405 | + add_meta_box( |
|
| 2406 | + 'espresso_news_post_box', |
|
| 2407 | + $news_box_title, |
|
| 2408 | + array( |
|
| 2409 | + $this, |
|
| 2410 | + 'espresso_news_post_box', |
|
| 2411 | + ), |
|
| 2412 | + $this->_wp_page_slug, |
|
| 2413 | + 'side' |
|
| 2414 | + ); |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * Code for setting up espresso ratings request metabox. |
|
| 2421 | + */ |
|
| 2422 | + protected function _espresso_ratings_request() |
|
| 2423 | + { |
|
| 2424 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2425 | + return; |
|
| 2426 | + } |
|
| 2427 | + $ratings_box_title = apply_filters( |
|
| 2428 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2429 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2430 | + ); |
|
| 2431 | + add_meta_box( |
|
| 2432 | + 'espresso_ratings_request', |
|
| 2433 | + $ratings_box_title, |
|
| 2434 | + array( |
|
| 2435 | + $this, |
|
| 2436 | + 'espresso_ratings_request', |
|
| 2437 | + ), |
|
| 2438 | + $this->_wp_page_slug, |
|
| 2439 | + 'side' |
|
| 2440 | + ); |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + |
|
| 2444 | + |
|
| 2445 | + /** |
|
| 2446 | + * Code for setting up espresso ratings request metabox content. |
|
| 2447 | + * |
|
| 2448 | + * @throws DomainException |
|
| 2449 | + */ |
|
| 2450 | + public function espresso_ratings_request() |
|
| 2451 | + { |
|
| 2452 | + EEH_Template::display_template( |
|
| 2453 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2454 | + array() |
|
| 2455 | + ); |
|
| 2456 | + } |
|
| 2457 | + |
|
| 2458 | + |
|
| 2459 | + |
|
| 2460 | + public static function cached_rss_display($rss_id, $url) |
|
| 2461 | + { |
|
| 2462 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2463 | + . __('Loading…') |
|
| 2464 | + . '</p><p class="hide-if-js">' |
|
| 2465 | + . esc_html__('This widget requires JavaScript.') |
|
| 2466 | + . '</p>'; |
|
| 2467 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2468 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2469 | + $post = '</div>' . "\n"; |
|
| 2470 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2471 | + $output = get_transient($cache_key); |
|
| 2472 | + if ($output !== false) { |
|
| 2473 | + echo $pre . $output . $post; |
|
| 2474 | + return true; |
|
| 2475 | + } |
|
| 2476 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2477 | + echo $pre . $loading . $post; |
|
| 2478 | + return false; |
|
| 2479 | + } |
|
| 2480 | + ob_start(); |
|
| 2481 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2482 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2483 | + return true; |
|
| 2484 | + } |
|
| 2485 | + |
|
| 2486 | + |
|
| 2487 | + |
|
| 2488 | + public function espresso_news_post_box() |
|
| 2489 | + { |
|
| 2490 | + ?> |
|
| 2491 | 2491 | <div class="padding"> |
| 2492 | 2492 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2493 | 2493 | <?php |
| 2494 | - // Get RSS Feed(s) |
|
| 2495 | - self::cached_rss_display( |
|
| 2496 | - 'espresso_news_post_box_content', |
|
| 2497 | - urlencode( |
|
| 2498 | - apply_filters( |
|
| 2499 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2500 | - 'http://eventespresso.com/feed/' |
|
| 2501 | - ) |
|
| 2502 | - ) |
|
| 2503 | - ); |
|
| 2504 | - ?> |
|
| 2494 | + // Get RSS Feed(s) |
|
| 2495 | + self::cached_rss_display( |
|
| 2496 | + 'espresso_news_post_box_content', |
|
| 2497 | + urlencode( |
|
| 2498 | + apply_filters( |
|
| 2499 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2500 | + 'http://eventespresso.com/feed/' |
|
| 2501 | + ) |
|
| 2502 | + ) |
|
| 2503 | + ); |
|
| 2504 | + ?> |
|
| 2505 | 2505 | </div> |
| 2506 | 2506 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2507 | 2507 | </div> |
| 2508 | 2508 | <?php |
| 2509 | - } |
|
| 2510 | - |
|
| 2511 | - |
|
| 2512 | - |
|
| 2513 | - private function _espresso_links_post_box() |
|
| 2514 | - { |
|
| 2515 | - //Hiding until we actually have content to put in here... |
|
| 2516 | - //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2517 | - } |
|
| 2518 | - |
|
| 2519 | - |
|
| 2520 | - |
|
| 2521 | - public function espresso_links_post_box() |
|
| 2522 | - { |
|
| 2523 | - //Hiding until we actually have content to put in here... |
|
| 2524 | - // EEH_Template::display_template( |
|
| 2525 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2526 | - // ); |
|
| 2527 | - } |
|
| 2528 | - |
|
| 2529 | - |
|
| 2530 | - |
|
| 2531 | - protected function _espresso_sponsors_post_box() |
|
| 2532 | - { |
|
| 2533 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2534 | - add_meta_box( |
|
| 2535 | - 'espresso_sponsors_post_box', |
|
| 2536 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2537 | - array($this, 'espresso_sponsors_post_box'), |
|
| 2538 | - $this->_wp_page_slug, |
|
| 2539 | - 'side' |
|
| 2540 | - ); |
|
| 2541 | - } |
|
| 2542 | - } |
|
| 2543 | - |
|
| 2544 | - |
|
| 2545 | - |
|
| 2546 | - public function espresso_sponsors_post_box() |
|
| 2547 | - { |
|
| 2548 | - EEH_Template::display_template( |
|
| 2549 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2550 | - ); |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - |
|
| 2554 | - |
|
| 2555 | - private function _publish_post_box() |
|
| 2556 | - { |
|
| 2557 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2558 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2559 | - // then we'll use that for the metabox label. |
|
| 2560 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2561 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2562 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2563 | - : $this->_labels['publishbox']; |
|
| 2564 | - } else { |
|
| 2565 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2566 | - } |
|
| 2567 | - $box_label = apply_filters( |
|
| 2568 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2569 | - $box_label, |
|
| 2570 | - $this->_req_action, |
|
| 2571 | - $this |
|
| 2572 | - ); |
|
| 2573 | - add_meta_box( |
|
| 2574 | - $meta_box_ref, |
|
| 2575 | - $box_label, |
|
| 2576 | - array($this, 'editor_overview'), |
|
| 2577 | - $this->_current_screen->id, |
|
| 2578 | - 'side', |
|
| 2579 | - 'high' |
|
| 2580 | - ); |
|
| 2581 | - } |
|
| 2582 | - |
|
| 2583 | - |
|
| 2584 | - |
|
| 2585 | - public function editor_overview() |
|
| 2586 | - { |
|
| 2587 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2588 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2589 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2590 | - : ''; |
|
| 2591 | - echo EEH_Template::display_template( |
|
| 2592 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2593 | - $this->_template_args, |
|
| 2594 | - true |
|
| 2595 | - ); |
|
| 2596 | - } |
|
| 2597 | - |
|
| 2598 | - |
|
| 2599 | - /** end of globally available metaboxes section **/ |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - |
|
| 2603 | - /** |
|
| 2604 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2605 | - * protected method. |
|
| 2606 | - * |
|
| 2607 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2608 | - * @since 4.6.0 |
|
| 2609 | - * @param string $name |
|
| 2610 | - * @param int $id |
|
| 2611 | - * @param bool $delete |
|
| 2612 | - * @param string $save_close_redirect_URL |
|
| 2613 | - * @param bool $both_btns |
|
| 2614 | - * @throws EE_Error |
|
| 2615 | - * @throws InvalidArgumentException |
|
| 2616 | - * @throws InvalidDataTypeException |
|
| 2617 | - * @throws InvalidInterfaceException |
|
| 2618 | - */ |
|
| 2619 | - public function set_publish_post_box_vars( |
|
| 2620 | - $name = '', |
|
| 2621 | - $id = 0, |
|
| 2622 | - $delete = false, |
|
| 2623 | - $save_close_redirect_URL = '', |
|
| 2624 | - $both_btns = true |
|
| 2625 | - ) { |
|
| 2626 | - $this->_set_publish_post_box_vars( |
|
| 2627 | - $name, |
|
| 2628 | - $id, |
|
| 2629 | - $delete, |
|
| 2630 | - $save_close_redirect_URL, |
|
| 2631 | - $both_btns |
|
| 2632 | - ); |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - |
|
| 2636 | - |
|
| 2637 | - /** |
|
| 2638 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2639 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2640 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2641 | - * values for the name and id arguments. |
|
| 2642 | - * |
|
| 2643 | - * @todo Add in validation for name/id arguments. |
|
| 2644 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2645 | - * @param int $id id attached to the item published |
|
| 2646 | - * @param string $delete page route callback for the delete action |
|
| 2647 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2648 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2649 | - * the Save button |
|
| 2650 | - * @throws EE_Error |
|
| 2651 | - * @throws InvalidArgumentException |
|
| 2652 | - * @throws InvalidDataTypeException |
|
| 2653 | - * @throws InvalidInterfaceException |
|
| 2654 | - */ |
|
| 2655 | - protected function _set_publish_post_box_vars( |
|
| 2656 | - $name = '', |
|
| 2657 | - $id = 0, |
|
| 2658 | - $delete = '', |
|
| 2659 | - $save_close_redirect_URL = '', |
|
| 2660 | - $both_btns = true |
|
| 2661 | - ) { |
|
| 2662 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2663 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2664 | - ? $save_close_redirect_URL |
|
| 2665 | - : $this->_admin_base_url; |
|
| 2666 | - // create the Save & Close and Save buttons |
|
| 2667 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2668 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2669 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2670 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2671 | - : ''; |
|
| 2672 | - if ($delete && ! empty($id)) { |
|
| 2673 | - //make sure we have a default if just true is sent. |
|
| 2674 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2675 | - $delete_link_args = array($name => $id); |
|
| 2676 | - $delete = $this->get_action_link_or_button( |
|
| 2677 | - $delete, |
|
| 2678 | - $delete, |
|
| 2679 | - $delete_link_args, |
|
| 2680 | - 'submitdelete deletion', |
|
| 2681 | - '', |
|
| 2682 | - false |
|
| 2683 | - ); |
|
| 2684 | - } |
|
| 2685 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2686 | - if (! empty($name) && ! empty($id)) { |
|
| 2687 | - $hidden_field_arr[$name] = array( |
|
| 2688 | - 'type' => 'hidden', |
|
| 2689 | - 'value' => $id, |
|
| 2690 | - ); |
|
| 2691 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2692 | - } else { |
|
| 2693 | - $hf = ''; |
|
| 2694 | - } |
|
| 2695 | - // add hidden field |
|
| 2696 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2697 | - ? $hf[$name]['field'] |
|
| 2698 | - : $hf; |
|
| 2699 | - } |
|
| 2700 | - |
|
| 2701 | - |
|
| 2702 | - |
|
| 2703 | - /** |
|
| 2704 | - * displays an error message to ppl who have javascript disabled |
|
| 2705 | - * |
|
| 2706 | - * @return void |
|
| 2707 | - */ |
|
| 2708 | - private function _display_no_javascript_warning() |
|
| 2709 | - { |
|
| 2710 | - ?> |
|
| 2509 | + } |
|
| 2510 | + |
|
| 2511 | + |
|
| 2512 | + |
|
| 2513 | + private function _espresso_links_post_box() |
|
| 2514 | + { |
|
| 2515 | + //Hiding until we actually have content to put in here... |
|
| 2516 | + //add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2517 | + } |
|
| 2518 | + |
|
| 2519 | + |
|
| 2520 | + |
|
| 2521 | + public function espresso_links_post_box() |
|
| 2522 | + { |
|
| 2523 | + //Hiding until we actually have content to put in here... |
|
| 2524 | + // EEH_Template::display_template( |
|
| 2525 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2526 | + // ); |
|
| 2527 | + } |
|
| 2528 | + |
|
| 2529 | + |
|
| 2530 | + |
|
| 2531 | + protected function _espresso_sponsors_post_box() |
|
| 2532 | + { |
|
| 2533 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2534 | + add_meta_box( |
|
| 2535 | + 'espresso_sponsors_post_box', |
|
| 2536 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2537 | + array($this, 'espresso_sponsors_post_box'), |
|
| 2538 | + $this->_wp_page_slug, |
|
| 2539 | + 'side' |
|
| 2540 | + ); |
|
| 2541 | + } |
|
| 2542 | + } |
|
| 2543 | + |
|
| 2544 | + |
|
| 2545 | + |
|
| 2546 | + public function espresso_sponsors_post_box() |
|
| 2547 | + { |
|
| 2548 | + EEH_Template::display_template( |
|
| 2549 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2550 | + ); |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + |
|
| 2554 | + |
|
| 2555 | + private function _publish_post_box() |
|
| 2556 | + { |
|
| 2557 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2558 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2559 | + // then we'll use that for the metabox label. |
|
| 2560 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2561 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2562 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2563 | + : $this->_labels['publishbox']; |
|
| 2564 | + } else { |
|
| 2565 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2566 | + } |
|
| 2567 | + $box_label = apply_filters( |
|
| 2568 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2569 | + $box_label, |
|
| 2570 | + $this->_req_action, |
|
| 2571 | + $this |
|
| 2572 | + ); |
|
| 2573 | + add_meta_box( |
|
| 2574 | + $meta_box_ref, |
|
| 2575 | + $box_label, |
|
| 2576 | + array($this, 'editor_overview'), |
|
| 2577 | + $this->_current_screen->id, |
|
| 2578 | + 'side', |
|
| 2579 | + 'high' |
|
| 2580 | + ); |
|
| 2581 | + } |
|
| 2582 | + |
|
| 2583 | + |
|
| 2584 | + |
|
| 2585 | + public function editor_overview() |
|
| 2586 | + { |
|
| 2587 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2588 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2589 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2590 | + : ''; |
|
| 2591 | + echo EEH_Template::display_template( |
|
| 2592 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2593 | + $this->_template_args, |
|
| 2594 | + true |
|
| 2595 | + ); |
|
| 2596 | + } |
|
| 2597 | + |
|
| 2598 | + |
|
| 2599 | + /** end of globally available metaboxes section **/ |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + |
|
| 2603 | + /** |
|
| 2604 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2605 | + * protected method. |
|
| 2606 | + * |
|
| 2607 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2608 | + * @since 4.6.0 |
|
| 2609 | + * @param string $name |
|
| 2610 | + * @param int $id |
|
| 2611 | + * @param bool $delete |
|
| 2612 | + * @param string $save_close_redirect_URL |
|
| 2613 | + * @param bool $both_btns |
|
| 2614 | + * @throws EE_Error |
|
| 2615 | + * @throws InvalidArgumentException |
|
| 2616 | + * @throws InvalidDataTypeException |
|
| 2617 | + * @throws InvalidInterfaceException |
|
| 2618 | + */ |
|
| 2619 | + public function set_publish_post_box_vars( |
|
| 2620 | + $name = '', |
|
| 2621 | + $id = 0, |
|
| 2622 | + $delete = false, |
|
| 2623 | + $save_close_redirect_URL = '', |
|
| 2624 | + $both_btns = true |
|
| 2625 | + ) { |
|
| 2626 | + $this->_set_publish_post_box_vars( |
|
| 2627 | + $name, |
|
| 2628 | + $id, |
|
| 2629 | + $delete, |
|
| 2630 | + $save_close_redirect_URL, |
|
| 2631 | + $both_btns |
|
| 2632 | + ); |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + |
|
| 2636 | + |
|
| 2637 | + /** |
|
| 2638 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2639 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2640 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2641 | + * values for the name and id arguments. |
|
| 2642 | + * |
|
| 2643 | + * @todo Add in validation for name/id arguments. |
|
| 2644 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2645 | + * @param int $id id attached to the item published |
|
| 2646 | + * @param string $delete page route callback for the delete action |
|
| 2647 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2648 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2649 | + * the Save button |
|
| 2650 | + * @throws EE_Error |
|
| 2651 | + * @throws InvalidArgumentException |
|
| 2652 | + * @throws InvalidDataTypeException |
|
| 2653 | + * @throws InvalidInterfaceException |
|
| 2654 | + */ |
|
| 2655 | + protected function _set_publish_post_box_vars( |
|
| 2656 | + $name = '', |
|
| 2657 | + $id = 0, |
|
| 2658 | + $delete = '', |
|
| 2659 | + $save_close_redirect_URL = '', |
|
| 2660 | + $both_btns = true |
|
| 2661 | + ) { |
|
| 2662 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2663 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2664 | + ? $save_close_redirect_URL |
|
| 2665 | + : $this->_admin_base_url; |
|
| 2666 | + // create the Save & Close and Save buttons |
|
| 2667 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2668 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2669 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2670 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2671 | + : ''; |
|
| 2672 | + if ($delete && ! empty($id)) { |
|
| 2673 | + //make sure we have a default if just true is sent. |
|
| 2674 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2675 | + $delete_link_args = array($name => $id); |
|
| 2676 | + $delete = $this->get_action_link_or_button( |
|
| 2677 | + $delete, |
|
| 2678 | + $delete, |
|
| 2679 | + $delete_link_args, |
|
| 2680 | + 'submitdelete deletion', |
|
| 2681 | + '', |
|
| 2682 | + false |
|
| 2683 | + ); |
|
| 2684 | + } |
|
| 2685 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2686 | + if (! empty($name) && ! empty($id)) { |
|
| 2687 | + $hidden_field_arr[$name] = array( |
|
| 2688 | + 'type' => 'hidden', |
|
| 2689 | + 'value' => $id, |
|
| 2690 | + ); |
|
| 2691 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2692 | + } else { |
|
| 2693 | + $hf = ''; |
|
| 2694 | + } |
|
| 2695 | + // add hidden field |
|
| 2696 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2697 | + ? $hf[$name]['field'] |
|
| 2698 | + : $hf; |
|
| 2699 | + } |
|
| 2700 | + |
|
| 2701 | + |
|
| 2702 | + |
|
| 2703 | + /** |
|
| 2704 | + * displays an error message to ppl who have javascript disabled |
|
| 2705 | + * |
|
| 2706 | + * @return void |
|
| 2707 | + */ |
|
| 2708 | + private function _display_no_javascript_warning() |
|
| 2709 | + { |
|
| 2710 | + ?> |
|
| 2711 | 2711 | <noscript> |
| 2712 | 2712 | <div id="no-js-message" class="error"> |
| 2713 | 2713 | <p style="font-size:1.3em;"> |
| 2714 | 2714 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2715 | 2715 | <?php esc_html_e( |
| 2716 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2717 | - 'event_espresso' |
|
| 2718 | - ); ?> |
|
| 2716 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2717 | + 'event_espresso' |
|
| 2718 | + ); ?> |
|
| 2719 | 2719 | </p> |
| 2720 | 2720 | </div> |
| 2721 | 2721 | </noscript> |
| 2722 | 2722 | <?php |
| 2723 | - } |
|
| 2723 | + } |
|
| 2724 | 2724 | |
| 2725 | 2725 | |
| 2726 | 2726 | |
| 2727 | - /** |
|
| 2728 | - * displays espresso success and/or error notices |
|
| 2729 | - * |
|
| 2730 | - * @return void |
|
| 2731 | - */ |
|
| 2732 | - private function _display_espresso_notices() |
|
| 2733 | - { |
|
| 2734 | - $notices = $this->_get_transient(true); |
|
| 2735 | - echo stripslashes($notices); |
|
| 2736 | - } |
|
| 2727 | + /** |
|
| 2728 | + * displays espresso success and/or error notices |
|
| 2729 | + * |
|
| 2730 | + * @return void |
|
| 2731 | + */ |
|
| 2732 | + private function _display_espresso_notices() |
|
| 2733 | + { |
|
| 2734 | + $notices = $this->_get_transient(true); |
|
| 2735 | + echo stripslashes($notices); |
|
| 2736 | + } |
|
| 2737 | 2737 | |
| 2738 | 2738 | |
| 2739 | 2739 | |
| 2740 | - /** |
|
| 2741 | - * spinny things pacify the masses |
|
| 2742 | - * |
|
| 2743 | - * @return void |
|
| 2744 | - */ |
|
| 2745 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2746 | - { |
|
| 2747 | - ?> |
|
| 2740 | + /** |
|
| 2741 | + * spinny things pacify the masses |
|
| 2742 | + * |
|
| 2743 | + * @return void |
|
| 2744 | + */ |
|
| 2745 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2746 | + { |
|
| 2747 | + ?> |
|
| 2748 | 2748 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2749 | 2749 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e( |
| 2750 | - 'loading...', |
|
| 2751 | - 'event_espresso' |
|
| 2752 | - ); ?></span> |
|
| 2750 | + 'loading...', |
|
| 2751 | + 'event_espresso' |
|
| 2752 | + ); ?></span> |
|
| 2753 | 2753 | </div> |
| 2754 | 2754 | <?php |
| 2755 | - } |
|
| 2755 | + } |
|
| 2756 | 2756 | |
| 2757 | 2757 | |
| 2758 | 2758 | |
| 2759 | - /** |
|
| 2760 | - * add admin page overlay for modal boxes |
|
| 2761 | - * |
|
| 2762 | - * @return void |
|
| 2763 | - */ |
|
| 2764 | - protected function _add_admin_page_overlay() |
|
| 2765 | - { |
|
| 2766 | - ?> |
|
| 2759 | + /** |
|
| 2760 | + * add admin page overlay for modal boxes |
|
| 2761 | + * |
|
| 2762 | + * @return void |
|
| 2763 | + */ |
|
| 2764 | + protected function _add_admin_page_overlay() |
|
| 2765 | + { |
|
| 2766 | + ?> |
|
| 2767 | 2767 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2768 | 2768 | <?php |
| 2769 | - } |
|
| 2770 | - |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * facade for add_meta_box |
|
| 2775 | - * |
|
| 2776 | - * @param string $action where the metabox get's displayed |
|
| 2777 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2778 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2779 | - * instead of the one created in here. |
|
| 2780 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2781 | - * @param string $column what metabox column |
|
| 2782 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2783 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2784 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2785 | - * @throws \DomainException |
|
| 2786 | - */ |
|
| 2787 | - public function _add_admin_page_meta_box( |
|
| 2788 | - $action, |
|
| 2789 | - $title, |
|
| 2790 | - $callback, |
|
| 2791 | - $callback_args, |
|
| 2792 | - $column = 'normal', |
|
| 2793 | - $priority = 'high', |
|
| 2794 | - $create_func = true |
|
| 2795 | - ) { |
|
| 2796 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2797 | - //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2798 | - if (empty($callback_args) && $create_func) { |
|
| 2799 | - $callback_args = array( |
|
| 2800 | - 'template_path' => $this->_template_path, |
|
| 2801 | - 'template_args' => $this->_template_args, |
|
| 2802 | - ); |
|
| 2803 | - } |
|
| 2804 | - //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2805 | - $call_back_func = $create_func |
|
| 2806 | - ? function ($post, $metabox) |
|
| 2807 | - { |
|
| 2808 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2809 | - echo EEH_Template::display_template( |
|
| 2810 | - $metabox['args']['template_path'], |
|
| 2811 | - $metabox['args']['template_args'], |
|
| 2812 | - true |
|
| 2813 | - ); |
|
| 2814 | - } |
|
| 2815 | - : $callback; |
|
| 2816 | - add_meta_box( |
|
| 2817 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2818 | - $title, |
|
| 2819 | - $call_back_func, |
|
| 2820 | - $this->_wp_page_slug, |
|
| 2821 | - $column, |
|
| 2822 | - $priority, |
|
| 2823 | - $callback_args |
|
| 2824 | - ); |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - |
|
| 2828 | - |
|
| 2829 | - /** |
|
| 2830 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2831 | - * |
|
| 2832 | - * @throws DomainException |
|
| 2833 | - * @throws EE_Error |
|
| 2834 | - */ |
|
| 2835 | - public function display_admin_page_with_metabox_columns() |
|
| 2836 | - { |
|
| 2837 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2838 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2839 | - $this->_column_template_path, |
|
| 2840 | - $this->_template_args, |
|
| 2841 | - true |
|
| 2842 | - ); |
|
| 2843 | - //the final wrapper |
|
| 2844 | - $this->admin_page_wrapper(); |
|
| 2845 | - } |
|
| 2846 | - |
|
| 2847 | - |
|
| 2848 | - |
|
| 2849 | - /** |
|
| 2850 | - * generates HTML wrapper for an admin details page |
|
| 2851 | - * |
|
| 2852 | - * @return void |
|
| 2853 | - * @throws EE_Error |
|
| 2854 | - * @throws DomainException |
|
| 2855 | - */ |
|
| 2856 | - public function display_admin_page_with_sidebar() |
|
| 2857 | - { |
|
| 2858 | - $this->_display_admin_page(true); |
|
| 2859 | - } |
|
| 2860 | - |
|
| 2861 | - |
|
| 2862 | - |
|
| 2863 | - /** |
|
| 2864 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2865 | - * |
|
| 2866 | - * @return void |
|
| 2867 | - * @throws EE_Error |
|
| 2868 | - * @throws DomainException |
|
| 2869 | - */ |
|
| 2870 | - public function display_admin_page_with_no_sidebar() |
|
| 2871 | - { |
|
| 2872 | - $this->_display_admin_page(); |
|
| 2873 | - } |
|
| 2874 | - |
|
| 2875 | - |
|
| 2876 | - |
|
| 2877 | - /** |
|
| 2878 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2879 | - * |
|
| 2880 | - * @return void |
|
| 2881 | - * @throws EE_Error |
|
| 2882 | - * @throws DomainException |
|
| 2883 | - */ |
|
| 2884 | - public function display_about_admin_page() |
|
| 2885 | - { |
|
| 2886 | - $this->_display_admin_page(false, true); |
|
| 2887 | - } |
|
| 2888 | - |
|
| 2889 | - |
|
| 2890 | - |
|
| 2891 | - /** |
|
| 2892 | - * display_admin_page |
|
| 2893 | - * contains the code for actually displaying an admin page |
|
| 2894 | - * |
|
| 2895 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2896 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2897 | - * @return void |
|
| 2898 | - * @throws DomainException |
|
| 2899 | - * @throws EE_Error |
|
| 2900 | - */ |
|
| 2901 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2902 | - { |
|
| 2903 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2904 | - //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2905 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2906 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2907 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2908 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2909 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2910 | - ? 'poststuff' |
|
| 2911 | - : 'espresso-default-admin'; |
|
| 2912 | - $template_path = $sidebar |
|
| 2913 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2914 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2915 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2916 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2917 | - } |
|
| 2918 | - $template_path = ! empty($this->_column_template_path) |
|
| 2919 | - ? $this->_column_template_path : $template_path; |
|
| 2920 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2921 | - ? $this->_template_args['admin_page_content'] |
|
| 2922 | - : ''; |
|
| 2923 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2924 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2925 | - : ''; |
|
| 2926 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2927 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2928 | - : ''; |
|
| 2929 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2930 | - $template_path, |
|
| 2931 | - $this->_template_args, |
|
| 2932 | - true |
|
| 2933 | - ); |
|
| 2934 | - // the final template wrapper |
|
| 2935 | - $this->admin_page_wrapper($about); |
|
| 2936 | - } |
|
| 2937 | - |
|
| 2938 | - |
|
| 2939 | - |
|
| 2940 | - /** |
|
| 2941 | - * This is used to display caf preview pages. |
|
| 2942 | - * |
|
| 2943 | - * @since 4.3.2 |
|
| 2944 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2945 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2946 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2947 | - * @return void |
|
| 2948 | - * @throws DomainException |
|
| 2949 | - * @throws EE_Error |
|
| 2950 | - * @throws InvalidArgumentException |
|
| 2951 | - * @throws InvalidDataTypeException |
|
| 2952 | - * @throws InvalidInterfaceException |
|
| 2953 | - */ |
|
| 2954 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2955 | - { |
|
| 2956 | - //let's generate a default preview action button if there isn't one already present. |
|
| 2957 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2958 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2959 | - 'event_espresso' |
|
| 2960 | - ); |
|
| 2961 | - $buy_now_url = add_query_arg( |
|
| 2962 | - array( |
|
| 2963 | - 'ee_ver' => 'ee4', |
|
| 2964 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2965 | - 'utm_medium' => 'link', |
|
| 2966 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2967 | - 'utm_content' => 'buy_now_button', |
|
| 2968 | - ), |
|
| 2969 | - 'http://eventespresso.com/pricing/' |
|
| 2970 | - ); |
|
| 2971 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2972 | - ? $this->get_action_link_or_button( |
|
| 2973 | - '', |
|
| 2974 | - 'buy_now', |
|
| 2975 | - array(), |
|
| 2976 | - 'button-primary button-large', |
|
| 2977 | - $buy_now_url, |
|
| 2978 | - true |
|
| 2979 | - ) |
|
| 2980 | - : $this->_template_args['preview_action_button']; |
|
| 2981 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2982 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2983 | - $this->_template_args, |
|
| 2984 | - true |
|
| 2985 | - ); |
|
| 2986 | - $this->_display_admin_page($display_sidebar); |
|
| 2987 | - } |
|
| 2988 | - |
|
| 2989 | - |
|
| 2990 | - |
|
| 2991 | - /** |
|
| 2992 | - * display_admin_list_table_page_with_sidebar |
|
| 2993 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2994 | - * |
|
| 2995 | - * @return void |
|
| 2996 | - * @throws EE_Error |
|
| 2997 | - * @throws DomainException |
|
| 2998 | - */ |
|
| 2999 | - public function display_admin_list_table_page_with_sidebar() |
|
| 3000 | - { |
|
| 3001 | - $this->_display_admin_list_table_page(true); |
|
| 3002 | - } |
|
| 3003 | - |
|
| 3004 | - |
|
| 3005 | - |
|
| 3006 | - /** |
|
| 3007 | - * display_admin_list_table_page_with_no_sidebar |
|
| 3008 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3009 | - * |
|
| 3010 | - * @return void |
|
| 3011 | - * @throws EE_Error |
|
| 3012 | - * @throws DomainException |
|
| 3013 | - */ |
|
| 3014 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 3015 | - { |
|
| 3016 | - $this->_display_admin_list_table_page(); |
|
| 3017 | - } |
|
| 3018 | - |
|
| 3019 | - |
|
| 3020 | - |
|
| 3021 | - /** |
|
| 3022 | - * generates html wrapper for an admin_list_table page |
|
| 3023 | - * |
|
| 3024 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3025 | - * @return void |
|
| 3026 | - * @throws DomainException |
|
| 3027 | - * @throws EE_Error |
|
| 3028 | - */ |
|
| 3029 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 3030 | - { |
|
| 3031 | - //setup search attributes |
|
| 3032 | - $this->_set_search_attributes(); |
|
| 3033 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3034 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3035 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 3036 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 3037 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 3038 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3039 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 3040 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3041 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3042 | - if (! empty($ajax_sorting_callback)) { |
|
| 3043 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3044 | - $ajax_sorting_callback . '_nonce', |
|
| 3045 | - $ajax_sorting_callback . '_nonce', |
|
| 3046 | - false, |
|
| 3047 | - false |
|
| 3048 | - ); |
|
| 3049 | - // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 3050 | - // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 3051 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3052 | - . $this->page_slug |
|
| 3053 | - . '" />'; |
|
| 3054 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3055 | - . $ajax_sorting_callback |
|
| 3056 | - . '" />'; |
|
| 3057 | - } else { |
|
| 3058 | - $sortable_list_table_form_fields = ''; |
|
| 3059 | - } |
|
| 3060 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3061 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3062 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 3063 | - : ''; |
|
| 3064 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3065 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3066 | - . $nonce_ref |
|
| 3067 | - . '" value="' |
|
| 3068 | - . wp_create_nonce($nonce_ref) |
|
| 3069 | - . '">'; |
|
| 3070 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3071 | - //display message about search results? |
|
| 3072 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3073 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3074 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3075 | - trim($this->_req_data['s'], '%') |
|
| 3076 | - ) . '</p>' |
|
| 3077 | - : ''; |
|
| 3078 | - // filter before_list_table template arg |
|
| 3079 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3080 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3081 | - $this->_template_args['before_list_table'], |
|
| 3082 | - $this->page_slug, |
|
| 3083 | - $this->_req_data, |
|
| 3084 | - $this->_req_action |
|
| 3085 | - ); |
|
| 3086 | - // convert to array and filter again |
|
| 3087 | - // arrays are easier to inject new items in a specific location, |
|
| 3088 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3089 | - $this->_template_args['before_list_table'] = implode( |
|
| 3090 | - " \n", |
|
| 3091 | - (array)apply_filters( |
|
| 3092 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3093 | - (array)$this->_template_args['before_list_table'], |
|
| 3094 | - $this->page_slug, |
|
| 3095 | - $this->_req_data, |
|
| 3096 | - $this->_req_action |
|
| 3097 | - ) |
|
| 3098 | - ); |
|
| 3099 | - // filter after_list_table template arg |
|
| 3100 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3101 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3102 | - $this->_template_args['after_list_table'], |
|
| 3103 | - $this->page_slug, |
|
| 3104 | - $this->_req_data, |
|
| 3105 | - $this->_req_action |
|
| 3106 | - ); |
|
| 3107 | - // convert to array and filter again |
|
| 3108 | - // arrays are easier to inject new items in a specific location, |
|
| 3109 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3110 | - $this->_template_args['after_list_table'] = implode( |
|
| 3111 | - " \n", |
|
| 3112 | - (array)apply_filters( |
|
| 3113 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3114 | - (array)$this->_template_args['after_list_table'], |
|
| 3115 | - $this->page_slug, |
|
| 3116 | - $this->_req_data, |
|
| 3117 | - $this->_req_action |
|
| 3118 | - ) |
|
| 3119 | - ); |
|
| 3120 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3121 | - $template_path, |
|
| 3122 | - $this->_template_args, |
|
| 3123 | - true |
|
| 3124 | - ); |
|
| 3125 | - // the final template wrapper |
|
| 3126 | - if ($sidebar) { |
|
| 3127 | - $this->display_admin_page_with_sidebar(); |
|
| 3128 | - } else { |
|
| 3129 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3130 | - } |
|
| 3131 | - } |
|
| 3132 | - |
|
| 3133 | - |
|
| 3134 | - |
|
| 3135 | - /** |
|
| 3136 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3137 | - * html string for the legend. |
|
| 3138 | - * $items are expected in an array in the following format: |
|
| 3139 | - * $legend_items = array( |
|
| 3140 | - * 'item_id' => array( |
|
| 3141 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3142 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3143 | - * ) |
|
| 3144 | - * ); |
|
| 3145 | - * |
|
| 3146 | - * @param array $items see above for format of array |
|
| 3147 | - * @return string html string of legend |
|
| 3148 | - * @throws DomainException |
|
| 3149 | - */ |
|
| 3150 | - protected function _display_legend($items) |
|
| 3151 | - { |
|
| 3152 | - $this->_template_args['items'] = apply_filters( |
|
| 3153 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3154 | - (array)$items, |
|
| 3155 | - $this |
|
| 3156 | - ); |
|
| 3157 | - return EEH_Template::display_template( |
|
| 3158 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3159 | - $this->_template_args, |
|
| 3160 | - true |
|
| 3161 | - ); |
|
| 3162 | - } |
|
| 3163 | - |
|
| 3164 | - |
|
| 3165 | - /** |
|
| 3166 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3167 | - * The returned json object is created from an array in the following format: |
|
| 3168 | - * array( |
|
| 3169 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3170 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3171 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3172 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3173 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3174 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3175 | - * that might be included in here) |
|
| 3176 | - * ) |
|
| 3177 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3178 | - * |
|
| 3179 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3180 | - * instead of displayed. |
|
| 3181 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3182 | - * @return void |
|
| 3183 | - * @throws EE_Error |
|
| 3184 | - */ |
|
| 3185 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3186 | - { |
|
| 3187 | - //make sure any EE_Error notices have been handled. |
|
| 3188 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3189 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3190 | - unset($this->_template_args['data']); |
|
| 3191 | - $json = array( |
|
| 3192 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3193 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3194 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3195 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3196 | - 'notices' => EE_Error::get_notices(), |
|
| 3197 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3198 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3199 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3200 | - 'isEEajax' => true |
|
| 3201 | - //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3202 | - ); |
|
| 3203 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3204 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3205 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3206 | - } |
|
| 3207 | - echo wp_json_encode($json); |
|
| 3208 | - exit(); |
|
| 3209 | - } |
|
| 3210 | - |
|
| 3211 | - |
|
| 3212 | - |
|
| 3213 | - /** |
|
| 3214 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3215 | - * |
|
| 3216 | - * @return void |
|
| 3217 | - * @throws EE_Error |
|
| 3218 | - */ |
|
| 3219 | - public function return_json() |
|
| 3220 | - { |
|
| 3221 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3222 | - $this->_return_json(); |
|
| 3223 | - } else { |
|
| 3224 | - throw new EE_Error( |
|
| 3225 | - sprintf( |
|
| 3226 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3227 | - __FUNCTION__ |
|
| 3228 | - ) |
|
| 3229 | - ); |
|
| 3230 | - } |
|
| 3231 | - } |
|
| 3232 | - |
|
| 3233 | - |
|
| 3234 | - |
|
| 3235 | - /** |
|
| 3236 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3237 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3238 | - * |
|
| 3239 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3240 | - */ |
|
| 3241 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3242 | - { |
|
| 3243 | - $this->_hook_obj = $hook_obj; |
|
| 3244 | - } |
|
| 3245 | - |
|
| 3246 | - |
|
| 3247 | - |
|
| 3248 | - /** |
|
| 3249 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3250 | - * |
|
| 3251 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3252 | - * @return void |
|
| 3253 | - * @throws DomainException |
|
| 3254 | - * @throws EE_Error |
|
| 3255 | - */ |
|
| 3256 | - public function admin_page_wrapper($about = false) |
|
| 3257 | - { |
|
| 3258 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3259 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3260 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3261 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3262 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3263 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3264 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3265 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3266 | - : '' |
|
| 3267 | - ); |
|
| 3268 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3269 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3270 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3271 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3272 | - : '' |
|
| 3273 | - ); |
|
| 3274 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3275 | - // load settings page wrapper template |
|
| 3276 | - $template_path = ! defined('DOING_AJAX') |
|
| 3277 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3278 | - : EE_ADMIN_TEMPLATE |
|
| 3279 | - . 'admin_wrapper_ajax.template.php'; |
|
| 3280 | - //about page? |
|
| 3281 | - $template_path = $about |
|
| 3282 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3283 | - : $template_path; |
|
| 3284 | - if (defined('DOING_AJAX')) { |
|
| 3285 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3286 | - $template_path, |
|
| 3287 | - $this->_template_args, |
|
| 3288 | - true |
|
| 3289 | - ); |
|
| 3290 | - $this->_return_json(); |
|
| 3291 | - } else { |
|
| 3292 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3293 | - } |
|
| 3294 | - } |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - |
|
| 3298 | - /** |
|
| 3299 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3300 | - * |
|
| 3301 | - * @return string html |
|
| 3302 | - * @throws EE_Error |
|
| 3303 | - */ |
|
| 3304 | - protected function _get_main_nav_tabs() |
|
| 3305 | - { |
|
| 3306 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3307 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3308 | - // (rather than setting in the page_routes array) |
|
| 3309 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3310 | - } |
|
| 3311 | - |
|
| 3312 | - |
|
| 3313 | - |
|
| 3314 | - /** |
|
| 3315 | - * sort nav tabs |
|
| 3316 | - * |
|
| 3317 | - * @param $a |
|
| 3318 | - * @param $b |
|
| 3319 | - * @return int |
|
| 3320 | - */ |
|
| 3321 | - private function _sort_nav_tabs($a, $b) |
|
| 3322 | - { |
|
| 3323 | - if ($a['order'] === $b['order']) { |
|
| 3324 | - return 0; |
|
| 3325 | - } |
|
| 3326 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3327 | - } |
|
| 3328 | - |
|
| 3329 | - |
|
| 3330 | - |
|
| 3331 | - /** |
|
| 3332 | - * generates HTML for the forms used on admin pages |
|
| 3333 | - * |
|
| 3334 | - * @param array $input_vars - array of input field details |
|
| 3335 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3336 | - * use) |
|
| 3337 | - * @param bool $id |
|
| 3338 | - * @return string |
|
| 3339 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3340 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3341 | - */ |
|
| 3342 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3343 | - { |
|
| 3344 | - $content = $generator === 'string' |
|
| 3345 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3346 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3347 | - return $content; |
|
| 3348 | - } |
|
| 3349 | - |
|
| 3350 | - |
|
| 3351 | - |
|
| 3352 | - /** |
|
| 3353 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3354 | - * |
|
| 3355 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3356 | - * Close" button. |
|
| 3357 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3358 | - * 'Save', [1] => 'save & close') |
|
| 3359 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3360 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3361 | - * default actions by submitting some other value. |
|
| 3362 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3363 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3364 | - * close (normal form handling). |
|
| 3365 | - */ |
|
| 3366 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3367 | - { |
|
| 3368 | - //make sure $text and $actions are in an array |
|
| 3369 | - $text = (array)$text; |
|
| 3370 | - $actions = (array)$actions; |
|
| 3371 | - $referrer_url = empty($referrer) |
|
| 3372 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3373 | - . $_SERVER['REQUEST_URI'] |
|
| 3374 | - . '" />' |
|
| 3375 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3376 | - . $referrer |
|
| 3377 | - . '" />'; |
|
| 3378 | - $button_text = ! empty($text) |
|
| 3379 | - ? $text |
|
| 3380 | - : array( |
|
| 3381 | - esc_html__('Save', 'event_espresso'), |
|
| 3382 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3383 | - ); |
|
| 3384 | - $default_names = array('save', 'save_and_close'); |
|
| 3385 | - //add in a hidden index for the current page (so save and close redirects properly) |
|
| 3386 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3387 | - foreach ($button_text as $key => $button) { |
|
| 3388 | - $ref = $default_names[$key]; |
|
| 3389 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3390 | - . $ref |
|
| 3391 | - . '" value="' |
|
| 3392 | - . $button |
|
| 3393 | - . '" name="' |
|
| 3394 | - . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3395 | - . '" id="' |
|
| 3396 | - . $this->_current_view . '_' . $ref |
|
| 3397 | - . '" />'; |
|
| 3398 | - if (! $both) { |
|
| 3399 | - break; |
|
| 3400 | - } |
|
| 3401 | - } |
|
| 3402 | - } |
|
| 3403 | - |
|
| 3404 | - |
|
| 3405 | - |
|
| 3406 | - /** |
|
| 3407 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3408 | - * |
|
| 3409 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3410 | - * @since 4.6.0 |
|
| 3411 | - * @param string $route |
|
| 3412 | - * @param array $additional_hidden_fields |
|
| 3413 | - */ |
|
| 3414 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3415 | - { |
|
| 3416 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3417 | - } |
|
| 3418 | - |
|
| 3419 | - |
|
| 3420 | - |
|
| 3421 | - /** |
|
| 3422 | - * set form open and close tags on add/edit pages. |
|
| 3423 | - * |
|
| 3424 | - * @param string $route the route you want the form to direct to |
|
| 3425 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3426 | - * @return void |
|
| 3427 | - */ |
|
| 3428 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3429 | - { |
|
| 3430 | - if (empty($route)) { |
|
| 3431 | - $user_msg = esc_html__( |
|
| 3432 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3433 | - 'event_espresso' |
|
| 3434 | - ); |
|
| 3435 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3436 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3437 | - __FUNCTION__, |
|
| 3438 | - __CLASS__ |
|
| 3439 | - ); |
|
| 3440 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3441 | - } |
|
| 3442 | - // open form |
|
| 3443 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3444 | - . $this->_admin_base_url |
|
| 3445 | - . '" id="' |
|
| 3446 | - . $route |
|
| 3447 | - . '_event_form" >'; |
|
| 3448 | - // add nonce |
|
| 3449 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3450 | - // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 3451 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3452 | - // add REQUIRED form action |
|
| 3453 | - $hidden_fields = array( |
|
| 3454 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3455 | - ); |
|
| 3456 | - // merge arrays |
|
| 3457 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3458 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3459 | - : $hidden_fields; |
|
| 3460 | - // generate form fields |
|
| 3461 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3462 | - // add fields to form |
|
| 3463 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3464 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3465 | - } |
|
| 3466 | - // close form |
|
| 3467 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3468 | - } |
|
| 3469 | - |
|
| 3470 | - |
|
| 3471 | - |
|
| 3472 | - /** |
|
| 3473 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3474 | - * discovered it would be useful for external code to have access. |
|
| 3475 | - * |
|
| 3476 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3477 | - * @since 4.5.0 |
|
| 3478 | - * @param bool $success |
|
| 3479 | - * @param string $what |
|
| 3480 | - * @param string $action_desc |
|
| 3481 | - * @param array $query_args |
|
| 3482 | - * @param bool $override_overwrite |
|
| 3483 | - * @throws EE_Error |
|
| 3484 | - */ |
|
| 3485 | - public function redirect_after_action( |
|
| 3486 | - $success = false, |
|
| 3487 | - $what = 'item', |
|
| 3488 | - $action_desc = 'processed', |
|
| 3489 | - $query_args = array(), |
|
| 3490 | - $override_overwrite = false |
|
| 3491 | - ) { |
|
| 3492 | - $this->_redirect_after_action( |
|
| 3493 | - $success, |
|
| 3494 | - $what, |
|
| 3495 | - $action_desc, |
|
| 3496 | - $query_args, |
|
| 3497 | - $override_overwrite |
|
| 3498 | - ); |
|
| 3499 | - } |
|
| 3500 | - |
|
| 3501 | - |
|
| 3502 | - |
|
| 3503 | - /** |
|
| 3504 | - * _redirect_after_action |
|
| 3505 | - * |
|
| 3506 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3507 | - * @param string $what - what the action was performed on |
|
| 3508 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3509 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3510 | - * action is completed |
|
| 3511 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3512 | - * override this so that they show. |
|
| 3513 | - * @return void |
|
| 3514 | - * @throws EE_Error |
|
| 3515 | - */ |
|
| 3516 | - protected function _redirect_after_action( |
|
| 3517 | - $success = 0, |
|
| 3518 | - $what = 'item', |
|
| 3519 | - $action_desc = 'processed', |
|
| 3520 | - $query_args = array(), |
|
| 3521 | - $override_overwrite = false |
|
| 3522 | - ) { |
|
| 3523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3524 | - //class name for actions/filters. |
|
| 3525 | - $classname = get_class($this); |
|
| 3526 | - // set redirect url. |
|
| 3527 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3528 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3529 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3530 | - $notices = EE_Error::get_notices(false); |
|
| 3531 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3532 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3533 | - EE_Error::overwrite_success(); |
|
| 3534 | - } |
|
| 3535 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3536 | - // how many records affected ? more than one record ? or just one ? |
|
| 3537 | - if ($success > 1) { |
|
| 3538 | - // set plural msg |
|
| 3539 | - EE_Error::add_success( |
|
| 3540 | - sprintf( |
|
| 3541 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3542 | - $what, |
|
| 3543 | - $action_desc |
|
| 3544 | - ), |
|
| 3545 | - __FILE__, |
|
| 3546 | - __FUNCTION__, |
|
| 3547 | - __LINE__ |
|
| 3548 | - ); |
|
| 3549 | - } elseif ($success === 1) { |
|
| 3550 | - // set singular msg |
|
| 3551 | - EE_Error::add_success( |
|
| 3552 | - sprintf( |
|
| 3553 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3554 | - $what, |
|
| 3555 | - $action_desc |
|
| 3556 | - ), |
|
| 3557 | - __FILE__, |
|
| 3558 | - __FUNCTION__, |
|
| 3559 | - __LINE__ |
|
| 3560 | - ); |
|
| 3561 | - } |
|
| 3562 | - } |
|
| 3563 | - // check that $query_args isn't something crazy |
|
| 3564 | - if (! is_array($query_args)) { |
|
| 3565 | - $query_args = array(); |
|
| 3566 | - } |
|
| 3567 | - /** |
|
| 3568 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3569 | - * redirections on save and close actions |
|
| 3570 | - * |
|
| 3571 | - * @since 4.2.0 |
|
| 3572 | - * @param array $query_args The original query_args array coming into the |
|
| 3573 | - * method. |
|
| 3574 | - */ |
|
| 3575 | - do_action( |
|
| 3576 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3577 | - $query_args |
|
| 3578 | - ); |
|
| 3579 | - //calculate where we're going (if we have a "save and close" button pushed) |
|
| 3580 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3581 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3582 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3583 | - // regenerate query args array from referrer URL |
|
| 3584 | - parse_str($parsed_url['query'], $query_args); |
|
| 3585 | - // correct page and action will be in the query args now |
|
| 3586 | - $redirect_url = admin_url('admin.php'); |
|
| 3587 | - } |
|
| 3588 | - //merge any default query_args set in _default_route_query_args property |
|
| 3589 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | - $args_to_merge = array(); |
|
| 3591 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3592 | - //is there a wp_referer array in our _default_route_query_args property? |
|
| 3593 | - if ($query_param === 'wp_referer') { |
|
| 3594 | - $query_value = (array)$query_value; |
|
| 3595 | - foreach ($query_value as $reference => $value) { |
|
| 3596 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3597 | - continue; |
|
| 3598 | - } |
|
| 3599 | - //finally we will override any arguments in the referer with |
|
| 3600 | - //what might be set on the _default_route_query_args array. |
|
| 3601 | - if (isset($this->_default_route_query_args[$reference])) { |
|
| 3602 | - $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3603 | - } else { |
|
| 3604 | - $args_to_merge[$reference] = urlencode($value); |
|
| 3605 | - } |
|
| 3606 | - } |
|
| 3607 | - continue; |
|
| 3608 | - } |
|
| 3609 | - $args_to_merge[$query_param] = $query_value; |
|
| 3610 | - } |
|
| 3611 | - //now let's merge these arguments but override with what was specifically sent in to the |
|
| 3612 | - //redirect. |
|
| 3613 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3614 | - } |
|
| 3615 | - $this->_process_notices($query_args); |
|
| 3616 | - // generate redirect url |
|
| 3617 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3618 | - if (isset($query_args['action'])) { |
|
| 3619 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3620 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3621 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3622 | - } |
|
| 3623 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3624 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3625 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3626 | - $redirect_url = apply_filters( |
|
| 3627 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3628 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3629 | - $query_args |
|
| 3630 | - ); |
|
| 3631 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3632 | - if (defined('DOING_AJAX')) { |
|
| 3633 | - $default_data = array( |
|
| 3634 | - 'close' => true, |
|
| 3635 | - 'redirect_url' => $redirect_url, |
|
| 3636 | - 'where' => 'main', |
|
| 3637 | - 'what' => 'append', |
|
| 3638 | - ); |
|
| 3639 | - $this->_template_args['success'] = $success; |
|
| 3640 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3641 | - $default_data, |
|
| 3642 | - $this->_template_args['data'] |
|
| 3643 | - ) : $default_data; |
|
| 3644 | - $this->_return_json(); |
|
| 3645 | - } |
|
| 3646 | - wp_safe_redirect($redirect_url); |
|
| 3647 | - exit(); |
|
| 3648 | - } |
|
| 3649 | - |
|
| 3650 | - |
|
| 3651 | - |
|
| 3652 | - /** |
|
| 3653 | - * process any notices before redirecting (or returning ajax request) |
|
| 3654 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3655 | - * |
|
| 3656 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3657 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3658 | - * page_routes haven't been defined yet. |
|
| 3659 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3660 | - * still save a transient for the notice. |
|
| 3661 | - * @return void |
|
| 3662 | - * @throws EE_Error |
|
| 3663 | - */ |
|
| 3664 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3665 | - { |
|
| 3666 | - //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3667 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3668 | - $notices = EE_Error::get_notices(false); |
|
| 3669 | - if (empty($this->_template_args['success'])) { |
|
| 3670 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3671 | - } |
|
| 3672 | - if (empty($this->_template_args['errors'])) { |
|
| 3673 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3674 | - } |
|
| 3675 | - if (empty($this->_template_args['attention'])) { |
|
| 3676 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3677 | - } |
|
| 3678 | - } |
|
| 3679 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3680 | - //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3681 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3682 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3683 | - $this->_add_transient( |
|
| 3684 | - $route, |
|
| 3685 | - $this->_template_args['notices'], |
|
| 3686 | - true, |
|
| 3687 | - $skip_route_verify |
|
| 3688 | - ); |
|
| 3689 | - } |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - |
|
| 3693 | - |
|
| 3694 | - /** |
|
| 3695 | - * get_action_link_or_button |
|
| 3696 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3697 | - * |
|
| 3698 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3699 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3700 | - * property. |
|
| 3701 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3702 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3703 | - * @param string $base_url If this is not provided |
|
| 3704 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3705 | - * Otherwise this value will be used. |
|
| 3706 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3707 | - * @return string |
|
| 3708 | - * @throws InvalidArgumentException |
|
| 3709 | - * @throws InvalidInterfaceException |
|
| 3710 | - * @throws InvalidDataTypeException |
|
| 3711 | - * @throws EE_Error |
|
| 3712 | - */ |
|
| 3713 | - public function get_action_link_or_button( |
|
| 3714 | - $action, |
|
| 3715 | - $type = 'add', |
|
| 3716 | - $extra_request = array(), |
|
| 3717 | - $class = 'button-primary', |
|
| 3718 | - $base_url = '', |
|
| 3719 | - $exclude_nonce = false |
|
| 3720 | - ) { |
|
| 3721 | - //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3722 | - if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3723 | - throw new EE_Error( |
|
| 3724 | - sprintf( |
|
| 3725 | - esc_html__( |
|
| 3726 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3727 | - 'event_espresso' |
|
| 3728 | - ), |
|
| 3729 | - $action |
|
| 3730 | - ) |
|
| 3731 | - ); |
|
| 3732 | - } |
|
| 3733 | - if (! isset($this->_labels['buttons'][$type])) { |
|
| 3734 | - throw new EE_Error( |
|
| 3735 | - sprintf( |
|
| 3736 | - __( |
|
| 3737 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3738 | - 'event_espresso' |
|
| 3739 | - ), |
|
| 3740 | - $type |
|
| 3741 | - ) |
|
| 3742 | - ); |
|
| 3743 | - } |
|
| 3744 | - //finally check user access for this button. |
|
| 3745 | - $has_access = $this->check_user_access($action, true); |
|
| 3746 | - if (! $has_access) { |
|
| 3747 | - return ''; |
|
| 3748 | - } |
|
| 3749 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3750 | - $query_args = array( |
|
| 3751 | - 'action' => $action, |
|
| 3752 | - ); |
|
| 3753 | - //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3754 | - if (! empty($extra_request)) { |
|
| 3755 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3756 | - } |
|
| 3757 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3758 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3759 | - } |
|
| 3760 | - |
|
| 3761 | - |
|
| 3762 | - |
|
| 3763 | - /** |
|
| 3764 | - * _per_page_screen_option |
|
| 3765 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3766 | - * |
|
| 3767 | - * @return void |
|
| 3768 | - * @throws InvalidArgumentException |
|
| 3769 | - * @throws InvalidInterfaceException |
|
| 3770 | - * @throws InvalidDataTypeException |
|
| 3771 | - */ |
|
| 3772 | - protected function _per_page_screen_option() |
|
| 3773 | - { |
|
| 3774 | - $option = 'per_page'; |
|
| 3775 | - $args = array( |
|
| 3776 | - 'label' => esc_html__( |
|
| 3777 | - apply_filters( |
|
| 3778 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3779 | - $this->_admin_page_title, |
|
| 3780 | - $this |
|
| 3781 | - ) |
|
| 3782 | - ), |
|
| 3783 | - 'default' => (int) apply_filters( |
|
| 3784 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3785 | - 10 |
|
| 3786 | - ), |
|
| 3787 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3788 | - ); |
|
| 3789 | - //ONLY add the screen option if the user has access to it. |
|
| 3790 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3791 | - add_screen_option($option, $args); |
|
| 3792 | - } |
|
| 3793 | - } |
|
| 3794 | - |
|
| 3795 | - |
|
| 3796 | - |
|
| 3797 | - /** |
|
| 3798 | - * set_per_page_screen_option |
|
| 3799 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3800 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3801 | - * admin_menu. |
|
| 3802 | - * |
|
| 3803 | - * @return void |
|
| 3804 | - */ |
|
| 3805 | - private function _set_per_page_screen_options() |
|
| 3806 | - { |
|
| 3807 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3808 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3809 | - if (! $user = wp_get_current_user()) { |
|
| 3810 | - return; |
|
| 3811 | - } |
|
| 3812 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3813 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3814 | - if ($option != sanitize_key($option)) { |
|
| 3815 | - return; |
|
| 3816 | - } |
|
| 3817 | - $map_option = $option; |
|
| 3818 | - $option = str_replace('-', '_', $option); |
|
| 3819 | - switch ($map_option) { |
|
| 3820 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3821 | - $value = (int)$value; |
|
| 3822 | - $max_value = apply_filters( |
|
| 3823 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3824 | - 999, |
|
| 3825 | - $this->_current_page, |
|
| 3826 | - $this->_current_view |
|
| 3827 | - ); |
|
| 3828 | - if ($value < 1 || $value > $max_value) { |
|
| 3829 | - return; |
|
| 3830 | - } |
|
| 3831 | - break; |
|
| 3832 | - default: |
|
| 3833 | - $value = apply_filters( |
|
| 3834 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3835 | - false, |
|
| 3836 | - $option, |
|
| 3837 | - $value |
|
| 3838 | - ); |
|
| 3839 | - if (false === $value) { |
|
| 3840 | - return; |
|
| 3841 | - } |
|
| 3842 | - break; |
|
| 3843 | - } |
|
| 3844 | - update_user_meta($user->ID, $option, $value); |
|
| 3845 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3846 | - exit; |
|
| 3847 | - } |
|
| 3848 | - } |
|
| 3849 | - |
|
| 3850 | - |
|
| 3851 | - |
|
| 3852 | - /** |
|
| 3853 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3854 | - * |
|
| 3855 | - * @param array $data array that will be assigned to template args. |
|
| 3856 | - */ |
|
| 3857 | - public function set_template_args($data) |
|
| 3858 | - { |
|
| 3859 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3860 | - } |
|
| 3861 | - |
|
| 3862 | - |
|
| 3863 | - |
|
| 3864 | - /** |
|
| 3865 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3866 | - * |
|
| 3867 | - * @param string $route the route that should receive the transient |
|
| 3868 | - * @param array $data the data that gets sent |
|
| 3869 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3870 | - * normal route transient. |
|
| 3871 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3872 | - * when we are adding a transient before page_routes have been defined. |
|
| 3873 | - * @return void |
|
| 3874 | - * @throws EE_Error |
|
| 3875 | - */ |
|
| 3876 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3877 | - { |
|
| 3878 | - $user_id = get_current_user_id(); |
|
| 3879 | - if (! $skip_route_verify) { |
|
| 3880 | - $this->_verify_route($route); |
|
| 3881 | - } |
|
| 3882 | - //now let's set the string for what kind of transient we're setting |
|
| 3883 | - $transient = $notices |
|
| 3884 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3885 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3886 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3887 | - //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3888 | - $existing = is_multisite() && is_network_admin() |
|
| 3889 | - ? get_site_transient($transient) |
|
| 3890 | - : get_transient($transient); |
|
| 3891 | - if ($existing) { |
|
| 3892 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3893 | - } |
|
| 3894 | - if (is_multisite() && is_network_admin()) { |
|
| 3895 | - set_site_transient($transient, $data, 8); |
|
| 3896 | - } else { |
|
| 3897 | - set_transient($transient, $data, 8); |
|
| 3898 | - } |
|
| 3899 | - } |
|
| 3900 | - |
|
| 3901 | - |
|
| 3902 | - |
|
| 3903 | - /** |
|
| 3904 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3905 | - * |
|
| 3906 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3907 | - * @param string $route |
|
| 3908 | - * @return mixed data |
|
| 3909 | - */ |
|
| 3910 | - protected function _get_transient($notices = false, $route = '') |
|
| 3911 | - { |
|
| 3912 | - $user_id = get_current_user_id(); |
|
| 3913 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3914 | - $transient = $notices |
|
| 3915 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3916 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3917 | - $data = is_multisite() && is_network_admin() |
|
| 3918 | - ? get_site_transient($transient) |
|
| 3919 | - : get_transient($transient); |
|
| 3920 | - //delete transient after retrieval (just in case it hasn't expired); |
|
| 3921 | - if (is_multisite() && is_network_admin()) { |
|
| 3922 | - delete_site_transient($transient); |
|
| 3923 | - } else { |
|
| 3924 | - delete_transient($transient); |
|
| 3925 | - } |
|
| 3926 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3927 | - } |
|
| 3928 | - |
|
| 3929 | - |
|
| 3930 | - |
|
| 3931 | - /** |
|
| 3932 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3933 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3934 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3935 | - * |
|
| 3936 | - * @return void |
|
| 3937 | - */ |
|
| 3938 | - protected function _transient_garbage_collection() |
|
| 3939 | - { |
|
| 3940 | - global $wpdb; |
|
| 3941 | - //retrieve all existing transients |
|
| 3942 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3943 | - if ($results = $wpdb->get_results($query)) { |
|
| 3944 | - foreach ($results as $result) { |
|
| 3945 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3946 | - get_transient($transient); |
|
| 3947 | - if (is_multisite() && is_network_admin()) { |
|
| 3948 | - get_site_transient($transient); |
|
| 3949 | - } |
|
| 3950 | - } |
|
| 3951 | - } |
|
| 3952 | - } |
|
| 3953 | - |
|
| 3954 | - |
|
| 3955 | - |
|
| 3956 | - /** |
|
| 3957 | - * get_view |
|
| 3958 | - * |
|
| 3959 | - * @return string content of _view property |
|
| 3960 | - */ |
|
| 3961 | - public function get_view() |
|
| 3962 | - { |
|
| 3963 | - return $this->_view; |
|
| 3964 | - } |
|
| 3965 | - |
|
| 3966 | - |
|
| 3967 | - |
|
| 3968 | - /** |
|
| 3969 | - * getter for the protected $_views property |
|
| 3970 | - * |
|
| 3971 | - * @return array |
|
| 3972 | - */ |
|
| 3973 | - public function get_views() |
|
| 3974 | - { |
|
| 3975 | - return $this->_views; |
|
| 3976 | - } |
|
| 3977 | - |
|
| 3978 | - |
|
| 3979 | - |
|
| 3980 | - /** |
|
| 3981 | - * get_current_page |
|
| 3982 | - * |
|
| 3983 | - * @return string _current_page property value |
|
| 3984 | - */ |
|
| 3985 | - public function get_current_page() |
|
| 3986 | - { |
|
| 3987 | - return $this->_current_page; |
|
| 3988 | - } |
|
| 3989 | - |
|
| 3990 | - |
|
| 3991 | - |
|
| 3992 | - /** |
|
| 3993 | - * get_current_view |
|
| 3994 | - * |
|
| 3995 | - * @return string _current_view property value |
|
| 3996 | - */ |
|
| 3997 | - public function get_current_view() |
|
| 3998 | - { |
|
| 3999 | - return $this->_current_view; |
|
| 4000 | - } |
|
| 4001 | - |
|
| 4002 | - |
|
| 4003 | - |
|
| 4004 | - /** |
|
| 4005 | - * get_current_screen |
|
| 4006 | - * |
|
| 4007 | - * @return object The current WP_Screen object |
|
| 4008 | - */ |
|
| 4009 | - public function get_current_screen() |
|
| 4010 | - { |
|
| 4011 | - return $this->_current_screen; |
|
| 4012 | - } |
|
| 4013 | - |
|
| 4014 | - |
|
| 4015 | - |
|
| 4016 | - /** |
|
| 4017 | - * get_current_page_view_url |
|
| 4018 | - * |
|
| 4019 | - * @return string This returns the url for the current_page_view. |
|
| 4020 | - */ |
|
| 4021 | - public function get_current_page_view_url() |
|
| 4022 | - { |
|
| 4023 | - return $this->_current_page_view_url; |
|
| 4024 | - } |
|
| 4025 | - |
|
| 4026 | - |
|
| 4027 | - |
|
| 4028 | - /** |
|
| 4029 | - * just returns the _req_data property |
|
| 4030 | - * |
|
| 4031 | - * @return array |
|
| 4032 | - */ |
|
| 4033 | - public function get_request_data() |
|
| 4034 | - { |
|
| 4035 | - return $this->_req_data; |
|
| 4036 | - } |
|
| 4037 | - |
|
| 4038 | - |
|
| 4039 | - |
|
| 4040 | - /** |
|
| 4041 | - * returns the _req_data protected property |
|
| 4042 | - * |
|
| 4043 | - * @return string |
|
| 4044 | - */ |
|
| 4045 | - public function get_req_action() |
|
| 4046 | - { |
|
| 4047 | - return $this->_req_action; |
|
| 4048 | - } |
|
| 4049 | - |
|
| 4050 | - |
|
| 4051 | - |
|
| 4052 | - /** |
|
| 4053 | - * @return bool value of $_is_caf property |
|
| 4054 | - */ |
|
| 4055 | - public function is_caf() |
|
| 4056 | - { |
|
| 4057 | - return $this->_is_caf; |
|
| 4058 | - } |
|
| 4059 | - |
|
| 4060 | - |
|
| 4061 | - |
|
| 4062 | - /** |
|
| 4063 | - * @return mixed |
|
| 4064 | - */ |
|
| 4065 | - public function default_espresso_metaboxes() |
|
| 4066 | - { |
|
| 4067 | - return $this->_default_espresso_metaboxes; |
|
| 4068 | - } |
|
| 4069 | - |
|
| 4070 | - |
|
| 4071 | - |
|
| 4072 | - /** |
|
| 4073 | - * @return mixed |
|
| 4074 | - */ |
|
| 4075 | - public function admin_base_url() |
|
| 4076 | - { |
|
| 4077 | - return $this->_admin_base_url; |
|
| 4078 | - } |
|
| 2769 | + } |
|
| 2770 | + |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * facade for add_meta_box |
|
| 2775 | + * |
|
| 2776 | + * @param string $action where the metabox get's displayed |
|
| 2777 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2778 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2779 | + * instead of the one created in here. |
|
| 2780 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2781 | + * @param string $column what metabox column |
|
| 2782 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2783 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2784 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2785 | + * @throws \DomainException |
|
| 2786 | + */ |
|
| 2787 | + public function _add_admin_page_meta_box( |
|
| 2788 | + $action, |
|
| 2789 | + $title, |
|
| 2790 | + $callback, |
|
| 2791 | + $callback_args, |
|
| 2792 | + $column = 'normal', |
|
| 2793 | + $priority = 'high', |
|
| 2794 | + $create_func = true |
|
| 2795 | + ) { |
|
| 2796 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2797 | + //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2798 | + if (empty($callback_args) && $create_func) { |
|
| 2799 | + $callback_args = array( |
|
| 2800 | + 'template_path' => $this->_template_path, |
|
| 2801 | + 'template_args' => $this->_template_args, |
|
| 2802 | + ); |
|
| 2803 | + } |
|
| 2804 | + //if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2805 | + $call_back_func = $create_func |
|
| 2806 | + ? function ($post, $metabox) |
|
| 2807 | + { |
|
| 2808 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2809 | + echo EEH_Template::display_template( |
|
| 2810 | + $metabox['args']['template_path'], |
|
| 2811 | + $metabox['args']['template_args'], |
|
| 2812 | + true |
|
| 2813 | + ); |
|
| 2814 | + } |
|
| 2815 | + : $callback; |
|
| 2816 | + add_meta_box( |
|
| 2817 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2818 | + $title, |
|
| 2819 | + $call_back_func, |
|
| 2820 | + $this->_wp_page_slug, |
|
| 2821 | + $column, |
|
| 2822 | + $priority, |
|
| 2823 | + $callback_args |
|
| 2824 | + ); |
|
| 2825 | + } |
|
| 2826 | + |
|
| 2827 | + |
|
| 2828 | + |
|
| 2829 | + /** |
|
| 2830 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2831 | + * |
|
| 2832 | + * @throws DomainException |
|
| 2833 | + * @throws EE_Error |
|
| 2834 | + */ |
|
| 2835 | + public function display_admin_page_with_metabox_columns() |
|
| 2836 | + { |
|
| 2837 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2838 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2839 | + $this->_column_template_path, |
|
| 2840 | + $this->_template_args, |
|
| 2841 | + true |
|
| 2842 | + ); |
|
| 2843 | + //the final wrapper |
|
| 2844 | + $this->admin_page_wrapper(); |
|
| 2845 | + } |
|
| 2846 | + |
|
| 2847 | + |
|
| 2848 | + |
|
| 2849 | + /** |
|
| 2850 | + * generates HTML wrapper for an admin details page |
|
| 2851 | + * |
|
| 2852 | + * @return void |
|
| 2853 | + * @throws EE_Error |
|
| 2854 | + * @throws DomainException |
|
| 2855 | + */ |
|
| 2856 | + public function display_admin_page_with_sidebar() |
|
| 2857 | + { |
|
| 2858 | + $this->_display_admin_page(true); |
|
| 2859 | + } |
|
| 2860 | + |
|
| 2861 | + |
|
| 2862 | + |
|
| 2863 | + /** |
|
| 2864 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2865 | + * |
|
| 2866 | + * @return void |
|
| 2867 | + * @throws EE_Error |
|
| 2868 | + * @throws DomainException |
|
| 2869 | + */ |
|
| 2870 | + public function display_admin_page_with_no_sidebar() |
|
| 2871 | + { |
|
| 2872 | + $this->_display_admin_page(); |
|
| 2873 | + } |
|
| 2874 | + |
|
| 2875 | + |
|
| 2876 | + |
|
| 2877 | + /** |
|
| 2878 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2879 | + * |
|
| 2880 | + * @return void |
|
| 2881 | + * @throws EE_Error |
|
| 2882 | + * @throws DomainException |
|
| 2883 | + */ |
|
| 2884 | + public function display_about_admin_page() |
|
| 2885 | + { |
|
| 2886 | + $this->_display_admin_page(false, true); |
|
| 2887 | + } |
|
| 2888 | + |
|
| 2889 | + |
|
| 2890 | + |
|
| 2891 | + /** |
|
| 2892 | + * display_admin_page |
|
| 2893 | + * contains the code for actually displaying an admin page |
|
| 2894 | + * |
|
| 2895 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2896 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2897 | + * @return void |
|
| 2898 | + * @throws DomainException |
|
| 2899 | + * @throws EE_Error |
|
| 2900 | + */ |
|
| 2901 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2902 | + { |
|
| 2903 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2904 | + //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2905 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2906 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2907 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2908 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2909 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2910 | + ? 'poststuff' |
|
| 2911 | + : 'espresso-default-admin'; |
|
| 2912 | + $template_path = $sidebar |
|
| 2913 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2914 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2915 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2916 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2917 | + } |
|
| 2918 | + $template_path = ! empty($this->_column_template_path) |
|
| 2919 | + ? $this->_column_template_path : $template_path; |
|
| 2920 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2921 | + ? $this->_template_args['admin_page_content'] |
|
| 2922 | + : ''; |
|
| 2923 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2924 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2925 | + : ''; |
|
| 2926 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2927 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2928 | + : ''; |
|
| 2929 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2930 | + $template_path, |
|
| 2931 | + $this->_template_args, |
|
| 2932 | + true |
|
| 2933 | + ); |
|
| 2934 | + // the final template wrapper |
|
| 2935 | + $this->admin_page_wrapper($about); |
|
| 2936 | + } |
|
| 2937 | + |
|
| 2938 | + |
|
| 2939 | + |
|
| 2940 | + /** |
|
| 2941 | + * This is used to display caf preview pages. |
|
| 2942 | + * |
|
| 2943 | + * @since 4.3.2 |
|
| 2944 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2945 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2946 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2947 | + * @return void |
|
| 2948 | + * @throws DomainException |
|
| 2949 | + * @throws EE_Error |
|
| 2950 | + * @throws InvalidArgumentException |
|
| 2951 | + * @throws InvalidDataTypeException |
|
| 2952 | + * @throws InvalidInterfaceException |
|
| 2953 | + */ |
|
| 2954 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2955 | + { |
|
| 2956 | + //let's generate a default preview action button if there isn't one already present. |
|
| 2957 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2958 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2959 | + 'event_espresso' |
|
| 2960 | + ); |
|
| 2961 | + $buy_now_url = add_query_arg( |
|
| 2962 | + array( |
|
| 2963 | + 'ee_ver' => 'ee4', |
|
| 2964 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2965 | + 'utm_medium' => 'link', |
|
| 2966 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2967 | + 'utm_content' => 'buy_now_button', |
|
| 2968 | + ), |
|
| 2969 | + 'http://eventespresso.com/pricing/' |
|
| 2970 | + ); |
|
| 2971 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2972 | + ? $this->get_action_link_or_button( |
|
| 2973 | + '', |
|
| 2974 | + 'buy_now', |
|
| 2975 | + array(), |
|
| 2976 | + 'button-primary button-large', |
|
| 2977 | + $buy_now_url, |
|
| 2978 | + true |
|
| 2979 | + ) |
|
| 2980 | + : $this->_template_args['preview_action_button']; |
|
| 2981 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2982 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2983 | + $this->_template_args, |
|
| 2984 | + true |
|
| 2985 | + ); |
|
| 2986 | + $this->_display_admin_page($display_sidebar); |
|
| 2987 | + } |
|
| 2988 | + |
|
| 2989 | + |
|
| 2990 | + |
|
| 2991 | + /** |
|
| 2992 | + * display_admin_list_table_page_with_sidebar |
|
| 2993 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2994 | + * |
|
| 2995 | + * @return void |
|
| 2996 | + * @throws EE_Error |
|
| 2997 | + * @throws DomainException |
|
| 2998 | + */ |
|
| 2999 | + public function display_admin_list_table_page_with_sidebar() |
|
| 3000 | + { |
|
| 3001 | + $this->_display_admin_list_table_page(true); |
|
| 3002 | + } |
|
| 3003 | + |
|
| 3004 | + |
|
| 3005 | + |
|
| 3006 | + /** |
|
| 3007 | + * display_admin_list_table_page_with_no_sidebar |
|
| 3008 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 3009 | + * |
|
| 3010 | + * @return void |
|
| 3011 | + * @throws EE_Error |
|
| 3012 | + * @throws DomainException |
|
| 3013 | + */ |
|
| 3014 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 3015 | + { |
|
| 3016 | + $this->_display_admin_list_table_page(); |
|
| 3017 | + } |
|
| 3018 | + |
|
| 3019 | + |
|
| 3020 | + |
|
| 3021 | + /** |
|
| 3022 | + * generates html wrapper for an admin_list_table page |
|
| 3023 | + * |
|
| 3024 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3025 | + * @return void |
|
| 3026 | + * @throws DomainException |
|
| 3027 | + * @throws EE_Error |
|
| 3028 | + */ |
|
| 3029 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 3030 | + { |
|
| 3031 | + //setup search attributes |
|
| 3032 | + $this->_set_search_attributes(); |
|
| 3033 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3034 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3035 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 3036 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 3037 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 3038 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3039 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 3040 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3041 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3042 | + if (! empty($ajax_sorting_callback)) { |
|
| 3043 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3044 | + $ajax_sorting_callback . '_nonce', |
|
| 3045 | + $ajax_sorting_callback . '_nonce', |
|
| 3046 | + false, |
|
| 3047 | + false |
|
| 3048 | + ); |
|
| 3049 | + // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 3050 | + // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 3051 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3052 | + . $this->page_slug |
|
| 3053 | + . '" />'; |
|
| 3054 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3055 | + . $ajax_sorting_callback |
|
| 3056 | + . '" />'; |
|
| 3057 | + } else { |
|
| 3058 | + $sortable_list_table_form_fields = ''; |
|
| 3059 | + } |
|
| 3060 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3061 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3062 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 3063 | + : ''; |
|
| 3064 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3065 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3066 | + . $nonce_ref |
|
| 3067 | + . '" value="' |
|
| 3068 | + . wp_create_nonce($nonce_ref) |
|
| 3069 | + . '">'; |
|
| 3070 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3071 | + //display message about search results? |
|
| 3072 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3073 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3074 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3075 | + trim($this->_req_data['s'], '%') |
|
| 3076 | + ) . '</p>' |
|
| 3077 | + : ''; |
|
| 3078 | + // filter before_list_table template arg |
|
| 3079 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3080 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3081 | + $this->_template_args['before_list_table'], |
|
| 3082 | + $this->page_slug, |
|
| 3083 | + $this->_req_data, |
|
| 3084 | + $this->_req_action |
|
| 3085 | + ); |
|
| 3086 | + // convert to array and filter again |
|
| 3087 | + // arrays are easier to inject new items in a specific location, |
|
| 3088 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3089 | + $this->_template_args['before_list_table'] = implode( |
|
| 3090 | + " \n", |
|
| 3091 | + (array)apply_filters( |
|
| 3092 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3093 | + (array)$this->_template_args['before_list_table'], |
|
| 3094 | + $this->page_slug, |
|
| 3095 | + $this->_req_data, |
|
| 3096 | + $this->_req_action |
|
| 3097 | + ) |
|
| 3098 | + ); |
|
| 3099 | + // filter after_list_table template arg |
|
| 3100 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3101 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3102 | + $this->_template_args['after_list_table'], |
|
| 3103 | + $this->page_slug, |
|
| 3104 | + $this->_req_data, |
|
| 3105 | + $this->_req_action |
|
| 3106 | + ); |
|
| 3107 | + // convert to array and filter again |
|
| 3108 | + // arrays are easier to inject new items in a specific location, |
|
| 3109 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3110 | + $this->_template_args['after_list_table'] = implode( |
|
| 3111 | + " \n", |
|
| 3112 | + (array)apply_filters( |
|
| 3113 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3114 | + (array)$this->_template_args['after_list_table'], |
|
| 3115 | + $this->page_slug, |
|
| 3116 | + $this->_req_data, |
|
| 3117 | + $this->_req_action |
|
| 3118 | + ) |
|
| 3119 | + ); |
|
| 3120 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3121 | + $template_path, |
|
| 3122 | + $this->_template_args, |
|
| 3123 | + true |
|
| 3124 | + ); |
|
| 3125 | + // the final template wrapper |
|
| 3126 | + if ($sidebar) { |
|
| 3127 | + $this->display_admin_page_with_sidebar(); |
|
| 3128 | + } else { |
|
| 3129 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3130 | + } |
|
| 3131 | + } |
|
| 3132 | + |
|
| 3133 | + |
|
| 3134 | + |
|
| 3135 | + /** |
|
| 3136 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3137 | + * html string for the legend. |
|
| 3138 | + * $items are expected in an array in the following format: |
|
| 3139 | + * $legend_items = array( |
|
| 3140 | + * 'item_id' => array( |
|
| 3141 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3142 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3143 | + * ) |
|
| 3144 | + * ); |
|
| 3145 | + * |
|
| 3146 | + * @param array $items see above for format of array |
|
| 3147 | + * @return string html string of legend |
|
| 3148 | + * @throws DomainException |
|
| 3149 | + */ |
|
| 3150 | + protected function _display_legend($items) |
|
| 3151 | + { |
|
| 3152 | + $this->_template_args['items'] = apply_filters( |
|
| 3153 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3154 | + (array)$items, |
|
| 3155 | + $this |
|
| 3156 | + ); |
|
| 3157 | + return EEH_Template::display_template( |
|
| 3158 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3159 | + $this->_template_args, |
|
| 3160 | + true |
|
| 3161 | + ); |
|
| 3162 | + } |
|
| 3163 | + |
|
| 3164 | + |
|
| 3165 | + /** |
|
| 3166 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3167 | + * The returned json object is created from an array in the following format: |
|
| 3168 | + * array( |
|
| 3169 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3170 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3171 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3172 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3173 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3174 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3175 | + * that might be included in here) |
|
| 3176 | + * ) |
|
| 3177 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3178 | + * |
|
| 3179 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3180 | + * instead of displayed. |
|
| 3181 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3182 | + * @return void |
|
| 3183 | + * @throws EE_Error |
|
| 3184 | + */ |
|
| 3185 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3186 | + { |
|
| 3187 | + //make sure any EE_Error notices have been handled. |
|
| 3188 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3189 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3190 | + unset($this->_template_args['data']); |
|
| 3191 | + $json = array( |
|
| 3192 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3193 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3194 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3195 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3196 | + 'notices' => EE_Error::get_notices(), |
|
| 3197 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3198 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3199 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3200 | + 'isEEajax' => true |
|
| 3201 | + //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3202 | + ); |
|
| 3203 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3204 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3205 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3206 | + } |
|
| 3207 | + echo wp_json_encode($json); |
|
| 3208 | + exit(); |
|
| 3209 | + } |
|
| 3210 | + |
|
| 3211 | + |
|
| 3212 | + |
|
| 3213 | + /** |
|
| 3214 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3215 | + * |
|
| 3216 | + * @return void |
|
| 3217 | + * @throws EE_Error |
|
| 3218 | + */ |
|
| 3219 | + public function return_json() |
|
| 3220 | + { |
|
| 3221 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3222 | + $this->_return_json(); |
|
| 3223 | + } else { |
|
| 3224 | + throw new EE_Error( |
|
| 3225 | + sprintf( |
|
| 3226 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3227 | + __FUNCTION__ |
|
| 3228 | + ) |
|
| 3229 | + ); |
|
| 3230 | + } |
|
| 3231 | + } |
|
| 3232 | + |
|
| 3233 | + |
|
| 3234 | + |
|
| 3235 | + /** |
|
| 3236 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3237 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3238 | + * |
|
| 3239 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3240 | + */ |
|
| 3241 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3242 | + { |
|
| 3243 | + $this->_hook_obj = $hook_obj; |
|
| 3244 | + } |
|
| 3245 | + |
|
| 3246 | + |
|
| 3247 | + |
|
| 3248 | + /** |
|
| 3249 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3250 | + * |
|
| 3251 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3252 | + * @return void |
|
| 3253 | + * @throws DomainException |
|
| 3254 | + * @throws EE_Error |
|
| 3255 | + */ |
|
| 3256 | + public function admin_page_wrapper($about = false) |
|
| 3257 | + { |
|
| 3258 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3259 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3260 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3261 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3262 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3263 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3264 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3265 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3266 | + : '' |
|
| 3267 | + ); |
|
| 3268 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3269 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3270 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3271 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3272 | + : '' |
|
| 3273 | + ); |
|
| 3274 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3275 | + // load settings page wrapper template |
|
| 3276 | + $template_path = ! defined('DOING_AJAX') |
|
| 3277 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3278 | + : EE_ADMIN_TEMPLATE |
|
| 3279 | + . 'admin_wrapper_ajax.template.php'; |
|
| 3280 | + //about page? |
|
| 3281 | + $template_path = $about |
|
| 3282 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3283 | + : $template_path; |
|
| 3284 | + if (defined('DOING_AJAX')) { |
|
| 3285 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3286 | + $template_path, |
|
| 3287 | + $this->_template_args, |
|
| 3288 | + true |
|
| 3289 | + ); |
|
| 3290 | + $this->_return_json(); |
|
| 3291 | + } else { |
|
| 3292 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3293 | + } |
|
| 3294 | + } |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + |
|
| 3298 | + /** |
|
| 3299 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3300 | + * |
|
| 3301 | + * @return string html |
|
| 3302 | + * @throws EE_Error |
|
| 3303 | + */ |
|
| 3304 | + protected function _get_main_nav_tabs() |
|
| 3305 | + { |
|
| 3306 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3307 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3308 | + // (rather than setting in the page_routes array) |
|
| 3309 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3310 | + } |
|
| 3311 | + |
|
| 3312 | + |
|
| 3313 | + |
|
| 3314 | + /** |
|
| 3315 | + * sort nav tabs |
|
| 3316 | + * |
|
| 3317 | + * @param $a |
|
| 3318 | + * @param $b |
|
| 3319 | + * @return int |
|
| 3320 | + */ |
|
| 3321 | + private function _sort_nav_tabs($a, $b) |
|
| 3322 | + { |
|
| 3323 | + if ($a['order'] === $b['order']) { |
|
| 3324 | + return 0; |
|
| 3325 | + } |
|
| 3326 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3327 | + } |
|
| 3328 | + |
|
| 3329 | + |
|
| 3330 | + |
|
| 3331 | + /** |
|
| 3332 | + * generates HTML for the forms used on admin pages |
|
| 3333 | + * |
|
| 3334 | + * @param array $input_vars - array of input field details |
|
| 3335 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3336 | + * use) |
|
| 3337 | + * @param bool $id |
|
| 3338 | + * @return string |
|
| 3339 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3340 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3341 | + */ |
|
| 3342 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3343 | + { |
|
| 3344 | + $content = $generator === 'string' |
|
| 3345 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3346 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3347 | + return $content; |
|
| 3348 | + } |
|
| 3349 | + |
|
| 3350 | + |
|
| 3351 | + |
|
| 3352 | + /** |
|
| 3353 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3354 | + * |
|
| 3355 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3356 | + * Close" button. |
|
| 3357 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3358 | + * 'Save', [1] => 'save & close') |
|
| 3359 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3360 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3361 | + * default actions by submitting some other value. |
|
| 3362 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3363 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3364 | + * close (normal form handling). |
|
| 3365 | + */ |
|
| 3366 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3367 | + { |
|
| 3368 | + //make sure $text and $actions are in an array |
|
| 3369 | + $text = (array)$text; |
|
| 3370 | + $actions = (array)$actions; |
|
| 3371 | + $referrer_url = empty($referrer) |
|
| 3372 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3373 | + . $_SERVER['REQUEST_URI'] |
|
| 3374 | + . '" />' |
|
| 3375 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3376 | + . $referrer |
|
| 3377 | + . '" />'; |
|
| 3378 | + $button_text = ! empty($text) |
|
| 3379 | + ? $text |
|
| 3380 | + : array( |
|
| 3381 | + esc_html__('Save', 'event_espresso'), |
|
| 3382 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3383 | + ); |
|
| 3384 | + $default_names = array('save', 'save_and_close'); |
|
| 3385 | + //add in a hidden index for the current page (so save and close redirects properly) |
|
| 3386 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3387 | + foreach ($button_text as $key => $button) { |
|
| 3388 | + $ref = $default_names[$key]; |
|
| 3389 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3390 | + . $ref |
|
| 3391 | + . '" value="' |
|
| 3392 | + . $button |
|
| 3393 | + . '" name="' |
|
| 3394 | + . (! empty($actions) ? $actions[$key] : $ref) |
|
| 3395 | + . '" id="' |
|
| 3396 | + . $this->_current_view . '_' . $ref |
|
| 3397 | + . '" />'; |
|
| 3398 | + if (! $both) { |
|
| 3399 | + break; |
|
| 3400 | + } |
|
| 3401 | + } |
|
| 3402 | + } |
|
| 3403 | + |
|
| 3404 | + |
|
| 3405 | + |
|
| 3406 | + /** |
|
| 3407 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3408 | + * |
|
| 3409 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3410 | + * @since 4.6.0 |
|
| 3411 | + * @param string $route |
|
| 3412 | + * @param array $additional_hidden_fields |
|
| 3413 | + */ |
|
| 3414 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3415 | + { |
|
| 3416 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3417 | + } |
|
| 3418 | + |
|
| 3419 | + |
|
| 3420 | + |
|
| 3421 | + /** |
|
| 3422 | + * set form open and close tags on add/edit pages. |
|
| 3423 | + * |
|
| 3424 | + * @param string $route the route you want the form to direct to |
|
| 3425 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3426 | + * @return void |
|
| 3427 | + */ |
|
| 3428 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3429 | + { |
|
| 3430 | + if (empty($route)) { |
|
| 3431 | + $user_msg = esc_html__( |
|
| 3432 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3433 | + 'event_espresso' |
|
| 3434 | + ); |
|
| 3435 | + $dev_msg = $user_msg . "\n" . sprintf( |
|
| 3436 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3437 | + __FUNCTION__, |
|
| 3438 | + __CLASS__ |
|
| 3439 | + ); |
|
| 3440 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3441 | + } |
|
| 3442 | + // open form |
|
| 3443 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3444 | + . $this->_admin_base_url |
|
| 3445 | + . '" id="' |
|
| 3446 | + . $route |
|
| 3447 | + . '_event_form" >'; |
|
| 3448 | + // add nonce |
|
| 3449 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3450 | + // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 3451 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3452 | + // add REQUIRED form action |
|
| 3453 | + $hidden_fields = array( |
|
| 3454 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3455 | + ); |
|
| 3456 | + // merge arrays |
|
| 3457 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3458 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3459 | + : $hidden_fields; |
|
| 3460 | + // generate form fields |
|
| 3461 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3462 | + // add fields to form |
|
| 3463 | + foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 3464 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3465 | + } |
|
| 3466 | + // close form |
|
| 3467 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3468 | + } |
|
| 3469 | + |
|
| 3470 | + |
|
| 3471 | + |
|
| 3472 | + /** |
|
| 3473 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3474 | + * discovered it would be useful for external code to have access. |
|
| 3475 | + * |
|
| 3476 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3477 | + * @since 4.5.0 |
|
| 3478 | + * @param bool $success |
|
| 3479 | + * @param string $what |
|
| 3480 | + * @param string $action_desc |
|
| 3481 | + * @param array $query_args |
|
| 3482 | + * @param bool $override_overwrite |
|
| 3483 | + * @throws EE_Error |
|
| 3484 | + */ |
|
| 3485 | + public function redirect_after_action( |
|
| 3486 | + $success = false, |
|
| 3487 | + $what = 'item', |
|
| 3488 | + $action_desc = 'processed', |
|
| 3489 | + $query_args = array(), |
|
| 3490 | + $override_overwrite = false |
|
| 3491 | + ) { |
|
| 3492 | + $this->_redirect_after_action( |
|
| 3493 | + $success, |
|
| 3494 | + $what, |
|
| 3495 | + $action_desc, |
|
| 3496 | + $query_args, |
|
| 3497 | + $override_overwrite |
|
| 3498 | + ); |
|
| 3499 | + } |
|
| 3500 | + |
|
| 3501 | + |
|
| 3502 | + |
|
| 3503 | + /** |
|
| 3504 | + * _redirect_after_action |
|
| 3505 | + * |
|
| 3506 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3507 | + * @param string $what - what the action was performed on |
|
| 3508 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3509 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3510 | + * action is completed |
|
| 3511 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3512 | + * override this so that they show. |
|
| 3513 | + * @return void |
|
| 3514 | + * @throws EE_Error |
|
| 3515 | + */ |
|
| 3516 | + protected function _redirect_after_action( |
|
| 3517 | + $success = 0, |
|
| 3518 | + $what = 'item', |
|
| 3519 | + $action_desc = 'processed', |
|
| 3520 | + $query_args = array(), |
|
| 3521 | + $override_overwrite = false |
|
| 3522 | + ) { |
|
| 3523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3524 | + //class name for actions/filters. |
|
| 3525 | + $classname = get_class($this); |
|
| 3526 | + // set redirect url. |
|
| 3527 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3528 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3529 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3530 | + $notices = EE_Error::get_notices(false); |
|
| 3531 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3532 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3533 | + EE_Error::overwrite_success(); |
|
| 3534 | + } |
|
| 3535 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3536 | + // how many records affected ? more than one record ? or just one ? |
|
| 3537 | + if ($success > 1) { |
|
| 3538 | + // set plural msg |
|
| 3539 | + EE_Error::add_success( |
|
| 3540 | + sprintf( |
|
| 3541 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3542 | + $what, |
|
| 3543 | + $action_desc |
|
| 3544 | + ), |
|
| 3545 | + __FILE__, |
|
| 3546 | + __FUNCTION__, |
|
| 3547 | + __LINE__ |
|
| 3548 | + ); |
|
| 3549 | + } elseif ($success === 1) { |
|
| 3550 | + // set singular msg |
|
| 3551 | + EE_Error::add_success( |
|
| 3552 | + sprintf( |
|
| 3553 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3554 | + $what, |
|
| 3555 | + $action_desc |
|
| 3556 | + ), |
|
| 3557 | + __FILE__, |
|
| 3558 | + __FUNCTION__, |
|
| 3559 | + __LINE__ |
|
| 3560 | + ); |
|
| 3561 | + } |
|
| 3562 | + } |
|
| 3563 | + // check that $query_args isn't something crazy |
|
| 3564 | + if (! is_array($query_args)) { |
|
| 3565 | + $query_args = array(); |
|
| 3566 | + } |
|
| 3567 | + /** |
|
| 3568 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3569 | + * redirections on save and close actions |
|
| 3570 | + * |
|
| 3571 | + * @since 4.2.0 |
|
| 3572 | + * @param array $query_args The original query_args array coming into the |
|
| 3573 | + * method. |
|
| 3574 | + */ |
|
| 3575 | + do_action( |
|
| 3576 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3577 | + $query_args |
|
| 3578 | + ); |
|
| 3579 | + //calculate where we're going (if we have a "save and close" button pushed) |
|
| 3580 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3581 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3582 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3583 | + // regenerate query args array from referrer URL |
|
| 3584 | + parse_str($parsed_url['query'], $query_args); |
|
| 3585 | + // correct page and action will be in the query args now |
|
| 3586 | + $redirect_url = admin_url('admin.php'); |
|
| 3587 | + } |
|
| 3588 | + //merge any default query_args set in _default_route_query_args property |
|
| 3589 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | + $args_to_merge = array(); |
|
| 3591 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3592 | + //is there a wp_referer array in our _default_route_query_args property? |
|
| 3593 | + if ($query_param === 'wp_referer') { |
|
| 3594 | + $query_value = (array)$query_value; |
|
| 3595 | + foreach ($query_value as $reference => $value) { |
|
| 3596 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3597 | + continue; |
|
| 3598 | + } |
|
| 3599 | + //finally we will override any arguments in the referer with |
|
| 3600 | + //what might be set on the _default_route_query_args array. |
|
| 3601 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3602 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3603 | + } else { |
|
| 3604 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3605 | + } |
|
| 3606 | + } |
|
| 3607 | + continue; |
|
| 3608 | + } |
|
| 3609 | + $args_to_merge[$query_param] = $query_value; |
|
| 3610 | + } |
|
| 3611 | + //now let's merge these arguments but override with what was specifically sent in to the |
|
| 3612 | + //redirect. |
|
| 3613 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3614 | + } |
|
| 3615 | + $this->_process_notices($query_args); |
|
| 3616 | + // generate redirect url |
|
| 3617 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3618 | + if (isset($query_args['action'])) { |
|
| 3619 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3620 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3621 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3622 | + } |
|
| 3623 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3624 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3625 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3626 | + $redirect_url = apply_filters( |
|
| 3627 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3628 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3629 | + $query_args |
|
| 3630 | + ); |
|
| 3631 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3632 | + if (defined('DOING_AJAX')) { |
|
| 3633 | + $default_data = array( |
|
| 3634 | + 'close' => true, |
|
| 3635 | + 'redirect_url' => $redirect_url, |
|
| 3636 | + 'where' => 'main', |
|
| 3637 | + 'what' => 'append', |
|
| 3638 | + ); |
|
| 3639 | + $this->_template_args['success'] = $success; |
|
| 3640 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3641 | + $default_data, |
|
| 3642 | + $this->_template_args['data'] |
|
| 3643 | + ) : $default_data; |
|
| 3644 | + $this->_return_json(); |
|
| 3645 | + } |
|
| 3646 | + wp_safe_redirect($redirect_url); |
|
| 3647 | + exit(); |
|
| 3648 | + } |
|
| 3649 | + |
|
| 3650 | + |
|
| 3651 | + |
|
| 3652 | + /** |
|
| 3653 | + * process any notices before redirecting (or returning ajax request) |
|
| 3654 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3655 | + * |
|
| 3656 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3657 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3658 | + * page_routes haven't been defined yet. |
|
| 3659 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3660 | + * still save a transient for the notice. |
|
| 3661 | + * @return void |
|
| 3662 | + * @throws EE_Error |
|
| 3663 | + */ |
|
| 3664 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3665 | + { |
|
| 3666 | + //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3667 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3668 | + $notices = EE_Error::get_notices(false); |
|
| 3669 | + if (empty($this->_template_args['success'])) { |
|
| 3670 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3671 | + } |
|
| 3672 | + if (empty($this->_template_args['errors'])) { |
|
| 3673 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3674 | + } |
|
| 3675 | + if (empty($this->_template_args['attention'])) { |
|
| 3676 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3677 | + } |
|
| 3678 | + } |
|
| 3679 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3680 | + //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3681 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3682 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3683 | + $this->_add_transient( |
|
| 3684 | + $route, |
|
| 3685 | + $this->_template_args['notices'], |
|
| 3686 | + true, |
|
| 3687 | + $skip_route_verify |
|
| 3688 | + ); |
|
| 3689 | + } |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + |
|
| 3693 | + |
|
| 3694 | + /** |
|
| 3695 | + * get_action_link_or_button |
|
| 3696 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3697 | + * |
|
| 3698 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3699 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3700 | + * property. |
|
| 3701 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3702 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3703 | + * @param string $base_url If this is not provided |
|
| 3704 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3705 | + * Otherwise this value will be used. |
|
| 3706 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3707 | + * @return string |
|
| 3708 | + * @throws InvalidArgumentException |
|
| 3709 | + * @throws InvalidInterfaceException |
|
| 3710 | + * @throws InvalidDataTypeException |
|
| 3711 | + * @throws EE_Error |
|
| 3712 | + */ |
|
| 3713 | + public function get_action_link_or_button( |
|
| 3714 | + $action, |
|
| 3715 | + $type = 'add', |
|
| 3716 | + $extra_request = array(), |
|
| 3717 | + $class = 'button-primary', |
|
| 3718 | + $base_url = '', |
|
| 3719 | + $exclude_nonce = false |
|
| 3720 | + ) { |
|
| 3721 | + //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3722 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3723 | + throw new EE_Error( |
|
| 3724 | + sprintf( |
|
| 3725 | + esc_html__( |
|
| 3726 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3727 | + 'event_espresso' |
|
| 3728 | + ), |
|
| 3729 | + $action |
|
| 3730 | + ) |
|
| 3731 | + ); |
|
| 3732 | + } |
|
| 3733 | + if (! isset($this->_labels['buttons'][$type])) { |
|
| 3734 | + throw new EE_Error( |
|
| 3735 | + sprintf( |
|
| 3736 | + __( |
|
| 3737 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3738 | + 'event_espresso' |
|
| 3739 | + ), |
|
| 3740 | + $type |
|
| 3741 | + ) |
|
| 3742 | + ); |
|
| 3743 | + } |
|
| 3744 | + //finally check user access for this button. |
|
| 3745 | + $has_access = $this->check_user_access($action, true); |
|
| 3746 | + if (! $has_access) { |
|
| 3747 | + return ''; |
|
| 3748 | + } |
|
| 3749 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3750 | + $query_args = array( |
|
| 3751 | + 'action' => $action, |
|
| 3752 | + ); |
|
| 3753 | + //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3754 | + if (! empty($extra_request)) { |
|
| 3755 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3756 | + } |
|
| 3757 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3758 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3759 | + } |
|
| 3760 | + |
|
| 3761 | + |
|
| 3762 | + |
|
| 3763 | + /** |
|
| 3764 | + * _per_page_screen_option |
|
| 3765 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3766 | + * |
|
| 3767 | + * @return void |
|
| 3768 | + * @throws InvalidArgumentException |
|
| 3769 | + * @throws InvalidInterfaceException |
|
| 3770 | + * @throws InvalidDataTypeException |
|
| 3771 | + */ |
|
| 3772 | + protected function _per_page_screen_option() |
|
| 3773 | + { |
|
| 3774 | + $option = 'per_page'; |
|
| 3775 | + $args = array( |
|
| 3776 | + 'label' => esc_html__( |
|
| 3777 | + apply_filters( |
|
| 3778 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3779 | + $this->_admin_page_title, |
|
| 3780 | + $this |
|
| 3781 | + ) |
|
| 3782 | + ), |
|
| 3783 | + 'default' => (int) apply_filters( |
|
| 3784 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3785 | + 10 |
|
| 3786 | + ), |
|
| 3787 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3788 | + ); |
|
| 3789 | + //ONLY add the screen option if the user has access to it. |
|
| 3790 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3791 | + add_screen_option($option, $args); |
|
| 3792 | + } |
|
| 3793 | + } |
|
| 3794 | + |
|
| 3795 | + |
|
| 3796 | + |
|
| 3797 | + /** |
|
| 3798 | + * set_per_page_screen_option |
|
| 3799 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3800 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3801 | + * admin_menu. |
|
| 3802 | + * |
|
| 3803 | + * @return void |
|
| 3804 | + */ |
|
| 3805 | + private function _set_per_page_screen_options() |
|
| 3806 | + { |
|
| 3807 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3808 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3809 | + if (! $user = wp_get_current_user()) { |
|
| 3810 | + return; |
|
| 3811 | + } |
|
| 3812 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3813 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3814 | + if ($option != sanitize_key($option)) { |
|
| 3815 | + return; |
|
| 3816 | + } |
|
| 3817 | + $map_option = $option; |
|
| 3818 | + $option = str_replace('-', '_', $option); |
|
| 3819 | + switch ($map_option) { |
|
| 3820 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3821 | + $value = (int)$value; |
|
| 3822 | + $max_value = apply_filters( |
|
| 3823 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3824 | + 999, |
|
| 3825 | + $this->_current_page, |
|
| 3826 | + $this->_current_view |
|
| 3827 | + ); |
|
| 3828 | + if ($value < 1 || $value > $max_value) { |
|
| 3829 | + return; |
|
| 3830 | + } |
|
| 3831 | + break; |
|
| 3832 | + default: |
|
| 3833 | + $value = apply_filters( |
|
| 3834 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3835 | + false, |
|
| 3836 | + $option, |
|
| 3837 | + $value |
|
| 3838 | + ); |
|
| 3839 | + if (false === $value) { |
|
| 3840 | + return; |
|
| 3841 | + } |
|
| 3842 | + break; |
|
| 3843 | + } |
|
| 3844 | + update_user_meta($user->ID, $option, $value); |
|
| 3845 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3846 | + exit; |
|
| 3847 | + } |
|
| 3848 | + } |
|
| 3849 | + |
|
| 3850 | + |
|
| 3851 | + |
|
| 3852 | + /** |
|
| 3853 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3854 | + * |
|
| 3855 | + * @param array $data array that will be assigned to template args. |
|
| 3856 | + */ |
|
| 3857 | + public function set_template_args($data) |
|
| 3858 | + { |
|
| 3859 | + $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3860 | + } |
|
| 3861 | + |
|
| 3862 | + |
|
| 3863 | + |
|
| 3864 | + /** |
|
| 3865 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3866 | + * |
|
| 3867 | + * @param string $route the route that should receive the transient |
|
| 3868 | + * @param array $data the data that gets sent |
|
| 3869 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3870 | + * normal route transient. |
|
| 3871 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3872 | + * when we are adding a transient before page_routes have been defined. |
|
| 3873 | + * @return void |
|
| 3874 | + * @throws EE_Error |
|
| 3875 | + */ |
|
| 3876 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3877 | + { |
|
| 3878 | + $user_id = get_current_user_id(); |
|
| 3879 | + if (! $skip_route_verify) { |
|
| 3880 | + $this->_verify_route($route); |
|
| 3881 | + } |
|
| 3882 | + //now let's set the string for what kind of transient we're setting |
|
| 3883 | + $transient = $notices |
|
| 3884 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3885 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3886 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3887 | + //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3888 | + $existing = is_multisite() && is_network_admin() |
|
| 3889 | + ? get_site_transient($transient) |
|
| 3890 | + : get_transient($transient); |
|
| 3891 | + if ($existing) { |
|
| 3892 | + $data = array_merge((array)$data, (array)$existing); |
|
| 3893 | + } |
|
| 3894 | + if (is_multisite() && is_network_admin()) { |
|
| 3895 | + set_site_transient($transient, $data, 8); |
|
| 3896 | + } else { |
|
| 3897 | + set_transient($transient, $data, 8); |
|
| 3898 | + } |
|
| 3899 | + } |
|
| 3900 | + |
|
| 3901 | + |
|
| 3902 | + |
|
| 3903 | + /** |
|
| 3904 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3905 | + * |
|
| 3906 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3907 | + * @param string $route |
|
| 3908 | + * @return mixed data |
|
| 3909 | + */ |
|
| 3910 | + protected function _get_transient($notices = false, $route = '') |
|
| 3911 | + { |
|
| 3912 | + $user_id = get_current_user_id(); |
|
| 3913 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3914 | + $transient = $notices |
|
| 3915 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3916 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3917 | + $data = is_multisite() && is_network_admin() |
|
| 3918 | + ? get_site_transient($transient) |
|
| 3919 | + : get_transient($transient); |
|
| 3920 | + //delete transient after retrieval (just in case it hasn't expired); |
|
| 3921 | + if (is_multisite() && is_network_admin()) { |
|
| 3922 | + delete_site_transient($transient); |
|
| 3923 | + } else { |
|
| 3924 | + delete_transient($transient); |
|
| 3925 | + } |
|
| 3926 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3927 | + } |
|
| 3928 | + |
|
| 3929 | + |
|
| 3930 | + |
|
| 3931 | + /** |
|
| 3932 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3933 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3934 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3935 | + * |
|
| 3936 | + * @return void |
|
| 3937 | + */ |
|
| 3938 | + protected function _transient_garbage_collection() |
|
| 3939 | + { |
|
| 3940 | + global $wpdb; |
|
| 3941 | + //retrieve all existing transients |
|
| 3942 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3943 | + if ($results = $wpdb->get_results($query)) { |
|
| 3944 | + foreach ($results as $result) { |
|
| 3945 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3946 | + get_transient($transient); |
|
| 3947 | + if (is_multisite() && is_network_admin()) { |
|
| 3948 | + get_site_transient($transient); |
|
| 3949 | + } |
|
| 3950 | + } |
|
| 3951 | + } |
|
| 3952 | + } |
|
| 3953 | + |
|
| 3954 | + |
|
| 3955 | + |
|
| 3956 | + /** |
|
| 3957 | + * get_view |
|
| 3958 | + * |
|
| 3959 | + * @return string content of _view property |
|
| 3960 | + */ |
|
| 3961 | + public function get_view() |
|
| 3962 | + { |
|
| 3963 | + return $this->_view; |
|
| 3964 | + } |
|
| 3965 | + |
|
| 3966 | + |
|
| 3967 | + |
|
| 3968 | + /** |
|
| 3969 | + * getter for the protected $_views property |
|
| 3970 | + * |
|
| 3971 | + * @return array |
|
| 3972 | + */ |
|
| 3973 | + public function get_views() |
|
| 3974 | + { |
|
| 3975 | + return $this->_views; |
|
| 3976 | + } |
|
| 3977 | + |
|
| 3978 | + |
|
| 3979 | + |
|
| 3980 | + /** |
|
| 3981 | + * get_current_page |
|
| 3982 | + * |
|
| 3983 | + * @return string _current_page property value |
|
| 3984 | + */ |
|
| 3985 | + public function get_current_page() |
|
| 3986 | + { |
|
| 3987 | + return $this->_current_page; |
|
| 3988 | + } |
|
| 3989 | + |
|
| 3990 | + |
|
| 3991 | + |
|
| 3992 | + /** |
|
| 3993 | + * get_current_view |
|
| 3994 | + * |
|
| 3995 | + * @return string _current_view property value |
|
| 3996 | + */ |
|
| 3997 | + public function get_current_view() |
|
| 3998 | + { |
|
| 3999 | + return $this->_current_view; |
|
| 4000 | + } |
|
| 4001 | + |
|
| 4002 | + |
|
| 4003 | + |
|
| 4004 | + /** |
|
| 4005 | + * get_current_screen |
|
| 4006 | + * |
|
| 4007 | + * @return object The current WP_Screen object |
|
| 4008 | + */ |
|
| 4009 | + public function get_current_screen() |
|
| 4010 | + { |
|
| 4011 | + return $this->_current_screen; |
|
| 4012 | + } |
|
| 4013 | + |
|
| 4014 | + |
|
| 4015 | + |
|
| 4016 | + /** |
|
| 4017 | + * get_current_page_view_url |
|
| 4018 | + * |
|
| 4019 | + * @return string This returns the url for the current_page_view. |
|
| 4020 | + */ |
|
| 4021 | + public function get_current_page_view_url() |
|
| 4022 | + { |
|
| 4023 | + return $this->_current_page_view_url; |
|
| 4024 | + } |
|
| 4025 | + |
|
| 4026 | + |
|
| 4027 | + |
|
| 4028 | + /** |
|
| 4029 | + * just returns the _req_data property |
|
| 4030 | + * |
|
| 4031 | + * @return array |
|
| 4032 | + */ |
|
| 4033 | + public function get_request_data() |
|
| 4034 | + { |
|
| 4035 | + return $this->_req_data; |
|
| 4036 | + } |
|
| 4037 | + |
|
| 4038 | + |
|
| 4039 | + |
|
| 4040 | + /** |
|
| 4041 | + * returns the _req_data protected property |
|
| 4042 | + * |
|
| 4043 | + * @return string |
|
| 4044 | + */ |
|
| 4045 | + public function get_req_action() |
|
| 4046 | + { |
|
| 4047 | + return $this->_req_action; |
|
| 4048 | + } |
|
| 4049 | + |
|
| 4050 | + |
|
| 4051 | + |
|
| 4052 | + /** |
|
| 4053 | + * @return bool value of $_is_caf property |
|
| 4054 | + */ |
|
| 4055 | + public function is_caf() |
|
| 4056 | + { |
|
| 4057 | + return $this->_is_caf; |
|
| 4058 | + } |
|
| 4059 | + |
|
| 4060 | + |
|
| 4061 | + |
|
| 4062 | + /** |
|
| 4063 | + * @return mixed |
|
| 4064 | + */ |
|
| 4065 | + public function default_espresso_metaboxes() |
|
| 4066 | + { |
|
| 4067 | + return $this->_default_espresso_metaboxes; |
|
| 4068 | + } |
|
| 4069 | + |
|
| 4070 | + |
|
| 4071 | + |
|
| 4072 | + /** |
|
| 4073 | + * @return mixed |
|
| 4074 | + */ |
|
| 4075 | + public function admin_base_url() |
|
| 4076 | + { |
|
| 4077 | + return $this->_admin_base_url; |
|
| 4078 | + } |
|
| 4079 | 4079 | |
| 4080 | 4080 | |
| 4081 | 4081 | |
| 4082 | - /** |
|
| 4083 | - * @return mixed |
|
| 4084 | - */ |
|
| 4085 | - public function wp_page_slug() |
|
| 4086 | - { |
|
| 4087 | - return $this->_wp_page_slug; |
|
| 4088 | - } |
|
| 4082 | + /** |
|
| 4083 | + * @return mixed |
|
| 4084 | + */ |
|
| 4085 | + public function wp_page_slug() |
|
| 4086 | + { |
|
| 4087 | + return $this->_wp_page_slug; |
|
| 4088 | + } |
|
| 4089 | 4089 | |
| 4090 | 4090 | |
| 4091 | - |
|
| 4092 | - /** |
|
| 4093 | - * updates espresso configuration settings |
|
| 4094 | - * |
|
| 4095 | - * @param string $tab |
|
| 4096 | - * @param EE_Config_Base|EE_Config $config |
|
| 4097 | - * @param string $file file where error occurred |
|
| 4098 | - * @param string $func function where error occurred |
|
| 4099 | - * @param string $line line no where error occurred |
|
| 4100 | - * @return boolean |
|
| 4101 | - */ |
|
| 4102 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4103 | - { |
|
| 4104 | - //remove any options that are NOT going to be saved with the config settings. |
|
| 4105 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4106 | - $config->core->ee_ueip_has_notified = true; |
|
| 4107 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4108 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4109 | - update_option('ee_ueip_has_notified', true); |
|
| 4110 | - } |
|
| 4111 | - // and save it (note we're also doing the network save here) |
|
| 4112 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4113 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4114 | - if ($config_saved && $net_saved) { |
|
| 4115 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4116 | - return true; |
|
| 4117 | - } |
|
| 4118 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4119 | - return false; |
|
| 4120 | - } |
|
| 4121 | - |
|
| 4122 | - |
|
| 4123 | - |
|
| 4124 | - /** |
|
| 4125 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4126 | - * |
|
| 4127 | - * @return array |
|
| 4128 | - */ |
|
| 4129 | - public function get_yes_no_values() |
|
| 4130 | - { |
|
| 4131 | - return $this->_yes_no_values; |
|
| 4132 | - } |
|
| 4133 | - |
|
| 4134 | - |
|
| 4135 | - |
|
| 4136 | - protected function _get_dir() |
|
| 4137 | - { |
|
| 4138 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4139 | - return dirname($reflector->getFileName()); |
|
| 4140 | - } |
|
| 4141 | - |
|
| 4142 | - |
|
| 4143 | - |
|
| 4144 | - /** |
|
| 4145 | - * A helper for getting a "next link". |
|
| 4146 | - * |
|
| 4147 | - * @param string $url The url to link to |
|
| 4148 | - * @param string $class The class to use. |
|
| 4149 | - * @return string |
|
| 4150 | - */ |
|
| 4151 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4152 | - { |
|
| 4153 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4154 | - } |
|
| 4155 | - |
|
| 4156 | - |
|
| 4157 | - |
|
| 4158 | - /** |
|
| 4159 | - * A helper for getting a "previous link". |
|
| 4160 | - * |
|
| 4161 | - * @param string $url The url to link to |
|
| 4162 | - * @param string $class The class to use. |
|
| 4163 | - * @return string |
|
| 4164 | - */ |
|
| 4165 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4166 | - { |
|
| 4167 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4168 | - } |
|
| 4169 | - |
|
| 4170 | - |
|
| 4171 | - |
|
| 4172 | - |
|
| 4173 | - |
|
| 4174 | - |
|
| 4175 | - |
|
| 4176 | - //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4177 | - |
|
| 4178 | - |
|
| 4179 | - /** |
|
| 4180 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4181 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4182 | - * _req_data array. |
|
| 4183 | - * |
|
| 4184 | - * @return bool success/fail |
|
| 4185 | - * @throws EE_Error |
|
| 4186 | - * @throws InvalidArgumentException |
|
| 4187 | - * @throws ReflectionException |
|
| 4188 | - * @throws InvalidDataTypeException |
|
| 4189 | - * @throws InvalidInterfaceException |
|
| 4190 | - */ |
|
| 4191 | - protected function _process_resend_registration() |
|
| 4192 | - { |
|
| 4193 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4194 | - do_action( |
|
| 4195 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4196 | - $this->_template_args['success'], |
|
| 4197 | - $this->_req_data |
|
| 4198 | - ); |
|
| 4199 | - return $this->_template_args['success']; |
|
| 4200 | - } |
|
| 4201 | - |
|
| 4202 | - |
|
| 4203 | - |
|
| 4204 | - /** |
|
| 4205 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4206 | - * |
|
| 4207 | - * @param \EE_Payment $payment |
|
| 4208 | - * @return bool success/fail |
|
| 4209 | - */ |
|
| 4210 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4211 | - { |
|
| 4212 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4213 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4214 | - $this->_template_args['success'] = apply_filters( |
|
| 4215 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4216 | - false, |
|
| 4217 | - $payment |
|
| 4218 | - ); |
|
| 4219 | - return $this->_template_args['success']; |
|
| 4220 | - } |
|
| 4091 | + |
|
| 4092 | + /** |
|
| 4093 | + * updates espresso configuration settings |
|
| 4094 | + * |
|
| 4095 | + * @param string $tab |
|
| 4096 | + * @param EE_Config_Base|EE_Config $config |
|
| 4097 | + * @param string $file file where error occurred |
|
| 4098 | + * @param string $func function where error occurred |
|
| 4099 | + * @param string $line line no where error occurred |
|
| 4100 | + * @return boolean |
|
| 4101 | + */ |
|
| 4102 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4103 | + { |
|
| 4104 | + //remove any options that are NOT going to be saved with the config settings. |
|
| 4105 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4106 | + $config->core->ee_ueip_has_notified = true; |
|
| 4107 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4108 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4109 | + update_option('ee_ueip_has_notified', true); |
|
| 4110 | + } |
|
| 4111 | + // and save it (note we're also doing the network save here) |
|
| 4112 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4113 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4114 | + if ($config_saved && $net_saved) { |
|
| 4115 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4116 | + return true; |
|
| 4117 | + } |
|
| 4118 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4119 | + return false; |
|
| 4120 | + } |
|
| 4121 | + |
|
| 4122 | + |
|
| 4123 | + |
|
| 4124 | + /** |
|
| 4125 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4126 | + * |
|
| 4127 | + * @return array |
|
| 4128 | + */ |
|
| 4129 | + public function get_yes_no_values() |
|
| 4130 | + { |
|
| 4131 | + return $this->_yes_no_values; |
|
| 4132 | + } |
|
| 4133 | + |
|
| 4134 | + |
|
| 4135 | + |
|
| 4136 | + protected function _get_dir() |
|
| 4137 | + { |
|
| 4138 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4139 | + return dirname($reflector->getFileName()); |
|
| 4140 | + } |
|
| 4141 | + |
|
| 4142 | + |
|
| 4143 | + |
|
| 4144 | + /** |
|
| 4145 | + * A helper for getting a "next link". |
|
| 4146 | + * |
|
| 4147 | + * @param string $url The url to link to |
|
| 4148 | + * @param string $class The class to use. |
|
| 4149 | + * @return string |
|
| 4150 | + */ |
|
| 4151 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4152 | + { |
|
| 4153 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4154 | + } |
|
| 4155 | + |
|
| 4156 | + |
|
| 4157 | + |
|
| 4158 | + /** |
|
| 4159 | + * A helper for getting a "previous link". |
|
| 4160 | + * |
|
| 4161 | + * @param string $url The url to link to |
|
| 4162 | + * @param string $class The class to use. |
|
| 4163 | + * @return string |
|
| 4164 | + */ |
|
| 4165 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4166 | + { |
|
| 4167 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4168 | + } |
|
| 4169 | + |
|
| 4170 | + |
|
| 4171 | + |
|
| 4172 | + |
|
| 4173 | + |
|
| 4174 | + |
|
| 4175 | + |
|
| 4176 | + //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4177 | + |
|
| 4178 | + |
|
| 4179 | + /** |
|
| 4180 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4181 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4182 | + * _req_data array. |
|
| 4183 | + * |
|
| 4184 | + * @return bool success/fail |
|
| 4185 | + * @throws EE_Error |
|
| 4186 | + * @throws InvalidArgumentException |
|
| 4187 | + * @throws ReflectionException |
|
| 4188 | + * @throws InvalidDataTypeException |
|
| 4189 | + * @throws InvalidInterfaceException |
|
| 4190 | + */ |
|
| 4191 | + protected function _process_resend_registration() |
|
| 4192 | + { |
|
| 4193 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4194 | + do_action( |
|
| 4195 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4196 | + $this->_template_args['success'], |
|
| 4197 | + $this->_req_data |
|
| 4198 | + ); |
|
| 4199 | + return $this->_template_args['success']; |
|
| 4200 | + } |
|
| 4201 | + |
|
| 4202 | + |
|
| 4203 | + |
|
| 4204 | + /** |
|
| 4205 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4206 | + * |
|
| 4207 | + * @param \EE_Payment $payment |
|
| 4208 | + * @return bool success/fail |
|
| 4209 | + */ |
|
| 4210 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4211 | + { |
|
| 4212 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4213 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4214 | + $this->_template_args['success'] = apply_filters( |
|
| 4215 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4216 | + false, |
|
| 4217 | + $payment |
|
| 4218 | + ); |
|
| 4219 | + return $this->_template_args['success']; |
|
| 4220 | + } |
|
| 4221 | 4221 | |
| 4222 | 4222 | |
| 4223 | 4223 | } |
@@ -18,77 +18,77 @@ |
||
| 18 | 18 | class Extend_Support_Admin_Page extends Support_Admin_Page |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - public function __construct($routing = true) |
|
| 22 | - { |
|
| 23 | - parent::__construct($routing); |
|
| 24 | - define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'support/templates/'); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - protected function _extend_page_config() |
|
| 30 | - { |
|
| 31 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'support'; |
|
| 32 | - //new routes and new configs (or overrides ) |
|
| 33 | - $new_page_routes = array( |
|
| 34 | - 'faq' => array( |
|
| 35 | - 'func' => '_faq', |
|
| 36 | - 'capability' => 'ee_read_ee', |
|
| 37 | - ), |
|
| 38 | - ); |
|
| 39 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 40 | - $new_page_config = array( |
|
| 41 | - 'faq' => array( |
|
| 42 | - 'nav' => array( |
|
| 43 | - 'label' => esc_html__('FAQ', 'event_espresso'), |
|
| 44 | - 'order' => 40, |
|
| 45 | - ), |
|
| 46 | - 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
| 47 | - 'require_nonce' => false, |
|
| 48 | - ), |
|
| 49 | - ); |
|
| 50 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 51 | - $this->_page_config['default']['metaboxes'][] = '_installation_boxes'; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - protected function _faq() |
|
| 57 | - { |
|
| 58 | - $template_path = EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH . 'support_admin_details_faq.template.php'; |
|
| 59 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 60 | - $template_path, |
|
| 61 | - '', |
|
| 62 | - true |
|
| 63 | - ); |
|
| 64 | - $this->display_admin_page_with_sidebar(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - protected function _installation_boxes() |
|
| 70 | - { |
|
| 71 | - $callback_args = array( |
|
| 72 | - 'template_path' => EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH |
|
| 73 | - . 'support_admin_details_additional_information.template.php', |
|
| 74 | - ); |
|
| 75 | - add_meta_box( |
|
| 76 | - 'espresso_additional_information_support', |
|
| 77 | - esc_html__('Additional Information', 'event_espresso'), |
|
| 78 | - function ($post, $metabox) |
|
| 79 | - { |
|
| 80 | - echo EEH_Template::display_template( |
|
| 81 | - $metabox['args']['template_path'], |
|
| 82 | - '', |
|
| 83 | - true |
|
| 84 | - ); |
|
| 85 | - }, |
|
| 86 | - $this->_current_screen->id, |
|
| 87 | - 'normal', |
|
| 88 | - 'high', |
|
| 89 | - $callback_args |
|
| 90 | - ); |
|
| 91 | - } |
|
| 21 | + public function __construct($routing = true) |
|
| 22 | + { |
|
| 23 | + parent::__construct($routing); |
|
| 24 | + define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'support/templates/'); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + protected function _extend_page_config() |
|
| 30 | + { |
|
| 31 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'support'; |
|
| 32 | + //new routes and new configs (or overrides ) |
|
| 33 | + $new_page_routes = array( |
|
| 34 | + 'faq' => array( |
|
| 35 | + 'func' => '_faq', |
|
| 36 | + 'capability' => 'ee_read_ee', |
|
| 37 | + ), |
|
| 38 | + ); |
|
| 39 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 40 | + $new_page_config = array( |
|
| 41 | + 'faq' => array( |
|
| 42 | + 'nav' => array( |
|
| 43 | + 'label' => esc_html__('FAQ', 'event_espresso'), |
|
| 44 | + 'order' => 40, |
|
| 45 | + ), |
|
| 46 | + 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
| 47 | + 'require_nonce' => false, |
|
| 48 | + ), |
|
| 49 | + ); |
|
| 50 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 51 | + $this->_page_config['default']['metaboxes'][] = '_installation_boxes'; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + protected function _faq() |
|
| 57 | + { |
|
| 58 | + $template_path = EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH . 'support_admin_details_faq.template.php'; |
|
| 59 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 60 | + $template_path, |
|
| 61 | + '', |
|
| 62 | + true |
|
| 63 | + ); |
|
| 64 | + $this->display_admin_page_with_sidebar(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + protected function _installation_boxes() |
|
| 70 | + { |
|
| 71 | + $callback_args = array( |
|
| 72 | + 'template_path' => EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH |
|
| 73 | + . 'support_admin_details_additional_information.template.php', |
|
| 74 | + ); |
|
| 75 | + add_meta_box( |
|
| 76 | + 'espresso_additional_information_support', |
|
| 77 | + esc_html__('Additional Information', 'event_espresso'), |
|
| 78 | + function ($post, $metabox) |
|
| 79 | + { |
|
| 80 | + echo EEH_Template::display_template( |
|
| 81 | + $metabox['args']['template_path'], |
|
| 82 | + '', |
|
| 83 | + true |
|
| 84 | + ); |
|
| 85 | + }, |
|
| 86 | + $this->_current_screen->id, |
|
| 87 | + 'normal', |
|
| 88 | + 'high', |
|
| 89 | + $callback_args |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -defined('EVENT_ESPRESSO_VERSION')|| exit('NO direct script access allowed'); |
|
| 4 | +defined('EVENT_ESPRESSO_VERSION') || exit('NO direct script access allowed'); |
|
| 5 | 5 | |
| 6 | 6 | |
| 7 | 7 | |
@@ -21,16 +21,16 @@ discard block |
||
| 21 | 21 | public function __construct($routing = true) |
| 22 | 22 | { |
| 23 | 23 | parent::__construct($routing); |
| 24 | - define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'support/templates/'); |
|
| 24 | + define('EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'support/templates/'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | protected function _extend_page_config() |
| 30 | 30 | { |
| 31 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'support'; |
|
| 31 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'support'; |
|
| 32 | 32 | //new routes and new configs (or overrides ) |
| 33 | - $new_page_routes = array( |
|
| 33 | + $new_page_routes = array( |
|
| 34 | 34 | 'faq' => array( |
| 35 | 35 | 'func' => '_faq', |
| 36 | 36 | 'capability' => 'ee_read_ee', |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | protected function _faq() |
| 57 | 57 | { |
| 58 | - $template_path = EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH . 'support_admin_details_faq.template.php'; |
|
| 58 | + $template_path = EE_SUPPORT_CAF_ADMIN_TEMPLATE_PATH.'support_admin_details_faq.template.php'; |
|
| 59 | 59 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 60 | 60 | $template_path, |
| 61 | 61 | '', |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | add_meta_box( |
| 76 | 76 | 'espresso_additional_information_support', |
| 77 | 77 | esc_html__('Additional Information', 'event_espresso'), |
| 78 | - function ($post, $metabox) |
|
| 78 | + function($post, $metabox) |
|
| 79 | 79 | { |
| 80 | 80 | echo EEH_Template::display_template( |
| 81 | 81 | $metabox['args']['template_path'], |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -17,629 +17,629 @@ discard block |
||
| 17 | 17 | class EEH_Debug_Tools |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * instance of the EEH_Autoloader object |
|
| 22 | - * |
|
| 23 | - * @var $_instance |
|
| 24 | - * @access private |
|
| 25 | - */ |
|
| 26 | - private static $_instance; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $_memory_usage_points = array(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @singleton method used to instantiate class object |
|
| 37 | - * @access public |
|
| 38 | - * @return EEH_Debug_Tools |
|
| 39 | - */ |
|
| 40 | - public static function instance() |
|
| 41 | - { |
|
| 42 | - // check if class object is instantiated, and instantiated properly |
|
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | - self::$_instance = new self(); |
|
| 45 | - } |
|
| 46 | - return self::$_instance; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * private class constructor |
|
| 53 | - */ |
|
| 54 | - private function __construct() |
|
| 55 | - { |
|
| 56 | - // load Kint PHP debugging library |
|
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | - } |
|
| 65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | - // } |
|
| 68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * show_db_name |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public static function show_db_name() |
|
| 82 | - { |
|
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | - . DB_NAME |
|
| 86 | - . '</p>'; |
|
| 87 | - } |
|
| 88 | - if (EE_DEBUG) { |
|
| 89 | - Benchmark::displayResults(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function espresso_session_footer_dump() |
|
| 101 | - { |
|
| 102 | - if ( |
|
| 103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | - && ! defined('DOING_AJAX') |
|
| 105 | - && class_exists('Kint') |
|
| 106 | - && function_exists('wp_get_current_user') |
|
| 107 | - && current_user_can('update_core') |
|
| 108 | - && class_exists('EE_Registry') |
|
| 109 | - ) { |
|
| 110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | - $this->espresso_list_hooked_functions(); |
|
| 114 | - Benchmark::displayResults(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * List All Hooked Functions |
|
| 122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | - * |
|
| 125 | - * @param string $tag |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function espresso_list_hooked_functions($tag = '') |
|
| 129 | - { |
|
| 130 | - global $wp_filter; |
|
| 131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | - if ($tag) { |
|
| 133 | - $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | - if (! is_array($hook[$tag])) { |
|
| 135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | - } else { |
|
| 140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | - ksort($hook); |
|
| 142 | - } |
|
| 143 | - foreach ($hook as $tag_name => $priorities) { |
|
| 144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | - ksort($priorities); |
|
| 146 | - foreach ($priorities as $priority => $function) { |
|
| 147 | - echo $priority; |
|
| 148 | - foreach ($function as $name => $properties) { |
|
| 149 | - echo "\t$name<br />"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * registered_filter_callbacks |
|
| 159 | - * |
|
| 160 | - * @param string $hook_name |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | - { |
|
| 165 | - $filters = array(); |
|
| 166 | - global $wp_filter; |
|
| 167 | - if (isset($wp_filter[$hook_name])) { |
|
| 168 | - $filters[$hook_name] = array(); |
|
| 169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | - $filters[$hook_name][$priority] = array(); |
|
| 171 | - foreach ($callbacks as $callback) { |
|
| 172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - return $filters; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * captures plugin activation errors for debugging |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - * @throws EE_Error |
|
| 186 | - */ |
|
| 187 | - public static function ee_plugin_activation_errors() |
|
| 188 | - { |
|
| 189 | - if (WP_DEBUG) { |
|
| 190 | - $activation_errors = ob_get_contents(); |
|
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | - } |
|
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | - if (class_exists('EEH_File')) { |
|
| 196 | - try { |
|
| 197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | - ); |
|
| 200 | - EEH_File::write_to_file( |
|
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | - $activation_errors |
|
| 203 | - ); |
|
| 204 | - } catch (EE_Error $e) { |
|
| 205 | - EE_Error::add_error( |
|
| 206 | - sprintf( |
|
| 207 | - __( |
|
| 208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - $e->getMessage() |
|
| 212 | - ), |
|
| 213 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - } else { |
|
| 217 | - // old school attempt |
|
| 218 | - file_put_contents( |
|
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | - $activation_errors |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | - * or we want to make sure they use something the right way. |
|
| 234 | - * |
|
| 235 | - * @access public |
|
| 236 | - * @param string $function The function that was called |
|
| 237 | - * @param string $message A message explaining what has been done incorrectly |
|
| 238 | - * @param string $version The version of Event Espresso where the error was added |
|
| 239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | - * but not have any notices appear until a later version. This allows developers |
|
| 242 | - * extra time to update their code before notices appear. |
|
| 243 | - * @param int $error_type |
|
| 244 | - * @uses trigger_error() |
|
| 245 | - */ |
|
| 246 | - public function doing_it_wrong( |
|
| 247 | - $function, |
|
| 248 | - $message, |
|
| 249 | - $version, |
|
| 250 | - $applies_when = '', |
|
| 251 | - $error_type = null |
|
| 252 | - ) { |
|
| 253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | - // because we swapped the parameter order around for the last two params, |
|
| 256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | - if (is_int($applies_when)) { |
|
| 258 | - $error_type = $applies_when; |
|
| 259 | - $applies_when = espresso_version(); |
|
| 260 | - } |
|
| 261 | - // if not displaying notices yet, then just leave |
|
| 262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | - $version = $version === null |
|
| 267 | - ? '' |
|
| 268 | - : sprintf( |
|
| 269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | - $version |
|
| 271 | - ); |
|
| 272 | - $error_message = sprintf( |
|
| 273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | - $function, |
|
| 275 | - '<strong>', |
|
| 276 | - '</strong>', |
|
| 277 | - $message, |
|
| 278 | - $version |
|
| 279 | - ); |
|
| 280 | - // don't trigger error if doing ajax, |
|
| 281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | - 'event_espresso' |
|
| 286 | - ); |
|
| 287 | - $error_message .= '<ul><li>'; |
|
| 288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | - $error_message .= '</ul>'; |
|
| 290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | - //now we set this on the transient so it shows up on the next request. |
|
| 292 | - EE_Error::get_notices(false, true); |
|
| 293 | - } else { |
|
| 294 | - trigger_error($error_message, $error_type); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Logger helpers |
|
| 303 | - */ |
|
| 304 | - /** |
|
| 305 | - * debug |
|
| 306 | - * |
|
| 307 | - * @param string $class |
|
| 308 | - * @param string $func |
|
| 309 | - * @param string $line |
|
| 310 | - * @param array $info |
|
| 311 | - * @param bool $display_request |
|
| 312 | - * @param string $debug_index |
|
| 313 | - * @param string $debug_key |
|
| 314 | - * @throws EE_Error |
|
| 315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | - */ |
|
| 317 | - public static function log( |
|
| 318 | - $class = '', |
|
| 319 | - $func = '', |
|
| 320 | - $line = '', |
|
| 321 | - $info = array(), |
|
| 322 | - $display_request = false, |
|
| 323 | - $debug_index = '', |
|
| 324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | - ) { |
|
| 326 | - if (WP_DEBUG) { |
|
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | - $debug_data = get_option($debug_key, array()); |
|
| 329 | - $default_data = array( |
|
| 330 | - $class => $func . '() : ' . $line, |
|
| 331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | - ); |
|
| 333 | - // don't serialize objects |
|
| 334 | - $info = self::strip_objects($info); |
|
| 335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | - if (! isset($debug_data[$index])) { |
|
| 337 | - $debug_data[$index] = array(); |
|
| 338 | - } |
|
| 339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | - update_option($debug_key, $debug_data); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * strip_objects |
|
| 348 | - * |
|
| 349 | - * @param array $info |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - public static function strip_objects($info = array()) |
|
| 353 | - { |
|
| 354 | - foreach ($info as $key => $value) { |
|
| 355 | - if (is_array($value)) { |
|
| 356 | - $info[$key] = self::strip_objects($value); |
|
| 357 | - } else if (is_object($value)) { |
|
| 358 | - $object_class = get_class($value); |
|
| 359 | - $info[$object_class] = array(); |
|
| 360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | - if (method_exists($value, 'ID')) { |
|
| 362 | - $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | - } |
|
| 364 | - if (method_exists($value, 'status')) { |
|
| 365 | - $info[$object_class]['status'] = $value->status(); |
|
| 366 | - } else if (method_exists($value, 'status_ID')) { |
|
| 367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | - } |
|
| 369 | - unset($info[$key]); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return (array)$info; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param mixed $var |
|
| 379 | - * @param string $var_name |
|
| 380 | - * @param string $file |
|
| 381 | - * @param int|string $line |
|
| 382 | - * @param int $heading_tag |
|
| 383 | - * @param bool $die |
|
| 384 | - * @param string $margin |
|
| 385 | - */ |
|
| 386 | - public static function printv( |
|
| 387 | - $var, |
|
| 388 | - $var_name = '', |
|
| 389 | - $file = '', |
|
| 390 | - $line = '', |
|
| 391 | - $heading_tag = 5, |
|
| 392 | - $die = false, |
|
| 393 | - $margin = '' |
|
| 394 | - ) { |
|
| 395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | - $is_method = method_exists($var_name, $var); |
|
| 398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 401 | - $result .= $is_method |
|
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | - if ($die) { |
|
| 407 | - die($result); |
|
| 408 | - } |
|
| 409 | - echo $result; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $var_name |
|
| 416 | - * @param string $heading_tag |
|
| 417 | - * @param string $margin |
|
| 418 | - * @return string |
|
| 419 | - */ |
|
| 420 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
| 421 | - { |
|
| 422 | - if (defined('EE_TESTS_DIR')) { |
|
| 423 | - return "\n{$var_name}"; |
|
| 424 | - } |
|
| 425 | - $margin = "25px 0 0 {$margin}"; |
|
| 426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * @param string $heading_tag |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - protected static function headingX($heading_tag = 'h5') |
|
| 436 | - { |
|
| 437 | - if (defined('EE_TESTS_DIR')) { |
|
| 438 | - return ''; |
|
| 439 | - } |
|
| 440 | - return '</' . $heading_tag . '>'; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param string $content |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - protected static function grey_span($content = '') |
|
| 450 | - { |
|
| 451 | - if (defined('EE_TESTS_DIR')) { |
|
| 452 | - return $content; |
|
| 453 | - } |
|
| 454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @param string $file |
|
| 461 | - * @param int $line |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 464 | - protected static function file_and_line($file, $line) |
|
| 465 | - { |
|
| 466 | - if ($file === '' || $line === '' || defined('EE_TESTS_DIR')) { |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 470 | - . $file |
|
| 471 | - . '<br />line no: ' |
|
| 472 | - . $line |
|
| 473 | - . '</span>'; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * @param string $content |
|
| 480 | - * @return string |
|
| 481 | - */ |
|
| 482 | - protected static function orange_span($content = '') |
|
| 483 | - { |
|
| 484 | - if (defined('EE_TESTS_DIR')) { |
|
| 485 | - return $content; |
|
| 486 | - } |
|
| 487 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @param mixed $var |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - protected static function pre_span($var) |
|
| 497 | - { |
|
| 498 | - ob_start(); |
|
| 499 | - var_dump($var); |
|
| 500 | - $var = ob_get_clean(); |
|
| 501 | - if (defined('EE_TESTS_DIR')) { |
|
| 502 | - return "\n" . $var; |
|
| 503 | - } |
|
| 504 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * @param mixed $var |
|
| 511 | - * @param string $var_name |
|
| 512 | - * @param string $file |
|
| 513 | - * @param int|string $line |
|
| 514 | - * @param int $heading_tag |
|
| 515 | - * @param bool $die |
|
| 516 | - */ |
|
| 517 | - public static function printr( |
|
| 518 | - $var, |
|
| 519 | - $var_name = '', |
|
| 520 | - $file = '', |
|
| 521 | - $line = '', |
|
| 522 | - $heading_tag = 5, |
|
| 523 | - $die = false |
|
| 524 | - ) { |
|
| 525 | - // return; |
|
| 526 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 527 | - $margin = is_admin() ? ' 180px' : '0'; |
|
| 528 | - //$print_r = false; |
|
| 529 | - if (is_string($var)) { |
|
| 530 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 531 | - return; |
|
| 532 | - } |
|
| 533 | - if (is_object($var)) { |
|
| 534 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
| 535 | - //$print_r = true; |
|
| 536 | - } else if (is_array($var)) { |
|
| 537 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
| 538 | - //$print_r = true; |
|
| 539 | - } else if (is_numeric($var)) { |
|
| 540 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 541 | - } else if ($var === null) { |
|
| 542 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
| 543 | - } |
|
| 544 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 545 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 546 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 547 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 548 | - EEH_Debug_Tools::pre_span($var) |
|
| 549 | - ); |
|
| 550 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 551 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 552 | - if ($die) { |
|
| 553 | - die($result); |
|
| 554 | - } |
|
| 555 | - echo $result; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /******************** deprecated ********************/ |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * @deprecated 4.9.39.rc.034 |
|
| 566 | - */ |
|
| 567 | - public function reset_times() |
|
| 568 | - { |
|
| 569 | - Benchmark::resetTimes(); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * @deprecated 4.9.39.rc.034 |
|
| 576 | - * @param null $timer_name |
|
| 577 | - */ |
|
| 578 | - public function start_timer($timer_name = null) |
|
| 579 | - { |
|
| 580 | - Benchmark::startTimer($timer_name); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * @deprecated 4.9.39.rc.034 |
|
| 587 | - * @param string $timer_name |
|
| 588 | - */ |
|
| 589 | - public function stop_timer($timer_name = '') |
|
| 590 | - { |
|
| 591 | - Benchmark::stopTimer($timer_name); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @deprecated 4.9.39.rc.034 |
|
| 598 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 599 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - public function measure_memory($label, $output_now = false) |
|
| 603 | - { |
|
| 604 | - Benchmark::measureMemory($label, $output_now); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * @deprecated 4.9.39.rc.034 |
|
| 611 | - * @param int $size |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function convert($size) |
|
| 615 | - { |
|
| 616 | - return Benchmark::convert($size); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @deprecated 4.9.39.rc.034 |
|
| 623 | - * @param bool $output_now |
|
| 624 | - * @return string |
|
| 625 | - */ |
|
| 626 | - public function show_times($output_now = true) |
|
| 627 | - { |
|
| 628 | - return Benchmark::displayResults($output_now); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * @deprecated 4.9.39.rc.034 |
|
| 635 | - * @param string $timer_name |
|
| 636 | - * @param float $total_time |
|
| 637 | - * @return string |
|
| 638 | - */ |
|
| 639 | - public function format_time($timer_name, $total_time) |
|
| 640 | - { |
|
| 641 | - return Benchmark::formatTime($timer_name, $total_time); |
|
| 642 | - } |
|
| 20 | + /** |
|
| 21 | + * instance of the EEH_Autoloader object |
|
| 22 | + * |
|
| 23 | + * @var $_instance |
|
| 24 | + * @access private |
|
| 25 | + */ |
|
| 26 | + private static $_instance; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $_memory_usage_points = array(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @singleton method used to instantiate class object |
|
| 37 | + * @access public |
|
| 38 | + * @return EEH_Debug_Tools |
|
| 39 | + */ |
|
| 40 | + public static function instance() |
|
| 41 | + { |
|
| 42 | + // check if class object is instantiated, and instantiated properly |
|
| 43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | + self::$_instance = new self(); |
|
| 45 | + } |
|
| 46 | + return self::$_instance; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * private class constructor |
|
| 53 | + */ |
|
| 54 | + private function __construct() |
|
| 55 | + { |
|
| 56 | + // load Kint PHP debugging library |
|
| 57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | + } |
|
| 65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | + // } |
|
| 68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * show_db_name |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public static function show_db_name() |
|
| 82 | + { |
|
| 83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | + . DB_NAME |
|
| 86 | + . '</p>'; |
|
| 87 | + } |
|
| 88 | + if (EE_DEBUG) { |
|
| 89 | + Benchmark::displayResults(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function espresso_session_footer_dump() |
|
| 101 | + { |
|
| 102 | + if ( |
|
| 103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | + && ! defined('DOING_AJAX') |
|
| 105 | + && class_exists('Kint') |
|
| 106 | + && function_exists('wp_get_current_user') |
|
| 107 | + && current_user_can('update_core') |
|
| 108 | + && class_exists('EE_Registry') |
|
| 109 | + ) { |
|
| 110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | + $this->espresso_list_hooked_functions(); |
|
| 114 | + Benchmark::displayResults(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * List All Hooked Functions |
|
| 122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | + * |
|
| 125 | + * @param string $tag |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function espresso_list_hooked_functions($tag = '') |
|
| 129 | + { |
|
| 130 | + global $wp_filter; |
|
| 131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | + if ($tag) { |
|
| 133 | + $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | + if (! is_array($hook[$tag])) { |
|
| 135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | + } else { |
|
| 140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | + ksort($hook); |
|
| 142 | + } |
|
| 143 | + foreach ($hook as $tag_name => $priorities) { |
|
| 144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | + ksort($priorities); |
|
| 146 | + foreach ($priorities as $priority => $function) { |
|
| 147 | + echo $priority; |
|
| 148 | + foreach ($function as $name => $properties) { |
|
| 149 | + echo "\t$name<br />"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * registered_filter_callbacks |
|
| 159 | + * |
|
| 160 | + * @param string $hook_name |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | + { |
|
| 165 | + $filters = array(); |
|
| 166 | + global $wp_filter; |
|
| 167 | + if (isset($wp_filter[$hook_name])) { |
|
| 168 | + $filters[$hook_name] = array(); |
|
| 169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | + $filters[$hook_name][$priority] = array(); |
|
| 171 | + foreach ($callbacks as $callback) { |
|
| 172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + return $filters; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * captures plugin activation errors for debugging |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + * @throws EE_Error |
|
| 186 | + */ |
|
| 187 | + public static function ee_plugin_activation_errors() |
|
| 188 | + { |
|
| 189 | + if (WP_DEBUG) { |
|
| 190 | + $activation_errors = ob_get_contents(); |
|
| 191 | + if (! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | + } |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | + if (class_exists('EEH_File')) { |
|
| 196 | + try { |
|
| 197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | + ); |
|
| 200 | + EEH_File::write_to_file( |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | + $activation_errors |
|
| 203 | + ); |
|
| 204 | + } catch (EE_Error $e) { |
|
| 205 | + EE_Error::add_error( |
|
| 206 | + sprintf( |
|
| 207 | + __( |
|
| 208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + $e->getMessage() |
|
| 212 | + ), |
|
| 213 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + } else { |
|
| 217 | + // old school attempt |
|
| 218 | + file_put_contents( |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | + $activation_errors |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | + * or we want to make sure they use something the right way. |
|
| 234 | + * |
|
| 235 | + * @access public |
|
| 236 | + * @param string $function The function that was called |
|
| 237 | + * @param string $message A message explaining what has been done incorrectly |
|
| 238 | + * @param string $version The version of Event Espresso where the error was added |
|
| 239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | + * but not have any notices appear until a later version. This allows developers |
|
| 242 | + * extra time to update their code before notices appear. |
|
| 243 | + * @param int $error_type |
|
| 244 | + * @uses trigger_error() |
|
| 245 | + */ |
|
| 246 | + public function doing_it_wrong( |
|
| 247 | + $function, |
|
| 248 | + $message, |
|
| 249 | + $version, |
|
| 250 | + $applies_when = '', |
|
| 251 | + $error_type = null |
|
| 252 | + ) { |
|
| 253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | + // because we swapped the parameter order around for the last two params, |
|
| 256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | + if (is_int($applies_when)) { |
|
| 258 | + $error_type = $applies_when; |
|
| 259 | + $applies_when = espresso_version(); |
|
| 260 | + } |
|
| 261 | + // if not displaying notices yet, then just leave |
|
| 262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | + $version = $version === null |
|
| 267 | + ? '' |
|
| 268 | + : sprintf( |
|
| 269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | + $version |
|
| 271 | + ); |
|
| 272 | + $error_message = sprintf( |
|
| 273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | + $function, |
|
| 275 | + '<strong>', |
|
| 276 | + '</strong>', |
|
| 277 | + $message, |
|
| 278 | + $version |
|
| 279 | + ); |
|
| 280 | + // don't trigger error if doing ajax, |
|
| 281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | + $error_message .= ' ' . esc_html__( |
|
| 284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | + 'event_espresso' |
|
| 286 | + ); |
|
| 287 | + $error_message .= '<ul><li>'; |
|
| 288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | + $error_message .= '</ul>'; |
|
| 290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | + //now we set this on the transient so it shows up on the next request. |
|
| 292 | + EE_Error::get_notices(false, true); |
|
| 293 | + } else { |
|
| 294 | + trigger_error($error_message, $error_type); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Logger helpers |
|
| 303 | + */ |
|
| 304 | + /** |
|
| 305 | + * debug |
|
| 306 | + * |
|
| 307 | + * @param string $class |
|
| 308 | + * @param string $func |
|
| 309 | + * @param string $line |
|
| 310 | + * @param array $info |
|
| 311 | + * @param bool $display_request |
|
| 312 | + * @param string $debug_index |
|
| 313 | + * @param string $debug_key |
|
| 314 | + * @throws EE_Error |
|
| 315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | + */ |
|
| 317 | + public static function log( |
|
| 318 | + $class = '', |
|
| 319 | + $func = '', |
|
| 320 | + $line = '', |
|
| 321 | + $info = array(), |
|
| 322 | + $display_request = false, |
|
| 323 | + $debug_index = '', |
|
| 324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | + ) { |
|
| 326 | + if (WP_DEBUG) { |
|
| 327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | + $debug_data = get_option($debug_key, array()); |
|
| 329 | + $default_data = array( |
|
| 330 | + $class => $func . '() : ' . $line, |
|
| 331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | + ); |
|
| 333 | + // don't serialize objects |
|
| 334 | + $info = self::strip_objects($info); |
|
| 335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | + if (! isset($debug_data[$index])) { |
|
| 337 | + $debug_data[$index] = array(); |
|
| 338 | + } |
|
| 339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | + update_option($debug_key, $debug_data); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * strip_objects |
|
| 348 | + * |
|
| 349 | + * @param array $info |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + public static function strip_objects($info = array()) |
|
| 353 | + { |
|
| 354 | + foreach ($info as $key => $value) { |
|
| 355 | + if (is_array($value)) { |
|
| 356 | + $info[$key] = self::strip_objects($value); |
|
| 357 | + } else if (is_object($value)) { |
|
| 358 | + $object_class = get_class($value); |
|
| 359 | + $info[$object_class] = array(); |
|
| 360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | + if (method_exists($value, 'ID')) { |
|
| 362 | + $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | + } |
|
| 364 | + if (method_exists($value, 'status')) { |
|
| 365 | + $info[$object_class]['status'] = $value->status(); |
|
| 366 | + } else if (method_exists($value, 'status_ID')) { |
|
| 367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | + } |
|
| 369 | + unset($info[$key]); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + return (array)$info; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param mixed $var |
|
| 379 | + * @param string $var_name |
|
| 380 | + * @param string $file |
|
| 381 | + * @param int|string $line |
|
| 382 | + * @param int $heading_tag |
|
| 383 | + * @param bool $die |
|
| 384 | + * @param string $margin |
|
| 385 | + */ |
|
| 386 | + public static function printv( |
|
| 387 | + $var, |
|
| 388 | + $var_name = '', |
|
| 389 | + $file = '', |
|
| 390 | + $line = '', |
|
| 391 | + $heading_tag = 5, |
|
| 392 | + $die = false, |
|
| 393 | + $margin = '' |
|
| 394 | + ) { |
|
| 395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | + $is_method = method_exists($var_name, $var); |
|
| 398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 401 | + $result .= $is_method |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | + if ($die) { |
|
| 407 | + die($result); |
|
| 408 | + } |
|
| 409 | + echo $result; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $var_name |
|
| 416 | + * @param string $heading_tag |
|
| 417 | + * @param string $margin |
|
| 418 | + * @return string |
|
| 419 | + */ |
|
| 420 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
| 421 | + { |
|
| 422 | + if (defined('EE_TESTS_DIR')) { |
|
| 423 | + return "\n{$var_name}"; |
|
| 424 | + } |
|
| 425 | + $margin = "25px 0 0 {$margin}"; |
|
| 426 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * @param string $heading_tag |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + protected static function headingX($heading_tag = 'h5') |
|
| 436 | + { |
|
| 437 | + if (defined('EE_TESTS_DIR')) { |
|
| 438 | + return ''; |
|
| 439 | + } |
|
| 440 | + return '</' . $heading_tag . '>'; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param string $content |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + protected static function grey_span($content = '') |
|
| 450 | + { |
|
| 451 | + if (defined('EE_TESTS_DIR')) { |
|
| 452 | + return $content; |
|
| 453 | + } |
|
| 454 | + return '<span style="color:#999">' . $content . '</span>'; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @param string $file |
|
| 461 | + * @param int $line |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | + protected static function file_and_line($file, $line) |
|
| 465 | + { |
|
| 466 | + if ($file === '' || $line === '' || defined('EE_TESTS_DIR')) { |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 470 | + . $file |
|
| 471 | + . '<br />line no: ' |
|
| 472 | + . $line |
|
| 473 | + . '</span>'; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * @param string $content |
|
| 480 | + * @return string |
|
| 481 | + */ |
|
| 482 | + protected static function orange_span($content = '') |
|
| 483 | + { |
|
| 484 | + if (defined('EE_TESTS_DIR')) { |
|
| 485 | + return $content; |
|
| 486 | + } |
|
| 487 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @param mixed $var |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + protected static function pre_span($var) |
|
| 497 | + { |
|
| 498 | + ob_start(); |
|
| 499 | + var_dump($var); |
|
| 500 | + $var = ob_get_clean(); |
|
| 501 | + if (defined('EE_TESTS_DIR')) { |
|
| 502 | + return "\n" . $var; |
|
| 503 | + } |
|
| 504 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * @param mixed $var |
|
| 511 | + * @param string $var_name |
|
| 512 | + * @param string $file |
|
| 513 | + * @param int|string $line |
|
| 514 | + * @param int $heading_tag |
|
| 515 | + * @param bool $die |
|
| 516 | + */ |
|
| 517 | + public static function printr( |
|
| 518 | + $var, |
|
| 519 | + $var_name = '', |
|
| 520 | + $file = '', |
|
| 521 | + $line = '', |
|
| 522 | + $heading_tag = 5, |
|
| 523 | + $die = false |
|
| 524 | + ) { |
|
| 525 | + // return; |
|
| 526 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 527 | + $margin = is_admin() ? ' 180px' : '0'; |
|
| 528 | + //$print_r = false; |
|
| 529 | + if (is_string($var)) { |
|
| 530 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 531 | + return; |
|
| 532 | + } |
|
| 533 | + if (is_object($var)) { |
|
| 534 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
| 535 | + //$print_r = true; |
|
| 536 | + } else if (is_array($var)) { |
|
| 537 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
| 538 | + //$print_r = true; |
|
| 539 | + } else if (is_numeric($var)) { |
|
| 540 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 541 | + } else if ($var === null) { |
|
| 542 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
| 543 | + } |
|
| 544 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 545 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 546 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 547 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 548 | + EEH_Debug_Tools::pre_span($var) |
|
| 549 | + ); |
|
| 550 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 551 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 552 | + if ($die) { |
|
| 553 | + die($result); |
|
| 554 | + } |
|
| 555 | + echo $result; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /******************** deprecated ********************/ |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * @deprecated 4.9.39.rc.034 |
|
| 566 | + */ |
|
| 567 | + public function reset_times() |
|
| 568 | + { |
|
| 569 | + Benchmark::resetTimes(); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * @deprecated 4.9.39.rc.034 |
|
| 576 | + * @param null $timer_name |
|
| 577 | + */ |
|
| 578 | + public function start_timer($timer_name = null) |
|
| 579 | + { |
|
| 580 | + Benchmark::startTimer($timer_name); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * @deprecated 4.9.39.rc.034 |
|
| 587 | + * @param string $timer_name |
|
| 588 | + */ |
|
| 589 | + public function stop_timer($timer_name = '') |
|
| 590 | + { |
|
| 591 | + Benchmark::stopTimer($timer_name); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @deprecated 4.9.39.rc.034 |
|
| 598 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 599 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + public function measure_memory($label, $output_now = false) |
|
| 603 | + { |
|
| 604 | + Benchmark::measureMemory($label, $output_now); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * @deprecated 4.9.39.rc.034 |
|
| 611 | + * @param int $size |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function convert($size) |
|
| 615 | + { |
|
| 616 | + return Benchmark::convert($size); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @deprecated 4.9.39.rc.034 |
|
| 623 | + * @param bool $output_now |
|
| 624 | + * @return string |
|
| 625 | + */ |
|
| 626 | + public function show_times($output_now = true) |
|
| 627 | + { |
|
| 628 | + return Benchmark::displayResults($output_now); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * @deprecated 4.9.39.rc.034 |
|
| 635 | + * @param string $timer_name |
|
| 636 | + * @param float $total_time |
|
| 637 | + * @return string |
|
| 638 | + */ |
|
| 639 | + public function format_time($timer_name, $total_time) |
|
| 640 | + { |
|
| 641 | + return Benchmark::formatTime($timer_name, $total_time); |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | 644 | |
| 645 | 645 | |
@@ -652,31 +652,31 @@ discard block |
||
| 652 | 652 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 653 | 653 | */ |
| 654 | 654 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
| 655 | - function dump_wp_query() |
|
| 656 | - { |
|
| 657 | - global $wp_query; |
|
| 658 | - d($wp_query); |
|
| 659 | - } |
|
| 655 | + function dump_wp_query() |
|
| 656 | + { |
|
| 657 | + global $wp_query; |
|
| 658 | + d($wp_query); |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | /** |
| 662 | 662 | * borrowed from Kint Debugger |
| 663 | 663 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 664 | 664 | */ |
| 665 | 665 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
| 666 | - function dump_wp() |
|
| 667 | - { |
|
| 668 | - global $wp; |
|
| 669 | - d($wp); |
|
| 670 | - } |
|
| 666 | + function dump_wp() |
|
| 667 | + { |
|
| 668 | + global $wp; |
|
| 669 | + d($wp); |
|
| 670 | + } |
|
| 671 | 671 | } |
| 672 | 672 | /** |
| 673 | 673 | * borrowed from Kint Debugger |
| 674 | 674 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 675 | 675 | */ |
| 676 | 676 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
| 677 | - function dump_post() |
|
| 678 | - { |
|
| 679 | - global $post; |
|
| 680 | - d($post); |
|
| 681 | - } |
|
| 677 | + function dump_post() |
|
| 678 | + { |
|
| 679 | + global $post; |
|
| 680 | + d($post); |
|
| 681 | + } |
|
| 682 | 682 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | } |
| 6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public static function instance() |
| 41 | 41 | { |
| 42 | 42 | // check if class object is instantiated, and instantiated properly |
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | private function __construct() |
| 55 | 55 | { |
| 56 | 56 | // load Kint PHP debugging library |
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
| 58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
| 59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
| 60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
| 61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
| 62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
| 64 | 64 | } |
| 65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
| 66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public static function show_db_name() |
| 82 | 82 | { |
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
| 85 | 85 | . DB_NAME |
| 86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
| 132 | 132 | if ($tag) { |
| 133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
| 134 | - if (! is_array($hook[$tag])) { |
|
| 134 | + if ( ! is_array($hook[$tag])) { |
|
| 135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
| 139 | 139 | } else { |
| 140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
| 141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | if (WP_DEBUG) { |
| 190 | 190 | $activation_errors = ob_get_contents(); |
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | + if ( ! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
| 193 | 193 | } |
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
| 195 | 195 | if (class_exists('EEH_File')) { |
| 196 | 196 | try { |
| 197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
| 199 | 199 | ); |
| 200 | 200 | EEH_File::write_to_file( |
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 202 | 202 | $activation_errors |
| 203 | 203 | ); |
| 204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | } else { |
| 217 | 217 | // old school attempt |
| 218 | 218 | file_put_contents( |
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 220 | 220 | $activation_errors |
| 221 | 221 | ); |
| 222 | 222 | } |
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
| 224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | // don't trigger error if doing ajax, |
| 281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
| 282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 283 | + $error_message .= ' '.esc_html__( |
|
| 284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
| 285 | 285 | 'event_espresso' |
| 286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
| 324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
| 325 | 325 | ) { |
| 326 | 326 | if (WP_DEBUG) { |
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
| 328 | 328 | $debug_data = get_option($debug_key, array()); |
| 329 | 329 | $default_data = array( |
| 330 | - $class => $func . '() : ' . $line, |
|
| 330 | + $class => $func.'() : '.$line, |
|
| 331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
| 332 | 332 | ); |
| 333 | 333 | // don't serialize objects |
| 334 | 334 | $info = self::strip_objects($info); |
| 335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
| 336 | - if (! isset($debug_data[$index])) { |
|
| 336 | + if ( ! isset($debug_data[$index])) { |
|
| 337 | 337 | $debug_data[$index] = array(); |
| 338 | 338 | } |
| 339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | unset($info[$key]); |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | - return (array)$info; |
|
| 372 | + return (array) $info; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
| 401 | 401 | $result .= $is_method |
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
| 404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
| 405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
| 406 | 406 | if ($die) { |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | return "\n{$var_name}"; |
| 424 | 424 | } |
| 425 | 425 | $margin = "25px 0 0 {$margin}"; |
| 426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 426 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | if (defined('EE_TESTS_DIR')) { |
| 438 | 438 | return ''; |
| 439 | 439 | } |
| 440 | - return '</' . $heading_tag . '>'; |
|
| 440 | + return '</'.$heading_tag.'>'; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | if (defined('EE_TESTS_DIR')) { |
| 452 | 452 | return $content; |
| 453 | 453 | } |
| 454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 454 | + return '<span style="color:#999">'.$content.'</span>'; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | if (defined('EE_TESTS_DIR')) { |
| 485 | 485 | return $content; |
| 486 | 486 | } |
| 487 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 487 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -499,9 +499,9 @@ discard block |
||
| 499 | 499 | var_dump($var); |
| 500 | 500 | $var = ob_get_clean(); |
| 501 | 501 | if (defined('EE_TESTS_DIR')) { |
| 502 | - return "\n" . $var; |
|
| 502 | + return "\n".$var; |
|
| 503 | 503 | } |
| 504 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 504 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
| 545 | 545 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 546 | 546 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
| 547 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 547 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
| 548 | 548 | EEH_Debug_Tools::pre_span($var) |
| 549 | 549 | ); |
| 550 | 550 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 6 | 6 | |
| 7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('No direct script access allowed'); |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | |
@@ -22,805 +22,805 @@ discard block |
||
| 22 | 22 | class EE_Dependency_Map |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | - */ |
|
| 33 | - const load_new_object = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | - */ |
|
| 39 | - const load_from_cache = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * When registering a dependency, |
|
| 43 | - * this indicates to keep any existing dependencies that already exist, |
|
| 44 | - * and simply discard any new dependencies declared in the incoming data |
|
| 45 | - */ |
|
| 46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * When registering a dependency, |
|
| 50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | - */ |
|
| 52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @type EE_Dependency_Map $_instance |
|
| 58 | - */ |
|
| 59 | - protected static $_instance; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @type EE_Request $request |
|
| 63 | - */ |
|
| 64 | - protected $_request; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @type EE_Response $response |
|
| 68 | - */ |
|
| 69 | - protected $_response; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @type LoaderInterface $loader |
|
| 73 | - */ |
|
| 74 | - protected $loader; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @type array $_dependency_map |
|
| 78 | - */ |
|
| 79 | - protected $_dependency_map = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @type array $_class_loaders |
|
| 83 | - */ |
|
| 84 | - protected $_class_loaders = array(); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @type array $_aliases |
|
| 88 | - */ |
|
| 89 | - protected $_aliases = array(); |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * EE_Dependency_Map constructor. |
|
| 95 | - * |
|
| 96 | - * @param EE_Request $request |
|
| 97 | - * @param EE_Response $response |
|
| 98 | - */ |
|
| 99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 100 | - { |
|
| 101 | - $this->_request = $request; |
|
| 102 | - $this->_response = $response; |
|
| 103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 104 | - do_action('EE_Dependency_Map____construct'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @throws InvalidDataTypeException |
|
| 111 | - * @throws InvalidInterfaceException |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - */ |
|
| 114 | - public function initialize() |
|
| 115 | - { |
|
| 116 | - $this->_register_core_dependencies(); |
|
| 117 | - $this->_register_core_class_loaders(); |
|
| 118 | - $this->_register_core_aliases(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @singleton method used to instantiate class object |
|
| 125 | - * @access public |
|
| 126 | - * @param EE_Request $request |
|
| 127 | - * @param EE_Response $response |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - */ |
|
| 130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 131 | - { |
|
| 132 | - // check if class object is instantiated, and instantiated properly |
|
| 133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 135 | - } |
|
| 136 | - return self::$_instance; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param LoaderInterface $loader |
|
| 143 | - */ |
|
| 144 | - public function setLoader(LoaderInterface $loader) |
|
| 145 | - { |
|
| 146 | - $this->loader = $loader; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param string $class |
|
| 153 | - * @param array $dependencies |
|
| 154 | - * @param int $overwrite |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public static function register_dependencies( |
|
| 158 | - $class, |
|
| 159 | - array $dependencies, |
|
| 160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 161 | - ) { |
|
| 162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 169 | - * to the class specified by the first parameter. |
|
| 170 | - * IMPORTANT !!! |
|
| 171 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 172 | - * the order of the constructor parameters for the class in question. |
|
| 173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 175 | - * |
|
| 176 | - * @param string $class |
|
| 177 | - * @param array $dependencies |
|
| 178 | - * @param int $overwrite |
|
| 179 | - * @return bool |
|
| 180 | - */ |
|
| 181 | - public function registerDependencies( |
|
| 182 | - $class, |
|
| 183 | - array $dependencies, |
|
| 184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 185 | - ) { |
|
| 186 | - $class = trim($class, '\\'); |
|
| 187 | - $registered = false; |
|
| 188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 190 | - } |
|
| 191 | - // we need to make sure that any aliases used when registering a dependency |
|
| 192 | - // get resolved to the correct class name |
|
| 193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 194 | - $alias = self::$_instance->get_alias($dependency); |
|
| 195 | - if ( |
|
| 196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 198 | - ) { |
|
| 199 | - unset($dependencies[$dependency]); |
|
| 200 | - $dependencies[$alias] = $load_source; |
|
| 201 | - $registered = true; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - // now add our two lists of dependencies together. |
|
| 205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 206 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 208 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 209 | - // especially with numerically indexed arrays |
|
| 210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 211 | - // now we need to ensure that the resulting dependencies |
|
| 212 | - // array only has the entries that are required for the class |
|
| 213 | - // so first count how many dependencies were originally registered for the class |
|
| 214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 217 | - // then truncate the final array to match that count |
|
| 218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 219 | - // otherwise just take the incoming array because nothing previously existed |
|
| 220 | - : $dependencies; |
|
| 221 | - return $registered; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $class_name |
|
| 228 | - * @param string $loader |
|
| 229 | - * @return bool |
|
| 230 | - * @throws DomainException |
|
| 231 | - */ |
|
| 232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 233 | - { |
|
| 234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 235 | - throw new DomainException( |
|
| 236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 240 | - if ( |
|
| 241 | - ! is_callable($loader) |
|
| 242 | - && ( |
|
| 243 | - strpos($loader, 'load_') !== 0 |
|
| 244 | - || ! method_exists('EE_Registry', $loader) |
|
| 245 | - ) |
|
| 246 | - ) { |
|
| 247 | - throw new DomainException( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $loader |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - public function dependency_map() |
|
| 271 | - { |
|
| 272 | - return $this->_dependency_map; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 279 | - * |
|
| 280 | - * @param string $class_name |
|
| 281 | - * @return boolean |
|
| 282 | - */ |
|
| 283 | - public function has($class_name = '') |
|
| 284 | - { |
|
| 285 | - // all legacy models have the same dependencies |
|
| 286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 287 | - $class_name = 'LEGACY_MODELS'; |
|
| 288 | - } |
|
| 289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 296 | - * |
|
| 297 | - * @param string $class_name |
|
| 298 | - * @param string $dependency |
|
| 299 | - * @return bool |
|
| 300 | - */ |
|
| 301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 302 | - { |
|
| 303 | - // all legacy models have the same dependencies |
|
| 304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 305 | - $class_name = 'LEGACY_MODELS'; |
|
| 306 | - } |
|
| 307 | - $dependency = $this->get_alias($dependency); |
|
| 308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 309 | - ? true |
|
| 310 | - : false; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 317 | - * |
|
| 318 | - * @param string $class_name |
|
| 319 | - * @param string $dependency |
|
| 320 | - * @return int |
|
| 321 | - */ |
|
| 322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 323 | - { |
|
| 324 | - // all legacy models have the same dependencies |
|
| 325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 326 | - $class_name = 'LEGACY_MODELS'; |
|
| 327 | - } |
|
| 328 | - $dependency = $this->get_alias($dependency); |
|
| 329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 331 | - : EE_Dependency_Map::not_registered; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param string $class_name |
|
| 338 | - * @return string | Closure |
|
| 339 | - */ |
|
| 340 | - public function class_loader($class_name) |
|
| 341 | - { |
|
| 342 | - // all legacy models use load_model() |
|
| 343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 344 | - return 'load_model'; |
|
| 345 | - } |
|
| 346 | - $class_name = $this->get_alias($class_name); |
|
| 347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @return array |
|
| 354 | - */ |
|
| 355 | - public function class_loaders() |
|
| 356 | - { |
|
| 357 | - return $this->_class_loaders; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * adds an alias for a classname |
|
| 364 | - * |
|
| 365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 368 | - */ |
|
| 369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 370 | - { |
|
| 371 | - if ($for_class !== '') { |
|
| 372 | - if (! isset($this->_aliases[$for_class])) { |
|
| 373 | - $this->_aliases[$for_class] = array(); |
|
| 374 | - } |
|
| 375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 376 | - } |
|
| 377 | - $this->_aliases[$class_name] = $alias; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * returns TRUE if the provided class name has an alias |
|
| 384 | - * |
|
| 385 | - * @param string $class_name |
|
| 386 | - * @param string $for_class |
|
| 387 | - * @return bool |
|
| 388 | - */ |
|
| 389 | - public function has_alias($class_name = '', $for_class = '') |
|
| 390 | - { |
|
| 391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 392 | - || ( |
|
| 393 | - isset($this->_aliases[$class_name]) |
|
| 394 | - && ! is_array($this->_aliases[$class_name]) |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 403 | - * for example: |
|
| 404 | - * if the following two entries were added to the _aliases array: |
|
| 405 | - * array( |
|
| 406 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 408 | - * ) |
|
| 409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 410 | - * to load an instance of 'some\namespace\classname' |
|
| 411 | - * |
|
| 412 | - * @param string $class_name |
|
| 413 | - * @param string $for_class |
|
| 414 | - * @return string |
|
| 415 | - */ |
|
| 416 | - public function get_alias($class_name = '', $for_class = '') |
|
| 417 | - { |
|
| 418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 419 | - return $class_name; |
|
| 420 | - } |
|
| 421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 423 | - } |
|
| 424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | - * This is done by using the following class constants: |
|
| 433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | - */ |
|
| 436 | - protected function _register_core_dependencies() |
|
| 437 | - { |
|
| 438 | - $this->_dependency_map = array( |
|
| 439 | - 'EE_Request_Handler' => array( |
|
| 440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EE_System' => array( |
|
| 443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 446 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 448 | - ), |
|
| 449 | - 'EE_Session' => array( |
|
| 450 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 451 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 452 | - ), |
|
| 453 | - 'EE_Cart' => array( |
|
| 454 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 455 | - ), |
|
| 456 | - 'EE_Front_Controller' => array( |
|
| 457 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 458 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - ), |
|
| 461 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 462 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | - ), |
|
| 464 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 465 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 466 | - ), |
|
| 467 | - 'EE_Message_Resource_Manager' => array( |
|
| 468 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 469 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - ), |
|
| 472 | - 'EE_Message_Factory' => array( |
|
| 473 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 474 | - ), |
|
| 475 | - 'EE_messages' => array( |
|
| 476 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - ), |
|
| 478 | - 'EE_Messages_Generator' => array( |
|
| 479 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 480 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - ), |
|
| 484 | - 'EE_Messages_Processor' => array( |
|
| 485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EE_Messages_Queue' => array( |
|
| 488 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 489 | - ), |
|
| 490 | - 'EE_Messages_Template_Defaults' => array( |
|
| 491 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - ), |
|
| 494 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 497 | - ), |
|
| 498 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 499 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 502 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ), |
|
| 505 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 506 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 507 | - ), |
|
| 508 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 509 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 510 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - ), |
|
| 512 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 513 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 514 | - ), |
|
| 515 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 516 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 517 | - ), |
|
| 518 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 519 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 522 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 525 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 528 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ), |
|
| 530 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 531 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ), |
|
| 533 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 534 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - ), |
|
| 536 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 537 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ), |
|
| 539 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 540 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ), |
|
| 542 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 543 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 546 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ), |
|
| 548 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 549 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ), |
|
| 551 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 552 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ), |
|
| 554 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 557 | - ), |
|
| 558 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 561 | - ), |
|
| 562 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ), |
|
| 566 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 569 | - ), |
|
| 570 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 573 | - ), |
|
| 574 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - ), |
|
| 578 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 581 | - ), |
|
| 582 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - ), |
|
| 586 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 589 | - ), |
|
| 590 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 593 | - ), |
|
| 594 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 595 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 596 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 597 | - ), |
|
| 598 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 599 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 602 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ), |
|
| 604 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - ), |
|
| 607 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 608 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 609 | - ), |
|
| 610 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 611 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ), |
|
| 613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - ), |
|
| 616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | - ), |
|
| 619 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 620 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 621 | - ), |
|
| 622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 623 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 624 | - ), |
|
| 625 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 626 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 627 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ), |
|
| 629 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 630 | - null, |
|
| 631 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 632 | - ), |
|
| 633 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 634 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | - ), |
|
| 636 | - 'LEGACY_MODELS' => array( |
|
| 637 | - null, |
|
| 638 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 639 | - ), |
|
| 640 | - 'EE_Module_Request_Router' => array( |
|
| 641 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 642 | - ), |
|
| 643 | - 'EE_Registration_Processor' => array( |
|
| 644 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 645 | - ), |
|
| 646 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 647 | - null, |
|
| 648 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 649 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 650 | - ), |
|
| 651 | - ); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Registers how core classes are loaded. |
|
| 658 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 659 | - * 'EE_Request_Handler' => 'load_core' |
|
| 660 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 661 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 662 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 663 | - * 'Some_Class' => function () { |
|
| 664 | - * return new Some_Class(); |
|
| 665 | - * }, |
|
| 666 | - * This is required for instantiating dependencies |
|
| 667 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 668 | - * 'Required_Interface' => function () { |
|
| 669 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 670 | - * }, |
|
| 671 | - * |
|
| 672 | - * @throws InvalidInterfaceException |
|
| 673 | - * @throws InvalidDataTypeException |
|
| 674 | - * @throws InvalidArgumentException |
|
| 675 | - */ |
|
| 676 | - protected function _register_core_class_loaders() |
|
| 677 | - { |
|
| 678 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 679 | - //be used in a closure. |
|
| 680 | - $request = &$this->_request; |
|
| 681 | - $response = &$this->_response; |
|
| 682 | - // $loader = &$this->loader; |
|
| 683 | - $this->_class_loaders = array( |
|
| 684 | - //load_core |
|
| 685 | - 'EE_Capabilities' => 'load_core', |
|
| 686 | - 'EE_Encryption' => 'load_core', |
|
| 687 | - 'EE_Front_Controller' => 'load_core', |
|
| 688 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 689 | - 'EE_Registry' => 'load_core', |
|
| 690 | - 'EE_Request' => function () use (&$request) { |
|
| 691 | - return $request; |
|
| 692 | - }, |
|
| 693 | - 'EE_Response' => function () use (&$response) { |
|
| 694 | - return $response; |
|
| 695 | - }, |
|
| 696 | - 'EE_Request_Handler' => 'load_core', |
|
| 697 | - 'EE_Session' => 'load_core', |
|
| 698 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 699 | - 'EE_System' => 'load_core', |
|
| 700 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 701 | - 'EE_Register_CPTs' => 'load_core', |
|
| 702 | - 'EE_Admin' => 'load_core', |
|
| 703 | - //load_lib |
|
| 704 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 705 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 706 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 707 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 708 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 709 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 710 | - 'EE_Message_Repository' => 'load_lib', |
|
| 711 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 712 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 713 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 714 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 715 | - 'EE_Messages_Generator' => function () { |
|
| 716 | - return EE_Registry::instance()->load_lib( |
|
| 717 | - 'Messages_Generator', |
|
| 718 | - array(), |
|
| 719 | - false, |
|
| 720 | - false |
|
| 721 | - ); |
|
| 722 | - }, |
|
| 723 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 724 | - return EE_Registry::instance()->load_lib( |
|
| 725 | - 'Messages_Template_Defaults', |
|
| 726 | - $arguments, |
|
| 727 | - false, |
|
| 728 | - false |
|
| 729 | - ); |
|
| 730 | - }, |
|
| 731 | - //load_model |
|
| 732 | - // 'EEM_Attendee' => 'load_model', |
|
| 733 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
| 734 | - // 'EEM_Message_Template' => 'load_model', |
|
| 735 | - //load_helper |
|
| 736 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 737 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 738 | - return new EEH_Parse_Shortcodes(); |
|
| 739 | - } |
|
| 740 | - return null; |
|
| 741 | - }, |
|
| 742 | - 'EE_Template_Config' => function () { |
|
| 743 | - return EE_Config::instance()->template_settings; |
|
| 744 | - }, |
|
| 745 | - 'EE_Currency_Config' => function () { |
|
| 746 | - return EE_Config::instance()->currency; |
|
| 747 | - }, |
|
| 748 | - 'EE_Registration_Config' => function () { |
|
| 749 | - return EE_Config::instance()->registration; |
|
| 750 | - }, |
|
| 751 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 752 | - return LoaderFactory::getLoader(); |
|
| 753 | - }, |
|
| 754 | - ); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * can be used for supplying alternate names for classes, |
|
| 761 | - * or for connecting interface names to instantiable classes |
|
| 762 | - */ |
|
| 763 | - protected function _register_core_aliases() |
|
| 764 | - { |
|
| 765 | - $this->_aliases = array( |
|
| 766 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 767 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 768 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 769 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 770 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 771 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 772 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 773 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 774 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 775 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 776 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 777 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 778 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 779 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 780 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 781 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 782 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 783 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 784 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 785 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 786 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 787 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 788 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 789 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 790 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 791 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 792 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 793 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 794 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 795 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 796 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 797 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 798 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 799 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 800 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 801 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 802 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 803 | - ); |
|
| 804 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 805 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 813 | - * request Primarily used by unit tests. |
|
| 814 | - * |
|
| 815 | - * @throws InvalidDataTypeException |
|
| 816 | - * @throws InvalidInterfaceException |
|
| 817 | - * @throws InvalidArgumentException |
|
| 818 | - */ |
|
| 819 | - public function reset() |
|
| 820 | - { |
|
| 821 | - $this->_register_core_class_loaders(); |
|
| 822 | - $this->_register_core_dependencies(); |
|
| 823 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | + */ |
|
| 33 | + const load_new_object = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | + */ |
|
| 39 | + const load_from_cache = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * When registering a dependency, |
|
| 43 | + * this indicates to keep any existing dependencies that already exist, |
|
| 44 | + * and simply discard any new dependencies declared in the incoming data |
|
| 45 | + */ |
|
| 46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * When registering a dependency, |
|
| 50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | + */ |
|
| 52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @type EE_Dependency_Map $_instance |
|
| 58 | + */ |
|
| 59 | + protected static $_instance; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @type EE_Request $request |
|
| 63 | + */ |
|
| 64 | + protected $_request; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @type EE_Response $response |
|
| 68 | + */ |
|
| 69 | + protected $_response; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @type LoaderInterface $loader |
|
| 73 | + */ |
|
| 74 | + protected $loader; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @type array $_dependency_map |
|
| 78 | + */ |
|
| 79 | + protected $_dependency_map = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @type array $_class_loaders |
|
| 83 | + */ |
|
| 84 | + protected $_class_loaders = array(); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @type array $_aliases |
|
| 88 | + */ |
|
| 89 | + protected $_aliases = array(); |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * EE_Dependency_Map constructor. |
|
| 95 | + * |
|
| 96 | + * @param EE_Request $request |
|
| 97 | + * @param EE_Response $response |
|
| 98 | + */ |
|
| 99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 100 | + { |
|
| 101 | + $this->_request = $request; |
|
| 102 | + $this->_response = $response; |
|
| 103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 104 | + do_action('EE_Dependency_Map____construct'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @throws InvalidDataTypeException |
|
| 111 | + * @throws InvalidInterfaceException |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + */ |
|
| 114 | + public function initialize() |
|
| 115 | + { |
|
| 116 | + $this->_register_core_dependencies(); |
|
| 117 | + $this->_register_core_class_loaders(); |
|
| 118 | + $this->_register_core_aliases(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @singleton method used to instantiate class object |
|
| 125 | + * @access public |
|
| 126 | + * @param EE_Request $request |
|
| 127 | + * @param EE_Response $response |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + */ |
|
| 130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 131 | + { |
|
| 132 | + // check if class object is instantiated, and instantiated properly |
|
| 133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 135 | + } |
|
| 136 | + return self::$_instance; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param LoaderInterface $loader |
|
| 143 | + */ |
|
| 144 | + public function setLoader(LoaderInterface $loader) |
|
| 145 | + { |
|
| 146 | + $this->loader = $loader; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param string $class |
|
| 153 | + * @param array $dependencies |
|
| 154 | + * @param int $overwrite |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public static function register_dependencies( |
|
| 158 | + $class, |
|
| 159 | + array $dependencies, |
|
| 160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 161 | + ) { |
|
| 162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 169 | + * to the class specified by the first parameter. |
|
| 170 | + * IMPORTANT !!! |
|
| 171 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 172 | + * the order of the constructor parameters for the class in question. |
|
| 173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 175 | + * |
|
| 176 | + * @param string $class |
|
| 177 | + * @param array $dependencies |
|
| 178 | + * @param int $overwrite |
|
| 179 | + * @return bool |
|
| 180 | + */ |
|
| 181 | + public function registerDependencies( |
|
| 182 | + $class, |
|
| 183 | + array $dependencies, |
|
| 184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 185 | + ) { |
|
| 186 | + $class = trim($class, '\\'); |
|
| 187 | + $registered = false; |
|
| 188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 190 | + } |
|
| 191 | + // we need to make sure that any aliases used when registering a dependency |
|
| 192 | + // get resolved to the correct class name |
|
| 193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 194 | + $alias = self::$_instance->get_alias($dependency); |
|
| 195 | + if ( |
|
| 196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 198 | + ) { |
|
| 199 | + unset($dependencies[$dependency]); |
|
| 200 | + $dependencies[$alias] = $load_source; |
|
| 201 | + $registered = true; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + // now add our two lists of dependencies together. |
|
| 205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 206 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 208 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 209 | + // especially with numerically indexed arrays |
|
| 210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 211 | + // now we need to ensure that the resulting dependencies |
|
| 212 | + // array only has the entries that are required for the class |
|
| 213 | + // so first count how many dependencies were originally registered for the class |
|
| 214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 217 | + // then truncate the final array to match that count |
|
| 218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 219 | + // otherwise just take the incoming array because nothing previously existed |
|
| 220 | + : $dependencies; |
|
| 221 | + return $registered; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $class_name |
|
| 228 | + * @param string $loader |
|
| 229 | + * @return bool |
|
| 230 | + * @throws DomainException |
|
| 231 | + */ |
|
| 232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 233 | + { |
|
| 234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 235 | + throw new DomainException( |
|
| 236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 240 | + if ( |
|
| 241 | + ! is_callable($loader) |
|
| 242 | + && ( |
|
| 243 | + strpos($loader, 'load_') !== 0 |
|
| 244 | + || ! method_exists('EE_Registry', $loader) |
|
| 245 | + ) |
|
| 246 | + ) { |
|
| 247 | + throw new DomainException( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $loader |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + public function dependency_map() |
|
| 271 | + { |
|
| 272 | + return $this->_dependency_map; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 279 | + * |
|
| 280 | + * @param string $class_name |
|
| 281 | + * @return boolean |
|
| 282 | + */ |
|
| 283 | + public function has($class_name = '') |
|
| 284 | + { |
|
| 285 | + // all legacy models have the same dependencies |
|
| 286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 287 | + $class_name = 'LEGACY_MODELS'; |
|
| 288 | + } |
|
| 289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 296 | + * |
|
| 297 | + * @param string $class_name |
|
| 298 | + * @param string $dependency |
|
| 299 | + * @return bool |
|
| 300 | + */ |
|
| 301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 302 | + { |
|
| 303 | + // all legacy models have the same dependencies |
|
| 304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 305 | + $class_name = 'LEGACY_MODELS'; |
|
| 306 | + } |
|
| 307 | + $dependency = $this->get_alias($dependency); |
|
| 308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 309 | + ? true |
|
| 310 | + : false; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 317 | + * |
|
| 318 | + * @param string $class_name |
|
| 319 | + * @param string $dependency |
|
| 320 | + * @return int |
|
| 321 | + */ |
|
| 322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 323 | + { |
|
| 324 | + // all legacy models have the same dependencies |
|
| 325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 326 | + $class_name = 'LEGACY_MODELS'; |
|
| 327 | + } |
|
| 328 | + $dependency = $this->get_alias($dependency); |
|
| 329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 331 | + : EE_Dependency_Map::not_registered; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param string $class_name |
|
| 338 | + * @return string | Closure |
|
| 339 | + */ |
|
| 340 | + public function class_loader($class_name) |
|
| 341 | + { |
|
| 342 | + // all legacy models use load_model() |
|
| 343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
| 344 | + return 'load_model'; |
|
| 345 | + } |
|
| 346 | + $class_name = $this->get_alias($class_name); |
|
| 347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @return array |
|
| 354 | + */ |
|
| 355 | + public function class_loaders() |
|
| 356 | + { |
|
| 357 | + return $this->_class_loaders; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * adds an alias for a classname |
|
| 364 | + * |
|
| 365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 368 | + */ |
|
| 369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 370 | + { |
|
| 371 | + if ($for_class !== '') { |
|
| 372 | + if (! isset($this->_aliases[$for_class])) { |
|
| 373 | + $this->_aliases[$for_class] = array(); |
|
| 374 | + } |
|
| 375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 376 | + } |
|
| 377 | + $this->_aliases[$class_name] = $alias; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * returns TRUE if the provided class name has an alias |
|
| 384 | + * |
|
| 385 | + * @param string $class_name |
|
| 386 | + * @param string $for_class |
|
| 387 | + * @return bool |
|
| 388 | + */ |
|
| 389 | + public function has_alias($class_name = '', $for_class = '') |
|
| 390 | + { |
|
| 391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 392 | + || ( |
|
| 393 | + isset($this->_aliases[$class_name]) |
|
| 394 | + && ! is_array($this->_aliases[$class_name]) |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 403 | + * for example: |
|
| 404 | + * if the following two entries were added to the _aliases array: |
|
| 405 | + * array( |
|
| 406 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 408 | + * ) |
|
| 409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 410 | + * to load an instance of 'some\namespace\classname' |
|
| 411 | + * |
|
| 412 | + * @param string $class_name |
|
| 413 | + * @param string $for_class |
|
| 414 | + * @return string |
|
| 415 | + */ |
|
| 416 | + public function get_alias($class_name = '', $for_class = '') |
|
| 417 | + { |
|
| 418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 419 | + return $class_name; |
|
| 420 | + } |
|
| 421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 423 | + } |
|
| 424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | + * This is done by using the following class constants: |
|
| 433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | + */ |
|
| 436 | + protected function _register_core_dependencies() |
|
| 437 | + { |
|
| 438 | + $this->_dependency_map = array( |
|
| 439 | + 'EE_Request_Handler' => array( |
|
| 440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EE_System' => array( |
|
| 443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 446 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 448 | + ), |
|
| 449 | + 'EE_Session' => array( |
|
| 450 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 451 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 452 | + ), |
|
| 453 | + 'EE_Cart' => array( |
|
| 454 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 455 | + ), |
|
| 456 | + 'EE_Front_Controller' => array( |
|
| 457 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 458 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + ), |
|
| 461 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 462 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | + ), |
|
| 464 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 465 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 466 | + ), |
|
| 467 | + 'EE_Message_Resource_Manager' => array( |
|
| 468 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 469 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + ), |
|
| 472 | + 'EE_Message_Factory' => array( |
|
| 473 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 474 | + ), |
|
| 475 | + 'EE_messages' => array( |
|
| 476 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + ), |
|
| 478 | + 'EE_Messages_Generator' => array( |
|
| 479 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 480 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + ), |
|
| 484 | + 'EE_Messages_Processor' => array( |
|
| 485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EE_Messages_Queue' => array( |
|
| 488 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 489 | + ), |
|
| 490 | + 'EE_Messages_Template_Defaults' => array( |
|
| 491 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + ), |
|
| 494 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 497 | + ), |
|
| 498 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 499 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 502 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ), |
|
| 505 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 506 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 507 | + ), |
|
| 508 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 509 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 510 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + ), |
|
| 512 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 513 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 514 | + ), |
|
| 515 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 516 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 517 | + ), |
|
| 518 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 519 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 522 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 525 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 528 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ), |
|
| 530 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 531 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ), |
|
| 533 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 534 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + ), |
|
| 536 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 537 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ), |
|
| 539 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 540 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ), |
|
| 542 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 543 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 546 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ), |
|
| 548 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 549 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ), |
|
| 551 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 552 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ), |
|
| 554 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 557 | + ), |
|
| 558 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 561 | + ), |
|
| 562 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ), |
|
| 566 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 569 | + ), |
|
| 570 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 573 | + ), |
|
| 574 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + ), |
|
| 578 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 581 | + ), |
|
| 582 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + ), |
|
| 586 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 589 | + ), |
|
| 590 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 593 | + ), |
|
| 594 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 595 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 596 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 597 | + ), |
|
| 598 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 599 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 602 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ), |
|
| 604 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + ), |
|
| 607 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 608 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 609 | + ), |
|
| 610 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 611 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ), |
|
| 613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + ), |
|
| 616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | + ), |
|
| 619 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 620 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 621 | + ), |
|
| 622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 623 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 624 | + ), |
|
| 625 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 626 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 627 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ), |
|
| 629 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 630 | + null, |
|
| 631 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 632 | + ), |
|
| 633 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 634 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | + ), |
|
| 636 | + 'LEGACY_MODELS' => array( |
|
| 637 | + null, |
|
| 638 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 639 | + ), |
|
| 640 | + 'EE_Module_Request_Router' => array( |
|
| 641 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 642 | + ), |
|
| 643 | + 'EE_Registration_Processor' => array( |
|
| 644 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 645 | + ), |
|
| 646 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 647 | + null, |
|
| 648 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 649 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 650 | + ), |
|
| 651 | + ); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Registers how core classes are loaded. |
|
| 658 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 659 | + * 'EE_Request_Handler' => 'load_core' |
|
| 660 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 661 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 662 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 663 | + * 'Some_Class' => function () { |
|
| 664 | + * return new Some_Class(); |
|
| 665 | + * }, |
|
| 666 | + * This is required for instantiating dependencies |
|
| 667 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 668 | + * 'Required_Interface' => function () { |
|
| 669 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 670 | + * }, |
|
| 671 | + * |
|
| 672 | + * @throws InvalidInterfaceException |
|
| 673 | + * @throws InvalidDataTypeException |
|
| 674 | + * @throws InvalidArgumentException |
|
| 675 | + */ |
|
| 676 | + protected function _register_core_class_loaders() |
|
| 677 | + { |
|
| 678 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 679 | + //be used in a closure. |
|
| 680 | + $request = &$this->_request; |
|
| 681 | + $response = &$this->_response; |
|
| 682 | + // $loader = &$this->loader; |
|
| 683 | + $this->_class_loaders = array( |
|
| 684 | + //load_core |
|
| 685 | + 'EE_Capabilities' => 'load_core', |
|
| 686 | + 'EE_Encryption' => 'load_core', |
|
| 687 | + 'EE_Front_Controller' => 'load_core', |
|
| 688 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 689 | + 'EE_Registry' => 'load_core', |
|
| 690 | + 'EE_Request' => function () use (&$request) { |
|
| 691 | + return $request; |
|
| 692 | + }, |
|
| 693 | + 'EE_Response' => function () use (&$response) { |
|
| 694 | + return $response; |
|
| 695 | + }, |
|
| 696 | + 'EE_Request_Handler' => 'load_core', |
|
| 697 | + 'EE_Session' => 'load_core', |
|
| 698 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 699 | + 'EE_System' => 'load_core', |
|
| 700 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 701 | + 'EE_Register_CPTs' => 'load_core', |
|
| 702 | + 'EE_Admin' => 'load_core', |
|
| 703 | + //load_lib |
|
| 704 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 705 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 706 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 707 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 708 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 709 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 710 | + 'EE_Message_Repository' => 'load_lib', |
|
| 711 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 712 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 713 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 714 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 715 | + 'EE_Messages_Generator' => function () { |
|
| 716 | + return EE_Registry::instance()->load_lib( |
|
| 717 | + 'Messages_Generator', |
|
| 718 | + array(), |
|
| 719 | + false, |
|
| 720 | + false |
|
| 721 | + ); |
|
| 722 | + }, |
|
| 723 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 724 | + return EE_Registry::instance()->load_lib( |
|
| 725 | + 'Messages_Template_Defaults', |
|
| 726 | + $arguments, |
|
| 727 | + false, |
|
| 728 | + false |
|
| 729 | + ); |
|
| 730 | + }, |
|
| 731 | + //load_model |
|
| 732 | + // 'EEM_Attendee' => 'load_model', |
|
| 733 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
| 734 | + // 'EEM_Message_Template' => 'load_model', |
|
| 735 | + //load_helper |
|
| 736 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 737 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 738 | + return new EEH_Parse_Shortcodes(); |
|
| 739 | + } |
|
| 740 | + return null; |
|
| 741 | + }, |
|
| 742 | + 'EE_Template_Config' => function () { |
|
| 743 | + return EE_Config::instance()->template_settings; |
|
| 744 | + }, |
|
| 745 | + 'EE_Currency_Config' => function () { |
|
| 746 | + return EE_Config::instance()->currency; |
|
| 747 | + }, |
|
| 748 | + 'EE_Registration_Config' => function () { |
|
| 749 | + return EE_Config::instance()->registration; |
|
| 750 | + }, |
|
| 751 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 752 | + return LoaderFactory::getLoader(); |
|
| 753 | + }, |
|
| 754 | + ); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * can be used for supplying alternate names for classes, |
|
| 761 | + * or for connecting interface names to instantiable classes |
|
| 762 | + */ |
|
| 763 | + protected function _register_core_aliases() |
|
| 764 | + { |
|
| 765 | + $this->_aliases = array( |
|
| 766 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 767 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 768 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 769 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 770 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 771 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 772 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 773 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 774 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 775 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 776 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 777 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 778 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 779 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 780 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 781 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 782 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 783 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 784 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 785 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 786 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 787 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 788 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 789 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 790 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 791 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 792 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 793 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 794 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 795 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 796 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 797 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 798 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 799 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 800 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 801 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 802 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 803 | + ); |
|
| 804 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 805 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 813 | + * request Primarily used by unit tests. |
|
| 814 | + * |
|
| 815 | + * @throws InvalidDataTypeException |
|
| 816 | + * @throws InvalidInterfaceException |
|
| 817 | + * @throws InvalidArgumentException |
|
| 818 | + */ |
|
| 819 | + public function reset() |
|
| 820 | + { |
|
| 821 | + $this->_register_core_class_loaders(); |
|
| 822 | + $this->_register_core_dependencies(); |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | 825 | |
| 826 | 826 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | - * @return array |
|
| 73 | + * @return string[] |
|
| 74 | 74 | */ |
| 75 | 75 | public function __sleep() |
| 76 | 76 | { |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | use DomainException; |
| 8 | 8 | |
| 9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 10 | - exit('No direct script access allowed'); |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | |
@@ -25,154 +25,154 @@ discard block |
||
| 25 | 25 | class DbSafeDateTime extends DateTime |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @type string db_safe_timestamp_format |
|
| 30 | - */ |
|
| 31 | - const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
| 35 | - * |
|
| 36 | - * @type string $_datetime_string |
|
| 37 | - */ |
|
| 38 | - protected $_datetime_string = ''; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * where to write the error log to |
|
| 42 | - * |
|
| 43 | - * @type string $_error_log_dir |
|
| 44 | - */ |
|
| 45 | - protected $_error_log_dir = ''; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $error_log_dir |
|
| 51 | - */ |
|
| 52 | - public function setErrorLogDir($error_log_dir) |
|
| 53 | - { |
|
| 54 | - // if the folder path is writable, then except the path + filename, else keep empty |
|
| 55 | - $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
| 56 | - ? $error_log_dir |
|
| 57 | - : ''; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function __toString() |
|
| 66 | - { |
|
| 67 | - return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function __sleep() |
|
| 76 | - { |
|
| 77 | - $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 78 | - $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
|
| 79 | - $this->_datetime_string); |
|
| 80 | - if (! $date instanceof DateTime) { |
|
| 81 | - try { |
|
| 82 | - // we want a stack trace to determine where the malformed date came from, so... |
|
| 83 | - throw new DomainException(''); |
|
| 84 | - } catch (DomainException $e) { |
|
| 85 | - $stack_trace = $e->getTraceAsString(); |
|
| 86 | - } |
|
| 87 | - $this->writeToErrorLog( |
|
| 88 | - sprintf( |
|
| 89 | - __( |
|
| 90 | - 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
| 91 | - 'event_espresso' |
|
| 92 | - ), |
|
| 93 | - $this->_datetime_string, |
|
| 94 | - '<br />', |
|
| 95 | - print_r(DateTime::getLastErrors(), true), |
|
| 96 | - PHP_VERSION, |
|
| 97 | - $stack_trace |
|
| 98 | - ) |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - return array('_datetime_string'); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * if an empty or null value got saved to the db for a datetime, |
|
| 108 | - * then some servers and/or PHP itself will incorrectly convert that date string |
|
| 109 | - * resulting in "-0001-11-30" for the year-month-day. |
|
| 110 | - * see the Notes section |
|
| 111 | - * |
|
| 112 | - * @link http://php.net/manual/en/datetime.formats.date.php |
|
| 113 | - * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
| 114 | - * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
| 115 | - * so we're no better off, but at least things won't go fatal on us. |
|
| 116 | - */ |
|
| 117 | - public function __wakeup() |
|
| 118 | - { |
|
| 119 | - $this->_datetime_string = str_replace( |
|
| 120 | - array('-0001-11-29', '-0001-11-30'), |
|
| 121 | - '0000-00-00', |
|
| 122 | - $this->_datetime_string |
|
| 123 | - ); |
|
| 124 | - $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
|
| 125 | - $this->_datetime_string); |
|
| 126 | - if (! $date instanceof DateTime) { |
|
| 127 | - $this->writeToErrorLog( |
|
| 128 | - sprintf( |
|
| 129 | - __( |
|
| 130 | - 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
| 131 | - 'event_espresso' |
|
| 132 | - ), |
|
| 133 | - $this->_datetime_string, |
|
| 134 | - '<br />', |
|
| 135 | - print_r(DateTime::getLastErrors(), true), |
|
| 136 | - PHP_VERSION |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - } else { |
|
| 140 | - $this->__construct( |
|
| 141 | - $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 142 | - new DateTimeZone($date->format('e')) |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Creates a DbSafeDateTime from ye old DateTime |
|
| 150 | - * |
|
| 151 | - * @param DateTime $datetime |
|
| 152 | - * @return \EventEspresso\core\domain\entities\DbSafeDateTime |
|
| 153 | - */ |
|
| 154 | - public static function createFromDateTime(DateTime $datetime) |
|
| 155 | - { |
|
| 156 | - return new DbSafeDateTime( |
|
| 157 | - $datetime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 158 | - new DateTimeZone($datetime->format('e')) |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param string $message |
|
| 165 | - */ |
|
| 166 | - private function writeToErrorLog($message) |
|
| 167 | - { |
|
| 168 | - if (! empty($this->_error_log_dir)) { |
|
| 169 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
| 170 | - error_log($message, 3, $this->_error_log_dir); |
|
| 171 | - } else { |
|
| 172 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
| 173 | - error_log($message); |
|
| 174 | - } |
|
| 175 | - } |
|
| 28 | + /** |
|
| 29 | + * @type string db_safe_timestamp_format |
|
| 30 | + */ |
|
| 31 | + const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
| 35 | + * |
|
| 36 | + * @type string $_datetime_string |
|
| 37 | + */ |
|
| 38 | + protected $_datetime_string = ''; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * where to write the error log to |
|
| 42 | + * |
|
| 43 | + * @type string $_error_log_dir |
|
| 44 | + */ |
|
| 45 | + protected $_error_log_dir = ''; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $error_log_dir |
|
| 51 | + */ |
|
| 52 | + public function setErrorLogDir($error_log_dir) |
|
| 53 | + { |
|
| 54 | + // if the folder path is writable, then except the path + filename, else keep empty |
|
| 55 | + $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
| 56 | + ? $error_log_dir |
|
| 57 | + : ''; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function __toString() |
|
| 66 | + { |
|
| 67 | + return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function __sleep() |
|
| 76 | + { |
|
| 77 | + $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
| 78 | + $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
|
| 79 | + $this->_datetime_string); |
|
| 80 | + if (! $date instanceof DateTime) { |
|
| 81 | + try { |
|
| 82 | + // we want a stack trace to determine where the malformed date came from, so... |
|
| 83 | + throw new DomainException(''); |
|
| 84 | + } catch (DomainException $e) { |
|
| 85 | + $stack_trace = $e->getTraceAsString(); |
|
| 86 | + } |
|
| 87 | + $this->writeToErrorLog( |
|
| 88 | + sprintf( |
|
| 89 | + __( |
|
| 90 | + 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
| 91 | + 'event_espresso' |
|
| 92 | + ), |
|
| 93 | + $this->_datetime_string, |
|
| 94 | + '<br />', |
|
| 95 | + print_r(DateTime::getLastErrors(), true), |
|
| 96 | + PHP_VERSION, |
|
| 97 | + $stack_trace |
|
| 98 | + ) |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + return array('_datetime_string'); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * if an empty or null value got saved to the db for a datetime, |
|
| 108 | + * then some servers and/or PHP itself will incorrectly convert that date string |
|
| 109 | + * resulting in "-0001-11-30" for the year-month-day. |
|
| 110 | + * see the Notes section |
|
| 111 | + * |
|
| 112 | + * @link http://php.net/manual/en/datetime.formats.date.php |
|
| 113 | + * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
| 114 | + * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
| 115 | + * so we're no better off, but at least things won't go fatal on us. |
|
| 116 | + */ |
|
| 117 | + public function __wakeup() |
|
| 118 | + { |
|
| 119 | + $this->_datetime_string = str_replace( |
|
| 120 | + array('-0001-11-29', '-0001-11-30'), |
|
| 121 | + '0000-00-00', |
|
| 122 | + $this->_datetime_string |
|
| 123 | + ); |
|
| 124 | + $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
|
| 125 | + $this->_datetime_string); |
|
| 126 | + if (! $date instanceof DateTime) { |
|
| 127 | + $this->writeToErrorLog( |
|
| 128 | + sprintf( |
|
| 129 | + __( |
|
| 130 | + 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
| 131 | + 'event_espresso' |
|
| 132 | + ), |
|
| 133 | + $this->_datetime_string, |
|
| 134 | + '<br />', |
|
| 135 | + print_r(DateTime::getLastErrors(), true), |
|
| 136 | + PHP_VERSION |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + } else { |
|
| 140 | + $this->__construct( |
|
| 141 | + $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 142 | + new DateTimeZone($date->format('e')) |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Creates a DbSafeDateTime from ye old DateTime |
|
| 150 | + * |
|
| 151 | + * @param DateTime $datetime |
|
| 152 | + * @return \EventEspresso\core\domain\entities\DbSafeDateTime |
|
| 153 | + */ |
|
| 154 | + public static function createFromDateTime(DateTime $datetime) |
|
| 155 | + { |
|
| 156 | + return new DbSafeDateTime( |
|
| 157 | + $datetime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 158 | + new DateTimeZone($datetime->format('e')) |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param string $message |
|
| 165 | + */ |
|
| 166 | + private function writeToErrorLog($message) |
|
| 167 | + { |
|
| 168 | + if (! empty($this->_error_log_dir)) { |
|
| 169 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
| 170 | + error_log($message, 3, $this->_error_log_dir); |
|
| 171 | + } else { |
|
| 172 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
| 173 | + error_log($message); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | 177 | |
| 178 | 178 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | use DateTimeZone; |
| 7 | 7 | use DomainException; |
| 8 | 8 | |
| 9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | 10 | exit('No direct script access allowed'); |
| 11 | 11 | } |
| 12 | 12 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
| 78 | 78 | $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
| 79 | 79 | $this->_datetime_string); |
| 80 | - if (! $date instanceof DateTime) { |
|
| 80 | + if ( ! $date instanceof DateTime) { |
|
| 81 | 81 | try { |
| 82 | 82 | // we want a stack trace to determine where the malformed date came from, so... |
| 83 | 83 | throw new DomainException(''); |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | '0000-00-00', |
| 122 | 122 | $this->_datetime_string |
| 123 | 123 | ); |
| 124 | - $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
|
| 124 | + $date = DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, |
|
| 125 | 125 | $this->_datetime_string); |
| 126 | - if (! $date instanceof DateTime) { |
|
| 126 | + if ( ! $date instanceof DateTime) { |
|
| 127 | 127 | $this->writeToErrorLog( |
| 128 | 128 | sprintf( |
| 129 | 129 | __( |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | private function writeToErrorLog($message) |
| 167 | 167 | { |
| 168 | - if (! empty($this->_error_log_dir)) { |
|
| 168 | + if ( ! empty($this->_error_log_dir)) { |
|
| 169 | 169 | /** @noinspection ForgottenDebugOutputInspection */ |
| 170 | 170 | error_log($message, 3, $this->_error_log_dir); |
| 171 | 171 | } else { |
@@ -14,9 +14,9 @@ |
||
| 14 | 14 | * @param array $options |
| 15 | 15 | */ |
| 16 | 16 | public function __construct($options = array()){ |
| 17 | - if( empty($options['default'])) { |
|
| 18 | - $options['default'] = esc_html__('Submit', 'event_espresso'); |
|
| 19 | - } |
|
| 17 | + if( empty($options['default'])) { |
|
| 18 | + $options['default'] = esc_html__('Submit', 'event_espresso'); |
|
| 19 | + } |
|
| 20 | 20 | $this->_set_display_strategy(new EE_Submit_Input_Display_Strategy()); |
| 21 | 21 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
| 22 | 22 | $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() ); |
@@ -8,18 +8,18 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * This input has a default validation strategy of plaintext (which can be removed after construction) |
| 10 | 10 | */ |
| 11 | -class EE_Submit_Input extends EE_Form_Input_Base{ |
|
| 11 | +class EE_Submit_Input extends EE_Form_Input_Base { |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @param array $options |
| 15 | 15 | */ |
| 16 | - public function __construct($options = array()){ |
|
| 17 | - if( empty($options['default'])) { |
|
| 16 | + public function __construct($options = array()) { |
|
| 17 | + if (empty($options['default'])) { |
|
| 18 | 18 | $options['default'] = esc_html__('Submit', 'event_espresso'); |
| 19 | 19 | } |
| 20 | 20 | $this->_set_display_strategy(new EE_Submit_Input_Display_Strategy()); |
| 21 | 21 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
| 22 | - $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() ); |
|
| 22 | + $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy()); |
|
| 23 | 23 | parent::__construct($options); |
| 24 | 24 | } |
| 25 | 25 | } |