@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -22,668 +22,668 @@ discard block |
||
| 22 | 22 | final class EE_Front_Controller |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * $_template_path |
|
| 27 | - * @var string $_template_path |
|
| 28 | - * @access public |
|
| 29 | - */ |
|
| 30 | - private $_template_path; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * $_template |
|
| 34 | - * @var string $_template |
|
| 35 | - * @access public |
|
| 36 | - */ |
|
| 37 | - private $_template; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @type EE_Registry $Registry |
|
| 41 | - * @access protected |
|
| 42 | - */ |
|
| 43 | - protected $Registry; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @type EE_Request_Handler $Request_Handler |
|
| 47 | - * @access protected |
|
| 48 | - */ |
|
| 49 | - protected $Request_Handler; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
| 53 | - * @access protected |
|
| 54 | - */ |
|
| 55 | - protected $Module_Request_Router; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * class constructor |
|
| 60 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 61 | - * |
|
| 62 | - * @access public |
|
| 63 | - * @param \EE_Registry $Registry |
|
| 64 | - * @param \EE_Request_Handler $Request_Handler |
|
| 65 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 66 | - */ |
|
| 67 | - public function __construct( |
|
| 68 | - EE_Registry $Registry, |
|
| 69 | - EE_Request_Handler $Request_Handler, |
|
| 70 | - EE_Module_Request_Router $Module_Request_Router |
|
| 71 | - ) { |
|
| 72 | - $this->Registry = $Registry; |
|
| 73 | - $this->Request_Handler = $Request_Handler; |
|
| 74 | - $this->Module_Request_Router = $Module_Request_Router; |
|
| 75 | - // make sure template tags are loaded immediately so that themes don't break |
|
| 76 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10); |
|
| 77 | - // determine how to integrate WP_Query with the EE models |
|
| 78 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 79 | - // load other resources and begin to actually run shortcodes and modules |
|
| 80 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 81 | - // analyse the incoming WP request |
|
| 82 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 83 | - // process any content shortcodes |
|
| 84 | - add_action('parse_request', array($this, '_initialize_shortcodes'), 5); |
|
| 85 | - // process request with module factory |
|
| 86 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 87 | - // before headers sent |
|
| 88 | - add_action('wp', array($this, 'wp'), 5); |
|
| 89 | - // load css and js |
|
| 90 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1); |
|
| 91 | - // header |
|
| 92 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 93 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
| 94 | - // display errors |
|
| 95 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 96 | - // the content |
|
| 97 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 98 | - //exclude our private cpt comments |
|
| 99 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 100 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 101 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 102 | - // action hook EE |
|
| 103 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 104 | - // for checking that browser cookies are enabled |
|
| 105 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 106 | - setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/'); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return EE_Request_Handler |
|
| 113 | - */ |
|
| 114 | - public function Request_Handler() |
|
| 115 | - { |
|
| 116 | - return $this->Request_Handler; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return EE_Module_Request_Router |
|
| 122 | - */ |
|
| 123 | - public function Module_Request_Router() |
|
| 124 | - { |
|
| 125 | - return $this->Module_Request_Router; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 137 | - * load it's functions.php file ( if not already loaded ) |
|
| 138 | - * |
|
| 139 | - * @return void |
|
| 140 | - */ |
|
| 141 | - public function load_espresso_template_tags() |
|
| 142 | - { |
|
| 143 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 144 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * filter_wp_comments |
|
| 151 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 152 | - * widgets/queries done on frontend |
|
| 153 | - * |
|
| 154 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 155 | - * @return array array of comment clauses with modifications. |
|
| 156 | - */ |
|
| 157 | - public function filter_wp_comments($clauses) |
|
| 158 | - { |
|
| 159 | - global $wpdb; |
|
| 160 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 161 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 162 | - foreach ($cpts as $cpt => $details) { |
|
| 163 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return $clauses; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * employ_CPT_Strategy |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @return void |
|
| 175 | - */ |
|
| 176 | - public function employ_CPT_Strategy() |
|
| 177 | - { |
|
| 178 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 179 | - $this->Registry->load_core('CPT_Strategy'); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 186 | - * |
|
| 187 | - * @param string $url incoming url |
|
| 188 | - * @return string final assembled url |
|
| 189 | - */ |
|
| 190 | - public function maybe_force_admin_ajax_ssl($url) |
|
| 191 | - { |
|
| 192 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 193 | - $url = str_replace('http://', 'https://', $url); |
|
| 194 | - } |
|
| 195 | - return $url; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 208 | - * default priority init phases have run |
|
| 209 | - * |
|
| 210 | - * @access public |
|
| 211 | - * @return void |
|
| 212 | - */ |
|
| 213 | - public function wp_loaded() |
|
| 214 | - { |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 222 | - /** |
|
| 223 | - * _get_request |
|
| 224 | - * |
|
| 225 | - * @access public |
|
| 226 | - * @param WP $WP |
|
| 227 | - * @return void |
|
| 228 | - */ |
|
| 229 | - public function get_request(WP $WP) |
|
| 230 | - { |
|
| 231 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 232 | - $this->Request_Handler->parse_request($WP); |
|
| 233 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for |
|
| 239 | - * the currently requested page |
|
| 240 | - * |
|
| 241 | - * @access public |
|
| 242 | - * @param WP $WP |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - public function _initialize_shortcodes(WP $WP) |
|
| 246 | - { |
|
| 247 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this); |
|
| 248 | - $this->Request_Handler->set_request_vars($WP); |
|
| 249 | - // grab post_name from request |
|
| 250 | - $current_post = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
| 251 | - $this->Request_Handler->get('post_name')); |
|
| 252 | - $show_on_front = get_option('show_on_front'); |
|
| 253 | - // if it's not set, then check if frontpage is blog |
|
| 254 | - if (empty($current_post)) { |
|
| 255 | - // yup.. this is the posts page, prepare to load all shortcode modules |
|
| 256 | - $current_post = 'posts'; |
|
| 257 | - // unless.. |
|
| 258 | - if ($show_on_front === 'page') { |
|
| 259 | - // some other page is set as the homepage |
|
| 260 | - $page_on_front = get_option('page_on_front'); |
|
| 261 | - if ($page_on_front) { |
|
| 262 | - // k now we need to find the post_name for this page |
|
| 263 | - global $wpdb; |
|
| 264 | - $page_on_front = $wpdb->get_var( |
|
| 265 | - $wpdb->prepare( |
|
| 266 | - "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d", |
|
| 267 | - $page_on_front |
|
| 268 | - ) |
|
| 269 | - ); |
|
| 270 | - // set the current post slug to what it actually is |
|
| 271 | - $current_post = $page_on_front ? $page_on_front : $current_post; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - // where are posts being displayed ? |
|
| 276 | - $page_for_posts = EE_Config::get_page_for_posts(); |
|
| 277 | - // in case $current_post is hierarchical like: /parent-page/current-page |
|
| 278 | - $current_post = basename($current_post); |
|
| 279 | - // are we on a category page? |
|
| 280 | - $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name', |
|
| 281 | - $WP->query_vars); |
|
| 282 | - // make sure shortcodes are set |
|
| 283 | - if (isset($this->Registry->CFG->core->post_shortcodes)) { |
|
| 284 | - if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) { |
|
| 285 | - $this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array(); |
|
| 286 | - } |
|
| 287 | - // cycle thru all posts with shortcodes set |
|
| 288 | - foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
| 289 | - // filter shortcodes so |
|
| 290 | - $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes', |
|
| 291 | - $post_shortcodes); |
|
| 292 | - // now cycle thru shortcodes |
|
| 293 | - foreach ($post_shortcodes as $shortcode_class => $post_id) { |
|
| 294 | - // are we on this page, or on the blog page, or an EE CPT category page ? |
|
| 295 | - if ($current_post === $post_name || $term_exists) { |
|
| 296 | - // maybe init the shortcode |
|
| 297 | - $this->initialize_shortcode_if_active_on_page( |
|
| 298 | - $shortcode_class, |
|
| 299 | - $current_post, |
|
| 300 | - $page_for_posts, |
|
| 301 | - $post_id, |
|
| 302 | - $term_exists, |
|
| 303 | - $WP |
|
| 304 | - ); |
|
| 305 | - // if this is NOT the "Posts page" and we have a valid entry |
|
| 306 | - // for the "Posts page" in our tracked post_shortcodes array |
|
| 307 | - // but the shortcode is not being tracked for this page |
|
| 308 | - } else if ( |
|
| 309 | - $post_name !== $page_for_posts |
|
| 310 | - && isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts]) |
|
| 311 | - && ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class]) |
|
| 312 | - ) { |
|
| 313 | - // then remove the "fallback" shortcode processor |
|
| 314 | - remove_shortcode($shortcode_class); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @param string $shortcode_class |
|
| 325 | - * @param string $current_post |
|
| 326 | - * @param string $page_for_posts |
|
| 327 | - * @param int $post_id |
|
| 328 | - * @param bool $term_exists |
|
| 329 | - * @param WP $WP |
|
| 330 | - */ |
|
| 331 | - protected function initialize_shortcode_if_active_on_page( |
|
| 332 | - $shortcode_class, |
|
| 333 | - $current_post, |
|
| 334 | - $page_for_posts, |
|
| 335 | - $post_id, |
|
| 336 | - $term_exists, |
|
| 337 | - $WP |
|
| 338 | - ) { |
|
| 339 | - // verify shortcode is in list of registered shortcodes |
|
| 340 | - if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) { |
|
| 341 | - if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) { |
|
| 342 | - EE_Error::add_error( |
|
| 343 | - sprintf( |
|
| 344 | - __( |
|
| 345 | - 'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.', |
|
| 346 | - 'event_espresso' |
|
| 347 | - ), |
|
| 348 | - $shortcode_class |
|
| 349 | - ), |
|
| 350 | - __FILE__, |
|
| 351 | - __FUNCTION__, |
|
| 352 | - __LINE__ |
|
| 353 | - ); |
|
| 354 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 355 | - } |
|
| 356 | - add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor')); |
|
| 357 | - return; |
|
| 358 | - } |
|
| 359 | - // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ? |
|
| 360 | - if ( |
|
| 361 | - $term_exists |
|
| 362 | - || $current_post === $page_for_posts |
|
| 363 | - || isset($this->Registry->CFG->core->post_shortcodes[$current_post]) |
|
| 364 | - ) { |
|
| 365 | - // let's pause to reflect on this... |
|
| 366 | - $sc_reflector = new ReflectionClass('EES_' . $shortcode_class); |
|
| 367 | - // ensure that class is actually a shortcode |
|
| 368 | - if ( |
|
| 369 | - defined('WP_DEBUG') |
|
| 370 | - && WP_DEBUG === true |
|
| 371 | - && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
| 372 | - ) { |
|
| 373 | - EE_Error::add_error( |
|
| 374 | - sprintf( |
|
| 375 | - __( |
|
| 376 | - 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
| 377 | - 'event_espresso' |
|
| 378 | - ), |
|
| 379 | - $shortcode_class |
|
| 380 | - ), |
|
| 381 | - __FILE__, |
|
| 382 | - __FUNCTION__, |
|
| 383 | - __LINE__ |
|
| 384 | - ); |
|
| 385 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 386 | - return; |
|
| 387 | - } |
|
| 388 | - // and pass the request object to the run method |
|
| 389 | - $this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
| 390 | - // fire the shortcode class's run method, so that it can activate resources |
|
| 391 | - $this->Registry->shortcodes->{$shortcode_class}->run($WP); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 398 | - * |
|
| 399 | - * @access public |
|
| 400 | - * @param WP_Query $WP_Query |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 403 | - public function pre_get_posts($WP_Query) |
|
| 404 | - { |
|
| 405 | - // only load Module_Request_Router if this is the main query |
|
| 406 | - if ( |
|
| 407 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 408 | - && $WP_Query->is_main_query() |
|
| 409 | - ) { |
|
| 410 | - // cycle thru module routes |
|
| 411 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 412 | - // determine module and method for route |
|
| 413 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 414 | - if ($module instanceof EED_Module) { |
|
| 415 | - // get registered view for route |
|
| 416 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 417 | - // grab module name |
|
| 418 | - $module_name = $module->module_name(); |
|
| 419 | - // map the module to the module objects |
|
| 420 | - $this->Registry->modules->{$module_name} = $module; |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /*********************************************** WP HOOK ***********************************************/ |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * wp - basically last chance to do stuff before headers sent |
|
| 435 | - * |
|
| 436 | - * @access public |
|
| 437 | - * @return void |
|
| 438 | - */ |
|
| 439 | - public function wp() |
|
| 440 | - { |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /*********************************************** WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK ***********************************************/ |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * wp_enqueue_scripts |
|
| 450 | - * |
|
| 451 | - * @access public |
|
| 452 | - * @return void |
|
| 453 | - */ |
|
| 454 | - public function wp_enqueue_scripts() |
|
| 455 | - { |
|
| 456 | - |
|
| 457 | - // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_css', '__return_false' ); |
|
| 458 | - if (apply_filters('FHEE_load_css', true)) { |
|
| 459 | - |
|
| 460 | - $this->Registry->CFG->template_settings->enable_default_style = true; |
|
| 461 | - //Load the ThemeRoller styles if enabled |
|
| 462 | - if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) { |
|
| 463 | - |
|
| 464 | - //Load custom style sheet if available |
|
| 465 | - if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) { |
|
| 466 | - wp_register_style('espresso_custom_css', |
|
| 467 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet, |
|
| 468 | - EVENT_ESPRESSO_VERSION); |
|
| 469 | - wp_enqueue_style('espresso_custom_css'); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) { |
|
| 473 | - wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css', |
|
| 474 | - array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 475 | - } else { |
|
| 476 | - wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 477 | - array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 478 | - } |
|
| 479 | - wp_enqueue_style('espresso_default'); |
|
| 480 | - |
|
| 481 | - if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) { |
|
| 482 | - wp_register_style('espresso_style', |
|
| 483 | - get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 484 | - array('dashicons', 'espresso_default')); |
|
| 485 | - } else { |
|
| 486 | - wp_register_style('espresso_style', |
|
| 487 | - EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 488 | - array('dashicons', 'espresso_default')); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_js', '__return_false' ); |
|
| 496 | - if (apply_filters('FHEE_load_js', true)) { |
|
| 497 | - |
|
| 498 | - wp_enqueue_script('jquery'); |
|
| 499 | - //let's make sure that all required scripts have been setup |
|
| 500 | - if (function_exists('wp_script_is') && ! wp_script_is('jquery')) { |
|
| 501 | - $msg = sprintf( |
|
| 502 | - __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.', |
|
| 503 | - 'event_espresso'), |
|
| 504 | - '<em><br />', |
|
| 505 | - '</em>' |
|
| 506 | - ); |
|
| 507 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 508 | - } |
|
| 509 | - // load core js |
|
| 510 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), |
|
| 511 | - EVENT_ESPRESSO_VERSION, true); |
|
| 512 | - wp_enqueue_script('espresso_core'); |
|
| 513 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 514 | - |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 518 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 519 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - //accounting.js library |
|
| 524 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 525 | - if (apply_filters('FHEE_load_accounting_js', false)) { |
|
| 526 | - $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js'; |
|
| 527 | - wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 528 | - array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 529 | - wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true); |
|
| 530 | - wp_enqueue_script('ee-accounting'); |
|
| 531 | - |
|
| 532 | - $currency_config = array( |
|
| 533 | - 'currency' => array( |
|
| 534 | - 'symbol' => $this->Registry->CFG->currency->sign, |
|
| 535 | - 'format' => array( |
|
| 536 | - 'pos' => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s', |
|
| 537 | - 'neg' => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 538 | - 'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s', |
|
| 539 | - ), |
|
| 540 | - 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 541 | - 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 542 | - 'precision' => $this->Registry->CFG->currency->dec_plc, |
|
| 543 | - ), |
|
| 544 | - 'number' => array( |
|
| 545 | - 'precision' => 0, |
|
| 546 | - 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 547 | - 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 548 | - ), |
|
| 549 | - ); |
|
| 550 | - wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - if ( ! function_exists('wp_head')) { |
|
| 554 | - $msg = sprintf( |
|
| 555 | - __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 556 | - 'event_espresso'), |
|
| 557 | - '<em><br />', |
|
| 558 | - '</em>' |
|
| 559 | - ); |
|
| 560 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 561 | - } |
|
| 562 | - if ( ! function_exists('wp_footer')) { |
|
| 563 | - $msg = sprintf( |
|
| 564 | - __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 565 | - 'event_espresso'), |
|
| 566 | - '<em><br />', |
|
| 567 | - '</em>' |
|
| 568 | - ); |
|
| 569 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * header_meta_tag |
|
| 577 | - * |
|
| 578 | - * @access public |
|
| 579 | - * @return void |
|
| 580 | - */ |
|
| 581 | - public function header_meta_tag() |
|
| 582 | - { |
|
| 583 | - print( |
|
| 584 | - apply_filters( |
|
| 585 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 586 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 587 | - ); |
|
| 588 | - |
|
| 589 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 590 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 591 | - if ( |
|
| 592 | - is_tax('espresso_event_type') |
|
| 593 | - && get_option( 'blog_public' ) !== '0' |
|
| 594 | - ) { |
|
| 595 | - print( |
|
| 596 | - apply_filters( |
|
| 597 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 598 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 599 | - ) |
|
| 600 | - ); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /*********************************************** THE_CONTENT FILTER HOOK ***********************************************/ |
|
| 608 | - /** |
|
| 609 | - * the_content |
|
| 610 | - * |
|
| 611 | - * @access public |
|
| 612 | - * @param $the_content |
|
| 613 | - * @return string |
|
| 614 | - */ |
|
| 615 | - // public function the_content( $the_content ) { |
|
| 616 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 617 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 618 | - // } |
|
| 619 | - // return $the_content; |
|
| 620 | - // } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * display_errors |
|
| 628 | - * |
|
| 629 | - * @access public |
|
| 630 | - * @return string |
|
| 631 | - */ |
|
| 632 | - public function display_errors() |
|
| 633 | - { |
|
| 634 | - static $shown_already = false; |
|
| 635 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 636 | - if ( |
|
| 637 | - ! $shown_already |
|
| 638 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 639 | - && is_main_query() |
|
| 640 | - && ! is_feed() |
|
| 641 | - && in_the_loop() |
|
| 642 | - && $this->Request_Handler->is_espresso_page() |
|
| 643 | - ) { |
|
| 644 | - echo EE_Error::get_notices(); |
|
| 645 | - $shown_already = true; |
|
| 646 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 647 | - } |
|
| 648 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /*********************************************** UTILITIES ***********************************************/ |
|
| 656 | - /** |
|
| 657 | - * template_include |
|
| 658 | - * |
|
| 659 | - * @access public |
|
| 660 | - * @param string $template_include_path |
|
| 661 | - * @return string |
|
| 662 | - */ |
|
| 663 | - public function template_include($template_include_path = null) |
|
| 664 | - { |
|
| 665 | - if ($this->Request_Handler->is_espresso_page()) { |
|
| 666 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 667 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 668 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 669 | - $this->_template = basename($this->_template_path); |
|
| 670 | - return $this->_template_path; |
|
| 671 | - } |
|
| 672 | - return $template_include_path; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * get_selected_template |
|
| 678 | - * |
|
| 679 | - * @access public |
|
| 680 | - * @param bool $with_path |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - public function get_selected_template($with_path = false) |
|
| 684 | - { |
|
| 685 | - return $with_path ? $this->_template_path : $this->_template; |
|
| 686 | - } |
|
| 25 | + /** |
|
| 26 | + * $_template_path |
|
| 27 | + * @var string $_template_path |
|
| 28 | + * @access public |
|
| 29 | + */ |
|
| 30 | + private $_template_path; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * $_template |
|
| 34 | + * @var string $_template |
|
| 35 | + * @access public |
|
| 36 | + */ |
|
| 37 | + private $_template; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @type EE_Registry $Registry |
|
| 41 | + * @access protected |
|
| 42 | + */ |
|
| 43 | + protected $Registry; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @type EE_Request_Handler $Request_Handler |
|
| 47 | + * @access protected |
|
| 48 | + */ |
|
| 49 | + protected $Request_Handler; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
| 53 | + * @access protected |
|
| 54 | + */ |
|
| 55 | + protected $Module_Request_Router; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * class constructor |
|
| 60 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 61 | + * |
|
| 62 | + * @access public |
|
| 63 | + * @param \EE_Registry $Registry |
|
| 64 | + * @param \EE_Request_Handler $Request_Handler |
|
| 65 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 66 | + */ |
|
| 67 | + public function __construct( |
|
| 68 | + EE_Registry $Registry, |
|
| 69 | + EE_Request_Handler $Request_Handler, |
|
| 70 | + EE_Module_Request_Router $Module_Request_Router |
|
| 71 | + ) { |
|
| 72 | + $this->Registry = $Registry; |
|
| 73 | + $this->Request_Handler = $Request_Handler; |
|
| 74 | + $this->Module_Request_Router = $Module_Request_Router; |
|
| 75 | + // make sure template tags are loaded immediately so that themes don't break |
|
| 76 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10); |
|
| 77 | + // determine how to integrate WP_Query with the EE models |
|
| 78 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 79 | + // load other resources and begin to actually run shortcodes and modules |
|
| 80 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 81 | + // analyse the incoming WP request |
|
| 82 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 83 | + // process any content shortcodes |
|
| 84 | + add_action('parse_request', array($this, '_initialize_shortcodes'), 5); |
|
| 85 | + // process request with module factory |
|
| 86 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 87 | + // before headers sent |
|
| 88 | + add_action('wp', array($this, 'wp'), 5); |
|
| 89 | + // load css and js |
|
| 90 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1); |
|
| 91 | + // header |
|
| 92 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 93 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
| 94 | + // display errors |
|
| 95 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 96 | + // the content |
|
| 97 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 98 | + //exclude our private cpt comments |
|
| 99 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 100 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 101 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 102 | + // action hook EE |
|
| 103 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 104 | + // for checking that browser cookies are enabled |
|
| 105 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 106 | + setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/'); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return EE_Request_Handler |
|
| 113 | + */ |
|
| 114 | + public function Request_Handler() |
|
| 115 | + { |
|
| 116 | + return $this->Request_Handler; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return EE_Module_Request_Router |
|
| 122 | + */ |
|
| 123 | + public function Module_Request_Router() |
|
| 124 | + { |
|
| 125 | + return $this->Module_Request_Router; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 137 | + * load it's functions.php file ( if not already loaded ) |
|
| 138 | + * |
|
| 139 | + * @return void |
|
| 140 | + */ |
|
| 141 | + public function load_espresso_template_tags() |
|
| 142 | + { |
|
| 143 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 144 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * filter_wp_comments |
|
| 151 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 152 | + * widgets/queries done on frontend |
|
| 153 | + * |
|
| 154 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 155 | + * @return array array of comment clauses with modifications. |
|
| 156 | + */ |
|
| 157 | + public function filter_wp_comments($clauses) |
|
| 158 | + { |
|
| 159 | + global $wpdb; |
|
| 160 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 161 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 162 | + foreach ($cpts as $cpt => $details) { |
|
| 163 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return $clauses; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * employ_CPT_Strategy |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @return void |
|
| 175 | + */ |
|
| 176 | + public function employ_CPT_Strategy() |
|
| 177 | + { |
|
| 178 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 179 | + $this->Registry->load_core('CPT_Strategy'); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 186 | + * |
|
| 187 | + * @param string $url incoming url |
|
| 188 | + * @return string final assembled url |
|
| 189 | + */ |
|
| 190 | + public function maybe_force_admin_ajax_ssl($url) |
|
| 191 | + { |
|
| 192 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 193 | + $url = str_replace('http://', 'https://', $url); |
|
| 194 | + } |
|
| 195 | + return $url; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 208 | + * default priority init phases have run |
|
| 209 | + * |
|
| 210 | + * @access public |
|
| 211 | + * @return void |
|
| 212 | + */ |
|
| 213 | + public function wp_loaded() |
|
| 214 | + { |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 222 | + /** |
|
| 223 | + * _get_request |
|
| 224 | + * |
|
| 225 | + * @access public |
|
| 226 | + * @param WP $WP |
|
| 227 | + * @return void |
|
| 228 | + */ |
|
| 229 | + public function get_request(WP $WP) |
|
| 230 | + { |
|
| 231 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 232 | + $this->Request_Handler->parse_request($WP); |
|
| 233 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for |
|
| 239 | + * the currently requested page |
|
| 240 | + * |
|
| 241 | + * @access public |
|
| 242 | + * @param WP $WP |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + public function _initialize_shortcodes(WP $WP) |
|
| 246 | + { |
|
| 247 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this); |
|
| 248 | + $this->Request_Handler->set_request_vars($WP); |
|
| 249 | + // grab post_name from request |
|
| 250 | + $current_post = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
| 251 | + $this->Request_Handler->get('post_name')); |
|
| 252 | + $show_on_front = get_option('show_on_front'); |
|
| 253 | + // if it's not set, then check if frontpage is blog |
|
| 254 | + if (empty($current_post)) { |
|
| 255 | + // yup.. this is the posts page, prepare to load all shortcode modules |
|
| 256 | + $current_post = 'posts'; |
|
| 257 | + // unless.. |
|
| 258 | + if ($show_on_front === 'page') { |
|
| 259 | + // some other page is set as the homepage |
|
| 260 | + $page_on_front = get_option('page_on_front'); |
|
| 261 | + if ($page_on_front) { |
|
| 262 | + // k now we need to find the post_name for this page |
|
| 263 | + global $wpdb; |
|
| 264 | + $page_on_front = $wpdb->get_var( |
|
| 265 | + $wpdb->prepare( |
|
| 266 | + "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d", |
|
| 267 | + $page_on_front |
|
| 268 | + ) |
|
| 269 | + ); |
|
| 270 | + // set the current post slug to what it actually is |
|
| 271 | + $current_post = $page_on_front ? $page_on_front : $current_post; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + // where are posts being displayed ? |
|
| 276 | + $page_for_posts = EE_Config::get_page_for_posts(); |
|
| 277 | + // in case $current_post is hierarchical like: /parent-page/current-page |
|
| 278 | + $current_post = basename($current_post); |
|
| 279 | + // are we on a category page? |
|
| 280 | + $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name', |
|
| 281 | + $WP->query_vars); |
|
| 282 | + // make sure shortcodes are set |
|
| 283 | + if (isset($this->Registry->CFG->core->post_shortcodes)) { |
|
| 284 | + if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) { |
|
| 285 | + $this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array(); |
|
| 286 | + } |
|
| 287 | + // cycle thru all posts with shortcodes set |
|
| 288 | + foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
| 289 | + // filter shortcodes so |
|
| 290 | + $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes', |
|
| 291 | + $post_shortcodes); |
|
| 292 | + // now cycle thru shortcodes |
|
| 293 | + foreach ($post_shortcodes as $shortcode_class => $post_id) { |
|
| 294 | + // are we on this page, or on the blog page, or an EE CPT category page ? |
|
| 295 | + if ($current_post === $post_name || $term_exists) { |
|
| 296 | + // maybe init the shortcode |
|
| 297 | + $this->initialize_shortcode_if_active_on_page( |
|
| 298 | + $shortcode_class, |
|
| 299 | + $current_post, |
|
| 300 | + $page_for_posts, |
|
| 301 | + $post_id, |
|
| 302 | + $term_exists, |
|
| 303 | + $WP |
|
| 304 | + ); |
|
| 305 | + // if this is NOT the "Posts page" and we have a valid entry |
|
| 306 | + // for the "Posts page" in our tracked post_shortcodes array |
|
| 307 | + // but the shortcode is not being tracked for this page |
|
| 308 | + } else if ( |
|
| 309 | + $post_name !== $page_for_posts |
|
| 310 | + && isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts]) |
|
| 311 | + && ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class]) |
|
| 312 | + ) { |
|
| 313 | + // then remove the "fallback" shortcode processor |
|
| 314 | + remove_shortcode($shortcode_class); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @param string $shortcode_class |
|
| 325 | + * @param string $current_post |
|
| 326 | + * @param string $page_for_posts |
|
| 327 | + * @param int $post_id |
|
| 328 | + * @param bool $term_exists |
|
| 329 | + * @param WP $WP |
|
| 330 | + */ |
|
| 331 | + protected function initialize_shortcode_if_active_on_page( |
|
| 332 | + $shortcode_class, |
|
| 333 | + $current_post, |
|
| 334 | + $page_for_posts, |
|
| 335 | + $post_id, |
|
| 336 | + $term_exists, |
|
| 337 | + $WP |
|
| 338 | + ) { |
|
| 339 | + // verify shortcode is in list of registered shortcodes |
|
| 340 | + if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) { |
|
| 341 | + if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) { |
|
| 342 | + EE_Error::add_error( |
|
| 343 | + sprintf( |
|
| 344 | + __( |
|
| 345 | + 'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.', |
|
| 346 | + 'event_espresso' |
|
| 347 | + ), |
|
| 348 | + $shortcode_class |
|
| 349 | + ), |
|
| 350 | + __FILE__, |
|
| 351 | + __FUNCTION__, |
|
| 352 | + __LINE__ |
|
| 353 | + ); |
|
| 354 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 355 | + } |
|
| 356 | + add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor')); |
|
| 357 | + return; |
|
| 358 | + } |
|
| 359 | + // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ? |
|
| 360 | + if ( |
|
| 361 | + $term_exists |
|
| 362 | + || $current_post === $page_for_posts |
|
| 363 | + || isset($this->Registry->CFG->core->post_shortcodes[$current_post]) |
|
| 364 | + ) { |
|
| 365 | + // let's pause to reflect on this... |
|
| 366 | + $sc_reflector = new ReflectionClass('EES_' . $shortcode_class); |
|
| 367 | + // ensure that class is actually a shortcode |
|
| 368 | + if ( |
|
| 369 | + defined('WP_DEBUG') |
|
| 370 | + && WP_DEBUG === true |
|
| 371 | + && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
| 372 | + ) { |
|
| 373 | + EE_Error::add_error( |
|
| 374 | + sprintf( |
|
| 375 | + __( |
|
| 376 | + 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
| 377 | + 'event_espresso' |
|
| 378 | + ), |
|
| 379 | + $shortcode_class |
|
| 380 | + ), |
|
| 381 | + __FILE__, |
|
| 382 | + __FUNCTION__, |
|
| 383 | + __LINE__ |
|
| 384 | + ); |
|
| 385 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 386 | + return; |
|
| 387 | + } |
|
| 388 | + // and pass the request object to the run method |
|
| 389 | + $this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
| 390 | + // fire the shortcode class's run method, so that it can activate resources |
|
| 391 | + $this->Registry->shortcodes->{$shortcode_class}->run($WP); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 398 | + * |
|
| 399 | + * @access public |
|
| 400 | + * @param WP_Query $WP_Query |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | + public function pre_get_posts($WP_Query) |
|
| 404 | + { |
|
| 405 | + // only load Module_Request_Router if this is the main query |
|
| 406 | + if ( |
|
| 407 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 408 | + && $WP_Query->is_main_query() |
|
| 409 | + ) { |
|
| 410 | + // cycle thru module routes |
|
| 411 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 412 | + // determine module and method for route |
|
| 413 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 414 | + if ($module instanceof EED_Module) { |
|
| 415 | + // get registered view for route |
|
| 416 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 417 | + // grab module name |
|
| 418 | + $module_name = $module->module_name(); |
|
| 419 | + // map the module to the module objects |
|
| 420 | + $this->Registry->modules->{$module_name} = $module; |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /*********************************************** WP HOOK ***********************************************/ |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * wp - basically last chance to do stuff before headers sent |
|
| 435 | + * |
|
| 436 | + * @access public |
|
| 437 | + * @return void |
|
| 438 | + */ |
|
| 439 | + public function wp() |
|
| 440 | + { |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /*********************************************** WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK ***********************************************/ |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * wp_enqueue_scripts |
|
| 450 | + * |
|
| 451 | + * @access public |
|
| 452 | + * @return void |
|
| 453 | + */ |
|
| 454 | + public function wp_enqueue_scripts() |
|
| 455 | + { |
|
| 456 | + |
|
| 457 | + // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_css', '__return_false' ); |
|
| 458 | + if (apply_filters('FHEE_load_css', true)) { |
|
| 459 | + |
|
| 460 | + $this->Registry->CFG->template_settings->enable_default_style = true; |
|
| 461 | + //Load the ThemeRoller styles if enabled |
|
| 462 | + if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) { |
|
| 463 | + |
|
| 464 | + //Load custom style sheet if available |
|
| 465 | + if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) { |
|
| 466 | + wp_register_style('espresso_custom_css', |
|
| 467 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet, |
|
| 468 | + EVENT_ESPRESSO_VERSION); |
|
| 469 | + wp_enqueue_style('espresso_custom_css'); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) { |
|
| 473 | + wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css', |
|
| 474 | + array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 475 | + } else { |
|
| 476 | + wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 477 | + array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 478 | + } |
|
| 479 | + wp_enqueue_style('espresso_default'); |
|
| 480 | + |
|
| 481 | + if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) { |
|
| 482 | + wp_register_style('espresso_style', |
|
| 483 | + get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 484 | + array('dashicons', 'espresso_default')); |
|
| 485 | + } else { |
|
| 486 | + wp_register_style('espresso_style', |
|
| 487 | + EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 488 | + array('dashicons', 'espresso_default')); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_js', '__return_false' ); |
|
| 496 | + if (apply_filters('FHEE_load_js', true)) { |
|
| 497 | + |
|
| 498 | + wp_enqueue_script('jquery'); |
|
| 499 | + //let's make sure that all required scripts have been setup |
|
| 500 | + if (function_exists('wp_script_is') && ! wp_script_is('jquery')) { |
|
| 501 | + $msg = sprintf( |
|
| 502 | + __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.', |
|
| 503 | + 'event_espresso'), |
|
| 504 | + '<em><br />', |
|
| 505 | + '</em>' |
|
| 506 | + ); |
|
| 507 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 508 | + } |
|
| 509 | + // load core js |
|
| 510 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), |
|
| 511 | + EVENT_ESPRESSO_VERSION, true); |
|
| 512 | + wp_enqueue_script('espresso_core'); |
|
| 513 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 514 | + |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 518 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 519 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + //accounting.js library |
|
| 524 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 525 | + if (apply_filters('FHEE_load_accounting_js', false)) { |
|
| 526 | + $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js'; |
|
| 527 | + wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 528 | + array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 529 | + wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true); |
|
| 530 | + wp_enqueue_script('ee-accounting'); |
|
| 531 | + |
|
| 532 | + $currency_config = array( |
|
| 533 | + 'currency' => array( |
|
| 534 | + 'symbol' => $this->Registry->CFG->currency->sign, |
|
| 535 | + 'format' => array( |
|
| 536 | + 'pos' => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s', |
|
| 537 | + 'neg' => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 538 | + 'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s', |
|
| 539 | + ), |
|
| 540 | + 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 541 | + 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 542 | + 'precision' => $this->Registry->CFG->currency->dec_plc, |
|
| 543 | + ), |
|
| 544 | + 'number' => array( |
|
| 545 | + 'precision' => 0, |
|
| 546 | + 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 547 | + 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 548 | + ), |
|
| 549 | + ); |
|
| 550 | + wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + if ( ! function_exists('wp_head')) { |
|
| 554 | + $msg = sprintf( |
|
| 555 | + __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 556 | + 'event_espresso'), |
|
| 557 | + '<em><br />', |
|
| 558 | + '</em>' |
|
| 559 | + ); |
|
| 560 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 561 | + } |
|
| 562 | + if ( ! function_exists('wp_footer')) { |
|
| 563 | + $msg = sprintf( |
|
| 564 | + __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 565 | + 'event_espresso'), |
|
| 566 | + '<em><br />', |
|
| 567 | + '</em>' |
|
| 568 | + ); |
|
| 569 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * header_meta_tag |
|
| 577 | + * |
|
| 578 | + * @access public |
|
| 579 | + * @return void |
|
| 580 | + */ |
|
| 581 | + public function header_meta_tag() |
|
| 582 | + { |
|
| 583 | + print( |
|
| 584 | + apply_filters( |
|
| 585 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 586 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 587 | + ); |
|
| 588 | + |
|
| 589 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 590 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 591 | + if ( |
|
| 592 | + is_tax('espresso_event_type') |
|
| 593 | + && get_option( 'blog_public' ) !== '0' |
|
| 594 | + ) { |
|
| 595 | + print( |
|
| 596 | + apply_filters( |
|
| 597 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 598 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 599 | + ) |
|
| 600 | + ); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /*********************************************** THE_CONTENT FILTER HOOK ***********************************************/ |
|
| 608 | + /** |
|
| 609 | + * the_content |
|
| 610 | + * |
|
| 611 | + * @access public |
|
| 612 | + * @param $the_content |
|
| 613 | + * @return string |
|
| 614 | + */ |
|
| 615 | + // public function the_content( $the_content ) { |
|
| 616 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 617 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 618 | + // } |
|
| 619 | + // return $the_content; |
|
| 620 | + // } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * display_errors |
|
| 628 | + * |
|
| 629 | + * @access public |
|
| 630 | + * @return string |
|
| 631 | + */ |
|
| 632 | + public function display_errors() |
|
| 633 | + { |
|
| 634 | + static $shown_already = false; |
|
| 635 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 636 | + if ( |
|
| 637 | + ! $shown_already |
|
| 638 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 639 | + && is_main_query() |
|
| 640 | + && ! is_feed() |
|
| 641 | + && in_the_loop() |
|
| 642 | + && $this->Request_Handler->is_espresso_page() |
|
| 643 | + ) { |
|
| 644 | + echo EE_Error::get_notices(); |
|
| 645 | + $shown_already = true; |
|
| 646 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 647 | + } |
|
| 648 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /*********************************************** UTILITIES ***********************************************/ |
|
| 656 | + /** |
|
| 657 | + * template_include |
|
| 658 | + * |
|
| 659 | + * @access public |
|
| 660 | + * @param string $template_include_path |
|
| 661 | + * @return string |
|
| 662 | + */ |
|
| 663 | + public function template_include($template_include_path = null) |
|
| 664 | + { |
|
| 665 | + if ($this->Request_Handler->is_espresso_page()) { |
|
| 666 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 667 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 668 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 669 | + $this->_template = basename($this->_template_path); |
|
| 670 | + return $this->_template_path; |
|
| 671 | + } |
|
| 672 | + return $template_include_path; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * get_selected_template |
|
| 678 | + * |
|
| 679 | + * @access public |
|
| 680 | + * @param bool $with_path |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + public function get_selected_template($with_path = false) |
|
| 684 | + { |
|
| 685 | + return $with_path ? $this->_template_path : $this->_template; |
|
| 686 | + } |
|
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | } |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function load_espresso_template_tags() |
| 142 | 142 | { |
| 143 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 144 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 143 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
| 144 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | || isset($this->Registry->CFG->core->post_shortcodes[$current_post]) |
| 364 | 364 | ) { |
| 365 | 365 | // let's pause to reflect on this... |
| 366 | - $sc_reflector = new ReflectionClass('EES_' . $shortcode_class); |
|
| 366 | + $sc_reflector = new ReflectionClass('EES_'.$shortcode_class); |
|
| 367 | 367 | // ensure that class is actually a shortcode |
| 368 | 368 | if ( |
| 369 | 369 | defined('WP_DEBUG') |
@@ -464,27 +464,27 @@ discard block |
||
| 464 | 464 | //Load custom style sheet if available |
| 465 | 465 | if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) { |
| 466 | 466 | wp_register_style('espresso_custom_css', |
| 467 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet, |
|
| 467 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->Registry->CFG->template_settings->custom_style_sheet, |
|
| 468 | 468 | EVENT_ESPRESSO_VERSION); |
| 469 | 469 | wp_enqueue_style('espresso_custom_css'); |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) { |
|
| 473 | - wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css', |
|
| 472 | + if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')) { |
|
| 473 | + wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css', |
|
| 474 | 474 | array('dashicons'), EVENT_ESPRESSO_VERSION); |
| 475 | 475 | } else { |
| 476 | - wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 476 | + wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
| 477 | 477 | array('dashicons'), EVENT_ESPRESSO_VERSION); |
| 478 | 478 | } |
| 479 | 479 | wp_enqueue_style('espresso_default'); |
| 480 | 480 | |
| 481 | - if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) { |
|
| 481 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'style.css')) { |
|
| 482 | 482 | wp_register_style('espresso_style', |
| 483 | - get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 483 | + get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'style.css', |
|
| 484 | 484 | array('dashicons', 'espresso_default')); |
| 485 | 485 | } else { |
| 486 | 486 | wp_register_style('espresso_style', |
| 487 | - EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 487 | + EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'style.css', |
|
| 488 | 488 | array('dashicons', 'espresso_default')); |
| 489 | 489 | } |
| 490 | 490 | |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 508 | 508 | } |
| 509 | 509 | // load core js |
| 510 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), |
|
| 510 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), |
|
| 511 | 511 | EVENT_ESPRESSO_VERSION, true); |
| 512 | 512 | wp_enqueue_script('espresso_core'); |
| 513 | 513 | wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
@@ -523,8 +523,8 @@ discard block |
||
| 523 | 523 | //accounting.js library |
| 524 | 524 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 525 | 525 | if (apply_filters('FHEE_load_accounting_js', false)) { |
| 526 | - $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js'; |
|
| 527 | - wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 526 | + $acct_js = EE_THIRD_PARTY_URL.'accounting/accounting.js'; |
|
| 527 | + wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 528 | 528 | array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true); |
| 529 | 529 | wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true); |
| 530 | 530 | wp_enqueue_script('ee-accounting'); |
@@ -583,19 +583,19 @@ discard block |
||
| 583 | 583 | print( |
| 584 | 584 | apply_filters( |
| 585 | 585 | 'FHEE__EE_Front_Controller__header_meta_tag', |
| 586 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 586 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
| 587 | 587 | ); |
| 588 | 588 | |
| 589 | 589 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
| 590 | 590 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
| 591 | 591 | if ( |
| 592 | 592 | is_tax('espresso_event_type') |
| 593 | - && get_option( 'blog_public' ) !== '0' |
|
| 593 | + && get_option('blog_public') !== '0' |
|
| 594 | 594 | ) { |
| 595 | 595 | print( |
| 596 | 596 | apply_filters( |
| 597 | 597 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
| 598 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 598 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
| 599 | 599 | ) |
| 600 | 600 | ); |
| 601 | 601 | } |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | ) { |
| 644 | 644 | echo EE_Error::get_notices(); |
| 645 | 645 | $shown_already = true; |
| 646 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 646 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
| 647 | 647 | } |
| 648 | 648 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
| 649 | 649 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -28,2112 +28,2112 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - //set in _init_page_props() |
|
| 32 | - public $page_slug; |
|
| 31 | + //set in _init_page_props() |
|
| 32 | + public $page_slug; |
|
| 33 | 33 | |
| 34 | - public $page_label; |
|
| 34 | + public $page_label; |
|
| 35 | 35 | |
| 36 | - public $page_folder; |
|
| 36 | + public $page_folder; |
|
| 37 | 37 | |
| 38 | - //set in define_page_props() |
|
| 39 | - protected $_admin_base_url; |
|
| 38 | + //set in define_page_props() |
|
| 39 | + protected $_admin_base_url; |
|
| 40 | 40 | |
| 41 | - protected $_admin_base_path; |
|
| 41 | + protected $_admin_base_path; |
|
| 42 | 42 | |
| 43 | - protected $_admin_page_title; |
|
| 43 | + protected $_admin_page_title; |
|
| 44 | 44 | |
| 45 | - protected $_labels; |
|
| 45 | + protected $_labels; |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - //set early within EE_Admin_Init |
|
| 49 | - protected $_wp_page_slug; |
|
| 48 | + //set early within EE_Admin_Init |
|
| 49 | + protected $_wp_page_slug; |
|
| 50 | 50 | |
| 51 | - //navtabs |
|
| 52 | - protected $_nav_tabs; |
|
| 51 | + //navtabs |
|
| 52 | + protected $_nav_tabs; |
|
| 53 | 53 | |
| 54 | - protected $_default_nav_tab_name; |
|
| 54 | + protected $_default_nav_tab_name; |
|
| 55 | 55 | |
| 56 | - //helptourstops |
|
| 57 | - protected $_help_tour = array(); |
|
| 56 | + //helptourstops |
|
| 57 | + protected $_help_tour = array(); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - //template variables (used by templates) |
|
| 61 | - protected $_template_path; |
|
| 60 | + //template variables (used by templates) |
|
| 61 | + protected $_template_path; |
|
| 62 | 62 | |
| 63 | - protected $_column_template_path; |
|
| 63 | + protected $_column_template_path; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var array $_template_args |
|
| 67 | - */ |
|
| 68 | - protected $_template_args = array(); |
|
| 65 | + /** |
|
| 66 | + * @var array $_template_args |
|
| 67 | + */ |
|
| 68 | + protected $_template_args = array(); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * this will hold the list table object for a given view. |
|
| 72 | - * |
|
| 73 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 74 | - */ |
|
| 75 | - protected $_list_table_object; |
|
| 70 | + /** |
|
| 71 | + * this will hold the list table object for a given view. |
|
| 72 | + * |
|
| 73 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 74 | + */ |
|
| 75 | + protected $_list_table_object; |
|
| 76 | 76 | |
| 77 | - //bools |
|
| 78 | - protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 77 | + //bools |
|
| 78 | + protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states. |
|
| 79 | 79 | |
| 80 | - protected $_routing; |
|
| 80 | + protected $_routing; |
|
| 81 | 81 | |
| 82 | - //list table args |
|
| 83 | - protected $_view; |
|
| 82 | + //list table args |
|
| 83 | + protected $_view; |
|
| 84 | 84 | |
| 85 | - protected $_views; |
|
| 85 | + protected $_views; |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - //action => method pairs used for routing incoming requests |
|
| 89 | - protected $_page_routes; |
|
| 88 | + //action => method pairs used for routing incoming requests |
|
| 89 | + protected $_page_routes; |
|
| 90 | 90 | |
| 91 | - protected $_page_config; |
|
| 91 | + protected $_page_config; |
|
| 92 | 92 | |
| 93 | - //the current page route and route config |
|
| 94 | - protected $_route; |
|
| 93 | + //the current page route and route config |
|
| 94 | + protected $_route; |
|
| 95 | 95 | |
| 96 | - protected $_route_config; |
|
| 96 | + protected $_route_config; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 100 | - * actions. |
|
| 101 | - * |
|
| 102 | - * @since 4.6.x |
|
| 103 | - * @var array. |
|
| 104 | - */ |
|
| 105 | - protected $_default_route_query_args; |
|
| 98 | + /** |
|
| 99 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 100 | + * actions. |
|
| 101 | + * |
|
| 102 | + * @since 4.6.x |
|
| 103 | + * @var array. |
|
| 104 | + */ |
|
| 105 | + protected $_default_route_query_args; |
|
| 106 | 106 | |
| 107 | - //set via request page and action args. |
|
| 108 | - protected $_current_page; |
|
| 107 | + //set via request page and action args. |
|
| 108 | + protected $_current_page; |
|
| 109 | 109 | |
| 110 | - protected $_current_view; |
|
| 110 | + protected $_current_view; |
|
| 111 | 111 | |
| 112 | - protected $_current_page_view_url; |
|
| 112 | + protected $_current_page_view_url; |
|
| 113 | 113 | |
| 114 | - //sanitized request action (and nonce) |
|
| 115 | - /** |
|
| 116 | - * @var string $_req_action |
|
| 117 | - */ |
|
| 118 | - protected $_req_action; |
|
| 114 | + //sanitized request action (and nonce) |
|
| 115 | + /** |
|
| 116 | + * @var string $_req_action |
|
| 117 | + */ |
|
| 118 | + protected $_req_action; |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @var string $_req_nonce |
|
| 122 | - */ |
|
| 123 | - protected $_req_nonce; |
|
| 120 | + /** |
|
| 121 | + * @var string $_req_nonce |
|
| 122 | + */ |
|
| 123 | + protected $_req_nonce; |
|
| 124 | 124 | |
| 125 | - //search related |
|
| 126 | - protected $_search_btn_label; |
|
| 125 | + //search related |
|
| 126 | + protected $_search_btn_label; |
|
| 127 | 127 | |
| 128 | - protected $_search_box_callback; |
|
| 128 | + protected $_search_box_callback; |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * WP Current Screen object |
|
| 132 | - * |
|
| 133 | - * @var WP_Screen |
|
| 134 | - */ |
|
| 135 | - protected $_current_screen; |
|
| 130 | + /** |
|
| 131 | + * WP Current Screen object |
|
| 132 | + * |
|
| 133 | + * @var WP_Screen |
|
| 134 | + */ |
|
| 135 | + protected $_current_screen; |
|
| 136 | 136 | |
| 137 | - //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 138 | - protected $_hook_obj; |
|
| 137 | + //for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 138 | + protected $_hook_obj; |
|
| 139 | 139 | |
| 140 | - //for holding incoming request data |
|
| 141 | - protected $_req_data; |
|
| 140 | + //for holding incoming request data |
|
| 141 | + protected $_req_data; |
|
| 142 | 142 | |
| 143 | - // yes / no array for admin form fields |
|
| 144 | - protected $_yes_no_values = array(); |
|
| 145 | - |
|
| 146 | - //some default things shared by all child classes |
|
| 147 | - protected $_default_espresso_metaboxes; |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * EE_Registry Object |
|
| 151 | - * |
|
| 152 | - * @var EE_Registry |
|
| 153 | - * @access protected |
|
| 154 | - */ |
|
| 155 | - protected $EE = null; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 161 | - * |
|
| 162 | - * @var boolean |
|
| 163 | - */ |
|
| 164 | - protected $_is_caf = false; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @Constructor |
|
| 170 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 171 | - * @access public |
|
| 172 | - */ |
|
| 173 | - public function __construct($routing = true) |
|
| 174 | - { |
|
| 175 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 176 | - $this->_is_caf = true; |
|
| 177 | - } |
|
| 178 | - $this->_yes_no_values = array( |
|
| 179 | - array('id' => true, 'text' => __('Yes', 'event_espresso')), |
|
| 180 | - array('id' => false, 'text' => __('No', 'event_espresso')), |
|
| 181 | - ); |
|
| 182 | - //set the _req_data property. |
|
| 183 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 184 | - //routing enabled? |
|
| 185 | - $this->_routing = $routing; |
|
| 186 | - //set initial page props (child method) |
|
| 187 | - $this->_init_page_props(); |
|
| 188 | - //set global defaults |
|
| 189 | - $this->_set_defaults(); |
|
| 190 | - //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 191 | - $this->_global_ajax_hooks(); |
|
| 192 | - $this->_ajax_hooks(); |
|
| 193 | - //other_page_hooks have to be early too. |
|
| 194 | - $this->_do_other_page_hooks(); |
|
| 195 | - //This just allows us to have extending clases do something specific before the parent constructor runs _page_setup. |
|
| 196 | - if (method_exists($this, '_before_page_setup')) { |
|
| 197 | - $this->_before_page_setup(); |
|
| 198 | - } |
|
| 199 | - //set up page dependencies |
|
| 200 | - $this->_page_setup(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * _init_page_props |
|
| 207 | - * Child classes use to set at least the following properties: |
|
| 208 | - * $page_slug. |
|
| 209 | - * $page_label. |
|
| 210 | - * |
|
| 211 | - * @abstract |
|
| 212 | - * @access protected |
|
| 213 | - * @return void |
|
| 214 | - */ |
|
| 215 | - abstract protected function _init_page_props(); |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * _ajax_hooks |
|
| 221 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 222 | - * Note: within the ajax callback methods. |
|
| 223 | - * |
|
| 224 | - * @abstract |
|
| 225 | - * @access protected |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - abstract protected function _ajax_hooks(); |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * _define_page_props |
|
| 234 | - * child classes define page properties in here. Must include at least: |
|
| 235 | - * $_admin_base_url = base_url for all admin pages |
|
| 236 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 237 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 238 | - * array( |
|
| 239 | - * 'buttons' => array( |
|
| 240 | - * 'add' => __('label for add new button'), |
|
| 241 | - * 'edit' => __('label for edit button'), |
|
| 242 | - * 'delete' => __('label for delete button') |
|
| 243 | - * ) |
|
| 244 | - * ) |
|
| 245 | - * |
|
| 246 | - * @abstract |
|
| 247 | - * @access protected |
|
| 248 | - * @return void |
|
| 249 | - */ |
|
| 250 | - abstract protected function _define_page_props(); |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * _set_page_routes |
|
| 256 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also have a 'default' |
|
| 257 | - * route. Here's the format |
|
| 258 | - * $this->_page_routes = array( |
|
| 259 | - * 'default' => array( |
|
| 260 | - * 'func' => '_default_method_handling_route', |
|
| 261 | - * 'args' => array('array','of','args'), |
|
| 262 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing) |
|
| 263 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after. The string you enter here should match the defined route reference for a headers sent route. |
|
| 264 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access this route. |
|
| 265 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks). |
|
| 266 | - * ), |
|
| 267 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method. |
|
| 268 | - * ) |
|
| 269 | - * ) |
|
| 270 | - * |
|
| 271 | - * @abstract |
|
| 272 | - * @access protected |
|
| 273 | - * @return void |
|
| 274 | - */ |
|
| 275 | - abstract protected function _set_page_routes(); |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * _set_page_config |
|
| 281 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page. |
|
| 282 | - * Format: |
|
| 283 | - * $this->_page_config = array( |
|
| 284 | - * 'default' => array( |
|
| 285 | - * 'labels' => array( |
|
| 286 | - * 'buttons' => array( |
|
| 287 | - * 'add' => __('label for adding item'), |
|
| 288 | - * 'edit' => __('label for editing item'), |
|
| 289 | - * 'delete' => __('label for deleting item') |
|
| 290 | - * ), |
|
| 291 | - * 'publishbox' => __('Localized Title for Publish metabox', 'event_espresso') |
|
| 292 | - * ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method |
|
| 293 | - * 'nav' => array( |
|
| 294 | - * 'label' => __('Label for Tab', 'event_espresso'). |
|
| 295 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 296 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 297 | - * 'order' => 10, //required to indicate tab position. |
|
| 298 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter. |
|
| 299 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 300 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages. |
|
| 301 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added later. We just use |
|
| 302 | - * this flag to make sure the necessary js gets enqueued on page load. |
|
| 303 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 304 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The array indicates the max number of columns (4) and the default number of columns on page load (2). There is an option |
|
| 305 | - * in the "screen_options" dropdown that is setup so users can pick what columns they want to display. |
|
| 306 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 307 | - * 'tab_id' => array( |
|
| 308 | - * 'title' => 'tab_title', |
|
| 309 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content. The fallback if it isn't present is to try a the callback. Filename should match a file in the admin |
|
| 310 | - * folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 311 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class |
|
| 312 | - * ), |
|
| 313 | - * 'tab2_id' => array( |
|
| 314 | - * 'title' => 'tab2 title', |
|
| 315 | - * 'filename' => 'file_name_2' |
|
| 316 | - * 'callback' => 'callback_method_for_content', |
|
| 317 | - * ), |
|
| 318 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 319 | - * 'help_tour' => array( |
|
| 320 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 321 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 322 | - * ), |
|
| 323 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present). To remove the requirement for a nonce check when this route is visited just set |
|
| 324 | - * 'require_nonce' to FALSE |
|
| 325 | - * ) |
|
| 326 | - * ) |
|
| 327 | - * |
|
| 328 | - * @abstract |
|
| 329 | - * @access protected |
|
| 330 | - * @return void |
|
| 331 | - */ |
|
| 332 | - abstract protected function _set_page_config(); |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** end sample help_tour methods **/ |
|
| 339 | - /** |
|
| 340 | - * _add_screen_options |
|
| 341 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 342 | - * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view. |
|
| 343 | - * |
|
| 344 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 345 | - * see also WP_Screen object documents... |
|
| 346 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 347 | - * @abstract |
|
| 348 | - * @access protected |
|
| 349 | - * @return void |
|
| 350 | - */ |
|
| 351 | - abstract protected function _add_screen_options(); |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * _add_feature_pointers |
|
| 357 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 358 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view. |
|
| 359 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 360 | - * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 361 | - * |
|
| 362 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 363 | - * @abstract |
|
| 364 | - * @access protected |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - abstract protected function _add_feature_pointers(); |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * load_scripts_styles |
|
| 373 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific scripts/styles |
|
| 374 | - * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 375 | - * |
|
| 376 | - * @abstract |
|
| 377 | - * @access public |
|
| 378 | - * @return void |
|
| 379 | - */ |
|
| 380 | - abstract public function load_scripts_styles(); |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * admin_init |
|
| 386 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to all pages/views loaded by child class. |
|
| 387 | - * |
|
| 388 | - * @abstract |
|
| 389 | - * @access public |
|
| 390 | - * @return void |
|
| 391 | - */ |
|
| 392 | - abstract public function admin_init(); |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * admin_notices |
|
| 398 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 399 | - * |
|
| 400 | - * @abstract |
|
| 401 | - * @access public |
|
| 402 | - * @return void |
|
| 403 | - */ |
|
| 404 | - abstract public function admin_notices(); |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * admin_footer_scripts |
|
| 410 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 411 | - * |
|
| 412 | - * @access public |
|
| 413 | - * @return void |
|
| 414 | - */ |
|
| 415 | - abstract public function admin_footer_scripts(); |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * admin_footer |
|
| 421 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class. |
|
| 422 | - * |
|
| 423 | - * @access public |
|
| 424 | - * @return void |
|
| 425 | - */ |
|
| 426 | - public function admin_footer() |
|
| 427 | - { |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * _global_ajax_hooks |
|
| 434 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 435 | - * Note: within the ajax callback methods. |
|
| 436 | - * |
|
| 437 | - * @abstract |
|
| 438 | - * @access protected |
|
| 439 | - * @return void |
|
| 440 | - */ |
|
| 441 | - protected function _global_ajax_hooks() |
|
| 442 | - { |
|
| 443 | - //for lazy loading of metabox content |
|
| 444 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - public function ajax_metabox_content() |
|
| 450 | - { |
|
| 451 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 452 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 453 | - self::cached_rss_display($contentid, $url); |
|
| 454 | - wp_die(); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * _page_setup |
|
| 461 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested doesn't match the object. |
|
| 462 | - * |
|
| 463 | - * @final |
|
| 464 | - * @access protected |
|
| 465 | - * @return void |
|
| 466 | - */ |
|
| 467 | - final protected function _page_setup() |
|
| 468 | - { |
|
| 469 | - //requires? |
|
| 470 | - //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. |
|
| 471 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 472 | - //next verify if we need to load anything... |
|
| 473 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 474 | - $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
|
| 475 | - global $ee_menu_slugs; |
|
| 476 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 477 | - if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
|
| 478 | - return false; |
|
| 479 | - } |
|
| 480 | - // 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 |
|
| 481 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) { |
|
| 482 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action']; |
|
| 483 | - } |
|
| 484 | - // then set blank or -1 action values to 'default' |
|
| 485 | - $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default'; |
|
| 486 | - //if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 487 | - $this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 488 | - //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 489 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 490 | - $this->_current_view = $this->_req_action; |
|
| 491 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 492 | - $this->_define_page_props(); |
|
| 493 | - $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
|
| 494 | - //default things |
|
| 495 | - $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box'); |
|
| 496 | - //set page configs |
|
| 497 | - $this->_set_page_routes(); |
|
| 498 | - $this->_set_page_config(); |
|
| 499 | - //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 500 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 501 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 502 | - } |
|
| 503 | - //for caffeinated and other extended functionality. If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays |
|
| 504 | - if (method_exists($this, '_extend_page_config')) { |
|
| 505 | - $this->_extend_page_config(); |
|
| 506 | - } |
|
| 507 | - //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays. |
|
| 508 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 509 | - $this->_extend_page_config_for_cpt(); |
|
| 510 | - } |
|
| 511 | - //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 512 | - $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | - $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 514 | - //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 515 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 516 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 517 | - } |
|
| 518 | - //next route only if routing enabled |
|
| 519 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 520 | - $this->_verify_routes(); |
|
| 521 | - //next let's just check user_access and kill if no access |
|
| 522 | - $this->check_user_access(); |
|
| 523 | - if ($this->_is_UI_request) { |
|
| 524 | - //admin_init stuff - global, all views for this page class, specific view |
|
| 525 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 526 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 527 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 528 | - } |
|
| 529 | - } else { |
|
| 530 | - //hijack regular WP loading and route admin request immediately |
|
| 531 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 532 | - $this->route_admin_request(); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 541 | - * |
|
| 542 | - * @access private |
|
| 543 | - * @return void |
|
| 544 | - */ |
|
| 545 | - private function _do_other_page_hooks() |
|
| 546 | - { |
|
| 547 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 548 | - foreach ($registered_pages as $page) { |
|
| 549 | - //now let's setup the file name and class that should be present |
|
| 550 | - $classname = str_replace('.class.php', '', $page); |
|
| 551 | - //autoloaders should take care of loading file |
|
| 552 | - if ( ! class_exists($classname)) { |
|
| 553 | - $error_msg[] = sprintf(__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 554 | - $error_msg[] = $error_msg[0] |
|
| 555 | - . "\r\n" |
|
| 556 | - . sprintf(__('There is no class in place for the %s admin hooks page.%sMake sure you have <strong>%s</strong> defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 557 | - 'event_espresso'), $page, '<br />', $classname); |
|
| 558 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 559 | - } |
|
| 560 | - $a = new ReflectionClass($classname); |
|
| 561 | - //notice we are passing the instance of this class to the hook object. |
|
| 562 | - $hookobj[] = $a->newInstance($this); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - public function load_page_dependencies() |
|
| 569 | - { |
|
| 570 | - try { |
|
| 571 | - $this->_load_page_dependencies(); |
|
| 572 | - } catch (EE_Error $e) { |
|
| 573 | - $e->get_error(); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * load_page_dependencies |
|
| 581 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 582 | - * |
|
| 583 | - * @access public |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - protected function _load_page_dependencies() |
|
| 587 | - { |
|
| 588 | - //let's set the current_screen and screen options to override what WP set |
|
| 589 | - $this->_current_screen = get_current_screen(); |
|
| 590 | - //load admin_notices - global, page class, and view specific |
|
| 591 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 592 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 593 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 594 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 595 | - } |
|
| 596 | - //load network admin_notices - global, page class, and view specific |
|
| 597 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 598 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 599 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 600 | - } |
|
| 601 | - //this will save any per_page screen options if they are present |
|
| 602 | - $this->_set_per_page_screen_options(); |
|
| 603 | - //setup list table properties |
|
| 604 | - $this->_set_list_table(); |
|
| 605 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 606 | - $this->_add_registered_meta_boxes(); |
|
| 607 | - $this->_add_screen_columns(); |
|
| 608 | - //add screen options - global, page child class, and view specific |
|
| 609 | - $this->_add_global_screen_options(); |
|
| 610 | - $this->_add_screen_options(); |
|
| 611 | - if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 612 | - call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 613 | - } |
|
| 614 | - //add help tab(s) and tours- set via page_config and qtips. |
|
| 615 | - $this->_add_help_tour(); |
|
| 616 | - $this->_add_help_tabs(); |
|
| 617 | - $this->_add_qtips(); |
|
| 618 | - //add feature_pointers - global, page child class, and view specific |
|
| 619 | - $this->_add_feature_pointers(); |
|
| 620 | - $this->_add_global_feature_pointers(); |
|
| 621 | - if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 622 | - call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 623 | - } |
|
| 624 | - //enqueue scripts/styles - global, page class, and view specific |
|
| 625 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 626 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 627 | - if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 628 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 629 | - } |
|
| 630 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 631 | - //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
|
| 632 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 633 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 634 | - if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 635 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 636 | - } |
|
| 637 | - //admin footer scripts |
|
| 638 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 639 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 640 | - if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 641 | - add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 642 | - } |
|
| 643 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 644 | - //targeted hook |
|
| 645 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * _set_defaults |
|
| 652 | - * This sets some global defaults for class properties. |
|
| 653 | - */ |
|
| 654 | - private function _set_defaults() |
|
| 655 | - { |
|
| 656 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 657 | - $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array(); |
|
| 658 | - $this->default_nav_tab_name = 'overview'; |
|
| 659 | - //init template args |
|
| 660 | - $this->_template_args = array( |
|
| 661 | - 'admin_page_header' => '', |
|
| 662 | - 'admin_page_content' => '', |
|
| 663 | - 'post_body_content' => '', |
|
| 664 | - 'before_list_table' => '', |
|
| 665 | - 'after_list_table' => '', |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * route_admin_request |
|
| 673 | - * |
|
| 674 | - * @see _route_admin_request() |
|
| 675 | - * @access public |
|
| 676 | - * @return void|exception error |
|
| 677 | - */ |
|
| 678 | - public function route_admin_request() |
|
| 679 | - { |
|
| 680 | - try { |
|
| 681 | - $this->_route_admin_request(); |
|
| 682 | - } catch (EE_Error $e) { |
|
| 683 | - $e->get_error(); |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function set_wp_page_slug($wp_page_slug) |
|
| 690 | - { |
|
| 691 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 692 | - //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 693 | - if (is_network_admin()) { |
|
| 694 | - $this->_wp_page_slug .= '-network'; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * _verify_routes |
|
| 702 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so we know if we need to drop out. |
|
| 703 | - * |
|
| 704 | - * @access protected |
|
| 705 | - * @return void |
|
| 706 | - */ |
|
| 707 | - protected function _verify_routes() |
|
| 708 | - { |
|
| 709 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 710 | - if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 711 | - return false; |
|
| 712 | - } |
|
| 713 | - $this->_route = false; |
|
| 714 | - $func = false; |
|
| 715 | - $args = array(); |
|
| 716 | - // check that the page_routes array is not empty |
|
| 717 | - if (empty($this->_page_routes)) { |
|
| 718 | - // user error msg |
|
| 719 | - $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 720 | - // developer error msg |
|
| 721 | - $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | - throw new EE_Error($error_msg); |
|
| 723 | - } |
|
| 724 | - // and that the requested page route exists |
|
| 725 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 726 | - $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 727 | - $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array(); |
|
| 728 | - } else { |
|
| 729 | - // user error msg |
|
| 730 | - $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 731 | - // developer error msg |
|
| 732 | - $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | - throw new EE_Error($error_msg); |
|
| 734 | - } |
|
| 735 | - // and that a default route exists |
|
| 736 | - if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 737 | - // user error msg |
|
| 738 | - $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 739 | - // developer error msg |
|
| 740 | - $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | - throw new EE_Error($error_msg); |
|
| 742 | - } |
|
| 743 | - //first lets' catch if the UI request has EVER been set. |
|
| 744 | - if ($this->_is_UI_request === null) { |
|
| 745 | - //lets set if this is a UI request or not. |
|
| 746 | - $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false; |
|
| 747 | - //wait a minute... we might have a noheader in the route array |
|
| 748 | - $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 749 | - } |
|
| 750 | - $this->_set_current_labels(); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 757 | - * |
|
| 758 | - * @param string $route the route name we're verifying |
|
| 759 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 760 | - */ |
|
| 761 | - protected function _verify_route($route) |
|
| 762 | - { |
|
| 763 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 764 | - return true; |
|
| 765 | - } else { |
|
| 766 | - // user error msg |
|
| 767 | - $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 768 | - // developer error msg |
|
| 769 | - $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | - throw new EE_Error($error_msg); |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * perform nonce verification |
|
| 778 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!) |
|
| 779 | - * |
|
| 780 | - * @param string $nonce The nonce sent |
|
| 781 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 782 | - * @return mixed (bool|die) |
|
| 783 | - */ |
|
| 784 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 785 | - { |
|
| 786 | - // verify nonce against expected value |
|
| 787 | - if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 788 | - // these are not the droids you are looking for !!! |
|
| 789 | - $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
|
| 790 | - if (WP_DEBUG) { |
|
| 791 | - $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | - } |
|
| 793 | - if ( ! defined('DOING_AJAX')) { |
|
| 794 | - wp_die($msg); |
|
| 795 | - } else { |
|
| 796 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 797 | - $this->_return_json(); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - /** |
|
| 805 | - * _route_admin_request() |
|
| 806 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 807 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 808 | - * in the page routes and then will try to load the corresponding method. |
|
| 809 | - * |
|
| 810 | - * @access protected |
|
| 811 | - * @return void |
|
| 812 | - * @throws \EE_Error |
|
| 813 | - */ |
|
| 814 | - protected function _route_admin_request() |
|
| 815 | - { |
|
| 816 | - if ( ! $this->_is_UI_request) { |
|
| 817 | - $this->_verify_routes(); |
|
| 818 | - } |
|
| 819 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 820 | - ? $this->_route_config['require_nonce'] |
|
| 821 | - : true; |
|
| 822 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 823 | - // set nonce from post data |
|
| 824 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 825 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 826 | - : ''; |
|
| 827 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 828 | - } |
|
| 829 | - //set the nav_tabs array but ONLY if this is UI_request |
|
| 830 | - if ($this->_is_UI_request) { |
|
| 831 | - $this->_set_nav_tabs(); |
|
| 832 | - } |
|
| 833 | - // grab callback function |
|
| 834 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 835 | - // check if callback has args |
|
| 836 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 837 | - $error_msg = ''; |
|
| 838 | - // action right before calling route |
|
| 839 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 840 | - if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 841 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 842 | - } |
|
| 843 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 844 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 845 | - $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI'])); |
|
| 846 | - if ( ! empty($func)) { |
|
| 847 | - if (is_array($func)) { |
|
| 848 | - list($class, $method) = $func; |
|
| 849 | - } else if (strpos($func, '::') !== false) { |
|
| 850 | - list($class, $method) = explode('::', $func); |
|
| 851 | - } else { |
|
| 852 | - $class = $this; |
|
| 853 | - $method = $func; |
|
| 854 | - } |
|
| 855 | - if ( ! (is_object($class) && $class === $this)) { |
|
| 856 | - // send along this admin page object for access by addons. |
|
| 857 | - $args['admin_page_object'] = $this; |
|
| 858 | - } |
|
| 859 | - if ( |
|
| 860 | - //is it a method on a class that doesn't work? |
|
| 861 | - ( |
|
| 862 | - method_exists($class, $method) |
|
| 863 | - && call_user_func_array(array($class, $method), $args) === false |
|
| 864 | - ) |
|
| 865 | - || ( |
|
| 866 | - //is it a standalone function that doesn't work? |
|
| 867 | - function_exists($method) |
|
| 868 | - && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false |
|
| 869 | - ) |
|
| 870 | - || ( |
|
| 871 | - //is it neither a class method NOR a standalone function? |
|
| 872 | - ! method_exists($class, $method) |
|
| 873 | - && ! function_exists($method) |
|
| 874 | - ) |
|
| 875 | - ) { |
|
| 876 | - // user error msg |
|
| 877 | - $error_msg = __('An error occurred. The requested page route could not be found.', 'event_espresso'); |
|
| 878 | - // developer error msg |
|
| 879 | - $error_msg .= '||'; |
|
| 880 | - $error_msg .= sprintf( |
|
| 881 | - __( |
|
| 882 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 883 | - 'event_espresso' |
|
| 884 | - ), |
|
| 885 | - $method |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - if ( ! empty($error_msg)) { |
|
| 889 | - throw new EE_Error($error_msg); |
|
| 890 | - } |
|
| 891 | - } |
|
| 892 | - //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route. |
|
| 893 | - //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. |
|
| 894 | - if ($this->_is_UI_request === false |
|
| 895 | - && is_array($this->_route) |
|
| 896 | - && ! empty($this->_route['headers_sent_route']) |
|
| 897 | - ) { |
|
| 898 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 906 | - * route redirects to a headers route in its route config. |
|
| 907 | - * |
|
| 908 | - * @since 4.3.0 |
|
| 909 | - * @param string $new_route New (non header) route to redirect to. |
|
| 910 | - * @return void |
|
| 911 | - */ |
|
| 912 | - protected function _reset_routing_properties($new_route) |
|
| 913 | - { |
|
| 914 | - $this->_is_UI_request = true; |
|
| 915 | - //now we set the current route to whatever the headers_sent_route is set at |
|
| 916 | - $this->_req_data['action'] = $new_route; |
|
| 917 | - //rerun page setup |
|
| 918 | - $this->_page_setup(); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * _add_query_arg |
|
| 925 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 926 | - *(internally just uses EEH_URL's function with the same name) |
|
| 927 | - * |
|
| 928 | - * @access public |
|
| 929 | - * @param array $args |
|
| 930 | - * @param string $url |
|
| 931 | - * @param bool $sticky if true, then the existing Request params will be appended to the generated |
|
| 932 | - * url in an associative array indexed by the key 'wp_referer'; |
|
| 933 | - * Example usage: |
|
| 934 | - * If the current page is: |
|
| 935 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 936 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 937 | - * &_wpnonce=5467821 |
|
| 938 | - * and you call: |
|
| 939 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 940 | - * array( |
|
| 941 | - * 'action' => 'resend_something', |
|
| 942 | - * 'page=>espresso_registrations' |
|
| 943 | - * ), |
|
| 944 | - * $some_url, |
|
| 945 | - * true |
|
| 946 | - * ); |
|
| 947 | - * It will produce a url in this structure: |
|
| 948 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 949 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 950 | - * month_range]=March%202015 |
|
| 951 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 952 | - * @return string |
|
| 953 | - */ |
|
| 954 | - public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false) |
|
| 955 | - { |
|
| 956 | - //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 957 | - if ($sticky) { |
|
| 958 | - $request = $_REQUEST; |
|
| 959 | - unset($request['_wp_http_referer']); |
|
| 960 | - unset($request['wp_referer']); |
|
| 961 | - foreach ($request as $key => $value) { |
|
| 962 | - //do not add nonces |
|
| 963 | - if (strpos($key, 'nonce') !== false) { |
|
| 964 | - continue; |
|
| 965 | - } |
|
| 966 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * This returns a generated link that will load the related help tab. |
|
| 976 | - * |
|
| 977 | - * @param string $help_tab_id the id for the connected help tab |
|
| 978 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 979 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 980 | - * @uses EEH_Template::get_help_tab_link() |
|
| 981 | - * @return string generated link |
|
| 982 | - */ |
|
| 983 | - protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false) |
|
| 984 | - { |
|
| 985 | - return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text); |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * _add_help_tabs |
|
| 992 | - * Note child classes define their help tabs within the page_config array. |
|
| 993 | - * |
|
| 994 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 995 | - * @access protected |
|
| 996 | - * @return void |
|
| 997 | - */ |
|
| 998 | - protected function _add_help_tabs() |
|
| 999 | - { |
|
| 1000 | - $tour_buttons = ''; |
|
| 1001 | - if (isset($this->_page_config[$this->_req_action])) { |
|
| 1002 | - $config = $this->_page_config[$this->_req_action]; |
|
| 1003 | - //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1004 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1005 | - $tb = array(); |
|
| 1006 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1007 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1008 | - //if this is the end tour then we don't need to setup a button |
|
| 1009 | - if ($tour instanceof EE_Help_Tour_final_stop) { |
|
| 1010 | - continue; |
|
| 1011 | - } |
|
| 1012 | - $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1013 | - } |
|
| 1014 | - $tour_buttons .= implode('<br />', $tb); |
|
| 1015 | - $tour_buttons .= '</div></div>'; |
|
| 1016 | - } |
|
| 1017 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1018 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1019 | - //check that the callback given is valid |
|
| 1020 | - if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1021 | - throw new EE_Error(sprintf(__('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', |
|
| 1022 | - 'event_espresso'), $config['help_sidebar'], get_class($this))); |
|
| 1023 | - } |
|
| 1024 | - $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1025 | - $content .= $tour_buttons; //add help tour buttons. |
|
| 1026 | - //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1027 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1028 | - } |
|
| 1029 | - //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. |
|
| 1030 | - if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1031 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1032 | - } |
|
| 1033 | - //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1034 | - if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1035 | - $_ht['id'] = $this->page_slug; |
|
| 1036 | - $_ht['title'] = __('Help Tours', 'event_espresso'); |
|
| 1037 | - $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1038 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1039 | - }/**/ |
|
| 1040 | - if ( ! isset($config['help_tabs'])) { |
|
| 1041 | - return; |
|
| 1042 | - } //no help tabs for this route |
|
| 1043 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1044 | - //we're here so there ARE help tabs! |
|
| 1045 | - //make sure we've got what we need |
|
| 1046 | - if ( ! isset($cfg['title'])) { |
|
| 1047 | - throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); |
|
| 1048 | - } |
|
| 1049 | - if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1050 | - throw new EE_Error(__('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', |
|
| 1051 | - 'event_espresso')); |
|
| 1052 | - } |
|
| 1053 | - //first priority goes to content. |
|
| 1054 | - if ( ! empty($cfg['content'])) { |
|
| 1055 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1056 | - //second priority goes to filename |
|
| 1057 | - } else if ( ! empty($cfg['filename'])) { |
|
| 1058 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1059 | - //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) |
|
| 1060 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1061 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1062 | - if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
|
| 1063 | - EE_Error::add_error(sprintf(__('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', |
|
| 1064 | - 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); |
|
| 1065 | - return; |
|
| 1066 | - } |
|
| 1067 | - $template_args['admin_page_obj'] = $this; |
|
| 1068 | - $content = EEH_Template::display_template($file_path, $template_args, true); |
|
| 1069 | - } else { |
|
| 1070 | - $content = ''; |
|
| 1071 | - } |
|
| 1072 | - //check if callback is valid |
|
| 1073 | - if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) { |
|
| 1074 | - EE_Error::add_error(sprintf(__('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.', |
|
| 1075 | - 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); |
|
| 1076 | - return; |
|
| 1077 | - } |
|
| 1078 | - //setup config array for help tab method |
|
| 1079 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1080 | - $_ht = array( |
|
| 1081 | - 'id' => $id, |
|
| 1082 | - 'title' => $cfg['title'], |
|
| 1083 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1084 | - 'content' => $content, |
|
| 1085 | - ); |
|
| 1086 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is an array with properties for setting up usage of the joyride plugin |
|
| 1095 | - * |
|
| 1096 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1097 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments |
|
| 1098 | - * @access protected |
|
| 1099 | - * @return void |
|
| 1100 | - */ |
|
| 1101 | - protected function _add_help_tour() |
|
| 1102 | - { |
|
| 1103 | - $tours = array(); |
|
| 1104 | - $this->_help_tour = array(); |
|
| 1105 | - //exit early if help tours are turned off globally |
|
| 1106 | - if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) { |
|
| 1107 | - return; |
|
| 1108 | - } |
|
| 1109 | - //loop through _page_config to find any help_tour defined |
|
| 1110 | - foreach ($this->_page_config as $route => $config) { |
|
| 1111 | - //we're only going to set things up for this route |
|
| 1112 | - if ($route !== $this->_req_action) { |
|
| 1113 | - continue; |
|
| 1114 | - } |
|
| 1115 | - if (isset($config['help_tour'])) { |
|
| 1116 | - foreach ($config['help_tour'] as $tour) { |
|
| 1117 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1118 | - //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
|
| 1119 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1120 | - //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1121 | - if ( ! is_readable($file_path)) { |
|
| 1122 | - EE_Error::add_error(sprintf(__('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', 'event_espresso'), |
|
| 1123 | - $file_path, $tour), __FILE__, __FUNCTION__, __LINE__); |
|
| 1124 | - return; |
|
| 1125 | - } |
|
| 1126 | - require_once $file_path; |
|
| 1127 | - if ( ! class_exists($tour)) { |
|
| 1128 | - $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
|
| 1129 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('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.', |
|
| 1130 | - 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
|
| 1131 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 1132 | - } |
|
| 1133 | - $a = new ReflectionClass($tour); |
|
| 1134 | - $tour_obj = $a->newInstance($this->_is_caf); |
|
| 1135 | - $tours[] = $tour_obj; |
|
| 1136 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1137 | - } |
|
| 1138 | - //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1139 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1140 | - $tours[] = $end_stop_tour; |
|
| 1141 | - $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - if ( ! empty($tours)) { |
|
| 1145 | - $this->_help_tour['tours'] = $tours; |
|
| 1146 | - } |
|
| 1147 | - //thats it! Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically. |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1154 | - * |
|
| 1155 | - * @access protected |
|
| 1156 | - * @return void |
|
| 1157 | - */ |
|
| 1158 | - protected function _add_qtips() |
|
| 1159 | - { |
|
| 1160 | - if (isset($this->_route_config['qtips'])) { |
|
| 1161 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1162 | - //load qtip loader |
|
| 1163 | - $path = array( |
|
| 1164 | - $this->_get_dir() . '/qtips/', |
|
| 1165 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1166 | - ); |
|
| 1167 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - /** |
|
| 1174 | - * _set_nav_tabs |
|
| 1175 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly. |
|
| 1176 | - * |
|
| 1177 | - * @access protected |
|
| 1178 | - * @return void |
|
| 1179 | - */ |
|
| 1180 | - protected function _set_nav_tabs() |
|
| 1181 | - { |
|
| 1182 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1183 | - $i = 0; |
|
| 1184 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1185 | - if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) { |
|
| 1186 | - continue; |
|
| 1187 | - } //no nav tab for this config |
|
| 1188 | - //check for persistent flag |
|
| 1189 | - if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) { |
|
| 1190 | - continue; |
|
| 1191 | - } //nav tab is only to appear when route requested. |
|
| 1192 | - if ( ! $this->check_user_access($slug, true)) { |
|
| 1193 | - continue; |
|
| 1194 | - } //no nav tab becasue current user does not have access. |
|
| 1195 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1196 | - $this->_nav_tabs[$slug] = array( |
|
| 1197 | - 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
|
| 1198 | - 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
|
| 1199 | - 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1200 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1201 | - ); |
|
| 1202 | - $i++; |
|
| 1203 | - } |
|
| 1204 | - //if $this->_nav_tabs is empty then lets set the default |
|
| 1205 | - if (empty($this->_nav_tabs)) { |
|
| 1206 | - $this->_nav_tabs[$this->default_nav_tab_name] = array( |
|
| 1207 | - 'url' => $this->admin_base_url, |
|
| 1208 | - 'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)), |
|
| 1209 | - 'css_class' => 'nav-tab-active', |
|
| 1210 | - 'order' => 10, |
|
| 1211 | - ); |
|
| 1212 | - } |
|
| 1213 | - //now let's sort the tabs according to order |
|
| 1214 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - |
|
| 1219 | - /** |
|
| 1220 | - * _set_current_labels |
|
| 1221 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array |
|
| 1222 | - * |
|
| 1223 | - * @access private |
|
| 1224 | - * @return void |
|
| 1225 | - */ |
|
| 1226 | - private function _set_current_labels() |
|
| 1227 | - { |
|
| 1228 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1229 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1230 | - if (is_array($text)) { |
|
| 1231 | - foreach ($text as $sublabel => $subtext) { |
|
| 1232 | - $this->_labels[$label][$sublabel] = $subtext; |
|
| 1233 | - } |
|
| 1234 | - } else { |
|
| 1235 | - $this->_labels[$label] = $text; |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * verifies user access for this admin page |
|
| 1245 | - * |
|
| 1246 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1247 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just return false if verify fail. |
|
| 1248 | - * @return BOOL|wp_die() |
|
| 1249 | - */ |
|
| 1250 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1251 | - { |
|
| 1252 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1253 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1254 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1255 | - ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1256 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1257 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability']; |
|
| 1258 | - } else { |
|
| 1259 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1260 | - } |
|
| 1261 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1262 | - if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1263 | - if ($verify_only) { |
|
| 1264 | - return false; |
|
| 1265 | - } else { |
|
| 1266 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - return true; |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - |
|
| 1274 | - /** |
|
| 1275 | - * admin_init_global |
|
| 1276 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1277 | - * This method executes for ALL EE Admin pages. |
|
| 1278 | - * |
|
| 1279 | - * @access public |
|
| 1280 | - * @return void |
|
| 1281 | - */ |
|
| 1282 | - public function admin_init_global() |
|
| 1283 | - { |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * wp_loaded_global |
|
| 1290 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an EE_Admin page and will execute on every EE Admin Page load |
|
| 1291 | - * |
|
| 1292 | - * @access public |
|
| 1293 | - * @return void |
|
| 1294 | - */ |
|
| 1295 | - public function wp_loaded() |
|
| 1296 | - { |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - |
|
| 1300 | - |
|
| 1301 | - /** |
|
| 1302 | - * admin_notices |
|
| 1303 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1304 | - * |
|
| 1305 | - * @access public |
|
| 1306 | - * @return void |
|
| 1307 | - */ |
|
| 1308 | - public function admin_notices_global() |
|
| 1309 | - { |
|
| 1310 | - $this->_display_no_javascript_warning(); |
|
| 1311 | - $this->_display_espresso_notices(); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - public function network_admin_notices_global() |
|
| 1317 | - { |
|
| 1318 | - $this->_display_no_javascript_warning(); |
|
| 1319 | - $this->_display_espresso_notices(); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - /** |
|
| 1325 | - * admin_footer_scripts_global |
|
| 1326 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1327 | - * |
|
| 1328 | - * @access public |
|
| 1329 | - * @return void |
|
| 1330 | - */ |
|
| 1331 | - public function admin_footer_scripts_global() |
|
| 1332 | - { |
|
| 1333 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1334 | - $this->_add_admin_page_overlay(); |
|
| 1335 | - //if metaboxes are present we need to add the nonce field |
|
| 1336 | - if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) { |
|
| 1337 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1338 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1339 | - } |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - /** |
|
| 1345 | - * admin_footer_global |
|
| 1346 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages. |
|
| 1347 | - * |
|
| 1348 | - * @access public |
|
| 1349 | - * @return void |
|
| 1350 | - */ |
|
| 1351 | - public function admin_footer_global() |
|
| 1352 | - { |
|
| 1353 | - //dialog container for dialog helper |
|
| 1354 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1355 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1356 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1357 | - $d_cont .= '</div>'; |
|
| 1358 | - echo $d_cont; |
|
| 1359 | - //help tour stuff? |
|
| 1360 | - if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1361 | - echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1362 | - } |
|
| 1363 | - //current set timezone for timezone js |
|
| 1364 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * This function sees if there is a method for help popup content existing for the given route. If there is then we'll use the retrieved array to output the content using the template. |
|
| 1371 | - * For child classes: |
|
| 1372 | - * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for |
|
| 1373 | - * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content for the |
|
| 1374 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1375 | - * 'help_trigger_id' => array( |
|
| 1376 | - * 'title' => __('localized title for popup', 'event_espresso'), |
|
| 1377 | - * 'content' => __('localized content for popup', 'event_espresso') |
|
| 1378 | - * ) |
|
| 1379 | - * ); |
|
| 1380 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1381 | - * |
|
| 1382 | - * @access protected |
|
| 1383 | - * @return string content |
|
| 1384 | - */ |
|
| 1385 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1386 | - { |
|
| 1387 | - $content = ''; |
|
| 1388 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1389 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1390 | - //loop through the array and setup content |
|
| 1391 | - foreach ($help_array as $trigger => $help) { |
|
| 1392 | - //make sure the array is setup properly |
|
| 1393 | - if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1394 | - throw new EE_Error(__('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', |
|
| 1395 | - 'event_espresso')); |
|
| 1396 | - } |
|
| 1397 | - //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1398 | - $template_args = array( |
|
| 1399 | - 'help_popup_id' => $trigger, |
|
| 1400 | - 'help_popup_title' => $help['title'], |
|
| 1401 | - 'help_popup_content' => $help['content'], |
|
| 1402 | - ); |
|
| 1403 | - $content .= EEH_Template::display_template($template_path, $template_args, true); |
|
| 1404 | - } |
|
| 1405 | - if ($display) { |
|
| 1406 | - echo $content; |
|
| 1407 | - } else { |
|
| 1408 | - return $content; |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - |
|
| 1413 | - |
|
| 1414 | - /** |
|
| 1415 | - * All this does is retrive the help content array if set by the EE_Admin_Page child |
|
| 1416 | - * |
|
| 1417 | - * @access private |
|
| 1418 | - * @return array properly formatted array for help popup content |
|
| 1419 | - */ |
|
| 1420 | - private function _get_help_content() |
|
| 1421 | - { |
|
| 1422 | - //what is the method we're looking for? |
|
| 1423 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1424 | - //if method doesn't exist let's get out. |
|
| 1425 | - if ( ! method_exists($this, $method_name)) { |
|
| 1426 | - return array(); |
|
| 1427 | - } |
|
| 1428 | - //k we're good to go let's retrieve the help array |
|
| 1429 | - $help_array = call_user_func(array($this, $method_name)); |
|
| 1430 | - //make sure we've got an array! |
|
| 1431 | - if ( ! is_array($help_array)) { |
|
| 1432 | - throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso')); |
|
| 1433 | - } |
|
| 1434 | - return $help_array; |
|
| 1435 | - } |
|
| 1436 | - |
|
| 1437 | - |
|
| 1438 | - |
|
| 1439 | - /** |
|
| 1440 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1441 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1442 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1443 | - * |
|
| 1444 | - * @access protected |
|
| 1445 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1446 | - * @param boolean $display if false then we return the trigger string |
|
| 1447 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1448 | - * @return string |
|
| 1449 | - */ |
|
| 1450 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1451 | - { |
|
| 1452 | - if (defined('DOING_AJAX')) { |
|
| 1453 | - return; |
|
| 1454 | - } |
|
| 1455 | - //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 |
|
| 1456 | - $help_array = $this->_get_help_content(); |
|
| 1457 | - $help_content = ''; |
|
| 1458 | - if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1459 | - $help_array[$trigger_id] = array( |
|
| 1460 | - 'title' => __('Missing Content', 'event_espresso'), |
|
| 1461 | - 'content' => __('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.)', |
|
| 1462 | - 'event_espresso'), |
|
| 1463 | - ); |
|
| 1464 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1465 | - } |
|
| 1466 | - //let's setup the trigger |
|
| 1467 | - $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1468 | - $content = $content . $help_content; |
|
| 1469 | - if ($display) { |
|
| 1470 | - echo $content; |
|
| 1471 | - } else { |
|
| 1472 | - return $content; |
|
| 1473 | - } |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - |
|
| 1477 | - |
|
| 1478 | - /** |
|
| 1479 | - * _add_global_screen_options |
|
| 1480 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1481 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1482 | - * |
|
| 1483 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1484 | - * see also WP_Screen object documents... |
|
| 1485 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1486 | - * @abstract |
|
| 1487 | - * @access private |
|
| 1488 | - * @return void |
|
| 1489 | - */ |
|
| 1490 | - private function _add_global_screen_options() |
|
| 1491 | - { |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - |
|
| 1495 | - |
|
| 1496 | - /** |
|
| 1497 | - * _add_global_feature_pointers |
|
| 1498 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1499 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1500 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1501 | - * |
|
| 1502 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 1503 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1504 | - * @abstract |
|
| 1505 | - * @access protected |
|
| 1506 | - * @return void |
|
| 1507 | - */ |
|
| 1508 | - private function _add_global_feature_pointers() |
|
| 1509 | - { |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * load_global_scripts_styles |
|
| 1516 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1517 | - * |
|
| 1518 | - * @return void |
|
| 1519 | - */ |
|
| 1520 | - public function load_global_scripts_styles() |
|
| 1521 | - { |
|
| 1522 | - /** STYLES **/ |
|
| 1523 | - // add debugging styles |
|
| 1524 | - if (WP_DEBUG) { |
|
| 1525 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1526 | - } |
|
| 1527 | - //register all styles |
|
| 1528 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1529 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1530 | - //helpers styles |
|
| 1531 | - wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1532 | - //enqueue global styles |
|
| 1533 | - wp_enqueue_style('ee-admin-css'); |
|
| 1534 | - /** SCRIPTS **/ |
|
| 1535 | - //register all scripts |
|
| 1536 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1537 | - wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1538 | - wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1539 | - wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1540 | - // register jQuery Validate - see /includes/functions/wp_hooks.php |
|
| 1541 | - add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 1542 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1543 | - //script for sorting tables |
|
| 1544 | - wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | - //script for parsing uri's |
|
| 1546 | - wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | - //and parsing associative serialized form elements |
|
| 1548 | - wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1549 | - //helpers scripts |
|
| 1550 | - wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1551 | - wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | - wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1553 | - wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | - //google charts |
|
| 1555 | - wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
|
| 1556 | - //enqueue global scripts |
|
| 1557 | - //taking care of metaboxes |
|
| 1558 | - if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) { |
|
| 1559 | - wp_enqueue_script('dashboard'); |
|
| 1560 | - } |
|
| 1561 | - //enqueue thickbox for ee help popups. default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups |
|
| 1562 | - if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) { |
|
| 1563 | - wp_enqueue_script('ee_admin_js'); |
|
| 1564 | - wp_enqueue_style('ee-admin-css'); |
|
| 1565 | - } |
|
| 1566 | - //localize script for ajax lazy loading |
|
| 1567 | - $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content')); |
|
| 1568 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1569 | - /** |
|
| 1570 | - * help tour stuff |
|
| 1571 | - */ |
|
| 1572 | - if ( ! empty($this->_help_tour)) { |
|
| 1573 | - //register the js for kicking things off |
|
| 1574 | - wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1575 | - //setup tours for the js tour object |
|
| 1576 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1577 | - $tours[] = array( |
|
| 1578 | - 'id' => $tour->get_slug(), |
|
| 1579 | - 'options' => $tour->get_options(), |
|
| 1580 | - ); |
|
| 1581 | - } |
|
| 1582 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1583 | - //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1584 | - } |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - |
|
| 1589 | - /** |
|
| 1590 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1591 | - * |
|
| 1592 | - * @access public |
|
| 1593 | - * @return void |
|
| 1594 | - */ |
|
| 1595 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 1596 | - { |
|
| 1597 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1598 | - EE_Registry::$i18n_js_strings['confirm_delete'] = __('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!!!', 'event_espresso'); |
|
| 1599 | - EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso'); |
|
| 1600 | - EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso'); |
|
| 1601 | - EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso'); |
|
| 1602 | - EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso'); |
|
| 1603 | - EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1604 | - EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso'); |
|
| 1605 | - EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso'); |
|
| 1606 | - EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso'); |
|
| 1607 | - EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso'); |
|
| 1608 | - EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso'); |
|
| 1609 | - EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso'); |
|
| 1610 | - EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso'); |
|
| 1611 | - EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso'); |
|
| 1612 | - EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso'); |
|
| 1613 | - EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso'); |
|
| 1614 | - EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso'); |
|
| 1615 | - EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1616 | - EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso'); |
|
| 1617 | - EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso'); |
|
| 1618 | - EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso'); |
|
| 1619 | - EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso'); |
|
| 1620 | - EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso'); |
|
| 1621 | - EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso'); |
|
| 1622 | - EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso'); |
|
| 1623 | - EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso'); |
|
| 1624 | - EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso'); |
|
| 1625 | - EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso'); |
|
| 1626 | - EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso'); |
|
| 1627 | - EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso'); |
|
| 1628 | - EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso'); |
|
| 1629 | - EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso'); |
|
| 1630 | - EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso'); |
|
| 1631 | - EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso'); |
|
| 1632 | - EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso'); |
|
| 1633 | - EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso'); |
|
| 1634 | - EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso'); |
|
| 1635 | - EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso'); |
|
| 1636 | - EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso'); |
|
| 1637 | - //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance |
|
| 1638 | - //admin page when in maintenance mode and ee_admin_js is not loaded then. This works everywhere else because |
|
| 1639 | - //espresso_core is listed as a dependency of ee_admin_js. |
|
| 1640 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - |
|
| 1645 | - /** |
|
| 1646 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1647 | - * |
|
| 1648 | - * @access public |
|
| 1649 | - * @return void |
|
| 1650 | - */ |
|
| 1651 | - public function add_xdebug_style() |
|
| 1652 | - { |
|
| 1653 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - |
|
| 1657 | - /************************/ |
|
| 1658 | - /** LIST TABLE METHODS **/ |
|
| 1659 | - /************************/ |
|
| 1660 | - /** |
|
| 1661 | - * this sets up the list table if the current view requires it. |
|
| 1662 | - * |
|
| 1663 | - * @access protected |
|
| 1664 | - * @return void |
|
| 1665 | - */ |
|
| 1666 | - protected function _set_list_table() |
|
| 1667 | - { |
|
| 1668 | - //first is this a list_table view? |
|
| 1669 | - if ( ! isset($this->_route_config['list_table'])) { |
|
| 1670 | - return; |
|
| 1671 | - } //not a list_table view so get out. |
|
| 1672 | - //list table functions are per view specific (because some admin pages might have more than one listtable!) |
|
| 1673 | - if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1674 | - //user error msg |
|
| 1675 | - $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
|
| 1676 | - //developer error msg |
|
| 1677 | - $error_msg .= '||' . sprintf(__('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.', 'event_espresso'), |
|
| 1678 | - $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1679 | - throw new EE_Error($error_msg); |
|
| 1680 | - } |
|
| 1681 | - //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1682 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1683 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1684 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1685 | - $this->_set_list_table_view(); |
|
| 1686 | - $this->_set_list_table_object(); |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - |
|
| 1690 | - |
|
| 1691 | - /** |
|
| 1692 | - * set current view for List Table |
|
| 1693 | - * |
|
| 1694 | - * @access public |
|
| 1695 | - * @return array |
|
| 1696 | - */ |
|
| 1697 | - protected function _set_list_table_view() |
|
| 1698 | - { |
|
| 1699 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1700 | - // looking at active items or dumpster diving ? |
|
| 1701 | - if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 1702 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1703 | - } else { |
|
| 1704 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 1705 | - } |
|
| 1706 | - } |
|
| 1707 | - |
|
| 1708 | - |
|
| 1709 | - |
|
| 1710 | - /** |
|
| 1711 | - * _set_list_table_object |
|
| 1712 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1713 | - * |
|
| 1714 | - * @throws \EE_Error |
|
| 1715 | - */ |
|
| 1716 | - protected function _set_list_table_object() |
|
| 1717 | - { |
|
| 1718 | - if (isset($this->_route_config['list_table'])) { |
|
| 1719 | - if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1720 | - throw new EE_Error( |
|
| 1721 | - sprintf( |
|
| 1722 | - __( |
|
| 1723 | - '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.', |
|
| 1724 | - 'event_espresso' |
|
| 1725 | - ), |
|
| 1726 | - $this->_route_config['list_table'], |
|
| 1727 | - get_class($this) |
|
| 1728 | - ) |
|
| 1729 | - ); |
|
| 1730 | - } |
|
| 1731 | - $list_table = $this->_route_config['list_table']; |
|
| 1732 | - $this->_list_table_object = new $list_table($this); |
|
| 1733 | - } |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - |
|
| 1737 | - |
|
| 1738 | - /** |
|
| 1739 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 1740 | - * |
|
| 1741 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 1742 | - * urls. The array should be indexed by the view it is being |
|
| 1743 | - * added to. |
|
| 1744 | - * @return array |
|
| 1745 | - */ |
|
| 1746 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 1747 | - { |
|
| 1748 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1749 | - if (empty($this->_views)) { |
|
| 1750 | - $this->_views = array(); |
|
| 1751 | - } |
|
| 1752 | - // cycle thru views |
|
| 1753 | - foreach ($this->_views as $key => $view) { |
|
| 1754 | - $query_args = array(); |
|
| 1755 | - // check for current view |
|
| 1756 | - $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
|
| 1757 | - $query_args['action'] = $this->_req_action; |
|
| 1758 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1759 | - $query_args['status'] = $view['slug']; |
|
| 1760 | - //merge any other arguments sent in. |
|
| 1761 | - if (isset($extra_query_args[$view['slug']])) { |
|
| 1762 | - $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 1763 | - } |
|
| 1764 | - $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1765 | - } |
|
| 1766 | - return $this->_views; |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - /** |
|
| 1772 | - * _entries_per_page_dropdown |
|
| 1773 | - * generates a drop down box for selecting the number of visiable rows in an admin page list table |
|
| 1774 | - * |
|
| 1775 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it. |
|
| 1776 | - * @access protected |
|
| 1777 | - * @param int $max_entries total number of rows in the table |
|
| 1778 | - * @return string |
|
| 1779 | - */ |
|
| 1780 | - protected function _entries_per_page_dropdown($max_entries = false) |
|
| 1781 | - { |
|
| 1782 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1783 | - $values = array(10, 25, 50, 100); |
|
| 1784 | - $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 1785 | - if ($max_entries) { |
|
| 1786 | - $values[] = $max_entries; |
|
| 1787 | - sort($values); |
|
| 1788 | - } |
|
| 1789 | - $entries_per_page_dropdown = ' |
|
| 143 | + // yes / no array for admin form fields |
|
| 144 | + protected $_yes_no_values = array(); |
|
| 145 | + |
|
| 146 | + //some default things shared by all child classes |
|
| 147 | + protected $_default_espresso_metaboxes; |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * EE_Registry Object |
|
| 151 | + * |
|
| 152 | + * @var EE_Registry |
|
| 153 | + * @access protected |
|
| 154 | + */ |
|
| 155 | + protected $EE = null; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 161 | + * |
|
| 162 | + * @var boolean |
|
| 163 | + */ |
|
| 164 | + protected $_is_caf = false; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @Constructor |
|
| 170 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 171 | + * @access public |
|
| 172 | + */ |
|
| 173 | + public function __construct($routing = true) |
|
| 174 | + { |
|
| 175 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 176 | + $this->_is_caf = true; |
|
| 177 | + } |
|
| 178 | + $this->_yes_no_values = array( |
|
| 179 | + array('id' => true, 'text' => __('Yes', 'event_espresso')), |
|
| 180 | + array('id' => false, 'text' => __('No', 'event_espresso')), |
|
| 181 | + ); |
|
| 182 | + //set the _req_data property. |
|
| 183 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 184 | + //routing enabled? |
|
| 185 | + $this->_routing = $routing; |
|
| 186 | + //set initial page props (child method) |
|
| 187 | + $this->_init_page_props(); |
|
| 188 | + //set global defaults |
|
| 189 | + $this->_set_defaults(); |
|
| 190 | + //set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 191 | + $this->_global_ajax_hooks(); |
|
| 192 | + $this->_ajax_hooks(); |
|
| 193 | + //other_page_hooks have to be early too. |
|
| 194 | + $this->_do_other_page_hooks(); |
|
| 195 | + //This just allows us to have extending clases do something specific before the parent constructor runs _page_setup. |
|
| 196 | + if (method_exists($this, '_before_page_setup')) { |
|
| 197 | + $this->_before_page_setup(); |
|
| 198 | + } |
|
| 199 | + //set up page dependencies |
|
| 200 | + $this->_page_setup(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * _init_page_props |
|
| 207 | + * Child classes use to set at least the following properties: |
|
| 208 | + * $page_slug. |
|
| 209 | + * $page_label. |
|
| 210 | + * |
|
| 211 | + * @abstract |
|
| 212 | + * @access protected |
|
| 213 | + * @return void |
|
| 214 | + */ |
|
| 215 | + abstract protected function _init_page_props(); |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * _ajax_hooks |
|
| 221 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 222 | + * Note: within the ajax callback methods. |
|
| 223 | + * |
|
| 224 | + * @abstract |
|
| 225 | + * @access protected |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + abstract protected function _ajax_hooks(); |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * _define_page_props |
|
| 234 | + * child classes define page properties in here. Must include at least: |
|
| 235 | + * $_admin_base_url = base_url for all admin pages |
|
| 236 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 237 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 238 | + * array( |
|
| 239 | + * 'buttons' => array( |
|
| 240 | + * 'add' => __('label for add new button'), |
|
| 241 | + * 'edit' => __('label for edit button'), |
|
| 242 | + * 'delete' => __('label for delete button') |
|
| 243 | + * ) |
|
| 244 | + * ) |
|
| 245 | + * |
|
| 246 | + * @abstract |
|
| 247 | + * @access protected |
|
| 248 | + * @return void |
|
| 249 | + */ |
|
| 250 | + abstract protected function _define_page_props(); |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * _set_page_routes |
|
| 256 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also have a 'default' |
|
| 257 | + * route. Here's the format |
|
| 258 | + * $this->_page_routes = array( |
|
| 259 | + * 'default' => array( |
|
| 260 | + * 'func' => '_default_method_handling_route', |
|
| 261 | + * 'args' => array('array','of','args'), |
|
| 262 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing) |
|
| 263 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after. The string you enter here should match the defined route reference for a headers sent route. |
|
| 264 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access this route. |
|
| 265 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks). |
|
| 266 | + * ), |
|
| 267 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method. |
|
| 268 | + * ) |
|
| 269 | + * ) |
|
| 270 | + * |
|
| 271 | + * @abstract |
|
| 272 | + * @access protected |
|
| 273 | + * @return void |
|
| 274 | + */ |
|
| 275 | + abstract protected function _set_page_routes(); |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * _set_page_config |
|
| 281 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page. |
|
| 282 | + * Format: |
|
| 283 | + * $this->_page_config = array( |
|
| 284 | + * 'default' => array( |
|
| 285 | + * 'labels' => array( |
|
| 286 | + * 'buttons' => array( |
|
| 287 | + * 'add' => __('label for adding item'), |
|
| 288 | + * 'edit' => __('label for editing item'), |
|
| 289 | + * 'delete' => __('label for deleting item') |
|
| 290 | + * ), |
|
| 291 | + * 'publishbox' => __('Localized Title for Publish metabox', 'event_espresso') |
|
| 292 | + * ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method |
|
| 293 | + * 'nav' => array( |
|
| 294 | + * 'label' => __('Label for Tab', 'event_espresso'). |
|
| 295 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 296 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 297 | + * 'order' => 10, //required to indicate tab position. |
|
| 298 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter. |
|
| 299 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 300 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages. |
|
| 301 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added later. We just use |
|
| 302 | + * this flag to make sure the necessary js gets enqueued on page load. |
|
| 303 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 304 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The array indicates the max number of columns (4) and the default number of columns on page load (2). There is an option |
|
| 305 | + * in the "screen_options" dropdown that is setup so users can pick what columns they want to display. |
|
| 306 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 307 | + * 'tab_id' => array( |
|
| 308 | + * 'title' => 'tab_title', |
|
| 309 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content. The fallback if it isn't present is to try a the callback. Filename should match a file in the admin |
|
| 310 | + * folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 311 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class |
|
| 312 | + * ), |
|
| 313 | + * 'tab2_id' => array( |
|
| 314 | + * 'title' => 'tab2 title', |
|
| 315 | + * 'filename' => 'file_name_2' |
|
| 316 | + * 'callback' => 'callback_method_for_content', |
|
| 317 | + * ), |
|
| 318 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 319 | + * 'help_tour' => array( |
|
| 320 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 321 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 322 | + * ), |
|
| 323 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present). To remove the requirement for a nonce check when this route is visited just set |
|
| 324 | + * 'require_nonce' to FALSE |
|
| 325 | + * ) |
|
| 326 | + * ) |
|
| 327 | + * |
|
| 328 | + * @abstract |
|
| 329 | + * @access protected |
|
| 330 | + * @return void |
|
| 331 | + */ |
|
| 332 | + abstract protected function _set_page_config(); |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** end sample help_tour methods **/ |
|
| 339 | + /** |
|
| 340 | + * _add_screen_options |
|
| 341 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 342 | + * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view. |
|
| 343 | + * |
|
| 344 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 345 | + * see also WP_Screen object documents... |
|
| 346 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 347 | + * @abstract |
|
| 348 | + * @access protected |
|
| 349 | + * @return void |
|
| 350 | + */ |
|
| 351 | + abstract protected function _add_screen_options(); |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * _add_feature_pointers |
|
| 357 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 358 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view. |
|
| 359 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 360 | + * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 361 | + * |
|
| 362 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 363 | + * @abstract |
|
| 364 | + * @access protected |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + abstract protected function _add_feature_pointers(); |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * load_scripts_styles |
|
| 373 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific scripts/styles |
|
| 374 | + * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 375 | + * |
|
| 376 | + * @abstract |
|
| 377 | + * @access public |
|
| 378 | + * @return void |
|
| 379 | + */ |
|
| 380 | + abstract public function load_scripts_styles(); |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * admin_init |
|
| 386 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to all pages/views loaded by child class. |
|
| 387 | + * |
|
| 388 | + * @abstract |
|
| 389 | + * @access public |
|
| 390 | + * @return void |
|
| 391 | + */ |
|
| 392 | + abstract public function admin_init(); |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * admin_notices |
|
| 398 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 399 | + * |
|
| 400 | + * @abstract |
|
| 401 | + * @access public |
|
| 402 | + * @return void |
|
| 403 | + */ |
|
| 404 | + abstract public function admin_notices(); |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * admin_footer_scripts |
|
| 410 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class. |
|
| 411 | + * |
|
| 412 | + * @access public |
|
| 413 | + * @return void |
|
| 414 | + */ |
|
| 415 | + abstract public function admin_footer_scripts(); |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * admin_footer |
|
| 421 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class. |
|
| 422 | + * |
|
| 423 | + * @access public |
|
| 424 | + * @return void |
|
| 425 | + */ |
|
| 426 | + public function admin_footer() |
|
| 427 | + { |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * _global_ajax_hooks |
|
| 434 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 435 | + * Note: within the ajax callback methods. |
|
| 436 | + * |
|
| 437 | + * @abstract |
|
| 438 | + * @access protected |
|
| 439 | + * @return void |
|
| 440 | + */ |
|
| 441 | + protected function _global_ajax_hooks() |
|
| 442 | + { |
|
| 443 | + //for lazy loading of metabox content |
|
| 444 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + public function ajax_metabox_content() |
|
| 450 | + { |
|
| 451 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 452 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 453 | + self::cached_rss_display($contentid, $url); |
|
| 454 | + wp_die(); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * _page_setup |
|
| 461 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested doesn't match the object. |
|
| 462 | + * |
|
| 463 | + * @final |
|
| 464 | + * @access protected |
|
| 465 | + * @return void |
|
| 466 | + */ |
|
| 467 | + final protected function _page_setup() |
|
| 468 | + { |
|
| 469 | + //requires? |
|
| 470 | + //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. |
|
| 471 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 472 | + //next verify if we need to load anything... |
|
| 473 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 474 | + $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
|
| 475 | + global $ee_menu_slugs; |
|
| 476 | + $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 477 | + if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
|
| 478 | + return false; |
|
| 479 | + } |
|
| 480 | + // 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 |
|
| 481 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) { |
|
| 482 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action']; |
|
| 483 | + } |
|
| 484 | + // then set blank or -1 action values to 'default' |
|
| 485 | + $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default'; |
|
| 486 | + //if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 487 | + $this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 488 | + //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 489 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
|
| 490 | + $this->_current_view = $this->_req_action; |
|
| 491 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 492 | + $this->_define_page_props(); |
|
| 493 | + $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
|
| 494 | + //default things |
|
| 495 | + $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box'); |
|
| 496 | + //set page configs |
|
| 497 | + $this->_set_page_routes(); |
|
| 498 | + $this->_set_page_config(); |
|
| 499 | + //let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 500 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 501 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 502 | + } |
|
| 503 | + //for caffeinated and other extended functionality. If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays |
|
| 504 | + if (method_exists($this, '_extend_page_config')) { |
|
| 505 | + $this->_extend_page_config(); |
|
| 506 | + } |
|
| 507 | + //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays. |
|
| 508 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 509 | + $this->_extend_page_config_for_cpt(); |
|
| 510 | + } |
|
| 511 | + //filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 512 | + $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | + $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 514 | + //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 515 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 516 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 517 | + } |
|
| 518 | + //next route only if routing enabled |
|
| 519 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 520 | + $this->_verify_routes(); |
|
| 521 | + //next let's just check user_access and kill if no access |
|
| 522 | + $this->check_user_access(); |
|
| 523 | + if ($this->_is_UI_request) { |
|
| 524 | + //admin_init stuff - global, all views for this page class, specific view |
|
| 525 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 526 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 527 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 528 | + } |
|
| 529 | + } else { |
|
| 530 | + //hijack regular WP loading and route admin request immediately |
|
| 531 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 532 | + $this->route_admin_request(); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 541 | + * |
|
| 542 | + * @access private |
|
| 543 | + * @return void |
|
| 544 | + */ |
|
| 545 | + private function _do_other_page_hooks() |
|
| 546 | + { |
|
| 547 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 548 | + foreach ($registered_pages as $page) { |
|
| 549 | + //now let's setup the file name and class that should be present |
|
| 550 | + $classname = str_replace('.class.php', '', $page); |
|
| 551 | + //autoloaders should take care of loading file |
|
| 552 | + if ( ! class_exists($classname)) { |
|
| 553 | + $error_msg[] = sprintf(__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page); |
|
| 554 | + $error_msg[] = $error_msg[0] |
|
| 555 | + . "\r\n" |
|
| 556 | + . sprintf(__('There is no class in place for the %s admin hooks page.%sMake sure you have <strong>%s</strong> defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 557 | + 'event_espresso'), $page, '<br />', $classname); |
|
| 558 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 559 | + } |
|
| 560 | + $a = new ReflectionClass($classname); |
|
| 561 | + //notice we are passing the instance of this class to the hook object. |
|
| 562 | + $hookobj[] = $a->newInstance($this); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + public function load_page_dependencies() |
|
| 569 | + { |
|
| 570 | + try { |
|
| 571 | + $this->_load_page_dependencies(); |
|
| 572 | + } catch (EE_Error $e) { |
|
| 573 | + $e->get_error(); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * load_page_dependencies |
|
| 581 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 582 | + * |
|
| 583 | + * @access public |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + protected function _load_page_dependencies() |
|
| 587 | + { |
|
| 588 | + //let's set the current_screen and screen options to override what WP set |
|
| 589 | + $this->_current_screen = get_current_screen(); |
|
| 590 | + //load admin_notices - global, page class, and view specific |
|
| 591 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 592 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 593 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 594 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 595 | + } |
|
| 596 | + //load network admin_notices - global, page class, and view specific |
|
| 597 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 598 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 599 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 600 | + } |
|
| 601 | + //this will save any per_page screen options if they are present |
|
| 602 | + $this->_set_per_page_screen_options(); |
|
| 603 | + //setup list table properties |
|
| 604 | + $this->_set_list_table(); |
|
| 605 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 606 | + $this->_add_registered_meta_boxes(); |
|
| 607 | + $this->_add_screen_columns(); |
|
| 608 | + //add screen options - global, page child class, and view specific |
|
| 609 | + $this->_add_global_screen_options(); |
|
| 610 | + $this->_add_screen_options(); |
|
| 611 | + if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 612 | + call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 613 | + } |
|
| 614 | + //add help tab(s) and tours- set via page_config and qtips. |
|
| 615 | + $this->_add_help_tour(); |
|
| 616 | + $this->_add_help_tabs(); |
|
| 617 | + $this->_add_qtips(); |
|
| 618 | + //add feature_pointers - global, page child class, and view specific |
|
| 619 | + $this->_add_feature_pointers(); |
|
| 620 | + $this->_add_global_feature_pointers(); |
|
| 621 | + if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 622 | + call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 623 | + } |
|
| 624 | + //enqueue scripts/styles - global, page class, and view specific |
|
| 625 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 626 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 627 | + if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 628 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 629 | + } |
|
| 630 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 631 | + //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
|
| 632 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 633 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 634 | + if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 635 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 636 | + } |
|
| 637 | + //admin footer scripts |
|
| 638 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 639 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 640 | + if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 641 | + add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 642 | + } |
|
| 643 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 644 | + //targeted hook |
|
| 645 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * _set_defaults |
|
| 652 | + * This sets some global defaults for class properties. |
|
| 653 | + */ |
|
| 654 | + private function _set_defaults() |
|
| 655 | + { |
|
| 656 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 657 | + $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array(); |
|
| 658 | + $this->default_nav_tab_name = 'overview'; |
|
| 659 | + //init template args |
|
| 660 | + $this->_template_args = array( |
|
| 661 | + 'admin_page_header' => '', |
|
| 662 | + 'admin_page_content' => '', |
|
| 663 | + 'post_body_content' => '', |
|
| 664 | + 'before_list_table' => '', |
|
| 665 | + 'after_list_table' => '', |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * route_admin_request |
|
| 673 | + * |
|
| 674 | + * @see _route_admin_request() |
|
| 675 | + * @access public |
|
| 676 | + * @return void|exception error |
|
| 677 | + */ |
|
| 678 | + public function route_admin_request() |
|
| 679 | + { |
|
| 680 | + try { |
|
| 681 | + $this->_route_admin_request(); |
|
| 682 | + } catch (EE_Error $e) { |
|
| 683 | + $e->get_error(); |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function set_wp_page_slug($wp_page_slug) |
|
| 690 | + { |
|
| 691 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 692 | + //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 693 | + if (is_network_admin()) { |
|
| 694 | + $this->_wp_page_slug .= '-network'; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * _verify_routes |
|
| 702 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so we know if we need to drop out. |
|
| 703 | + * |
|
| 704 | + * @access protected |
|
| 705 | + * @return void |
|
| 706 | + */ |
|
| 707 | + protected function _verify_routes() |
|
| 708 | + { |
|
| 709 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 710 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 711 | + return false; |
|
| 712 | + } |
|
| 713 | + $this->_route = false; |
|
| 714 | + $func = false; |
|
| 715 | + $args = array(); |
|
| 716 | + // check that the page_routes array is not empty |
|
| 717 | + if (empty($this->_page_routes)) { |
|
| 718 | + // user error msg |
|
| 719 | + $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 720 | + // developer error msg |
|
| 721 | + $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | + throw new EE_Error($error_msg); |
|
| 723 | + } |
|
| 724 | + // and that the requested page route exists |
|
| 725 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 726 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 727 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array(); |
|
| 728 | + } else { |
|
| 729 | + // user error msg |
|
| 730 | + $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 731 | + // developer error msg |
|
| 732 | + $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | + throw new EE_Error($error_msg); |
|
| 734 | + } |
|
| 735 | + // and that a default route exists |
|
| 736 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 737 | + // user error msg |
|
| 738 | + $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 739 | + // developer error msg |
|
| 740 | + $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | + throw new EE_Error($error_msg); |
|
| 742 | + } |
|
| 743 | + //first lets' catch if the UI request has EVER been set. |
|
| 744 | + if ($this->_is_UI_request === null) { |
|
| 745 | + //lets set if this is a UI request or not. |
|
| 746 | + $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false; |
|
| 747 | + //wait a minute... we might have a noheader in the route array |
|
| 748 | + $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 749 | + } |
|
| 750 | + $this->_set_current_labels(); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 757 | + * |
|
| 758 | + * @param string $route the route name we're verifying |
|
| 759 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 760 | + */ |
|
| 761 | + protected function _verify_route($route) |
|
| 762 | + { |
|
| 763 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 764 | + return true; |
|
| 765 | + } else { |
|
| 766 | + // user error msg |
|
| 767 | + $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
|
| 768 | + // developer error msg |
|
| 769 | + $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | + throw new EE_Error($error_msg); |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * perform nonce verification |
|
| 778 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!) |
|
| 779 | + * |
|
| 780 | + * @param string $nonce The nonce sent |
|
| 781 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 782 | + * @return mixed (bool|die) |
|
| 783 | + */ |
|
| 784 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 785 | + { |
|
| 786 | + // verify nonce against expected value |
|
| 787 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 788 | + // these are not the droids you are looking for !!! |
|
| 789 | + $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
|
| 790 | + if (WP_DEBUG) { |
|
| 791 | + $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | + } |
|
| 793 | + if ( ! defined('DOING_AJAX')) { |
|
| 794 | + wp_die($msg); |
|
| 795 | + } else { |
|
| 796 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 797 | + $this->_return_json(); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + /** |
|
| 805 | + * _route_admin_request() |
|
| 806 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 807 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 808 | + * in the page routes and then will try to load the corresponding method. |
|
| 809 | + * |
|
| 810 | + * @access protected |
|
| 811 | + * @return void |
|
| 812 | + * @throws \EE_Error |
|
| 813 | + */ |
|
| 814 | + protected function _route_admin_request() |
|
| 815 | + { |
|
| 816 | + if ( ! $this->_is_UI_request) { |
|
| 817 | + $this->_verify_routes(); |
|
| 818 | + } |
|
| 819 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 820 | + ? $this->_route_config['require_nonce'] |
|
| 821 | + : true; |
|
| 822 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 823 | + // set nonce from post data |
|
| 824 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 825 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 826 | + : ''; |
|
| 827 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 828 | + } |
|
| 829 | + //set the nav_tabs array but ONLY if this is UI_request |
|
| 830 | + if ($this->_is_UI_request) { |
|
| 831 | + $this->_set_nav_tabs(); |
|
| 832 | + } |
|
| 833 | + // grab callback function |
|
| 834 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 835 | + // check if callback has args |
|
| 836 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 837 | + $error_msg = ''; |
|
| 838 | + // action right before calling route |
|
| 839 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 840 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 841 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 842 | + } |
|
| 843 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 844 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 845 | + $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI'])); |
|
| 846 | + if ( ! empty($func)) { |
|
| 847 | + if (is_array($func)) { |
|
| 848 | + list($class, $method) = $func; |
|
| 849 | + } else if (strpos($func, '::') !== false) { |
|
| 850 | + list($class, $method) = explode('::', $func); |
|
| 851 | + } else { |
|
| 852 | + $class = $this; |
|
| 853 | + $method = $func; |
|
| 854 | + } |
|
| 855 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 856 | + // send along this admin page object for access by addons. |
|
| 857 | + $args['admin_page_object'] = $this; |
|
| 858 | + } |
|
| 859 | + if ( |
|
| 860 | + //is it a method on a class that doesn't work? |
|
| 861 | + ( |
|
| 862 | + method_exists($class, $method) |
|
| 863 | + && call_user_func_array(array($class, $method), $args) === false |
|
| 864 | + ) |
|
| 865 | + || ( |
|
| 866 | + //is it a standalone function that doesn't work? |
|
| 867 | + function_exists($method) |
|
| 868 | + && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false |
|
| 869 | + ) |
|
| 870 | + || ( |
|
| 871 | + //is it neither a class method NOR a standalone function? |
|
| 872 | + ! method_exists($class, $method) |
|
| 873 | + && ! function_exists($method) |
|
| 874 | + ) |
|
| 875 | + ) { |
|
| 876 | + // user error msg |
|
| 877 | + $error_msg = __('An error occurred. The requested page route could not be found.', 'event_espresso'); |
|
| 878 | + // developer error msg |
|
| 879 | + $error_msg .= '||'; |
|
| 880 | + $error_msg .= sprintf( |
|
| 881 | + __( |
|
| 882 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 883 | + 'event_espresso' |
|
| 884 | + ), |
|
| 885 | + $method |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + if ( ! empty($error_msg)) { |
|
| 889 | + throw new EE_Error($error_msg); |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | + //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route. |
|
| 893 | + //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. |
|
| 894 | + if ($this->_is_UI_request === false |
|
| 895 | + && is_array($this->_route) |
|
| 896 | + && ! empty($this->_route['headers_sent_route']) |
|
| 897 | + ) { |
|
| 898 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 906 | + * route redirects to a headers route in its route config. |
|
| 907 | + * |
|
| 908 | + * @since 4.3.0 |
|
| 909 | + * @param string $new_route New (non header) route to redirect to. |
|
| 910 | + * @return void |
|
| 911 | + */ |
|
| 912 | + protected function _reset_routing_properties($new_route) |
|
| 913 | + { |
|
| 914 | + $this->_is_UI_request = true; |
|
| 915 | + //now we set the current route to whatever the headers_sent_route is set at |
|
| 916 | + $this->_req_data['action'] = $new_route; |
|
| 917 | + //rerun page setup |
|
| 918 | + $this->_page_setup(); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * _add_query_arg |
|
| 925 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 926 | + *(internally just uses EEH_URL's function with the same name) |
|
| 927 | + * |
|
| 928 | + * @access public |
|
| 929 | + * @param array $args |
|
| 930 | + * @param string $url |
|
| 931 | + * @param bool $sticky if true, then the existing Request params will be appended to the generated |
|
| 932 | + * url in an associative array indexed by the key 'wp_referer'; |
|
| 933 | + * Example usage: |
|
| 934 | + * If the current page is: |
|
| 935 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 936 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 937 | + * &_wpnonce=5467821 |
|
| 938 | + * and you call: |
|
| 939 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 940 | + * array( |
|
| 941 | + * 'action' => 'resend_something', |
|
| 942 | + * 'page=>espresso_registrations' |
|
| 943 | + * ), |
|
| 944 | + * $some_url, |
|
| 945 | + * true |
|
| 946 | + * ); |
|
| 947 | + * It will produce a url in this structure: |
|
| 948 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 949 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 950 | + * month_range]=March%202015 |
|
| 951 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 952 | + * @return string |
|
| 953 | + */ |
|
| 954 | + public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false) |
|
| 955 | + { |
|
| 956 | + //if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 957 | + if ($sticky) { |
|
| 958 | + $request = $_REQUEST; |
|
| 959 | + unset($request['_wp_http_referer']); |
|
| 960 | + unset($request['wp_referer']); |
|
| 961 | + foreach ($request as $key => $value) { |
|
| 962 | + //do not add nonces |
|
| 963 | + if (strpos($key, 'nonce') !== false) { |
|
| 964 | + continue; |
|
| 965 | + } |
|
| 966 | + $args['wp_referer[' . $key . ']'] = $value; |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * This returns a generated link that will load the related help tab. |
|
| 976 | + * |
|
| 977 | + * @param string $help_tab_id the id for the connected help tab |
|
| 978 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 979 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 980 | + * @uses EEH_Template::get_help_tab_link() |
|
| 981 | + * @return string generated link |
|
| 982 | + */ |
|
| 983 | + protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false) |
|
| 984 | + { |
|
| 985 | + return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text); |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * _add_help_tabs |
|
| 992 | + * Note child classes define their help tabs within the page_config array. |
|
| 993 | + * |
|
| 994 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 995 | + * @access protected |
|
| 996 | + * @return void |
|
| 997 | + */ |
|
| 998 | + protected function _add_help_tabs() |
|
| 999 | + { |
|
| 1000 | + $tour_buttons = ''; |
|
| 1001 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1002 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1003 | + //is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1004 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1005 | + $tb = array(); |
|
| 1006 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1007 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1008 | + //if this is the end tour then we don't need to setup a button |
|
| 1009 | + if ($tour instanceof EE_Help_Tour_final_stop) { |
|
| 1010 | + continue; |
|
| 1011 | + } |
|
| 1012 | + $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1013 | + } |
|
| 1014 | + $tour_buttons .= implode('<br />', $tb); |
|
| 1015 | + $tour_buttons .= '</div></div>'; |
|
| 1016 | + } |
|
| 1017 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1018 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1019 | + //check that the callback given is valid |
|
| 1020 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1021 | + throw new EE_Error(sprintf(__('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', |
|
| 1022 | + 'event_espresso'), $config['help_sidebar'], get_class($this))); |
|
| 1023 | + } |
|
| 1024 | + $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1025 | + $content .= $tour_buttons; //add help tour buttons. |
|
| 1026 | + //do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1027 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1028 | + } |
|
| 1029 | + //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar. |
|
| 1030 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1031 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1032 | + } |
|
| 1033 | + //handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1034 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1035 | + $_ht['id'] = $this->page_slug; |
|
| 1036 | + $_ht['title'] = __('Help Tours', 'event_espresso'); |
|
| 1037 | + $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1038 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1039 | + }/**/ |
|
| 1040 | + if ( ! isset($config['help_tabs'])) { |
|
| 1041 | + return; |
|
| 1042 | + } //no help tabs for this route |
|
| 1043 | + foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1044 | + //we're here so there ARE help tabs! |
|
| 1045 | + //make sure we've got what we need |
|
| 1046 | + if ( ! isset($cfg['title'])) { |
|
| 1047 | + throw new EE_Error(__('The _page_config array is not set up properly for help tabs. It is missing a title', 'event_espresso')); |
|
| 1048 | + } |
|
| 1049 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1050 | + throw new EE_Error(__('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', |
|
| 1051 | + 'event_espresso')); |
|
| 1052 | + } |
|
| 1053 | + //first priority goes to content. |
|
| 1054 | + if ( ! empty($cfg['content'])) { |
|
| 1055 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1056 | + //second priority goes to filename |
|
| 1057 | + } else if ( ! empty($cfg['filename'])) { |
|
| 1058 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1059 | + //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) |
|
| 1060 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1061 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1062 | + if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
|
| 1063 | + EE_Error::add_error(sprintf(__('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', |
|
| 1064 | + 'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__); |
|
| 1065 | + return; |
|
| 1066 | + } |
|
| 1067 | + $template_args['admin_page_obj'] = $this; |
|
| 1068 | + $content = EEH_Template::display_template($file_path, $template_args, true); |
|
| 1069 | + } else { |
|
| 1070 | + $content = ''; |
|
| 1071 | + } |
|
| 1072 | + //check if callback is valid |
|
| 1073 | + if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) { |
|
| 1074 | + EE_Error::add_error(sprintf(__('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.', |
|
| 1075 | + 'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__); |
|
| 1076 | + return; |
|
| 1077 | + } |
|
| 1078 | + //setup config array for help tab method |
|
| 1079 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1080 | + $_ht = array( |
|
| 1081 | + 'id' => $id, |
|
| 1082 | + 'title' => $cfg['title'], |
|
| 1083 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1084 | + 'content' => $content, |
|
| 1085 | + ); |
|
| 1086 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is an array with properties for setting up usage of the joyride plugin |
|
| 1095 | + * |
|
| 1096 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1097 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments |
|
| 1098 | + * @access protected |
|
| 1099 | + * @return void |
|
| 1100 | + */ |
|
| 1101 | + protected function _add_help_tour() |
|
| 1102 | + { |
|
| 1103 | + $tours = array(); |
|
| 1104 | + $this->_help_tour = array(); |
|
| 1105 | + //exit early if help tours are turned off globally |
|
| 1106 | + if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) { |
|
| 1107 | + return; |
|
| 1108 | + } |
|
| 1109 | + //loop through _page_config to find any help_tour defined |
|
| 1110 | + foreach ($this->_page_config as $route => $config) { |
|
| 1111 | + //we're only going to set things up for this route |
|
| 1112 | + if ($route !== $this->_req_action) { |
|
| 1113 | + continue; |
|
| 1114 | + } |
|
| 1115 | + if (isset($config['help_tour'])) { |
|
| 1116 | + foreach ($config['help_tour'] as $tour) { |
|
| 1117 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1118 | + //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
|
| 1119 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1120 | + //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1121 | + if ( ! is_readable($file_path)) { |
|
| 1122 | + EE_Error::add_error(sprintf(__('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', 'event_espresso'), |
|
| 1123 | + $file_path, $tour), __FILE__, __FUNCTION__, __LINE__); |
|
| 1124 | + return; |
|
| 1125 | + } |
|
| 1126 | + require_once $file_path; |
|
| 1127 | + if ( ! class_exists($tour)) { |
|
| 1128 | + $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
|
| 1129 | + $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('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.', |
|
| 1130 | + 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
|
| 1131 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 1132 | + } |
|
| 1133 | + $a = new ReflectionClass($tour); |
|
| 1134 | + $tour_obj = $a->newInstance($this->_is_caf); |
|
| 1135 | + $tours[] = $tour_obj; |
|
| 1136 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1137 | + } |
|
| 1138 | + //let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1139 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1140 | + $tours[] = $end_stop_tour; |
|
| 1141 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + if ( ! empty($tours)) { |
|
| 1145 | + $this->_help_tour['tours'] = $tours; |
|
| 1146 | + } |
|
| 1147 | + //thats it! Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically. |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1154 | + * |
|
| 1155 | + * @access protected |
|
| 1156 | + * @return void |
|
| 1157 | + */ |
|
| 1158 | + protected function _add_qtips() |
|
| 1159 | + { |
|
| 1160 | + if (isset($this->_route_config['qtips'])) { |
|
| 1161 | + $qtips = (array)$this->_route_config['qtips']; |
|
| 1162 | + //load qtip loader |
|
| 1163 | + $path = array( |
|
| 1164 | + $this->_get_dir() . '/qtips/', |
|
| 1165 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1166 | + ); |
|
| 1167 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + /** |
|
| 1174 | + * _set_nav_tabs |
|
| 1175 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly. |
|
| 1176 | + * |
|
| 1177 | + * @access protected |
|
| 1178 | + * @return void |
|
| 1179 | + */ |
|
| 1180 | + protected function _set_nav_tabs() |
|
| 1181 | + { |
|
| 1182 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1183 | + $i = 0; |
|
| 1184 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1185 | + if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) { |
|
| 1186 | + continue; |
|
| 1187 | + } //no nav tab for this config |
|
| 1188 | + //check for persistent flag |
|
| 1189 | + if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) { |
|
| 1190 | + continue; |
|
| 1191 | + } //nav tab is only to appear when route requested. |
|
| 1192 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1193 | + continue; |
|
| 1194 | + } //no nav tab becasue current user does not have access. |
|
| 1195 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1196 | + $this->_nav_tabs[$slug] = array( |
|
| 1197 | + 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
|
| 1198 | + 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
|
| 1199 | + 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1200 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1201 | + ); |
|
| 1202 | + $i++; |
|
| 1203 | + } |
|
| 1204 | + //if $this->_nav_tabs is empty then lets set the default |
|
| 1205 | + if (empty($this->_nav_tabs)) { |
|
| 1206 | + $this->_nav_tabs[$this->default_nav_tab_name] = array( |
|
| 1207 | + 'url' => $this->admin_base_url, |
|
| 1208 | + 'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)), |
|
| 1209 | + 'css_class' => 'nav-tab-active', |
|
| 1210 | + 'order' => 10, |
|
| 1211 | + ); |
|
| 1212 | + } |
|
| 1213 | + //now let's sort the tabs according to order |
|
| 1214 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + |
|
| 1219 | + /** |
|
| 1220 | + * _set_current_labels |
|
| 1221 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array |
|
| 1222 | + * |
|
| 1223 | + * @access private |
|
| 1224 | + * @return void |
|
| 1225 | + */ |
|
| 1226 | + private function _set_current_labels() |
|
| 1227 | + { |
|
| 1228 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1229 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1230 | + if (is_array($text)) { |
|
| 1231 | + foreach ($text as $sublabel => $subtext) { |
|
| 1232 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1233 | + } |
|
| 1234 | + } else { |
|
| 1235 | + $this->_labels[$label] = $text; |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * verifies user access for this admin page |
|
| 1245 | + * |
|
| 1246 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1247 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just return false if verify fail. |
|
| 1248 | + * @return BOOL|wp_die() |
|
| 1249 | + */ |
|
| 1250 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1251 | + { |
|
| 1252 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1253 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1254 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1255 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1256 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1257 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability']; |
|
| 1258 | + } else { |
|
| 1259 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1260 | + } |
|
| 1261 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1262 | + if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1263 | + if ($verify_only) { |
|
| 1264 | + return false; |
|
| 1265 | + } else { |
|
| 1266 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + return true; |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + |
|
| 1274 | + /** |
|
| 1275 | + * admin_init_global |
|
| 1276 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1277 | + * This method executes for ALL EE Admin pages. |
|
| 1278 | + * |
|
| 1279 | + * @access public |
|
| 1280 | + * @return void |
|
| 1281 | + */ |
|
| 1282 | + public function admin_init_global() |
|
| 1283 | + { |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * wp_loaded_global |
|
| 1290 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an EE_Admin page and will execute on every EE Admin Page load |
|
| 1291 | + * |
|
| 1292 | + * @access public |
|
| 1293 | + * @return void |
|
| 1294 | + */ |
|
| 1295 | + public function wp_loaded() |
|
| 1296 | + { |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + |
|
| 1300 | + |
|
| 1301 | + /** |
|
| 1302 | + * admin_notices |
|
| 1303 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1304 | + * |
|
| 1305 | + * @access public |
|
| 1306 | + * @return void |
|
| 1307 | + */ |
|
| 1308 | + public function admin_notices_global() |
|
| 1309 | + { |
|
| 1310 | + $this->_display_no_javascript_warning(); |
|
| 1311 | + $this->_display_espresso_notices(); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + public function network_admin_notices_global() |
|
| 1317 | + { |
|
| 1318 | + $this->_display_no_javascript_warning(); |
|
| 1319 | + $this->_display_espresso_notices(); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + /** |
|
| 1325 | + * admin_footer_scripts_global |
|
| 1326 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages. |
|
| 1327 | + * |
|
| 1328 | + * @access public |
|
| 1329 | + * @return void |
|
| 1330 | + */ |
|
| 1331 | + public function admin_footer_scripts_global() |
|
| 1332 | + { |
|
| 1333 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1334 | + $this->_add_admin_page_overlay(); |
|
| 1335 | + //if metaboxes are present we need to add the nonce field |
|
| 1336 | + if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) { |
|
| 1337 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1338 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1339 | + } |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + /** |
|
| 1345 | + * admin_footer_global |
|
| 1346 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages. |
|
| 1347 | + * |
|
| 1348 | + * @access public |
|
| 1349 | + * @return void |
|
| 1350 | + */ |
|
| 1351 | + public function admin_footer_global() |
|
| 1352 | + { |
|
| 1353 | + //dialog container for dialog helper |
|
| 1354 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1355 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1356 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1357 | + $d_cont .= '</div>'; |
|
| 1358 | + echo $d_cont; |
|
| 1359 | + //help tour stuff? |
|
| 1360 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
| 1361 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
| 1362 | + } |
|
| 1363 | + //current set timezone for timezone js |
|
| 1364 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * This function sees if there is a method for help popup content existing for the given route. If there is then we'll use the retrieved array to output the content using the template. |
|
| 1371 | + * For child classes: |
|
| 1372 | + * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for |
|
| 1373 | + * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content for the |
|
| 1374 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1375 | + * 'help_trigger_id' => array( |
|
| 1376 | + * 'title' => __('localized title for popup', 'event_espresso'), |
|
| 1377 | + * 'content' => __('localized content for popup', 'event_espresso') |
|
| 1378 | + * ) |
|
| 1379 | + * ); |
|
| 1380 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1381 | + * |
|
| 1382 | + * @access protected |
|
| 1383 | + * @return string content |
|
| 1384 | + */ |
|
| 1385 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1386 | + { |
|
| 1387 | + $content = ''; |
|
| 1388 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1389 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1390 | + //loop through the array and setup content |
|
| 1391 | + foreach ($help_array as $trigger => $help) { |
|
| 1392 | + //make sure the array is setup properly |
|
| 1393 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
| 1394 | + throw new EE_Error(__('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', |
|
| 1395 | + 'event_espresso')); |
|
| 1396 | + } |
|
| 1397 | + //we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1398 | + $template_args = array( |
|
| 1399 | + 'help_popup_id' => $trigger, |
|
| 1400 | + 'help_popup_title' => $help['title'], |
|
| 1401 | + 'help_popup_content' => $help['content'], |
|
| 1402 | + ); |
|
| 1403 | + $content .= EEH_Template::display_template($template_path, $template_args, true); |
|
| 1404 | + } |
|
| 1405 | + if ($display) { |
|
| 1406 | + echo $content; |
|
| 1407 | + } else { |
|
| 1408 | + return $content; |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + |
|
| 1413 | + |
|
| 1414 | + /** |
|
| 1415 | + * All this does is retrive the help content array if set by the EE_Admin_Page child |
|
| 1416 | + * |
|
| 1417 | + * @access private |
|
| 1418 | + * @return array properly formatted array for help popup content |
|
| 1419 | + */ |
|
| 1420 | + private function _get_help_content() |
|
| 1421 | + { |
|
| 1422 | + //what is the method we're looking for? |
|
| 1423 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1424 | + //if method doesn't exist let's get out. |
|
| 1425 | + if ( ! method_exists($this, $method_name)) { |
|
| 1426 | + return array(); |
|
| 1427 | + } |
|
| 1428 | + //k we're good to go let's retrieve the help array |
|
| 1429 | + $help_array = call_user_func(array($this, $method_name)); |
|
| 1430 | + //make sure we've got an array! |
|
| 1431 | + if ( ! is_array($help_array)) { |
|
| 1432 | + throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso')); |
|
| 1433 | + } |
|
| 1434 | + return $help_array; |
|
| 1435 | + } |
|
| 1436 | + |
|
| 1437 | + |
|
| 1438 | + |
|
| 1439 | + /** |
|
| 1440 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1441 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1442 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1443 | + * |
|
| 1444 | + * @access protected |
|
| 1445 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1446 | + * @param boolean $display if false then we return the trigger string |
|
| 1447 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1448 | + * @return string |
|
| 1449 | + */ |
|
| 1450 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1451 | + { |
|
| 1452 | + if (defined('DOING_AJAX')) { |
|
| 1453 | + return; |
|
| 1454 | + } |
|
| 1455 | + //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 |
|
| 1456 | + $help_array = $this->_get_help_content(); |
|
| 1457 | + $help_content = ''; |
|
| 1458 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1459 | + $help_array[$trigger_id] = array( |
|
| 1460 | + 'title' => __('Missing Content', 'event_espresso'), |
|
| 1461 | + 'content' => __('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.)', |
|
| 1462 | + 'event_espresso'), |
|
| 1463 | + ); |
|
| 1464 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1465 | + } |
|
| 1466 | + //let's setup the trigger |
|
| 1467 | + $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1468 | + $content = $content . $help_content; |
|
| 1469 | + if ($display) { |
|
| 1470 | + echo $content; |
|
| 1471 | + } else { |
|
| 1472 | + return $content; |
|
| 1473 | + } |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + |
|
| 1477 | + |
|
| 1478 | + /** |
|
| 1479 | + * _add_global_screen_options |
|
| 1480 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1481 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1482 | + * |
|
| 1483 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1484 | + * see also WP_Screen object documents... |
|
| 1485 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1486 | + * @abstract |
|
| 1487 | + * @access private |
|
| 1488 | + * @return void |
|
| 1489 | + */ |
|
| 1490 | + private function _add_global_screen_options() |
|
| 1491 | + { |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + |
|
| 1495 | + |
|
| 1496 | + /** |
|
| 1497 | + * _add_global_feature_pointers |
|
| 1498 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1499 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1500 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1501 | + * |
|
| 1502 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see: |
|
| 1503 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1504 | + * @abstract |
|
| 1505 | + * @access protected |
|
| 1506 | + * @return void |
|
| 1507 | + */ |
|
| 1508 | + private function _add_global_feature_pointers() |
|
| 1509 | + { |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + |
|
| 1514 | + /** |
|
| 1515 | + * load_global_scripts_styles |
|
| 1516 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1517 | + * |
|
| 1518 | + * @return void |
|
| 1519 | + */ |
|
| 1520 | + public function load_global_scripts_styles() |
|
| 1521 | + { |
|
| 1522 | + /** STYLES **/ |
|
| 1523 | + // add debugging styles |
|
| 1524 | + if (WP_DEBUG) { |
|
| 1525 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1526 | + } |
|
| 1527 | + //register all styles |
|
| 1528 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1529 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1530 | + //helpers styles |
|
| 1531 | + wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1532 | + //enqueue global styles |
|
| 1533 | + wp_enqueue_style('ee-admin-css'); |
|
| 1534 | + /** SCRIPTS **/ |
|
| 1535 | + //register all scripts |
|
| 1536 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1537 | + wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1538 | + wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1539 | + wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1540 | + // register jQuery Validate - see /includes/functions/wp_hooks.php |
|
| 1541 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 1542 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1543 | + //script for sorting tables |
|
| 1544 | + wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | + //script for parsing uri's |
|
| 1546 | + wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | + //and parsing associative serialized form elements |
|
| 1548 | + wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1549 | + //helpers scripts |
|
| 1550 | + wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1551 | + wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | + wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1553 | + wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | + //google charts |
|
| 1555 | + wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
|
| 1556 | + //enqueue global scripts |
|
| 1557 | + //taking care of metaboxes |
|
| 1558 | + if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) { |
|
| 1559 | + wp_enqueue_script('dashboard'); |
|
| 1560 | + } |
|
| 1561 | + //enqueue thickbox for ee help popups. default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups |
|
| 1562 | + if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) { |
|
| 1563 | + wp_enqueue_script('ee_admin_js'); |
|
| 1564 | + wp_enqueue_style('ee-admin-css'); |
|
| 1565 | + } |
|
| 1566 | + //localize script for ajax lazy loading |
|
| 1567 | + $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content')); |
|
| 1568 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 1569 | + /** |
|
| 1570 | + * help tour stuff |
|
| 1571 | + */ |
|
| 1572 | + if ( ! empty($this->_help_tour)) { |
|
| 1573 | + //register the js for kicking things off |
|
| 1574 | + wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1575 | + //setup tours for the js tour object |
|
| 1576 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1577 | + $tours[] = array( |
|
| 1578 | + 'id' => $tour->get_slug(), |
|
| 1579 | + 'options' => $tour->get_options(), |
|
| 1580 | + ); |
|
| 1581 | + } |
|
| 1582 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1583 | + //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1584 | + } |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + |
|
| 1589 | + /** |
|
| 1590 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1591 | + * |
|
| 1592 | + * @access public |
|
| 1593 | + * @return void |
|
| 1594 | + */ |
|
| 1595 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 1596 | + { |
|
| 1597 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 1598 | + EE_Registry::$i18n_js_strings['confirm_delete'] = __('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!!!', 'event_espresso'); |
|
| 1599 | + EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso'); |
|
| 1600 | + EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso'); |
|
| 1601 | + EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso'); |
|
| 1602 | + EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso'); |
|
| 1603 | + EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1604 | + EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso'); |
|
| 1605 | + EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso'); |
|
| 1606 | + EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso'); |
|
| 1607 | + EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso'); |
|
| 1608 | + EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso'); |
|
| 1609 | + EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso'); |
|
| 1610 | + EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso'); |
|
| 1611 | + EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso'); |
|
| 1612 | + EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso'); |
|
| 1613 | + EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso'); |
|
| 1614 | + EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso'); |
|
| 1615 | + EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso'); |
|
| 1616 | + EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso'); |
|
| 1617 | + EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso'); |
|
| 1618 | + EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso'); |
|
| 1619 | + EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso'); |
|
| 1620 | + EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso'); |
|
| 1621 | + EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso'); |
|
| 1622 | + EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso'); |
|
| 1623 | + EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso'); |
|
| 1624 | + EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso'); |
|
| 1625 | + EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso'); |
|
| 1626 | + EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso'); |
|
| 1627 | + EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso'); |
|
| 1628 | + EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso'); |
|
| 1629 | + EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso'); |
|
| 1630 | + EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso'); |
|
| 1631 | + EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso'); |
|
| 1632 | + EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso'); |
|
| 1633 | + EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso'); |
|
| 1634 | + EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso'); |
|
| 1635 | + EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso'); |
|
| 1636 | + EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso'); |
|
| 1637 | + //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance |
|
| 1638 | + //admin page when in maintenance mode and ee_admin_js is not loaded then. This works everywhere else because |
|
| 1639 | + //espresso_core is listed as a dependency of ee_admin_js. |
|
| 1640 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + |
|
| 1645 | + /** |
|
| 1646 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 1647 | + * |
|
| 1648 | + * @access public |
|
| 1649 | + * @return void |
|
| 1650 | + */ |
|
| 1651 | + public function add_xdebug_style() |
|
| 1652 | + { |
|
| 1653 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + |
|
| 1657 | + /************************/ |
|
| 1658 | + /** LIST TABLE METHODS **/ |
|
| 1659 | + /************************/ |
|
| 1660 | + /** |
|
| 1661 | + * this sets up the list table if the current view requires it. |
|
| 1662 | + * |
|
| 1663 | + * @access protected |
|
| 1664 | + * @return void |
|
| 1665 | + */ |
|
| 1666 | + protected function _set_list_table() |
|
| 1667 | + { |
|
| 1668 | + //first is this a list_table view? |
|
| 1669 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 1670 | + return; |
|
| 1671 | + } //not a list_table view so get out. |
|
| 1672 | + //list table functions are per view specific (because some admin pages might have more than one listtable!) |
|
| 1673 | + if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1674 | + //user error msg |
|
| 1675 | + $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
|
| 1676 | + //developer error msg |
|
| 1677 | + $error_msg .= '||' . sprintf(__('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.', 'event_espresso'), |
|
| 1678 | + $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1679 | + throw new EE_Error($error_msg); |
|
| 1680 | + } |
|
| 1681 | + //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 1682 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1683 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1684 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 1685 | + $this->_set_list_table_view(); |
|
| 1686 | + $this->_set_list_table_object(); |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + |
|
| 1690 | + |
|
| 1691 | + /** |
|
| 1692 | + * set current view for List Table |
|
| 1693 | + * |
|
| 1694 | + * @access public |
|
| 1695 | + * @return array |
|
| 1696 | + */ |
|
| 1697 | + protected function _set_list_table_view() |
|
| 1698 | + { |
|
| 1699 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1700 | + // looking at active items or dumpster diving ? |
|
| 1701 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 1702 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 1703 | + } else { |
|
| 1704 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 1705 | + } |
|
| 1706 | + } |
|
| 1707 | + |
|
| 1708 | + |
|
| 1709 | + |
|
| 1710 | + /** |
|
| 1711 | + * _set_list_table_object |
|
| 1712 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 1713 | + * |
|
| 1714 | + * @throws \EE_Error |
|
| 1715 | + */ |
|
| 1716 | + protected function _set_list_table_object() |
|
| 1717 | + { |
|
| 1718 | + if (isset($this->_route_config['list_table'])) { |
|
| 1719 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 1720 | + throw new EE_Error( |
|
| 1721 | + sprintf( |
|
| 1722 | + __( |
|
| 1723 | + '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.', |
|
| 1724 | + 'event_espresso' |
|
| 1725 | + ), |
|
| 1726 | + $this->_route_config['list_table'], |
|
| 1727 | + get_class($this) |
|
| 1728 | + ) |
|
| 1729 | + ); |
|
| 1730 | + } |
|
| 1731 | + $list_table = $this->_route_config['list_table']; |
|
| 1732 | + $this->_list_table_object = new $list_table($this); |
|
| 1733 | + } |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + |
|
| 1737 | + |
|
| 1738 | + /** |
|
| 1739 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 1740 | + * |
|
| 1741 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 1742 | + * urls. The array should be indexed by the view it is being |
|
| 1743 | + * added to. |
|
| 1744 | + * @return array |
|
| 1745 | + */ |
|
| 1746 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 1747 | + { |
|
| 1748 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1749 | + if (empty($this->_views)) { |
|
| 1750 | + $this->_views = array(); |
|
| 1751 | + } |
|
| 1752 | + // cycle thru views |
|
| 1753 | + foreach ($this->_views as $key => $view) { |
|
| 1754 | + $query_args = array(); |
|
| 1755 | + // check for current view |
|
| 1756 | + $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
|
| 1757 | + $query_args['action'] = $this->_req_action; |
|
| 1758 | + $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1759 | + $query_args['status'] = $view['slug']; |
|
| 1760 | + //merge any other arguments sent in. |
|
| 1761 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 1762 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
| 1763 | + } |
|
| 1764 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1765 | + } |
|
| 1766 | + return $this->_views; |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + /** |
|
| 1772 | + * _entries_per_page_dropdown |
|
| 1773 | + * generates a drop down box for selecting the number of visiable rows in an admin page list table |
|
| 1774 | + * |
|
| 1775 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it. |
|
| 1776 | + * @access protected |
|
| 1777 | + * @param int $max_entries total number of rows in the table |
|
| 1778 | + * @return string |
|
| 1779 | + */ |
|
| 1780 | + protected function _entries_per_page_dropdown($max_entries = false) |
|
| 1781 | + { |
|
| 1782 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1783 | + $values = array(10, 25, 50, 100); |
|
| 1784 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 1785 | + if ($max_entries) { |
|
| 1786 | + $values[] = $max_entries; |
|
| 1787 | + sort($values); |
|
| 1788 | + } |
|
| 1789 | + $entries_per_page_dropdown = ' |
|
| 1790 | 1790 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 1791 | 1791 | <label class="hide-if-no-js"> |
| 1792 | 1792 | Show |
| 1793 | 1793 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 1794 | - foreach ($values as $value) { |
|
| 1795 | - if ($value < $max_entries) { |
|
| 1796 | - $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1797 | - $entries_per_page_dropdown .= ' |
|
| 1794 | + foreach ($values as $value) { |
|
| 1795 | + if ($value < $max_entries) { |
|
| 1796 | + $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1797 | + $entries_per_page_dropdown .= ' |
|
| 1798 | 1798 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 1799 | - } |
|
| 1800 | - } |
|
| 1801 | - $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1802 | - $entries_per_page_dropdown .= ' |
|
| 1799 | + } |
|
| 1800 | + } |
|
| 1801 | + $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1802 | + $entries_per_page_dropdown .= ' |
|
| 1803 | 1803 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 1804 | - $entries_per_page_dropdown .= ' |
|
| 1804 | + $entries_per_page_dropdown .= ' |
|
| 1805 | 1805 | </select> |
| 1806 | 1806 | entries |
| 1807 | 1807 | </label> |
| 1808 | 1808 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 1809 | 1809 | </div> |
| 1810 | 1810 | '; |
| 1811 | - return $entries_per_page_dropdown; |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - |
|
| 1816 | - /** |
|
| 1817 | - * _set_search_attributes |
|
| 1818 | - * |
|
| 1819 | - * @access protected |
|
| 1820 | - * @return void |
|
| 1821 | - */ |
|
| 1822 | - public function _set_search_attributes() |
|
| 1823 | - { |
|
| 1824 | - $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
|
| 1825 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - /*** END LIST TABLE METHODS **/ |
|
| 1829 | - /*****************************/ |
|
| 1830 | - /** |
|
| 1831 | - * _add_registered_metaboxes |
|
| 1832 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 1833 | - * |
|
| 1834 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 1835 | - * @access private |
|
| 1836 | - * @return void |
|
| 1837 | - */ |
|
| 1838 | - private function _add_registered_meta_boxes() |
|
| 1839 | - { |
|
| 1840 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1841 | - //we only add meta boxes if the page_route calls for it |
|
| 1842 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 1843 | - && is_array( |
|
| 1844 | - $this->_route_config['metaboxes'] |
|
| 1845 | - ) |
|
| 1846 | - ) { |
|
| 1847 | - // this simply loops through the callbacks provided |
|
| 1848 | - // and checks if there is a corresponding callback registered by the child |
|
| 1849 | - // if there is then we go ahead and process the metabox loader. |
|
| 1850 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 1851 | - // first check for Closures |
|
| 1852 | - if ($metabox_callback instanceof Closure) { |
|
| 1853 | - $result = $metabox_callback(); |
|
| 1854 | - } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 1855 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 1856 | - } else { |
|
| 1857 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
| 1858 | - } |
|
| 1859 | - if ($result === false) { |
|
| 1860 | - // user error msg |
|
| 1861 | - $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
|
| 1862 | - // developer error msg |
|
| 1863 | - $error_msg .= '||' . sprintf( |
|
| 1864 | - __( |
|
| 1865 | - '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.', |
|
| 1866 | - 'event_espresso' |
|
| 1867 | - ), |
|
| 1868 | - $metabox_callback |
|
| 1869 | - ); |
|
| 1870 | - throw new EE_Error($error_msg); |
|
| 1871 | - } |
|
| 1872 | - } |
|
| 1873 | - } |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * _add_screen_columns |
|
| 1880 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page. |
|
| 1881 | - * |
|
| 1882 | - * @access private |
|
| 1883 | - * @return void |
|
| 1884 | - */ |
|
| 1885 | - private function _add_screen_columns() |
|
| 1886 | - { |
|
| 1887 | - if ( |
|
| 1888 | - is_array($this->_route_config) |
|
| 1889 | - && isset($this->_route_config['columns']) |
|
| 1890 | - && is_array($this->_route_config['columns']) |
|
| 1891 | - && count($this->_route_config['columns']) === 2 |
|
| 1892 | - ) { |
|
| 1893 | - add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1894 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 1895 | - $screen_id = $this->_current_screen->id; |
|
| 1896 | - $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1897 | - $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
|
| 1898 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1899 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 1900 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 1901 | - $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1902 | - //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 1903 | - $this->_route_config['has_metaboxes'] = true; |
|
| 1904 | - } |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - |
|
| 1908 | - |
|
| 1909 | - /**********************************/ |
|
| 1910 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 1911 | - /** |
|
| 1912 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply referencing the callback in the _page_config array property. This way you can be very specific about what pages these get |
|
| 1913 | - * loaded on. |
|
| 1914 | - */ |
|
| 1915 | - private function _espresso_news_post_box() |
|
| 1916 | - { |
|
| 1917 | - $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso')); |
|
| 1918 | - add_meta_box('espresso_news_post_box', $news_box_title, array( |
|
| 1919 | - $this, |
|
| 1920 | - 'espresso_news_post_box', |
|
| 1921 | - ), $this->_wp_page_slug, 'side'); |
|
| 1922 | - } |
|
| 1923 | - |
|
| 1924 | - |
|
| 1925 | - |
|
| 1926 | - /** |
|
| 1927 | - * Code for setting up espresso ratings request metabox. |
|
| 1928 | - */ |
|
| 1929 | - protected function _espresso_ratings_request() |
|
| 1930 | - { |
|
| 1931 | - if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 1932 | - return ''; |
|
| 1933 | - } |
|
| 1934 | - $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso')); |
|
| 1935 | - add_meta_box('espresso_ratings_request', $ratings_box_title, array( |
|
| 1936 | - $this, |
|
| 1937 | - 'espresso_ratings_request', |
|
| 1938 | - ), $this->_wp_page_slug, 'side'); |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - |
|
| 1943 | - /** |
|
| 1944 | - * Code for setting up espresso ratings request metabox content. |
|
| 1945 | - */ |
|
| 1946 | - public function espresso_ratings_request() |
|
| 1947 | - { |
|
| 1948 | - $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1949 | - EEH_Template::display_template($template_path, array()); |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - |
|
| 1953 | - |
|
| 1954 | - public static function cached_rss_display($rss_id, $url) |
|
| 1955 | - { |
|
| 1956 | - $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1957 | - $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
| 1958 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1959 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1960 | - $post = '</div>' . "\n"; |
|
| 1961 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1962 | - if (false != ($output = get_transient($cache_key))) { |
|
| 1963 | - echo $pre . $output . $post; |
|
| 1964 | - return true; |
|
| 1965 | - } |
|
| 1966 | - if ( ! $doing_ajax) { |
|
| 1967 | - echo $pre . $loading . $post; |
|
| 1968 | - return false; |
|
| 1969 | - } |
|
| 1970 | - ob_start(); |
|
| 1971 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 1972 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 1973 | - return true; |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - |
|
| 1977 | - |
|
| 1978 | - public function espresso_news_post_box() |
|
| 1979 | - { |
|
| 1980 | - ?> |
|
| 1811 | + return $entries_per_page_dropdown; |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + |
|
| 1816 | + /** |
|
| 1817 | + * _set_search_attributes |
|
| 1818 | + * |
|
| 1819 | + * @access protected |
|
| 1820 | + * @return void |
|
| 1821 | + */ |
|
| 1822 | + public function _set_search_attributes() |
|
| 1823 | + { |
|
| 1824 | + $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
|
| 1825 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + /*** END LIST TABLE METHODS **/ |
|
| 1829 | + /*****************************/ |
|
| 1830 | + /** |
|
| 1831 | + * _add_registered_metaboxes |
|
| 1832 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 1833 | + * |
|
| 1834 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 1835 | + * @access private |
|
| 1836 | + * @return void |
|
| 1837 | + */ |
|
| 1838 | + private function _add_registered_meta_boxes() |
|
| 1839 | + { |
|
| 1840 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1841 | + //we only add meta boxes if the page_route calls for it |
|
| 1842 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 1843 | + && is_array( |
|
| 1844 | + $this->_route_config['metaboxes'] |
|
| 1845 | + ) |
|
| 1846 | + ) { |
|
| 1847 | + // this simply loops through the callbacks provided |
|
| 1848 | + // and checks if there is a corresponding callback registered by the child |
|
| 1849 | + // if there is then we go ahead and process the metabox loader. |
|
| 1850 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 1851 | + // first check for Closures |
|
| 1852 | + if ($metabox_callback instanceof Closure) { |
|
| 1853 | + $result = $metabox_callback(); |
|
| 1854 | + } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 1855 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 1856 | + } else { |
|
| 1857 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
| 1858 | + } |
|
| 1859 | + if ($result === false) { |
|
| 1860 | + // user error msg |
|
| 1861 | + $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
|
| 1862 | + // developer error msg |
|
| 1863 | + $error_msg .= '||' . sprintf( |
|
| 1864 | + __( |
|
| 1865 | + '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.', |
|
| 1866 | + 'event_espresso' |
|
| 1867 | + ), |
|
| 1868 | + $metabox_callback |
|
| 1869 | + ); |
|
| 1870 | + throw new EE_Error($error_msg); |
|
| 1871 | + } |
|
| 1872 | + } |
|
| 1873 | + } |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * _add_screen_columns |
|
| 1880 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page. |
|
| 1881 | + * |
|
| 1882 | + * @access private |
|
| 1883 | + * @return void |
|
| 1884 | + */ |
|
| 1885 | + private function _add_screen_columns() |
|
| 1886 | + { |
|
| 1887 | + if ( |
|
| 1888 | + is_array($this->_route_config) |
|
| 1889 | + && isset($this->_route_config['columns']) |
|
| 1890 | + && is_array($this->_route_config['columns']) |
|
| 1891 | + && count($this->_route_config['columns']) === 2 |
|
| 1892 | + ) { |
|
| 1893 | + add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1894 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 1895 | + $screen_id = $this->_current_screen->id; |
|
| 1896 | + $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1897 | + $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
|
| 1898 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1899 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 1900 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 1901 | + $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1902 | + //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 1903 | + $this->_route_config['has_metaboxes'] = true; |
|
| 1904 | + } |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + |
|
| 1908 | + |
|
| 1909 | + /**********************************/ |
|
| 1910 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 1911 | + /** |
|
| 1912 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply referencing the callback in the _page_config array property. This way you can be very specific about what pages these get |
|
| 1913 | + * loaded on. |
|
| 1914 | + */ |
|
| 1915 | + private function _espresso_news_post_box() |
|
| 1916 | + { |
|
| 1917 | + $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso')); |
|
| 1918 | + add_meta_box('espresso_news_post_box', $news_box_title, array( |
|
| 1919 | + $this, |
|
| 1920 | + 'espresso_news_post_box', |
|
| 1921 | + ), $this->_wp_page_slug, 'side'); |
|
| 1922 | + } |
|
| 1923 | + |
|
| 1924 | + |
|
| 1925 | + |
|
| 1926 | + /** |
|
| 1927 | + * Code for setting up espresso ratings request metabox. |
|
| 1928 | + */ |
|
| 1929 | + protected function _espresso_ratings_request() |
|
| 1930 | + { |
|
| 1931 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 1932 | + return ''; |
|
| 1933 | + } |
|
| 1934 | + $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso')); |
|
| 1935 | + add_meta_box('espresso_ratings_request', $ratings_box_title, array( |
|
| 1936 | + $this, |
|
| 1937 | + 'espresso_ratings_request', |
|
| 1938 | + ), $this->_wp_page_slug, 'side'); |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + |
|
| 1943 | + /** |
|
| 1944 | + * Code for setting up espresso ratings request metabox content. |
|
| 1945 | + */ |
|
| 1946 | + public function espresso_ratings_request() |
|
| 1947 | + { |
|
| 1948 | + $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1949 | + EEH_Template::display_template($template_path, array()); |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + |
|
| 1953 | + |
|
| 1954 | + public static function cached_rss_display($rss_id, $url) |
|
| 1955 | + { |
|
| 1956 | + $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1957 | + $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
|
| 1958 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1959 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1960 | + $post = '</div>' . "\n"; |
|
| 1961 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1962 | + if (false != ($output = get_transient($cache_key))) { |
|
| 1963 | + echo $pre . $output . $post; |
|
| 1964 | + return true; |
|
| 1965 | + } |
|
| 1966 | + if ( ! $doing_ajax) { |
|
| 1967 | + echo $pre . $loading . $post; |
|
| 1968 | + return false; |
|
| 1969 | + } |
|
| 1970 | + ob_start(); |
|
| 1971 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 1972 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 1973 | + return true; |
|
| 1974 | + } |
|
| 1975 | + |
|
| 1976 | + |
|
| 1977 | + |
|
| 1978 | + public function espresso_news_post_box() |
|
| 1979 | + { |
|
| 1980 | + ?> |
|
| 1981 | 1981 | <div class="padding"> |
| 1982 | 1982 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 1983 | 1983 | <?php |
| 1984 | - // Get RSS Feed(s) |
|
| 1985 | - $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/'); |
|
| 1986 | - $url = urlencode($feed_url); |
|
| 1987 | - self::cached_rss_display('espresso_news_post_box_content', $url); |
|
| 1988 | - ?> |
|
| 1984 | + // Get RSS Feed(s) |
|
| 1985 | + $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/'); |
|
| 1986 | + $url = urlencode($feed_url); |
|
| 1987 | + self::cached_rss_display('espresso_news_post_box_content', $url); |
|
| 1988 | + ?> |
|
| 1989 | 1989 | </div> |
| 1990 | 1990 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 1991 | 1991 | </div> |
| 1992 | 1992 | <?php |
| 1993 | - } |
|
| 1994 | - |
|
| 1995 | - |
|
| 1996 | - |
|
| 1997 | - private function _espresso_links_post_box() |
|
| 1998 | - { |
|
| 1999 | - //Hiding until we actually have content to put in here... |
|
| 2000 | - //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2001 | - } |
|
| 2002 | - |
|
| 2003 | - |
|
| 2004 | - |
|
| 2005 | - public function espresso_links_post_box() |
|
| 2006 | - { |
|
| 2007 | - //Hiding until we actually have content to put in here... |
|
| 2008 | - //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'; |
|
| 2009 | - //EEH_Template::display_template( $templatepath ); |
|
| 2010 | - } |
|
| 2011 | - |
|
| 2012 | - |
|
| 2013 | - |
|
| 2014 | - protected function _espresso_sponsors_post_box() |
|
| 2015 | - { |
|
| 2016 | - $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true); |
|
| 2017 | - if ($show_sponsors) { |
|
| 2018 | - add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2019 | - } |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - |
|
| 2023 | - |
|
| 2024 | - public function espresso_sponsors_post_box() |
|
| 2025 | - { |
|
| 2026 | - $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2027 | - EEH_Template::display_template($templatepath); |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - |
|
| 2031 | - |
|
| 2032 | - private function _publish_post_box() |
|
| 2033 | - { |
|
| 2034 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2035 | - //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2036 | - if ( ! empty($this->_labels['publishbox'])) { |
|
| 2037 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 2038 | - } else { |
|
| 2039 | - $box_label = __('Publish', 'event_espresso'); |
|
| 2040 | - } |
|
| 2041 | - $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this); |
|
| 2042 | - add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high'); |
|
| 2043 | - } |
|
| 2044 | - |
|
| 2045 | - |
|
| 2046 | - |
|
| 2047 | - public function editor_overview() |
|
| 2048 | - { |
|
| 2049 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2050 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2051 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2052 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2053 | - } |
|
| 2054 | - |
|
| 2055 | - |
|
| 2056 | - /** end of globally available metaboxes section **/ |
|
| 2057 | - /*************************************************/ |
|
| 2058 | - /** |
|
| 2059 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2060 | - * protected method. |
|
| 2061 | - * |
|
| 2062 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2063 | - * @since 4.6.0 |
|
| 2064 | - */ |
|
| 2065 | - public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true) |
|
| 2066 | - { |
|
| 2067 | - $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2068 | - } |
|
| 2069 | - |
|
| 2070 | - |
|
| 2071 | - |
|
| 2072 | - /** |
|
| 2073 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2074 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2075 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2076 | - * values for the name and id arguments. |
|
| 2077 | - * |
|
| 2078 | - * @todo Add in validation for name/id arguments. |
|
| 2079 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2080 | - * @param int $id id attached to the item published |
|
| 2081 | - * @param string $delete page route callback for the delete action |
|
| 2082 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2083 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button |
|
| 2084 | - * @throws \EE_Error |
|
| 2085 | - */ |
|
| 2086 | - protected function _set_publish_post_box_vars( |
|
| 2087 | - $name = '', |
|
| 2088 | - $id = 0, |
|
| 2089 | - $delete = '', |
|
| 2090 | - $save_close_redirect_URL = '', |
|
| 2091 | - $both_btns = true |
|
| 2092 | - ) { |
|
| 2093 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2094 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url; |
|
| 2095 | - // create the Save & Close and Save buttons |
|
| 2096 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2097 | - //if we have extra content set let's add it in if not make sure its empty |
|
| 2098 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2099 | - if ($delete && ! empty($id)) { |
|
| 2100 | - //make sure we have a default if just true is sent. |
|
| 2101 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2102 | - $delete_link_args = array($name => $id); |
|
| 2103 | - $delete = $this->get_action_link_or_button( |
|
| 2104 | - $delete, |
|
| 2105 | - $delete, |
|
| 2106 | - $delete_link_args, |
|
| 2107 | - 'submitdelete deletion', |
|
| 2108 | - '', |
|
| 2109 | - false |
|
| 2110 | - ); |
|
| 2111 | - } |
|
| 2112 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2113 | - if ( ! empty($name) && ! empty($id)) { |
|
| 2114 | - $hidden_field_arr[$name] = array( |
|
| 2115 | - 'type' => 'hidden', |
|
| 2116 | - 'value' => $id, |
|
| 2117 | - ); |
|
| 2118 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2119 | - } else { |
|
| 2120 | - $hf = ''; |
|
| 2121 | - } |
|
| 2122 | - // add hidden field |
|
| 2123 | - $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf; |
|
| 2124 | - } |
|
| 2125 | - |
|
| 2126 | - |
|
| 2127 | - |
|
| 2128 | - /** |
|
| 2129 | - * displays an error message to ppl who have javascript disabled |
|
| 2130 | - * |
|
| 2131 | - * @access private |
|
| 2132 | - * @return string |
|
| 2133 | - */ |
|
| 2134 | - private function _display_no_javascript_warning() |
|
| 2135 | - { |
|
| 2136 | - ?> |
|
| 1993 | + } |
|
| 1994 | + |
|
| 1995 | + |
|
| 1996 | + |
|
| 1997 | + private function _espresso_links_post_box() |
|
| 1998 | + { |
|
| 1999 | + //Hiding until we actually have content to put in here... |
|
| 2000 | + //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2001 | + } |
|
| 2002 | + |
|
| 2003 | + |
|
| 2004 | + |
|
| 2005 | + public function espresso_links_post_box() |
|
| 2006 | + { |
|
| 2007 | + //Hiding until we actually have content to put in here... |
|
| 2008 | + //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'; |
|
| 2009 | + //EEH_Template::display_template( $templatepath ); |
|
| 2010 | + } |
|
| 2011 | + |
|
| 2012 | + |
|
| 2013 | + |
|
| 2014 | + protected function _espresso_sponsors_post_box() |
|
| 2015 | + { |
|
| 2016 | + $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true); |
|
| 2017 | + if ($show_sponsors) { |
|
| 2018 | + add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2019 | + } |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + |
|
| 2023 | + |
|
| 2024 | + public function espresso_sponsors_post_box() |
|
| 2025 | + { |
|
| 2026 | + $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2027 | + EEH_Template::display_template($templatepath); |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + |
|
| 2031 | + |
|
| 2032 | + private function _publish_post_box() |
|
| 2033 | + { |
|
| 2034 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2035 | + //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2036 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2037 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 2038 | + } else { |
|
| 2039 | + $box_label = __('Publish', 'event_espresso'); |
|
| 2040 | + } |
|
| 2041 | + $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this); |
|
| 2042 | + add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high'); |
|
| 2043 | + } |
|
| 2044 | + |
|
| 2045 | + |
|
| 2046 | + |
|
| 2047 | + public function editor_overview() |
|
| 2048 | + { |
|
| 2049 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2050 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2051 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2052 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2053 | + } |
|
| 2054 | + |
|
| 2055 | + |
|
| 2056 | + /** end of globally available metaboxes section **/ |
|
| 2057 | + /*************************************************/ |
|
| 2058 | + /** |
|
| 2059 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2060 | + * protected method. |
|
| 2061 | + * |
|
| 2062 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2063 | + * @since 4.6.0 |
|
| 2064 | + */ |
|
| 2065 | + public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true) |
|
| 2066 | + { |
|
| 2067 | + $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns); |
|
| 2068 | + } |
|
| 2069 | + |
|
| 2070 | + |
|
| 2071 | + |
|
| 2072 | + /** |
|
| 2073 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2074 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2075 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2076 | + * values for the name and id arguments. |
|
| 2077 | + * |
|
| 2078 | + * @todo Add in validation for name/id arguments. |
|
| 2079 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2080 | + * @param int $id id attached to the item published |
|
| 2081 | + * @param string $delete page route callback for the delete action |
|
| 2082 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2083 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button |
|
| 2084 | + * @throws \EE_Error |
|
| 2085 | + */ |
|
| 2086 | + protected function _set_publish_post_box_vars( |
|
| 2087 | + $name = '', |
|
| 2088 | + $id = 0, |
|
| 2089 | + $delete = '', |
|
| 2090 | + $save_close_redirect_URL = '', |
|
| 2091 | + $both_btns = true |
|
| 2092 | + ) { |
|
| 2093 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2094 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url; |
|
| 2095 | + // create the Save & Close and Save buttons |
|
| 2096 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2097 | + //if we have extra content set let's add it in if not make sure its empty |
|
| 2098 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
|
| 2099 | + if ($delete && ! empty($id)) { |
|
| 2100 | + //make sure we have a default if just true is sent. |
|
| 2101 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2102 | + $delete_link_args = array($name => $id); |
|
| 2103 | + $delete = $this->get_action_link_or_button( |
|
| 2104 | + $delete, |
|
| 2105 | + $delete, |
|
| 2106 | + $delete_link_args, |
|
| 2107 | + 'submitdelete deletion', |
|
| 2108 | + '', |
|
| 2109 | + false |
|
| 2110 | + ); |
|
| 2111 | + } |
|
| 2112 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2113 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2114 | + $hidden_field_arr[$name] = array( |
|
| 2115 | + 'type' => 'hidden', |
|
| 2116 | + 'value' => $id, |
|
| 2117 | + ); |
|
| 2118 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2119 | + } else { |
|
| 2120 | + $hf = ''; |
|
| 2121 | + } |
|
| 2122 | + // add hidden field |
|
| 2123 | + $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf; |
|
| 2124 | + } |
|
| 2125 | + |
|
| 2126 | + |
|
| 2127 | + |
|
| 2128 | + /** |
|
| 2129 | + * displays an error message to ppl who have javascript disabled |
|
| 2130 | + * |
|
| 2131 | + * @access private |
|
| 2132 | + * @return string |
|
| 2133 | + */ |
|
| 2134 | + private function _display_no_javascript_warning() |
|
| 2135 | + { |
|
| 2136 | + ?> |
|
| 2137 | 2137 | <noscript> |
| 2138 | 2138 | <div id="no-js-message" class="error"> |
| 2139 | 2139 | <p style="font-size:1.3em;"> |
@@ -2143,1251 +2143,1251 @@ discard block |
||
| 2143 | 2143 | </div> |
| 2144 | 2144 | </noscript> |
| 2145 | 2145 | <?php |
| 2146 | - } |
|
| 2146 | + } |
|
| 2147 | 2147 | |
| 2148 | 2148 | |
| 2149 | 2149 | |
| 2150 | - /** |
|
| 2151 | - * displays espresso success and/or error notices |
|
| 2152 | - * |
|
| 2153 | - * @access private |
|
| 2154 | - * @return string |
|
| 2155 | - */ |
|
| 2156 | - private function _display_espresso_notices() |
|
| 2157 | - { |
|
| 2158 | - $notices = $this->_get_transient(true); |
|
| 2159 | - echo stripslashes($notices); |
|
| 2160 | - } |
|
| 2150 | + /** |
|
| 2151 | + * displays espresso success and/or error notices |
|
| 2152 | + * |
|
| 2153 | + * @access private |
|
| 2154 | + * @return string |
|
| 2155 | + */ |
|
| 2156 | + private function _display_espresso_notices() |
|
| 2157 | + { |
|
| 2158 | + $notices = $this->_get_transient(true); |
|
| 2159 | + echo stripslashes($notices); |
|
| 2160 | + } |
|
| 2161 | 2161 | |
| 2162 | 2162 | |
| 2163 | 2163 | |
| 2164 | - /** |
|
| 2165 | - * spinny things pacify the masses |
|
| 2166 | - * |
|
| 2167 | - * @access private |
|
| 2168 | - * @return string |
|
| 2169 | - */ |
|
| 2170 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2171 | - { |
|
| 2172 | - ?> |
|
| 2164 | + /** |
|
| 2165 | + * spinny things pacify the masses |
|
| 2166 | + * |
|
| 2167 | + * @access private |
|
| 2168 | + * @return string |
|
| 2169 | + */ |
|
| 2170 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2171 | + { |
|
| 2172 | + ?> |
|
| 2173 | 2173 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2174 | 2174 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php _e('loading...', 'event_espresso'); ?></span> |
| 2175 | 2175 | </div> |
| 2176 | 2176 | <?php |
| 2177 | - } |
|
| 2177 | + } |
|
| 2178 | 2178 | |
| 2179 | 2179 | |
| 2180 | 2180 | |
| 2181 | - /** |
|
| 2182 | - * add admin page overlay for modal boxes |
|
| 2183 | - * |
|
| 2184 | - * @access private |
|
| 2185 | - * @return string |
|
| 2186 | - */ |
|
| 2187 | - protected function _add_admin_page_overlay() |
|
| 2188 | - { |
|
| 2189 | - ?> |
|
| 2181 | + /** |
|
| 2182 | + * add admin page overlay for modal boxes |
|
| 2183 | + * |
|
| 2184 | + * @access private |
|
| 2185 | + * @return string |
|
| 2186 | + */ |
|
| 2187 | + protected function _add_admin_page_overlay() |
|
| 2188 | + { |
|
| 2189 | + ?> |
|
| 2190 | 2190 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2191 | 2191 | <?php |
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * facade for add_meta_box |
|
| 2198 | - * |
|
| 2199 | - * @param string $action where the metabox get's displayed |
|
| 2200 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2201 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here. |
|
| 2202 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2203 | - * @param string $column what metabox column |
|
| 2204 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2205 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box. |
|
| 2206 | - */ |
|
| 2207 | - public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true) |
|
| 2208 | - { |
|
| 2209 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2210 | - //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. |
|
| 2211 | - if (empty($callback_args) && $create_func) { |
|
| 2212 | - $callback_args = array( |
|
| 2213 | - 'template_path' => $this->_template_path, |
|
| 2214 | - 'template_args' => $this->_template_args, |
|
| 2215 | - ); |
|
| 2216 | - } |
|
| 2217 | - //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) |
|
| 2218 | - $call_back_func = $create_func ? create_function('$post, $metabox', |
|
| 2219 | - 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
|
| 2220 | - add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2221 | - } |
|
| 2222 | - |
|
| 2223 | - |
|
| 2224 | - |
|
| 2225 | - /** |
|
| 2226 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2227 | - * |
|
| 2228 | - * @return [type] [description] |
|
| 2229 | - */ |
|
| 2230 | - public function display_admin_page_with_metabox_columns() |
|
| 2231 | - { |
|
| 2232 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2233 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true); |
|
| 2234 | - //the final wrapper |
|
| 2235 | - $this->admin_page_wrapper(); |
|
| 2236 | - } |
|
| 2237 | - |
|
| 2238 | - |
|
| 2239 | - |
|
| 2240 | - /** |
|
| 2241 | - * generates HTML wrapper for an admin details page |
|
| 2242 | - * |
|
| 2243 | - * @access public |
|
| 2244 | - * @return void |
|
| 2245 | - */ |
|
| 2246 | - public function display_admin_page_with_sidebar() |
|
| 2247 | - { |
|
| 2248 | - $this->_display_admin_page(true); |
|
| 2249 | - } |
|
| 2250 | - |
|
| 2251 | - |
|
| 2252 | - |
|
| 2253 | - /** |
|
| 2254 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2255 | - * |
|
| 2256 | - * @access public |
|
| 2257 | - * @return void |
|
| 2258 | - */ |
|
| 2259 | - public function display_admin_page_with_no_sidebar() |
|
| 2260 | - { |
|
| 2261 | - $this->_display_admin_page(); |
|
| 2262 | - } |
|
| 2263 | - |
|
| 2264 | - |
|
| 2265 | - |
|
| 2266 | - /** |
|
| 2267 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2268 | - * |
|
| 2269 | - * @access public |
|
| 2270 | - * @return void |
|
| 2271 | - */ |
|
| 2272 | - public function display_about_admin_page() |
|
| 2273 | - { |
|
| 2274 | - $this->_display_admin_page(false, true); |
|
| 2275 | - } |
|
| 2276 | - |
|
| 2277 | - |
|
| 2278 | - |
|
| 2279 | - /** |
|
| 2280 | - * display_admin_page |
|
| 2281 | - * contains the code for actually displaying an admin page |
|
| 2282 | - * |
|
| 2283 | - * @access private |
|
| 2284 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2285 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2286 | - * @return void |
|
| 2287 | - */ |
|
| 2288 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2289 | - { |
|
| 2290 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2291 | - //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2292 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2293 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2294 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2295 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2296 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2297 | - ? 'poststuff' |
|
| 2298 | - : 'espresso-default-admin'; |
|
| 2299 | - $template_path = $sidebar |
|
| 2300 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2301 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2302 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2303 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2304 | - } |
|
| 2305 | - $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2306 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
|
| 2307 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''; |
|
| 2308 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''; |
|
| 2309 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2310 | - // the final template wrapper |
|
| 2311 | - $this->admin_page_wrapper($about); |
|
| 2312 | - } |
|
| 2313 | - |
|
| 2314 | - |
|
| 2315 | - |
|
| 2316 | - /** |
|
| 2317 | - * This is used to display caf preview pages. |
|
| 2318 | - * |
|
| 2319 | - * @since 4.3.2 |
|
| 2320 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2321 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2322 | - * @return void |
|
| 2323 | - * @throws \EE_Error |
|
| 2324 | - */ |
|
| 2325 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2326 | - { |
|
| 2327 | - //let's generate a default preview action button if there isn't one already present. |
|
| 2328 | - $this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso'); |
|
| 2329 | - $buy_now_url = add_query_arg( |
|
| 2330 | - array( |
|
| 2331 | - 'ee_ver' => 'ee4', |
|
| 2332 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2333 | - 'utm_medium' => 'link', |
|
| 2334 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2335 | - 'utm_content' => 'buy_now_button', |
|
| 2336 | - ), |
|
| 2337 | - 'http://eventespresso.com/pricing/' |
|
| 2338 | - ); |
|
| 2339 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2340 | - ? $this->get_action_link_or_button( |
|
| 2341 | - '', |
|
| 2342 | - 'buy_now', |
|
| 2343 | - array(), |
|
| 2344 | - 'button-primary button-large', |
|
| 2345 | - $buy_now_url, |
|
| 2346 | - true |
|
| 2347 | - ) |
|
| 2348 | - : $this->_template_args['preview_action_button']; |
|
| 2349 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2350 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2351 | - $template_path, |
|
| 2352 | - $this->_template_args, |
|
| 2353 | - true |
|
| 2354 | - ); |
|
| 2355 | - $this->_display_admin_page($display_sidebar); |
|
| 2356 | - } |
|
| 2357 | - |
|
| 2358 | - |
|
| 2359 | - |
|
| 2360 | - /** |
|
| 2361 | - * display_admin_list_table_page_with_sidebar |
|
| 2362 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2363 | - * |
|
| 2364 | - * @access public |
|
| 2365 | - * @return void |
|
| 2366 | - */ |
|
| 2367 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2368 | - { |
|
| 2369 | - $this->_display_admin_list_table_page(true); |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - |
|
| 2373 | - |
|
| 2374 | - /** |
|
| 2375 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2376 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2377 | - * |
|
| 2378 | - * @access public |
|
| 2379 | - * @return void |
|
| 2380 | - */ |
|
| 2381 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2382 | - { |
|
| 2383 | - $this->_display_admin_list_table_page(); |
|
| 2384 | - } |
|
| 2385 | - |
|
| 2386 | - |
|
| 2387 | - |
|
| 2388 | - /** |
|
| 2389 | - * generates html wrapper for an admin_list_table page |
|
| 2390 | - * |
|
| 2391 | - * @access private |
|
| 2392 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2393 | - * @return void |
|
| 2394 | - */ |
|
| 2395 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2396 | - { |
|
| 2397 | - //setup search attributes |
|
| 2398 | - $this->_set_search_attributes(); |
|
| 2399 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2400 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2401 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2402 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2403 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2404 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2405 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2406 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2407 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2408 | - if ( ! empty($ajax_sorting_callback)) { |
|
| 2409 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2410 | - $ajax_sorting_callback . '_nonce', |
|
| 2411 | - $ajax_sorting_callback . '_nonce', |
|
| 2412 | - false, |
|
| 2413 | - false |
|
| 2414 | - ); |
|
| 2415 | - // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 2416 | - // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 2417 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2418 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2419 | - } else { |
|
| 2420 | - $sortable_list_table_form_fields = ''; |
|
| 2421 | - } |
|
| 2422 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2423 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
|
| 2424 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2425 | - $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2426 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2427 | - //display message about search results? |
|
| 2428 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2429 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2430 | - __('Displaying search results for the search string: <strong><em>%s</em></strong>', |
|
| 2431 | - 'event_espresso'), |
|
| 2432 | - trim($this->_req_data['s'], '%') |
|
| 2433 | - ) . '</p>' |
|
| 2434 | - : ''; |
|
| 2435 | - // filter before_list_table template arg |
|
| 2436 | - $this->_template_args['before_list_table'] = implode( |
|
| 2437 | - " \n", |
|
| 2438 | - (array)apply_filters( |
|
| 2439 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2440 | - (array)$this->_template_args['before_list_table'], |
|
| 2441 | - $this->page_slug, |
|
| 2442 | - $this->_req_data, |
|
| 2443 | - $this->_req_action |
|
| 2444 | - ) |
|
| 2445 | - ); |
|
| 2446 | - // filter after_list_table template arg |
|
| 2447 | - $this->_template_args['after_list_table'] = implode( |
|
| 2448 | - " \n", |
|
| 2449 | - (array)apply_filters( |
|
| 2450 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2451 | - (array)$this->_template_args['after_list_table'], |
|
| 2452 | - $this->page_slug, |
|
| 2453 | - $this->_req_data, |
|
| 2454 | - $this->_req_action |
|
| 2455 | - ) |
|
| 2456 | - ); |
|
| 2457 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2458 | - $template_path, |
|
| 2459 | - $this->_template_args, |
|
| 2460 | - true |
|
| 2461 | - ); |
|
| 2462 | - // the final template wrapper |
|
| 2463 | - if ($sidebar) { |
|
| 2464 | - $this->display_admin_page_with_sidebar(); |
|
| 2465 | - } else { |
|
| 2466 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2467 | - } |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - |
|
| 2471 | - |
|
| 2472 | - /** |
|
| 2473 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend. |
|
| 2474 | - * $items are expected in an array in the following format: |
|
| 2475 | - * $legend_items = array( |
|
| 2476 | - * 'item_id' => array( |
|
| 2477 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2478 | - * 'desc' => __('localized description of item'); |
|
| 2479 | - * ) |
|
| 2480 | - * ); |
|
| 2481 | - * |
|
| 2482 | - * @param array $items see above for format of array |
|
| 2483 | - * @return string html string of legend |
|
| 2484 | - */ |
|
| 2485 | - protected function _display_legend($items) |
|
| 2486 | - { |
|
| 2487 | - $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2488 | - $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2489 | - return EEH_Template::display_template($legend_template, $this->_template_args, true); |
|
| 2490 | - } |
|
| 2491 | - |
|
| 2492 | - |
|
| 2493 | - |
|
| 2494 | - /** |
|
| 2495 | - * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2496 | - * |
|
| 2497 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed. |
|
| 2498 | - * The returned json object is created from an array in the following format: |
|
| 2499 | - * array( |
|
| 2500 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2501 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2502 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2503 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2504 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any |
|
| 2505 | - * specific template args that might be included in here) |
|
| 2506 | - * ) |
|
| 2507 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 2508 | - * @return void |
|
| 2509 | - */ |
|
| 2510 | - protected function _return_json($sticky_notices = false) |
|
| 2511 | - { |
|
| 2512 | - //make sure any EE_Error notices have been handled. |
|
| 2513 | - $this->_process_notices(array(), true, $sticky_notices); |
|
| 2514 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 2515 | - unset($this->_template_args['data']); |
|
| 2516 | - $json = array( |
|
| 2517 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2518 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2519 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2520 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2521 | - 'notices' => EE_Error::get_notices(), |
|
| 2522 | - 'content' => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '', |
|
| 2523 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 2524 | - 'isEEajax' => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2525 | - ); |
|
| 2526 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2527 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 2528 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 2529 | - } |
|
| 2530 | - if (function_exists('wp_json_encode')) { |
|
| 2531 | - echo wp_json_encode($json); |
|
| 2532 | - } else { |
|
| 2533 | - echo json_encode($json); |
|
| 2534 | - } |
|
| 2535 | - exit(); |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - |
|
| 2539 | - |
|
| 2540 | - /** |
|
| 2541 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2542 | - * |
|
| 2543 | - * @return void |
|
| 2544 | - * @throws EE_Error |
|
| 2545 | - */ |
|
| 2546 | - public function return_json() |
|
| 2547 | - { |
|
| 2548 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2549 | - $this->_return_json(); |
|
| 2550 | - } else { |
|
| 2551 | - throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__)); |
|
| 2552 | - } |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - |
|
| 2556 | - |
|
| 2557 | - /** |
|
| 2558 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 2559 | - * |
|
| 2560 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 2561 | - * @access public |
|
| 2562 | - */ |
|
| 2563 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 2564 | - { |
|
| 2565 | - $this->_hook_obj = $hook_obj; |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - |
|
| 2569 | - |
|
| 2570 | - /** |
|
| 2571 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 2572 | - * |
|
| 2573 | - * @access public |
|
| 2574 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 2575 | - * @return void |
|
| 2576 | - */ |
|
| 2577 | - public function admin_page_wrapper($about = false) |
|
| 2578 | - { |
|
| 2579 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2580 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 2581 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 2582 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 2583 | - $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2584 | - isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
|
| 2585 | - $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2586 | - isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
|
| 2587 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 2588 | - // load settings page wrapper template |
|
| 2589 | - $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2590 | - //about page? |
|
| 2591 | - $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2592 | - if (defined('DOING_AJAX')) { |
|
| 2593 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2594 | - $this->_return_json(); |
|
| 2595 | - } else { |
|
| 2596 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2597 | - } |
|
| 2598 | - } |
|
| 2599 | - |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - /** |
|
| 2603 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 2604 | - * |
|
| 2605 | - * @return string html |
|
| 2606 | - */ |
|
| 2607 | - protected function _get_main_nav_tabs() |
|
| 2608 | - { |
|
| 2609 | - //let's generate the html using the EEH_Tabbed_Content helper. We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array) |
|
| 2610 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 2611 | - } |
|
| 2612 | - |
|
| 2613 | - |
|
| 2614 | - |
|
| 2615 | - /** |
|
| 2616 | - * sort nav tabs |
|
| 2617 | - * |
|
| 2618 | - * @access public |
|
| 2619 | - * @param $a |
|
| 2620 | - * @param $b |
|
| 2621 | - * @return int |
|
| 2622 | - */ |
|
| 2623 | - private function _sort_nav_tabs($a, $b) |
|
| 2624 | - { |
|
| 2625 | - if ($a['order'] == $b['order']) { |
|
| 2626 | - return 0; |
|
| 2627 | - } |
|
| 2628 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 2629 | - } |
|
| 2630 | - |
|
| 2631 | - |
|
| 2632 | - |
|
| 2633 | - /** |
|
| 2634 | - * generates HTML for the forms used on admin pages |
|
| 2635 | - * |
|
| 2636 | - * @access protected |
|
| 2637 | - * @param array $input_vars - array of input field details |
|
| 2638 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use) |
|
| 2639 | - * @return string |
|
| 2640 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 2641 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 2642 | - */ |
|
| 2643 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 2644 | - { |
|
| 2645 | - $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 2646 | - return $content; |
|
| 2647 | - } |
|
| 2648 | - |
|
| 2649 | - |
|
| 2650 | - |
|
| 2651 | - /** |
|
| 2652 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 2653 | - * |
|
| 2654 | - * @access protected |
|
| 2655 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & Close" button. |
|
| 2656 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close') |
|
| 2657 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button). We can also use this to just dump default actions by submitting some other value. |
|
| 2658 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling). |
|
| 2659 | - */ |
|
| 2660 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 2661 | - { |
|
| 2662 | - //make sure $text and $actions are in an array |
|
| 2663 | - $text = (array)$text; |
|
| 2664 | - $actions = (array)$actions; |
|
| 2665 | - $referrer_url = empty($referrer) ? '' : $referrer; |
|
| 2666 | - $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2667 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2668 | - $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
|
| 2669 | - $default_names = array('save', 'save_and_close'); |
|
| 2670 | - //add in a hidden index for the current page (so save and close redirects properly) |
|
| 2671 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 2672 | - foreach ($button_text as $key => $button) { |
|
| 2673 | - $ref = $default_names[$key]; |
|
| 2674 | - $id = $this->_current_view . '_' . $ref; |
|
| 2675 | - $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 2676 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2677 | - if ( ! $both) { |
|
| 2678 | - break; |
|
| 2679 | - } |
|
| 2680 | - } |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - |
|
| 2684 | - |
|
| 2685 | - /** |
|
| 2686 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 2687 | - * |
|
| 2688 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 2689 | - * @since 4.6.0 |
|
| 2690 | - * @param string $route |
|
| 2691 | - * @param array $additional_hidden_fields |
|
| 2692 | - */ |
|
| 2693 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2694 | - { |
|
| 2695 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 2696 | - } |
|
| 2697 | - |
|
| 2698 | - |
|
| 2699 | - |
|
| 2700 | - /** |
|
| 2701 | - * set form open and close tags on add/edit pages. |
|
| 2702 | - * |
|
| 2703 | - * @access protected |
|
| 2704 | - * @param string $route the route you want the form to direct to |
|
| 2705 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 2706 | - * @return void |
|
| 2707 | - */ |
|
| 2708 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2709 | - { |
|
| 2710 | - if (empty($route)) { |
|
| 2711 | - $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
|
| 2712 | - $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2713 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2714 | - } |
|
| 2715 | - // open form |
|
| 2716 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2717 | - // add nonce |
|
| 2718 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2719 | - // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 2720 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2721 | - // add REQUIRED form action |
|
| 2722 | - $hidden_fields = array( |
|
| 2723 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 2724 | - ); |
|
| 2725 | - // merge arrays |
|
| 2726 | - $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields; |
|
| 2727 | - // generate form fields |
|
| 2728 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 2729 | - // add fields to form |
|
| 2730 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2731 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2732 | - } |
|
| 2733 | - // close form |
|
| 2734 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 2735 | - } |
|
| 2736 | - |
|
| 2737 | - |
|
| 2738 | - |
|
| 2739 | - /** |
|
| 2740 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 2741 | - * discovered it would be useful for external code to have access. |
|
| 2742 | - * |
|
| 2743 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 2744 | - * @since 4.5.0 |
|
| 2745 | - */ |
|
| 2746 | - public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2747 | - { |
|
| 2748 | - $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite); |
|
| 2749 | - } |
|
| 2750 | - |
|
| 2751 | - |
|
| 2752 | - |
|
| 2753 | - /** |
|
| 2754 | - * _redirect_after_action |
|
| 2755 | - * |
|
| 2756 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 2757 | - * @param string $what - what the action was performed on |
|
| 2758 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 2759 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin action is completed |
|
| 2760 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show. |
|
| 2761 | - * @access protected |
|
| 2762 | - * @return void |
|
| 2763 | - */ |
|
| 2764 | - protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2765 | - { |
|
| 2766 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2767 | - //class name for actions/filters. |
|
| 2768 | - $classname = get_class($this); |
|
| 2769 | - //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url |
|
| 2770 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 2771 | - $notices = EE_Error::get_notices(false); |
|
| 2772 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 2773 | - if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 2774 | - EE_Error::overwrite_success(); |
|
| 2775 | - } |
|
| 2776 | - if ( ! empty($what) && ! empty($action_desc)) { |
|
| 2777 | - // how many records affected ? more than one record ? or just one ? |
|
| 2778 | - if ($success > 1 && empty($notices['errors'])) { |
|
| 2779 | - // set plural msg |
|
| 2780 | - EE_Error::add_success( |
|
| 2781 | - sprintf( |
|
| 2782 | - __('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 2783 | - $what, |
|
| 2784 | - $action_desc |
|
| 2785 | - ), |
|
| 2786 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2787 | - ); |
|
| 2788 | - } else if ($success == 1 && empty($notices['errors'])) { |
|
| 2789 | - // set singular msg |
|
| 2790 | - EE_Error::add_success( |
|
| 2791 | - sprintf( |
|
| 2792 | - __('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 2793 | - $what, |
|
| 2794 | - $action_desc |
|
| 2795 | - ), |
|
| 2796 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2797 | - ); |
|
| 2798 | - } |
|
| 2799 | - } |
|
| 2800 | - // check that $query_args isn't something crazy |
|
| 2801 | - if ( ! is_array($query_args)) { |
|
| 2802 | - $query_args = array(); |
|
| 2803 | - } |
|
| 2804 | - /** |
|
| 2805 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 2806 | - * redirections on save and close actions |
|
| 2807 | - * |
|
| 2808 | - * @since 4.2.0 |
|
| 2809 | - * @param array $query_args The original query_args array coming into the |
|
| 2810 | - * method. |
|
| 2811 | - */ |
|
| 2812 | - do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2813 | - //calculate where we're going (if we have a "save and close" button pushed) |
|
| 2814 | - if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
|
| 2815 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 2816 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 2817 | - // regenerate query args array from referrer URL |
|
| 2818 | - parse_str($parsed_url['query'], $query_args); |
|
| 2819 | - // correct page and action will be in the query args now |
|
| 2820 | - $redirect_url = admin_url('admin.php'); |
|
| 2821 | - } |
|
| 2822 | - //merge any default query_args set in _default_route_query_args property |
|
| 2823 | - if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 2824 | - $args_to_merge = array(); |
|
| 2825 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 2826 | - //is there a wp_referer array in our _default_route_query_args property? |
|
| 2827 | - if ($query_param == 'wp_referer') { |
|
| 2828 | - $query_value = (array)$query_value; |
|
| 2829 | - foreach ($query_value as $reference => $value) { |
|
| 2830 | - if (strpos($reference, 'nonce') !== false) { |
|
| 2831 | - continue; |
|
| 2832 | - } |
|
| 2833 | - //finally we will override any arguments in the referer with |
|
| 2834 | - //what might be set on the _default_route_query_args array. |
|
| 2835 | - if (isset($this->_default_route_query_args[$reference])) { |
|
| 2836 | - $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 2837 | - } else { |
|
| 2838 | - $args_to_merge[$reference] = urlencode($value); |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - continue; |
|
| 2842 | - } |
|
| 2843 | - $args_to_merge[$query_param] = $query_value; |
|
| 2844 | - } |
|
| 2845 | - //now let's merge these arguments but override with what was specifically sent in to the |
|
| 2846 | - //redirect. |
|
| 2847 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 2848 | - } |
|
| 2849 | - $this->_process_notices($query_args); |
|
| 2850 | - // generate redirect url |
|
| 2851 | - // if redirecting to anything other than the main page, add a nonce |
|
| 2852 | - if (isset($query_args['action'])) { |
|
| 2853 | - // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 2854 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2855 | - } |
|
| 2856 | - //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
|
| 2857 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2858 | - $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2859 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 2860 | - if (defined('DOING_AJAX')) { |
|
| 2861 | - $default_data = array( |
|
| 2862 | - 'close' => true, |
|
| 2863 | - 'redirect_url' => $redirect_url, |
|
| 2864 | - 'where' => 'main', |
|
| 2865 | - 'what' => 'append', |
|
| 2866 | - ); |
|
| 2867 | - $this->_template_args['success'] = $success; |
|
| 2868 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data; |
|
| 2869 | - $this->_return_json(); |
|
| 2870 | - } |
|
| 2871 | - wp_safe_redirect($redirect_url); |
|
| 2872 | - exit(); |
|
| 2873 | - } |
|
| 2874 | - |
|
| 2875 | - |
|
| 2876 | - |
|
| 2877 | - /** |
|
| 2878 | - * process any notices before redirecting (or returning ajax request) |
|
| 2879 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 2880 | - * |
|
| 2881 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 2882 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet. |
|
| 2883 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice. |
|
| 2884 | - * @return void |
|
| 2885 | - */ |
|
| 2886 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 2887 | - { |
|
| 2888 | - //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 2889 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2890 | - $notices = EE_Error::get_notices(false); |
|
| 2891 | - if (empty($this->_template_args['success'])) { |
|
| 2892 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 2893 | - } |
|
| 2894 | - if (empty($this->_template_args['errors'])) { |
|
| 2895 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 2896 | - } |
|
| 2897 | - if (empty($this->_template_args['attention'])) { |
|
| 2898 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 2899 | - } |
|
| 2900 | - } |
|
| 2901 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 2902 | - //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 2903 | - if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 2904 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 2905 | - $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify); |
|
| 2906 | - } |
|
| 2907 | - } |
|
| 2908 | - |
|
| 2909 | - |
|
| 2910 | - |
|
| 2911 | - /** |
|
| 2912 | - * get_action_link_or_button |
|
| 2913 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 2914 | - * |
|
| 2915 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 2916 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property. |
|
| 2917 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 2918 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 2919 | - * @param string $base_url If this is not provided |
|
| 2920 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 2921 | - * Otherwise this value will be used. |
|
| 2922 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 2923 | - * @return string |
|
| 2924 | - * @throws \EE_Error |
|
| 2925 | - */ |
|
| 2926 | - public function get_action_link_or_button( |
|
| 2927 | - $action, |
|
| 2928 | - $type = 'add', |
|
| 2929 | - $extra_request = array(), |
|
| 2930 | - $class = 'button-primary', |
|
| 2931 | - $base_url = '', |
|
| 2932 | - $exclude_nonce = false |
|
| 2933 | - ) { |
|
| 2934 | - //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 2935 | - if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 2936 | - throw new EE_Error( |
|
| 2937 | - sprintf( |
|
| 2938 | - __( |
|
| 2939 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 2940 | - 'event_espresso' |
|
| 2941 | - ), |
|
| 2942 | - $action |
|
| 2943 | - ) |
|
| 2944 | - ); |
|
| 2945 | - } |
|
| 2946 | - if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 2947 | - throw new EE_Error( |
|
| 2948 | - sprintf( |
|
| 2949 | - __( |
|
| 2950 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 2951 | - 'event_espresso' |
|
| 2952 | - ), |
|
| 2953 | - $type |
|
| 2954 | - ) |
|
| 2955 | - ); |
|
| 2956 | - } |
|
| 2957 | - //finally check user access for this button. |
|
| 2958 | - $has_access = $this->check_user_access($action, true); |
|
| 2959 | - if ( ! $has_access) { |
|
| 2960 | - return ''; |
|
| 2961 | - } |
|
| 2962 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 2963 | - $query_args = array( |
|
| 2964 | - 'action' => $action, |
|
| 2965 | - ); |
|
| 2966 | - //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 2967 | - if ( ! empty($extra_request)) { |
|
| 2968 | - $query_args = array_merge($extra_request, $query_args); |
|
| 2969 | - } |
|
| 2970 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 2971 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 2972 | - } |
|
| 2973 | - |
|
| 2974 | - |
|
| 2975 | - |
|
| 2976 | - /** |
|
| 2977 | - * _per_page_screen_option |
|
| 2978 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 2979 | - * |
|
| 2980 | - * @return void |
|
| 2981 | - */ |
|
| 2982 | - protected function _per_page_screen_option() |
|
| 2983 | - { |
|
| 2984 | - $option = 'per_page'; |
|
| 2985 | - $args = array( |
|
| 2986 | - 'label' => $this->_admin_page_title, |
|
| 2987 | - 'default' => 10, |
|
| 2988 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 2989 | - ); |
|
| 2990 | - //ONLY add the screen option if the user has access to it. |
|
| 2991 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 2992 | - add_screen_option($option, $args); |
|
| 2993 | - } |
|
| 2994 | - } |
|
| 2995 | - |
|
| 2996 | - |
|
| 2997 | - |
|
| 2998 | - /** |
|
| 2999 | - * set_per_page_screen_option |
|
| 3000 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3001 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu. |
|
| 3002 | - * |
|
| 3003 | - * @access private |
|
| 3004 | - * @return void |
|
| 3005 | - */ |
|
| 3006 | - private function _set_per_page_screen_options() |
|
| 3007 | - { |
|
| 3008 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3009 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3010 | - if ( ! $user = wp_get_current_user()) { |
|
| 3011 | - return; |
|
| 3012 | - } |
|
| 3013 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3014 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3015 | - if ($option != sanitize_key($option)) { |
|
| 3016 | - return; |
|
| 3017 | - } |
|
| 3018 | - $map_option = $option; |
|
| 3019 | - $option = str_replace('-', '_', $option); |
|
| 3020 | - switch ($map_option) { |
|
| 3021 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3022 | - $value = (int)$value; |
|
| 3023 | - if ($value < 1 || $value > 999) { |
|
| 3024 | - return; |
|
| 3025 | - } |
|
| 3026 | - break; |
|
| 3027 | - default: |
|
| 3028 | - $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value); |
|
| 3029 | - if (false === $value) { |
|
| 3030 | - return; |
|
| 3031 | - } |
|
| 3032 | - break; |
|
| 3033 | - } |
|
| 3034 | - update_user_meta($user->ID, $option, $value); |
|
| 3035 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3036 | - exit; |
|
| 3037 | - } |
|
| 3038 | - } |
|
| 3039 | - |
|
| 3040 | - |
|
| 3041 | - |
|
| 3042 | - /** |
|
| 3043 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3044 | - * |
|
| 3045 | - * @param array $data array that will be assigned to template args. |
|
| 3046 | - */ |
|
| 3047 | - public function set_template_args($data) |
|
| 3048 | - { |
|
| 3049 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3050 | - } |
|
| 3051 | - |
|
| 3052 | - |
|
| 3053 | - |
|
| 3054 | - /** |
|
| 3055 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3056 | - * |
|
| 3057 | - * @access protected |
|
| 3058 | - * @param string $route the route that should receive the transient |
|
| 3059 | - * @param array $data the data that gets sent |
|
| 3060 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient. |
|
| 3061 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used when we are adding a transient before page_routes have been defined. |
|
| 3062 | - * @return void |
|
| 3063 | - */ |
|
| 3064 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3065 | - { |
|
| 3066 | - $user_id = get_current_user_id(); |
|
| 3067 | - if ( ! $skip_route_verify) { |
|
| 3068 | - $this->_verify_route($route); |
|
| 3069 | - } |
|
| 3070 | - //now let's set the string for what kind of transient we're setting |
|
| 3071 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3072 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3073 | - //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3074 | - $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3075 | - if ($existing) { |
|
| 3076 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3077 | - } |
|
| 3078 | - if (is_multisite() && is_network_admin()) { |
|
| 3079 | - set_site_transient($transient, $data, 8); |
|
| 3080 | - } else { |
|
| 3081 | - set_transient($transient, $data, 8); |
|
| 3082 | - } |
|
| 3083 | - } |
|
| 3084 | - |
|
| 3085 | - |
|
| 3086 | - |
|
| 3087 | - /** |
|
| 3088 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3089 | - * |
|
| 3090 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3091 | - * @return mixed data |
|
| 3092 | - */ |
|
| 3093 | - protected function _get_transient($notices = false, $route = false) |
|
| 3094 | - { |
|
| 3095 | - $user_id = get_current_user_id(); |
|
| 3096 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3097 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3098 | - $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3099 | - //delete transient after retrieval (just in case it hasn't expired); |
|
| 3100 | - if (is_multisite() && is_network_admin()) { |
|
| 3101 | - delete_site_transient($transient); |
|
| 3102 | - } else { |
|
| 3103 | - delete_transient($transient); |
|
| 3104 | - } |
|
| 3105 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3106 | - } |
|
| 3107 | - |
|
| 3108 | - |
|
| 3109 | - |
|
| 3110 | - /** |
|
| 3111 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later. |
|
| 3112 | - * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.) |
|
| 3113 | - * |
|
| 3114 | - * @return void |
|
| 3115 | - */ |
|
| 3116 | - protected function _transient_garbage_collection() |
|
| 3117 | - { |
|
| 3118 | - global $wpdb; |
|
| 3119 | - //retrieve all existing transients |
|
| 3120 | - $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3121 | - if ($results = $wpdb->get_results($query)) { |
|
| 3122 | - foreach ($results as $result) { |
|
| 3123 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3124 | - get_transient($transient); |
|
| 3125 | - if (is_multisite() && is_network_admin()) { |
|
| 3126 | - get_site_transient($transient); |
|
| 3127 | - } |
|
| 3128 | - } |
|
| 3129 | - } |
|
| 3130 | - } |
|
| 3131 | - |
|
| 3132 | - |
|
| 3133 | - |
|
| 3134 | - /** |
|
| 3135 | - * get_view |
|
| 3136 | - * |
|
| 3137 | - * @access public |
|
| 3138 | - * @return string content of _view property |
|
| 3139 | - */ |
|
| 3140 | - public function get_view() |
|
| 3141 | - { |
|
| 3142 | - return $this->_view; |
|
| 3143 | - } |
|
| 3144 | - |
|
| 3145 | - |
|
| 3146 | - |
|
| 3147 | - /** |
|
| 3148 | - * getter for the protected $_views property |
|
| 3149 | - * |
|
| 3150 | - * @return array |
|
| 3151 | - */ |
|
| 3152 | - public function get_views() |
|
| 3153 | - { |
|
| 3154 | - return $this->_views; |
|
| 3155 | - } |
|
| 3156 | - |
|
| 3157 | - |
|
| 3158 | - |
|
| 3159 | - /** |
|
| 3160 | - * get_current_page |
|
| 3161 | - * |
|
| 3162 | - * @access public |
|
| 3163 | - * @return string _current_page property value |
|
| 3164 | - */ |
|
| 3165 | - public function get_current_page() |
|
| 3166 | - { |
|
| 3167 | - return $this->_current_page; |
|
| 3168 | - } |
|
| 3169 | - |
|
| 3170 | - |
|
| 3171 | - |
|
| 3172 | - /** |
|
| 3173 | - * get_current_view |
|
| 3174 | - * |
|
| 3175 | - * @access public |
|
| 3176 | - * @return string _current_view property value |
|
| 3177 | - */ |
|
| 3178 | - public function get_current_view() |
|
| 3179 | - { |
|
| 3180 | - return $this->_current_view; |
|
| 3181 | - } |
|
| 3182 | - |
|
| 3183 | - |
|
| 3184 | - |
|
| 3185 | - /** |
|
| 3186 | - * get_current_screen |
|
| 3187 | - * |
|
| 3188 | - * @access public |
|
| 3189 | - * @return object The current WP_Screen object |
|
| 3190 | - */ |
|
| 3191 | - public function get_current_screen() |
|
| 3192 | - { |
|
| 3193 | - return $this->_current_screen; |
|
| 3194 | - } |
|
| 3195 | - |
|
| 3196 | - |
|
| 3197 | - |
|
| 3198 | - /** |
|
| 3199 | - * get_current_page_view_url |
|
| 3200 | - * |
|
| 3201 | - * @access public |
|
| 3202 | - * @return string This returns the url for the current_page_view. |
|
| 3203 | - */ |
|
| 3204 | - public function get_current_page_view_url() |
|
| 3205 | - { |
|
| 3206 | - return $this->_current_page_view_url; |
|
| 3207 | - } |
|
| 3208 | - |
|
| 3209 | - |
|
| 3210 | - |
|
| 3211 | - /** |
|
| 3212 | - * just returns the _req_data property |
|
| 3213 | - * |
|
| 3214 | - * @return array |
|
| 3215 | - */ |
|
| 3216 | - public function get_request_data() |
|
| 3217 | - { |
|
| 3218 | - return $this->_req_data; |
|
| 3219 | - } |
|
| 3220 | - |
|
| 3221 | - |
|
| 3222 | - |
|
| 3223 | - /** |
|
| 3224 | - * returns the _req_data protected property |
|
| 3225 | - * |
|
| 3226 | - * @return string |
|
| 3227 | - */ |
|
| 3228 | - public function get_req_action() |
|
| 3229 | - { |
|
| 3230 | - return $this->_req_action; |
|
| 3231 | - } |
|
| 3232 | - |
|
| 3233 | - |
|
| 3234 | - |
|
| 3235 | - /** |
|
| 3236 | - * @return bool value of $_is_caf property |
|
| 3237 | - */ |
|
| 3238 | - public function is_caf() |
|
| 3239 | - { |
|
| 3240 | - return $this->_is_caf; |
|
| 3241 | - } |
|
| 3242 | - |
|
| 3243 | - |
|
| 3244 | - |
|
| 3245 | - /** |
|
| 3246 | - * @return mixed |
|
| 3247 | - */ |
|
| 3248 | - public function default_espresso_metaboxes() |
|
| 3249 | - { |
|
| 3250 | - return $this->_default_espresso_metaboxes; |
|
| 3251 | - } |
|
| 3252 | - |
|
| 3253 | - |
|
| 3254 | - |
|
| 3255 | - /** |
|
| 3256 | - * @return mixed |
|
| 3257 | - */ |
|
| 3258 | - public function admin_base_url() |
|
| 3259 | - { |
|
| 3260 | - return $this->_admin_base_url; |
|
| 3261 | - } |
|
| 3262 | - |
|
| 3263 | - |
|
| 3264 | - |
|
| 3265 | - /** |
|
| 3266 | - * @return mixed |
|
| 3267 | - */ |
|
| 3268 | - public function wp_page_slug() |
|
| 3269 | - { |
|
| 3270 | - return $this->_wp_page_slug; |
|
| 3271 | - } |
|
| 3272 | - |
|
| 3273 | - |
|
| 3274 | - |
|
| 3275 | - /** |
|
| 3276 | - * updates espresso configuration settings |
|
| 3277 | - * |
|
| 3278 | - * @access protected |
|
| 3279 | - * @param string $tab |
|
| 3280 | - * @param EE_Config_Base|EE_Config $config |
|
| 3281 | - * @param string $file file where error occurred |
|
| 3282 | - * @param string $func function where error occurred |
|
| 3283 | - * @param string $line line no where error occurred |
|
| 3284 | - * @return boolean |
|
| 3285 | - */ |
|
| 3286 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3287 | - { |
|
| 3288 | - //remove any options that are NOT going to be saved with the config settings. |
|
| 3289 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 3290 | - $config->core->ee_ueip_has_notified = true; |
|
| 3291 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3292 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3293 | - update_option('ee_ueip_has_notified', true); |
|
| 3294 | - } |
|
| 3295 | - // and save it (note we're also doing the network save here) |
|
| 3296 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3297 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3298 | - if ($config_saved && $net_saved) { |
|
| 3299 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3300 | - return true; |
|
| 3301 | - } else { |
|
| 3302 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3303 | - return false; |
|
| 3304 | - } |
|
| 3305 | - } |
|
| 3306 | - |
|
| 3307 | - |
|
| 3308 | - |
|
| 3309 | - /** |
|
| 3310 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3311 | - * |
|
| 3312 | - * @return array |
|
| 3313 | - */ |
|
| 3314 | - public function get_yes_no_values() |
|
| 3315 | - { |
|
| 3316 | - return $this->_yes_no_values; |
|
| 3317 | - } |
|
| 3318 | - |
|
| 3319 | - |
|
| 3320 | - |
|
| 3321 | - protected function _get_dir() |
|
| 3322 | - { |
|
| 3323 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 3324 | - return dirname($reflector->getFileName()); |
|
| 3325 | - } |
|
| 3326 | - |
|
| 3327 | - |
|
| 3328 | - |
|
| 3329 | - /** |
|
| 3330 | - * A helper for getting a "next link". |
|
| 3331 | - * |
|
| 3332 | - * @param string $url The url to link to |
|
| 3333 | - * @param string $class The class to use. |
|
| 3334 | - * @return string |
|
| 3335 | - */ |
|
| 3336 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3337 | - { |
|
| 3338 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3339 | - } |
|
| 3340 | - |
|
| 3341 | - |
|
| 3342 | - |
|
| 3343 | - /** |
|
| 3344 | - * A helper for getting a "previous link". |
|
| 3345 | - * |
|
| 3346 | - * @param string $url The url to link to |
|
| 3347 | - * @param string $class The class to use. |
|
| 3348 | - * @return string |
|
| 3349 | - */ |
|
| 3350 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3351 | - { |
|
| 3352 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3353 | - } |
|
| 3354 | - |
|
| 3355 | - |
|
| 3356 | - |
|
| 3357 | - |
|
| 3358 | - |
|
| 3359 | - |
|
| 3360 | - |
|
| 3361 | - //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3362 | - /** |
|
| 3363 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller 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 _req_data |
|
| 3364 | - * array. |
|
| 3365 | - * |
|
| 3366 | - * @return bool success/fail |
|
| 3367 | - */ |
|
| 3368 | - protected function _process_resend_registration() |
|
| 3369 | - { |
|
| 3370 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3371 | - do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data); |
|
| 3372 | - return $this->_template_args['success']; |
|
| 3373 | - } |
|
| 3374 | - |
|
| 3375 | - |
|
| 3376 | - |
|
| 3377 | - /** |
|
| 3378 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3379 | - * |
|
| 3380 | - * @access protected |
|
| 3381 | - * @param \EE_Payment $payment |
|
| 3382 | - * @return bool success/fail |
|
| 3383 | - */ |
|
| 3384 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 3385 | - { |
|
| 3386 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3387 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3388 | - $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment); |
|
| 3389 | - return $this->_template_args['success']; |
|
| 3390 | - } |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * facade for add_meta_box |
|
| 2198 | + * |
|
| 2199 | + * @param string $action where the metabox get's displayed |
|
| 2200 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2201 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here. |
|
| 2202 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2203 | + * @param string $column what metabox column |
|
| 2204 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2205 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box. |
|
| 2206 | + */ |
|
| 2207 | + public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true) |
|
| 2208 | + { |
|
| 2209 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2210 | + //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. |
|
| 2211 | + if (empty($callback_args) && $create_func) { |
|
| 2212 | + $callback_args = array( |
|
| 2213 | + 'template_path' => $this->_template_path, |
|
| 2214 | + 'template_args' => $this->_template_args, |
|
| 2215 | + ); |
|
| 2216 | + } |
|
| 2217 | + //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) |
|
| 2218 | + $call_back_func = $create_func ? create_function('$post, $metabox', |
|
| 2219 | + 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
|
| 2220 | + add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2221 | + } |
|
| 2222 | + |
|
| 2223 | + |
|
| 2224 | + |
|
| 2225 | + /** |
|
| 2226 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2227 | + * |
|
| 2228 | + * @return [type] [description] |
|
| 2229 | + */ |
|
| 2230 | + public function display_admin_page_with_metabox_columns() |
|
| 2231 | + { |
|
| 2232 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2233 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true); |
|
| 2234 | + //the final wrapper |
|
| 2235 | + $this->admin_page_wrapper(); |
|
| 2236 | + } |
|
| 2237 | + |
|
| 2238 | + |
|
| 2239 | + |
|
| 2240 | + /** |
|
| 2241 | + * generates HTML wrapper for an admin details page |
|
| 2242 | + * |
|
| 2243 | + * @access public |
|
| 2244 | + * @return void |
|
| 2245 | + */ |
|
| 2246 | + public function display_admin_page_with_sidebar() |
|
| 2247 | + { |
|
| 2248 | + $this->_display_admin_page(true); |
|
| 2249 | + } |
|
| 2250 | + |
|
| 2251 | + |
|
| 2252 | + |
|
| 2253 | + /** |
|
| 2254 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2255 | + * |
|
| 2256 | + * @access public |
|
| 2257 | + * @return void |
|
| 2258 | + */ |
|
| 2259 | + public function display_admin_page_with_no_sidebar() |
|
| 2260 | + { |
|
| 2261 | + $this->_display_admin_page(); |
|
| 2262 | + } |
|
| 2263 | + |
|
| 2264 | + |
|
| 2265 | + |
|
| 2266 | + /** |
|
| 2267 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2268 | + * |
|
| 2269 | + * @access public |
|
| 2270 | + * @return void |
|
| 2271 | + */ |
|
| 2272 | + public function display_about_admin_page() |
|
| 2273 | + { |
|
| 2274 | + $this->_display_admin_page(false, true); |
|
| 2275 | + } |
|
| 2276 | + |
|
| 2277 | + |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * display_admin_page |
|
| 2281 | + * contains the code for actually displaying an admin page |
|
| 2282 | + * |
|
| 2283 | + * @access private |
|
| 2284 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2285 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2286 | + * @return void |
|
| 2287 | + */ |
|
| 2288 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2289 | + { |
|
| 2290 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2291 | + //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2292 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2293 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2294 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2295 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2296 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2297 | + ? 'poststuff' |
|
| 2298 | + : 'espresso-default-admin'; |
|
| 2299 | + $template_path = $sidebar |
|
| 2300 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2301 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2302 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2303 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2304 | + } |
|
| 2305 | + $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
|
| 2306 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
|
| 2307 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''; |
|
| 2308 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''; |
|
| 2309 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2310 | + // the final template wrapper |
|
| 2311 | + $this->admin_page_wrapper($about); |
|
| 2312 | + } |
|
| 2313 | + |
|
| 2314 | + |
|
| 2315 | + |
|
| 2316 | + /** |
|
| 2317 | + * This is used to display caf preview pages. |
|
| 2318 | + * |
|
| 2319 | + * @since 4.3.2 |
|
| 2320 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2321 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2322 | + * @return void |
|
| 2323 | + * @throws \EE_Error |
|
| 2324 | + */ |
|
| 2325 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2326 | + { |
|
| 2327 | + //let's generate a default preview action button if there isn't one already present. |
|
| 2328 | + $this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso'); |
|
| 2329 | + $buy_now_url = add_query_arg( |
|
| 2330 | + array( |
|
| 2331 | + 'ee_ver' => 'ee4', |
|
| 2332 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2333 | + 'utm_medium' => 'link', |
|
| 2334 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2335 | + 'utm_content' => 'buy_now_button', |
|
| 2336 | + ), |
|
| 2337 | + 'http://eventespresso.com/pricing/' |
|
| 2338 | + ); |
|
| 2339 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2340 | + ? $this->get_action_link_or_button( |
|
| 2341 | + '', |
|
| 2342 | + 'buy_now', |
|
| 2343 | + array(), |
|
| 2344 | + 'button-primary button-large', |
|
| 2345 | + $buy_now_url, |
|
| 2346 | + true |
|
| 2347 | + ) |
|
| 2348 | + : $this->_template_args['preview_action_button']; |
|
| 2349 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2350 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2351 | + $template_path, |
|
| 2352 | + $this->_template_args, |
|
| 2353 | + true |
|
| 2354 | + ); |
|
| 2355 | + $this->_display_admin_page($display_sidebar); |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + |
|
| 2359 | + |
|
| 2360 | + /** |
|
| 2361 | + * display_admin_list_table_page_with_sidebar |
|
| 2362 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2363 | + * |
|
| 2364 | + * @access public |
|
| 2365 | + * @return void |
|
| 2366 | + */ |
|
| 2367 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2368 | + { |
|
| 2369 | + $this->_display_admin_list_table_page(true); |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + |
|
| 2373 | + |
|
| 2374 | + /** |
|
| 2375 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2376 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2377 | + * |
|
| 2378 | + * @access public |
|
| 2379 | + * @return void |
|
| 2380 | + */ |
|
| 2381 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2382 | + { |
|
| 2383 | + $this->_display_admin_list_table_page(); |
|
| 2384 | + } |
|
| 2385 | + |
|
| 2386 | + |
|
| 2387 | + |
|
| 2388 | + /** |
|
| 2389 | + * generates html wrapper for an admin_list_table page |
|
| 2390 | + * |
|
| 2391 | + * @access private |
|
| 2392 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2393 | + * @return void |
|
| 2394 | + */ |
|
| 2395 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2396 | + { |
|
| 2397 | + //setup search attributes |
|
| 2398 | + $this->_set_search_attributes(); |
|
| 2399 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2400 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2401 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2402 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2403 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2404 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2405 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2406 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2407 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2408 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2409 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2410 | + $ajax_sorting_callback . '_nonce', |
|
| 2411 | + $ajax_sorting_callback . '_nonce', |
|
| 2412 | + false, |
|
| 2413 | + false |
|
| 2414 | + ); |
|
| 2415 | + // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
|
| 2416 | + // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
|
| 2417 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2418 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2419 | + } else { |
|
| 2420 | + $sortable_list_table_form_fields = ''; |
|
| 2421 | + } |
|
| 2422 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 2423 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
|
| 2424 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2425 | + $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2426 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 2427 | + //display message about search results? |
|
| 2428 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 2429 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 2430 | + __('Displaying search results for the search string: <strong><em>%s</em></strong>', |
|
| 2431 | + 'event_espresso'), |
|
| 2432 | + trim($this->_req_data['s'], '%') |
|
| 2433 | + ) . '</p>' |
|
| 2434 | + : ''; |
|
| 2435 | + // filter before_list_table template arg |
|
| 2436 | + $this->_template_args['before_list_table'] = implode( |
|
| 2437 | + " \n", |
|
| 2438 | + (array)apply_filters( |
|
| 2439 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 2440 | + (array)$this->_template_args['before_list_table'], |
|
| 2441 | + $this->page_slug, |
|
| 2442 | + $this->_req_data, |
|
| 2443 | + $this->_req_action |
|
| 2444 | + ) |
|
| 2445 | + ); |
|
| 2446 | + // filter after_list_table template arg |
|
| 2447 | + $this->_template_args['after_list_table'] = implode( |
|
| 2448 | + " \n", |
|
| 2449 | + (array)apply_filters( |
|
| 2450 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 2451 | + (array)$this->_template_args['after_list_table'], |
|
| 2452 | + $this->page_slug, |
|
| 2453 | + $this->_req_data, |
|
| 2454 | + $this->_req_action |
|
| 2455 | + ) |
|
| 2456 | + ); |
|
| 2457 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2458 | + $template_path, |
|
| 2459 | + $this->_template_args, |
|
| 2460 | + true |
|
| 2461 | + ); |
|
| 2462 | + // the final template wrapper |
|
| 2463 | + if ($sidebar) { |
|
| 2464 | + $this->display_admin_page_with_sidebar(); |
|
| 2465 | + } else { |
|
| 2466 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2467 | + } |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + |
|
| 2471 | + |
|
| 2472 | + /** |
|
| 2473 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend. |
|
| 2474 | + * $items are expected in an array in the following format: |
|
| 2475 | + * $legend_items = array( |
|
| 2476 | + * 'item_id' => array( |
|
| 2477 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 2478 | + * 'desc' => __('localized description of item'); |
|
| 2479 | + * ) |
|
| 2480 | + * ); |
|
| 2481 | + * |
|
| 2482 | + * @param array $items see above for format of array |
|
| 2483 | + * @return string html string of legend |
|
| 2484 | + */ |
|
| 2485 | + protected function _display_legend($items) |
|
| 2486 | + { |
|
| 2487 | + $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2488 | + $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2489 | + return EEH_Template::display_template($legend_template, $this->_template_args, true); |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + |
|
| 2493 | + |
|
| 2494 | + /** |
|
| 2495 | + * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 2496 | + * |
|
| 2497 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed. |
|
| 2498 | + * The returned json object is created from an array in the following format: |
|
| 2499 | + * array( |
|
| 2500 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 2501 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 2502 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 2503 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 2504 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any |
|
| 2505 | + * specific template args that might be included in here) |
|
| 2506 | + * ) |
|
| 2507 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 2508 | + * @return void |
|
| 2509 | + */ |
|
| 2510 | + protected function _return_json($sticky_notices = false) |
|
| 2511 | + { |
|
| 2512 | + //make sure any EE_Error notices have been handled. |
|
| 2513 | + $this->_process_notices(array(), true, $sticky_notices); |
|
| 2514 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 2515 | + unset($this->_template_args['data']); |
|
| 2516 | + $json = array( |
|
| 2517 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 2518 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 2519 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 2520 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 2521 | + 'notices' => EE_Error::get_notices(), |
|
| 2522 | + 'content' => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '', |
|
| 2523 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 2524 | + 'isEEajax' => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 2525 | + ); |
|
| 2526 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 2527 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 2528 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 2529 | + } |
|
| 2530 | + if (function_exists('wp_json_encode')) { |
|
| 2531 | + echo wp_json_encode($json); |
|
| 2532 | + } else { |
|
| 2533 | + echo json_encode($json); |
|
| 2534 | + } |
|
| 2535 | + exit(); |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + |
|
| 2539 | + |
|
| 2540 | + /** |
|
| 2541 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 2542 | + * |
|
| 2543 | + * @return void |
|
| 2544 | + * @throws EE_Error |
|
| 2545 | + */ |
|
| 2546 | + public function return_json() |
|
| 2547 | + { |
|
| 2548 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2549 | + $this->_return_json(); |
|
| 2550 | + } else { |
|
| 2551 | + throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__)); |
|
| 2552 | + } |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + |
|
| 2556 | + |
|
| 2557 | + /** |
|
| 2558 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 2559 | + * |
|
| 2560 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 2561 | + * @access public |
|
| 2562 | + */ |
|
| 2563 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 2564 | + { |
|
| 2565 | + $this->_hook_obj = $hook_obj; |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + |
|
| 2569 | + |
|
| 2570 | + /** |
|
| 2571 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 2572 | + * |
|
| 2573 | + * @access public |
|
| 2574 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 2575 | + * @return void |
|
| 2576 | + */ |
|
| 2577 | + public function admin_page_wrapper($about = false) |
|
| 2578 | + { |
|
| 2579 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2580 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 2581 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 2582 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 2583 | + $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2584 | + isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
|
| 2585 | + $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2586 | + isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
|
| 2587 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 2588 | + // load settings page wrapper template |
|
| 2589 | + $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2590 | + //about page? |
|
| 2591 | + $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2592 | + if (defined('DOING_AJAX')) { |
|
| 2593 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2594 | + $this->_return_json(); |
|
| 2595 | + } else { |
|
| 2596 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 2597 | + } |
|
| 2598 | + } |
|
| 2599 | + |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + /** |
|
| 2603 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 2604 | + * |
|
| 2605 | + * @return string html |
|
| 2606 | + */ |
|
| 2607 | + protected function _get_main_nav_tabs() |
|
| 2608 | + { |
|
| 2609 | + //let's generate the html using the EEH_Tabbed_Content helper. We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array) |
|
| 2610 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 2611 | + } |
|
| 2612 | + |
|
| 2613 | + |
|
| 2614 | + |
|
| 2615 | + /** |
|
| 2616 | + * sort nav tabs |
|
| 2617 | + * |
|
| 2618 | + * @access public |
|
| 2619 | + * @param $a |
|
| 2620 | + * @param $b |
|
| 2621 | + * @return int |
|
| 2622 | + */ |
|
| 2623 | + private function _sort_nav_tabs($a, $b) |
|
| 2624 | + { |
|
| 2625 | + if ($a['order'] == $b['order']) { |
|
| 2626 | + return 0; |
|
| 2627 | + } |
|
| 2628 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 2629 | + } |
|
| 2630 | + |
|
| 2631 | + |
|
| 2632 | + |
|
| 2633 | + /** |
|
| 2634 | + * generates HTML for the forms used on admin pages |
|
| 2635 | + * |
|
| 2636 | + * @access protected |
|
| 2637 | + * @param array $input_vars - array of input field details |
|
| 2638 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to use) |
|
| 2639 | + * @return string |
|
| 2640 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 2641 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 2642 | + */ |
|
| 2643 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
| 2644 | + { |
|
| 2645 | + $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 2646 | + return $content; |
|
| 2647 | + } |
|
| 2648 | + |
|
| 2649 | + |
|
| 2650 | + |
|
| 2651 | + /** |
|
| 2652 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 2653 | + * |
|
| 2654 | + * @access protected |
|
| 2655 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & Close" button. |
|
| 2656 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close') |
|
| 2657 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button). We can also use this to just dump default actions by submitting some other value. |
|
| 2658 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling). |
|
| 2659 | + */ |
|
| 2660 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 2661 | + { |
|
| 2662 | + //make sure $text and $actions are in an array |
|
| 2663 | + $text = (array)$text; |
|
| 2664 | + $actions = (array)$actions; |
|
| 2665 | + $referrer_url = empty($referrer) ? '' : $referrer; |
|
| 2666 | + $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2667 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2668 | + $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
|
| 2669 | + $default_names = array('save', 'save_and_close'); |
|
| 2670 | + //add in a hidden index for the current page (so save and close redirects properly) |
|
| 2671 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 2672 | + foreach ($button_text as $key => $button) { |
|
| 2673 | + $ref = $default_names[$key]; |
|
| 2674 | + $id = $this->_current_view . '_' . $ref; |
|
| 2675 | + $name = ! empty($actions) ? $actions[$key] : $ref; |
|
| 2676 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2677 | + if ( ! $both) { |
|
| 2678 | + break; |
|
| 2679 | + } |
|
| 2680 | + } |
|
| 2681 | + } |
|
| 2682 | + |
|
| 2683 | + |
|
| 2684 | + |
|
| 2685 | + /** |
|
| 2686 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 2687 | + * |
|
| 2688 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 2689 | + * @since 4.6.0 |
|
| 2690 | + * @param string $route |
|
| 2691 | + * @param array $additional_hidden_fields |
|
| 2692 | + */ |
|
| 2693 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2694 | + { |
|
| 2695 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 2696 | + } |
|
| 2697 | + |
|
| 2698 | + |
|
| 2699 | + |
|
| 2700 | + /** |
|
| 2701 | + * set form open and close tags on add/edit pages. |
|
| 2702 | + * |
|
| 2703 | + * @access protected |
|
| 2704 | + * @param string $route the route you want the form to direct to |
|
| 2705 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 2706 | + * @return void |
|
| 2707 | + */ |
|
| 2708 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 2709 | + { |
|
| 2710 | + if (empty($route)) { |
|
| 2711 | + $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
|
| 2712 | + $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2713 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2714 | + } |
|
| 2715 | + // open form |
|
| 2716 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2717 | + // add nonce |
|
| 2718 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2719 | + // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
|
| 2720 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2721 | + // add REQUIRED form action |
|
| 2722 | + $hidden_fields = array( |
|
| 2723 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 2724 | + ); |
|
| 2725 | + // merge arrays |
|
| 2726 | + $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields; |
|
| 2727 | + // generate form fields |
|
| 2728 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 2729 | + // add fields to form |
|
| 2730 | + foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2731 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2732 | + } |
|
| 2733 | + // close form |
|
| 2734 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 2735 | + } |
|
| 2736 | + |
|
| 2737 | + |
|
| 2738 | + |
|
| 2739 | + /** |
|
| 2740 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 2741 | + * discovered it would be useful for external code to have access. |
|
| 2742 | + * |
|
| 2743 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 2744 | + * @since 4.5.0 |
|
| 2745 | + */ |
|
| 2746 | + public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2747 | + { |
|
| 2748 | + $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite); |
|
| 2749 | + } |
|
| 2750 | + |
|
| 2751 | + |
|
| 2752 | + |
|
| 2753 | + /** |
|
| 2754 | + * _redirect_after_action |
|
| 2755 | + * |
|
| 2756 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 2757 | + * @param string $what - what the action was performed on |
|
| 2758 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 2759 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin action is completed |
|
| 2760 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show. |
|
| 2761 | + * @access protected |
|
| 2762 | + * @return void |
|
| 2763 | + */ |
|
| 2764 | + protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false) |
|
| 2765 | + { |
|
| 2766 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2767 | + //class name for actions/filters. |
|
| 2768 | + $classname = get_class($this); |
|
| 2769 | + //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url |
|
| 2770 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 2771 | + $notices = EE_Error::get_notices(false); |
|
| 2772 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 2773 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 2774 | + EE_Error::overwrite_success(); |
|
| 2775 | + } |
|
| 2776 | + if ( ! empty($what) && ! empty($action_desc)) { |
|
| 2777 | + // how many records affected ? more than one record ? or just one ? |
|
| 2778 | + if ($success > 1 && empty($notices['errors'])) { |
|
| 2779 | + // set plural msg |
|
| 2780 | + EE_Error::add_success( |
|
| 2781 | + sprintf( |
|
| 2782 | + __('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 2783 | + $what, |
|
| 2784 | + $action_desc |
|
| 2785 | + ), |
|
| 2786 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2787 | + ); |
|
| 2788 | + } else if ($success == 1 && empty($notices['errors'])) { |
|
| 2789 | + // set singular msg |
|
| 2790 | + EE_Error::add_success( |
|
| 2791 | + sprintf( |
|
| 2792 | + __('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 2793 | + $what, |
|
| 2794 | + $action_desc |
|
| 2795 | + ), |
|
| 2796 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2797 | + ); |
|
| 2798 | + } |
|
| 2799 | + } |
|
| 2800 | + // check that $query_args isn't something crazy |
|
| 2801 | + if ( ! is_array($query_args)) { |
|
| 2802 | + $query_args = array(); |
|
| 2803 | + } |
|
| 2804 | + /** |
|
| 2805 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 2806 | + * redirections on save and close actions |
|
| 2807 | + * |
|
| 2808 | + * @since 4.2.0 |
|
| 2809 | + * @param array $query_args The original query_args array coming into the |
|
| 2810 | + * method. |
|
| 2811 | + */ |
|
| 2812 | + do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2813 | + //calculate where we're going (if we have a "save and close" button pushed) |
|
| 2814 | + if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
|
| 2815 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 2816 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 2817 | + // regenerate query args array from referrer URL |
|
| 2818 | + parse_str($parsed_url['query'], $query_args); |
|
| 2819 | + // correct page and action will be in the query args now |
|
| 2820 | + $redirect_url = admin_url('admin.php'); |
|
| 2821 | + } |
|
| 2822 | + //merge any default query_args set in _default_route_query_args property |
|
| 2823 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 2824 | + $args_to_merge = array(); |
|
| 2825 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 2826 | + //is there a wp_referer array in our _default_route_query_args property? |
|
| 2827 | + if ($query_param == 'wp_referer') { |
|
| 2828 | + $query_value = (array)$query_value; |
|
| 2829 | + foreach ($query_value as $reference => $value) { |
|
| 2830 | + if (strpos($reference, 'nonce') !== false) { |
|
| 2831 | + continue; |
|
| 2832 | + } |
|
| 2833 | + //finally we will override any arguments in the referer with |
|
| 2834 | + //what might be set on the _default_route_query_args array. |
|
| 2835 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 2836 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 2837 | + } else { |
|
| 2838 | + $args_to_merge[$reference] = urlencode($value); |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + continue; |
|
| 2842 | + } |
|
| 2843 | + $args_to_merge[$query_param] = $query_value; |
|
| 2844 | + } |
|
| 2845 | + //now let's merge these arguments but override with what was specifically sent in to the |
|
| 2846 | + //redirect. |
|
| 2847 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 2848 | + } |
|
| 2849 | + $this->_process_notices($query_args); |
|
| 2850 | + // generate redirect url |
|
| 2851 | + // if redirecting to anything other than the main page, add a nonce |
|
| 2852 | + if (isset($query_args['action'])) { |
|
| 2853 | + // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 2854 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2855 | + } |
|
| 2856 | + //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
|
| 2857 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2858 | + $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2859 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 2860 | + if (defined('DOING_AJAX')) { |
|
| 2861 | + $default_data = array( |
|
| 2862 | + 'close' => true, |
|
| 2863 | + 'redirect_url' => $redirect_url, |
|
| 2864 | + 'where' => 'main', |
|
| 2865 | + 'what' => 'append', |
|
| 2866 | + ); |
|
| 2867 | + $this->_template_args['success'] = $success; |
|
| 2868 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data; |
|
| 2869 | + $this->_return_json(); |
|
| 2870 | + } |
|
| 2871 | + wp_safe_redirect($redirect_url); |
|
| 2872 | + exit(); |
|
| 2873 | + } |
|
| 2874 | + |
|
| 2875 | + |
|
| 2876 | + |
|
| 2877 | + /** |
|
| 2878 | + * process any notices before redirecting (or returning ajax request) |
|
| 2879 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 2880 | + * |
|
| 2881 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 2882 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet. |
|
| 2883 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice. |
|
| 2884 | + * @return void |
|
| 2885 | + */ |
|
| 2886 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 2887 | + { |
|
| 2888 | + //first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 2889 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2890 | + $notices = EE_Error::get_notices(false); |
|
| 2891 | + if (empty($this->_template_args['success'])) { |
|
| 2892 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 2893 | + } |
|
| 2894 | + if (empty($this->_template_args['errors'])) { |
|
| 2895 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 2896 | + } |
|
| 2897 | + if (empty($this->_template_args['attention'])) { |
|
| 2898 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 2899 | + } |
|
| 2900 | + } |
|
| 2901 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 2902 | + //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 2903 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 2904 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 2905 | + $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify); |
|
| 2906 | + } |
|
| 2907 | + } |
|
| 2908 | + |
|
| 2909 | + |
|
| 2910 | + |
|
| 2911 | + /** |
|
| 2912 | + * get_action_link_or_button |
|
| 2913 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 2914 | + * |
|
| 2915 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 2916 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) property. |
|
| 2917 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 2918 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 2919 | + * @param string $base_url If this is not provided |
|
| 2920 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 2921 | + * Otherwise this value will be used. |
|
| 2922 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 2923 | + * @return string |
|
| 2924 | + * @throws \EE_Error |
|
| 2925 | + */ |
|
| 2926 | + public function get_action_link_or_button( |
|
| 2927 | + $action, |
|
| 2928 | + $type = 'add', |
|
| 2929 | + $extra_request = array(), |
|
| 2930 | + $class = 'button-primary', |
|
| 2931 | + $base_url = '', |
|
| 2932 | + $exclude_nonce = false |
|
| 2933 | + ) { |
|
| 2934 | + //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 2935 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 2936 | + throw new EE_Error( |
|
| 2937 | + sprintf( |
|
| 2938 | + __( |
|
| 2939 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 2940 | + 'event_espresso' |
|
| 2941 | + ), |
|
| 2942 | + $action |
|
| 2943 | + ) |
|
| 2944 | + ); |
|
| 2945 | + } |
|
| 2946 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 2947 | + throw new EE_Error( |
|
| 2948 | + sprintf( |
|
| 2949 | + __( |
|
| 2950 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 2951 | + 'event_espresso' |
|
| 2952 | + ), |
|
| 2953 | + $type |
|
| 2954 | + ) |
|
| 2955 | + ); |
|
| 2956 | + } |
|
| 2957 | + //finally check user access for this button. |
|
| 2958 | + $has_access = $this->check_user_access($action, true); |
|
| 2959 | + if ( ! $has_access) { |
|
| 2960 | + return ''; |
|
| 2961 | + } |
|
| 2962 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 2963 | + $query_args = array( |
|
| 2964 | + 'action' => $action, |
|
| 2965 | + ); |
|
| 2966 | + //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 2967 | + if ( ! empty($extra_request)) { |
|
| 2968 | + $query_args = array_merge($extra_request, $query_args); |
|
| 2969 | + } |
|
| 2970 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 2971 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 2972 | + } |
|
| 2973 | + |
|
| 2974 | + |
|
| 2975 | + |
|
| 2976 | + /** |
|
| 2977 | + * _per_page_screen_option |
|
| 2978 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 2979 | + * |
|
| 2980 | + * @return void |
|
| 2981 | + */ |
|
| 2982 | + protected function _per_page_screen_option() |
|
| 2983 | + { |
|
| 2984 | + $option = 'per_page'; |
|
| 2985 | + $args = array( |
|
| 2986 | + 'label' => $this->_admin_page_title, |
|
| 2987 | + 'default' => 10, |
|
| 2988 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 2989 | + ); |
|
| 2990 | + //ONLY add the screen option if the user has access to it. |
|
| 2991 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 2992 | + add_screen_option($option, $args); |
|
| 2993 | + } |
|
| 2994 | + } |
|
| 2995 | + |
|
| 2996 | + |
|
| 2997 | + |
|
| 2998 | + /** |
|
| 2999 | + * set_per_page_screen_option |
|
| 3000 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3001 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu. |
|
| 3002 | + * |
|
| 3003 | + * @access private |
|
| 3004 | + * @return void |
|
| 3005 | + */ |
|
| 3006 | + private function _set_per_page_screen_options() |
|
| 3007 | + { |
|
| 3008 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3009 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3010 | + if ( ! $user = wp_get_current_user()) { |
|
| 3011 | + return; |
|
| 3012 | + } |
|
| 3013 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3014 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3015 | + if ($option != sanitize_key($option)) { |
|
| 3016 | + return; |
|
| 3017 | + } |
|
| 3018 | + $map_option = $option; |
|
| 3019 | + $option = str_replace('-', '_', $option); |
|
| 3020 | + switch ($map_option) { |
|
| 3021 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3022 | + $value = (int)$value; |
|
| 3023 | + if ($value < 1 || $value > 999) { |
|
| 3024 | + return; |
|
| 3025 | + } |
|
| 3026 | + break; |
|
| 3027 | + default: |
|
| 3028 | + $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value); |
|
| 3029 | + if (false === $value) { |
|
| 3030 | + return; |
|
| 3031 | + } |
|
| 3032 | + break; |
|
| 3033 | + } |
|
| 3034 | + update_user_meta($user->ID, $option, $value); |
|
| 3035 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3036 | + exit; |
|
| 3037 | + } |
|
| 3038 | + } |
|
| 3039 | + |
|
| 3040 | + |
|
| 3041 | + |
|
| 3042 | + /** |
|
| 3043 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3044 | + * |
|
| 3045 | + * @param array $data array that will be assigned to template args. |
|
| 3046 | + */ |
|
| 3047 | + public function set_template_args($data) |
|
| 3048 | + { |
|
| 3049 | + $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3050 | + } |
|
| 3051 | + |
|
| 3052 | + |
|
| 3053 | + |
|
| 3054 | + /** |
|
| 3055 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3056 | + * |
|
| 3057 | + * @access protected |
|
| 3058 | + * @param string $route the route that should receive the transient |
|
| 3059 | + * @param array $data the data that gets sent |
|
| 3060 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a normal route transient. |
|
| 3061 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used when we are adding a transient before page_routes have been defined. |
|
| 3062 | + * @return void |
|
| 3063 | + */ |
|
| 3064 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3065 | + { |
|
| 3066 | + $user_id = get_current_user_id(); |
|
| 3067 | + if ( ! $skip_route_verify) { |
|
| 3068 | + $this->_verify_route($route); |
|
| 3069 | + } |
|
| 3070 | + //now let's set the string for what kind of transient we're setting |
|
| 3071 | + $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3072 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3073 | + //is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3074 | + $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3075 | + if ($existing) { |
|
| 3076 | + $data = array_merge((array)$data, (array)$existing); |
|
| 3077 | + } |
|
| 3078 | + if (is_multisite() && is_network_admin()) { |
|
| 3079 | + set_site_transient($transient, $data, 8); |
|
| 3080 | + } else { |
|
| 3081 | + set_transient($transient, $data, 8); |
|
| 3082 | + } |
|
| 3083 | + } |
|
| 3084 | + |
|
| 3085 | + |
|
| 3086 | + |
|
| 3087 | + /** |
|
| 3088 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3089 | + * |
|
| 3090 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3091 | + * @return mixed data |
|
| 3092 | + */ |
|
| 3093 | + protected function _get_transient($notices = false, $route = false) |
|
| 3094 | + { |
|
| 3095 | + $user_id = get_current_user_id(); |
|
| 3096 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3097 | + $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3098 | + $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
|
| 3099 | + //delete transient after retrieval (just in case it hasn't expired); |
|
| 3100 | + if (is_multisite() && is_network_admin()) { |
|
| 3101 | + delete_site_transient($transient); |
|
| 3102 | + } else { |
|
| 3103 | + delete_transient($transient); |
|
| 3104 | + } |
|
| 3105 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3106 | + } |
|
| 3107 | + |
|
| 3108 | + |
|
| 3109 | + |
|
| 3110 | + /** |
|
| 3111 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later. |
|
| 3112 | + * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.) |
|
| 3113 | + * |
|
| 3114 | + * @return void |
|
| 3115 | + */ |
|
| 3116 | + protected function _transient_garbage_collection() |
|
| 3117 | + { |
|
| 3118 | + global $wpdb; |
|
| 3119 | + //retrieve all existing transients |
|
| 3120 | + $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3121 | + if ($results = $wpdb->get_results($query)) { |
|
| 3122 | + foreach ($results as $result) { |
|
| 3123 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3124 | + get_transient($transient); |
|
| 3125 | + if (is_multisite() && is_network_admin()) { |
|
| 3126 | + get_site_transient($transient); |
|
| 3127 | + } |
|
| 3128 | + } |
|
| 3129 | + } |
|
| 3130 | + } |
|
| 3131 | + |
|
| 3132 | + |
|
| 3133 | + |
|
| 3134 | + /** |
|
| 3135 | + * get_view |
|
| 3136 | + * |
|
| 3137 | + * @access public |
|
| 3138 | + * @return string content of _view property |
|
| 3139 | + */ |
|
| 3140 | + public function get_view() |
|
| 3141 | + { |
|
| 3142 | + return $this->_view; |
|
| 3143 | + } |
|
| 3144 | + |
|
| 3145 | + |
|
| 3146 | + |
|
| 3147 | + /** |
|
| 3148 | + * getter for the protected $_views property |
|
| 3149 | + * |
|
| 3150 | + * @return array |
|
| 3151 | + */ |
|
| 3152 | + public function get_views() |
|
| 3153 | + { |
|
| 3154 | + return $this->_views; |
|
| 3155 | + } |
|
| 3156 | + |
|
| 3157 | + |
|
| 3158 | + |
|
| 3159 | + /** |
|
| 3160 | + * get_current_page |
|
| 3161 | + * |
|
| 3162 | + * @access public |
|
| 3163 | + * @return string _current_page property value |
|
| 3164 | + */ |
|
| 3165 | + public function get_current_page() |
|
| 3166 | + { |
|
| 3167 | + return $this->_current_page; |
|
| 3168 | + } |
|
| 3169 | + |
|
| 3170 | + |
|
| 3171 | + |
|
| 3172 | + /** |
|
| 3173 | + * get_current_view |
|
| 3174 | + * |
|
| 3175 | + * @access public |
|
| 3176 | + * @return string _current_view property value |
|
| 3177 | + */ |
|
| 3178 | + public function get_current_view() |
|
| 3179 | + { |
|
| 3180 | + return $this->_current_view; |
|
| 3181 | + } |
|
| 3182 | + |
|
| 3183 | + |
|
| 3184 | + |
|
| 3185 | + /** |
|
| 3186 | + * get_current_screen |
|
| 3187 | + * |
|
| 3188 | + * @access public |
|
| 3189 | + * @return object The current WP_Screen object |
|
| 3190 | + */ |
|
| 3191 | + public function get_current_screen() |
|
| 3192 | + { |
|
| 3193 | + return $this->_current_screen; |
|
| 3194 | + } |
|
| 3195 | + |
|
| 3196 | + |
|
| 3197 | + |
|
| 3198 | + /** |
|
| 3199 | + * get_current_page_view_url |
|
| 3200 | + * |
|
| 3201 | + * @access public |
|
| 3202 | + * @return string This returns the url for the current_page_view. |
|
| 3203 | + */ |
|
| 3204 | + public function get_current_page_view_url() |
|
| 3205 | + { |
|
| 3206 | + return $this->_current_page_view_url; |
|
| 3207 | + } |
|
| 3208 | + |
|
| 3209 | + |
|
| 3210 | + |
|
| 3211 | + /** |
|
| 3212 | + * just returns the _req_data property |
|
| 3213 | + * |
|
| 3214 | + * @return array |
|
| 3215 | + */ |
|
| 3216 | + public function get_request_data() |
|
| 3217 | + { |
|
| 3218 | + return $this->_req_data; |
|
| 3219 | + } |
|
| 3220 | + |
|
| 3221 | + |
|
| 3222 | + |
|
| 3223 | + /** |
|
| 3224 | + * returns the _req_data protected property |
|
| 3225 | + * |
|
| 3226 | + * @return string |
|
| 3227 | + */ |
|
| 3228 | + public function get_req_action() |
|
| 3229 | + { |
|
| 3230 | + return $this->_req_action; |
|
| 3231 | + } |
|
| 3232 | + |
|
| 3233 | + |
|
| 3234 | + |
|
| 3235 | + /** |
|
| 3236 | + * @return bool value of $_is_caf property |
|
| 3237 | + */ |
|
| 3238 | + public function is_caf() |
|
| 3239 | + { |
|
| 3240 | + return $this->_is_caf; |
|
| 3241 | + } |
|
| 3242 | + |
|
| 3243 | + |
|
| 3244 | + |
|
| 3245 | + /** |
|
| 3246 | + * @return mixed |
|
| 3247 | + */ |
|
| 3248 | + public function default_espresso_metaboxes() |
|
| 3249 | + { |
|
| 3250 | + return $this->_default_espresso_metaboxes; |
|
| 3251 | + } |
|
| 3252 | + |
|
| 3253 | + |
|
| 3254 | + |
|
| 3255 | + /** |
|
| 3256 | + * @return mixed |
|
| 3257 | + */ |
|
| 3258 | + public function admin_base_url() |
|
| 3259 | + { |
|
| 3260 | + return $this->_admin_base_url; |
|
| 3261 | + } |
|
| 3262 | + |
|
| 3263 | + |
|
| 3264 | + |
|
| 3265 | + /** |
|
| 3266 | + * @return mixed |
|
| 3267 | + */ |
|
| 3268 | + public function wp_page_slug() |
|
| 3269 | + { |
|
| 3270 | + return $this->_wp_page_slug; |
|
| 3271 | + } |
|
| 3272 | + |
|
| 3273 | + |
|
| 3274 | + |
|
| 3275 | + /** |
|
| 3276 | + * updates espresso configuration settings |
|
| 3277 | + * |
|
| 3278 | + * @access protected |
|
| 3279 | + * @param string $tab |
|
| 3280 | + * @param EE_Config_Base|EE_Config $config |
|
| 3281 | + * @param string $file file where error occurred |
|
| 3282 | + * @param string $func function where error occurred |
|
| 3283 | + * @param string $line line no where error occurred |
|
| 3284 | + * @return boolean |
|
| 3285 | + */ |
|
| 3286 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 3287 | + { |
|
| 3288 | + //remove any options that are NOT going to be saved with the config settings. |
|
| 3289 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 3290 | + $config->core->ee_ueip_has_notified = true; |
|
| 3291 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 3292 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 3293 | + update_option('ee_ueip_has_notified', true); |
|
| 3294 | + } |
|
| 3295 | + // and save it (note we're also doing the network save here) |
|
| 3296 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 3297 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 3298 | + if ($config_saved && $net_saved) { |
|
| 3299 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 3300 | + return true; |
|
| 3301 | + } else { |
|
| 3302 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 3303 | + return false; |
|
| 3304 | + } |
|
| 3305 | + } |
|
| 3306 | + |
|
| 3307 | + |
|
| 3308 | + |
|
| 3309 | + /** |
|
| 3310 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 3311 | + * |
|
| 3312 | + * @return array |
|
| 3313 | + */ |
|
| 3314 | + public function get_yes_no_values() |
|
| 3315 | + { |
|
| 3316 | + return $this->_yes_no_values; |
|
| 3317 | + } |
|
| 3318 | + |
|
| 3319 | + |
|
| 3320 | + |
|
| 3321 | + protected function _get_dir() |
|
| 3322 | + { |
|
| 3323 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 3324 | + return dirname($reflector->getFileName()); |
|
| 3325 | + } |
|
| 3326 | + |
|
| 3327 | + |
|
| 3328 | + |
|
| 3329 | + /** |
|
| 3330 | + * A helper for getting a "next link". |
|
| 3331 | + * |
|
| 3332 | + * @param string $url The url to link to |
|
| 3333 | + * @param string $class The class to use. |
|
| 3334 | + * @return string |
|
| 3335 | + */ |
|
| 3336 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 3337 | + { |
|
| 3338 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3339 | + } |
|
| 3340 | + |
|
| 3341 | + |
|
| 3342 | + |
|
| 3343 | + /** |
|
| 3344 | + * A helper for getting a "previous link". |
|
| 3345 | + * |
|
| 3346 | + * @param string $url The url to link to |
|
| 3347 | + * @param string $class The class to use. |
|
| 3348 | + * @return string |
|
| 3349 | + */ |
|
| 3350 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 3351 | + { |
|
| 3352 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3353 | + } |
|
| 3354 | + |
|
| 3355 | + |
|
| 3356 | + |
|
| 3357 | + |
|
| 3358 | + |
|
| 3359 | + |
|
| 3360 | + |
|
| 3361 | + //below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 3362 | + /** |
|
| 3363 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller 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 _req_data |
|
| 3364 | + * array. |
|
| 3365 | + * |
|
| 3366 | + * @return bool success/fail |
|
| 3367 | + */ |
|
| 3368 | + protected function _process_resend_registration() |
|
| 3369 | + { |
|
| 3370 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 3371 | + do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data); |
|
| 3372 | + return $this->_template_args['success']; |
|
| 3373 | + } |
|
| 3374 | + |
|
| 3375 | + |
|
| 3376 | + |
|
| 3377 | + /** |
|
| 3378 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 3379 | + * |
|
| 3380 | + * @access protected |
|
| 3381 | + * @param \EE_Payment $payment |
|
| 3382 | + * @return bool success/fail |
|
| 3383 | + */ |
|
| 3384 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 3385 | + { |
|
| 3386 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 3387 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 3388 | + $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment); |
|
| 3389 | + return $this->_template_args['success']; |
|
| 3390 | + } |
|
| 3391 | 3391 | |
| 3392 | 3392 | |
| 3393 | 3393 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
| 474 | 474 | $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this)))); |
| 475 | 475 | global $ee_menu_slugs; |
| 476 | - $ee_menu_slugs = (array)$ee_menu_slugs; |
|
| 476 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 477 | 477 | if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) { |
| 478 | 478 | return false; |
| 479 | 479 | } |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
| 489 | 489 | $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action; |
| 490 | 490 | $this->_current_view = $this->_req_action; |
| 491 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 491 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 492 | 492 | $this->_define_page_props(); |
| 493 | 493 | $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url); |
| 494 | 494 | //default things |
@@ -509,11 +509,11 @@ discard block |
||
| 509 | 509 | $this->_extend_page_config_for_cpt(); |
| 510 | 510 | } |
| 511 | 511 | //filter routes and page_config so addons can add their stuff. Filtering done per class |
| 512 | - $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | - $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this); |
|
| 512 | + $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this); |
|
| 513 | + $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this); |
|
| 514 | 514 | //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 515 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 516 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2); |
|
| 515 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 516 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2); |
|
| 517 | 517 | } |
| 518 | 518 | //next route only if routing enabled |
| 519 | 519 | if ($this->_routing && ! defined('DOING_AJAX')) { |
@@ -523,8 +523,8 @@ discard block |
||
| 523 | 523 | if ($this->_is_UI_request) { |
| 524 | 524 | //admin_init stuff - global, all views for this page class, specific view |
| 525 | 525 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 526 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 527 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 526 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 527 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 528 | 528 | } |
| 529 | 529 | } else { |
| 530 | 530 | //hijack regular WP loading and route admin request immediately |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | private function _do_other_page_hooks() |
| 546 | 546 | { |
| 547 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 547 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 548 | 548 | foreach ($registered_pages as $page) { |
| 549 | 549 | //now let's setup the file name and class that should be present |
| 550 | 550 | $classname = str_replace('.class.php', '', $page); |
@@ -590,13 +590,13 @@ discard block |
||
| 590 | 590 | //load admin_notices - global, page class, and view specific |
| 591 | 591 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 592 | 592 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 593 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 594 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 593 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 594 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 595 | 595 | } |
| 596 | 596 | //load network admin_notices - global, page class, and view specific |
| 597 | 597 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 598 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 599 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 598 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 599 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 600 | 600 | } |
| 601 | 601 | //this will save any per_page screen options if they are present |
| 602 | 602 | $this->_set_per_page_screen_options(); |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | //add screen options - global, page child class, and view specific |
| 609 | 609 | $this->_add_global_screen_options(); |
| 610 | 610 | $this->_add_screen_options(); |
| 611 | - if (method_exists($this, '_add_screen_options_' . $this->_current_view)) { |
|
| 612 | - call_user_func(array($this, '_add_screen_options_' . $this->_current_view)); |
|
| 611 | + if (method_exists($this, '_add_screen_options_'.$this->_current_view)) { |
|
| 612 | + call_user_func(array($this, '_add_screen_options_'.$this->_current_view)); |
|
| 613 | 613 | } |
| 614 | 614 | //add help tab(s) and tours- set via page_config and qtips. |
| 615 | 615 | $this->_add_help_tour(); |
@@ -618,31 +618,31 @@ discard block |
||
| 618 | 618 | //add feature_pointers - global, page child class, and view specific |
| 619 | 619 | $this->_add_feature_pointers(); |
| 620 | 620 | $this->_add_global_feature_pointers(); |
| 621 | - if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) { |
|
| 622 | - call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view)); |
|
| 621 | + if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) { |
|
| 622 | + call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view)); |
|
| 623 | 623 | } |
| 624 | 624 | //enqueue scripts/styles - global, page class, and view specific |
| 625 | 625 | add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
| 626 | 626 | add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
| 627 | - if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) { |
|
| 628 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15); |
|
| 627 | + if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) { |
|
| 628 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15); |
|
| 629 | 629 | } |
| 630 | 630 | add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
| 631 | 631 | //admin_print_footer_scripts - global, page child class, and view specific. NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. In most cases that's doing_it_wrong(). But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these |
| 632 | 632 | add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
| 633 | 633 | add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
| 634 | - if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) { |
|
| 635 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101); |
|
| 634 | + if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) { |
|
| 635 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101); |
|
| 636 | 636 | } |
| 637 | 637 | //admin footer scripts |
| 638 | 638 | add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
| 639 | 639 | add_action('admin_footer', array($this, 'admin_footer'), 100); |
| 640 | - if (method_exists($this, 'admin_footer_' . $this->_current_view)) { |
|
| 641 | - add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101); |
|
| 640 | + if (method_exists($this, 'admin_footer_'.$this->_current_view)) { |
|
| 641 | + add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101); |
|
| 642 | 642 | } |
| 643 | 643 | do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
| 644 | 644 | //targeted hook |
| 645 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action); |
|
| 645 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | // user error msg |
| 719 | 719 | $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 720 | 720 | // developer error msg |
| 721 | - $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 721 | + $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso'); |
|
| 722 | 722 | throw new EE_Error($error_msg); |
| 723 | 723 | } |
| 724 | 724 | // and that the requested page route exists |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | // user error msg |
| 730 | 730 | $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 731 | 731 | // developer error msg |
| 732 | - $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 732 | + $error_msg .= '||'.$error_msg.sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action); |
|
| 733 | 733 | throw new EE_Error($error_msg); |
| 734 | 734 | } |
| 735 | 735 | // and that a default route exists |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | // user error msg |
| 738 | 738 | $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title); |
| 739 | 739 | // developer error msg |
| 740 | - $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 740 | + $error_msg .= '||'.$error_msg.__(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso'); |
|
| 741 | 741 | throw new EE_Error($error_msg); |
| 742 | 742 | } |
| 743 | 743 | //first lets' catch if the UI request has EVER been set. |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | // user error msg |
| 767 | 767 | $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title); |
| 768 | 768 | // developer error msg |
| 769 | - $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 769 | + $error_msg .= '||'.$error_msg.sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route); |
|
| 770 | 770 | throw new EE_Error($error_msg); |
| 771 | 771 | } |
| 772 | 772 | } |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | // these are not the droids you are looking for !!! |
| 789 | 789 | $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>'); |
| 790 | 790 | if (WP_DEBUG) { |
| 791 | - $msg .= "\n " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 791 | + $msg .= "\n ".sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__); |
|
| 792 | 792 | } |
| 793 | 793 | if ( ! defined('DOING_AJAX')) { |
| 794 | 794 | wp_die($msg); |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | if (strpos($key, 'nonce') !== false) { |
| 964 | 964 | continue; |
| 965 | 965 | } |
| 966 | - $args['wp_referer[' . $key . ']'] = $value; |
|
| 966 | + $args['wp_referer['.$key.']'] = $value; |
|
| 967 | 967 | } |
| 968 | 968 | } |
| 969 | 969 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | if ($tour instanceof EE_Help_Tour_final_stop) { |
| 1010 | 1010 | continue; |
| 1011 | 1011 | } |
| 1012 | - $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>'; |
|
| 1012 | + $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>'; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | $tour_buttons .= implode('<br />', $tb); |
| 1015 | 1015 | $tour_buttons .= '</div></div>'; |
@@ -1021,7 +1021,7 @@ discard block |
||
| 1021 | 1021 | throw new EE_Error(sprintf(__('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', |
| 1022 | 1022 | 'event_espresso'), $config['help_sidebar'], get_class($this))); |
| 1023 | 1023 | } |
| 1024 | - $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1024 | + $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar']))); |
|
| 1025 | 1025 | $content .= $tour_buttons; //add help tour buttons. |
| 1026 | 1026 | //do we have any help tours setup? Cause if we do we want to add the buttons |
| 1027 | 1027 | $this->_current_screen->set_help_sidebar($content); |
@@ -1034,13 +1034,13 @@ discard block |
||
| 1034 | 1034 | if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
| 1035 | 1035 | $_ht['id'] = $this->page_slug; |
| 1036 | 1036 | $_ht['title'] = __('Help Tours', 'event_espresso'); |
| 1037 | - $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>'; |
|
| 1037 | + $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>'; |
|
| 1038 | 1038 | $this->_current_screen->add_help_tab($_ht); |
| 1039 | 1039 | }/**/ |
| 1040 | 1040 | if ( ! isset($config['help_tabs'])) { |
| 1041 | 1041 | return; |
| 1042 | 1042 | } //no help tabs for this route |
| 1043 | - foreach ((array)$config['help_tabs'] as $tab_id => $cfg) { |
|
| 1043 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1044 | 1044 | //we're here so there ARE help tabs! |
| 1045 | 1045 | //make sure we've got what we need |
| 1046 | 1046 | if ( ! isset($cfg['title'])) { |
@@ -1055,9 +1055,9 @@ discard block |
||
| 1055 | 1055 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1056 | 1056 | //second priority goes to filename |
| 1057 | 1057 | } else if ( ! empty($cfg['filename'])) { |
| 1058 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1058 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1059 | 1059 | //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) |
| 1060 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path; |
|
| 1060 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path; |
|
| 1061 | 1061 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1062 | 1062 | if ( ! is_readable($file_path) && ! isset($cfg['callback'])) { |
| 1063 | 1063 | EE_Error::add_error(sprintf(__('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', |
@@ -1076,7 +1076,7 @@ discard block |
||
| 1076 | 1076 | return; |
| 1077 | 1077 | } |
| 1078 | 1078 | //setup config array for help tab method |
| 1079 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1079 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1080 | 1080 | $_ht = array( |
| 1081 | 1081 | 'id' => $id, |
| 1082 | 1082 | 'title' => $cfg['title'], |
@@ -1114,9 +1114,9 @@ discard block |
||
| 1114 | 1114 | } |
| 1115 | 1115 | if (isset($config['help_tour'])) { |
| 1116 | 1116 | foreach ($config['help_tour'] as $tour) { |
| 1117 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1117 | + $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php'; |
|
| 1118 | 1118 | //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent |
| 1119 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path; |
|
| 1119 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path; |
|
| 1120 | 1120 | //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1121 | 1121 | if ( ! is_readable($file_path)) { |
| 1122 | 1122 | EE_Error::add_error(sprintf(__('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', 'event_espresso'), |
@@ -1126,7 +1126,7 @@ discard block |
||
| 1126 | 1126 | require_once $file_path; |
| 1127 | 1127 | if ( ! class_exists($tour)) { |
| 1128 | 1128 | $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour); |
| 1129 | - $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('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.', |
|
| 1129 | + $error_msg[] = $error_msg[0]."\r\n".sprintf(__('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.', |
|
| 1130 | 1130 | 'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this)); |
| 1131 | 1131 | throw new EE_Error(implode('||', $error_msg)); |
| 1132 | 1132 | } |
@@ -1158,11 +1158,11 @@ discard block |
||
| 1158 | 1158 | protected function _add_qtips() |
| 1159 | 1159 | { |
| 1160 | 1160 | if (isset($this->_route_config['qtips'])) { |
| 1161 | - $qtips = (array)$this->_route_config['qtips']; |
|
| 1161 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1162 | 1162 | //load qtip loader |
| 1163 | 1163 | $path = array( |
| 1164 | - $this->_get_dir() . '/qtips/', |
|
| 1165 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1164 | + $this->_get_dir().'/qtips/', |
|
| 1165 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1166 | 1166 | ); |
| 1167 | 1167 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
| 1168 | 1168 | } |
@@ -1192,11 +1192,11 @@ discard block |
||
| 1192 | 1192 | if ( ! $this->check_user_access($slug, true)) { |
| 1193 | 1193 | continue; |
| 1194 | 1194 | } //no nav tab becasue current user does not have access. |
| 1195 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1195 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1196 | 1196 | $this->_nav_tabs[$slug] = array( |
| 1197 | 1197 | 'url' => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url), |
| 1198 | 1198 | 'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)), |
| 1199 | - 'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1199 | + 'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1200 | 1200 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1201 | 1201 | ); |
| 1202 | 1202 | $i++; |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | $capability = empty($capability) ? 'manage_options' : $capability; |
| 1260 | 1260 | } |
| 1261 | 1261 | $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
| 1262 | - if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1262 | + if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) { |
|
| 1263 | 1263 | if ($verify_only) { |
| 1264 | 1264 | return false; |
| 1265 | 1265 | } else { |
@@ -1351,7 +1351,7 @@ discard block |
||
| 1351 | 1351 | public function admin_footer_global() |
| 1352 | 1352 | { |
| 1353 | 1353 | //dialog container for dialog helper |
| 1354 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1354 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1355 | 1355 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1356 | 1356 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1357 | 1357 | $d_cont .= '</div>'; |
@@ -1361,7 +1361,7 @@ discard block |
||
| 1361 | 1361 | echo implode('<br />', $this->_help_tour[$this->_req_action]); |
| 1362 | 1362 | } |
| 1363 | 1363 | //current set timezone for timezone js |
| 1364 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1364 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | 1367 | |
@@ -1386,7 +1386,7 @@ discard block |
||
| 1386 | 1386 | { |
| 1387 | 1387 | $content = ''; |
| 1388 | 1388 | $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
| 1389 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php'; |
|
| 1389 | + $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php'; |
|
| 1390 | 1390 | //loop through the array and setup content |
| 1391 | 1391 | foreach ($help_array as $trigger => $help) { |
| 1392 | 1392 | //make sure the array is setup properly |
@@ -1420,7 +1420,7 @@ discard block |
||
| 1420 | 1420 | private function _get_help_content() |
| 1421 | 1421 | { |
| 1422 | 1422 | //what is the method we're looking for? |
| 1423 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1423 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1424 | 1424 | //if method doesn't exist let's get out. |
| 1425 | 1425 | if ( ! method_exists($this, $method_name)) { |
| 1426 | 1426 | return array(); |
@@ -1464,8 +1464,8 @@ discard block |
||
| 1464 | 1464 | $help_content = $this->_set_help_popup_content($help_array, false); |
| 1465 | 1465 | } |
| 1466 | 1466 | //let's setup the trigger |
| 1467 | - $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1468 | - $content = $content . $help_content; |
|
| 1467 | + $content = '<a class="ee-dialog" href="?height='.$dimensions[0].'&width='.$dimensions[1].'&inlineId='.$trigger_id.'" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1468 | + $content = $content.$help_content; |
|
| 1469 | 1469 | if ($display) { |
| 1470 | 1470 | echo $content; |
| 1471 | 1471 | } else { |
@@ -1525,32 +1525,32 @@ discard block |
||
| 1525 | 1525 | add_action('admin_head', array($this, 'add_xdebug_style')); |
| 1526 | 1526 | } |
| 1527 | 1527 | //register all styles |
| 1528 | - wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1529 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1528 | + wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1529 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1530 | 1530 | //helpers styles |
| 1531 | - wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1531 | + wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1532 | 1532 | //enqueue global styles |
| 1533 | 1533 | wp_enqueue_style('ee-admin-css'); |
| 1534 | 1534 | /** SCRIPTS **/ |
| 1535 | 1535 | //register all scripts |
| 1536 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1537 | - wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1538 | - wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1539 | - wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1536 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1537 | + wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1538 | + wp_register_script('ee_admin_js', EE_ADMIN_URL.'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
| 1539 | + wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true); |
|
| 1540 | 1540 | // register jQuery Validate - see /includes/functions/wp_hooks.php |
| 1541 | 1541 | add_filter('FHEE_load_jquery_validate', '__return_true'); |
| 1542 | 1542 | add_filter('FHEE_load_joyride', '__return_true'); |
| 1543 | 1543 | //script for sorting tables |
| 1544 | - wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1544 | + wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL."assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 1545 | 1545 | //script for parsing uri's |
| 1546 | - wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1546 | + wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1547 | 1547 | //and parsing associative serialized form elements |
| 1548 | - wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1548 | + wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1549 | 1549 | //helpers scripts |
| 1550 | - wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1551 | - wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | - wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1553 | - wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1550 | + wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); |
|
| 1551 | + wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true); |
|
| 1552 | + wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 1553 | + wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true); |
|
| 1554 | 1554 | //google charts |
| 1555 | 1555 | wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false); |
| 1556 | 1556 | //enqueue global scripts |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | */ |
| 1572 | 1572 | if ( ! empty($this->_help_tour)) { |
| 1573 | 1573 | //register the js for kicking things off |
| 1574 | - wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1574 | + wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true); |
|
| 1575 | 1575 | //setup tours for the js tour object |
| 1576 | 1576 | foreach ($this->_help_tour['tours'] as $tour) { |
| 1577 | 1577 | $tours[] = array( |
@@ -1670,17 +1670,17 @@ discard block |
||
| 1670 | 1670 | return; |
| 1671 | 1671 | } //not a list_table view so get out. |
| 1672 | 1672 | //list table functions are per view specific (because some admin pages might have more than one listtable!) |
| 1673 | - if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) { |
|
| 1673 | + if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) { |
|
| 1674 | 1674 | //user error msg |
| 1675 | 1675 | $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso'); |
| 1676 | 1676 | //developer error msg |
| 1677 | - $error_msg .= '||' . sprintf(__('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.', 'event_espresso'), |
|
| 1678 | - $this->_req_action, '_set_list_table_views_' . $this->_req_action); |
|
| 1677 | + $error_msg .= '||'.sprintf(__('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.', 'event_espresso'), |
|
| 1678 | + $this->_req_action, '_set_list_table_views_'.$this->_req_action); |
|
| 1679 | 1679 | throw new EE_Error($error_msg); |
| 1680 | 1680 | } |
| 1681 | 1681 | //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 1682 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views); |
|
| 1683 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 1682 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views); |
|
| 1683 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 1684 | 1684 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 1685 | 1685 | $this->_set_list_table_view(); |
| 1686 | 1686 | $this->_set_list_table_object(); |
@@ -1755,7 +1755,7 @@ discard block |
||
| 1755 | 1755 | // check for current view |
| 1756 | 1756 | $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : ''; |
| 1757 | 1757 | $query_args['action'] = $this->_req_action; |
| 1758 | - $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 1758 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 1759 | 1759 | $query_args['status'] = $view['slug']; |
| 1760 | 1760 | //merge any other arguments sent in. |
| 1761 | 1761 | if (isset($extra_query_args[$view['slug']])) { |
@@ -1793,14 +1793,14 @@ discard block |
||
| 1793 | 1793 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 1794 | 1794 | foreach ($values as $value) { |
| 1795 | 1795 | if ($value < $max_entries) { |
| 1796 | - $selected = $value == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1796 | + $selected = $value == $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 1797 | 1797 | $entries_per_page_dropdown .= ' |
| 1798 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 1798 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 1799 | 1799 | } |
| 1800 | 1800 | } |
| 1801 | - $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 1801 | + $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 1802 | 1802 | $entries_per_page_dropdown .= ' |
| 1803 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 1803 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 1804 | 1804 | $entries_per_page_dropdown .= ' |
| 1805 | 1805 | </select> |
| 1806 | 1806 | entries |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | public function _set_search_attributes() |
| 1823 | 1823 | { |
| 1824 | 1824 | $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label); |
| 1825 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 1825 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 1826 | 1826 | } |
| 1827 | 1827 | |
| 1828 | 1828 | /*** END LIST TABLE METHODS **/ |
@@ -1860,7 +1860,7 @@ discard block |
||
| 1860 | 1860 | // user error msg |
| 1861 | 1861 | $error_msg = __('An error occurred. The requested metabox could not be found.', 'event_espresso'); |
| 1862 | 1862 | // developer error msg |
| 1863 | - $error_msg .= '||' . sprintf( |
|
| 1863 | + $error_msg .= '||'.sprintf( |
|
| 1864 | 1864 | __( |
| 1865 | 1865 | '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.', |
| 1866 | 1866 | 'event_espresso' |
@@ -1890,15 +1890,15 @@ discard block |
||
| 1890 | 1890 | && is_array($this->_route_config['columns']) |
| 1891 | 1891 | && count($this->_route_config['columns']) === 2 |
| 1892 | 1892 | ) { |
| 1893 | - add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1])); |
|
| 1893 | + add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1])); |
|
| 1894 | 1894 | $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
| 1895 | 1895 | $screen_id = $this->_current_screen->id; |
| 1896 | - $screen_columns = (int)get_user_option("screen_layout_$screen_id"); |
|
| 1896 | + $screen_columns = (int) get_user_option("screen_layout_$screen_id"); |
|
| 1897 | 1897 | $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1]; |
| 1898 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 1898 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 1899 | 1899 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 1900 | 1900 | $this->_template_args['screen'] = $this->_current_screen; |
| 1901 | - $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 1901 | + $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php'; |
|
| 1902 | 1902 | //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
| 1903 | 1903 | $this->_route_config['has_metaboxes'] = true; |
| 1904 | 1904 | } |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | */ |
| 1946 | 1946 | public function espresso_ratings_request() |
| 1947 | 1947 | { |
| 1948 | - $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'; |
|
| 1948 | + $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'; |
|
| 1949 | 1949 | EEH_Template::display_template($template_path, array()); |
| 1950 | 1950 | } |
| 1951 | 1951 | |
@@ -1953,18 +1953,18 @@ discard block |
||
| 1953 | 1953 | |
| 1954 | 1954 | public static function cached_rss_display($rss_id, $url) |
| 1955 | 1955 | { |
| 1956 | - $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading…') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>'; |
|
| 1956 | + $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading…').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>'; |
|
| 1957 | 1957 | $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX); |
| 1958 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 1959 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 1960 | - $post = '</div>' . "\n"; |
|
| 1961 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 1958 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 1959 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 1960 | + $post = '</div>'."\n"; |
|
| 1961 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 1962 | 1962 | if (false != ($output = get_transient($cache_key))) { |
| 1963 | - echo $pre . $output . $post; |
|
| 1963 | + echo $pre.$output.$post; |
|
| 1964 | 1964 | return true; |
| 1965 | 1965 | } |
| 1966 | 1966 | if ( ! $doing_ajax) { |
| 1967 | - echo $pre . $loading . $post; |
|
| 1967 | + echo $pre.$loading.$post; |
|
| 1968 | 1968 | return false; |
| 1969 | 1969 | } |
| 1970 | 1970 | ob_start(); |
@@ -2023,7 +2023,7 @@ discard block |
||
| 2023 | 2023 | |
| 2024 | 2024 | public function espresso_sponsors_post_box() |
| 2025 | 2025 | { |
| 2026 | - $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2026 | + $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'; |
|
| 2027 | 2027 | EEH_Template::display_template($templatepath); |
| 2028 | 2028 | } |
| 2029 | 2029 | |
@@ -2031,7 +2031,7 @@ discard block |
||
| 2031 | 2031 | |
| 2032 | 2032 | private function _publish_post_box() |
| 2033 | 2033 | { |
| 2034 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2034 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2035 | 2035 | //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label. Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2036 | 2036 | if ( ! empty($this->_labels['publishbox'])) { |
| 2037 | 2037 | $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
@@ -2048,7 +2048,7 @@ discard block |
||
| 2048 | 2048 | { |
| 2049 | 2049 | //if we have extra content set let's add it in if not make sure its empty |
| 2050 | 2050 | $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : ''; |
| 2051 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php'; |
|
| 2051 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php'; |
|
| 2052 | 2052 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2053 | 2053 | } |
| 2054 | 2054 | |
@@ -2217,7 +2217,7 @@ discard block |
||
| 2217 | 2217 | //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) |
| 2218 | 2218 | $call_back_func = $create_func ? create_function('$post, $metabox', |
| 2219 | 2219 | 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback; |
| 2220 | - add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2220 | + add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args); |
|
| 2221 | 2221 | } |
| 2222 | 2222 | |
| 2223 | 2223 | |
@@ -2297,10 +2297,10 @@ discard block |
||
| 2297 | 2297 | ? 'poststuff' |
| 2298 | 2298 | : 'espresso-default-admin'; |
| 2299 | 2299 | $template_path = $sidebar |
| 2300 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2301 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2300 | + ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php' |
|
| 2301 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2302 | 2302 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2303 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2303 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2304 | 2304 | } |
| 2305 | 2305 | $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path; |
| 2306 | 2306 | $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : ''; |
@@ -2346,7 +2346,7 @@ discard block |
||
| 2346 | 2346 | true |
| 2347 | 2347 | ) |
| 2348 | 2348 | : $this->_template_args['preview_action_button']; |
| 2349 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php'; |
|
| 2349 | + $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php'; |
|
| 2350 | 2350 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2351 | 2351 | $template_path, |
| 2352 | 2352 | $this->_template_args, |
@@ -2397,7 +2397,7 @@ discard block |
||
| 2397 | 2397 | //setup search attributes |
| 2398 | 2398 | $this->_set_search_attributes(); |
| 2399 | 2399 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2400 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2400 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2401 | 2401 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 2402 | 2402 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 2403 | 2403 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2407,37 +2407,37 @@ discard block |
||
| 2407 | 2407 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2408 | 2408 | if ( ! empty($ajax_sorting_callback)) { |
| 2409 | 2409 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2410 | - $ajax_sorting_callback . '_nonce', |
|
| 2411 | - $ajax_sorting_callback . '_nonce', |
|
| 2410 | + $ajax_sorting_callback.'_nonce', |
|
| 2411 | + $ajax_sorting_callback.'_nonce', |
|
| 2412 | 2412 | false, |
| 2413 | 2413 | false |
| 2414 | 2414 | ); |
| 2415 | 2415 | // $reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce'; |
| 2416 | 2416 | // $sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE ); |
| 2417 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />'; |
|
| 2418 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />'; |
|
| 2417 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />'; |
|
| 2418 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />'; |
|
| 2419 | 2419 | } else { |
| 2420 | 2420 | $sortable_list_table_form_fields = ''; |
| 2421 | 2421 | } |
| 2422 | 2422 | $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
| 2423 | 2423 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : ''; |
| 2424 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 2425 | - $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">'; |
|
| 2424 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 2425 | + $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">'; |
|
| 2426 | 2426 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 2427 | 2427 | //display message about search results? |
| 2428 | 2428 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 2429 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 2429 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 2430 | 2430 | __('Displaying search results for the search string: <strong><em>%s</em></strong>', |
| 2431 | 2431 | 'event_espresso'), |
| 2432 | 2432 | trim($this->_req_data['s'], '%') |
| 2433 | - ) . '</p>' |
|
| 2433 | + ).'</p>' |
|
| 2434 | 2434 | : ''; |
| 2435 | 2435 | // filter before_list_table template arg |
| 2436 | 2436 | $this->_template_args['before_list_table'] = implode( |
| 2437 | 2437 | " \n", |
| 2438 | - (array)apply_filters( |
|
| 2438 | + (array) apply_filters( |
|
| 2439 | 2439 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
| 2440 | - (array)$this->_template_args['before_list_table'], |
|
| 2440 | + (array) $this->_template_args['before_list_table'], |
|
| 2441 | 2441 | $this->page_slug, |
| 2442 | 2442 | $this->_req_data, |
| 2443 | 2443 | $this->_req_action |
@@ -2446,9 +2446,9 @@ discard block |
||
| 2446 | 2446 | // filter after_list_table template arg |
| 2447 | 2447 | $this->_template_args['after_list_table'] = implode( |
| 2448 | 2448 | " \n", |
| 2449 | - (array)apply_filters( |
|
| 2449 | + (array) apply_filters( |
|
| 2450 | 2450 | 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
| 2451 | - (array)$this->_template_args['after_list_table'], |
|
| 2451 | + (array) $this->_template_args['after_list_table'], |
|
| 2452 | 2452 | $this->page_slug, |
| 2453 | 2453 | $this->_req_data, |
| 2454 | 2454 | $this->_req_action |
@@ -2484,8 +2484,8 @@ discard block |
||
| 2484 | 2484 | */ |
| 2485 | 2485 | protected function _display_legend($items) |
| 2486 | 2486 | { |
| 2487 | - $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this); |
|
| 2488 | - $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php'; |
|
| 2487 | + $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this); |
|
| 2488 | + $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php'; |
|
| 2489 | 2489 | return EEH_Template::display_template($legend_template, $this->_template_args, true); |
| 2490 | 2490 | } |
| 2491 | 2491 | |
@@ -2580,15 +2580,15 @@ discard block |
||
| 2580 | 2580 | $this->_nav_tabs = $this->_get_main_nav_tabs(); |
| 2581 | 2581 | $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
| 2582 | 2582 | $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
| 2583 | - $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2583 | + $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view, |
|
| 2584 | 2584 | isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : ''); |
| 2585 | - $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view, |
|
| 2585 | + $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view, |
|
| 2586 | 2586 | isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : ''); |
| 2587 | 2587 | $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
| 2588 | 2588 | // load settings page wrapper template |
| 2589 | - $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 2589 | + $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php'; |
|
| 2590 | 2590 | //about page? |
| 2591 | - $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path; |
|
| 2591 | + $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path; |
|
| 2592 | 2592 | if (defined('DOING_AJAX')) { |
| 2593 | 2593 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2594 | 2594 | $this->_return_json(); |
@@ -2660,20 +2660,20 @@ discard block |
||
| 2660 | 2660 | protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
| 2661 | 2661 | { |
| 2662 | 2662 | //make sure $text and $actions are in an array |
| 2663 | - $text = (array)$text; |
|
| 2664 | - $actions = (array)$actions; |
|
| 2663 | + $text = (array) $text; |
|
| 2664 | + $actions = (array) $actions; |
|
| 2665 | 2665 | $referrer_url = empty($referrer) ? '' : $referrer; |
| 2666 | - $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />' |
|
| 2667 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />'; |
|
| 2666 | + $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />' |
|
| 2667 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />'; |
|
| 2668 | 2668 | $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso')); |
| 2669 | 2669 | $default_names = array('save', 'save_and_close'); |
| 2670 | 2670 | //add in a hidden index for the current page (so save and close redirects properly) |
| 2671 | 2671 | $this->_template_args['save_buttons'] = $referrer_url; |
| 2672 | 2672 | foreach ($button_text as $key => $button) { |
| 2673 | 2673 | $ref = $default_names[$key]; |
| 2674 | - $id = $this->_current_view . '_' . $ref; |
|
| 2674 | + $id = $this->_current_view.'_'.$ref; |
|
| 2675 | 2675 | $name = ! empty($actions) ? $actions[$key] : $ref; |
| 2676 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />'; |
|
| 2676 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />'; |
|
| 2677 | 2677 | if ( ! $both) { |
| 2678 | 2678 | break; |
| 2679 | 2679 | } |
@@ -2709,15 +2709,15 @@ discard block |
||
| 2709 | 2709 | { |
| 2710 | 2710 | if (empty($route)) { |
| 2711 | 2711 | $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso'); |
| 2712 | - $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2713 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2712 | + $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__); |
|
| 2713 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2714 | 2714 | } |
| 2715 | 2715 | // open form |
| 2716 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >'; |
|
| 2716 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >'; |
|
| 2717 | 2717 | // add nonce |
| 2718 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 2718 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 2719 | 2719 | // $nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE ); |
| 2720 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 2720 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 2721 | 2721 | // add REQUIRED form action |
| 2722 | 2722 | $hidden_fields = array( |
| 2723 | 2723 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -2727,8 +2727,8 @@ discard block |
||
| 2727 | 2727 | // generate form fields |
| 2728 | 2728 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 2729 | 2729 | // add fields to form |
| 2730 | - foreach ((array)$form_fields as $field_name => $form_field) { |
|
| 2731 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 2730 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 2731 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 2732 | 2732 | } |
| 2733 | 2733 | // close form |
| 2734 | 2734 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -2809,7 +2809,7 @@ discard block |
||
| 2809 | 2809 | * @param array $query_args The original query_args array coming into the |
| 2810 | 2810 | * method. |
| 2811 | 2811 | */ |
| 2812 | - do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args); |
|
| 2812 | + do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args); |
|
| 2813 | 2813 | //calculate where we're going (if we have a "save and close" button pushed) |
| 2814 | 2814 | if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) { |
| 2815 | 2815 | // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
@@ -2825,7 +2825,7 @@ discard block |
||
| 2825 | 2825 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 2826 | 2826 | //is there a wp_referer array in our _default_route_query_args property? |
| 2827 | 2827 | if ($query_param == 'wp_referer') { |
| 2828 | - $query_value = (array)$query_value; |
|
| 2828 | + $query_value = (array) $query_value; |
|
| 2829 | 2829 | foreach ($query_value as $reference => $value) { |
| 2830 | 2830 | if (strpos($reference, 'nonce') !== false) { |
| 2831 | 2831 | continue; |
@@ -2851,11 +2851,11 @@ discard block |
||
| 2851 | 2851 | // if redirecting to anything other than the main page, add a nonce |
| 2852 | 2852 | if (isset($query_args['action'])) { |
| 2853 | 2853 | // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars |
| 2854 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2854 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2855 | 2855 | } |
| 2856 | 2856 | //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that). |
| 2857 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 2858 | - $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2857 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 2858 | + $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args); |
|
| 2859 | 2859 | // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
| 2860 | 2860 | if (defined('DOING_AJAX')) { |
| 2861 | 2861 | $default_data = array( |
@@ -2985,7 +2985,7 @@ discard block |
||
| 2985 | 2985 | $args = array( |
| 2986 | 2986 | 'label' => $this->_admin_page_title, |
| 2987 | 2987 | 'default' => 10, |
| 2988 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 2988 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 2989 | 2989 | ); |
| 2990 | 2990 | //ONLY add the screen option if the user has access to it. |
| 2991 | 2991 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3018,8 +3018,8 @@ discard block |
||
| 3018 | 3018 | $map_option = $option; |
| 3019 | 3019 | $option = str_replace('-', '_', $option); |
| 3020 | 3020 | switch ($map_option) { |
| 3021 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3022 | - $value = (int)$value; |
|
| 3021 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3022 | + $value = (int) $value; |
|
| 3023 | 3023 | if ($value < 1 || $value > 999) { |
| 3024 | 3024 | return; |
| 3025 | 3025 | } |
@@ -3046,7 +3046,7 @@ discard block |
||
| 3046 | 3046 | */ |
| 3047 | 3047 | public function set_template_args($data) |
| 3048 | 3048 | { |
| 3049 | - $this->_template_args = array_merge($this->_template_args, (array)$data); |
|
| 3049 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3050 | 3050 | } |
| 3051 | 3051 | |
| 3052 | 3052 | |
@@ -3068,12 +3068,12 @@ discard block |
||
| 3068 | 3068 | $this->_verify_route($route); |
| 3069 | 3069 | } |
| 3070 | 3070 | //now let's set the string for what kind of transient we're setting |
| 3071 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3071 | + $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3072 | 3072 | $data = $notices ? array('notices' => $data) : $data; |
| 3073 | 3073 | //is there already a transient for this route? If there is then let's ADD to that transient |
| 3074 | 3074 | $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
| 3075 | 3075 | if ($existing) { |
| 3076 | - $data = array_merge((array)$data, (array)$existing); |
|
| 3076 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3077 | 3077 | } |
| 3078 | 3078 | if (is_multisite() && is_network_admin()) { |
| 3079 | 3079 | set_site_transient($transient, $data, 8); |
@@ -3094,7 +3094,7 @@ discard block |
||
| 3094 | 3094 | { |
| 3095 | 3095 | $user_id = get_current_user_id(); |
| 3096 | 3096 | $route = ! $route ? $this->_req_action : $route; |
| 3097 | - $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3097 | + $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3098 | 3098 | $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient); |
| 3099 | 3099 | //delete transient after retrieval (just in case it hasn't expired); |
| 3100 | 3100 | if (is_multisite() && is_network_admin()) { |
@@ -3335,7 +3335,7 @@ discard block |
||
| 3335 | 3335 | */ |
| 3336 | 3336 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 3337 | 3337 | { |
| 3338 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3338 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3339 | 3339 | } |
| 3340 | 3340 | |
| 3341 | 3341 | |
@@ -3349,7 +3349,7 @@ discard block |
||
| 3349 | 3349 | */ |
| 3350 | 3350 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 3351 | 3351 | { |
| 3352 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 3352 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 3353 | 3353 | } |
| 3354 | 3354 | |
| 3355 | 3355 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('ABSPATH')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /* |
| 5 | 5 | Plugin Name: Event Espresso |
@@ -40,239 +40,239 @@ discard block |
||
| 40 | 40 | * @since 4.0 |
| 41 | 41 | */ |
| 42 | 42 | if (function_exists('espresso_version')) { |
| 43 | - /** |
|
| 44 | - * espresso_duplicate_plugin_error |
|
| 45 | - * displays if more than one version of EE is activated at the same time |
|
| 46 | - */ |
|
| 47 | - function espresso_duplicate_plugin_error() |
|
| 48 | - { |
|
| 49 | - ?> |
|
| 43 | + /** |
|
| 44 | + * espresso_duplicate_plugin_error |
|
| 45 | + * displays if more than one version of EE is activated at the same time |
|
| 46 | + */ |
|
| 47 | + function espresso_duplicate_plugin_error() |
|
| 48 | + { |
|
| 49 | + ?> |
|
| 50 | 50 | <div class="error"> |
| 51 | 51 | <p> |
| 52 | 52 | <?php echo esc_html__( |
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - /** |
|
| 97 | - * espresso_version |
|
| 98 | - * Returns the plugin version |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - function espresso_version() |
|
| 103 | - { |
|
| 104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.028'); |
|
| 105 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + /** |
|
| 97 | + * espresso_version |
|
| 98 | + * Returns the plugin version |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + function espresso_version() |
|
| 103 | + { |
|
| 104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.22.rc.028'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // define versions |
|
| 108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | - if ( ! defined('DS')) { |
|
| 115 | - define('DS', '/'); |
|
| 116 | - } |
|
| 117 | - if ( ! defined('PS')) { |
|
| 118 | - define('PS', PATH_SEPARATOR); |
|
| 119 | - } |
|
| 120 | - if ( ! defined('SP')) { |
|
| 121 | - define('SP', ' '); |
|
| 122 | - } |
|
| 123 | - if ( ! defined('EENL')) { |
|
| 124 | - define('EENL', "\n"); |
|
| 125 | - } |
|
| 126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | - // define the plugin directory and URL |
|
| 128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | - // main root folder paths |
|
| 132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | - // core system paths |
|
| 141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | - // gateways |
|
| 154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | - // asset URL paths |
|
| 157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | - // define upload paths |
|
| 164 | - $uploads = wp_upload_dir(); |
|
| 165 | - // define the uploads directory and URL |
|
| 166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | - // define the templates directory and URL |
|
| 169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | - // define the gateway directory and URL |
|
| 172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | - // languages folder/path |
|
| 175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | - //check for dompdf fonts in uploads |
|
| 178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | - } |
|
| 181 | - //ajax constants |
|
| 182 | - define( |
|
| 183 | - 'EE_FRONT_AJAX', |
|
| 184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | - ); |
|
| 186 | - define( |
|
| 187 | - 'EE_ADMIN_AJAX', |
|
| 188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | - ); |
|
| 190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | - //want to change its default value! or find when -1 means infinity |
|
| 193 | - define('EE_INF_IN_DB', -1); |
|
| 194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | - define('EE_DEBUG', false); |
|
| 196 | - /** |
|
| 197 | - * espresso_plugin_activation |
|
| 198 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 199 | - */ |
|
| 200 | - function espresso_plugin_activation() |
|
| 201 | - { |
|
| 202 | - update_option('ee_espresso_activation', true); |
|
| 203 | - } |
|
| 107 | + // define versions |
|
| 108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
| 109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
| 110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
| 111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
| 112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
| 114 | + if ( ! defined('DS')) { |
|
| 115 | + define('DS', '/'); |
|
| 116 | + } |
|
| 117 | + if ( ! defined('PS')) { |
|
| 118 | + define('PS', PATH_SEPARATOR); |
|
| 119 | + } |
|
| 120 | + if ( ! defined('SP')) { |
|
| 121 | + define('SP', ' '); |
|
| 122 | + } |
|
| 123 | + if ( ! defined('EENL')) { |
|
| 124 | + define('EENL', "\n"); |
|
| 125 | + } |
|
| 126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
| 127 | + // define the plugin directory and URL |
|
| 128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
| 131 | + // main root folder paths |
|
| 132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
| 133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
| 134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
| 135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
| 136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
| 137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
| 138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
| 139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
| 140 | + // core system paths |
|
| 141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
| 142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
| 143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
| 144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
| 145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
| 146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
| 147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
| 148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
| 149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
| 150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
| 151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
| 152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
| 153 | + // gateways |
|
| 154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
| 155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
| 156 | + // asset URL paths |
|
| 157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
| 158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
| 159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
| 160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
| 161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
| 162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
| 163 | + // define upload paths |
|
| 164 | + $uploads = wp_upload_dir(); |
|
| 165 | + // define the uploads directory and URL |
|
| 166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
| 167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
| 168 | + // define the templates directory and URL |
|
| 169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
| 171 | + // define the gateway directory and URL |
|
| 172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
| 174 | + // languages folder/path |
|
| 175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
| 176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
| 177 | + //check for dompdf fonts in uploads |
|
| 178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
| 179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
| 180 | + } |
|
| 181 | + //ajax constants |
|
| 182 | + define( |
|
| 183 | + 'EE_FRONT_AJAX', |
|
| 184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
| 185 | + ); |
|
| 186 | + define( |
|
| 187 | + 'EE_ADMIN_AJAX', |
|
| 188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
| 189 | + ); |
|
| 190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
| 191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
| 192 | + //want to change its default value! or find when -1 means infinity |
|
| 193 | + define('EE_INF_IN_DB', -1); |
|
| 194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
| 195 | + define('EE_DEBUG', false); |
|
| 196 | + /** |
|
| 197 | + * espresso_plugin_activation |
|
| 198 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 199 | + */ |
|
| 200 | + function espresso_plugin_activation() |
|
| 201 | + { |
|
| 202 | + update_option('ee_espresso_activation', true); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 206 | - /** |
|
| 207 | - * espresso_load_error_handling |
|
| 208 | - * this function loads EE's class for handling exceptions and errors |
|
| 209 | - */ |
|
| 210 | - function espresso_load_error_handling() |
|
| 211 | - { |
|
| 212 | - // load debugging tools |
|
| 213 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 214 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 215 | - EEH_Debug_Tools::instance(); |
|
| 216 | - } |
|
| 217 | - // load error handling |
|
| 218 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 219 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 220 | - } else { |
|
| 221 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 222 | - } |
|
| 223 | - } |
|
| 205 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 206 | + /** |
|
| 207 | + * espresso_load_error_handling |
|
| 208 | + * this function loads EE's class for handling exceptions and errors |
|
| 209 | + */ |
|
| 210 | + function espresso_load_error_handling() |
|
| 211 | + { |
|
| 212 | + // load debugging tools |
|
| 213 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 214 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
| 215 | + EEH_Debug_Tools::instance(); |
|
| 216 | + } |
|
| 217 | + // load error handling |
|
| 218 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 219 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
| 220 | + } else { |
|
| 221 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * espresso_load_required |
|
| 227 | - * given a class name and path, this function will load that file or throw an exception |
|
| 228 | - * |
|
| 229 | - * @param string $classname |
|
| 230 | - * @param string $full_path_to_file |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 234 | - { |
|
| 235 | - static $error_handling_loaded = false; |
|
| 236 | - if ( ! $error_handling_loaded) { |
|
| 237 | - espresso_load_error_handling(); |
|
| 238 | - $error_handling_loaded = true; |
|
| 239 | - } |
|
| 240 | - if (is_readable($full_path_to_file)) { |
|
| 241 | - require_once($full_path_to_file); |
|
| 242 | - } else { |
|
| 243 | - throw new EE_Error ( |
|
| 244 | - sprintf( |
|
| 245 | - esc_html__( |
|
| 246 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 247 | - 'event_espresso' |
|
| 248 | - ), |
|
| 249 | - $classname |
|
| 250 | - ) |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - } |
|
| 225 | + /** |
|
| 226 | + * espresso_load_required |
|
| 227 | + * given a class name and path, this function will load that file or throw an exception |
|
| 228 | + * |
|
| 229 | + * @param string $classname |
|
| 230 | + * @param string $full_path_to_file |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 234 | + { |
|
| 235 | + static $error_handling_loaded = false; |
|
| 236 | + if ( ! $error_handling_loaded) { |
|
| 237 | + espresso_load_error_handling(); |
|
| 238 | + $error_handling_loaded = true; |
|
| 239 | + } |
|
| 240 | + if (is_readable($full_path_to_file)) { |
|
| 241 | + require_once($full_path_to_file); |
|
| 242 | + } else { |
|
| 243 | + throw new EE_Error ( |
|
| 244 | + sprintf( |
|
| 245 | + esc_html__( |
|
| 246 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 247 | + 'event_espresso' |
|
| 248 | + ), |
|
| 249 | + $classname |
|
| 250 | + ) |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 256 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 257 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 258 | - new EE_Bootstrap(); |
|
| 259 | - } |
|
| 255 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
| 256 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
| 257 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
| 258 | + new EE_Bootstrap(); |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | if ( ! function_exists('espresso_deactivate_plugin')) { |
| 262 | - /** |
|
| 263 | - * deactivate_plugin |
|
| 264 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 265 | - * |
|
| 266 | - * @access public |
|
| 267 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 271 | - { |
|
| 272 | - if ( ! function_exists('deactivate_plugins')) { |
|
| 273 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 274 | - } |
|
| 275 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 276 | - deactivate_plugins($plugin_basename); |
|
| 277 | - } |
|
| 262 | + /** |
|
| 263 | + * deactivate_plugin |
|
| 264 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 265 | + * |
|
| 266 | + * @access public |
|
| 267 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 271 | + { |
|
| 272 | + if ( ! function_exists('deactivate_plugins')) { |
|
| 273 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
| 274 | + } |
|
| 275 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 276 | + deactivate_plugins($plugin_basename); |
|
| 277 | + } |
|
| 278 | 278 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -17,2572 +17,2572 @@ discard block |
||
| 17 | 17 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This will hold the event object for event_details screen. |
|
| 22 | - * |
|
| 23 | - * @access protected |
|
| 24 | - * @var EE_Event $_event |
|
| 25 | - */ |
|
| 26 | - protected $_event; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This will hold the category object for category_details screen. |
|
| 31 | - * |
|
| 32 | - * @var stdClass $_category |
|
| 33 | - */ |
|
| 34 | - protected $_category; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * This will hold the event model instance |
|
| 39 | - * |
|
| 40 | - * @var EEM_Event $_event_model |
|
| 41 | - */ |
|
| 42 | - protected $_event_model; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Event |
|
| 47 | - */ |
|
| 48 | - protected $_cpt_model_obj = false; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - protected function _init_page_props() |
|
| 53 | - { |
|
| 54 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 55 | - $this->page_label = EVENTS_LABEL; |
|
| 56 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 57 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 58 | - $this->_cpt_model_names = array( |
|
| 59 | - 'create_new' => 'EEM_Event', |
|
| 60 | - 'edit' => 'EEM_Event', |
|
| 61 | - ); |
|
| 62 | - $this->_cpt_edit_routes = array( |
|
| 63 | - 'espresso_events' => 'edit', |
|
| 64 | - ); |
|
| 65 | - add_action( |
|
| 66 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 67 | - array($this, 'verify_event_edit') |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - protected function _ajax_hooks() |
|
| 74 | - { |
|
| 75 | - //todo: all hooks for events ajax goes in here. |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - protected function _define_page_props() |
|
| 81 | - { |
|
| 82 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 83 | - $this->_labels = array( |
|
| 84 | - 'buttons' => array( |
|
| 85 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 86 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 87 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 88 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 89 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 90 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 91 | - ), |
|
| 92 | - 'editor_title' => array( |
|
| 93 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 94 | - ), |
|
| 95 | - 'publishbox' => array( |
|
| 96 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 97 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 98 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 99 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 100 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 101 | - ), |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - protected function _set_page_routes() |
|
| 108 | - { |
|
| 109 | - //load formatter helper |
|
| 110 | - //load field generator helper |
|
| 111 | - //is there a evt_id in the request? |
|
| 112 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 113 | - ? $this->_req_data['EVT_ID'] : 0; |
|
| 114 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 115 | - $this->_page_routes = array( |
|
| 116 | - 'default' => array( |
|
| 117 | - 'func' => '_events_overview_list_table', |
|
| 118 | - 'capability' => 'ee_read_events', |
|
| 119 | - ), |
|
| 120 | - 'create_new' => array( |
|
| 121 | - 'func' => '_create_new_cpt_item', |
|
| 122 | - 'capability' => 'ee_edit_events', |
|
| 123 | - ), |
|
| 124 | - 'edit' => array( |
|
| 125 | - 'func' => '_edit_cpt_item', |
|
| 126 | - 'capability' => 'ee_edit_event', |
|
| 127 | - 'obj_id' => $evt_id, |
|
| 128 | - ), |
|
| 129 | - 'copy_event' => array( |
|
| 130 | - 'func' => '_copy_events', |
|
| 131 | - 'capability' => 'ee_edit_event', |
|
| 132 | - 'obj_id' => $evt_id, |
|
| 133 | - 'noheader' => true, |
|
| 134 | - ), |
|
| 135 | - 'trash_event' => array( |
|
| 136 | - 'func' => '_trash_or_restore_event', |
|
| 137 | - 'args' => array('event_status' => 'trash'), |
|
| 138 | - 'capability' => 'ee_delete_event', |
|
| 139 | - 'obj_id' => $evt_id, |
|
| 140 | - 'noheader' => true, |
|
| 141 | - ), |
|
| 142 | - 'trash_events' => array( |
|
| 143 | - 'func' => '_trash_or_restore_events', |
|
| 144 | - 'args' => array('event_status' => 'trash'), |
|
| 145 | - 'capability' => 'ee_delete_events', |
|
| 146 | - 'noheader' => true, |
|
| 147 | - ), |
|
| 148 | - 'restore_event' => array( |
|
| 149 | - 'func' => '_trash_or_restore_event', |
|
| 150 | - 'args' => array('event_status' => 'draft'), |
|
| 151 | - 'capability' => 'ee_delete_event', |
|
| 152 | - 'obj_id' => $evt_id, |
|
| 153 | - 'noheader' => true, |
|
| 154 | - ), |
|
| 155 | - 'restore_events' => array( |
|
| 156 | - 'func' => '_trash_or_restore_events', |
|
| 157 | - 'args' => array('event_status' => 'draft'), |
|
| 158 | - 'capability' => 'ee_delete_events', |
|
| 159 | - 'noheader' => true, |
|
| 160 | - ), |
|
| 161 | - 'delete_event' => array( |
|
| 162 | - 'func' => '_delete_event', |
|
| 163 | - 'capability' => 'ee_delete_event', |
|
| 164 | - 'obj_id' => $evt_id, |
|
| 165 | - 'noheader' => true, |
|
| 166 | - ), |
|
| 167 | - 'delete_events' => array( |
|
| 168 | - 'func' => '_delete_events', |
|
| 169 | - 'capability' => 'ee_delete_events', |
|
| 170 | - 'noheader' => true, |
|
| 171 | - ), |
|
| 172 | - 'view_report' => array( |
|
| 173 | - 'func' => '_view_report', |
|
| 174 | - 'capablity' => 'ee_edit_events', |
|
| 175 | - ), |
|
| 176 | - 'default_event_settings' => array( |
|
| 177 | - 'func' => '_default_event_settings', |
|
| 178 | - 'capability' => 'manage_options', |
|
| 179 | - ), |
|
| 180 | - 'update_default_event_settings' => array( |
|
| 181 | - 'func' => '_update_default_event_settings', |
|
| 182 | - 'capability' => 'manage_options', |
|
| 183 | - 'noheader' => true, |
|
| 184 | - ), |
|
| 185 | - 'template_settings' => array( |
|
| 186 | - 'func' => '_template_settings', |
|
| 187 | - 'capability' => 'manage_options', |
|
| 188 | - ), |
|
| 189 | - //event category tab related |
|
| 190 | - 'add_category' => array( |
|
| 191 | - 'func' => '_category_details', |
|
| 192 | - 'capability' => 'ee_edit_event_category', |
|
| 193 | - 'args' => array('add'), |
|
| 194 | - ), |
|
| 195 | - 'edit_category' => array( |
|
| 196 | - 'func' => '_category_details', |
|
| 197 | - 'capability' => 'ee_edit_event_category', |
|
| 198 | - 'args' => array('edit'), |
|
| 199 | - ), |
|
| 200 | - 'delete_categories' => array( |
|
| 201 | - 'func' => '_delete_categories', |
|
| 202 | - 'capability' => 'ee_delete_event_category', |
|
| 203 | - 'noheader' => true, |
|
| 204 | - ), |
|
| 205 | - 'delete_category' => array( |
|
| 206 | - 'func' => '_delete_categories', |
|
| 207 | - 'capability' => 'ee_delete_event_category', |
|
| 208 | - 'noheader' => true, |
|
| 209 | - ), |
|
| 210 | - 'insert_category' => array( |
|
| 211 | - 'func' => '_insert_or_update_category', |
|
| 212 | - 'args' => array('new_category' => true), |
|
| 213 | - 'capability' => 'ee_edit_event_category', |
|
| 214 | - 'noheader' => true, |
|
| 215 | - ), |
|
| 216 | - 'update_category' => array( |
|
| 217 | - 'func' => '_insert_or_update_category', |
|
| 218 | - 'args' => array('new_category' => false), |
|
| 219 | - 'capability' => 'ee_edit_event_category', |
|
| 220 | - 'noheader' => true, |
|
| 221 | - ), |
|
| 222 | - 'category_list' => array( |
|
| 223 | - 'func' => '_category_list_table', |
|
| 224 | - 'capability' => 'ee_manage_event_categories', |
|
| 225 | - ), |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - protected function _set_page_config() |
|
| 232 | - { |
|
| 233 | - $this->_page_config = array( |
|
| 234 | - 'default' => array( |
|
| 235 | - 'nav' => array( |
|
| 236 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 237 | - 'order' => 10, |
|
| 238 | - ), |
|
| 239 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 240 | - 'help_tabs' => array( |
|
| 241 | - 'events_overview_help_tab' => array( |
|
| 242 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 243 | - 'filename' => 'events_overview', |
|
| 244 | - ), |
|
| 245 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 246 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 247 | - 'filename' => 'events_overview_table_column_headings', |
|
| 248 | - ), |
|
| 249 | - 'events_overview_filters_help_tab' => array( |
|
| 250 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 251 | - 'filename' => 'events_overview_filters', |
|
| 252 | - ), |
|
| 253 | - 'events_overview_view_help_tab' => array( |
|
| 254 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 255 | - 'filename' => 'events_overview_views', |
|
| 256 | - ), |
|
| 257 | - 'events_overview_other_help_tab' => array( |
|
| 258 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 259 | - 'filename' => 'events_overview_other', |
|
| 260 | - ), |
|
| 261 | - ), |
|
| 262 | - 'help_tour' => array( |
|
| 263 | - 'Event_Overview_Help_Tour', |
|
| 264 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 265 | - ), |
|
| 266 | - 'qtips' => array( |
|
| 267 | - 'EE_Event_List_Table_Tips', |
|
| 268 | - ), |
|
| 269 | - 'require_nonce' => false, |
|
| 270 | - ), |
|
| 271 | - 'create_new' => array( |
|
| 272 | - 'nav' => array( |
|
| 273 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 274 | - 'order' => 5, |
|
| 275 | - 'persistent' => false, |
|
| 276 | - ), |
|
| 277 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 278 | - 'help_tabs' => array( |
|
| 279 | - 'event_editor_help_tab' => array( |
|
| 280 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 281 | - 'filename' => 'event_editor', |
|
| 282 | - ), |
|
| 283 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 284 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 285 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 286 | - ), |
|
| 287 | - 'event_editor_venue_details_help_tab' => array( |
|
| 288 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 289 | - 'filename' => 'event_editor_venue_details', |
|
| 290 | - ), |
|
| 291 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 292 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 293 | - 'filename' => 'event_editor_event_datetimes', |
|
| 294 | - ), |
|
| 295 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 296 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 297 | - 'filename' => 'event_editor_event_tickets', |
|
| 298 | - ), |
|
| 299 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 300 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 301 | - 'filename' => 'event_editor_event_registration_options', |
|
| 302 | - ), |
|
| 303 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 304 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 305 | - 'filename' => 'event_editor_tags_categories', |
|
| 306 | - ), |
|
| 307 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 308 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 309 | - 'filename' => 'event_editor_questions_registrants', |
|
| 310 | - ), |
|
| 311 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 312 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 313 | - 'filename' => 'event_editor_save_new_event', |
|
| 314 | - ), |
|
| 315 | - 'event_editor_other_help_tab' => array( |
|
| 316 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 317 | - 'filename' => 'event_editor_other', |
|
| 318 | - ), |
|
| 319 | - ), |
|
| 320 | - 'help_tour' => array( |
|
| 321 | - 'Event_Editor_Help_Tour', |
|
| 322 | - ), |
|
| 323 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 324 | - 'require_nonce' => false, |
|
| 325 | - ), |
|
| 326 | - 'edit' => array( |
|
| 327 | - 'nav' => array( |
|
| 328 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 329 | - 'order' => 5, |
|
| 330 | - 'persistent' => false, |
|
| 331 | - 'url' => isset($this->_req_data['post']) |
|
| 332 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 333 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 334 | - $this->_current_page_view_url |
|
| 335 | - ) |
|
| 336 | - : $this->_admin_base_url, |
|
| 337 | - ), |
|
| 338 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 339 | - 'help_tabs' => array( |
|
| 340 | - 'event_editor_help_tab' => array( |
|
| 341 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 342 | - 'filename' => 'event_editor', |
|
| 343 | - ), |
|
| 344 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 345 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 346 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 347 | - ), |
|
| 348 | - 'event_editor_venue_details_help_tab' => array( |
|
| 349 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 350 | - 'filename' => 'event_editor_venue_details', |
|
| 351 | - ), |
|
| 352 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 353 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 354 | - 'filename' => 'event_editor_event_datetimes', |
|
| 355 | - ), |
|
| 356 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 357 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 358 | - 'filename' => 'event_editor_event_tickets', |
|
| 359 | - ), |
|
| 360 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 361 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 362 | - 'filename' => 'event_editor_event_registration_options', |
|
| 363 | - ), |
|
| 364 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 365 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 366 | - 'filename' => 'event_editor_tags_categories', |
|
| 367 | - ), |
|
| 368 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 369 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 370 | - 'filename' => 'event_editor_questions_registrants', |
|
| 371 | - ), |
|
| 372 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 373 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 374 | - 'filename' => 'event_editor_save_new_event', |
|
| 375 | - ), |
|
| 376 | - 'event_editor_other_help_tab' => array( |
|
| 377 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 378 | - 'filename' => 'event_editor_other', |
|
| 379 | - ), |
|
| 380 | - ), |
|
| 381 | - /*'help_tour' => array( |
|
| 20 | + /** |
|
| 21 | + * This will hold the event object for event_details screen. |
|
| 22 | + * |
|
| 23 | + * @access protected |
|
| 24 | + * @var EE_Event $_event |
|
| 25 | + */ |
|
| 26 | + protected $_event; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This will hold the category object for category_details screen. |
|
| 31 | + * |
|
| 32 | + * @var stdClass $_category |
|
| 33 | + */ |
|
| 34 | + protected $_category; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * This will hold the event model instance |
|
| 39 | + * |
|
| 40 | + * @var EEM_Event $_event_model |
|
| 41 | + */ |
|
| 42 | + protected $_event_model; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Event |
|
| 47 | + */ |
|
| 48 | + protected $_cpt_model_obj = false; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + protected function _init_page_props() |
|
| 53 | + { |
|
| 54 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 55 | + $this->page_label = EVENTS_LABEL; |
|
| 56 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 57 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 58 | + $this->_cpt_model_names = array( |
|
| 59 | + 'create_new' => 'EEM_Event', |
|
| 60 | + 'edit' => 'EEM_Event', |
|
| 61 | + ); |
|
| 62 | + $this->_cpt_edit_routes = array( |
|
| 63 | + 'espresso_events' => 'edit', |
|
| 64 | + ); |
|
| 65 | + add_action( |
|
| 66 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 67 | + array($this, 'verify_event_edit') |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + protected function _ajax_hooks() |
|
| 74 | + { |
|
| 75 | + //todo: all hooks for events ajax goes in here. |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + protected function _define_page_props() |
|
| 81 | + { |
|
| 82 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 83 | + $this->_labels = array( |
|
| 84 | + 'buttons' => array( |
|
| 85 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 86 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 87 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 88 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 89 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 90 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 91 | + ), |
|
| 92 | + 'editor_title' => array( |
|
| 93 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 94 | + ), |
|
| 95 | + 'publishbox' => array( |
|
| 96 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 97 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 98 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 99 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 100 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 101 | + ), |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + protected function _set_page_routes() |
|
| 108 | + { |
|
| 109 | + //load formatter helper |
|
| 110 | + //load field generator helper |
|
| 111 | + //is there a evt_id in the request? |
|
| 112 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 113 | + ? $this->_req_data['EVT_ID'] : 0; |
|
| 114 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 115 | + $this->_page_routes = array( |
|
| 116 | + 'default' => array( |
|
| 117 | + 'func' => '_events_overview_list_table', |
|
| 118 | + 'capability' => 'ee_read_events', |
|
| 119 | + ), |
|
| 120 | + 'create_new' => array( |
|
| 121 | + 'func' => '_create_new_cpt_item', |
|
| 122 | + 'capability' => 'ee_edit_events', |
|
| 123 | + ), |
|
| 124 | + 'edit' => array( |
|
| 125 | + 'func' => '_edit_cpt_item', |
|
| 126 | + 'capability' => 'ee_edit_event', |
|
| 127 | + 'obj_id' => $evt_id, |
|
| 128 | + ), |
|
| 129 | + 'copy_event' => array( |
|
| 130 | + 'func' => '_copy_events', |
|
| 131 | + 'capability' => 'ee_edit_event', |
|
| 132 | + 'obj_id' => $evt_id, |
|
| 133 | + 'noheader' => true, |
|
| 134 | + ), |
|
| 135 | + 'trash_event' => array( |
|
| 136 | + 'func' => '_trash_or_restore_event', |
|
| 137 | + 'args' => array('event_status' => 'trash'), |
|
| 138 | + 'capability' => 'ee_delete_event', |
|
| 139 | + 'obj_id' => $evt_id, |
|
| 140 | + 'noheader' => true, |
|
| 141 | + ), |
|
| 142 | + 'trash_events' => array( |
|
| 143 | + 'func' => '_trash_or_restore_events', |
|
| 144 | + 'args' => array('event_status' => 'trash'), |
|
| 145 | + 'capability' => 'ee_delete_events', |
|
| 146 | + 'noheader' => true, |
|
| 147 | + ), |
|
| 148 | + 'restore_event' => array( |
|
| 149 | + 'func' => '_trash_or_restore_event', |
|
| 150 | + 'args' => array('event_status' => 'draft'), |
|
| 151 | + 'capability' => 'ee_delete_event', |
|
| 152 | + 'obj_id' => $evt_id, |
|
| 153 | + 'noheader' => true, |
|
| 154 | + ), |
|
| 155 | + 'restore_events' => array( |
|
| 156 | + 'func' => '_trash_or_restore_events', |
|
| 157 | + 'args' => array('event_status' => 'draft'), |
|
| 158 | + 'capability' => 'ee_delete_events', |
|
| 159 | + 'noheader' => true, |
|
| 160 | + ), |
|
| 161 | + 'delete_event' => array( |
|
| 162 | + 'func' => '_delete_event', |
|
| 163 | + 'capability' => 'ee_delete_event', |
|
| 164 | + 'obj_id' => $evt_id, |
|
| 165 | + 'noheader' => true, |
|
| 166 | + ), |
|
| 167 | + 'delete_events' => array( |
|
| 168 | + 'func' => '_delete_events', |
|
| 169 | + 'capability' => 'ee_delete_events', |
|
| 170 | + 'noheader' => true, |
|
| 171 | + ), |
|
| 172 | + 'view_report' => array( |
|
| 173 | + 'func' => '_view_report', |
|
| 174 | + 'capablity' => 'ee_edit_events', |
|
| 175 | + ), |
|
| 176 | + 'default_event_settings' => array( |
|
| 177 | + 'func' => '_default_event_settings', |
|
| 178 | + 'capability' => 'manage_options', |
|
| 179 | + ), |
|
| 180 | + 'update_default_event_settings' => array( |
|
| 181 | + 'func' => '_update_default_event_settings', |
|
| 182 | + 'capability' => 'manage_options', |
|
| 183 | + 'noheader' => true, |
|
| 184 | + ), |
|
| 185 | + 'template_settings' => array( |
|
| 186 | + 'func' => '_template_settings', |
|
| 187 | + 'capability' => 'manage_options', |
|
| 188 | + ), |
|
| 189 | + //event category tab related |
|
| 190 | + 'add_category' => array( |
|
| 191 | + 'func' => '_category_details', |
|
| 192 | + 'capability' => 'ee_edit_event_category', |
|
| 193 | + 'args' => array('add'), |
|
| 194 | + ), |
|
| 195 | + 'edit_category' => array( |
|
| 196 | + 'func' => '_category_details', |
|
| 197 | + 'capability' => 'ee_edit_event_category', |
|
| 198 | + 'args' => array('edit'), |
|
| 199 | + ), |
|
| 200 | + 'delete_categories' => array( |
|
| 201 | + 'func' => '_delete_categories', |
|
| 202 | + 'capability' => 'ee_delete_event_category', |
|
| 203 | + 'noheader' => true, |
|
| 204 | + ), |
|
| 205 | + 'delete_category' => array( |
|
| 206 | + 'func' => '_delete_categories', |
|
| 207 | + 'capability' => 'ee_delete_event_category', |
|
| 208 | + 'noheader' => true, |
|
| 209 | + ), |
|
| 210 | + 'insert_category' => array( |
|
| 211 | + 'func' => '_insert_or_update_category', |
|
| 212 | + 'args' => array('new_category' => true), |
|
| 213 | + 'capability' => 'ee_edit_event_category', |
|
| 214 | + 'noheader' => true, |
|
| 215 | + ), |
|
| 216 | + 'update_category' => array( |
|
| 217 | + 'func' => '_insert_or_update_category', |
|
| 218 | + 'args' => array('new_category' => false), |
|
| 219 | + 'capability' => 'ee_edit_event_category', |
|
| 220 | + 'noheader' => true, |
|
| 221 | + ), |
|
| 222 | + 'category_list' => array( |
|
| 223 | + 'func' => '_category_list_table', |
|
| 224 | + 'capability' => 'ee_manage_event_categories', |
|
| 225 | + ), |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + protected function _set_page_config() |
|
| 232 | + { |
|
| 233 | + $this->_page_config = array( |
|
| 234 | + 'default' => array( |
|
| 235 | + 'nav' => array( |
|
| 236 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 237 | + 'order' => 10, |
|
| 238 | + ), |
|
| 239 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 240 | + 'help_tabs' => array( |
|
| 241 | + 'events_overview_help_tab' => array( |
|
| 242 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 243 | + 'filename' => 'events_overview', |
|
| 244 | + ), |
|
| 245 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 246 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 247 | + 'filename' => 'events_overview_table_column_headings', |
|
| 248 | + ), |
|
| 249 | + 'events_overview_filters_help_tab' => array( |
|
| 250 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 251 | + 'filename' => 'events_overview_filters', |
|
| 252 | + ), |
|
| 253 | + 'events_overview_view_help_tab' => array( |
|
| 254 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 255 | + 'filename' => 'events_overview_views', |
|
| 256 | + ), |
|
| 257 | + 'events_overview_other_help_tab' => array( |
|
| 258 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 259 | + 'filename' => 'events_overview_other', |
|
| 260 | + ), |
|
| 261 | + ), |
|
| 262 | + 'help_tour' => array( |
|
| 263 | + 'Event_Overview_Help_Tour', |
|
| 264 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 265 | + ), |
|
| 266 | + 'qtips' => array( |
|
| 267 | + 'EE_Event_List_Table_Tips', |
|
| 268 | + ), |
|
| 269 | + 'require_nonce' => false, |
|
| 270 | + ), |
|
| 271 | + 'create_new' => array( |
|
| 272 | + 'nav' => array( |
|
| 273 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 274 | + 'order' => 5, |
|
| 275 | + 'persistent' => false, |
|
| 276 | + ), |
|
| 277 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 278 | + 'help_tabs' => array( |
|
| 279 | + 'event_editor_help_tab' => array( |
|
| 280 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 281 | + 'filename' => 'event_editor', |
|
| 282 | + ), |
|
| 283 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 284 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 285 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 286 | + ), |
|
| 287 | + 'event_editor_venue_details_help_tab' => array( |
|
| 288 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 289 | + 'filename' => 'event_editor_venue_details', |
|
| 290 | + ), |
|
| 291 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 292 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 293 | + 'filename' => 'event_editor_event_datetimes', |
|
| 294 | + ), |
|
| 295 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 296 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 297 | + 'filename' => 'event_editor_event_tickets', |
|
| 298 | + ), |
|
| 299 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 300 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 301 | + 'filename' => 'event_editor_event_registration_options', |
|
| 302 | + ), |
|
| 303 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 304 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 305 | + 'filename' => 'event_editor_tags_categories', |
|
| 306 | + ), |
|
| 307 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 308 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 309 | + 'filename' => 'event_editor_questions_registrants', |
|
| 310 | + ), |
|
| 311 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 312 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 313 | + 'filename' => 'event_editor_save_new_event', |
|
| 314 | + ), |
|
| 315 | + 'event_editor_other_help_tab' => array( |
|
| 316 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 317 | + 'filename' => 'event_editor_other', |
|
| 318 | + ), |
|
| 319 | + ), |
|
| 320 | + 'help_tour' => array( |
|
| 321 | + 'Event_Editor_Help_Tour', |
|
| 322 | + ), |
|
| 323 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 324 | + 'require_nonce' => false, |
|
| 325 | + ), |
|
| 326 | + 'edit' => array( |
|
| 327 | + 'nav' => array( |
|
| 328 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 329 | + 'order' => 5, |
|
| 330 | + 'persistent' => false, |
|
| 331 | + 'url' => isset($this->_req_data['post']) |
|
| 332 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 333 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 334 | + $this->_current_page_view_url |
|
| 335 | + ) |
|
| 336 | + : $this->_admin_base_url, |
|
| 337 | + ), |
|
| 338 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 339 | + 'help_tabs' => array( |
|
| 340 | + 'event_editor_help_tab' => array( |
|
| 341 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 342 | + 'filename' => 'event_editor', |
|
| 343 | + ), |
|
| 344 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 345 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 346 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 347 | + ), |
|
| 348 | + 'event_editor_venue_details_help_tab' => array( |
|
| 349 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 350 | + 'filename' => 'event_editor_venue_details', |
|
| 351 | + ), |
|
| 352 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 353 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 354 | + 'filename' => 'event_editor_event_datetimes', |
|
| 355 | + ), |
|
| 356 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 357 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 358 | + 'filename' => 'event_editor_event_tickets', |
|
| 359 | + ), |
|
| 360 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 361 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 362 | + 'filename' => 'event_editor_event_registration_options', |
|
| 363 | + ), |
|
| 364 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 365 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 366 | + 'filename' => 'event_editor_tags_categories', |
|
| 367 | + ), |
|
| 368 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 369 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 370 | + 'filename' => 'event_editor_questions_registrants', |
|
| 371 | + ), |
|
| 372 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 373 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 374 | + 'filename' => 'event_editor_save_new_event', |
|
| 375 | + ), |
|
| 376 | + 'event_editor_other_help_tab' => array( |
|
| 377 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 378 | + 'filename' => 'event_editor_other', |
|
| 379 | + ), |
|
| 380 | + ), |
|
| 381 | + /*'help_tour' => array( |
|
| 382 | 382 | 'Event_Edit_Help_Tour' |
| 383 | 383 | ),*/ |
| 384 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 385 | - 'require_nonce' => false, |
|
| 386 | - ), |
|
| 387 | - 'default_event_settings' => array( |
|
| 388 | - 'nav' => array( |
|
| 389 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 390 | - 'order' => 40, |
|
| 391 | - ), |
|
| 392 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 393 | - 'labels' => array( |
|
| 394 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 395 | - ), |
|
| 396 | - 'help_tabs' => array( |
|
| 397 | - 'default_settings_help_tab' => array( |
|
| 398 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 399 | - 'filename' => 'events_default_settings', |
|
| 400 | - ), |
|
| 401 | - 'default_settings_status_help_tab' => array( |
|
| 402 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 403 | - 'filename' => 'events_default_settings_status', |
|
| 404 | - ), |
|
| 405 | - ), |
|
| 406 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 407 | - 'require_nonce' => false, |
|
| 408 | - ), |
|
| 409 | - //template settings |
|
| 410 | - 'template_settings' => array( |
|
| 411 | - 'nav' => array( |
|
| 412 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 413 | - 'order' => 30, |
|
| 414 | - ), |
|
| 415 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 416 | - 'help_tabs' => array( |
|
| 417 | - 'general_settings_templates_help_tab' => array( |
|
| 418 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 419 | - 'filename' => 'general_settings_templates', |
|
| 420 | - ), |
|
| 421 | - ), |
|
| 422 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 423 | - 'require_nonce' => false, |
|
| 424 | - ), |
|
| 425 | - //event category stuff |
|
| 426 | - 'add_category' => array( |
|
| 427 | - 'nav' => array( |
|
| 428 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 429 | - 'order' => 15, |
|
| 430 | - 'persistent' => false, |
|
| 431 | - ), |
|
| 432 | - 'help_tabs' => array( |
|
| 433 | - 'add_category_help_tab' => array( |
|
| 434 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 435 | - 'filename' => 'events_add_category', |
|
| 436 | - ), |
|
| 437 | - ), |
|
| 438 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 439 | - 'metaboxes' => array('_publish_post_box'), |
|
| 440 | - 'require_nonce' => false, |
|
| 441 | - ), |
|
| 442 | - 'edit_category' => array( |
|
| 443 | - 'nav' => array( |
|
| 444 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 445 | - 'order' => 15, |
|
| 446 | - 'persistent' => false, |
|
| 447 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 448 | - ? add_query_arg( |
|
| 449 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 450 | - $this->_current_page_view_url |
|
| 451 | - ) |
|
| 452 | - : $this->_admin_base_url, |
|
| 453 | - ), |
|
| 454 | - 'help_tabs' => array( |
|
| 455 | - 'edit_category_help_tab' => array( |
|
| 456 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 457 | - 'filename' => 'events_edit_category', |
|
| 458 | - ), |
|
| 459 | - ), |
|
| 460 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 461 | - 'metaboxes' => array('_publish_post_box'), |
|
| 462 | - 'require_nonce' => false, |
|
| 463 | - ), |
|
| 464 | - 'category_list' => array( |
|
| 465 | - 'nav' => array( |
|
| 466 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 467 | - 'order' => 20, |
|
| 468 | - ), |
|
| 469 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 470 | - 'help_tabs' => array( |
|
| 471 | - 'events_categories_help_tab' => array( |
|
| 472 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 473 | - 'filename' => 'events_categories', |
|
| 474 | - ), |
|
| 475 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 476 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 477 | - 'filename' => 'events_categories_table_column_headings', |
|
| 478 | - ), |
|
| 479 | - 'events_categories_view_help_tab' => array( |
|
| 480 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 481 | - 'filename' => 'events_categories_views', |
|
| 482 | - ), |
|
| 483 | - 'events_categories_other_help_tab' => array( |
|
| 484 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 485 | - 'filename' => 'events_categories_other', |
|
| 486 | - ), |
|
| 487 | - ), |
|
| 488 | - 'help_tour' => array( |
|
| 489 | - 'Event_Categories_Help_Tour', |
|
| 490 | - ), |
|
| 491 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 492 | - 'require_nonce' => false, |
|
| 493 | - ), |
|
| 494 | - ); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - protected function _add_screen_options() |
|
| 500 | - { |
|
| 501 | - //todo |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - protected function _add_screen_options_default() |
|
| 507 | - { |
|
| 508 | - $this->_per_page_screen_option(); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - protected function _add_screen_options_category_list() |
|
| 514 | - { |
|
| 515 | - $page_title = $this->_admin_page_title; |
|
| 516 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 517 | - $this->_per_page_screen_option(); |
|
| 518 | - $this->_admin_page_title = $page_title; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - protected function _add_feature_pointers() |
|
| 524 | - { |
|
| 525 | - //todo |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - public function load_scripts_styles() |
|
| 531 | - { |
|
| 532 | - wp_register_style( |
|
| 533 | - 'events-admin-css', |
|
| 534 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 535 | - array(), |
|
| 536 | - EVENT_ESPRESSO_VERSION |
|
| 537 | - ); |
|
| 538 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 539 | - wp_enqueue_style('events-admin-css'); |
|
| 540 | - wp_enqueue_style('ee-cat-admin'); |
|
| 541 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 542 | - //registers for all views |
|
| 543 | - //scripts |
|
| 544 | - wp_register_script( |
|
| 545 | - 'event_editor_js', |
|
| 546 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 547 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 548 | - EVENT_ESPRESSO_VERSION, |
|
| 549 | - true |
|
| 550 | - ); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * enqueuing scripts and styles specific to this view |
|
| 557 | - * |
|
| 558 | - * @return void |
|
| 559 | - */ |
|
| 560 | - public function load_scripts_styles_create_new() |
|
| 561 | - { |
|
| 562 | - $this->load_scripts_styles_edit(); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * enqueuing scripts and styles specific to this view |
|
| 569 | - * |
|
| 570 | - * @return void |
|
| 571 | - */ |
|
| 572 | - public function load_scripts_styles_edit() |
|
| 573 | - { |
|
| 574 | - //styles |
|
| 575 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 576 | - wp_register_style( |
|
| 577 | - 'event-editor-css', |
|
| 578 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 579 | - array('ee-admin-css'), |
|
| 580 | - EVENT_ESPRESSO_VERSION |
|
| 581 | - ); |
|
| 582 | - wp_enqueue_style('event-editor-css'); |
|
| 583 | - //scripts |
|
| 584 | - wp_register_script( |
|
| 585 | - 'event-datetime-metabox', |
|
| 586 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 587 | - array('event_editor_js', 'ee-datepicker'), |
|
| 588 | - EVENT_ESPRESSO_VERSION |
|
| 589 | - ); |
|
| 590 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - public function load_scripts_styles_add_category() |
|
| 596 | - { |
|
| 597 | - $this->load_scripts_styles_edit_category(); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - public function load_scripts_styles_edit_category() |
|
| 603 | - { |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - protected function _set_list_table_views_category_list() |
|
| 609 | - { |
|
| 610 | - $this->_views = array( |
|
| 611 | - 'all' => array( |
|
| 612 | - 'slug' => 'all', |
|
| 613 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 614 | - 'count' => 0, |
|
| 615 | - 'bulk_action' => array( |
|
| 616 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 617 | - ), |
|
| 618 | - ), |
|
| 619 | - ); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - public function admin_init() |
|
| 625 | - { |
|
| 626 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 627 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 628 | - 'event_espresso' |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - //nothing needed for events with these methods. |
|
| 635 | - public function admin_notices() |
|
| 636 | - { |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - public function admin_footer_scripts() |
|
| 642 | - { |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 649 | - * warning (via EE_Error::add_error()); |
|
| 650 | - * |
|
| 651 | - * @param EE_Event $event Event object |
|
| 652 | - * @access public |
|
| 653 | - * @return void |
|
| 654 | - */ |
|
| 655 | - public function verify_event_edit($event = null) |
|
| 656 | - { |
|
| 657 | - // no event? |
|
| 658 | - if (empty($event)) { |
|
| 659 | - // set event |
|
| 660 | - $event = $this->_cpt_model_obj; |
|
| 661 | - } |
|
| 662 | - // STILL no event? |
|
| 663 | - if (empty ($event)) { |
|
| 664 | - return; |
|
| 665 | - } |
|
| 666 | - $orig_status = $event->status(); |
|
| 667 | - // first check if event is active. |
|
| 668 | - if ( |
|
| 669 | - $orig_status === EEM_Event::cancelled |
|
| 670 | - || $orig_status === EEM_Event::postponed |
|
| 671 | - || $event->is_expired() |
|
| 672 | - || $event->is_inactive() |
|
| 673 | - ) { |
|
| 674 | - return; |
|
| 675 | - } |
|
| 676 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
| 677 | - if ($event->is_sold_out(true)) { |
|
| 678 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 679 | - EE_Error::add_attention( |
|
| 680 | - sprintf( |
|
| 681 | - esc_html__( |
|
| 682 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 683 | - 'event_espresso' |
|
| 684 | - ), |
|
| 685 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 686 | - ) |
|
| 687 | - ); |
|
| 688 | - } |
|
| 689 | - return; |
|
| 690 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
| 691 | - EE_Error::add_attention( |
|
| 692 | - sprintf( |
|
| 693 | - esc_html__( |
|
| 694 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 695 | - 'event_espresso' |
|
| 696 | - ), |
|
| 697 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 698 | - ) |
|
| 699 | - ); |
|
| 700 | - } |
|
| 701 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 702 | - if ( ! $event->tickets_on_sale()) { |
|
| 703 | - return; |
|
| 704 | - } |
|
| 705 | - //made it here so show warning |
|
| 706 | - $this->_edit_event_warning(); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 713 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 714 | - * |
|
| 715 | - * @access protected |
|
| 716 | - * @return void |
|
| 717 | - */ |
|
| 718 | - protected function _edit_event_warning() |
|
| 719 | - { |
|
| 720 | - // we don't want to add warnings during these requests |
|
| 721 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 722 | - return; |
|
| 723 | - } |
|
| 724 | - EE_Error::add_attention( |
|
| 725 | - esc_html__( |
|
| 726 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 727 | - 'event_espresso' |
|
| 728 | - ) |
|
| 729 | - ); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 736 | - * Otherwise, do the normal logic |
|
| 737 | - * |
|
| 738 | - * @return string |
|
| 739 | - * @throws \EE_Error |
|
| 740 | - */ |
|
| 741 | - protected function _create_new_cpt_item() |
|
| 742 | - { |
|
| 743 | - $gmt_offset = get_option('gmt_offset'); |
|
| 744 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 745 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 746 | - EE_Error::add_attention( |
|
| 747 | - sprintf( |
|
| 748 | - __( |
|
| 749 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 750 | - 'event_espresso' |
|
| 751 | - ), |
|
| 752 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 753 | - '</a>' |
|
| 754 | - ), |
|
| 755 | - __FILE__, |
|
| 756 | - __FUNCTION__, |
|
| 757 | - __LINE__ |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - return parent::_create_new_cpt_item(); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - protected function _set_list_table_views_default() |
|
| 766 | - { |
|
| 767 | - $this->_views = array( |
|
| 768 | - 'all' => array( |
|
| 769 | - 'slug' => 'all', |
|
| 770 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 771 | - 'count' => 0, |
|
| 772 | - 'bulk_action' => array( |
|
| 773 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 774 | - ), |
|
| 775 | - ), |
|
| 776 | - 'draft' => array( |
|
| 777 | - 'slug' => 'draft', |
|
| 778 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 779 | - 'count' => 0, |
|
| 780 | - 'bulk_action' => array( |
|
| 781 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 782 | - ), |
|
| 783 | - ), |
|
| 784 | - ); |
|
| 785 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 786 | - $this->_views['trash'] = array( |
|
| 787 | - 'slug' => 'trash', |
|
| 788 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 789 | - 'count' => 0, |
|
| 790 | - 'bulk_action' => array( |
|
| 791 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 792 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 793 | - ), |
|
| 794 | - ); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * @return array |
|
| 802 | - */ |
|
| 803 | - protected function _event_legend_items() |
|
| 804 | - { |
|
| 805 | - $items = array( |
|
| 806 | - 'view_details' => array( |
|
| 807 | - 'class' => 'dashicons dashicons-search', |
|
| 808 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 809 | - ), |
|
| 810 | - 'edit_event' => array( |
|
| 811 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 812 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 813 | - ), |
|
| 814 | - 'view_attendees' => array( |
|
| 815 | - 'class' => 'dashicons dashicons-groups', |
|
| 816 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 817 | - ), |
|
| 818 | - ); |
|
| 819 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 820 | - $statuses = array( |
|
| 821 | - 'sold_out_status' => array( |
|
| 822 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 823 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 824 | - ), |
|
| 825 | - 'active_status' => array( |
|
| 826 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 827 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 828 | - ), |
|
| 829 | - 'upcoming_status' => array( |
|
| 830 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 831 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 832 | - ), |
|
| 833 | - 'postponed_status' => array( |
|
| 834 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 835 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 836 | - ), |
|
| 837 | - 'cancelled_status' => array( |
|
| 838 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 839 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 840 | - ), |
|
| 841 | - 'expired_status' => array( |
|
| 842 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 843 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 844 | - ), |
|
| 845 | - 'inactive_status' => array( |
|
| 846 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 847 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 848 | - ), |
|
| 849 | - ); |
|
| 850 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 851 | - return array_merge($items, $statuses); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - /** |
|
| 857 | - * _event_model |
|
| 858 | - * |
|
| 859 | - * @return EEM_Event |
|
| 860 | - */ |
|
| 861 | - private function _event_model() |
|
| 862 | - { |
|
| 863 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 864 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 865 | - } |
|
| 866 | - return $this->_event_model; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 873 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 874 | - * |
|
| 875 | - * @param string $return the current html |
|
| 876 | - * @param int $id the post id for the page |
|
| 877 | - * @param string $new_title What the title is |
|
| 878 | - * @param string $new_slug what the slug is |
|
| 879 | - * @return string The new html string for the permalink area |
|
| 880 | - */ |
|
| 881 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 882 | - { |
|
| 883 | - //make sure this is only when editing |
|
| 884 | - if ( ! empty($id)) { |
|
| 885 | - $post = get_post($id); |
|
| 886 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 887 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 888 | - . '</a> '; |
|
| 889 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 890 | - . $post->ID |
|
| 891 | - . ']">'; |
|
| 892 | - } |
|
| 893 | - return $return; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * _events_overview_list_table |
|
| 900 | - * This contains the logic for showing the events_overview list |
|
| 901 | - * |
|
| 902 | - * @access protected |
|
| 903 | - * @return void |
|
| 904 | - * @throws \EE_Error |
|
| 905 | - */ |
|
| 906 | - protected function _events_overview_list_table() |
|
| 907 | - { |
|
| 908 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 909 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 910 | - ? (array)$this->_template_args['after_list_table'] |
|
| 911 | - : array(); |
|
| 912 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 913 | - . EEH_Template::get_button_or_link( |
|
| 914 | - get_post_type_archive_link('espresso_events'), |
|
| 915 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 916 | - 'button' |
|
| 917 | - ); |
|
| 918 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 919 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 920 | - 'create_new', |
|
| 921 | - 'add', |
|
| 922 | - array(), |
|
| 923 | - 'add-new-h2' |
|
| 924 | - ); |
|
| 925 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * this allows for extra misc actions in the default WP publish box |
|
| 932 | - * |
|
| 933 | - * @return void |
|
| 934 | - */ |
|
| 935 | - public function extra_misc_actions_publish_box() |
|
| 936 | - { |
|
| 937 | - $this->_generate_publish_box_extra_content(); |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 944 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 945 | - * data. |
|
| 946 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 947 | - * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 948 | - * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 949 | - * you handle this accordingly. |
|
| 950 | - * |
|
| 951 | - * @access protected |
|
| 952 | - * @abstract |
|
| 953 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 954 | - * @param object $post The post object of the cpt that was saved. |
|
| 955 | - * @return void |
|
| 956 | - */ |
|
| 957 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 958 | - { |
|
| 959 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 960 | - //get out we're not processing an event save. |
|
| 961 | - return; |
|
| 962 | - } |
|
| 963 | - $event_values = array( |
|
| 964 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 965 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 966 | - 'EVT_additional_limit' => min( |
|
| 967 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 968 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 969 | - ), |
|
| 970 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 971 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 972 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 973 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 974 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 975 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 976 | - ? $this->_req_data['timezone_string'] : null, |
|
| 977 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 978 | - ? $this->_req_data['externalURL'] : null, |
|
| 979 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 980 | - ? $this->_req_data['event_phone'] : null, |
|
| 981 | - ); |
|
| 982 | - //update event |
|
| 983 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 984 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 985 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 986 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 987 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 988 | - $event_update_callbacks = apply_filters( |
|
| 989 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 990 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 991 | - ); |
|
| 992 | - $att_success = true; |
|
| 993 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 994 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 995 | - $att_success = ! $att_success ? $att_success |
|
| 996 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 997 | - } |
|
| 998 | - //any errors? |
|
| 999 | - if ($success && false === $att_success) { |
|
| 1000 | - EE_Error::add_error( |
|
| 1001 | - esc_html__( |
|
| 1002 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1003 | - 'event_espresso' |
|
| 1004 | - ), |
|
| 1005 | - __FILE__, |
|
| 1006 | - __FUNCTION__, |
|
| 1007 | - __LINE__ |
|
| 1008 | - ); |
|
| 1009 | - } else if ($success === false) { |
|
| 1010 | - EE_Error::add_error( |
|
| 1011 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1012 | - __FILE__, |
|
| 1013 | - __FUNCTION__, |
|
| 1014 | - __LINE__ |
|
| 1015 | - ); |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * @see parent::restore_item() |
|
| 1023 | - * @param int $post_id |
|
| 1024 | - * @param int $revision_id |
|
| 1025 | - */ |
|
| 1026 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1027 | - { |
|
| 1028 | - //copy existing event meta to new post |
|
| 1029 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1030 | - if ($post_evt instanceof EE_Event) { |
|
| 1031 | - //meta revision restore |
|
| 1032 | - $post_evt->restore_revision($revision_id); |
|
| 1033 | - //related objs restore |
|
| 1034 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * Attach the venue to the Event |
|
| 1042 | - * |
|
| 1043 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1044 | - * @param array $data The request data from the form |
|
| 1045 | - * @return bool Success or fail. |
|
| 1046 | - */ |
|
| 1047 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1048 | - { |
|
| 1049 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1050 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1051 | - $rows_affected = null; |
|
| 1052 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1053 | - // very important. If we don't have a venue name... |
|
| 1054 | - // then we'll get out because not necessary to create empty venue |
|
| 1055 | - if (empty($data['venue_title'])) { |
|
| 1056 | - return false; |
|
| 1057 | - } |
|
| 1058 | - $venue_array = array( |
|
| 1059 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1060 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1061 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1062 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1063 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1064 | - : null, |
|
| 1065 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1066 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1067 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1068 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1069 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1070 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1071 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1072 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1073 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1074 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1075 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1076 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1077 | - 'status' => 'publish', |
|
| 1078 | - ); |
|
| 1079 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1080 | - if ( ! empty($venue_id)) { |
|
| 1081 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1082 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1083 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1084 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1085 | - return $rows_affected > 0 ? true : false; |
|
| 1086 | - } else { |
|
| 1087 | - //we insert the venue |
|
| 1088 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1089 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1090 | - return ! empty($venue_id) ? true : false; |
|
| 1091 | - } |
|
| 1092 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1099 | - * |
|
| 1100 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1101 | - * @param array $data The request data from the form |
|
| 1102 | - * @return array |
|
| 1103 | - */ |
|
| 1104 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1105 | - { |
|
| 1106 | - $success = true; |
|
| 1107 | - $saved_dtt = null; |
|
| 1108 | - $saved_tickets = array(); |
|
| 1109 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1110 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1111 | - //trim all values to ensure any excess whitespace is removed. |
|
| 1112 | - $dtt = array_map('trim', $dtt); |
|
| 1113 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1114 | - : $dtt['DTT_EVT_start']; |
|
| 1115 | - $datetime_values = array( |
|
| 1116 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1117 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1118 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1119 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1120 | - 'DTT_order' => $row, |
|
| 1121 | - ); |
|
| 1122 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1123 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 1124 | - $DTM = EE_Registry::instance() |
|
| 1125 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1126 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1127 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1128 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1129 | - foreach ($datetime_values as $field => $value) { |
|
| 1130 | - $DTM->set($field, $value); |
|
| 1131 | - } |
|
| 1132 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1133 | - $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1134 | - } else { |
|
| 1135 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1136 | - 'Datetime', |
|
| 1137 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1138 | - false, |
|
| 1139 | - false |
|
| 1140 | - ); |
|
| 1141 | - foreach ($datetime_values as $field => $value) { |
|
| 1142 | - $DTM->set($field, $value); |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - $DTM->save(); |
|
| 1146 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1147 | - //load DTT helper |
|
| 1148 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1149 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1150 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1151 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1152 | - $DTT->save(); |
|
| 1153 | - } |
|
| 1154 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1155 | - $saved_dtt = $DTT; |
|
| 1156 | - $success = ! $success ? $success : $DTT; |
|
| 1157 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1158 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1159 | - } |
|
| 1160 | - //no dtts get deleted so we don't do any of that logic here. |
|
| 1161 | - //update tickets next |
|
| 1162 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1163 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1164 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1165 | - $update_prices = false; |
|
| 1166 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1167 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1168 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1169 | - $tkt = array_map('trim', $tkt); |
|
| 1170 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1171 | - //let's use now in the set timezone. |
|
| 1172 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1173 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1174 | - } |
|
| 1175 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1176 | - //use the start date of the first datetime |
|
| 1177 | - $dtt = $evtobj->first_datetime(); |
|
| 1178 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1179 | - $incoming_date_formats[0], |
|
| 1180 | - $incoming_date_formats[1] |
|
| 1181 | - ); |
|
| 1182 | - } |
|
| 1183 | - $TKT_values = array( |
|
| 1184 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1185 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1186 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1187 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1188 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1189 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1190 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1191 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1192 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1193 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1194 | - 'TKT_row' => $row, |
|
| 1195 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1196 | - 'TKT_price' => $ticket_price, |
|
| 1197 | - ); |
|
| 1198 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1199 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1200 | - $TKT_values['TKT_ID'] = 0; |
|
| 1201 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1202 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1203 | - $update_prices = true; |
|
| 1204 | - } |
|
| 1205 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1206 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1207 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1208 | - if ( ! empty($tkt['TKT_ID'])) { |
|
| 1209 | - $TKT = EE_Registry::instance() |
|
| 1210 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1211 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1212 | - if ($TKT instanceof EE_Ticket) { |
|
| 1213 | - $ticket_sold = $TKT->count_related( |
|
| 1214 | - 'Registration', |
|
| 1215 | - array( |
|
| 1216 | - array( |
|
| 1217 | - 'STS_ID' => array( |
|
| 1218 | - 'NOT IN', |
|
| 1219 | - array(EEM_Registration::status_id_incomplete), |
|
| 1220 | - ), |
|
| 1221 | - ), |
|
| 1222 | - ) |
|
| 1223 | - ) > 0 ? true : false; |
|
| 1224 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1225 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1226 | - && ! $TKT->get( |
|
| 1227 | - 'TKT_deleted' |
|
| 1228 | - ) ? true : false; |
|
| 1229 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1230 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1231 | - //set new values |
|
| 1232 | - foreach ($TKT_values as $field => $value) { |
|
| 1233 | - if ($field == 'TKT_qty') { |
|
| 1234 | - $TKT->set_qty($value); |
|
| 1235 | - } else { |
|
| 1236 | - $TKT->set($field, $value); |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1240 | - if ($create_new_TKT) { |
|
| 1241 | - //archive the old ticket first |
|
| 1242 | - $TKT->set('TKT_deleted', 1); |
|
| 1243 | - $TKT->save(); |
|
| 1244 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1245 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1246 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1247 | - $TKT = clone $TKT; |
|
| 1248 | - $TKT->set('TKT_ID', 0); |
|
| 1249 | - $TKT->set('TKT_deleted', 0); |
|
| 1250 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1251 | - $TKT->set('TKT_sold', 0); |
|
| 1252 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1253 | - $update_prices = true; |
|
| 1254 | - } |
|
| 1255 | - //make sure price is set if it hasn't been already |
|
| 1256 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1257 | - } |
|
| 1258 | - } else { |
|
| 1259 | - //no TKT_id so a new TKT |
|
| 1260 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1261 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1262 | - if ($TKT instanceof EE_Ticket) { |
|
| 1263 | - //need to reset values to properly account for the date formats |
|
| 1264 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1265 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1266 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1267 | - //set new values |
|
| 1268 | - foreach ($TKT_values as $field => $value) { |
|
| 1269 | - if ($field == 'TKT_qty') { |
|
| 1270 | - $TKT->set_qty($value); |
|
| 1271 | - } else { |
|
| 1272 | - $TKT->set($field, $value); |
|
| 1273 | - } |
|
| 1274 | - } |
|
| 1275 | - $update_prices = true; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - // cap ticket qty by datetime reg limits |
|
| 1279 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1280 | - //update ticket. |
|
| 1281 | - $TKT->save(); |
|
| 1282 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1283 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1284 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1285 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1286 | - $TKT->save(); |
|
| 1287 | - } |
|
| 1288 | - //initially let's add the ticket to the dtt |
|
| 1289 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1290 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1291 | - //add prices to ticket |
|
| 1292 | - $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1293 | - } |
|
| 1294 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1295 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1296 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1297 | - foreach ($tickets_removed as $id) { |
|
| 1298 | - $id = absint($id); |
|
| 1299 | - //get the ticket for this id |
|
| 1300 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1301 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1302 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1303 | - foreach ($dtts as $dtt) { |
|
| 1304 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1305 | - } |
|
| 1306 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1307 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1308 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1309 | - $tkt_to_remove->delete_permanently(); |
|
| 1310 | - } |
|
| 1311 | - return array($saved_dtt, $saved_tickets); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * This attaches a list of given prices to a ticket. |
|
| 1318 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1319 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1320 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1321 | - * |
|
| 1322 | - * @access private |
|
| 1323 | - * @param array $prices Array of prices from the form. |
|
| 1324 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1325 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1326 | - * @return void |
|
| 1327 | - */ |
|
| 1328 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1329 | - { |
|
| 1330 | - foreach ($prices as $row => $prc) { |
|
| 1331 | - $PRC_values = array( |
|
| 1332 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1333 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1334 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1335 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1336 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1337 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1338 | - 'PRC_order' => $row, |
|
| 1339 | - ); |
|
| 1340 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1341 | - $PRC_values['PRC_ID'] = 0; |
|
| 1342 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1343 | - } else { |
|
| 1344 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1345 | - //update this price with new values |
|
| 1346 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1347 | - $PRC->set($field, $newprc); |
|
| 1348 | - } |
|
| 1349 | - $PRC->save(); |
|
| 1350 | - } |
|
| 1351 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1352 | - } |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - |
|
| 1356 | - |
|
| 1357 | - /** |
|
| 1358 | - * Add in our autosave ajax handlers |
|
| 1359 | - * |
|
| 1360 | - * @return void |
|
| 1361 | - */ |
|
| 1362 | - protected function _ee_autosave_create_new() |
|
| 1363 | - { |
|
| 1364 | - // $this->_ee_autosave_edit(); |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - protected function _ee_autosave_edit() |
|
| 1370 | - { |
|
| 1371 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * _generate_publish_box_extra_content |
|
| 1378 | - * |
|
| 1379 | - * @access private |
|
| 1380 | - * @return void |
|
| 1381 | - */ |
|
| 1382 | - private function _generate_publish_box_extra_content() |
|
| 1383 | - { |
|
| 1384 | - //load formatter helper |
|
| 1385 | - //args for getting related registrations |
|
| 1386 | - $approved_query_args = array( |
|
| 1387 | - array( |
|
| 1388 | - 'REG_deleted' => 0, |
|
| 1389 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1390 | - ), |
|
| 1391 | - ); |
|
| 1392 | - $not_approved_query_args = array( |
|
| 1393 | - array( |
|
| 1394 | - 'REG_deleted' => 0, |
|
| 1395 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1396 | - ), |
|
| 1397 | - ); |
|
| 1398 | - $pending_payment_query_args = array( |
|
| 1399 | - array( |
|
| 1400 | - 'REG_deleted' => 0, |
|
| 1401 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1402 | - ), |
|
| 1403 | - ); |
|
| 1404 | - // publish box |
|
| 1405 | - $publish_box_extra_args = array( |
|
| 1406 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1407 | - array( |
|
| 1408 | - 'action' => 'default', |
|
| 1409 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1410 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1411 | - ), |
|
| 1412 | - REG_ADMIN_URL |
|
| 1413 | - ), |
|
| 1414 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1415 | - array( |
|
| 1416 | - 'action' => 'default', |
|
| 1417 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1418 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1419 | - ), |
|
| 1420 | - REG_ADMIN_URL |
|
| 1421 | - ), |
|
| 1422 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1423 | - array( |
|
| 1424 | - 'action' => 'default', |
|
| 1425 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1426 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1427 | - ), |
|
| 1428 | - REG_ADMIN_URL |
|
| 1429 | - ), |
|
| 1430 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1431 | - 'Registration', |
|
| 1432 | - $approved_query_args |
|
| 1433 | - ), |
|
| 1434 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1435 | - 'Registration', |
|
| 1436 | - $not_approved_query_args |
|
| 1437 | - ), |
|
| 1438 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1439 | - 'Registration', |
|
| 1440 | - $pending_payment_query_args |
|
| 1441 | - ), |
|
| 1442 | - 'misc_pub_section_class' => apply_filters( |
|
| 1443 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1444 | - 'misc-pub-section' |
|
| 1445 | - ), |
|
| 1446 | - //'email_attendees_url' => add_query_arg( |
|
| 1447 | - // array( |
|
| 1448 | - // 'event_admin_reports' => 'event_newsletter', |
|
| 1449 | - // 'event_id' => $this->_cpt_model_obj->id |
|
| 1450 | - // ), |
|
| 1451 | - // 'admin.php?page=espresso_registrations' |
|
| 1452 | - //), |
|
| 1453 | - ); |
|
| 1454 | - ob_start(); |
|
| 1455 | - do_action( |
|
| 1456 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1457 | - $this->_cpt_model_obj |
|
| 1458 | - ); |
|
| 1459 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1460 | - // load template |
|
| 1461 | - EEH_Template::display_template( |
|
| 1462 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1463 | - $publish_box_extra_args |
|
| 1464 | - ); |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - |
|
| 1468 | - |
|
| 1469 | - /** |
|
| 1470 | - * This just returns whatever is set as the _event object property |
|
| 1471 | - * //todo this will become obsolete once the models are in place |
|
| 1472 | - * |
|
| 1473 | - * @return object |
|
| 1474 | - */ |
|
| 1475 | - public function get_event_object() |
|
| 1476 | - { |
|
| 1477 | - return $this->_cpt_model_obj; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - |
|
| 1482 | - |
|
| 1483 | - /** METABOXES * */ |
|
| 1484 | - /** |
|
| 1485 | - * _register_event_editor_meta_boxes |
|
| 1486 | - * add all metaboxes related to the event_editor |
|
| 1487 | - * |
|
| 1488 | - * @return void |
|
| 1489 | - */ |
|
| 1490 | - protected function _register_event_editor_meta_boxes() |
|
| 1491 | - { |
|
| 1492 | - $this->verify_cpt_object(); |
|
| 1493 | - add_meta_box( |
|
| 1494 | - 'espresso_event_editor_tickets', |
|
| 1495 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1496 | - array($this, 'ticket_metabox'), |
|
| 1497 | - $this->page_slug, |
|
| 1498 | - 'normal', |
|
| 1499 | - 'high' |
|
| 1500 | - ); |
|
| 1501 | - add_meta_box( |
|
| 1502 | - 'espresso_event_editor_event_options', |
|
| 1503 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1504 | - array($this, 'registration_options_meta_box'), |
|
| 1505 | - $this->page_slug, |
|
| 1506 | - 'side', |
|
| 1507 | - 'default' |
|
| 1508 | - ); |
|
| 1509 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1510 | - // where a metabox has a related management page in the admin |
|
| 1511 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1512 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - |
|
| 1516 | - |
|
| 1517 | - public function ticket_metabox() |
|
| 1518 | - { |
|
| 1519 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1520 | - //defaults for template args |
|
| 1521 | - $template_args = array( |
|
| 1522 | - 'existing_datetime_ids' => '', |
|
| 1523 | - 'event_datetime_help_link' => '', |
|
| 1524 | - 'ticket_options_help_link' => '', |
|
| 1525 | - 'time' => null, |
|
| 1526 | - 'ticket_rows' => '', |
|
| 1527 | - 'existing_ticket_ids' => '', |
|
| 1528 | - 'total_ticket_rows' => 1, |
|
| 1529 | - 'ticket_js_structure' => '', |
|
| 1530 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1531 | - 'disabled' => '', |
|
| 1532 | - ); |
|
| 1533 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1534 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1535 | - /** |
|
| 1536 | - * 1. Start with retrieving Datetimes |
|
| 1537 | - * 2. Fore each datetime get related tickets |
|
| 1538 | - * 3. For each ticket get related prices |
|
| 1539 | - */ |
|
| 1540 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1541 | - /** @type EE_Datetime $first_datetime */ |
|
| 1542 | - $first_datetime = reset($times); |
|
| 1543 | - //do we get related tickets? |
|
| 1544 | - if ($first_datetime instanceof EE_Datetime |
|
| 1545 | - && $first_datetime->ID() !== 0 |
|
| 1546 | - ) { |
|
| 1547 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1548 | - $template_args['time'] = $first_datetime; |
|
| 1549 | - $related_tickets = $first_datetime->tickets( |
|
| 1550 | - array( |
|
| 1551 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1552 | - 'default_where_conditions' => 'none', |
|
| 1553 | - ) |
|
| 1554 | - ); |
|
| 1555 | - if ( ! empty($related_tickets)) { |
|
| 1556 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1557 | - $row = 0; |
|
| 1558 | - foreach ($related_tickets as $ticket) { |
|
| 1559 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1560 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1561 | - $row++; |
|
| 1562 | - } |
|
| 1563 | - } else { |
|
| 1564 | - $template_args['total_ticket_rows'] = 1; |
|
| 1565 | - /** @type EE_Ticket $ticket */ |
|
| 1566 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1567 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1568 | - } |
|
| 1569 | - } else { |
|
| 1570 | - $template_args['time'] = $times[0]; |
|
| 1571 | - /** @type EE_Ticket $ticket */ |
|
| 1572 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1573 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1574 | - // NOTE: we're just sending the first default row |
|
| 1575 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1576 | - } |
|
| 1577 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1578 | - 'event_editor_event_datetimes_help_tab' |
|
| 1579 | - ); |
|
| 1580 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1581 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1582 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1583 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1584 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1585 | - true |
|
| 1586 | - ); |
|
| 1587 | - $template = apply_filters( |
|
| 1588 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1589 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1590 | - ); |
|
| 1591 | - EEH_Template::display_template($template, $template_args); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1598 | - * |
|
| 1599 | - * @access private |
|
| 1600 | - * @param EE_Ticket $ticket the ticket object |
|
| 1601 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1602 | - * @param int $row |
|
| 1603 | - * @return string generated html for the ticket row. |
|
| 1604 | - */ |
|
| 1605 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1606 | - { |
|
| 1607 | - $template_args = array( |
|
| 1608 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1609 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1610 | - : '', |
|
| 1611 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1612 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1613 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1614 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1615 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1616 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1617 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1618 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1619 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1620 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1621 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1622 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1623 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1624 | - : ' disabled=disabled', |
|
| 1625 | - ); |
|
| 1626 | - $price = $ticket->ID() !== 0 |
|
| 1627 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1628 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1629 | - $price_args = array( |
|
| 1630 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1631 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1632 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1633 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1634 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1635 | - ); |
|
| 1636 | - //make sure we have default start and end dates if skeleton |
|
| 1637 | - //handle rows that should NOT be empty |
|
| 1638 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1639 | - //if empty then the start date will be now. |
|
| 1640 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1641 | - } |
|
| 1642 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1643 | - //get the earliest datetime (if present); |
|
| 1644 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1645 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1646 | - 'Datetime', |
|
| 1647 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1648 | - ) |
|
| 1649 | - : null; |
|
| 1650 | - if ( ! empty($earliest_dtt)) { |
|
| 1651 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1652 | - } else { |
|
| 1653 | - $template_args['TKT_end_date'] = date( |
|
| 1654 | - 'Y-m-d h:i a', |
|
| 1655 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1656 | - ); |
|
| 1657 | - } |
|
| 1658 | - } |
|
| 1659 | - $template_args = array_merge($template_args, $price_args); |
|
| 1660 | - $template = apply_filters( |
|
| 1661 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1662 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1663 | - $ticket |
|
| 1664 | - ); |
|
| 1665 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - |
|
| 1670 | - public function registration_options_meta_box() |
|
| 1671 | - { |
|
| 1672 | - $yes_no_values = array( |
|
| 1673 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1674 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1675 | - ); |
|
| 1676 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1677 | - array( |
|
| 1678 | - EEM_Registration::status_id_cancelled, |
|
| 1679 | - EEM_Registration::status_id_declined, |
|
| 1680 | - EEM_Registration::status_id_incomplete, |
|
| 1681 | - ), |
|
| 1682 | - true |
|
| 1683 | - ); |
|
| 1684 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1685 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1686 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1687 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1688 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1689 | - 'default_reg_status', |
|
| 1690 | - $default_reg_status_values, |
|
| 1691 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1692 | - ); |
|
| 1693 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1694 | - 'display_desc', |
|
| 1695 | - $yes_no_values, |
|
| 1696 | - $this->_cpt_model_obj->display_description() |
|
| 1697 | - ); |
|
| 1698 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1699 | - 'display_ticket_selector', |
|
| 1700 | - $yes_no_values, |
|
| 1701 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1702 | - '', |
|
| 1703 | - '', |
|
| 1704 | - false |
|
| 1705 | - ); |
|
| 1706 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1707 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1708 | - '', |
|
| 1709 | - $template_args, |
|
| 1710 | - $yes_no_values, |
|
| 1711 | - $default_reg_status_values |
|
| 1712 | - ); |
|
| 1713 | - EEH_Template::display_template( |
|
| 1714 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1715 | - $template_args |
|
| 1716 | - ); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * _get_events() |
|
| 1723 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1724 | - * |
|
| 1725 | - * @access public |
|
| 1726 | - * @param int $per_page count of items per page (20 default); |
|
| 1727 | - * @param int $current_page what is the current page being viewed. |
|
| 1728 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1729 | - * If FALSE then we return an array of event objects |
|
| 1730 | - * that match the given _view and paging parameters. |
|
| 1731 | - * @return array an array of event objects. |
|
| 1732 | - */ |
|
| 1733 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1734 | - { |
|
| 1735 | - $EEME = $this->_event_model(); |
|
| 1736 | - $offset = ($current_page - 1) * $per_page; |
|
| 1737 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1738 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1739 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1740 | - if (isset($this->_req_data['month_range'])) { |
|
| 1741 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1742 | - $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
| 1743 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1744 | - } |
|
| 1745 | - $where = array(); |
|
| 1746 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1747 | - //determine what post_status our condition will have for the query. |
|
| 1748 | - switch ($status) { |
|
| 1749 | - case 'month' : |
|
| 1750 | - case 'today' : |
|
| 1751 | - case null : |
|
| 1752 | - case 'all' : |
|
| 1753 | - break; |
|
| 1754 | - case 'draft' : |
|
| 1755 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1756 | - break; |
|
| 1757 | - default : |
|
| 1758 | - $where['status'] = $status; |
|
| 1759 | - } |
|
| 1760 | - //categories? |
|
| 1761 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1762 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1763 | - if ( ! empty ($category)) { |
|
| 1764 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1765 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1766 | - } |
|
| 1767 | - //date where conditions |
|
| 1768 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1769 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1770 | - $DateTime = new DateTime( |
|
| 1771 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1772 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1773 | - ); |
|
| 1774 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1775 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1776 | - ->format('t'))->setTime(23, 59, 59) |
|
| 1777 | - ->format(implode(' ', $start_formats)); |
|
| 1778 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1779 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1780 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1781 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1782 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1783 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1784 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1785 | - $now = date('Y-m-01'); |
|
| 1786 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1787 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1788 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1789 | - ->setTime(23, 59, 59) |
|
| 1790 | - ->format(implode(' ', $start_formats)); |
|
| 1791 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1792 | - } |
|
| 1793 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1794 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1795 | - } else { |
|
| 1796 | - if ( ! isset($where['status'])) { |
|
| 1797 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1798 | - $where['OR'] = array( |
|
| 1799 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1800 | - 'AND' => array( |
|
| 1801 | - 'status*inclusive' => array('=', 'private'), |
|
| 1802 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1803 | - ), |
|
| 1804 | - ); |
|
| 1805 | - } |
|
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1809 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1810 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1811 | - ) { |
|
| 1812 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1813 | - } |
|
| 1814 | - } |
|
| 1815 | - //search query handling |
|
| 1816 | - if (isset($this->_req_data['s'])) { |
|
| 1817 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1818 | - $where['OR'] = array( |
|
| 1819 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1820 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1821 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1822 | - ); |
|
| 1823 | - } |
|
| 1824 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1825 | - $query_params = apply_filters( |
|
| 1826 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1827 | - array( |
|
| 1828 | - $where, |
|
| 1829 | - 'limit' => $limit, |
|
| 1830 | - 'order_by' => $orderby, |
|
| 1831 | - 'order' => $order, |
|
| 1832 | - 'group_by' => 'EVT_ID', |
|
| 1833 | - ), |
|
| 1834 | - $this->_req_data |
|
| 1835 | - ); |
|
| 1836 | - //let's first check if we have special requests coming in. |
|
| 1837 | - if (isset($this->_req_data['active_status'])) { |
|
| 1838 | - switch ($this->_req_data['active_status']) { |
|
| 1839 | - case 'upcoming' : |
|
| 1840 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1841 | - break; |
|
| 1842 | - case 'expired' : |
|
| 1843 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1844 | - break; |
|
| 1845 | - case 'active' : |
|
| 1846 | - return $EEME->get_active_events($query_params, $count); |
|
| 1847 | - break; |
|
| 1848 | - case 'inactive' : |
|
| 1849 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1850 | - break; |
|
| 1851 | - } |
|
| 1852 | - } |
|
| 1853 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1854 | - return $events; |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1861 | - * |
|
| 1862 | - * @param string $post_id |
|
| 1863 | - */ |
|
| 1864 | - public function trash_cpt_item($post_id) |
|
| 1865 | - { |
|
| 1866 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1867 | - $this->_trash_or_restore_event('trash', false); |
|
| 1868 | - } |
|
| 1869 | - |
|
| 1870 | - |
|
| 1871 | - |
|
| 1872 | - /** |
|
| 1873 | - * @param string $post_id |
|
| 1874 | - */ |
|
| 1875 | - public function restore_cpt_item($post_id) |
|
| 1876 | - { |
|
| 1877 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1878 | - $this->_trash_or_restore_event('draft', false); |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * @param string $post_id |
|
| 1885 | - */ |
|
| 1886 | - public function delete_cpt_item($post_id) |
|
| 1887 | - { |
|
| 1888 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1889 | - $this->_delete_event(false); |
|
| 1890 | - } |
|
| 1891 | - |
|
| 1892 | - |
|
| 1893 | - |
|
| 1894 | - /** |
|
| 1895 | - * _trash_or_restore_event |
|
| 1896 | - * |
|
| 1897 | - * @access protected |
|
| 1898 | - * @param string $event_status |
|
| 1899 | - * @param bool $redirect_after |
|
| 1900 | - */ |
|
| 1901 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1902 | - { |
|
| 1903 | - //determine the event id and set to array. |
|
| 1904 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1905 | - // loop thru events |
|
| 1906 | - if ($EVT_ID) { |
|
| 1907 | - // clean status |
|
| 1908 | - $event_status = sanitize_key($event_status); |
|
| 1909 | - // grab status |
|
| 1910 | - if ( ! empty($event_status)) { |
|
| 1911 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1912 | - } else { |
|
| 1913 | - $success = false; |
|
| 1914 | - $msg = esc_html__( |
|
| 1915 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1916 | - 'event_espresso' |
|
| 1917 | - ); |
|
| 1918 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1919 | - } |
|
| 1920 | - } else { |
|
| 1921 | - $success = false; |
|
| 1922 | - $msg = esc_html__( |
|
| 1923 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1924 | - 'event_espresso' |
|
| 1925 | - ); |
|
| 1926 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1927 | - } |
|
| 1928 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1929 | - if ($redirect_after) { |
|
| 1930 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1931 | - } |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - |
|
| 1935 | - |
|
| 1936 | - /** |
|
| 1937 | - * _trash_or_restore_events |
|
| 1938 | - * |
|
| 1939 | - * @access protected |
|
| 1940 | - * @param string $event_status |
|
| 1941 | - * @return void |
|
| 1942 | - */ |
|
| 1943 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1944 | - { |
|
| 1945 | - // clean status |
|
| 1946 | - $event_status = sanitize_key($event_status); |
|
| 1947 | - // grab status |
|
| 1948 | - if ( ! empty($event_status)) { |
|
| 1949 | - $success = true; |
|
| 1950 | - //determine the event id and set to array. |
|
| 1951 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1952 | - // loop thru events |
|
| 1953 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 1954 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 1955 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1956 | - $success = $results !== false ? $success : false; |
|
| 1957 | - } else { |
|
| 1958 | - $msg = sprintf( |
|
| 1959 | - esc_html__( |
|
| 1960 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1961 | - 'event_espresso' |
|
| 1962 | - ), |
|
| 1963 | - $EVT_ID |
|
| 1964 | - ); |
|
| 1965 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1966 | - $success = false; |
|
| 1967 | - } |
|
| 1968 | - } |
|
| 1969 | - } else { |
|
| 1970 | - $success = false; |
|
| 1971 | - $msg = esc_html__( |
|
| 1972 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1973 | - 'event_espresso' |
|
| 1974 | - ); |
|
| 1975 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1976 | - } |
|
| 1977 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1978 | - $success = $success ? 2 : false; |
|
| 1979 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1980 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - |
|
| 1984 | - |
|
| 1985 | - /** |
|
| 1986 | - * _trash_or_restore_events |
|
| 1987 | - * |
|
| 1988 | - * @access private |
|
| 1989 | - * @param int $EVT_ID |
|
| 1990 | - * @param string $event_status |
|
| 1991 | - * @return bool |
|
| 1992 | - */ |
|
| 1993 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1994 | - { |
|
| 1995 | - // grab event id |
|
| 1996 | - if ( ! $EVT_ID) { |
|
| 1997 | - $msg = esc_html__( |
|
| 1998 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 1999 | - 'event_espresso' |
|
| 2000 | - ); |
|
| 2001 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2002 | - return false; |
|
| 2003 | - } |
|
| 2004 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2005 | - // clean status |
|
| 2006 | - $event_status = sanitize_key($event_status); |
|
| 2007 | - // grab status |
|
| 2008 | - if (empty($event_status)) { |
|
| 2009 | - $msg = esc_html__( |
|
| 2010 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2011 | - 'event_espresso' |
|
| 2012 | - ); |
|
| 2013 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2014 | - return false; |
|
| 2015 | - } |
|
| 2016 | - // was event trashed or restored ? |
|
| 2017 | - switch ($event_status) { |
|
| 2018 | - case 'draft' : |
|
| 2019 | - $action = 'restored from the trash'; |
|
| 2020 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2021 | - break; |
|
| 2022 | - case 'trash' : |
|
| 2023 | - $action = 'moved to the trash'; |
|
| 2024 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2025 | - break; |
|
| 2026 | - default : |
|
| 2027 | - $action = 'updated'; |
|
| 2028 | - $hook = false; |
|
| 2029 | - } |
|
| 2030 | - //use class to change status |
|
| 2031 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2032 | - $success = $this->_cpt_model_obj->save(); |
|
| 2033 | - if ($success === false) { |
|
| 2034 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2035 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2036 | - return false; |
|
| 2037 | - } |
|
| 2038 | - if ($hook) { |
|
| 2039 | - do_action($hook); |
|
| 2040 | - } |
|
| 2041 | - return true; |
|
| 2042 | - } |
|
| 2043 | - |
|
| 2044 | - |
|
| 2045 | - |
|
| 2046 | - /** |
|
| 2047 | - * _delete_event |
|
| 2048 | - * |
|
| 2049 | - * @access protected |
|
| 2050 | - * @param bool $redirect_after |
|
| 2051 | - */ |
|
| 2052 | - protected function _delete_event($redirect_after = true) |
|
| 2053 | - { |
|
| 2054 | - //determine the event id and set to array. |
|
| 2055 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2056 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2057 | - // loop thru events |
|
| 2058 | - if ($EVT_ID) { |
|
| 2059 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2060 | - // get list of events with no prices |
|
| 2061 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2062 | - // remove this event from the list of events with no prices |
|
| 2063 | - if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2064 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2065 | - } |
|
| 2066 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2067 | - } else { |
|
| 2068 | - $success = false; |
|
| 2069 | - $msg = esc_html__( |
|
| 2070 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2071 | - 'event_espresso' |
|
| 2072 | - ); |
|
| 2073 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2074 | - } |
|
| 2075 | - if ($redirect_after) { |
|
| 2076 | - $this->_redirect_after_action( |
|
| 2077 | - $success, |
|
| 2078 | - 'Event', |
|
| 2079 | - 'deleted', |
|
| 2080 | - array('action' => 'default', 'status' => 'trash') |
|
| 2081 | - ); |
|
| 2082 | - } |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - |
|
| 2086 | - |
|
| 2087 | - /** |
|
| 2088 | - * _delete_events |
|
| 2089 | - * |
|
| 2090 | - * @access protected |
|
| 2091 | - * @return void |
|
| 2092 | - */ |
|
| 2093 | - protected function _delete_events() |
|
| 2094 | - { |
|
| 2095 | - $success = true; |
|
| 2096 | - // get list of events with no prices |
|
| 2097 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2098 | - //determine the event id and set to array. |
|
| 2099 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2100 | - // loop thru events |
|
| 2101 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2102 | - $EVT_ID = absint($EVT_ID); |
|
| 2103 | - if ($EVT_ID) { |
|
| 2104 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2105 | - $success = $results !== false ? $success : false; |
|
| 2106 | - // remove this event from the list of events with no prices |
|
| 2107 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2108 | - } else { |
|
| 2109 | - $success = false; |
|
| 2110 | - $msg = esc_html__( |
|
| 2111 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2112 | - 'event_espresso' |
|
| 2113 | - ); |
|
| 2114 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2115 | - } |
|
| 2116 | - } |
|
| 2117 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2118 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2119 | - $success = $success ? 2 : false; |
|
| 2120 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2121 | - } |
|
| 2122 | - |
|
| 2123 | - |
|
| 2124 | - |
|
| 2125 | - /** |
|
| 2126 | - * _permanently_delete_event |
|
| 2127 | - * |
|
| 2128 | - * @access private |
|
| 2129 | - * @param int $EVT_ID |
|
| 2130 | - * @return bool |
|
| 2131 | - */ |
|
| 2132 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2133 | - { |
|
| 2134 | - // grab event id |
|
| 2135 | - if ( ! $EVT_ID) { |
|
| 2136 | - $msg = esc_html__( |
|
| 2137 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2138 | - 'event_espresso' |
|
| 2139 | - ); |
|
| 2140 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2141 | - return false; |
|
| 2142 | - } |
|
| 2143 | - if ( |
|
| 2144 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2145 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2146 | - ) { |
|
| 2147 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2148 | - } |
|
| 2149 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2150 | - return false; |
|
| 2151 | - } |
|
| 2152 | - //need to delete related tickets and prices first. |
|
| 2153 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2154 | - foreach ($datetimes as $datetime) { |
|
| 2155 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2156 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2157 | - foreach ($tickets as $ticket) { |
|
| 2158 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2159 | - $ticket->delete_related_permanently('Price'); |
|
| 2160 | - $ticket->delete_permanently(); |
|
| 2161 | - } |
|
| 2162 | - $datetime->delete(); |
|
| 2163 | - } |
|
| 2164 | - //what about related venues or terms? |
|
| 2165 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2166 | - foreach ($venues as $venue) { |
|
| 2167 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2168 | - } |
|
| 2169 | - //any attached question groups? |
|
| 2170 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2171 | - if ( ! empty($question_groups)) { |
|
| 2172 | - foreach ($question_groups as $question_group) { |
|
| 2173 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2174 | - } |
|
| 2175 | - } |
|
| 2176 | - //Message Template Groups |
|
| 2177 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2178 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2179 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2180 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2181 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2182 | - } |
|
| 2183 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2184 | - // did it all go as planned ? |
|
| 2185 | - if ($success) { |
|
| 2186 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2187 | - EE_Error::add_success($msg); |
|
| 2188 | - } else { |
|
| 2189 | - $msg = sprintf( |
|
| 2190 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2191 | - $EVT_ID |
|
| 2192 | - ); |
|
| 2193 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2194 | - return false; |
|
| 2195 | - } |
|
| 2196 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2197 | - return true; |
|
| 2198 | - } |
|
| 2199 | - |
|
| 2200 | - |
|
| 2201 | - |
|
| 2202 | - /** |
|
| 2203 | - * get total number of events |
|
| 2204 | - * |
|
| 2205 | - * @access public |
|
| 2206 | - * @return int |
|
| 2207 | - */ |
|
| 2208 | - public function total_events() |
|
| 2209 | - { |
|
| 2210 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2211 | - return $count; |
|
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - |
|
| 2215 | - |
|
| 2216 | - /** |
|
| 2217 | - * get total number of draft events |
|
| 2218 | - * |
|
| 2219 | - * @access public |
|
| 2220 | - * @return int |
|
| 2221 | - */ |
|
| 2222 | - public function total_events_draft() |
|
| 2223 | - { |
|
| 2224 | - $where = array( |
|
| 2225 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2226 | - ); |
|
| 2227 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2228 | - return $count; |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * get total number of trashed events |
|
| 2235 | - * |
|
| 2236 | - * @access public |
|
| 2237 | - * @return int |
|
| 2238 | - */ |
|
| 2239 | - public function total_trashed_events() |
|
| 2240 | - { |
|
| 2241 | - $where = array( |
|
| 2242 | - 'status' => 'trash', |
|
| 2243 | - ); |
|
| 2244 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2245 | - return $count; |
|
| 2246 | - } |
|
| 2247 | - |
|
| 2248 | - |
|
| 2249 | - |
|
| 2250 | - /** |
|
| 2251 | - * _default_event_settings |
|
| 2252 | - * This generates the Default Settings Tab |
|
| 2253 | - * |
|
| 2254 | - * @return void |
|
| 2255 | - */ |
|
| 2256 | - protected function _default_event_settings() |
|
| 2257 | - { |
|
| 2258 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2259 | - $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2260 | - // exclude array |
|
| 2261 | - array( |
|
| 2262 | - EEM_Registration::status_id_cancelled, |
|
| 2263 | - EEM_Registration::status_id_declined, |
|
| 2264 | - EEM_Registration::status_id_incomplete, |
|
| 2265 | - EEM_Registration::status_id_wait_list, |
|
| 2266 | - ), |
|
| 2267 | - // translated |
|
| 2268 | - true |
|
| 2269 | - ); |
|
| 2270 | - $this->_template_args['default_reg_status'] = isset( |
|
| 2271 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2272 | - ) |
|
| 2273 | - && in_array( |
|
| 2274 | - EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2275 | - $this->_template_args['reg_status_array'] |
|
| 2276 | - ) |
|
| 2277 | - ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2278 | - : EEM_Registration::status_id_pending_payment; |
|
| 2279 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2280 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2281 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2282 | - EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2283 | - $this->_template_args, |
|
| 2284 | - true |
|
| 2285 | - ); |
|
| 2286 | - $this->display_admin_page_with_sidebar(); |
|
| 2287 | - } |
|
| 2288 | - |
|
| 2289 | - |
|
| 2290 | - |
|
| 2291 | - /** |
|
| 2292 | - * _update_default_event_settings |
|
| 2293 | - * |
|
| 2294 | - * @access protected |
|
| 2295 | - * @return void |
|
| 2296 | - */ |
|
| 2297 | - protected function _update_default_event_settings() |
|
| 2298 | - { |
|
| 2299 | - EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2300 | - ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2301 | - : EEM_Registration::status_id_pending_payment; |
|
| 2302 | - $what = 'Default Event Settings'; |
|
| 2303 | - $success = $this->_update_espresso_configuration( |
|
| 2304 | - $what, |
|
| 2305 | - EE_Config::instance(), |
|
| 2306 | - __FILE__, |
|
| 2307 | - __FUNCTION__, |
|
| 2308 | - __LINE__ |
|
| 2309 | - ); |
|
| 2310 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2311 | - } |
|
| 2312 | - |
|
| 2313 | - |
|
| 2314 | - |
|
| 2315 | - /************* Templates *************/ |
|
| 2316 | - protected function _template_settings() |
|
| 2317 | - { |
|
| 2318 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2319 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2320 | - . EVENTS_ASSETS_URL |
|
| 2321 | - . DS |
|
| 2322 | - . 'images' |
|
| 2323 | - . DS |
|
| 2324 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2325 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2326 | - . '" />'; |
|
| 2327 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2328 | - 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2329 | - 'event_espresso' |
|
| 2330 | - ) . '</strong>'; |
|
| 2331 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2332 | - } |
|
| 2333 | - |
|
| 2334 | - |
|
| 2335 | - /** Event Category Stuff **/ |
|
| 2336 | - /** |
|
| 2337 | - * set the _category property with the category object for the loaded page. |
|
| 2338 | - * |
|
| 2339 | - * @access private |
|
| 2340 | - * @return void |
|
| 2341 | - */ |
|
| 2342 | - private function _set_category_object() |
|
| 2343 | - { |
|
| 2344 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2345 | - return; |
|
| 2346 | - } //already have the category object so get out. |
|
| 2347 | - //set default category object |
|
| 2348 | - $this->_set_empty_category_object(); |
|
| 2349 | - //only set if we've got an id |
|
| 2350 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2351 | - return; |
|
| 2352 | - } |
|
| 2353 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2354 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2355 | - if ( ! empty($term)) { |
|
| 2356 | - $this->_category->category_name = $term->name; |
|
| 2357 | - $this->_category->category_identifier = $term->slug; |
|
| 2358 | - $this->_category->category_desc = $term->description; |
|
| 2359 | - $this->_category->id = $term->term_id; |
|
| 2360 | - $this->_category->parent = $term->parent; |
|
| 2361 | - } |
|
| 2362 | - } |
|
| 2363 | - |
|
| 2364 | - |
|
| 2365 | - |
|
| 2366 | - private function _set_empty_category_object() |
|
| 2367 | - { |
|
| 2368 | - $this->_category = new stdClass(); |
|
| 2369 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2370 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2371 | - } |
|
| 2372 | - |
|
| 2373 | - |
|
| 2374 | - |
|
| 2375 | - protected function _category_list_table() |
|
| 2376 | - { |
|
| 2377 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2378 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2379 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2380 | - 'add_category', |
|
| 2381 | - 'add_category', |
|
| 2382 | - array(), |
|
| 2383 | - 'add-new-h2' |
|
| 2384 | - ); |
|
| 2385 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - |
|
| 2389 | - |
|
| 2390 | - /** |
|
| 2391 | - * @param $view |
|
| 2392 | - */ |
|
| 2393 | - protected function _category_details($view) |
|
| 2394 | - { |
|
| 2395 | - //load formatter helper |
|
| 2396 | - //load field generator helper |
|
| 2397 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2398 | - $this->_set_add_edit_form_tags($route); |
|
| 2399 | - $this->_set_category_object(); |
|
| 2400 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2401 | - $delete_action = 'delete_category'; |
|
| 2402 | - //custom redirect |
|
| 2403 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2404 | - array('action' => 'category_list'), |
|
| 2405 | - $this->_admin_base_url |
|
| 2406 | - ); |
|
| 2407 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2408 | - //take care of contents |
|
| 2409 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2410 | - $this->display_admin_page_with_sidebar(); |
|
| 2411 | - } |
|
| 2412 | - |
|
| 2413 | - |
|
| 2414 | - |
|
| 2415 | - /** |
|
| 2416 | - * @return mixed |
|
| 2417 | - */ |
|
| 2418 | - protected function _category_details_content() |
|
| 2419 | - { |
|
| 2420 | - $editor_args['category_desc'] = array( |
|
| 2421 | - 'type' => 'wp_editor', |
|
| 2422 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2423 | - 'class' => 'my_editor_custom', |
|
| 2424 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2425 | - ); |
|
| 2426 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2427 | - $all_terms = get_terms( |
|
| 2428 | - array('espresso_event_categories'), |
|
| 2429 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2430 | - ); |
|
| 2431 | - //setup category select for term parents. |
|
| 2432 | - $category_select_values[] = array( |
|
| 2433 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2434 | - 'id' => 0, |
|
| 2435 | - ); |
|
| 2436 | - foreach ($all_terms as $term) { |
|
| 2437 | - $category_select_values[] = array( |
|
| 2438 | - 'text' => $term->name, |
|
| 2439 | - 'id' => $term->term_id, |
|
| 2440 | - ); |
|
| 2441 | - } |
|
| 2442 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2443 | - 'category_parent', |
|
| 2444 | - $category_select_values, |
|
| 2445 | - $this->_category->parent |
|
| 2446 | - ); |
|
| 2447 | - $template_args = array( |
|
| 2448 | - 'category' => $this->_category, |
|
| 2449 | - 'category_select' => $category_select, |
|
| 2450 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2451 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2452 | - 'disable' => '', |
|
| 2453 | - 'disabled_message' => false, |
|
| 2454 | - ); |
|
| 2455 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2456 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2457 | - } |
|
| 2458 | - |
|
| 2459 | - |
|
| 2460 | - |
|
| 2461 | - protected function _delete_categories() |
|
| 2462 | - { |
|
| 2463 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2464 | - : (array)$this->_req_data['category_id']; |
|
| 2465 | - foreach ($cat_ids as $cat_id) { |
|
| 2466 | - $this->_delete_category($cat_id); |
|
| 2467 | - } |
|
| 2468 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2469 | - $query_args = array( |
|
| 2470 | - 'action' => 'category_list', |
|
| 2471 | - ); |
|
| 2472 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - |
|
| 2476 | - |
|
| 2477 | - /** |
|
| 2478 | - * @param $cat_id |
|
| 2479 | - */ |
|
| 2480 | - protected function _delete_category($cat_id) |
|
| 2481 | - { |
|
| 2482 | - $cat_id = absint($cat_id); |
|
| 2483 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2484 | - } |
|
| 2485 | - |
|
| 2486 | - |
|
| 2487 | - |
|
| 2488 | - /** |
|
| 2489 | - * @param $new_category |
|
| 2490 | - */ |
|
| 2491 | - protected function _insert_or_update_category($new_category) |
|
| 2492 | - { |
|
| 2493 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2494 | - $success = 0; //we already have a success message so lets not send another. |
|
| 2495 | - if ($cat_id) { |
|
| 2496 | - $query_args = array( |
|
| 2497 | - 'action' => 'edit_category', |
|
| 2498 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2499 | - ); |
|
| 2500 | - } else { |
|
| 2501 | - $query_args = array('action' => 'add_category'); |
|
| 2502 | - } |
|
| 2503 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2504 | - } |
|
| 2505 | - |
|
| 2506 | - |
|
| 2507 | - |
|
| 2508 | - /** |
|
| 2509 | - * @param bool $update |
|
| 2510 | - * @return bool|mixed|string |
|
| 2511 | - */ |
|
| 2512 | - private function _insert_category($update = false) |
|
| 2513 | - { |
|
| 2514 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2515 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2516 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2517 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2518 | - if (empty($category_name)) { |
|
| 2519 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2520 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2521 | - return false; |
|
| 2522 | - } |
|
| 2523 | - $term_args = array( |
|
| 2524 | - 'name' => $category_name, |
|
| 2525 | - 'description' => $category_desc, |
|
| 2526 | - 'parent' => $category_parent, |
|
| 2527 | - ); |
|
| 2528 | - //was the category_identifier input disabled? |
|
| 2529 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2530 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2531 | - } |
|
| 2532 | - $insert_ids = $update |
|
| 2533 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2534 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2535 | - if ( ! is_array($insert_ids)) { |
|
| 2536 | - $msg = esc_html__( |
|
| 2537 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2538 | - 'event_espresso' |
|
| 2539 | - ); |
|
| 2540 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2541 | - } else { |
|
| 2542 | - $cat_id = $insert_ids['term_id']; |
|
| 2543 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2544 | - EE_Error::add_success($msg); |
|
| 2545 | - } |
|
| 2546 | - return $cat_id; |
|
| 2547 | - } |
|
| 2548 | - |
|
| 2549 | - |
|
| 2550 | - |
|
| 2551 | - /** |
|
| 2552 | - * @param int $per_page |
|
| 2553 | - * @param int $current_page |
|
| 2554 | - * @param bool $count |
|
| 2555 | - * @return \EE_Base_Class[]|int |
|
| 2556 | - */ |
|
| 2557 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2558 | - { |
|
| 2559 | - //testing term stuff |
|
| 2560 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2561 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2562 | - $limit = ($current_page - 1) * $per_page; |
|
| 2563 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2564 | - if (isset($this->_req_data['s'])) { |
|
| 2565 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2566 | - $where['OR'] = array( |
|
| 2567 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2568 | - 'description' => array('LIKE', $sstr), |
|
| 2569 | - ); |
|
| 2570 | - } |
|
| 2571 | - $query_params = array( |
|
| 2572 | - $where, |
|
| 2573 | - 'order_by' => array($orderby => $order), |
|
| 2574 | - 'limit' => $limit . ',' . $per_page, |
|
| 2575 | - 'force_join' => array('Term'), |
|
| 2576 | - ); |
|
| 2577 | - $categories = $count |
|
| 2578 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2579 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2580 | - return $categories; |
|
| 2581 | - } |
|
| 2582 | - |
|
| 2583 | - |
|
| 2584 | - |
|
| 2585 | - /* end category stuff */ |
|
| 2586 | - /**************/ |
|
| 384 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 385 | + 'require_nonce' => false, |
|
| 386 | + ), |
|
| 387 | + 'default_event_settings' => array( |
|
| 388 | + 'nav' => array( |
|
| 389 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 390 | + 'order' => 40, |
|
| 391 | + ), |
|
| 392 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 393 | + 'labels' => array( |
|
| 394 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 395 | + ), |
|
| 396 | + 'help_tabs' => array( |
|
| 397 | + 'default_settings_help_tab' => array( |
|
| 398 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 399 | + 'filename' => 'events_default_settings', |
|
| 400 | + ), |
|
| 401 | + 'default_settings_status_help_tab' => array( |
|
| 402 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 403 | + 'filename' => 'events_default_settings_status', |
|
| 404 | + ), |
|
| 405 | + ), |
|
| 406 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 407 | + 'require_nonce' => false, |
|
| 408 | + ), |
|
| 409 | + //template settings |
|
| 410 | + 'template_settings' => array( |
|
| 411 | + 'nav' => array( |
|
| 412 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 413 | + 'order' => 30, |
|
| 414 | + ), |
|
| 415 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 416 | + 'help_tabs' => array( |
|
| 417 | + 'general_settings_templates_help_tab' => array( |
|
| 418 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 419 | + 'filename' => 'general_settings_templates', |
|
| 420 | + ), |
|
| 421 | + ), |
|
| 422 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 423 | + 'require_nonce' => false, |
|
| 424 | + ), |
|
| 425 | + //event category stuff |
|
| 426 | + 'add_category' => array( |
|
| 427 | + 'nav' => array( |
|
| 428 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 429 | + 'order' => 15, |
|
| 430 | + 'persistent' => false, |
|
| 431 | + ), |
|
| 432 | + 'help_tabs' => array( |
|
| 433 | + 'add_category_help_tab' => array( |
|
| 434 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 435 | + 'filename' => 'events_add_category', |
|
| 436 | + ), |
|
| 437 | + ), |
|
| 438 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 439 | + 'metaboxes' => array('_publish_post_box'), |
|
| 440 | + 'require_nonce' => false, |
|
| 441 | + ), |
|
| 442 | + 'edit_category' => array( |
|
| 443 | + 'nav' => array( |
|
| 444 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 445 | + 'order' => 15, |
|
| 446 | + 'persistent' => false, |
|
| 447 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 448 | + ? add_query_arg( |
|
| 449 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 450 | + $this->_current_page_view_url |
|
| 451 | + ) |
|
| 452 | + : $this->_admin_base_url, |
|
| 453 | + ), |
|
| 454 | + 'help_tabs' => array( |
|
| 455 | + 'edit_category_help_tab' => array( |
|
| 456 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 457 | + 'filename' => 'events_edit_category', |
|
| 458 | + ), |
|
| 459 | + ), |
|
| 460 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 461 | + 'metaboxes' => array('_publish_post_box'), |
|
| 462 | + 'require_nonce' => false, |
|
| 463 | + ), |
|
| 464 | + 'category_list' => array( |
|
| 465 | + 'nav' => array( |
|
| 466 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 467 | + 'order' => 20, |
|
| 468 | + ), |
|
| 469 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 470 | + 'help_tabs' => array( |
|
| 471 | + 'events_categories_help_tab' => array( |
|
| 472 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 473 | + 'filename' => 'events_categories', |
|
| 474 | + ), |
|
| 475 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 476 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 477 | + 'filename' => 'events_categories_table_column_headings', |
|
| 478 | + ), |
|
| 479 | + 'events_categories_view_help_tab' => array( |
|
| 480 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 481 | + 'filename' => 'events_categories_views', |
|
| 482 | + ), |
|
| 483 | + 'events_categories_other_help_tab' => array( |
|
| 484 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 485 | + 'filename' => 'events_categories_other', |
|
| 486 | + ), |
|
| 487 | + ), |
|
| 488 | + 'help_tour' => array( |
|
| 489 | + 'Event_Categories_Help_Tour', |
|
| 490 | + ), |
|
| 491 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 492 | + 'require_nonce' => false, |
|
| 493 | + ), |
|
| 494 | + ); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + protected function _add_screen_options() |
|
| 500 | + { |
|
| 501 | + //todo |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + protected function _add_screen_options_default() |
|
| 507 | + { |
|
| 508 | + $this->_per_page_screen_option(); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + protected function _add_screen_options_category_list() |
|
| 514 | + { |
|
| 515 | + $page_title = $this->_admin_page_title; |
|
| 516 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 517 | + $this->_per_page_screen_option(); |
|
| 518 | + $this->_admin_page_title = $page_title; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + protected function _add_feature_pointers() |
|
| 524 | + { |
|
| 525 | + //todo |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + public function load_scripts_styles() |
|
| 531 | + { |
|
| 532 | + wp_register_style( |
|
| 533 | + 'events-admin-css', |
|
| 534 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 535 | + array(), |
|
| 536 | + EVENT_ESPRESSO_VERSION |
|
| 537 | + ); |
|
| 538 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 539 | + wp_enqueue_style('events-admin-css'); |
|
| 540 | + wp_enqueue_style('ee-cat-admin'); |
|
| 541 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 542 | + //registers for all views |
|
| 543 | + //scripts |
|
| 544 | + wp_register_script( |
|
| 545 | + 'event_editor_js', |
|
| 546 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 547 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 548 | + EVENT_ESPRESSO_VERSION, |
|
| 549 | + true |
|
| 550 | + ); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * enqueuing scripts and styles specific to this view |
|
| 557 | + * |
|
| 558 | + * @return void |
|
| 559 | + */ |
|
| 560 | + public function load_scripts_styles_create_new() |
|
| 561 | + { |
|
| 562 | + $this->load_scripts_styles_edit(); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * enqueuing scripts and styles specific to this view |
|
| 569 | + * |
|
| 570 | + * @return void |
|
| 571 | + */ |
|
| 572 | + public function load_scripts_styles_edit() |
|
| 573 | + { |
|
| 574 | + //styles |
|
| 575 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 576 | + wp_register_style( |
|
| 577 | + 'event-editor-css', |
|
| 578 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 579 | + array('ee-admin-css'), |
|
| 580 | + EVENT_ESPRESSO_VERSION |
|
| 581 | + ); |
|
| 582 | + wp_enqueue_style('event-editor-css'); |
|
| 583 | + //scripts |
|
| 584 | + wp_register_script( |
|
| 585 | + 'event-datetime-metabox', |
|
| 586 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 587 | + array('event_editor_js', 'ee-datepicker'), |
|
| 588 | + EVENT_ESPRESSO_VERSION |
|
| 589 | + ); |
|
| 590 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + public function load_scripts_styles_add_category() |
|
| 596 | + { |
|
| 597 | + $this->load_scripts_styles_edit_category(); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + public function load_scripts_styles_edit_category() |
|
| 603 | + { |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + protected function _set_list_table_views_category_list() |
|
| 609 | + { |
|
| 610 | + $this->_views = array( |
|
| 611 | + 'all' => array( |
|
| 612 | + 'slug' => 'all', |
|
| 613 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 614 | + 'count' => 0, |
|
| 615 | + 'bulk_action' => array( |
|
| 616 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 617 | + ), |
|
| 618 | + ), |
|
| 619 | + ); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + public function admin_init() |
|
| 625 | + { |
|
| 626 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 627 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 628 | + 'event_espresso' |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + //nothing needed for events with these methods. |
|
| 635 | + public function admin_notices() |
|
| 636 | + { |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + public function admin_footer_scripts() |
|
| 642 | + { |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 649 | + * warning (via EE_Error::add_error()); |
|
| 650 | + * |
|
| 651 | + * @param EE_Event $event Event object |
|
| 652 | + * @access public |
|
| 653 | + * @return void |
|
| 654 | + */ |
|
| 655 | + public function verify_event_edit($event = null) |
|
| 656 | + { |
|
| 657 | + // no event? |
|
| 658 | + if (empty($event)) { |
|
| 659 | + // set event |
|
| 660 | + $event = $this->_cpt_model_obj; |
|
| 661 | + } |
|
| 662 | + // STILL no event? |
|
| 663 | + if (empty ($event)) { |
|
| 664 | + return; |
|
| 665 | + } |
|
| 666 | + $orig_status = $event->status(); |
|
| 667 | + // first check if event is active. |
|
| 668 | + if ( |
|
| 669 | + $orig_status === EEM_Event::cancelled |
|
| 670 | + || $orig_status === EEM_Event::postponed |
|
| 671 | + || $event->is_expired() |
|
| 672 | + || $event->is_inactive() |
|
| 673 | + ) { |
|
| 674 | + return; |
|
| 675 | + } |
|
| 676 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
| 677 | + if ($event->is_sold_out(true)) { |
|
| 678 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 679 | + EE_Error::add_attention( |
|
| 680 | + sprintf( |
|
| 681 | + esc_html__( |
|
| 682 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 683 | + 'event_espresso' |
|
| 684 | + ), |
|
| 685 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 686 | + ) |
|
| 687 | + ); |
|
| 688 | + } |
|
| 689 | + return; |
|
| 690 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
| 691 | + EE_Error::add_attention( |
|
| 692 | + sprintf( |
|
| 693 | + esc_html__( |
|
| 694 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 695 | + 'event_espresso' |
|
| 696 | + ), |
|
| 697 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 698 | + ) |
|
| 699 | + ); |
|
| 700 | + } |
|
| 701 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 702 | + if ( ! $event->tickets_on_sale()) { |
|
| 703 | + return; |
|
| 704 | + } |
|
| 705 | + //made it here so show warning |
|
| 706 | + $this->_edit_event_warning(); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 713 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 714 | + * |
|
| 715 | + * @access protected |
|
| 716 | + * @return void |
|
| 717 | + */ |
|
| 718 | + protected function _edit_event_warning() |
|
| 719 | + { |
|
| 720 | + // we don't want to add warnings during these requests |
|
| 721 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 722 | + return; |
|
| 723 | + } |
|
| 724 | + EE_Error::add_attention( |
|
| 725 | + esc_html__( |
|
| 726 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 727 | + 'event_espresso' |
|
| 728 | + ) |
|
| 729 | + ); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 736 | + * Otherwise, do the normal logic |
|
| 737 | + * |
|
| 738 | + * @return string |
|
| 739 | + * @throws \EE_Error |
|
| 740 | + */ |
|
| 741 | + protected function _create_new_cpt_item() |
|
| 742 | + { |
|
| 743 | + $gmt_offset = get_option('gmt_offset'); |
|
| 744 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 745 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 746 | + EE_Error::add_attention( |
|
| 747 | + sprintf( |
|
| 748 | + __( |
|
| 749 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 750 | + 'event_espresso' |
|
| 751 | + ), |
|
| 752 | + '<a href="' . admin_url('options-general.php') . '">', |
|
| 753 | + '</a>' |
|
| 754 | + ), |
|
| 755 | + __FILE__, |
|
| 756 | + __FUNCTION__, |
|
| 757 | + __LINE__ |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + return parent::_create_new_cpt_item(); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + protected function _set_list_table_views_default() |
|
| 766 | + { |
|
| 767 | + $this->_views = array( |
|
| 768 | + 'all' => array( |
|
| 769 | + 'slug' => 'all', |
|
| 770 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 771 | + 'count' => 0, |
|
| 772 | + 'bulk_action' => array( |
|
| 773 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 774 | + ), |
|
| 775 | + ), |
|
| 776 | + 'draft' => array( |
|
| 777 | + 'slug' => 'draft', |
|
| 778 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 779 | + 'count' => 0, |
|
| 780 | + 'bulk_action' => array( |
|
| 781 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 782 | + ), |
|
| 783 | + ), |
|
| 784 | + ); |
|
| 785 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 786 | + $this->_views['trash'] = array( |
|
| 787 | + 'slug' => 'trash', |
|
| 788 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 789 | + 'count' => 0, |
|
| 790 | + 'bulk_action' => array( |
|
| 791 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 792 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 793 | + ), |
|
| 794 | + ); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * @return array |
|
| 802 | + */ |
|
| 803 | + protected function _event_legend_items() |
|
| 804 | + { |
|
| 805 | + $items = array( |
|
| 806 | + 'view_details' => array( |
|
| 807 | + 'class' => 'dashicons dashicons-search', |
|
| 808 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 809 | + ), |
|
| 810 | + 'edit_event' => array( |
|
| 811 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 812 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 813 | + ), |
|
| 814 | + 'view_attendees' => array( |
|
| 815 | + 'class' => 'dashicons dashicons-groups', |
|
| 816 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 817 | + ), |
|
| 818 | + ); |
|
| 819 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 820 | + $statuses = array( |
|
| 821 | + 'sold_out_status' => array( |
|
| 822 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 823 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 824 | + ), |
|
| 825 | + 'active_status' => array( |
|
| 826 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 827 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 828 | + ), |
|
| 829 | + 'upcoming_status' => array( |
|
| 830 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 831 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 832 | + ), |
|
| 833 | + 'postponed_status' => array( |
|
| 834 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 835 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 836 | + ), |
|
| 837 | + 'cancelled_status' => array( |
|
| 838 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 839 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 840 | + ), |
|
| 841 | + 'expired_status' => array( |
|
| 842 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 843 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 844 | + ), |
|
| 845 | + 'inactive_status' => array( |
|
| 846 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 847 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 848 | + ), |
|
| 849 | + ); |
|
| 850 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 851 | + return array_merge($items, $statuses); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + /** |
|
| 857 | + * _event_model |
|
| 858 | + * |
|
| 859 | + * @return EEM_Event |
|
| 860 | + */ |
|
| 861 | + private function _event_model() |
|
| 862 | + { |
|
| 863 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 864 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 865 | + } |
|
| 866 | + return $this->_event_model; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 873 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 874 | + * |
|
| 875 | + * @param string $return the current html |
|
| 876 | + * @param int $id the post id for the page |
|
| 877 | + * @param string $new_title What the title is |
|
| 878 | + * @param string $new_slug what the slug is |
|
| 879 | + * @return string The new html string for the permalink area |
|
| 880 | + */ |
|
| 881 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 882 | + { |
|
| 883 | + //make sure this is only when editing |
|
| 884 | + if ( ! empty($id)) { |
|
| 885 | + $post = get_post($id); |
|
| 886 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 887 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 888 | + . '</a> '; |
|
| 889 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 890 | + . $post->ID |
|
| 891 | + . ']">'; |
|
| 892 | + } |
|
| 893 | + return $return; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * _events_overview_list_table |
|
| 900 | + * This contains the logic for showing the events_overview list |
|
| 901 | + * |
|
| 902 | + * @access protected |
|
| 903 | + * @return void |
|
| 904 | + * @throws \EE_Error |
|
| 905 | + */ |
|
| 906 | + protected function _events_overview_list_table() |
|
| 907 | + { |
|
| 908 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 909 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 910 | + ? (array)$this->_template_args['after_list_table'] |
|
| 911 | + : array(); |
|
| 912 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 913 | + . EEH_Template::get_button_or_link( |
|
| 914 | + get_post_type_archive_link('espresso_events'), |
|
| 915 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 916 | + 'button' |
|
| 917 | + ); |
|
| 918 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 919 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 920 | + 'create_new', |
|
| 921 | + 'add', |
|
| 922 | + array(), |
|
| 923 | + 'add-new-h2' |
|
| 924 | + ); |
|
| 925 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * this allows for extra misc actions in the default WP publish box |
|
| 932 | + * |
|
| 933 | + * @return void |
|
| 934 | + */ |
|
| 935 | + public function extra_misc_actions_publish_box() |
|
| 936 | + { |
|
| 937 | + $this->_generate_publish_box_extra_content(); |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 944 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 945 | + * data. |
|
| 946 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 947 | + * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 948 | + * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 949 | + * you handle this accordingly. |
|
| 950 | + * |
|
| 951 | + * @access protected |
|
| 952 | + * @abstract |
|
| 953 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 954 | + * @param object $post The post object of the cpt that was saved. |
|
| 955 | + * @return void |
|
| 956 | + */ |
|
| 957 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 958 | + { |
|
| 959 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 960 | + //get out we're not processing an event save. |
|
| 961 | + return; |
|
| 962 | + } |
|
| 963 | + $event_values = array( |
|
| 964 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 965 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 966 | + 'EVT_additional_limit' => min( |
|
| 967 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 968 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 969 | + ), |
|
| 970 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 971 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 972 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 973 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 974 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 975 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 976 | + ? $this->_req_data['timezone_string'] : null, |
|
| 977 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 978 | + ? $this->_req_data['externalURL'] : null, |
|
| 979 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 980 | + ? $this->_req_data['event_phone'] : null, |
|
| 981 | + ); |
|
| 982 | + //update event |
|
| 983 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 984 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 985 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 986 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 987 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 988 | + $event_update_callbacks = apply_filters( |
|
| 989 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 990 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 991 | + ); |
|
| 992 | + $att_success = true; |
|
| 993 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 994 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 995 | + $att_success = ! $att_success ? $att_success |
|
| 996 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 997 | + } |
|
| 998 | + //any errors? |
|
| 999 | + if ($success && false === $att_success) { |
|
| 1000 | + EE_Error::add_error( |
|
| 1001 | + esc_html__( |
|
| 1002 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1003 | + 'event_espresso' |
|
| 1004 | + ), |
|
| 1005 | + __FILE__, |
|
| 1006 | + __FUNCTION__, |
|
| 1007 | + __LINE__ |
|
| 1008 | + ); |
|
| 1009 | + } else if ($success === false) { |
|
| 1010 | + EE_Error::add_error( |
|
| 1011 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1012 | + __FILE__, |
|
| 1013 | + __FUNCTION__, |
|
| 1014 | + __LINE__ |
|
| 1015 | + ); |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * @see parent::restore_item() |
|
| 1023 | + * @param int $post_id |
|
| 1024 | + * @param int $revision_id |
|
| 1025 | + */ |
|
| 1026 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1027 | + { |
|
| 1028 | + //copy existing event meta to new post |
|
| 1029 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1030 | + if ($post_evt instanceof EE_Event) { |
|
| 1031 | + //meta revision restore |
|
| 1032 | + $post_evt->restore_revision($revision_id); |
|
| 1033 | + //related objs restore |
|
| 1034 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * Attach the venue to the Event |
|
| 1042 | + * |
|
| 1043 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1044 | + * @param array $data The request data from the form |
|
| 1045 | + * @return bool Success or fail. |
|
| 1046 | + */ |
|
| 1047 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1048 | + { |
|
| 1049 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1050 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1051 | + $rows_affected = null; |
|
| 1052 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1053 | + // very important. If we don't have a venue name... |
|
| 1054 | + // then we'll get out because not necessary to create empty venue |
|
| 1055 | + if (empty($data['venue_title'])) { |
|
| 1056 | + return false; |
|
| 1057 | + } |
|
| 1058 | + $venue_array = array( |
|
| 1059 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1060 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1061 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1062 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1063 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1064 | + : null, |
|
| 1065 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1066 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1067 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1068 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1069 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1070 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1071 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1072 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1073 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1074 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1075 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1076 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1077 | + 'status' => 'publish', |
|
| 1078 | + ); |
|
| 1079 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1080 | + if ( ! empty($venue_id)) { |
|
| 1081 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1082 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1083 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1084 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1085 | + return $rows_affected > 0 ? true : false; |
|
| 1086 | + } else { |
|
| 1087 | + //we insert the venue |
|
| 1088 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1089 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1090 | + return ! empty($venue_id) ? true : false; |
|
| 1091 | + } |
|
| 1092 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1099 | + * |
|
| 1100 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1101 | + * @param array $data The request data from the form |
|
| 1102 | + * @return array |
|
| 1103 | + */ |
|
| 1104 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1105 | + { |
|
| 1106 | + $success = true; |
|
| 1107 | + $saved_dtt = null; |
|
| 1108 | + $saved_tickets = array(); |
|
| 1109 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1110 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1111 | + //trim all values to ensure any excess whitespace is removed. |
|
| 1112 | + $dtt = array_map('trim', $dtt); |
|
| 1113 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1114 | + : $dtt['DTT_EVT_start']; |
|
| 1115 | + $datetime_values = array( |
|
| 1116 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1117 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1118 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1119 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1120 | + 'DTT_order' => $row, |
|
| 1121 | + ); |
|
| 1122 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1123 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1124 | + $DTM = EE_Registry::instance() |
|
| 1125 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1126 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1127 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1128 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1129 | + foreach ($datetime_values as $field => $value) { |
|
| 1130 | + $DTM->set($field, $value); |
|
| 1131 | + } |
|
| 1132 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1133 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1134 | + } else { |
|
| 1135 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1136 | + 'Datetime', |
|
| 1137 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1138 | + false, |
|
| 1139 | + false |
|
| 1140 | + ); |
|
| 1141 | + foreach ($datetime_values as $field => $value) { |
|
| 1142 | + $DTM->set($field, $value); |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + $DTM->save(); |
|
| 1146 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1147 | + //load DTT helper |
|
| 1148 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1149 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1150 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1151 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1152 | + $DTT->save(); |
|
| 1153 | + } |
|
| 1154 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1155 | + $saved_dtt = $DTT; |
|
| 1156 | + $success = ! $success ? $success : $DTT; |
|
| 1157 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1158 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1159 | + } |
|
| 1160 | + //no dtts get deleted so we don't do any of that logic here. |
|
| 1161 | + //update tickets next |
|
| 1162 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1163 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1164 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1165 | + $update_prices = false; |
|
| 1166 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1167 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1168 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1169 | + $tkt = array_map('trim', $tkt); |
|
| 1170 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1171 | + //let's use now in the set timezone. |
|
| 1172 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1173 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1174 | + } |
|
| 1175 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1176 | + //use the start date of the first datetime |
|
| 1177 | + $dtt = $evtobj->first_datetime(); |
|
| 1178 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1179 | + $incoming_date_formats[0], |
|
| 1180 | + $incoming_date_formats[1] |
|
| 1181 | + ); |
|
| 1182 | + } |
|
| 1183 | + $TKT_values = array( |
|
| 1184 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1185 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1186 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1187 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1188 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1189 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1190 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1191 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1192 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1193 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1194 | + 'TKT_row' => $row, |
|
| 1195 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1196 | + 'TKT_price' => $ticket_price, |
|
| 1197 | + ); |
|
| 1198 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1199 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1200 | + $TKT_values['TKT_ID'] = 0; |
|
| 1201 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1202 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1203 | + $update_prices = true; |
|
| 1204 | + } |
|
| 1205 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1206 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1207 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1208 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1209 | + $TKT = EE_Registry::instance() |
|
| 1210 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1211 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1212 | + if ($TKT instanceof EE_Ticket) { |
|
| 1213 | + $ticket_sold = $TKT->count_related( |
|
| 1214 | + 'Registration', |
|
| 1215 | + array( |
|
| 1216 | + array( |
|
| 1217 | + 'STS_ID' => array( |
|
| 1218 | + 'NOT IN', |
|
| 1219 | + array(EEM_Registration::status_id_incomplete), |
|
| 1220 | + ), |
|
| 1221 | + ), |
|
| 1222 | + ) |
|
| 1223 | + ) > 0 ? true : false; |
|
| 1224 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1225 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1226 | + && ! $TKT->get( |
|
| 1227 | + 'TKT_deleted' |
|
| 1228 | + ) ? true : false; |
|
| 1229 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1230 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1231 | + //set new values |
|
| 1232 | + foreach ($TKT_values as $field => $value) { |
|
| 1233 | + if ($field == 'TKT_qty') { |
|
| 1234 | + $TKT->set_qty($value); |
|
| 1235 | + } else { |
|
| 1236 | + $TKT->set($field, $value); |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1240 | + if ($create_new_TKT) { |
|
| 1241 | + //archive the old ticket first |
|
| 1242 | + $TKT->set('TKT_deleted', 1); |
|
| 1243 | + $TKT->save(); |
|
| 1244 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1245 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1246 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1247 | + $TKT = clone $TKT; |
|
| 1248 | + $TKT->set('TKT_ID', 0); |
|
| 1249 | + $TKT->set('TKT_deleted', 0); |
|
| 1250 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1251 | + $TKT->set('TKT_sold', 0); |
|
| 1252 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1253 | + $update_prices = true; |
|
| 1254 | + } |
|
| 1255 | + //make sure price is set if it hasn't been already |
|
| 1256 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1257 | + } |
|
| 1258 | + } else { |
|
| 1259 | + //no TKT_id so a new TKT |
|
| 1260 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1261 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1262 | + if ($TKT instanceof EE_Ticket) { |
|
| 1263 | + //need to reset values to properly account for the date formats |
|
| 1264 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1265 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1266 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1267 | + //set new values |
|
| 1268 | + foreach ($TKT_values as $field => $value) { |
|
| 1269 | + if ($field == 'TKT_qty') { |
|
| 1270 | + $TKT->set_qty($value); |
|
| 1271 | + } else { |
|
| 1272 | + $TKT->set($field, $value); |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | + $update_prices = true; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + // cap ticket qty by datetime reg limits |
|
| 1279 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1280 | + //update ticket. |
|
| 1281 | + $TKT->save(); |
|
| 1282 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1283 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1284 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1285 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1286 | + $TKT->save(); |
|
| 1287 | + } |
|
| 1288 | + //initially let's add the ticket to the dtt |
|
| 1289 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1290 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1291 | + //add prices to ticket |
|
| 1292 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1293 | + } |
|
| 1294 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1295 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1296 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1297 | + foreach ($tickets_removed as $id) { |
|
| 1298 | + $id = absint($id); |
|
| 1299 | + //get the ticket for this id |
|
| 1300 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1301 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1302 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1303 | + foreach ($dtts as $dtt) { |
|
| 1304 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1305 | + } |
|
| 1306 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1307 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1308 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1309 | + $tkt_to_remove->delete_permanently(); |
|
| 1310 | + } |
|
| 1311 | + return array($saved_dtt, $saved_tickets); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * This attaches a list of given prices to a ticket. |
|
| 1318 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1319 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1320 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1321 | + * |
|
| 1322 | + * @access private |
|
| 1323 | + * @param array $prices Array of prices from the form. |
|
| 1324 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1325 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1326 | + * @return void |
|
| 1327 | + */ |
|
| 1328 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1329 | + { |
|
| 1330 | + foreach ($prices as $row => $prc) { |
|
| 1331 | + $PRC_values = array( |
|
| 1332 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1333 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1334 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1335 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1336 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1337 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1338 | + 'PRC_order' => $row, |
|
| 1339 | + ); |
|
| 1340 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1341 | + $PRC_values['PRC_ID'] = 0; |
|
| 1342 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1343 | + } else { |
|
| 1344 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1345 | + //update this price with new values |
|
| 1346 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1347 | + $PRC->set($field, $newprc); |
|
| 1348 | + } |
|
| 1349 | + $PRC->save(); |
|
| 1350 | + } |
|
| 1351 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1352 | + } |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + |
|
| 1356 | + |
|
| 1357 | + /** |
|
| 1358 | + * Add in our autosave ajax handlers |
|
| 1359 | + * |
|
| 1360 | + * @return void |
|
| 1361 | + */ |
|
| 1362 | + protected function _ee_autosave_create_new() |
|
| 1363 | + { |
|
| 1364 | + // $this->_ee_autosave_edit(); |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + protected function _ee_autosave_edit() |
|
| 1370 | + { |
|
| 1371 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * _generate_publish_box_extra_content |
|
| 1378 | + * |
|
| 1379 | + * @access private |
|
| 1380 | + * @return void |
|
| 1381 | + */ |
|
| 1382 | + private function _generate_publish_box_extra_content() |
|
| 1383 | + { |
|
| 1384 | + //load formatter helper |
|
| 1385 | + //args for getting related registrations |
|
| 1386 | + $approved_query_args = array( |
|
| 1387 | + array( |
|
| 1388 | + 'REG_deleted' => 0, |
|
| 1389 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1390 | + ), |
|
| 1391 | + ); |
|
| 1392 | + $not_approved_query_args = array( |
|
| 1393 | + array( |
|
| 1394 | + 'REG_deleted' => 0, |
|
| 1395 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1396 | + ), |
|
| 1397 | + ); |
|
| 1398 | + $pending_payment_query_args = array( |
|
| 1399 | + array( |
|
| 1400 | + 'REG_deleted' => 0, |
|
| 1401 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1402 | + ), |
|
| 1403 | + ); |
|
| 1404 | + // publish box |
|
| 1405 | + $publish_box_extra_args = array( |
|
| 1406 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1407 | + array( |
|
| 1408 | + 'action' => 'default', |
|
| 1409 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1410 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1411 | + ), |
|
| 1412 | + REG_ADMIN_URL |
|
| 1413 | + ), |
|
| 1414 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1415 | + array( |
|
| 1416 | + 'action' => 'default', |
|
| 1417 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1418 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1419 | + ), |
|
| 1420 | + REG_ADMIN_URL |
|
| 1421 | + ), |
|
| 1422 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1423 | + array( |
|
| 1424 | + 'action' => 'default', |
|
| 1425 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1426 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1427 | + ), |
|
| 1428 | + REG_ADMIN_URL |
|
| 1429 | + ), |
|
| 1430 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1431 | + 'Registration', |
|
| 1432 | + $approved_query_args |
|
| 1433 | + ), |
|
| 1434 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1435 | + 'Registration', |
|
| 1436 | + $not_approved_query_args |
|
| 1437 | + ), |
|
| 1438 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1439 | + 'Registration', |
|
| 1440 | + $pending_payment_query_args |
|
| 1441 | + ), |
|
| 1442 | + 'misc_pub_section_class' => apply_filters( |
|
| 1443 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1444 | + 'misc-pub-section' |
|
| 1445 | + ), |
|
| 1446 | + //'email_attendees_url' => add_query_arg( |
|
| 1447 | + // array( |
|
| 1448 | + // 'event_admin_reports' => 'event_newsletter', |
|
| 1449 | + // 'event_id' => $this->_cpt_model_obj->id |
|
| 1450 | + // ), |
|
| 1451 | + // 'admin.php?page=espresso_registrations' |
|
| 1452 | + //), |
|
| 1453 | + ); |
|
| 1454 | + ob_start(); |
|
| 1455 | + do_action( |
|
| 1456 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1457 | + $this->_cpt_model_obj |
|
| 1458 | + ); |
|
| 1459 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1460 | + // load template |
|
| 1461 | + EEH_Template::display_template( |
|
| 1462 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1463 | + $publish_box_extra_args |
|
| 1464 | + ); |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + |
|
| 1468 | + |
|
| 1469 | + /** |
|
| 1470 | + * This just returns whatever is set as the _event object property |
|
| 1471 | + * //todo this will become obsolete once the models are in place |
|
| 1472 | + * |
|
| 1473 | + * @return object |
|
| 1474 | + */ |
|
| 1475 | + public function get_event_object() |
|
| 1476 | + { |
|
| 1477 | + return $this->_cpt_model_obj; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + |
|
| 1482 | + |
|
| 1483 | + /** METABOXES * */ |
|
| 1484 | + /** |
|
| 1485 | + * _register_event_editor_meta_boxes |
|
| 1486 | + * add all metaboxes related to the event_editor |
|
| 1487 | + * |
|
| 1488 | + * @return void |
|
| 1489 | + */ |
|
| 1490 | + protected function _register_event_editor_meta_boxes() |
|
| 1491 | + { |
|
| 1492 | + $this->verify_cpt_object(); |
|
| 1493 | + add_meta_box( |
|
| 1494 | + 'espresso_event_editor_tickets', |
|
| 1495 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1496 | + array($this, 'ticket_metabox'), |
|
| 1497 | + $this->page_slug, |
|
| 1498 | + 'normal', |
|
| 1499 | + 'high' |
|
| 1500 | + ); |
|
| 1501 | + add_meta_box( |
|
| 1502 | + 'espresso_event_editor_event_options', |
|
| 1503 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1504 | + array($this, 'registration_options_meta_box'), |
|
| 1505 | + $this->page_slug, |
|
| 1506 | + 'side', |
|
| 1507 | + 'default' |
|
| 1508 | + ); |
|
| 1509 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1510 | + // where a metabox has a related management page in the admin |
|
| 1511 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1512 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + |
|
| 1516 | + |
|
| 1517 | + public function ticket_metabox() |
|
| 1518 | + { |
|
| 1519 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1520 | + //defaults for template args |
|
| 1521 | + $template_args = array( |
|
| 1522 | + 'existing_datetime_ids' => '', |
|
| 1523 | + 'event_datetime_help_link' => '', |
|
| 1524 | + 'ticket_options_help_link' => '', |
|
| 1525 | + 'time' => null, |
|
| 1526 | + 'ticket_rows' => '', |
|
| 1527 | + 'existing_ticket_ids' => '', |
|
| 1528 | + 'total_ticket_rows' => 1, |
|
| 1529 | + 'ticket_js_structure' => '', |
|
| 1530 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1531 | + 'disabled' => '', |
|
| 1532 | + ); |
|
| 1533 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1534 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1535 | + /** |
|
| 1536 | + * 1. Start with retrieving Datetimes |
|
| 1537 | + * 2. Fore each datetime get related tickets |
|
| 1538 | + * 3. For each ticket get related prices |
|
| 1539 | + */ |
|
| 1540 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1541 | + /** @type EE_Datetime $first_datetime */ |
|
| 1542 | + $first_datetime = reset($times); |
|
| 1543 | + //do we get related tickets? |
|
| 1544 | + if ($first_datetime instanceof EE_Datetime |
|
| 1545 | + && $first_datetime->ID() !== 0 |
|
| 1546 | + ) { |
|
| 1547 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1548 | + $template_args['time'] = $first_datetime; |
|
| 1549 | + $related_tickets = $first_datetime->tickets( |
|
| 1550 | + array( |
|
| 1551 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1552 | + 'default_where_conditions' => 'none', |
|
| 1553 | + ) |
|
| 1554 | + ); |
|
| 1555 | + if ( ! empty($related_tickets)) { |
|
| 1556 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1557 | + $row = 0; |
|
| 1558 | + foreach ($related_tickets as $ticket) { |
|
| 1559 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1560 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1561 | + $row++; |
|
| 1562 | + } |
|
| 1563 | + } else { |
|
| 1564 | + $template_args['total_ticket_rows'] = 1; |
|
| 1565 | + /** @type EE_Ticket $ticket */ |
|
| 1566 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1567 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1568 | + } |
|
| 1569 | + } else { |
|
| 1570 | + $template_args['time'] = $times[0]; |
|
| 1571 | + /** @type EE_Ticket $ticket */ |
|
| 1572 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1573 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1574 | + // NOTE: we're just sending the first default row |
|
| 1575 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1576 | + } |
|
| 1577 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1578 | + 'event_editor_event_datetimes_help_tab' |
|
| 1579 | + ); |
|
| 1580 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1581 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1582 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1583 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1584 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1585 | + true |
|
| 1586 | + ); |
|
| 1587 | + $template = apply_filters( |
|
| 1588 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1589 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1590 | + ); |
|
| 1591 | + EEH_Template::display_template($template, $template_args); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1598 | + * |
|
| 1599 | + * @access private |
|
| 1600 | + * @param EE_Ticket $ticket the ticket object |
|
| 1601 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1602 | + * @param int $row |
|
| 1603 | + * @return string generated html for the ticket row. |
|
| 1604 | + */ |
|
| 1605 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1606 | + { |
|
| 1607 | + $template_args = array( |
|
| 1608 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1609 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1610 | + : '', |
|
| 1611 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1612 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1613 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1614 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1615 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1616 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1617 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1618 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1619 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1620 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1621 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1622 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1623 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1624 | + : ' disabled=disabled', |
|
| 1625 | + ); |
|
| 1626 | + $price = $ticket->ID() !== 0 |
|
| 1627 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1628 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1629 | + $price_args = array( |
|
| 1630 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1631 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1632 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1633 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1634 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1635 | + ); |
|
| 1636 | + //make sure we have default start and end dates if skeleton |
|
| 1637 | + //handle rows that should NOT be empty |
|
| 1638 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1639 | + //if empty then the start date will be now. |
|
| 1640 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1641 | + } |
|
| 1642 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1643 | + //get the earliest datetime (if present); |
|
| 1644 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1645 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1646 | + 'Datetime', |
|
| 1647 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1648 | + ) |
|
| 1649 | + : null; |
|
| 1650 | + if ( ! empty($earliest_dtt)) { |
|
| 1651 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1652 | + } else { |
|
| 1653 | + $template_args['TKT_end_date'] = date( |
|
| 1654 | + 'Y-m-d h:i a', |
|
| 1655 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1656 | + ); |
|
| 1657 | + } |
|
| 1658 | + } |
|
| 1659 | + $template_args = array_merge($template_args, $price_args); |
|
| 1660 | + $template = apply_filters( |
|
| 1661 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1662 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1663 | + $ticket |
|
| 1664 | + ); |
|
| 1665 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + |
|
| 1670 | + public function registration_options_meta_box() |
|
| 1671 | + { |
|
| 1672 | + $yes_no_values = array( |
|
| 1673 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1674 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1675 | + ); |
|
| 1676 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1677 | + array( |
|
| 1678 | + EEM_Registration::status_id_cancelled, |
|
| 1679 | + EEM_Registration::status_id_declined, |
|
| 1680 | + EEM_Registration::status_id_incomplete, |
|
| 1681 | + ), |
|
| 1682 | + true |
|
| 1683 | + ); |
|
| 1684 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1685 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1686 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1687 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1688 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1689 | + 'default_reg_status', |
|
| 1690 | + $default_reg_status_values, |
|
| 1691 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1692 | + ); |
|
| 1693 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1694 | + 'display_desc', |
|
| 1695 | + $yes_no_values, |
|
| 1696 | + $this->_cpt_model_obj->display_description() |
|
| 1697 | + ); |
|
| 1698 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1699 | + 'display_ticket_selector', |
|
| 1700 | + $yes_no_values, |
|
| 1701 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1702 | + '', |
|
| 1703 | + '', |
|
| 1704 | + false |
|
| 1705 | + ); |
|
| 1706 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1707 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1708 | + '', |
|
| 1709 | + $template_args, |
|
| 1710 | + $yes_no_values, |
|
| 1711 | + $default_reg_status_values |
|
| 1712 | + ); |
|
| 1713 | + EEH_Template::display_template( |
|
| 1714 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1715 | + $template_args |
|
| 1716 | + ); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * _get_events() |
|
| 1723 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1724 | + * |
|
| 1725 | + * @access public |
|
| 1726 | + * @param int $per_page count of items per page (20 default); |
|
| 1727 | + * @param int $current_page what is the current page being viewed. |
|
| 1728 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1729 | + * If FALSE then we return an array of event objects |
|
| 1730 | + * that match the given _view and paging parameters. |
|
| 1731 | + * @return array an array of event objects. |
|
| 1732 | + */ |
|
| 1733 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1734 | + { |
|
| 1735 | + $EEME = $this->_event_model(); |
|
| 1736 | + $offset = ($current_page - 1) * $per_page; |
|
| 1737 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1738 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1739 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1740 | + if (isset($this->_req_data['month_range'])) { |
|
| 1741 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1742 | + $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
| 1743 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1744 | + } |
|
| 1745 | + $where = array(); |
|
| 1746 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1747 | + //determine what post_status our condition will have for the query. |
|
| 1748 | + switch ($status) { |
|
| 1749 | + case 'month' : |
|
| 1750 | + case 'today' : |
|
| 1751 | + case null : |
|
| 1752 | + case 'all' : |
|
| 1753 | + break; |
|
| 1754 | + case 'draft' : |
|
| 1755 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1756 | + break; |
|
| 1757 | + default : |
|
| 1758 | + $where['status'] = $status; |
|
| 1759 | + } |
|
| 1760 | + //categories? |
|
| 1761 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1762 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1763 | + if ( ! empty ($category)) { |
|
| 1764 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1765 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1766 | + } |
|
| 1767 | + //date where conditions |
|
| 1768 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1769 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1770 | + $DateTime = new DateTime( |
|
| 1771 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1772 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1773 | + ); |
|
| 1774 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1775 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1776 | + ->format('t'))->setTime(23, 59, 59) |
|
| 1777 | + ->format(implode(' ', $start_formats)); |
|
| 1778 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1779 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1780 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1781 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1782 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1783 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1784 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1785 | + $now = date('Y-m-01'); |
|
| 1786 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1787 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1788 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1789 | + ->setTime(23, 59, 59) |
|
| 1790 | + ->format(implode(' ', $start_formats)); |
|
| 1791 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1792 | + } |
|
| 1793 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1794 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1795 | + } else { |
|
| 1796 | + if ( ! isset($where['status'])) { |
|
| 1797 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1798 | + $where['OR'] = array( |
|
| 1799 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1800 | + 'AND' => array( |
|
| 1801 | + 'status*inclusive' => array('=', 'private'), |
|
| 1802 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1803 | + ), |
|
| 1804 | + ); |
|
| 1805 | + } |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1809 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1810 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1811 | + ) { |
|
| 1812 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1813 | + } |
|
| 1814 | + } |
|
| 1815 | + //search query handling |
|
| 1816 | + if (isset($this->_req_data['s'])) { |
|
| 1817 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1818 | + $where['OR'] = array( |
|
| 1819 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1820 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1821 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1822 | + ); |
|
| 1823 | + } |
|
| 1824 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1825 | + $query_params = apply_filters( |
|
| 1826 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1827 | + array( |
|
| 1828 | + $where, |
|
| 1829 | + 'limit' => $limit, |
|
| 1830 | + 'order_by' => $orderby, |
|
| 1831 | + 'order' => $order, |
|
| 1832 | + 'group_by' => 'EVT_ID', |
|
| 1833 | + ), |
|
| 1834 | + $this->_req_data |
|
| 1835 | + ); |
|
| 1836 | + //let's first check if we have special requests coming in. |
|
| 1837 | + if (isset($this->_req_data['active_status'])) { |
|
| 1838 | + switch ($this->_req_data['active_status']) { |
|
| 1839 | + case 'upcoming' : |
|
| 1840 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1841 | + break; |
|
| 1842 | + case 'expired' : |
|
| 1843 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1844 | + break; |
|
| 1845 | + case 'active' : |
|
| 1846 | + return $EEME->get_active_events($query_params, $count); |
|
| 1847 | + break; |
|
| 1848 | + case 'inactive' : |
|
| 1849 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1850 | + break; |
|
| 1851 | + } |
|
| 1852 | + } |
|
| 1853 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1854 | + return $events; |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1861 | + * |
|
| 1862 | + * @param string $post_id |
|
| 1863 | + */ |
|
| 1864 | + public function trash_cpt_item($post_id) |
|
| 1865 | + { |
|
| 1866 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1867 | + $this->_trash_or_restore_event('trash', false); |
|
| 1868 | + } |
|
| 1869 | + |
|
| 1870 | + |
|
| 1871 | + |
|
| 1872 | + /** |
|
| 1873 | + * @param string $post_id |
|
| 1874 | + */ |
|
| 1875 | + public function restore_cpt_item($post_id) |
|
| 1876 | + { |
|
| 1877 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1878 | + $this->_trash_or_restore_event('draft', false); |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * @param string $post_id |
|
| 1885 | + */ |
|
| 1886 | + public function delete_cpt_item($post_id) |
|
| 1887 | + { |
|
| 1888 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1889 | + $this->_delete_event(false); |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + |
|
| 1893 | + |
|
| 1894 | + /** |
|
| 1895 | + * _trash_or_restore_event |
|
| 1896 | + * |
|
| 1897 | + * @access protected |
|
| 1898 | + * @param string $event_status |
|
| 1899 | + * @param bool $redirect_after |
|
| 1900 | + */ |
|
| 1901 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1902 | + { |
|
| 1903 | + //determine the event id and set to array. |
|
| 1904 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1905 | + // loop thru events |
|
| 1906 | + if ($EVT_ID) { |
|
| 1907 | + // clean status |
|
| 1908 | + $event_status = sanitize_key($event_status); |
|
| 1909 | + // grab status |
|
| 1910 | + if ( ! empty($event_status)) { |
|
| 1911 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1912 | + } else { |
|
| 1913 | + $success = false; |
|
| 1914 | + $msg = esc_html__( |
|
| 1915 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1916 | + 'event_espresso' |
|
| 1917 | + ); |
|
| 1918 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1919 | + } |
|
| 1920 | + } else { |
|
| 1921 | + $success = false; |
|
| 1922 | + $msg = esc_html__( |
|
| 1923 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1924 | + 'event_espresso' |
|
| 1925 | + ); |
|
| 1926 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1927 | + } |
|
| 1928 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1929 | + if ($redirect_after) { |
|
| 1930 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1931 | + } |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + |
|
| 1935 | + |
|
| 1936 | + /** |
|
| 1937 | + * _trash_or_restore_events |
|
| 1938 | + * |
|
| 1939 | + * @access protected |
|
| 1940 | + * @param string $event_status |
|
| 1941 | + * @return void |
|
| 1942 | + */ |
|
| 1943 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1944 | + { |
|
| 1945 | + // clean status |
|
| 1946 | + $event_status = sanitize_key($event_status); |
|
| 1947 | + // grab status |
|
| 1948 | + if ( ! empty($event_status)) { |
|
| 1949 | + $success = true; |
|
| 1950 | + //determine the event id and set to array. |
|
| 1951 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1952 | + // loop thru events |
|
| 1953 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 1954 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 1955 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1956 | + $success = $results !== false ? $success : false; |
|
| 1957 | + } else { |
|
| 1958 | + $msg = sprintf( |
|
| 1959 | + esc_html__( |
|
| 1960 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1961 | + 'event_espresso' |
|
| 1962 | + ), |
|
| 1963 | + $EVT_ID |
|
| 1964 | + ); |
|
| 1965 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1966 | + $success = false; |
|
| 1967 | + } |
|
| 1968 | + } |
|
| 1969 | + } else { |
|
| 1970 | + $success = false; |
|
| 1971 | + $msg = esc_html__( |
|
| 1972 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1973 | + 'event_espresso' |
|
| 1974 | + ); |
|
| 1975 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1976 | + } |
|
| 1977 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1978 | + $success = $success ? 2 : false; |
|
| 1979 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1980 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + |
|
| 1984 | + |
|
| 1985 | + /** |
|
| 1986 | + * _trash_or_restore_events |
|
| 1987 | + * |
|
| 1988 | + * @access private |
|
| 1989 | + * @param int $EVT_ID |
|
| 1990 | + * @param string $event_status |
|
| 1991 | + * @return bool |
|
| 1992 | + */ |
|
| 1993 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1994 | + { |
|
| 1995 | + // grab event id |
|
| 1996 | + if ( ! $EVT_ID) { |
|
| 1997 | + $msg = esc_html__( |
|
| 1998 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 1999 | + 'event_espresso' |
|
| 2000 | + ); |
|
| 2001 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2002 | + return false; |
|
| 2003 | + } |
|
| 2004 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2005 | + // clean status |
|
| 2006 | + $event_status = sanitize_key($event_status); |
|
| 2007 | + // grab status |
|
| 2008 | + if (empty($event_status)) { |
|
| 2009 | + $msg = esc_html__( |
|
| 2010 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2011 | + 'event_espresso' |
|
| 2012 | + ); |
|
| 2013 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2014 | + return false; |
|
| 2015 | + } |
|
| 2016 | + // was event trashed or restored ? |
|
| 2017 | + switch ($event_status) { |
|
| 2018 | + case 'draft' : |
|
| 2019 | + $action = 'restored from the trash'; |
|
| 2020 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2021 | + break; |
|
| 2022 | + case 'trash' : |
|
| 2023 | + $action = 'moved to the trash'; |
|
| 2024 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2025 | + break; |
|
| 2026 | + default : |
|
| 2027 | + $action = 'updated'; |
|
| 2028 | + $hook = false; |
|
| 2029 | + } |
|
| 2030 | + //use class to change status |
|
| 2031 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2032 | + $success = $this->_cpt_model_obj->save(); |
|
| 2033 | + if ($success === false) { |
|
| 2034 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2035 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2036 | + return false; |
|
| 2037 | + } |
|
| 2038 | + if ($hook) { |
|
| 2039 | + do_action($hook); |
|
| 2040 | + } |
|
| 2041 | + return true; |
|
| 2042 | + } |
|
| 2043 | + |
|
| 2044 | + |
|
| 2045 | + |
|
| 2046 | + /** |
|
| 2047 | + * _delete_event |
|
| 2048 | + * |
|
| 2049 | + * @access protected |
|
| 2050 | + * @param bool $redirect_after |
|
| 2051 | + */ |
|
| 2052 | + protected function _delete_event($redirect_after = true) |
|
| 2053 | + { |
|
| 2054 | + //determine the event id and set to array. |
|
| 2055 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2056 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2057 | + // loop thru events |
|
| 2058 | + if ($EVT_ID) { |
|
| 2059 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2060 | + // get list of events with no prices |
|
| 2061 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2062 | + // remove this event from the list of events with no prices |
|
| 2063 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2064 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2065 | + } |
|
| 2066 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2067 | + } else { |
|
| 2068 | + $success = false; |
|
| 2069 | + $msg = esc_html__( |
|
| 2070 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2071 | + 'event_espresso' |
|
| 2072 | + ); |
|
| 2073 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2074 | + } |
|
| 2075 | + if ($redirect_after) { |
|
| 2076 | + $this->_redirect_after_action( |
|
| 2077 | + $success, |
|
| 2078 | + 'Event', |
|
| 2079 | + 'deleted', |
|
| 2080 | + array('action' => 'default', 'status' => 'trash') |
|
| 2081 | + ); |
|
| 2082 | + } |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + |
|
| 2086 | + |
|
| 2087 | + /** |
|
| 2088 | + * _delete_events |
|
| 2089 | + * |
|
| 2090 | + * @access protected |
|
| 2091 | + * @return void |
|
| 2092 | + */ |
|
| 2093 | + protected function _delete_events() |
|
| 2094 | + { |
|
| 2095 | + $success = true; |
|
| 2096 | + // get list of events with no prices |
|
| 2097 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2098 | + //determine the event id and set to array. |
|
| 2099 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2100 | + // loop thru events |
|
| 2101 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2102 | + $EVT_ID = absint($EVT_ID); |
|
| 2103 | + if ($EVT_ID) { |
|
| 2104 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2105 | + $success = $results !== false ? $success : false; |
|
| 2106 | + // remove this event from the list of events with no prices |
|
| 2107 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2108 | + } else { |
|
| 2109 | + $success = false; |
|
| 2110 | + $msg = esc_html__( |
|
| 2111 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2112 | + 'event_espresso' |
|
| 2113 | + ); |
|
| 2114 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2115 | + } |
|
| 2116 | + } |
|
| 2117 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2118 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2119 | + $success = $success ? 2 : false; |
|
| 2120 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2121 | + } |
|
| 2122 | + |
|
| 2123 | + |
|
| 2124 | + |
|
| 2125 | + /** |
|
| 2126 | + * _permanently_delete_event |
|
| 2127 | + * |
|
| 2128 | + * @access private |
|
| 2129 | + * @param int $EVT_ID |
|
| 2130 | + * @return bool |
|
| 2131 | + */ |
|
| 2132 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2133 | + { |
|
| 2134 | + // grab event id |
|
| 2135 | + if ( ! $EVT_ID) { |
|
| 2136 | + $msg = esc_html__( |
|
| 2137 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2138 | + 'event_espresso' |
|
| 2139 | + ); |
|
| 2140 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2141 | + return false; |
|
| 2142 | + } |
|
| 2143 | + if ( |
|
| 2144 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2145 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2146 | + ) { |
|
| 2147 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2148 | + } |
|
| 2149 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2150 | + return false; |
|
| 2151 | + } |
|
| 2152 | + //need to delete related tickets and prices first. |
|
| 2153 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2154 | + foreach ($datetimes as $datetime) { |
|
| 2155 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2156 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2157 | + foreach ($tickets as $ticket) { |
|
| 2158 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2159 | + $ticket->delete_related_permanently('Price'); |
|
| 2160 | + $ticket->delete_permanently(); |
|
| 2161 | + } |
|
| 2162 | + $datetime->delete(); |
|
| 2163 | + } |
|
| 2164 | + //what about related venues or terms? |
|
| 2165 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2166 | + foreach ($venues as $venue) { |
|
| 2167 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2168 | + } |
|
| 2169 | + //any attached question groups? |
|
| 2170 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2171 | + if ( ! empty($question_groups)) { |
|
| 2172 | + foreach ($question_groups as $question_group) { |
|
| 2173 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2174 | + } |
|
| 2175 | + } |
|
| 2176 | + //Message Template Groups |
|
| 2177 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2178 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2179 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2180 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2181 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2182 | + } |
|
| 2183 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2184 | + // did it all go as planned ? |
|
| 2185 | + if ($success) { |
|
| 2186 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2187 | + EE_Error::add_success($msg); |
|
| 2188 | + } else { |
|
| 2189 | + $msg = sprintf( |
|
| 2190 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2191 | + $EVT_ID |
|
| 2192 | + ); |
|
| 2193 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2194 | + return false; |
|
| 2195 | + } |
|
| 2196 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2197 | + return true; |
|
| 2198 | + } |
|
| 2199 | + |
|
| 2200 | + |
|
| 2201 | + |
|
| 2202 | + /** |
|
| 2203 | + * get total number of events |
|
| 2204 | + * |
|
| 2205 | + * @access public |
|
| 2206 | + * @return int |
|
| 2207 | + */ |
|
| 2208 | + public function total_events() |
|
| 2209 | + { |
|
| 2210 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2211 | + return $count; |
|
| 2212 | + } |
|
| 2213 | + |
|
| 2214 | + |
|
| 2215 | + |
|
| 2216 | + /** |
|
| 2217 | + * get total number of draft events |
|
| 2218 | + * |
|
| 2219 | + * @access public |
|
| 2220 | + * @return int |
|
| 2221 | + */ |
|
| 2222 | + public function total_events_draft() |
|
| 2223 | + { |
|
| 2224 | + $where = array( |
|
| 2225 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2226 | + ); |
|
| 2227 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2228 | + return $count; |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * get total number of trashed events |
|
| 2235 | + * |
|
| 2236 | + * @access public |
|
| 2237 | + * @return int |
|
| 2238 | + */ |
|
| 2239 | + public function total_trashed_events() |
|
| 2240 | + { |
|
| 2241 | + $where = array( |
|
| 2242 | + 'status' => 'trash', |
|
| 2243 | + ); |
|
| 2244 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2245 | + return $count; |
|
| 2246 | + } |
|
| 2247 | + |
|
| 2248 | + |
|
| 2249 | + |
|
| 2250 | + /** |
|
| 2251 | + * _default_event_settings |
|
| 2252 | + * This generates the Default Settings Tab |
|
| 2253 | + * |
|
| 2254 | + * @return void |
|
| 2255 | + */ |
|
| 2256 | + protected function _default_event_settings() |
|
| 2257 | + { |
|
| 2258 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2259 | + $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2260 | + // exclude array |
|
| 2261 | + array( |
|
| 2262 | + EEM_Registration::status_id_cancelled, |
|
| 2263 | + EEM_Registration::status_id_declined, |
|
| 2264 | + EEM_Registration::status_id_incomplete, |
|
| 2265 | + EEM_Registration::status_id_wait_list, |
|
| 2266 | + ), |
|
| 2267 | + // translated |
|
| 2268 | + true |
|
| 2269 | + ); |
|
| 2270 | + $this->_template_args['default_reg_status'] = isset( |
|
| 2271 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2272 | + ) |
|
| 2273 | + && in_array( |
|
| 2274 | + EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2275 | + $this->_template_args['reg_status_array'] |
|
| 2276 | + ) |
|
| 2277 | + ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2278 | + : EEM_Registration::status_id_pending_payment; |
|
| 2279 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2280 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2281 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2282 | + EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2283 | + $this->_template_args, |
|
| 2284 | + true |
|
| 2285 | + ); |
|
| 2286 | + $this->display_admin_page_with_sidebar(); |
|
| 2287 | + } |
|
| 2288 | + |
|
| 2289 | + |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * _update_default_event_settings |
|
| 2293 | + * |
|
| 2294 | + * @access protected |
|
| 2295 | + * @return void |
|
| 2296 | + */ |
|
| 2297 | + protected function _update_default_event_settings() |
|
| 2298 | + { |
|
| 2299 | + EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2300 | + ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2301 | + : EEM_Registration::status_id_pending_payment; |
|
| 2302 | + $what = 'Default Event Settings'; |
|
| 2303 | + $success = $this->_update_espresso_configuration( |
|
| 2304 | + $what, |
|
| 2305 | + EE_Config::instance(), |
|
| 2306 | + __FILE__, |
|
| 2307 | + __FUNCTION__, |
|
| 2308 | + __LINE__ |
|
| 2309 | + ); |
|
| 2310 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2311 | + } |
|
| 2312 | + |
|
| 2313 | + |
|
| 2314 | + |
|
| 2315 | + /************* Templates *************/ |
|
| 2316 | + protected function _template_settings() |
|
| 2317 | + { |
|
| 2318 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2319 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2320 | + . EVENTS_ASSETS_URL |
|
| 2321 | + . DS |
|
| 2322 | + . 'images' |
|
| 2323 | + . DS |
|
| 2324 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2325 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2326 | + . '" />'; |
|
| 2327 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2328 | + 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2329 | + 'event_espresso' |
|
| 2330 | + ) . '</strong>'; |
|
| 2331 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2332 | + } |
|
| 2333 | + |
|
| 2334 | + |
|
| 2335 | + /** Event Category Stuff **/ |
|
| 2336 | + /** |
|
| 2337 | + * set the _category property with the category object for the loaded page. |
|
| 2338 | + * |
|
| 2339 | + * @access private |
|
| 2340 | + * @return void |
|
| 2341 | + */ |
|
| 2342 | + private function _set_category_object() |
|
| 2343 | + { |
|
| 2344 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2345 | + return; |
|
| 2346 | + } //already have the category object so get out. |
|
| 2347 | + //set default category object |
|
| 2348 | + $this->_set_empty_category_object(); |
|
| 2349 | + //only set if we've got an id |
|
| 2350 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2351 | + return; |
|
| 2352 | + } |
|
| 2353 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2354 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2355 | + if ( ! empty($term)) { |
|
| 2356 | + $this->_category->category_name = $term->name; |
|
| 2357 | + $this->_category->category_identifier = $term->slug; |
|
| 2358 | + $this->_category->category_desc = $term->description; |
|
| 2359 | + $this->_category->id = $term->term_id; |
|
| 2360 | + $this->_category->parent = $term->parent; |
|
| 2361 | + } |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + |
|
| 2365 | + |
|
| 2366 | + private function _set_empty_category_object() |
|
| 2367 | + { |
|
| 2368 | + $this->_category = new stdClass(); |
|
| 2369 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2370 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2371 | + } |
|
| 2372 | + |
|
| 2373 | + |
|
| 2374 | + |
|
| 2375 | + protected function _category_list_table() |
|
| 2376 | + { |
|
| 2377 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2378 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2379 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2380 | + 'add_category', |
|
| 2381 | + 'add_category', |
|
| 2382 | + array(), |
|
| 2383 | + 'add-new-h2' |
|
| 2384 | + ); |
|
| 2385 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + |
|
| 2389 | + |
|
| 2390 | + /** |
|
| 2391 | + * @param $view |
|
| 2392 | + */ |
|
| 2393 | + protected function _category_details($view) |
|
| 2394 | + { |
|
| 2395 | + //load formatter helper |
|
| 2396 | + //load field generator helper |
|
| 2397 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2398 | + $this->_set_add_edit_form_tags($route); |
|
| 2399 | + $this->_set_category_object(); |
|
| 2400 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2401 | + $delete_action = 'delete_category'; |
|
| 2402 | + //custom redirect |
|
| 2403 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2404 | + array('action' => 'category_list'), |
|
| 2405 | + $this->_admin_base_url |
|
| 2406 | + ); |
|
| 2407 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2408 | + //take care of contents |
|
| 2409 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2410 | + $this->display_admin_page_with_sidebar(); |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + |
|
| 2414 | + |
|
| 2415 | + /** |
|
| 2416 | + * @return mixed |
|
| 2417 | + */ |
|
| 2418 | + protected function _category_details_content() |
|
| 2419 | + { |
|
| 2420 | + $editor_args['category_desc'] = array( |
|
| 2421 | + 'type' => 'wp_editor', |
|
| 2422 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2423 | + 'class' => 'my_editor_custom', |
|
| 2424 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2425 | + ); |
|
| 2426 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2427 | + $all_terms = get_terms( |
|
| 2428 | + array('espresso_event_categories'), |
|
| 2429 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2430 | + ); |
|
| 2431 | + //setup category select for term parents. |
|
| 2432 | + $category_select_values[] = array( |
|
| 2433 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2434 | + 'id' => 0, |
|
| 2435 | + ); |
|
| 2436 | + foreach ($all_terms as $term) { |
|
| 2437 | + $category_select_values[] = array( |
|
| 2438 | + 'text' => $term->name, |
|
| 2439 | + 'id' => $term->term_id, |
|
| 2440 | + ); |
|
| 2441 | + } |
|
| 2442 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2443 | + 'category_parent', |
|
| 2444 | + $category_select_values, |
|
| 2445 | + $this->_category->parent |
|
| 2446 | + ); |
|
| 2447 | + $template_args = array( |
|
| 2448 | + 'category' => $this->_category, |
|
| 2449 | + 'category_select' => $category_select, |
|
| 2450 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2451 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2452 | + 'disable' => '', |
|
| 2453 | + 'disabled_message' => false, |
|
| 2454 | + ); |
|
| 2455 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2456 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2457 | + } |
|
| 2458 | + |
|
| 2459 | + |
|
| 2460 | + |
|
| 2461 | + protected function _delete_categories() |
|
| 2462 | + { |
|
| 2463 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2464 | + : (array)$this->_req_data['category_id']; |
|
| 2465 | + foreach ($cat_ids as $cat_id) { |
|
| 2466 | + $this->_delete_category($cat_id); |
|
| 2467 | + } |
|
| 2468 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2469 | + $query_args = array( |
|
| 2470 | + 'action' => 'category_list', |
|
| 2471 | + ); |
|
| 2472 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + |
|
| 2476 | + |
|
| 2477 | + /** |
|
| 2478 | + * @param $cat_id |
|
| 2479 | + */ |
|
| 2480 | + protected function _delete_category($cat_id) |
|
| 2481 | + { |
|
| 2482 | + $cat_id = absint($cat_id); |
|
| 2483 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2484 | + } |
|
| 2485 | + |
|
| 2486 | + |
|
| 2487 | + |
|
| 2488 | + /** |
|
| 2489 | + * @param $new_category |
|
| 2490 | + */ |
|
| 2491 | + protected function _insert_or_update_category($new_category) |
|
| 2492 | + { |
|
| 2493 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2494 | + $success = 0; //we already have a success message so lets not send another. |
|
| 2495 | + if ($cat_id) { |
|
| 2496 | + $query_args = array( |
|
| 2497 | + 'action' => 'edit_category', |
|
| 2498 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2499 | + ); |
|
| 2500 | + } else { |
|
| 2501 | + $query_args = array('action' => 'add_category'); |
|
| 2502 | + } |
|
| 2503 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2504 | + } |
|
| 2505 | + |
|
| 2506 | + |
|
| 2507 | + |
|
| 2508 | + /** |
|
| 2509 | + * @param bool $update |
|
| 2510 | + * @return bool|mixed|string |
|
| 2511 | + */ |
|
| 2512 | + private function _insert_category($update = false) |
|
| 2513 | + { |
|
| 2514 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2515 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2516 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2517 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2518 | + if (empty($category_name)) { |
|
| 2519 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2520 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2521 | + return false; |
|
| 2522 | + } |
|
| 2523 | + $term_args = array( |
|
| 2524 | + 'name' => $category_name, |
|
| 2525 | + 'description' => $category_desc, |
|
| 2526 | + 'parent' => $category_parent, |
|
| 2527 | + ); |
|
| 2528 | + //was the category_identifier input disabled? |
|
| 2529 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2530 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2531 | + } |
|
| 2532 | + $insert_ids = $update |
|
| 2533 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2534 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2535 | + if ( ! is_array($insert_ids)) { |
|
| 2536 | + $msg = esc_html__( |
|
| 2537 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2538 | + 'event_espresso' |
|
| 2539 | + ); |
|
| 2540 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2541 | + } else { |
|
| 2542 | + $cat_id = $insert_ids['term_id']; |
|
| 2543 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2544 | + EE_Error::add_success($msg); |
|
| 2545 | + } |
|
| 2546 | + return $cat_id; |
|
| 2547 | + } |
|
| 2548 | + |
|
| 2549 | + |
|
| 2550 | + |
|
| 2551 | + /** |
|
| 2552 | + * @param int $per_page |
|
| 2553 | + * @param int $current_page |
|
| 2554 | + * @param bool $count |
|
| 2555 | + * @return \EE_Base_Class[]|int |
|
| 2556 | + */ |
|
| 2557 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2558 | + { |
|
| 2559 | + //testing term stuff |
|
| 2560 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2561 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2562 | + $limit = ($current_page - 1) * $per_page; |
|
| 2563 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2564 | + if (isset($this->_req_data['s'])) { |
|
| 2565 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2566 | + $where['OR'] = array( |
|
| 2567 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2568 | + 'description' => array('LIKE', $sstr), |
|
| 2569 | + ); |
|
| 2570 | + } |
|
| 2571 | + $query_params = array( |
|
| 2572 | + $where, |
|
| 2573 | + 'order_by' => array($orderby => $order), |
|
| 2574 | + 'limit' => $limit . ',' . $per_page, |
|
| 2575 | + 'force_join' => array('Term'), |
|
| 2576 | + ); |
|
| 2577 | + $categories = $count |
|
| 2578 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2579 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2580 | + return $categories; |
|
| 2581 | + } |
|
| 2582 | + |
|
| 2583 | + |
|
| 2584 | + |
|
| 2585 | + /* end category stuff */ |
|
| 2586 | + /**************/ |
|
| 2587 | 2587 | } |
| 2588 | 2588 | //end class Events_Admin_Page |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace EventEspresso\modules\ticket_selector; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 5 | - exit( 'No direct script access allowed' ); |
|
| 5 | + exit( 'No direct script access allowed' ); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -19,475 +19,475 @@ discard block |
||
| 19 | 19 | class ProcessTicketSelector |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * array of datetimes and the spaces available for them |
|
| 24 | - * |
|
| 25 | - * @access private |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private static $_available_spaces = array(); |
|
| 22 | + /** |
|
| 23 | + * array of datetimes and the spaces available for them |
|
| 24 | + * |
|
| 25 | + * @access private |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private static $_available_spaces = array(); |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * process_ticket_selections |
|
| 34 | - * |
|
| 35 | - * @return array|bool |
|
| 36 | - * @throws \EE_Error |
|
| 37 | - */ |
|
| 38 | - public function processTicketSelections() |
|
| 39 | - { |
|
| 40 | - do_action( 'EED_Ticket_Selector__process_ticket_selections__before' ); |
|
| 41 | - // do we have an event id? |
|
| 42 | - if ( ! \EE_Registry::instance()->REQ->is_set( 'tkt-slctr-event-id' ) ) { |
|
| 43 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 44 | - \EE_Error::add_error( |
|
| 45 | - sprintf( |
|
| 46 | - __( |
|
| 47 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 48 | - 'event_espresso' |
|
| 49 | - ), |
|
| 50 | - '<br/>' |
|
| 51 | - ), |
|
| 52 | - __FILE__, |
|
| 53 | - __FUNCTION__, |
|
| 54 | - __LINE__ |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - //if event id is valid |
|
| 58 | - $id = absint( \EE_Registry::instance()->REQ->get( 'tkt-slctr-event-id' ) ); |
|
| 59 | - // check nonce |
|
| 60 | - if ( |
|
| 61 | - ! is_admin() |
|
| 62 | - && ( |
|
| 63 | - ! \EE_Registry::instance()->REQ->is_set( 'process_ticket_selections_nonce_' . $id ) |
|
| 64 | - || ! wp_verify_nonce( |
|
| 65 | - \EE_Registry::instance()->REQ->get( 'process_ticket_selections_nonce_' . $id ), |
|
| 66 | - 'process_ticket_selections' |
|
| 67 | - ) |
|
| 68 | - ) |
|
| 69 | - ) { |
|
| 70 | - \EE_Error::add_error( |
|
| 71 | - sprintf( |
|
| 72 | - __( |
|
| 73 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 74 | - 'event_espresso' |
|
| 75 | - ), |
|
| 76 | - '<br/>' |
|
| 77 | - ), |
|
| 78 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 79 | - ); |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 32 | + /** |
|
| 33 | + * process_ticket_selections |
|
| 34 | + * |
|
| 35 | + * @return array|bool |
|
| 36 | + * @throws \EE_Error |
|
| 37 | + */ |
|
| 38 | + public function processTicketSelections() |
|
| 39 | + { |
|
| 40 | + do_action( 'EED_Ticket_Selector__process_ticket_selections__before' ); |
|
| 41 | + // do we have an event id? |
|
| 42 | + if ( ! \EE_Registry::instance()->REQ->is_set( 'tkt-slctr-event-id' ) ) { |
|
| 43 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 44 | + \EE_Error::add_error( |
|
| 45 | + sprintf( |
|
| 46 | + __( |
|
| 47 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 48 | + 'event_espresso' |
|
| 49 | + ), |
|
| 50 | + '<br/>' |
|
| 51 | + ), |
|
| 52 | + __FILE__, |
|
| 53 | + __FUNCTION__, |
|
| 54 | + __LINE__ |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + //if event id is valid |
|
| 58 | + $id = absint( \EE_Registry::instance()->REQ->get( 'tkt-slctr-event-id' ) ); |
|
| 59 | + // check nonce |
|
| 60 | + if ( |
|
| 61 | + ! is_admin() |
|
| 62 | + && ( |
|
| 63 | + ! \EE_Registry::instance()->REQ->is_set( 'process_ticket_selections_nonce_' . $id ) |
|
| 64 | + || ! wp_verify_nonce( |
|
| 65 | + \EE_Registry::instance()->REQ->get( 'process_ticket_selections_nonce_' . $id ), |
|
| 66 | + 'process_ticket_selections' |
|
| 67 | + ) |
|
| 68 | + ) |
|
| 69 | + ) { |
|
| 70 | + \EE_Error::add_error( |
|
| 71 | + sprintf( |
|
| 72 | + __( |
|
| 73 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 74 | + 'event_espresso' |
|
| 75 | + ), |
|
| 76 | + '<br/>' |
|
| 77 | + ), |
|
| 78 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 79 | + ); |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | 82 | // d( \EE_Registry::instance()->REQ ); |
| 83 | - self::$_available_spaces = array( |
|
| 84 | - 'tickets' => array(), |
|
| 85 | - 'datetimes' => array(), |
|
| 86 | - ); |
|
| 87 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
| 88 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
| 89 | - \EE_Registry::instance()->load_core( 'Session' ); |
|
| 90 | - // unless otherwise requested, clear the session |
|
| 91 | - if ( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true ) ) { |
|
| 92 | - \EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
|
| 93 | - } |
|
| 94 | - //d( \EE_Registry::instance()->SSN ); |
|
| 95 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 96 | - // validate/sanitize data |
|
| 97 | - $valid = $this->validatePostData( $id ); |
|
| 98 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 99 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
| 100 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
| 101 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
| 102 | - //check total tickets ordered vs max number of attendees that can register |
|
| 103 | - if ( $valid[ 'total_tickets' ] > $valid[ 'max_atndz' ] ) { |
|
| 104 | - // ordering too many tickets !!! |
|
| 105 | - $total_tickets_string = _n( |
|
| 106 | - 'You have attempted to purchase %s ticket.', |
|
| 107 | - 'You have attempted to purchase %s tickets.', |
|
| 108 | - $valid[ 'total_tickets' ], |
|
| 109 | - 'event_espresso' |
|
| 110 | - ); |
|
| 111 | - $limit_error_1 = sprintf( $total_tickets_string, $valid[ 'total_tickets' ] ); |
|
| 112 | - // dev only message |
|
| 113 | - $max_atndz_string = _n( |
|
| 114 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 115 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 116 | - $valid[ 'max_atndz' ], |
|
| 117 | - 'event_espresso' |
|
| 118 | - ); |
|
| 119 | - $limit_error_2 = sprintf( $max_atndz_string, $valid[ 'max_atndz' ], $valid[ 'max_atndz' ] ); |
|
| 120 | - \EE_Error::add_error( $limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 121 | - } else { |
|
| 122 | - // all data appears to be valid |
|
| 123 | - $tckts_slctd = false; |
|
| 124 | - $success = true; |
|
| 125 | - // load cart |
|
| 126 | - \EE_Registry::instance()->load_core( 'Cart' ); |
|
| 127 | - // cycle thru the number of data rows sent from the event listing |
|
| 128 | - for ( $x = 0; $x < $valid[ 'rows' ]; $x++ ) { |
|
| 129 | - // does this row actually contain a ticket quantity? |
|
| 130 | - if ( isset( $valid[ 'qty' ][ $x ] ) && $valid[ 'qty' ][ $x ] > 0 ) { |
|
| 131 | - // YES we have a ticket quantity |
|
| 132 | - $tckts_slctd = true; |
|
| 133 | - // d( $valid['ticket_obj'][$x] ); |
|
| 134 | - if ( $valid[ 'ticket_obj' ][ $x ] instanceof \EE_Ticket ) { |
|
| 135 | - // then add ticket to cart |
|
| 136 | - $ticket_added = $this->addTicketToCart( $valid[ 'ticket_obj' ][ $x ], |
|
| 137 | - $valid[ 'qty' ][ $x ] ); |
|
| 138 | - $success = ! $ticket_added ? false : $success; |
|
| 139 | - if ( \EE_Error::has_error() ) { |
|
| 140 | - break; |
|
| 141 | - } |
|
| 142 | - } else { |
|
| 143 | - // nothing added to cart retrieved |
|
| 144 | - \EE_Error::add_error( |
|
| 145 | - sprintf( |
|
| 146 | - __( |
|
| 147 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 148 | - 'event_espresso' |
|
| 149 | - ), |
|
| 150 | - '<br/>' |
|
| 151 | - ), |
|
| 152 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - //d( \EE_Registry::instance()->CART ); |
|
| 158 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 159 | - if ( $tckts_slctd ) { |
|
| 160 | - if ( $success ) { |
|
| 161 | - do_action( |
|
| 162 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 163 | - \EE_Registry::instance()->CART, |
|
| 164 | - $this |
|
| 165 | - ); |
|
| 166 | - \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
| 167 | - \EE_Registry::instance()->CART->save_cart( false ); |
|
| 168 | - //d( \EE_Registry::instance()->CART ); |
|
| 169 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 170 | - // just return TRUE for registrations being made from admin |
|
| 171 | - if ( is_admin() ) { |
|
| 172 | - return true; |
|
| 173 | - } |
|
| 174 | - wp_safe_redirect( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 175 | - \EE_Registry::instance()->CFG->core->reg_page_url() ) ); |
|
| 176 | - exit(); |
|
| 177 | - } else { |
|
| 178 | - if ( ! \EE_Error::has_error() ) { |
|
| 179 | - // nothing added to cart |
|
| 180 | - \EE_Error::add_attention( __( 'No tickets were added for the event', 'event_espresso' ), |
|
| 181 | - __FILE__, __FUNCTION__, __LINE__ ); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } else { |
|
| 185 | - // no ticket quantities were selected |
|
| 186 | - \EE_Error::add_error( __( 'You need to select a ticket quantity before you can proceed.', |
|
| 187 | - 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 191 | - // at this point, just return if registration is being made from admin |
|
| 192 | - if ( is_admin() ) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - if ( $valid[ 'return_url' ] ) { |
|
| 196 | - \EE_Error::get_notices( false, true ); |
|
| 197 | - wp_safe_redirect( $valid[ 'return_url' ] ); |
|
| 198 | - exit(); |
|
| 199 | - } elseif ( isset( $event_to_add[ 'id' ] ) ) { |
|
| 200 | - \EE_Error::get_notices( false, true ); |
|
| 201 | - wp_safe_redirect( get_permalink( $event_to_add[ 'id' ] ) ); |
|
| 202 | - exit(); |
|
| 203 | - } else { |
|
| 204 | - echo \EE_Error::get_notices(); |
|
| 205 | - } |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 83 | + self::$_available_spaces = array( |
|
| 84 | + 'tickets' => array(), |
|
| 85 | + 'datetimes' => array(), |
|
| 86 | + ); |
|
| 87 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
| 88 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
| 89 | + \EE_Registry::instance()->load_core( 'Session' ); |
|
| 90 | + // unless otherwise requested, clear the session |
|
| 91 | + if ( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true ) ) { |
|
| 92 | + \EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
|
| 93 | + } |
|
| 94 | + //d( \EE_Registry::instance()->SSN ); |
|
| 95 | + do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 96 | + // validate/sanitize data |
|
| 97 | + $valid = $this->validatePostData( $id ); |
|
| 98 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 99 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
| 100 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
| 101 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
| 102 | + //check total tickets ordered vs max number of attendees that can register |
|
| 103 | + if ( $valid[ 'total_tickets' ] > $valid[ 'max_atndz' ] ) { |
|
| 104 | + // ordering too many tickets !!! |
|
| 105 | + $total_tickets_string = _n( |
|
| 106 | + 'You have attempted to purchase %s ticket.', |
|
| 107 | + 'You have attempted to purchase %s tickets.', |
|
| 108 | + $valid[ 'total_tickets' ], |
|
| 109 | + 'event_espresso' |
|
| 110 | + ); |
|
| 111 | + $limit_error_1 = sprintf( $total_tickets_string, $valid[ 'total_tickets' ] ); |
|
| 112 | + // dev only message |
|
| 113 | + $max_atndz_string = _n( |
|
| 114 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 115 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 116 | + $valid[ 'max_atndz' ], |
|
| 117 | + 'event_espresso' |
|
| 118 | + ); |
|
| 119 | + $limit_error_2 = sprintf( $max_atndz_string, $valid[ 'max_atndz' ], $valid[ 'max_atndz' ] ); |
|
| 120 | + \EE_Error::add_error( $limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 121 | + } else { |
|
| 122 | + // all data appears to be valid |
|
| 123 | + $tckts_slctd = false; |
|
| 124 | + $success = true; |
|
| 125 | + // load cart |
|
| 126 | + \EE_Registry::instance()->load_core( 'Cart' ); |
|
| 127 | + // cycle thru the number of data rows sent from the event listing |
|
| 128 | + for ( $x = 0; $x < $valid[ 'rows' ]; $x++ ) { |
|
| 129 | + // does this row actually contain a ticket quantity? |
|
| 130 | + if ( isset( $valid[ 'qty' ][ $x ] ) && $valid[ 'qty' ][ $x ] > 0 ) { |
|
| 131 | + // YES we have a ticket quantity |
|
| 132 | + $tckts_slctd = true; |
|
| 133 | + // d( $valid['ticket_obj'][$x] ); |
|
| 134 | + if ( $valid[ 'ticket_obj' ][ $x ] instanceof \EE_Ticket ) { |
|
| 135 | + // then add ticket to cart |
|
| 136 | + $ticket_added = $this->addTicketToCart( $valid[ 'ticket_obj' ][ $x ], |
|
| 137 | + $valid[ 'qty' ][ $x ] ); |
|
| 138 | + $success = ! $ticket_added ? false : $success; |
|
| 139 | + if ( \EE_Error::has_error() ) { |
|
| 140 | + break; |
|
| 141 | + } |
|
| 142 | + } else { |
|
| 143 | + // nothing added to cart retrieved |
|
| 144 | + \EE_Error::add_error( |
|
| 145 | + sprintf( |
|
| 146 | + __( |
|
| 147 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 148 | + 'event_espresso' |
|
| 149 | + ), |
|
| 150 | + '<br/>' |
|
| 151 | + ), |
|
| 152 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + //d( \EE_Registry::instance()->CART ); |
|
| 158 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 159 | + if ( $tckts_slctd ) { |
|
| 160 | + if ( $success ) { |
|
| 161 | + do_action( |
|
| 162 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 163 | + \EE_Registry::instance()->CART, |
|
| 164 | + $this |
|
| 165 | + ); |
|
| 166 | + \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
| 167 | + \EE_Registry::instance()->CART->save_cart( false ); |
|
| 168 | + //d( \EE_Registry::instance()->CART ); |
|
| 169 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 170 | + // just return TRUE for registrations being made from admin |
|
| 171 | + if ( is_admin() ) { |
|
| 172 | + return true; |
|
| 173 | + } |
|
| 174 | + wp_safe_redirect( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 175 | + \EE_Registry::instance()->CFG->core->reg_page_url() ) ); |
|
| 176 | + exit(); |
|
| 177 | + } else { |
|
| 178 | + if ( ! \EE_Error::has_error() ) { |
|
| 179 | + // nothing added to cart |
|
| 180 | + \EE_Error::add_attention( __( 'No tickets were added for the event', 'event_espresso' ), |
|
| 181 | + __FILE__, __FUNCTION__, __LINE__ ); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } else { |
|
| 185 | + // no ticket quantities were selected |
|
| 186 | + \EE_Error::add_error( __( 'You need to select a ticket quantity before you can proceed.', |
|
| 187 | + 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 191 | + // at this point, just return if registration is being made from admin |
|
| 192 | + if ( is_admin() ) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + if ( $valid[ 'return_url' ] ) { |
|
| 196 | + \EE_Error::get_notices( false, true ); |
|
| 197 | + wp_safe_redirect( $valid[ 'return_url' ] ); |
|
| 198 | + exit(); |
|
| 199 | + } elseif ( isset( $event_to_add[ 'id' ] ) ) { |
|
| 200 | + \EE_Error::get_notices( false, true ); |
|
| 201 | + wp_safe_redirect( get_permalink( $event_to_add[ 'id' ] ) ); |
|
| 202 | + exit(); |
|
| 203 | + } else { |
|
| 204 | + echo \EE_Error::get_notices(); |
|
| 205 | + } |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * validate_post_data |
|
| 213 | - * |
|
| 214 | - * @param int $id |
|
| 215 | - * @return array|FALSE |
|
| 216 | - */ |
|
| 217 | - private function validatePostData( $id = 0 ) |
|
| 218 | - { |
|
| 219 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 220 | - if ( ! $id ) { |
|
| 221 | - \EE_Error::add_error( |
|
| 222 | - __( 'The event id provided was not valid.', 'event_espresso' ), |
|
| 223 | - __FILE__, |
|
| 224 | - __FUNCTION__, |
|
| 225 | - __LINE__ |
|
| 226 | - ); |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - // start with an empty array() |
|
| 230 | - $valid_data = array(); |
|
| 231 | - // grab valid id |
|
| 232 | - $valid_data[ 'id' ] = $id; |
|
| 233 | - // grab and sanitize return-url |
|
| 234 | - $valid_data[ 'return_url' ] = esc_url_raw( |
|
| 235 | - \EE_Registry::instance()->REQ->get( 'tkt-slctr-return-url-' . $id ) |
|
| 236 | - ); |
|
| 237 | - // array of other form names |
|
| 238 | - $inputs_to_clean = array( |
|
| 239 | - 'event_id' => 'tkt-slctr-event-id', |
|
| 240 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 241 | - 'rows' => 'tkt-slctr-rows-', |
|
| 242 | - 'qty' => 'tkt-slctr-qty-', |
|
| 243 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 244 | - 'return_url' => 'tkt-slctr-return-url-', |
|
| 245 | - ); |
|
| 246 | - // let's track the total number of tickets ordered.' |
|
| 247 | - $valid_data[ 'total_tickets' ] = 0; |
|
| 248 | - // cycle through $inputs_to_clean array |
|
| 249 | - foreach ( $inputs_to_clean as $what => $input_to_clean ) { |
|
| 250 | - // check for POST data |
|
| 251 | - if ( \EE_Registry::instance()->REQ->is_set( $input_to_clean . $id ) ) { |
|
| 252 | - // grab value |
|
| 253 | - $input_value = \EE_Registry::instance()->REQ->get( $input_to_clean . $id ); |
|
| 254 | - switch ( $what ) { |
|
| 255 | - // integers |
|
| 256 | - case 'event_id': |
|
| 257 | - $valid_data[ $what ] = absint( $input_value ); |
|
| 258 | - // get event via the event id we put in the form |
|
| 259 | - $valid_data[ 'event' ] = \EE_Registry::instance() |
|
| 260 | - ->load_model( 'Event' ) |
|
| 261 | - ->get_one_by_ID( $valid_data[ 'event_id' ] ); |
|
| 262 | - break; |
|
| 263 | - case 'rows': |
|
| 264 | - case 'max_atndz': |
|
| 265 | - $valid_data[ $what ] = absint( $input_value ); |
|
| 266 | - break; |
|
| 267 | - // arrays of integers |
|
| 268 | - case 'qty': |
|
| 269 | - /** @var array $row_qty */ |
|
| 270 | - $row_qty = $input_value; |
|
| 271 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 272 | - if ( ! is_array( $row_qty ) ) { |
|
| 273 | - // get number of rows |
|
| 274 | - $rows = \EE_Registry::instance()->REQ->is_set( 'tkt-slctr-rows-' . $id ) |
|
| 275 | - ? absint( \EE_Registry::instance()->REQ->get( 'tkt-slctr-rows-' . $id ) ) |
|
| 276 | - : 1; |
|
| 277 | - // explode ints by the dash |
|
| 278 | - $row_qty = explode( '-', $row_qty ); |
|
| 279 | - $row = isset( $row_qty[ 0 ] ) ? ( absint( $row_qty[ 0 ] ) ) : 1; |
|
| 280 | - $qty = isset( $row_qty[ 1 ] ) ? absint( $row_qty[ 1 ] ) : 0; |
|
| 281 | - $row_qty = array( $row => $qty ); |
|
| 282 | - for ( $x = 1; $x <= $rows; $x++ ) { |
|
| 283 | - if ( ! isset( $row_qty[ $x ] ) ) { |
|
| 284 | - $row_qty[ $x ] = 0; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - ksort( $row_qty ); |
|
| 289 | - // cycle thru values |
|
| 290 | - foreach ( $row_qty as $qty ) { |
|
| 291 | - $qty = absint( $qty ); |
|
| 292 | - // sanitize as integers |
|
| 293 | - $valid_data[ $what ][] = $qty; |
|
| 294 | - $valid_data[ 'total_tickets' ] += $qty; |
|
| 295 | - } |
|
| 296 | - break; |
|
| 297 | - // array of integers |
|
| 298 | - case 'ticket_id': |
|
| 299 | - $value_array = array(); |
|
| 300 | - // cycle thru values |
|
| 301 | - foreach ( (array)$input_value as $key => $value ) { |
|
| 302 | - // allow only numbers, letters, spaces, commas and dashes |
|
| 303 | - $value_array[ $key ] = wp_strip_all_tags( $value ); |
|
| 304 | - // get ticket via the ticket id we put in the form |
|
| 305 | - $ticket_obj = \EE_Registry::instance()->load_model( 'Ticket' )->get_one_by_ID( $value ); |
|
| 306 | - $valid_data[ 'ticket_obj' ][ $key ] = $ticket_obj; |
|
| 307 | - } |
|
| 308 | - $valid_data[ $what ] = $value_array; |
|
| 309 | - break; |
|
| 310 | - case 'return_url' : |
|
| 311 | - // grab and sanitize return-url |
|
| 312 | - $valid_data[ $what ] = esc_url_raw( $input_value ); |
|
| 313 | - break; |
|
| 314 | - } // end switch $what |
|
| 315 | - } |
|
| 316 | - } // end foreach $inputs_to_clean |
|
| 317 | - return $valid_data; |
|
| 318 | - } |
|
| 211 | + /** |
|
| 212 | + * validate_post_data |
|
| 213 | + * |
|
| 214 | + * @param int $id |
|
| 215 | + * @return array|FALSE |
|
| 216 | + */ |
|
| 217 | + private function validatePostData( $id = 0 ) |
|
| 218 | + { |
|
| 219 | + do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 220 | + if ( ! $id ) { |
|
| 221 | + \EE_Error::add_error( |
|
| 222 | + __( 'The event id provided was not valid.', 'event_espresso' ), |
|
| 223 | + __FILE__, |
|
| 224 | + __FUNCTION__, |
|
| 225 | + __LINE__ |
|
| 226 | + ); |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + // start with an empty array() |
|
| 230 | + $valid_data = array(); |
|
| 231 | + // grab valid id |
|
| 232 | + $valid_data[ 'id' ] = $id; |
|
| 233 | + // grab and sanitize return-url |
|
| 234 | + $valid_data[ 'return_url' ] = esc_url_raw( |
|
| 235 | + \EE_Registry::instance()->REQ->get( 'tkt-slctr-return-url-' . $id ) |
|
| 236 | + ); |
|
| 237 | + // array of other form names |
|
| 238 | + $inputs_to_clean = array( |
|
| 239 | + 'event_id' => 'tkt-slctr-event-id', |
|
| 240 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 241 | + 'rows' => 'tkt-slctr-rows-', |
|
| 242 | + 'qty' => 'tkt-slctr-qty-', |
|
| 243 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 244 | + 'return_url' => 'tkt-slctr-return-url-', |
|
| 245 | + ); |
|
| 246 | + // let's track the total number of tickets ordered.' |
|
| 247 | + $valid_data[ 'total_tickets' ] = 0; |
|
| 248 | + // cycle through $inputs_to_clean array |
|
| 249 | + foreach ( $inputs_to_clean as $what => $input_to_clean ) { |
|
| 250 | + // check for POST data |
|
| 251 | + if ( \EE_Registry::instance()->REQ->is_set( $input_to_clean . $id ) ) { |
|
| 252 | + // grab value |
|
| 253 | + $input_value = \EE_Registry::instance()->REQ->get( $input_to_clean . $id ); |
|
| 254 | + switch ( $what ) { |
|
| 255 | + // integers |
|
| 256 | + case 'event_id': |
|
| 257 | + $valid_data[ $what ] = absint( $input_value ); |
|
| 258 | + // get event via the event id we put in the form |
|
| 259 | + $valid_data[ 'event' ] = \EE_Registry::instance() |
|
| 260 | + ->load_model( 'Event' ) |
|
| 261 | + ->get_one_by_ID( $valid_data[ 'event_id' ] ); |
|
| 262 | + break; |
|
| 263 | + case 'rows': |
|
| 264 | + case 'max_atndz': |
|
| 265 | + $valid_data[ $what ] = absint( $input_value ); |
|
| 266 | + break; |
|
| 267 | + // arrays of integers |
|
| 268 | + case 'qty': |
|
| 269 | + /** @var array $row_qty */ |
|
| 270 | + $row_qty = $input_value; |
|
| 271 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 272 | + if ( ! is_array( $row_qty ) ) { |
|
| 273 | + // get number of rows |
|
| 274 | + $rows = \EE_Registry::instance()->REQ->is_set( 'tkt-slctr-rows-' . $id ) |
|
| 275 | + ? absint( \EE_Registry::instance()->REQ->get( 'tkt-slctr-rows-' . $id ) ) |
|
| 276 | + : 1; |
|
| 277 | + // explode ints by the dash |
|
| 278 | + $row_qty = explode( '-', $row_qty ); |
|
| 279 | + $row = isset( $row_qty[ 0 ] ) ? ( absint( $row_qty[ 0 ] ) ) : 1; |
|
| 280 | + $qty = isset( $row_qty[ 1 ] ) ? absint( $row_qty[ 1 ] ) : 0; |
|
| 281 | + $row_qty = array( $row => $qty ); |
|
| 282 | + for ( $x = 1; $x <= $rows; $x++ ) { |
|
| 283 | + if ( ! isset( $row_qty[ $x ] ) ) { |
|
| 284 | + $row_qty[ $x ] = 0; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + ksort( $row_qty ); |
|
| 289 | + // cycle thru values |
|
| 290 | + foreach ( $row_qty as $qty ) { |
|
| 291 | + $qty = absint( $qty ); |
|
| 292 | + // sanitize as integers |
|
| 293 | + $valid_data[ $what ][] = $qty; |
|
| 294 | + $valid_data[ 'total_tickets' ] += $qty; |
|
| 295 | + } |
|
| 296 | + break; |
|
| 297 | + // array of integers |
|
| 298 | + case 'ticket_id': |
|
| 299 | + $value_array = array(); |
|
| 300 | + // cycle thru values |
|
| 301 | + foreach ( (array)$input_value as $key => $value ) { |
|
| 302 | + // allow only numbers, letters, spaces, commas and dashes |
|
| 303 | + $value_array[ $key ] = wp_strip_all_tags( $value ); |
|
| 304 | + // get ticket via the ticket id we put in the form |
|
| 305 | + $ticket_obj = \EE_Registry::instance()->load_model( 'Ticket' )->get_one_by_ID( $value ); |
|
| 306 | + $valid_data[ 'ticket_obj' ][ $key ] = $ticket_obj; |
|
| 307 | + } |
|
| 308 | + $valid_data[ $what ] = $value_array; |
|
| 309 | + break; |
|
| 310 | + case 'return_url' : |
|
| 311 | + // grab and sanitize return-url |
|
| 312 | + $valid_data[ $what ] = esc_url_raw( $input_value ); |
|
| 313 | + break; |
|
| 314 | + } // end switch $what |
|
| 315 | + } |
|
| 316 | + } // end foreach $inputs_to_clean |
|
| 317 | + return $valid_data; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | 320 | |
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * adds a ticket to the cart |
|
| 324 | - * |
|
| 325 | - * @param \EE_Ticket $ticket |
|
| 326 | - * @param int $qty |
|
| 327 | - * @return TRUE on success, FALSE on fail |
|
| 328 | - * @throws \EE_Error |
|
| 329 | - */ |
|
| 330 | - private function addTicketToCart( \EE_Ticket $ticket = null, $qty = 1 ) |
|
| 331 | - { |
|
| 332 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 333 | - // get the number of spaces left for this datetime ticket |
|
| 334 | - $available_spaces = $this->ticketDatetimeAvailability( $ticket ); |
|
| 335 | - // compare available spaces against the number of tickets being purchased |
|
| 336 | - if ( $available_spaces >= $qty ) { |
|
| 337 | - // allow addons to prevent a ticket from being added to cart |
|
| 338 | - if ( |
|
| 339 | - ! apply_filters( |
|
| 340 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 341 | - true, |
|
| 342 | - $ticket, |
|
| 343 | - $qty, |
|
| 344 | - $available_spaces |
|
| 345 | - ) |
|
| 346 | - ) { |
|
| 347 | - return false; |
|
| 348 | - } |
|
| 349 | - // add event to cart |
|
| 350 | - if ( \EE_Registry::instance()->CART->add_ticket_to_cart( $ticket, $qty ) ) { |
|
| 351 | - $this->recalculateTicketDatetimeAvailability( $ticket, $qty ); |
|
| 352 | - return true; |
|
| 353 | - } |
|
| 354 | - return false; |
|
| 355 | - } |
|
| 356 | - // tickets can not be purchased but let's find the exact number left |
|
| 357 | - // for the last ticket selected PRIOR to subtracting tickets |
|
| 358 | - $available_spaces = $this->ticketDatetimeAvailability( $ticket, true ); |
|
| 359 | - // greedy greedy greedy eh? |
|
| 360 | - if ( $available_spaces > 0 ) { |
|
| 361 | - // add error messaging - we're using the _n function that will generate |
|
| 362 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
| 363 | - \EE_Error::add_error( |
|
| 364 | - sprintf( |
|
| 365 | - _n( |
|
| 366 | - 'We\'re sorry, but there is only %s available space left for this event at this particular date and time.%sPlease select a different number (or different combination) of tickets.', |
|
| 367 | - 'We\'re sorry, but there are only %s available spaces left for this event at this particular date and time.%sPlease select a different number (or different combination) of tickets.', |
|
| 368 | - $available_spaces, |
|
| 369 | - 'event_espresso' |
|
| 370 | - ), |
|
| 371 | - $available_spaces, |
|
| 372 | - '<br />' |
|
| 373 | - ), |
|
| 374 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 375 | - ); |
|
| 376 | - } else { |
|
| 377 | - \EE_Error::add_error( |
|
| 378 | - __( |
|
| 379 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
| 380 | - 'event_espresso' |
|
| 381 | - ), |
|
| 382 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 383 | - ); |
|
| 384 | - } |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 322 | + /** |
|
| 323 | + * adds a ticket to the cart |
|
| 324 | + * |
|
| 325 | + * @param \EE_Ticket $ticket |
|
| 326 | + * @param int $qty |
|
| 327 | + * @return TRUE on success, FALSE on fail |
|
| 328 | + * @throws \EE_Error |
|
| 329 | + */ |
|
| 330 | + private function addTicketToCart( \EE_Ticket $ticket = null, $qty = 1 ) |
|
| 331 | + { |
|
| 332 | + do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 333 | + // get the number of spaces left for this datetime ticket |
|
| 334 | + $available_spaces = $this->ticketDatetimeAvailability( $ticket ); |
|
| 335 | + // compare available spaces against the number of tickets being purchased |
|
| 336 | + if ( $available_spaces >= $qty ) { |
|
| 337 | + // allow addons to prevent a ticket from being added to cart |
|
| 338 | + if ( |
|
| 339 | + ! apply_filters( |
|
| 340 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 341 | + true, |
|
| 342 | + $ticket, |
|
| 343 | + $qty, |
|
| 344 | + $available_spaces |
|
| 345 | + ) |
|
| 346 | + ) { |
|
| 347 | + return false; |
|
| 348 | + } |
|
| 349 | + // add event to cart |
|
| 350 | + if ( \EE_Registry::instance()->CART->add_ticket_to_cart( $ticket, $qty ) ) { |
|
| 351 | + $this->recalculateTicketDatetimeAvailability( $ticket, $qty ); |
|
| 352 | + return true; |
|
| 353 | + } |
|
| 354 | + return false; |
|
| 355 | + } |
|
| 356 | + // tickets can not be purchased but let's find the exact number left |
|
| 357 | + // for the last ticket selected PRIOR to subtracting tickets |
|
| 358 | + $available_spaces = $this->ticketDatetimeAvailability( $ticket, true ); |
|
| 359 | + // greedy greedy greedy eh? |
|
| 360 | + if ( $available_spaces > 0 ) { |
|
| 361 | + // add error messaging - we're using the _n function that will generate |
|
| 362 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
| 363 | + \EE_Error::add_error( |
|
| 364 | + sprintf( |
|
| 365 | + _n( |
|
| 366 | + 'We\'re sorry, but there is only %s available space left for this event at this particular date and time.%sPlease select a different number (or different combination) of tickets.', |
|
| 367 | + 'We\'re sorry, but there are only %s available spaces left for this event at this particular date and time.%sPlease select a different number (or different combination) of tickets.', |
|
| 368 | + $available_spaces, |
|
| 369 | + 'event_espresso' |
|
| 370 | + ), |
|
| 371 | + $available_spaces, |
|
| 372 | + '<br />' |
|
| 373 | + ), |
|
| 374 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 375 | + ); |
|
| 376 | + } else { |
|
| 377 | + \EE_Error::add_error( |
|
| 378 | + __( |
|
| 379 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
| 380 | + 'event_espresso' |
|
| 381 | + ), |
|
| 382 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 383 | + ); |
|
| 384 | + } |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | |
| 390 | - /** |
|
| 391 | - * ticketDatetimeAvailability |
|
| 392 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
| 393 | - * and tracks the spaces remaining for each of those datetimes |
|
| 394 | - * |
|
| 395 | - * @param \EE_Ticket $ticket - selected ticket |
|
| 396 | - * @param bool $get_original_ticket_spaces |
|
| 397 | - * @return int |
|
| 398 | - * @throws \EE_Error |
|
| 399 | - */ |
|
| 400 | - private function ticketDatetimeAvailability( \EE_Ticket $ticket, $get_original_ticket_spaces = false ) |
|
| 401 | - { |
|
| 402 | - // if the $_available_spaces array has not been set up yet... |
|
| 403 | - if ( ! isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 404 | - $this->setInitialTicketDatetimeAvailability( $ticket ); |
|
| 405 | - } |
|
| 406 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
| 407 | - if ( isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 408 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 409 | - foreach ( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
| 410 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
| 411 | - if ( $get_original_ticket_spaces ) { |
|
| 412 | - // then grab the available spaces from the "tickets" array |
|
| 413 | - // and compare with the above to get the lowest number |
|
| 414 | - $available_spaces = min( |
|
| 415 | - $available_spaces, |
|
| 416 | - self::$_available_spaces[ 'tickets' ][ $ticket->ID() ][ $DTD_ID ] |
|
| 417 | - ); |
|
| 418 | - } else { |
|
| 419 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
| 420 | - $available_spaces = min( $available_spaces, self::$_available_spaces[ 'datetimes' ][ $DTD_ID ] ); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - return $available_spaces; |
|
| 425 | - } |
|
| 390 | + /** |
|
| 391 | + * ticketDatetimeAvailability |
|
| 392 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
| 393 | + * and tracks the spaces remaining for each of those datetimes |
|
| 394 | + * |
|
| 395 | + * @param \EE_Ticket $ticket - selected ticket |
|
| 396 | + * @param bool $get_original_ticket_spaces |
|
| 397 | + * @return int |
|
| 398 | + * @throws \EE_Error |
|
| 399 | + */ |
|
| 400 | + private function ticketDatetimeAvailability( \EE_Ticket $ticket, $get_original_ticket_spaces = false ) |
|
| 401 | + { |
|
| 402 | + // if the $_available_spaces array has not been set up yet... |
|
| 403 | + if ( ! isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 404 | + $this->setInitialTicketDatetimeAvailability( $ticket ); |
|
| 405 | + } |
|
| 406 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
| 407 | + if ( isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 408 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 409 | + foreach ( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
| 410 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
| 411 | + if ( $get_original_ticket_spaces ) { |
|
| 412 | + // then grab the available spaces from the "tickets" array |
|
| 413 | + // and compare with the above to get the lowest number |
|
| 414 | + $available_spaces = min( |
|
| 415 | + $available_spaces, |
|
| 416 | + self::$_available_spaces[ 'tickets' ][ $ticket->ID() ][ $DTD_ID ] |
|
| 417 | + ); |
|
| 418 | + } else { |
|
| 419 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
| 420 | + $available_spaces = min( $available_spaces, self::$_available_spaces[ 'datetimes' ][ $DTD_ID ] ); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + return $available_spaces; |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | |
| 428 | 428 | |
| 429 | - /** |
|
| 430 | - * @param \EE_Ticket $ticket |
|
| 431 | - * @return void |
|
| 432 | - * @throws \EE_Error |
|
| 433 | - */ |
|
| 434 | - private function setInitialTicketDatetimeAvailability( \EE_Ticket $ticket ) |
|
| 435 | - { |
|
| 436 | - // first, get all of the datetimes that are available to this ticket |
|
| 437 | - $datetimes = $ticket->get_many_related( |
|
| 438 | - 'Datetime', |
|
| 439 | - array( |
|
| 440 | - array( |
|
| 441 | - 'DTT_EVT_end' => array( |
|
| 442 | - '>=', |
|
| 443 | - \EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ), |
|
| 444 | - ), |
|
| 445 | - ), |
|
| 446 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ), |
|
| 447 | - ) |
|
| 448 | - ); |
|
| 449 | - if ( ! empty( $datetimes ) ) { |
|
| 450 | - // now loop thru all of the datetimes |
|
| 451 | - foreach ( $datetimes as $datetime ) { |
|
| 452 | - if ( $datetime instanceof \EE_Datetime ) { |
|
| 453 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
| 454 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
| 455 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
| 456 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
| 457 | - self::$_available_spaces[ 'tickets' ][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
| 458 | - ( $ticket->qty() - $ticket->sold() ), |
|
| 459 | - $spaces_remaining |
|
| 460 | - ); |
|
| 461 | - // if the remaining spaces for this datetime is already set, |
|
| 462 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
| 463 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
| 464 | - self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ] = isset( |
|
| 465 | - self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ] |
|
| 466 | - ) |
|
| 467 | - ? min( self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ], $spaces_remaining ) |
|
| 468 | - : $spaces_remaining; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 429 | + /** |
|
| 430 | + * @param \EE_Ticket $ticket |
|
| 431 | + * @return void |
|
| 432 | + * @throws \EE_Error |
|
| 433 | + */ |
|
| 434 | + private function setInitialTicketDatetimeAvailability( \EE_Ticket $ticket ) |
|
| 435 | + { |
|
| 436 | + // first, get all of the datetimes that are available to this ticket |
|
| 437 | + $datetimes = $ticket->get_many_related( |
|
| 438 | + 'Datetime', |
|
| 439 | + array( |
|
| 440 | + array( |
|
| 441 | + 'DTT_EVT_end' => array( |
|
| 442 | + '>=', |
|
| 443 | + \EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ), |
|
| 444 | + ), |
|
| 445 | + ), |
|
| 446 | + 'order_by' => array( 'DTT_EVT_start' => 'ASC' ), |
|
| 447 | + ) |
|
| 448 | + ); |
|
| 449 | + if ( ! empty( $datetimes ) ) { |
|
| 450 | + // now loop thru all of the datetimes |
|
| 451 | + foreach ( $datetimes as $datetime ) { |
|
| 452 | + if ( $datetime instanceof \EE_Datetime ) { |
|
| 453 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
| 454 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
| 455 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
| 456 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
| 457 | + self::$_available_spaces[ 'tickets' ][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
| 458 | + ( $ticket->qty() - $ticket->sold() ), |
|
| 459 | + $spaces_remaining |
|
| 460 | + ); |
|
| 461 | + // if the remaining spaces for this datetime is already set, |
|
| 462 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
| 463 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
| 464 | + self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ] = isset( |
|
| 465 | + self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ] |
|
| 466 | + ) |
|
| 467 | + ? min( self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ], $spaces_remaining ) |
|
| 468 | + : $spaces_remaining; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | 473 | |
| 474 | 474 | |
| 475 | 475 | |
| 476 | - /** |
|
| 477 | - * @param \EE_Ticket $ticket |
|
| 478 | - * @param int $qty |
|
| 479 | - * @return void |
|
| 480 | - */ |
|
| 481 | - private function recalculateTicketDatetimeAvailability( \EE_Ticket $ticket, $qty = 0 ) |
|
| 482 | - { |
|
| 483 | - if ( isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 484 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 485 | - foreach ( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
| 486 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
| 487 | - self::$_available_spaces[ 'datetimes' ][ $DTD_ID ] -= $qty; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 476 | + /** |
|
| 477 | + * @param \EE_Ticket $ticket |
|
| 478 | + * @param int $qty |
|
| 479 | + * @return void |
|
| 480 | + */ |
|
| 481 | + private function recalculateTicketDatetimeAvailability( \EE_Ticket $ticket, $qty = 0 ) |
|
| 482 | + { |
|
| 483 | + if ( isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 484 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 485 | + foreach ( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
| 486 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
| 487 | + self::$_available_spaces[ 'datetimes' ][ $DTD_ID ] -= $qty; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | 492 | |
| 493 | 493 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\modules\ticket_selector; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function processTicketSelections() |
| 39 | 39 | { |
| 40 | - do_action( 'EED_Ticket_Selector__process_ticket_selections__before' ); |
|
| 40 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 41 | 41 | // do we have an event id? |
| 42 | - if ( ! \EE_Registry::instance()->REQ->is_set( 'tkt-slctr-event-id' ) ) { |
|
| 42 | + if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
| 43 | 43 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
| 44 | 44 | \EE_Error::add_error( |
| 45 | 45 | sprintf( |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | //if event id is valid |
| 58 | - $id = absint( \EE_Registry::instance()->REQ->get( 'tkt-slctr-event-id' ) ); |
|
| 58 | + $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
| 59 | 59 | // check nonce |
| 60 | 60 | if ( |
| 61 | 61 | ! is_admin() |
| 62 | 62 | && ( |
| 63 | - ! \EE_Registry::instance()->REQ->is_set( 'process_ticket_selections_nonce_' . $id ) |
|
| 63 | + ! \EE_Registry::instance()->REQ->is_set('process_ticket_selections_nonce_'.$id) |
|
| 64 | 64 | || ! wp_verify_nonce( |
| 65 | - \EE_Registry::instance()->REQ->get( 'process_ticket_selections_nonce_' . $id ), |
|
| 65 | + \EE_Registry::instance()->REQ->get('process_ticket_selections_nonce_'.$id), |
|
| 66 | 66 | 'process_ticket_selections' |
| 67 | 67 | ) |
| 68 | 68 | ) |
@@ -86,57 +86,57 @@ discard block |
||
| 86 | 86 | ); |
| 87 | 87 | //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
| 88 | 88 | // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
| 89 | - \EE_Registry::instance()->load_core( 'Session' ); |
|
| 89 | + \EE_Registry::instance()->load_core('Session'); |
|
| 90 | 90 | // unless otherwise requested, clear the session |
| 91 | - if ( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true ) ) { |
|
| 92 | - \EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
|
| 91 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 92 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 93 | 93 | } |
| 94 | 94 | //d( \EE_Registry::instance()->SSN ); |
| 95 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 95 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 96 | 96 | // validate/sanitize data |
| 97 | - $valid = $this->validatePostData( $id ); |
|
| 97 | + $valid = $this->validatePostData($id); |
|
| 98 | 98 | //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
| 99 | 99 | //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
| 100 | 100 | //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
| 101 | 101 | //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
| 102 | 102 | //check total tickets ordered vs max number of attendees that can register |
| 103 | - if ( $valid[ 'total_tickets' ] > $valid[ 'max_atndz' ] ) { |
|
| 103 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 104 | 104 | // ordering too many tickets !!! |
| 105 | 105 | $total_tickets_string = _n( |
| 106 | 106 | 'You have attempted to purchase %s ticket.', |
| 107 | 107 | 'You have attempted to purchase %s tickets.', |
| 108 | - $valid[ 'total_tickets' ], |
|
| 108 | + $valid['total_tickets'], |
|
| 109 | 109 | 'event_espresso' |
| 110 | 110 | ); |
| 111 | - $limit_error_1 = sprintf( $total_tickets_string, $valid[ 'total_tickets' ] ); |
|
| 111 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 112 | 112 | // dev only message |
| 113 | 113 | $max_atndz_string = _n( |
| 114 | 114 | 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
| 115 | 115 | 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
| 116 | - $valid[ 'max_atndz' ], |
|
| 116 | + $valid['max_atndz'], |
|
| 117 | 117 | 'event_espresso' |
| 118 | 118 | ); |
| 119 | - $limit_error_2 = sprintf( $max_atndz_string, $valid[ 'max_atndz' ], $valid[ 'max_atndz' ] ); |
|
| 120 | - \EE_Error::add_error( $limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 119 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 120 | + \EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 121 | 121 | } else { |
| 122 | 122 | // all data appears to be valid |
| 123 | 123 | $tckts_slctd = false; |
| 124 | 124 | $success = true; |
| 125 | 125 | // load cart |
| 126 | - \EE_Registry::instance()->load_core( 'Cart' ); |
|
| 126 | + \EE_Registry::instance()->load_core('Cart'); |
|
| 127 | 127 | // cycle thru the number of data rows sent from the event listing |
| 128 | - for ( $x = 0; $x < $valid[ 'rows' ]; $x++ ) { |
|
| 128 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 129 | 129 | // does this row actually contain a ticket quantity? |
| 130 | - if ( isset( $valid[ 'qty' ][ $x ] ) && $valid[ 'qty' ][ $x ] > 0 ) { |
|
| 130 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 131 | 131 | // YES we have a ticket quantity |
| 132 | 132 | $tckts_slctd = true; |
| 133 | 133 | // d( $valid['ticket_obj'][$x] ); |
| 134 | - if ( $valid[ 'ticket_obj' ][ $x ] instanceof \EE_Ticket ) { |
|
| 134 | + if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
| 135 | 135 | // then add ticket to cart |
| 136 | - $ticket_added = $this->addTicketToCart( $valid[ 'ticket_obj' ][ $x ], |
|
| 137 | - $valid[ 'qty' ][ $x ] ); |
|
| 136 | + $ticket_added = $this->addTicketToCart($valid['ticket_obj'][$x], |
|
| 137 | + $valid['qty'][$x]); |
|
| 138 | 138 | $success = ! $ticket_added ? false : $success; |
| 139 | - if ( \EE_Error::has_error() ) { |
|
| 139 | + if (\EE_Error::has_error()) { |
|
| 140 | 140 | break; |
| 141 | 141 | } |
| 142 | 142 | } else { |
@@ -156,49 +156,49 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | //d( \EE_Registry::instance()->CART ); |
| 158 | 158 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
| 159 | - if ( $tckts_slctd ) { |
|
| 160 | - if ( $success ) { |
|
| 159 | + if ($tckts_slctd) { |
|
| 160 | + if ($success) { |
|
| 161 | 161 | do_action( |
| 162 | 162 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
| 163 | 163 | \EE_Registry::instance()->CART, |
| 164 | 164 | $this |
| 165 | 165 | ); |
| 166 | 166 | \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
| 167 | - \EE_Registry::instance()->CART->save_cart( false ); |
|
| 167 | + \EE_Registry::instance()->CART->save_cart(false); |
|
| 168 | 168 | //d( \EE_Registry::instance()->CART ); |
| 169 | 169 | // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
| 170 | 170 | // just return TRUE for registrations being made from admin |
| 171 | - if ( is_admin() ) { |
|
| 171 | + if (is_admin()) { |
|
| 172 | 172 | return true; |
| 173 | 173 | } |
| 174 | - wp_safe_redirect( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 175 | - \EE_Registry::instance()->CFG->core->reg_page_url() ) ); |
|
| 174 | + wp_safe_redirect(apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 175 | + \EE_Registry::instance()->CFG->core->reg_page_url())); |
|
| 176 | 176 | exit(); |
| 177 | 177 | } else { |
| 178 | - if ( ! \EE_Error::has_error() ) { |
|
| 178 | + if ( ! \EE_Error::has_error()) { |
|
| 179 | 179 | // nothing added to cart |
| 180 | - \EE_Error::add_attention( __( 'No tickets were added for the event', 'event_espresso' ), |
|
| 181 | - __FILE__, __FUNCTION__, __LINE__ ); |
|
| 180 | + \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
| 181 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } else { |
| 185 | 185 | // no ticket quantities were selected |
| 186 | - \EE_Error::add_error( __( 'You need to select a ticket quantity before you can proceed.', |
|
| 187 | - 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 186 | + \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
| 187 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
| 191 | 191 | // at this point, just return if registration is being made from admin |
| 192 | - if ( is_admin() ) { |
|
| 192 | + if (is_admin()) { |
|
| 193 | 193 | return false; |
| 194 | 194 | } |
| 195 | - if ( $valid[ 'return_url' ] ) { |
|
| 196 | - \EE_Error::get_notices( false, true ); |
|
| 197 | - wp_safe_redirect( $valid[ 'return_url' ] ); |
|
| 195 | + if ($valid['return_url']) { |
|
| 196 | + \EE_Error::get_notices(false, true); |
|
| 197 | + wp_safe_redirect($valid['return_url']); |
|
| 198 | 198 | exit(); |
| 199 | - } elseif ( isset( $event_to_add[ 'id' ] ) ) { |
|
| 200 | - \EE_Error::get_notices( false, true ); |
|
| 201 | - wp_safe_redirect( get_permalink( $event_to_add[ 'id' ] ) ); |
|
| 199 | + } elseif (isset($event_to_add['id'])) { |
|
| 200 | + \EE_Error::get_notices(false, true); |
|
| 201 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
| 202 | 202 | exit(); |
| 203 | 203 | } else { |
| 204 | 204 | echo \EE_Error::get_notices(); |
@@ -214,12 +214,12 @@ discard block |
||
| 214 | 214 | * @param int $id |
| 215 | 215 | * @return array|FALSE |
| 216 | 216 | */ |
| 217 | - private function validatePostData( $id = 0 ) |
|
| 217 | + private function validatePostData($id = 0) |
|
| 218 | 218 | { |
| 219 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 220 | - if ( ! $id ) { |
|
| 219 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 220 | + if ( ! $id) { |
|
| 221 | 221 | \EE_Error::add_error( |
| 222 | - __( 'The event id provided was not valid.', 'event_espresso' ), |
|
| 222 | + __('The event id provided was not valid.', 'event_espresso'), |
|
| 223 | 223 | __FILE__, |
| 224 | 224 | __FUNCTION__, |
| 225 | 225 | __LINE__ |
@@ -229,10 +229,10 @@ discard block |
||
| 229 | 229 | // start with an empty array() |
| 230 | 230 | $valid_data = array(); |
| 231 | 231 | // grab valid id |
| 232 | - $valid_data[ 'id' ] = $id; |
|
| 232 | + $valid_data['id'] = $id; |
|
| 233 | 233 | // grab and sanitize return-url |
| 234 | - $valid_data[ 'return_url' ] = esc_url_raw( |
|
| 235 | - \EE_Registry::instance()->REQ->get( 'tkt-slctr-return-url-' . $id ) |
|
| 234 | + $valid_data['return_url'] = esc_url_raw( |
|
| 235 | + \EE_Registry::instance()->REQ->get('tkt-slctr-return-url-'.$id) |
|
| 236 | 236 | ); |
| 237 | 237 | // array of other form names |
| 238 | 238 | $inputs_to_clean = array( |
@@ -244,72 +244,72 @@ discard block |
||
| 244 | 244 | 'return_url' => 'tkt-slctr-return-url-', |
| 245 | 245 | ); |
| 246 | 246 | // let's track the total number of tickets ordered.' |
| 247 | - $valid_data[ 'total_tickets' ] = 0; |
|
| 247 | + $valid_data['total_tickets'] = 0; |
|
| 248 | 248 | // cycle through $inputs_to_clean array |
| 249 | - foreach ( $inputs_to_clean as $what => $input_to_clean ) { |
|
| 249 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 250 | 250 | // check for POST data |
| 251 | - if ( \EE_Registry::instance()->REQ->is_set( $input_to_clean . $id ) ) { |
|
| 251 | + if (\EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
| 252 | 252 | // grab value |
| 253 | - $input_value = \EE_Registry::instance()->REQ->get( $input_to_clean . $id ); |
|
| 254 | - switch ( $what ) { |
|
| 253 | + $input_value = \EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
| 254 | + switch ($what) { |
|
| 255 | 255 | // integers |
| 256 | 256 | case 'event_id': |
| 257 | - $valid_data[ $what ] = absint( $input_value ); |
|
| 257 | + $valid_data[$what] = absint($input_value); |
|
| 258 | 258 | // get event via the event id we put in the form |
| 259 | - $valid_data[ 'event' ] = \EE_Registry::instance() |
|
| 260 | - ->load_model( 'Event' ) |
|
| 261 | - ->get_one_by_ID( $valid_data[ 'event_id' ] ); |
|
| 259 | + $valid_data['event'] = \EE_Registry::instance() |
|
| 260 | + ->load_model('Event') |
|
| 261 | + ->get_one_by_ID($valid_data['event_id']); |
|
| 262 | 262 | break; |
| 263 | 263 | case 'rows': |
| 264 | 264 | case 'max_atndz': |
| 265 | - $valid_data[ $what ] = absint( $input_value ); |
|
| 265 | + $valid_data[$what] = absint($input_value); |
|
| 266 | 266 | break; |
| 267 | 267 | // arrays of integers |
| 268 | 268 | case 'qty': |
| 269 | 269 | /** @var array $row_qty */ |
| 270 | 270 | $row_qty = $input_value; |
| 271 | 271 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
| 272 | - if ( ! is_array( $row_qty ) ) { |
|
| 272 | + if ( ! is_array($row_qty)) { |
|
| 273 | 273 | // get number of rows |
| 274 | - $rows = \EE_Registry::instance()->REQ->is_set( 'tkt-slctr-rows-' . $id ) |
|
| 275 | - ? absint( \EE_Registry::instance()->REQ->get( 'tkt-slctr-rows-' . $id ) ) |
|
| 274 | + $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) |
|
| 275 | + ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) |
|
| 276 | 276 | : 1; |
| 277 | 277 | // explode ints by the dash |
| 278 | - $row_qty = explode( '-', $row_qty ); |
|
| 279 | - $row = isset( $row_qty[ 0 ] ) ? ( absint( $row_qty[ 0 ] ) ) : 1; |
|
| 280 | - $qty = isset( $row_qty[ 1 ] ) ? absint( $row_qty[ 1 ] ) : 0; |
|
| 281 | - $row_qty = array( $row => $qty ); |
|
| 282 | - for ( $x = 1; $x <= $rows; $x++ ) { |
|
| 283 | - if ( ! isset( $row_qty[ $x ] ) ) { |
|
| 284 | - $row_qty[ $x ] = 0; |
|
| 278 | + $row_qty = explode('-', $row_qty); |
|
| 279 | + $row = isset($row_qty[0]) ? (absint($row_qty[0])) : 1; |
|
| 280 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 281 | + $row_qty = array($row => $qty); |
|
| 282 | + for ($x = 1; $x <= $rows; $x++) { |
|
| 283 | + if ( ! isset($row_qty[$x])) { |
|
| 284 | + $row_qty[$x] = 0; |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | - ksort( $row_qty ); |
|
| 288 | + ksort($row_qty); |
|
| 289 | 289 | // cycle thru values |
| 290 | - foreach ( $row_qty as $qty ) { |
|
| 291 | - $qty = absint( $qty ); |
|
| 290 | + foreach ($row_qty as $qty) { |
|
| 291 | + $qty = absint($qty); |
|
| 292 | 292 | // sanitize as integers |
| 293 | - $valid_data[ $what ][] = $qty; |
|
| 294 | - $valid_data[ 'total_tickets' ] += $qty; |
|
| 293 | + $valid_data[$what][] = $qty; |
|
| 294 | + $valid_data['total_tickets'] += $qty; |
|
| 295 | 295 | } |
| 296 | 296 | break; |
| 297 | 297 | // array of integers |
| 298 | 298 | case 'ticket_id': |
| 299 | 299 | $value_array = array(); |
| 300 | 300 | // cycle thru values |
| 301 | - foreach ( (array)$input_value as $key => $value ) { |
|
| 301 | + foreach ((array) $input_value as $key => $value) { |
|
| 302 | 302 | // allow only numbers, letters, spaces, commas and dashes |
| 303 | - $value_array[ $key ] = wp_strip_all_tags( $value ); |
|
| 303 | + $value_array[$key] = wp_strip_all_tags($value); |
|
| 304 | 304 | // get ticket via the ticket id we put in the form |
| 305 | - $ticket_obj = \EE_Registry::instance()->load_model( 'Ticket' )->get_one_by_ID( $value ); |
|
| 306 | - $valid_data[ 'ticket_obj' ][ $key ] = $ticket_obj; |
|
| 305 | + $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
| 306 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
| 307 | 307 | } |
| 308 | - $valid_data[ $what ] = $value_array; |
|
| 308 | + $valid_data[$what] = $value_array; |
|
| 309 | 309 | break; |
| 310 | 310 | case 'return_url' : |
| 311 | 311 | // grab and sanitize return-url |
| 312 | - $valid_data[ $what ] = esc_url_raw( $input_value ); |
|
| 312 | + $valid_data[$what] = esc_url_raw($input_value); |
|
| 313 | 313 | break; |
| 314 | 314 | } // end switch $what |
| 315 | 315 | } |
@@ -327,13 +327,13 @@ discard block |
||
| 327 | 327 | * @return TRUE on success, FALSE on fail |
| 328 | 328 | * @throws \EE_Error |
| 329 | 329 | */ |
| 330 | - private function addTicketToCart( \EE_Ticket $ticket = null, $qty = 1 ) |
|
| 330 | + private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
| 331 | 331 | { |
| 332 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 332 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 333 | 333 | // get the number of spaces left for this datetime ticket |
| 334 | - $available_spaces = $this->ticketDatetimeAvailability( $ticket ); |
|
| 334 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
| 335 | 335 | // compare available spaces against the number of tickets being purchased |
| 336 | - if ( $available_spaces >= $qty ) { |
|
| 336 | + if ($available_spaces >= $qty) { |
|
| 337 | 337 | // allow addons to prevent a ticket from being added to cart |
| 338 | 338 | if ( |
| 339 | 339 | ! apply_filters( |
@@ -347,17 +347,17 @@ discard block |
||
| 347 | 347 | return false; |
| 348 | 348 | } |
| 349 | 349 | // add event to cart |
| 350 | - if ( \EE_Registry::instance()->CART->add_ticket_to_cart( $ticket, $qty ) ) { |
|
| 351 | - $this->recalculateTicketDatetimeAvailability( $ticket, $qty ); |
|
| 350 | + if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
| 351 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 352 | 352 | return true; |
| 353 | 353 | } |
| 354 | 354 | return false; |
| 355 | 355 | } |
| 356 | 356 | // tickets can not be purchased but let's find the exact number left |
| 357 | 357 | // for the last ticket selected PRIOR to subtracting tickets |
| 358 | - $available_spaces = $this->ticketDatetimeAvailability( $ticket, true ); |
|
| 358 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
| 359 | 359 | // greedy greedy greedy eh? |
| 360 | - if ( $available_spaces > 0 ) { |
|
| 360 | + if ($available_spaces > 0) { |
|
| 361 | 361 | // add error messaging - we're using the _n function that will generate |
| 362 | 362 | // the appropriate singular or plural message based on the number of $available_spaces |
| 363 | 363 | \EE_Error::add_error( |
@@ -397,27 +397,27 @@ discard block |
||
| 397 | 397 | * @return int |
| 398 | 398 | * @throws \EE_Error |
| 399 | 399 | */ |
| 400 | - private function ticketDatetimeAvailability( \EE_Ticket $ticket, $get_original_ticket_spaces = false ) |
|
| 400 | + private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
| 401 | 401 | { |
| 402 | 402 | // if the $_available_spaces array has not been set up yet... |
| 403 | - if ( ! isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 404 | - $this->setInitialTicketDatetimeAvailability( $ticket ); |
|
| 403 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 404 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
| 405 | 405 | } |
| 406 | 406 | $available_spaces = $ticket->qty() - $ticket->sold(); |
| 407 | - if ( isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 407 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 408 | 408 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
| 409 | - foreach ( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
| 409 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 410 | 410 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
| 411 | - if ( $get_original_ticket_spaces ) { |
|
| 411 | + if ($get_original_ticket_spaces) { |
|
| 412 | 412 | // then grab the available spaces from the "tickets" array |
| 413 | 413 | // and compare with the above to get the lowest number |
| 414 | 414 | $available_spaces = min( |
| 415 | 415 | $available_spaces, |
| 416 | - self::$_available_spaces[ 'tickets' ][ $ticket->ID() ][ $DTD_ID ] |
|
| 416 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
| 417 | 417 | ); |
| 418 | 418 | } else { |
| 419 | 419 | // we want the updated ticket availability as stored in the "datetimes" array |
| 420 | - $available_spaces = min( $available_spaces, self::$_available_spaces[ 'datetimes' ][ $DTD_ID ] ); |
|
| 420 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | } |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * @return void |
| 432 | 432 | * @throws \EE_Error |
| 433 | 433 | */ |
| 434 | - private function setInitialTicketDatetimeAvailability( \EE_Ticket $ticket ) |
|
| 434 | + private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
| 435 | 435 | { |
| 436 | 436 | // first, get all of the datetimes that are available to this ticket |
| 437 | 437 | $datetimes = $ticket->get_many_related( |
@@ -440,31 +440,31 @@ discard block |
||
| 440 | 440 | array( |
| 441 | 441 | 'DTT_EVT_end' => array( |
| 442 | 442 | '>=', |
| 443 | - \EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ), |
|
| 443 | + \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 444 | 444 | ), |
| 445 | 445 | ), |
| 446 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ), |
|
| 446 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 447 | 447 | ) |
| 448 | 448 | ); |
| 449 | - if ( ! empty( $datetimes ) ) { |
|
| 449 | + if ( ! empty($datetimes)) { |
|
| 450 | 450 | // now loop thru all of the datetimes |
| 451 | - foreach ( $datetimes as $datetime ) { |
|
| 452 | - if ( $datetime instanceof \EE_Datetime ) { |
|
| 451 | + foreach ($datetimes as $datetime) { |
|
| 452 | + if ($datetime instanceof \EE_Datetime) { |
|
| 453 | 453 | // the number of spaces available for the datetime without considering individual ticket quantities |
| 454 | 454 | $spaces_remaining = $datetime->spaces_remaining(); |
| 455 | 455 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
| 456 | 456 | // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
| 457 | - self::$_available_spaces[ 'tickets' ][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
| 458 | - ( $ticket->qty() - $ticket->sold() ), |
|
| 457 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
| 458 | + ($ticket->qty() - $ticket->sold()), |
|
| 459 | 459 | $spaces_remaining |
| 460 | 460 | ); |
| 461 | 461 | // if the remaining spaces for this datetime is already set, |
| 462 | 462 | // then compare that against the datetime spaces remaining, and take the lowest number, |
| 463 | 463 | // else just take the datetime spaces remaining, and assign to the datetimes array |
| 464 | - self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ] = isset( |
|
| 465 | - self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ] |
|
| 464 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
| 465 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
| 466 | 466 | ) |
| 467 | - ? min( self::$_available_spaces[ 'datetimes' ][ $datetime->ID() ], $spaces_remaining ) |
|
| 467 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
| 468 | 468 | : $spaces_remaining; |
| 469 | 469 | } |
| 470 | 470 | } |
@@ -478,13 +478,13 @@ discard block |
||
| 478 | 478 | * @param int $qty |
| 479 | 479 | * @return void |
| 480 | 480 | */ |
| 481 | - private function recalculateTicketDatetimeAvailability( \EE_Ticket $ticket, $qty = 0 ) |
|
| 481 | + private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
| 482 | 482 | { |
| 483 | - if ( isset( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] ) ) { |
|
| 483 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 484 | 484 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
| 485 | - foreach ( self::$_available_spaces[ 'tickets' ][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
| 485 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 486 | 486 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
| 487 | - self::$_available_spaces[ 'datetimes' ][ $DTD_ID ] -= $qty; |
|
| 487 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | } |