@@ -222,7 +222,7 @@ |
||
| 222 | 222 | /** |
| 223 | 223 | * constructor |
| 224 | 224 | * |
| 225 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 225 | + * @param EE_Admin_Page $adminpage the calling admin_page_object |
|
| 226 | 226 | */ |
| 227 | 227 | public function __construct(EE_Admin_Page $adminpage) |
| 228 | 228 | { |
@@ -13,707 +13,707 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * we're just going to use this to hold the name of the caller class (child class name) |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $caller; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
| 26 | - * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
| 27 | - * used later to make sure we require the needed files. |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - */ |
|
| 31 | - protected $_extend; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * child classes MUST set this property so that the page object can be loaded correctly |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $_name; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * This is set by child classes and is an associative array of ajax hooks in the format: |
|
| 44 | - * array( |
|
| 45 | - * 'ajax_action_ref' => 'executing_method'; //must be public |
|
| 46 | - * ) |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $_ajax_func; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
| 55 | - * array( |
|
| 56 | - * 'page_route' => 'executing_method' //must be public |
|
| 57 | - * ) |
|
| 58 | - * |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - protected $_init_func; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
| 66 | - * array( |
|
| 67 | - * 0 => array( |
|
| 68 | - * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
| 69 | - * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
| 70 | - * will be added to each route. |
|
| 71 | - * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
| 72 | - * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
| 73 | - * method arguments. |
|
| 74 | - * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
| 75 | - * automatically) |
|
| 76 | - * 'priority' => 'default', //default 'default' (optional) |
|
| 77 | - * 'label' => __('Localized Title', 'event_espresso'), |
|
| 78 | - * 'context' => 'advanced' //advanced is default (optional), |
|
| 79 | - * 'callback_args' => array() //any callback args to include (optional) |
|
| 80 | - * ) |
|
| 81 | - * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - protected $_metaboxes; |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
| 90 | - * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
| 91 | - * array: array( |
|
| 92 | - * 0 => array( |
|
| 93 | - * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
| 94 | - * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
| 95 | - * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
| 96 | - * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
| 97 | - * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
| 98 | - * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
| 99 | - * id for the screen the metabox is on. |
|
| 100 | - * ) |
|
| 101 | - * ) |
|
| 102 | - * |
|
| 103 | - * @var array |
|
| 104 | - */ |
|
| 105 | - protected $_remove_metaboxes; |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
| 110 | - * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
| 111 | - * second array index is for indicating what routes each script/style loads on. array( |
|
| 112 | - * 'registers' => array( |
|
| 113 | - * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
| 114 | - * argument to link scripts together. |
|
| 115 | - * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
| 116 | - * 'url' => 'http://urltoscript.css.js', |
|
| 117 | - * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
| 118 | - * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
| 119 | - * gets loaded before the one you are setting here. |
|
| 120 | - * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
| 121 | - * ), |
|
| 122 | - * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
| 123 | - * the script gets enqueued on. |
|
| 124 | - * 'script_ref' => array('route_one', 'route_two') |
|
| 125 | - * ), |
|
| 126 | - * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
| 127 | - * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
| 128 | - * the object. |
|
| 129 | - * 'scrip_ref' => array( |
|
| 130 | - * 'NAME_OF_JS_OBJECT' => array( |
|
| 131 | - * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
| 132 | - * 'some_data' => 5 |
|
| 133 | - * ) |
|
| 134 | - * ) |
|
| 135 | - * ) |
|
| 136 | - * ) |
|
| 137 | - * |
|
| 138 | - * @var array |
|
| 139 | - */ |
|
| 140 | - protected $_scripts_styles; |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * This is a property that will contain the current route. |
|
| 145 | - * |
|
| 146 | - * @var string; |
|
| 147 | - */ |
|
| 148 | - protected $_current_route; |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
| 153 | - * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
| 154 | - * 'wp_hook_reference' => 1 |
|
| 155 | - * ) |
|
| 156 | - * ) |
|
| 157 | - * |
|
| 158 | - * @var array |
|
| 159 | - */ |
|
| 160 | - protected $_wp_action_filters_priority; |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
| 165 | - * |
|
| 166 | - * @var array |
|
| 167 | - */ |
|
| 168 | - protected $_req_data; |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * This just holds an instance of the page object for this hook |
|
| 173 | - * |
|
| 174 | - * @var EE_Admin_Page |
|
| 175 | - */ |
|
| 176 | - protected $_page_object; |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
| 181 | - * |
|
| 182 | - * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
| 183 | - */ |
|
| 184 | - protected $_adminpage_obj; |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Holds EE_Registry object |
|
| 189 | - * |
|
| 190 | - * @var EE_Registry |
|
| 191 | - */ |
|
| 192 | - protected $EE = null; |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * constructor |
|
| 197 | - * |
|
| 198 | - * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 199 | - */ |
|
| 200 | - public function __construct(EE_Admin_Page $adminpage) |
|
| 201 | - { |
|
| 202 | - |
|
| 203 | - $this->_adminpage_obj = $adminpage; |
|
| 204 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 205 | - $this->_set_defaults(); |
|
| 206 | - $this->_set_hooks_properties(); |
|
| 207 | - // first let's verify we're on the right page |
|
| 208 | - if (! isset($this->_req_data['page']) |
|
| 209 | - || (isset($this->_req_data['page']) |
|
| 210 | - && $this->_adminpage_obj->page_slug |
|
| 211 | - != $this->_req_data['page'])) { |
|
| 212 | - return; |
|
| 213 | - } //get out nothing more to be done here. |
|
| 214 | - // allow for extends to modify properties |
|
| 215 | - if (method_exists($this, '_extend_properties')) { |
|
| 216 | - $this->_extend_properties(); |
|
| 217 | - } |
|
| 218 | - $this->_set_page_object(); |
|
| 219 | - $this->_init_hooks(); |
|
| 220 | - $this->_load_custom_methods(); |
|
| 221 | - $this->_load_routed_hooks(); |
|
| 222 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
| 223 | - add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
| 224 | - add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
| 225 | - $this->_ajax_hooks(); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * used by child classes to set the following properties: |
|
| 231 | - * $_ajax_func (optional) |
|
| 232 | - * $_init_func (optional) |
|
| 233 | - * $_metaboxes (optional) |
|
| 234 | - * $_scripts (optional) |
|
| 235 | - * $_styles (optional) |
|
| 236 | - * $_name (required) |
|
| 237 | - * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
| 238 | - * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
| 239 | - * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
| 240 | - * |
|
| 241 | - * @access protected |
|
| 242 | - * @abstract |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - abstract protected function _set_hooks_properties(); |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
| 250 | - * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
| 251 | - * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
| 252 | - * |
|
| 253 | - * @access public |
|
| 254 | - * @return void |
|
| 255 | - */ |
|
| 256 | - public function enqueue_scripts_styles() |
|
| 257 | - { |
|
| 258 | - |
|
| 259 | - if (! empty($this->_scripts_styles)) { |
|
| 260 | - // first let's do all the registrations |
|
| 261 | - if (! isset($this->_scripts_styles['registers'])) { |
|
| 262 | - $msg[] = __( |
|
| 263 | - 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
| 264 | - 'event_espresso' |
|
| 265 | - ); |
|
| 266 | - $msg[] = sprintf( |
|
| 267 | - __( |
|
| 268 | - 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ), |
|
| 271 | - '<strong>' . $this->caller . '</strong>' |
|
| 272 | - ); |
|
| 273 | - throw new EE_Error(implode('||', $msg)); |
|
| 274 | - } |
|
| 275 | - foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
| 276 | - $defaults = array( |
|
| 277 | - 'type' => 'js', |
|
| 278 | - 'url' => '', |
|
| 279 | - 'depends' => array(), |
|
| 280 | - 'version' => EVENT_ESPRESSO_VERSION, |
|
| 281 | - 'footer' => true, |
|
| 282 | - ); |
|
| 283 | - $details = wp_parse_args($details, $defaults); |
|
| 284 | - extract($details); |
|
| 285 | - // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
| 286 | - $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
| 287 | - // let's make sure we're not missing any REQUIRED parameters |
|
| 288 | - if (empty($url)) { |
|
| 289 | - $msg[] = sprintf( |
|
| 290 | - __('Missing the url for the requested %s', 'event_espresso'), |
|
| 291 | - $type == 'js' ? 'script' : 'stylesheet' |
|
| 292 | - ); |
|
| 293 | - $msg[] = sprintf( |
|
| 294 | - __( |
|
| 295 | - 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
| 296 | - 'event_espresso' |
|
| 297 | - ), |
|
| 298 | - '<strong>' . $this->caller . '</strong>', |
|
| 299 | - $ref |
|
| 300 | - ); |
|
| 301 | - throw new EE_Error(implode('||', $msg)); |
|
| 302 | - } |
|
| 303 | - // made it here so let's do the appropriate registration |
|
| 304 | - $type == 'js' |
|
| 305 | - ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
| 306 | - : wp_register_style( |
|
| 307 | - $ref, |
|
| 308 | - $url, |
|
| 309 | - $depends, |
|
| 310 | - $version |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - // k now lets do the enqueues |
|
| 314 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 315 | - return; |
|
| 316 | - } //not sure if we should throw an error here or not. |
|
| 317 | - foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
| 318 | - // make sure $routes is an array |
|
| 319 | - $routes = (array) $routes; |
|
| 320 | - if (in_array($this->_current_route, $routes)) { |
|
| 321 | - $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 322 | - : wp_enqueue_style($ref); |
|
| 323 | - // if we have a localization for the script let's do that too. |
|
| 324 | - if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
| 325 | - foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
| 326 | - wp_localize_script( |
|
| 327 | - $ref, |
|
| 328 | - $object_name, |
|
| 329 | - $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - // let's do the deregisters |
|
| 336 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 337 | - return; |
|
| 338 | - } |
|
| 339 | - foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
| 340 | - $defaults = array( |
|
| 341 | - 'type' => 'js', |
|
| 342 | - ); |
|
| 343 | - $details = wp_parse_args($details, $defaults); |
|
| 344 | - extract($details); |
|
| 345 | - $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * just set the defaults for the hooks properties. |
|
| 353 | - * |
|
| 354 | - * @access private |
|
| 355 | - * @return void |
|
| 356 | - */ |
|
| 357 | - private function _set_defaults() |
|
| 358 | - { |
|
| 359 | - $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
| 360 | - $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 361 | - $this->caller = get_class($this); |
|
| 362 | - $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * this sets the _page_object property |
|
| 368 | - * |
|
| 369 | - * @access protected |
|
| 370 | - * @return void |
|
| 371 | - */ |
|
| 372 | - protected function _set_page_object() |
|
| 373 | - { |
|
| 374 | - // first make sure $this->_name is set |
|
| 375 | - if (empty($this->_name)) { |
|
| 376 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 377 | - $msg[] = sprintf( |
|
| 378 | - __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
| 379 | - $this->caller |
|
| 380 | - ); |
|
| 381 | - throw new EE_Error(implode('||', $msg)); |
|
| 382 | - } |
|
| 383 | - $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
|
| 384 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
| 385 | - // first default file (if exists) |
|
| 386 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
| 387 | - if (is_readable($decaf_file)) { |
|
| 388 | - require_once($decaf_file); |
|
| 389 | - } |
|
| 390 | - // now we have to do require for extended file (if needed) |
|
| 391 | - if ($this->_extend) { |
|
| 392 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
| 393 | - } |
|
| 394 | - // if we've got an extended class we use that! |
|
| 395 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 396 | - // let's make sure the class exists |
|
| 397 | - if (! class_exists($ref)) { |
|
| 398 | - $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 399 | - $msg[] = sprintf( |
|
| 400 | - __( |
|
| 401 | - 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
| 402 | - 'event_espresso' |
|
| 403 | - ), |
|
| 404 | - $ref |
|
| 405 | - ); |
|
| 406 | - throw new EE_Error(implode('||', $msg)); |
|
| 407 | - } |
|
| 408 | - $a = new ReflectionClass($ref); |
|
| 409 | - $this->_page_object = $a->newInstance(false); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
| 415 | - * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
| 416 | - * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
| 417 | - * |
|
| 418 | - * @access private |
|
| 419 | - * @return void |
|
| 420 | - */ |
|
| 421 | - private function _load_custom_methods() |
|
| 422 | - { |
|
| 423 | - /** |
|
| 424 | - * method cannot be named 'default' (@see http://us3.php |
|
| 425 | - * .net/manual/en/reserved.keywords.php) so need to |
|
| 426 | - * handle routes that are "default" |
|
| 427 | - * |
|
| 428 | - * @since 4.3.0 |
|
| 429 | - */ |
|
| 430 | - $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
| 431 | - // these run before the Admin_Page route executes. |
|
| 432 | - if (method_exists($this, $method_callback)) { |
|
| 433 | - call_user_func(array($this, $method_callback)); |
|
| 434 | - } |
|
| 435 | - // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
| 436 | - // first the actions |
|
| 437 | - // note that these action hooks will have the $query_args value available. |
|
| 438 | - $admin_class_name = get_class($this->_adminpage_obj); |
|
| 439 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 440 | - add_action( |
|
| 441 | - 'AHEE__' |
|
| 442 | - . $admin_class_name |
|
| 443 | - . '___redirect_after_action__before_redirect_modification_' |
|
| 444 | - . $this->_current_route, |
|
| 445 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 446 | - 10 |
|
| 447 | - ); |
|
| 448 | - } |
|
| 449 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 450 | - add_action( |
|
| 451 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 452 | - array($this, '_redirect_action_' . $this->_current_route), |
|
| 453 | - 10 |
|
| 454 | - ); |
|
| 455 | - } |
|
| 456 | - // let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
| 457 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 458 | - add_filter( |
|
| 459 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 460 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
| 461 | - 10, |
|
| 462 | - 2 |
|
| 463 | - ); |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
| 470 | - * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
| 471 | - * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
| 472 | - * |
|
| 473 | - * @return void |
|
| 474 | - */ |
|
| 475 | - private function _load_routed_hooks() |
|
| 476 | - { |
|
| 477 | - |
|
| 478 | - // this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
| 479 | - $hook_filter_array = array( |
|
| 480 | - 'admin_footer' => array( |
|
| 481 | - 'type' => 'action', |
|
| 482 | - 'argnum' => 1, |
|
| 483 | - 'priority' => 10, |
|
| 484 | - ), |
|
| 485 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 486 | - 'type' => 'filter', |
|
| 487 | - 'argnum' => 1, |
|
| 488 | - 'priority' => 10, |
|
| 489 | - ), |
|
| 490 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 491 | - 'type' => 'filter', |
|
| 492 | - 'argnum' => 1, |
|
| 493 | - 'priority' => 10, |
|
| 494 | - ), |
|
| 495 | - 'FHEE_list_table_views' => array( |
|
| 496 | - 'type' => 'filter', |
|
| 497 | - 'argnum' => 1, |
|
| 498 | - 'priority' => 10, |
|
| 499 | - ), |
|
| 500 | - 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
| 501 | - 'type' => 'action', |
|
| 502 | - 'argnum' => 1, |
|
| 503 | - 'priority' => 10, |
|
| 504 | - ), |
|
| 505 | - ); |
|
| 506 | - foreach ($hook_filter_array as $hook => $args) { |
|
| 507 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 508 | - if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
| 509 | - $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
| 510 | - } |
|
| 511 | - if ($args['type'] == 'action') { |
|
| 512 | - add_action( |
|
| 513 | - $hook, |
|
| 514 | - array($this, $this->_current_route . '_' . $hook), |
|
| 515 | - $args['priority'], |
|
| 516 | - $args['argnum'] |
|
| 517 | - ); |
|
| 518 | - } else { |
|
| 519 | - add_filter( |
|
| 520 | - $hook, |
|
| 521 | - array($this, $this->_current_route . '_' . $hook), |
|
| 522 | - $args['priority'], |
|
| 523 | - $args['argnum'] |
|
| 524 | - ); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Loop throught the $_ajax_func array and add_actions for the array. |
|
| 533 | - * |
|
| 534 | - * @return void |
|
| 535 | - */ |
|
| 536 | - private function _ajax_hooks() |
|
| 537 | - { |
|
| 538 | - |
|
| 539 | - if (empty($this->_ajax_func)) { |
|
| 540 | - return; |
|
| 541 | - } //get out there's nothing to take care of. |
|
| 542 | - foreach ($this->_ajax_func as $action => $method) { |
|
| 543 | - // make sure method exists |
|
| 544 | - if (! method_exists($this, $method)) { |
|
| 545 | - $msg[] = __( |
|
| 546 | - 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
| 547 | - 'event_espresso' |
|
| 548 | - ) . '<br />'; |
|
| 549 | - $msg[] = sprintf( |
|
| 550 | - __( |
|
| 551 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 552 | - 'event_espresso' |
|
| 553 | - ), |
|
| 554 | - $method, |
|
| 555 | - $this->caller |
|
| 556 | - ); |
|
| 557 | - throw new EE_Error(implode('||', $msg)); |
|
| 558 | - } |
|
| 559 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Loop throught the $_init_func array and add_actions for the array. |
|
| 566 | - * |
|
| 567 | - * @return void |
|
| 568 | - */ |
|
| 569 | - protected function _init_hooks() |
|
| 570 | - { |
|
| 571 | - if (empty($this->_init_func)) { |
|
| 572 | - return; |
|
| 573 | - } //get out there's nothing to take care of. |
|
| 574 | - // We need to determine what page_route we are on! |
|
| 575 | - $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 576 | - foreach ($this->_init_func as $route => $method) { |
|
| 577 | - // make sure method exists |
|
| 578 | - if (! method_exists($this, $method)) { |
|
| 579 | - $msg[] = __( |
|
| 580 | - 'There is no corresponding method for the hook labeled in the _init_func array', |
|
| 581 | - 'event_espresso' |
|
| 582 | - ) . '<br />'; |
|
| 583 | - $msg[] = sprintf( |
|
| 584 | - __( |
|
| 585 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 586 | - 'event_espresso' |
|
| 587 | - ), |
|
| 588 | - $method, |
|
| 589 | - $this->caller |
|
| 590 | - ); |
|
| 591 | - throw new EE_Error(implode('||', $msg)); |
|
| 592 | - } |
|
| 593 | - if ($route == $this->_current_route) { |
|
| 594 | - add_action('admin_init', array($this, $method)); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Loop through the _metaboxes property and add_metaboxes accordingly |
|
| 602 | - * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
| 603 | - * |
|
| 604 | - * @access public |
|
| 605 | - * @return void |
|
| 606 | - */ |
|
| 607 | - public function add_metaboxes() |
|
| 608 | - { |
|
| 609 | - if (empty($this->_metaboxes)) { |
|
| 610 | - return; |
|
| 611 | - } //get out we don't have any metaboxes to set for this connection |
|
| 612 | - $this->_handle_metabox_array($this->_metaboxes); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - private function _handle_metabox_array($boxes, $add = true) |
|
| 617 | - { |
|
| 618 | - |
|
| 619 | - foreach ($boxes as $box) { |
|
| 620 | - if (! isset($box['page_route'])) { |
|
| 621 | - continue; |
|
| 622 | - } //we dont' have a valid array |
|
| 623 | - // let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
| 624 | - $box['page_route'] = (array) $box['page_route']; |
|
| 625 | - foreach ($box['page_route'] as $route) { |
|
| 626 | - if ($route != $this->_current_route) { |
|
| 627 | - continue; |
|
| 628 | - } //get out we only add metaboxes for set route. |
|
| 629 | - if ($add) { |
|
| 630 | - $this->_add_metabox($box); |
|
| 631 | - } else { |
|
| 632 | - $this->_remove_metabox($box); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
| 641 | - * |
|
| 642 | - * @access public |
|
| 643 | - * @return void |
|
| 644 | - */ |
|
| 645 | - public function remove_metaboxes() |
|
| 646 | - { |
|
| 647 | - |
|
| 648 | - if (empty($this->_remove_metaboxes)) { |
|
| 649 | - return; |
|
| 650 | - } //get out there are no metaboxes to remove |
|
| 651 | - $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * This just handles adding a metabox |
|
| 657 | - * |
|
| 658 | - * @access private |
|
| 659 | - * @param array $args an array of args that have been set for this metabox by the child class |
|
| 660 | - */ |
|
| 661 | - private function _add_metabox($args) |
|
| 662 | - { |
|
| 663 | - $current_screen = get_current_screen(); |
|
| 664 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 665 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 666 | - // set defaults |
|
| 667 | - $defaults = array( |
|
| 668 | - 'func' => $func, |
|
| 669 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 670 | - 'priority' => 'default', |
|
| 671 | - 'label' => $this->caller, |
|
| 672 | - 'context' => 'advanced', |
|
| 673 | - 'callback_args' => array(), |
|
| 674 | - 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
| 675 | - ); |
|
| 676 | - $args = wp_parse_args($args, $defaults); |
|
| 677 | - extract($args); |
|
| 678 | - // make sure method exists |
|
| 679 | - if (! method_exists($this, $func)) { |
|
| 680 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 681 | - $msg[] = sprintf( |
|
| 682 | - __( |
|
| 683 | - 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 684 | - 'event_espresso' |
|
| 685 | - ), |
|
| 686 | - $func, |
|
| 687 | - $this->caller |
|
| 688 | - ); |
|
| 689 | - throw new EE_Error(implode('||', $msg)); |
|
| 690 | - } |
|
| 691 | - // everything checks out so lets add the metabox |
|
| 692 | - add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - private function _remove_metabox($args) |
|
| 697 | - { |
|
| 698 | - $current_screen = get_current_screen(); |
|
| 699 | - $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 700 | - $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 701 | - // set defaults |
|
| 702 | - $defaults = array( |
|
| 703 | - 'id' => isset($args['id']) |
|
| 704 | - ? $args['id'] |
|
| 705 | - : $this->_current_route |
|
| 706 | - . '_' |
|
| 707 | - . $this->caller |
|
| 708 | - . '_' |
|
| 709 | - . $func |
|
| 710 | - . '_metabox', |
|
| 711 | - 'context' => 'default', |
|
| 712 | - 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id, |
|
| 713 | - ); |
|
| 714 | - $args = wp_parse_args($args, $defaults); |
|
| 715 | - extract($args); |
|
| 716 | - // everything checks out so lets remove the box! |
|
| 717 | - remove_meta_box($id, $screen, $context); |
|
| 718 | - } |
|
| 16 | + /** |
|
| 17 | + * we're just going to use this to hold the name of the caller class (child class name) |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $caller; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e. |
|
| 26 | + * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks). This flag is |
|
| 27 | + * used later to make sure we require the needed files. |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + */ |
|
| 31 | + protected $_extend; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * child classes MUST set this property so that the page object can be loaded correctly |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $_name; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * This is set by child classes and is an associative array of ajax hooks in the format: |
|
| 44 | + * array( |
|
| 45 | + * 'ajax_action_ref' => 'executing_method'; //must be public |
|
| 46 | + * ) |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $_ajax_func; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * This is an array of methods that get executed on a page routes admin_init hook. Use the following format: |
|
| 55 | + * array( |
|
| 56 | + * 'page_route' => 'executing_method' //must be public |
|
| 57 | + * ) |
|
| 58 | + * |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + protected $_init_func; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * This is an array of methods that output metabox content for the given page route. Use the following format: |
|
| 66 | + * array( |
|
| 67 | + * 0 => array( |
|
| 68 | + * 'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected |
|
| 69 | + * with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox |
|
| 70 | + * will be added to each route. |
|
| 71 | + * 'func' => 'executing_method', //must be public (i.e. public function executing_method($post, |
|
| 72 | + * $callback_args){} ). Note if you include callback args in the array then you need to declare them in the |
|
| 73 | + * method arguments. |
|
| 74 | + * 'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it |
|
| 75 | + * automatically) |
|
| 76 | + * 'priority' => 'default', //default 'default' (optional) |
|
| 77 | + * 'label' => __('Localized Title', 'event_espresso'), |
|
| 78 | + * 'context' => 'advanced' //advanced is default (optional), |
|
| 79 | + * 'callback_args' => array() //any callback args to include (optional) |
|
| 80 | + * ) |
|
| 81 | + * Why are we indexing numerically? Because it's possible there may be more than one metabox per page_route. |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + protected $_metaboxes; |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * This is an array of values that indicate any metaboxes we want removed from a given page route. Usually this is |
|
| 90 | + * used when caffeinated functionality is replacing decaffeinated functionality. Use the following format for the |
|
| 91 | + * array: array( |
|
| 92 | + * 0 => array( |
|
| 93 | + * 'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s) |
|
| 94 | + * that are in the class being connected with (i.e. 'edit', or 'create_new'). |
|
| 95 | + * 'id' => 'identifier_for_metabox', //what the id is of the metabox being removed |
|
| 96 | + * 'context' => 'normal', //the context for the metabox being removed (has to match) |
|
| 97 | + * 'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox |
|
| 98 | + * using the currently loaded screen object->id however, there may be cases where you have to specify the |
|
| 99 | + * id for the screen the metabox is on. |
|
| 100 | + * ) |
|
| 101 | + * ) |
|
| 102 | + * |
|
| 103 | + * @var array |
|
| 104 | + */ |
|
| 105 | + protected $_remove_metaboxes; |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * This parent class takes care of loading the scripts and styles if the child class has set the properties for |
|
| 110 | + * them in the following format. Note, the first array index ('register') is for defining all the registers. The |
|
| 111 | + * second array index is for indicating what routes each script/style loads on. array( |
|
| 112 | + * 'registers' => array( |
|
| 113 | + * 'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency' |
|
| 114 | + * argument to link scripts together. |
|
| 115 | + * 'type' => 'js' // 'js' or 'css' (defaults to js). This tells us what type of wp_function to use |
|
| 116 | + * 'url' => 'http://urltoscript.css.js', |
|
| 117 | + * 'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has |
|
| 118 | + * already been registered elsewhere in the system. You can just use the depends array to make sure it |
|
| 119 | + * gets loaded before the one you are setting here. |
|
| 120 | + * 'footer' => TRUE //defaults to true (styles don't use this parameter) |
|
| 121 | + * ), |
|
| 122 | + * 'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes |
|
| 123 | + * the script gets enqueued on. |
|
| 124 | + * 'script_ref' => array('route_one', 'route_two') |
|
| 125 | + * ), |
|
| 126 | + * 'localize' => array( //this allows you to set a localize object. Indicate which script the object is being |
|
| 127 | + * attached to and then include an array indexed by the name of the object and the array of key/value pairs for |
|
| 128 | + * the object. |
|
| 129 | + * 'scrip_ref' => array( |
|
| 130 | + * 'NAME_OF_JS_OBJECT' => array( |
|
| 131 | + * 'translate_ref' => __('localized_string', 'event_espresso'), |
|
| 132 | + * 'some_data' => 5 |
|
| 133 | + * ) |
|
| 134 | + * ) |
|
| 135 | + * ) |
|
| 136 | + * ) |
|
| 137 | + * |
|
| 138 | + * @var array |
|
| 139 | + */ |
|
| 140 | + protected $_scripts_styles; |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * This is a property that will contain the current route. |
|
| 145 | + * |
|
| 146 | + * @var string; |
|
| 147 | + */ |
|
| 148 | + protected $_current_route; |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * this optional property can be set by child classes to override the priority for the automatic action/filter hook |
|
| 153 | + * loading in the `_load_routed_hooks()` method. Please follow this format: array( |
|
| 154 | + * 'wp_hook_reference' => 1 |
|
| 155 | + * ) |
|
| 156 | + * ) |
|
| 157 | + * |
|
| 158 | + * @var array |
|
| 159 | + */ |
|
| 160 | + protected $_wp_action_filters_priority; |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST |
|
| 165 | + * |
|
| 166 | + * @var array |
|
| 167 | + */ |
|
| 168 | + protected $_req_data; |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * This just holds an instance of the page object for this hook |
|
| 173 | + * |
|
| 174 | + * @var EE_Admin_Page |
|
| 175 | + */ |
|
| 176 | + protected $_page_object; |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * This holds the EE_Admin_Page object from the calling admin page that this object hooks into. |
|
| 181 | + * |
|
| 182 | + * @var EE_Admin_Page|EE_Admin_Page_CPT |
|
| 183 | + */ |
|
| 184 | + protected $_adminpage_obj; |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Holds EE_Registry object |
|
| 189 | + * |
|
| 190 | + * @var EE_Registry |
|
| 191 | + */ |
|
| 192 | + protected $EE = null; |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * constructor |
|
| 197 | + * |
|
| 198 | + * @param EE_Admin_Page $admin_page the calling admin_page_object |
|
| 199 | + */ |
|
| 200 | + public function __construct(EE_Admin_Page $adminpage) |
|
| 201 | + { |
|
| 202 | + |
|
| 203 | + $this->_adminpage_obj = $adminpage; |
|
| 204 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 205 | + $this->_set_defaults(); |
|
| 206 | + $this->_set_hooks_properties(); |
|
| 207 | + // first let's verify we're on the right page |
|
| 208 | + if (! isset($this->_req_data['page']) |
|
| 209 | + || (isset($this->_req_data['page']) |
|
| 210 | + && $this->_adminpage_obj->page_slug |
|
| 211 | + != $this->_req_data['page'])) { |
|
| 212 | + return; |
|
| 213 | + } //get out nothing more to be done here. |
|
| 214 | + // allow for extends to modify properties |
|
| 215 | + if (method_exists($this, '_extend_properties')) { |
|
| 216 | + $this->_extend_properties(); |
|
| 217 | + } |
|
| 218 | + $this->_set_page_object(); |
|
| 219 | + $this->_init_hooks(); |
|
| 220 | + $this->_load_custom_methods(); |
|
| 221 | + $this->_load_routed_hooks(); |
|
| 222 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
| 223 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
| 224 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
| 225 | + $this->_ajax_hooks(); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * used by child classes to set the following properties: |
|
| 231 | + * $_ajax_func (optional) |
|
| 232 | + * $_init_func (optional) |
|
| 233 | + * $_metaboxes (optional) |
|
| 234 | + * $_scripts (optional) |
|
| 235 | + * $_styles (optional) |
|
| 236 | + * $_name (required) |
|
| 237 | + * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the |
|
| 238 | + * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen |
|
| 239 | + * really early on page load (just after admin_init) if they want to have them registered for handling early. |
|
| 240 | + * |
|
| 241 | + * @access protected |
|
| 242 | + * @abstract |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + abstract protected function _set_hooks_properties(); |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * The hooks for enqueue_scripts and enqueue_styles will be run in here. Child classes need to define their |
|
| 250 | + * scripts and styles in the relevant $_scripts and $_styles properties. Child classes must have also already |
|
| 251 | + * registered the scripts and styles using wp_register_script and wp_register_style functions. |
|
| 252 | + * |
|
| 253 | + * @access public |
|
| 254 | + * @return void |
|
| 255 | + */ |
|
| 256 | + public function enqueue_scripts_styles() |
|
| 257 | + { |
|
| 258 | + |
|
| 259 | + if (! empty($this->_scripts_styles)) { |
|
| 260 | + // first let's do all the registrations |
|
| 261 | + if (! isset($this->_scripts_styles['registers'])) { |
|
| 262 | + $msg[] = __( |
|
| 263 | + 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
|
| 264 | + 'event_espresso' |
|
| 265 | + ); |
|
| 266 | + $msg[] = sprintf( |
|
| 267 | + __( |
|
| 268 | + 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ), |
|
| 271 | + '<strong>' . $this->caller . '</strong>' |
|
| 272 | + ); |
|
| 273 | + throw new EE_Error(implode('||', $msg)); |
|
| 274 | + } |
|
| 275 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
| 276 | + $defaults = array( |
|
| 277 | + 'type' => 'js', |
|
| 278 | + 'url' => '', |
|
| 279 | + 'depends' => array(), |
|
| 280 | + 'version' => EVENT_ESPRESSO_VERSION, |
|
| 281 | + 'footer' => true, |
|
| 282 | + ); |
|
| 283 | + $details = wp_parse_args($details, $defaults); |
|
| 284 | + extract($details); |
|
| 285 | + // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
|
| 286 | + $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
| 287 | + // let's make sure we're not missing any REQUIRED parameters |
|
| 288 | + if (empty($url)) { |
|
| 289 | + $msg[] = sprintf( |
|
| 290 | + __('Missing the url for the requested %s', 'event_espresso'), |
|
| 291 | + $type == 'js' ? 'script' : 'stylesheet' |
|
| 292 | + ); |
|
| 293 | + $msg[] = sprintf( |
|
| 294 | + __( |
|
| 295 | + 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
|
| 296 | + 'event_espresso' |
|
| 297 | + ), |
|
| 298 | + '<strong>' . $this->caller . '</strong>', |
|
| 299 | + $ref |
|
| 300 | + ); |
|
| 301 | + throw new EE_Error(implode('||', $msg)); |
|
| 302 | + } |
|
| 303 | + // made it here so let's do the appropriate registration |
|
| 304 | + $type == 'js' |
|
| 305 | + ? wp_register_script($ref, $url, $depends, $version, $footer) |
|
| 306 | + : wp_register_style( |
|
| 307 | + $ref, |
|
| 308 | + $url, |
|
| 309 | + $depends, |
|
| 310 | + $version |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + // k now lets do the enqueues |
|
| 314 | + if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 315 | + return; |
|
| 316 | + } //not sure if we should throw an error here or not. |
|
| 317 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
| 318 | + // make sure $routes is an array |
|
| 319 | + $routes = (array) $routes; |
|
| 320 | + if (in_array($this->_current_route, $routes)) { |
|
| 321 | + $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 322 | + : wp_enqueue_style($ref); |
|
| 323 | + // if we have a localization for the script let's do that too. |
|
| 324 | + if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
| 325 | + foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
| 326 | + wp_localize_script( |
|
| 327 | + $ref, |
|
| 328 | + $object_name, |
|
| 329 | + $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + // let's do the deregisters |
|
| 336 | + if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 337 | + return; |
|
| 338 | + } |
|
| 339 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
| 340 | + $defaults = array( |
|
| 341 | + 'type' => 'js', |
|
| 342 | + ); |
|
| 343 | + $details = wp_parse_args($details, $defaults); |
|
| 344 | + extract($details); |
|
| 345 | + $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * just set the defaults for the hooks properties. |
|
| 353 | + * |
|
| 354 | + * @access private |
|
| 355 | + * @return void |
|
| 356 | + */ |
|
| 357 | + private function _set_defaults() |
|
| 358 | + { |
|
| 359 | + $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
|
| 360 | + $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 361 | + $this->caller = get_class($this); |
|
| 362 | + $this->_extend = stripos($this->caller, 'Extend') ? true : false; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * this sets the _page_object property |
|
| 368 | + * |
|
| 369 | + * @access protected |
|
| 370 | + * @return void |
|
| 371 | + */ |
|
| 372 | + protected function _set_page_object() |
|
| 373 | + { |
|
| 374 | + // first make sure $this->_name is set |
|
| 375 | + if (empty($this->_name)) { |
|
| 376 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 377 | + $msg[] = sprintf( |
|
| 378 | + __("This is because the %s child class has not set the '_name' property", 'event_espresso'), |
|
| 379 | + $this->caller |
|
| 380 | + ); |
|
| 381 | + throw new EE_Error(implode('||', $msg)); |
|
| 382 | + } |
|
| 383 | + $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
|
| 384 | + $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
| 385 | + // first default file (if exists) |
|
| 386 | + $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
| 387 | + if (is_readable($decaf_file)) { |
|
| 388 | + require_once($decaf_file); |
|
| 389 | + } |
|
| 390 | + // now we have to do require for extended file (if needed) |
|
| 391 | + if ($this->_extend) { |
|
| 392 | + require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
| 393 | + } |
|
| 394 | + // if we've got an extended class we use that! |
|
| 395 | + $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 396 | + // let's make sure the class exists |
|
| 397 | + if (! class_exists($ref)) { |
|
| 398 | + $msg[] = __('We can\'t load the page object', 'event_espresso'); |
|
| 399 | + $msg[] = sprintf( |
|
| 400 | + __( |
|
| 401 | + 'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', |
|
| 402 | + 'event_espresso' |
|
| 403 | + ), |
|
| 404 | + $ref |
|
| 405 | + ); |
|
| 406 | + throw new EE_Error(implode('||', $msg)); |
|
| 407 | + } |
|
| 408 | + $a = new ReflectionClass($ref); |
|
| 409 | + $this->_page_object = $a->newInstance(false); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded. The |
|
| 415 | + * advantage of this is when doing things like running our own db interactions on saves etc. Remember that |
|
| 416 | + * $this->_req_data (all the _POST and _GET data) is available to your methods. |
|
| 417 | + * |
|
| 418 | + * @access private |
|
| 419 | + * @return void |
|
| 420 | + */ |
|
| 421 | + private function _load_custom_methods() |
|
| 422 | + { |
|
| 423 | + /** |
|
| 424 | + * method cannot be named 'default' (@see http://us3.php |
|
| 425 | + * .net/manual/en/reserved.keywords.php) so need to |
|
| 426 | + * handle routes that are "default" |
|
| 427 | + * |
|
| 428 | + * @since 4.3.0 |
|
| 429 | + */ |
|
| 430 | + $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
|
| 431 | + // these run before the Admin_Page route executes. |
|
| 432 | + if (method_exists($this, $method_callback)) { |
|
| 433 | + call_user_func(array($this, $method_callback)); |
|
| 434 | + } |
|
| 435 | + // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
|
| 436 | + // first the actions |
|
| 437 | + // note that these action hooks will have the $query_args value available. |
|
| 438 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
| 439 | + if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 440 | + add_action( |
|
| 441 | + 'AHEE__' |
|
| 442 | + . $admin_class_name |
|
| 443 | + . '___redirect_after_action__before_redirect_modification_' |
|
| 444 | + . $this->_current_route, |
|
| 445 | + array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 446 | + 10 |
|
| 447 | + ); |
|
| 448 | + } |
|
| 449 | + if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 450 | + add_action( |
|
| 451 | + 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 452 | + array($this, '_redirect_action_' . $this->_current_route), |
|
| 453 | + 10 |
|
| 454 | + ); |
|
| 455 | + } |
|
| 456 | + // let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
|
| 457 | + if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 458 | + add_filter( |
|
| 459 | + 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 460 | + array($this, '_redirect_filter_' . $this->_current_route), |
|
| 461 | + 10, |
|
| 462 | + 2 |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * This method will search for a corresponding method with a name matching the route and the wp_hook to run. This |
|
| 470 | + * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route. |
|
| 471 | + * just remember, methods MUST be public Future hooks should be added in here to be access by child classes. |
|
| 472 | + * |
|
| 473 | + * @return void |
|
| 474 | + */ |
|
| 475 | + private function _load_routed_hooks() |
|
| 476 | + { |
|
| 477 | + |
|
| 478 | + // this array provides the hook action names that will be referenced. Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook. We'll default all priorities for automatic hooks to 10. |
|
| 479 | + $hook_filter_array = array( |
|
| 480 | + 'admin_footer' => array( |
|
| 481 | + 'type' => 'action', |
|
| 482 | + 'argnum' => 1, |
|
| 483 | + 'priority' => 10, |
|
| 484 | + ), |
|
| 485 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 486 | + 'type' => 'filter', |
|
| 487 | + 'argnum' => 1, |
|
| 488 | + 'priority' => 10, |
|
| 489 | + ), |
|
| 490 | + 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 491 | + 'type' => 'filter', |
|
| 492 | + 'argnum' => 1, |
|
| 493 | + 'priority' => 10, |
|
| 494 | + ), |
|
| 495 | + 'FHEE_list_table_views' => array( |
|
| 496 | + 'type' => 'filter', |
|
| 497 | + 'argnum' => 1, |
|
| 498 | + 'priority' => 10, |
|
| 499 | + ), |
|
| 500 | + 'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes' => array( |
|
| 501 | + 'type' => 'action', |
|
| 502 | + 'argnum' => 1, |
|
| 503 | + 'priority' => 10, |
|
| 504 | + ), |
|
| 505 | + ); |
|
| 506 | + foreach ($hook_filter_array as $hook => $args) { |
|
| 507 | + if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 508 | + if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
| 509 | + $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
| 510 | + } |
|
| 511 | + if ($args['type'] == 'action') { |
|
| 512 | + add_action( |
|
| 513 | + $hook, |
|
| 514 | + array($this, $this->_current_route . '_' . $hook), |
|
| 515 | + $args['priority'], |
|
| 516 | + $args['argnum'] |
|
| 517 | + ); |
|
| 518 | + } else { |
|
| 519 | + add_filter( |
|
| 520 | + $hook, |
|
| 521 | + array($this, $this->_current_route . '_' . $hook), |
|
| 522 | + $args['priority'], |
|
| 523 | + $args['argnum'] |
|
| 524 | + ); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Loop throught the $_ajax_func array and add_actions for the array. |
|
| 533 | + * |
|
| 534 | + * @return void |
|
| 535 | + */ |
|
| 536 | + private function _ajax_hooks() |
|
| 537 | + { |
|
| 538 | + |
|
| 539 | + if (empty($this->_ajax_func)) { |
|
| 540 | + return; |
|
| 541 | + } //get out there's nothing to take care of. |
|
| 542 | + foreach ($this->_ajax_func as $action => $method) { |
|
| 543 | + // make sure method exists |
|
| 544 | + if (! method_exists($this, $method)) { |
|
| 545 | + $msg[] = __( |
|
| 546 | + 'There is no corresponding method for the hook labeled in the _ajax_func array', |
|
| 547 | + 'event_espresso' |
|
| 548 | + ) . '<br />'; |
|
| 549 | + $msg[] = sprintf( |
|
| 550 | + __( |
|
| 551 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 552 | + 'event_espresso' |
|
| 553 | + ), |
|
| 554 | + $method, |
|
| 555 | + $this->caller |
|
| 556 | + ); |
|
| 557 | + throw new EE_Error(implode('||', $msg)); |
|
| 558 | + } |
|
| 559 | + add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Loop throught the $_init_func array and add_actions for the array. |
|
| 566 | + * |
|
| 567 | + * @return void |
|
| 568 | + */ |
|
| 569 | + protected function _init_hooks() |
|
| 570 | + { |
|
| 571 | + if (empty($this->_init_func)) { |
|
| 572 | + return; |
|
| 573 | + } //get out there's nothing to take care of. |
|
| 574 | + // We need to determine what page_route we are on! |
|
| 575 | + $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
| 576 | + foreach ($this->_init_func as $route => $method) { |
|
| 577 | + // make sure method exists |
|
| 578 | + if (! method_exists($this, $method)) { |
|
| 579 | + $msg[] = __( |
|
| 580 | + 'There is no corresponding method for the hook labeled in the _init_func array', |
|
| 581 | + 'event_espresso' |
|
| 582 | + ) . '<br />'; |
|
| 583 | + $msg[] = sprintf( |
|
| 584 | + __( |
|
| 585 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 586 | + 'event_espresso' |
|
| 587 | + ), |
|
| 588 | + $method, |
|
| 589 | + $this->caller |
|
| 590 | + ); |
|
| 591 | + throw new EE_Error(implode('||', $msg)); |
|
| 592 | + } |
|
| 593 | + if ($route == $this->_current_route) { |
|
| 594 | + add_action('admin_init', array($this, $method)); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Loop through the _metaboxes property and add_metaboxes accordingly |
|
| 602 | + * //todo we could eventually make this a config component class (i.e. new EE_Metabox); |
|
| 603 | + * |
|
| 604 | + * @access public |
|
| 605 | + * @return void |
|
| 606 | + */ |
|
| 607 | + public function add_metaboxes() |
|
| 608 | + { |
|
| 609 | + if (empty($this->_metaboxes)) { |
|
| 610 | + return; |
|
| 611 | + } //get out we don't have any metaboxes to set for this connection |
|
| 612 | + $this->_handle_metabox_array($this->_metaboxes); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + private function _handle_metabox_array($boxes, $add = true) |
|
| 617 | + { |
|
| 618 | + |
|
| 619 | + foreach ($boxes as $box) { |
|
| 620 | + if (! isset($box['page_route'])) { |
|
| 621 | + continue; |
|
| 622 | + } //we dont' have a valid array |
|
| 623 | + // let's make sure $box['page_route'] is an array so the "foreach" will work. |
|
| 624 | + $box['page_route'] = (array) $box['page_route']; |
|
| 625 | + foreach ($box['page_route'] as $route) { |
|
| 626 | + if ($route != $this->_current_route) { |
|
| 627 | + continue; |
|
| 628 | + } //get out we only add metaboxes for set route. |
|
| 629 | + if ($add) { |
|
| 630 | + $this->_add_metabox($box); |
|
| 631 | + } else { |
|
| 632 | + $this->_remove_metabox($box); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Loop through the _remove_metaboxes property and remove metaboxes accordingly. |
|
| 641 | + * |
|
| 642 | + * @access public |
|
| 643 | + * @return void |
|
| 644 | + */ |
|
| 645 | + public function remove_metaboxes() |
|
| 646 | + { |
|
| 647 | + |
|
| 648 | + if (empty($this->_remove_metaboxes)) { |
|
| 649 | + return; |
|
| 650 | + } //get out there are no metaboxes to remove |
|
| 651 | + $this->_handle_metabox_array($this->_remove_metaboxes, false); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * This just handles adding a metabox |
|
| 657 | + * |
|
| 658 | + * @access private |
|
| 659 | + * @param array $args an array of args that have been set for this metabox by the child class |
|
| 660 | + */ |
|
| 661 | + private function _add_metabox($args) |
|
| 662 | + { |
|
| 663 | + $current_screen = get_current_screen(); |
|
| 664 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 665 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 666 | + // set defaults |
|
| 667 | + $defaults = array( |
|
| 668 | + 'func' => $func, |
|
| 669 | + 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 670 | + 'priority' => 'default', |
|
| 671 | + 'label' => $this->caller, |
|
| 672 | + 'context' => 'advanced', |
|
| 673 | + 'callback_args' => array(), |
|
| 674 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id, |
|
| 675 | + ); |
|
| 676 | + $args = wp_parse_args($args, $defaults); |
|
| 677 | + extract($args); |
|
| 678 | + // make sure method exists |
|
| 679 | + if (! method_exists($this, $func)) { |
|
| 680 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 681 | + $msg[] = sprintf( |
|
| 682 | + __( |
|
| 683 | + 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
|
| 684 | + 'event_espresso' |
|
| 685 | + ), |
|
| 686 | + $func, |
|
| 687 | + $this->caller |
|
| 688 | + ); |
|
| 689 | + throw new EE_Error(implode('||', $msg)); |
|
| 690 | + } |
|
| 691 | + // everything checks out so lets add the metabox |
|
| 692 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + private function _remove_metabox($args) |
|
| 697 | + { |
|
| 698 | + $current_screen = get_current_screen(); |
|
| 699 | + $screen_id = is_object($current_screen) ? $current_screen->id : null; |
|
| 700 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
| 701 | + // set defaults |
|
| 702 | + $defaults = array( |
|
| 703 | + 'id' => isset($args['id']) |
|
| 704 | + ? $args['id'] |
|
| 705 | + : $this->_current_route |
|
| 706 | + . '_' |
|
| 707 | + . $this->caller |
|
| 708 | + . '_' |
|
| 709 | + . $func |
|
| 710 | + . '_metabox', |
|
| 711 | + 'context' => 'default', |
|
| 712 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id, |
|
| 713 | + ); |
|
| 714 | + $args = wp_parse_args($args, $defaults); |
|
| 715 | + extract($args); |
|
| 716 | + // everything checks out so lets remove the box! |
|
| 717 | + remove_meta_box($id, $screen, $context); |
|
| 718 | + } |
|
| 719 | 719 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $this->_set_defaults(); |
| 206 | 206 | $this->_set_hooks_properties(); |
| 207 | 207 | // first let's verify we're on the right page |
| 208 | - if (! isset($this->_req_data['page']) |
|
| 208 | + if ( ! isset($this->_req_data['page']) |
|
| 209 | 209 | || (isset($this->_req_data['page']) |
| 210 | 210 | && $this->_adminpage_obj->page_slug |
| 211 | 211 | != $this->_req_data['page'])) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | public function enqueue_scripts_styles() |
| 257 | 257 | { |
| 258 | 258 | |
| 259 | - if (! empty($this->_scripts_styles)) { |
|
| 259 | + if ( ! empty($this->_scripts_styles)) { |
|
| 260 | 260 | // first let's do all the registrations |
| 261 | - if (! isset($this->_scripts_styles['registers'])) { |
|
| 261 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
| 262 | 262 | $msg[] = __( |
| 263 | 263 | 'There is no "registers" index in the <code>$this->_scripts_styles</code> property.', |
| 264 | 264 | 'event_espresso' |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | 'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', |
| 269 | 269 | 'event_espresso' |
| 270 | 270 | ), |
| 271 | - '<strong>' . $this->caller . '</strong>' |
|
| 271 | + '<strong>'.$this->caller.'</strong>' |
|
| 272 | 272 | ); |
| 273 | 273 | throw new EE_Error(implode('||', $msg)); |
| 274 | 274 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $details = wp_parse_args($details, $defaults); |
| 284 | 284 | extract($details); |
| 285 | 285 | // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
| 286 | - $this->_scripts_styles['registers'][ $ref ]['type'] = $type; |
|
| 286 | + $this->_scripts_styles['registers'][$ref]['type'] = $type; |
|
| 287 | 287 | // let's make sure we're not missing any REQUIRED parameters |
| 288 | 288 | if (empty($url)) { |
| 289 | 289 | $msg[] = sprintf( |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | 'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', |
| 296 | 296 | 'event_espresso' |
| 297 | 297 | ), |
| 298 | - '<strong>' . $this->caller . '</strong>', |
|
| 298 | + '<strong>'.$this->caller.'</strong>', |
|
| 299 | 299 | $ref |
| 300 | 300 | ); |
| 301 | 301 | throw new EE_Error(implode('||', $msg)); |
@@ -311,29 +311,29 @@ discard block |
||
| 311 | 311 | ); |
| 312 | 312 | } |
| 313 | 313 | // k now lets do the enqueues |
| 314 | - if (! isset($this->_scripts_styles['enqueues'])) { |
|
| 314 | + if ( ! isset($this->_scripts_styles['enqueues'])) { |
|
| 315 | 315 | return; |
| 316 | 316 | } //not sure if we should throw an error here or not. |
| 317 | 317 | foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
| 318 | 318 | // make sure $routes is an array |
| 319 | 319 | $routes = (array) $routes; |
| 320 | 320 | if (in_array($this->_current_route, $routes)) { |
| 321 | - $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 321 | + $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) |
|
| 322 | 322 | : wp_enqueue_style($ref); |
| 323 | 323 | // if we have a localization for the script let's do that too. |
| 324 | - if (isset($this->_scripts_styles['localize'][ $ref ])) { |
|
| 325 | - foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) { |
|
| 324 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
| 325 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
| 326 | 326 | wp_localize_script( |
| 327 | 327 | $ref, |
| 328 | 328 | $object_name, |
| 329 | - $this->_scripts_styles['localize'][ $ref ][ $object_name ] |
|
| 329 | + $this->_scripts_styles['localize'][$ref][$object_name] |
|
| 330 | 330 | ); |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | // let's do the deregisters |
| 336 | - if (! isset($this->_scripts_styles['deregisters'])) { |
|
| 336 | + if ( ! isset($this->_scripts_styles['deregisters'])) { |
|
| 337 | 337 | return; |
| 338 | 338 | } |
| 339 | 339 | foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
@@ -381,20 +381,20 @@ discard block |
||
| 381 | 381 | throw new EE_Error(implode('||', $msg)); |
| 382 | 382 | } |
| 383 | 383 | $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message |
| 384 | - $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message |
|
| 384 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; // take the message -> The_Message |
|
| 385 | 385 | // first default file (if exists) |
| 386 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
| 386 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php'; |
|
| 387 | 387 | if (is_readable($decaf_file)) { |
| 388 | 388 | require_once($decaf_file); |
| 389 | 389 | } |
| 390 | 390 | // now we have to do require for extended file (if needed) |
| 391 | 391 | if ($this->_extend) { |
| 392 | - require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php'); |
|
| 392 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php'); |
|
| 393 | 393 | } |
| 394 | 394 | // if we've got an extended class we use that! |
| 395 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
| 395 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
| 396 | 396 | // let's make sure the class exists |
| 397 | - if (! class_exists($ref)) { |
|
| 397 | + if ( ! class_exists($ref)) { |
|
| 398 | 398 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
| 399 | 399 | $msg[] = sprintf( |
| 400 | 400 | __( |
@@ -436,28 +436,28 @@ discard block |
||
| 436 | 436 | // first the actions |
| 437 | 437 | // note that these action hooks will have the $query_args value available. |
| 438 | 438 | $admin_class_name = get_class($this->_adminpage_obj); |
| 439 | - if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) { |
|
| 439 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
| 440 | 440 | add_action( |
| 441 | 441 | 'AHEE__' |
| 442 | 442 | . $admin_class_name |
| 443 | 443 | . '___redirect_after_action__before_redirect_modification_' |
| 444 | 444 | . $this->_current_route, |
| 445 | - array($this, '_redirect_action_early_' . $this->_current_route), |
|
| 445 | + array($this, '_redirect_action_early_'.$this->_current_route), |
|
| 446 | 446 | 10 |
| 447 | 447 | ); |
| 448 | 448 | } |
| 449 | - if (method_exists($this, '_redirect_action_' . $this->_current_route)) { |
|
| 449 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
| 450 | 450 | add_action( |
| 451 | - 'AHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 452 | - array($this, '_redirect_action_' . $this->_current_route), |
|
| 451 | + 'AHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
| 452 | + array($this, '_redirect_action_'.$this->_current_route), |
|
| 453 | 453 | 10 |
| 454 | 454 | ); |
| 455 | 455 | } |
| 456 | 456 | // let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
| 457 | - if (method_exists($this, '_redirect_filter_' . $this->_current_route)) { |
|
| 457 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
| 458 | 458 | add_filter( |
| 459 | - 'FHEE_redirect_' . $admin_class_name . $this->_current_route, |
|
| 460 | - array($this, '_redirect_filter_' . $this->_current_route), |
|
| 459 | + 'FHEE_redirect_'.$admin_class_name.$this->_current_route, |
|
| 460 | + array($this, '_redirect_filter_'.$this->_current_route), |
|
| 461 | 461 | 10, |
| 462 | 462 | 2 |
| 463 | 463 | ); |
@@ -482,12 +482,12 @@ discard block |
||
| 482 | 482 | 'argnum' => 1, |
| 483 | 483 | 'priority' => 10, |
| 484 | 484 | ), |
| 485 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
| 485 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
| 486 | 486 | 'type' => 'filter', |
| 487 | 487 | 'argnum' => 1, |
| 488 | 488 | 'priority' => 10, |
| 489 | 489 | ), |
| 490 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
| 490 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
| 491 | 491 | 'type' => 'filter', |
| 492 | 492 | 'argnum' => 1, |
| 493 | 493 | 'priority' => 10, |
@@ -504,21 +504,21 @@ discard block |
||
| 504 | 504 | ), |
| 505 | 505 | ); |
| 506 | 506 | foreach ($hook_filter_array as $hook => $args) { |
| 507 | - if (method_exists($this, $this->_current_route . '_' . $hook)) { |
|
| 508 | - if (isset($this->_wp_action_filters_priority[ $hook ])) { |
|
| 509 | - $args['priority'] = $this->_wp_action_filters_priority[ $hook ]; |
|
| 507 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
| 508 | + if (isset($this->_wp_action_filters_priority[$hook])) { |
|
| 509 | + $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
|
| 510 | 510 | } |
| 511 | 511 | if ($args['type'] == 'action') { |
| 512 | 512 | add_action( |
| 513 | 513 | $hook, |
| 514 | - array($this, $this->_current_route . '_' . $hook), |
|
| 514 | + array($this, $this->_current_route.'_'.$hook), |
|
| 515 | 515 | $args['priority'], |
| 516 | 516 | $args['argnum'] |
| 517 | 517 | ); |
| 518 | 518 | } else { |
| 519 | 519 | add_filter( |
| 520 | 520 | $hook, |
| 521 | - array($this, $this->_current_route . '_' . $hook), |
|
| 521 | + array($this, $this->_current_route.'_'.$hook), |
|
| 522 | 522 | $args['priority'], |
| 523 | 523 | $args['argnum'] |
| 524 | 524 | ); |
@@ -541,11 +541,11 @@ discard block |
||
| 541 | 541 | } //get out there's nothing to take care of. |
| 542 | 542 | foreach ($this->_ajax_func as $action => $method) { |
| 543 | 543 | // make sure method exists |
| 544 | - if (! method_exists($this, $method)) { |
|
| 544 | + if ( ! method_exists($this, $method)) { |
|
| 545 | 545 | $msg[] = __( |
| 546 | 546 | 'There is no corresponding method for the hook labeled in the _ajax_func array', |
| 547 | 547 | 'event_espresso' |
| 548 | - ) . '<br />'; |
|
| 548 | + ).'<br />'; |
|
| 549 | 549 | $msg[] = sprintf( |
| 550 | 550 | __( |
| 551 | 551 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | ); |
| 557 | 557 | throw new EE_Error(implode('||', $msg)); |
| 558 | 558 | } |
| 559 | - add_action('wp_ajax_' . $action, array($this, $method)); |
|
| 559 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | |
@@ -575,11 +575,11 @@ discard block |
||
| 575 | 575 | $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
| 576 | 576 | foreach ($this->_init_func as $route => $method) { |
| 577 | 577 | // make sure method exists |
| 578 | - if (! method_exists($this, $method)) { |
|
| 578 | + if ( ! method_exists($this, $method)) { |
|
| 579 | 579 | $msg[] = __( |
| 580 | 580 | 'There is no corresponding method for the hook labeled in the _init_func array', |
| 581 | 581 | 'event_espresso' |
| 582 | - ) . '<br />'; |
|
| 582 | + ).'<br />'; |
|
| 583 | 583 | $msg[] = sprintf( |
| 584 | 584 | __( |
| 585 | 585 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | { |
| 618 | 618 | |
| 619 | 619 | foreach ($boxes as $box) { |
| 620 | - if (! isset($box['page_route'])) { |
|
| 620 | + if ( ! isset($box['page_route'])) { |
|
| 621 | 621 | continue; |
| 622 | 622 | } //we dont' have a valid array |
| 623 | 623 | // let's make sure $box['page_route'] is an array so the "foreach" will work. |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | // set defaults |
| 667 | 667 | $defaults = array( |
| 668 | 668 | 'func' => $func, |
| 669 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
| 669 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
| 670 | 670 | 'priority' => 'default', |
| 671 | 671 | 'label' => $this->caller, |
| 672 | 672 | 'context' => 'advanced', |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | $args = wp_parse_args($args, $defaults); |
| 677 | 677 | extract($args); |
| 678 | 678 | // make sure method exists |
| 679 | - if (! method_exists($this, $func)) { |
|
| 680 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
| 679 | + if ( ! method_exists($this, $func)) { |
|
| 680 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
| 681 | 681 | $msg[] = sprintf( |
| 682 | 682 | __( |
| 683 | 683 | 'The method name given in the array is %s, check the spelling and make sure it exists in the %s class', |
@@ -13,72 +13,72 @@ |
||
| 13 | 13 | trait BaseCoreAdmin |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Core method for going to an Event Espresso Admin page. |
|
| 18 | - * @param string $page |
|
| 19 | - * @param string $action |
|
| 20 | - * @param string $additional_params |
|
| 21 | - */ |
|
| 22 | - public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
| 23 | - { |
|
| 24 | - $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Core method for going to an Event Espresso Admin page. |
|
| 18 | + * @param string $page |
|
| 19 | + * @param string $action |
|
| 20 | + * @param string $additional_params |
|
| 21 | + */ |
|
| 22 | + public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
| 23 | + { |
|
| 24 | + $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
| 30 | - * @return \EventEspressoAcceptanceTester; |
|
| 31 | - */ |
|
| 32 | - protected function actor() |
|
| 33 | - { |
|
| 34 | - /** @var \EventEspressoAcceptanceTester $this */ |
|
| 35 | - return $this; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
| 30 | + * @return \EventEspressoAcceptanceTester; |
|
| 31 | + */ |
|
| 32 | + protected function actor() |
|
| 33 | + { |
|
| 34 | + /** @var \EventEspressoAcceptanceTester $this */ |
|
| 35 | + return $this; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Use this to set the per page option for a list table page. |
|
| 41 | - * Assumes you are on a page that has this field exposed. |
|
| 42 | - * |
|
| 43 | - * @param int|string $per_page_value |
|
| 44 | - * @throws \Codeception\Exception\TestRuntimeException |
|
| 45 | - */ |
|
| 46 | - public function setPerPageOptionForScreen($per_page_value) |
|
| 47 | - { |
|
| 48 | - $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
| 49 | - $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
| 50 | - $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
| 51 | - $this->actor()->wait(8); |
|
| 52 | - } |
|
| 39 | + /** |
|
| 40 | + * Use this to set the per page option for a list table page. |
|
| 41 | + * Assumes you are on a page that has this field exposed. |
|
| 42 | + * |
|
| 43 | + * @param int|string $per_page_value |
|
| 44 | + * @throws \Codeception\Exception\TestRuntimeException |
|
| 45 | + */ |
|
| 46 | + public function setPerPageOptionForScreen($per_page_value) |
|
| 47 | + { |
|
| 48 | + $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
| 49 | + $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
| 50 | + $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
| 51 | + $this->actor()->wait(8); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Use this to append a given value to a wpEditor instance. |
|
| 58 | - * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
| 59 | - * the value is added to the text area. |
|
| 60 | - * |
|
| 61 | - * @param $field_reference |
|
| 62 | - * @param $value |
|
| 63 | - * @throws \Codeception\Exception\ElementNotFound |
|
| 64 | - */ |
|
| 65 | - public function appendToWPEditorField($field_reference, $value) |
|
| 66 | - { |
|
| 67 | - $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
| 68 | - $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
| 69 | - } |
|
| 56 | + /** |
|
| 57 | + * Use this to append a given value to a wpEditor instance. |
|
| 58 | + * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and |
|
| 59 | + * the value is added to the text area. |
|
| 60 | + * |
|
| 61 | + * @param $field_reference |
|
| 62 | + * @param $value |
|
| 63 | + * @throws \Codeception\Exception\ElementNotFound |
|
| 64 | + */ |
|
| 65 | + public function appendToWPEditorField($field_reference, $value) |
|
| 66 | + { |
|
| 67 | + $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference)); |
|
| 68 | + $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Use to select and submit the given bulk action. |
|
| 74 | - * @param string $bulk_action_option |
|
| 75 | - */ |
|
| 76 | - public function submitBulkActionOnListTable($bulk_action_option) |
|
| 77 | - { |
|
| 78 | - $this->actor()->selectOption( |
|
| 79 | - CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
| 80 | - $bulk_action_option |
|
| 81 | - ); |
|
| 82 | - $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
| 83 | - } |
|
| 72 | + /** |
|
| 73 | + * Use to select and submit the given bulk action. |
|
| 74 | + * @param string $bulk_action_option |
|
| 75 | + */ |
|
| 76 | + public function submitBulkActionOnListTable($bulk_action_option) |
|
| 77 | + { |
|
| 78 | + $this->actor()->selectOption( |
|
| 79 | + CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD, |
|
| 80 | + $bulk_action_option |
|
| 81 | + ); |
|
| 82 | + $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -832,7 +832,7 @@ |
||
| 832 | 832 | * Takes care of setting up the addressee object(s) for the primary attendee. |
| 833 | 833 | * |
| 834 | 834 | * @access protected |
| 835 | - * @return array of EE_Addressee objects |
|
| 835 | + * @return EE_Messages_Addressee[] of EE_Addressee objects |
|
| 836 | 836 | * @throws EE_Error |
| 837 | 837 | */ |
| 838 | 838 | protected function _primary_attendee_addressees() |
@@ -17,913 +17,913 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * message type child classes will set what contexts are associated with the message type via this array. |
|
| 22 | - * format: |
|
| 23 | - * array( |
|
| 24 | - * 'context' => array( |
|
| 25 | - * 'label' => __('Context Label', 'event_espresso'), |
|
| 26 | - * 'description' => __('Context description (for help popups)', 'event_espresso') |
|
| 27 | - * )); |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $_contexts = array(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This property is used to define what the display label will be for contexts (eg. "Recipients", "Themes" etc.) |
|
| 36 | - * Format: |
|
| 37 | - * array( 'label' => 'something', 'plural' => 'somethings', 'description' => 'something' ); |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $_context_label; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** MESSAGE ASSEMBLING PROPERTIES **/ |
|
| 45 | - /** |
|
| 46 | - * This parameter simply holds all the message objects for retrieval by the controller and sending to the messenger. |
|
| 47 | - * |
|
| 48 | - * @var array of message objects. |
|
| 49 | - */ |
|
| 50 | - public $messages = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The following holds the templates that will be used to assemble the message object for the messenger. |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - protected $_templates; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * If a specific template is being parsed, this will hold the message template group GRP_ID for that template. |
|
| 62 | - * |
|
| 63 | - * @var int. |
|
| 64 | - */ |
|
| 65 | - protected $_GRP_ID; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** OTHER INFO PROPERTIES **/ |
|
| 69 | - /** |
|
| 70 | - * This will hold the count of the message objects in the messages array. This could be used for determining if |
|
| 71 | - * batching/queueing is needed. |
|
| 72 | - * |
|
| 73 | - * @var int |
|
| 74 | - */ |
|
| 75 | - public $count = 0; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * This is set via the `do_messenger_hooks` method and contains the messenger being used to send the message of |
|
| 80 | - * this message type at time of sending. |
|
| 81 | - * |
|
| 82 | - * @var EE_messenger |
|
| 83 | - */ |
|
| 84 | - protected $_active_messenger; |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * This will hold the shortcode_replace instance for handling replacement of shortcodes in the various templates |
|
| 89 | - * |
|
| 90 | - * @var object |
|
| 91 | - */ |
|
| 92 | - protected $_shortcode_replace; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * The purpose for this property is to simply allow message types to indicate if the message generated is intended |
|
| 97 | - * for only single context. Child message types should redefine this variable (if necessary) in the |
|
| 98 | - * _set_data_Handler() method. |
|
| 99 | - * |
|
| 100 | - * @var boolean |
|
| 101 | - */ |
|
| 102 | - protected $_single_message = false; |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * This will hold an array of specific reg_ids that are receiving messages. |
|
| 107 | - * |
|
| 108 | - * @since 4.7.x |
|
| 109 | - * @var array |
|
| 110 | - */ |
|
| 111 | - protected $_regs_for_sending = array(); |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * This holds the data passed to this class from the controller and also the final processed data. |
|
| 116 | - * |
|
| 117 | - * @var object |
|
| 118 | - */ |
|
| 119 | - protected $_data; |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * this is just a flag indicating whether we're in preview mode or not. |
|
| 124 | - * |
|
| 125 | - * @var bool |
|
| 126 | - */ |
|
| 127 | - protected $_preview = false; |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * This just holds defaults for addressee data that children merge with their data array setup |
|
| 132 | - * |
|
| 133 | - * @var array |
|
| 134 | - */ |
|
| 135 | - protected $_default_addressee_data; |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Child classes declare through this property what handler they want to use for the incoming data and this string |
|
| 140 | - * is used to instantiate the EE_Messages_incoming_data child class for that handler. |
|
| 141 | - * |
|
| 142 | - * @var string |
|
| 143 | - */ |
|
| 144 | - protected $_data_handler; |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * This holds any specific fields for holding any settings related to a message type (if any needed) |
|
| 149 | - * |
|
| 150 | - * @var array |
|
| 151 | - */ |
|
| 152 | - protected $_admin_settings_fields = array(); |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * this property will hold any existing setting that may have been set in the admin. |
|
| 156 | - * |
|
| 157 | - * @var array |
|
| 158 | - */ |
|
| 159 | - protected $_existing_admin_settings = array(); |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * This is used to designate the generating and alternative sending messengers for a message type. It is set via |
|
| 164 | - * set_with_messengers() on construct. Note, generating messenger also acts as a sending messenger for this message |
|
| 165 | - * type. However ONLY the generating messengers are used for creating templates for this message type. Should be |
|
| 166 | - * in this format: |
|
| 167 | - * { |
|
| 168 | - * |
|
| 169 | - * @type string $generating_messenger the name of the generating messenger. Generating |
|
| 170 | - * messengers are used for generating templates, |
|
| 171 | - * doing validation and defining valid shortcodes. |
|
| 172 | - * { |
|
| 173 | - * @type string $sending_messenger values are the name(s) for the sending |
|
| 174 | - * messengers. sending messengers are |
|
| 175 | - * just valid delivery vehicles that will utilize |
|
| 176 | - * the templates (and generated EE_message |
|
| 177 | - * objects from the generating messengers). |
|
| 178 | - * } |
|
| 179 | - * } |
|
| 180 | - * @since 4.5.0 |
|
| 181 | - * @var array |
|
| 182 | - */ |
|
| 183 | - protected $_with_messengers = array(); |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * This holds the addressees in an array indexed by context for later retrieval when assembling the message objects. |
|
| 188 | - * |
|
| 189 | - * @access protected |
|
| 190 | - * @var array |
|
| 191 | - */ |
|
| 192 | - protected $_addressees = array(); |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * This allows each message type to set what alternate messenger&message type combination can be used for fallback |
|
| 197 | - * default templates if there are no specific ones defined for this messenger and message type. Should be in the |
|
| 198 | - * format: |
|
| 199 | - * array( |
|
| 200 | - * 'messenger' => 'message_type', |
|
| 201 | - * 'another_messenger' => another_message_type |
|
| 202 | - * ); |
|
| 203 | - * This is set in the message type constructor. |
|
| 204 | - * |
|
| 205 | - * @var array |
|
| 206 | - */ |
|
| 207 | - protected $_master_templates = array(); |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * This holds whatever the set template pack is for a message template group when generating messages. |
|
| 212 | - * |
|
| 213 | - * @since 4.5.0 |
|
| 214 | - * @var EE_Messages_Template_Pack |
|
| 215 | - */ |
|
| 216 | - protected $_template_pack; |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * This holds whatever the set variation is for a message template group when generating messages. |
|
| 221 | - * |
|
| 222 | - * @since 4.5.0 |
|
| 223 | - * @var string |
|
| 224 | - */ |
|
| 225 | - protected $_variation; |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * EE_message_type constructor. |
|
| 230 | - */ |
|
| 231 | - public function __construct() |
|
| 232 | - { |
|
| 233 | - $this->_messages_item_type = 'message_type'; |
|
| 234 | - $this->_set_contexts(); |
|
| 235 | - $this->_set_with_messengers(); |
|
| 236 | - parent::__construct(); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * This sets the data handler for the message type. It must be used to define the _data_handler property. It is |
|
| 242 | - * called when messages are setup. |
|
| 243 | - * |
|
| 244 | - * @abstract |
|
| 245 | - * @access protected |
|
| 246 | - * @return void |
|
| 247 | - */ |
|
| 248 | - abstract protected function _set_data_handler(); |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * This method should return a EE_Base_Class object (or array of EE_Base_Class objects) for the given context and |
|
| 253 | - * ID (which should be the primary key id for the base class). Client code doesn't have to know what a message |
|
| 254 | - * type's data handler is. |
|
| 255 | - * |
|
| 256 | - * @since 4.5.0 |
|
| 257 | - * @param string $context This should be a string matching a valid context for the message type. |
|
| 258 | - * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
| 259 | - * guessing a url). |
|
| 260 | - * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
| 261 | - * EE_Base_Class_Object |
|
| 262 | - * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
|
| 263 | - */ |
|
| 264 | - abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * _set_contexts |
|
| 269 | - * This sets up the contexts associated with the message_type |
|
| 270 | - * |
|
| 271 | - * @abstract |
|
| 272 | - * @access protected |
|
| 273 | - * @return void |
|
| 274 | - */ |
|
| 275 | - abstract protected function _set_contexts(); |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * This is used to get the "id" value fo the msg_trigger_url generated by get_url_trigger(). |
|
| 280 | - * In most cases, child classes don't need anything, (hence the default of 0), however if there is a specific |
|
| 281 | - * EE_Base_Class that is required in generating a message for a message type recipient then the message |
|
| 282 | - * type should override this method and use the given params to generate the correct ID. |
|
| 283 | - * |
|
| 284 | - * @param string $context The message type context. |
|
| 285 | - * @param EE_Registration $registration Registration object |
|
| 286 | - * @deprecated 4.9.0 |
|
| 287 | - * @return int |
|
| 288 | - */ |
|
| 289 | - protected function _get_id_for_msg_url($context, EE_Registration $registration) |
|
| 290 | - { |
|
| 291 | - return 0; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * This sets up any action/filter hooks this message type puts in place for a specific messenger. Note that by |
|
| 297 | - * default this does nothing. Child classes will need to override if they want to add specific hooks for a |
|
| 298 | - * messenger. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.0 |
|
| 301 | - * @return void |
|
| 302 | - */ |
|
| 303 | - protected function _do_messenger_hooks() |
|
| 304 | - { |
|
| 305 | - return; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * This is a public wrapper for the protected _do_messenger_hooks() method. |
|
| 311 | - * For backward compat reasons, this was done rather than making the protected method public. |
|
| 312 | - * |
|
| 313 | - * @param EE_messenger $messenger This is used to set the $_active_messenger property, so message types are able |
|
| 314 | - * to know what messenger is being used to send the message at the time of |
|
| 315 | - * sending. |
|
| 316 | - * @since 4.9.0 |
|
| 317 | - */ |
|
| 318 | - public function do_messenger_hooks($messenger = null) |
|
| 319 | - { |
|
| 320 | - $this->_active_messenger = $messenger; |
|
| 321 | - $this->_do_messenger_hooks(); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * This method returns whether this message type should always generate a new copy |
|
| 327 | - * when requested, or if links can be to the already generated copy. |
|
| 328 | - * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table. |
|
| 329 | - * Child classes should override this if different from the default of false. |
|
| 330 | - * |
|
| 331 | - * @return bool false means can link to generated EE_Message. true must regenerate. |
|
| 332 | - */ |
|
| 333 | - public function always_generate() |
|
| 334 | - { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Returns the priority for the message type. |
|
| 341 | - * Priorities are defined as constants on EEM_Message. Currently there are three priorities: |
|
| 342 | - * - EEM_Message::priority_high |
|
| 343 | - * - EEM_Message::priority_medium |
|
| 344 | - * - EEM_Message::priority_low |
|
| 345 | - * Priority is used to determine the weight the message type is given when queuing for generation and/or sending. |
|
| 346 | - * |
|
| 347 | - * @see EEM_Message for more phpdocs on priority. |
|
| 348 | - * The default priority for all message_types is EEM_Message::priority_low. Message Types wanting to give |
|
| 349 | - * a higher priority must override this method. Also note, messengers are able to override priorities |
|
| 350 | - * queuing instructions if their "send_now" flag is set to true. An example of this is the HTML messenger |
|
| 351 | - * which displays things in the browser. |
|
| 352 | - * @since 4.9.0 |
|
| 353 | - * @return int |
|
| 354 | - */ |
|
| 355 | - public function get_priority() |
|
| 356 | - { |
|
| 357 | - return EEM_Message::priority_low; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * This runs the _set_data_handler() method for message types and then returns what got set. |
|
| 363 | - * |
|
| 364 | - * @param mixed $data This sets the data property for the message type with the incoming data used for generating. |
|
| 365 | - * @return string (the reference for the data handler) (will be an empty string if could not be determined). |
|
| 366 | - */ |
|
| 367 | - public function get_data_handler($data) |
|
| 368 | - { |
|
| 369 | - $this->_data = $data; |
|
| 370 | - $this->_set_data_handler(); |
|
| 371 | - return apply_filters('FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * This is called externally to reset the value of the $_data property for the message type. |
|
| 377 | - * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
| 378 | - * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called |
|
| 379 | - * (and for back compat reasons). This particular method is used in |
|
| 380 | - * EE_Messages_Generator::_reset_current_properties to ensure that the internal _data on the message type is |
|
| 381 | - * cleaned before subsequent EE_Message generation in the same request. |
|
| 382 | - * |
|
| 383 | - * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
| 384 | - * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
| 385 | - * expectation of what it is. Likely we need to ensure that _data is not persisted IN the message type |
|
| 386 | - * at all. |
|
| 387 | - * @internal Plugin authors, do not implement this method, it is subject to change. |
|
| 388 | - * @since 4.9 |
|
| 389 | - */ |
|
| 390 | - public function reset_data() |
|
| 391 | - { |
|
| 392 | - $this->_data = null; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * This does some validation of incoming params gets the url trigger from the defined method in the specific child |
|
| 398 | - * class and then filters the results. |
|
| 399 | - * |
|
| 400 | - * @param string $context The message type context |
|
| 401 | - * @param string $sending_messenger The sending messenger |
|
| 402 | - * @param EE_Registration $registration Registration object |
|
| 403 | - * @throws EE_Error |
|
| 404 | - * @deprecated 4.9.0 Likely 4.9.10 or 4.10.0 will remove this method completely |
|
| 405 | - * @return string generated url |
|
| 406 | - */ |
|
| 407 | - public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) |
|
| 408 | - { |
|
| 409 | - // validate context |
|
| 410 | - // valid context? |
|
| 411 | - if (! isset($this->_contexts[ $context ])) { |
|
| 412 | - throw new EE_Error( |
|
| 413 | - sprintf( |
|
| 414 | - __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 415 | - $context, |
|
| 416 | - get_class($this) |
|
| 417 | - ) |
|
| 418 | - ); |
|
| 419 | - } |
|
| 420 | - // valid sending_messenger? |
|
| 421 | - $not_valid_msgr = false; |
|
| 422 | - foreach ($this->_with_messengers as $generating => $sendings) { |
|
| 423 | - if (empty($sendings) || array_search($sending_messenger, $sendings) === false) { |
|
| 424 | - $not_valid_msgr = true; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - if ($not_valid_msgr) { |
|
| 428 | - throw new EE_Error( |
|
| 429 | - sprintf( |
|
| 430 | - __( |
|
| 431 | - 'The given sending messenger string (%s) does not match a valid sending messenger with the %s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 432 | - 'event_espresso' |
|
| 433 | - ), |
|
| 434 | - $sending_messenger, |
|
| 435 | - get_class($this) |
|
| 436 | - ) |
|
| 437 | - ); |
|
| 438 | - } |
|
| 439 | - return EEH_MSG_Template::generate_url_trigger( |
|
| 440 | - $sending_messenger, |
|
| 441 | - $this->_active_messenger->name, |
|
| 442 | - $context, |
|
| 443 | - $this->name, |
|
| 444 | - $registration, |
|
| 445 | - $this->_GRP_ID, |
|
| 446 | - $this->_get_id_for_msg_url($context, $registration) |
|
| 447 | - ); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Wrapper for _get_data_for_context() that handles some validation before calling the main class and also allows |
|
| 453 | - * for filtering. This is (currently) called by the EED_Messages module. |
|
| 454 | - * |
|
| 455 | - * @since 4.5.0 |
|
| 456 | - * @throws EE_Error |
|
| 457 | - * @param string $context This should be a string matching a valid context for the message type. |
|
| 458 | - * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
| 459 | - * guessing a url). |
|
| 460 | - * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
| 461 | - * EE_Base_Class_Object |
|
| 462 | - * @return mixed (EE_Base_Class||EE_Base_Class[]) |
|
| 463 | - */ |
|
| 464 | - public function get_data_for_context($context, EE_Registration $registration, $id = 0) |
|
| 465 | - { |
|
| 466 | - // valid context? |
|
| 467 | - if (! isset($this->_contexts[ $context ])) { |
|
| 468 | - throw new EE_Error( |
|
| 469 | - sprintf( |
|
| 470 | - __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 471 | - $context, |
|
| 472 | - get_class($this) |
|
| 473 | - ) |
|
| 474 | - ); |
|
| 475 | - } |
|
| 476 | - // get data and apply global and class specific filters on it. |
|
| 477 | - $data = apply_filters( |
|
| 478 | - 'FHEE__EE_message_type__get_data_for_context__data', |
|
| 479 | - $this->_get_data_for_context($context, $registration, $id), |
|
| 480 | - $this |
|
| 481 | - ); |
|
| 482 | - $data = apply_filters('FHEE__' . get_class($this) . '__get_data_for_context__data', $data, $this); |
|
| 483 | - // if empty then something went wrong! |
|
| 484 | - if (empty($data)) { |
|
| 485 | - throw new EE_Error( |
|
| 486 | - sprintf( |
|
| 487 | - __( |
|
| 488 | - 'There is no data retrieved, it is possible that the id given (%d) does not match any value in the database for the corresponding EE_Base_Class used by the data handler for the %s message type.', |
|
| 489 | - 'event_espresso' |
|
| 490 | - ), |
|
| 491 | - $id, |
|
| 492 | - $this->name |
|
| 493 | - ) |
|
| 494 | - ); |
|
| 495 | - } |
|
| 496 | - return $data; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * This returns the contents of the _data property. |
|
| 502 | - * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
| 503 | - * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called. |
|
| 504 | - * |
|
| 505 | - * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
| 506 | - * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
| 507 | - * expectation of what it is. |
|
| 508 | - * @internal Plugin authors, do not implement this method, it is subject to change. |
|
| 509 | - * @return mixed |
|
| 510 | - */ |
|
| 511 | - public function get_data() |
|
| 512 | - { |
|
| 513 | - return $this->_data; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * used to set the $_with_messengers property. (this is a default, child classes SHOULD override) |
|
| 519 | - * |
|
| 520 | - * @see property definition for description of setup. |
|
| 521 | - * @since 4.5.0 |
|
| 522 | - * @abstract |
|
| 523 | - * @return void |
|
| 524 | - */ |
|
| 525 | - protected function _set_with_messengers() |
|
| 526 | - { |
|
| 527 | - $this->_with_messengers = array( |
|
| 528 | - 'email' => array('html'), |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Return the value of the _with_messengers property |
|
| 535 | - * |
|
| 536 | - * @since 4.5.0 |
|
| 537 | - * @return array |
|
| 538 | - */ |
|
| 539 | - public function with_messengers() |
|
| 540 | - { |
|
| 541 | - return apply_filters( |
|
| 542 | - 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class($this), |
|
| 543 | - $this->_with_messengers |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class |
|
| 550 | - * callback function if that page is registered via the `_admin_registered_page` property set by the child class. |
|
| 551 | - * * |
|
| 552 | - * |
|
| 553 | - * @param string $page the slug of the EE admin page |
|
| 554 | - * @param array $messengers an array of active messenger objects |
|
| 555 | - * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
|
| 556 | - * @param array $extra This is just an extra argument that can be used to pass additional data for setting up |
|
| 557 | - * page content. |
|
| 558 | - * @access public |
|
| 559 | - * @return string |
|
| 560 | - */ |
|
| 561 | - public function get_message_type_admin_page_content( |
|
| 562 | - $page, |
|
| 563 | - $action = null, |
|
| 564 | - $extra = array(), |
|
| 565 | - $messengers = array() |
|
| 566 | - ) { |
|
| 567 | - // we can also further refine the context by action (if present). |
|
| 568 | - return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @return array |
|
| 574 | - */ |
|
| 575 | - public function get_contexts() |
|
| 576 | - { |
|
| 577 | - return $this->_contexts; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * This just returns the context label for a given context (as set in $_context_label property) |
|
| 583 | - * |
|
| 584 | - * @access public |
|
| 585 | - * @return array |
|
| 586 | - */ |
|
| 587 | - public function get_context_label() |
|
| 588 | - { |
|
| 589 | - return $this->_context_label; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * This just returns the (filtered) _master_templates property. |
|
| 595 | - * |
|
| 596 | - * @see property definition for documentation. |
|
| 597 | - * @return array |
|
| 598 | - */ |
|
| 599 | - public function get_master_templates() |
|
| 600 | - { |
|
| 601 | - // first class specific filter then filter that by the global filter. |
|
| 602 | - $master_templates = apply_filters( |
|
| 603 | - 'FHEE__' . get_class($this) . '__get_master_templates', |
|
| 604 | - $this->_master_templates |
|
| 605 | - ); |
|
| 606 | - return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Accepts an incoming data handler which contains data for processing, and returns an array of |
|
| 612 | - * EE_Messages_Addressee objects. |
|
| 613 | - * |
|
| 614 | - * @param EE_Messages_incoming_data $data |
|
| 615 | - * @param string $context Limit addressees to specific context. |
|
| 616 | - * @return array An array indexed by context where each context is an array of EE_Messages_Addressee objects for |
|
| 617 | - * that context |
|
| 618 | - * @throws EE_Error |
|
| 619 | - */ |
|
| 620 | - public function get_addressees(EE_Messages_incoming_data $data, $context = '') |
|
| 621 | - { |
|
| 622 | - // override _data |
|
| 623 | - $this->_data = $data; |
|
| 624 | - $addressees = array(); |
|
| 625 | - $original_contexts = $this->_contexts; |
|
| 626 | - // if incoming context then limit to that context |
|
| 627 | - if (! empty($context)) { |
|
| 628 | - $cntxt = ! empty($this->_contexts[ $context ]) ? $this->_contexts[ $context ] : ''; |
|
| 629 | - if (! empty($cntxt)) { |
|
| 630 | - $this->_contexts = array(); |
|
| 631 | - $this->_contexts[ $context ] = $cntxt; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $this->_set_default_addressee_data(); |
|
| 635 | - if ($this->_process_data()) { |
|
| 636 | - $addressees = $this->_addressees; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // reset contexts and addressees |
|
| 640 | - $this->_contexts = $original_contexts; |
|
| 641 | - $this->_addressees = array(); |
|
| 642 | - return $addressees; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * processes the data object so we get |
|
| 648 | - * |
|
| 649 | - * @throws EE_Error |
|
| 650 | - * @return bool true means data was processed successfully, false means not. |
|
| 651 | - */ |
|
| 652 | - protected function _process_data() |
|
| 653 | - { |
|
| 654 | - // at a minimum, we NEED EE_Attendee objects. |
|
| 655 | - if (empty($this->_data->attendees)) { |
|
| 656 | - return false; // there's no data to process! |
|
| 657 | - } |
|
| 658 | - // process addressees for each context. Child classes will have to have methods for |
|
| 659 | - // each context defined to handle the processing of the data object within them |
|
| 660 | - foreach ($this->_contexts as $context => $details) { |
|
| 661 | - $xpctd_method = '_' . $context . '_addressees'; |
|
| 662 | - if (! method_exists($this, $xpctd_method)) { |
|
| 663 | - throw new EE_Error( |
|
| 664 | - sprintf( |
|
| 665 | - __( |
|
| 666 | - 'The data for %1$s message type cannot be prepared because there is no set method for doing so. The expected method name is "%2$s" please doublecheck the %1$s message type class and make sure that method is present', |
|
| 667 | - 'event_espresso' |
|
| 668 | - ), |
|
| 669 | - $this->label['singular'], |
|
| 670 | - $xpctd_method |
|
| 671 | - ) |
|
| 672 | - ); |
|
| 673 | - } |
|
| 674 | - $this->_addressees[ $context ] = call_user_func(array($this, $xpctd_method)); |
|
| 675 | - } |
|
| 676 | - return true; // data was processed successfully. |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * sets the default_addressee_data property, |
|
| 682 | - * |
|
| 683 | - * @access private |
|
| 684 | - * @return void |
|
| 685 | - */ |
|
| 686 | - private function _set_default_addressee_data() |
|
| 687 | - { |
|
| 688 | - $this->_default_addressee_data = array( |
|
| 689 | - 'billing' => $this->_data->billing, |
|
| 690 | - 'taxes' => $this->_data->taxes, |
|
| 691 | - 'tax_line_items' => $this->_data->tax_line_items, |
|
| 692 | - 'additional_line_items' => $this->_data->additional_line_items, |
|
| 693 | - 'grand_total_line_item' => $this->_data->grand_total_line_item, |
|
| 694 | - 'txn' => $this->_data->txn, |
|
| 695 | - 'payments' => $this->_data->payments, |
|
| 696 | - 'payment' => isset($this->_data->payment) && $this->_data->payment instanceof EE_Payment |
|
| 697 | - ? $this->_data->payment |
|
| 698 | - : null, |
|
| 699 | - 'reg_objs' => $this->_data->reg_objs, |
|
| 700 | - 'registrations' => $this->_data->registrations, |
|
| 701 | - 'datetimes' => $this->_data->datetimes, |
|
| 702 | - 'tickets' => $this->_data->tickets, |
|
| 703 | - 'line_items_with_children' => $this->_data->line_items_with_children, |
|
| 704 | - 'questions' => $this->_data->questions, |
|
| 705 | - 'answers' => $this->_data->answers, |
|
| 706 | - 'txn_status' => $this->_data->txn_status, |
|
| 707 | - 'total_ticket_count' => $this->_data->total_ticket_count, |
|
| 708 | - ); |
|
| 709 | - if (is_array($this->_data->primary_attendee_data)) { |
|
| 710 | - $this->_default_addressee_data = array_merge( |
|
| 711 | - $this->_default_addressee_data, |
|
| 712 | - $this->_data->primary_attendee_data |
|
| 713 | - ); |
|
| 714 | - $this->_default_addressee_data['primary_att_obj'] = $this->_data->primary_attendee_data['att_obj']; |
|
| 715 | - $this->_default_addressee_data['primary_reg_obj'] = $this->_data->primary_attendee_data['reg_obj']; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - /******************** |
|
| 20 | + /** |
|
| 21 | + * message type child classes will set what contexts are associated with the message type via this array. |
|
| 22 | + * format: |
|
| 23 | + * array( |
|
| 24 | + * 'context' => array( |
|
| 25 | + * 'label' => __('Context Label', 'event_espresso'), |
|
| 26 | + * 'description' => __('Context description (for help popups)', 'event_espresso') |
|
| 27 | + * )); |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $_contexts = array(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This property is used to define what the display label will be for contexts (eg. "Recipients", "Themes" etc.) |
|
| 36 | + * Format: |
|
| 37 | + * array( 'label' => 'something', 'plural' => 'somethings', 'description' => 'something' ); |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $_context_label; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** MESSAGE ASSEMBLING PROPERTIES **/ |
|
| 45 | + /** |
|
| 46 | + * This parameter simply holds all the message objects for retrieval by the controller and sending to the messenger. |
|
| 47 | + * |
|
| 48 | + * @var array of message objects. |
|
| 49 | + */ |
|
| 50 | + public $messages = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The following holds the templates that will be used to assemble the message object for the messenger. |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + protected $_templates; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * If a specific template is being parsed, this will hold the message template group GRP_ID for that template. |
|
| 62 | + * |
|
| 63 | + * @var int. |
|
| 64 | + */ |
|
| 65 | + protected $_GRP_ID; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** OTHER INFO PROPERTIES **/ |
|
| 69 | + /** |
|
| 70 | + * This will hold the count of the message objects in the messages array. This could be used for determining if |
|
| 71 | + * batching/queueing is needed. |
|
| 72 | + * |
|
| 73 | + * @var int |
|
| 74 | + */ |
|
| 75 | + public $count = 0; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * This is set via the `do_messenger_hooks` method and contains the messenger being used to send the message of |
|
| 80 | + * this message type at time of sending. |
|
| 81 | + * |
|
| 82 | + * @var EE_messenger |
|
| 83 | + */ |
|
| 84 | + protected $_active_messenger; |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * This will hold the shortcode_replace instance for handling replacement of shortcodes in the various templates |
|
| 89 | + * |
|
| 90 | + * @var object |
|
| 91 | + */ |
|
| 92 | + protected $_shortcode_replace; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * The purpose for this property is to simply allow message types to indicate if the message generated is intended |
|
| 97 | + * for only single context. Child message types should redefine this variable (if necessary) in the |
|
| 98 | + * _set_data_Handler() method. |
|
| 99 | + * |
|
| 100 | + * @var boolean |
|
| 101 | + */ |
|
| 102 | + protected $_single_message = false; |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * This will hold an array of specific reg_ids that are receiving messages. |
|
| 107 | + * |
|
| 108 | + * @since 4.7.x |
|
| 109 | + * @var array |
|
| 110 | + */ |
|
| 111 | + protected $_regs_for_sending = array(); |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * This holds the data passed to this class from the controller and also the final processed data. |
|
| 116 | + * |
|
| 117 | + * @var object |
|
| 118 | + */ |
|
| 119 | + protected $_data; |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * this is just a flag indicating whether we're in preview mode or not. |
|
| 124 | + * |
|
| 125 | + * @var bool |
|
| 126 | + */ |
|
| 127 | + protected $_preview = false; |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * This just holds defaults for addressee data that children merge with their data array setup |
|
| 132 | + * |
|
| 133 | + * @var array |
|
| 134 | + */ |
|
| 135 | + protected $_default_addressee_data; |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Child classes declare through this property what handler they want to use for the incoming data and this string |
|
| 140 | + * is used to instantiate the EE_Messages_incoming_data child class for that handler. |
|
| 141 | + * |
|
| 142 | + * @var string |
|
| 143 | + */ |
|
| 144 | + protected $_data_handler; |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * This holds any specific fields for holding any settings related to a message type (if any needed) |
|
| 149 | + * |
|
| 150 | + * @var array |
|
| 151 | + */ |
|
| 152 | + protected $_admin_settings_fields = array(); |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * this property will hold any existing setting that may have been set in the admin. |
|
| 156 | + * |
|
| 157 | + * @var array |
|
| 158 | + */ |
|
| 159 | + protected $_existing_admin_settings = array(); |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * This is used to designate the generating and alternative sending messengers for a message type. It is set via |
|
| 164 | + * set_with_messengers() on construct. Note, generating messenger also acts as a sending messenger for this message |
|
| 165 | + * type. However ONLY the generating messengers are used for creating templates for this message type. Should be |
|
| 166 | + * in this format: |
|
| 167 | + * { |
|
| 168 | + * |
|
| 169 | + * @type string $generating_messenger the name of the generating messenger. Generating |
|
| 170 | + * messengers are used for generating templates, |
|
| 171 | + * doing validation and defining valid shortcodes. |
|
| 172 | + * { |
|
| 173 | + * @type string $sending_messenger values are the name(s) for the sending |
|
| 174 | + * messengers. sending messengers are |
|
| 175 | + * just valid delivery vehicles that will utilize |
|
| 176 | + * the templates (and generated EE_message |
|
| 177 | + * objects from the generating messengers). |
|
| 178 | + * } |
|
| 179 | + * } |
|
| 180 | + * @since 4.5.0 |
|
| 181 | + * @var array |
|
| 182 | + */ |
|
| 183 | + protected $_with_messengers = array(); |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * This holds the addressees in an array indexed by context for later retrieval when assembling the message objects. |
|
| 188 | + * |
|
| 189 | + * @access protected |
|
| 190 | + * @var array |
|
| 191 | + */ |
|
| 192 | + protected $_addressees = array(); |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * This allows each message type to set what alternate messenger&message type combination can be used for fallback |
|
| 197 | + * default templates if there are no specific ones defined for this messenger and message type. Should be in the |
|
| 198 | + * format: |
|
| 199 | + * array( |
|
| 200 | + * 'messenger' => 'message_type', |
|
| 201 | + * 'another_messenger' => another_message_type |
|
| 202 | + * ); |
|
| 203 | + * This is set in the message type constructor. |
|
| 204 | + * |
|
| 205 | + * @var array |
|
| 206 | + */ |
|
| 207 | + protected $_master_templates = array(); |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * This holds whatever the set template pack is for a message template group when generating messages. |
|
| 212 | + * |
|
| 213 | + * @since 4.5.0 |
|
| 214 | + * @var EE_Messages_Template_Pack |
|
| 215 | + */ |
|
| 216 | + protected $_template_pack; |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * This holds whatever the set variation is for a message template group when generating messages. |
|
| 221 | + * |
|
| 222 | + * @since 4.5.0 |
|
| 223 | + * @var string |
|
| 224 | + */ |
|
| 225 | + protected $_variation; |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * EE_message_type constructor. |
|
| 230 | + */ |
|
| 231 | + public function __construct() |
|
| 232 | + { |
|
| 233 | + $this->_messages_item_type = 'message_type'; |
|
| 234 | + $this->_set_contexts(); |
|
| 235 | + $this->_set_with_messengers(); |
|
| 236 | + parent::__construct(); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * This sets the data handler for the message type. It must be used to define the _data_handler property. It is |
|
| 242 | + * called when messages are setup. |
|
| 243 | + * |
|
| 244 | + * @abstract |
|
| 245 | + * @access protected |
|
| 246 | + * @return void |
|
| 247 | + */ |
|
| 248 | + abstract protected function _set_data_handler(); |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * This method should return a EE_Base_Class object (or array of EE_Base_Class objects) for the given context and |
|
| 253 | + * ID (which should be the primary key id for the base class). Client code doesn't have to know what a message |
|
| 254 | + * type's data handler is. |
|
| 255 | + * |
|
| 256 | + * @since 4.5.0 |
|
| 257 | + * @param string $context This should be a string matching a valid context for the message type. |
|
| 258 | + * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
| 259 | + * guessing a url). |
|
| 260 | + * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
| 261 | + * EE_Base_Class_Object |
|
| 262 | + * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
|
| 263 | + */ |
|
| 264 | + abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * _set_contexts |
|
| 269 | + * This sets up the contexts associated with the message_type |
|
| 270 | + * |
|
| 271 | + * @abstract |
|
| 272 | + * @access protected |
|
| 273 | + * @return void |
|
| 274 | + */ |
|
| 275 | + abstract protected function _set_contexts(); |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * This is used to get the "id" value fo the msg_trigger_url generated by get_url_trigger(). |
|
| 280 | + * In most cases, child classes don't need anything, (hence the default of 0), however if there is a specific |
|
| 281 | + * EE_Base_Class that is required in generating a message for a message type recipient then the message |
|
| 282 | + * type should override this method and use the given params to generate the correct ID. |
|
| 283 | + * |
|
| 284 | + * @param string $context The message type context. |
|
| 285 | + * @param EE_Registration $registration Registration object |
|
| 286 | + * @deprecated 4.9.0 |
|
| 287 | + * @return int |
|
| 288 | + */ |
|
| 289 | + protected function _get_id_for_msg_url($context, EE_Registration $registration) |
|
| 290 | + { |
|
| 291 | + return 0; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * This sets up any action/filter hooks this message type puts in place for a specific messenger. Note that by |
|
| 297 | + * default this does nothing. Child classes will need to override if they want to add specific hooks for a |
|
| 298 | + * messenger. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.0 |
|
| 301 | + * @return void |
|
| 302 | + */ |
|
| 303 | + protected function _do_messenger_hooks() |
|
| 304 | + { |
|
| 305 | + return; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * This is a public wrapper for the protected _do_messenger_hooks() method. |
|
| 311 | + * For backward compat reasons, this was done rather than making the protected method public. |
|
| 312 | + * |
|
| 313 | + * @param EE_messenger $messenger This is used to set the $_active_messenger property, so message types are able |
|
| 314 | + * to know what messenger is being used to send the message at the time of |
|
| 315 | + * sending. |
|
| 316 | + * @since 4.9.0 |
|
| 317 | + */ |
|
| 318 | + public function do_messenger_hooks($messenger = null) |
|
| 319 | + { |
|
| 320 | + $this->_active_messenger = $messenger; |
|
| 321 | + $this->_do_messenger_hooks(); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * This method returns whether this message type should always generate a new copy |
|
| 327 | + * when requested, or if links can be to the already generated copy. |
|
| 328 | + * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table. |
|
| 329 | + * Child classes should override this if different from the default of false. |
|
| 330 | + * |
|
| 331 | + * @return bool false means can link to generated EE_Message. true must regenerate. |
|
| 332 | + */ |
|
| 333 | + public function always_generate() |
|
| 334 | + { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Returns the priority for the message type. |
|
| 341 | + * Priorities are defined as constants on EEM_Message. Currently there are three priorities: |
|
| 342 | + * - EEM_Message::priority_high |
|
| 343 | + * - EEM_Message::priority_medium |
|
| 344 | + * - EEM_Message::priority_low |
|
| 345 | + * Priority is used to determine the weight the message type is given when queuing for generation and/or sending. |
|
| 346 | + * |
|
| 347 | + * @see EEM_Message for more phpdocs on priority. |
|
| 348 | + * The default priority for all message_types is EEM_Message::priority_low. Message Types wanting to give |
|
| 349 | + * a higher priority must override this method. Also note, messengers are able to override priorities |
|
| 350 | + * queuing instructions if their "send_now" flag is set to true. An example of this is the HTML messenger |
|
| 351 | + * which displays things in the browser. |
|
| 352 | + * @since 4.9.0 |
|
| 353 | + * @return int |
|
| 354 | + */ |
|
| 355 | + public function get_priority() |
|
| 356 | + { |
|
| 357 | + return EEM_Message::priority_low; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * This runs the _set_data_handler() method for message types and then returns what got set. |
|
| 363 | + * |
|
| 364 | + * @param mixed $data This sets the data property for the message type with the incoming data used for generating. |
|
| 365 | + * @return string (the reference for the data handler) (will be an empty string if could not be determined). |
|
| 366 | + */ |
|
| 367 | + public function get_data_handler($data) |
|
| 368 | + { |
|
| 369 | + $this->_data = $data; |
|
| 370 | + $this->_set_data_handler(); |
|
| 371 | + return apply_filters('FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * This is called externally to reset the value of the $_data property for the message type. |
|
| 377 | + * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
| 378 | + * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called |
|
| 379 | + * (and for back compat reasons). This particular method is used in |
|
| 380 | + * EE_Messages_Generator::_reset_current_properties to ensure that the internal _data on the message type is |
|
| 381 | + * cleaned before subsequent EE_Message generation in the same request. |
|
| 382 | + * |
|
| 383 | + * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
| 384 | + * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
| 385 | + * expectation of what it is. Likely we need to ensure that _data is not persisted IN the message type |
|
| 386 | + * at all. |
|
| 387 | + * @internal Plugin authors, do not implement this method, it is subject to change. |
|
| 388 | + * @since 4.9 |
|
| 389 | + */ |
|
| 390 | + public function reset_data() |
|
| 391 | + { |
|
| 392 | + $this->_data = null; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * This does some validation of incoming params gets the url trigger from the defined method in the specific child |
|
| 398 | + * class and then filters the results. |
|
| 399 | + * |
|
| 400 | + * @param string $context The message type context |
|
| 401 | + * @param string $sending_messenger The sending messenger |
|
| 402 | + * @param EE_Registration $registration Registration object |
|
| 403 | + * @throws EE_Error |
|
| 404 | + * @deprecated 4.9.0 Likely 4.9.10 or 4.10.0 will remove this method completely |
|
| 405 | + * @return string generated url |
|
| 406 | + */ |
|
| 407 | + public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) |
|
| 408 | + { |
|
| 409 | + // validate context |
|
| 410 | + // valid context? |
|
| 411 | + if (! isset($this->_contexts[ $context ])) { |
|
| 412 | + throw new EE_Error( |
|
| 413 | + sprintf( |
|
| 414 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 415 | + $context, |
|
| 416 | + get_class($this) |
|
| 417 | + ) |
|
| 418 | + ); |
|
| 419 | + } |
|
| 420 | + // valid sending_messenger? |
|
| 421 | + $not_valid_msgr = false; |
|
| 422 | + foreach ($this->_with_messengers as $generating => $sendings) { |
|
| 423 | + if (empty($sendings) || array_search($sending_messenger, $sendings) === false) { |
|
| 424 | + $not_valid_msgr = true; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + if ($not_valid_msgr) { |
|
| 428 | + throw new EE_Error( |
|
| 429 | + sprintf( |
|
| 430 | + __( |
|
| 431 | + 'The given sending messenger string (%s) does not match a valid sending messenger with the %s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 432 | + 'event_espresso' |
|
| 433 | + ), |
|
| 434 | + $sending_messenger, |
|
| 435 | + get_class($this) |
|
| 436 | + ) |
|
| 437 | + ); |
|
| 438 | + } |
|
| 439 | + return EEH_MSG_Template::generate_url_trigger( |
|
| 440 | + $sending_messenger, |
|
| 441 | + $this->_active_messenger->name, |
|
| 442 | + $context, |
|
| 443 | + $this->name, |
|
| 444 | + $registration, |
|
| 445 | + $this->_GRP_ID, |
|
| 446 | + $this->_get_id_for_msg_url($context, $registration) |
|
| 447 | + ); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Wrapper for _get_data_for_context() that handles some validation before calling the main class and also allows |
|
| 453 | + * for filtering. This is (currently) called by the EED_Messages module. |
|
| 454 | + * |
|
| 455 | + * @since 4.5.0 |
|
| 456 | + * @throws EE_Error |
|
| 457 | + * @param string $context This should be a string matching a valid context for the message type. |
|
| 458 | + * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
| 459 | + * guessing a url). |
|
| 460 | + * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
| 461 | + * EE_Base_Class_Object |
|
| 462 | + * @return mixed (EE_Base_Class||EE_Base_Class[]) |
|
| 463 | + */ |
|
| 464 | + public function get_data_for_context($context, EE_Registration $registration, $id = 0) |
|
| 465 | + { |
|
| 466 | + // valid context? |
|
| 467 | + if (! isset($this->_contexts[ $context ])) { |
|
| 468 | + throw new EE_Error( |
|
| 469 | + sprintf( |
|
| 470 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 471 | + $context, |
|
| 472 | + get_class($this) |
|
| 473 | + ) |
|
| 474 | + ); |
|
| 475 | + } |
|
| 476 | + // get data and apply global and class specific filters on it. |
|
| 477 | + $data = apply_filters( |
|
| 478 | + 'FHEE__EE_message_type__get_data_for_context__data', |
|
| 479 | + $this->_get_data_for_context($context, $registration, $id), |
|
| 480 | + $this |
|
| 481 | + ); |
|
| 482 | + $data = apply_filters('FHEE__' . get_class($this) . '__get_data_for_context__data', $data, $this); |
|
| 483 | + // if empty then something went wrong! |
|
| 484 | + if (empty($data)) { |
|
| 485 | + throw new EE_Error( |
|
| 486 | + sprintf( |
|
| 487 | + __( |
|
| 488 | + 'There is no data retrieved, it is possible that the id given (%d) does not match any value in the database for the corresponding EE_Base_Class used by the data handler for the %s message type.', |
|
| 489 | + 'event_espresso' |
|
| 490 | + ), |
|
| 491 | + $id, |
|
| 492 | + $this->name |
|
| 493 | + ) |
|
| 494 | + ); |
|
| 495 | + } |
|
| 496 | + return $data; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * This returns the contents of the _data property. |
|
| 502 | + * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
| 503 | + * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called. |
|
| 504 | + * |
|
| 505 | + * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
| 506 | + * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
| 507 | + * expectation of what it is. |
|
| 508 | + * @internal Plugin authors, do not implement this method, it is subject to change. |
|
| 509 | + * @return mixed |
|
| 510 | + */ |
|
| 511 | + public function get_data() |
|
| 512 | + { |
|
| 513 | + return $this->_data; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * used to set the $_with_messengers property. (this is a default, child classes SHOULD override) |
|
| 519 | + * |
|
| 520 | + * @see property definition for description of setup. |
|
| 521 | + * @since 4.5.0 |
|
| 522 | + * @abstract |
|
| 523 | + * @return void |
|
| 524 | + */ |
|
| 525 | + protected function _set_with_messengers() |
|
| 526 | + { |
|
| 527 | + $this->_with_messengers = array( |
|
| 528 | + 'email' => array('html'), |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Return the value of the _with_messengers property |
|
| 535 | + * |
|
| 536 | + * @since 4.5.0 |
|
| 537 | + * @return array |
|
| 538 | + */ |
|
| 539 | + public function with_messengers() |
|
| 540 | + { |
|
| 541 | + return apply_filters( |
|
| 542 | + 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class($this), |
|
| 543 | + $this->_with_messengers |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class |
|
| 550 | + * callback function if that page is registered via the `_admin_registered_page` property set by the child class. |
|
| 551 | + * * |
|
| 552 | + * |
|
| 553 | + * @param string $page the slug of the EE admin page |
|
| 554 | + * @param array $messengers an array of active messenger objects |
|
| 555 | + * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
|
| 556 | + * @param array $extra This is just an extra argument that can be used to pass additional data for setting up |
|
| 557 | + * page content. |
|
| 558 | + * @access public |
|
| 559 | + * @return string |
|
| 560 | + */ |
|
| 561 | + public function get_message_type_admin_page_content( |
|
| 562 | + $page, |
|
| 563 | + $action = null, |
|
| 564 | + $extra = array(), |
|
| 565 | + $messengers = array() |
|
| 566 | + ) { |
|
| 567 | + // we can also further refine the context by action (if present). |
|
| 568 | + return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @return array |
|
| 574 | + */ |
|
| 575 | + public function get_contexts() |
|
| 576 | + { |
|
| 577 | + return $this->_contexts; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * This just returns the context label for a given context (as set in $_context_label property) |
|
| 583 | + * |
|
| 584 | + * @access public |
|
| 585 | + * @return array |
|
| 586 | + */ |
|
| 587 | + public function get_context_label() |
|
| 588 | + { |
|
| 589 | + return $this->_context_label; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * This just returns the (filtered) _master_templates property. |
|
| 595 | + * |
|
| 596 | + * @see property definition for documentation. |
|
| 597 | + * @return array |
|
| 598 | + */ |
|
| 599 | + public function get_master_templates() |
|
| 600 | + { |
|
| 601 | + // first class specific filter then filter that by the global filter. |
|
| 602 | + $master_templates = apply_filters( |
|
| 603 | + 'FHEE__' . get_class($this) . '__get_master_templates', |
|
| 604 | + $this->_master_templates |
|
| 605 | + ); |
|
| 606 | + return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Accepts an incoming data handler which contains data for processing, and returns an array of |
|
| 612 | + * EE_Messages_Addressee objects. |
|
| 613 | + * |
|
| 614 | + * @param EE_Messages_incoming_data $data |
|
| 615 | + * @param string $context Limit addressees to specific context. |
|
| 616 | + * @return array An array indexed by context where each context is an array of EE_Messages_Addressee objects for |
|
| 617 | + * that context |
|
| 618 | + * @throws EE_Error |
|
| 619 | + */ |
|
| 620 | + public function get_addressees(EE_Messages_incoming_data $data, $context = '') |
|
| 621 | + { |
|
| 622 | + // override _data |
|
| 623 | + $this->_data = $data; |
|
| 624 | + $addressees = array(); |
|
| 625 | + $original_contexts = $this->_contexts; |
|
| 626 | + // if incoming context then limit to that context |
|
| 627 | + if (! empty($context)) { |
|
| 628 | + $cntxt = ! empty($this->_contexts[ $context ]) ? $this->_contexts[ $context ] : ''; |
|
| 629 | + if (! empty($cntxt)) { |
|
| 630 | + $this->_contexts = array(); |
|
| 631 | + $this->_contexts[ $context ] = $cntxt; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $this->_set_default_addressee_data(); |
|
| 635 | + if ($this->_process_data()) { |
|
| 636 | + $addressees = $this->_addressees; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // reset contexts and addressees |
|
| 640 | + $this->_contexts = $original_contexts; |
|
| 641 | + $this->_addressees = array(); |
|
| 642 | + return $addressees; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * processes the data object so we get |
|
| 648 | + * |
|
| 649 | + * @throws EE_Error |
|
| 650 | + * @return bool true means data was processed successfully, false means not. |
|
| 651 | + */ |
|
| 652 | + protected function _process_data() |
|
| 653 | + { |
|
| 654 | + // at a minimum, we NEED EE_Attendee objects. |
|
| 655 | + if (empty($this->_data->attendees)) { |
|
| 656 | + return false; // there's no data to process! |
|
| 657 | + } |
|
| 658 | + // process addressees for each context. Child classes will have to have methods for |
|
| 659 | + // each context defined to handle the processing of the data object within them |
|
| 660 | + foreach ($this->_contexts as $context => $details) { |
|
| 661 | + $xpctd_method = '_' . $context . '_addressees'; |
|
| 662 | + if (! method_exists($this, $xpctd_method)) { |
|
| 663 | + throw new EE_Error( |
|
| 664 | + sprintf( |
|
| 665 | + __( |
|
| 666 | + 'The data for %1$s message type cannot be prepared because there is no set method for doing so. The expected method name is "%2$s" please doublecheck the %1$s message type class and make sure that method is present', |
|
| 667 | + 'event_espresso' |
|
| 668 | + ), |
|
| 669 | + $this->label['singular'], |
|
| 670 | + $xpctd_method |
|
| 671 | + ) |
|
| 672 | + ); |
|
| 673 | + } |
|
| 674 | + $this->_addressees[ $context ] = call_user_func(array($this, $xpctd_method)); |
|
| 675 | + } |
|
| 676 | + return true; // data was processed successfully. |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * sets the default_addressee_data property, |
|
| 682 | + * |
|
| 683 | + * @access private |
|
| 684 | + * @return void |
|
| 685 | + */ |
|
| 686 | + private function _set_default_addressee_data() |
|
| 687 | + { |
|
| 688 | + $this->_default_addressee_data = array( |
|
| 689 | + 'billing' => $this->_data->billing, |
|
| 690 | + 'taxes' => $this->_data->taxes, |
|
| 691 | + 'tax_line_items' => $this->_data->tax_line_items, |
|
| 692 | + 'additional_line_items' => $this->_data->additional_line_items, |
|
| 693 | + 'grand_total_line_item' => $this->_data->grand_total_line_item, |
|
| 694 | + 'txn' => $this->_data->txn, |
|
| 695 | + 'payments' => $this->_data->payments, |
|
| 696 | + 'payment' => isset($this->_data->payment) && $this->_data->payment instanceof EE_Payment |
|
| 697 | + ? $this->_data->payment |
|
| 698 | + : null, |
|
| 699 | + 'reg_objs' => $this->_data->reg_objs, |
|
| 700 | + 'registrations' => $this->_data->registrations, |
|
| 701 | + 'datetimes' => $this->_data->datetimes, |
|
| 702 | + 'tickets' => $this->_data->tickets, |
|
| 703 | + 'line_items_with_children' => $this->_data->line_items_with_children, |
|
| 704 | + 'questions' => $this->_data->questions, |
|
| 705 | + 'answers' => $this->_data->answers, |
|
| 706 | + 'txn_status' => $this->_data->txn_status, |
|
| 707 | + 'total_ticket_count' => $this->_data->total_ticket_count, |
|
| 708 | + ); |
|
| 709 | + if (is_array($this->_data->primary_attendee_data)) { |
|
| 710 | + $this->_default_addressee_data = array_merge( |
|
| 711 | + $this->_default_addressee_data, |
|
| 712 | + $this->_data->primary_attendee_data |
|
| 713 | + ); |
|
| 714 | + $this->_default_addressee_data['primary_att_obj'] = $this->_data->primary_attendee_data['att_obj']; |
|
| 715 | + $this->_default_addressee_data['primary_reg_obj'] = $this->_data->primary_attendee_data['reg_obj']; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + /******************** |
|
| 722 | 722 | * setup default shared addressee object/contexts |
| 723 | 723 | * These can be utilized simply by defining the context in the child message type. |
| 724 | 724 | * They can also be overridden if a specific message type needs to do something different for that context. |
| 725 | 725 | ****************/ |
| 726 | - /** |
|
| 727 | - * see abstract declaration in parent class for details, children message types can |
|
| 728 | - * override these valid shortcodes if desired (we include all for all contexts by default). |
|
| 729 | - */ |
|
| 730 | - protected function _set_valid_shortcodes() |
|
| 731 | - { |
|
| 732 | - $all_shortcodes = array( |
|
| 733 | - 'attendee_list', |
|
| 734 | - 'attendee', |
|
| 735 | - 'datetime_list', |
|
| 736 | - 'datetime', |
|
| 737 | - 'event_list', |
|
| 738 | - 'event_meta', |
|
| 739 | - 'event', |
|
| 740 | - 'organization', |
|
| 741 | - 'recipient_details', |
|
| 742 | - 'recipient_list', |
|
| 743 | - 'ticket_list', |
|
| 744 | - 'ticket', |
|
| 745 | - 'transaction', |
|
| 746 | - 'venue', |
|
| 747 | - 'primary_registration_details', |
|
| 748 | - 'primary_registration_list', |
|
| 749 | - 'event_author', |
|
| 750 | - 'email', |
|
| 751 | - 'messenger', |
|
| 752 | - ); |
|
| 753 | - $contexts = $this->get_contexts(); |
|
| 754 | - foreach ($contexts as $context => $details) { |
|
| 755 | - $this->_valid_shortcodes[ $context ] = $all_shortcodes; |
|
| 756 | - // make sure non admin context does not include the event_author shortcodes |
|
| 757 | - if ($context != 'admin') { |
|
| 758 | - if (($key = array_search('event_author', $this->_valid_shortcodes[ $context ])) !== false) { |
|
| 759 | - unset($this->_valid_shortcodes[ $context ][ $key ]); |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - // make sure admin context does not include the recipient_details shortcodes |
|
| 764 | - // IF we have admin context hooked in message types might not have that context. |
|
| 765 | - if (! empty($this->_valid_shortcodes['admin'])) { |
|
| 766 | - if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
| 767 | - unset($this->_valid_shortcodes['admin'][ $key ]); |
|
| 768 | - } |
|
| 769 | - // make sure admin context does not include the recipient_details shortcodes |
|
| 770 | - if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
| 771 | - unset($this->_valid_shortcodes['admin'][ $key ]); |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * Used by Validators to modify the valid shortcodes. |
|
| 779 | - * |
|
| 780 | - * @param array $new_config array of valid shortcodes (by context) |
|
| 781 | - * @return void sets valid_shortcodes property |
|
| 782 | - */ |
|
| 783 | - public function reset_valid_shortcodes_config($new_config) |
|
| 784 | - { |
|
| 785 | - foreach ($new_config as $context => $shortcodes) { |
|
| 786 | - $this->_valid_shortcodes[ $context ] = $shortcodes; |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * returns an array of addressee objects for event_admins |
|
| 793 | - * |
|
| 794 | - * @access protected |
|
| 795 | - * @return array array of EE_Messages_Addressee objects |
|
| 796 | - * @throws EE_Error |
|
| 797 | - * @throws InvalidArgumentException |
|
| 798 | - * @throws InvalidDataTypeException |
|
| 799 | - * @throws InvalidInterfaceException |
|
| 800 | - */ |
|
| 801 | - protected function _admin_addressees() |
|
| 802 | - { |
|
| 803 | - $admin_events = array(); |
|
| 804 | - $addressees = array(); |
|
| 805 | - // first we need to get the event admin user id for all the events |
|
| 806 | - // and setup an addressee object for each unique admin user. |
|
| 807 | - foreach ($this->_data->events as $line_ref => $event) { |
|
| 808 | - $admin_id = $this->_get_event_admin_id($event['ID']); |
|
| 809 | - // make sure we are just including the events that belong to this admin! |
|
| 810 | - $admin_events[ $admin_id ][ $line_ref ] = $event; |
|
| 811 | - } |
|
| 812 | - // k now we can loop through the event_admins and setup the addressee data. |
|
| 813 | - foreach ($admin_events as $admin_id => $event_details) { |
|
| 814 | - $aee = array( |
|
| 815 | - 'user_id' => $admin_id, |
|
| 816 | - 'events' => $event_details, |
|
| 817 | - 'attendees' => $this->_data->attendees, |
|
| 818 | - 'recipient_id' => $admin_id, |
|
| 819 | - 'recipient_type' => 'WP_User', |
|
| 820 | - ); |
|
| 821 | - $aee = array_merge($this->_default_addressee_data, $aee); |
|
| 822 | - $addressees[] = new EE_Messages_Addressee($aee); |
|
| 823 | - } |
|
| 824 | - return $addressees; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Takes care of setting up the addressee object(s) for the primary attendee. |
|
| 830 | - * |
|
| 831 | - * @access protected |
|
| 832 | - * @return array of EE_Addressee objects |
|
| 833 | - * @throws EE_Error |
|
| 834 | - */ |
|
| 835 | - protected function _primary_attendee_addressees() |
|
| 836 | - { |
|
| 837 | - $aee = $this->_default_addressee_data; |
|
| 838 | - $aee['events'] = $this->_data->events; |
|
| 839 | - $aee['attendees'] = $this->_data->attendees; |
|
| 840 | - $aee['recipient_id'] = $aee['primary_att_obj'] instanceof EE_Attendee ? $aee['primary_att_obj']->ID() : 0; |
|
| 841 | - $aee['recipient_type'] = 'Attendee'; |
|
| 842 | - // great now we can instantiate the $addressee object and return (as an array); |
|
| 843 | - $add[] = new EE_Messages_Addressee($aee); |
|
| 844 | - return $add; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Takes care of setting up the addressee object(s) for the registered attendees |
|
| 850 | - * |
|
| 851 | - * @access protected |
|
| 852 | - * @return array of EE_Addressee objects |
|
| 853 | - */ |
|
| 854 | - protected function _attendee_addressees() |
|
| 855 | - { |
|
| 856 | - $add = array(); |
|
| 857 | - // we just have to loop through the attendees. We'll also set the attached events for each attendee. |
|
| 858 | - // use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
|
| 859 | - $already_processed = array(); |
|
| 860 | - foreach ($this->_data->attendees as $att_id => $details) { |
|
| 861 | - // set the attendee array to blank on each loop; |
|
| 862 | - $aee = array(); |
|
| 863 | - if (isset($this->_data->reg_obj) |
|
| 864 | - && ($this->_data->reg_obj->attendee_ID() != $att_id) |
|
| 865 | - && $this->_single_message |
|
| 866 | - ) { |
|
| 867 | - continue; |
|
| 868 | - } |
|
| 869 | - // is $this->_regs_for_sending present? |
|
| 870 | - // If so, let's make sure we ONLY generate addressee for registrations in that array. |
|
| 871 | - if (! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
| 872 | - $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
| 873 | - if (empty($regs_allowed)) { |
|
| 874 | - continue; |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - if (apply_filters( |
|
| 878 | - 'FHEE__EE_message_type___attendee_addressees__prevent_duplicate_email_sends', |
|
| 879 | - true, |
|
| 880 | - $this->_data, |
|
| 881 | - $this |
|
| 882 | - ) |
|
| 883 | - && in_array($att_id, $already_processed, true) |
|
| 884 | - ) { |
|
| 885 | - continue; |
|
| 886 | - } |
|
| 887 | - $already_processed[] = $att_id; |
|
| 888 | - foreach ($details as $item => $value) { |
|
| 889 | - $aee[ $item ] = $value; |
|
| 890 | - if ($item === 'line_ref') { |
|
| 891 | - foreach ($value as $event_id) { |
|
| 892 | - $aee['events'][ $event_id ] = $this->_data->events[ $event_id ]; |
|
| 893 | - } |
|
| 894 | - } |
|
| 895 | - if ($item === 'attendee_email') { |
|
| 896 | - $aee['attendee_email'] = $value; |
|
| 897 | - } |
|
| 898 | - /*if ( $item == 'registration_id' ) { |
|
| 726 | + /** |
|
| 727 | + * see abstract declaration in parent class for details, children message types can |
|
| 728 | + * override these valid shortcodes if desired (we include all for all contexts by default). |
|
| 729 | + */ |
|
| 730 | + protected function _set_valid_shortcodes() |
|
| 731 | + { |
|
| 732 | + $all_shortcodes = array( |
|
| 733 | + 'attendee_list', |
|
| 734 | + 'attendee', |
|
| 735 | + 'datetime_list', |
|
| 736 | + 'datetime', |
|
| 737 | + 'event_list', |
|
| 738 | + 'event_meta', |
|
| 739 | + 'event', |
|
| 740 | + 'organization', |
|
| 741 | + 'recipient_details', |
|
| 742 | + 'recipient_list', |
|
| 743 | + 'ticket_list', |
|
| 744 | + 'ticket', |
|
| 745 | + 'transaction', |
|
| 746 | + 'venue', |
|
| 747 | + 'primary_registration_details', |
|
| 748 | + 'primary_registration_list', |
|
| 749 | + 'event_author', |
|
| 750 | + 'email', |
|
| 751 | + 'messenger', |
|
| 752 | + ); |
|
| 753 | + $contexts = $this->get_contexts(); |
|
| 754 | + foreach ($contexts as $context => $details) { |
|
| 755 | + $this->_valid_shortcodes[ $context ] = $all_shortcodes; |
|
| 756 | + // make sure non admin context does not include the event_author shortcodes |
|
| 757 | + if ($context != 'admin') { |
|
| 758 | + if (($key = array_search('event_author', $this->_valid_shortcodes[ $context ])) !== false) { |
|
| 759 | + unset($this->_valid_shortcodes[ $context ][ $key ]); |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + // make sure admin context does not include the recipient_details shortcodes |
|
| 764 | + // IF we have admin context hooked in message types might not have that context. |
|
| 765 | + if (! empty($this->_valid_shortcodes['admin'])) { |
|
| 766 | + if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
| 767 | + unset($this->_valid_shortcodes['admin'][ $key ]); |
|
| 768 | + } |
|
| 769 | + // make sure admin context does not include the recipient_details shortcodes |
|
| 770 | + if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
| 771 | + unset($this->_valid_shortcodes['admin'][ $key ]); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * Used by Validators to modify the valid shortcodes. |
|
| 779 | + * |
|
| 780 | + * @param array $new_config array of valid shortcodes (by context) |
|
| 781 | + * @return void sets valid_shortcodes property |
|
| 782 | + */ |
|
| 783 | + public function reset_valid_shortcodes_config($new_config) |
|
| 784 | + { |
|
| 785 | + foreach ($new_config as $context => $shortcodes) { |
|
| 786 | + $this->_valid_shortcodes[ $context ] = $shortcodes; |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * returns an array of addressee objects for event_admins |
|
| 793 | + * |
|
| 794 | + * @access protected |
|
| 795 | + * @return array array of EE_Messages_Addressee objects |
|
| 796 | + * @throws EE_Error |
|
| 797 | + * @throws InvalidArgumentException |
|
| 798 | + * @throws InvalidDataTypeException |
|
| 799 | + * @throws InvalidInterfaceException |
|
| 800 | + */ |
|
| 801 | + protected function _admin_addressees() |
|
| 802 | + { |
|
| 803 | + $admin_events = array(); |
|
| 804 | + $addressees = array(); |
|
| 805 | + // first we need to get the event admin user id for all the events |
|
| 806 | + // and setup an addressee object for each unique admin user. |
|
| 807 | + foreach ($this->_data->events as $line_ref => $event) { |
|
| 808 | + $admin_id = $this->_get_event_admin_id($event['ID']); |
|
| 809 | + // make sure we are just including the events that belong to this admin! |
|
| 810 | + $admin_events[ $admin_id ][ $line_ref ] = $event; |
|
| 811 | + } |
|
| 812 | + // k now we can loop through the event_admins and setup the addressee data. |
|
| 813 | + foreach ($admin_events as $admin_id => $event_details) { |
|
| 814 | + $aee = array( |
|
| 815 | + 'user_id' => $admin_id, |
|
| 816 | + 'events' => $event_details, |
|
| 817 | + 'attendees' => $this->_data->attendees, |
|
| 818 | + 'recipient_id' => $admin_id, |
|
| 819 | + 'recipient_type' => 'WP_User', |
|
| 820 | + ); |
|
| 821 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
| 822 | + $addressees[] = new EE_Messages_Addressee($aee); |
|
| 823 | + } |
|
| 824 | + return $addressees; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Takes care of setting up the addressee object(s) for the primary attendee. |
|
| 830 | + * |
|
| 831 | + * @access protected |
|
| 832 | + * @return array of EE_Addressee objects |
|
| 833 | + * @throws EE_Error |
|
| 834 | + */ |
|
| 835 | + protected function _primary_attendee_addressees() |
|
| 836 | + { |
|
| 837 | + $aee = $this->_default_addressee_data; |
|
| 838 | + $aee['events'] = $this->_data->events; |
|
| 839 | + $aee['attendees'] = $this->_data->attendees; |
|
| 840 | + $aee['recipient_id'] = $aee['primary_att_obj'] instanceof EE_Attendee ? $aee['primary_att_obj']->ID() : 0; |
|
| 841 | + $aee['recipient_type'] = 'Attendee'; |
|
| 842 | + // great now we can instantiate the $addressee object and return (as an array); |
|
| 843 | + $add[] = new EE_Messages_Addressee($aee); |
|
| 844 | + return $add; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Takes care of setting up the addressee object(s) for the registered attendees |
|
| 850 | + * |
|
| 851 | + * @access protected |
|
| 852 | + * @return array of EE_Addressee objects |
|
| 853 | + */ |
|
| 854 | + protected function _attendee_addressees() |
|
| 855 | + { |
|
| 856 | + $add = array(); |
|
| 857 | + // we just have to loop through the attendees. We'll also set the attached events for each attendee. |
|
| 858 | + // use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
|
| 859 | + $already_processed = array(); |
|
| 860 | + foreach ($this->_data->attendees as $att_id => $details) { |
|
| 861 | + // set the attendee array to blank on each loop; |
|
| 862 | + $aee = array(); |
|
| 863 | + if (isset($this->_data->reg_obj) |
|
| 864 | + && ($this->_data->reg_obj->attendee_ID() != $att_id) |
|
| 865 | + && $this->_single_message |
|
| 866 | + ) { |
|
| 867 | + continue; |
|
| 868 | + } |
|
| 869 | + // is $this->_regs_for_sending present? |
|
| 870 | + // If so, let's make sure we ONLY generate addressee for registrations in that array. |
|
| 871 | + if (! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
| 872 | + $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
| 873 | + if (empty($regs_allowed)) { |
|
| 874 | + continue; |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + if (apply_filters( |
|
| 878 | + 'FHEE__EE_message_type___attendee_addressees__prevent_duplicate_email_sends', |
|
| 879 | + true, |
|
| 880 | + $this->_data, |
|
| 881 | + $this |
|
| 882 | + ) |
|
| 883 | + && in_array($att_id, $already_processed, true) |
|
| 884 | + ) { |
|
| 885 | + continue; |
|
| 886 | + } |
|
| 887 | + $already_processed[] = $att_id; |
|
| 888 | + foreach ($details as $item => $value) { |
|
| 889 | + $aee[ $item ] = $value; |
|
| 890 | + if ($item === 'line_ref') { |
|
| 891 | + foreach ($value as $event_id) { |
|
| 892 | + $aee['events'][ $event_id ] = $this->_data->events[ $event_id ]; |
|
| 893 | + } |
|
| 894 | + } |
|
| 895 | + if ($item === 'attendee_email') { |
|
| 896 | + $aee['attendee_email'] = $value; |
|
| 897 | + } |
|
| 898 | + /*if ( $item == 'registration_id' ) { |
|
| 899 | 899 | $aee['attendee_registration_id'] = $value; |
| 900 | 900 | }/**/ |
| 901 | - } |
|
| 902 | - // note the FIRST reg object in this array is the one |
|
| 903 | - // we'll use for this attendee as the primary registration for this attendee. |
|
| 904 | - $aee['reg_obj'] = reset($this->_data->attendees[ $att_id ]['reg_objs']); |
|
| 905 | - $aee['attendees'] = $this->_data->attendees; |
|
| 906 | - $aee['recipient_id'] = $att_id; |
|
| 907 | - $aee['recipient_type'] = 'Attendee'; |
|
| 908 | - // merge in the primary attendee data |
|
| 909 | - $aee = array_merge($this->_default_addressee_data, $aee); |
|
| 910 | - $add[] = new EE_Messages_Addressee($aee); |
|
| 911 | - } |
|
| 912 | - return $add; |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * @param $event_id |
|
| 918 | - * @return int |
|
| 919 | - * @throws EE_Error |
|
| 920 | - * @throws InvalidArgumentException |
|
| 921 | - * @throws InvalidDataTypeException |
|
| 922 | - * @throws InvalidInterfaceException |
|
| 923 | - */ |
|
| 924 | - protected function _get_event_admin_id($event_id) |
|
| 925 | - { |
|
| 926 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 927 | - return $event instanceof EE_Event ? $event->wp_user() : 0; |
|
| 928 | - } |
|
| 901 | + } |
|
| 902 | + // note the FIRST reg object in this array is the one |
|
| 903 | + // we'll use for this attendee as the primary registration for this attendee. |
|
| 904 | + $aee['reg_obj'] = reset($this->_data->attendees[ $att_id ]['reg_objs']); |
|
| 905 | + $aee['attendees'] = $this->_data->attendees; |
|
| 906 | + $aee['recipient_id'] = $att_id; |
|
| 907 | + $aee['recipient_type'] = 'Attendee'; |
|
| 908 | + // merge in the primary attendee data |
|
| 909 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
| 910 | + $add[] = new EE_Messages_Addressee($aee); |
|
| 911 | + } |
|
| 912 | + return $add; |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * @param $event_id |
|
| 918 | + * @return int |
|
| 919 | + * @throws EE_Error |
|
| 920 | + * @throws InvalidArgumentException |
|
| 921 | + * @throws InvalidDataTypeException |
|
| 922 | + * @throws InvalidInterfaceException |
|
| 923 | + */ |
|
| 924 | + protected function _get_event_admin_id($event_id) |
|
| 925 | + { |
|
| 926 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 927 | + return $event instanceof EE_Event ? $event->wp_user() : 0; |
|
| 928 | + } |
|
| 929 | 929 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | { |
| 409 | 409 | // validate context |
| 410 | 410 | // valid context? |
| 411 | - if (! isset($this->_contexts[ $context ])) { |
|
| 411 | + if ( ! isset($this->_contexts[$context])) { |
|
| 412 | 412 | throw new EE_Error( |
| 413 | 413 | sprintf( |
| 414 | 414 | __('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | public function get_data_for_context($context, EE_Registration $registration, $id = 0) |
| 465 | 465 | { |
| 466 | 466 | // valid context? |
| 467 | - if (! isset($this->_contexts[ $context ])) { |
|
| 467 | + if ( ! isset($this->_contexts[$context])) { |
|
| 468 | 468 | throw new EE_Error( |
| 469 | 469 | sprintf( |
| 470 | 470 | __('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | $this->_get_data_for_context($context, $registration, $id), |
| 480 | 480 | $this |
| 481 | 481 | ); |
| 482 | - $data = apply_filters('FHEE__' . get_class($this) . '__get_data_for_context__data', $data, $this); |
|
| 482 | + $data = apply_filters('FHEE__'.get_class($this).'__get_data_for_context__data', $data, $this); |
|
| 483 | 483 | // if empty then something went wrong! |
| 484 | 484 | if (empty($data)) { |
| 485 | 485 | throw new EE_Error( |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | public function with_messengers() |
| 540 | 540 | { |
| 541 | 541 | return apply_filters( |
| 542 | - 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class($this), |
|
| 542 | + 'FHEE__EE_message_type__get_with_messengers__with_messengers__'.get_class($this), |
|
| 543 | 543 | $this->_with_messengers |
| 544 | 544 | ); |
| 545 | 545 | } |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | { |
| 601 | 601 | // first class specific filter then filter that by the global filter. |
| 602 | 602 | $master_templates = apply_filters( |
| 603 | - 'FHEE__' . get_class($this) . '__get_master_templates', |
|
| 603 | + 'FHEE__'.get_class($this).'__get_master_templates', |
|
| 604 | 604 | $this->_master_templates |
| 605 | 605 | ); |
| 606 | 606 | return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
@@ -624,11 +624,11 @@ discard block |
||
| 624 | 624 | $addressees = array(); |
| 625 | 625 | $original_contexts = $this->_contexts; |
| 626 | 626 | // if incoming context then limit to that context |
| 627 | - if (! empty($context)) { |
|
| 628 | - $cntxt = ! empty($this->_contexts[ $context ]) ? $this->_contexts[ $context ] : ''; |
|
| 629 | - if (! empty($cntxt)) { |
|
| 630 | - $this->_contexts = array(); |
|
| 631 | - $this->_contexts[ $context ] = $cntxt; |
|
| 627 | + if ( ! empty($context)) { |
|
| 628 | + $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
|
| 629 | + if ( ! empty($cntxt)) { |
|
| 630 | + $this->_contexts = array(); |
|
| 631 | + $this->_contexts[$context] = $cntxt; |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | $this->_set_default_addressee_data(); |
@@ -653,13 +653,13 @@ discard block |
||
| 653 | 653 | { |
| 654 | 654 | // at a minimum, we NEED EE_Attendee objects. |
| 655 | 655 | if (empty($this->_data->attendees)) { |
| 656 | - return false; // there's no data to process! |
|
| 656 | + return false; // there's no data to process! |
|
| 657 | 657 | } |
| 658 | 658 | // process addressees for each context. Child classes will have to have methods for |
| 659 | 659 | // each context defined to handle the processing of the data object within them |
| 660 | 660 | foreach ($this->_contexts as $context => $details) { |
| 661 | - $xpctd_method = '_' . $context . '_addressees'; |
|
| 662 | - if (! method_exists($this, $xpctd_method)) { |
|
| 661 | + $xpctd_method = '_'.$context.'_addressees'; |
|
| 662 | + if ( ! method_exists($this, $xpctd_method)) { |
|
| 663 | 663 | throw new EE_Error( |
| 664 | 664 | sprintf( |
| 665 | 665 | __( |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | ) |
| 672 | 672 | ); |
| 673 | 673 | } |
| 674 | - $this->_addressees[ $context ] = call_user_func(array($this, $xpctd_method)); |
|
| 674 | + $this->_addressees[$context] = call_user_func(array($this, $xpctd_method)); |
|
| 675 | 675 | } |
| 676 | 676 | return true; // data was processed successfully. |
| 677 | 677 | } |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | 'total_ticket_count' => $this->_data->total_ticket_count, |
| 708 | 708 | ); |
| 709 | 709 | if (is_array($this->_data->primary_attendee_data)) { |
| 710 | - $this->_default_addressee_data = array_merge( |
|
| 710 | + $this->_default_addressee_data = array_merge( |
|
| 711 | 711 | $this->_default_addressee_data, |
| 712 | 712 | $this->_data->primary_attendee_data |
| 713 | 713 | ); |
@@ -750,25 +750,25 @@ discard block |
||
| 750 | 750 | 'email', |
| 751 | 751 | 'messenger', |
| 752 | 752 | ); |
| 753 | - $contexts = $this->get_contexts(); |
|
| 753 | + $contexts = $this->get_contexts(); |
|
| 754 | 754 | foreach ($contexts as $context => $details) { |
| 755 | - $this->_valid_shortcodes[ $context ] = $all_shortcodes; |
|
| 755 | + $this->_valid_shortcodes[$context] = $all_shortcodes; |
|
| 756 | 756 | // make sure non admin context does not include the event_author shortcodes |
| 757 | 757 | if ($context != 'admin') { |
| 758 | - if (($key = array_search('event_author', $this->_valid_shortcodes[ $context ])) !== false) { |
|
| 759 | - unset($this->_valid_shortcodes[ $context ][ $key ]); |
|
| 758 | + if (($key = array_search('event_author', $this->_valid_shortcodes[$context])) !== false) { |
|
| 759 | + unset($this->_valid_shortcodes[$context][$key]); |
|
| 760 | 760 | } |
| 761 | 761 | } |
| 762 | 762 | } |
| 763 | 763 | // make sure admin context does not include the recipient_details shortcodes |
| 764 | 764 | // IF we have admin context hooked in message types might not have that context. |
| 765 | - if (! empty($this->_valid_shortcodes['admin'])) { |
|
| 765 | + if ( ! empty($this->_valid_shortcodes['admin'])) { |
|
| 766 | 766 | if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
| 767 | - unset($this->_valid_shortcodes['admin'][ $key ]); |
|
| 767 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
| 768 | 768 | } |
| 769 | 769 | // make sure admin context does not include the recipient_details shortcodes |
| 770 | 770 | if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
| 771 | - unset($this->_valid_shortcodes['admin'][ $key ]); |
|
| 771 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | } |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | public function reset_valid_shortcodes_config($new_config) |
| 784 | 784 | { |
| 785 | 785 | foreach ($new_config as $context => $shortcodes) { |
| 786 | - $this->_valid_shortcodes[ $context ] = $shortcodes; |
|
| 786 | + $this->_valid_shortcodes[$context] = $shortcodes; |
|
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | |
@@ -807,11 +807,11 @@ discard block |
||
| 807 | 807 | foreach ($this->_data->events as $line_ref => $event) { |
| 808 | 808 | $admin_id = $this->_get_event_admin_id($event['ID']); |
| 809 | 809 | // make sure we are just including the events that belong to this admin! |
| 810 | - $admin_events[ $admin_id ][ $line_ref ] = $event; |
|
| 810 | + $admin_events[$admin_id][$line_ref] = $event; |
|
| 811 | 811 | } |
| 812 | 812 | // k now we can loop through the event_admins and setup the addressee data. |
| 813 | 813 | foreach ($admin_events as $admin_id => $event_details) { |
| 814 | - $aee = array( |
|
| 814 | + $aee = array( |
|
| 815 | 815 | 'user_id' => $admin_id, |
| 816 | 816 | 'events' => $event_details, |
| 817 | 817 | 'attendees' => $this->_data->attendees, |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | } |
| 869 | 869 | // is $this->_regs_for_sending present? |
| 870 | 870 | // If so, let's make sure we ONLY generate addressee for registrations in that array. |
| 871 | - if (! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
| 871 | + if ( ! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
| 872 | 872 | $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
| 873 | 873 | if (empty($regs_allowed)) { |
| 874 | 874 | continue; |
@@ -886,10 +886,10 @@ discard block |
||
| 886 | 886 | } |
| 887 | 887 | $already_processed[] = $att_id; |
| 888 | 888 | foreach ($details as $item => $value) { |
| 889 | - $aee[ $item ] = $value; |
|
| 889 | + $aee[$item] = $value; |
|
| 890 | 890 | if ($item === 'line_ref') { |
| 891 | 891 | foreach ($value as $event_id) { |
| 892 | - $aee['events'][ $event_id ] = $this->_data->events[ $event_id ]; |
|
| 892 | + $aee['events'][$event_id] = $this->_data->events[$event_id]; |
|
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | 895 | if ($item === 'attendee_email') { |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | } |
| 902 | 902 | // note the FIRST reg object in this array is the one |
| 903 | 903 | // we'll use for this attendee as the primary registration for this attendee. |
| 904 | - $aee['reg_obj'] = reset($this->_data->attendees[ $att_id ]['reg_objs']); |
|
| 904 | + $aee['reg_obj'] = reset($this->_data->attendees[$att_id]['reg_objs']); |
|
| 905 | 905 | $aee['attendees'] = $this->_data->attendees; |
| 906 | 906 | $aee['recipient_id'] = $att_id; |
| 907 | 907 | $aee['recipient_type'] = 'Attendee'; |
@@ -632,7 +632,7 @@ |
||
| 632 | 632 | * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
| 633 | 633 | * or EEH_MSG_Template::convert_payment_status_to_message_type |
| 634 | 634 | * @param string $payment_status The payment status being matched. |
| 635 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 635 | + * @return string|false The payment message type slug matching the status or false if no match. |
|
| 636 | 636 | * @throws EE_Error |
| 637 | 637 | * @throws InvalidArgumentException |
| 638 | 638 | * @throws ReflectionException |
@@ -16,1335 +16,1335 @@ |
||
| 16 | 16 | class EED_Messages extends EED_Module |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This holds the EE_messages controller |
|
| 21 | - * |
|
| 22 | - * @deprecated 4.9.0 |
|
| 23 | - * @var EE_messages $_EEMSG |
|
| 24 | - */ |
|
| 25 | - protected static $_EEMSG; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 29 | - */ |
|
| 30 | - protected static $_message_resource_manager; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * This holds the EE_Messages_Processor business class. |
|
| 34 | - * |
|
| 35 | - * @type EE_Messages_Processor |
|
| 36 | - */ |
|
| 37 | - protected static $_MSG_PROCESSOR; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * holds all the paths for various messages components. |
|
| 41 | - * Utilized by autoloader registry |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - protected static $_MSG_PATHS; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 50 | - * Format is: |
|
| 51 | - * array( |
|
| 52 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 53 | - * ) |
|
| 54 | - * |
|
| 55 | - * @var EE_Messages_Template_Pack[] |
|
| 56 | - */ |
|
| 57 | - protected static $_TMP_PACKS = array(); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return EED_Messages |
|
| 62 | - */ |
|
| 63 | - public static function instance() |
|
| 64 | - { |
|
| 65 | - return parent::get_instance(__CLASS__); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 71 | - * |
|
| 72 | - * @since 4.5.0 |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - public static function set_hooks() |
|
| 76 | - { |
|
| 77 | - // actions |
|
| 78 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 79 | - add_action( |
|
| 80 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 81 | - array('EED_Messages', 'maybe_registration'), |
|
| 82 | - 10, |
|
| 83 | - 2 |
|
| 84 | - ); |
|
| 85 | - // filters |
|
| 86 | - add_filter( |
|
| 87 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 88 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 89 | - 10, |
|
| 90 | - 4 |
|
| 91 | - ); |
|
| 92 | - add_filter( |
|
| 93 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 94 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 95 | - 10, |
|
| 96 | - 4 |
|
| 97 | - ); |
|
| 98 | - // register routes |
|
| 99 | - self::_register_routes(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 104 | - * |
|
| 105 | - * @access public |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public static function set_hooks_admin() |
|
| 109 | - { |
|
| 110 | - // actions |
|
| 111 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 112 | - add_action( |
|
| 113 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 114 | - array('EED_Messages', 'payment_reminder'), |
|
| 115 | - 10 |
|
| 116 | - ); |
|
| 117 | - add_action( |
|
| 118 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 119 | - array('EED_Messages', 'maybe_registration'), |
|
| 120 | - 10, |
|
| 121 | - 3 |
|
| 122 | - ); |
|
| 123 | - add_action( |
|
| 124 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 125 | - array('EED_Messages', 'send_newsletter_message'), |
|
| 126 | - 10, |
|
| 127 | - 2 |
|
| 128 | - ); |
|
| 129 | - add_action( |
|
| 130 | - 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 131 | - array('EED_Messages', 'cancelled_registration'), |
|
| 132 | - 10 |
|
| 133 | - ); |
|
| 134 | - add_action( |
|
| 135 | - 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 136 | - array('EED_Messages', 'process_admin_payment'), |
|
| 137 | - 10, |
|
| 138 | - 1 |
|
| 139 | - ); |
|
| 140 | - // filters |
|
| 141 | - add_filter( |
|
| 142 | - 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 143 | - array('EED_Messages', 'process_resend'), |
|
| 144 | - 10, |
|
| 145 | - 2 |
|
| 146 | - ); |
|
| 147 | - add_filter( |
|
| 148 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 149 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 150 | - 10, |
|
| 151 | - 4 |
|
| 152 | - ); |
|
| 153 | - add_filter( |
|
| 154 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 155 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 156 | - 10, |
|
| 157 | - 4 |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * All the message triggers done by route go in here. |
|
| 164 | - * |
|
| 165 | - * @since 4.5.0 |
|
| 166 | - * @return void |
|
| 167 | - */ |
|
| 168 | - protected static function _register_routes() |
|
| 169 | - { |
|
| 170 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 171 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 172 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 173 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 174 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * This is called when a browser display trigger is executed. |
|
| 180 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 181 | - * browser. |
|
| 182 | - * |
|
| 183 | - * @since 4.9.0 |
|
| 184 | - * @param WP $WP |
|
| 185 | - * @throws EE_Error |
|
| 186 | - * @throws InvalidArgumentException |
|
| 187 | - * @throws ReflectionException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - */ |
|
| 191 | - public function browser_trigger($WP) |
|
| 192 | - { |
|
| 193 | - // ensure controller is loaded |
|
| 194 | - self::_load_controller(); |
|
| 195 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 196 | - try { |
|
| 197 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 198 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 199 | - } catch (EE_Error $e) { |
|
| 200 | - $error_msg = __( |
|
| 201 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ); |
|
| 204 | - // add specific message for developers if WP_DEBUG in on |
|
| 205 | - $error_msg .= '||' . $e->getMessage(); |
|
| 206 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * This is called when a browser error trigger is executed. |
|
| 213 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 214 | - * message and display it. |
|
| 215 | - * |
|
| 216 | - * @since 4.9.0 |
|
| 217 | - * @param $WP |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws InvalidArgumentException |
|
| 220 | - * @throws InvalidDataTypeException |
|
| 221 | - * @throws InvalidInterfaceException |
|
| 222 | - */ |
|
| 223 | - public function browser_error_trigger($WP) |
|
| 224 | - { |
|
| 225 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 226 | - if ($token) { |
|
| 227 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 228 | - if ($message instanceof EE_Message) { |
|
| 229 | - header('HTTP/1.1 200 OK'); |
|
| 230 | - $error_msg = nl2br($message->error_message()); |
|
| 231 | - ?> |
|
| 19 | + /** |
|
| 20 | + * This holds the EE_messages controller |
|
| 21 | + * |
|
| 22 | + * @deprecated 4.9.0 |
|
| 23 | + * @var EE_messages $_EEMSG |
|
| 24 | + */ |
|
| 25 | + protected static $_EEMSG; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 29 | + */ |
|
| 30 | + protected static $_message_resource_manager; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * This holds the EE_Messages_Processor business class. |
|
| 34 | + * |
|
| 35 | + * @type EE_Messages_Processor |
|
| 36 | + */ |
|
| 37 | + protected static $_MSG_PROCESSOR; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * holds all the paths for various messages components. |
|
| 41 | + * Utilized by autoloader registry |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + protected static $_MSG_PATHS; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 50 | + * Format is: |
|
| 51 | + * array( |
|
| 52 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 53 | + * ) |
|
| 54 | + * |
|
| 55 | + * @var EE_Messages_Template_Pack[] |
|
| 56 | + */ |
|
| 57 | + protected static $_TMP_PACKS = array(); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return EED_Messages |
|
| 62 | + */ |
|
| 63 | + public static function instance() |
|
| 64 | + { |
|
| 65 | + return parent::get_instance(__CLASS__); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 71 | + * |
|
| 72 | + * @since 4.5.0 |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + public static function set_hooks() |
|
| 76 | + { |
|
| 77 | + // actions |
|
| 78 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 79 | + add_action( |
|
| 80 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 81 | + array('EED_Messages', 'maybe_registration'), |
|
| 82 | + 10, |
|
| 83 | + 2 |
|
| 84 | + ); |
|
| 85 | + // filters |
|
| 86 | + add_filter( |
|
| 87 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 88 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 89 | + 10, |
|
| 90 | + 4 |
|
| 91 | + ); |
|
| 92 | + add_filter( |
|
| 93 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 94 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 95 | + 10, |
|
| 96 | + 4 |
|
| 97 | + ); |
|
| 98 | + // register routes |
|
| 99 | + self::_register_routes(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 104 | + * |
|
| 105 | + * @access public |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public static function set_hooks_admin() |
|
| 109 | + { |
|
| 110 | + // actions |
|
| 111 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 112 | + add_action( |
|
| 113 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 114 | + array('EED_Messages', 'payment_reminder'), |
|
| 115 | + 10 |
|
| 116 | + ); |
|
| 117 | + add_action( |
|
| 118 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 119 | + array('EED_Messages', 'maybe_registration'), |
|
| 120 | + 10, |
|
| 121 | + 3 |
|
| 122 | + ); |
|
| 123 | + add_action( |
|
| 124 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 125 | + array('EED_Messages', 'send_newsletter_message'), |
|
| 126 | + 10, |
|
| 127 | + 2 |
|
| 128 | + ); |
|
| 129 | + add_action( |
|
| 130 | + 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 131 | + array('EED_Messages', 'cancelled_registration'), |
|
| 132 | + 10 |
|
| 133 | + ); |
|
| 134 | + add_action( |
|
| 135 | + 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 136 | + array('EED_Messages', 'process_admin_payment'), |
|
| 137 | + 10, |
|
| 138 | + 1 |
|
| 139 | + ); |
|
| 140 | + // filters |
|
| 141 | + add_filter( |
|
| 142 | + 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 143 | + array('EED_Messages', 'process_resend'), |
|
| 144 | + 10, |
|
| 145 | + 2 |
|
| 146 | + ); |
|
| 147 | + add_filter( |
|
| 148 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 149 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 150 | + 10, |
|
| 151 | + 4 |
|
| 152 | + ); |
|
| 153 | + add_filter( |
|
| 154 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 155 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 156 | + 10, |
|
| 157 | + 4 |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * All the message triggers done by route go in here. |
|
| 164 | + * |
|
| 165 | + * @since 4.5.0 |
|
| 166 | + * @return void |
|
| 167 | + */ |
|
| 168 | + protected static function _register_routes() |
|
| 169 | + { |
|
| 170 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 171 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 172 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 173 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 174 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * This is called when a browser display trigger is executed. |
|
| 180 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 181 | + * browser. |
|
| 182 | + * |
|
| 183 | + * @since 4.9.0 |
|
| 184 | + * @param WP $WP |
|
| 185 | + * @throws EE_Error |
|
| 186 | + * @throws InvalidArgumentException |
|
| 187 | + * @throws ReflectionException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + */ |
|
| 191 | + public function browser_trigger($WP) |
|
| 192 | + { |
|
| 193 | + // ensure controller is loaded |
|
| 194 | + self::_load_controller(); |
|
| 195 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 196 | + try { |
|
| 197 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 198 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 199 | + } catch (EE_Error $e) { |
|
| 200 | + $error_msg = __( |
|
| 201 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ); |
|
| 204 | + // add specific message for developers if WP_DEBUG in on |
|
| 205 | + $error_msg .= '||' . $e->getMessage(); |
|
| 206 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * This is called when a browser error trigger is executed. |
|
| 213 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 214 | + * message and display it. |
|
| 215 | + * |
|
| 216 | + * @since 4.9.0 |
|
| 217 | + * @param $WP |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws InvalidArgumentException |
|
| 220 | + * @throws InvalidDataTypeException |
|
| 221 | + * @throws InvalidInterfaceException |
|
| 222 | + */ |
|
| 223 | + public function browser_error_trigger($WP) |
|
| 224 | + { |
|
| 225 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 226 | + if ($token) { |
|
| 227 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 228 | + if ($message instanceof EE_Message) { |
|
| 229 | + header('HTTP/1.1 200 OK'); |
|
| 230 | + $error_msg = nl2br($message->error_message()); |
|
| 231 | + ?> |
|
| 232 | 232 | <!DOCTYPE html> |
| 233 | 233 | <html> |
| 234 | 234 | <head></head> |
| 235 | 235 | <body> |
| 236 | 236 | <?php echo empty($error_msg) |
| 237 | - ? esc_html__( |
|
| 238 | - 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ) |
|
| 241 | - : wp_kses( |
|
| 242 | - $error_msg, |
|
| 243 | - array( |
|
| 244 | - 'a' => array( |
|
| 245 | - 'href' => array(), |
|
| 246 | - 'title' => array(), |
|
| 247 | - ), |
|
| 248 | - 'span' => array(), |
|
| 249 | - 'div' => array(), |
|
| 250 | - 'p' => array(), |
|
| 251 | - 'strong' => array(), |
|
| 252 | - 'em' => array(), |
|
| 253 | - 'br' => array(), |
|
| 254 | - ) |
|
| 255 | - ); ?> |
|
| 237 | + ? esc_html__( |
|
| 238 | + 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ) |
|
| 241 | + : wp_kses( |
|
| 242 | + $error_msg, |
|
| 243 | + array( |
|
| 244 | + 'a' => array( |
|
| 245 | + 'href' => array(), |
|
| 246 | + 'title' => array(), |
|
| 247 | + ), |
|
| 248 | + 'span' => array(), |
|
| 249 | + 'div' => array(), |
|
| 250 | + 'p' => array(), |
|
| 251 | + 'strong' => array(), |
|
| 252 | + 'em' => array(), |
|
| 253 | + 'br' => array(), |
|
| 254 | + ) |
|
| 255 | + ); ?> |
|
| 256 | 256 | </body> |
| 257 | 257 | </html> |
| 258 | 258 | <?php |
| 259 | - exit; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * This runs when the msg_url_trigger route has initiated. |
|
| 268 | - * |
|
| 269 | - * @since 4.5.0 |
|
| 270 | - * @param WP $WP |
|
| 271 | - * @throws EE_Error |
|
| 272 | - * @throws InvalidArgumentException |
|
| 273 | - * @throws ReflectionException |
|
| 274 | - * @throws InvalidDataTypeException |
|
| 275 | - * @throws InvalidInterfaceException |
|
| 276 | - */ |
|
| 277 | - public function run($WP) |
|
| 278 | - { |
|
| 279 | - // ensure controller is loaded |
|
| 280 | - self::_load_controller(); |
|
| 281 | - // attempt to process message |
|
| 282 | - try { |
|
| 283 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 284 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 285 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 286 | - } catch (EE_Error $e) { |
|
| 287 | - $error_msg = __( |
|
| 288 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 289 | - 'event_espresso' |
|
| 290 | - ); |
|
| 291 | - // add specific message for developers if WP_DEBUG in on |
|
| 292 | - $error_msg .= '||' . $e->getMessage(); |
|
| 293 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 300 | - * |
|
| 301 | - * @param WP $WP |
|
| 302 | - */ |
|
| 303 | - public function execute_batch_request($WP) |
|
| 304 | - { |
|
| 305 | - $this->run_cron(); |
|
| 306 | - header('HTTP/1.1 200 OK'); |
|
| 307 | - exit(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 313 | - * request. |
|
| 314 | - */ |
|
| 315 | - public function run_cron() |
|
| 316 | - { |
|
| 317 | - self::_load_controller(); |
|
| 318 | - // get required vars |
|
| 319 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 320 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 321 | - |
|
| 322 | - // now let's verify transient, if not valid exit immediately |
|
| 323 | - if (! get_transient($transient_key)) { |
|
| 324 | - /** |
|
| 325 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 326 | - * request. |
|
| 327 | - */ |
|
| 328 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // if made it here, lets' delete the transient to keep the db clean |
|
| 332 | - delete_transient($transient_key); |
|
| 333 | - |
|
| 334 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 335 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 336 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 337 | - self::$_MSG_PROCESSOR->$method(); |
|
| 338 | - } else { |
|
| 339 | - // no matching task |
|
| 340 | - /** |
|
| 341 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 342 | - * request. |
|
| 343 | - */ |
|
| 344 | - trigger_error( |
|
| 345 | - esc_attr( |
|
| 346 | - sprintf( |
|
| 347 | - __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 348 | - $cron_type |
|
| 349 | - ) |
|
| 350 | - ) |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * This is used to retrieve the template pack for the given name. |
|
| 361 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 362 | - * the default template pack is returned. |
|
| 363 | - * |
|
| 364 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 365 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 366 | - * in generating the Pack class name). |
|
| 367 | - * @return EE_Messages_Template_Pack |
|
| 368 | - * @throws EE_Error |
|
| 369 | - * @throws InvalidArgumentException |
|
| 370 | - * @throws ReflectionException |
|
| 371 | - * @throws InvalidDataTypeException |
|
| 372 | - * @throws InvalidInterfaceException |
|
| 373 | - */ |
|
| 374 | - public static function get_template_pack($template_pack_name) |
|
| 375 | - { |
|
| 376 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 377 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Retrieves an array of all template packs. |
|
| 383 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 384 | - * |
|
| 385 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 386 | - * @return EE_Messages_Template_Pack[] |
|
| 387 | - * @throws EE_Error |
|
| 388 | - * @throws InvalidArgumentException |
|
| 389 | - * @throws ReflectionException |
|
| 390 | - * @throws InvalidDataTypeException |
|
| 391 | - * @throws InvalidInterfaceException |
|
| 392 | - */ |
|
| 393 | - public static function get_template_packs() |
|
| 394 | - { |
|
| 395 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 396 | - |
|
| 397 | - // for backward compat, let's make sure this returns in the same format as originally. |
|
| 398 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 399 | - $template_pack_collection->rewind(); |
|
| 400 | - $template_packs = array(); |
|
| 401 | - while ($template_pack_collection->valid()) { |
|
| 402 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 403 | - $template_pack_collection->next(); |
|
| 404 | - } |
|
| 405 | - return $template_packs; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 411 | - * |
|
| 412 | - * @since 4.5.0 |
|
| 413 | - * @return void |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public static function set_autoloaders() |
|
| 417 | - { |
|
| 418 | - if (empty(self::$_MSG_PATHS)) { |
|
| 419 | - self::_set_messages_paths(); |
|
| 420 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 421 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 422 | - } |
|
| 423 | - // add aliases |
|
| 424 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 425 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 432 | - * for use by the Messages Autoloaders |
|
| 433 | - * |
|
| 434 | - * @since 4.5.0 |
|
| 435 | - * @return void. |
|
| 436 | - */ |
|
| 437 | - protected static function _set_messages_paths() |
|
| 438 | - { |
|
| 439 | - $dir_ref = array( |
|
| 440 | - 'messages/message_type', |
|
| 441 | - 'messages/messenger', |
|
| 442 | - 'messages/defaults', |
|
| 443 | - 'messages/defaults/email', |
|
| 444 | - 'messages/data_class', |
|
| 445 | - 'messages/validators', |
|
| 446 | - 'messages/validators/email', |
|
| 447 | - 'messages/validators/html', |
|
| 448 | - 'shortcodes', |
|
| 449 | - ); |
|
| 450 | - $paths = array(); |
|
| 451 | - foreach ($dir_ref as $index => $dir) { |
|
| 452 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 453 | - } |
|
| 454 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Takes care of loading dependencies |
|
| 460 | - * |
|
| 461 | - * @since 4.5.0 |
|
| 462 | - * @return void |
|
| 463 | - * @throws EE_Error |
|
| 464 | - * @throws InvalidArgumentException |
|
| 465 | - * @throws ReflectionException |
|
| 466 | - * @throws InvalidDataTypeException |
|
| 467 | - * @throws InvalidInterfaceException |
|
| 468 | - */ |
|
| 469 | - protected static function _load_controller() |
|
| 470 | - { |
|
| 471 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 472 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 473 | - self::set_autoloaders(); |
|
| 474 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 475 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 476 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @param EE_Transaction $transaction |
|
| 483 | - * @throws EE_Error |
|
| 484 | - * @throws InvalidArgumentException |
|
| 485 | - * @throws InvalidDataTypeException |
|
| 486 | - * @throws InvalidInterfaceException |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - */ |
|
| 489 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 490 | - { |
|
| 491 | - self::_load_controller(); |
|
| 492 | - $data = array($transaction, null); |
|
| 493 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 499 | - * |
|
| 500 | - * @param EE_Transaction $transaction object |
|
| 501 | - * @param EE_Payment|null $payment object |
|
| 502 | - * @return void |
|
| 503 | - * @throws EE_Error |
|
| 504 | - * @throws InvalidArgumentException |
|
| 505 | - * @throws ReflectionException |
|
| 506 | - * @throws InvalidDataTypeException |
|
| 507 | - * @throws InvalidInterfaceException |
|
| 508 | - */ |
|
| 509 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 510 | - { |
|
| 511 | - // if there's no payment object, then we cannot do a payment type message! |
|
| 512 | - if (! $payment instanceof EE_Payment) { |
|
| 513 | - return; |
|
| 514 | - } |
|
| 515 | - self::_load_controller(); |
|
| 516 | - $data = array($transaction, $payment); |
|
| 517 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 518 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 519 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 520 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 521 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @param EE_Transaction $transaction |
|
| 527 | - * @throws EE_Error |
|
| 528 | - * @throws InvalidArgumentException |
|
| 529 | - * @throws InvalidDataTypeException |
|
| 530 | - * @throws InvalidInterfaceException |
|
| 531 | - * @throws ReflectionException |
|
| 532 | - */ |
|
| 533 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 534 | - { |
|
| 535 | - self::_load_controller(); |
|
| 536 | - $data = array($transaction, null); |
|
| 537 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Trigger for Registration messages |
|
| 543 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 544 | - * incoming transaction. |
|
| 545 | - * |
|
| 546 | - * @param EE_Registration $registration |
|
| 547 | - * @param array $extra_details |
|
| 548 | - * @return void |
|
| 549 | - * @throws EE_Error |
|
| 550 | - * @throws InvalidArgumentException |
|
| 551 | - * @throws InvalidDataTypeException |
|
| 552 | - * @throws InvalidInterfaceException |
|
| 553 | - * @throws ReflectionException |
|
| 554 | - * @throws EntityNotFoundException |
|
| 555 | - */ |
|
| 556 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 557 | - { |
|
| 558 | - |
|
| 559 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 560 | - // no messages please |
|
| 561 | - return; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 565 | - $all_registrations = $registration->transaction()->registrations( |
|
| 566 | - array( |
|
| 567 | - array('REG_deleted' => false), |
|
| 568 | - 'order_by' => array( |
|
| 569 | - 'Event.EVT_name' => 'ASC', |
|
| 570 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 571 | - 'Attendee.ATT_fname' => 'ASC', |
|
| 572 | - ), |
|
| 573 | - ) |
|
| 574 | - ); |
|
| 575 | - // cached array of statuses so we only trigger messages once per status. |
|
| 576 | - $statuses_sent = array(); |
|
| 577 | - self::_load_controller(); |
|
| 578 | - $mtgs = array(); |
|
| 579 | - |
|
| 580 | - // loop through registrations and trigger messages once per status. |
|
| 581 | - foreach ($all_registrations as $reg) { |
|
| 582 | - // already triggered? |
|
| 583 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 584 | - continue; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 588 | - $mtgs = array_merge( |
|
| 589 | - $mtgs, |
|
| 590 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 591 | - $message_type, |
|
| 592 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 593 | - ) |
|
| 594 | - ); |
|
| 595 | - $statuses_sent[] = $reg->status_ID(); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if (count($statuses_sent) > 1) { |
|
| 599 | - $mtgs = array_merge( |
|
| 600 | - $mtgs, |
|
| 601 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 602 | - 'registration_summary', |
|
| 603 | - array($registration->transaction(), null) |
|
| 604 | - ) |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - // batch queue and initiate request |
|
| 609 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 610 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 616 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 617 | - * |
|
| 618 | - * @param EE_Registration $registration [description] |
|
| 619 | - * @param array $extra_details [description] |
|
| 620 | - * @return bool true = send away, false = nope halt the presses. |
|
| 621 | - */ |
|
| 622 | - protected static function _verify_registration_notification_send( |
|
| 623 | - EE_Registration $registration, |
|
| 624 | - $extra_details = array() |
|
| 625 | - ) { |
|
| 626 | - if (! $registration->is_primary_registrant()) { |
|
| 627 | - return false; |
|
| 628 | - } |
|
| 629 | - // first we check if we're in admin and not doing front ajax |
|
| 630 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 631 | - // make sure appropriate admin params are set for sending messages |
|
| 632 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 633 | - | ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 634 | - ) { |
|
| 635 | - // no messages sent please. |
|
| 636 | - return false; |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - // frontend request (either regular or via AJAX) |
|
| 640 | - // TXN is NOT finalized ? |
|
| 641 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 642 | - return false; |
|
| 643 | - } |
|
| 644 | - // return visit but nothing changed ??? |
|
| 645 | - if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 646 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 647 | - ) { |
|
| 648 | - return false; |
|
| 649 | - } |
|
| 650 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 651 | - if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 652 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 653 | - ) { |
|
| 654 | - return false; |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - // release the kraken |
|
| 658 | - return true; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 664 | - * status id. |
|
| 665 | - * |
|
| 666 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 667 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 668 | - * @param string $reg_status |
|
| 669 | - * @return array |
|
| 670 | - * @throws EE_Error |
|
| 671 | - * @throws InvalidArgumentException |
|
| 672 | - * @throws ReflectionException |
|
| 673 | - * @throws InvalidDataTypeException |
|
| 674 | - * @throws InvalidInterfaceException |
|
| 675 | - */ |
|
| 676 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 677 | - { |
|
| 678 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 679 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 680 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 681 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Simply returns the payment message type for the given payment status. |
|
| 687 | - * |
|
| 688 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 689 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 690 | - * @param string $payment_status The payment status being matched. |
|
| 691 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 692 | - * @throws EE_Error |
|
| 693 | - * @throws InvalidArgumentException |
|
| 694 | - * @throws ReflectionException |
|
| 695 | - * @throws InvalidDataTypeException |
|
| 696 | - * @throws InvalidInterfaceException |
|
| 697 | - */ |
|
| 698 | - protected static function _get_payment_message_type($payment_status) |
|
| 699 | - { |
|
| 700 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 701 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 702 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 703 | - : false; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 709 | - * |
|
| 710 | - * @access public |
|
| 711 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 712 | - * @return bool success/fail |
|
| 713 | - * @throws EE_Error |
|
| 714 | - * @throws InvalidArgumentException |
|
| 715 | - * @throws InvalidDataTypeException |
|
| 716 | - * @throws InvalidInterfaceException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - */ |
|
| 719 | - public static function process_resend($req_data) |
|
| 720 | - { |
|
| 721 | - self::_load_controller(); |
|
| 722 | - |
|
| 723 | - // if $msgID in this request then skip to the new resend_message |
|
| 724 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 725 | - return self::resend_message(); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 729 | - $req_data = (array) $req_data; |
|
| 730 | - foreach ($req_data as $request_key => $request_value) { |
|
| 731 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 735 | - )) { |
|
| 736 | - return false; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - try { |
|
| 740 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 741 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 742 | - } catch (EE_Error $e) { |
|
| 743 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 744 | - return false; |
|
| 745 | - } |
|
| 746 | - EE_Error::add_success( |
|
| 747 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 748 | - ); |
|
| 749 | - return true; // everything got queued. |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 755 | - * |
|
| 756 | - * @return bool |
|
| 757 | - * @throws EE_Error |
|
| 758 | - * @throws InvalidArgumentException |
|
| 759 | - * @throws InvalidDataTypeException |
|
| 760 | - * @throws InvalidInterfaceException |
|
| 761 | - * @throws ReflectionException |
|
| 762 | - */ |
|
| 763 | - public static function resend_message() |
|
| 764 | - { |
|
| 765 | - self::_load_controller(); |
|
| 766 | - |
|
| 767 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 768 | - if (! $msgID) { |
|
| 769 | - EE_Error::add_error( |
|
| 770 | - __( |
|
| 771 | - 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 772 | - 'event_espresso' |
|
| 773 | - ), |
|
| 774 | - __FILE__, |
|
| 775 | - __FUNCTION__, |
|
| 776 | - __LINE__ |
|
| 777 | - ); |
|
| 778 | - return false; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 782 | - |
|
| 783 | - // setup success message. |
|
| 784 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 785 | - EE_Error::add_success( |
|
| 786 | - sprintf( |
|
| 787 | - _n( |
|
| 788 | - 'There was %d message queued for resending.', |
|
| 789 | - 'There were %d messages queued for resending.', |
|
| 790 | - $count_ready_for_resend, |
|
| 791 | - 'event_espresso' |
|
| 792 | - ), |
|
| 793 | - $count_ready_for_resend |
|
| 794 | - ) |
|
| 795 | - ); |
|
| 796 | - return true; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * Message triggers for manual payment applied by admin |
|
| 802 | - * |
|
| 803 | - * @param EE_Payment $payment EE_payment object |
|
| 804 | - * @return bool success/fail |
|
| 805 | - * @throws EE_Error |
|
| 806 | - * @throws InvalidArgumentException |
|
| 807 | - * @throws ReflectionException |
|
| 808 | - * @throws InvalidDataTypeException |
|
| 809 | - * @throws InvalidInterfaceException |
|
| 810 | - */ |
|
| 811 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 812 | - { |
|
| 813 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 814 | - // we need to get the transaction object |
|
| 815 | - $transaction = $payment->transaction(); |
|
| 816 | - if ($transaction instanceof EE_Transaction) { |
|
| 817 | - $data = array($transaction, $payment); |
|
| 818 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 819 | - |
|
| 820 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 821 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 822 | - |
|
| 823 | - // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 824 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 825 | - ? false : $message_type; |
|
| 826 | - |
|
| 827 | - self::_load_controller(); |
|
| 828 | - |
|
| 829 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 830 | - |
|
| 831 | - // get count of queued for generation |
|
| 832 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 833 | - array( |
|
| 834 | - EEM_Message::status_incomplete, |
|
| 835 | - EEM_Message::status_idle, |
|
| 836 | - ) |
|
| 837 | - ); |
|
| 838 | - |
|
| 839 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 840 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 841 | - return true; |
|
| 842 | - } else { |
|
| 843 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 844 | - EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 845 | - ); |
|
| 846 | - /** |
|
| 847 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 848 | - * IMMEDIATE generation. |
|
| 849 | - */ |
|
| 850 | - if ($count_failed > 0) { |
|
| 851 | - EE_Error::add_error( |
|
| 852 | - sprintf( |
|
| 853 | - _n( |
|
| 854 | - 'The payment notification generation failed.', |
|
| 855 | - '%d payment notifications failed being sent.', |
|
| 856 | - $count_failed, |
|
| 857 | - 'event_espresso' |
|
| 858 | - ), |
|
| 859 | - $count_failed |
|
| 860 | - ), |
|
| 861 | - __FILE__, |
|
| 862 | - __FUNCTION__, |
|
| 863 | - __LINE__ |
|
| 864 | - ); |
|
| 865 | - |
|
| 866 | - return false; |
|
| 867 | - } else { |
|
| 868 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 869 | - return true; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - } else { |
|
| 873 | - EE_Error::add_error( |
|
| 874 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 875 | - 'event_espresso' |
|
| 876 | - ); |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 884 | - * |
|
| 885 | - * @since 4.3.0 |
|
| 886 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 887 | - * @param int $grp_id a specific message template group id. |
|
| 888 | - * @return void |
|
| 889 | - * @throws EE_Error |
|
| 890 | - * @throws InvalidArgumentException |
|
| 891 | - * @throws InvalidDataTypeException |
|
| 892 | - * @throws InvalidInterfaceException |
|
| 893 | - * @throws ReflectionException |
|
| 894 | - */ |
|
| 895 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 896 | - { |
|
| 897 | - // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 898 | - EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 899 | - self::_load_controller(); |
|
| 900 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 906 | - * |
|
| 907 | - * @since 4.3.0 |
|
| 908 | - * @param string $registration_message_trigger_url |
|
| 909 | - * @param EE_Registration $registration |
|
| 910 | - * @param string $messenger |
|
| 911 | - * @param string $message_type |
|
| 912 | - * @return string |
|
| 913 | - * @throws EE_Error |
|
| 914 | - * @throws InvalidArgumentException |
|
| 915 | - * @throws InvalidDataTypeException |
|
| 916 | - * @throws InvalidInterfaceException |
|
| 917 | - */ |
|
| 918 | - public static function registration_message_trigger_url( |
|
| 919 | - $registration_message_trigger_url, |
|
| 920 | - EE_Registration $registration, |
|
| 921 | - $messenger = 'html', |
|
| 922 | - $message_type = 'invoice' |
|
| 923 | - ) { |
|
| 924 | - // whitelist $messenger |
|
| 925 | - switch ($messenger) { |
|
| 926 | - case 'pdf': |
|
| 927 | - $sending_messenger = 'pdf'; |
|
| 928 | - $generating_messenger = 'html'; |
|
| 929 | - break; |
|
| 930 | - case 'html': |
|
| 931 | - default: |
|
| 932 | - $sending_messenger = 'html'; |
|
| 933 | - $generating_messenger = 'html'; |
|
| 934 | - break; |
|
| 935 | - } |
|
| 936 | - // whitelist $message_type |
|
| 937 | - switch ($message_type) { |
|
| 938 | - case 'receipt': |
|
| 939 | - $message_type = 'receipt'; |
|
| 940 | - break; |
|
| 941 | - case 'invoice': |
|
| 942 | - default: |
|
| 943 | - $message_type = 'invoice'; |
|
| 944 | - break; |
|
| 945 | - } |
|
| 946 | - // verify that both the messenger AND the message type are active |
|
| 947 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 948 | - && EEH_MSG_Template::is_mt_active($message_type) |
|
| 949 | - ) { |
|
| 950 | - // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 951 | - $template_query_params = array( |
|
| 952 | - 'MTP_is_active' => true, |
|
| 953 | - 'MTP_messenger' => $generating_messenger, |
|
| 954 | - 'MTP_message_type' => $message_type, |
|
| 955 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 956 | - ); |
|
| 957 | - // get the message template group. |
|
| 958 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 959 | - // if we don't have an EE_Message_Template_Group then return |
|
| 960 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 961 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 962 | - unset($template_query_params['Event.EVT_ID']); |
|
| 963 | - // get global template as the fallback |
|
| 964 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 965 | - } |
|
| 966 | - // if we don't have an EE_Message_Template_Group then return |
|
| 967 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 968 | - return ''; |
|
| 969 | - } |
|
| 970 | - // generate the URL |
|
| 971 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 972 | - $sending_messenger, |
|
| 973 | - $generating_messenger, |
|
| 974 | - 'purchaser', |
|
| 975 | - $message_type, |
|
| 976 | - $registration, |
|
| 977 | - $msg_template_group->ID(), |
|
| 978 | - $registration->transaction_ID() |
|
| 979 | - ); |
|
| 980 | - } |
|
| 981 | - return $registration_message_trigger_url; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * Use to generate and return a message preview! |
|
| 987 | - * |
|
| 988 | - * @param string $type This should correspond with a valid message type |
|
| 989 | - * @param string $context This should correspond with a valid context for the message type |
|
| 990 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 991 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 992 | - * preview |
|
| 993 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 994 | - * @throws EE_Error |
|
| 995 | - * @throws InvalidArgumentException |
|
| 996 | - * @throws InvalidDataTypeException |
|
| 997 | - * @throws InvalidInterfaceException |
|
| 998 | - * @throws ReflectionException |
|
| 999 | - */ |
|
| 1000 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 1001 | - { |
|
| 1002 | - self::_load_controller(); |
|
| 1003 | - $mtg = new EE_Message_To_Generate( |
|
| 1004 | - $messenger, |
|
| 1005 | - $type, |
|
| 1006 | - array(), |
|
| 1007 | - $context, |
|
| 1008 | - true |
|
| 1009 | - ); |
|
| 1010 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1011 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1012 | - // loop through all content for the preview and remove any persisted records. |
|
| 1013 | - $content = ''; |
|
| 1014 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1015 | - $content = $message->content(); |
|
| 1016 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1017 | - $message->delete(); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - return $content; |
|
| 1021 | - } else { |
|
| 1022 | - return $generated_preview_queue; |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1029 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1030 | - * content found in the EE_Message objects in the queue. |
|
| 1031 | - * |
|
| 1032 | - * @since 4.9.0 |
|
| 1033 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 1034 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1035 | - * type name is still required to send along the message type to the |
|
| 1036 | - * messenger because this is used for determining what specific |
|
| 1037 | - * variations might be loaded for the generated message. |
|
| 1038 | - * @param EE_Messages_Queue $queue |
|
| 1039 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1040 | - * aggregate EE_Message object. |
|
| 1041 | - * @return bool success or fail. |
|
| 1042 | - * @throws EE_Error |
|
| 1043 | - * @throws InvalidArgumentException |
|
| 1044 | - * @throws ReflectionException |
|
| 1045 | - * @throws InvalidDataTypeException |
|
| 1046 | - * @throws InvalidInterfaceException |
|
| 1047 | - */ |
|
| 1048 | - public static function send_message_with_messenger_only( |
|
| 1049 | - $messenger, |
|
| 1050 | - $message_type, |
|
| 1051 | - EE_Messages_Queue $queue, |
|
| 1052 | - $custom_subject = '' |
|
| 1053 | - ) { |
|
| 1054 | - self::_load_controller(); |
|
| 1055 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1056 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1057 | - 'Message_To_Generate_From_Queue', |
|
| 1058 | - array( |
|
| 1059 | - $messenger, |
|
| 1060 | - $message_type, |
|
| 1061 | - $queue, |
|
| 1062 | - $custom_subject, |
|
| 1063 | - ) |
|
| 1064 | - ); |
|
| 1065 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1071 | - * |
|
| 1072 | - * @since 4.9.0 |
|
| 1073 | - * @param array $message_ids An array of message ids |
|
| 1074 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1075 | - * messages. |
|
| 1076 | - * @throws EE_Error |
|
| 1077 | - * @throws InvalidArgumentException |
|
| 1078 | - * @throws InvalidDataTypeException |
|
| 1079 | - * @throws InvalidInterfaceException |
|
| 1080 | - * @throws ReflectionException |
|
| 1081 | - */ |
|
| 1082 | - public static function generate_now($message_ids) |
|
| 1083 | - { |
|
| 1084 | - self::_load_controller(); |
|
| 1085 | - $messages = EEM_Message::instance()->get_all( |
|
| 1086 | - array( |
|
| 1087 | - 0 => array( |
|
| 1088 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1089 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1090 | - ), |
|
| 1091 | - ) |
|
| 1092 | - ); |
|
| 1093 | - $generated_queue = false; |
|
| 1094 | - if ($messages) { |
|
| 1095 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1099 | - EE_Error::add_error( |
|
| 1100 | - __( |
|
| 1101 | - 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1102 | - 'event_espresso' |
|
| 1103 | - ), |
|
| 1104 | - __FILE__, |
|
| 1105 | - __FUNCTION__, |
|
| 1106 | - __LINE__ |
|
| 1107 | - ); |
|
| 1108 | - } |
|
| 1109 | - return $generated_queue; |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1115 | - * EEM_Message::status_idle |
|
| 1116 | - * |
|
| 1117 | - * @since 4.9.0 |
|
| 1118 | - * @param $message_ids |
|
| 1119 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1120 | - * @throws EE_Error |
|
| 1121 | - * @throws InvalidArgumentException |
|
| 1122 | - * @throws InvalidDataTypeException |
|
| 1123 | - * @throws InvalidInterfaceException |
|
| 1124 | - * @throws ReflectionException |
|
| 1125 | - */ |
|
| 1126 | - public static function send_now($message_ids) |
|
| 1127 | - { |
|
| 1128 | - self::_load_controller(); |
|
| 1129 | - $messages = EEM_Message::instance()->get_all( |
|
| 1130 | - array( |
|
| 1131 | - 0 => array( |
|
| 1132 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1133 | - 'STS_ID' => array( |
|
| 1134 | - 'IN', |
|
| 1135 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1136 | - ), |
|
| 1137 | - ), |
|
| 1138 | - ) |
|
| 1139 | - ); |
|
| 1140 | - $sent_queue = false; |
|
| 1141 | - if ($messages) { |
|
| 1142 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1146 | - EE_Error::add_error( |
|
| 1147 | - __( |
|
| 1148 | - 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1149 | - 'event_espresso' |
|
| 1150 | - ), |
|
| 1151 | - __FILE__, |
|
| 1152 | - __FUNCTION__, |
|
| 1153 | - __LINE__ |
|
| 1154 | - ); |
|
| 1155 | - } else { |
|
| 1156 | - // can count how many sent by using the messages in the queue |
|
| 1157 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1158 | - if ($sent_count > 0) { |
|
| 1159 | - EE_Error::add_success( |
|
| 1160 | - sprintf( |
|
| 1161 | - _n( |
|
| 1162 | - 'There was %d message successfully sent.', |
|
| 1163 | - 'There were %d messages successfully sent.', |
|
| 1164 | - $sent_count, |
|
| 1165 | - 'event_espresso' |
|
| 1166 | - ), |
|
| 1167 | - $sent_count |
|
| 1168 | - ) |
|
| 1169 | - ); |
|
| 1170 | - } else { |
|
| 1171 | - EE_Error::overwrite_errors(); |
|
| 1172 | - EE_Error::add_error( |
|
| 1173 | - __( |
|
| 1174 | - 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 259 | + exit; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * This runs when the msg_url_trigger route has initiated. |
|
| 268 | + * |
|
| 269 | + * @since 4.5.0 |
|
| 270 | + * @param WP $WP |
|
| 271 | + * @throws EE_Error |
|
| 272 | + * @throws InvalidArgumentException |
|
| 273 | + * @throws ReflectionException |
|
| 274 | + * @throws InvalidDataTypeException |
|
| 275 | + * @throws InvalidInterfaceException |
|
| 276 | + */ |
|
| 277 | + public function run($WP) |
|
| 278 | + { |
|
| 279 | + // ensure controller is loaded |
|
| 280 | + self::_load_controller(); |
|
| 281 | + // attempt to process message |
|
| 282 | + try { |
|
| 283 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 284 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 285 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 286 | + } catch (EE_Error $e) { |
|
| 287 | + $error_msg = __( |
|
| 288 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 289 | + 'event_espresso' |
|
| 290 | + ); |
|
| 291 | + // add specific message for developers if WP_DEBUG in on |
|
| 292 | + $error_msg .= '||' . $e->getMessage(); |
|
| 293 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 300 | + * |
|
| 301 | + * @param WP $WP |
|
| 302 | + */ |
|
| 303 | + public function execute_batch_request($WP) |
|
| 304 | + { |
|
| 305 | + $this->run_cron(); |
|
| 306 | + header('HTTP/1.1 200 OK'); |
|
| 307 | + exit(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 313 | + * request. |
|
| 314 | + */ |
|
| 315 | + public function run_cron() |
|
| 316 | + { |
|
| 317 | + self::_load_controller(); |
|
| 318 | + // get required vars |
|
| 319 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 320 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 321 | + |
|
| 322 | + // now let's verify transient, if not valid exit immediately |
|
| 323 | + if (! get_transient($transient_key)) { |
|
| 324 | + /** |
|
| 325 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 326 | + * request. |
|
| 327 | + */ |
|
| 328 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // if made it here, lets' delete the transient to keep the db clean |
|
| 332 | + delete_transient($transient_key); |
|
| 333 | + |
|
| 334 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 335 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 336 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 337 | + self::$_MSG_PROCESSOR->$method(); |
|
| 338 | + } else { |
|
| 339 | + // no matching task |
|
| 340 | + /** |
|
| 341 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 342 | + * request. |
|
| 343 | + */ |
|
| 344 | + trigger_error( |
|
| 345 | + esc_attr( |
|
| 346 | + sprintf( |
|
| 347 | + __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 348 | + $cron_type |
|
| 349 | + ) |
|
| 350 | + ) |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * This is used to retrieve the template pack for the given name. |
|
| 361 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 362 | + * the default template pack is returned. |
|
| 363 | + * |
|
| 364 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 365 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 366 | + * in generating the Pack class name). |
|
| 367 | + * @return EE_Messages_Template_Pack |
|
| 368 | + * @throws EE_Error |
|
| 369 | + * @throws InvalidArgumentException |
|
| 370 | + * @throws ReflectionException |
|
| 371 | + * @throws InvalidDataTypeException |
|
| 372 | + * @throws InvalidInterfaceException |
|
| 373 | + */ |
|
| 374 | + public static function get_template_pack($template_pack_name) |
|
| 375 | + { |
|
| 376 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 377 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Retrieves an array of all template packs. |
|
| 383 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 384 | + * |
|
| 385 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 386 | + * @return EE_Messages_Template_Pack[] |
|
| 387 | + * @throws EE_Error |
|
| 388 | + * @throws InvalidArgumentException |
|
| 389 | + * @throws ReflectionException |
|
| 390 | + * @throws InvalidDataTypeException |
|
| 391 | + * @throws InvalidInterfaceException |
|
| 392 | + */ |
|
| 393 | + public static function get_template_packs() |
|
| 394 | + { |
|
| 395 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 396 | + |
|
| 397 | + // for backward compat, let's make sure this returns in the same format as originally. |
|
| 398 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 399 | + $template_pack_collection->rewind(); |
|
| 400 | + $template_packs = array(); |
|
| 401 | + while ($template_pack_collection->valid()) { |
|
| 402 | + $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 403 | + $template_pack_collection->next(); |
|
| 404 | + } |
|
| 405 | + return $template_packs; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 411 | + * |
|
| 412 | + * @since 4.5.0 |
|
| 413 | + * @return void |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public static function set_autoloaders() |
|
| 417 | + { |
|
| 418 | + if (empty(self::$_MSG_PATHS)) { |
|
| 419 | + self::_set_messages_paths(); |
|
| 420 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 421 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 422 | + } |
|
| 423 | + // add aliases |
|
| 424 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 425 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 432 | + * for use by the Messages Autoloaders |
|
| 433 | + * |
|
| 434 | + * @since 4.5.0 |
|
| 435 | + * @return void. |
|
| 436 | + */ |
|
| 437 | + protected static function _set_messages_paths() |
|
| 438 | + { |
|
| 439 | + $dir_ref = array( |
|
| 440 | + 'messages/message_type', |
|
| 441 | + 'messages/messenger', |
|
| 442 | + 'messages/defaults', |
|
| 443 | + 'messages/defaults/email', |
|
| 444 | + 'messages/data_class', |
|
| 445 | + 'messages/validators', |
|
| 446 | + 'messages/validators/email', |
|
| 447 | + 'messages/validators/html', |
|
| 448 | + 'shortcodes', |
|
| 449 | + ); |
|
| 450 | + $paths = array(); |
|
| 451 | + foreach ($dir_ref as $index => $dir) { |
|
| 452 | + $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 453 | + } |
|
| 454 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Takes care of loading dependencies |
|
| 460 | + * |
|
| 461 | + * @since 4.5.0 |
|
| 462 | + * @return void |
|
| 463 | + * @throws EE_Error |
|
| 464 | + * @throws InvalidArgumentException |
|
| 465 | + * @throws ReflectionException |
|
| 466 | + * @throws InvalidDataTypeException |
|
| 467 | + * @throws InvalidInterfaceException |
|
| 468 | + */ |
|
| 469 | + protected static function _load_controller() |
|
| 470 | + { |
|
| 471 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 472 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 473 | + self::set_autoloaders(); |
|
| 474 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 475 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 476 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @param EE_Transaction $transaction |
|
| 483 | + * @throws EE_Error |
|
| 484 | + * @throws InvalidArgumentException |
|
| 485 | + * @throws InvalidDataTypeException |
|
| 486 | + * @throws InvalidInterfaceException |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + */ |
|
| 489 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 490 | + { |
|
| 491 | + self::_load_controller(); |
|
| 492 | + $data = array($transaction, null); |
|
| 493 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 499 | + * |
|
| 500 | + * @param EE_Transaction $transaction object |
|
| 501 | + * @param EE_Payment|null $payment object |
|
| 502 | + * @return void |
|
| 503 | + * @throws EE_Error |
|
| 504 | + * @throws InvalidArgumentException |
|
| 505 | + * @throws ReflectionException |
|
| 506 | + * @throws InvalidDataTypeException |
|
| 507 | + * @throws InvalidInterfaceException |
|
| 508 | + */ |
|
| 509 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 510 | + { |
|
| 511 | + // if there's no payment object, then we cannot do a payment type message! |
|
| 512 | + if (! $payment instanceof EE_Payment) { |
|
| 513 | + return; |
|
| 514 | + } |
|
| 515 | + self::_load_controller(); |
|
| 516 | + $data = array($transaction, $payment); |
|
| 517 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 518 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 519 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 520 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 521 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @param EE_Transaction $transaction |
|
| 527 | + * @throws EE_Error |
|
| 528 | + * @throws InvalidArgumentException |
|
| 529 | + * @throws InvalidDataTypeException |
|
| 530 | + * @throws InvalidInterfaceException |
|
| 531 | + * @throws ReflectionException |
|
| 532 | + */ |
|
| 533 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 534 | + { |
|
| 535 | + self::_load_controller(); |
|
| 536 | + $data = array($transaction, null); |
|
| 537 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Trigger for Registration messages |
|
| 543 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 544 | + * incoming transaction. |
|
| 545 | + * |
|
| 546 | + * @param EE_Registration $registration |
|
| 547 | + * @param array $extra_details |
|
| 548 | + * @return void |
|
| 549 | + * @throws EE_Error |
|
| 550 | + * @throws InvalidArgumentException |
|
| 551 | + * @throws InvalidDataTypeException |
|
| 552 | + * @throws InvalidInterfaceException |
|
| 553 | + * @throws ReflectionException |
|
| 554 | + * @throws EntityNotFoundException |
|
| 555 | + */ |
|
| 556 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 557 | + { |
|
| 558 | + |
|
| 559 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 560 | + // no messages please |
|
| 561 | + return; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 565 | + $all_registrations = $registration->transaction()->registrations( |
|
| 566 | + array( |
|
| 567 | + array('REG_deleted' => false), |
|
| 568 | + 'order_by' => array( |
|
| 569 | + 'Event.EVT_name' => 'ASC', |
|
| 570 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 571 | + 'Attendee.ATT_fname' => 'ASC', |
|
| 572 | + ), |
|
| 573 | + ) |
|
| 574 | + ); |
|
| 575 | + // cached array of statuses so we only trigger messages once per status. |
|
| 576 | + $statuses_sent = array(); |
|
| 577 | + self::_load_controller(); |
|
| 578 | + $mtgs = array(); |
|
| 579 | + |
|
| 580 | + // loop through registrations and trigger messages once per status. |
|
| 581 | + foreach ($all_registrations as $reg) { |
|
| 582 | + // already triggered? |
|
| 583 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 584 | + continue; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 588 | + $mtgs = array_merge( |
|
| 589 | + $mtgs, |
|
| 590 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 591 | + $message_type, |
|
| 592 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 593 | + ) |
|
| 594 | + ); |
|
| 595 | + $statuses_sent[] = $reg->status_ID(); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if (count($statuses_sent) > 1) { |
|
| 599 | + $mtgs = array_merge( |
|
| 600 | + $mtgs, |
|
| 601 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 602 | + 'registration_summary', |
|
| 603 | + array($registration->transaction(), null) |
|
| 604 | + ) |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + // batch queue and initiate request |
|
| 609 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 610 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 616 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 617 | + * |
|
| 618 | + * @param EE_Registration $registration [description] |
|
| 619 | + * @param array $extra_details [description] |
|
| 620 | + * @return bool true = send away, false = nope halt the presses. |
|
| 621 | + */ |
|
| 622 | + protected static function _verify_registration_notification_send( |
|
| 623 | + EE_Registration $registration, |
|
| 624 | + $extra_details = array() |
|
| 625 | + ) { |
|
| 626 | + if (! $registration->is_primary_registrant()) { |
|
| 627 | + return false; |
|
| 628 | + } |
|
| 629 | + // first we check if we're in admin and not doing front ajax |
|
| 630 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 631 | + // make sure appropriate admin params are set for sending messages |
|
| 632 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 633 | + | ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 634 | + ) { |
|
| 635 | + // no messages sent please. |
|
| 636 | + return false; |
|
| 637 | + } |
|
| 638 | + } else { |
|
| 639 | + // frontend request (either regular or via AJAX) |
|
| 640 | + // TXN is NOT finalized ? |
|
| 641 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 642 | + return false; |
|
| 643 | + } |
|
| 644 | + // return visit but nothing changed ??? |
|
| 645 | + if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 646 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 647 | + ) { |
|
| 648 | + return false; |
|
| 649 | + } |
|
| 650 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 651 | + if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 652 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 653 | + ) { |
|
| 654 | + return false; |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + // release the kraken |
|
| 658 | + return true; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 664 | + * status id. |
|
| 665 | + * |
|
| 666 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 667 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 668 | + * @param string $reg_status |
|
| 669 | + * @return array |
|
| 670 | + * @throws EE_Error |
|
| 671 | + * @throws InvalidArgumentException |
|
| 672 | + * @throws ReflectionException |
|
| 673 | + * @throws InvalidDataTypeException |
|
| 674 | + * @throws InvalidInterfaceException |
|
| 675 | + */ |
|
| 676 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 677 | + { |
|
| 678 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 679 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 680 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 681 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Simply returns the payment message type for the given payment status. |
|
| 687 | + * |
|
| 688 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 689 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 690 | + * @param string $payment_status The payment status being matched. |
|
| 691 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 692 | + * @throws EE_Error |
|
| 693 | + * @throws InvalidArgumentException |
|
| 694 | + * @throws ReflectionException |
|
| 695 | + * @throws InvalidDataTypeException |
|
| 696 | + * @throws InvalidInterfaceException |
|
| 697 | + */ |
|
| 698 | + protected static function _get_payment_message_type($payment_status) |
|
| 699 | + { |
|
| 700 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 701 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 702 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 703 | + : false; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 709 | + * |
|
| 710 | + * @access public |
|
| 711 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 712 | + * @return bool success/fail |
|
| 713 | + * @throws EE_Error |
|
| 714 | + * @throws InvalidArgumentException |
|
| 715 | + * @throws InvalidDataTypeException |
|
| 716 | + * @throws InvalidInterfaceException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + */ |
|
| 719 | + public static function process_resend($req_data) |
|
| 720 | + { |
|
| 721 | + self::_load_controller(); |
|
| 722 | + |
|
| 723 | + // if $msgID in this request then skip to the new resend_message |
|
| 724 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 725 | + return self::resend_message(); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 729 | + $req_data = (array) $req_data; |
|
| 730 | + foreach ($req_data as $request_key => $request_value) { |
|
| 731 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 735 | + )) { |
|
| 736 | + return false; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + try { |
|
| 740 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 741 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 742 | + } catch (EE_Error $e) { |
|
| 743 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 746 | + EE_Error::add_success( |
|
| 747 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 748 | + ); |
|
| 749 | + return true; // everything got queued. |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 755 | + * |
|
| 756 | + * @return bool |
|
| 757 | + * @throws EE_Error |
|
| 758 | + * @throws InvalidArgumentException |
|
| 759 | + * @throws InvalidDataTypeException |
|
| 760 | + * @throws InvalidInterfaceException |
|
| 761 | + * @throws ReflectionException |
|
| 762 | + */ |
|
| 763 | + public static function resend_message() |
|
| 764 | + { |
|
| 765 | + self::_load_controller(); |
|
| 766 | + |
|
| 767 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 768 | + if (! $msgID) { |
|
| 769 | + EE_Error::add_error( |
|
| 770 | + __( |
|
| 771 | + 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 772 | + 'event_espresso' |
|
| 773 | + ), |
|
| 774 | + __FILE__, |
|
| 775 | + __FUNCTION__, |
|
| 776 | + __LINE__ |
|
| 777 | + ); |
|
| 778 | + return false; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 782 | + |
|
| 783 | + // setup success message. |
|
| 784 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 785 | + EE_Error::add_success( |
|
| 786 | + sprintf( |
|
| 787 | + _n( |
|
| 788 | + 'There was %d message queued for resending.', |
|
| 789 | + 'There were %d messages queued for resending.', |
|
| 790 | + $count_ready_for_resend, |
|
| 791 | + 'event_espresso' |
|
| 792 | + ), |
|
| 793 | + $count_ready_for_resend |
|
| 794 | + ) |
|
| 795 | + ); |
|
| 796 | + return true; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * Message triggers for manual payment applied by admin |
|
| 802 | + * |
|
| 803 | + * @param EE_Payment $payment EE_payment object |
|
| 804 | + * @return bool success/fail |
|
| 805 | + * @throws EE_Error |
|
| 806 | + * @throws InvalidArgumentException |
|
| 807 | + * @throws ReflectionException |
|
| 808 | + * @throws InvalidDataTypeException |
|
| 809 | + * @throws InvalidInterfaceException |
|
| 810 | + */ |
|
| 811 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 812 | + { |
|
| 813 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 814 | + // we need to get the transaction object |
|
| 815 | + $transaction = $payment->transaction(); |
|
| 816 | + if ($transaction instanceof EE_Transaction) { |
|
| 817 | + $data = array($transaction, $payment); |
|
| 818 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 819 | + |
|
| 820 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 821 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 822 | + |
|
| 823 | + // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 824 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 825 | + ? false : $message_type; |
|
| 826 | + |
|
| 827 | + self::_load_controller(); |
|
| 828 | + |
|
| 829 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 830 | + |
|
| 831 | + // get count of queued for generation |
|
| 832 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 833 | + array( |
|
| 834 | + EEM_Message::status_incomplete, |
|
| 835 | + EEM_Message::status_idle, |
|
| 836 | + ) |
|
| 837 | + ); |
|
| 838 | + |
|
| 839 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 840 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 841 | + return true; |
|
| 842 | + } else { |
|
| 843 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 844 | + EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 845 | + ); |
|
| 846 | + /** |
|
| 847 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 848 | + * IMMEDIATE generation. |
|
| 849 | + */ |
|
| 850 | + if ($count_failed > 0) { |
|
| 851 | + EE_Error::add_error( |
|
| 852 | + sprintf( |
|
| 853 | + _n( |
|
| 854 | + 'The payment notification generation failed.', |
|
| 855 | + '%d payment notifications failed being sent.', |
|
| 856 | + $count_failed, |
|
| 857 | + 'event_espresso' |
|
| 858 | + ), |
|
| 859 | + $count_failed |
|
| 860 | + ), |
|
| 861 | + __FILE__, |
|
| 862 | + __FUNCTION__, |
|
| 863 | + __LINE__ |
|
| 864 | + ); |
|
| 865 | + |
|
| 866 | + return false; |
|
| 867 | + } else { |
|
| 868 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 869 | + return true; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + } else { |
|
| 873 | + EE_Error::add_error( |
|
| 874 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 875 | + 'event_espresso' |
|
| 876 | + ); |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 884 | + * |
|
| 885 | + * @since 4.3.0 |
|
| 886 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 887 | + * @param int $grp_id a specific message template group id. |
|
| 888 | + * @return void |
|
| 889 | + * @throws EE_Error |
|
| 890 | + * @throws InvalidArgumentException |
|
| 891 | + * @throws InvalidDataTypeException |
|
| 892 | + * @throws InvalidInterfaceException |
|
| 893 | + * @throws ReflectionException |
|
| 894 | + */ |
|
| 895 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 896 | + { |
|
| 897 | + // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 898 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 899 | + self::_load_controller(); |
|
| 900 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 906 | + * |
|
| 907 | + * @since 4.3.0 |
|
| 908 | + * @param string $registration_message_trigger_url |
|
| 909 | + * @param EE_Registration $registration |
|
| 910 | + * @param string $messenger |
|
| 911 | + * @param string $message_type |
|
| 912 | + * @return string |
|
| 913 | + * @throws EE_Error |
|
| 914 | + * @throws InvalidArgumentException |
|
| 915 | + * @throws InvalidDataTypeException |
|
| 916 | + * @throws InvalidInterfaceException |
|
| 917 | + */ |
|
| 918 | + public static function registration_message_trigger_url( |
|
| 919 | + $registration_message_trigger_url, |
|
| 920 | + EE_Registration $registration, |
|
| 921 | + $messenger = 'html', |
|
| 922 | + $message_type = 'invoice' |
|
| 923 | + ) { |
|
| 924 | + // whitelist $messenger |
|
| 925 | + switch ($messenger) { |
|
| 926 | + case 'pdf': |
|
| 927 | + $sending_messenger = 'pdf'; |
|
| 928 | + $generating_messenger = 'html'; |
|
| 929 | + break; |
|
| 930 | + case 'html': |
|
| 931 | + default: |
|
| 932 | + $sending_messenger = 'html'; |
|
| 933 | + $generating_messenger = 'html'; |
|
| 934 | + break; |
|
| 935 | + } |
|
| 936 | + // whitelist $message_type |
|
| 937 | + switch ($message_type) { |
|
| 938 | + case 'receipt': |
|
| 939 | + $message_type = 'receipt'; |
|
| 940 | + break; |
|
| 941 | + case 'invoice': |
|
| 942 | + default: |
|
| 943 | + $message_type = 'invoice'; |
|
| 944 | + break; |
|
| 945 | + } |
|
| 946 | + // verify that both the messenger AND the message type are active |
|
| 947 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 948 | + && EEH_MSG_Template::is_mt_active($message_type) |
|
| 949 | + ) { |
|
| 950 | + // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 951 | + $template_query_params = array( |
|
| 952 | + 'MTP_is_active' => true, |
|
| 953 | + 'MTP_messenger' => $generating_messenger, |
|
| 954 | + 'MTP_message_type' => $message_type, |
|
| 955 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 956 | + ); |
|
| 957 | + // get the message template group. |
|
| 958 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 959 | + // if we don't have an EE_Message_Template_Group then return |
|
| 960 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 961 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 962 | + unset($template_query_params['Event.EVT_ID']); |
|
| 963 | + // get global template as the fallback |
|
| 964 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 965 | + } |
|
| 966 | + // if we don't have an EE_Message_Template_Group then return |
|
| 967 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 968 | + return ''; |
|
| 969 | + } |
|
| 970 | + // generate the URL |
|
| 971 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 972 | + $sending_messenger, |
|
| 973 | + $generating_messenger, |
|
| 974 | + 'purchaser', |
|
| 975 | + $message_type, |
|
| 976 | + $registration, |
|
| 977 | + $msg_template_group->ID(), |
|
| 978 | + $registration->transaction_ID() |
|
| 979 | + ); |
|
| 980 | + } |
|
| 981 | + return $registration_message_trigger_url; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * Use to generate and return a message preview! |
|
| 987 | + * |
|
| 988 | + * @param string $type This should correspond with a valid message type |
|
| 989 | + * @param string $context This should correspond with a valid context for the message type |
|
| 990 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 991 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 992 | + * preview |
|
| 993 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 994 | + * @throws EE_Error |
|
| 995 | + * @throws InvalidArgumentException |
|
| 996 | + * @throws InvalidDataTypeException |
|
| 997 | + * @throws InvalidInterfaceException |
|
| 998 | + * @throws ReflectionException |
|
| 999 | + */ |
|
| 1000 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 1001 | + { |
|
| 1002 | + self::_load_controller(); |
|
| 1003 | + $mtg = new EE_Message_To_Generate( |
|
| 1004 | + $messenger, |
|
| 1005 | + $type, |
|
| 1006 | + array(), |
|
| 1007 | + $context, |
|
| 1008 | + true |
|
| 1009 | + ); |
|
| 1010 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1011 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1012 | + // loop through all content for the preview and remove any persisted records. |
|
| 1013 | + $content = ''; |
|
| 1014 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1015 | + $content = $message->content(); |
|
| 1016 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1017 | + $message->delete(); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + return $content; |
|
| 1021 | + } else { |
|
| 1022 | + return $generated_preview_queue; |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1029 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1030 | + * content found in the EE_Message objects in the queue. |
|
| 1031 | + * |
|
| 1032 | + * @since 4.9.0 |
|
| 1033 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 1034 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1035 | + * type name is still required to send along the message type to the |
|
| 1036 | + * messenger because this is used for determining what specific |
|
| 1037 | + * variations might be loaded for the generated message. |
|
| 1038 | + * @param EE_Messages_Queue $queue |
|
| 1039 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1040 | + * aggregate EE_Message object. |
|
| 1041 | + * @return bool success or fail. |
|
| 1042 | + * @throws EE_Error |
|
| 1043 | + * @throws InvalidArgumentException |
|
| 1044 | + * @throws ReflectionException |
|
| 1045 | + * @throws InvalidDataTypeException |
|
| 1046 | + * @throws InvalidInterfaceException |
|
| 1047 | + */ |
|
| 1048 | + public static function send_message_with_messenger_only( |
|
| 1049 | + $messenger, |
|
| 1050 | + $message_type, |
|
| 1051 | + EE_Messages_Queue $queue, |
|
| 1052 | + $custom_subject = '' |
|
| 1053 | + ) { |
|
| 1054 | + self::_load_controller(); |
|
| 1055 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1056 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1057 | + 'Message_To_Generate_From_Queue', |
|
| 1058 | + array( |
|
| 1059 | + $messenger, |
|
| 1060 | + $message_type, |
|
| 1061 | + $queue, |
|
| 1062 | + $custom_subject, |
|
| 1063 | + ) |
|
| 1064 | + ); |
|
| 1065 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1071 | + * |
|
| 1072 | + * @since 4.9.0 |
|
| 1073 | + * @param array $message_ids An array of message ids |
|
| 1074 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1075 | + * messages. |
|
| 1076 | + * @throws EE_Error |
|
| 1077 | + * @throws InvalidArgumentException |
|
| 1078 | + * @throws InvalidDataTypeException |
|
| 1079 | + * @throws InvalidInterfaceException |
|
| 1080 | + * @throws ReflectionException |
|
| 1081 | + */ |
|
| 1082 | + public static function generate_now($message_ids) |
|
| 1083 | + { |
|
| 1084 | + self::_load_controller(); |
|
| 1085 | + $messages = EEM_Message::instance()->get_all( |
|
| 1086 | + array( |
|
| 1087 | + 0 => array( |
|
| 1088 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1089 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1090 | + ), |
|
| 1091 | + ) |
|
| 1092 | + ); |
|
| 1093 | + $generated_queue = false; |
|
| 1094 | + if ($messages) { |
|
| 1095 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1099 | + EE_Error::add_error( |
|
| 1100 | + __( |
|
| 1101 | + 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1102 | + 'event_espresso' |
|
| 1103 | + ), |
|
| 1104 | + __FILE__, |
|
| 1105 | + __FUNCTION__, |
|
| 1106 | + __LINE__ |
|
| 1107 | + ); |
|
| 1108 | + } |
|
| 1109 | + return $generated_queue; |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1115 | + * EEM_Message::status_idle |
|
| 1116 | + * |
|
| 1117 | + * @since 4.9.0 |
|
| 1118 | + * @param $message_ids |
|
| 1119 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1120 | + * @throws EE_Error |
|
| 1121 | + * @throws InvalidArgumentException |
|
| 1122 | + * @throws InvalidDataTypeException |
|
| 1123 | + * @throws InvalidInterfaceException |
|
| 1124 | + * @throws ReflectionException |
|
| 1125 | + */ |
|
| 1126 | + public static function send_now($message_ids) |
|
| 1127 | + { |
|
| 1128 | + self::_load_controller(); |
|
| 1129 | + $messages = EEM_Message::instance()->get_all( |
|
| 1130 | + array( |
|
| 1131 | + 0 => array( |
|
| 1132 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1133 | + 'STS_ID' => array( |
|
| 1134 | + 'IN', |
|
| 1135 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1136 | + ), |
|
| 1137 | + ), |
|
| 1138 | + ) |
|
| 1139 | + ); |
|
| 1140 | + $sent_queue = false; |
|
| 1141 | + if ($messages) { |
|
| 1142 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1146 | + EE_Error::add_error( |
|
| 1147 | + __( |
|
| 1148 | + 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1149 | + 'event_espresso' |
|
| 1150 | + ), |
|
| 1151 | + __FILE__, |
|
| 1152 | + __FUNCTION__, |
|
| 1153 | + __LINE__ |
|
| 1154 | + ); |
|
| 1155 | + } else { |
|
| 1156 | + // can count how many sent by using the messages in the queue |
|
| 1157 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1158 | + if ($sent_count > 0) { |
|
| 1159 | + EE_Error::add_success( |
|
| 1160 | + sprintf( |
|
| 1161 | + _n( |
|
| 1162 | + 'There was %d message successfully sent.', |
|
| 1163 | + 'There were %d messages successfully sent.', |
|
| 1164 | + $sent_count, |
|
| 1165 | + 'event_espresso' |
|
| 1166 | + ), |
|
| 1167 | + $sent_count |
|
| 1168 | + ) |
|
| 1169 | + ); |
|
| 1170 | + } else { |
|
| 1171 | + EE_Error::overwrite_errors(); |
|
| 1172 | + EE_Error::add_error( |
|
| 1173 | + __( |
|
| 1174 | + 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 1175 | 1175 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 1176 | - 'event_espresso' |
|
| 1177 | - ), |
|
| 1178 | - __FILE__, |
|
| 1179 | - __FUNCTION__, |
|
| 1180 | - __LINE__ |
|
| 1181 | - ); |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - return $sent_queue; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - |
|
| 1188 | - /** |
|
| 1189 | - * Generate and send immediately from the given $message_ids |
|
| 1190 | - * |
|
| 1191 | - * @param array $message_ids EE_Message entity ids. |
|
| 1192 | - * @throws EE_Error |
|
| 1193 | - * @throws InvalidArgumentException |
|
| 1194 | - * @throws InvalidDataTypeException |
|
| 1195 | - * @throws InvalidInterfaceException |
|
| 1196 | - * @throws ReflectionException |
|
| 1197 | - */ |
|
| 1198 | - public static function generate_and_send_now(array $message_ids) |
|
| 1199 | - { |
|
| 1200 | - $generated_queue = self::generate_now($message_ids); |
|
| 1201 | - // now let's just trigger sending immediately from this queue. |
|
| 1202 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1203 | - ? $generated_queue->execute() |
|
| 1204 | - : 0; |
|
| 1205 | - if ($messages_sent) { |
|
| 1206 | - EE_Error::add_success( |
|
| 1207 | - esc_html( |
|
| 1208 | - sprintf( |
|
| 1209 | - _n( |
|
| 1210 | - 'There was %d message successfully generated and sent.', |
|
| 1211 | - 'There were %d messages successfully generated and sent.', |
|
| 1212 | - $messages_sent, |
|
| 1213 | - 'event_espresso' |
|
| 1214 | - ), |
|
| 1215 | - $messages_sent |
|
| 1216 | - ) |
|
| 1217 | - ) |
|
| 1218 | - ); |
|
| 1219 | - // errors would be added via the generate_now method. |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * This will queue the incoming message ids for resending. |
|
| 1226 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1227 | - * |
|
| 1228 | - * @since 4.9.0 |
|
| 1229 | - * @param array $message_ids An array of EE_Message IDs |
|
| 1230 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1231 | - * resending. |
|
| 1232 | - * @throws EE_Error |
|
| 1233 | - * @throws InvalidArgumentException |
|
| 1234 | - * @throws InvalidDataTypeException |
|
| 1235 | - * @throws InvalidInterfaceException |
|
| 1236 | - * @throws ReflectionException |
|
| 1237 | - */ |
|
| 1238 | - public static function queue_for_resending($message_ids) |
|
| 1239 | - { |
|
| 1240 | - self::_load_controller(); |
|
| 1241 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1242 | - |
|
| 1243 | - // get queue and count |
|
| 1244 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1245 | - |
|
| 1246 | - if ($queue_count > 0 |
|
| 1247 | - ) { |
|
| 1248 | - EE_Error::add_success( |
|
| 1249 | - sprintf( |
|
| 1250 | - _n( |
|
| 1251 | - '%d message successfully queued for resending.', |
|
| 1252 | - '%d messages successfully queued for resending.', |
|
| 1253 | - $queue_count, |
|
| 1254 | - 'event_espresso' |
|
| 1255 | - ), |
|
| 1256 | - $queue_count |
|
| 1257 | - ) |
|
| 1258 | - ); |
|
| 1259 | - /** |
|
| 1260 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1261 | - */ |
|
| 1262 | - } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1263 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1264 | - ) { |
|
| 1265 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1266 | - if ($queue_count > 0) { |
|
| 1267 | - EE_Error::add_success( |
|
| 1268 | - sprintf( |
|
| 1269 | - _n( |
|
| 1270 | - '%d message successfully sent.', |
|
| 1271 | - '%d messages successfully sent.', |
|
| 1272 | - $queue_count, |
|
| 1273 | - 'event_espresso' |
|
| 1274 | - ), |
|
| 1275 | - $queue_count |
|
| 1276 | - ) |
|
| 1277 | - ); |
|
| 1278 | - } else { |
|
| 1279 | - EE_Error::add_error( |
|
| 1280 | - __( |
|
| 1281 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1282 | - 'event_espresso' |
|
| 1283 | - ), |
|
| 1284 | - __FILE__, |
|
| 1285 | - __FUNCTION__, |
|
| 1286 | - __LINE__ |
|
| 1287 | - ); |
|
| 1288 | - } |
|
| 1289 | - } else { |
|
| 1290 | - EE_Error::add_error( |
|
| 1291 | - __( |
|
| 1292 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1293 | - 'event_espresso' |
|
| 1294 | - ), |
|
| 1295 | - __FILE__, |
|
| 1296 | - __FUNCTION__, |
|
| 1297 | - __LINE__ |
|
| 1298 | - ); |
|
| 1299 | - } |
|
| 1300 | - return (bool) $queue_count; |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - |
|
| 1304 | - /** |
|
| 1305 | - * debug |
|
| 1306 | - * |
|
| 1307 | - * @param string $class |
|
| 1308 | - * @param string $func |
|
| 1309 | - * @param string $line |
|
| 1310 | - * @param \EE_Transaction $transaction |
|
| 1311 | - * @param array $info |
|
| 1312 | - * @param bool $display_request |
|
| 1313 | - * @throws EE_Error |
|
| 1314 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1315 | - */ |
|
| 1316 | - protected static function log( |
|
| 1317 | - $class = '', |
|
| 1318 | - $func = '', |
|
| 1319 | - $line = '', |
|
| 1320 | - EE_Transaction $transaction, |
|
| 1321 | - $info = array(), |
|
| 1322 | - $display_request = false |
|
| 1323 | - ) { |
|
| 1324 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1325 | - if ($transaction instanceof EE_Transaction) { |
|
| 1326 | - // don't serialize objects |
|
| 1327 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1328 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1329 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1330 | - if ($transaction->ID()) { |
|
| 1331 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1332 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Resets all the static properties in this class when called. |
|
| 1341 | - */ |
|
| 1342 | - public static function reset() |
|
| 1343 | - { |
|
| 1344 | - self::$_EEMSG = null; |
|
| 1345 | - self::$_message_resource_manager = null; |
|
| 1346 | - self::$_MSG_PROCESSOR = null; |
|
| 1347 | - self::$_MSG_PATHS = null; |
|
| 1348 | - self::$_TMP_PACKS = array(); |
|
| 1349 | - } |
|
| 1176 | + 'event_espresso' |
|
| 1177 | + ), |
|
| 1178 | + __FILE__, |
|
| 1179 | + __FUNCTION__, |
|
| 1180 | + __LINE__ |
|
| 1181 | + ); |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + return $sent_queue; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + |
|
| 1188 | + /** |
|
| 1189 | + * Generate and send immediately from the given $message_ids |
|
| 1190 | + * |
|
| 1191 | + * @param array $message_ids EE_Message entity ids. |
|
| 1192 | + * @throws EE_Error |
|
| 1193 | + * @throws InvalidArgumentException |
|
| 1194 | + * @throws InvalidDataTypeException |
|
| 1195 | + * @throws InvalidInterfaceException |
|
| 1196 | + * @throws ReflectionException |
|
| 1197 | + */ |
|
| 1198 | + public static function generate_and_send_now(array $message_ids) |
|
| 1199 | + { |
|
| 1200 | + $generated_queue = self::generate_now($message_ids); |
|
| 1201 | + // now let's just trigger sending immediately from this queue. |
|
| 1202 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1203 | + ? $generated_queue->execute() |
|
| 1204 | + : 0; |
|
| 1205 | + if ($messages_sent) { |
|
| 1206 | + EE_Error::add_success( |
|
| 1207 | + esc_html( |
|
| 1208 | + sprintf( |
|
| 1209 | + _n( |
|
| 1210 | + 'There was %d message successfully generated and sent.', |
|
| 1211 | + 'There were %d messages successfully generated and sent.', |
|
| 1212 | + $messages_sent, |
|
| 1213 | + 'event_espresso' |
|
| 1214 | + ), |
|
| 1215 | + $messages_sent |
|
| 1216 | + ) |
|
| 1217 | + ) |
|
| 1218 | + ); |
|
| 1219 | + // errors would be added via the generate_now method. |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * This will queue the incoming message ids for resending. |
|
| 1226 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1227 | + * |
|
| 1228 | + * @since 4.9.0 |
|
| 1229 | + * @param array $message_ids An array of EE_Message IDs |
|
| 1230 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1231 | + * resending. |
|
| 1232 | + * @throws EE_Error |
|
| 1233 | + * @throws InvalidArgumentException |
|
| 1234 | + * @throws InvalidDataTypeException |
|
| 1235 | + * @throws InvalidInterfaceException |
|
| 1236 | + * @throws ReflectionException |
|
| 1237 | + */ |
|
| 1238 | + public static function queue_for_resending($message_ids) |
|
| 1239 | + { |
|
| 1240 | + self::_load_controller(); |
|
| 1241 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1242 | + |
|
| 1243 | + // get queue and count |
|
| 1244 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1245 | + |
|
| 1246 | + if ($queue_count > 0 |
|
| 1247 | + ) { |
|
| 1248 | + EE_Error::add_success( |
|
| 1249 | + sprintf( |
|
| 1250 | + _n( |
|
| 1251 | + '%d message successfully queued for resending.', |
|
| 1252 | + '%d messages successfully queued for resending.', |
|
| 1253 | + $queue_count, |
|
| 1254 | + 'event_espresso' |
|
| 1255 | + ), |
|
| 1256 | + $queue_count |
|
| 1257 | + ) |
|
| 1258 | + ); |
|
| 1259 | + /** |
|
| 1260 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1261 | + */ |
|
| 1262 | + } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1263 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1264 | + ) { |
|
| 1265 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1266 | + if ($queue_count > 0) { |
|
| 1267 | + EE_Error::add_success( |
|
| 1268 | + sprintf( |
|
| 1269 | + _n( |
|
| 1270 | + '%d message successfully sent.', |
|
| 1271 | + '%d messages successfully sent.', |
|
| 1272 | + $queue_count, |
|
| 1273 | + 'event_espresso' |
|
| 1274 | + ), |
|
| 1275 | + $queue_count |
|
| 1276 | + ) |
|
| 1277 | + ); |
|
| 1278 | + } else { |
|
| 1279 | + EE_Error::add_error( |
|
| 1280 | + __( |
|
| 1281 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1282 | + 'event_espresso' |
|
| 1283 | + ), |
|
| 1284 | + __FILE__, |
|
| 1285 | + __FUNCTION__, |
|
| 1286 | + __LINE__ |
|
| 1287 | + ); |
|
| 1288 | + } |
|
| 1289 | + } else { |
|
| 1290 | + EE_Error::add_error( |
|
| 1291 | + __( |
|
| 1292 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1293 | + 'event_espresso' |
|
| 1294 | + ), |
|
| 1295 | + __FILE__, |
|
| 1296 | + __FUNCTION__, |
|
| 1297 | + __LINE__ |
|
| 1298 | + ); |
|
| 1299 | + } |
|
| 1300 | + return (bool) $queue_count; |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + |
|
| 1304 | + /** |
|
| 1305 | + * debug |
|
| 1306 | + * |
|
| 1307 | + * @param string $class |
|
| 1308 | + * @param string $func |
|
| 1309 | + * @param string $line |
|
| 1310 | + * @param \EE_Transaction $transaction |
|
| 1311 | + * @param array $info |
|
| 1312 | + * @param bool $display_request |
|
| 1313 | + * @throws EE_Error |
|
| 1314 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1315 | + */ |
|
| 1316 | + protected static function log( |
|
| 1317 | + $class = '', |
|
| 1318 | + $func = '', |
|
| 1319 | + $line = '', |
|
| 1320 | + EE_Transaction $transaction, |
|
| 1321 | + $info = array(), |
|
| 1322 | + $display_request = false |
|
| 1323 | + ) { |
|
| 1324 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1325 | + if ($transaction instanceof EE_Transaction) { |
|
| 1326 | + // don't serialize objects |
|
| 1327 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1328 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1329 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1330 | + if ($transaction->ID()) { |
|
| 1331 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1332 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Resets all the static properties in this class when called. |
|
| 1341 | + */ |
|
| 1342 | + public static function reset() |
|
| 1343 | + { |
|
| 1344 | + self::$_EEMSG = null; |
|
| 1345 | + self::$_message_resource_manager = null; |
|
| 1346 | + self::$_MSG_PROCESSOR = null; |
|
| 1347 | + self::$_MSG_PATHS = null; |
|
| 1348 | + self::$_TMP_PACKS = array(); |
|
| 1349 | + } |
|
| 1350 | 1350 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | 'event_espresso' |
| 203 | 203 | ); |
| 204 | 204 | // add specific message for developers if WP_DEBUG in on |
| 205 | - $error_msg .= '||' . $e->getMessage(); |
|
| 205 | + $error_msg .= '||'.$e->getMessage(); |
|
| 206 | 206 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 207 | 207 | } |
| 208 | 208 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | 'event_espresso' |
| 290 | 290 | ); |
| 291 | 291 | // add specific message for developers if WP_DEBUG in on |
| 292 | - $error_msg .= '||' . $e->getMessage(); |
|
| 292 | + $error_msg .= '||'.$e->getMessage(); |
|
| 293 | 293 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $transient_key = EE_Registry::instance()->REQ->get('key'); |
| 321 | 321 | |
| 322 | 322 | // now let's verify transient, if not valid exit immediately |
| 323 | - if (! get_transient($transient_key)) { |
|
| 323 | + if ( ! get_transient($transient_key)) { |
|
| 324 | 324 | /** |
| 325 | 325 | * trigger error so this gets in the error logs. This is important because it happens on a non-user |
| 326 | 326 | * request. |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | delete_transient($transient_key); |
| 333 | 333 | |
| 334 | 334 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
| 335 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 335 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
| 336 | 336 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
| 337 | 337 | self::$_MSG_PROCESSOR->$method(); |
| 338 | 338 | } else { |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $template_pack_collection->rewind(); |
| 400 | 400 | $template_packs = array(); |
| 401 | 401 | while ($template_pack_collection->valid()) { |
| 402 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 402 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 403 | 403 | $template_pack_collection->next(); |
| 404 | 404 | } |
| 405 | 405 | return $template_packs; |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | ); |
| 450 | 450 | $paths = array(); |
| 451 | 451 | foreach ($dir_ref as $index => $dir) { |
| 452 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 452 | + $paths[$index] = EE_LIBRARIES.$dir; |
|
| 453 | 453 | } |
| 454 | 454 | self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
| 455 | 455 | } |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | */ |
| 469 | 469 | protected static function _load_controller() |
| 470 | 470 | { |
| 471 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 471 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 472 | 472 | EE_Registry::instance()->load_core('Request_Handler'); |
| 473 | 473 | self::set_autoloaders(); |
| 474 | 474 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
| 510 | 510 | { |
| 511 | 511 | // if there's no payment object, then we cannot do a payment type message! |
| 512 | - if (! $payment instanceof EE_Payment) { |
|
| 512 | + if ( ! $payment instanceof EE_Payment) { |
|
| 513 | 513 | return; |
| 514 | 514 | } |
| 515 | 515 | self::_load_controller(); |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
| 557 | 557 | { |
| 558 | 558 | |
| 559 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 559 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 560 | 560 | // no messages please |
| 561 | 561 | return; |
| 562 | 562 | } |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | EE_Registration $registration, |
| 624 | 624 | $extra_details = array() |
| 625 | 625 | ) { |
| 626 | - if (! $registration->is_primary_registrant()) { |
|
| 626 | + if ( ! $registration->is_primary_registrant()) { |
|
| 627 | 627 | return false; |
| 628 | 628 | } |
| 629 | 629 | // first we check if we're in admin and not doing front ajax |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | } else { |
| 639 | 639 | // frontend request (either regular or via AJAX) |
| 640 | 640 | // TXN is NOT finalized ? |
| 641 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 641 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 642 | 642 | return false; |
| 643 | 643 | } |
| 644 | 644 | // return visit but nothing changed ??? |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | return false; |
| 649 | 649 | } |
| 650 | 650 | // NOT sending messages && reg status is something other than "Not-Approved" |
| 651 | - if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 651 | + if ( ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 652 | 652 | $registration->status_ID() !== EEM_Registration::status_id_not_approved |
| 653 | 653 | ) { |
| 654 | 654 | return false; |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | EE_Registry::instance()->REQ->set($request_key, $request_value); |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 734 | + if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 735 | 735 | )) { |
| 736 | 736 | return false; |
| 737 | 737 | } |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | self::_load_controller(); |
| 766 | 766 | |
| 767 | 767 | $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
| 768 | - if (! $msgID) { |
|
| 768 | + if ( ! $msgID) { |
|
| 769 | 769 | EE_Error::add_error( |
| 770 | 770 | __( |
| 771 | 771 | 'Something went wrong because there is no "MSG_ID" value in the request', |
@@ -957,14 +957,14 @@ discard block |
||
| 957 | 957 | // get the message template group. |
| 958 | 958 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
| 959 | 959 | // if we don't have an EE_Message_Template_Group then return |
| 960 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 960 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 961 | 961 | // remove EVT_ID from query params so that global templates get picked up |
| 962 | 962 | unset($template_query_params['Event.EVT_ID']); |
| 963 | 963 | // get global template as the fallback |
| 964 | 964 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
| 965 | 965 | } |
| 966 | 966 | // if we don't have an EE_Message_Template_Group then return |
| 967 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 967 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 968 | 968 | return ''; |
| 969 | 969 | } |
| 970 | 970 | // generate the URL |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1098 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1099 | 1099 | EE_Error::add_error( |
| 1100 | 1100 | __( |
| 1101 | 1101 | 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
@@ -1142,7 +1142,7 @@ discard block |
||
| 1142 | 1142 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1145 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1146 | 1146 | EE_Error::add_error( |
| 1147 | 1147 | __( |
| 1148 | 1148 | 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | $info['TXN_status'] = $transaction->status_ID(); |
| 1329 | 1329 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
| 1330 | 1330 | if ($transaction->ID()) { |
| 1331 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1331 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
| 1332 | 1332 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
| 1333 | 1333 | } |
| 1334 | 1334 | } |
@@ -16,129 +16,129 @@ |
||
| 16 | 16 | interface NoticesContainerInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $notice |
|
| 21 | - * @param bool $dismissible |
|
| 22 | - * @param string $file |
|
| 23 | - * @param string $func |
|
| 24 | - * @param string $line |
|
| 25 | - */ |
|
| 26 | - public function addInformation($notice, $dismissible = true, $file = '', $func = '', $line = ''); |
|
| 19 | + /** |
|
| 20 | + * @param string $notice |
|
| 21 | + * @param bool $dismissible |
|
| 22 | + * @param string $file |
|
| 23 | + * @param string $func |
|
| 24 | + * @param string $line |
|
| 25 | + */ |
|
| 26 | + public function addInformation($notice, $dismissible = true, $file = '', $func = '', $line = ''); |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param string $notice |
|
| 31 | - * @param bool $dismissible |
|
| 32 | - * @param string $file |
|
| 33 | - * @param string $func |
|
| 34 | - * @param string $line |
|
| 35 | - * @return |
|
| 36 | - */ |
|
| 37 | - public function addAttention($notice, $dismissible = true, $file = '', $func = '', $line = ''); |
|
| 29 | + /** |
|
| 30 | + * @param string $notice |
|
| 31 | + * @param bool $dismissible |
|
| 32 | + * @param string $file |
|
| 33 | + * @param string $func |
|
| 34 | + * @param string $line |
|
| 35 | + * @return |
|
| 36 | + */ |
|
| 37 | + public function addAttention($notice, $dismissible = true, $file = '', $func = '', $line = ''); |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $notice |
|
| 43 | - * @param bool $dismissible |
|
| 44 | - * @param string $file |
|
| 45 | - * @param string $func |
|
| 46 | - * @param string $line |
|
| 47 | - */ |
|
| 48 | - public function addError($notice, $dismissible = true, $file, $func, $line); |
|
| 41 | + /** |
|
| 42 | + * @param string $notice |
|
| 43 | + * @param bool $dismissible |
|
| 44 | + * @param string $file |
|
| 45 | + * @param string $func |
|
| 46 | + * @param string $line |
|
| 47 | + */ |
|
| 48 | + public function addError($notice, $dismissible = true, $file, $func, $line); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $notice |
|
| 54 | - * @param bool $dismissible |
|
| 55 | - * @param string $file |
|
| 56 | - * @param string $func |
|
| 57 | - * @param string $line |
|
| 58 | - */ |
|
| 59 | - public function addSuccess($notice, $dismissible = true, $file = '', $func = '', $line = ''); |
|
| 52 | + /** |
|
| 53 | + * @param string $notice |
|
| 54 | + * @param bool $dismissible |
|
| 55 | + * @param string $file |
|
| 56 | + * @param string $func |
|
| 57 | + * @param string $line |
|
| 58 | + */ |
|
| 59 | + public function addSuccess($notice, $dismissible = true, $file = '', $func = '', $line = ''); |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return boolean |
|
| 65 | - */ |
|
| 66 | - public function hasInformation(); |
|
| 63 | + /** |
|
| 64 | + * @return boolean |
|
| 65 | + */ |
|
| 66 | + public function hasInformation(); |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return boolean |
|
| 72 | - */ |
|
| 73 | - public function hasAttention(); |
|
| 70 | + /** |
|
| 71 | + * @return boolean |
|
| 72 | + */ |
|
| 73 | + public function hasAttention(); |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - public function hasError(); |
|
| 77 | + /** |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + public function hasError(); |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - public function hasSuccess(); |
|
| 84 | + /** |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + public function hasSuccess(); |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return int |
|
| 93 | - */ |
|
| 94 | - public function countInformation(); |
|
| 91 | + /** |
|
| 92 | + * @return int |
|
| 93 | + */ |
|
| 94 | + public function countInformation(); |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - public function countAttention(); |
|
| 98 | + /** |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + public function countAttention(); |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return int |
|
| 107 | - */ |
|
| 108 | - public function countError(); |
|
| 105 | + /** |
|
| 106 | + * @return int |
|
| 107 | + */ |
|
| 108 | + public function countError(); |
|
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * @return int |
|
| 114 | - */ |
|
| 115 | - public function countSuccess(); |
|
| 112 | + /** |
|
| 113 | + * @return int |
|
| 114 | + */ |
|
| 115 | + public function countSuccess(); |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @return NoticeInterface[] |
|
| 121 | - */ |
|
| 122 | - public function getInformation(); |
|
| 119 | + /** |
|
| 120 | + * @return NoticeInterface[] |
|
| 121 | + */ |
|
| 122 | + public function getInformation(); |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * @return NoticeInterface[] |
|
| 128 | - */ |
|
| 129 | - public function getAttention(); |
|
| 126 | + /** |
|
| 127 | + * @return NoticeInterface[] |
|
| 128 | + */ |
|
| 129 | + public function getAttention(); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return NoticeInterface[] |
|
| 135 | - */ |
|
| 136 | - public function getError(); |
|
| 133 | + /** |
|
| 134 | + * @return NoticeInterface[] |
|
| 135 | + */ |
|
| 136 | + public function getError(); |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @return NoticeInterface[] |
|
| 142 | - */ |
|
| 143 | - public function getSuccess(); |
|
| 140 | + /** |
|
| 141 | + * @return NoticeInterface[] |
|
| 142 | + */ |
|
| 143 | + public function getSuccess(); |
|
| 144 | 144 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
| 37 | 37 | foreach ($notices->getError() as $notice) { |
| 38 | 38 | if ($this->getThrowExceptions()) { |
| 39 | - $error_string .= '<br />' . $notice->message(); |
|
| 39 | + $error_string .= '<br />'.$notice->message(); |
|
| 40 | 40 | } else { |
| 41 | 41 | new AdminNotice($notice); |
| 42 | 42 | } |
@@ -14,42 +14,42 @@ |
||
| 14 | 14 | class ConvertNoticesToAdminNotices extends NoticeConverter |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Converts Notice objects into AdminNotice notifications |
|
| 19 | - * |
|
| 20 | - * @param NoticesContainerInterface $notices |
|
| 21 | - * @throws DomainException |
|
| 22 | - */ |
|
| 23 | - public function process(NoticesContainerInterface $notices) |
|
| 24 | - { |
|
| 25 | - if ($notices->hasAttention()) { |
|
| 26 | - foreach ($notices->getAttention() as $notice) { |
|
| 27 | - new AdminNotice($notice); |
|
| 28 | - } |
|
| 29 | - } |
|
| 30 | - if ($notices->hasError()) { |
|
| 31 | - $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
|
| 32 | - foreach ($notices->getError() as $notice) { |
|
| 33 | - if ($this->getThrowExceptions()) { |
|
| 34 | - $error_string .= '<br />' . $notice->message(); |
|
| 35 | - } else { |
|
| 36 | - new AdminNotice($notice); |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - if ($this->getThrowExceptions()) { |
|
| 40 | - throw new DomainException($error_string); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - if ($notices->hasSuccess()) { |
|
| 44 | - foreach ($notices->getSuccess() as $notice) { |
|
| 45 | - new AdminNotice($notice); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - if ($notices->hasInformation()) { |
|
| 49 | - foreach ($notices->getInformation() as $notice) { |
|
| 50 | - new AdminNotice($notice); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - $this->clearNotices(); |
|
| 54 | - } |
|
| 17 | + /** |
|
| 18 | + * Converts Notice objects into AdminNotice notifications |
|
| 19 | + * |
|
| 20 | + * @param NoticesContainerInterface $notices |
|
| 21 | + * @throws DomainException |
|
| 22 | + */ |
|
| 23 | + public function process(NoticesContainerInterface $notices) |
|
| 24 | + { |
|
| 25 | + if ($notices->hasAttention()) { |
|
| 26 | + foreach ($notices->getAttention() as $notice) { |
|
| 27 | + new AdminNotice($notice); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | + if ($notices->hasError()) { |
|
| 31 | + $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
|
| 32 | + foreach ($notices->getError() as $notice) { |
|
| 33 | + if ($this->getThrowExceptions()) { |
|
| 34 | + $error_string .= '<br />' . $notice->message(); |
|
| 35 | + } else { |
|
| 36 | + new AdminNotice($notice); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + if ($this->getThrowExceptions()) { |
|
| 40 | + throw new DomainException($error_string); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + if ($notices->hasSuccess()) { |
|
| 44 | + foreach ($notices->getSuccess() as $notice) { |
|
| 45 | + new AdminNotice($notice); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + if ($notices->hasInformation()) { |
|
| 49 | + foreach ($notices->getInformation() as $notice) { |
|
| 50 | + new AdminNotice($notice); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + $this->clearNotices(); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | 276 | * @access public |
| 277 | - * @return string |
|
| 277 | + * @return boolean |
|
| 278 | 278 | */ |
| 279 | 279 | public static function is_iframe() |
| 280 | 280 | { |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | * display_description |
| 893 | 893 | * |
| 894 | 894 | * @access public |
| 895 | - * @param $value |
|
| 895 | + * @param integer $value |
|
| 896 | 896 | * @return bool |
| 897 | 897 | */ |
| 898 | 898 | public static function display_description($value) |
@@ -16,1094 +16,1094 @@ discard block |
||
| 16 | 16 | class EED_Events_Archive extends EED_Module |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - const EVENT_DETAILS_PRIORITY = 100; |
|
| 20 | - |
|
| 21 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
| 22 | - |
|
| 23 | - const EVENT_TICKETS_PRIORITY = 120; |
|
| 24 | - |
|
| 25 | - const EVENT_VENUES_PRIORITY = 130; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - public static $espresso_event_list_ID = 0; |
|
| 29 | - |
|
| 30 | - public static $espresso_grid_event_lists = array(); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type bool $using_get_the_excerpt |
|
| 34 | - */ |
|
| 35 | - protected static $using_get_the_excerpt = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Used to flag when the event list is being called from an external iframe. |
|
| 39 | - * |
|
| 40 | - * @var bool $iframe |
|
| 41 | - */ |
|
| 42 | - protected static $iframe = false; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
|
| 46 | - */ |
|
| 47 | - private static $_iframe_embed_button; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @type EE_Template_Part_Manager $template_parts |
|
| 51 | - */ |
|
| 52 | - protected $template_parts; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return EED_Events_Archive |
|
| 57 | - */ |
|
| 58 | - public static function instance() |
|
| 59 | - { |
|
| 60 | - return parent::get_instance(__CLASS__); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 66 | - * |
|
| 67 | - * @return void |
|
| 68 | - * @throws InvalidArgumentException |
|
| 69 | - * @throws InvalidDataTypeException |
|
| 70 | - * @throws InvalidInterfaceException |
|
| 71 | - */ |
|
| 72 | - public static function set_hooks() |
|
| 73 | - { |
|
| 74 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 75 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 76 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 77 | - ); |
|
| 78 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 79 | - EE_Config::register_route( |
|
| 80 | - $custom_post_types['espresso_events']['plural_slug'], |
|
| 81 | - 'Events_Archive', |
|
| 82 | - 'run' |
|
| 83 | - ); |
|
| 84 | - EE_Config::register_route( |
|
| 85 | - 'event_list', |
|
| 86 | - 'Events_Archive', |
|
| 87 | - 'event_list' |
|
| 88 | - ); |
|
| 89 | - EE_Config::register_route( |
|
| 90 | - 'iframe', |
|
| 91 | - 'Events_Archive', |
|
| 92 | - 'event_list_iframe', |
|
| 93 | - 'event_list' |
|
| 94 | - ); |
|
| 95 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 101 | - * |
|
| 102 | - * @access public |
|
| 103 | - * @return void |
|
| 104 | - */ |
|
| 105 | - public static function set_hooks_admin() |
|
| 106 | - { |
|
| 107 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 108 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
| 109 | - // to load assets for "espresso_events" page on the "default" route (action) |
|
| 110 | - add_action( |
|
| 111 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
| 112 | - array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
| 113 | - 10 |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * set_definitions |
|
| 120 | - * |
|
| 121 | - * @access public |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public static function set_definitions() |
|
| 125 | - { |
|
| 126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * set up EE_Events_Archive_Config |
|
| 133 | - */ |
|
| 134 | - protected function set_config() |
|
| 135 | - { |
|
| 136 | - $this->set_config_section('template_settings'); |
|
| 137 | - $this->set_config_class('EE_Events_Archive_Config'); |
|
| 138 | - $this->set_config_name('EED_Events_Archive'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return EventListIframeEmbedButton |
|
| 144 | - */ |
|
| 145 | - public static function get_iframe_embed_button() |
|
| 146 | - { |
|
| 147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | - self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
| 149 | - } |
|
| 150 | - return self::$_iframe_embed_button; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * event_list_iframe_embed_button |
|
| 156 | - * |
|
| 157 | - * @return void |
|
| 158 | - * @throws \EE_Error |
|
| 159 | - */ |
|
| 160 | - public static function event_list_iframe_embed_button() |
|
| 161 | - { |
|
| 162 | - $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button(); |
|
| 163 | - $iframe_embed_button->addEmbedButton(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * initialize_template_parts |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @param \EE_Events_Archive_Config $config |
|
| 172 | - * @return \EE_Template_Part_Manager |
|
| 173 | - */ |
|
| 174 | - public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
| 175 | - { |
|
| 176 | - $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
| 177 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 178 | - $template_parts = new EE_Template_Part_Manager(); |
|
| 179 | - $template_parts->add_template_part( |
|
| 180 | - 'tickets', |
|
| 181 | - __('Ticket Selector', 'event_espresso'), |
|
| 182 | - 'content-espresso_events-tickets.php', |
|
| 183 | - $config->display_order_tickets |
|
| 184 | - ); |
|
| 185 | - $template_parts->add_template_part( |
|
| 186 | - 'datetimes', |
|
| 187 | - __('Dates and Times', 'event_espresso'), |
|
| 188 | - 'content-espresso_events-datetimes.php', |
|
| 189 | - $config->display_order_datetimes |
|
| 190 | - ); |
|
| 191 | - $template_parts->add_template_part( |
|
| 192 | - 'event', |
|
| 193 | - __('Event Description', 'event_espresso'), |
|
| 194 | - 'content-espresso_events-details.php', |
|
| 195 | - $config->display_order_event |
|
| 196 | - ); |
|
| 197 | - $template_parts->add_template_part( |
|
| 198 | - 'venue', |
|
| 199 | - __('Venue Information', 'event_espresso'), |
|
| 200 | - 'content-espresso_events-venues.php', |
|
| 201 | - $config->display_order_venue |
|
| 202 | - ); |
|
| 203 | - do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
| 204 | - return $template_parts; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
| 210 | - * incoming request |
|
| 211 | - * |
|
| 212 | - * @access public |
|
| 213 | - * @param WP $WP |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public function run($WP) |
|
| 217 | - { |
|
| 218 | - do_action('AHEE__EED_Events_Archive__before_run'); |
|
| 219 | - // ensure valid EE_Events_Archive_Config() object exists |
|
| 220 | - $this->set_config(); |
|
| 221 | - /** @type EE_Events_Archive_Config $config */ |
|
| 222 | - $config = $this->config(); |
|
| 223 | - // load other required components |
|
| 224 | - $this->load_event_list_assets(); |
|
| 225 | - // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
| 226 | - // add query filters |
|
| 227 | - EEH_Event_Query::add_query_filters(); |
|
| 228 | - // set params that will get used by the filters |
|
| 229 | - EEH_Event_Query::set_query_params( |
|
| 230 | - '', // month |
|
| 231 | - '', // category |
|
| 232 | - $config->display_expired_events, // show_expired |
|
| 233 | - 'start_date', // orderby |
|
| 234 | - 'ASC' // sort |
|
| 235 | - ); |
|
| 236 | - // check what template is loaded |
|
| 237 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
| 243 | - * |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - public function event_list() |
|
| 247 | - { |
|
| 248 | - // ensure valid EE_Events_Archive_Config() object exists |
|
| 249 | - $this->set_config(); |
|
| 250 | - // load other required components |
|
| 251 | - $this->load_event_list_assets(); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @access public |
|
| 257 | - * @return void |
|
| 258 | - * @throws \EE_Error |
|
| 259 | - * @throws \DomainException |
|
| 260 | - */ |
|
| 261 | - public function event_list_iframe() |
|
| 262 | - { |
|
| 263 | - \EED_Events_Archive::$iframe = true; |
|
| 264 | - $event_list_iframe = new EventsArchiveIframe($this); |
|
| 265 | - $event_list_iframe->display(); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @access public |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public static function is_iframe() |
|
| 274 | - { |
|
| 275 | - return \EED_Events_Archive::$iframe; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @access public |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public static function link_target() |
|
| 284 | - { |
|
| 285 | - return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * template_include |
|
| 291 | - * |
|
| 292 | - * @access public |
|
| 293 | - * @param string $template |
|
| 294 | - * @return string |
|
| 295 | - */ |
|
| 296 | - public function template_include($template = '') |
|
| 297 | - { |
|
| 298 | - // don't add content filter for dedicated EE child themes or private posts |
|
| 299 | - if (! EEH_Template::is_espresso_theme()) { |
|
| 300 | - /** @type EE_Events_Archive_Config $config */ |
|
| 301 | - $config = $this->config(); |
|
| 302 | - // add status banner ? |
|
| 303 | - if ($config->display_status_banner) { |
|
| 304 | - add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
| 305 | - } |
|
| 306 | - // if NOT a custom template |
|
| 307 | - if (apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
| 308 | - || EE_Registry::instance() |
|
| 309 | - ->load_core('Front_Controller') |
|
| 310 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
| 311 | - ) { |
|
| 312 | - // don't display entry meta because the existing theme will take care of that |
|
| 313 | - add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
| 314 | - // load functions.php file for the theme (loaded by WP if using child theme) |
|
| 315 | - EEH_Template::load_espresso_theme_functions(); |
|
| 316 | - // because we don't know if the theme is using the_excerpt() |
|
| 317 | - add_filter( |
|
| 318 | - 'the_excerpt', |
|
| 319 | - array('EED_Events_Archive', 'event_details'), |
|
| 320 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 321 | - ); |
|
| 322 | - // or the_content |
|
| 323 | - add_filter( |
|
| 324 | - 'the_content', |
|
| 325 | - array('EED_Events_Archive', 'event_details'), |
|
| 326 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 327 | - ); |
|
| 328 | - // and just in case they are running get_the_excerpt() which DESTROYS things |
|
| 329 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 330 | - // don't display entry meta because the existing theme will take care of that |
|
| 331 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - return $template; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
| 340 | - * on the_content() |
|
| 341 | - * |
|
| 342 | - * @access public |
|
| 343 | - * @param string $excerpt |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public static function get_the_excerpt($excerpt = '') |
|
| 347 | - { |
|
| 348 | - if (post_password_required()) { |
|
| 349 | - return $excerpt; |
|
| 350 | - } |
|
| 351 | - if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
| 352 | - remove_filter( |
|
| 353 | - 'the_excerpt', |
|
| 354 | - array('EED_Events_Archive', 'event_details'), |
|
| 355 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 356 | - ); |
|
| 357 | - remove_filter( |
|
| 358 | - 'the_content', |
|
| 359 | - array('EED_Events_Archive', 'event_details'), |
|
| 360 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 361 | - ); |
|
| 362 | - $excerpt = EED_Events_Archive::event_details($excerpt); |
|
| 363 | - } else { |
|
| 364 | - EED_Events_Archive::$using_get_the_excerpt = true; |
|
| 365 | - add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
| 366 | - } |
|
| 367 | - return $excerpt; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * end_get_the_excerpt |
|
| 373 | - * |
|
| 374 | - * @access public |
|
| 375 | - * @param string $text |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public static function end_get_the_excerpt($text = '') |
|
| 379 | - { |
|
| 380 | - EED_Events_Archive::$using_get_the_excerpt = false; |
|
| 381 | - return $text; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * the_title |
|
| 387 | - * |
|
| 388 | - * @access public |
|
| 389 | - * @param string $title |
|
| 390 | - * @param string $id |
|
| 391 | - * @return string |
|
| 392 | - */ |
|
| 393 | - public static function the_title($title = '', $id = '') |
|
| 394 | - { |
|
| 395 | - global $post; |
|
| 396 | - if ($post instanceof WP_Post) { |
|
| 397 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 398 | - } |
|
| 399 | - return $title; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * event_details |
|
| 405 | - * |
|
| 406 | - * @access public |
|
| 407 | - * @param string $content |
|
| 408 | - * @return string |
|
| 409 | - */ |
|
| 410 | - public static function event_details($content) |
|
| 411 | - { |
|
| 412 | - global $post; |
|
| 413 | - static $current_post_ID = 0; |
|
| 414 | - if ($current_post_ID !== $post->ID |
|
| 415 | - && $post->post_type === 'espresso_events' |
|
| 416 | - && ! EED_Events_Archive::$using_get_the_excerpt |
|
| 417 | - && ! post_password_required() |
|
| 418 | - && ( |
|
| 419 | - apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
| 420 | - || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
| 421 | - ) |
|
| 422 | - ) { |
|
| 423 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 424 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 425 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 426 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 427 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 428 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
| 429 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 430 | - if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
| 431 | - $content = \EED_Events_Archive::use_sortable_display_order(); |
|
| 432 | - } else { |
|
| 433 | - $content = \EED_Events_Archive::use_filterable_display_order(); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - return $content; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * use_sortable_display_order |
|
| 442 | - * |
|
| 443 | - * @access protected |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - protected static function use_sortable_display_order() |
|
| 447 | - { |
|
| 448 | - // no further password checks required atm |
|
| 449 | - add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
| 450 | - // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
| 451 | - // (otherwise it will recurse and blow up the interweb) |
|
| 452 | - remove_filter( |
|
| 453 | - 'the_excerpt', |
|
| 454 | - array('EED_Events_Archive', 'event_details'), |
|
| 455 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 456 | - ); |
|
| 457 | - remove_filter( |
|
| 458 | - 'the_content', |
|
| 459 | - array('EED_Events_Archive', 'event_details'), |
|
| 460 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 461 | - ); |
|
| 462 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 463 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 464 | - EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
| 465 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 466 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
| 467 | - // re-add our main filters (or else the next event won't have them) |
|
| 468 | - add_filter( |
|
| 469 | - 'the_excerpt', |
|
| 470 | - array('EED_Events_Archive', 'event_details'), |
|
| 471 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 472 | - ); |
|
| 473 | - add_filter( |
|
| 474 | - 'the_content', |
|
| 475 | - array('EED_Events_Archive', 'event_details'), |
|
| 476 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 477 | - ); |
|
| 478 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 479 | - remove_filter( |
|
| 480 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
| 481 | - '__return_true' |
|
| 482 | - ); |
|
| 483 | - return $content; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * use_filterable_display_order |
|
| 489 | - * |
|
| 490 | - * @access protected |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - protected static function use_filterable_display_order() |
|
| 494 | - { |
|
| 495 | - // we need to first remove this callback from being applied to the_content() |
|
| 496 | - // (otherwise it will recurse and blow up the interweb) |
|
| 497 | - remove_filter( |
|
| 498 | - 'the_excerpt', |
|
| 499 | - array('EED_Events_Archive', 'event_details'), |
|
| 500 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 501 | - ); |
|
| 502 | - remove_filter( |
|
| 503 | - 'the_content', |
|
| 504 | - array('EED_Events_Archive', 'event_details'), |
|
| 505 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 506 | - ); |
|
| 507 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 508 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 509 | - EED_Events_Archive::_add_additional_excerpt_filters(); |
|
| 510 | - EED_Events_Archive::_add_additional_content_filters(); |
|
| 511 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
| 512 | - // now load our template |
|
| 513 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 514 | - // re-add our main filters (or else the next event won't have them) |
|
| 515 | - add_filter( |
|
| 516 | - 'the_excerpt', |
|
| 517 | - array('EED_Events_Archive', 'event_details'), |
|
| 518 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 519 | - ); |
|
| 520 | - add_filter( |
|
| 521 | - 'the_content', |
|
| 522 | - array('EED_Events_Archive', 'event_details'), |
|
| 523 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 524 | - ); |
|
| 525 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 526 | - // but remove the other filters so that they don't get applied to the next post |
|
| 527 | - EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
| 528 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
| 529 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 530 | - // return ! empty( $template ) ? $template : $content; |
|
| 531 | - return $content; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * event_datetimes - adds datetimes ABOVE content |
|
| 537 | - * |
|
| 538 | - * @access public |
|
| 539 | - * @param string $content |
|
| 540 | - * @return string |
|
| 541 | - */ |
|
| 542 | - public static function event_datetimes($content) |
|
| 543 | - { |
|
| 544 | - if (post_password_required()) { |
|
| 545 | - return $content; |
|
| 546 | - } |
|
| 547 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 553 | - * |
|
| 554 | - * @access public |
|
| 555 | - * @param string $content |
|
| 556 | - * @return string |
|
| 557 | - */ |
|
| 558 | - public static function event_tickets($content) |
|
| 559 | - { |
|
| 560 | - if (post_password_required()) { |
|
| 561 | - return $content; |
|
| 562 | - } |
|
| 563 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * event_venues - adds venues BELOW content |
|
| 569 | - * |
|
| 570 | - * @access public |
|
| 571 | - * @param string $content |
|
| 572 | - * @return string |
|
| 573 | - */ |
|
| 574 | - public static function event_venue($content) |
|
| 575 | - { |
|
| 576 | - return EED_Events_Archive::event_venues($content); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * event_venues - adds venues BELOW content |
|
| 582 | - * |
|
| 583 | - * @access public |
|
| 584 | - * @param string $content |
|
| 585 | - * @return string |
|
| 586 | - */ |
|
| 587 | - public static function event_venues($content) |
|
| 588 | - { |
|
| 589 | - if (post_password_required()) { |
|
| 590 | - return $content; |
|
| 591 | - } |
|
| 592 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * _add_additional_content_filters |
|
| 598 | - * |
|
| 599 | - * @access private |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - private static function _add_additional_excerpt_filters() |
|
| 603 | - { |
|
| 604 | - add_filter( |
|
| 605 | - 'the_excerpt', |
|
| 606 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 607 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 608 | - ); |
|
| 609 | - add_filter( |
|
| 610 | - 'the_excerpt', |
|
| 611 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 612 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 613 | - ); |
|
| 614 | - add_filter( |
|
| 615 | - 'the_excerpt', |
|
| 616 | - array('EED_Events_Archive', 'event_venues'), |
|
| 617 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * _add_additional_content_filters |
|
| 624 | - * |
|
| 625 | - * @access private |
|
| 626 | - * @return void |
|
| 627 | - */ |
|
| 628 | - private static function _add_additional_content_filters() |
|
| 629 | - { |
|
| 630 | - add_filter( |
|
| 631 | - 'the_content', |
|
| 632 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 633 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 634 | - ); |
|
| 635 | - add_filter( |
|
| 636 | - 'the_content', |
|
| 637 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 638 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 639 | - ); |
|
| 640 | - add_filter( |
|
| 641 | - 'the_content', |
|
| 642 | - array('EED_Events_Archive', 'event_venues'), |
|
| 643 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * _remove_additional_events_archive_filters |
|
| 650 | - * |
|
| 651 | - * @access private |
|
| 652 | - * @return void |
|
| 653 | - */ |
|
| 654 | - private static function _remove_additional_events_archive_filters() |
|
| 655 | - { |
|
| 656 | - remove_filter( |
|
| 657 | - 'the_excerpt', |
|
| 658 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 659 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 660 | - ); |
|
| 661 | - remove_filter( |
|
| 662 | - 'the_excerpt', |
|
| 663 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 664 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 665 | - ); |
|
| 666 | - remove_filter( |
|
| 667 | - 'the_excerpt', |
|
| 668 | - array('EED_Events_Archive', 'event_venues'), |
|
| 669 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 670 | - ); |
|
| 671 | - remove_filter( |
|
| 672 | - 'the_content', |
|
| 673 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 674 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 675 | - ); |
|
| 676 | - remove_filter( |
|
| 677 | - 'the_content', |
|
| 678 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 679 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 680 | - ); |
|
| 681 | - remove_filter( |
|
| 682 | - 'the_content', |
|
| 683 | - array('EED_Events_Archive', 'event_venues'), |
|
| 684 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 685 | - ); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * remove_all_events_archive_filters |
|
| 691 | - * |
|
| 692 | - * @access public |
|
| 693 | - * @return void |
|
| 694 | - */ |
|
| 695 | - public static function remove_all_events_archive_filters() |
|
| 696 | - { |
|
| 697 | - // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
| 698 | - remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
| 699 | - remove_filter( |
|
| 700 | - 'the_excerpt', |
|
| 701 | - array('EED_Events_Archive', 'event_details'), |
|
| 702 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 703 | - ); |
|
| 704 | - remove_filter( |
|
| 705 | - 'the_excerpt', |
|
| 706 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 707 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 708 | - ); |
|
| 709 | - remove_filter( |
|
| 710 | - 'the_excerpt', |
|
| 711 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 712 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 713 | - ); |
|
| 714 | - remove_filter( |
|
| 715 | - 'the_excerpt', |
|
| 716 | - array('EED_Events_Archive', 'event_venues'), |
|
| 717 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 718 | - ); |
|
| 719 | - remove_filter( |
|
| 720 | - 'the_content', |
|
| 721 | - array('EED_Events_Archive', 'event_details'), |
|
| 722 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 723 | - ); |
|
| 724 | - remove_filter( |
|
| 725 | - 'the_content', |
|
| 726 | - array('EED_Events_Archive', 'event_datetimes'), |
|
| 727 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 728 | - ); |
|
| 729 | - remove_filter( |
|
| 730 | - 'the_content', |
|
| 731 | - array('EED_Events_Archive', 'event_tickets'), |
|
| 732 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 733 | - ); |
|
| 734 | - remove_filter( |
|
| 735 | - 'the_content', |
|
| 736 | - array('EED_Events_Archive', 'event_venues'), |
|
| 737 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 738 | - ); |
|
| 739 | - // don't display entry meta because the existing theme will take care of that |
|
| 740 | - remove_filter( |
|
| 741 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
| 742 | - '__return_false' |
|
| 743 | - ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * load_event_list_assets |
|
| 749 | - * |
|
| 750 | - * @access public |
|
| 751 | - * @return void |
|
| 752 | - */ |
|
| 753 | - public function load_event_list_assets() |
|
| 754 | - { |
|
| 755 | - do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
| 756 | - add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 757 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 758 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 759 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 760 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * wp_enqueue_scripts |
|
| 767 | - * |
|
| 768 | - * @access public |
|
| 769 | - * @return void |
|
| 770 | - */ |
|
| 771 | - public function wp_enqueue_scripts() |
|
| 772 | - { |
|
| 773 | - // get some style |
|
| 774 | - if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
| 775 | - // first check uploads folder |
|
| 776 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
| 777 | - wp_register_style( |
|
| 778 | - $this->theme, |
|
| 779 | - get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', |
|
| 780 | - array('dashicons', 'espresso_default') |
|
| 781 | - ); |
|
| 782 | - } else { |
|
| 783 | - } |
|
| 784 | - wp_enqueue_style($this->theme); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * template_settings_form |
|
| 791 | - * |
|
| 792 | - * @access public |
|
| 793 | - * @static |
|
| 794 | - * @return string |
|
| 795 | - */ |
|
| 796 | - public static function template_settings_form() |
|
| 797 | - { |
|
| 798 | - $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
| 799 | - $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
| 800 | - ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
| 801 | - $template_settings->EED_Events_Archive = apply_filters( |
|
| 802 | - 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
| 803 | - $template_settings->EED_Events_Archive |
|
| 804 | - ); |
|
| 805 | - $events_archive_settings = array( |
|
| 806 | - 'display_status_banner' => 0, |
|
| 807 | - 'display_description' => 1, |
|
| 808 | - 'display_ticket_selector' => 0, |
|
| 809 | - 'display_datetimes' => 1, |
|
| 810 | - 'display_venue' => 0, |
|
| 811 | - 'display_expired_events' => 0, |
|
| 812 | - ); |
|
| 813 | - $events_archive_settings = array_merge( |
|
| 814 | - $events_archive_settings, |
|
| 815 | - (array) $template_settings->EED_Events_Archive |
|
| 816 | - ); |
|
| 817 | - EEH_Template::display_template( |
|
| 818 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
| 819 | - $events_archive_settings |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * update_template_settings |
|
| 826 | - * |
|
| 827 | - * @access public |
|
| 828 | - * @param EE_Template_Config $CFG |
|
| 829 | - * @param EE_Request_Handler $REQ |
|
| 830 | - * @return EE_Template_Config |
|
| 831 | - */ |
|
| 832 | - public static function update_template_settings($CFG, $REQ) |
|
| 833 | - { |
|
| 834 | - $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
| 835 | - // unless we are resetting the config... |
|
| 836 | - if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 837 | - || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
| 838 | - ) { |
|
| 839 | - $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
| 840 | - ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
| 841 | - $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
| 842 | - ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
| 843 | - $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
| 844 | - ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
| 845 | - $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
| 846 | - $REQ['EED_Events_Archive_display_datetimes'] |
|
| 847 | - ) : 1; |
|
| 848 | - $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
| 849 | - $REQ['EED_Events_Archive_display_venue'] |
|
| 850 | - ) : 0; |
|
| 851 | - $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
| 852 | - ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
| 853 | - } |
|
| 854 | - return $CFG; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - |
|
| 858 | - /** |
|
| 859 | - * event_list_css |
|
| 860 | - * |
|
| 861 | - * @access public |
|
| 862 | - * @param string $extra_class |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - public static function event_list_css($extra_class = '') |
|
| 866 | - { |
|
| 867 | - $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 868 | - $event_list_css[] = 'espresso-event-list-event'; |
|
| 869 | - return implode(' ', $event_list_css); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * event_categories |
|
| 875 | - * |
|
| 876 | - * @access public |
|
| 877 | - * @return array |
|
| 878 | - */ |
|
| 879 | - public static function event_categories() |
|
| 880 | - { |
|
| 881 | - return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * display_description |
|
| 887 | - * |
|
| 888 | - * @access public |
|
| 889 | - * @param $value |
|
| 890 | - * @return bool |
|
| 891 | - */ |
|
| 892 | - public static function display_description($value) |
|
| 893 | - { |
|
| 894 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 895 | - $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
| 896 | - return $display_description === $value ? true : false; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * display_ticket_selector |
|
| 902 | - * |
|
| 903 | - * @access public |
|
| 904 | - * @return bool |
|
| 905 | - */ |
|
| 906 | - public static function display_ticket_selector() |
|
| 907 | - { |
|
| 908 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 909 | - return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * display_venue |
|
| 915 | - * |
|
| 916 | - * @access public |
|
| 917 | - * @return bool |
|
| 918 | - */ |
|
| 919 | - public static function display_venue() |
|
| 920 | - { |
|
| 921 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 922 | - return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * display_datetimes |
|
| 928 | - * |
|
| 929 | - * @access public |
|
| 930 | - * @return bool |
|
| 931 | - */ |
|
| 932 | - public static function display_datetimes() |
|
| 933 | - { |
|
| 934 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 935 | - return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * event_list_title |
|
| 941 | - * |
|
| 942 | - * @access public |
|
| 943 | - * @return string |
|
| 944 | - */ |
|
| 945 | - public static function event_list_title() |
|
| 946 | - { |
|
| 947 | - return apply_filters( |
|
| 948 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
| 949 | - __('Upcoming Events', 'event_espresso') |
|
| 950 | - ); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - // GRAVEYARD |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * @since 4.4.0 |
|
| 959 | - */ |
|
| 960 | - public static function _doing_it_wrong_notice($function = '') |
|
| 961 | - { |
|
| 962 | - EE_Error::doing_it_wrong( |
|
| 963 | - __FUNCTION__, |
|
| 964 | - sprintf( |
|
| 965 | - __( |
|
| 966 | - 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', |
|
| 967 | - 'event_espresso' |
|
| 968 | - ), |
|
| 969 | - $function, |
|
| 970 | - '<br />', |
|
| 971 | - '4.6.0' |
|
| 972 | - ), |
|
| 973 | - '4.4.0' |
|
| 974 | - ); |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * @deprecated |
|
| 980 | - * @since 4.4.0 |
|
| 981 | - */ |
|
| 982 | - public function get_post_data() |
|
| 983 | - { |
|
| 984 | - EEH_Event_Query::set_query_params(); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * @deprecated |
|
| 990 | - * @since 4.4.0 |
|
| 991 | - */ |
|
| 992 | - public function posts_fields($SQL, WP_Query $wp_query) |
|
| 993 | - { |
|
| 994 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 995 | - return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * @deprecated |
|
| 1001 | - * @since 4.4.0 |
|
| 1002 | - */ |
|
| 1003 | - public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
| 1004 | - { |
|
| 1005 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1006 | - return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * @deprecated |
|
| 1012 | - * @since 4.4.0 |
|
| 1013 | - */ |
|
| 1014 | - public function posts_join($SQL, WP_Query $wp_query) |
|
| 1015 | - { |
|
| 1016 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1017 | - return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * @deprecated |
|
| 1023 | - * @since 4.4.0 |
|
| 1024 | - */ |
|
| 1025 | - public static function posts_join_sql_for_terms($join_terms = null) |
|
| 1026 | - { |
|
| 1027 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1028 | - return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * @deprecated |
|
| 1034 | - * @since 4.4.0 |
|
| 1035 | - */ |
|
| 1036 | - public static function posts_join_for_orderby($orderby_params = array()) |
|
| 1037 | - { |
|
| 1038 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1039 | - return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * @deprecated |
|
| 1045 | - * @since 4.4.0 |
|
| 1046 | - */ |
|
| 1047 | - public function posts_where($SQL, WP_Query $wp_query) |
|
| 1048 | - { |
|
| 1049 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1050 | - return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * @deprecated |
|
| 1056 | - * @since 4.4.0 |
|
| 1057 | - */ |
|
| 1058 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
| 1059 | - { |
|
| 1060 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1061 | - return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * @deprecated |
|
| 1067 | - * @since 4.4.0 |
|
| 1068 | - */ |
|
| 1069 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
| 1070 | - { |
|
| 1071 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1072 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * @deprecated |
|
| 1078 | - * @since 4.4.0 |
|
| 1079 | - */ |
|
| 1080 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
| 1081 | - { |
|
| 1082 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1083 | - return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * @deprecated |
|
| 1089 | - * @since 4.4.0 |
|
| 1090 | - */ |
|
| 1091 | - public function posts_orderby($SQL, WP_Query $wp_query) |
|
| 1092 | - { |
|
| 1093 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1094 | - return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * @deprecated |
|
| 1100 | - * @since 4.4.0 |
|
| 1101 | - */ |
|
| 1102 | - public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
| 1103 | - { |
|
| 1104 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1105 | - return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
| 1106 | - } |
|
| 19 | + const EVENT_DETAILS_PRIORITY = 100; |
|
| 20 | + |
|
| 21 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
| 22 | + |
|
| 23 | + const EVENT_TICKETS_PRIORITY = 120; |
|
| 24 | + |
|
| 25 | + const EVENT_VENUES_PRIORITY = 130; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + public static $espresso_event_list_ID = 0; |
|
| 29 | + |
|
| 30 | + public static $espresso_grid_event_lists = array(); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type bool $using_get_the_excerpt |
|
| 34 | + */ |
|
| 35 | + protected static $using_get_the_excerpt = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Used to flag when the event list is being called from an external iframe. |
|
| 39 | + * |
|
| 40 | + * @var bool $iframe |
|
| 41 | + */ |
|
| 42 | + protected static $iframe = false; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
|
| 46 | + */ |
|
| 47 | + private static $_iframe_embed_button; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @type EE_Template_Part_Manager $template_parts |
|
| 51 | + */ |
|
| 52 | + protected $template_parts; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return EED_Events_Archive |
|
| 57 | + */ |
|
| 58 | + public static function instance() |
|
| 59 | + { |
|
| 60 | + return parent::get_instance(__CLASS__); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 66 | + * |
|
| 67 | + * @return void |
|
| 68 | + * @throws InvalidArgumentException |
|
| 69 | + * @throws InvalidDataTypeException |
|
| 70 | + * @throws InvalidInterfaceException |
|
| 71 | + */ |
|
| 72 | + public static function set_hooks() |
|
| 73 | + { |
|
| 74 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
| 75 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
| 76 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
| 77 | + ); |
|
| 78 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
| 79 | + EE_Config::register_route( |
|
| 80 | + $custom_post_types['espresso_events']['plural_slug'], |
|
| 81 | + 'Events_Archive', |
|
| 82 | + 'run' |
|
| 83 | + ); |
|
| 84 | + EE_Config::register_route( |
|
| 85 | + 'event_list', |
|
| 86 | + 'Events_Archive', |
|
| 87 | + 'event_list' |
|
| 88 | + ); |
|
| 89 | + EE_Config::register_route( |
|
| 90 | + 'iframe', |
|
| 91 | + 'Events_Archive', |
|
| 92 | + 'event_list_iframe', |
|
| 93 | + 'event_list' |
|
| 94 | + ); |
|
| 95 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 101 | + * |
|
| 102 | + * @access public |
|
| 103 | + * @return void |
|
| 104 | + */ |
|
| 105 | + public static function set_hooks_admin() |
|
| 106 | + { |
|
| 107 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
| 108 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
| 109 | + // to load assets for "espresso_events" page on the "default" route (action) |
|
| 110 | + add_action( |
|
| 111 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
| 112 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
| 113 | + 10 |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * set_definitions |
|
| 120 | + * |
|
| 121 | + * @access public |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public static function set_definitions() |
|
| 125 | + { |
|
| 126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * set up EE_Events_Archive_Config |
|
| 133 | + */ |
|
| 134 | + protected function set_config() |
|
| 135 | + { |
|
| 136 | + $this->set_config_section('template_settings'); |
|
| 137 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
| 138 | + $this->set_config_name('EED_Events_Archive'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return EventListIframeEmbedButton |
|
| 144 | + */ |
|
| 145 | + public static function get_iframe_embed_button() |
|
| 146 | + { |
|
| 147 | + if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | + self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
| 149 | + } |
|
| 150 | + return self::$_iframe_embed_button; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * event_list_iframe_embed_button |
|
| 156 | + * |
|
| 157 | + * @return void |
|
| 158 | + * @throws \EE_Error |
|
| 159 | + */ |
|
| 160 | + public static function event_list_iframe_embed_button() |
|
| 161 | + { |
|
| 162 | + $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button(); |
|
| 163 | + $iframe_embed_button->addEmbedButton(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * initialize_template_parts |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @param \EE_Events_Archive_Config $config |
|
| 172 | + * @return \EE_Template_Part_Manager |
|
| 173 | + */ |
|
| 174 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
| 175 | + { |
|
| 176 | + $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
| 177 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
| 178 | + $template_parts = new EE_Template_Part_Manager(); |
|
| 179 | + $template_parts->add_template_part( |
|
| 180 | + 'tickets', |
|
| 181 | + __('Ticket Selector', 'event_espresso'), |
|
| 182 | + 'content-espresso_events-tickets.php', |
|
| 183 | + $config->display_order_tickets |
|
| 184 | + ); |
|
| 185 | + $template_parts->add_template_part( |
|
| 186 | + 'datetimes', |
|
| 187 | + __('Dates and Times', 'event_espresso'), |
|
| 188 | + 'content-espresso_events-datetimes.php', |
|
| 189 | + $config->display_order_datetimes |
|
| 190 | + ); |
|
| 191 | + $template_parts->add_template_part( |
|
| 192 | + 'event', |
|
| 193 | + __('Event Description', 'event_espresso'), |
|
| 194 | + 'content-espresso_events-details.php', |
|
| 195 | + $config->display_order_event |
|
| 196 | + ); |
|
| 197 | + $template_parts->add_template_part( |
|
| 198 | + 'venue', |
|
| 199 | + __('Venue Information', 'event_espresso'), |
|
| 200 | + 'content-espresso_events-venues.php', |
|
| 201 | + $config->display_order_venue |
|
| 202 | + ); |
|
| 203 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
| 204 | + return $template_parts; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
| 210 | + * incoming request |
|
| 211 | + * |
|
| 212 | + * @access public |
|
| 213 | + * @param WP $WP |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public function run($WP) |
|
| 217 | + { |
|
| 218 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
| 219 | + // ensure valid EE_Events_Archive_Config() object exists |
|
| 220 | + $this->set_config(); |
|
| 221 | + /** @type EE_Events_Archive_Config $config */ |
|
| 222 | + $config = $this->config(); |
|
| 223 | + // load other required components |
|
| 224 | + $this->load_event_list_assets(); |
|
| 225 | + // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
| 226 | + // add query filters |
|
| 227 | + EEH_Event_Query::add_query_filters(); |
|
| 228 | + // set params that will get used by the filters |
|
| 229 | + EEH_Event_Query::set_query_params( |
|
| 230 | + '', // month |
|
| 231 | + '', // category |
|
| 232 | + $config->display_expired_events, // show_expired |
|
| 233 | + 'start_date', // orderby |
|
| 234 | + 'ASC' // sort |
|
| 235 | + ); |
|
| 236 | + // check what template is loaded |
|
| 237 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
| 243 | + * |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + public function event_list() |
|
| 247 | + { |
|
| 248 | + // ensure valid EE_Events_Archive_Config() object exists |
|
| 249 | + $this->set_config(); |
|
| 250 | + // load other required components |
|
| 251 | + $this->load_event_list_assets(); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @access public |
|
| 257 | + * @return void |
|
| 258 | + * @throws \EE_Error |
|
| 259 | + * @throws \DomainException |
|
| 260 | + */ |
|
| 261 | + public function event_list_iframe() |
|
| 262 | + { |
|
| 263 | + \EED_Events_Archive::$iframe = true; |
|
| 264 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
| 265 | + $event_list_iframe->display(); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @access public |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public static function is_iframe() |
|
| 274 | + { |
|
| 275 | + return \EED_Events_Archive::$iframe; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @access public |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public static function link_target() |
|
| 284 | + { |
|
| 285 | + return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * template_include |
|
| 291 | + * |
|
| 292 | + * @access public |
|
| 293 | + * @param string $template |
|
| 294 | + * @return string |
|
| 295 | + */ |
|
| 296 | + public function template_include($template = '') |
|
| 297 | + { |
|
| 298 | + // don't add content filter for dedicated EE child themes or private posts |
|
| 299 | + if (! EEH_Template::is_espresso_theme()) { |
|
| 300 | + /** @type EE_Events_Archive_Config $config */ |
|
| 301 | + $config = $this->config(); |
|
| 302 | + // add status banner ? |
|
| 303 | + if ($config->display_status_banner) { |
|
| 304 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
| 305 | + } |
|
| 306 | + // if NOT a custom template |
|
| 307 | + if (apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
| 308 | + || EE_Registry::instance() |
|
| 309 | + ->load_core('Front_Controller') |
|
| 310 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
| 311 | + ) { |
|
| 312 | + // don't display entry meta because the existing theme will take care of that |
|
| 313 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
| 314 | + // load functions.php file for the theme (loaded by WP if using child theme) |
|
| 315 | + EEH_Template::load_espresso_theme_functions(); |
|
| 316 | + // because we don't know if the theme is using the_excerpt() |
|
| 317 | + add_filter( |
|
| 318 | + 'the_excerpt', |
|
| 319 | + array('EED_Events_Archive', 'event_details'), |
|
| 320 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 321 | + ); |
|
| 322 | + // or the_content |
|
| 323 | + add_filter( |
|
| 324 | + 'the_content', |
|
| 325 | + array('EED_Events_Archive', 'event_details'), |
|
| 326 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 327 | + ); |
|
| 328 | + // and just in case they are running get_the_excerpt() which DESTROYS things |
|
| 329 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 330 | + // don't display entry meta because the existing theme will take care of that |
|
| 331 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + return $template; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
| 340 | + * on the_content() |
|
| 341 | + * |
|
| 342 | + * @access public |
|
| 343 | + * @param string $excerpt |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public static function get_the_excerpt($excerpt = '') |
|
| 347 | + { |
|
| 348 | + if (post_password_required()) { |
|
| 349 | + return $excerpt; |
|
| 350 | + } |
|
| 351 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
| 352 | + remove_filter( |
|
| 353 | + 'the_excerpt', |
|
| 354 | + array('EED_Events_Archive', 'event_details'), |
|
| 355 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 356 | + ); |
|
| 357 | + remove_filter( |
|
| 358 | + 'the_content', |
|
| 359 | + array('EED_Events_Archive', 'event_details'), |
|
| 360 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 361 | + ); |
|
| 362 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
| 363 | + } else { |
|
| 364 | + EED_Events_Archive::$using_get_the_excerpt = true; |
|
| 365 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
| 366 | + } |
|
| 367 | + return $excerpt; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * end_get_the_excerpt |
|
| 373 | + * |
|
| 374 | + * @access public |
|
| 375 | + * @param string $text |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public static function end_get_the_excerpt($text = '') |
|
| 379 | + { |
|
| 380 | + EED_Events_Archive::$using_get_the_excerpt = false; |
|
| 381 | + return $text; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * the_title |
|
| 387 | + * |
|
| 388 | + * @access public |
|
| 389 | + * @param string $title |
|
| 390 | + * @param string $id |
|
| 391 | + * @return string |
|
| 392 | + */ |
|
| 393 | + public static function the_title($title = '', $id = '') |
|
| 394 | + { |
|
| 395 | + global $post; |
|
| 396 | + if ($post instanceof WP_Post) { |
|
| 397 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 398 | + } |
|
| 399 | + return $title; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * event_details |
|
| 405 | + * |
|
| 406 | + * @access public |
|
| 407 | + * @param string $content |
|
| 408 | + * @return string |
|
| 409 | + */ |
|
| 410 | + public static function event_details($content) |
|
| 411 | + { |
|
| 412 | + global $post; |
|
| 413 | + static $current_post_ID = 0; |
|
| 414 | + if ($current_post_ID !== $post->ID |
|
| 415 | + && $post->post_type === 'espresso_events' |
|
| 416 | + && ! EED_Events_Archive::$using_get_the_excerpt |
|
| 417 | + && ! post_password_required() |
|
| 418 | + && ( |
|
| 419 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
| 420 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
| 421 | + ) |
|
| 422 | + ) { |
|
| 423 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
| 424 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
| 425 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
| 426 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
| 427 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
| 428 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
| 429 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
| 430 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
| 431 | + $content = \EED_Events_Archive::use_sortable_display_order(); |
|
| 432 | + } else { |
|
| 433 | + $content = \EED_Events_Archive::use_filterable_display_order(); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + return $content; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * use_sortable_display_order |
|
| 442 | + * |
|
| 443 | + * @access protected |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + protected static function use_sortable_display_order() |
|
| 447 | + { |
|
| 448 | + // no further password checks required atm |
|
| 449 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
| 450 | + // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
| 451 | + // (otherwise it will recurse and blow up the interweb) |
|
| 452 | + remove_filter( |
|
| 453 | + 'the_excerpt', |
|
| 454 | + array('EED_Events_Archive', 'event_details'), |
|
| 455 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 456 | + ); |
|
| 457 | + remove_filter( |
|
| 458 | + 'the_content', |
|
| 459 | + array('EED_Events_Archive', 'event_details'), |
|
| 460 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 461 | + ); |
|
| 462 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 463 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 464 | + EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
| 465 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 466 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
| 467 | + // re-add our main filters (or else the next event won't have them) |
|
| 468 | + add_filter( |
|
| 469 | + 'the_excerpt', |
|
| 470 | + array('EED_Events_Archive', 'event_details'), |
|
| 471 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 472 | + ); |
|
| 473 | + add_filter( |
|
| 474 | + 'the_content', |
|
| 475 | + array('EED_Events_Archive', 'event_details'), |
|
| 476 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 477 | + ); |
|
| 478 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 479 | + remove_filter( |
|
| 480 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
| 481 | + '__return_true' |
|
| 482 | + ); |
|
| 483 | + return $content; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * use_filterable_display_order |
|
| 489 | + * |
|
| 490 | + * @access protected |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + protected static function use_filterable_display_order() |
|
| 494 | + { |
|
| 495 | + // we need to first remove this callback from being applied to the_content() |
|
| 496 | + // (otherwise it will recurse and blow up the interweb) |
|
| 497 | + remove_filter( |
|
| 498 | + 'the_excerpt', |
|
| 499 | + array('EED_Events_Archive', 'event_details'), |
|
| 500 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 501 | + ); |
|
| 502 | + remove_filter( |
|
| 503 | + 'the_content', |
|
| 504 | + array('EED_Events_Archive', 'event_details'), |
|
| 505 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 506 | + ); |
|
| 507 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
| 508 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
| 509 | + EED_Events_Archive::_add_additional_excerpt_filters(); |
|
| 510 | + EED_Events_Archive::_add_additional_content_filters(); |
|
| 511 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
| 512 | + // now load our template |
|
| 513 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
| 514 | + // re-add our main filters (or else the next event won't have them) |
|
| 515 | + add_filter( |
|
| 516 | + 'the_excerpt', |
|
| 517 | + array('EED_Events_Archive', 'event_details'), |
|
| 518 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 519 | + ); |
|
| 520 | + add_filter( |
|
| 521 | + 'the_content', |
|
| 522 | + array('EED_Events_Archive', 'event_details'), |
|
| 523 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 524 | + ); |
|
| 525 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
| 526 | + // but remove the other filters so that they don't get applied to the next post |
|
| 527 | + EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
| 528 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
| 529 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
| 530 | + // return ! empty( $template ) ? $template : $content; |
|
| 531 | + return $content; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * event_datetimes - adds datetimes ABOVE content |
|
| 537 | + * |
|
| 538 | + * @access public |
|
| 539 | + * @param string $content |
|
| 540 | + * @return string |
|
| 541 | + */ |
|
| 542 | + public static function event_datetimes($content) |
|
| 543 | + { |
|
| 544 | + if (post_password_required()) { |
|
| 545 | + return $content; |
|
| 546 | + } |
|
| 547 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
| 553 | + * |
|
| 554 | + * @access public |
|
| 555 | + * @param string $content |
|
| 556 | + * @return string |
|
| 557 | + */ |
|
| 558 | + public static function event_tickets($content) |
|
| 559 | + { |
|
| 560 | + if (post_password_required()) { |
|
| 561 | + return $content; |
|
| 562 | + } |
|
| 563 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * event_venues - adds venues BELOW content |
|
| 569 | + * |
|
| 570 | + * @access public |
|
| 571 | + * @param string $content |
|
| 572 | + * @return string |
|
| 573 | + */ |
|
| 574 | + public static function event_venue($content) |
|
| 575 | + { |
|
| 576 | + return EED_Events_Archive::event_venues($content); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * event_venues - adds venues BELOW content |
|
| 582 | + * |
|
| 583 | + * @access public |
|
| 584 | + * @param string $content |
|
| 585 | + * @return string |
|
| 586 | + */ |
|
| 587 | + public static function event_venues($content) |
|
| 588 | + { |
|
| 589 | + if (post_password_required()) { |
|
| 590 | + return $content; |
|
| 591 | + } |
|
| 592 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * _add_additional_content_filters |
|
| 598 | + * |
|
| 599 | + * @access private |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + private static function _add_additional_excerpt_filters() |
|
| 603 | + { |
|
| 604 | + add_filter( |
|
| 605 | + 'the_excerpt', |
|
| 606 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 607 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 608 | + ); |
|
| 609 | + add_filter( |
|
| 610 | + 'the_excerpt', |
|
| 611 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 612 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 613 | + ); |
|
| 614 | + add_filter( |
|
| 615 | + 'the_excerpt', |
|
| 616 | + array('EED_Events_Archive', 'event_venues'), |
|
| 617 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * _add_additional_content_filters |
|
| 624 | + * |
|
| 625 | + * @access private |
|
| 626 | + * @return void |
|
| 627 | + */ |
|
| 628 | + private static function _add_additional_content_filters() |
|
| 629 | + { |
|
| 630 | + add_filter( |
|
| 631 | + 'the_content', |
|
| 632 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 633 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 634 | + ); |
|
| 635 | + add_filter( |
|
| 636 | + 'the_content', |
|
| 637 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 638 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 639 | + ); |
|
| 640 | + add_filter( |
|
| 641 | + 'the_content', |
|
| 642 | + array('EED_Events_Archive', 'event_venues'), |
|
| 643 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * _remove_additional_events_archive_filters |
|
| 650 | + * |
|
| 651 | + * @access private |
|
| 652 | + * @return void |
|
| 653 | + */ |
|
| 654 | + private static function _remove_additional_events_archive_filters() |
|
| 655 | + { |
|
| 656 | + remove_filter( |
|
| 657 | + 'the_excerpt', |
|
| 658 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 659 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 660 | + ); |
|
| 661 | + remove_filter( |
|
| 662 | + 'the_excerpt', |
|
| 663 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 664 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 665 | + ); |
|
| 666 | + remove_filter( |
|
| 667 | + 'the_excerpt', |
|
| 668 | + array('EED_Events_Archive', 'event_venues'), |
|
| 669 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 670 | + ); |
|
| 671 | + remove_filter( |
|
| 672 | + 'the_content', |
|
| 673 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 674 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 675 | + ); |
|
| 676 | + remove_filter( |
|
| 677 | + 'the_content', |
|
| 678 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 679 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 680 | + ); |
|
| 681 | + remove_filter( |
|
| 682 | + 'the_content', |
|
| 683 | + array('EED_Events_Archive', 'event_venues'), |
|
| 684 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * remove_all_events_archive_filters |
|
| 691 | + * |
|
| 692 | + * @access public |
|
| 693 | + * @return void |
|
| 694 | + */ |
|
| 695 | + public static function remove_all_events_archive_filters() |
|
| 696 | + { |
|
| 697 | + // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
| 698 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
| 699 | + remove_filter( |
|
| 700 | + 'the_excerpt', |
|
| 701 | + array('EED_Events_Archive', 'event_details'), |
|
| 702 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 703 | + ); |
|
| 704 | + remove_filter( |
|
| 705 | + 'the_excerpt', |
|
| 706 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 707 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 708 | + ); |
|
| 709 | + remove_filter( |
|
| 710 | + 'the_excerpt', |
|
| 711 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 712 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 713 | + ); |
|
| 714 | + remove_filter( |
|
| 715 | + 'the_excerpt', |
|
| 716 | + array('EED_Events_Archive', 'event_venues'), |
|
| 717 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 718 | + ); |
|
| 719 | + remove_filter( |
|
| 720 | + 'the_content', |
|
| 721 | + array('EED_Events_Archive', 'event_details'), |
|
| 722 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
| 723 | + ); |
|
| 724 | + remove_filter( |
|
| 725 | + 'the_content', |
|
| 726 | + array('EED_Events_Archive', 'event_datetimes'), |
|
| 727 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
| 728 | + ); |
|
| 729 | + remove_filter( |
|
| 730 | + 'the_content', |
|
| 731 | + array('EED_Events_Archive', 'event_tickets'), |
|
| 732 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
| 733 | + ); |
|
| 734 | + remove_filter( |
|
| 735 | + 'the_content', |
|
| 736 | + array('EED_Events_Archive', 'event_venues'), |
|
| 737 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
| 738 | + ); |
|
| 739 | + // don't display entry meta because the existing theme will take care of that |
|
| 740 | + remove_filter( |
|
| 741 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
| 742 | + '__return_false' |
|
| 743 | + ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * load_event_list_assets |
|
| 749 | + * |
|
| 750 | + * @access public |
|
| 751 | + * @return void |
|
| 752 | + */ |
|
| 753 | + public function load_event_list_assets() |
|
| 754 | + { |
|
| 755 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
| 756 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 757 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 758 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 759 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 760 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * wp_enqueue_scripts |
|
| 767 | + * |
|
| 768 | + * @access public |
|
| 769 | + * @return void |
|
| 770 | + */ |
|
| 771 | + public function wp_enqueue_scripts() |
|
| 772 | + { |
|
| 773 | + // get some style |
|
| 774 | + if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
| 775 | + // first check uploads folder |
|
| 776 | + if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
| 777 | + wp_register_style( |
|
| 778 | + $this->theme, |
|
| 779 | + get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', |
|
| 780 | + array('dashicons', 'espresso_default') |
|
| 781 | + ); |
|
| 782 | + } else { |
|
| 783 | + } |
|
| 784 | + wp_enqueue_style($this->theme); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * template_settings_form |
|
| 791 | + * |
|
| 792 | + * @access public |
|
| 793 | + * @static |
|
| 794 | + * @return string |
|
| 795 | + */ |
|
| 796 | + public static function template_settings_form() |
|
| 797 | + { |
|
| 798 | + $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
| 799 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
| 800 | + ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
| 801 | + $template_settings->EED_Events_Archive = apply_filters( |
|
| 802 | + 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
| 803 | + $template_settings->EED_Events_Archive |
|
| 804 | + ); |
|
| 805 | + $events_archive_settings = array( |
|
| 806 | + 'display_status_banner' => 0, |
|
| 807 | + 'display_description' => 1, |
|
| 808 | + 'display_ticket_selector' => 0, |
|
| 809 | + 'display_datetimes' => 1, |
|
| 810 | + 'display_venue' => 0, |
|
| 811 | + 'display_expired_events' => 0, |
|
| 812 | + ); |
|
| 813 | + $events_archive_settings = array_merge( |
|
| 814 | + $events_archive_settings, |
|
| 815 | + (array) $template_settings->EED_Events_Archive |
|
| 816 | + ); |
|
| 817 | + EEH_Template::display_template( |
|
| 818 | + EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
| 819 | + $events_archive_settings |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * update_template_settings |
|
| 826 | + * |
|
| 827 | + * @access public |
|
| 828 | + * @param EE_Template_Config $CFG |
|
| 829 | + * @param EE_Request_Handler $REQ |
|
| 830 | + * @return EE_Template_Config |
|
| 831 | + */ |
|
| 832 | + public static function update_template_settings($CFG, $REQ) |
|
| 833 | + { |
|
| 834 | + $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
| 835 | + // unless we are resetting the config... |
|
| 836 | + if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 837 | + || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
| 838 | + ) { |
|
| 839 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
| 840 | + ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
| 841 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
| 842 | + ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
| 843 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
| 844 | + ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
| 845 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
| 846 | + $REQ['EED_Events_Archive_display_datetimes'] |
|
| 847 | + ) : 1; |
|
| 848 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
| 849 | + $REQ['EED_Events_Archive_display_venue'] |
|
| 850 | + ) : 0; |
|
| 851 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
| 852 | + ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
| 853 | + } |
|
| 854 | + return $CFG; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * event_list_css |
|
| 860 | + * |
|
| 861 | + * @access public |
|
| 862 | + * @param string $extra_class |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + public static function event_list_css($extra_class = '') |
|
| 866 | + { |
|
| 867 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 868 | + $event_list_css[] = 'espresso-event-list-event'; |
|
| 869 | + return implode(' ', $event_list_css); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * event_categories |
|
| 875 | + * |
|
| 876 | + * @access public |
|
| 877 | + * @return array |
|
| 878 | + */ |
|
| 879 | + public static function event_categories() |
|
| 880 | + { |
|
| 881 | + return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * display_description |
|
| 887 | + * |
|
| 888 | + * @access public |
|
| 889 | + * @param $value |
|
| 890 | + * @return bool |
|
| 891 | + */ |
|
| 892 | + public static function display_description($value) |
|
| 893 | + { |
|
| 894 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 895 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
| 896 | + return $display_description === $value ? true : false; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * display_ticket_selector |
|
| 902 | + * |
|
| 903 | + * @access public |
|
| 904 | + * @return bool |
|
| 905 | + */ |
|
| 906 | + public static function display_ticket_selector() |
|
| 907 | + { |
|
| 908 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 909 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * display_venue |
|
| 915 | + * |
|
| 916 | + * @access public |
|
| 917 | + * @return bool |
|
| 918 | + */ |
|
| 919 | + public static function display_venue() |
|
| 920 | + { |
|
| 921 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 922 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * display_datetimes |
|
| 928 | + * |
|
| 929 | + * @access public |
|
| 930 | + * @return bool |
|
| 931 | + */ |
|
| 932 | + public static function display_datetimes() |
|
| 933 | + { |
|
| 934 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
| 935 | + return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * event_list_title |
|
| 941 | + * |
|
| 942 | + * @access public |
|
| 943 | + * @return string |
|
| 944 | + */ |
|
| 945 | + public static function event_list_title() |
|
| 946 | + { |
|
| 947 | + return apply_filters( |
|
| 948 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
| 949 | + __('Upcoming Events', 'event_espresso') |
|
| 950 | + ); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + // GRAVEYARD |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * @since 4.4.0 |
|
| 959 | + */ |
|
| 960 | + public static function _doing_it_wrong_notice($function = '') |
|
| 961 | + { |
|
| 962 | + EE_Error::doing_it_wrong( |
|
| 963 | + __FUNCTION__, |
|
| 964 | + sprintf( |
|
| 965 | + __( |
|
| 966 | + 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', |
|
| 967 | + 'event_espresso' |
|
| 968 | + ), |
|
| 969 | + $function, |
|
| 970 | + '<br />', |
|
| 971 | + '4.6.0' |
|
| 972 | + ), |
|
| 973 | + '4.4.0' |
|
| 974 | + ); |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * @deprecated |
|
| 980 | + * @since 4.4.0 |
|
| 981 | + */ |
|
| 982 | + public function get_post_data() |
|
| 983 | + { |
|
| 984 | + EEH_Event_Query::set_query_params(); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * @deprecated |
|
| 990 | + * @since 4.4.0 |
|
| 991 | + */ |
|
| 992 | + public function posts_fields($SQL, WP_Query $wp_query) |
|
| 993 | + { |
|
| 994 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 995 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * @deprecated |
|
| 1001 | + * @since 4.4.0 |
|
| 1002 | + */ |
|
| 1003 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
| 1004 | + { |
|
| 1005 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1006 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * @deprecated |
|
| 1012 | + * @since 4.4.0 |
|
| 1013 | + */ |
|
| 1014 | + public function posts_join($SQL, WP_Query $wp_query) |
|
| 1015 | + { |
|
| 1016 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1017 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * @deprecated |
|
| 1023 | + * @since 4.4.0 |
|
| 1024 | + */ |
|
| 1025 | + public static function posts_join_sql_for_terms($join_terms = null) |
|
| 1026 | + { |
|
| 1027 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1028 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * @deprecated |
|
| 1034 | + * @since 4.4.0 |
|
| 1035 | + */ |
|
| 1036 | + public static function posts_join_for_orderby($orderby_params = array()) |
|
| 1037 | + { |
|
| 1038 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1039 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * @deprecated |
|
| 1045 | + * @since 4.4.0 |
|
| 1046 | + */ |
|
| 1047 | + public function posts_where($SQL, WP_Query $wp_query) |
|
| 1048 | + { |
|
| 1049 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1050 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * @deprecated |
|
| 1056 | + * @since 4.4.0 |
|
| 1057 | + */ |
|
| 1058 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
| 1059 | + { |
|
| 1060 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1061 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * @deprecated |
|
| 1067 | + * @since 4.4.0 |
|
| 1068 | + */ |
|
| 1069 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
| 1070 | + { |
|
| 1071 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1072 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * @deprecated |
|
| 1078 | + * @since 4.4.0 |
|
| 1079 | + */ |
|
| 1080 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
| 1081 | + { |
|
| 1082 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1083 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @deprecated |
|
| 1089 | + * @since 4.4.0 |
|
| 1090 | + */ |
|
| 1091 | + public function posts_orderby($SQL, WP_Query $wp_query) |
|
| 1092 | + { |
|
| 1093 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1094 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * @deprecated |
|
| 1100 | + * @since 4.4.0 |
|
| 1101 | + */ |
|
| 1102 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
| 1103 | + { |
|
| 1104 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
| 1105 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
| 1106 | + } |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | |
@@ -1112,9 +1112,9 @@ discard block |
||
| 1112 | 1112 | */ |
| 1113 | 1113 | function espresso_get_event_list_ID() |
| 1114 | 1114 | { |
| 1115 | - EED_Events_Archive::$espresso_event_list_ID++; |
|
| 1116 | - EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
| 1117 | - return EED_Events_Archive::$espresso_event_list_ID; |
|
| 1115 | + EED_Events_Archive::$espresso_event_list_ID++; |
|
| 1116 | + EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
| 1117 | + return EED_Events_Archive::$espresso_event_list_ID; |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | /** |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | */ |
| 1123 | 1123 | function espresso_event_list_title() |
| 1124 | 1124 | { |
| 1125 | - return EED_Events_Archive::event_list_title(); |
|
| 1125 | + return EED_Events_Archive::event_list_title(); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | /** |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | */ |
| 1132 | 1132 | function espresso_event_list_css($extra_class = '') |
| 1133 | 1133 | { |
| 1134 | - return EED_Events_Archive::event_list_css($extra_class); |
|
| 1134 | + return EED_Events_Archive::event_list_css($extra_class); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1139,7 +1139,7 @@ discard block |
||
| 1139 | 1139 | */ |
| 1140 | 1140 | function espresso_get_event_categories() |
| 1141 | 1141 | { |
| 1142 | - return EED_Events_Archive::event_categories(); |
|
| 1142 | + return EED_Events_Archive::event_categories(); |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1147,7 +1147,7 @@ discard block |
||
| 1147 | 1147 | */ |
| 1148 | 1148 | function espresso_display_full_description_in_event_list() |
| 1149 | 1149 | { |
| 1150 | - return EED_Events_Archive::display_description(2); |
|
| 1150 | + return EED_Events_Archive::display_description(2); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | */ |
| 1156 | 1156 | function espresso_display_excerpt_in_event_list() |
| 1157 | 1157 | { |
| 1158 | - return EED_Events_Archive::display_description(1); |
|
| 1158 | + return EED_Events_Archive::display_description(1); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1163,7 +1163,7 @@ discard block |
||
| 1163 | 1163 | */ |
| 1164 | 1164 | function espresso_display_ticket_selector_in_event_list() |
| 1165 | 1165 | { |
| 1166 | - return EED_Events_Archive::display_ticket_selector(); |
|
| 1166 | + return EED_Events_Archive::display_ticket_selector(); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | /** |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | */ |
| 1172 | 1172 | function espresso_display_venue_in_event_list() |
| 1173 | 1173 | { |
| 1174 | - return EED_Events_Archive::display_venue(); |
|
| 1174 | + return EED_Events_Archive::display_venue(); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | /** |
@@ -1179,5 +1179,5 @@ discard block |
||
| 1179 | 1179 | */ |
| 1180 | 1180 | function espresso_display_datetimes_in_event_list() |
| 1181 | 1181 | { |
| 1182 | - return EED_Events_Archive::display_datetimes(); |
|
| 1182 | + return EED_Events_Archive::display_datetimes(); |
|
| 1183 | 1183 | } |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public static function set_definitions() |
| 125 | 125 | { |
| 126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
| 127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public static function get_iframe_embed_button() |
| 146 | 146 | { |
| 147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 147 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
| 148 | 148 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
| 149 | 149 | } |
| 150 | 150 | return self::$_iframe_embed_button; |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | EEH_Event_Query::add_query_filters(); |
| 228 | 228 | // set params that will get used by the filters |
| 229 | 229 | EEH_Event_Query::set_query_params( |
| 230 | - '', // month |
|
| 231 | - '', // category |
|
| 232 | - $config->display_expired_events, // show_expired |
|
| 233 | - 'start_date', // orderby |
|
| 230 | + '', // month |
|
| 231 | + '', // category |
|
| 232 | + $config->display_expired_events, // show_expired |
|
| 233 | + 'start_date', // orderby |
|
| 234 | 234 | 'ASC' // sort |
| 235 | 235 | ); |
| 236 | 236 | // check what template is loaded |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | public function template_include($template = '') |
| 297 | 297 | { |
| 298 | 298 | // don't add content filter for dedicated EE child themes or private posts |
| 299 | - if (! EEH_Template::is_espresso_theme()) { |
|
| 299 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
| 300 | 300 | /** @type EE_Events_Archive_Config $config */ |
| 301 | 301 | $config = $this->config(); |
| 302 | 302 | // add status banner ? |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | { |
| 395 | 395 | global $post; |
| 396 | 396 | if ($post instanceof WP_Post) { |
| 397 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title; |
|
| 397 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title; |
|
| 398 | 398 | } |
| 399 | 399 | return $title; |
| 400 | 400 | } |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | if (post_password_required()) { |
| 545 | 545 | return $content; |
| 546 | 546 | } |
| 547 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
| 547 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | if (post_password_required()) { |
| 561 | 561 | return $content; |
| 562 | 562 | } |
| 563 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
| 563 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | if (post_password_required()) { |
| 590 | 590 | return $content; |
| 591 | 591 | } |
| 592 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 592 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | |
@@ -773,10 +773,10 @@ discard block |
||
| 773 | 773 | // get some style |
| 774 | 774 | if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
| 775 | 775 | // first check uploads folder |
| 776 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
| 776 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) { |
|
| 777 | 777 | wp_register_style( |
| 778 | 778 | $this->theme, |
| 779 | - get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', |
|
| 779 | + get_stylesheet_directory_uri().$this->theme.DS.'style.css', |
|
| 780 | 780 | array('dashicons', 'espresso_default') |
| 781 | 781 | ); |
| 782 | 782 | } else { |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | (array) $template_settings->EED_Events_Archive |
| 816 | 816 | ); |
| 817 | 817 | EEH_Template::display_template( |
| 818 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
| 818 | + EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', |
|
| 819 | 819 | $events_archive_settings |
| 820 | 820 | ); |
| 821 | 821 | } |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | { |
| 834 | 834 | $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
| 835 | 835 | // unless we are resetting the config... |
| 836 | - if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 836 | + if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
| 837 | 837 | || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
| 838 | 838 | ) { |
| 839 | 839 | $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
| 21 | 21 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
| 22 | 22 | * @param $string |
| 23 | - * @param $start |
|
| 24 | - * @param $length |
|
| 23 | + * @param integer $start |
|
| 24 | + * @param integer $length |
|
| 25 | 25 | * @return bool|string |
| 26 | 26 | */ |
| 27 | 27 | function mb_strcut($string, $start, $length = null) |
@@ -11,675 +11,675 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 13 | 13 | if (! function_exists('mb_strcut')) { |
| 14 | - /** |
|
| 15 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 16 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 17 | - * @param $string |
|
| 18 | - * @param $start |
|
| 19 | - * @param $length |
|
| 20 | - * @return bool|string |
|
| 21 | - */ |
|
| 22 | - function mb_strcut($string, $start, $length = null) |
|
| 23 | - { |
|
| 24 | - return mb_substr($string, $start, $length); |
|
| 25 | - } |
|
| 14 | + /** |
|
| 15 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 16 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 17 | + * @param $string |
|
| 18 | + * @param $start |
|
| 19 | + * @param $length |
|
| 20 | + * @return bool|string |
|
| 21 | + */ |
|
| 22 | + function mb_strcut($string, $start, $length = null) |
|
| 23 | + { |
|
| 24 | + return mb_substr($string, $start, $length); |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Merchant API Username. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $_api_username; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Merchant API Password. |
|
| 39 | - * |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $_api_password; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * API Signature. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $_api_signature; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Request Shipping address on PP checkout page. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $_request_shipping_addr; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Business/personal logo. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - protected $_image_url; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * gateway URL variable |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - protected $_base_gateway_url = ''; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * EEG_Paypal_Express constructor. |
|
| 76 | - */ |
|
| 77 | - public function __construct() |
|
| 78 | - { |
|
| 79 | - $this->_currencies_supported = array( |
|
| 80 | - 'USD', |
|
| 81 | - 'AUD', |
|
| 82 | - 'BRL', |
|
| 83 | - 'CAD', |
|
| 84 | - 'CZK', |
|
| 85 | - 'DKK', |
|
| 86 | - 'EUR', |
|
| 87 | - 'HKD', |
|
| 88 | - 'HUF', |
|
| 89 | - 'ILS', |
|
| 90 | - 'JPY', |
|
| 91 | - 'MYR', |
|
| 92 | - 'MXN', |
|
| 93 | - 'NOK', |
|
| 94 | - 'NZD', |
|
| 95 | - 'PHP', |
|
| 96 | - 'PLN', |
|
| 97 | - 'GBP', |
|
| 98 | - 'RUB', |
|
| 99 | - 'SGD', |
|
| 100 | - 'SEK', |
|
| 101 | - 'CHF', |
|
| 102 | - 'TWD', |
|
| 103 | - 'THB', |
|
| 104 | - 'TRY', |
|
| 105 | - ); |
|
| 106 | - parent::__construct(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 113 | - * |
|
| 114 | - * @param array $settings_array |
|
| 115 | - */ |
|
| 116 | - public function set_settings($settings_array) |
|
| 117 | - { |
|
| 118 | - parent::set_settings($settings_array); |
|
| 119 | - // Redirect URL. |
|
| 120 | - $this->_base_gateway_url = $this->_debug_mode |
|
| 121 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 122 | - : 'https://api-3t.paypal.com/nvp'; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param EEI_Payment $payment |
|
| 129 | - * @param array $billing_info |
|
| 130 | - * @param string $return_url |
|
| 131 | - * @param string $notify_url |
|
| 132 | - * @param string $cancel_url |
|
| 133 | - * @return \EE_Payment|\EEI_Payment |
|
| 134 | - * @throws \EE_Error |
|
| 135 | - */ |
|
| 136 | - public function set_redirection_info( |
|
| 137 | - $payment, |
|
| 138 | - $billing_info = array(), |
|
| 139 | - $return_url = null, |
|
| 140 | - $notify_url = null, |
|
| 141 | - $cancel_url = null |
|
| 142 | - ) { |
|
| 143 | - if (! $payment instanceof EEI_Payment) { |
|
| 144 | - $payment->set_gateway_response( |
|
| 145 | - esc_html__( |
|
| 146 | - 'Error. No associated payment was found.', |
|
| 147 | - 'event_espresso' |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 151 | - return $payment; |
|
| 152 | - } |
|
| 153 | - $transaction = $payment->transaction(); |
|
| 154 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 155 | - $payment->set_gateway_response( |
|
| 156 | - esc_html__( |
|
| 157 | - 'Could not process this payment because it has no associated transaction.', |
|
| 158 | - 'event_espresso' |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 162 | - return $payment; |
|
| 163 | - } |
|
| 164 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 165 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 166 | - $primary_registration = $transaction->primary_registration(); |
|
| 167 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 168 | - ? $primary_registration->attendee() |
|
| 169 | - : false; |
|
| 170 | - $locale = explode('-', get_bloginfo('language')); |
|
| 171 | - // Gather request parameters. |
|
| 172 | - $token_request_dtls = array( |
|
| 173 | - 'METHOD' => 'SetExpressCheckout', |
|
| 174 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 175 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 176 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 177 | - 'RETURNURL' => $return_url, |
|
| 178 | - 'CANCELURL' => $cancel_url, |
|
| 179 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 180 | - // Buyer does not need to create a PayPal account to check out. |
|
| 181 | - // This is referred to as PayPal Account Optional. |
|
| 182 | - 'SOLUTIONTYPE' => 'Sole', |
|
| 183 | - // EE will blow up if you change this |
|
| 184 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 185 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 186 | - 'LOCALECODE' => $locale[1] |
|
| 187 | - ); |
|
| 188 | - // Show itemized list. |
|
| 189 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 190 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 191 | - // Automatically filling out shipping and contact information. |
|
| 192 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 193 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 194 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 195 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 200 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 201 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 202 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 203 | - } elseif (! $this->_request_shipping_addr) { |
|
| 204 | - // Do not request shipping details on the PP Checkout page. |
|
| 205 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 206 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 207 | - } |
|
| 208 | - // Used a business/personal logo on the PayPal page. |
|
| 209 | - if (! empty($this->_image_url)) { |
|
| 210 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 211 | - } |
|
| 212 | - $token_request_dtls = apply_filters( |
|
| 213 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 214 | - $token_request_dtls, |
|
| 215 | - $this |
|
| 216 | - ); |
|
| 217 | - // Request PayPal token. |
|
| 218 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 219 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 220 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 221 | - ? $token_rstatus['args'] |
|
| 222 | - : array(); |
|
| 223 | - if ($token_rstatus['status']) { |
|
| 224 | - // We got the Token so we may continue with the payment and redirect the client. |
|
| 225 | - $payment->set_details($response_args); |
|
| 226 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 227 | - $payment->set_redirect_url( |
|
| 228 | - $gateway_url |
|
| 229 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 230 | - . $response_args['TOKEN'] |
|
| 231 | - ); |
|
| 232 | - } else { |
|
| 233 | - if (isset($response_args['L_ERRORCODE'])) { |
|
| 234 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 235 | - } else { |
|
| 236 | - $payment->set_gateway_response( |
|
| 237 | - esc_html__( |
|
| 238 | - 'Error occurred while trying to setup the Express Checkout.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - } |
|
| 243 | - $payment->set_details($response_args); |
|
| 244 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 245 | - } |
|
| 246 | - return $payment; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param array $update_info { |
|
| 253 | - * @type string $gateway_txn_id |
|
| 254 | - * @type string status an EEMI_Payment status |
|
| 255 | - * } |
|
| 256 | - * @param EEI_Transaction $transaction |
|
| 257 | - * @return EEI_Payment |
|
| 258 | - */ |
|
| 259 | - public function handle_payment_update($update_info, $transaction) |
|
| 260 | - { |
|
| 261 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 262 | - if ($payment instanceof EEI_Payment) { |
|
| 263 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 264 | - $transaction = $payment->transaction(); |
|
| 265 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 266 | - $payment->set_gateway_response( |
|
| 267 | - esc_html__( |
|
| 268 | - 'Could not process this payment because it has no associated transaction.', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ) |
|
| 271 | - ); |
|
| 272 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 273 | - return $payment; |
|
| 274 | - } |
|
| 275 | - $primary_registrant = $transaction->primary_registration(); |
|
| 276 | - $payment_details = $payment->details(); |
|
| 277 | - // Check if we still have the token. |
|
| 278 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 279 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 280 | - return $payment; |
|
| 281 | - } |
|
| 282 | - $cdetails_request_dtls = array( |
|
| 283 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 284 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 285 | - ); |
|
| 286 | - // Request Customer Details. |
|
| 287 | - $cdetails_request_response = $this->_ppExpress_request( |
|
| 288 | - $cdetails_request_dtls, |
|
| 289 | - 'Customer Details', |
|
| 290 | - $payment |
|
| 291 | - ); |
|
| 292 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 293 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 294 | - ? $cdetails_rstatus['args'] |
|
| 295 | - : array(); |
|
| 296 | - if ($cdetails_rstatus['status']) { |
|
| 297 | - // We got the PayerID so now we can Complete the transaction. |
|
| 298 | - $docheckout_request_dtls = array( |
|
| 299 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 300 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 301 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 302 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 303 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 304 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 305 | - // EE will blow up if you change this |
|
| 306 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 307 | - ); |
|
| 308 | - // Include itemized list. |
|
| 309 | - $itemized_list = $this->itemize_list( |
|
| 310 | - $payment, |
|
| 311 | - $transaction, |
|
| 312 | - $cdata_response_args |
|
| 313 | - ); |
|
| 314 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 315 | - // Payment Checkout/Capture. |
|
| 316 | - $docheckout_request_response = $this->_ppExpress_request( |
|
| 317 | - $docheckout_request_dtls, |
|
| 318 | - 'Do Payment', |
|
| 319 | - $payment |
|
| 320 | - ); |
|
| 321 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 322 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 323 | - ? $docheckout_rstatus['args'] |
|
| 324 | - : array(); |
|
| 325 | - if ($docheckout_rstatus['status']) { |
|
| 326 | - // All is well, payment approved. |
|
| 327 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 328 | - $primary_registrant->reg_code() |
|
| 329 | - : ''; |
|
| 330 | - $payment->set_extra_accntng($primary_registration_code); |
|
| 331 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 332 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 333 | - : 0); |
|
| 334 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 335 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 336 | - : null); |
|
| 337 | - $payment->set_details($cdata_response_args); |
|
| 338 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 339 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 340 | - : ''); |
|
| 341 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 342 | - } else { |
|
| 343 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 344 | - $payment->set_gateway_response( |
|
| 345 | - $docheckout_response_args['L_ERRORCODE'] |
|
| 346 | - . '; ' |
|
| 347 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 348 | - ); |
|
| 349 | - } else { |
|
| 350 | - $payment->set_gateway_response( |
|
| 351 | - esc_html__( |
|
| 352 | - 'Error occurred while trying to Capture the funds.', |
|
| 353 | - 'event_espresso' |
|
| 354 | - ) |
|
| 355 | - ); |
|
| 356 | - } |
|
| 357 | - $payment->set_details($docheckout_response_args); |
|
| 358 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 359 | - } |
|
| 360 | - } else { |
|
| 361 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 362 | - $payment->set_gateway_response( |
|
| 363 | - $cdata_response_args['L_ERRORCODE'] |
|
| 364 | - . '; ' |
|
| 365 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 366 | - ); |
|
| 367 | - } else { |
|
| 368 | - $payment->set_gateway_response( |
|
| 369 | - esc_html__( |
|
| 370 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
| 371 | - 'event_espresso' |
|
| 372 | - ) |
|
| 373 | - ); |
|
| 374 | - } |
|
| 375 | - $payment->set_details($cdata_response_args); |
|
| 376 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 377 | - } |
|
| 378 | - } else { |
|
| 379 | - $payment->set_gateway_response( |
|
| 380 | - esc_html__( |
|
| 381 | - 'Error occurred while trying to process the payment.', |
|
| 382 | - 'event_espresso' |
|
| 383 | - ) |
|
| 384 | - ); |
|
| 385 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 386 | - } |
|
| 387 | - return $payment; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Make a list of items that are in the giver transaction. |
|
| 394 | - * |
|
| 395 | - * @param EEI_Payment $payment |
|
| 396 | - * @param EEI_Transaction $transaction |
|
| 397 | - * @param array $request_response_args Data from a previous communication with PP. |
|
| 398 | - * @return array |
|
| 399 | - */ |
|
| 400 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 401 | - { |
|
| 402 | - $itemized_list = array(); |
|
| 403 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 404 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 405 | - if (! empty($request_response_args) |
|
| 406 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 407 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 408 | - ) { |
|
| 409 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 410 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 411 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
| 412 | - ) { |
|
| 413 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - // If we got only a few Items then something is not right. |
|
| 417 | - if (count($itemized_list) > 2) { |
|
| 418 | - return $itemized_list; |
|
| 419 | - } else { |
|
| 420 | - if (WP_DEBUG) { |
|
| 421 | - throw new EE_Error( |
|
| 422 | - sprintf( |
|
| 423 | - esc_html__( |
|
| 424 | - // @codingStandardsIgnoreStart |
|
| 425 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 426 | - // @codingStandardsIgnoreEnd |
|
| 427 | - 'event_espresso' |
|
| 428 | - ), |
|
| 429 | - wp_json_encode($itemized_list) |
|
| 430 | - ) |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 434 | - $itemized_list = array(); |
|
| 435 | - $this->log( |
|
| 436 | - array( |
|
| 437 | - esc_html__( |
|
| 438 | - 'Could not generate a proper item list with:', |
|
| 439 | - 'event_espresso' |
|
| 440 | - ) => $request_response_args |
|
| 441 | - ), |
|
| 442 | - $payment |
|
| 443 | - ); |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - // ...otherwise we generate a new list for this transaction. |
|
| 447 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 448 | - $item_num = 0; |
|
| 449 | - $itemized_sum = 0; |
|
| 450 | - $total_line_items = $transaction->total_line_item(); |
|
| 451 | - // Go through each item in the list. |
|
| 452 | - foreach ($total_line_items->get_items() as $line_item) { |
|
| 453 | - if ($line_item instanceof EE_Line_Item) { |
|
| 454 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 455 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 456 | - continue; |
|
| 457 | - } |
|
| 458 | - $unit_price = $line_item->unit_price(); |
|
| 459 | - $line_item_quantity = $line_item->quantity(); |
|
| 460 | - // This is a discount. |
|
| 461 | - if ($line_item->is_percent()) { |
|
| 462 | - $unit_price = $line_item->total(); |
|
| 463 | - $line_item_quantity = 1; |
|
| 464 | - } |
|
| 465 | - // Item Name. |
|
| 466 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 467 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 468 | - 0, |
|
| 469 | - 127 |
|
| 470 | - ); |
|
| 471 | - // Item description. |
|
| 472 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 473 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 474 | - 0, |
|
| 475 | - 127 |
|
| 476 | - ); |
|
| 477 | - // Cost of individual item. |
|
| 478 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 479 | - // Item Number. |
|
| 480 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 481 | - // Item quantity. |
|
| 482 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 483 | - // Digital item is sold. |
|
| 484 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 485 | - $itemized_sum += $line_item->total(); |
|
| 486 | - ++$item_num; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - // Item's sales S/H and tax amount. |
|
| 490 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 491 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 492 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 493 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 494 | - $itemized_sum_diff_from_txn_total = round( |
|
| 495 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 496 | - 2 |
|
| 497 | - ); |
|
| 498 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 499 | - // add the difference as an extra line item. |
|
| 500 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 501 | - // Item Name. |
|
| 502 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 503 | - esc_html__( |
|
| 504 | - 'Other (promotion/surcharge/cancellation)', |
|
| 505 | - 'event_espresso' |
|
| 506 | - ), |
|
| 507 | - 0, |
|
| 508 | - 127 |
|
| 509 | - ); |
|
| 510 | - // Item description. |
|
| 511 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 512 | - // Cost of individual item. |
|
| 513 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 514 | - $itemized_sum_diff_from_txn_total |
|
| 515 | - ); |
|
| 516 | - // Item Number. |
|
| 517 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 518 | - // Item quantity. |
|
| 519 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 520 | - // Digital item is sold. |
|
| 521 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 522 | - $item_num++; |
|
| 523 | - } |
|
| 524 | - } else { |
|
| 525 | - // Just one Item. |
|
| 526 | - // Item Name. |
|
| 527 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 528 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 529 | - 0, |
|
| 530 | - 127 |
|
| 531 | - ); |
|
| 532 | - // Item description. |
|
| 533 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 534 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 535 | - 0, |
|
| 536 | - 127 |
|
| 537 | - ); |
|
| 538 | - // Cost of individual item. |
|
| 539 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 540 | - // Item Number. |
|
| 541 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 542 | - // Item quantity. |
|
| 543 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 544 | - // Digital item is sold. |
|
| 545 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 546 | - // Item's sales S/H and tax amount. |
|
| 547 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 548 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 549 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 550 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 551 | - } |
|
| 552 | - return $itemized_list; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Make the Express checkout request. |
|
| 559 | - * |
|
| 560 | - * @param array $request_params |
|
| 561 | - * @param string $request_text |
|
| 562 | - * @param EEI_Payment $payment |
|
| 563 | - * @return mixed |
|
| 564 | - */ |
|
| 565 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 566 | - { |
|
| 567 | - $request_dtls = array( |
|
| 568 | - 'VERSION' => '204.0', |
|
| 569 | - 'USER' => urlencode($this->_api_username), |
|
| 570 | - 'PWD' => urlencode($this->_api_password), |
|
| 571 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 572 | - ); |
|
| 573 | - $dtls = array_merge($request_dtls, $request_params); |
|
| 574 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 575 | - // Request Customer Details. |
|
| 576 | - $request_response = wp_remote_post( |
|
| 577 | - $this->_base_gateway_url, |
|
| 578 | - array( |
|
| 579 | - 'method' => 'POST', |
|
| 580 | - 'timeout' => 45, |
|
| 581 | - 'httpversion' => '1.1', |
|
| 582 | - 'cookies' => array(), |
|
| 583 | - 'headers' => array(), |
|
| 584 | - 'body' => http_build_query($dtls, '', '&'), |
|
| 585 | - ) |
|
| 586 | - ); |
|
| 587 | - // Log the response. |
|
| 588 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 589 | - return $request_response; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Check the response status. |
|
| 596 | - * |
|
| 597 | - * @param mixed $request_response |
|
| 598 | - * @return array |
|
| 599 | - */ |
|
| 600 | - public function _ppExpress_check_response($request_response) |
|
| 601 | - { |
|
| 602 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 603 | - // If we got here then there was an error in this request. |
|
| 604 | - return array('status' => false, 'args' => $request_response); |
|
| 605 | - } |
|
| 606 | - $response_args = array(); |
|
| 607 | - parse_str(urldecode($request_response['body']), $response_args); |
|
| 608 | - if (! isset($response_args['ACK'])) { |
|
| 609 | - return array('status' => false, 'args' => $request_response); |
|
| 610 | - } |
|
| 611 | - if (( |
|
| 612 | - isset($response_args['PAYERID']) |
|
| 613 | - || isset($response_args['TOKEN']) |
|
| 614 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 615 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 616 | - ) |
|
| 617 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 618 | - ) { |
|
| 619 | - // Response status OK, return response parameters for further processing. |
|
| 620 | - return array('status' => true, 'args' => $response_args); |
|
| 621 | - } |
|
| 622 | - $errors = $this->_get_errors($response_args); |
|
| 623 | - return array('status' => false, 'args' => $errors); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * Log a "Cleared" request. |
|
| 630 | - * |
|
| 631 | - * @param array $request |
|
| 632 | - * @param EEI_Payment $payment |
|
| 633 | - * @param string $info |
|
| 634 | - * @return void |
|
| 635 | - */ |
|
| 636 | - private function _log_clean_request($request, $payment, $info) |
|
| 637 | - { |
|
| 638 | - $cleaned_request_data = $request; |
|
| 639 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 640 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Get error from the response data. |
|
| 647 | - * |
|
| 648 | - * @param array $data_array |
|
| 649 | - * @return array |
|
| 650 | - */ |
|
| 651 | - private function _get_errors($data_array) |
|
| 652 | - { |
|
| 653 | - $errors = array(); |
|
| 654 | - $n = 0; |
|
| 655 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 656 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 657 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 658 | - : ''; |
|
| 659 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 660 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 661 | - : ''; |
|
| 662 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 663 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 664 | - : ''; |
|
| 665 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 666 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 667 | - : ''; |
|
| 668 | - if ($n === 0) { |
|
| 669 | - $errors = array( |
|
| 670 | - 'L_ERRORCODE' => $l_error_code, |
|
| 671 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
| 672 | - 'L_LONGMESSAGE' => $l_long_message, |
|
| 673 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
| 674 | - ); |
|
| 675 | - } else { |
|
| 676 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 677 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 678 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 679 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 680 | - } |
|
| 681 | - $n++; |
|
| 682 | - } |
|
| 683 | - return $errors; |
|
| 684 | - } |
|
| 30 | + /** |
|
| 31 | + * Merchant API Username. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $_api_username; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Merchant API Password. |
|
| 39 | + * |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $_api_password; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * API Signature. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $_api_signature; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Request Shipping address on PP checkout page. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $_request_shipping_addr; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Business/personal logo. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + protected $_image_url; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * gateway URL variable |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + protected $_base_gateway_url = ''; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * EEG_Paypal_Express constructor. |
|
| 76 | + */ |
|
| 77 | + public function __construct() |
|
| 78 | + { |
|
| 79 | + $this->_currencies_supported = array( |
|
| 80 | + 'USD', |
|
| 81 | + 'AUD', |
|
| 82 | + 'BRL', |
|
| 83 | + 'CAD', |
|
| 84 | + 'CZK', |
|
| 85 | + 'DKK', |
|
| 86 | + 'EUR', |
|
| 87 | + 'HKD', |
|
| 88 | + 'HUF', |
|
| 89 | + 'ILS', |
|
| 90 | + 'JPY', |
|
| 91 | + 'MYR', |
|
| 92 | + 'MXN', |
|
| 93 | + 'NOK', |
|
| 94 | + 'NZD', |
|
| 95 | + 'PHP', |
|
| 96 | + 'PLN', |
|
| 97 | + 'GBP', |
|
| 98 | + 'RUB', |
|
| 99 | + 'SGD', |
|
| 100 | + 'SEK', |
|
| 101 | + 'CHF', |
|
| 102 | + 'TWD', |
|
| 103 | + 'THB', |
|
| 104 | + 'TRY', |
|
| 105 | + ); |
|
| 106 | + parent::__construct(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 113 | + * |
|
| 114 | + * @param array $settings_array |
|
| 115 | + */ |
|
| 116 | + public function set_settings($settings_array) |
|
| 117 | + { |
|
| 118 | + parent::set_settings($settings_array); |
|
| 119 | + // Redirect URL. |
|
| 120 | + $this->_base_gateway_url = $this->_debug_mode |
|
| 121 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 122 | + : 'https://api-3t.paypal.com/nvp'; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param EEI_Payment $payment |
|
| 129 | + * @param array $billing_info |
|
| 130 | + * @param string $return_url |
|
| 131 | + * @param string $notify_url |
|
| 132 | + * @param string $cancel_url |
|
| 133 | + * @return \EE_Payment|\EEI_Payment |
|
| 134 | + * @throws \EE_Error |
|
| 135 | + */ |
|
| 136 | + public function set_redirection_info( |
|
| 137 | + $payment, |
|
| 138 | + $billing_info = array(), |
|
| 139 | + $return_url = null, |
|
| 140 | + $notify_url = null, |
|
| 141 | + $cancel_url = null |
|
| 142 | + ) { |
|
| 143 | + if (! $payment instanceof EEI_Payment) { |
|
| 144 | + $payment->set_gateway_response( |
|
| 145 | + esc_html__( |
|
| 146 | + 'Error. No associated payment was found.', |
|
| 147 | + 'event_espresso' |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 151 | + return $payment; |
|
| 152 | + } |
|
| 153 | + $transaction = $payment->transaction(); |
|
| 154 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 155 | + $payment->set_gateway_response( |
|
| 156 | + esc_html__( |
|
| 157 | + 'Could not process this payment because it has no associated transaction.', |
|
| 158 | + 'event_espresso' |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 162 | + return $payment; |
|
| 163 | + } |
|
| 164 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 165 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 166 | + $primary_registration = $transaction->primary_registration(); |
|
| 167 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 168 | + ? $primary_registration->attendee() |
|
| 169 | + : false; |
|
| 170 | + $locale = explode('-', get_bloginfo('language')); |
|
| 171 | + // Gather request parameters. |
|
| 172 | + $token_request_dtls = array( |
|
| 173 | + 'METHOD' => 'SetExpressCheckout', |
|
| 174 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 175 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 176 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 177 | + 'RETURNURL' => $return_url, |
|
| 178 | + 'CANCELURL' => $cancel_url, |
|
| 179 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 180 | + // Buyer does not need to create a PayPal account to check out. |
|
| 181 | + // This is referred to as PayPal Account Optional. |
|
| 182 | + 'SOLUTIONTYPE' => 'Sole', |
|
| 183 | + // EE will blow up if you change this |
|
| 184 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 185 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 186 | + 'LOCALECODE' => $locale[1] |
|
| 187 | + ); |
|
| 188 | + // Show itemized list. |
|
| 189 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 190 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 191 | + // Automatically filling out shipping and contact information. |
|
| 192 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 193 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 194 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 195 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 200 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 201 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 202 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 203 | + } elseif (! $this->_request_shipping_addr) { |
|
| 204 | + // Do not request shipping details on the PP Checkout page. |
|
| 205 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 206 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 207 | + } |
|
| 208 | + // Used a business/personal logo on the PayPal page. |
|
| 209 | + if (! empty($this->_image_url)) { |
|
| 210 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 211 | + } |
|
| 212 | + $token_request_dtls = apply_filters( |
|
| 213 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 214 | + $token_request_dtls, |
|
| 215 | + $this |
|
| 216 | + ); |
|
| 217 | + // Request PayPal token. |
|
| 218 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 219 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 220 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 221 | + ? $token_rstatus['args'] |
|
| 222 | + : array(); |
|
| 223 | + if ($token_rstatus['status']) { |
|
| 224 | + // We got the Token so we may continue with the payment and redirect the client. |
|
| 225 | + $payment->set_details($response_args); |
|
| 226 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 227 | + $payment->set_redirect_url( |
|
| 228 | + $gateway_url |
|
| 229 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 230 | + . $response_args['TOKEN'] |
|
| 231 | + ); |
|
| 232 | + } else { |
|
| 233 | + if (isset($response_args['L_ERRORCODE'])) { |
|
| 234 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 235 | + } else { |
|
| 236 | + $payment->set_gateway_response( |
|
| 237 | + esc_html__( |
|
| 238 | + 'Error occurred while trying to setup the Express Checkout.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | + $payment->set_details($response_args); |
|
| 244 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 245 | + } |
|
| 246 | + return $payment; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param array $update_info { |
|
| 253 | + * @type string $gateway_txn_id |
|
| 254 | + * @type string status an EEMI_Payment status |
|
| 255 | + * } |
|
| 256 | + * @param EEI_Transaction $transaction |
|
| 257 | + * @return EEI_Payment |
|
| 258 | + */ |
|
| 259 | + public function handle_payment_update($update_info, $transaction) |
|
| 260 | + { |
|
| 261 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 262 | + if ($payment instanceof EEI_Payment) { |
|
| 263 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 264 | + $transaction = $payment->transaction(); |
|
| 265 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 266 | + $payment->set_gateway_response( |
|
| 267 | + esc_html__( |
|
| 268 | + 'Could not process this payment because it has no associated transaction.', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ) |
|
| 271 | + ); |
|
| 272 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 273 | + return $payment; |
|
| 274 | + } |
|
| 275 | + $primary_registrant = $transaction->primary_registration(); |
|
| 276 | + $payment_details = $payment->details(); |
|
| 277 | + // Check if we still have the token. |
|
| 278 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 279 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 280 | + return $payment; |
|
| 281 | + } |
|
| 282 | + $cdetails_request_dtls = array( |
|
| 283 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 284 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 285 | + ); |
|
| 286 | + // Request Customer Details. |
|
| 287 | + $cdetails_request_response = $this->_ppExpress_request( |
|
| 288 | + $cdetails_request_dtls, |
|
| 289 | + 'Customer Details', |
|
| 290 | + $payment |
|
| 291 | + ); |
|
| 292 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 293 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 294 | + ? $cdetails_rstatus['args'] |
|
| 295 | + : array(); |
|
| 296 | + if ($cdetails_rstatus['status']) { |
|
| 297 | + // We got the PayerID so now we can Complete the transaction. |
|
| 298 | + $docheckout_request_dtls = array( |
|
| 299 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 300 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 301 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 302 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 303 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 304 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 305 | + // EE will blow up if you change this |
|
| 306 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 307 | + ); |
|
| 308 | + // Include itemized list. |
|
| 309 | + $itemized_list = $this->itemize_list( |
|
| 310 | + $payment, |
|
| 311 | + $transaction, |
|
| 312 | + $cdata_response_args |
|
| 313 | + ); |
|
| 314 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 315 | + // Payment Checkout/Capture. |
|
| 316 | + $docheckout_request_response = $this->_ppExpress_request( |
|
| 317 | + $docheckout_request_dtls, |
|
| 318 | + 'Do Payment', |
|
| 319 | + $payment |
|
| 320 | + ); |
|
| 321 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 322 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 323 | + ? $docheckout_rstatus['args'] |
|
| 324 | + : array(); |
|
| 325 | + if ($docheckout_rstatus['status']) { |
|
| 326 | + // All is well, payment approved. |
|
| 327 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 328 | + $primary_registrant->reg_code() |
|
| 329 | + : ''; |
|
| 330 | + $payment->set_extra_accntng($primary_registration_code); |
|
| 331 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 332 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 333 | + : 0); |
|
| 334 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 335 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 336 | + : null); |
|
| 337 | + $payment->set_details($cdata_response_args); |
|
| 338 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 339 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 340 | + : ''); |
|
| 341 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 342 | + } else { |
|
| 343 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 344 | + $payment->set_gateway_response( |
|
| 345 | + $docheckout_response_args['L_ERRORCODE'] |
|
| 346 | + . '; ' |
|
| 347 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 348 | + ); |
|
| 349 | + } else { |
|
| 350 | + $payment->set_gateway_response( |
|
| 351 | + esc_html__( |
|
| 352 | + 'Error occurred while trying to Capture the funds.', |
|
| 353 | + 'event_espresso' |
|
| 354 | + ) |
|
| 355 | + ); |
|
| 356 | + } |
|
| 357 | + $payment->set_details($docheckout_response_args); |
|
| 358 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 359 | + } |
|
| 360 | + } else { |
|
| 361 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 362 | + $payment->set_gateway_response( |
|
| 363 | + $cdata_response_args['L_ERRORCODE'] |
|
| 364 | + . '; ' |
|
| 365 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 366 | + ); |
|
| 367 | + } else { |
|
| 368 | + $payment->set_gateway_response( |
|
| 369 | + esc_html__( |
|
| 370 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
| 371 | + 'event_espresso' |
|
| 372 | + ) |
|
| 373 | + ); |
|
| 374 | + } |
|
| 375 | + $payment->set_details($cdata_response_args); |
|
| 376 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 377 | + } |
|
| 378 | + } else { |
|
| 379 | + $payment->set_gateway_response( |
|
| 380 | + esc_html__( |
|
| 381 | + 'Error occurred while trying to process the payment.', |
|
| 382 | + 'event_espresso' |
|
| 383 | + ) |
|
| 384 | + ); |
|
| 385 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 386 | + } |
|
| 387 | + return $payment; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Make a list of items that are in the giver transaction. |
|
| 394 | + * |
|
| 395 | + * @param EEI_Payment $payment |
|
| 396 | + * @param EEI_Transaction $transaction |
|
| 397 | + * @param array $request_response_args Data from a previous communication with PP. |
|
| 398 | + * @return array |
|
| 399 | + */ |
|
| 400 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 401 | + { |
|
| 402 | + $itemized_list = array(); |
|
| 403 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 404 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 405 | + if (! empty($request_response_args) |
|
| 406 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 407 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 408 | + ) { |
|
| 409 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 410 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 411 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
| 412 | + ) { |
|
| 413 | + $itemized_list[ $arg_key ] = $arg_val; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + // If we got only a few Items then something is not right. |
|
| 417 | + if (count($itemized_list) > 2) { |
|
| 418 | + return $itemized_list; |
|
| 419 | + } else { |
|
| 420 | + if (WP_DEBUG) { |
|
| 421 | + throw new EE_Error( |
|
| 422 | + sprintf( |
|
| 423 | + esc_html__( |
|
| 424 | + // @codingStandardsIgnoreStart |
|
| 425 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 426 | + // @codingStandardsIgnoreEnd |
|
| 427 | + 'event_espresso' |
|
| 428 | + ), |
|
| 429 | + wp_json_encode($itemized_list) |
|
| 430 | + ) |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 434 | + $itemized_list = array(); |
|
| 435 | + $this->log( |
|
| 436 | + array( |
|
| 437 | + esc_html__( |
|
| 438 | + 'Could not generate a proper item list with:', |
|
| 439 | + 'event_espresso' |
|
| 440 | + ) => $request_response_args |
|
| 441 | + ), |
|
| 442 | + $payment |
|
| 443 | + ); |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + // ...otherwise we generate a new list for this transaction. |
|
| 447 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 448 | + $item_num = 0; |
|
| 449 | + $itemized_sum = 0; |
|
| 450 | + $total_line_items = $transaction->total_line_item(); |
|
| 451 | + // Go through each item in the list. |
|
| 452 | + foreach ($total_line_items->get_items() as $line_item) { |
|
| 453 | + if ($line_item instanceof EE_Line_Item) { |
|
| 454 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 455 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 456 | + continue; |
|
| 457 | + } |
|
| 458 | + $unit_price = $line_item->unit_price(); |
|
| 459 | + $line_item_quantity = $line_item->quantity(); |
|
| 460 | + // This is a discount. |
|
| 461 | + if ($line_item->is_percent()) { |
|
| 462 | + $unit_price = $line_item->total(); |
|
| 463 | + $line_item_quantity = 1; |
|
| 464 | + } |
|
| 465 | + // Item Name. |
|
| 466 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 467 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 468 | + 0, |
|
| 469 | + 127 |
|
| 470 | + ); |
|
| 471 | + // Item description. |
|
| 472 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 473 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 474 | + 0, |
|
| 475 | + 127 |
|
| 476 | + ); |
|
| 477 | + // Cost of individual item. |
|
| 478 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 479 | + // Item Number. |
|
| 480 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 481 | + // Item quantity. |
|
| 482 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 483 | + // Digital item is sold. |
|
| 484 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 485 | + $itemized_sum += $line_item->total(); |
|
| 486 | + ++$item_num; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + // Item's sales S/H and tax amount. |
|
| 490 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 491 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 492 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 493 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 494 | + $itemized_sum_diff_from_txn_total = round( |
|
| 495 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 496 | + 2 |
|
| 497 | + ); |
|
| 498 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 499 | + // add the difference as an extra line item. |
|
| 500 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 501 | + // Item Name. |
|
| 502 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 503 | + esc_html__( |
|
| 504 | + 'Other (promotion/surcharge/cancellation)', |
|
| 505 | + 'event_espresso' |
|
| 506 | + ), |
|
| 507 | + 0, |
|
| 508 | + 127 |
|
| 509 | + ); |
|
| 510 | + // Item description. |
|
| 511 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 512 | + // Cost of individual item. |
|
| 513 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 514 | + $itemized_sum_diff_from_txn_total |
|
| 515 | + ); |
|
| 516 | + // Item Number. |
|
| 517 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 518 | + // Item quantity. |
|
| 519 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 520 | + // Digital item is sold. |
|
| 521 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 522 | + $item_num++; |
|
| 523 | + } |
|
| 524 | + } else { |
|
| 525 | + // Just one Item. |
|
| 526 | + // Item Name. |
|
| 527 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 528 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 529 | + 0, |
|
| 530 | + 127 |
|
| 531 | + ); |
|
| 532 | + // Item description. |
|
| 533 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 534 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 535 | + 0, |
|
| 536 | + 127 |
|
| 537 | + ); |
|
| 538 | + // Cost of individual item. |
|
| 539 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 540 | + // Item Number. |
|
| 541 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 542 | + // Item quantity. |
|
| 543 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 544 | + // Digital item is sold. |
|
| 545 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 546 | + // Item's sales S/H and tax amount. |
|
| 547 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 548 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 549 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 550 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 551 | + } |
|
| 552 | + return $itemized_list; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Make the Express checkout request. |
|
| 559 | + * |
|
| 560 | + * @param array $request_params |
|
| 561 | + * @param string $request_text |
|
| 562 | + * @param EEI_Payment $payment |
|
| 563 | + * @return mixed |
|
| 564 | + */ |
|
| 565 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 566 | + { |
|
| 567 | + $request_dtls = array( |
|
| 568 | + 'VERSION' => '204.0', |
|
| 569 | + 'USER' => urlencode($this->_api_username), |
|
| 570 | + 'PWD' => urlencode($this->_api_password), |
|
| 571 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 572 | + ); |
|
| 573 | + $dtls = array_merge($request_dtls, $request_params); |
|
| 574 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 575 | + // Request Customer Details. |
|
| 576 | + $request_response = wp_remote_post( |
|
| 577 | + $this->_base_gateway_url, |
|
| 578 | + array( |
|
| 579 | + 'method' => 'POST', |
|
| 580 | + 'timeout' => 45, |
|
| 581 | + 'httpversion' => '1.1', |
|
| 582 | + 'cookies' => array(), |
|
| 583 | + 'headers' => array(), |
|
| 584 | + 'body' => http_build_query($dtls, '', '&'), |
|
| 585 | + ) |
|
| 586 | + ); |
|
| 587 | + // Log the response. |
|
| 588 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 589 | + return $request_response; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Check the response status. |
|
| 596 | + * |
|
| 597 | + * @param mixed $request_response |
|
| 598 | + * @return array |
|
| 599 | + */ |
|
| 600 | + public function _ppExpress_check_response($request_response) |
|
| 601 | + { |
|
| 602 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 603 | + // If we got here then there was an error in this request. |
|
| 604 | + return array('status' => false, 'args' => $request_response); |
|
| 605 | + } |
|
| 606 | + $response_args = array(); |
|
| 607 | + parse_str(urldecode($request_response['body']), $response_args); |
|
| 608 | + if (! isset($response_args['ACK'])) { |
|
| 609 | + return array('status' => false, 'args' => $request_response); |
|
| 610 | + } |
|
| 611 | + if (( |
|
| 612 | + isset($response_args['PAYERID']) |
|
| 613 | + || isset($response_args['TOKEN']) |
|
| 614 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 615 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 616 | + ) |
|
| 617 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 618 | + ) { |
|
| 619 | + // Response status OK, return response parameters for further processing. |
|
| 620 | + return array('status' => true, 'args' => $response_args); |
|
| 621 | + } |
|
| 622 | + $errors = $this->_get_errors($response_args); |
|
| 623 | + return array('status' => false, 'args' => $errors); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * Log a "Cleared" request. |
|
| 630 | + * |
|
| 631 | + * @param array $request |
|
| 632 | + * @param EEI_Payment $payment |
|
| 633 | + * @param string $info |
|
| 634 | + * @return void |
|
| 635 | + */ |
|
| 636 | + private function _log_clean_request($request, $payment, $info) |
|
| 637 | + { |
|
| 638 | + $cleaned_request_data = $request; |
|
| 639 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 640 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Get error from the response data. |
|
| 647 | + * |
|
| 648 | + * @param array $data_array |
|
| 649 | + * @return array |
|
| 650 | + */ |
|
| 651 | + private function _get_errors($data_array) |
|
| 652 | + { |
|
| 653 | + $errors = array(); |
|
| 654 | + $n = 0; |
|
| 655 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 656 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 657 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 658 | + : ''; |
|
| 659 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 660 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 661 | + : ''; |
|
| 662 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 663 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 664 | + : ''; |
|
| 665 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 666 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 667 | + : ''; |
|
| 668 | + if ($n === 0) { |
|
| 669 | + $errors = array( |
|
| 670 | + 'L_ERRORCODE' => $l_error_code, |
|
| 671 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
| 672 | + 'L_LONGMESSAGE' => $l_long_message, |
|
| 673 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
| 674 | + ); |
|
| 675 | + } else { |
|
| 676 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 677 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 678 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 679 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 680 | + } |
|
| 681 | + $n++; |
|
| 682 | + } |
|
| 683 | + return $errors; |
|
| 684 | + } |
|
| 685 | 685 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * ---------------------------------------------- |
| 11 | 11 | */ |
| 12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 13 | -if (! function_exists('mb_strcut')) { |
|
| 13 | +if ( ! function_exists('mb_strcut')) { |
|
| 14 | 14 | /** |
| 15 | 15 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
| 16 | 16 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $notify_url = null, |
| 141 | 141 | $cancel_url = null |
| 142 | 142 | ) { |
| 143 | - if (! $payment instanceof EEI_Payment) { |
|
| 143 | + if ( ! $payment instanceof EEI_Payment) { |
|
| 144 | 144 | $payment->set_gateway_response( |
| 145 | 145 | esc_html__( |
| 146 | 146 | 'Error. No associated payment was found.', |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | return $payment; |
| 152 | 152 | } |
| 153 | 153 | $transaction = $payment->transaction(); |
| 154 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 154 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
| 155 | 155 | $payment->set_gateway_response( |
| 156 | 156 | esc_html__( |
| 157 | 157 | 'Could not process this payment because it has no associated transaction.', |
@@ -200,13 +200,13 @@ discard block |
||
| 200 | 200 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
| 201 | 201 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
| 202 | 202 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
| 203 | - } elseif (! $this->_request_shipping_addr) { |
|
| 203 | + } elseif ( ! $this->_request_shipping_addr) { |
|
| 204 | 204 | // Do not request shipping details on the PP Checkout page. |
| 205 | 205 | $token_request_dtls['NOSHIPPING'] = '1'; |
| 206 | 206 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
| 207 | 207 | } |
| 208 | 208 | // Used a business/personal logo on the PayPal page. |
| 209 | - if (! empty($this->_image_url)) { |
|
| 209 | + if ( ! empty($this->_image_url)) { |
|
| 210 | 210 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
| 211 | 211 | } |
| 212 | 212 | $token_request_dtls = apply_filters( |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | ); |
| 232 | 232 | } else { |
| 233 | 233 | if (isset($response_args['L_ERRORCODE'])) { |
| 234 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
| 235 | 235 | } else { |
| 236 | 236 | $payment->set_gateway_response( |
| 237 | 237 | esc_html__( |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | if ($payment instanceof EEI_Payment) { |
| 263 | 263 | $this->log(array('Return from Authorization' => $update_info), $payment); |
| 264 | 264 | $transaction = $payment->transaction(); |
| 265 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
| 266 | 266 | $payment->set_gateway_response( |
| 267 | 267 | esc_html__( |
| 268 | 268 | 'Could not process this payment because it has no associated transaction.', |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | $primary_registrant = $transaction->primary_registration(); |
| 276 | 276 | $payment_details = $payment->details(); |
| 277 | 277 | // Check if we still have the token. |
| 278 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 279 | 279 | $payment->set_status($this->_pay_model->failed_status()); |
| 280 | 280 | return $payment; |
| 281 | 281 | } |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | $itemized_list = array(); |
| 403 | 403 | $gateway_formatter = $this->_get_gateway_formatter(); |
| 404 | 404 | // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
| 405 | - if (! empty($request_response_args) |
|
| 405 | + if ( ! empty($request_response_args) |
|
| 406 | 406 | && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
| 407 | 407 | && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
| 408 | 408 | ) { |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
| 411 | 411 | && strpos($arg_key, 'NOTIFYURL') === false |
| 412 | 412 | ) { |
| 413 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 413 | + $itemized_list[$arg_key] = $arg_val; |
|
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | // If we got only a few Items then something is not right. |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | $line_item_quantity = 1; |
| 464 | 464 | } |
| 465 | 465 | // Item Name. |
| 466 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 466 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
| 467 | 467 | $gateway_formatter->formatLineItemName($line_item, $payment), |
| 468 | 468 | 0, |
| 469 | 469 | 127 |
| 470 | 470 | ); |
| 471 | 471 | // Item description. |
| 472 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 472 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut( |
|
| 473 | 473 | $gateway_formatter->formatLineItemDesc($line_item, $payment), |
| 474 | 474 | 0, |
| 475 | 475 | 127 |
| 476 | 476 | ); |
| 477 | 477 | // Cost of individual item. |
| 478 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 478 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
| 479 | 479 | // Item Number. |
| 480 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 480 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
| 481 | 481 | // Item quantity. |
| 482 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 482 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
| 483 | 483 | // Digital item is sold. |
| 484 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 484 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
| 485 | 485 | $itemized_sum += $line_item->total(); |
| 486 | 486 | ++$item_num; |
| 487 | 487 | } |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | // add the difference as an extra line item. |
| 500 | 500 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
| 501 | 501 | // Item Name. |
| 502 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 502 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
| 503 | 503 | esc_html__( |
| 504 | 504 | 'Other (promotion/surcharge/cancellation)', |
| 505 | 505 | 'event_espresso' |
@@ -508,17 +508,17 @@ discard block |
||
| 508 | 508 | 127 |
| 509 | 509 | ); |
| 510 | 510 | // Item description. |
| 511 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 511 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
| 512 | 512 | // Cost of individual item. |
| 513 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 513 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
| 514 | 514 | $itemized_sum_diff_from_txn_total |
| 515 | 515 | ); |
| 516 | 516 | // Item Number. |
| 517 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 517 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
| 518 | 518 | // Item quantity. |
| 519 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 519 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
| 520 | 520 | // Digital item is sold. |
| 521 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 521 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
| 522 | 522 | $item_num++; |
| 523 | 523 | } |
| 524 | 524 | } else { |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | 'SIGNATURE' => urlencode($this->_api_signature), |
| 572 | 572 | ); |
| 573 | 573 | $dtls = array_merge($request_dtls, $request_params); |
| 574 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
| 575 | 575 | // Request Customer Details. |
| 576 | 576 | $request_response = wp_remote_post( |
| 577 | 577 | $this->_base_gateway_url, |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | ) |
| 586 | 586 | ); |
| 587 | 587 | // Log the response. |
| 588 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
| 589 | 589 | return $request_response; |
| 590 | 590 | } |
| 591 | 591 | |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | } |
| 606 | 606 | $response_args = array(); |
| 607 | 607 | parse_str(urldecode($request_response['body']), $response_args); |
| 608 | - if (! isset($response_args['ACK'])) { |
|
| 608 | + if ( ! isset($response_args['ACK'])) { |
|
| 609 | 609 | return array('status' => false, 'args' => $request_response); |
| 610 | 610 | } |
| 611 | 611 | if (( |
@@ -652,18 +652,18 @@ discard block |
||
| 652 | 652 | { |
| 653 | 653 | $errors = array(); |
| 654 | 654 | $n = 0; |
| 655 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 656 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 657 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 655 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
| 656 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
| 657 | + ? $data_array["L_ERRORCODE{$n}"] |
|
| 658 | 658 | : ''; |
| 659 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 660 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 659 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
| 660 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
| 661 | 661 | : ''; |
| 662 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 663 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 662 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
| 663 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
| 664 | 664 | : ''; |
| 665 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 666 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 665 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
| 666 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
| 667 | 667 | : ''; |
| 668 | 668 | if ($n === 0) { |
| 669 | 669 | $errors = array( |
@@ -673,10 +673,10 @@ discard block |
||
| 673 | 673 | 'L_SEVERITYCODE' => $l_severity_code, |
| 674 | 674 | ); |
| 675 | 675 | } else { |
| 676 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 677 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 678 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 679 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 676 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
| 677 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
| 678 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
| 679 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
| 680 | 680 | } |
| 681 | 681 | $n++; |
| 682 | 682 | } |
@@ -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 | { |
@@ -17,4080 +17,4080 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - // set in _init_page_props() |
|
| 21 | - public $page_slug; |
|
| 20 | + // set in _init_page_props() |
|
| 21 | + public $page_slug; |
|
| 22 | 22 | |
| 23 | - public $page_label; |
|
| 23 | + public $page_label; |
|
| 24 | 24 | |
| 25 | - public $page_folder; |
|
| 25 | + public $page_folder; |
|
| 26 | 26 | |
| 27 | - // set in define_page_props() |
|
| 28 | - protected $_admin_base_url; |
|
| 27 | + // set in define_page_props() |
|
| 28 | + protected $_admin_base_url; |
|
| 29 | 29 | |
| 30 | - protected $_admin_base_path; |
|
| 30 | + protected $_admin_base_path; |
|
| 31 | 31 | |
| 32 | - protected $_admin_page_title; |
|
| 32 | + protected $_admin_page_title; |
|
| 33 | 33 | |
| 34 | - protected $_labels; |
|
| 34 | + protected $_labels; |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - // set early within EE_Admin_Init |
|
| 38 | - protected $_wp_page_slug; |
|
| 37 | + // set early within EE_Admin_Init |
|
| 38 | + protected $_wp_page_slug; |
|
| 39 | 39 | |
| 40 | - // navtabs |
|
| 41 | - protected $_nav_tabs; |
|
| 40 | + // navtabs |
|
| 41 | + protected $_nav_tabs; |
|
| 42 | 42 | |
| 43 | - protected $_default_nav_tab_name; |
|
| 43 | + protected $_default_nav_tab_name; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var array $_help_tour |
|
| 47 | - */ |
|
| 48 | - protected $_help_tour = array(); |
|
| 45 | + /** |
|
| 46 | + * @var array $_help_tour |
|
| 47 | + */ |
|
| 48 | + protected $_help_tour = array(); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - // template variables (used by templates) |
|
| 52 | - protected $_template_path; |
|
| 51 | + // template variables (used by templates) |
|
| 52 | + protected $_template_path; |
|
| 53 | 53 | |
| 54 | - protected $_column_template_path; |
|
| 54 | + protected $_column_template_path; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var array $_template_args |
|
| 58 | - */ |
|
| 59 | - protected $_template_args = array(); |
|
| 56 | + /** |
|
| 57 | + * @var array $_template_args |
|
| 58 | + */ |
|
| 59 | + protected $_template_args = array(); |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * this will hold the list table object for a given view. |
|
| 63 | - * |
|
| 64 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 65 | - */ |
|
| 66 | - protected $_list_table_object; |
|
| 61 | + /** |
|
| 62 | + * this will hold the list table object for a given view. |
|
| 63 | + * |
|
| 64 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 65 | + */ |
|
| 66 | + protected $_list_table_object; |
|
| 67 | 67 | |
| 68 | - // bools |
|
| 69 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 68 | + // bools |
|
| 69 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 70 | 70 | |
| 71 | - protected $_routing; |
|
| 71 | + protected $_routing; |
|
| 72 | 72 | |
| 73 | - // list table args |
|
| 74 | - protected $_view; |
|
| 73 | + // list table args |
|
| 74 | + protected $_view; |
|
| 75 | 75 | |
| 76 | - protected $_views; |
|
| 76 | + protected $_views; |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - // action => method pairs used for routing incoming requests |
|
| 80 | - protected $_page_routes; |
|
| 79 | + // action => method pairs used for routing incoming requests |
|
| 80 | + protected $_page_routes; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @var array $_page_config |
|
| 84 | - */ |
|
| 85 | - protected $_page_config; |
|
| 82 | + /** |
|
| 83 | + * @var array $_page_config |
|
| 84 | + */ |
|
| 85 | + protected $_page_config; |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * the current page route and route config |
|
| 89 | - * |
|
| 90 | - * @var string $_route |
|
| 91 | - */ |
|
| 92 | - protected $_route; |
|
| 87 | + /** |
|
| 88 | + * the current page route and route config |
|
| 89 | + * |
|
| 90 | + * @var string $_route |
|
| 91 | + */ |
|
| 92 | + protected $_route; |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @var string $_cpt_route |
|
| 96 | - */ |
|
| 97 | - protected $_cpt_route; |
|
| 94 | + /** |
|
| 95 | + * @var string $_cpt_route |
|
| 96 | + */ |
|
| 97 | + protected $_cpt_route; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @var array $_route_config |
|
| 101 | - */ |
|
| 102 | - protected $_route_config; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 106 | - * actions. |
|
| 107 | - * |
|
| 108 | - * @since 4.6.x |
|
| 109 | - * @var array. |
|
| 110 | - */ |
|
| 111 | - protected $_default_route_query_args; |
|
| 112 | - |
|
| 113 | - // set via request page and action args. |
|
| 114 | - protected $_current_page; |
|
| 115 | - |
|
| 116 | - protected $_current_view; |
|
| 117 | - |
|
| 118 | - protected $_current_page_view_url; |
|
| 119 | - |
|
| 120 | - // sanitized request action (and nonce) |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @var string $_req_action |
|
| 124 | - */ |
|
| 125 | - protected $_req_action; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var string $_req_nonce |
|
| 129 | - */ |
|
| 130 | - protected $_req_nonce; |
|
| 131 | - |
|
| 132 | - // search related |
|
| 133 | - protected $_search_btn_label; |
|
| 134 | - |
|
| 135 | - protected $_search_box_callback; |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * WP Current Screen object |
|
| 139 | - * |
|
| 140 | - * @var WP_Screen |
|
| 141 | - */ |
|
| 142 | - protected $_current_screen; |
|
| 143 | - |
|
| 144 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 145 | - protected $_hook_obj; |
|
| 146 | - |
|
| 147 | - // for holding incoming request data |
|
| 148 | - protected $_req_data; |
|
| 149 | - |
|
| 150 | - // yes / no array for admin form fields |
|
| 151 | - protected $_yes_no_values = array(); |
|
| 152 | - |
|
| 153 | - // some default things shared by all child classes |
|
| 154 | - protected $_default_espresso_metaboxes; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * EE_Registry Object |
|
| 158 | - * |
|
| 159 | - * @var EE_Registry |
|
| 160 | - */ |
|
| 161 | - protected $EE = null; |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 166 | - * |
|
| 167 | - * @var boolean |
|
| 168 | - */ |
|
| 169 | - protected $_is_caf = false; |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @Constructor |
|
| 174 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 175 | - * @throws EE_Error |
|
| 176 | - * @throws InvalidArgumentException |
|
| 177 | - * @throws ReflectionException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - */ |
|
| 181 | - public function __construct($routing = true) |
|
| 182 | - { |
|
| 183 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 184 | - $this->_is_caf = true; |
|
| 185 | - } |
|
| 186 | - $this->_yes_no_values = array( |
|
| 187 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 188 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 189 | - ); |
|
| 190 | - // set the _req_data property. |
|
| 191 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 192 | - // routing enabled? |
|
| 193 | - $this->_routing = $routing; |
|
| 194 | - // set initial page props (child method) |
|
| 195 | - $this->_init_page_props(); |
|
| 196 | - // set global defaults |
|
| 197 | - $this->_set_defaults(); |
|
| 198 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 199 | - $this->_global_ajax_hooks(); |
|
| 200 | - $this->_ajax_hooks(); |
|
| 201 | - // other_page_hooks have to be early too. |
|
| 202 | - $this->_do_other_page_hooks(); |
|
| 203 | - // This just allows us to have extending classes do something specific |
|
| 204 | - // before the parent constructor runs _page_setup(). |
|
| 205 | - if (method_exists($this, '_before_page_setup')) { |
|
| 206 | - $this->_before_page_setup(); |
|
| 207 | - } |
|
| 208 | - // set up page dependencies |
|
| 209 | - $this->_page_setup(); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * _init_page_props |
|
| 215 | - * Child classes use to set at least the following properties: |
|
| 216 | - * $page_slug. |
|
| 217 | - * $page_label. |
|
| 218 | - * |
|
| 219 | - * @abstract |
|
| 220 | - * @return void |
|
| 221 | - */ |
|
| 222 | - abstract protected function _init_page_props(); |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * _ajax_hooks |
|
| 227 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 228 | - * Note: within the ajax callback methods. |
|
| 229 | - * |
|
| 230 | - * @abstract |
|
| 231 | - * @return void |
|
| 232 | - */ |
|
| 233 | - abstract protected function _ajax_hooks(); |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * _define_page_props |
|
| 238 | - * child classes define page properties in here. Must include at least: |
|
| 239 | - * $_admin_base_url = base_url for all admin pages |
|
| 240 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 241 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 242 | - * array( |
|
| 243 | - * 'buttons' => array( |
|
| 244 | - * 'add' => esc_html__('label for add new button'), |
|
| 245 | - * 'edit' => esc_html__('label for edit button'), |
|
| 246 | - * 'delete' => esc_html__('label for delete button') |
|
| 247 | - * ) |
|
| 248 | - * ) |
|
| 249 | - * |
|
| 250 | - * @abstract |
|
| 251 | - * @return void |
|
| 252 | - */ |
|
| 253 | - abstract protected function _define_page_props(); |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * _set_page_routes |
|
| 258 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 259 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 260 | - * have a 'default' route. Here's the format |
|
| 261 | - * $this->_page_routes = array( |
|
| 262 | - * 'default' => array( |
|
| 263 | - * 'func' => '_default_method_handling_route', |
|
| 264 | - * 'args' => array('array','of','args'), |
|
| 265 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 266 | - * ajax request, backend processing) |
|
| 267 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 268 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 269 | - * headers sent route. |
|
| 270 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 271 | - * this route. |
|
| 272 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 273 | - * checks). |
|
| 274 | - * ), |
|
| 275 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 276 | - * handling method. |
|
| 277 | - * ) |
|
| 278 | - * ) |
|
| 279 | - * |
|
| 280 | - * @abstract |
|
| 281 | - * @return void |
|
| 282 | - */ |
|
| 283 | - abstract protected function _set_page_routes(); |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * _set_page_config |
|
| 288 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 289 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 290 | - * $this->_page_config = array( |
|
| 291 | - * 'default' => array( |
|
| 292 | - * 'labels' => array( |
|
| 293 | - * 'buttons' => array( |
|
| 294 | - * 'add' => esc_html__('label for adding item'), |
|
| 295 | - * 'edit' => esc_html__('label for editing item'), |
|
| 296 | - * 'delete' => esc_html__('label for deleting item') |
|
| 297 | - * ), |
|
| 298 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 299 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 300 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 301 | - * _define_page_props() method |
|
| 302 | - * 'nav' => array( |
|
| 303 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 304 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 305 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 306 | - * 'order' => 10, //required to indicate tab position. |
|
| 307 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 308 | - * displayed then add this parameter. |
|
| 309 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 310 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 311 | - * metaboxes set for eventespresso admin pages. |
|
| 312 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 313 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 314 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 315 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 316 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 317 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 318 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 319 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 320 | - * want to display. |
|
| 321 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 322 | - * 'tab_id' => array( |
|
| 323 | - * 'title' => 'tab_title', |
|
| 324 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 325 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 326 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 327 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 328 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 329 | - * attempt to use the callback which should match the name of a method in the class |
|
| 330 | - * ), |
|
| 331 | - * 'tab2_id' => array( |
|
| 332 | - * 'title' => 'tab2 title', |
|
| 333 | - * 'filename' => 'file_name_2' |
|
| 334 | - * 'callback' => 'callback_method_for_content', |
|
| 335 | - * ), |
|
| 336 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 337 | - * help tab area on an admin page. @link |
|
| 338 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 339 | - * 'help_tour' => array( |
|
| 340 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 341 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 342 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 343 | - * ), |
|
| 344 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 345 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 346 | - * just set |
|
| 347 | - * 'require_nonce' to FALSE |
|
| 348 | - * ) |
|
| 349 | - * ) |
|
| 350 | - * |
|
| 351 | - * @abstract |
|
| 352 | - * @return void |
|
| 353 | - */ |
|
| 354 | - abstract protected function _set_page_config(); |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** end sample help_tour methods **/ |
|
| 361 | - /** |
|
| 362 | - * _add_screen_options |
|
| 363 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 364 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 365 | - * to a particular view. |
|
| 366 | - * |
|
| 367 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 368 | - * see also WP_Screen object documents... |
|
| 369 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 370 | - * @abstract |
|
| 371 | - * @return void |
|
| 372 | - */ |
|
| 373 | - abstract protected function _add_screen_options(); |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * _add_feature_pointers |
|
| 378 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 379 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 380 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 381 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 382 | - * extended) also see: |
|
| 383 | - * |
|
| 384 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 385 | - * @abstract |
|
| 386 | - * @return void |
|
| 387 | - */ |
|
| 388 | - abstract protected function _add_feature_pointers(); |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * load_scripts_styles |
|
| 393 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 394 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 395 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 396 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 397 | - * |
|
| 398 | - * @abstract |
|
| 399 | - * @return void |
|
| 400 | - */ |
|
| 401 | - abstract public function load_scripts_styles(); |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * admin_init |
|
| 406 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 407 | - * all pages/views loaded by child class. |
|
| 408 | - * |
|
| 409 | - * @abstract |
|
| 410 | - * @return void |
|
| 411 | - */ |
|
| 412 | - abstract public function admin_init(); |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * admin_notices |
|
| 417 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 418 | - * all pages/views loaded by child class. |
|
| 419 | - * |
|
| 420 | - * @abstract |
|
| 421 | - * @return void |
|
| 422 | - */ |
|
| 423 | - abstract public function admin_notices(); |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * admin_footer_scripts |
|
| 428 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 429 | - * will apply to all pages/views loaded by child class. |
|
| 430 | - * |
|
| 431 | - * @return void |
|
| 432 | - */ |
|
| 433 | - abstract public function admin_footer_scripts(); |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * admin_footer |
|
| 438 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 439 | - * apply to all pages/views loaded by child class. |
|
| 440 | - * |
|
| 441 | - * @return void |
|
| 442 | - */ |
|
| 443 | - public function admin_footer() |
|
| 444 | - { |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * _global_ajax_hooks |
|
| 450 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 451 | - * Note: within the ajax callback methods. |
|
| 452 | - * |
|
| 453 | - * @abstract |
|
| 454 | - * @return void |
|
| 455 | - */ |
|
| 456 | - protected function _global_ajax_hooks() |
|
| 457 | - { |
|
| 458 | - // for lazy loading of metabox content |
|
| 459 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - public function ajax_metabox_content() |
|
| 464 | - { |
|
| 465 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 466 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 467 | - self::cached_rss_display($contentid, $url); |
|
| 468 | - wp_die(); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * _page_setup |
|
| 474 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 475 | - * doesn't match the object. |
|
| 476 | - * |
|
| 477 | - * @final |
|
| 478 | - * @return void |
|
| 479 | - * @throws EE_Error |
|
| 480 | - * @throws InvalidArgumentException |
|
| 481 | - * @throws ReflectionException |
|
| 482 | - * @throws InvalidDataTypeException |
|
| 483 | - * @throws InvalidInterfaceException |
|
| 484 | - */ |
|
| 485 | - final protected function _page_setup() |
|
| 486 | - { |
|
| 487 | - // requires? |
|
| 488 | - // 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. |
|
| 489 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 490 | - // next verify if we need to load anything... |
|
| 491 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 492 | - $this->page_folder = strtolower( |
|
| 493 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 494 | - ); |
|
| 495 | - global $ee_menu_slugs; |
|
| 496 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 497 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 498 | - return; |
|
| 499 | - } |
|
| 500 | - // 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 |
|
| 501 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 502 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 503 | - ? $this->_req_data['action2'] |
|
| 504 | - : $this->_req_data['action']; |
|
| 505 | - } |
|
| 506 | - // then set blank or -1 action values to 'default' |
|
| 507 | - $this->_req_action = isset($this->_req_data['action']) |
|
| 508 | - && ! empty($this->_req_data['action']) |
|
| 509 | - && $this->_req_data['action'] !== '-1' |
|
| 510 | - ? sanitize_key($this->_req_data['action']) |
|
| 511 | - : 'default'; |
|
| 512 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 513 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 514 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 515 | - ? $this->_req_data['route'] : $this->_req_action; |
|
| 516 | - // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 517 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 518 | - ? $this->_req_data['route'] |
|
| 519 | - : $this->_req_action; |
|
| 520 | - $this->_current_view = $this->_req_action; |
|
| 521 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 522 | - $this->_define_page_props(); |
|
| 523 | - $this->_current_page_view_url = add_query_arg( |
|
| 524 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 525 | - $this->_admin_base_url |
|
| 526 | - ); |
|
| 527 | - // default things |
|
| 528 | - $this->_default_espresso_metaboxes = array( |
|
| 529 | - '_espresso_news_post_box', |
|
| 530 | - '_espresso_links_post_box', |
|
| 531 | - '_espresso_ratings_request', |
|
| 532 | - '_espresso_sponsors_post_box', |
|
| 533 | - ); |
|
| 534 | - // set page configs |
|
| 535 | - $this->_set_page_routes(); |
|
| 536 | - $this->_set_page_config(); |
|
| 537 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 538 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 539 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 540 | - } |
|
| 541 | - // for caffeinated and other extended functionality. |
|
| 542 | - // If there is a _extend_page_config method |
|
| 543 | - // then let's run that to modify the all the various page configuration arrays |
|
| 544 | - if (method_exists($this, '_extend_page_config')) { |
|
| 545 | - $this->_extend_page_config(); |
|
| 546 | - } |
|
| 547 | - // for CPT and other extended functionality. |
|
| 548 | - // If there is an _extend_page_config_for_cpt |
|
| 549 | - // then let's run that to modify all the various page configuration arrays. |
|
| 550 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 551 | - $this->_extend_page_config_for_cpt(); |
|
| 552 | - } |
|
| 553 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 554 | - $this->_page_routes = apply_filters( |
|
| 555 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 556 | - $this->_page_routes, |
|
| 557 | - $this |
|
| 558 | - ); |
|
| 559 | - $this->_page_config = apply_filters( |
|
| 560 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 561 | - $this->_page_config, |
|
| 562 | - $this |
|
| 563 | - ); |
|
| 564 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 565 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 566 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 567 | - add_action( |
|
| 568 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 569 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 570 | - 10, |
|
| 571 | - 2 |
|
| 572 | - ); |
|
| 573 | - } |
|
| 574 | - // next route only if routing enabled |
|
| 575 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 576 | - $this->_verify_routes(); |
|
| 577 | - // next let's just check user_access and kill if no access |
|
| 578 | - $this->check_user_access(); |
|
| 579 | - if ($this->_is_UI_request) { |
|
| 580 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 581 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 582 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 583 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 584 | - } |
|
| 585 | - } else { |
|
| 586 | - // hijack regular WP loading and route admin request immediately |
|
| 587 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 588 | - $this->route_admin_request(); |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 596 | - * |
|
| 597 | - * @return void |
|
| 598 | - * @throws ReflectionException |
|
| 599 | - * @throws EE_Error |
|
| 600 | - */ |
|
| 601 | - private function _do_other_page_hooks() |
|
| 602 | - { |
|
| 603 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 604 | - foreach ($registered_pages as $page) { |
|
| 605 | - // now let's setup the file name and class that should be present |
|
| 606 | - $classname = str_replace('.class.php', '', $page); |
|
| 607 | - // autoloaders should take care of loading file |
|
| 608 | - if (! class_exists($classname)) { |
|
| 609 | - $error_msg[] = sprintf( |
|
| 610 | - esc_html__( |
|
| 611 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 612 | - 'event_espresso' |
|
| 613 | - ), |
|
| 614 | - $page |
|
| 615 | - ); |
|
| 616 | - $error_msg[] = $error_msg[0] |
|
| 617 | - . "\r\n" |
|
| 618 | - . sprintf( |
|
| 619 | - esc_html__( |
|
| 620 | - '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', |
|
| 621 | - 'event_espresso' |
|
| 622 | - ), |
|
| 623 | - $page, |
|
| 624 | - '<br />', |
|
| 625 | - '<strong>' . $classname . '</strong>' |
|
| 626 | - ); |
|
| 627 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 628 | - } |
|
| 629 | - $a = new ReflectionClass($classname); |
|
| 630 | - // notice we are passing the instance of this class to the hook object. |
|
| 631 | - $hookobj[] = $a->newInstance($this); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - public function load_page_dependencies() |
|
| 637 | - { |
|
| 638 | - try { |
|
| 639 | - $this->_load_page_dependencies(); |
|
| 640 | - } catch (EE_Error $e) { |
|
| 641 | - $e->get_error(); |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * load_page_dependencies |
|
| 648 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 649 | - * |
|
| 650 | - * @return void |
|
| 651 | - * @throws DomainException |
|
| 652 | - * @throws EE_Error |
|
| 653 | - * @throws InvalidArgumentException |
|
| 654 | - * @throws InvalidDataTypeException |
|
| 655 | - * @throws InvalidInterfaceException |
|
| 656 | - * @throws ReflectionException |
|
| 657 | - */ |
|
| 658 | - protected function _load_page_dependencies() |
|
| 659 | - { |
|
| 660 | - // let's set the current_screen and screen options to override what WP set |
|
| 661 | - $this->_current_screen = get_current_screen(); |
|
| 662 | - // load admin_notices - global, page class, and view specific |
|
| 663 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 664 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 665 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 666 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 667 | - } |
|
| 668 | - // load network admin_notices - global, page class, and view specific |
|
| 669 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 670 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 671 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 672 | - } |
|
| 673 | - // this will save any per_page screen options if they are present |
|
| 674 | - $this->_set_per_page_screen_options(); |
|
| 675 | - // setup list table properties |
|
| 676 | - $this->_set_list_table(); |
|
| 677 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 678 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 679 | - $this->_add_registered_meta_boxes(); |
|
| 680 | - $this->_add_screen_columns(); |
|
| 681 | - // add screen options - global, page child class, and view specific |
|
| 682 | - $this->_add_global_screen_options(); |
|
| 683 | - $this->_add_screen_options(); |
|
| 684 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 685 | - if (method_exists($this, $add_screen_options)) { |
|
| 686 | - $this->{$add_screen_options}(); |
|
| 687 | - } |
|
| 688 | - // add help tab(s) and tours- set via page_config and qtips. |
|
| 689 | - $this->_add_help_tour(); |
|
| 690 | - $this->_add_help_tabs(); |
|
| 691 | - $this->_add_qtips(); |
|
| 692 | - // add feature_pointers - global, page child class, and view specific |
|
| 693 | - $this->_add_feature_pointers(); |
|
| 694 | - $this->_add_global_feature_pointers(); |
|
| 695 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 696 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 697 | - $this->{$add_feature_pointer}(); |
|
| 698 | - } |
|
| 699 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 700 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 701 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 702 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 703 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 704 | - } |
|
| 705 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 706 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 707 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 708 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 709 | - // is a good use case. Notice the late priority we're giving these |
|
| 710 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 711 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 712 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 713 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 714 | - } |
|
| 715 | - // admin footer scripts |
|
| 716 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 717 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 718 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 719 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 720 | - } |
|
| 721 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 722 | - // targeted hook |
|
| 723 | - do_action( |
|
| 724 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 725 | - ); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * _set_defaults |
|
| 731 | - * This sets some global defaults for class properties. |
|
| 732 | - */ |
|
| 733 | - private function _set_defaults() |
|
| 734 | - { |
|
| 735 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 736 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 737 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 738 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
| 739 | - $this->_default_nav_tab_name = 'overview'; |
|
| 740 | - // init template args |
|
| 741 | - $this->_template_args = array( |
|
| 742 | - 'admin_page_header' => '', |
|
| 743 | - 'admin_page_content' => '', |
|
| 744 | - 'post_body_content' => '', |
|
| 745 | - 'before_list_table' => '', |
|
| 746 | - 'after_list_table' => '', |
|
| 747 | - ); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * route_admin_request |
|
| 753 | - * |
|
| 754 | - * @see _route_admin_request() |
|
| 755 | - * @return exception|void error |
|
| 756 | - * @throws InvalidArgumentException |
|
| 757 | - * @throws InvalidInterfaceException |
|
| 758 | - * @throws InvalidDataTypeException |
|
| 759 | - * @throws EE_Error |
|
| 760 | - * @throws ReflectionException |
|
| 761 | - */ |
|
| 762 | - public function route_admin_request() |
|
| 763 | - { |
|
| 764 | - try { |
|
| 765 | - $this->_route_admin_request(); |
|
| 766 | - } catch (EE_Error $e) { |
|
| 767 | - $e->get_error(); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - public function set_wp_page_slug($wp_page_slug) |
|
| 773 | - { |
|
| 774 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 775 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 776 | - if (is_network_admin()) { |
|
| 777 | - $this->_wp_page_slug .= '-network'; |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * _verify_routes |
|
| 784 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 785 | - * we know if we need to drop out. |
|
| 786 | - * |
|
| 787 | - * @return bool |
|
| 788 | - * @throws EE_Error |
|
| 789 | - */ |
|
| 790 | - protected function _verify_routes() |
|
| 791 | - { |
|
| 792 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 793 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 794 | - return false; |
|
| 795 | - } |
|
| 796 | - $this->_route = false; |
|
| 797 | - // check that the page_routes array is not empty |
|
| 798 | - if (empty($this->_page_routes)) { |
|
| 799 | - // user error msg |
|
| 800 | - $error_msg = sprintf( |
|
| 801 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 802 | - $this->_admin_page_title |
|
| 803 | - ); |
|
| 804 | - // developer error msg |
|
| 805 | - $error_msg .= '||' . $error_msg |
|
| 806 | - . esc_html__( |
|
| 807 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 808 | - 'event_espresso' |
|
| 809 | - ); |
|
| 810 | - throw new EE_Error($error_msg); |
|
| 811 | - } |
|
| 812 | - // and that the requested page route exists |
|
| 813 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 814 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 815 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 816 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 817 | - } else { |
|
| 818 | - // user error msg |
|
| 819 | - $error_msg = sprintf( |
|
| 820 | - esc_html__( |
|
| 821 | - 'The requested page route does not exist for the %s admin page.', |
|
| 822 | - 'event_espresso' |
|
| 823 | - ), |
|
| 824 | - $this->_admin_page_title |
|
| 825 | - ); |
|
| 826 | - // developer error msg |
|
| 827 | - $error_msg .= '||' . $error_msg |
|
| 828 | - . sprintf( |
|
| 829 | - esc_html__( |
|
| 830 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 831 | - 'event_espresso' |
|
| 832 | - ), |
|
| 833 | - $this->_req_action |
|
| 834 | - ); |
|
| 835 | - throw new EE_Error($error_msg); |
|
| 836 | - } |
|
| 837 | - // and that a default route exists |
|
| 838 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 839 | - // user error msg |
|
| 840 | - $error_msg = sprintf( |
|
| 841 | - esc_html__( |
|
| 842 | - 'A default page route has not been set for the % admin page.', |
|
| 843 | - 'event_espresso' |
|
| 844 | - ), |
|
| 845 | - $this->_admin_page_title |
|
| 846 | - ); |
|
| 847 | - // developer error msg |
|
| 848 | - $error_msg .= '||' . $error_msg |
|
| 849 | - . esc_html__( |
|
| 850 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ); |
|
| 853 | - throw new EE_Error($error_msg); |
|
| 854 | - } |
|
| 855 | - // first lets' catch if the UI request has EVER been set. |
|
| 856 | - if ($this->_is_UI_request === null) { |
|
| 857 | - // lets set if this is a UI request or not. |
|
| 858 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 859 | - // wait a minute... we might have a noheader in the route array |
|
| 860 | - $this->_is_UI_request = is_array($this->_route) |
|
| 861 | - && isset($this->_route['noheader']) |
|
| 862 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 863 | - } |
|
| 864 | - $this->_set_current_labels(); |
|
| 865 | - return true; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 871 | - * |
|
| 872 | - * @param string $route the route name we're verifying |
|
| 873 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 874 | - * @throws EE_Error |
|
| 875 | - */ |
|
| 876 | - protected function _verify_route($route) |
|
| 877 | - { |
|
| 878 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 879 | - return true; |
|
| 880 | - } |
|
| 881 | - // user error msg |
|
| 882 | - $error_msg = sprintf( |
|
| 883 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 884 | - $this->_admin_page_title |
|
| 885 | - ); |
|
| 886 | - // developer error msg |
|
| 887 | - $error_msg .= '||' . $error_msg |
|
| 888 | - . sprintf( |
|
| 889 | - esc_html__( |
|
| 890 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 891 | - 'event_espresso' |
|
| 892 | - ), |
|
| 893 | - $route |
|
| 894 | - ); |
|
| 895 | - throw new EE_Error($error_msg); |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * perform nonce verification |
|
| 901 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 902 | - * using this method (and save retyping!) |
|
| 903 | - * |
|
| 904 | - * @param string $nonce The nonce sent |
|
| 905 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 906 | - * @return void |
|
| 907 | - * @throws EE_Error |
|
| 908 | - */ |
|
| 909 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 910 | - { |
|
| 911 | - // verify nonce against expected value |
|
| 912 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 913 | - // these are not the droids you are looking for !!! |
|
| 914 | - $msg = sprintf( |
|
| 915 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 916 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 917 | - '</a>' |
|
| 918 | - ); |
|
| 919 | - if (WP_DEBUG) { |
|
| 920 | - $msg .= "\n " |
|
| 921 | - . sprintf( |
|
| 922 | - esc_html__( |
|
| 923 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 924 | - 'event_espresso' |
|
| 925 | - ), |
|
| 926 | - __CLASS__ |
|
| 927 | - ); |
|
| 928 | - } |
|
| 929 | - if (! defined('DOING_AJAX')) { |
|
| 930 | - wp_die($msg); |
|
| 931 | - } else { |
|
| 932 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 933 | - $this->_return_json(); |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * _route_admin_request() |
|
| 941 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 942 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 943 | - * in the page routes and then will try to load the corresponding method. |
|
| 944 | - * |
|
| 945 | - * @return void |
|
| 946 | - * @throws EE_Error |
|
| 947 | - * @throws InvalidArgumentException |
|
| 948 | - * @throws InvalidDataTypeException |
|
| 949 | - * @throws InvalidInterfaceException |
|
| 950 | - * @throws ReflectionException |
|
| 951 | - */ |
|
| 952 | - protected function _route_admin_request() |
|
| 953 | - { |
|
| 954 | - if (! $this->_is_UI_request) { |
|
| 955 | - $this->_verify_routes(); |
|
| 956 | - } |
|
| 957 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 958 | - ? $this->_route_config['require_nonce'] |
|
| 959 | - : true; |
|
| 960 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 961 | - // set nonce from post data |
|
| 962 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 963 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 964 | - : ''; |
|
| 965 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 966 | - } |
|
| 967 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 968 | - if ($this->_is_UI_request) { |
|
| 969 | - $this->_set_nav_tabs(); |
|
| 970 | - } |
|
| 971 | - // grab callback function |
|
| 972 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 973 | - // check if callback has args |
|
| 974 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 975 | - $error_msg = ''; |
|
| 976 | - // action right before calling route |
|
| 977 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 978 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 979 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 980 | - } |
|
| 981 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 982 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 983 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 984 | - '_wp_http_referer', |
|
| 985 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
| 986 | - ); |
|
| 987 | - if (! empty($func)) { |
|
| 988 | - if (is_array($func)) { |
|
| 989 | - list($class, $method) = $func; |
|
| 990 | - } elseif (strpos($func, '::') !== false) { |
|
| 991 | - list($class, $method) = explode('::', $func); |
|
| 992 | - } else { |
|
| 993 | - $class = $this; |
|
| 994 | - $method = $func; |
|
| 995 | - } |
|
| 996 | - if (! (is_object($class) && $class === $this)) { |
|
| 997 | - // send along this admin page object for access by addons. |
|
| 998 | - $args['admin_page_object'] = $this; |
|
| 999 | - } |
|
| 1000 | - if (// is it a method on a class that doesn't work? |
|
| 1001 | - ( |
|
| 1002 | - ( |
|
| 1003 | - method_exists($class, $method) |
|
| 1004 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 1005 | - ) |
|
| 1006 | - && ( |
|
| 1007 | - // is it a standalone function that doesn't work? |
|
| 1008 | - function_exists($method) |
|
| 1009 | - && call_user_func_array( |
|
| 1010 | - $func, |
|
| 1011 | - array_merge(array('admin_page_object' => $this), $args) |
|
| 1012 | - ) === false |
|
| 1013 | - ) |
|
| 1014 | - ) |
|
| 1015 | - || ( |
|
| 1016 | - // is it neither a class method NOR a standalone function? |
|
| 1017 | - ! method_exists($class, $method) |
|
| 1018 | - && ! function_exists($method) |
|
| 1019 | - ) |
|
| 1020 | - ) { |
|
| 1021 | - // user error msg |
|
| 1022 | - $error_msg = esc_html__( |
|
| 1023 | - 'An error occurred. The requested page route could not be found.', |
|
| 1024 | - 'event_espresso' |
|
| 1025 | - ); |
|
| 1026 | - // developer error msg |
|
| 1027 | - $error_msg .= '||'; |
|
| 1028 | - $error_msg .= sprintf( |
|
| 1029 | - esc_html__( |
|
| 1030 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1031 | - 'event_espresso' |
|
| 1032 | - ), |
|
| 1033 | - $method |
|
| 1034 | - ); |
|
| 1035 | - } |
|
| 1036 | - if (! empty($error_msg)) { |
|
| 1037 | - throw new EE_Error($error_msg); |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1041 | - // then we need to reset the routing properties to the new route. |
|
| 1042 | - // 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. |
|
| 1043 | - if ($this->_is_UI_request === false |
|
| 1044 | - && is_array($this->_route) |
|
| 1045 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1046 | - ) { |
|
| 1047 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1048 | - } |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1054 | - * route redirects to a headers route in its route config. |
|
| 1055 | - * |
|
| 1056 | - * @since 4.3.0 |
|
| 1057 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1058 | - * @return void |
|
| 1059 | - * @throws ReflectionException |
|
| 1060 | - * @throws InvalidArgumentException |
|
| 1061 | - * @throws InvalidInterfaceException |
|
| 1062 | - * @throws InvalidDataTypeException |
|
| 1063 | - * @throws EE_Error |
|
| 1064 | - */ |
|
| 1065 | - protected function _reset_routing_properties($new_route) |
|
| 1066 | - { |
|
| 1067 | - $this->_is_UI_request = true; |
|
| 1068 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1069 | - $this->_req_data['action'] = $new_route; |
|
| 1070 | - // rerun page setup |
|
| 1071 | - $this->_page_setup(); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * _add_query_arg |
|
| 1077 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1078 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1079 | - * |
|
| 1080 | - * @param array $args |
|
| 1081 | - * @param string $url |
|
| 1082 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1083 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1084 | - * Example usage: If the current page is: |
|
| 1085 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1086 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1087 | - * &_wpnonce=5467821 |
|
| 1088 | - * and you call: |
|
| 1089 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1090 | - * array( |
|
| 1091 | - * 'action' => 'resend_something', |
|
| 1092 | - * 'page=>espresso_registrations' |
|
| 1093 | - * ), |
|
| 1094 | - * $some_url, |
|
| 1095 | - * true |
|
| 1096 | - * ); |
|
| 1097 | - * It will produce a url in this structure: |
|
| 1098 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1099 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1100 | - * month_range]=March%202015 |
|
| 1101 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1102 | - * @return string |
|
| 1103 | - */ |
|
| 1104 | - public static function add_query_args_and_nonce( |
|
| 1105 | - $args = array(), |
|
| 1106 | - $url = false, |
|
| 1107 | - $sticky = false, |
|
| 1108 | - $exclude_nonce = false |
|
| 1109 | - ) { |
|
| 1110 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1111 | - if ($sticky) { |
|
| 1112 | - $request = $_REQUEST; |
|
| 1113 | - unset($request['_wp_http_referer']); |
|
| 1114 | - unset($request['wp_referer']); |
|
| 1115 | - foreach ($request as $key => $value) { |
|
| 1116 | - // do not add nonces |
|
| 1117 | - if (strpos($key, 'nonce') !== false) { |
|
| 1118 | - continue; |
|
| 1119 | - } |
|
| 1120 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * This returns a generated link that will load the related help tab. |
|
| 1129 | - * |
|
| 1130 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1131 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1132 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1133 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1134 | - * @return string generated link |
|
| 1135 | - */ |
|
| 1136 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1137 | - { |
|
| 1138 | - return EEH_Template::get_help_tab_link( |
|
| 1139 | - $help_tab_id, |
|
| 1140 | - $this->page_slug, |
|
| 1141 | - $this->_req_action, |
|
| 1142 | - $icon_style, |
|
| 1143 | - $help_text |
|
| 1144 | - ); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * _add_help_tabs |
|
| 1150 | - * Note child classes define their help tabs within the page_config array. |
|
| 1151 | - * |
|
| 1152 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1153 | - * @return void |
|
| 1154 | - * @throws DomainException |
|
| 1155 | - * @throws EE_Error |
|
| 1156 | - */ |
|
| 1157 | - protected function _add_help_tabs() |
|
| 1158 | - { |
|
| 1159 | - $tour_buttons = ''; |
|
| 1160 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1161 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1162 | - // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1163 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1164 | - $tb = array(); |
|
| 1165 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1166 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1167 | - // if this is the end tour then we don't need to setup a button |
|
| 1168 | - if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1169 | - continue; |
|
| 1170 | - } |
|
| 1171 | - $tb[] = '<button id="trigger-tour-' |
|
| 1172 | - . $tour->get_slug() |
|
| 1173 | - . '" class="button-primary trigger-ee-help-tour">' |
|
| 1174 | - . $tour->get_label() |
|
| 1175 | - . '</button>'; |
|
| 1176 | - } |
|
| 1177 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1178 | - $tour_buttons .= '</div></div>'; |
|
| 1179 | - } |
|
| 1180 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1181 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1182 | - // check that the callback given is valid |
|
| 1183 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1184 | - throw new EE_Error( |
|
| 1185 | - sprintf( |
|
| 1186 | - esc_html__( |
|
| 1187 | - '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', |
|
| 1188 | - 'event_espresso' |
|
| 1189 | - ), |
|
| 1190 | - $config['help_sidebar'], |
|
| 1191 | - get_class($this) |
|
| 1192 | - ) |
|
| 1193 | - ); |
|
| 1194 | - } |
|
| 1195 | - $content = apply_filters( |
|
| 1196 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1197 | - $this->{$config['help_sidebar']}() |
|
| 1198 | - ); |
|
| 1199 | - $content .= $tour_buttons; // add help tour buttons. |
|
| 1200 | - // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1201 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1202 | - } |
|
| 1203 | - // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1204 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1205 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1206 | - } |
|
| 1207 | - // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1208 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1209 | - $_ht['id'] = $this->page_slug; |
|
| 1210 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1211 | - $_ht['content'] = '<p>' |
|
| 1212 | - . esc_html__( |
|
| 1213 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1214 | - 'event_espresso' |
|
| 1215 | - ) . '</p>'; |
|
| 1216 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1217 | - } |
|
| 1218 | - if (! isset($config['help_tabs'])) { |
|
| 1219 | - return; |
|
| 1220 | - } //no help tabs for this route |
|
| 1221 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1222 | - // we're here so there ARE help tabs! |
|
| 1223 | - // make sure we've got what we need |
|
| 1224 | - if (! isset($cfg['title'])) { |
|
| 1225 | - throw new EE_Error( |
|
| 1226 | - esc_html__( |
|
| 1227 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1228 | - 'event_espresso' |
|
| 1229 | - ) |
|
| 1230 | - ); |
|
| 1231 | - } |
|
| 1232 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1233 | - throw new EE_Error( |
|
| 1234 | - esc_html__( |
|
| 1235 | - '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', |
|
| 1236 | - 'event_espresso' |
|
| 1237 | - ) |
|
| 1238 | - ); |
|
| 1239 | - } |
|
| 1240 | - // first priority goes to content. |
|
| 1241 | - if (! empty($cfg['content'])) { |
|
| 1242 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1243 | - // second priority goes to filename |
|
| 1244 | - } elseif (! empty($cfg['filename'])) { |
|
| 1245 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1246 | - // 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) |
|
| 1247 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1248 | - . basename($this->_get_dir()) |
|
| 1249 | - . '/help_tabs/' |
|
| 1250 | - . $cfg['filename'] |
|
| 1251 | - . '.help_tab.php' : $file_path; |
|
| 1252 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1253 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1254 | - EE_Error::add_error( |
|
| 1255 | - sprintf( |
|
| 1256 | - esc_html__( |
|
| 1257 | - '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', |
|
| 1258 | - 'event_espresso' |
|
| 1259 | - ), |
|
| 1260 | - $tab_id, |
|
| 1261 | - key($config), |
|
| 1262 | - $file_path |
|
| 1263 | - ), |
|
| 1264 | - __FILE__, |
|
| 1265 | - __FUNCTION__, |
|
| 1266 | - __LINE__ |
|
| 1267 | - ); |
|
| 1268 | - return; |
|
| 1269 | - } |
|
| 1270 | - $template_args['admin_page_obj'] = $this; |
|
| 1271 | - $content = EEH_Template::display_template( |
|
| 1272 | - $file_path, |
|
| 1273 | - $template_args, |
|
| 1274 | - true |
|
| 1275 | - ); |
|
| 1276 | - } else { |
|
| 1277 | - $content = ''; |
|
| 1278 | - } |
|
| 1279 | - // check if callback is valid |
|
| 1280 | - if (empty($content) && ( |
|
| 1281 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1282 | - ) |
|
| 1283 | - ) { |
|
| 1284 | - EE_Error::add_error( |
|
| 1285 | - sprintf( |
|
| 1286 | - esc_html__( |
|
| 1287 | - '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.', |
|
| 1288 | - 'event_espresso' |
|
| 1289 | - ), |
|
| 1290 | - $cfg['title'] |
|
| 1291 | - ), |
|
| 1292 | - __FILE__, |
|
| 1293 | - __FUNCTION__, |
|
| 1294 | - __LINE__ |
|
| 1295 | - ); |
|
| 1296 | - return; |
|
| 1297 | - } |
|
| 1298 | - // setup config array for help tab method |
|
| 1299 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1300 | - $_ht = array( |
|
| 1301 | - 'id' => $id, |
|
| 1302 | - 'title' => $cfg['title'], |
|
| 1303 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1304 | - 'content' => $content, |
|
| 1305 | - ); |
|
| 1306 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1314 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1315 | - * |
|
| 1316 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1317 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1318 | - * _set_page_config() comments |
|
| 1319 | - * @return void |
|
| 1320 | - * @throws EE_Error |
|
| 1321 | - * @throws InvalidArgumentException |
|
| 1322 | - * @throws InvalidDataTypeException |
|
| 1323 | - * @throws InvalidInterfaceException |
|
| 1324 | - */ |
|
| 1325 | - protected function _add_help_tour() |
|
| 1326 | - { |
|
| 1327 | - $tours = array(); |
|
| 1328 | - $this->_help_tour = array(); |
|
| 1329 | - // exit early if help tours are turned off globally |
|
| 1330 | - if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1331 | - || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1332 | - ) { |
|
| 1333 | - return; |
|
| 1334 | - } |
|
| 1335 | - // loop through _page_config to find any help_tour defined |
|
| 1336 | - foreach ($this->_page_config as $route => $config) { |
|
| 1337 | - // we're only going to set things up for this route |
|
| 1338 | - if ($route !== $this->_req_action) { |
|
| 1339 | - continue; |
|
| 1340 | - } |
|
| 1341 | - if (isset($config['help_tour'])) { |
|
| 1342 | - foreach ($config['help_tour'] as $tour) { |
|
| 1343 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1344 | - // let's see if we can get that file... |
|
| 1345 | - // if not its possible this is a decaf route not set in caffeinated |
|
| 1346 | - // so lets try and get the caffeinated equivalent |
|
| 1347 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1348 | - . basename($this->_get_dir()) |
|
| 1349 | - . '/help_tours/' |
|
| 1350 | - . $tour |
|
| 1351 | - . '.class.php' : $file_path; |
|
| 1352 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1353 | - if (! is_readable($file_path)) { |
|
| 1354 | - EE_Error::add_error( |
|
| 1355 | - sprintf( |
|
| 1356 | - esc_html__( |
|
| 1357 | - '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', |
|
| 1358 | - 'event_espresso' |
|
| 1359 | - ), |
|
| 1360 | - $file_path, |
|
| 1361 | - $tour |
|
| 1362 | - ), |
|
| 1363 | - __FILE__, |
|
| 1364 | - __FUNCTION__, |
|
| 1365 | - __LINE__ |
|
| 1366 | - ); |
|
| 1367 | - return; |
|
| 1368 | - } |
|
| 1369 | - require_once $file_path; |
|
| 1370 | - if (! class_exists($tour)) { |
|
| 1371 | - $error_msg[] = sprintf( |
|
| 1372 | - esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1373 | - $tour |
|
| 1374 | - ); |
|
| 1375 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1376 | - . sprintf( |
|
| 1377 | - esc_html__( |
|
| 1378 | - '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.', |
|
| 1379 | - 'event_espresso' |
|
| 1380 | - ), |
|
| 1381 | - $tour, |
|
| 1382 | - '<br />', |
|
| 1383 | - $tour, |
|
| 1384 | - $this->_req_action, |
|
| 1385 | - get_class($this) |
|
| 1386 | - ); |
|
| 1387 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1388 | - } |
|
| 1389 | - $tour_obj = new $tour($this->_is_caf); |
|
| 1390 | - $tours[] = $tour_obj; |
|
| 1391 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1392 | - } |
|
| 1393 | - // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1394 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1395 | - $tours[] = $end_stop_tour; |
|
| 1396 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - if (! empty($tours)) { |
|
| 1400 | - $this->_help_tour['tours'] = $tours; |
|
| 1401 | - } |
|
| 1402 | - // that's it! Now that the $_help_tours property is set (or not) |
|
| 1403 | - // the scripts and html should be taken care of automatically. |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - |
|
| 1407 | - /** |
|
| 1408 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1409 | - * |
|
| 1410 | - * @return void |
|
| 1411 | - */ |
|
| 1412 | - protected function _add_qtips() |
|
| 1413 | - { |
|
| 1414 | - if (isset($this->_route_config['qtips'])) { |
|
| 1415 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1416 | - // load qtip loader |
|
| 1417 | - $path = array( |
|
| 1418 | - $this->_get_dir() . '/qtips/', |
|
| 1419 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1420 | - ); |
|
| 1421 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * _set_nav_tabs |
|
| 1428 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1429 | - * wish to add additional tabs or modify accordingly. |
|
| 1430 | - * |
|
| 1431 | - * @return void |
|
| 1432 | - * @throws InvalidArgumentException |
|
| 1433 | - * @throws InvalidInterfaceException |
|
| 1434 | - * @throws InvalidDataTypeException |
|
| 1435 | - */ |
|
| 1436 | - protected function _set_nav_tabs() |
|
| 1437 | - { |
|
| 1438 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1439 | - $i = 0; |
|
| 1440 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1441 | - if (! is_array($config) |
|
| 1442 | - || ( |
|
| 1443 | - is_array($config) |
|
| 1444 | - && ( |
|
| 1445 | - (isset($config['nav']) && ! $config['nav']) |
|
| 1446 | - || ! isset($config['nav']) |
|
| 1447 | - ) |
|
| 1448 | - ) |
|
| 1449 | - ) { |
|
| 1450 | - continue; |
|
| 1451 | - } |
|
| 1452 | - // no nav tab for this config |
|
| 1453 | - // check for persistent flag |
|
| 1454 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1455 | - // nav tab is only to appear when route requested. |
|
| 1456 | - continue; |
|
| 1457 | - } |
|
| 1458 | - if (! $this->check_user_access($slug, true)) { |
|
| 1459 | - // no nav tab because current user does not have access. |
|
| 1460 | - continue; |
|
| 1461 | - } |
|
| 1462 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1463 | - $this->_nav_tabs[ $slug ] = array( |
|
| 1464 | - 'url' => isset($config['nav']['url']) |
|
| 1465 | - ? $config['nav']['url'] |
|
| 1466 | - : self::add_query_args_and_nonce( |
|
| 1467 | - array('action' => $slug), |
|
| 1468 | - $this->_admin_base_url |
|
| 1469 | - ), |
|
| 1470 | - 'link_text' => isset($config['nav']['label']) |
|
| 1471 | - ? $config['nav']['label'] |
|
| 1472 | - : ucwords( |
|
| 1473 | - str_replace('_', ' ', $slug) |
|
| 1474 | - ), |
|
| 1475 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1476 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1477 | - ); |
|
| 1478 | - $i++; |
|
| 1479 | - } |
|
| 1480 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1481 | - if (empty($this->_nav_tabs)) { |
|
| 1482 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1483 | - 'url' => $this->_admin_base_url, |
|
| 1484 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1485 | - 'css_class' => 'nav-tab-active', |
|
| 1486 | - 'order' => 10, |
|
| 1487 | - ); |
|
| 1488 | - } |
|
| 1489 | - // now let's sort the tabs according to order |
|
| 1490 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - |
|
| 1494 | - /** |
|
| 1495 | - * _set_current_labels |
|
| 1496 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1497 | - * property array |
|
| 1498 | - * |
|
| 1499 | - * @return void |
|
| 1500 | - */ |
|
| 1501 | - private function _set_current_labels() |
|
| 1502 | - { |
|
| 1503 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1504 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1505 | - if (is_array($text)) { |
|
| 1506 | - foreach ($text as $sublabel => $subtext) { |
|
| 1507 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1508 | - } |
|
| 1509 | - } else { |
|
| 1510 | - $this->_labels[ $label ] = $text; |
|
| 1511 | - } |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * verifies user access for this admin page |
|
| 1519 | - * |
|
| 1520 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1521 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1522 | - * return false if verify fail. |
|
| 1523 | - * @return bool |
|
| 1524 | - * @throws InvalidArgumentException |
|
| 1525 | - * @throws InvalidDataTypeException |
|
| 1526 | - * @throws InvalidInterfaceException |
|
| 1527 | - */ |
|
| 1528 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1529 | - { |
|
| 1530 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1531 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1532 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1533 | - && is_array( |
|
| 1534 | - $this->_page_routes[ $route_to_check ] |
|
| 1535 | - ) |
|
| 1536 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1537 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1538 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1539 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1540 | - : $this->_route['capability']; |
|
| 1541 | - } else { |
|
| 1542 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1543 | - } |
|
| 1544 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1545 | - if (! defined('DOING_AJAX') |
|
| 1546 | - && ( |
|
| 1547 | - ! function_exists('is_admin') |
|
| 1548 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1549 | - $capability, |
|
| 1550 | - $this->page_slug |
|
| 1551 | - . '_' |
|
| 1552 | - . $route_to_check, |
|
| 1553 | - $id |
|
| 1554 | - ) |
|
| 1555 | - ) |
|
| 1556 | - ) { |
|
| 1557 | - if ($verify_only) { |
|
| 1558 | - return false; |
|
| 1559 | - } |
|
| 1560 | - if (is_user_logged_in()) { |
|
| 1561 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1562 | - } else { |
|
| 1563 | - return false; |
|
| 1564 | - } |
|
| 1565 | - } |
|
| 1566 | - return true; |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * admin_init_global |
|
| 1572 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1573 | - * This method executes for ALL EE Admin pages. |
|
| 1574 | - * |
|
| 1575 | - * @return void |
|
| 1576 | - */ |
|
| 1577 | - public function admin_init_global() |
|
| 1578 | - { |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - |
|
| 1582 | - /** |
|
| 1583 | - * wp_loaded_global |
|
| 1584 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1585 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1586 | - * |
|
| 1587 | - * @return void |
|
| 1588 | - */ |
|
| 1589 | - public function wp_loaded() |
|
| 1590 | - { |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - |
|
| 1594 | - /** |
|
| 1595 | - * admin_notices |
|
| 1596 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1597 | - * ALL EE_Admin pages. |
|
| 1598 | - * |
|
| 1599 | - * @return void |
|
| 1600 | - */ |
|
| 1601 | - public function admin_notices_global() |
|
| 1602 | - { |
|
| 1603 | - $this->_display_no_javascript_warning(); |
|
| 1604 | - $this->_display_espresso_notices(); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - public function network_admin_notices_global() |
|
| 1609 | - { |
|
| 1610 | - $this->_display_no_javascript_warning(); |
|
| 1611 | - $this->_display_espresso_notices(); |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - |
|
| 1615 | - /** |
|
| 1616 | - * admin_footer_scripts_global |
|
| 1617 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1618 | - * will apply on ALL EE_Admin pages. |
|
| 1619 | - * |
|
| 1620 | - * @return void |
|
| 1621 | - */ |
|
| 1622 | - public function admin_footer_scripts_global() |
|
| 1623 | - { |
|
| 1624 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1625 | - $this->_add_admin_page_overlay(); |
|
| 1626 | - // if metaboxes are present we need to add the nonce field |
|
| 1627 | - if (isset($this->_route_config['metaboxes']) |
|
| 1628 | - || isset($this->_route_config['list_table']) |
|
| 1629 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1630 | - ) { |
|
| 1631 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1632 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1633 | - } |
|
| 1634 | - } |
|
| 1635 | - |
|
| 1636 | - |
|
| 1637 | - /** |
|
| 1638 | - * admin_footer_global |
|
| 1639 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1640 | - * ALL EE_Admin Pages. |
|
| 1641 | - * |
|
| 1642 | - * @return void |
|
| 1643 | - * @throws EE_Error |
|
| 1644 | - */ |
|
| 1645 | - public function admin_footer_global() |
|
| 1646 | - { |
|
| 1647 | - // dialog container for dialog helper |
|
| 1648 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1649 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1650 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1651 | - $d_cont .= '</div>'; |
|
| 1652 | - echo $d_cont; |
|
| 1653 | - // help tour stuff? |
|
| 1654 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1655 | - echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1656 | - } |
|
| 1657 | - // current set timezone for timezone js |
|
| 1658 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1659 | - } |
|
| 1660 | - |
|
| 1661 | - |
|
| 1662 | - /** |
|
| 1663 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1664 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1665 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1666 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1667 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1668 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1669 | - * for the |
|
| 1670 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1671 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1672 | - * 'help_trigger_id' => array( |
|
| 1673 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1674 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1675 | - * ) |
|
| 1676 | - * ); |
|
| 1677 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1678 | - * |
|
| 1679 | - * @param array $help_array |
|
| 1680 | - * @param bool $display |
|
| 1681 | - * @return string content |
|
| 1682 | - * @throws DomainException |
|
| 1683 | - * @throws EE_Error |
|
| 1684 | - */ |
|
| 1685 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1686 | - { |
|
| 1687 | - $content = ''; |
|
| 1688 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1689 | - // loop through the array and setup content |
|
| 1690 | - foreach ($help_array as $trigger => $help) { |
|
| 1691 | - // make sure the array is setup properly |
|
| 1692 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1693 | - throw new EE_Error( |
|
| 1694 | - esc_html__( |
|
| 1695 | - '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', |
|
| 1696 | - 'event_espresso' |
|
| 1697 | - ) |
|
| 1698 | - ); |
|
| 1699 | - } |
|
| 1700 | - // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1701 | - $template_args = array( |
|
| 1702 | - 'help_popup_id' => $trigger, |
|
| 1703 | - 'help_popup_title' => $help['title'], |
|
| 1704 | - 'help_popup_content' => $help['content'], |
|
| 1705 | - ); |
|
| 1706 | - $content .= EEH_Template::display_template( |
|
| 1707 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1708 | - $template_args, |
|
| 1709 | - true |
|
| 1710 | - ); |
|
| 1711 | - } |
|
| 1712 | - if ($display) { |
|
| 1713 | - echo $content; |
|
| 1714 | - return ''; |
|
| 1715 | - } |
|
| 1716 | - return $content; |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - |
|
| 1720 | - /** |
|
| 1721 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1722 | - * |
|
| 1723 | - * @return array properly formatted array for help popup content |
|
| 1724 | - * @throws EE_Error |
|
| 1725 | - */ |
|
| 1726 | - private function _get_help_content() |
|
| 1727 | - { |
|
| 1728 | - // what is the method we're looking for? |
|
| 1729 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1730 | - // if method doesn't exist let's get out. |
|
| 1731 | - if (! method_exists($this, $method_name)) { |
|
| 1732 | - return array(); |
|
| 1733 | - } |
|
| 1734 | - // k we're good to go let's retrieve the help array |
|
| 1735 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1736 | - // make sure we've got an array! |
|
| 1737 | - if (! is_array($help_array)) { |
|
| 1738 | - throw new EE_Error( |
|
| 1739 | - esc_html__( |
|
| 1740 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1741 | - 'event_espresso' |
|
| 1742 | - ) |
|
| 1743 | - ); |
|
| 1744 | - } |
|
| 1745 | - return $help_array; |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - |
|
| 1749 | - /** |
|
| 1750 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1751 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1752 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1753 | - * |
|
| 1754 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1755 | - * @param boolean $display if false then we return the trigger string |
|
| 1756 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1757 | - * @return string |
|
| 1758 | - * @throws DomainException |
|
| 1759 | - * @throws EE_Error |
|
| 1760 | - */ |
|
| 1761 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1762 | - { |
|
| 1763 | - if (defined('DOING_AJAX')) { |
|
| 1764 | - return ''; |
|
| 1765 | - } |
|
| 1766 | - // 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 |
|
| 1767 | - $help_array = $this->_get_help_content(); |
|
| 1768 | - $help_content = ''; |
|
| 1769 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1770 | - $help_array[ $trigger_id ] = array( |
|
| 1771 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1772 | - 'content' => esc_html__( |
|
| 1773 | - '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.)', |
|
| 1774 | - 'event_espresso' |
|
| 1775 | - ), |
|
| 1776 | - ); |
|
| 1777 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1778 | - } |
|
| 1779 | - // let's setup the trigger |
|
| 1780 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1781 | - . $dimensions[0] |
|
| 1782 | - . '&width=' |
|
| 1783 | - . $dimensions[1] |
|
| 1784 | - . '&inlineId=' |
|
| 1785 | - . $trigger_id |
|
| 1786 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1787 | - $content .= $help_content; |
|
| 1788 | - if ($display) { |
|
| 1789 | - echo $content; |
|
| 1790 | - return ''; |
|
| 1791 | - } |
|
| 1792 | - return $content; |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * _add_global_screen_options |
|
| 1798 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1799 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1800 | - * |
|
| 1801 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1802 | - * see also WP_Screen object documents... |
|
| 1803 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1804 | - * @abstract |
|
| 1805 | - * @return void |
|
| 1806 | - */ |
|
| 1807 | - private function _add_global_screen_options() |
|
| 1808 | - { |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - |
|
| 1812 | - /** |
|
| 1813 | - * _add_global_feature_pointers |
|
| 1814 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1815 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1816 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1817 | - * |
|
| 1818 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1819 | - * extended) also see: |
|
| 1820 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1821 | - * @abstract |
|
| 1822 | - * @return void |
|
| 1823 | - */ |
|
| 1824 | - private function _add_global_feature_pointers() |
|
| 1825 | - { |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * load_global_scripts_styles |
|
| 1831 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1832 | - * |
|
| 1833 | - * @return void |
|
| 1834 | - * @throws EE_Error |
|
| 1835 | - */ |
|
| 1836 | - public function load_global_scripts_styles() |
|
| 1837 | - { |
|
| 1838 | - /** STYLES **/ |
|
| 1839 | - // add debugging styles |
|
| 1840 | - if (WP_DEBUG) { |
|
| 1841 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1842 | - } |
|
| 1843 | - // register all styles |
|
| 1844 | - wp_register_style( |
|
| 1845 | - 'espresso-ui-theme', |
|
| 1846 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1847 | - array(), |
|
| 1848 | - EVENT_ESPRESSO_VERSION |
|
| 1849 | - ); |
|
| 1850 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1851 | - // helpers styles |
|
| 1852 | - wp_register_style( |
|
| 1853 | - 'ee-text-links', |
|
| 1854 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1855 | - array(), |
|
| 1856 | - EVENT_ESPRESSO_VERSION |
|
| 1857 | - ); |
|
| 1858 | - /** SCRIPTS **/ |
|
| 1859 | - // register all scripts |
|
| 1860 | - wp_register_script( |
|
| 1861 | - 'ee-dialog', |
|
| 1862 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1863 | - array('jquery', 'jquery-ui-draggable'), |
|
| 1864 | - EVENT_ESPRESSO_VERSION, |
|
| 1865 | - true |
|
| 1866 | - ); |
|
| 1867 | - wp_register_script( |
|
| 1868 | - 'ee_admin_js', |
|
| 1869 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1870 | - array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1871 | - EVENT_ESPRESSO_VERSION, |
|
| 1872 | - true |
|
| 1873 | - ); |
|
| 1874 | - wp_register_script( |
|
| 1875 | - 'jquery-ui-timepicker-addon', |
|
| 1876 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1877 | - array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1878 | - EVENT_ESPRESSO_VERSION, |
|
| 1879 | - true |
|
| 1880 | - ); |
|
| 1881 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1882 | - // script for sorting tables |
|
| 1883 | - wp_register_script( |
|
| 1884 | - 'espresso_ajax_table_sorting', |
|
| 1885 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1886 | - array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1887 | - EVENT_ESPRESSO_VERSION, |
|
| 1888 | - true |
|
| 1889 | - ); |
|
| 1890 | - // script for parsing uri's |
|
| 1891 | - wp_register_script( |
|
| 1892 | - 'ee-parse-uri', |
|
| 1893 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1894 | - array(), |
|
| 1895 | - EVENT_ESPRESSO_VERSION, |
|
| 1896 | - true |
|
| 1897 | - ); |
|
| 1898 | - // and parsing associative serialized form elements |
|
| 1899 | - wp_register_script( |
|
| 1900 | - 'ee-serialize-full-array', |
|
| 1901 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1902 | - array('jquery'), |
|
| 1903 | - EVENT_ESPRESSO_VERSION, |
|
| 1904 | - true |
|
| 1905 | - ); |
|
| 1906 | - // helpers scripts |
|
| 1907 | - wp_register_script( |
|
| 1908 | - 'ee-text-links', |
|
| 1909 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1910 | - array('jquery'), |
|
| 1911 | - EVENT_ESPRESSO_VERSION, |
|
| 1912 | - true |
|
| 1913 | - ); |
|
| 1914 | - wp_register_script( |
|
| 1915 | - 'ee-moment-core', |
|
| 1916 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1917 | - array(), |
|
| 1918 | - EVENT_ESPRESSO_VERSION, |
|
| 1919 | - true |
|
| 1920 | - ); |
|
| 1921 | - wp_register_script( |
|
| 1922 | - 'ee-moment', |
|
| 1923 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1924 | - array('ee-moment-core'), |
|
| 1925 | - EVENT_ESPRESSO_VERSION, |
|
| 1926 | - true |
|
| 1927 | - ); |
|
| 1928 | - wp_register_script( |
|
| 1929 | - 'ee-datepicker', |
|
| 1930 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1931 | - array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1932 | - EVENT_ESPRESSO_VERSION, |
|
| 1933 | - true |
|
| 1934 | - ); |
|
| 1935 | - // google charts |
|
| 1936 | - wp_register_script( |
|
| 1937 | - 'google-charts', |
|
| 1938 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1939 | - array(), |
|
| 1940 | - EVENT_ESPRESSO_VERSION, |
|
| 1941 | - false |
|
| 1942 | - ); |
|
| 1943 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1944 | - wp_enqueue_style('ee-admin-css'); |
|
| 1945 | - wp_enqueue_script('ee_admin_js'); |
|
| 1946 | - wp_enqueue_script('ee-accounting'); |
|
| 1947 | - wp_enqueue_script('jquery-validate'); |
|
| 1948 | - // taking care of metaboxes |
|
| 1949 | - if (empty($this->_cpt_route) |
|
| 1950 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1951 | - ) { |
|
| 1952 | - wp_enqueue_script('dashboard'); |
|
| 1953 | - } |
|
| 1954 | - // LOCALIZED DATA |
|
| 1955 | - // localize script for ajax lazy loading |
|
| 1956 | - $lazy_loader_container_ids = apply_filters( |
|
| 1957 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1958 | - array('espresso_news_post_box_content') |
|
| 1959 | - ); |
|
| 1960 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1961 | - /** |
|
| 1962 | - * help tour stuff |
|
| 1963 | - */ |
|
| 1964 | - if (! empty($this->_help_tour)) { |
|
| 1965 | - // register the js for kicking things off |
|
| 1966 | - wp_enqueue_script( |
|
| 1967 | - 'ee-help-tour', |
|
| 1968 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1969 | - array('jquery-joyride'), |
|
| 1970 | - EVENT_ESPRESSO_VERSION, |
|
| 1971 | - true |
|
| 1972 | - ); |
|
| 1973 | - $tours = array(); |
|
| 1974 | - // setup tours for the js tour object |
|
| 1975 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1976 | - if ($tour instanceof EE_Help_Tour) { |
|
| 1977 | - $tours[] = array( |
|
| 1978 | - 'id' => $tour->get_slug(), |
|
| 1979 | - 'options' => $tour->get_options(), |
|
| 1980 | - ); |
|
| 1981 | - } |
|
| 1982 | - } |
|
| 1983 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1984 | - // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1985 | - } |
|
| 1986 | - } |
|
| 1987 | - |
|
| 1988 | - |
|
| 1989 | - /** |
|
| 1990 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1991 | - * |
|
| 1992 | - * @return void |
|
| 1993 | - */ |
|
| 1994 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1995 | - { |
|
| 1996 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1997 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 1998 | - '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!!!', |
|
| 1999 | - 'event_espresso' |
|
| 2000 | - ); |
|
| 2001 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2002 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2003 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2004 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2005 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2006 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2007 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2008 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2009 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2010 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2011 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2012 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2013 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2014 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2015 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2016 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2017 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2018 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2019 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2020 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2021 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2022 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2023 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2024 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2025 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2026 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2027 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2028 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2029 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2030 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2031 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2032 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2033 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2034 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2035 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2036 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2037 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2038 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2044 | - * |
|
| 2045 | - * @return void |
|
| 2046 | - */ |
|
| 2047 | - public function add_xdebug_style() |
|
| 2048 | - { |
|
| 2049 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - |
|
| 2053 | - /************************/ |
|
| 2054 | - /** LIST TABLE METHODS **/ |
|
| 2055 | - /************************/ |
|
| 2056 | - /** |
|
| 2057 | - * this sets up the list table if the current view requires it. |
|
| 2058 | - * |
|
| 2059 | - * @return void |
|
| 2060 | - * @throws EE_Error |
|
| 2061 | - */ |
|
| 2062 | - protected function _set_list_table() |
|
| 2063 | - { |
|
| 2064 | - // first is this a list_table view? |
|
| 2065 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2066 | - return; |
|
| 2067 | - } //not a list_table view so get out. |
|
| 2068 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2069 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2070 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2071 | - // user error msg |
|
| 2072 | - $error_msg = esc_html__( |
|
| 2073 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2074 | - 'event_espresso' |
|
| 2075 | - ); |
|
| 2076 | - // developer error msg |
|
| 2077 | - $error_msg .= '||' |
|
| 2078 | - . sprintf( |
|
| 2079 | - esc_html__( |
|
| 2080 | - '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.', |
|
| 2081 | - 'event_espresso' |
|
| 2082 | - ), |
|
| 2083 | - $this->_req_action, |
|
| 2084 | - $list_table_view |
|
| 2085 | - ); |
|
| 2086 | - throw new EE_Error($error_msg); |
|
| 2087 | - } |
|
| 2088 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2089 | - $this->_views = apply_filters( |
|
| 2090 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2091 | - $this->_views |
|
| 2092 | - ); |
|
| 2093 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2094 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2095 | - $this->_set_list_table_view(); |
|
| 2096 | - $this->_set_list_table_object(); |
|
| 2097 | - } |
|
| 2098 | - |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * set current view for List Table |
|
| 2102 | - * |
|
| 2103 | - * @return void |
|
| 2104 | - */ |
|
| 2105 | - protected function _set_list_table_view() |
|
| 2106 | - { |
|
| 2107 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2108 | - // looking at active items or dumpster diving ? |
|
| 2109 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2110 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2111 | - } else { |
|
| 2112 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2113 | - } |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - |
|
| 2117 | - /** |
|
| 2118 | - * _set_list_table_object |
|
| 2119 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2120 | - * |
|
| 2121 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2122 | - * @throws \InvalidArgumentException |
|
| 2123 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2124 | - * @throws EE_Error |
|
| 2125 | - * @throws InvalidInterfaceException |
|
| 2126 | - */ |
|
| 2127 | - protected function _set_list_table_object() |
|
| 2128 | - { |
|
| 2129 | - if (isset($this->_route_config['list_table'])) { |
|
| 2130 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2131 | - throw new EE_Error( |
|
| 2132 | - sprintf( |
|
| 2133 | - esc_html__( |
|
| 2134 | - '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.', |
|
| 2135 | - 'event_espresso' |
|
| 2136 | - ), |
|
| 2137 | - $this->_route_config['list_table'], |
|
| 2138 | - get_class($this) |
|
| 2139 | - ) |
|
| 2140 | - ); |
|
| 2141 | - } |
|
| 2142 | - $this->_list_table_object = LoaderFactory::getLoader()->getShared( |
|
| 2143 | - $this->_route_config['list_table'], |
|
| 2144 | - array($this) |
|
| 2145 | - ); |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - |
|
| 2149 | - |
|
| 2150 | - /** |
|
| 2151 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2152 | - * |
|
| 2153 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2154 | - * urls. The array should be indexed by the view it is being |
|
| 2155 | - * added to. |
|
| 2156 | - * @return array |
|
| 2157 | - */ |
|
| 2158 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2159 | - { |
|
| 2160 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2161 | - if (empty($this->_views)) { |
|
| 2162 | - $this->_views = array(); |
|
| 2163 | - } |
|
| 2164 | - // cycle thru views |
|
| 2165 | - foreach ($this->_views as $key => $view) { |
|
| 2166 | - $query_args = array(); |
|
| 2167 | - // check for current view |
|
| 2168 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2169 | - $query_args['action'] = $this->_req_action; |
|
| 2170 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2171 | - $query_args['status'] = $view['slug']; |
|
| 2172 | - // merge any other arguments sent in. |
|
| 2173 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2174 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2175 | - } |
|
| 2176 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2177 | - } |
|
| 2178 | - return $this->_views; |
|
| 2179 | - } |
|
| 2180 | - |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * _entries_per_page_dropdown |
|
| 2184 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2185 | - * |
|
| 2186 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2187 | - * WP does it. |
|
| 2188 | - * @param int $max_entries total number of rows in the table |
|
| 2189 | - * @return string |
|
| 2190 | - */ |
|
| 2191 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2192 | - { |
|
| 2193 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2194 | - $values = array(10, 25, 50, 100); |
|
| 2195 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2196 | - if ($max_entries) { |
|
| 2197 | - $values[] = $max_entries; |
|
| 2198 | - sort($values); |
|
| 2199 | - } |
|
| 2200 | - $entries_per_page_dropdown = ' |
|
| 99 | + /** |
|
| 100 | + * @var array $_route_config |
|
| 101 | + */ |
|
| 102 | + protected $_route_config; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 106 | + * actions. |
|
| 107 | + * |
|
| 108 | + * @since 4.6.x |
|
| 109 | + * @var array. |
|
| 110 | + */ |
|
| 111 | + protected $_default_route_query_args; |
|
| 112 | + |
|
| 113 | + // set via request page and action args. |
|
| 114 | + protected $_current_page; |
|
| 115 | + |
|
| 116 | + protected $_current_view; |
|
| 117 | + |
|
| 118 | + protected $_current_page_view_url; |
|
| 119 | + |
|
| 120 | + // sanitized request action (and nonce) |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @var string $_req_action |
|
| 124 | + */ |
|
| 125 | + protected $_req_action; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var string $_req_nonce |
|
| 129 | + */ |
|
| 130 | + protected $_req_nonce; |
|
| 131 | + |
|
| 132 | + // search related |
|
| 133 | + protected $_search_btn_label; |
|
| 134 | + |
|
| 135 | + protected $_search_box_callback; |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * WP Current Screen object |
|
| 139 | + * |
|
| 140 | + * @var WP_Screen |
|
| 141 | + */ |
|
| 142 | + protected $_current_screen; |
|
| 143 | + |
|
| 144 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 145 | + protected $_hook_obj; |
|
| 146 | + |
|
| 147 | + // for holding incoming request data |
|
| 148 | + protected $_req_data; |
|
| 149 | + |
|
| 150 | + // yes / no array for admin form fields |
|
| 151 | + protected $_yes_no_values = array(); |
|
| 152 | + |
|
| 153 | + // some default things shared by all child classes |
|
| 154 | + protected $_default_espresso_metaboxes; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * EE_Registry Object |
|
| 158 | + * |
|
| 159 | + * @var EE_Registry |
|
| 160 | + */ |
|
| 161 | + protected $EE = null; |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 166 | + * |
|
| 167 | + * @var boolean |
|
| 168 | + */ |
|
| 169 | + protected $_is_caf = false; |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @Constructor |
|
| 174 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 175 | + * @throws EE_Error |
|
| 176 | + * @throws InvalidArgumentException |
|
| 177 | + * @throws ReflectionException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + */ |
|
| 181 | + public function __construct($routing = true) |
|
| 182 | + { |
|
| 183 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 184 | + $this->_is_caf = true; |
|
| 185 | + } |
|
| 186 | + $this->_yes_no_values = array( |
|
| 187 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 188 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 189 | + ); |
|
| 190 | + // set the _req_data property. |
|
| 191 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 192 | + // routing enabled? |
|
| 193 | + $this->_routing = $routing; |
|
| 194 | + // set initial page props (child method) |
|
| 195 | + $this->_init_page_props(); |
|
| 196 | + // set global defaults |
|
| 197 | + $this->_set_defaults(); |
|
| 198 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 199 | + $this->_global_ajax_hooks(); |
|
| 200 | + $this->_ajax_hooks(); |
|
| 201 | + // other_page_hooks have to be early too. |
|
| 202 | + $this->_do_other_page_hooks(); |
|
| 203 | + // This just allows us to have extending classes do something specific |
|
| 204 | + // before the parent constructor runs _page_setup(). |
|
| 205 | + if (method_exists($this, '_before_page_setup')) { |
|
| 206 | + $this->_before_page_setup(); |
|
| 207 | + } |
|
| 208 | + // set up page dependencies |
|
| 209 | + $this->_page_setup(); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * _init_page_props |
|
| 215 | + * Child classes use to set at least the following properties: |
|
| 216 | + * $page_slug. |
|
| 217 | + * $page_label. |
|
| 218 | + * |
|
| 219 | + * @abstract |
|
| 220 | + * @return void |
|
| 221 | + */ |
|
| 222 | + abstract protected function _init_page_props(); |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * _ajax_hooks |
|
| 227 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 228 | + * Note: within the ajax callback methods. |
|
| 229 | + * |
|
| 230 | + * @abstract |
|
| 231 | + * @return void |
|
| 232 | + */ |
|
| 233 | + abstract protected function _ajax_hooks(); |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * _define_page_props |
|
| 238 | + * child classes define page properties in here. Must include at least: |
|
| 239 | + * $_admin_base_url = base_url for all admin pages |
|
| 240 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 241 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 242 | + * array( |
|
| 243 | + * 'buttons' => array( |
|
| 244 | + * 'add' => esc_html__('label for add new button'), |
|
| 245 | + * 'edit' => esc_html__('label for edit button'), |
|
| 246 | + * 'delete' => esc_html__('label for delete button') |
|
| 247 | + * ) |
|
| 248 | + * ) |
|
| 249 | + * |
|
| 250 | + * @abstract |
|
| 251 | + * @return void |
|
| 252 | + */ |
|
| 253 | + abstract protected function _define_page_props(); |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * _set_page_routes |
|
| 258 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 259 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 260 | + * have a 'default' route. Here's the format |
|
| 261 | + * $this->_page_routes = array( |
|
| 262 | + * 'default' => array( |
|
| 263 | + * 'func' => '_default_method_handling_route', |
|
| 264 | + * 'args' => array('array','of','args'), |
|
| 265 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 266 | + * ajax request, backend processing) |
|
| 267 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 268 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 269 | + * headers sent route. |
|
| 270 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 271 | + * this route. |
|
| 272 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 273 | + * checks). |
|
| 274 | + * ), |
|
| 275 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 276 | + * handling method. |
|
| 277 | + * ) |
|
| 278 | + * ) |
|
| 279 | + * |
|
| 280 | + * @abstract |
|
| 281 | + * @return void |
|
| 282 | + */ |
|
| 283 | + abstract protected function _set_page_routes(); |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * _set_page_config |
|
| 288 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 289 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 290 | + * $this->_page_config = array( |
|
| 291 | + * 'default' => array( |
|
| 292 | + * 'labels' => array( |
|
| 293 | + * 'buttons' => array( |
|
| 294 | + * 'add' => esc_html__('label for adding item'), |
|
| 295 | + * 'edit' => esc_html__('label for editing item'), |
|
| 296 | + * 'delete' => esc_html__('label for deleting item') |
|
| 297 | + * ), |
|
| 298 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 299 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 300 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 301 | + * _define_page_props() method |
|
| 302 | + * 'nav' => array( |
|
| 303 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 304 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 305 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 306 | + * 'order' => 10, //required to indicate tab position. |
|
| 307 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 308 | + * displayed then add this parameter. |
|
| 309 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 310 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 311 | + * metaboxes set for eventespresso admin pages. |
|
| 312 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 313 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 314 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 315 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 316 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 317 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 318 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 319 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 320 | + * want to display. |
|
| 321 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 322 | + * 'tab_id' => array( |
|
| 323 | + * 'title' => 'tab_title', |
|
| 324 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 325 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 326 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 327 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 328 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 329 | + * attempt to use the callback which should match the name of a method in the class |
|
| 330 | + * ), |
|
| 331 | + * 'tab2_id' => array( |
|
| 332 | + * 'title' => 'tab2 title', |
|
| 333 | + * 'filename' => 'file_name_2' |
|
| 334 | + * 'callback' => 'callback_method_for_content', |
|
| 335 | + * ), |
|
| 336 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 337 | + * help tab area on an admin page. @link |
|
| 338 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 339 | + * 'help_tour' => array( |
|
| 340 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 341 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 342 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 343 | + * ), |
|
| 344 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 345 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 346 | + * just set |
|
| 347 | + * 'require_nonce' to FALSE |
|
| 348 | + * ) |
|
| 349 | + * ) |
|
| 350 | + * |
|
| 351 | + * @abstract |
|
| 352 | + * @return void |
|
| 353 | + */ |
|
| 354 | + abstract protected function _set_page_config(); |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** end sample help_tour methods **/ |
|
| 361 | + /** |
|
| 362 | + * _add_screen_options |
|
| 363 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 364 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 365 | + * to a particular view. |
|
| 366 | + * |
|
| 367 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 368 | + * see also WP_Screen object documents... |
|
| 369 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 370 | + * @abstract |
|
| 371 | + * @return void |
|
| 372 | + */ |
|
| 373 | + abstract protected function _add_screen_options(); |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * _add_feature_pointers |
|
| 378 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 379 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 380 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 381 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 382 | + * extended) also see: |
|
| 383 | + * |
|
| 384 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 385 | + * @abstract |
|
| 386 | + * @return void |
|
| 387 | + */ |
|
| 388 | + abstract protected function _add_feature_pointers(); |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * load_scripts_styles |
|
| 393 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 394 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 395 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 396 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 397 | + * |
|
| 398 | + * @abstract |
|
| 399 | + * @return void |
|
| 400 | + */ |
|
| 401 | + abstract public function load_scripts_styles(); |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * admin_init |
|
| 406 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 407 | + * all pages/views loaded by child class. |
|
| 408 | + * |
|
| 409 | + * @abstract |
|
| 410 | + * @return void |
|
| 411 | + */ |
|
| 412 | + abstract public function admin_init(); |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * admin_notices |
|
| 417 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 418 | + * all pages/views loaded by child class. |
|
| 419 | + * |
|
| 420 | + * @abstract |
|
| 421 | + * @return void |
|
| 422 | + */ |
|
| 423 | + abstract public function admin_notices(); |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * admin_footer_scripts |
|
| 428 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 429 | + * will apply to all pages/views loaded by child class. |
|
| 430 | + * |
|
| 431 | + * @return void |
|
| 432 | + */ |
|
| 433 | + abstract public function admin_footer_scripts(); |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * admin_footer |
|
| 438 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 439 | + * apply to all pages/views loaded by child class. |
|
| 440 | + * |
|
| 441 | + * @return void |
|
| 442 | + */ |
|
| 443 | + public function admin_footer() |
|
| 444 | + { |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * _global_ajax_hooks |
|
| 450 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 451 | + * Note: within the ajax callback methods. |
|
| 452 | + * |
|
| 453 | + * @abstract |
|
| 454 | + * @return void |
|
| 455 | + */ |
|
| 456 | + protected function _global_ajax_hooks() |
|
| 457 | + { |
|
| 458 | + // for lazy loading of metabox content |
|
| 459 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + public function ajax_metabox_content() |
|
| 464 | + { |
|
| 465 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 466 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 467 | + self::cached_rss_display($contentid, $url); |
|
| 468 | + wp_die(); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * _page_setup |
|
| 474 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 475 | + * doesn't match the object. |
|
| 476 | + * |
|
| 477 | + * @final |
|
| 478 | + * @return void |
|
| 479 | + * @throws EE_Error |
|
| 480 | + * @throws InvalidArgumentException |
|
| 481 | + * @throws ReflectionException |
|
| 482 | + * @throws InvalidDataTypeException |
|
| 483 | + * @throws InvalidInterfaceException |
|
| 484 | + */ |
|
| 485 | + final protected function _page_setup() |
|
| 486 | + { |
|
| 487 | + // requires? |
|
| 488 | + // 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. |
|
| 489 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 490 | + // next verify if we need to load anything... |
|
| 491 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 492 | + $this->page_folder = strtolower( |
|
| 493 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 494 | + ); |
|
| 495 | + global $ee_menu_slugs; |
|
| 496 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 497 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 498 | + return; |
|
| 499 | + } |
|
| 500 | + // 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 |
|
| 501 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 502 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 503 | + ? $this->_req_data['action2'] |
|
| 504 | + : $this->_req_data['action']; |
|
| 505 | + } |
|
| 506 | + // then set blank or -1 action values to 'default' |
|
| 507 | + $this->_req_action = isset($this->_req_data['action']) |
|
| 508 | + && ! empty($this->_req_data['action']) |
|
| 509 | + && $this->_req_data['action'] !== '-1' |
|
| 510 | + ? sanitize_key($this->_req_data['action']) |
|
| 511 | + : 'default'; |
|
| 512 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 513 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 514 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 515 | + ? $this->_req_data['route'] : $this->_req_action; |
|
| 516 | + // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 517 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 518 | + ? $this->_req_data['route'] |
|
| 519 | + : $this->_req_action; |
|
| 520 | + $this->_current_view = $this->_req_action; |
|
| 521 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 522 | + $this->_define_page_props(); |
|
| 523 | + $this->_current_page_view_url = add_query_arg( |
|
| 524 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 525 | + $this->_admin_base_url |
|
| 526 | + ); |
|
| 527 | + // default things |
|
| 528 | + $this->_default_espresso_metaboxes = array( |
|
| 529 | + '_espresso_news_post_box', |
|
| 530 | + '_espresso_links_post_box', |
|
| 531 | + '_espresso_ratings_request', |
|
| 532 | + '_espresso_sponsors_post_box', |
|
| 533 | + ); |
|
| 534 | + // set page configs |
|
| 535 | + $this->_set_page_routes(); |
|
| 536 | + $this->_set_page_config(); |
|
| 537 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 538 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 539 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 540 | + } |
|
| 541 | + // for caffeinated and other extended functionality. |
|
| 542 | + // If there is a _extend_page_config method |
|
| 543 | + // then let's run that to modify the all the various page configuration arrays |
|
| 544 | + if (method_exists($this, '_extend_page_config')) { |
|
| 545 | + $this->_extend_page_config(); |
|
| 546 | + } |
|
| 547 | + // for CPT and other extended functionality. |
|
| 548 | + // If there is an _extend_page_config_for_cpt |
|
| 549 | + // then let's run that to modify all the various page configuration arrays. |
|
| 550 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 551 | + $this->_extend_page_config_for_cpt(); |
|
| 552 | + } |
|
| 553 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 554 | + $this->_page_routes = apply_filters( |
|
| 555 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 556 | + $this->_page_routes, |
|
| 557 | + $this |
|
| 558 | + ); |
|
| 559 | + $this->_page_config = apply_filters( |
|
| 560 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 561 | + $this->_page_config, |
|
| 562 | + $this |
|
| 563 | + ); |
|
| 564 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 565 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 566 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 567 | + add_action( |
|
| 568 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 569 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 570 | + 10, |
|
| 571 | + 2 |
|
| 572 | + ); |
|
| 573 | + } |
|
| 574 | + // next route only if routing enabled |
|
| 575 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 576 | + $this->_verify_routes(); |
|
| 577 | + // next let's just check user_access and kill if no access |
|
| 578 | + $this->check_user_access(); |
|
| 579 | + if ($this->_is_UI_request) { |
|
| 580 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 581 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 582 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 583 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 584 | + } |
|
| 585 | + } else { |
|
| 586 | + // hijack regular WP loading and route admin request immediately |
|
| 587 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 588 | + $this->route_admin_request(); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 596 | + * |
|
| 597 | + * @return void |
|
| 598 | + * @throws ReflectionException |
|
| 599 | + * @throws EE_Error |
|
| 600 | + */ |
|
| 601 | + private function _do_other_page_hooks() |
|
| 602 | + { |
|
| 603 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 604 | + foreach ($registered_pages as $page) { |
|
| 605 | + // now let's setup the file name and class that should be present |
|
| 606 | + $classname = str_replace('.class.php', '', $page); |
|
| 607 | + // autoloaders should take care of loading file |
|
| 608 | + if (! class_exists($classname)) { |
|
| 609 | + $error_msg[] = sprintf( |
|
| 610 | + esc_html__( |
|
| 611 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 612 | + 'event_espresso' |
|
| 613 | + ), |
|
| 614 | + $page |
|
| 615 | + ); |
|
| 616 | + $error_msg[] = $error_msg[0] |
|
| 617 | + . "\r\n" |
|
| 618 | + . sprintf( |
|
| 619 | + esc_html__( |
|
| 620 | + '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', |
|
| 621 | + 'event_espresso' |
|
| 622 | + ), |
|
| 623 | + $page, |
|
| 624 | + '<br />', |
|
| 625 | + '<strong>' . $classname . '</strong>' |
|
| 626 | + ); |
|
| 627 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 628 | + } |
|
| 629 | + $a = new ReflectionClass($classname); |
|
| 630 | + // notice we are passing the instance of this class to the hook object. |
|
| 631 | + $hookobj[] = $a->newInstance($this); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + public function load_page_dependencies() |
|
| 637 | + { |
|
| 638 | + try { |
|
| 639 | + $this->_load_page_dependencies(); |
|
| 640 | + } catch (EE_Error $e) { |
|
| 641 | + $e->get_error(); |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * load_page_dependencies |
|
| 648 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 649 | + * |
|
| 650 | + * @return void |
|
| 651 | + * @throws DomainException |
|
| 652 | + * @throws EE_Error |
|
| 653 | + * @throws InvalidArgumentException |
|
| 654 | + * @throws InvalidDataTypeException |
|
| 655 | + * @throws InvalidInterfaceException |
|
| 656 | + * @throws ReflectionException |
|
| 657 | + */ |
|
| 658 | + protected function _load_page_dependencies() |
|
| 659 | + { |
|
| 660 | + // let's set the current_screen and screen options to override what WP set |
|
| 661 | + $this->_current_screen = get_current_screen(); |
|
| 662 | + // load admin_notices - global, page class, and view specific |
|
| 663 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 664 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 665 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 666 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 667 | + } |
|
| 668 | + // load network admin_notices - global, page class, and view specific |
|
| 669 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 670 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 671 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 672 | + } |
|
| 673 | + // this will save any per_page screen options if they are present |
|
| 674 | + $this->_set_per_page_screen_options(); |
|
| 675 | + // setup list table properties |
|
| 676 | + $this->_set_list_table(); |
|
| 677 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 678 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 679 | + $this->_add_registered_meta_boxes(); |
|
| 680 | + $this->_add_screen_columns(); |
|
| 681 | + // add screen options - global, page child class, and view specific |
|
| 682 | + $this->_add_global_screen_options(); |
|
| 683 | + $this->_add_screen_options(); |
|
| 684 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 685 | + if (method_exists($this, $add_screen_options)) { |
|
| 686 | + $this->{$add_screen_options}(); |
|
| 687 | + } |
|
| 688 | + // add help tab(s) and tours- set via page_config and qtips. |
|
| 689 | + $this->_add_help_tour(); |
|
| 690 | + $this->_add_help_tabs(); |
|
| 691 | + $this->_add_qtips(); |
|
| 692 | + // add feature_pointers - global, page child class, and view specific |
|
| 693 | + $this->_add_feature_pointers(); |
|
| 694 | + $this->_add_global_feature_pointers(); |
|
| 695 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 696 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 697 | + $this->{$add_feature_pointer}(); |
|
| 698 | + } |
|
| 699 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 700 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 701 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 702 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 703 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 704 | + } |
|
| 705 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 706 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 707 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 708 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 709 | + // is a good use case. Notice the late priority we're giving these |
|
| 710 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 711 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 712 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 713 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 714 | + } |
|
| 715 | + // admin footer scripts |
|
| 716 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 717 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 718 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 719 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 720 | + } |
|
| 721 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 722 | + // targeted hook |
|
| 723 | + do_action( |
|
| 724 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 725 | + ); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * _set_defaults |
|
| 731 | + * This sets some global defaults for class properties. |
|
| 732 | + */ |
|
| 733 | + private function _set_defaults() |
|
| 734 | + { |
|
| 735 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 736 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 737 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 738 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
| 739 | + $this->_default_nav_tab_name = 'overview'; |
|
| 740 | + // init template args |
|
| 741 | + $this->_template_args = array( |
|
| 742 | + 'admin_page_header' => '', |
|
| 743 | + 'admin_page_content' => '', |
|
| 744 | + 'post_body_content' => '', |
|
| 745 | + 'before_list_table' => '', |
|
| 746 | + 'after_list_table' => '', |
|
| 747 | + ); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * route_admin_request |
|
| 753 | + * |
|
| 754 | + * @see _route_admin_request() |
|
| 755 | + * @return exception|void error |
|
| 756 | + * @throws InvalidArgumentException |
|
| 757 | + * @throws InvalidInterfaceException |
|
| 758 | + * @throws InvalidDataTypeException |
|
| 759 | + * @throws EE_Error |
|
| 760 | + * @throws ReflectionException |
|
| 761 | + */ |
|
| 762 | + public function route_admin_request() |
|
| 763 | + { |
|
| 764 | + try { |
|
| 765 | + $this->_route_admin_request(); |
|
| 766 | + } catch (EE_Error $e) { |
|
| 767 | + $e->get_error(); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + public function set_wp_page_slug($wp_page_slug) |
|
| 773 | + { |
|
| 774 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 775 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 776 | + if (is_network_admin()) { |
|
| 777 | + $this->_wp_page_slug .= '-network'; |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * _verify_routes |
|
| 784 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 785 | + * we know if we need to drop out. |
|
| 786 | + * |
|
| 787 | + * @return bool |
|
| 788 | + * @throws EE_Error |
|
| 789 | + */ |
|
| 790 | + protected function _verify_routes() |
|
| 791 | + { |
|
| 792 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 793 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 794 | + return false; |
|
| 795 | + } |
|
| 796 | + $this->_route = false; |
|
| 797 | + // check that the page_routes array is not empty |
|
| 798 | + if (empty($this->_page_routes)) { |
|
| 799 | + // user error msg |
|
| 800 | + $error_msg = sprintf( |
|
| 801 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 802 | + $this->_admin_page_title |
|
| 803 | + ); |
|
| 804 | + // developer error msg |
|
| 805 | + $error_msg .= '||' . $error_msg |
|
| 806 | + . esc_html__( |
|
| 807 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 808 | + 'event_espresso' |
|
| 809 | + ); |
|
| 810 | + throw new EE_Error($error_msg); |
|
| 811 | + } |
|
| 812 | + // and that the requested page route exists |
|
| 813 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 814 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 815 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 816 | + ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 817 | + } else { |
|
| 818 | + // user error msg |
|
| 819 | + $error_msg = sprintf( |
|
| 820 | + esc_html__( |
|
| 821 | + 'The requested page route does not exist for the %s admin page.', |
|
| 822 | + 'event_espresso' |
|
| 823 | + ), |
|
| 824 | + $this->_admin_page_title |
|
| 825 | + ); |
|
| 826 | + // developer error msg |
|
| 827 | + $error_msg .= '||' . $error_msg |
|
| 828 | + . sprintf( |
|
| 829 | + esc_html__( |
|
| 830 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 831 | + 'event_espresso' |
|
| 832 | + ), |
|
| 833 | + $this->_req_action |
|
| 834 | + ); |
|
| 835 | + throw new EE_Error($error_msg); |
|
| 836 | + } |
|
| 837 | + // and that a default route exists |
|
| 838 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 839 | + // user error msg |
|
| 840 | + $error_msg = sprintf( |
|
| 841 | + esc_html__( |
|
| 842 | + 'A default page route has not been set for the % admin page.', |
|
| 843 | + 'event_espresso' |
|
| 844 | + ), |
|
| 845 | + $this->_admin_page_title |
|
| 846 | + ); |
|
| 847 | + // developer error msg |
|
| 848 | + $error_msg .= '||' . $error_msg |
|
| 849 | + . esc_html__( |
|
| 850 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ); |
|
| 853 | + throw new EE_Error($error_msg); |
|
| 854 | + } |
|
| 855 | + // first lets' catch if the UI request has EVER been set. |
|
| 856 | + if ($this->_is_UI_request === null) { |
|
| 857 | + // lets set if this is a UI request or not. |
|
| 858 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 859 | + // wait a minute... we might have a noheader in the route array |
|
| 860 | + $this->_is_UI_request = is_array($this->_route) |
|
| 861 | + && isset($this->_route['noheader']) |
|
| 862 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 863 | + } |
|
| 864 | + $this->_set_current_labels(); |
|
| 865 | + return true; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 871 | + * |
|
| 872 | + * @param string $route the route name we're verifying |
|
| 873 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 874 | + * @throws EE_Error |
|
| 875 | + */ |
|
| 876 | + protected function _verify_route($route) |
|
| 877 | + { |
|
| 878 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 879 | + return true; |
|
| 880 | + } |
|
| 881 | + // user error msg |
|
| 882 | + $error_msg = sprintf( |
|
| 883 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 884 | + $this->_admin_page_title |
|
| 885 | + ); |
|
| 886 | + // developer error msg |
|
| 887 | + $error_msg .= '||' . $error_msg |
|
| 888 | + . sprintf( |
|
| 889 | + esc_html__( |
|
| 890 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 891 | + 'event_espresso' |
|
| 892 | + ), |
|
| 893 | + $route |
|
| 894 | + ); |
|
| 895 | + throw new EE_Error($error_msg); |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * perform nonce verification |
|
| 901 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 902 | + * using this method (and save retyping!) |
|
| 903 | + * |
|
| 904 | + * @param string $nonce The nonce sent |
|
| 905 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 906 | + * @return void |
|
| 907 | + * @throws EE_Error |
|
| 908 | + */ |
|
| 909 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 910 | + { |
|
| 911 | + // verify nonce against expected value |
|
| 912 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 913 | + // these are not the droids you are looking for !!! |
|
| 914 | + $msg = sprintf( |
|
| 915 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 916 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 917 | + '</a>' |
|
| 918 | + ); |
|
| 919 | + if (WP_DEBUG) { |
|
| 920 | + $msg .= "\n " |
|
| 921 | + . sprintf( |
|
| 922 | + esc_html__( |
|
| 923 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 924 | + 'event_espresso' |
|
| 925 | + ), |
|
| 926 | + __CLASS__ |
|
| 927 | + ); |
|
| 928 | + } |
|
| 929 | + if (! defined('DOING_AJAX')) { |
|
| 930 | + wp_die($msg); |
|
| 931 | + } else { |
|
| 932 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 933 | + $this->_return_json(); |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * _route_admin_request() |
|
| 941 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 942 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 943 | + * in the page routes and then will try to load the corresponding method. |
|
| 944 | + * |
|
| 945 | + * @return void |
|
| 946 | + * @throws EE_Error |
|
| 947 | + * @throws InvalidArgumentException |
|
| 948 | + * @throws InvalidDataTypeException |
|
| 949 | + * @throws InvalidInterfaceException |
|
| 950 | + * @throws ReflectionException |
|
| 951 | + */ |
|
| 952 | + protected function _route_admin_request() |
|
| 953 | + { |
|
| 954 | + if (! $this->_is_UI_request) { |
|
| 955 | + $this->_verify_routes(); |
|
| 956 | + } |
|
| 957 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 958 | + ? $this->_route_config['require_nonce'] |
|
| 959 | + : true; |
|
| 960 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 961 | + // set nonce from post data |
|
| 962 | + $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 963 | + ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 964 | + : ''; |
|
| 965 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 966 | + } |
|
| 967 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 968 | + if ($this->_is_UI_request) { |
|
| 969 | + $this->_set_nav_tabs(); |
|
| 970 | + } |
|
| 971 | + // grab callback function |
|
| 972 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 973 | + // check if callback has args |
|
| 974 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 975 | + $error_msg = ''; |
|
| 976 | + // action right before calling route |
|
| 977 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 978 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 979 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 980 | + } |
|
| 981 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 982 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 983 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 984 | + '_wp_http_referer', |
|
| 985 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
| 986 | + ); |
|
| 987 | + if (! empty($func)) { |
|
| 988 | + if (is_array($func)) { |
|
| 989 | + list($class, $method) = $func; |
|
| 990 | + } elseif (strpos($func, '::') !== false) { |
|
| 991 | + list($class, $method) = explode('::', $func); |
|
| 992 | + } else { |
|
| 993 | + $class = $this; |
|
| 994 | + $method = $func; |
|
| 995 | + } |
|
| 996 | + if (! (is_object($class) && $class === $this)) { |
|
| 997 | + // send along this admin page object for access by addons. |
|
| 998 | + $args['admin_page_object'] = $this; |
|
| 999 | + } |
|
| 1000 | + if (// is it a method on a class that doesn't work? |
|
| 1001 | + ( |
|
| 1002 | + ( |
|
| 1003 | + method_exists($class, $method) |
|
| 1004 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 1005 | + ) |
|
| 1006 | + && ( |
|
| 1007 | + // is it a standalone function that doesn't work? |
|
| 1008 | + function_exists($method) |
|
| 1009 | + && call_user_func_array( |
|
| 1010 | + $func, |
|
| 1011 | + array_merge(array('admin_page_object' => $this), $args) |
|
| 1012 | + ) === false |
|
| 1013 | + ) |
|
| 1014 | + ) |
|
| 1015 | + || ( |
|
| 1016 | + // is it neither a class method NOR a standalone function? |
|
| 1017 | + ! method_exists($class, $method) |
|
| 1018 | + && ! function_exists($method) |
|
| 1019 | + ) |
|
| 1020 | + ) { |
|
| 1021 | + // user error msg |
|
| 1022 | + $error_msg = esc_html__( |
|
| 1023 | + 'An error occurred. The requested page route could not be found.', |
|
| 1024 | + 'event_espresso' |
|
| 1025 | + ); |
|
| 1026 | + // developer error msg |
|
| 1027 | + $error_msg .= '||'; |
|
| 1028 | + $error_msg .= sprintf( |
|
| 1029 | + esc_html__( |
|
| 1030 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1031 | + 'event_espresso' |
|
| 1032 | + ), |
|
| 1033 | + $method |
|
| 1034 | + ); |
|
| 1035 | + } |
|
| 1036 | + if (! empty($error_msg)) { |
|
| 1037 | + throw new EE_Error($error_msg); |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1041 | + // then we need to reset the routing properties to the new route. |
|
| 1042 | + // 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. |
|
| 1043 | + if ($this->_is_UI_request === false |
|
| 1044 | + && is_array($this->_route) |
|
| 1045 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1046 | + ) { |
|
| 1047 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1048 | + } |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1054 | + * route redirects to a headers route in its route config. |
|
| 1055 | + * |
|
| 1056 | + * @since 4.3.0 |
|
| 1057 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1058 | + * @return void |
|
| 1059 | + * @throws ReflectionException |
|
| 1060 | + * @throws InvalidArgumentException |
|
| 1061 | + * @throws InvalidInterfaceException |
|
| 1062 | + * @throws InvalidDataTypeException |
|
| 1063 | + * @throws EE_Error |
|
| 1064 | + */ |
|
| 1065 | + protected function _reset_routing_properties($new_route) |
|
| 1066 | + { |
|
| 1067 | + $this->_is_UI_request = true; |
|
| 1068 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1069 | + $this->_req_data['action'] = $new_route; |
|
| 1070 | + // rerun page setup |
|
| 1071 | + $this->_page_setup(); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * _add_query_arg |
|
| 1077 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1078 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1079 | + * |
|
| 1080 | + * @param array $args |
|
| 1081 | + * @param string $url |
|
| 1082 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1083 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1084 | + * Example usage: If the current page is: |
|
| 1085 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1086 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1087 | + * &_wpnonce=5467821 |
|
| 1088 | + * and you call: |
|
| 1089 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1090 | + * array( |
|
| 1091 | + * 'action' => 'resend_something', |
|
| 1092 | + * 'page=>espresso_registrations' |
|
| 1093 | + * ), |
|
| 1094 | + * $some_url, |
|
| 1095 | + * true |
|
| 1096 | + * ); |
|
| 1097 | + * It will produce a url in this structure: |
|
| 1098 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1099 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1100 | + * month_range]=March%202015 |
|
| 1101 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1102 | + * @return string |
|
| 1103 | + */ |
|
| 1104 | + public static function add_query_args_and_nonce( |
|
| 1105 | + $args = array(), |
|
| 1106 | + $url = false, |
|
| 1107 | + $sticky = false, |
|
| 1108 | + $exclude_nonce = false |
|
| 1109 | + ) { |
|
| 1110 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1111 | + if ($sticky) { |
|
| 1112 | + $request = $_REQUEST; |
|
| 1113 | + unset($request['_wp_http_referer']); |
|
| 1114 | + unset($request['wp_referer']); |
|
| 1115 | + foreach ($request as $key => $value) { |
|
| 1116 | + // do not add nonces |
|
| 1117 | + if (strpos($key, 'nonce') !== false) { |
|
| 1118 | + continue; |
|
| 1119 | + } |
|
| 1120 | + $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * This returns a generated link that will load the related help tab. |
|
| 1129 | + * |
|
| 1130 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1131 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1132 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1133 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1134 | + * @return string generated link |
|
| 1135 | + */ |
|
| 1136 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1137 | + { |
|
| 1138 | + return EEH_Template::get_help_tab_link( |
|
| 1139 | + $help_tab_id, |
|
| 1140 | + $this->page_slug, |
|
| 1141 | + $this->_req_action, |
|
| 1142 | + $icon_style, |
|
| 1143 | + $help_text |
|
| 1144 | + ); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * _add_help_tabs |
|
| 1150 | + * Note child classes define their help tabs within the page_config array. |
|
| 1151 | + * |
|
| 1152 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1153 | + * @return void |
|
| 1154 | + * @throws DomainException |
|
| 1155 | + * @throws EE_Error |
|
| 1156 | + */ |
|
| 1157 | + protected function _add_help_tabs() |
|
| 1158 | + { |
|
| 1159 | + $tour_buttons = ''; |
|
| 1160 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1161 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1162 | + // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1163 | + if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1164 | + $tb = array(); |
|
| 1165 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1166 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1167 | + // if this is the end tour then we don't need to setup a button |
|
| 1168 | + if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1169 | + continue; |
|
| 1170 | + } |
|
| 1171 | + $tb[] = '<button id="trigger-tour-' |
|
| 1172 | + . $tour->get_slug() |
|
| 1173 | + . '" class="button-primary trigger-ee-help-tour">' |
|
| 1174 | + . $tour->get_label() |
|
| 1175 | + . '</button>'; |
|
| 1176 | + } |
|
| 1177 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1178 | + $tour_buttons .= '</div></div>'; |
|
| 1179 | + } |
|
| 1180 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1181 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1182 | + // check that the callback given is valid |
|
| 1183 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1184 | + throw new EE_Error( |
|
| 1185 | + sprintf( |
|
| 1186 | + esc_html__( |
|
| 1187 | + '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', |
|
| 1188 | + 'event_espresso' |
|
| 1189 | + ), |
|
| 1190 | + $config['help_sidebar'], |
|
| 1191 | + get_class($this) |
|
| 1192 | + ) |
|
| 1193 | + ); |
|
| 1194 | + } |
|
| 1195 | + $content = apply_filters( |
|
| 1196 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1197 | + $this->{$config['help_sidebar']}() |
|
| 1198 | + ); |
|
| 1199 | + $content .= $tour_buttons; // add help tour buttons. |
|
| 1200 | + // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1201 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1202 | + } |
|
| 1203 | + // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1204 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1205 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1206 | + } |
|
| 1207 | + // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1208 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1209 | + $_ht['id'] = $this->page_slug; |
|
| 1210 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1211 | + $_ht['content'] = '<p>' |
|
| 1212 | + . esc_html__( |
|
| 1213 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1214 | + 'event_espresso' |
|
| 1215 | + ) . '</p>'; |
|
| 1216 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1217 | + } |
|
| 1218 | + if (! isset($config['help_tabs'])) { |
|
| 1219 | + return; |
|
| 1220 | + } //no help tabs for this route |
|
| 1221 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1222 | + // we're here so there ARE help tabs! |
|
| 1223 | + // make sure we've got what we need |
|
| 1224 | + if (! isset($cfg['title'])) { |
|
| 1225 | + throw new EE_Error( |
|
| 1226 | + esc_html__( |
|
| 1227 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1228 | + 'event_espresso' |
|
| 1229 | + ) |
|
| 1230 | + ); |
|
| 1231 | + } |
|
| 1232 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1233 | + throw new EE_Error( |
|
| 1234 | + esc_html__( |
|
| 1235 | + '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', |
|
| 1236 | + 'event_espresso' |
|
| 1237 | + ) |
|
| 1238 | + ); |
|
| 1239 | + } |
|
| 1240 | + // first priority goes to content. |
|
| 1241 | + if (! empty($cfg['content'])) { |
|
| 1242 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1243 | + // second priority goes to filename |
|
| 1244 | + } elseif (! empty($cfg['filename'])) { |
|
| 1245 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1246 | + // 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) |
|
| 1247 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1248 | + . basename($this->_get_dir()) |
|
| 1249 | + . '/help_tabs/' |
|
| 1250 | + . $cfg['filename'] |
|
| 1251 | + . '.help_tab.php' : $file_path; |
|
| 1252 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1253 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1254 | + EE_Error::add_error( |
|
| 1255 | + sprintf( |
|
| 1256 | + esc_html__( |
|
| 1257 | + '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', |
|
| 1258 | + 'event_espresso' |
|
| 1259 | + ), |
|
| 1260 | + $tab_id, |
|
| 1261 | + key($config), |
|
| 1262 | + $file_path |
|
| 1263 | + ), |
|
| 1264 | + __FILE__, |
|
| 1265 | + __FUNCTION__, |
|
| 1266 | + __LINE__ |
|
| 1267 | + ); |
|
| 1268 | + return; |
|
| 1269 | + } |
|
| 1270 | + $template_args['admin_page_obj'] = $this; |
|
| 1271 | + $content = EEH_Template::display_template( |
|
| 1272 | + $file_path, |
|
| 1273 | + $template_args, |
|
| 1274 | + true |
|
| 1275 | + ); |
|
| 1276 | + } else { |
|
| 1277 | + $content = ''; |
|
| 1278 | + } |
|
| 1279 | + // check if callback is valid |
|
| 1280 | + if (empty($content) && ( |
|
| 1281 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1282 | + ) |
|
| 1283 | + ) { |
|
| 1284 | + EE_Error::add_error( |
|
| 1285 | + sprintf( |
|
| 1286 | + esc_html__( |
|
| 1287 | + '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.', |
|
| 1288 | + 'event_espresso' |
|
| 1289 | + ), |
|
| 1290 | + $cfg['title'] |
|
| 1291 | + ), |
|
| 1292 | + __FILE__, |
|
| 1293 | + __FUNCTION__, |
|
| 1294 | + __LINE__ |
|
| 1295 | + ); |
|
| 1296 | + return; |
|
| 1297 | + } |
|
| 1298 | + // setup config array for help tab method |
|
| 1299 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1300 | + $_ht = array( |
|
| 1301 | + 'id' => $id, |
|
| 1302 | + 'title' => $cfg['title'], |
|
| 1303 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1304 | + 'content' => $content, |
|
| 1305 | + ); |
|
| 1306 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1314 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1315 | + * |
|
| 1316 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1317 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1318 | + * _set_page_config() comments |
|
| 1319 | + * @return void |
|
| 1320 | + * @throws EE_Error |
|
| 1321 | + * @throws InvalidArgumentException |
|
| 1322 | + * @throws InvalidDataTypeException |
|
| 1323 | + * @throws InvalidInterfaceException |
|
| 1324 | + */ |
|
| 1325 | + protected function _add_help_tour() |
|
| 1326 | + { |
|
| 1327 | + $tours = array(); |
|
| 1328 | + $this->_help_tour = array(); |
|
| 1329 | + // exit early if help tours are turned off globally |
|
| 1330 | + if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1331 | + || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1332 | + ) { |
|
| 1333 | + return; |
|
| 1334 | + } |
|
| 1335 | + // loop through _page_config to find any help_tour defined |
|
| 1336 | + foreach ($this->_page_config as $route => $config) { |
|
| 1337 | + // we're only going to set things up for this route |
|
| 1338 | + if ($route !== $this->_req_action) { |
|
| 1339 | + continue; |
|
| 1340 | + } |
|
| 1341 | + if (isset($config['help_tour'])) { |
|
| 1342 | + foreach ($config['help_tour'] as $tour) { |
|
| 1343 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1344 | + // let's see if we can get that file... |
|
| 1345 | + // if not its possible this is a decaf route not set in caffeinated |
|
| 1346 | + // so lets try and get the caffeinated equivalent |
|
| 1347 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1348 | + . basename($this->_get_dir()) |
|
| 1349 | + . '/help_tours/' |
|
| 1350 | + . $tour |
|
| 1351 | + . '.class.php' : $file_path; |
|
| 1352 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1353 | + if (! is_readable($file_path)) { |
|
| 1354 | + EE_Error::add_error( |
|
| 1355 | + sprintf( |
|
| 1356 | + esc_html__( |
|
| 1357 | + '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', |
|
| 1358 | + 'event_espresso' |
|
| 1359 | + ), |
|
| 1360 | + $file_path, |
|
| 1361 | + $tour |
|
| 1362 | + ), |
|
| 1363 | + __FILE__, |
|
| 1364 | + __FUNCTION__, |
|
| 1365 | + __LINE__ |
|
| 1366 | + ); |
|
| 1367 | + return; |
|
| 1368 | + } |
|
| 1369 | + require_once $file_path; |
|
| 1370 | + if (! class_exists($tour)) { |
|
| 1371 | + $error_msg[] = sprintf( |
|
| 1372 | + esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1373 | + $tour |
|
| 1374 | + ); |
|
| 1375 | + $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1376 | + . sprintf( |
|
| 1377 | + esc_html__( |
|
| 1378 | + '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.', |
|
| 1379 | + 'event_espresso' |
|
| 1380 | + ), |
|
| 1381 | + $tour, |
|
| 1382 | + '<br />', |
|
| 1383 | + $tour, |
|
| 1384 | + $this->_req_action, |
|
| 1385 | + get_class($this) |
|
| 1386 | + ); |
|
| 1387 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1388 | + } |
|
| 1389 | + $tour_obj = new $tour($this->_is_caf); |
|
| 1390 | + $tours[] = $tour_obj; |
|
| 1391 | + $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1392 | + } |
|
| 1393 | + // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1394 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1395 | + $tours[] = $end_stop_tour; |
|
| 1396 | + $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + if (! empty($tours)) { |
|
| 1400 | + $this->_help_tour['tours'] = $tours; |
|
| 1401 | + } |
|
| 1402 | + // that's it! Now that the $_help_tours property is set (or not) |
|
| 1403 | + // the scripts and html should be taken care of automatically. |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + |
|
| 1407 | + /** |
|
| 1408 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1409 | + * |
|
| 1410 | + * @return void |
|
| 1411 | + */ |
|
| 1412 | + protected function _add_qtips() |
|
| 1413 | + { |
|
| 1414 | + if (isset($this->_route_config['qtips'])) { |
|
| 1415 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1416 | + // load qtip loader |
|
| 1417 | + $path = array( |
|
| 1418 | + $this->_get_dir() . '/qtips/', |
|
| 1419 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1420 | + ); |
|
| 1421 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * _set_nav_tabs |
|
| 1428 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1429 | + * wish to add additional tabs or modify accordingly. |
|
| 1430 | + * |
|
| 1431 | + * @return void |
|
| 1432 | + * @throws InvalidArgumentException |
|
| 1433 | + * @throws InvalidInterfaceException |
|
| 1434 | + * @throws InvalidDataTypeException |
|
| 1435 | + */ |
|
| 1436 | + protected function _set_nav_tabs() |
|
| 1437 | + { |
|
| 1438 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1439 | + $i = 0; |
|
| 1440 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1441 | + if (! is_array($config) |
|
| 1442 | + || ( |
|
| 1443 | + is_array($config) |
|
| 1444 | + && ( |
|
| 1445 | + (isset($config['nav']) && ! $config['nav']) |
|
| 1446 | + || ! isset($config['nav']) |
|
| 1447 | + ) |
|
| 1448 | + ) |
|
| 1449 | + ) { |
|
| 1450 | + continue; |
|
| 1451 | + } |
|
| 1452 | + // no nav tab for this config |
|
| 1453 | + // check for persistent flag |
|
| 1454 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1455 | + // nav tab is only to appear when route requested. |
|
| 1456 | + continue; |
|
| 1457 | + } |
|
| 1458 | + if (! $this->check_user_access($slug, true)) { |
|
| 1459 | + // no nav tab because current user does not have access. |
|
| 1460 | + continue; |
|
| 1461 | + } |
|
| 1462 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1463 | + $this->_nav_tabs[ $slug ] = array( |
|
| 1464 | + 'url' => isset($config['nav']['url']) |
|
| 1465 | + ? $config['nav']['url'] |
|
| 1466 | + : self::add_query_args_and_nonce( |
|
| 1467 | + array('action' => $slug), |
|
| 1468 | + $this->_admin_base_url |
|
| 1469 | + ), |
|
| 1470 | + 'link_text' => isset($config['nav']['label']) |
|
| 1471 | + ? $config['nav']['label'] |
|
| 1472 | + : ucwords( |
|
| 1473 | + str_replace('_', ' ', $slug) |
|
| 1474 | + ), |
|
| 1475 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1476 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1477 | + ); |
|
| 1478 | + $i++; |
|
| 1479 | + } |
|
| 1480 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1481 | + if (empty($this->_nav_tabs)) { |
|
| 1482 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1483 | + 'url' => $this->_admin_base_url, |
|
| 1484 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1485 | + 'css_class' => 'nav-tab-active', |
|
| 1486 | + 'order' => 10, |
|
| 1487 | + ); |
|
| 1488 | + } |
|
| 1489 | + // now let's sort the tabs according to order |
|
| 1490 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + |
|
| 1494 | + /** |
|
| 1495 | + * _set_current_labels |
|
| 1496 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1497 | + * property array |
|
| 1498 | + * |
|
| 1499 | + * @return void |
|
| 1500 | + */ |
|
| 1501 | + private function _set_current_labels() |
|
| 1502 | + { |
|
| 1503 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1504 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1505 | + if (is_array($text)) { |
|
| 1506 | + foreach ($text as $sublabel => $subtext) { |
|
| 1507 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1508 | + } |
|
| 1509 | + } else { |
|
| 1510 | + $this->_labels[ $label ] = $text; |
|
| 1511 | + } |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * verifies user access for this admin page |
|
| 1519 | + * |
|
| 1520 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1521 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1522 | + * return false if verify fail. |
|
| 1523 | + * @return bool |
|
| 1524 | + * @throws InvalidArgumentException |
|
| 1525 | + * @throws InvalidDataTypeException |
|
| 1526 | + * @throws InvalidInterfaceException |
|
| 1527 | + */ |
|
| 1528 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1529 | + { |
|
| 1530 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1531 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1532 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1533 | + && is_array( |
|
| 1534 | + $this->_page_routes[ $route_to_check ] |
|
| 1535 | + ) |
|
| 1536 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1537 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1538 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1539 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1540 | + : $this->_route['capability']; |
|
| 1541 | + } else { |
|
| 1542 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1543 | + } |
|
| 1544 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1545 | + if (! defined('DOING_AJAX') |
|
| 1546 | + && ( |
|
| 1547 | + ! function_exists('is_admin') |
|
| 1548 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1549 | + $capability, |
|
| 1550 | + $this->page_slug |
|
| 1551 | + . '_' |
|
| 1552 | + . $route_to_check, |
|
| 1553 | + $id |
|
| 1554 | + ) |
|
| 1555 | + ) |
|
| 1556 | + ) { |
|
| 1557 | + if ($verify_only) { |
|
| 1558 | + return false; |
|
| 1559 | + } |
|
| 1560 | + if (is_user_logged_in()) { |
|
| 1561 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1562 | + } else { |
|
| 1563 | + return false; |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1566 | + return true; |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * admin_init_global |
|
| 1572 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1573 | + * This method executes for ALL EE Admin pages. |
|
| 1574 | + * |
|
| 1575 | + * @return void |
|
| 1576 | + */ |
|
| 1577 | + public function admin_init_global() |
|
| 1578 | + { |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + |
|
| 1582 | + /** |
|
| 1583 | + * wp_loaded_global |
|
| 1584 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1585 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1586 | + * |
|
| 1587 | + * @return void |
|
| 1588 | + */ |
|
| 1589 | + public function wp_loaded() |
|
| 1590 | + { |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + |
|
| 1594 | + /** |
|
| 1595 | + * admin_notices |
|
| 1596 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1597 | + * ALL EE_Admin pages. |
|
| 1598 | + * |
|
| 1599 | + * @return void |
|
| 1600 | + */ |
|
| 1601 | + public function admin_notices_global() |
|
| 1602 | + { |
|
| 1603 | + $this->_display_no_javascript_warning(); |
|
| 1604 | + $this->_display_espresso_notices(); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + public function network_admin_notices_global() |
|
| 1609 | + { |
|
| 1610 | + $this->_display_no_javascript_warning(); |
|
| 1611 | + $this->_display_espresso_notices(); |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + |
|
| 1615 | + /** |
|
| 1616 | + * admin_footer_scripts_global |
|
| 1617 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1618 | + * will apply on ALL EE_Admin pages. |
|
| 1619 | + * |
|
| 1620 | + * @return void |
|
| 1621 | + */ |
|
| 1622 | + public function admin_footer_scripts_global() |
|
| 1623 | + { |
|
| 1624 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1625 | + $this->_add_admin_page_overlay(); |
|
| 1626 | + // if metaboxes are present we need to add the nonce field |
|
| 1627 | + if (isset($this->_route_config['metaboxes']) |
|
| 1628 | + || isset($this->_route_config['list_table']) |
|
| 1629 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1630 | + ) { |
|
| 1631 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1632 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1633 | + } |
|
| 1634 | + } |
|
| 1635 | + |
|
| 1636 | + |
|
| 1637 | + /** |
|
| 1638 | + * admin_footer_global |
|
| 1639 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1640 | + * ALL EE_Admin Pages. |
|
| 1641 | + * |
|
| 1642 | + * @return void |
|
| 1643 | + * @throws EE_Error |
|
| 1644 | + */ |
|
| 1645 | + public function admin_footer_global() |
|
| 1646 | + { |
|
| 1647 | + // dialog container for dialog helper |
|
| 1648 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1649 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1650 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1651 | + $d_cont .= '</div>'; |
|
| 1652 | + echo $d_cont; |
|
| 1653 | + // help tour stuff? |
|
| 1654 | + if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1655 | + echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1656 | + } |
|
| 1657 | + // current set timezone for timezone js |
|
| 1658 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1659 | + } |
|
| 1660 | + |
|
| 1661 | + |
|
| 1662 | + /** |
|
| 1663 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1664 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1665 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1666 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1667 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1668 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1669 | + * for the |
|
| 1670 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1671 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1672 | + * 'help_trigger_id' => array( |
|
| 1673 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1674 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1675 | + * ) |
|
| 1676 | + * ); |
|
| 1677 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1678 | + * |
|
| 1679 | + * @param array $help_array |
|
| 1680 | + * @param bool $display |
|
| 1681 | + * @return string content |
|
| 1682 | + * @throws DomainException |
|
| 1683 | + * @throws EE_Error |
|
| 1684 | + */ |
|
| 1685 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1686 | + { |
|
| 1687 | + $content = ''; |
|
| 1688 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1689 | + // loop through the array and setup content |
|
| 1690 | + foreach ($help_array as $trigger => $help) { |
|
| 1691 | + // make sure the array is setup properly |
|
| 1692 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1693 | + throw new EE_Error( |
|
| 1694 | + esc_html__( |
|
| 1695 | + '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', |
|
| 1696 | + 'event_espresso' |
|
| 1697 | + ) |
|
| 1698 | + ); |
|
| 1699 | + } |
|
| 1700 | + // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1701 | + $template_args = array( |
|
| 1702 | + 'help_popup_id' => $trigger, |
|
| 1703 | + 'help_popup_title' => $help['title'], |
|
| 1704 | + 'help_popup_content' => $help['content'], |
|
| 1705 | + ); |
|
| 1706 | + $content .= EEH_Template::display_template( |
|
| 1707 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1708 | + $template_args, |
|
| 1709 | + true |
|
| 1710 | + ); |
|
| 1711 | + } |
|
| 1712 | + if ($display) { |
|
| 1713 | + echo $content; |
|
| 1714 | + return ''; |
|
| 1715 | + } |
|
| 1716 | + return $content; |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + |
|
| 1720 | + /** |
|
| 1721 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1722 | + * |
|
| 1723 | + * @return array properly formatted array for help popup content |
|
| 1724 | + * @throws EE_Error |
|
| 1725 | + */ |
|
| 1726 | + private function _get_help_content() |
|
| 1727 | + { |
|
| 1728 | + // what is the method we're looking for? |
|
| 1729 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1730 | + // if method doesn't exist let's get out. |
|
| 1731 | + if (! method_exists($this, $method_name)) { |
|
| 1732 | + return array(); |
|
| 1733 | + } |
|
| 1734 | + // k we're good to go let's retrieve the help array |
|
| 1735 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1736 | + // make sure we've got an array! |
|
| 1737 | + if (! is_array($help_array)) { |
|
| 1738 | + throw new EE_Error( |
|
| 1739 | + esc_html__( |
|
| 1740 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1741 | + 'event_espresso' |
|
| 1742 | + ) |
|
| 1743 | + ); |
|
| 1744 | + } |
|
| 1745 | + return $help_array; |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + |
|
| 1749 | + /** |
|
| 1750 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1751 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1752 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1753 | + * |
|
| 1754 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1755 | + * @param boolean $display if false then we return the trigger string |
|
| 1756 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1757 | + * @return string |
|
| 1758 | + * @throws DomainException |
|
| 1759 | + * @throws EE_Error |
|
| 1760 | + */ |
|
| 1761 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1762 | + { |
|
| 1763 | + if (defined('DOING_AJAX')) { |
|
| 1764 | + return ''; |
|
| 1765 | + } |
|
| 1766 | + // 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 |
|
| 1767 | + $help_array = $this->_get_help_content(); |
|
| 1768 | + $help_content = ''; |
|
| 1769 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1770 | + $help_array[ $trigger_id ] = array( |
|
| 1771 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1772 | + 'content' => esc_html__( |
|
| 1773 | + '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.)', |
|
| 1774 | + 'event_espresso' |
|
| 1775 | + ), |
|
| 1776 | + ); |
|
| 1777 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1778 | + } |
|
| 1779 | + // let's setup the trigger |
|
| 1780 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1781 | + . $dimensions[0] |
|
| 1782 | + . '&width=' |
|
| 1783 | + . $dimensions[1] |
|
| 1784 | + . '&inlineId=' |
|
| 1785 | + . $trigger_id |
|
| 1786 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1787 | + $content .= $help_content; |
|
| 1788 | + if ($display) { |
|
| 1789 | + echo $content; |
|
| 1790 | + return ''; |
|
| 1791 | + } |
|
| 1792 | + return $content; |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * _add_global_screen_options |
|
| 1798 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1799 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1800 | + * |
|
| 1801 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1802 | + * see also WP_Screen object documents... |
|
| 1803 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1804 | + * @abstract |
|
| 1805 | + * @return void |
|
| 1806 | + */ |
|
| 1807 | + private function _add_global_screen_options() |
|
| 1808 | + { |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + |
|
| 1812 | + /** |
|
| 1813 | + * _add_global_feature_pointers |
|
| 1814 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1815 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1816 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1817 | + * |
|
| 1818 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1819 | + * extended) also see: |
|
| 1820 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1821 | + * @abstract |
|
| 1822 | + * @return void |
|
| 1823 | + */ |
|
| 1824 | + private function _add_global_feature_pointers() |
|
| 1825 | + { |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * load_global_scripts_styles |
|
| 1831 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1832 | + * |
|
| 1833 | + * @return void |
|
| 1834 | + * @throws EE_Error |
|
| 1835 | + */ |
|
| 1836 | + public function load_global_scripts_styles() |
|
| 1837 | + { |
|
| 1838 | + /** STYLES **/ |
|
| 1839 | + // add debugging styles |
|
| 1840 | + if (WP_DEBUG) { |
|
| 1841 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1842 | + } |
|
| 1843 | + // register all styles |
|
| 1844 | + wp_register_style( |
|
| 1845 | + 'espresso-ui-theme', |
|
| 1846 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1847 | + array(), |
|
| 1848 | + EVENT_ESPRESSO_VERSION |
|
| 1849 | + ); |
|
| 1850 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1851 | + // helpers styles |
|
| 1852 | + wp_register_style( |
|
| 1853 | + 'ee-text-links', |
|
| 1854 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1855 | + array(), |
|
| 1856 | + EVENT_ESPRESSO_VERSION |
|
| 1857 | + ); |
|
| 1858 | + /** SCRIPTS **/ |
|
| 1859 | + // register all scripts |
|
| 1860 | + wp_register_script( |
|
| 1861 | + 'ee-dialog', |
|
| 1862 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1863 | + array('jquery', 'jquery-ui-draggable'), |
|
| 1864 | + EVENT_ESPRESSO_VERSION, |
|
| 1865 | + true |
|
| 1866 | + ); |
|
| 1867 | + wp_register_script( |
|
| 1868 | + 'ee_admin_js', |
|
| 1869 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1870 | + array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
| 1871 | + EVENT_ESPRESSO_VERSION, |
|
| 1872 | + true |
|
| 1873 | + ); |
|
| 1874 | + wp_register_script( |
|
| 1875 | + 'jquery-ui-timepicker-addon', |
|
| 1876 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1877 | + array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
| 1878 | + EVENT_ESPRESSO_VERSION, |
|
| 1879 | + true |
|
| 1880 | + ); |
|
| 1881 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1882 | + // script for sorting tables |
|
| 1883 | + wp_register_script( |
|
| 1884 | + 'espresso_ajax_table_sorting', |
|
| 1885 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1886 | + array('ee_admin_js', 'jquery-ui-sortable'), |
|
| 1887 | + EVENT_ESPRESSO_VERSION, |
|
| 1888 | + true |
|
| 1889 | + ); |
|
| 1890 | + // script for parsing uri's |
|
| 1891 | + wp_register_script( |
|
| 1892 | + 'ee-parse-uri', |
|
| 1893 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1894 | + array(), |
|
| 1895 | + EVENT_ESPRESSO_VERSION, |
|
| 1896 | + true |
|
| 1897 | + ); |
|
| 1898 | + // and parsing associative serialized form elements |
|
| 1899 | + wp_register_script( |
|
| 1900 | + 'ee-serialize-full-array', |
|
| 1901 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1902 | + array('jquery'), |
|
| 1903 | + EVENT_ESPRESSO_VERSION, |
|
| 1904 | + true |
|
| 1905 | + ); |
|
| 1906 | + // helpers scripts |
|
| 1907 | + wp_register_script( |
|
| 1908 | + 'ee-text-links', |
|
| 1909 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1910 | + array('jquery'), |
|
| 1911 | + EVENT_ESPRESSO_VERSION, |
|
| 1912 | + true |
|
| 1913 | + ); |
|
| 1914 | + wp_register_script( |
|
| 1915 | + 'ee-moment-core', |
|
| 1916 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1917 | + array(), |
|
| 1918 | + EVENT_ESPRESSO_VERSION, |
|
| 1919 | + true |
|
| 1920 | + ); |
|
| 1921 | + wp_register_script( |
|
| 1922 | + 'ee-moment', |
|
| 1923 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1924 | + array('ee-moment-core'), |
|
| 1925 | + EVENT_ESPRESSO_VERSION, |
|
| 1926 | + true |
|
| 1927 | + ); |
|
| 1928 | + wp_register_script( |
|
| 1929 | + 'ee-datepicker', |
|
| 1930 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1931 | + array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
| 1932 | + EVENT_ESPRESSO_VERSION, |
|
| 1933 | + true |
|
| 1934 | + ); |
|
| 1935 | + // google charts |
|
| 1936 | + wp_register_script( |
|
| 1937 | + 'google-charts', |
|
| 1938 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1939 | + array(), |
|
| 1940 | + EVENT_ESPRESSO_VERSION, |
|
| 1941 | + false |
|
| 1942 | + ); |
|
| 1943 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1944 | + wp_enqueue_style('ee-admin-css'); |
|
| 1945 | + wp_enqueue_script('ee_admin_js'); |
|
| 1946 | + wp_enqueue_script('ee-accounting'); |
|
| 1947 | + wp_enqueue_script('jquery-validate'); |
|
| 1948 | + // taking care of metaboxes |
|
| 1949 | + if (empty($this->_cpt_route) |
|
| 1950 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1951 | + ) { |
|
| 1952 | + wp_enqueue_script('dashboard'); |
|
| 1953 | + } |
|
| 1954 | + // LOCALIZED DATA |
|
| 1955 | + // localize script for ajax lazy loading |
|
| 1956 | + $lazy_loader_container_ids = apply_filters( |
|
| 1957 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1958 | + array('espresso_news_post_box_content') |
|
| 1959 | + ); |
|
| 1960 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1961 | + /** |
|
| 1962 | + * help tour stuff |
|
| 1963 | + */ |
|
| 1964 | + if (! empty($this->_help_tour)) { |
|
| 1965 | + // register the js for kicking things off |
|
| 1966 | + wp_enqueue_script( |
|
| 1967 | + 'ee-help-tour', |
|
| 1968 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1969 | + array('jquery-joyride'), |
|
| 1970 | + EVENT_ESPRESSO_VERSION, |
|
| 1971 | + true |
|
| 1972 | + ); |
|
| 1973 | + $tours = array(); |
|
| 1974 | + // setup tours for the js tour object |
|
| 1975 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1976 | + if ($tour instanceof EE_Help_Tour) { |
|
| 1977 | + $tours[] = array( |
|
| 1978 | + 'id' => $tour->get_slug(), |
|
| 1979 | + 'options' => $tour->get_options(), |
|
| 1980 | + ); |
|
| 1981 | + } |
|
| 1982 | + } |
|
| 1983 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1984 | + // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1985 | + } |
|
| 1986 | + } |
|
| 1987 | + |
|
| 1988 | + |
|
| 1989 | + /** |
|
| 1990 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1991 | + * |
|
| 1992 | + * @return void |
|
| 1993 | + */ |
|
| 1994 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1995 | + { |
|
| 1996 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1997 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 1998 | + '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!!!', |
|
| 1999 | + 'event_espresso' |
|
| 2000 | + ); |
|
| 2001 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2002 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2003 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2004 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2005 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2006 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2007 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2008 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2009 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2010 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2011 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2012 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2013 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2014 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2015 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2016 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2017 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2018 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2019 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2020 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2021 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2022 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2023 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2024 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2025 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2026 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2027 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2028 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2029 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2030 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2031 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2032 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2033 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2034 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2035 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2036 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2037 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2038 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2039 | + } |
|
| 2040 | + |
|
| 2041 | + |
|
| 2042 | + /** |
|
| 2043 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2044 | + * |
|
| 2045 | + * @return void |
|
| 2046 | + */ |
|
| 2047 | + public function add_xdebug_style() |
|
| 2048 | + { |
|
| 2049 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + |
|
| 2053 | + /************************/ |
|
| 2054 | + /** LIST TABLE METHODS **/ |
|
| 2055 | + /************************/ |
|
| 2056 | + /** |
|
| 2057 | + * this sets up the list table if the current view requires it. |
|
| 2058 | + * |
|
| 2059 | + * @return void |
|
| 2060 | + * @throws EE_Error |
|
| 2061 | + */ |
|
| 2062 | + protected function _set_list_table() |
|
| 2063 | + { |
|
| 2064 | + // first is this a list_table view? |
|
| 2065 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2066 | + return; |
|
| 2067 | + } //not a list_table view so get out. |
|
| 2068 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2069 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2070 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2071 | + // user error msg |
|
| 2072 | + $error_msg = esc_html__( |
|
| 2073 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2074 | + 'event_espresso' |
|
| 2075 | + ); |
|
| 2076 | + // developer error msg |
|
| 2077 | + $error_msg .= '||' |
|
| 2078 | + . sprintf( |
|
| 2079 | + esc_html__( |
|
| 2080 | + '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.', |
|
| 2081 | + 'event_espresso' |
|
| 2082 | + ), |
|
| 2083 | + $this->_req_action, |
|
| 2084 | + $list_table_view |
|
| 2085 | + ); |
|
| 2086 | + throw new EE_Error($error_msg); |
|
| 2087 | + } |
|
| 2088 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2089 | + $this->_views = apply_filters( |
|
| 2090 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2091 | + $this->_views |
|
| 2092 | + ); |
|
| 2093 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2094 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2095 | + $this->_set_list_table_view(); |
|
| 2096 | + $this->_set_list_table_object(); |
|
| 2097 | + } |
|
| 2098 | + |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * set current view for List Table |
|
| 2102 | + * |
|
| 2103 | + * @return void |
|
| 2104 | + */ |
|
| 2105 | + protected function _set_list_table_view() |
|
| 2106 | + { |
|
| 2107 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2108 | + // looking at active items or dumpster diving ? |
|
| 2109 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2110 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2111 | + } else { |
|
| 2112 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2113 | + } |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + |
|
| 2117 | + /** |
|
| 2118 | + * _set_list_table_object |
|
| 2119 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2120 | + * |
|
| 2121 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2122 | + * @throws \InvalidArgumentException |
|
| 2123 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2124 | + * @throws EE_Error |
|
| 2125 | + * @throws InvalidInterfaceException |
|
| 2126 | + */ |
|
| 2127 | + protected function _set_list_table_object() |
|
| 2128 | + { |
|
| 2129 | + if (isset($this->_route_config['list_table'])) { |
|
| 2130 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2131 | + throw new EE_Error( |
|
| 2132 | + sprintf( |
|
| 2133 | + esc_html__( |
|
| 2134 | + '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.', |
|
| 2135 | + 'event_espresso' |
|
| 2136 | + ), |
|
| 2137 | + $this->_route_config['list_table'], |
|
| 2138 | + get_class($this) |
|
| 2139 | + ) |
|
| 2140 | + ); |
|
| 2141 | + } |
|
| 2142 | + $this->_list_table_object = LoaderFactory::getLoader()->getShared( |
|
| 2143 | + $this->_route_config['list_table'], |
|
| 2144 | + array($this) |
|
| 2145 | + ); |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + |
|
| 2149 | + |
|
| 2150 | + /** |
|
| 2151 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2152 | + * |
|
| 2153 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2154 | + * urls. The array should be indexed by the view it is being |
|
| 2155 | + * added to. |
|
| 2156 | + * @return array |
|
| 2157 | + */ |
|
| 2158 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2159 | + { |
|
| 2160 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2161 | + if (empty($this->_views)) { |
|
| 2162 | + $this->_views = array(); |
|
| 2163 | + } |
|
| 2164 | + // cycle thru views |
|
| 2165 | + foreach ($this->_views as $key => $view) { |
|
| 2166 | + $query_args = array(); |
|
| 2167 | + // check for current view |
|
| 2168 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2169 | + $query_args['action'] = $this->_req_action; |
|
| 2170 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2171 | + $query_args['status'] = $view['slug']; |
|
| 2172 | + // merge any other arguments sent in. |
|
| 2173 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2174 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2175 | + } |
|
| 2176 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2177 | + } |
|
| 2178 | + return $this->_views; |
|
| 2179 | + } |
|
| 2180 | + |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * _entries_per_page_dropdown |
|
| 2184 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2185 | + * |
|
| 2186 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2187 | + * WP does it. |
|
| 2188 | + * @param int $max_entries total number of rows in the table |
|
| 2189 | + * @return string |
|
| 2190 | + */ |
|
| 2191 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2192 | + { |
|
| 2193 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2194 | + $values = array(10, 25, 50, 100); |
|
| 2195 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2196 | + if ($max_entries) { |
|
| 2197 | + $values[] = $max_entries; |
|
| 2198 | + sort($values); |
|
| 2199 | + } |
|
| 2200 | + $entries_per_page_dropdown = ' |
|
| 2201 | 2201 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2202 | 2202 | <label class="hide-if-no-js"> |
| 2203 | 2203 | Show |
| 2204 | 2204 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2205 | - foreach ($values as $value) { |
|
| 2206 | - if ($value < $max_entries) { |
|
| 2207 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2208 | - $entries_per_page_dropdown .= ' |
|
| 2205 | + foreach ($values as $value) { |
|
| 2206 | + if ($value < $max_entries) { |
|
| 2207 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2208 | + $entries_per_page_dropdown .= ' |
|
| 2209 | 2209 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2210 | - } |
|
| 2211 | - } |
|
| 2212 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2213 | - $entries_per_page_dropdown .= ' |
|
| 2210 | + } |
|
| 2211 | + } |
|
| 2212 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2213 | + $entries_per_page_dropdown .= ' |
|
| 2214 | 2214 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2215 | - $entries_per_page_dropdown .= ' |
|
| 2215 | + $entries_per_page_dropdown .= ' |
|
| 2216 | 2216 | </select> |
| 2217 | 2217 | entries |
| 2218 | 2218 | </label> |
| 2219 | 2219 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2220 | 2220 | </div> |
| 2221 | 2221 | '; |
| 2222 | - return $entries_per_page_dropdown; |
|
| 2223 | - } |
|
| 2224 | - |
|
| 2225 | - |
|
| 2226 | - /** |
|
| 2227 | - * _set_search_attributes |
|
| 2228 | - * |
|
| 2229 | - * @return void |
|
| 2230 | - */ |
|
| 2231 | - public function _set_search_attributes() |
|
| 2232 | - { |
|
| 2233 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2234 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2235 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2236 | - : $this->_search_btn_label |
|
| 2237 | - ); |
|
| 2238 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2239 | - } |
|
| 2240 | - |
|
| 2241 | - |
|
| 2242 | - |
|
| 2243 | - /*** END LIST TABLE METHODS **/ |
|
| 2244 | - |
|
| 2245 | - |
|
| 2246 | - /** |
|
| 2247 | - * _add_registered_metaboxes |
|
| 2248 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2249 | - * |
|
| 2250 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2251 | - * @return void |
|
| 2252 | - * @throws EE_Error |
|
| 2253 | - */ |
|
| 2254 | - private function _add_registered_meta_boxes() |
|
| 2255 | - { |
|
| 2256 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2257 | - // we only add meta boxes if the page_route calls for it |
|
| 2258 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2259 | - && is_array( |
|
| 2260 | - $this->_route_config['metaboxes'] |
|
| 2261 | - ) |
|
| 2262 | - ) { |
|
| 2263 | - // this simply loops through the callbacks provided |
|
| 2264 | - // and checks if there is a corresponding callback registered by the child |
|
| 2265 | - // if there is then we go ahead and process the metabox loader. |
|
| 2266 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2267 | - // first check for Closures |
|
| 2268 | - if ($metabox_callback instanceof Closure) { |
|
| 2269 | - $result = $metabox_callback(); |
|
| 2270 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2271 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2272 | - } else { |
|
| 2273 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2274 | - } |
|
| 2275 | - if ($result === false) { |
|
| 2276 | - // user error msg |
|
| 2277 | - $error_msg = esc_html__( |
|
| 2278 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2279 | - 'event_espresso' |
|
| 2280 | - ); |
|
| 2281 | - // developer error msg |
|
| 2282 | - $error_msg .= '||' |
|
| 2283 | - . sprintf( |
|
| 2284 | - esc_html__( |
|
| 2285 | - '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.', |
|
| 2286 | - 'event_espresso' |
|
| 2287 | - ), |
|
| 2288 | - $metabox_callback |
|
| 2289 | - ); |
|
| 2290 | - throw new EE_Error($error_msg); |
|
| 2291 | - } |
|
| 2292 | - } |
|
| 2293 | - } |
|
| 2294 | - } |
|
| 2295 | - |
|
| 2296 | - |
|
| 2297 | - /** |
|
| 2298 | - * _add_screen_columns |
|
| 2299 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2300 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2301 | - * |
|
| 2302 | - * @return void |
|
| 2303 | - */ |
|
| 2304 | - private function _add_screen_columns() |
|
| 2305 | - { |
|
| 2306 | - if (is_array($this->_route_config) |
|
| 2307 | - && isset($this->_route_config['columns']) |
|
| 2308 | - && is_array($this->_route_config['columns']) |
|
| 2309 | - && count($this->_route_config['columns']) === 2 |
|
| 2310 | - ) { |
|
| 2311 | - add_screen_option( |
|
| 2312 | - 'layout_columns', |
|
| 2313 | - array( |
|
| 2314 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2315 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2316 | - ) |
|
| 2317 | - ); |
|
| 2318 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2319 | - $screen_id = $this->_current_screen->id; |
|
| 2320 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2321 | - $total_columns = ! empty($screen_columns) |
|
| 2322 | - ? $screen_columns |
|
| 2323 | - : $this->_route_config['columns'][1]; |
|
| 2324 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2325 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2326 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2327 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2328 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2329 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2330 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2331 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2332 | - } |
|
| 2333 | - } |
|
| 2334 | - |
|
| 2335 | - |
|
| 2336 | - |
|
| 2337 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2338 | - |
|
| 2339 | - |
|
| 2340 | - /** |
|
| 2341 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2342 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2343 | - * these get loaded on. |
|
| 2344 | - */ |
|
| 2345 | - private function _espresso_news_post_box() |
|
| 2346 | - { |
|
| 2347 | - $news_box_title = apply_filters( |
|
| 2348 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2349 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2350 | - ); |
|
| 2351 | - add_meta_box( |
|
| 2352 | - 'espresso_news_post_box', |
|
| 2353 | - $news_box_title, |
|
| 2354 | - array( |
|
| 2355 | - $this, |
|
| 2356 | - 'espresso_news_post_box', |
|
| 2357 | - ), |
|
| 2358 | - $this->_wp_page_slug, |
|
| 2359 | - 'side' |
|
| 2360 | - ); |
|
| 2361 | - } |
|
| 2362 | - |
|
| 2363 | - |
|
| 2364 | - /** |
|
| 2365 | - * Code for setting up espresso ratings request metabox. |
|
| 2366 | - */ |
|
| 2367 | - protected function _espresso_ratings_request() |
|
| 2368 | - { |
|
| 2369 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2370 | - return; |
|
| 2371 | - } |
|
| 2372 | - $ratings_box_title = apply_filters( |
|
| 2373 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2374 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2375 | - ); |
|
| 2376 | - add_meta_box( |
|
| 2377 | - 'espresso_ratings_request', |
|
| 2378 | - $ratings_box_title, |
|
| 2379 | - array( |
|
| 2380 | - $this, |
|
| 2381 | - 'espresso_ratings_request', |
|
| 2382 | - ), |
|
| 2383 | - $this->_wp_page_slug, |
|
| 2384 | - 'side' |
|
| 2385 | - ); |
|
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - |
|
| 2389 | - /** |
|
| 2390 | - * Code for setting up espresso ratings request metabox content. |
|
| 2391 | - * |
|
| 2392 | - * @throws DomainException |
|
| 2393 | - */ |
|
| 2394 | - public function espresso_ratings_request() |
|
| 2395 | - { |
|
| 2396 | - EEH_Template::display_template( |
|
| 2397 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2398 | - array() |
|
| 2399 | - ); |
|
| 2400 | - } |
|
| 2401 | - |
|
| 2402 | - |
|
| 2403 | - public static function cached_rss_display($rss_id, $url) |
|
| 2404 | - { |
|
| 2405 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2406 | - . __('Loading…', 'event_espresso') |
|
| 2407 | - . '</p><p class="hide-if-js">' |
|
| 2408 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2409 | - . '</p>'; |
|
| 2410 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2411 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2412 | - $post = '</div>' . "\n"; |
|
| 2413 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2414 | - $output = get_transient($cache_key); |
|
| 2415 | - if ($output !== false) { |
|
| 2416 | - echo $pre . $output . $post; |
|
| 2417 | - return true; |
|
| 2418 | - } |
|
| 2419 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2420 | - echo $pre . $loading . $post; |
|
| 2421 | - return false; |
|
| 2422 | - } |
|
| 2423 | - ob_start(); |
|
| 2424 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2425 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2426 | - return true; |
|
| 2427 | - } |
|
| 2428 | - |
|
| 2429 | - |
|
| 2430 | - public function espresso_news_post_box() |
|
| 2431 | - { |
|
| 2432 | - ?> |
|
| 2222 | + return $entries_per_page_dropdown; |
|
| 2223 | + } |
|
| 2224 | + |
|
| 2225 | + |
|
| 2226 | + /** |
|
| 2227 | + * _set_search_attributes |
|
| 2228 | + * |
|
| 2229 | + * @return void |
|
| 2230 | + */ |
|
| 2231 | + public function _set_search_attributes() |
|
| 2232 | + { |
|
| 2233 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2234 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2235 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2236 | + : $this->_search_btn_label |
|
| 2237 | + ); |
|
| 2238 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2239 | + } |
|
| 2240 | + |
|
| 2241 | + |
|
| 2242 | + |
|
| 2243 | + /*** END LIST TABLE METHODS **/ |
|
| 2244 | + |
|
| 2245 | + |
|
| 2246 | + /** |
|
| 2247 | + * _add_registered_metaboxes |
|
| 2248 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2249 | + * |
|
| 2250 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2251 | + * @return void |
|
| 2252 | + * @throws EE_Error |
|
| 2253 | + */ |
|
| 2254 | + private function _add_registered_meta_boxes() |
|
| 2255 | + { |
|
| 2256 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2257 | + // we only add meta boxes if the page_route calls for it |
|
| 2258 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2259 | + && is_array( |
|
| 2260 | + $this->_route_config['metaboxes'] |
|
| 2261 | + ) |
|
| 2262 | + ) { |
|
| 2263 | + // this simply loops through the callbacks provided |
|
| 2264 | + // and checks if there is a corresponding callback registered by the child |
|
| 2265 | + // if there is then we go ahead and process the metabox loader. |
|
| 2266 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2267 | + // first check for Closures |
|
| 2268 | + if ($metabox_callback instanceof Closure) { |
|
| 2269 | + $result = $metabox_callback(); |
|
| 2270 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2271 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2272 | + } else { |
|
| 2273 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 2274 | + } |
|
| 2275 | + if ($result === false) { |
|
| 2276 | + // user error msg |
|
| 2277 | + $error_msg = esc_html__( |
|
| 2278 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2279 | + 'event_espresso' |
|
| 2280 | + ); |
|
| 2281 | + // developer error msg |
|
| 2282 | + $error_msg .= '||' |
|
| 2283 | + . sprintf( |
|
| 2284 | + esc_html__( |
|
| 2285 | + '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.', |
|
| 2286 | + 'event_espresso' |
|
| 2287 | + ), |
|
| 2288 | + $metabox_callback |
|
| 2289 | + ); |
|
| 2290 | + throw new EE_Error($error_msg); |
|
| 2291 | + } |
|
| 2292 | + } |
|
| 2293 | + } |
|
| 2294 | + } |
|
| 2295 | + |
|
| 2296 | + |
|
| 2297 | + /** |
|
| 2298 | + * _add_screen_columns |
|
| 2299 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2300 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2301 | + * |
|
| 2302 | + * @return void |
|
| 2303 | + */ |
|
| 2304 | + private function _add_screen_columns() |
|
| 2305 | + { |
|
| 2306 | + if (is_array($this->_route_config) |
|
| 2307 | + && isset($this->_route_config['columns']) |
|
| 2308 | + && is_array($this->_route_config['columns']) |
|
| 2309 | + && count($this->_route_config['columns']) === 2 |
|
| 2310 | + ) { |
|
| 2311 | + add_screen_option( |
|
| 2312 | + 'layout_columns', |
|
| 2313 | + array( |
|
| 2314 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2315 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2316 | + ) |
|
| 2317 | + ); |
|
| 2318 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2319 | + $screen_id = $this->_current_screen->id; |
|
| 2320 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2321 | + $total_columns = ! empty($screen_columns) |
|
| 2322 | + ? $screen_columns |
|
| 2323 | + : $this->_route_config['columns'][1]; |
|
| 2324 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2325 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2326 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2327 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2328 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2329 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2330 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2331 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2332 | + } |
|
| 2333 | + } |
|
| 2334 | + |
|
| 2335 | + |
|
| 2336 | + |
|
| 2337 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2338 | + |
|
| 2339 | + |
|
| 2340 | + /** |
|
| 2341 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2342 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2343 | + * these get loaded on. |
|
| 2344 | + */ |
|
| 2345 | + private function _espresso_news_post_box() |
|
| 2346 | + { |
|
| 2347 | + $news_box_title = apply_filters( |
|
| 2348 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2349 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2350 | + ); |
|
| 2351 | + add_meta_box( |
|
| 2352 | + 'espresso_news_post_box', |
|
| 2353 | + $news_box_title, |
|
| 2354 | + array( |
|
| 2355 | + $this, |
|
| 2356 | + 'espresso_news_post_box', |
|
| 2357 | + ), |
|
| 2358 | + $this->_wp_page_slug, |
|
| 2359 | + 'side' |
|
| 2360 | + ); |
|
| 2361 | + } |
|
| 2362 | + |
|
| 2363 | + |
|
| 2364 | + /** |
|
| 2365 | + * Code for setting up espresso ratings request metabox. |
|
| 2366 | + */ |
|
| 2367 | + protected function _espresso_ratings_request() |
|
| 2368 | + { |
|
| 2369 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2370 | + return; |
|
| 2371 | + } |
|
| 2372 | + $ratings_box_title = apply_filters( |
|
| 2373 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2374 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2375 | + ); |
|
| 2376 | + add_meta_box( |
|
| 2377 | + 'espresso_ratings_request', |
|
| 2378 | + $ratings_box_title, |
|
| 2379 | + array( |
|
| 2380 | + $this, |
|
| 2381 | + 'espresso_ratings_request', |
|
| 2382 | + ), |
|
| 2383 | + $this->_wp_page_slug, |
|
| 2384 | + 'side' |
|
| 2385 | + ); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + |
|
| 2389 | + /** |
|
| 2390 | + * Code for setting up espresso ratings request metabox content. |
|
| 2391 | + * |
|
| 2392 | + * @throws DomainException |
|
| 2393 | + */ |
|
| 2394 | + public function espresso_ratings_request() |
|
| 2395 | + { |
|
| 2396 | + EEH_Template::display_template( |
|
| 2397 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2398 | + array() |
|
| 2399 | + ); |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + public static function cached_rss_display($rss_id, $url) |
|
| 2404 | + { |
|
| 2405 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2406 | + . __('Loading…', 'event_espresso') |
|
| 2407 | + . '</p><p class="hide-if-js">' |
|
| 2408 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2409 | + . '</p>'; |
|
| 2410 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2411 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2412 | + $post = '</div>' . "\n"; |
|
| 2413 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2414 | + $output = get_transient($cache_key); |
|
| 2415 | + if ($output !== false) { |
|
| 2416 | + echo $pre . $output . $post; |
|
| 2417 | + return true; |
|
| 2418 | + } |
|
| 2419 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2420 | + echo $pre . $loading . $post; |
|
| 2421 | + return false; |
|
| 2422 | + } |
|
| 2423 | + ob_start(); |
|
| 2424 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2425 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2426 | + return true; |
|
| 2427 | + } |
|
| 2428 | + |
|
| 2429 | + |
|
| 2430 | + public function espresso_news_post_box() |
|
| 2431 | + { |
|
| 2432 | + ?> |
|
| 2433 | 2433 | <div class="padding"> |
| 2434 | 2434 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2435 | 2435 | <?php |
| 2436 | - // Get RSS Feed(s) |
|
| 2437 | - self::cached_rss_display( |
|
| 2438 | - 'espresso_news_post_box_content', |
|
| 2439 | - urlencode( |
|
| 2440 | - apply_filters( |
|
| 2441 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2442 | - 'http://eventespresso.com/feed/' |
|
| 2443 | - ) |
|
| 2444 | - ) |
|
| 2445 | - ); |
|
| 2446 | - ?> |
|
| 2436 | + // Get RSS Feed(s) |
|
| 2437 | + self::cached_rss_display( |
|
| 2438 | + 'espresso_news_post_box_content', |
|
| 2439 | + urlencode( |
|
| 2440 | + apply_filters( |
|
| 2441 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2442 | + 'http://eventespresso.com/feed/' |
|
| 2443 | + ) |
|
| 2444 | + ) |
|
| 2445 | + ); |
|
| 2446 | + ?> |
|
| 2447 | 2447 | </div> |
| 2448 | 2448 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2449 | 2449 | </div> |
| 2450 | 2450 | <?php |
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - |
|
| 2454 | - private function _espresso_links_post_box() |
|
| 2455 | - { |
|
| 2456 | - // Hiding until we actually have content to put in here... |
|
| 2457 | - // 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'); |
|
| 2458 | - } |
|
| 2459 | - |
|
| 2460 | - |
|
| 2461 | - public function espresso_links_post_box() |
|
| 2462 | - { |
|
| 2463 | - // Hiding until we actually have content to put in here... |
|
| 2464 | - // EEH_Template::display_template( |
|
| 2465 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2466 | - // ); |
|
| 2467 | - } |
|
| 2468 | - |
|
| 2469 | - |
|
| 2470 | - protected function _espresso_sponsors_post_box() |
|
| 2471 | - { |
|
| 2472 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2473 | - add_meta_box( |
|
| 2474 | - 'espresso_sponsors_post_box', |
|
| 2475 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2476 | - array($this, 'espresso_sponsors_post_box'), |
|
| 2477 | - $this->_wp_page_slug, |
|
| 2478 | - 'side' |
|
| 2479 | - ); |
|
| 2480 | - } |
|
| 2481 | - } |
|
| 2482 | - |
|
| 2483 | - |
|
| 2484 | - public function espresso_sponsors_post_box() |
|
| 2485 | - { |
|
| 2486 | - EEH_Template::display_template( |
|
| 2487 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2488 | - ); |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - private function _publish_post_box() |
|
| 2493 | - { |
|
| 2494 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2495 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2496 | - // then we'll use that for the metabox label. |
|
| 2497 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2498 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2499 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2500 | - : $this->_labels['publishbox']; |
|
| 2501 | - } else { |
|
| 2502 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2503 | - } |
|
| 2504 | - $box_label = apply_filters( |
|
| 2505 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2506 | - $box_label, |
|
| 2507 | - $this->_req_action, |
|
| 2508 | - $this |
|
| 2509 | - ); |
|
| 2510 | - add_meta_box( |
|
| 2511 | - $meta_box_ref, |
|
| 2512 | - $box_label, |
|
| 2513 | - array($this, 'editor_overview'), |
|
| 2514 | - $this->_current_screen->id, |
|
| 2515 | - 'side', |
|
| 2516 | - 'high' |
|
| 2517 | - ); |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - |
|
| 2521 | - public function editor_overview() |
|
| 2522 | - { |
|
| 2523 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2524 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2525 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2526 | - : ''; |
|
| 2527 | - echo EEH_Template::display_template( |
|
| 2528 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2529 | - $this->_template_args, |
|
| 2530 | - true |
|
| 2531 | - ); |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - |
|
| 2535 | - /** end of globally available metaboxes section **/ |
|
| 2536 | - |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2540 | - * protected method. |
|
| 2541 | - * |
|
| 2542 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2543 | - * @since 4.6.0 |
|
| 2544 | - * @param string $name |
|
| 2545 | - * @param int $id |
|
| 2546 | - * @param bool $delete |
|
| 2547 | - * @param string $save_close_redirect_URL |
|
| 2548 | - * @param bool $both_btns |
|
| 2549 | - * @throws EE_Error |
|
| 2550 | - * @throws InvalidArgumentException |
|
| 2551 | - * @throws InvalidDataTypeException |
|
| 2552 | - * @throws InvalidInterfaceException |
|
| 2553 | - */ |
|
| 2554 | - public function set_publish_post_box_vars( |
|
| 2555 | - $name = '', |
|
| 2556 | - $id = 0, |
|
| 2557 | - $delete = false, |
|
| 2558 | - $save_close_redirect_URL = '', |
|
| 2559 | - $both_btns = true |
|
| 2560 | - ) { |
|
| 2561 | - $this->_set_publish_post_box_vars( |
|
| 2562 | - $name, |
|
| 2563 | - $id, |
|
| 2564 | - $delete, |
|
| 2565 | - $save_close_redirect_URL, |
|
| 2566 | - $both_btns |
|
| 2567 | - ); |
|
| 2568 | - } |
|
| 2569 | - |
|
| 2570 | - |
|
| 2571 | - /** |
|
| 2572 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2573 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2574 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2575 | - * values for the name and id arguments. |
|
| 2576 | - * |
|
| 2577 | - * @todo Add in validation for name/id arguments. |
|
| 2578 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2579 | - * @param int $id id attached to the item published |
|
| 2580 | - * @param string $delete page route callback for the delete action |
|
| 2581 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2582 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2583 | - * the Save button |
|
| 2584 | - * @throws EE_Error |
|
| 2585 | - * @throws InvalidArgumentException |
|
| 2586 | - * @throws InvalidDataTypeException |
|
| 2587 | - * @throws InvalidInterfaceException |
|
| 2588 | - */ |
|
| 2589 | - protected function _set_publish_post_box_vars( |
|
| 2590 | - $name = '', |
|
| 2591 | - $id = 0, |
|
| 2592 | - $delete = '', |
|
| 2593 | - $save_close_redirect_URL = '', |
|
| 2594 | - $both_btns = true |
|
| 2595 | - ) { |
|
| 2596 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2597 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2598 | - ? $save_close_redirect_URL |
|
| 2599 | - : $this->_admin_base_url; |
|
| 2600 | - // create the Save & Close and Save buttons |
|
| 2601 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2602 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2603 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2604 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2605 | - : ''; |
|
| 2606 | - if ($delete && ! empty($id)) { |
|
| 2607 | - // make sure we have a default if just true is sent. |
|
| 2608 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2609 | - $delete_link_args = array($name => $id); |
|
| 2610 | - $delete = $this->get_action_link_or_button( |
|
| 2611 | - $delete, |
|
| 2612 | - $delete, |
|
| 2613 | - $delete_link_args, |
|
| 2614 | - 'submitdelete deletion', |
|
| 2615 | - '', |
|
| 2616 | - false |
|
| 2617 | - ); |
|
| 2618 | - } |
|
| 2619 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2620 | - if (! empty($name) && ! empty($id)) { |
|
| 2621 | - $hidden_field_arr[ $name ] = array( |
|
| 2622 | - 'type' => 'hidden', |
|
| 2623 | - 'value' => $id, |
|
| 2624 | - ); |
|
| 2625 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2626 | - } else { |
|
| 2627 | - $hf = ''; |
|
| 2628 | - } |
|
| 2629 | - // add hidden field |
|
| 2630 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2631 | - ? $hf[ $name ]['field'] |
|
| 2632 | - : $hf; |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - |
|
| 2636 | - /** |
|
| 2637 | - * displays an error message to ppl who have javascript disabled |
|
| 2638 | - * |
|
| 2639 | - * @return void |
|
| 2640 | - */ |
|
| 2641 | - private function _display_no_javascript_warning() |
|
| 2642 | - { |
|
| 2643 | - ?> |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + |
|
| 2454 | + private function _espresso_links_post_box() |
|
| 2455 | + { |
|
| 2456 | + // Hiding until we actually have content to put in here... |
|
| 2457 | + // 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'); |
|
| 2458 | + } |
|
| 2459 | + |
|
| 2460 | + |
|
| 2461 | + public function espresso_links_post_box() |
|
| 2462 | + { |
|
| 2463 | + // Hiding until we actually have content to put in here... |
|
| 2464 | + // EEH_Template::display_template( |
|
| 2465 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2466 | + // ); |
|
| 2467 | + } |
|
| 2468 | + |
|
| 2469 | + |
|
| 2470 | + protected function _espresso_sponsors_post_box() |
|
| 2471 | + { |
|
| 2472 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2473 | + add_meta_box( |
|
| 2474 | + 'espresso_sponsors_post_box', |
|
| 2475 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2476 | + array($this, 'espresso_sponsors_post_box'), |
|
| 2477 | + $this->_wp_page_slug, |
|
| 2478 | + 'side' |
|
| 2479 | + ); |
|
| 2480 | + } |
|
| 2481 | + } |
|
| 2482 | + |
|
| 2483 | + |
|
| 2484 | + public function espresso_sponsors_post_box() |
|
| 2485 | + { |
|
| 2486 | + EEH_Template::display_template( |
|
| 2487 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2488 | + ); |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + private function _publish_post_box() |
|
| 2493 | + { |
|
| 2494 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2495 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2496 | + // then we'll use that for the metabox label. |
|
| 2497 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2498 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2499 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2500 | + : $this->_labels['publishbox']; |
|
| 2501 | + } else { |
|
| 2502 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2503 | + } |
|
| 2504 | + $box_label = apply_filters( |
|
| 2505 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2506 | + $box_label, |
|
| 2507 | + $this->_req_action, |
|
| 2508 | + $this |
|
| 2509 | + ); |
|
| 2510 | + add_meta_box( |
|
| 2511 | + $meta_box_ref, |
|
| 2512 | + $box_label, |
|
| 2513 | + array($this, 'editor_overview'), |
|
| 2514 | + $this->_current_screen->id, |
|
| 2515 | + 'side', |
|
| 2516 | + 'high' |
|
| 2517 | + ); |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + |
|
| 2521 | + public function editor_overview() |
|
| 2522 | + { |
|
| 2523 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2524 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2525 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2526 | + : ''; |
|
| 2527 | + echo EEH_Template::display_template( |
|
| 2528 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2529 | + $this->_template_args, |
|
| 2530 | + true |
|
| 2531 | + ); |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + |
|
| 2535 | + /** end of globally available metaboxes section **/ |
|
| 2536 | + |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2540 | + * protected method. |
|
| 2541 | + * |
|
| 2542 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2543 | + * @since 4.6.0 |
|
| 2544 | + * @param string $name |
|
| 2545 | + * @param int $id |
|
| 2546 | + * @param bool $delete |
|
| 2547 | + * @param string $save_close_redirect_URL |
|
| 2548 | + * @param bool $both_btns |
|
| 2549 | + * @throws EE_Error |
|
| 2550 | + * @throws InvalidArgumentException |
|
| 2551 | + * @throws InvalidDataTypeException |
|
| 2552 | + * @throws InvalidInterfaceException |
|
| 2553 | + */ |
|
| 2554 | + public function set_publish_post_box_vars( |
|
| 2555 | + $name = '', |
|
| 2556 | + $id = 0, |
|
| 2557 | + $delete = false, |
|
| 2558 | + $save_close_redirect_URL = '', |
|
| 2559 | + $both_btns = true |
|
| 2560 | + ) { |
|
| 2561 | + $this->_set_publish_post_box_vars( |
|
| 2562 | + $name, |
|
| 2563 | + $id, |
|
| 2564 | + $delete, |
|
| 2565 | + $save_close_redirect_URL, |
|
| 2566 | + $both_btns |
|
| 2567 | + ); |
|
| 2568 | + } |
|
| 2569 | + |
|
| 2570 | + |
|
| 2571 | + /** |
|
| 2572 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2573 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2574 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2575 | + * values for the name and id arguments. |
|
| 2576 | + * |
|
| 2577 | + * @todo Add in validation for name/id arguments. |
|
| 2578 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2579 | + * @param int $id id attached to the item published |
|
| 2580 | + * @param string $delete page route callback for the delete action |
|
| 2581 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2582 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2583 | + * the Save button |
|
| 2584 | + * @throws EE_Error |
|
| 2585 | + * @throws InvalidArgumentException |
|
| 2586 | + * @throws InvalidDataTypeException |
|
| 2587 | + * @throws InvalidInterfaceException |
|
| 2588 | + */ |
|
| 2589 | + protected function _set_publish_post_box_vars( |
|
| 2590 | + $name = '', |
|
| 2591 | + $id = 0, |
|
| 2592 | + $delete = '', |
|
| 2593 | + $save_close_redirect_URL = '', |
|
| 2594 | + $both_btns = true |
|
| 2595 | + ) { |
|
| 2596 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2597 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2598 | + ? $save_close_redirect_URL |
|
| 2599 | + : $this->_admin_base_url; |
|
| 2600 | + // create the Save & Close and Save buttons |
|
| 2601 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2602 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2603 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2604 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2605 | + : ''; |
|
| 2606 | + if ($delete && ! empty($id)) { |
|
| 2607 | + // make sure we have a default if just true is sent. |
|
| 2608 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2609 | + $delete_link_args = array($name => $id); |
|
| 2610 | + $delete = $this->get_action_link_or_button( |
|
| 2611 | + $delete, |
|
| 2612 | + $delete, |
|
| 2613 | + $delete_link_args, |
|
| 2614 | + 'submitdelete deletion', |
|
| 2615 | + '', |
|
| 2616 | + false |
|
| 2617 | + ); |
|
| 2618 | + } |
|
| 2619 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2620 | + if (! empty($name) && ! empty($id)) { |
|
| 2621 | + $hidden_field_arr[ $name ] = array( |
|
| 2622 | + 'type' => 'hidden', |
|
| 2623 | + 'value' => $id, |
|
| 2624 | + ); |
|
| 2625 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2626 | + } else { |
|
| 2627 | + $hf = ''; |
|
| 2628 | + } |
|
| 2629 | + // add hidden field |
|
| 2630 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2631 | + ? $hf[ $name ]['field'] |
|
| 2632 | + : $hf; |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + |
|
| 2636 | + /** |
|
| 2637 | + * displays an error message to ppl who have javascript disabled |
|
| 2638 | + * |
|
| 2639 | + * @return void |
|
| 2640 | + */ |
|
| 2641 | + private function _display_no_javascript_warning() |
|
| 2642 | + { |
|
| 2643 | + ?> |
|
| 2644 | 2644 | <noscript> |
| 2645 | 2645 | <div id="no-js-message" class="error"> |
| 2646 | 2646 | <p style="font-size:1.3em;"> |
| 2647 | 2647 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2648 | 2648 | <?php esc_html_e( |
| 2649 | - '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.', |
|
| 2650 | - 'event_espresso' |
|
| 2651 | - ); ?> |
|
| 2649 | + '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.', |
|
| 2650 | + 'event_espresso' |
|
| 2651 | + ); ?> |
|
| 2652 | 2652 | </p> |
| 2653 | 2653 | </div> |
| 2654 | 2654 | </noscript> |
| 2655 | 2655 | <?php |
| 2656 | - } |
|
| 2657 | - |
|
| 2658 | - |
|
| 2659 | - /** |
|
| 2660 | - * displays espresso success and/or error notices |
|
| 2661 | - * |
|
| 2662 | - * @return void |
|
| 2663 | - */ |
|
| 2664 | - private function _display_espresso_notices() |
|
| 2665 | - { |
|
| 2666 | - $notices = $this->_get_transient(true); |
|
| 2667 | - echo stripslashes($notices); |
|
| 2668 | - } |
|
| 2669 | - |
|
| 2670 | - |
|
| 2671 | - /** |
|
| 2672 | - * spinny things pacify the masses |
|
| 2673 | - * |
|
| 2674 | - * @return void |
|
| 2675 | - */ |
|
| 2676 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2677 | - { |
|
| 2678 | - ?> |
|
| 2656 | + } |
|
| 2657 | + |
|
| 2658 | + |
|
| 2659 | + /** |
|
| 2660 | + * displays espresso success and/or error notices |
|
| 2661 | + * |
|
| 2662 | + * @return void |
|
| 2663 | + */ |
|
| 2664 | + private function _display_espresso_notices() |
|
| 2665 | + { |
|
| 2666 | + $notices = $this->_get_transient(true); |
|
| 2667 | + echo stripslashes($notices); |
|
| 2668 | + } |
|
| 2669 | + |
|
| 2670 | + |
|
| 2671 | + /** |
|
| 2672 | + * spinny things pacify the masses |
|
| 2673 | + * |
|
| 2674 | + * @return void |
|
| 2675 | + */ |
|
| 2676 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2677 | + { |
|
| 2678 | + ?> |
|
| 2679 | 2679 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2680 | 2680 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2681 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2681 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2682 | 2682 | </div> |
| 2683 | 2683 | <?php |
| 2684 | - } |
|
| 2684 | + } |
|
| 2685 | 2685 | |
| 2686 | 2686 | |
| 2687 | - /** |
|
| 2688 | - * add admin page overlay for modal boxes |
|
| 2689 | - * |
|
| 2690 | - * @return void |
|
| 2691 | - */ |
|
| 2692 | - protected function _add_admin_page_overlay() |
|
| 2693 | - { |
|
| 2694 | - ?> |
|
| 2687 | + /** |
|
| 2688 | + * add admin page overlay for modal boxes |
|
| 2689 | + * |
|
| 2690 | + * @return void |
|
| 2691 | + */ |
|
| 2692 | + protected function _add_admin_page_overlay() |
|
| 2693 | + { |
|
| 2694 | + ?> |
|
| 2695 | 2695 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2696 | 2696 | <?php |
| 2697 | - } |
|
| 2698 | - |
|
| 2699 | - |
|
| 2700 | - /** |
|
| 2701 | - * facade for add_meta_box |
|
| 2702 | - * |
|
| 2703 | - * @param string $action where the metabox get's displayed |
|
| 2704 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2705 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2706 | - * instead of the one created in here. |
|
| 2707 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2708 | - * @param string $column what metabox column |
|
| 2709 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2710 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2711 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2712 | - * @throws \DomainException |
|
| 2713 | - */ |
|
| 2714 | - public function _add_admin_page_meta_box( |
|
| 2715 | - $action, |
|
| 2716 | - $title, |
|
| 2717 | - $callback, |
|
| 2718 | - $callback_args, |
|
| 2719 | - $column = 'normal', |
|
| 2720 | - $priority = 'high', |
|
| 2721 | - $create_func = true |
|
| 2722 | - ) { |
|
| 2723 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2724 | - // 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. |
|
| 2725 | - if (empty($callback_args) && $create_func) { |
|
| 2726 | - $callback_args = array( |
|
| 2727 | - 'template_path' => $this->_template_path, |
|
| 2728 | - 'template_args' => $this->_template_args, |
|
| 2729 | - ); |
|
| 2730 | - } |
|
| 2731 | - // 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) |
|
| 2732 | - $call_back_func = $create_func |
|
| 2733 | - ? function ($post, $metabox) { |
|
| 2734 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2735 | - echo EEH_Template::display_template( |
|
| 2736 | - $metabox['args']['template_path'], |
|
| 2737 | - $metabox['args']['template_args'], |
|
| 2738 | - true |
|
| 2739 | - ); |
|
| 2740 | - } |
|
| 2741 | - : $callback; |
|
| 2742 | - add_meta_box( |
|
| 2743 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2744 | - $title, |
|
| 2745 | - $call_back_func, |
|
| 2746 | - $this->_wp_page_slug, |
|
| 2747 | - $column, |
|
| 2748 | - $priority, |
|
| 2749 | - $callback_args |
|
| 2750 | - ); |
|
| 2751 | - } |
|
| 2752 | - |
|
| 2753 | - |
|
| 2754 | - /** |
|
| 2755 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2756 | - * |
|
| 2757 | - * @throws DomainException |
|
| 2758 | - * @throws EE_Error |
|
| 2759 | - */ |
|
| 2760 | - public function display_admin_page_with_metabox_columns() |
|
| 2761 | - { |
|
| 2762 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2763 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2764 | - $this->_column_template_path, |
|
| 2765 | - $this->_template_args, |
|
| 2766 | - true |
|
| 2767 | - ); |
|
| 2768 | - // the final wrapper |
|
| 2769 | - $this->admin_page_wrapper(); |
|
| 2770 | - } |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * generates HTML wrapper for an admin details page |
|
| 2775 | - * |
|
| 2776 | - * @return void |
|
| 2777 | - * @throws EE_Error |
|
| 2778 | - * @throws DomainException |
|
| 2779 | - */ |
|
| 2780 | - public function display_admin_page_with_sidebar() |
|
| 2781 | - { |
|
| 2782 | - $this->_display_admin_page(true); |
|
| 2783 | - } |
|
| 2784 | - |
|
| 2785 | - |
|
| 2786 | - /** |
|
| 2787 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2788 | - * |
|
| 2789 | - * @return void |
|
| 2790 | - * @throws EE_Error |
|
| 2791 | - * @throws DomainException |
|
| 2792 | - */ |
|
| 2793 | - public function display_admin_page_with_no_sidebar() |
|
| 2794 | - { |
|
| 2795 | - $this->_display_admin_page(); |
|
| 2796 | - } |
|
| 2797 | - |
|
| 2798 | - |
|
| 2799 | - /** |
|
| 2800 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2801 | - * |
|
| 2802 | - * @return void |
|
| 2803 | - * @throws EE_Error |
|
| 2804 | - * @throws DomainException |
|
| 2805 | - */ |
|
| 2806 | - public function display_about_admin_page() |
|
| 2807 | - { |
|
| 2808 | - $this->_display_admin_page(false, true); |
|
| 2809 | - } |
|
| 2810 | - |
|
| 2811 | - |
|
| 2812 | - /** |
|
| 2813 | - * display_admin_page |
|
| 2814 | - * contains the code for actually displaying an admin page |
|
| 2815 | - * |
|
| 2816 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2817 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2818 | - * @return void |
|
| 2819 | - * @throws DomainException |
|
| 2820 | - * @throws EE_Error |
|
| 2821 | - */ |
|
| 2822 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2823 | - { |
|
| 2824 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2825 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2826 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2827 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2828 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2829 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2830 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2831 | - ? 'poststuff' |
|
| 2832 | - : 'espresso-default-admin'; |
|
| 2833 | - $template_path = $sidebar |
|
| 2834 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2835 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2836 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2837 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2838 | - } |
|
| 2839 | - $template_path = ! empty($this->_column_template_path) |
|
| 2840 | - ? $this->_column_template_path : $template_path; |
|
| 2841 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2842 | - ? $this->_template_args['admin_page_content'] |
|
| 2843 | - : ''; |
|
| 2844 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2845 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2846 | - : ''; |
|
| 2847 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2848 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2849 | - : ''; |
|
| 2850 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2851 | - $template_path, |
|
| 2852 | - $this->_template_args, |
|
| 2853 | - true |
|
| 2854 | - ); |
|
| 2855 | - // the final template wrapper |
|
| 2856 | - $this->admin_page_wrapper($about); |
|
| 2857 | - } |
|
| 2858 | - |
|
| 2859 | - |
|
| 2860 | - /** |
|
| 2861 | - * This is used to display caf preview pages. |
|
| 2862 | - * |
|
| 2863 | - * @since 4.3.2 |
|
| 2864 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2865 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2866 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2867 | - * @return void |
|
| 2868 | - * @throws DomainException |
|
| 2869 | - * @throws EE_Error |
|
| 2870 | - * @throws InvalidArgumentException |
|
| 2871 | - * @throws InvalidDataTypeException |
|
| 2872 | - * @throws InvalidInterfaceException |
|
| 2873 | - */ |
|
| 2874 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2875 | - { |
|
| 2876 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2877 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2878 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2879 | - 'event_espresso' |
|
| 2880 | - ); |
|
| 2881 | - $buy_now_url = add_query_arg( |
|
| 2882 | - array( |
|
| 2883 | - 'ee_ver' => 'ee4', |
|
| 2884 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2885 | - 'utm_medium' => 'link', |
|
| 2886 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2887 | - 'utm_content' => 'buy_now_button', |
|
| 2888 | - ), |
|
| 2889 | - 'http://eventespresso.com/pricing/' |
|
| 2890 | - ); |
|
| 2891 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2892 | - ? $this->get_action_link_or_button( |
|
| 2893 | - '', |
|
| 2894 | - 'buy_now', |
|
| 2895 | - array(), |
|
| 2896 | - 'button-primary button-large', |
|
| 2897 | - $buy_now_url, |
|
| 2898 | - true |
|
| 2899 | - ) |
|
| 2900 | - : $this->_template_args['preview_action_button']; |
|
| 2901 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2902 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2903 | - $this->_template_args, |
|
| 2904 | - true |
|
| 2905 | - ); |
|
| 2906 | - $this->_display_admin_page($display_sidebar); |
|
| 2907 | - } |
|
| 2908 | - |
|
| 2909 | - |
|
| 2910 | - /** |
|
| 2911 | - * display_admin_list_table_page_with_sidebar |
|
| 2912 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2913 | - * |
|
| 2914 | - * @return void |
|
| 2915 | - * @throws EE_Error |
|
| 2916 | - * @throws DomainException |
|
| 2917 | - */ |
|
| 2918 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2919 | - { |
|
| 2920 | - $this->_display_admin_list_table_page(true); |
|
| 2921 | - } |
|
| 2922 | - |
|
| 2923 | - |
|
| 2924 | - /** |
|
| 2925 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2926 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2927 | - * |
|
| 2928 | - * @return void |
|
| 2929 | - * @throws EE_Error |
|
| 2930 | - * @throws DomainException |
|
| 2931 | - */ |
|
| 2932 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2933 | - { |
|
| 2934 | - $this->_display_admin_list_table_page(); |
|
| 2935 | - } |
|
| 2936 | - |
|
| 2937 | - |
|
| 2938 | - /** |
|
| 2939 | - * generates html wrapper for an admin_list_table page |
|
| 2940 | - * |
|
| 2941 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2942 | - * @return void |
|
| 2943 | - * @throws DomainException |
|
| 2944 | - * @throws EE_Error |
|
| 2945 | - */ |
|
| 2946 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2947 | - { |
|
| 2948 | - // setup search attributes |
|
| 2949 | - $this->_set_search_attributes(); |
|
| 2950 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2951 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2952 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2953 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2954 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2955 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2956 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2957 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2958 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2959 | - if (! empty($ajax_sorting_callback)) { |
|
| 2960 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2961 | - $ajax_sorting_callback . '_nonce', |
|
| 2962 | - $ajax_sorting_callback . '_nonce', |
|
| 2963 | - false, |
|
| 2964 | - false |
|
| 2965 | - ); |
|
| 2966 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2967 | - . $this->page_slug |
|
| 2968 | - . '" />'; |
|
| 2969 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2970 | - . $ajax_sorting_callback |
|
| 2971 | - . '" />'; |
|
| 2972 | - } else { |
|
| 2973 | - $sortable_list_table_form_fields = ''; |
|
| 2974 | - } |
|
| 2975 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2976 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 2977 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 2978 | - : ''; |
|
| 2979 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2980 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 2981 | - . $nonce_ref |
|
| 2982 | - . '" value="' |
|
| 2983 | - . wp_create_nonce($nonce_ref) |
|
| 2984 | - . '">'; |
|
| 2985 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2986 | - // display message about search results? |
|
| 2987 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2988 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2989 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2990 | - trim($this->_req_data['s'], '%') |
|
| 2991 | - ) . '</p>' |
|
| 2992 | - : ''; |
|
| 2993 | - // filter before_list_table template arg |
|
| 2994 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 2995 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2996 | - $this->_template_args['before_list_table'], |
|
| 2997 | - $this->page_slug, |
|
| 2998 | - $this->_req_data, |
|
| 2999 | - $this->_req_action |
|
| 3000 | - ); |
|
| 3001 | - // convert to array and filter again |
|
| 3002 | - // arrays are easier to inject new items in a specific location, |
|
| 3003 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3004 | - $this->_template_args['before_list_table'] = implode( |
|
| 3005 | - " \n", |
|
| 3006 | - (array) apply_filters( |
|
| 3007 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3008 | - (array) $this->_template_args['before_list_table'], |
|
| 3009 | - $this->page_slug, |
|
| 3010 | - $this->_req_data, |
|
| 3011 | - $this->_req_action |
|
| 3012 | - ) |
|
| 3013 | - ); |
|
| 3014 | - // filter after_list_table template arg |
|
| 3015 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3016 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3017 | - $this->_template_args['after_list_table'], |
|
| 3018 | - $this->page_slug, |
|
| 3019 | - $this->_req_data, |
|
| 3020 | - $this->_req_action |
|
| 3021 | - ); |
|
| 3022 | - // convert to array and filter again |
|
| 3023 | - // arrays are easier to inject new items in a specific location, |
|
| 3024 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3025 | - $this->_template_args['after_list_table'] = implode( |
|
| 3026 | - " \n", |
|
| 3027 | - (array) apply_filters( |
|
| 3028 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3029 | - (array) $this->_template_args['after_list_table'], |
|
| 3030 | - $this->page_slug, |
|
| 3031 | - $this->_req_data, |
|
| 3032 | - $this->_req_action |
|
| 3033 | - ) |
|
| 3034 | - ); |
|
| 3035 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3036 | - $template_path, |
|
| 3037 | - $this->_template_args, |
|
| 3038 | - true |
|
| 3039 | - ); |
|
| 3040 | - // the final template wrapper |
|
| 3041 | - if ($sidebar) { |
|
| 3042 | - $this->display_admin_page_with_sidebar(); |
|
| 3043 | - } else { |
|
| 3044 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3045 | - } |
|
| 3046 | - } |
|
| 3047 | - |
|
| 3048 | - |
|
| 3049 | - /** |
|
| 3050 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3051 | - * html string for the legend. |
|
| 3052 | - * $items are expected in an array in the following format: |
|
| 3053 | - * $legend_items = array( |
|
| 3054 | - * 'item_id' => array( |
|
| 3055 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3056 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3057 | - * ) |
|
| 3058 | - * ); |
|
| 3059 | - * |
|
| 3060 | - * @param array $items see above for format of array |
|
| 3061 | - * @return string html string of legend |
|
| 3062 | - * @throws DomainException |
|
| 3063 | - */ |
|
| 3064 | - protected function _display_legend($items) |
|
| 3065 | - { |
|
| 3066 | - $this->_template_args['items'] = apply_filters( |
|
| 3067 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3068 | - (array) $items, |
|
| 3069 | - $this |
|
| 3070 | - ); |
|
| 3071 | - return EEH_Template::display_template( |
|
| 3072 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3073 | - $this->_template_args, |
|
| 3074 | - true |
|
| 3075 | - ); |
|
| 3076 | - } |
|
| 3077 | - |
|
| 3078 | - |
|
| 3079 | - /** |
|
| 3080 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3081 | - * The returned json object is created from an array in the following format: |
|
| 3082 | - * array( |
|
| 3083 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3084 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3085 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3086 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3087 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3088 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3089 | - * that might be included in here) |
|
| 3090 | - * ) |
|
| 3091 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3092 | - * |
|
| 3093 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3094 | - * instead of displayed. |
|
| 3095 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3096 | - * @return void |
|
| 3097 | - * @throws EE_Error |
|
| 3098 | - */ |
|
| 3099 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3100 | - { |
|
| 3101 | - // make sure any EE_Error notices have been handled. |
|
| 3102 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3103 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3104 | - unset($this->_template_args['data']); |
|
| 3105 | - $json = array( |
|
| 3106 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3107 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3108 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3109 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3110 | - 'notices' => EE_Error::get_notices(), |
|
| 3111 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3112 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3113 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3114 | - 'isEEajax' => true |
|
| 3115 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3116 | - ); |
|
| 3117 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3118 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3119 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3120 | - } |
|
| 3121 | - echo wp_json_encode($json); |
|
| 3122 | - exit(); |
|
| 3123 | - } |
|
| 3124 | - |
|
| 3125 | - |
|
| 3126 | - /** |
|
| 3127 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3128 | - * |
|
| 3129 | - * @return void |
|
| 3130 | - * @throws EE_Error |
|
| 3131 | - */ |
|
| 3132 | - public function return_json() |
|
| 3133 | - { |
|
| 3134 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3135 | - $this->_return_json(); |
|
| 3136 | - } else { |
|
| 3137 | - throw new EE_Error( |
|
| 3138 | - sprintf( |
|
| 3139 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3140 | - __FUNCTION__ |
|
| 3141 | - ) |
|
| 3142 | - ); |
|
| 3143 | - } |
|
| 3144 | - } |
|
| 3145 | - |
|
| 3146 | - |
|
| 3147 | - /** |
|
| 3148 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3149 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3150 | - * |
|
| 3151 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3152 | - */ |
|
| 3153 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3154 | - { |
|
| 3155 | - $this->_hook_obj = $hook_obj; |
|
| 3156 | - } |
|
| 3157 | - |
|
| 3158 | - |
|
| 3159 | - /** |
|
| 3160 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3161 | - * |
|
| 3162 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3163 | - * @return void |
|
| 3164 | - * @throws DomainException |
|
| 3165 | - * @throws EE_Error |
|
| 3166 | - */ |
|
| 3167 | - public function admin_page_wrapper($about = false) |
|
| 3168 | - { |
|
| 3169 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3170 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3171 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3172 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3173 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3174 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3175 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3176 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3177 | - : '' |
|
| 3178 | - ); |
|
| 3179 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3180 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3181 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3182 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3183 | - : '' |
|
| 3184 | - ); |
|
| 3185 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3186 | - // load settings page wrapper template |
|
| 3187 | - $template_path = ! defined('DOING_AJAX') |
|
| 3188 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3189 | - : EE_ADMIN_TEMPLATE |
|
| 3190 | - . 'admin_wrapper_ajax.template.php'; |
|
| 3191 | - // about page? |
|
| 3192 | - $template_path = $about |
|
| 3193 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3194 | - : $template_path; |
|
| 3195 | - if (defined('DOING_AJAX')) { |
|
| 3196 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3197 | - $template_path, |
|
| 3198 | - $this->_template_args, |
|
| 3199 | - true |
|
| 3200 | - ); |
|
| 3201 | - $this->_return_json(); |
|
| 3202 | - } else { |
|
| 3203 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3204 | - } |
|
| 3205 | - } |
|
| 3206 | - |
|
| 3207 | - |
|
| 3208 | - /** |
|
| 3209 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3210 | - * |
|
| 3211 | - * @return string html |
|
| 3212 | - * @throws EE_Error |
|
| 3213 | - */ |
|
| 3214 | - protected function _get_main_nav_tabs() |
|
| 3215 | - { |
|
| 3216 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3217 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3218 | - // (rather than setting in the page_routes array) |
|
| 3219 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3220 | - } |
|
| 3221 | - |
|
| 3222 | - |
|
| 3223 | - /** |
|
| 3224 | - * sort nav tabs |
|
| 3225 | - * |
|
| 3226 | - * @param $a |
|
| 3227 | - * @param $b |
|
| 3228 | - * @return int |
|
| 3229 | - */ |
|
| 3230 | - private function _sort_nav_tabs($a, $b) |
|
| 3231 | - { |
|
| 3232 | - if ($a['order'] === $b['order']) { |
|
| 3233 | - return 0; |
|
| 3234 | - } |
|
| 3235 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3236 | - } |
|
| 3237 | - |
|
| 3238 | - |
|
| 3239 | - /** |
|
| 3240 | - * generates HTML for the forms used on admin pages |
|
| 3241 | - * |
|
| 3242 | - * @param array $input_vars - array of input field details |
|
| 3243 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3244 | - * use) |
|
| 3245 | - * @param bool $id |
|
| 3246 | - * @return string |
|
| 3247 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3248 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3249 | - */ |
|
| 3250 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3251 | - { |
|
| 3252 | - $content = $generator === 'string' |
|
| 3253 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3254 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3255 | - return $content; |
|
| 3256 | - } |
|
| 3257 | - |
|
| 3258 | - |
|
| 3259 | - /** |
|
| 3260 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3261 | - * |
|
| 3262 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3263 | - * Close" button. |
|
| 3264 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3265 | - * 'Save', [1] => 'save & close') |
|
| 3266 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3267 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3268 | - * default actions by submitting some other value. |
|
| 3269 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3270 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3271 | - * close (normal form handling). |
|
| 3272 | - */ |
|
| 3273 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3274 | - { |
|
| 3275 | - // make sure $text and $actions are in an array |
|
| 3276 | - $text = (array) $text; |
|
| 3277 | - $actions = (array) $actions; |
|
| 3278 | - $referrer_url = empty($referrer) |
|
| 3279 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3280 | - . $_SERVER['REQUEST_URI'] |
|
| 3281 | - . '" />' |
|
| 3282 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3283 | - . $referrer |
|
| 3284 | - . '" />'; |
|
| 3285 | - $button_text = ! empty($text) |
|
| 3286 | - ? $text |
|
| 3287 | - : array( |
|
| 3288 | - esc_html__('Save', 'event_espresso'), |
|
| 3289 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3290 | - ); |
|
| 3291 | - $default_names = array('save', 'save_and_close'); |
|
| 3292 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3293 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3294 | - foreach ($button_text as $key => $button) { |
|
| 3295 | - $ref = $default_names[ $key ]; |
|
| 3296 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3297 | - . $ref |
|
| 3298 | - . '" value="' |
|
| 3299 | - . $button |
|
| 3300 | - . '" name="' |
|
| 3301 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3302 | - . '" id="' |
|
| 3303 | - . $this->_current_view . '_' . $ref |
|
| 3304 | - . '" />'; |
|
| 3305 | - if (! $both) { |
|
| 3306 | - break; |
|
| 3307 | - } |
|
| 3308 | - } |
|
| 3309 | - } |
|
| 3310 | - |
|
| 3311 | - |
|
| 3312 | - /** |
|
| 3313 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3314 | - * |
|
| 3315 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3316 | - * @since 4.6.0 |
|
| 3317 | - * @param string $route |
|
| 3318 | - * @param array $additional_hidden_fields |
|
| 3319 | - */ |
|
| 3320 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3321 | - { |
|
| 3322 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3323 | - } |
|
| 3324 | - |
|
| 3325 | - |
|
| 3326 | - /** |
|
| 3327 | - * set form open and close tags on add/edit pages. |
|
| 3328 | - * |
|
| 3329 | - * @param string $route the route you want the form to direct to |
|
| 3330 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3331 | - * @return void |
|
| 3332 | - */ |
|
| 3333 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3334 | - { |
|
| 3335 | - if (empty($route)) { |
|
| 3336 | - $user_msg = esc_html__( |
|
| 3337 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3338 | - 'event_espresso' |
|
| 3339 | - ); |
|
| 3340 | - $dev_msg = $user_msg . "\n" |
|
| 3341 | - . sprintf( |
|
| 3342 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3343 | - __FUNCTION__, |
|
| 3344 | - __CLASS__ |
|
| 3345 | - ); |
|
| 3346 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3347 | - } |
|
| 3348 | - // open form |
|
| 3349 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3350 | - . $this->_admin_base_url |
|
| 3351 | - . '" id="' |
|
| 3352 | - . $route |
|
| 3353 | - . '_event_form" >'; |
|
| 3354 | - // add nonce |
|
| 3355 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3356 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3357 | - // add REQUIRED form action |
|
| 3358 | - $hidden_fields = array( |
|
| 3359 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3360 | - ); |
|
| 3361 | - // merge arrays |
|
| 3362 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3363 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3364 | - : $hidden_fields; |
|
| 3365 | - // generate form fields |
|
| 3366 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3367 | - // add fields to form |
|
| 3368 | - foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3369 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3370 | - } |
|
| 3371 | - // close form |
|
| 3372 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3373 | - } |
|
| 3374 | - |
|
| 3375 | - |
|
| 3376 | - /** |
|
| 3377 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3378 | - * discovered it would be useful for external code to have access. |
|
| 3379 | - * |
|
| 3380 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3381 | - * @since 4.5.0 |
|
| 3382 | - * @param bool $success |
|
| 3383 | - * @param string $what |
|
| 3384 | - * @param string $action_desc |
|
| 3385 | - * @param array $query_args |
|
| 3386 | - * @param bool $override_overwrite |
|
| 3387 | - * @throws EE_Error |
|
| 3388 | - */ |
|
| 3389 | - public function redirect_after_action( |
|
| 3390 | - $success = false, |
|
| 3391 | - $what = 'item', |
|
| 3392 | - $action_desc = 'processed', |
|
| 3393 | - $query_args = array(), |
|
| 3394 | - $override_overwrite = false |
|
| 3395 | - ) { |
|
| 3396 | - $this->_redirect_after_action( |
|
| 3397 | - $success, |
|
| 3398 | - $what, |
|
| 3399 | - $action_desc, |
|
| 3400 | - $query_args, |
|
| 3401 | - $override_overwrite |
|
| 3402 | - ); |
|
| 3403 | - } |
|
| 3404 | - |
|
| 3405 | - |
|
| 3406 | - /** |
|
| 3407 | - * _redirect_after_action |
|
| 3408 | - * |
|
| 3409 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3410 | - * @param string $what - what the action was performed on |
|
| 3411 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3412 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3413 | - * action is completed |
|
| 3414 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3415 | - * override this so that they show. |
|
| 3416 | - * @return void |
|
| 3417 | - * @throws EE_Error |
|
| 3418 | - */ |
|
| 3419 | - protected function _redirect_after_action( |
|
| 3420 | - $success = 0, |
|
| 3421 | - $what = 'item', |
|
| 3422 | - $action_desc = 'processed', |
|
| 3423 | - $query_args = array(), |
|
| 3424 | - $override_overwrite = false |
|
| 3425 | - ) { |
|
| 3426 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3427 | - // class name for actions/filters. |
|
| 3428 | - $classname = get_class($this); |
|
| 3429 | - // set redirect url. |
|
| 3430 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3431 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3432 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3433 | - $notices = EE_Error::get_notices(false); |
|
| 3434 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3435 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3436 | - EE_Error::overwrite_success(); |
|
| 3437 | - } |
|
| 3438 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3439 | - // how many records affected ? more than one record ? or just one ? |
|
| 3440 | - if ($success > 1) { |
|
| 3441 | - // set plural msg |
|
| 3442 | - EE_Error::add_success( |
|
| 3443 | - sprintf( |
|
| 3444 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3445 | - $what, |
|
| 3446 | - $action_desc |
|
| 3447 | - ), |
|
| 3448 | - __FILE__, |
|
| 3449 | - __FUNCTION__, |
|
| 3450 | - __LINE__ |
|
| 3451 | - ); |
|
| 3452 | - } elseif ($success === 1) { |
|
| 3453 | - // set singular msg |
|
| 3454 | - EE_Error::add_success( |
|
| 3455 | - sprintf( |
|
| 3456 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3457 | - $what, |
|
| 3458 | - $action_desc |
|
| 3459 | - ), |
|
| 3460 | - __FILE__, |
|
| 3461 | - __FUNCTION__, |
|
| 3462 | - __LINE__ |
|
| 3463 | - ); |
|
| 3464 | - } |
|
| 3465 | - } |
|
| 3466 | - // check that $query_args isn't something crazy |
|
| 3467 | - if (! is_array($query_args)) { |
|
| 3468 | - $query_args = array(); |
|
| 3469 | - } |
|
| 3470 | - /** |
|
| 3471 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3472 | - * redirections on save and close actions |
|
| 3473 | - * |
|
| 3474 | - * @since 4.2.0 |
|
| 3475 | - * @param array $query_args The original query_args array coming into the |
|
| 3476 | - * method. |
|
| 3477 | - */ |
|
| 3478 | - do_action( |
|
| 3479 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3480 | - $query_args |
|
| 3481 | - ); |
|
| 3482 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3483 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3484 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3485 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3486 | - // regenerate query args array from referrer URL |
|
| 3487 | - parse_str($parsed_url['query'], $query_args); |
|
| 3488 | - // correct page and action will be in the query args now |
|
| 3489 | - $redirect_url = admin_url('admin.php'); |
|
| 3490 | - } |
|
| 3491 | - // merge any default query_args set in _default_route_query_args property |
|
| 3492 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3493 | - $args_to_merge = array(); |
|
| 3494 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3495 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3496 | - if ($query_param === 'wp_referer') { |
|
| 3497 | - $query_value = (array) $query_value; |
|
| 3498 | - foreach ($query_value as $reference => $value) { |
|
| 3499 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3500 | - continue; |
|
| 3501 | - } |
|
| 3502 | - // finally we will override any arguments in the referer with |
|
| 3503 | - // what might be set on the _default_route_query_args array. |
|
| 3504 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3505 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3506 | - } else { |
|
| 3507 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3508 | - } |
|
| 3509 | - } |
|
| 3510 | - continue; |
|
| 3511 | - } |
|
| 3512 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3513 | - } |
|
| 3514 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3515 | - // redirect. |
|
| 3516 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3517 | - } |
|
| 3518 | - $this->_process_notices($query_args); |
|
| 3519 | - // generate redirect url |
|
| 3520 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3521 | - if (isset($query_args['action'])) { |
|
| 3522 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3523 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3524 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3525 | - } |
|
| 3526 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3527 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3528 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3529 | - $redirect_url = apply_filters( |
|
| 3530 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3531 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3532 | - $query_args |
|
| 3533 | - ); |
|
| 3534 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3535 | - if (defined('DOING_AJAX')) { |
|
| 3536 | - $default_data = array( |
|
| 3537 | - 'close' => true, |
|
| 3538 | - 'redirect_url' => $redirect_url, |
|
| 3539 | - 'where' => 'main', |
|
| 3540 | - 'what' => 'append', |
|
| 3541 | - ); |
|
| 3542 | - $this->_template_args['success'] = $success; |
|
| 3543 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3544 | - $default_data, |
|
| 3545 | - $this->_template_args['data'] |
|
| 3546 | - ) : $default_data; |
|
| 3547 | - $this->_return_json(); |
|
| 3548 | - } |
|
| 3549 | - wp_safe_redirect($redirect_url); |
|
| 3550 | - exit(); |
|
| 3551 | - } |
|
| 3552 | - |
|
| 3553 | - |
|
| 3554 | - /** |
|
| 3555 | - * process any notices before redirecting (or returning ajax request) |
|
| 3556 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3557 | - * |
|
| 3558 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3559 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3560 | - * page_routes haven't been defined yet. |
|
| 3561 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3562 | - * still save a transient for the notice. |
|
| 3563 | - * @return void |
|
| 3564 | - * @throws EE_Error |
|
| 3565 | - */ |
|
| 3566 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3567 | - { |
|
| 3568 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3569 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3570 | - $notices = EE_Error::get_notices(false); |
|
| 3571 | - if (empty($this->_template_args['success'])) { |
|
| 3572 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3573 | - } |
|
| 3574 | - if (empty($this->_template_args['errors'])) { |
|
| 3575 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3576 | - } |
|
| 3577 | - if (empty($this->_template_args['attention'])) { |
|
| 3578 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3579 | - } |
|
| 3580 | - } |
|
| 3581 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3582 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3583 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3584 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3585 | - $this->_add_transient( |
|
| 3586 | - $route, |
|
| 3587 | - $this->_template_args['notices'], |
|
| 3588 | - true, |
|
| 3589 | - $skip_route_verify |
|
| 3590 | - ); |
|
| 3591 | - } |
|
| 3592 | - } |
|
| 3593 | - |
|
| 3594 | - |
|
| 3595 | - /** |
|
| 3596 | - * get_action_link_or_button |
|
| 3597 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3598 | - * |
|
| 3599 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3600 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3601 | - * property. |
|
| 3602 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3603 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3604 | - * @param string $base_url If this is not provided |
|
| 3605 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3606 | - * Otherwise this value will be used. |
|
| 3607 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3608 | - * @return string |
|
| 3609 | - * @throws InvalidArgumentException |
|
| 3610 | - * @throws InvalidInterfaceException |
|
| 3611 | - * @throws InvalidDataTypeException |
|
| 3612 | - * @throws EE_Error |
|
| 3613 | - */ |
|
| 3614 | - public function get_action_link_or_button( |
|
| 3615 | - $action, |
|
| 3616 | - $type = 'add', |
|
| 3617 | - $extra_request = array(), |
|
| 3618 | - $class = 'button-primary', |
|
| 3619 | - $base_url = '', |
|
| 3620 | - $exclude_nonce = false |
|
| 3621 | - ) { |
|
| 3622 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3623 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3624 | - throw new EE_Error( |
|
| 3625 | - sprintf( |
|
| 3626 | - esc_html__( |
|
| 3627 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3628 | - 'event_espresso' |
|
| 3629 | - ), |
|
| 3630 | - $action |
|
| 3631 | - ) |
|
| 3632 | - ); |
|
| 3633 | - } |
|
| 3634 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3635 | - throw new EE_Error( |
|
| 3636 | - sprintf( |
|
| 3637 | - __( |
|
| 3638 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3639 | - 'event_espresso' |
|
| 3640 | - ), |
|
| 3641 | - $type |
|
| 3642 | - ) |
|
| 3643 | - ); |
|
| 3644 | - } |
|
| 3645 | - // finally check user access for this button. |
|
| 3646 | - $has_access = $this->check_user_access($action, true); |
|
| 3647 | - if (! $has_access) { |
|
| 3648 | - return ''; |
|
| 3649 | - } |
|
| 3650 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3651 | - $query_args = array( |
|
| 3652 | - 'action' => $action, |
|
| 3653 | - ); |
|
| 3654 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3655 | - if (! empty($extra_request)) { |
|
| 3656 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3657 | - } |
|
| 3658 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3659 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3660 | - } |
|
| 3661 | - |
|
| 3662 | - |
|
| 3663 | - /** |
|
| 3664 | - * _per_page_screen_option |
|
| 3665 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3666 | - * |
|
| 3667 | - * @return void |
|
| 3668 | - * @throws InvalidArgumentException |
|
| 3669 | - * @throws InvalidInterfaceException |
|
| 3670 | - * @throws InvalidDataTypeException |
|
| 3671 | - */ |
|
| 3672 | - protected function _per_page_screen_option() |
|
| 3673 | - { |
|
| 3674 | - $option = 'per_page'; |
|
| 3675 | - $args = array( |
|
| 3676 | - 'label' => apply_filters( |
|
| 3677 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3678 | - $this->_admin_page_title, |
|
| 3679 | - $this |
|
| 3680 | - ), |
|
| 3681 | - 'default' => (int) apply_filters( |
|
| 3682 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3683 | - 10 |
|
| 3684 | - ), |
|
| 3685 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3686 | - ); |
|
| 3687 | - // ONLY add the screen option if the user has access to it. |
|
| 3688 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3689 | - add_screen_option($option, $args); |
|
| 3690 | - } |
|
| 3691 | - } |
|
| 3692 | - |
|
| 3693 | - |
|
| 3694 | - /** |
|
| 3695 | - * set_per_page_screen_option |
|
| 3696 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3697 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3698 | - * admin_menu. |
|
| 3699 | - * |
|
| 3700 | - * @return void |
|
| 3701 | - */ |
|
| 3702 | - private function _set_per_page_screen_options() |
|
| 3703 | - { |
|
| 3704 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3705 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3706 | - if (! $user = wp_get_current_user()) { |
|
| 3707 | - return; |
|
| 3708 | - } |
|
| 3709 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3710 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3711 | - if ($option != sanitize_key($option)) { |
|
| 3712 | - return; |
|
| 3713 | - } |
|
| 3714 | - $map_option = $option; |
|
| 3715 | - $option = str_replace('-', '_', $option); |
|
| 3716 | - switch ($map_option) { |
|
| 3717 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3718 | - $value = (int) $value; |
|
| 3719 | - $max_value = apply_filters( |
|
| 3720 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3721 | - 999, |
|
| 3722 | - $this->_current_page, |
|
| 3723 | - $this->_current_view |
|
| 3724 | - ); |
|
| 3725 | - if ($value < 1) { |
|
| 3726 | - return; |
|
| 3727 | - } |
|
| 3728 | - $value = min($value, $max_value); |
|
| 3729 | - break; |
|
| 3730 | - default: |
|
| 3731 | - $value = apply_filters( |
|
| 3732 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3733 | - false, |
|
| 3734 | - $option, |
|
| 3735 | - $value |
|
| 3736 | - ); |
|
| 3737 | - if (false === $value) { |
|
| 3738 | - return; |
|
| 3739 | - } |
|
| 3740 | - break; |
|
| 3741 | - } |
|
| 3742 | - update_user_meta($user->ID, $option, $value); |
|
| 3743 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3744 | - exit; |
|
| 3745 | - } |
|
| 3746 | - } |
|
| 3747 | - |
|
| 3748 | - |
|
| 3749 | - /** |
|
| 3750 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3751 | - * |
|
| 3752 | - * @param array $data array that will be assigned to template args. |
|
| 3753 | - */ |
|
| 3754 | - public function set_template_args($data) |
|
| 3755 | - { |
|
| 3756 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3757 | - } |
|
| 3758 | - |
|
| 3759 | - |
|
| 3760 | - /** |
|
| 3761 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3762 | - * |
|
| 3763 | - * @param string $route the route that should receive the transient |
|
| 3764 | - * @param array $data the data that gets sent |
|
| 3765 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3766 | - * normal route transient. |
|
| 3767 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3768 | - * when we are adding a transient before page_routes have been defined. |
|
| 3769 | - * @return void |
|
| 3770 | - * @throws EE_Error |
|
| 3771 | - */ |
|
| 3772 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3773 | - { |
|
| 3774 | - $user_id = get_current_user_id(); |
|
| 3775 | - if (! $skip_route_verify) { |
|
| 3776 | - $this->_verify_route($route); |
|
| 3777 | - } |
|
| 3778 | - // now let's set the string for what kind of transient we're setting |
|
| 3779 | - $transient = $notices |
|
| 3780 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3781 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3782 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3783 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3784 | - $existing = is_multisite() && is_network_admin() |
|
| 3785 | - ? get_site_transient($transient) |
|
| 3786 | - : get_transient($transient); |
|
| 3787 | - if ($existing) { |
|
| 3788 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3789 | - } |
|
| 3790 | - if (is_multisite() && is_network_admin()) { |
|
| 3791 | - set_site_transient($transient, $data, 8); |
|
| 3792 | - } else { |
|
| 3793 | - set_transient($transient, $data, 8); |
|
| 3794 | - } |
|
| 3795 | - } |
|
| 3796 | - |
|
| 3797 | - |
|
| 3798 | - /** |
|
| 3799 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3800 | - * |
|
| 3801 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3802 | - * @param string $route |
|
| 3803 | - * @return mixed data |
|
| 3804 | - */ |
|
| 3805 | - protected function _get_transient($notices = false, $route = '') |
|
| 3806 | - { |
|
| 3807 | - $user_id = get_current_user_id(); |
|
| 3808 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3809 | - $transient = $notices |
|
| 3810 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3811 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3812 | - $data = is_multisite() && is_network_admin() |
|
| 3813 | - ? get_site_transient($transient) |
|
| 3814 | - : get_transient($transient); |
|
| 3815 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3816 | - if (is_multisite() && is_network_admin()) { |
|
| 3817 | - delete_site_transient($transient); |
|
| 3818 | - } else { |
|
| 3819 | - delete_transient($transient); |
|
| 3820 | - } |
|
| 3821 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3822 | - } |
|
| 3823 | - |
|
| 3824 | - |
|
| 3825 | - /** |
|
| 3826 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3827 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3828 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3829 | - * |
|
| 3830 | - * @return void |
|
| 3831 | - */ |
|
| 3832 | - protected function _transient_garbage_collection() |
|
| 3833 | - { |
|
| 3834 | - global $wpdb; |
|
| 3835 | - // retrieve all existing transients |
|
| 3836 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3837 | - if ($results = $wpdb->get_results($query)) { |
|
| 3838 | - foreach ($results as $result) { |
|
| 3839 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3840 | - get_transient($transient); |
|
| 3841 | - if (is_multisite() && is_network_admin()) { |
|
| 3842 | - get_site_transient($transient); |
|
| 3843 | - } |
|
| 3844 | - } |
|
| 3845 | - } |
|
| 3846 | - } |
|
| 3847 | - |
|
| 3848 | - |
|
| 3849 | - /** |
|
| 3850 | - * get_view |
|
| 3851 | - * |
|
| 3852 | - * @return string content of _view property |
|
| 3853 | - */ |
|
| 3854 | - public function get_view() |
|
| 3855 | - { |
|
| 3856 | - return $this->_view; |
|
| 3857 | - } |
|
| 3858 | - |
|
| 3859 | - |
|
| 3860 | - /** |
|
| 3861 | - * getter for the protected $_views property |
|
| 3862 | - * |
|
| 3863 | - * @return array |
|
| 3864 | - */ |
|
| 3865 | - public function get_views() |
|
| 3866 | - { |
|
| 3867 | - return $this->_views; |
|
| 3868 | - } |
|
| 3869 | - |
|
| 3870 | - |
|
| 3871 | - /** |
|
| 3872 | - * get_current_page |
|
| 3873 | - * |
|
| 3874 | - * @return string _current_page property value |
|
| 3875 | - */ |
|
| 3876 | - public function get_current_page() |
|
| 3877 | - { |
|
| 3878 | - return $this->_current_page; |
|
| 3879 | - } |
|
| 3880 | - |
|
| 3881 | - |
|
| 3882 | - /** |
|
| 3883 | - * get_current_view |
|
| 3884 | - * |
|
| 3885 | - * @return string _current_view property value |
|
| 3886 | - */ |
|
| 3887 | - public function get_current_view() |
|
| 3888 | - { |
|
| 3889 | - return $this->_current_view; |
|
| 3890 | - } |
|
| 3891 | - |
|
| 3892 | - |
|
| 3893 | - /** |
|
| 3894 | - * get_current_screen |
|
| 3895 | - * |
|
| 3896 | - * @return object The current WP_Screen object |
|
| 3897 | - */ |
|
| 3898 | - public function get_current_screen() |
|
| 3899 | - { |
|
| 3900 | - return $this->_current_screen; |
|
| 3901 | - } |
|
| 3902 | - |
|
| 3903 | - |
|
| 3904 | - /** |
|
| 3905 | - * get_current_page_view_url |
|
| 3906 | - * |
|
| 3907 | - * @return string This returns the url for the current_page_view. |
|
| 3908 | - */ |
|
| 3909 | - public function get_current_page_view_url() |
|
| 3910 | - { |
|
| 3911 | - return $this->_current_page_view_url; |
|
| 3912 | - } |
|
| 3913 | - |
|
| 3914 | - |
|
| 3915 | - /** |
|
| 3916 | - * just returns the _req_data property |
|
| 3917 | - * |
|
| 3918 | - * @return array |
|
| 3919 | - */ |
|
| 3920 | - public function get_request_data() |
|
| 3921 | - { |
|
| 3922 | - return $this->_req_data; |
|
| 3923 | - } |
|
| 3924 | - |
|
| 3925 | - |
|
| 3926 | - /** |
|
| 3927 | - * returns the _req_data protected property |
|
| 3928 | - * |
|
| 3929 | - * @return string |
|
| 3930 | - */ |
|
| 3931 | - public function get_req_action() |
|
| 3932 | - { |
|
| 3933 | - return $this->_req_action; |
|
| 3934 | - } |
|
| 3935 | - |
|
| 3936 | - |
|
| 3937 | - /** |
|
| 3938 | - * @return bool value of $_is_caf property |
|
| 3939 | - */ |
|
| 3940 | - public function is_caf() |
|
| 3941 | - { |
|
| 3942 | - return $this->_is_caf; |
|
| 3943 | - } |
|
| 3944 | - |
|
| 3945 | - |
|
| 3946 | - /** |
|
| 3947 | - * @return mixed |
|
| 3948 | - */ |
|
| 3949 | - public function default_espresso_metaboxes() |
|
| 3950 | - { |
|
| 3951 | - return $this->_default_espresso_metaboxes; |
|
| 3952 | - } |
|
| 3953 | - |
|
| 3954 | - |
|
| 3955 | - /** |
|
| 3956 | - * @return mixed |
|
| 3957 | - */ |
|
| 3958 | - public function admin_base_url() |
|
| 3959 | - { |
|
| 3960 | - return $this->_admin_base_url; |
|
| 3961 | - } |
|
| 3962 | - |
|
| 3963 | - |
|
| 3964 | - /** |
|
| 3965 | - * @return mixed |
|
| 3966 | - */ |
|
| 3967 | - public function wp_page_slug() |
|
| 3968 | - { |
|
| 3969 | - return $this->_wp_page_slug; |
|
| 3970 | - } |
|
| 3971 | - |
|
| 3972 | - |
|
| 3973 | - /** |
|
| 3974 | - * updates espresso configuration settings |
|
| 3975 | - * |
|
| 3976 | - * @param string $tab |
|
| 3977 | - * @param EE_Config_Base|EE_Config $config |
|
| 3978 | - * @param string $file file where error occurred |
|
| 3979 | - * @param string $func function where error occurred |
|
| 3980 | - * @param string $line line no where error occurred |
|
| 3981 | - * @return boolean |
|
| 3982 | - */ |
|
| 3983 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3984 | - { |
|
| 3985 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 3986 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3987 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3988 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3989 | - update_option('ee_ueip_has_notified', true); |
|
| 3990 | - } |
|
| 3991 | - // and save it (note we're also doing the network save here) |
|
| 3992 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3993 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3994 | - if ($config_saved && $net_saved) { |
|
| 3995 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3996 | - return true; |
|
| 3997 | - } |
|
| 3998 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3999 | - return false; |
|
| 4000 | - } |
|
| 4001 | - |
|
| 4002 | - |
|
| 4003 | - /** |
|
| 4004 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4005 | - * |
|
| 4006 | - * @return array |
|
| 4007 | - */ |
|
| 4008 | - public function get_yes_no_values() |
|
| 4009 | - { |
|
| 4010 | - return $this->_yes_no_values; |
|
| 4011 | - } |
|
| 4012 | - |
|
| 4013 | - |
|
| 4014 | - protected function _get_dir() |
|
| 4015 | - { |
|
| 4016 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4017 | - return dirname($reflector->getFileName()); |
|
| 4018 | - } |
|
| 4019 | - |
|
| 4020 | - |
|
| 4021 | - /** |
|
| 4022 | - * A helper for getting a "next link". |
|
| 4023 | - * |
|
| 4024 | - * @param string $url The url to link to |
|
| 4025 | - * @param string $class The class to use. |
|
| 4026 | - * @return string |
|
| 4027 | - */ |
|
| 4028 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4029 | - { |
|
| 4030 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4031 | - } |
|
| 4032 | - |
|
| 4033 | - |
|
| 4034 | - /** |
|
| 4035 | - * A helper for getting a "previous link". |
|
| 4036 | - * |
|
| 4037 | - * @param string $url The url to link to |
|
| 4038 | - * @param string $class The class to use. |
|
| 4039 | - * @return string |
|
| 4040 | - */ |
|
| 4041 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4042 | - { |
|
| 4043 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4044 | - } |
|
| 4045 | - |
|
| 4046 | - |
|
| 4047 | - |
|
| 4048 | - |
|
| 4049 | - |
|
| 4050 | - |
|
| 4051 | - |
|
| 4052 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4053 | - |
|
| 4054 | - |
|
| 4055 | - /** |
|
| 4056 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4057 | - * 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 |
|
| 4058 | - * _req_data array. |
|
| 4059 | - * |
|
| 4060 | - * @return bool success/fail |
|
| 4061 | - * @throws EE_Error |
|
| 4062 | - * @throws InvalidArgumentException |
|
| 4063 | - * @throws ReflectionException |
|
| 4064 | - * @throws InvalidDataTypeException |
|
| 4065 | - * @throws InvalidInterfaceException |
|
| 4066 | - */ |
|
| 4067 | - protected function _process_resend_registration() |
|
| 4068 | - { |
|
| 4069 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4070 | - do_action( |
|
| 4071 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4072 | - $this->_template_args['success'], |
|
| 4073 | - $this->_req_data |
|
| 4074 | - ); |
|
| 4075 | - return $this->_template_args['success']; |
|
| 4076 | - } |
|
| 4077 | - |
|
| 4078 | - |
|
| 4079 | - /** |
|
| 4080 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4081 | - * |
|
| 4082 | - * @param \EE_Payment $payment |
|
| 4083 | - * @return bool success/fail |
|
| 4084 | - */ |
|
| 4085 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4086 | - { |
|
| 4087 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4088 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4089 | - $this->_template_args['success'] = apply_filters( |
|
| 4090 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4091 | - false, |
|
| 4092 | - $payment |
|
| 4093 | - ); |
|
| 4094 | - return $this->_template_args['success']; |
|
| 4095 | - } |
|
| 2697 | + } |
|
| 2698 | + |
|
| 2699 | + |
|
| 2700 | + /** |
|
| 2701 | + * facade for add_meta_box |
|
| 2702 | + * |
|
| 2703 | + * @param string $action where the metabox get's displayed |
|
| 2704 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2705 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2706 | + * instead of the one created in here. |
|
| 2707 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2708 | + * @param string $column what metabox column |
|
| 2709 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2710 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2711 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2712 | + * @throws \DomainException |
|
| 2713 | + */ |
|
| 2714 | + public function _add_admin_page_meta_box( |
|
| 2715 | + $action, |
|
| 2716 | + $title, |
|
| 2717 | + $callback, |
|
| 2718 | + $callback_args, |
|
| 2719 | + $column = 'normal', |
|
| 2720 | + $priority = 'high', |
|
| 2721 | + $create_func = true |
|
| 2722 | + ) { |
|
| 2723 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2724 | + // 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. |
|
| 2725 | + if (empty($callback_args) && $create_func) { |
|
| 2726 | + $callback_args = array( |
|
| 2727 | + 'template_path' => $this->_template_path, |
|
| 2728 | + 'template_args' => $this->_template_args, |
|
| 2729 | + ); |
|
| 2730 | + } |
|
| 2731 | + // 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) |
|
| 2732 | + $call_back_func = $create_func |
|
| 2733 | + ? function ($post, $metabox) { |
|
| 2734 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2735 | + echo EEH_Template::display_template( |
|
| 2736 | + $metabox['args']['template_path'], |
|
| 2737 | + $metabox['args']['template_args'], |
|
| 2738 | + true |
|
| 2739 | + ); |
|
| 2740 | + } |
|
| 2741 | + : $callback; |
|
| 2742 | + add_meta_box( |
|
| 2743 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2744 | + $title, |
|
| 2745 | + $call_back_func, |
|
| 2746 | + $this->_wp_page_slug, |
|
| 2747 | + $column, |
|
| 2748 | + $priority, |
|
| 2749 | + $callback_args |
|
| 2750 | + ); |
|
| 2751 | + } |
|
| 2752 | + |
|
| 2753 | + |
|
| 2754 | + /** |
|
| 2755 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2756 | + * |
|
| 2757 | + * @throws DomainException |
|
| 2758 | + * @throws EE_Error |
|
| 2759 | + */ |
|
| 2760 | + public function display_admin_page_with_metabox_columns() |
|
| 2761 | + { |
|
| 2762 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2763 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2764 | + $this->_column_template_path, |
|
| 2765 | + $this->_template_args, |
|
| 2766 | + true |
|
| 2767 | + ); |
|
| 2768 | + // the final wrapper |
|
| 2769 | + $this->admin_page_wrapper(); |
|
| 2770 | + } |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * generates HTML wrapper for an admin details page |
|
| 2775 | + * |
|
| 2776 | + * @return void |
|
| 2777 | + * @throws EE_Error |
|
| 2778 | + * @throws DomainException |
|
| 2779 | + */ |
|
| 2780 | + public function display_admin_page_with_sidebar() |
|
| 2781 | + { |
|
| 2782 | + $this->_display_admin_page(true); |
|
| 2783 | + } |
|
| 2784 | + |
|
| 2785 | + |
|
| 2786 | + /** |
|
| 2787 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2788 | + * |
|
| 2789 | + * @return void |
|
| 2790 | + * @throws EE_Error |
|
| 2791 | + * @throws DomainException |
|
| 2792 | + */ |
|
| 2793 | + public function display_admin_page_with_no_sidebar() |
|
| 2794 | + { |
|
| 2795 | + $this->_display_admin_page(); |
|
| 2796 | + } |
|
| 2797 | + |
|
| 2798 | + |
|
| 2799 | + /** |
|
| 2800 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2801 | + * |
|
| 2802 | + * @return void |
|
| 2803 | + * @throws EE_Error |
|
| 2804 | + * @throws DomainException |
|
| 2805 | + */ |
|
| 2806 | + public function display_about_admin_page() |
|
| 2807 | + { |
|
| 2808 | + $this->_display_admin_page(false, true); |
|
| 2809 | + } |
|
| 2810 | + |
|
| 2811 | + |
|
| 2812 | + /** |
|
| 2813 | + * display_admin_page |
|
| 2814 | + * contains the code for actually displaying an admin page |
|
| 2815 | + * |
|
| 2816 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2817 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2818 | + * @return void |
|
| 2819 | + * @throws DomainException |
|
| 2820 | + * @throws EE_Error |
|
| 2821 | + */ |
|
| 2822 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2823 | + { |
|
| 2824 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2825 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2826 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2827 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2828 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2829 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2830 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2831 | + ? 'poststuff' |
|
| 2832 | + : 'espresso-default-admin'; |
|
| 2833 | + $template_path = $sidebar |
|
| 2834 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2835 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2836 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2837 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2838 | + } |
|
| 2839 | + $template_path = ! empty($this->_column_template_path) |
|
| 2840 | + ? $this->_column_template_path : $template_path; |
|
| 2841 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2842 | + ? $this->_template_args['admin_page_content'] |
|
| 2843 | + : ''; |
|
| 2844 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2845 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2846 | + : ''; |
|
| 2847 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2848 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2849 | + : ''; |
|
| 2850 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2851 | + $template_path, |
|
| 2852 | + $this->_template_args, |
|
| 2853 | + true |
|
| 2854 | + ); |
|
| 2855 | + // the final template wrapper |
|
| 2856 | + $this->admin_page_wrapper($about); |
|
| 2857 | + } |
|
| 2858 | + |
|
| 2859 | + |
|
| 2860 | + /** |
|
| 2861 | + * This is used to display caf preview pages. |
|
| 2862 | + * |
|
| 2863 | + * @since 4.3.2 |
|
| 2864 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2865 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2866 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2867 | + * @return void |
|
| 2868 | + * @throws DomainException |
|
| 2869 | + * @throws EE_Error |
|
| 2870 | + * @throws InvalidArgumentException |
|
| 2871 | + * @throws InvalidDataTypeException |
|
| 2872 | + * @throws InvalidInterfaceException |
|
| 2873 | + */ |
|
| 2874 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2875 | + { |
|
| 2876 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2877 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2878 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2879 | + 'event_espresso' |
|
| 2880 | + ); |
|
| 2881 | + $buy_now_url = add_query_arg( |
|
| 2882 | + array( |
|
| 2883 | + 'ee_ver' => 'ee4', |
|
| 2884 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2885 | + 'utm_medium' => 'link', |
|
| 2886 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2887 | + 'utm_content' => 'buy_now_button', |
|
| 2888 | + ), |
|
| 2889 | + 'http://eventespresso.com/pricing/' |
|
| 2890 | + ); |
|
| 2891 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2892 | + ? $this->get_action_link_or_button( |
|
| 2893 | + '', |
|
| 2894 | + 'buy_now', |
|
| 2895 | + array(), |
|
| 2896 | + 'button-primary button-large', |
|
| 2897 | + $buy_now_url, |
|
| 2898 | + true |
|
| 2899 | + ) |
|
| 2900 | + : $this->_template_args['preview_action_button']; |
|
| 2901 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2902 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2903 | + $this->_template_args, |
|
| 2904 | + true |
|
| 2905 | + ); |
|
| 2906 | + $this->_display_admin_page($display_sidebar); |
|
| 2907 | + } |
|
| 2908 | + |
|
| 2909 | + |
|
| 2910 | + /** |
|
| 2911 | + * display_admin_list_table_page_with_sidebar |
|
| 2912 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2913 | + * |
|
| 2914 | + * @return void |
|
| 2915 | + * @throws EE_Error |
|
| 2916 | + * @throws DomainException |
|
| 2917 | + */ |
|
| 2918 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2919 | + { |
|
| 2920 | + $this->_display_admin_list_table_page(true); |
|
| 2921 | + } |
|
| 2922 | + |
|
| 2923 | + |
|
| 2924 | + /** |
|
| 2925 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2926 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2927 | + * |
|
| 2928 | + * @return void |
|
| 2929 | + * @throws EE_Error |
|
| 2930 | + * @throws DomainException |
|
| 2931 | + */ |
|
| 2932 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2933 | + { |
|
| 2934 | + $this->_display_admin_list_table_page(); |
|
| 2935 | + } |
|
| 2936 | + |
|
| 2937 | + |
|
| 2938 | + /** |
|
| 2939 | + * generates html wrapper for an admin_list_table page |
|
| 2940 | + * |
|
| 2941 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2942 | + * @return void |
|
| 2943 | + * @throws DomainException |
|
| 2944 | + * @throws EE_Error |
|
| 2945 | + */ |
|
| 2946 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2947 | + { |
|
| 2948 | + // setup search attributes |
|
| 2949 | + $this->_set_search_attributes(); |
|
| 2950 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2951 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2952 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2953 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2954 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2955 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2956 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2957 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2958 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2959 | + if (! empty($ajax_sorting_callback)) { |
|
| 2960 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2961 | + $ajax_sorting_callback . '_nonce', |
|
| 2962 | + $ajax_sorting_callback . '_nonce', |
|
| 2963 | + false, |
|
| 2964 | + false |
|
| 2965 | + ); |
|
| 2966 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 2967 | + . $this->page_slug |
|
| 2968 | + . '" />'; |
|
| 2969 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 2970 | + . $ajax_sorting_callback |
|
| 2971 | + . '" />'; |
|
| 2972 | + } else { |
|
| 2973 | + $sortable_list_table_form_fields = ''; |
|
| 2974 | + } |
|
| 2975 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2976 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 2977 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 2978 | + : ''; |
|
| 2979 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2980 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 2981 | + . $nonce_ref |
|
| 2982 | + . '" value="' |
|
| 2983 | + . wp_create_nonce($nonce_ref) |
|
| 2984 | + . '">'; |
|
| 2985 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2986 | + // display message about search results? |
|
| 2987 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2988 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2989 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 2990 | + trim($this->_req_data['s'], '%') |
|
| 2991 | + ) . '</p>' |
|
| 2992 | + : ''; |
|
| 2993 | + // filter before_list_table template arg |
|
| 2994 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 2995 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2996 | + $this->_template_args['before_list_table'], |
|
| 2997 | + $this->page_slug, |
|
| 2998 | + $this->_req_data, |
|
| 2999 | + $this->_req_action |
|
| 3000 | + ); |
|
| 3001 | + // convert to array and filter again |
|
| 3002 | + // arrays are easier to inject new items in a specific location, |
|
| 3003 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3004 | + $this->_template_args['before_list_table'] = implode( |
|
| 3005 | + " \n", |
|
| 3006 | + (array) apply_filters( |
|
| 3007 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3008 | + (array) $this->_template_args['before_list_table'], |
|
| 3009 | + $this->page_slug, |
|
| 3010 | + $this->_req_data, |
|
| 3011 | + $this->_req_action |
|
| 3012 | + ) |
|
| 3013 | + ); |
|
| 3014 | + // filter after_list_table template arg |
|
| 3015 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3016 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3017 | + $this->_template_args['after_list_table'], |
|
| 3018 | + $this->page_slug, |
|
| 3019 | + $this->_req_data, |
|
| 3020 | + $this->_req_action |
|
| 3021 | + ); |
|
| 3022 | + // convert to array and filter again |
|
| 3023 | + // arrays are easier to inject new items in a specific location, |
|
| 3024 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3025 | + $this->_template_args['after_list_table'] = implode( |
|
| 3026 | + " \n", |
|
| 3027 | + (array) apply_filters( |
|
| 3028 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3029 | + (array) $this->_template_args['after_list_table'], |
|
| 3030 | + $this->page_slug, |
|
| 3031 | + $this->_req_data, |
|
| 3032 | + $this->_req_action |
|
| 3033 | + ) |
|
| 3034 | + ); |
|
| 3035 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3036 | + $template_path, |
|
| 3037 | + $this->_template_args, |
|
| 3038 | + true |
|
| 3039 | + ); |
|
| 3040 | + // the final template wrapper |
|
| 3041 | + if ($sidebar) { |
|
| 3042 | + $this->display_admin_page_with_sidebar(); |
|
| 3043 | + } else { |
|
| 3044 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3045 | + } |
|
| 3046 | + } |
|
| 3047 | + |
|
| 3048 | + |
|
| 3049 | + /** |
|
| 3050 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3051 | + * html string for the legend. |
|
| 3052 | + * $items are expected in an array in the following format: |
|
| 3053 | + * $legend_items = array( |
|
| 3054 | + * 'item_id' => array( |
|
| 3055 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3056 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3057 | + * ) |
|
| 3058 | + * ); |
|
| 3059 | + * |
|
| 3060 | + * @param array $items see above for format of array |
|
| 3061 | + * @return string html string of legend |
|
| 3062 | + * @throws DomainException |
|
| 3063 | + */ |
|
| 3064 | + protected function _display_legend($items) |
|
| 3065 | + { |
|
| 3066 | + $this->_template_args['items'] = apply_filters( |
|
| 3067 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3068 | + (array) $items, |
|
| 3069 | + $this |
|
| 3070 | + ); |
|
| 3071 | + return EEH_Template::display_template( |
|
| 3072 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3073 | + $this->_template_args, |
|
| 3074 | + true |
|
| 3075 | + ); |
|
| 3076 | + } |
|
| 3077 | + |
|
| 3078 | + |
|
| 3079 | + /** |
|
| 3080 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3081 | + * The returned json object is created from an array in the following format: |
|
| 3082 | + * array( |
|
| 3083 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3084 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3085 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3086 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3087 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3088 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3089 | + * that might be included in here) |
|
| 3090 | + * ) |
|
| 3091 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3092 | + * |
|
| 3093 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3094 | + * instead of displayed. |
|
| 3095 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3096 | + * @return void |
|
| 3097 | + * @throws EE_Error |
|
| 3098 | + */ |
|
| 3099 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3100 | + { |
|
| 3101 | + // make sure any EE_Error notices have been handled. |
|
| 3102 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3103 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3104 | + unset($this->_template_args['data']); |
|
| 3105 | + $json = array( |
|
| 3106 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3107 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3108 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3109 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3110 | + 'notices' => EE_Error::get_notices(), |
|
| 3111 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3112 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3113 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3114 | + 'isEEajax' => true |
|
| 3115 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3116 | + ); |
|
| 3117 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3118 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3119 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3120 | + } |
|
| 3121 | + echo wp_json_encode($json); |
|
| 3122 | + exit(); |
|
| 3123 | + } |
|
| 3124 | + |
|
| 3125 | + |
|
| 3126 | + /** |
|
| 3127 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3128 | + * |
|
| 3129 | + * @return void |
|
| 3130 | + * @throws EE_Error |
|
| 3131 | + */ |
|
| 3132 | + public function return_json() |
|
| 3133 | + { |
|
| 3134 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3135 | + $this->_return_json(); |
|
| 3136 | + } else { |
|
| 3137 | + throw new EE_Error( |
|
| 3138 | + sprintf( |
|
| 3139 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3140 | + __FUNCTION__ |
|
| 3141 | + ) |
|
| 3142 | + ); |
|
| 3143 | + } |
|
| 3144 | + } |
|
| 3145 | + |
|
| 3146 | + |
|
| 3147 | + /** |
|
| 3148 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3149 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3150 | + * |
|
| 3151 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3152 | + */ |
|
| 3153 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3154 | + { |
|
| 3155 | + $this->_hook_obj = $hook_obj; |
|
| 3156 | + } |
|
| 3157 | + |
|
| 3158 | + |
|
| 3159 | + /** |
|
| 3160 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3161 | + * |
|
| 3162 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3163 | + * @return void |
|
| 3164 | + * @throws DomainException |
|
| 3165 | + * @throws EE_Error |
|
| 3166 | + */ |
|
| 3167 | + public function admin_page_wrapper($about = false) |
|
| 3168 | + { |
|
| 3169 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3170 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3171 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3172 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3173 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3174 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3175 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3176 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3177 | + : '' |
|
| 3178 | + ); |
|
| 3179 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3180 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3181 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3182 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3183 | + : '' |
|
| 3184 | + ); |
|
| 3185 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3186 | + // load settings page wrapper template |
|
| 3187 | + $template_path = ! defined('DOING_AJAX') |
|
| 3188 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3189 | + : EE_ADMIN_TEMPLATE |
|
| 3190 | + . 'admin_wrapper_ajax.template.php'; |
|
| 3191 | + // about page? |
|
| 3192 | + $template_path = $about |
|
| 3193 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3194 | + : $template_path; |
|
| 3195 | + if (defined('DOING_AJAX')) { |
|
| 3196 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3197 | + $template_path, |
|
| 3198 | + $this->_template_args, |
|
| 3199 | + true |
|
| 3200 | + ); |
|
| 3201 | + $this->_return_json(); |
|
| 3202 | + } else { |
|
| 3203 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3204 | + } |
|
| 3205 | + } |
|
| 3206 | + |
|
| 3207 | + |
|
| 3208 | + /** |
|
| 3209 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3210 | + * |
|
| 3211 | + * @return string html |
|
| 3212 | + * @throws EE_Error |
|
| 3213 | + */ |
|
| 3214 | + protected function _get_main_nav_tabs() |
|
| 3215 | + { |
|
| 3216 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3217 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3218 | + // (rather than setting in the page_routes array) |
|
| 3219 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3220 | + } |
|
| 3221 | + |
|
| 3222 | + |
|
| 3223 | + /** |
|
| 3224 | + * sort nav tabs |
|
| 3225 | + * |
|
| 3226 | + * @param $a |
|
| 3227 | + * @param $b |
|
| 3228 | + * @return int |
|
| 3229 | + */ |
|
| 3230 | + private function _sort_nav_tabs($a, $b) |
|
| 3231 | + { |
|
| 3232 | + if ($a['order'] === $b['order']) { |
|
| 3233 | + return 0; |
|
| 3234 | + } |
|
| 3235 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3236 | + } |
|
| 3237 | + |
|
| 3238 | + |
|
| 3239 | + /** |
|
| 3240 | + * generates HTML for the forms used on admin pages |
|
| 3241 | + * |
|
| 3242 | + * @param array $input_vars - array of input field details |
|
| 3243 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3244 | + * use) |
|
| 3245 | + * @param bool $id |
|
| 3246 | + * @return string |
|
| 3247 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3248 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3249 | + */ |
|
| 3250 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 3251 | + { |
|
| 3252 | + $content = $generator === 'string' |
|
| 3253 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3254 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3255 | + return $content; |
|
| 3256 | + } |
|
| 3257 | + |
|
| 3258 | + |
|
| 3259 | + /** |
|
| 3260 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3261 | + * |
|
| 3262 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3263 | + * Close" button. |
|
| 3264 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3265 | + * 'Save', [1] => 'save & close') |
|
| 3266 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3267 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3268 | + * default actions by submitting some other value. |
|
| 3269 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3270 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3271 | + * close (normal form handling). |
|
| 3272 | + */ |
|
| 3273 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3274 | + { |
|
| 3275 | + // make sure $text and $actions are in an array |
|
| 3276 | + $text = (array) $text; |
|
| 3277 | + $actions = (array) $actions; |
|
| 3278 | + $referrer_url = empty($referrer) |
|
| 3279 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3280 | + . $_SERVER['REQUEST_URI'] |
|
| 3281 | + . '" />' |
|
| 3282 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3283 | + . $referrer |
|
| 3284 | + . '" />'; |
|
| 3285 | + $button_text = ! empty($text) |
|
| 3286 | + ? $text |
|
| 3287 | + : array( |
|
| 3288 | + esc_html__('Save', 'event_espresso'), |
|
| 3289 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3290 | + ); |
|
| 3291 | + $default_names = array('save', 'save_and_close'); |
|
| 3292 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3293 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3294 | + foreach ($button_text as $key => $button) { |
|
| 3295 | + $ref = $default_names[ $key ]; |
|
| 3296 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3297 | + . $ref |
|
| 3298 | + . '" value="' |
|
| 3299 | + . $button |
|
| 3300 | + . '" name="' |
|
| 3301 | + . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3302 | + . '" id="' |
|
| 3303 | + . $this->_current_view . '_' . $ref |
|
| 3304 | + . '" />'; |
|
| 3305 | + if (! $both) { |
|
| 3306 | + break; |
|
| 3307 | + } |
|
| 3308 | + } |
|
| 3309 | + } |
|
| 3310 | + |
|
| 3311 | + |
|
| 3312 | + /** |
|
| 3313 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3314 | + * |
|
| 3315 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3316 | + * @since 4.6.0 |
|
| 3317 | + * @param string $route |
|
| 3318 | + * @param array $additional_hidden_fields |
|
| 3319 | + */ |
|
| 3320 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3321 | + { |
|
| 3322 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3323 | + } |
|
| 3324 | + |
|
| 3325 | + |
|
| 3326 | + /** |
|
| 3327 | + * set form open and close tags on add/edit pages. |
|
| 3328 | + * |
|
| 3329 | + * @param string $route the route you want the form to direct to |
|
| 3330 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3331 | + * @return void |
|
| 3332 | + */ |
|
| 3333 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3334 | + { |
|
| 3335 | + if (empty($route)) { |
|
| 3336 | + $user_msg = esc_html__( |
|
| 3337 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3338 | + 'event_espresso' |
|
| 3339 | + ); |
|
| 3340 | + $dev_msg = $user_msg . "\n" |
|
| 3341 | + . sprintf( |
|
| 3342 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3343 | + __FUNCTION__, |
|
| 3344 | + __CLASS__ |
|
| 3345 | + ); |
|
| 3346 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3347 | + } |
|
| 3348 | + // open form |
|
| 3349 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3350 | + . $this->_admin_base_url |
|
| 3351 | + . '" id="' |
|
| 3352 | + . $route |
|
| 3353 | + . '_event_form" >'; |
|
| 3354 | + // add nonce |
|
| 3355 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3356 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3357 | + // add REQUIRED form action |
|
| 3358 | + $hidden_fields = array( |
|
| 3359 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3360 | + ); |
|
| 3361 | + // merge arrays |
|
| 3362 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3363 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3364 | + : $hidden_fields; |
|
| 3365 | + // generate form fields |
|
| 3366 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3367 | + // add fields to form |
|
| 3368 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3369 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3370 | + } |
|
| 3371 | + // close form |
|
| 3372 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3373 | + } |
|
| 3374 | + |
|
| 3375 | + |
|
| 3376 | + /** |
|
| 3377 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3378 | + * discovered it would be useful for external code to have access. |
|
| 3379 | + * |
|
| 3380 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3381 | + * @since 4.5.0 |
|
| 3382 | + * @param bool $success |
|
| 3383 | + * @param string $what |
|
| 3384 | + * @param string $action_desc |
|
| 3385 | + * @param array $query_args |
|
| 3386 | + * @param bool $override_overwrite |
|
| 3387 | + * @throws EE_Error |
|
| 3388 | + */ |
|
| 3389 | + public function redirect_after_action( |
|
| 3390 | + $success = false, |
|
| 3391 | + $what = 'item', |
|
| 3392 | + $action_desc = 'processed', |
|
| 3393 | + $query_args = array(), |
|
| 3394 | + $override_overwrite = false |
|
| 3395 | + ) { |
|
| 3396 | + $this->_redirect_after_action( |
|
| 3397 | + $success, |
|
| 3398 | + $what, |
|
| 3399 | + $action_desc, |
|
| 3400 | + $query_args, |
|
| 3401 | + $override_overwrite |
|
| 3402 | + ); |
|
| 3403 | + } |
|
| 3404 | + |
|
| 3405 | + |
|
| 3406 | + /** |
|
| 3407 | + * _redirect_after_action |
|
| 3408 | + * |
|
| 3409 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3410 | + * @param string $what - what the action was performed on |
|
| 3411 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3412 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3413 | + * action is completed |
|
| 3414 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3415 | + * override this so that they show. |
|
| 3416 | + * @return void |
|
| 3417 | + * @throws EE_Error |
|
| 3418 | + */ |
|
| 3419 | + protected function _redirect_after_action( |
|
| 3420 | + $success = 0, |
|
| 3421 | + $what = 'item', |
|
| 3422 | + $action_desc = 'processed', |
|
| 3423 | + $query_args = array(), |
|
| 3424 | + $override_overwrite = false |
|
| 3425 | + ) { |
|
| 3426 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3427 | + // class name for actions/filters. |
|
| 3428 | + $classname = get_class($this); |
|
| 3429 | + // set redirect url. |
|
| 3430 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3431 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3432 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3433 | + $notices = EE_Error::get_notices(false); |
|
| 3434 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3435 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3436 | + EE_Error::overwrite_success(); |
|
| 3437 | + } |
|
| 3438 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3439 | + // how many records affected ? more than one record ? or just one ? |
|
| 3440 | + if ($success > 1) { |
|
| 3441 | + // set plural msg |
|
| 3442 | + EE_Error::add_success( |
|
| 3443 | + sprintf( |
|
| 3444 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3445 | + $what, |
|
| 3446 | + $action_desc |
|
| 3447 | + ), |
|
| 3448 | + __FILE__, |
|
| 3449 | + __FUNCTION__, |
|
| 3450 | + __LINE__ |
|
| 3451 | + ); |
|
| 3452 | + } elseif ($success === 1) { |
|
| 3453 | + // set singular msg |
|
| 3454 | + EE_Error::add_success( |
|
| 3455 | + sprintf( |
|
| 3456 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3457 | + $what, |
|
| 3458 | + $action_desc |
|
| 3459 | + ), |
|
| 3460 | + __FILE__, |
|
| 3461 | + __FUNCTION__, |
|
| 3462 | + __LINE__ |
|
| 3463 | + ); |
|
| 3464 | + } |
|
| 3465 | + } |
|
| 3466 | + // check that $query_args isn't something crazy |
|
| 3467 | + if (! is_array($query_args)) { |
|
| 3468 | + $query_args = array(); |
|
| 3469 | + } |
|
| 3470 | + /** |
|
| 3471 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3472 | + * redirections on save and close actions |
|
| 3473 | + * |
|
| 3474 | + * @since 4.2.0 |
|
| 3475 | + * @param array $query_args The original query_args array coming into the |
|
| 3476 | + * method. |
|
| 3477 | + */ |
|
| 3478 | + do_action( |
|
| 3479 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3480 | + $query_args |
|
| 3481 | + ); |
|
| 3482 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3483 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3484 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3485 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3486 | + // regenerate query args array from referrer URL |
|
| 3487 | + parse_str($parsed_url['query'], $query_args); |
|
| 3488 | + // correct page and action will be in the query args now |
|
| 3489 | + $redirect_url = admin_url('admin.php'); |
|
| 3490 | + } |
|
| 3491 | + // merge any default query_args set in _default_route_query_args property |
|
| 3492 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3493 | + $args_to_merge = array(); |
|
| 3494 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3495 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3496 | + if ($query_param === 'wp_referer') { |
|
| 3497 | + $query_value = (array) $query_value; |
|
| 3498 | + foreach ($query_value as $reference => $value) { |
|
| 3499 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3500 | + continue; |
|
| 3501 | + } |
|
| 3502 | + // finally we will override any arguments in the referer with |
|
| 3503 | + // what might be set on the _default_route_query_args array. |
|
| 3504 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3505 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3506 | + } else { |
|
| 3507 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3508 | + } |
|
| 3509 | + } |
|
| 3510 | + continue; |
|
| 3511 | + } |
|
| 3512 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3513 | + } |
|
| 3514 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3515 | + // redirect. |
|
| 3516 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3517 | + } |
|
| 3518 | + $this->_process_notices($query_args); |
|
| 3519 | + // generate redirect url |
|
| 3520 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3521 | + if (isset($query_args['action'])) { |
|
| 3522 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3523 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3524 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3525 | + } |
|
| 3526 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3527 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3528 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3529 | + $redirect_url = apply_filters( |
|
| 3530 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3531 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3532 | + $query_args |
|
| 3533 | + ); |
|
| 3534 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3535 | + if (defined('DOING_AJAX')) { |
|
| 3536 | + $default_data = array( |
|
| 3537 | + 'close' => true, |
|
| 3538 | + 'redirect_url' => $redirect_url, |
|
| 3539 | + 'where' => 'main', |
|
| 3540 | + 'what' => 'append', |
|
| 3541 | + ); |
|
| 3542 | + $this->_template_args['success'] = $success; |
|
| 3543 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3544 | + $default_data, |
|
| 3545 | + $this->_template_args['data'] |
|
| 3546 | + ) : $default_data; |
|
| 3547 | + $this->_return_json(); |
|
| 3548 | + } |
|
| 3549 | + wp_safe_redirect($redirect_url); |
|
| 3550 | + exit(); |
|
| 3551 | + } |
|
| 3552 | + |
|
| 3553 | + |
|
| 3554 | + /** |
|
| 3555 | + * process any notices before redirecting (or returning ajax request) |
|
| 3556 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3557 | + * |
|
| 3558 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3559 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3560 | + * page_routes haven't been defined yet. |
|
| 3561 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3562 | + * still save a transient for the notice. |
|
| 3563 | + * @return void |
|
| 3564 | + * @throws EE_Error |
|
| 3565 | + */ |
|
| 3566 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3567 | + { |
|
| 3568 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3569 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3570 | + $notices = EE_Error::get_notices(false); |
|
| 3571 | + if (empty($this->_template_args['success'])) { |
|
| 3572 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3573 | + } |
|
| 3574 | + if (empty($this->_template_args['errors'])) { |
|
| 3575 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3576 | + } |
|
| 3577 | + if (empty($this->_template_args['attention'])) { |
|
| 3578 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3579 | + } |
|
| 3580 | + } |
|
| 3581 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3582 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3583 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3584 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3585 | + $this->_add_transient( |
|
| 3586 | + $route, |
|
| 3587 | + $this->_template_args['notices'], |
|
| 3588 | + true, |
|
| 3589 | + $skip_route_verify |
|
| 3590 | + ); |
|
| 3591 | + } |
|
| 3592 | + } |
|
| 3593 | + |
|
| 3594 | + |
|
| 3595 | + /** |
|
| 3596 | + * get_action_link_or_button |
|
| 3597 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3598 | + * |
|
| 3599 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3600 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3601 | + * property. |
|
| 3602 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3603 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3604 | + * @param string $base_url If this is not provided |
|
| 3605 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3606 | + * Otherwise this value will be used. |
|
| 3607 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3608 | + * @return string |
|
| 3609 | + * @throws InvalidArgumentException |
|
| 3610 | + * @throws InvalidInterfaceException |
|
| 3611 | + * @throws InvalidDataTypeException |
|
| 3612 | + * @throws EE_Error |
|
| 3613 | + */ |
|
| 3614 | + public function get_action_link_or_button( |
|
| 3615 | + $action, |
|
| 3616 | + $type = 'add', |
|
| 3617 | + $extra_request = array(), |
|
| 3618 | + $class = 'button-primary', |
|
| 3619 | + $base_url = '', |
|
| 3620 | + $exclude_nonce = false |
|
| 3621 | + ) { |
|
| 3622 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3623 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3624 | + throw new EE_Error( |
|
| 3625 | + sprintf( |
|
| 3626 | + esc_html__( |
|
| 3627 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3628 | + 'event_espresso' |
|
| 3629 | + ), |
|
| 3630 | + $action |
|
| 3631 | + ) |
|
| 3632 | + ); |
|
| 3633 | + } |
|
| 3634 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3635 | + throw new EE_Error( |
|
| 3636 | + sprintf( |
|
| 3637 | + __( |
|
| 3638 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3639 | + 'event_espresso' |
|
| 3640 | + ), |
|
| 3641 | + $type |
|
| 3642 | + ) |
|
| 3643 | + ); |
|
| 3644 | + } |
|
| 3645 | + // finally check user access for this button. |
|
| 3646 | + $has_access = $this->check_user_access($action, true); |
|
| 3647 | + if (! $has_access) { |
|
| 3648 | + return ''; |
|
| 3649 | + } |
|
| 3650 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3651 | + $query_args = array( |
|
| 3652 | + 'action' => $action, |
|
| 3653 | + ); |
|
| 3654 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3655 | + if (! empty($extra_request)) { |
|
| 3656 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3657 | + } |
|
| 3658 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3659 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3660 | + } |
|
| 3661 | + |
|
| 3662 | + |
|
| 3663 | + /** |
|
| 3664 | + * _per_page_screen_option |
|
| 3665 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3666 | + * |
|
| 3667 | + * @return void |
|
| 3668 | + * @throws InvalidArgumentException |
|
| 3669 | + * @throws InvalidInterfaceException |
|
| 3670 | + * @throws InvalidDataTypeException |
|
| 3671 | + */ |
|
| 3672 | + protected function _per_page_screen_option() |
|
| 3673 | + { |
|
| 3674 | + $option = 'per_page'; |
|
| 3675 | + $args = array( |
|
| 3676 | + 'label' => apply_filters( |
|
| 3677 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3678 | + $this->_admin_page_title, |
|
| 3679 | + $this |
|
| 3680 | + ), |
|
| 3681 | + 'default' => (int) apply_filters( |
|
| 3682 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3683 | + 10 |
|
| 3684 | + ), |
|
| 3685 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3686 | + ); |
|
| 3687 | + // ONLY add the screen option if the user has access to it. |
|
| 3688 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3689 | + add_screen_option($option, $args); |
|
| 3690 | + } |
|
| 3691 | + } |
|
| 3692 | + |
|
| 3693 | + |
|
| 3694 | + /** |
|
| 3695 | + * set_per_page_screen_option |
|
| 3696 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3697 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3698 | + * admin_menu. |
|
| 3699 | + * |
|
| 3700 | + * @return void |
|
| 3701 | + */ |
|
| 3702 | + private function _set_per_page_screen_options() |
|
| 3703 | + { |
|
| 3704 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3705 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3706 | + if (! $user = wp_get_current_user()) { |
|
| 3707 | + return; |
|
| 3708 | + } |
|
| 3709 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3710 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3711 | + if ($option != sanitize_key($option)) { |
|
| 3712 | + return; |
|
| 3713 | + } |
|
| 3714 | + $map_option = $option; |
|
| 3715 | + $option = str_replace('-', '_', $option); |
|
| 3716 | + switch ($map_option) { |
|
| 3717 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3718 | + $value = (int) $value; |
|
| 3719 | + $max_value = apply_filters( |
|
| 3720 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3721 | + 999, |
|
| 3722 | + $this->_current_page, |
|
| 3723 | + $this->_current_view |
|
| 3724 | + ); |
|
| 3725 | + if ($value < 1) { |
|
| 3726 | + return; |
|
| 3727 | + } |
|
| 3728 | + $value = min($value, $max_value); |
|
| 3729 | + break; |
|
| 3730 | + default: |
|
| 3731 | + $value = apply_filters( |
|
| 3732 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3733 | + false, |
|
| 3734 | + $option, |
|
| 3735 | + $value |
|
| 3736 | + ); |
|
| 3737 | + if (false === $value) { |
|
| 3738 | + return; |
|
| 3739 | + } |
|
| 3740 | + break; |
|
| 3741 | + } |
|
| 3742 | + update_user_meta($user->ID, $option, $value); |
|
| 3743 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3744 | + exit; |
|
| 3745 | + } |
|
| 3746 | + } |
|
| 3747 | + |
|
| 3748 | + |
|
| 3749 | + /** |
|
| 3750 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3751 | + * |
|
| 3752 | + * @param array $data array that will be assigned to template args. |
|
| 3753 | + */ |
|
| 3754 | + public function set_template_args($data) |
|
| 3755 | + { |
|
| 3756 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3757 | + } |
|
| 3758 | + |
|
| 3759 | + |
|
| 3760 | + /** |
|
| 3761 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3762 | + * |
|
| 3763 | + * @param string $route the route that should receive the transient |
|
| 3764 | + * @param array $data the data that gets sent |
|
| 3765 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3766 | + * normal route transient. |
|
| 3767 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3768 | + * when we are adding a transient before page_routes have been defined. |
|
| 3769 | + * @return void |
|
| 3770 | + * @throws EE_Error |
|
| 3771 | + */ |
|
| 3772 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3773 | + { |
|
| 3774 | + $user_id = get_current_user_id(); |
|
| 3775 | + if (! $skip_route_verify) { |
|
| 3776 | + $this->_verify_route($route); |
|
| 3777 | + } |
|
| 3778 | + // now let's set the string for what kind of transient we're setting |
|
| 3779 | + $transient = $notices |
|
| 3780 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3781 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3782 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3783 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3784 | + $existing = is_multisite() && is_network_admin() |
|
| 3785 | + ? get_site_transient($transient) |
|
| 3786 | + : get_transient($transient); |
|
| 3787 | + if ($existing) { |
|
| 3788 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3789 | + } |
|
| 3790 | + if (is_multisite() && is_network_admin()) { |
|
| 3791 | + set_site_transient($transient, $data, 8); |
|
| 3792 | + } else { |
|
| 3793 | + set_transient($transient, $data, 8); |
|
| 3794 | + } |
|
| 3795 | + } |
|
| 3796 | + |
|
| 3797 | + |
|
| 3798 | + /** |
|
| 3799 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3800 | + * |
|
| 3801 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3802 | + * @param string $route |
|
| 3803 | + * @return mixed data |
|
| 3804 | + */ |
|
| 3805 | + protected function _get_transient($notices = false, $route = '') |
|
| 3806 | + { |
|
| 3807 | + $user_id = get_current_user_id(); |
|
| 3808 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3809 | + $transient = $notices |
|
| 3810 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3811 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3812 | + $data = is_multisite() && is_network_admin() |
|
| 3813 | + ? get_site_transient($transient) |
|
| 3814 | + : get_transient($transient); |
|
| 3815 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3816 | + if (is_multisite() && is_network_admin()) { |
|
| 3817 | + delete_site_transient($transient); |
|
| 3818 | + } else { |
|
| 3819 | + delete_transient($transient); |
|
| 3820 | + } |
|
| 3821 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3822 | + } |
|
| 3823 | + |
|
| 3824 | + |
|
| 3825 | + /** |
|
| 3826 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3827 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3828 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3829 | + * |
|
| 3830 | + * @return void |
|
| 3831 | + */ |
|
| 3832 | + protected function _transient_garbage_collection() |
|
| 3833 | + { |
|
| 3834 | + global $wpdb; |
|
| 3835 | + // retrieve all existing transients |
|
| 3836 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3837 | + if ($results = $wpdb->get_results($query)) { |
|
| 3838 | + foreach ($results as $result) { |
|
| 3839 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3840 | + get_transient($transient); |
|
| 3841 | + if (is_multisite() && is_network_admin()) { |
|
| 3842 | + get_site_transient($transient); |
|
| 3843 | + } |
|
| 3844 | + } |
|
| 3845 | + } |
|
| 3846 | + } |
|
| 3847 | + |
|
| 3848 | + |
|
| 3849 | + /** |
|
| 3850 | + * get_view |
|
| 3851 | + * |
|
| 3852 | + * @return string content of _view property |
|
| 3853 | + */ |
|
| 3854 | + public function get_view() |
|
| 3855 | + { |
|
| 3856 | + return $this->_view; |
|
| 3857 | + } |
|
| 3858 | + |
|
| 3859 | + |
|
| 3860 | + /** |
|
| 3861 | + * getter for the protected $_views property |
|
| 3862 | + * |
|
| 3863 | + * @return array |
|
| 3864 | + */ |
|
| 3865 | + public function get_views() |
|
| 3866 | + { |
|
| 3867 | + return $this->_views; |
|
| 3868 | + } |
|
| 3869 | + |
|
| 3870 | + |
|
| 3871 | + /** |
|
| 3872 | + * get_current_page |
|
| 3873 | + * |
|
| 3874 | + * @return string _current_page property value |
|
| 3875 | + */ |
|
| 3876 | + public function get_current_page() |
|
| 3877 | + { |
|
| 3878 | + return $this->_current_page; |
|
| 3879 | + } |
|
| 3880 | + |
|
| 3881 | + |
|
| 3882 | + /** |
|
| 3883 | + * get_current_view |
|
| 3884 | + * |
|
| 3885 | + * @return string _current_view property value |
|
| 3886 | + */ |
|
| 3887 | + public function get_current_view() |
|
| 3888 | + { |
|
| 3889 | + return $this->_current_view; |
|
| 3890 | + } |
|
| 3891 | + |
|
| 3892 | + |
|
| 3893 | + /** |
|
| 3894 | + * get_current_screen |
|
| 3895 | + * |
|
| 3896 | + * @return object The current WP_Screen object |
|
| 3897 | + */ |
|
| 3898 | + public function get_current_screen() |
|
| 3899 | + { |
|
| 3900 | + return $this->_current_screen; |
|
| 3901 | + } |
|
| 3902 | + |
|
| 3903 | + |
|
| 3904 | + /** |
|
| 3905 | + * get_current_page_view_url |
|
| 3906 | + * |
|
| 3907 | + * @return string This returns the url for the current_page_view. |
|
| 3908 | + */ |
|
| 3909 | + public function get_current_page_view_url() |
|
| 3910 | + { |
|
| 3911 | + return $this->_current_page_view_url; |
|
| 3912 | + } |
|
| 3913 | + |
|
| 3914 | + |
|
| 3915 | + /** |
|
| 3916 | + * just returns the _req_data property |
|
| 3917 | + * |
|
| 3918 | + * @return array |
|
| 3919 | + */ |
|
| 3920 | + public function get_request_data() |
|
| 3921 | + { |
|
| 3922 | + return $this->_req_data; |
|
| 3923 | + } |
|
| 3924 | + |
|
| 3925 | + |
|
| 3926 | + /** |
|
| 3927 | + * returns the _req_data protected property |
|
| 3928 | + * |
|
| 3929 | + * @return string |
|
| 3930 | + */ |
|
| 3931 | + public function get_req_action() |
|
| 3932 | + { |
|
| 3933 | + return $this->_req_action; |
|
| 3934 | + } |
|
| 3935 | + |
|
| 3936 | + |
|
| 3937 | + /** |
|
| 3938 | + * @return bool value of $_is_caf property |
|
| 3939 | + */ |
|
| 3940 | + public function is_caf() |
|
| 3941 | + { |
|
| 3942 | + return $this->_is_caf; |
|
| 3943 | + } |
|
| 3944 | + |
|
| 3945 | + |
|
| 3946 | + /** |
|
| 3947 | + * @return mixed |
|
| 3948 | + */ |
|
| 3949 | + public function default_espresso_metaboxes() |
|
| 3950 | + { |
|
| 3951 | + return $this->_default_espresso_metaboxes; |
|
| 3952 | + } |
|
| 3953 | + |
|
| 3954 | + |
|
| 3955 | + /** |
|
| 3956 | + * @return mixed |
|
| 3957 | + */ |
|
| 3958 | + public function admin_base_url() |
|
| 3959 | + { |
|
| 3960 | + return $this->_admin_base_url; |
|
| 3961 | + } |
|
| 3962 | + |
|
| 3963 | + |
|
| 3964 | + /** |
|
| 3965 | + * @return mixed |
|
| 3966 | + */ |
|
| 3967 | + public function wp_page_slug() |
|
| 3968 | + { |
|
| 3969 | + return $this->_wp_page_slug; |
|
| 3970 | + } |
|
| 3971 | + |
|
| 3972 | + |
|
| 3973 | + /** |
|
| 3974 | + * updates espresso configuration settings |
|
| 3975 | + * |
|
| 3976 | + * @param string $tab |
|
| 3977 | + * @param EE_Config_Base|EE_Config $config |
|
| 3978 | + * @param string $file file where error occurred |
|
| 3979 | + * @param string $func function where error occurred |
|
| 3980 | + * @param string $line line no where error occurred |
|
| 3981 | + * @return boolean |
|
| 3982 | + */ |
|
| 3983 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3984 | + { |
|
| 3985 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 3986 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3987 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3988 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3989 | + update_option('ee_ueip_has_notified', true); |
|
| 3990 | + } |
|
| 3991 | + // and save it (note we're also doing the network save here) |
|
| 3992 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3993 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3994 | + if ($config_saved && $net_saved) { |
|
| 3995 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3996 | + return true; |
|
| 3997 | + } |
|
| 3998 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3999 | + return false; |
|
| 4000 | + } |
|
| 4001 | + |
|
| 4002 | + |
|
| 4003 | + /** |
|
| 4004 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4005 | + * |
|
| 4006 | + * @return array |
|
| 4007 | + */ |
|
| 4008 | + public function get_yes_no_values() |
|
| 4009 | + { |
|
| 4010 | + return $this->_yes_no_values; |
|
| 4011 | + } |
|
| 4012 | + |
|
| 4013 | + |
|
| 4014 | + protected function _get_dir() |
|
| 4015 | + { |
|
| 4016 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4017 | + return dirname($reflector->getFileName()); |
|
| 4018 | + } |
|
| 4019 | + |
|
| 4020 | + |
|
| 4021 | + /** |
|
| 4022 | + * A helper for getting a "next link". |
|
| 4023 | + * |
|
| 4024 | + * @param string $url The url to link to |
|
| 4025 | + * @param string $class The class to use. |
|
| 4026 | + * @return string |
|
| 4027 | + */ |
|
| 4028 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4029 | + { |
|
| 4030 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4031 | + } |
|
| 4032 | + |
|
| 4033 | + |
|
| 4034 | + /** |
|
| 4035 | + * A helper for getting a "previous link". |
|
| 4036 | + * |
|
| 4037 | + * @param string $url The url to link to |
|
| 4038 | + * @param string $class The class to use. |
|
| 4039 | + * @return string |
|
| 4040 | + */ |
|
| 4041 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4042 | + { |
|
| 4043 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4044 | + } |
|
| 4045 | + |
|
| 4046 | + |
|
| 4047 | + |
|
| 4048 | + |
|
| 4049 | + |
|
| 4050 | + |
|
| 4051 | + |
|
| 4052 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4053 | + |
|
| 4054 | + |
|
| 4055 | + /** |
|
| 4056 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4057 | + * 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 |
|
| 4058 | + * _req_data array. |
|
| 4059 | + * |
|
| 4060 | + * @return bool success/fail |
|
| 4061 | + * @throws EE_Error |
|
| 4062 | + * @throws InvalidArgumentException |
|
| 4063 | + * @throws ReflectionException |
|
| 4064 | + * @throws InvalidDataTypeException |
|
| 4065 | + * @throws InvalidInterfaceException |
|
| 4066 | + */ |
|
| 4067 | + protected function _process_resend_registration() |
|
| 4068 | + { |
|
| 4069 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4070 | + do_action( |
|
| 4071 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4072 | + $this->_template_args['success'], |
|
| 4073 | + $this->_req_data |
|
| 4074 | + ); |
|
| 4075 | + return $this->_template_args['success']; |
|
| 4076 | + } |
|
| 4077 | + |
|
| 4078 | + |
|
| 4079 | + /** |
|
| 4080 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4081 | + * |
|
| 4082 | + * @param \EE_Payment $payment |
|
| 4083 | + * @return bool success/fail |
|
| 4084 | + */ |
|
| 4085 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4086 | + { |
|
| 4087 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4088 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4089 | + $this->_template_args['success'] = apply_filters( |
|
| 4090 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4091 | + false, |
|
| 4092 | + $payment |
|
| 4093 | + ); |
|
| 4094 | + return $this->_template_args['success']; |
|
| 4095 | + } |
|
| 4096 | 4096 | } |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | ); |
| 495 | 495 | global $ee_menu_slugs; |
| 496 | 496 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 497 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 497 | + if ( ! defined('DOING_AJAX') && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 498 | 498 | return; |
| 499 | 499 | } |
| 500 | 500 | // 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 |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | ? $this->_req_data['route'] |
| 519 | 519 | : $this->_req_action; |
| 520 | 520 | $this->_current_view = $this->_req_action; |
| 521 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 521 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 522 | 522 | $this->_define_page_props(); |
| 523 | 523 | $this->_current_page_view_url = add_query_arg( |
| 524 | 524 | array('page' => $this->_current_page, 'action' => $this->_current_view), |
@@ -552,21 +552,21 @@ discard block |
||
| 552 | 552 | } |
| 553 | 553 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 554 | 554 | $this->_page_routes = apply_filters( |
| 555 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 555 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 556 | 556 | $this->_page_routes, |
| 557 | 557 | $this |
| 558 | 558 | ); |
| 559 | 559 | $this->_page_config = apply_filters( |
| 560 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 560 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 561 | 561 | $this->_page_config, |
| 562 | 562 | $this |
| 563 | 563 | ); |
| 564 | 564 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 565 | 565 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 566 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 566 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 567 | 567 | add_action( |
| 568 | 568 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 569 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 569 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), |
|
| 570 | 570 | 10, |
| 571 | 571 | 2 |
| 572 | 572 | ); |
@@ -579,8 +579,8 @@ discard block |
||
| 579 | 579 | if ($this->_is_UI_request) { |
| 580 | 580 | // admin_init stuff - global, all views for this page class, specific view |
| 581 | 581 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 582 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 583 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 582 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 583 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 584 | 584 | } |
| 585 | 585 | } else { |
| 586 | 586 | // hijack regular WP loading and route admin request immediately |
@@ -600,12 +600,12 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | private function _do_other_page_hooks() |
| 602 | 602 | { |
| 603 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 603 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 604 | 604 | foreach ($registered_pages as $page) { |
| 605 | 605 | // now let's setup the file name and class that should be present |
| 606 | 606 | $classname = str_replace('.class.php', '', $page); |
| 607 | 607 | // autoloaders should take care of loading file |
| 608 | - if (! class_exists($classname)) { |
|
| 608 | + if ( ! class_exists($classname)) { |
|
| 609 | 609 | $error_msg[] = sprintf( |
| 610 | 610 | esc_html__( |
| 611 | 611 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | ), |
| 623 | 623 | $page, |
| 624 | 624 | '<br />', |
| 625 | - '<strong>' . $classname . '</strong>' |
|
| 625 | + '<strong>'.$classname.'</strong>' |
|
| 626 | 626 | ); |
| 627 | 627 | throw new EE_Error(implode('||', $error_msg)); |
| 628 | 628 | } |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | // load admin_notices - global, page class, and view specific |
| 663 | 663 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 664 | 664 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 665 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 666 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 665 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 666 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 667 | 667 | } |
| 668 | 668 | // load network admin_notices - global, page class, and view specific |
| 669 | 669 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 670 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 671 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 670 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 671 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 672 | 672 | } |
| 673 | 673 | // this will save any per_page screen options if they are present |
| 674 | 674 | $this->_set_per_page_screen_options(); |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | protected function _verify_routes() |
| 791 | 791 | { |
| 792 | 792 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 793 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 793 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 794 | 794 | return false; |
| 795 | 795 | } |
| 796 | 796 | $this->_route = false; |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | $this->_admin_page_title |
| 803 | 803 | ); |
| 804 | 804 | // developer error msg |
| 805 | - $error_msg .= '||' . $error_msg |
|
| 805 | + $error_msg .= '||'.$error_msg |
|
| 806 | 806 | . esc_html__( |
| 807 | 807 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 808 | 808 | 'event_espresso' |
@@ -811,9 +811,9 @@ discard block |
||
| 811 | 811 | } |
| 812 | 812 | // and that the requested page route exists |
| 813 | 813 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 814 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 815 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 816 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 814 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 815 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 816 | + ? $this->_page_config[$this->_req_action] : array(); |
|
| 817 | 817 | } else { |
| 818 | 818 | // user error msg |
| 819 | 819 | $error_msg = sprintf( |
@@ -824,7 +824,7 @@ discard block |
||
| 824 | 824 | $this->_admin_page_title |
| 825 | 825 | ); |
| 826 | 826 | // developer error msg |
| 827 | - $error_msg .= '||' . $error_msg |
|
| 827 | + $error_msg .= '||'.$error_msg |
|
| 828 | 828 | . sprintf( |
| 829 | 829 | esc_html__( |
| 830 | 830 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | throw new EE_Error($error_msg); |
| 836 | 836 | } |
| 837 | 837 | // and that a default route exists |
| 838 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 838 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 839 | 839 | // user error msg |
| 840 | 840 | $error_msg = sprintf( |
| 841 | 841 | esc_html__( |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | $this->_admin_page_title |
| 846 | 846 | ); |
| 847 | 847 | // developer error msg |
| 848 | - $error_msg .= '||' . $error_msg |
|
| 848 | + $error_msg .= '||'.$error_msg |
|
| 849 | 849 | . esc_html__( |
| 850 | 850 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 851 | 851 | 'event_espresso' |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | $this->_admin_page_title |
| 885 | 885 | ); |
| 886 | 886 | // developer error msg |
| 887 | - $error_msg .= '||' . $error_msg |
|
| 887 | + $error_msg .= '||'.$error_msg |
|
| 888 | 888 | . sprintf( |
| 889 | 889 | esc_html__( |
| 890 | 890 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -909,7 +909,7 @@ discard block |
||
| 909 | 909 | protected function _verify_nonce($nonce, $nonce_ref) |
| 910 | 910 | { |
| 911 | 911 | // verify nonce against expected value |
| 912 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 912 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 913 | 913 | // these are not the droids you are looking for !!! |
| 914 | 914 | $msg = sprintf( |
| 915 | 915 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | __CLASS__ |
| 927 | 927 | ); |
| 928 | 928 | } |
| 929 | - if (! defined('DOING_AJAX')) { |
|
| 929 | + if ( ! defined('DOING_AJAX')) { |
|
| 930 | 930 | wp_die($msg); |
| 931 | 931 | } else { |
| 932 | 932 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -951,7 +951,7 @@ discard block |
||
| 951 | 951 | */ |
| 952 | 952 | protected function _route_admin_request() |
| 953 | 953 | { |
| 954 | - if (! $this->_is_UI_request) { |
|
| 954 | + if ( ! $this->_is_UI_request) { |
|
| 955 | 955 | $this->_verify_routes(); |
| 956 | 956 | } |
| 957 | 957 | $nonce_check = isset($this->_route_config['require_nonce']) |
@@ -959,8 +959,8 @@ discard block |
||
| 959 | 959 | : true; |
| 960 | 960 | if ($this->_req_action !== 'default' && $nonce_check) { |
| 961 | 961 | // set nonce from post data |
| 962 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 963 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 962 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 963 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 964 | 964 | : ''; |
| 965 | 965 | $this->_verify_nonce($nonce, $this->_req_nonce); |
| 966 | 966 | } |
@@ -975,7 +975,7 @@ discard block |
||
| 975 | 975 | $error_msg = ''; |
| 976 | 976 | // action right before calling route |
| 977 | 977 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 978 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 978 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 979 | 979 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 980 | 980 | } |
| 981 | 981 | // right before calling the route, let's remove _wp_http_referer from the |
@@ -984,7 +984,7 @@ discard block |
||
| 984 | 984 | '_wp_http_referer', |
| 985 | 985 | wp_unslash($_SERVER['REQUEST_URI']) |
| 986 | 986 | ); |
| 987 | - if (! empty($func)) { |
|
| 987 | + if ( ! empty($func)) { |
|
| 988 | 988 | if (is_array($func)) { |
| 989 | 989 | list($class, $method) = $func; |
| 990 | 990 | } elseif (strpos($func, '::') !== false) { |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | $class = $this; |
| 994 | 994 | $method = $func; |
| 995 | 995 | } |
| 996 | - if (! (is_object($class) && $class === $this)) { |
|
| 996 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 997 | 997 | // send along this admin page object for access by addons. |
| 998 | 998 | $args['admin_page_object'] = $this; |
| 999 | 999 | } |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | $method |
| 1034 | 1034 | ); |
| 1035 | 1035 | } |
| 1036 | - if (! empty($error_msg)) { |
|
| 1036 | + if ( ! empty($error_msg)) { |
|
| 1037 | 1037 | throw new EE_Error($error_msg); |
| 1038 | 1038 | } |
| 1039 | 1039 | } |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | if (strpos($key, 'nonce') !== false) { |
| 1118 | 1118 | continue; |
| 1119 | 1119 | } |
| 1120 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1120 | + $args['wp_referer['.$key.']'] = $value; |
|
| 1121 | 1121 | } |
| 1122 | 1122 | } |
| 1123 | 1123 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1157,10 +1157,10 @@ discard block |
||
| 1157 | 1157 | protected function _add_help_tabs() |
| 1158 | 1158 | { |
| 1159 | 1159 | $tour_buttons = ''; |
| 1160 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1161 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1160 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1161 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1162 | 1162 | // is there a help tour for the current route? if there is let's setup the tour buttons |
| 1163 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1163 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1164 | 1164 | $tb = array(); |
| 1165 | 1165 | $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
| 1166 | 1166 | foreach ($this->_help_tour['tours'] as $tour) { |
@@ -1180,7 +1180,7 @@ discard block |
||
| 1180 | 1180 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1181 | 1181 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1182 | 1182 | // check that the callback given is valid |
| 1183 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1183 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1184 | 1184 | throw new EE_Error( |
| 1185 | 1185 | sprintf( |
| 1186 | 1186 | esc_html__( |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | ); |
| 1194 | 1194 | } |
| 1195 | 1195 | $content = apply_filters( |
| 1196 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1196 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1197 | 1197 | $this->{$config['help_sidebar']}() |
| 1198 | 1198 | ); |
| 1199 | 1199 | $content .= $tour_buttons; // add help tour buttons. |
@@ -1201,27 +1201,27 @@ discard block |
||
| 1201 | 1201 | $this->_current_screen->set_help_sidebar($content); |
| 1202 | 1202 | } |
| 1203 | 1203 | // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
| 1204 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1204 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1205 | 1205 | $this->_current_screen->set_help_sidebar($tour_buttons); |
| 1206 | 1206 | } |
| 1207 | 1207 | // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
| 1208 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1208 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1209 | 1209 | $_ht['id'] = $this->page_slug; |
| 1210 | 1210 | $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
| 1211 | 1211 | $_ht['content'] = '<p>' |
| 1212 | 1212 | . esc_html__( |
| 1213 | 1213 | 'The buttons to the right allow you to start/restart any help tours available for this page', |
| 1214 | 1214 | 'event_espresso' |
| 1215 | - ) . '</p>'; |
|
| 1215 | + ).'</p>'; |
|
| 1216 | 1216 | $this->_current_screen->add_help_tab($_ht); |
| 1217 | 1217 | } |
| 1218 | - if (! isset($config['help_tabs'])) { |
|
| 1218 | + if ( ! isset($config['help_tabs'])) { |
|
| 1219 | 1219 | return; |
| 1220 | 1220 | } //no help tabs for this route |
| 1221 | 1221 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1222 | 1222 | // we're here so there ARE help tabs! |
| 1223 | 1223 | // make sure we've got what we need |
| 1224 | - if (! isset($cfg['title'])) { |
|
| 1224 | + if ( ! isset($cfg['title'])) { |
|
| 1225 | 1225 | throw new EE_Error( |
| 1226 | 1226 | esc_html__( |
| 1227 | 1227 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1229,7 +1229,7 @@ discard block |
||
| 1229 | 1229 | ) |
| 1230 | 1230 | ); |
| 1231 | 1231 | } |
| 1232 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1232 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1233 | 1233 | throw new EE_Error( |
| 1234 | 1234 | esc_html__( |
| 1235 | 1235 | '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', |
@@ -1238,11 +1238,11 @@ discard block |
||
| 1238 | 1238 | ); |
| 1239 | 1239 | } |
| 1240 | 1240 | // first priority goes to content. |
| 1241 | - if (! empty($cfg['content'])) { |
|
| 1241 | + if ( ! empty($cfg['content'])) { |
|
| 1242 | 1242 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1243 | 1243 | // second priority goes to filename |
| 1244 | - } elseif (! empty($cfg['filename'])) { |
|
| 1245 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1244 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1245 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1246 | 1246 | // 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) |
| 1247 | 1247 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1248 | 1248 | . basename($this->_get_dir()) |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | . $cfg['filename'] |
| 1251 | 1251 | . '.help_tab.php' : $file_path; |
| 1252 | 1252 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1253 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1253 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1254 | 1254 | EE_Error::add_error( |
| 1255 | 1255 | sprintf( |
| 1256 | 1256 | esc_html__( |
@@ -1296,7 +1296,7 @@ discard block |
||
| 1296 | 1296 | return; |
| 1297 | 1297 | } |
| 1298 | 1298 | // setup config array for help tab method |
| 1299 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1299 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1300 | 1300 | $_ht = array( |
| 1301 | 1301 | 'id' => $id, |
| 1302 | 1302 | 'title' => $cfg['title'], |
@@ -1340,7 +1340,7 @@ discard block |
||
| 1340 | 1340 | } |
| 1341 | 1341 | if (isset($config['help_tour'])) { |
| 1342 | 1342 | foreach ($config['help_tour'] as $tour) { |
| 1343 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1343 | + $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php'; |
|
| 1344 | 1344 | // let's see if we can get that file... |
| 1345 | 1345 | // if not its possible this is a decaf route not set in caffeinated |
| 1346 | 1346 | // so lets try and get the caffeinated equivalent |
@@ -1350,7 +1350,7 @@ discard block |
||
| 1350 | 1350 | . $tour |
| 1351 | 1351 | . '.class.php' : $file_path; |
| 1352 | 1352 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1353 | - if (! is_readable($file_path)) { |
|
| 1353 | + if ( ! is_readable($file_path)) { |
|
| 1354 | 1354 | EE_Error::add_error( |
| 1355 | 1355 | sprintf( |
| 1356 | 1356 | esc_html__( |
@@ -1367,12 +1367,12 @@ discard block |
||
| 1367 | 1367 | return; |
| 1368 | 1368 | } |
| 1369 | 1369 | require_once $file_path; |
| 1370 | - if (! class_exists($tour)) { |
|
| 1370 | + if ( ! class_exists($tour)) { |
|
| 1371 | 1371 | $error_msg[] = sprintf( |
| 1372 | 1372 | esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
| 1373 | 1373 | $tour |
| 1374 | 1374 | ); |
| 1375 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1375 | + $error_msg[] = $error_msg[0]."\r\n" |
|
| 1376 | 1376 | . sprintf( |
| 1377 | 1377 | esc_html__( |
| 1378 | 1378 | '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.', |
@@ -1388,15 +1388,15 @@ discard block |
||
| 1388 | 1388 | } |
| 1389 | 1389 | $tour_obj = new $tour($this->_is_caf); |
| 1390 | 1390 | $tours[] = $tour_obj; |
| 1391 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1391 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1392 | 1392 | } |
| 1393 | 1393 | // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
| 1394 | 1394 | $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
| 1395 | 1395 | $tours[] = $end_stop_tour; |
| 1396 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1396 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1397 | 1397 | } |
| 1398 | 1398 | } |
| 1399 | - if (! empty($tours)) { |
|
| 1399 | + if ( ! empty($tours)) { |
|
| 1400 | 1400 | $this->_help_tour['tours'] = $tours; |
| 1401 | 1401 | } |
| 1402 | 1402 | // that's it! Now that the $_help_tours property is set (or not) |
@@ -1415,8 +1415,8 @@ discard block |
||
| 1415 | 1415 | $qtips = (array) $this->_route_config['qtips']; |
| 1416 | 1416 | // load qtip loader |
| 1417 | 1417 | $path = array( |
| 1418 | - $this->_get_dir() . '/qtips/', |
|
| 1419 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1418 | + $this->_get_dir().'/qtips/', |
|
| 1419 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1420 | 1420 | ); |
| 1421 | 1421 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1422 | 1422 | } |
@@ -1438,7 +1438,7 @@ discard block |
||
| 1438 | 1438 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1439 | 1439 | $i = 0; |
| 1440 | 1440 | foreach ($this->_page_config as $slug => $config) { |
| 1441 | - if (! is_array($config) |
|
| 1441 | + if ( ! is_array($config) |
|
| 1442 | 1442 | || ( |
| 1443 | 1443 | is_array($config) |
| 1444 | 1444 | && ( |
@@ -1455,12 +1455,12 @@ discard block |
||
| 1455 | 1455 | // nav tab is only to appear when route requested. |
| 1456 | 1456 | continue; |
| 1457 | 1457 | } |
| 1458 | - if (! $this->check_user_access($slug, true)) { |
|
| 1458 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1459 | 1459 | // no nav tab because current user does not have access. |
| 1460 | 1460 | continue; |
| 1461 | 1461 | } |
| 1462 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1463 | - $this->_nav_tabs[ $slug ] = array( |
|
| 1462 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1463 | + $this->_nav_tabs[$slug] = array( |
|
| 1464 | 1464 | 'url' => isset($config['nav']['url']) |
| 1465 | 1465 | ? $config['nav']['url'] |
| 1466 | 1466 | : self::add_query_args_and_nonce( |
@@ -1472,14 +1472,14 @@ discard block |
||
| 1472 | 1472 | : ucwords( |
| 1473 | 1473 | str_replace('_', ' ', $slug) |
| 1474 | 1474 | ), |
| 1475 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1475 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1476 | 1476 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1477 | 1477 | ); |
| 1478 | 1478 | $i++; |
| 1479 | 1479 | } |
| 1480 | 1480 | // if $this->_nav_tabs is empty then lets set the default |
| 1481 | 1481 | if (empty($this->_nav_tabs)) { |
| 1482 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1482 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1483 | 1483 | 'url' => $this->_admin_base_url, |
| 1484 | 1484 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1485 | 1485 | 'css_class' => 'nav-tab-active', |
@@ -1504,10 +1504,10 @@ discard block |
||
| 1504 | 1504 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1505 | 1505 | if (is_array($text)) { |
| 1506 | 1506 | foreach ($text as $sublabel => $subtext) { |
| 1507 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1507 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1508 | 1508 | } |
| 1509 | 1509 | } else { |
| 1510 | - $this->_labels[ $label ] = $text; |
|
| 1510 | + $this->_labels[$label] = $text; |
|
| 1511 | 1511 | } |
| 1512 | 1512 | } |
| 1513 | 1513 | } |
@@ -1529,12 +1529,12 @@ discard block |
||
| 1529 | 1529 | { |
| 1530 | 1530 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1531 | 1531 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1532 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1532 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1533 | 1533 | && is_array( |
| 1534 | - $this->_page_routes[ $route_to_check ] |
|
| 1534 | + $this->_page_routes[$route_to_check] |
|
| 1535 | 1535 | ) |
| 1536 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1537 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1536 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1537 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1538 | 1538 | if (empty($capability) && empty($route_to_check)) { |
| 1539 | 1539 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
| 1540 | 1540 | : $this->_route['capability']; |
@@ -1542,7 +1542,7 @@ discard block |
||
| 1542 | 1542 | $capability = empty($capability) ? 'manage_options' : $capability; |
| 1543 | 1543 | } |
| 1544 | 1544 | $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
| 1545 | - if (! defined('DOING_AJAX') |
|
| 1545 | + if ( ! defined('DOING_AJAX') |
|
| 1546 | 1546 | && ( |
| 1547 | 1547 | ! function_exists('is_admin') |
| 1548 | 1548 | || ! EE_Registry::instance()->CAP->current_user_can( |
@@ -1645,17 +1645,17 @@ discard block |
||
| 1645 | 1645 | public function admin_footer_global() |
| 1646 | 1646 | { |
| 1647 | 1647 | // dialog container for dialog helper |
| 1648 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1648 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1649 | 1649 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1650 | 1650 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1651 | 1651 | $d_cont .= '</div>'; |
| 1652 | 1652 | echo $d_cont; |
| 1653 | 1653 | // help tour stuff? |
| 1654 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1655 | - echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1654 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1655 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1656 | 1656 | } |
| 1657 | 1657 | // current set timezone for timezone js |
| 1658 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1658 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1689,7 +1689,7 @@ discard block |
||
| 1689 | 1689 | // loop through the array and setup content |
| 1690 | 1690 | foreach ($help_array as $trigger => $help) { |
| 1691 | 1691 | // make sure the array is setup properly |
| 1692 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1692 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1693 | 1693 | throw new EE_Error( |
| 1694 | 1694 | esc_html__( |
| 1695 | 1695 | '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', |
@@ -1704,7 +1704,7 @@ discard block |
||
| 1704 | 1704 | 'help_popup_content' => $help['content'], |
| 1705 | 1705 | ); |
| 1706 | 1706 | $content .= EEH_Template::display_template( |
| 1707 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1707 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1708 | 1708 | $template_args, |
| 1709 | 1709 | true |
| 1710 | 1710 | ); |
@@ -1726,15 +1726,15 @@ discard block |
||
| 1726 | 1726 | private function _get_help_content() |
| 1727 | 1727 | { |
| 1728 | 1728 | // what is the method we're looking for? |
| 1729 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1729 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1730 | 1730 | // if method doesn't exist let's get out. |
| 1731 | - if (! method_exists($this, $method_name)) { |
|
| 1731 | + if ( ! method_exists($this, $method_name)) { |
|
| 1732 | 1732 | return array(); |
| 1733 | 1733 | } |
| 1734 | 1734 | // k we're good to go let's retrieve the help array |
| 1735 | 1735 | $help_array = call_user_func(array($this, $method_name)); |
| 1736 | 1736 | // make sure we've got an array! |
| 1737 | - if (! is_array($help_array)) { |
|
| 1737 | + if ( ! is_array($help_array)) { |
|
| 1738 | 1738 | throw new EE_Error( |
| 1739 | 1739 | esc_html__( |
| 1740 | 1740 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1766,8 +1766,8 @@ discard block |
||
| 1766 | 1766 | // 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 |
| 1767 | 1767 | $help_array = $this->_get_help_content(); |
| 1768 | 1768 | $help_content = ''; |
| 1769 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1770 | - $help_array[ $trigger_id ] = array( |
|
| 1769 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1770 | + $help_array[$trigger_id] = array( |
|
| 1771 | 1771 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1772 | 1772 | 'content' => esc_html__( |
| 1773 | 1773 | '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.)', |
@@ -1843,15 +1843,15 @@ discard block |
||
| 1843 | 1843 | // register all styles |
| 1844 | 1844 | wp_register_style( |
| 1845 | 1845 | 'espresso-ui-theme', |
| 1846 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1846 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1847 | 1847 | array(), |
| 1848 | 1848 | EVENT_ESPRESSO_VERSION |
| 1849 | 1849 | ); |
| 1850 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1850 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1851 | 1851 | // helpers styles |
| 1852 | 1852 | wp_register_style( |
| 1853 | 1853 | 'ee-text-links', |
| 1854 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1854 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
| 1855 | 1855 | array(), |
| 1856 | 1856 | EVENT_ESPRESSO_VERSION |
| 1857 | 1857 | ); |
@@ -1859,21 +1859,21 @@ discard block |
||
| 1859 | 1859 | // register all scripts |
| 1860 | 1860 | wp_register_script( |
| 1861 | 1861 | 'ee-dialog', |
| 1862 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1862 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
| 1863 | 1863 | array('jquery', 'jquery-ui-draggable'), |
| 1864 | 1864 | EVENT_ESPRESSO_VERSION, |
| 1865 | 1865 | true |
| 1866 | 1866 | ); |
| 1867 | 1867 | wp_register_script( |
| 1868 | 1868 | 'ee_admin_js', |
| 1869 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1869 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
| 1870 | 1870 | array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
| 1871 | 1871 | EVENT_ESPRESSO_VERSION, |
| 1872 | 1872 | true |
| 1873 | 1873 | ); |
| 1874 | 1874 | wp_register_script( |
| 1875 | 1875 | 'jquery-ui-timepicker-addon', |
| 1876 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1876 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
| 1877 | 1877 | array('jquery-ui-datepicker', 'jquery-ui-slider'), |
| 1878 | 1878 | EVENT_ESPRESSO_VERSION, |
| 1879 | 1879 | true |
@@ -1882,7 +1882,7 @@ discard block |
||
| 1882 | 1882 | // script for sorting tables |
| 1883 | 1883 | wp_register_script( |
| 1884 | 1884 | 'espresso_ajax_table_sorting', |
| 1885 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1885 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
| 1886 | 1886 | array('ee_admin_js', 'jquery-ui-sortable'), |
| 1887 | 1887 | EVENT_ESPRESSO_VERSION, |
| 1888 | 1888 | true |
@@ -1890,7 +1890,7 @@ discard block |
||
| 1890 | 1890 | // script for parsing uri's |
| 1891 | 1891 | wp_register_script( |
| 1892 | 1892 | 'ee-parse-uri', |
| 1893 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1893 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
| 1894 | 1894 | array(), |
| 1895 | 1895 | EVENT_ESPRESSO_VERSION, |
| 1896 | 1896 | true |
@@ -1898,7 +1898,7 @@ discard block |
||
| 1898 | 1898 | // and parsing associative serialized form elements |
| 1899 | 1899 | wp_register_script( |
| 1900 | 1900 | 'ee-serialize-full-array', |
| 1901 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1901 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
| 1902 | 1902 | array('jquery'), |
| 1903 | 1903 | EVENT_ESPRESSO_VERSION, |
| 1904 | 1904 | true |
@@ -1906,28 +1906,28 @@ discard block |
||
| 1906 | 1906 | // helpers scripts |
| 1907 | 1907 | wp_register_script( |
| 1908 | 1908 | 'ee-text-links', |
| 1909 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1909 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
| 1910 | 1910 | array('jquery'), |
| 1911 | 1911 | EVENT_ESPRESSO_VERSION, |
| 1912 | 1912 | true |
| 1913 | 1913 | ); |
| 1914 | 1914 | wp_register_script( |
| 1915 | 1915 | 'ee-moment-core', |
| 1916 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1916 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
| 1917 | 1917 | array(), |
| 1918 | 1918 | EVENT_ESPRESSO_VERSION, |
| 1919 | 1919 | true |
| 1920 | 1920 | ); |
| 1921 | 1921 | wp_register_script( |
| 1922 | 1922 | 'ee-moment', |
| 1923 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1923 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
| 1924 | 1924 | array('ee-moment-core'), |
| 1925 | 1925 | EVENT_ESPRESSO_VERSION, |
| 1926 | 1926 | true |
| 1927 | 1927 | ); |
| 1928 | 1928 | wp_register_script( |
| 1929 | 1929 | 'ee-datepicker', |
| 1930 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1930 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
| 1931 | 1931 | array('jquery-ui-timepicker-addon', 'ee-moment'), |
| 1932 | 1932 | EVENT_ESPRESSO_VERSION, |
| 1933 | 1933 | true |
@@ -1961,11 +1961,11 @@ discard block |
||
| 1961 | 1961 | /** |
| 1962 | 1962 | * help tour stuff |
| 1963 | 1963 | */ |
| 1964 | - if (! empty($this->_help_tour)) { |
|
| 1964 | + if ( ! empty($this->_help_tour)) { |
|
| 1965 | 1965 | // register the js for kicking things off |
| 1966 | 1966 | wp_enqueue_script( |
| 1967 | 1967 | 'ee-help-tour', |
| 1968 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1968 | + EE_ADMIN_URL.'assets/ee-help-tour.js', |
|
| 1969 | 1969 | array('jquery-joyride'), |
| 1970 | 1970 | EVENT_ESPRESSO_VERSION, |
| 1971 | 1971 | true |
@@ -2062,12 +2062,12 @@ discard block |
||
| 2062 | 2062 | protected function _set_list_table() |
| 2063 | 2063 | { |
| 2064 | 2064 | // first is this a list_table view? |
| 2065 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2065 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 2066 | 2066 | return; |
| 2067 | 2067 | } //not a list_table view so get out. |
| 2068 | 2068 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 2069 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2070 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2069 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 2070 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2071 | 2071 | // user error msg |
| 2072 | 2072 | $error_msg = esc_html__( |
| 2073 | 2073 | 'An error occurred. The requested list table views could not be found.', |
@@ -2087,10 +2087,10 @@ discard block |
||
| 2087 | 2087 | } |
| 2088 | 2088 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2089 | 2089 | $this->_views = apply_filters( |
| 2090 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2090 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2091 | 2091 | $this->_views |
| 2092 | 2092 | ); |
| 2093 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2093 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2094 | 2094 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2095 | 2095 | $this->_set_list_table_view(); |
| 2096 | 2096 | $this->_set_list_table_object(); |
@@ -2106,7 +2106,7 @@ discard block |
||
| 2106 | 2106 | { |
| 2107 | 2107 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2108 | 2108 | // looking at active items or dumpster diving ? |
| 2109 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2109 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2110 | 2110 | $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
| 2111 | 2111 | } else { |
| 2112 | 2112 | $this->_view = sanitize_key($this->_req_data['status']); |
@@ -2127,7 +2127,7 @@ discard block |
||
| 2127 | 2127 | protected function _set_list_table_object() |
| 2128 | 2128 | { |
| 2129 | 2129 | if (isset($this->_route_config['list_table'])) { |
| 2130 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2130 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2131 | 2131 | throw new EE_Error( |
| 2132 | 2132 | sprintf( |
| 2133 | 2133 | esc_html__( |
@@ -2165,15 +2165,15 @@ discard block |
||
| 2165 | 2165 | foreach ($this->_views as $key => $view) { |
| 2166 | 2166 | $query_args = array(); |
| 2167 | 2167 | // check for current view |
| 2168 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2168 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2169 | 2169 | $query_args['action'] = $this->_req_action; |
| 2170 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2170 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2171 | 2171 | $query_args['status'] = $view['slug']; |
| 2172 | 2172 | // merge any other arguments sent in. |
| 2173 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2174 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2173 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2174 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 2175 | 2175 | } |
| 2176 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2176 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2177 | 2177 | } |
| 2178 | 2178 | return $this->_views; |
| 2179 | 2179 | } |
@@ -2192,7 +2192,7 @@ discard block |
||
| 2192 | 2192 | { |
| 2193 | 2193 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2194 | 2194 | $values = array(10, 25, 50, 100); |
| 2195 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2195 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2196 | 2196 | if ($max_entries) { |
| 2197 | 2197 | $values[] = $max_entries; |
| 2198 | 2198 | sort($values); |
@@ -2204,14 +2204,14 @@ discard block |
||
| 2204 | 2204 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2205 | 2205 | foreach ($values as $value) { |
| 2206 | 2206 | if ($value < $max_entries) { |
| 2207 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2207 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2208 | 2208 | $entries_per_page_dropdown .= ' |
| 2209 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2209 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2210 | 2210 | } |
| 2211 | 2211 | } |
| 2212 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2212 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2213 | 2213 | $entries_per_page_dropdown .= ' |
| 2214 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2214 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2215 | 2215 | $entries_per_page_dropdown .= ' |
| 2216 | 2216 | </select> |
| 2217 | 2217 | entries |
@@ -2235,7 +2235,7 @@ discard block |
||
| 2235 | 2235 | empty($this->_search_btn_label) ? $this->page_label |
| 2236 | 2236 | : $this->_search_btn_label |
| 2237 | 2237 | ); |
| 2238 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2238 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2239 | 2239 | } |
| 2240 | 2240 | |
| 2241 | 2241 | |
@@ -2321,7 +2321,7 @@ discard block |
||
| 2321 | 2321 | $total_columns = ! empty($screen_columns) |
| 2322 | 2322 | ? $screen_columns |
| 2323 | 2323 | : $this->_route_config['columns'][1]; |
| 2324 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2324 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2325 | 2325 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2326 | 2326 | $this->_template_args['screen'] = $this->_current_screen; |
| 2327 | 2327 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2366,7 +2366,7 @@ discard block |
||
| 2366 | 2366 | */ |
| 2367 | 2367 | protected function _espresso_ratings_request() |
| 2368 | 2368 | { |
| 2369 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2369 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2370 | 2370 | return; |
| 2371 | 2371 | } |
| 2372 | 2372 | $ratings_box_title = apply_filters( |
@@ -2394,7 +2394,7 @@ discard block |
||
| 2394 | 2394 | public function espresso_ratings_request() |
| 2395 | 2395 | { |
| 2396 | 2396 | EEH_Template::display_template( |
| 2397 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2397 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
| 2398 | 2398 | array() |
| 2399 | 2399 | ); |
| 2400 | 2400 | } |
@@ -2407,17 +2407,17 @@ discard block |
||
| 2407 | 2407 | . '</p><p class="hide-if-js">' |
| 2408 | 2408 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2409 | 2409 | . '</p>'; |
| 2410 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2411 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2412 | - $post = '</div>' . "\n"; |
|
| 2413 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2410 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2411 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 2412 | + $post = '</div>'."\n"; |
|
| 2413 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2414 | 2414 | $output = get_transient($cache_key); |
| 2415 | 2415 | if ($output !== false) { |
| 2416 | - echo $pre . $output . $post; |
|
| 2416 | + echo $pre.$output.$post; |
|
| 2417 | 2417 | return true; |
| 2418 | 2418 | } |
| 2419 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2420 | - echo $pre . $loading . $post; |
|
| 2419 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2420 | + echo $pre.$loading.$post; |
|
| 2421 | 2421 | return false; |
| 2422 | 2422 | } |
| 2423 | 2423 | ob_start(); |
@@ -2484,19 +2484,19 @@ discard block |
||
| 2484 | 2484 | public function espresso_sponsors_post_box() |
| 2485 | 2485 | { |
| 2486 | 2486 | EEH_Template::display_template( |
| 2487 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2487 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2488 | 2488 | ); |
| 2489 | 2489 | } |
| 2490 | 2490 | |
| 2491 | 2491 | |
| 2492 | 2492 | private function _publish_post_box() |
| 2493 | 2493 | { |
| 2494 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2494 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2495 | 2495 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2496 | 2496 | // then we'll use that for the metabox label. |
| 2497 | 2497 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2498 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2499 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2498 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2499 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2500 | 2500 | : $this->_labels['publishbox']; |
| 2501 | 2501 | } else { |
| 2502 | 2502 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2525,7 +2525,7 @@ discard block |
||
| 2525 | 2525 | ? $this->_template_args['publish_box_extra_content'] |
| 2526 | 2526 | : ''; |
| 2527 | 2527 | echo EEH_Template::display_template( |
| 2528 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2528 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2529 | 2529 | $this->_template_args, |
| 2530 | 2530 | true |
| 2531 | 2531 | ); |
@@ -2617,8 +2617,8 @@ discard block |
||
| 2617 | 2617 | ); |
| 2618 | 2618 | } |
| 2619 | 2619 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2620 | - if (! empty($name) && ! empty($id)) { |
|
| 2621 | - $hidden_field_arr[ $name ] = array( |
|
| 2620 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2621 | + $hidden_field_arr[$name] = array( |
|
| 2622 | 2622 | 'type' => 'hidden', |
| 2623 | 2623 | 'value' => $id, |
| 2624 | 2624 | ); |
@@ -2628,7 +2628,7 @@ discard block |
||
| 2628 | 2628 | } |
| 2629 | 2629 | // add hidden field |
| 2630 | 2630 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2631 | - ? $hf[ $name ]['field'] |
|
| 2631 | + ? $hf[$name]['field'] |
|
| 2632 | 2632 | : $hf; |
| 2633 | 2633 | } |
| 2634 | 2634 | |
@@ -2730,7 +2730,7 @@ discard block |
||
| 2730 | 2730 | } |
| 2731 | 2731 | // 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) |
| 2732 | 2732 | $call_back_func = $create_func |
| 2733 | - ? function ($post, $metabox) { |
|
| 2733 | + ? function($post, $metabox) { |
|
| 2734 | 2734 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2735 | 2735 | echo EEH_Template::display_template( |
| 2736 | 2736 | $metabox['args']['template_path'], |
@@ -2740,7 +2740,7 @@ discard block |
||
| 2740 | 2740 | } |
| 2741 | 2741 | : $callback; |
| 2742 | 2742 | add_meta_box( |
| 2743 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2743 | + str_replace('_', '-', $action).'-mbox', |
|
| 2744 | 2744 | $title, |
| 2745 | 2745 | $call_back_func, |
| 2746 | 2746 | $this->_wp_page_slug, |
@@ -2832,9 +2832,9 @@ discard block |
||
| 2832 | 2832 | : 'espresso-default-admin'; |
| 2833 | 2833 | $template_path = $sidebar |
| 2834 | 2834 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2835 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2835 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2836 | 2836 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2837 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2837 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2838 | 2838 | } |
| 2839 | 2839 | $template_path = ! empty($this->_column_template_path) |
| 2840 | 2840 | ? $this->_column_template_path : $template_path; |
@@ -2899,7 +2899,7 @@ discard block |
||
| 2899 | 2899 | ) |
| 2900 | 2900 | : $this->_template_args['preview_action_button']; |
| 2901 | 2901 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2902 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2902 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2903 | 2903 | $this->_template_args, |
| 2904 | 2904 | true |
| 2905 | 2905 | ); |
@@ -2948,7 +2948,7 @@ discard block |
||
| 2948 | 2948 | // setup search attributes |
| 2949 | 2949 | $this->_set_search_attributes(); |
| 2950 | 2950 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2951 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2951 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2952 | 2952 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 2953 | 2953 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 2954 | 2954 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2956,10 +2956,10 @@ discard block |
||
| 2956 | 2956 | $this->_template_args['current_route'] = $this->_req_action; |
| 2957 | 2957 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2958 | 2958 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2959 | - if (! empty($ajax_sorting_callback)) { |
|
| 2959 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2960 | 2960 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2961 | - $ajax_sorting_callback . '_nonce', |
|
| 2962 | - $ajax_sorting_callback . '_nonce', |
|
| 2961 | + $ajax_sorting_callback.'_nonce', |
|
| 2962 | + $ajax_sorting_callback.'_nonce', |
|
| 2963 | 2963 | false, |
| 2964 | 2964 | false |
| 2965 | 2965 | ); |
@@ -2976,7 +2976,7 @@ discard block |
||
| 2976 | 2976 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
| 2977 | 2977 | ? $this->_template_args['list_table_hidden_fields'] |
| 2978 | 2978 | : ''; |
| 2979 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2979 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2980 | 2980 | $hidden_form_fields .= '<input type="hidden" name="' |
| 2981 | 2981 | . $nonce_ref |
| 2982 | 2982 | . '" value="' |
@@ -2985,10 +2985,10 @@ discard block |
||
| 2985 | 2985 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 2986 | 2986 | // display message about search results? |
| 2987 | 2987 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 2988 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2988 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2989 | 2989 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 2990 | 2990 | trim($this->_req_data['s'], '%') |
| 2991 | - ) . '</p>' |
|
| 2991 | + ).'</p>' |
|
| 2992 | 2992 | : ''; |
| 2993 | 2993 | // filter before_list_table template arg |
| 2994 | 2994 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3069,7 +3069,7 @@ discard block |
||
| 3069 | 3069 | $this |
| 3070 | 3070 | ); |
| 3071 | 3071 | return EEH_Template::display_template( |
| 3072 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3072 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3073 | 3073 | $this->_template_args, |
| 3074 | 3074 | true |
| 3075 | 3075 | ); |
@@ -3292,17 +3292,17 @@ discard block |
||
| 3292 | 3292 | // add in a hidden index for the current page (so save and close redirects properly) |
| 3293 | 3293 | $this->_template_args['save_buttons'] = $referrer_url; |
| 3294 | 3294 | foreach ($button_text as $key => $button) { |
| 3295 | - $ref = $default_names[ $key ]; |
|
| 3295 | + $ref = $default_names[$key]; |
|
| 3296 | 3296 | $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
| 3297 | 3297 | . $ref |
| 3298 | 3298 | . '" value="' |
| 3299 | 3299 | . $button |
| 3300 | 3300 | . '" name="' |
| 3301 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3301 | + . ( ! empty($actions) ? $actions[$key] : $ref) |
|
| 3302 | 3302 | . '" id="' |
| 3303 | - . $this->_current_view . '_' . $ref |
|
| 3303 | + . $this->_current_view.'_'.$ref |
|
| 3304 | 3304 | . '" />'; |
| 3305 | - if (! $both) { |
|
| 3305 | + if ( ! $both) { |
|
| 3306 | 3306 | break; |
| 3307 | 3307 | } |
| 3308 | 3308 | } |
@@ -3337,13 +3337,13 @@ discard block |
||
| 3337 | 3337 | 'An error occurred. No action was set for this page\'s form.', |
| 3338 | 3338 | 'event_espresso' |
| 3339 | 3339 | ); |
| 3340 | - $dev_msg = $user_msg . "\n" |
|
| 3340 | + $dev_msg = $user_msg."\n" |
|
| 3341 | 3341 | . sprintf( |
| 3342 | 3342 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3343 | 3343 | __FUNCTION__, |
| 3344 | 3344 | __CLASS__ |
| 3345 | 3345 | ); |
| 3346 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3346 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3347 | 3347 | } |
| 3348 | 3348 | // open form |
| 3349 | 3349 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3352,8 +3352,8 @@ discard block |
||
| 3352 | 3352 | . $route |
| 3353 | 3353 | . '_event_form" >'; |
| 3354 | 3354 | // add nonce |
| 3355 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3356 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3355 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3356 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3357 | 3357 | // add REQUIRED form action |
| 3358 | 3358 | $hidden_fields = array( |
| 3359 | 3359 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -3366,7 +3366,7 @@ discard block |
||
| 3366 | 3366 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3367 | 3367 | // add fields to form |
| 3368 | 3368 | foreach ((array) $form_fields as $field_name => $form_field) { |
| 3369 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3369 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3370 | 3370 | } |
| 3371 | 3371 | // close form |
| 3372 | 3372 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3432,10 +3432,10 @@ discard block |
||
| 3432 | 3432 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3433 | 3433 | $notices = EE_Error::get_notices(false); |
| 3434 | 3434 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3435 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3435 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3436 | 3436 | EE_Error::overwrite_success(); |
| 3437 | 3437 | } |
| 3438 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3438 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3439 | 3439 | // how many records affected ? more than one record ? or just one ? |
| 3440 | 3440 | if ($success > 1) { |
| 3441 | 3441 | // set plural msg |
@@ -3464,7 +3464,7 @@ discard block |
||
| 3464 | 3464 | } |
| 3465 | 3465 | } |
| 3466 | 3466 | // check that $query_args isn't something crazy |
| 3467 | - if (! is_array($query_args)) { |
|
| 3467 | + if ( ! is_array($query_args)) { |
|
| 3468 | 3468 | $query_args = array(); |
| 3469 | 3469 | } |
| 3470 | 3470 | /** |
@@ -3489,7 +3489,7 @@ discard block |
||
| 3489 | 3489 | $redirect_url = admin_url('admin.php'); |
| 3490 | 3490 | } |
| 3491 | 3491 | // merge any default query_args set in _default_route_query_args property |
| 3492 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3492 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3493 | 3493 | $args_to_merge = array(); |
| 3494 | 3494 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3495 | 3495 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3501,15 +3501,15 @@ discard block |
||
| 3501 | 3501 | } |
| 3502 | 3502 | // finally we will override any arguments in the referer with |
| 3503 | 3503 | // what might be set on the _default_route_query_args array. |
| 3504 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3505 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3504 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3505 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3506 | 3506 | } else { |
| 3507 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3507 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3508 | 3508 | } |
| 3509 | 3509 | } |
| 3510 | 3510 | continue; |
| 3511 | 3511 | } |
| 3512 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3512 | + $args_to_merge[$query_param] = $query_value; |
|
| 3513 | 3513 | } |
| 3514 | 3514 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3515 | 3515 | // redirect. |
@@ -3521,13 +3521,13 @@ discard block |
||
| 3521 | 3521 | if (isset($query_args['action'])) { |
| 3522 | 3522 | // manually generate wp_nonce and merge that with the query vars |
| 3523 | 3523 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3524 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3524 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3525 | 3525 | } |
| 3526 | 3526 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3527 | 3527 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3528 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3528 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3529 | 3529 | $redirect_url = apply_filters( |
| 3530 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3530 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3531 | 3531 | self::add_query_args_and_nonce($query_args, $redirect_url), |
| 3532 | 3532 | $query_args |
| 3533 | 3533 | ); |
@@ -3580,7 +3580,7 @@ discard block |
||
| 3580 | 3580 | } |
| 3581 | 3581 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3582 | 3582 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3583 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3583 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3584 | 3584 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3585 | 3585 | $this->_add_transient( |
| 3586 | 3586 | $route, |
@@ -3620,7 +3620,7 @@ discard block |
||
| 3620 | 3620 | $exclude_nonce = false |
| 3621 | 3621 | ) { |
| 3622 | 3622 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3623 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3623 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3624 | 3624 | throw new EE_Error( |
| 3625 | 3625 | sprintf( |
| 3626 | 3626 | esc_html__( |
@@ -3631,7 +3631,7 @@ discard block |
||
| 3631 | 3631 | ) |
| 3632 | 3632 | ); |
| 3633 | 3633 | } |
| 3634 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3634 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3635 | 3635 | throw new EE_Error( |
| 3636 | 3636 | sprintf( |
| 3637 | 3637 | __( |
@@ -3644,7 +3644,7 @@ discard block |
||
| 3644 | 3644 | } |
| 3645 | 3645 | // finally check user access for this button. |
| 3646 | 3646 | $has_access = $this->check_user_access($action, true); |
| 3647 | - if (! $has_access) { |
|
| 3647 | + if ( ! $has_access) { |
|
| 3648 | 3648 | return ''; |
| 3649 | 3649 | } |
| 3650 | 3650 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3652,11 +3652,11 @@ discard block |
||
| 3652 | 3652 | 'action' => $action, |
| 3653 | 3653 | ); |
| 3654 | 3654 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3655 | - if (! empty($extra_request)) { |
|
| 3655 | + if ( ! empty($extra_request)) { |
|
| 3656 | 3656 | $query_args = array_merge($extra_request, $query_args); |
| 3657 | 3657 | } |
| 3658 | 3658 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3659 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3659 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3660 | 3660 | } |
| 3661 | 3661 | |
| 3662 | 3662 | |
@@ -3682,7 +3682,7 @@ discard block |
||
| 3682 | 3682 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3683 | 3683 | 10 |
| 3684 | 3684 | ), |
| 3685 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3685 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3686 | 3686 | ); |
| 3687 | 3687 | // ONLY add the screen option if the user has access to it. |
| 3688 | 3688 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3703,7 +3703,7 @@ discard block |
||
| 3703 | 3703 | { |
| 3704 | 3704 | if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
| 3705 | 3705 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3706 | - if (! $user = wp_get_current_user()) { |
|
| 3706 | + if ( ! $user = wp_get_current_user()) { |
|
| 3707 | 3707 | return; |
| 3708 | 3708 | } |
| 3709 | 3709 | $option = $_POST['wp_screen_options']['option']; |
@@ -3714,7 +3714,7 @@ discard block |
||
| 3714 | 3714 | $map_option = $option; |
| 3715 | 3715 | $option = str_replace('-', '_', $option); |
| 3716 | 3716 | switch ($map_option) { |
| 3717 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3717 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3718 | 3718 | $value = (int) $value; |
| 3719 | 3719 | $max_value = apply_filters( |
| 3720 | 3720 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
@@ -3772,13 +3772,13 @@ discard block |
||
| 3772 | 3772 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3773 | 3773 | { |
| 3774 | 3774 | $user_id = get_current_user_id(); |
| 3775 | - if (! $skip_route_verify) { |
|
| 3775 | + if ( ! $skip_route_verify) { |
|
| 3776 | 3776 | $this->_verify_route($route); |
| 3777 | 3777 | } |
| 3778 | 3778 | // now let's set the string for what kind of transient we're setting |
| 3779 | 3779 | $transient = $notices |
| 3780 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3781 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3780 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3781 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3782 | 3782 | $data = $notices ? array('notices' => $data) : $data; |
| 3783 | 3783 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3784 | 3784 | $existing = is_multisite() && is_network_admin() |
@@ -3807,8 +3807,8 @@ discard block |
||
| 3807 | 3807 | $user_id = get_current_user_id(); |
| 3808 | 3808 | $route = ! $route ? $this->_req_action : $route; |
| 3809 | 3809 | $transient = $notices |
| 3810 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3811 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3810 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3811 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3812 | 3812 | $data = is_multisite() && is_network_admin() |
| 3813 | 3813 | ? get_site_transient($transient) |
| 3814 | 3814 | : get_transient($transient); |
@@ -4027,7 +4027,7 @@ discard block |
||
| 4027 | 4027 | */ |
| 4028 | 4028 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 4029 | 4029 | { |
| 4030 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4030 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4031 | 4031 | } |
| 4032 | 4032 | |
| 4033 | 4033 | |
@@ -4040,7 +4040,7 @@ discard block |
||
| 4040 | 4040 | */ |
| 4041 | 4041 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 4042 | 4042 | { |
| 4043 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4043 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4044 | 4044 | } |
| 4045 | 4045 | |
| 4046 | 4046 | |