@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\domain\services\capabilities\PublicCapabilities; |
| 2 | 2 | use EventEspresso\core\exceptions\InvalidEntityException; |
| 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 | |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @return EED_Single_Page_Checkout |
| 55 | 55 | */ |
| 56 | 56 | public static function instance() { |
| 57 | - add_filter( 'EED_Single_Page_Checkout__SPCO_active', '__return_true' ); |
|
| 58 | - return parent::get_instance( __CLASS__ ); |
|
| 57 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 58 | + return parent::get_instance(__CLASS__); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
@@ -100,22 +100,22 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public static function set_hooks_admin() { |
| 102 | 102 | EED_Single_Page_Checkout::set_definitions(); |
| 103 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 103 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 104 | 104 | // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
| 105 | 105 | ob_start(); |
| 106 | 106 | EED_Single_Page_Checkout::load_request_handler(); |
| 107 | 107 | EED_Single_Page_Checkout::load_reg_steps(); |
| 108 | 108 | } else { |
| 109 | 109 | // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
| 110 | - add_action( 'pre_get_posts', array( 'EED_Single_Page_Checkout', 'load_reg_steps' ), 1 ); |
|
| 110 | + add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
| 111 | 111 | } |
| 112 | 112 | // set ajax hooks |
| 113 | - add_action( 'wp_ajax_process_reg_step', array( 'EED_Single_Page_Checkout', 'process_reg_step' )); |
|
| 114 | - add_action( 'wp_ajax_nopriv_process_reg_step', array( 'EED_Single_Page_Checkout', 'process_reg_step' )); |
|
| 115 | - add_action( 'wp_ajax_display_spco_reg_step', array( 'EED_Single_Page_Checkout', 'display_reg_step' )); |
|
| 116 | - add_action( 'wp_ajax_nopriv_display_spco_reg_step', array( 'EED_Single_Page_Checkout', 'display_reg_step' )); |
|
| 117 | - add_action( 'wp_ajax_update_reg_step', array( 'EED_Single_Page_Checkout', 'update_reg_step' )); |
|
| 118 | - add_action( 'wp_ajax_nopriv_update_reg_step', array( 'EED_Single_Page_Checkout', 'update_reg_step' )); |
|
| 113 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 114 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 115 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 116 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 117 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 118 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param string $ajax_action |
| 127 | 127 | * @throws \EE_Error |
| 128 | 128 | */ |
| 129 | - public static function process_ajax_request( $ajax_action ) { |
|
| 130 | - EE_Registry::instance()->REQ->set( 'action', $ajax_action ); |
|
| 129 | + public static function process_ajax_request($ajax_action) { |
|
| 130 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 131 | 131 | EED_Single_Page_Checkout::instance()->_initialize(); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @throws \EE_Error |
| 140 | 140 | */ |
| 141 | 141 | public static function display_reg_step() { |
| 142 | - EED_Single_Page_Checkout::process_ajax_request( 'display_spco_reg_step' ); |
|
| 142 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @throws \EE_Error |
| 151 | 151 | */ |
| 152 | 152 | public static function process_reg_step() { |
| 153 | - EED_Single_Page_Checkout::process_ajax_request( 'process_reg_step' ); |
|
| 153 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @throws \EE_Error |
| 162 | 162 | */ |
| 163 | 163 | public static function update_reg_step() { |
| 164 | - EED_Single_Page_Checkout::process_ajax_request( 'update_reg_step' ); |
|
| 164 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @throws \EE_Error |
| 175 | 175 | */ |
| 176 | 176 | public static function update_checkout() { |
| 177 | - EED_Single_Page_Checkout::process_ajax_request( 'update_checkout' ); |
|
| 177 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public static function load_request_handler() { |
| 189 | 189 | // load core Request_Handler class |
| 190 | - if ( ! isset( EE_Registry::instance()->REQ )) { |
|
| 191 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
| 190 | + if ( ! isset(EE_Registry::instance()->REQ)) { |
|
| 191 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
@@ -202,14 +202,14 @@ discard block |
||
| 202 | 202 | * @throws \EE_Error |
| 203 | 203 | */ |
| 204 | 204 | public static function set_definitions() { |
| 205 | - define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS ); |
|
| 206 | - define( 'SPCO_CSS_URL', plugin_dir_url( __FILE__ ) . 'css' . DS ); |
|
| 207 | - define( 'SPCO_IMG_URL', plugin_dir_url( __FILE__ ) . 'img' . DS ); |
|
| 208 | - define( 'SPCO_JS_URL', plugin_dir_url( __FILE__ ) . 'js' . DS ); |
|
| 209 | - define( 'SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS ); |
|
| 210 | - define( 'SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS ); |
|
| 211 | - define( 'SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS ); |
|
| 212 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( SPCO_BASE_PATH, TRUE ); |
|
| 205 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS); |
|
| 206 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
| 207 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
| 208 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
| 209 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
| 210 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
| 211 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
| 212 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, TRUE); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | public static function load_reg_steps() { |
| 226 | 226 | static $reg_steps_loaded = FALSE; |
| 227 | - if ( $reg_steps_loaded ) { |
|
| 227 | + if ($reg_steps_loaded) { |
|
| 228 | 228 | return; |
| 229 | 229 | } |
| 230 | 230 | // filter list of reg_steps |
@@ -233,24 +233,24 @@ discard block |
||
| 233 | 233 | EED_Single_Page_Checkout::get_reg_steps() |
| 234 | 234 | ); |
| 235 | 235 | // sort by key (order) |
| 236 | - ksort( $reg_steps_to_load ); |
|
| 236 | + ksort($reg_steps_to_load); |
|
| 237 | 237 | // loop through folders |
| 238 | - foreach ( $reg_steps_to_load as $order => $reg_step ) { |
|
| 238 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 239 | 239 | // we need a |
| 240 | - if ( isset( $reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'] )) { |
|
| 240 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 241 | 241 | // copy over to the reg_steps_array |
| 242 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
| 242 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 243 | 243 | // register custom key route for each reg step |
| 244 | 244 | // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
| 245 | - EE_Config::register_route( $reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step' ); |
|
| 245 | + EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
| 246 | 246 | // add AJAX or other hooks |
| 247 | - if ( isset( $reg_step['has_hooks'] ) && $reg_step['has_hooks'] ) { |
|
| 247 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 248 | 248 | // setup autoloaders if necessary |
| 249 | - if ( ! class_exists( $reg_step['class_name'] )) { |
|
| 250 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( $reg_step['file_path'], TRUE ); |
|
| 249 | + if ( ! class_exists($reg_step['class_name'])) { |
|
| 250 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], TRUE); |
|
| 251 | 251 | } |
| 252 | - if ( is_callable( $reg_step['class_name'], 'set_hooks' )) { |
|
| 253 | - call_user_func( array( $reg_step['class_name'], 'set_hooks' )); |
|
| 252 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 253 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -269,28 +269,28 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | public static function get_reg_steps() { |
| 271 | 271 | $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
| 272 | - if ( empty( $reg_steps )) { |
|
| 272 | + if (empty($reg_steps)) { |
|
| 273 | 273 | $reg_steps = array( |
| 274 | 274 | 10 => array( |
| 275 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 275 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
| 276 | 276 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
| 277 | 277 | 'slug' => 'attendee_information', |
| 278 | 278 | 'has_hooks' => FALSE |
| 279 | 279 | ), |
| 280 | 280 | 20 => array( |
| 281 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 281 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
| 282 | 282 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
| 283 | 283 | 'slug' => 'registration_confirmation', |
| 284 | 284 | 'has_hooks' => FALSE |
| 285 | 285 | ), |
| 286 | 286 | 30 => array( |
| 287 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 287 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
| 288 | 288 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
| 289 | 289 | 'slug' => 'payment_options', |
| 290 | 290 | 'has_hooks' => TRUE |
| 291 | 291 | ), |
| 292 | 292 | 999 => array( |
| 293 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 293 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
| 294 | 294 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
| 295 | 295 | 'slug' => 'finalize_registration', |
| 296 | 296 | 'has_hooks' => FALSE |
@@ -311,9 +311,9 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public static function registration_checkout_for_admin() { |
| 313 | 313 | EED_Single_Page_Checkout::load_reg_steps(); |
| 314 | - EE_Registry::instance()->REQ->set( 'step', 'attendee_information' ); |
|
| 315 | - EE_Registry::instance()->REQ->set( 'action', 'display_spco_reg_step' ); |
|
| 316 | - EE_Registry::instance()->REQ->set( 'process_form_submission', false ); |
|
| 314 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 315 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 316 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 317 | 317 | EED_Single_Page_Checkout::instance()->_initialize(); |
| 318 | 318 | EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
| 319 | 319 | return EE_Registry::instance()->REQ->get_output(); |
@@ -330,15 +330,15 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | public static function process_registration_from_admin() { |
| 332 | 332 | EED_Single_Page_Checkout::load_reg_steps(); |
| 333 | - EE_Registry::instance()->REQ->set( 'step', 'attendee_information' ); |
|
| 334 | - EE_Registry::instance()->REQ->set( 'action', 'process_reg_step' ); |
|
| 335 | - EE_Registry::instance()->REQ->set( 'process_form_submission', true ); |
|
| 333 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 334 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 335 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 336 | 336 | EED_Single_Page_Checkout::instance()->_initialize(); |
| 337 | - if ( EED_Single_Page_Checkout::instance()->checkout->current_step->completed() ) { |
|
| 338 | - $final_reg_step = end( EED_Single_Page_Checkout::instance()->checkout->reg_steps ); |
|
| 339 | - if ( $final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) { |
|
| 340 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated( $final_reg_step ); |
|
| 341 | - if ( $final_reg_step->process_reg_step() ) { |
|
| 337 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 338 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 339 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 340 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 341 | + if ($final_reg_step->process_reg_step()) { |
|
| 342 | 342 | $final_reg_step->set_completed(); |
| 343 | 343 | EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
| 344 | 344 | return EED_Single_Page_Checkout::instance()->checkout->transaction; |
@@ -358,11 +358,11 @@ discard block |
||
| 358 | 358 | * @return void |
| 359 | 359 | * @throws \EE_Error |
| 360 | 360 | */ |
| 361 | - public function run( $WP_Query ) { |
|
| 361 | + public function run($WP_Query) { |
|
| 362 | 362 | if ( |
| 363 | 363 | $WP_Query instanceof WP_Query |
| 364 | 364 | && $WP_Query->is_main_query() |
| 365 | - && apply_filters( 'FHEE__EED_Single_Page_Checkout__run', true ) |
|
| 365 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 366 | 366 | && $this->_is_reg_checkout() |
| 367 | 367 | ) { |
| 368 | 368 | $this->_initialize(); |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
| 382 | 382 | // get request URI for current request, but without the scheme or host |
| 383 | 383 | $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
| 384 | - $current_request_uri = html_entity_decode( $current_request_uri ); |
|
| 384 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
| 385 | 385 | // get array of query args from the current request URI |
| 386 | 386 | $query_args = \EEH_URL::get_query_string($current_request_uri); |
| 387 | 387 | // grab page id if it is set |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | // now strip all query args from current request URI |
| 392 | 392 | $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
| 393 | 393 | // and re-add the page id if it was set |
| 394 | - if ($page_id){ |
|
| 394 | + if ($page_id) { |
|
| 395 | 395 | $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
| 396 | 396 | } |
| 397 | 397 | // remove slashes and ? |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | * @return void |
| 411 | 411 | * @throws \EE_Error |
| 412 | 412 | */ |
| 413 | - public static function init( $WP_Query ) { |
|
| 414 | - EED_Single_Page_Checkout::instance()->run( $WP_Query ); |
|
| 413 | + public static function init($WP_Query) { |
|
| 414 | + EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -425,35 +425,35 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | private function _initialize() { |
| 427 | 427 | // ensure SPCO doesn't run twice |
| 428 | - if ( EED_Single_Page_Checkout::$_initialized ) { |
|
| 428 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
| 429 | 429 | return; |
| 430 | 430 | } |
| 431 | 431 | try { |
| 432 | 432 | // setup the EE_Checkout object |
| 433 | 433 | $this->checkout = $this->_initialize_checkout(); |
| 434 | 434 | // filter checkout |
| 435 | - $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout ); |
|
| 435 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 436 | 436 | // get the $_GET |
| 437 | 437 | $this->_get_request_vars(); |
| 438 | 438 | $this->_block_bots(); |
| 439 | 439 | // filter continue_reg |
| 440 | - $this->checkout->continue_reg = apply_filters( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout ); |
|
| 440 | + $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout); |
|
| 441 | 441 | // load the reg steps array |
| 442 | - if ( ! $this->_load_and_instantiate_reg_steps() ) { |
|
| 442 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 443 | 443 | EED_Single_Page_Checkout::$_initialized = true; |
| 444 | 444 | return; |
| 445 | 445 | } |
| 446 | 446 | // set the current step |
| 447 | - $this->checkout->set_current_step( $this->checkout->step ); |
|
| 447 | + $this->checkout->set_current_step($this->checkout->step); |
|
| 448 | 448 | // and the next step |
| 449 | 449 | $this->checkout->set_next_step(); |
| 450 | 450 | // was there already a valid transaction in the checkout from the session ? |
| 451 | - if ( ! $this->checkout->transaction instanceof EE_Transaction ) { |
|
| 451 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 452 | 452 | // get transaction from db or session |
| 453 | 453 | $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
| 454 | 454 | ? $this->_get_transaction_and_cart_for_previous_visit() |
| 455 | 455 | : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
| 456 | - if ( ! $this->checkout->transaction instanceof EE_Transaction ) { |
|
| 456 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 457 | 457 | // add some style and make it dance |
| 458 | 458 | $this->checkout->transaction = EE_Transaction::new_instance(); |
| 459 | 459 | $this->add_styles_and_scripts(); |
@@ -461,10 +461,10 @@ discard block |
||
| 461 | 461 | return; |
| 462 | 462 | } |
| 463 | 463 | // and the registrations for the transaction |
| 464 | - $this->_get_registrations( $this->checkout->transaction ); |
|
| 464 | + $this->_get_registrations($this->checkout->transaction); |
|
| 465 | 465 | } |
| 466 | 466 | // verify that everything has been setup correctly |
| 467 | - if ( ! $this->_final_verifications() ) { |
|
| 467 | + if ( ! $this->_final_verifications()) { |
|
| 468 | 468 | EED_Single_Page_Checkout::$_initialized = true; |
| 469 | 469 | return; |
| 470 | 470 | } |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | // set no cache headers and constants |
| 490 | 490 | EE_System::do_not_cache(); |
| 491 | 491 | // add anchor |
| 492 | - add_action( 'loop_start', array( $this, 'set_checkout_anchor' ), 1 ); |
|
| 493 | - } catch ( Exception $e ) { |
|
| 494 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 492 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 493 | + } catch (Exception $e) { |
|
| 494 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | |
@@ -509,20 +509,20 @@ discard block |
||
| 509 | 509 | // look in session for existing checkout |
| 510 | 510 | $checkout = EE_Registry::instance()->SSN->checkout(); |
| 511 | 511 | // verify |
| 512 | - if ( ! $checkout instanceof EE_Checkout ) { |
|
| 512 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 513 | 513 | // instantiate EE_Checkout object for handling the properties of the current checkout process |
| 514 | - $checkout = EE_Registry::instance()->load_file( SPCO_INC_PATH, 'EE_Checkout', 'class', array(), FALSE ); |
|
| 514 | + $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), FALSE); |
|
| 515 | 515 | } else { |
| 516 | - if ( $checkout->current_step->is_final_step() && $checkout->exit_spco() === true ) { |
|
| 516 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 517 | 517 | $this->unlock_transaction(); |
| 518 | - wp_safe_redirect( $checkout->redirect_url ); |
|
| 518 | + wp_safe_redirect($checkout->redirect_url); |
|
| 519 | 519 | exit(); |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | - $checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout ); |
|
| 522 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 523 | 523 | // verify again |
| 524 | - if ( ! $checkout instanceof EE_Checkout ) { |
|
| 525 | - throw new EE_Error( __( 'The EE_Checkout class could not be loaded.', 'event_espresso' ) ); |
|
| 524 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 525 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 526 | 526 | } |
| 527 | 527 | // reset anything that needs a clean slate for each request |
| 528 | 528 | $checkout->reset_for_current_request(); |
@@ -542,26 +542,26 @@ discard block |
||
| 542 | 542 | // load classes |
| 543 | 543 | EED_Single_Page_Checkout::load_request_handler(); |
| 544 | 544 | //make sure this request is marked as belonging to EE |
| 545 | - EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
|
| 545 | + EE_Registry::instance()->REQ->set_espresso_page(TRUE); |
|
| 546 | 546 | // which step is being requested ? |
| 547 | - $this->checkout->step = EE_Registry::instance()->REQ->get( 'step', $this->_get_first_step() ); |
|
| 547 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 548 | 548 | // which step is being edited ? |
| 549 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get( 'edit_step', '' ); |
|
| 549 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 550 | 550 | // and what we're doing on the current step |
| 551 | - $this->checkout->action = EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ); |
|
| 551 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 552 | 552 | // timestamp |
| 553 | - $this->checkout->uts = EE_Registry::instance()->REQ->get( 'uts', 0 ); |
|
| 553 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 554 | 554 | // returning to edit ? |
| 555 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get( 'e_reg_url_link', '' ); |
|
| 555 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 556 | 556 | // or some other kind of revisit ? |
| 557 | - $this->checkout->revisit = EE_Registry::instance()->REQ->get( 'revisit', FALSE ); |
|
| 557 | + $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', FALSE); |
|
| 558 | 558 | // and whether or not to generate a reg form for this request |
| 559 | - $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get( 'generate_reg_form', TRUE ); // TRUE FALSE |
|
| 559 | + $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', TRUE); // TRUE FALSE |
|
| 560 | 560 | // and whether or not to process a reg form submission for this request |
| 561 | - $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get( 'process_form_submission', FALSE ); // TRUE FALSE |
|
| 561 | + $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', FALSE); // TRUE FALSE |
|
| 562 | 562 | $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step' |
| 563 | 563 | ? $this->checkout->process_form_submission |
| 564 | - : FALSE; // TRUE FALSE |
|
| 564 | + : FALSE; // TRUE FALSE |
|
| 565 | 565 | // $this->_display_request_vars(); |
| 566 | 566 | } |
| 567 | 567 | |
@@ -574,17 +574,17 @@ discard block |
||
| 574 | 574 | * @return void |
| 575 | 575 | */ |
| 576 | 576 | protected function _display_request_vars() { |
| 577 | - if ( ! WP_DEBUG ) { |
|
| 577 | + if ( ! WP_DEBUG) { |
|
| 578 | 578 | return; |
| 579 | 579 | } |
| 580 | - EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 581 | - EEH_Debug_Tools::printr( $this->checkout->step, '$this->checkout->step', __FILE__, __LINE__ ); |
|
| 582 | - EEH_Debug_Tools::printr( $this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__ ); |
|
| 583 | - EEH_Debug_Tools::printr( $this->checkout->action, '$this->checkout->action', __FILE__, __LINE__ ); |
|
| 584 | - EEH_Debug_Tools::printr( $this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__ ); |
|
| 585 | - EEH_Debug_Tools::printr( $this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__ ); |
|
| 586 | - EEH_Debug_Tools::printr( $this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__ ); |
|
| 587 | - EEH_Debug_Tools::printr( $this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__ ); |
|
| 580 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 581 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 582 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 583 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 584 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 585 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 586 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 587 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | */ |
| 600 | 600 | private function _block_bots() { |
| 601 | 601 | $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
| 602 | - if ( $invalid_checkout_access->checkoutAccessIsInvalid( $this->checkout ) ) { |
|
| 602 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 603 | 603 | $this->_handle_html_redirects(); |
| 604 | 604 | } |
| 605 | 605 | } |
@@ -615,8 +615,8 @@ discard block |
||
| 615 | 615 | * @return array |
| 616 | 616 | */ |
| 617 | 617 | private function _get_first_step() { |
| 618 | - $first_step = reset( EED_Single_Page_Checkout::$_reg_steps_array ); |
|
| 619 | - return isset( $first_step['slug'] ) ? $first_step['slug'] : 'attendee_information'; |
|
| 618 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 619 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | |
@@ -632,27 +632,27 @@ discard block |
||
| 632 | 632 | private function _load_and_instantiate_reg_steps() { |
| 633 | 633 | // have reg_steps already been instantiated ? |
| 634 | 634 | if ( |
| 635 | - empty( $this->checkout->reg_steps ) || |
|
| 636 | - apply_filters( 'FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout ) |
|
| 635 | + empty($this->checkout->reg_steps) || |
|
| 636 | + apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 637 | 637 | ) { |
| 638 | 638 | // if not, then loop through raw reg steps array |
| 639 | - foreach ( EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step ) { |
|
| 640 | - if ( ! $this->_load_and_instantiate_reg_step( $reg_step, $order )) { |
|
| 639 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 640 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 641 | 641 | return false; |
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | EE_Registry::instance()->CFG->registration->skip_reg_confirmation = TRUE; |
| 645 | 645 | EE_Registry::instance()->CFG->registration->reg_confirmation_last = TRUE; |
| 646 | 646 | // skip the registration_confirmation page ? |
| 647 | - if ( EE_Registry::instance()->CFG->registration->skip_reg_confirmation ) { |
|
| 647 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 648 | 648 | // just remove it from the reg steps array |
| 649 | - $this->checkout->remove_reg_step( 'registration_confirmation', false ); |
|
| 649 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 650 | 650 | } else if ( |
| 651 | - isset( $this->checkout->reg_steps['registration_confirmation'] ) |
|
| 651 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 652 | 652 | && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
| 653 | 653 | ) { |
| 654 | 654 | // set the order to something big like 100 |
| 655 | - $this->checkout->set_reg_step_order( 'registration_confirmation', 100 ); |
|
| 655 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 656 | 656 | } |
| 657 | 657 | // filter the array for good luck |
| 658 | 658 | $this->checkout->reg_steps = apply_filters( |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | // finally re-sort based on the reg step class order properties |
| 663 | 663 | $this->checkout->sort_reg_steps(); |
| 664 | 664 | } else { |
| 665 | - foreach ( $this->checkout->reg_steps as $reg_step ) { |
|
| 665 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 666 | 666 | // set all current step stati to FALSE |
| 667 | - $reg_step->set_is_current_step( FALSE ); |
|
| 667 | + $reg_step->set_is_current_step(FALSE); |
|
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | - if ( empty( $this->checkout->reg_steps )) { |
|
| 671 | - EE_Error::add_error( __( 'No Reg Steps were loaded..', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 670 | + if (empty($this->checkout->reg_steps)) { |
|
| 671 | + EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 672 | 672 | return false; |
| 673 | 673 | } |
| 674 | 674 | // make reg step details available to JS |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | * @param int $order |
| 687 | 687 | * @return bool |
| 688 | 688 | */ |
| 689 | - private function _load_and_instantiate_reg_step( $reg_step = array(), $order = 0 ) { |
|
| 689 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) { |
|
| 690 | 690 | |
| 691 | 691 | // we need a file_path, class_name, and slug to add a reg step |
| 692 | - if ( isset( $reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'] )) { |
|
| 692 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 693 | 693 | // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
| 694 | 694 | if ( |
| 695 | 695 | $this->checkout->reg_url_link |
@@ -707,26 +707,26 @@ discard block |
||
| 707 | 707 | FALSE |
| 708 | 708 | ); |
| 709 | 709 | // did we gets the goods ? |
| 710 | - if ( $reg_step_obj instanceof EE_SPCO_Reg_Step ) { |
|
| 710 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 711 | 711 | // set reg step order based on config |
| 712 | - $reg_step_obj->set_order( $order ); |
|
| 712 | + $reg_step_obj->set_order($order); |
|
| 713 | 713 | // add instantiated reg step object to the master reg steps array |
| 714 | - $this->checkout->add_reg_step( $reg_step_obj ); |
|
| 714 | + $this->checkout->add_reg_step($reg_step_obj); |
|
| 715 | 715 | } else { |
| 716 | 716 | EE_Error::add_error( |
| 717 | - __( 'The current step could not be set.', 'event_espresso' ), |
|
| 717 | + __('The current step could not be set.', 'event_espresso'), |
|
| 718 | 718 | __FILE__, __FUNCTION__, __LINE__ |
| 719 | 719 | ); |
| 720 | 720 | return false; |
| 721 | 721 | } |
| 722 | 722 | } else { |
| 723 | - if ( WP_DEBUG ) { |
|
| 723 | + if (WP_DEBUG) { |
|
| 724 | 724 | EE_Error::add_error( |
| 725 | 725 | sprintf( |
| 726 | - __( 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso' ), |
|
| 727 | - isset( $reg_step['file_path'] ) ? $reg_step['file_path'] : '', |
|
| 728 | - isset( $reg_step['class_name'] ) ? $reg_step['class_name'] : '', |
|
| 729 | - isset( $reg_step['slug'] ) ? $reg_step['slug'] : '', |
|
| 726 | + __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
| 727 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 728 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 729 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 730 | 730 | '<ul>', |
| 731 | 731 | '<li>', |
| 732 | 732 | '</li>', |
@@ -750,16 +750,16 @@ discard block |
||
| 750 | 750 | */ |
| 751 | 751 | private function _get_transaction_and_cart_for_previous_visit() { |
| 752 | 752 | /** @var $TXN_model EEM_Transaction */ |
| 753 | - $TXN_model = EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 753 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 754 | 754 | // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
| 755 | - $transaction = $TXN_model->get_transaction_from_reg_url_link( $this->checkout->reg_url_link ); |
|
| 755 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 756 | 756 | // verify transaction |
| 757 | - if ( $transaction instanceof EE_Transaction ) { |
|
| 757 | + if ($transaction instanceof EE_Transaction) { |
|
| 758 | 758 | // and get the cart that was used for that transaction |
| 759 | - $this->checkout->cart = $this->_get_cart_for_transaction( $transaction ); |
|
| 759 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 760 | 760 | return $transaction; |
| 761 | 761 | } else { |
| 762 | - EE_Error::add_error( __( 'Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
| 762 | + EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 763 | 763 | return NULL; |
| 764 | 764 | } |
| 765 | 765 | } |
@@ -773,8 +773,8 @@ discard block |
||
| 773 | 773 | * @param EE_Transaction $transaction |
| 774 | 774 | * @return EE_Cart |
| 775 | 775 | */ |
| 776 | - private function _get_cart_for_transaction( $transaction ) { |
|
| 777 | - return $this->checkout->get_cart_for_transaction( $transaction ); |
|
| 776 | + private function _get_cart_for_transaction($transaction) { |
|
| 777 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | |
@@ -786,8 +786,8 @@ discard block |
||
| 786 | 786 | * @param EE_Transaction $transaction |
| 787 | 787 | * @return EE_Cart |
| 788 | 788 | */ |
| 789 | - public function get_cart_for_transaction( EE_Transaction $transaction ) { |
|
| 790 | - return $this->checkout->get_cart_for_transaction( $transaction ); |
|
| 789 | + public function get_cart_for_transaction(EE_Transaction $transaction) { |
|
| 790 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | |
@@ -803,17 +803,17 @@ discard block |
||
| 803 | 803 | private function _get_cart_for_current_session_and_setup_new_transaction() { |
| 804 | 804 | // if there's no transaction, then this is the FIRST visit to SPCO |
| 805 | 805 | // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
| 806 | - $this->checkout->cart = $this->_get_cart_for_transaction( NULL ); |
|
| 806 | + $this->checkout->cart = $this->_get_cart_for_transaction(NULL); |
|
| 807 | 807 | // and then create a new transaction |
| 808 | 808 | $transaction = $this->_initialize_transaction(); |
| 809 | 809 | // verify transaction |
| 810 | - if ( $transaction instanceof EE_Transaction ) { |
|
| 810 | + if ($transaction instanceof EE_Transaction) { |
|
| 811 | 811 | // save it so that we have an ID for other objects to use |
| 812 | 812 | $transaction->save(); |
| 813 | 813 | // and save TXN data to the cart |
| 814 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( $transaction->ID() ); |
|
| 814 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 815 | 815 | } else { |
| 816 | - EE_Error::add_error( __( 'A Valid Transaction could not be initialized.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 816 | + EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 817 | 817 | } |
| 818 | 818 | return $transaction; |
| 819 | 819 | } |
@@ -841,8 +841,8 @@ discard block |
||
| 841 | 841 | 'STS_ID' => EEM_Transaction::failed_status_code, |
| 842 | 842 | ) |
| 843 | 843 | ); |
| 844 | - } catch( Exception $e ) { |
|
| 845 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 844 | + } catch (Exception $e) { |
|
| 845 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 846 | 846 | } |
| 847 | 847 | return NULL; |
| 848 | 848 | } |
@@ -858,38 +858,38 @@ discard block |
||
| 858 | 858 | * @throws \EventEspresso\core\exceptions\InvalidEntityException |
| 859 | 859 | * @throws \EE_Error |
| 860 | 860 | */ |
| 861 | - private function _get_registrations( EE_Transaction $transaction ) { |
|
| 861 | + private function _get_registrations(EE_Transaction $transaction) { |
|
| 862 | 862 | // first step: grab the registrants { : o |
| 863 | - $registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, true ); |
|
| 863 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
| 864 | 864 | // verify registrations have been set |
| 865 | - if ( empty( $registrations )) { |
|
| 865 | + if (empty($registrations)) { |
|
| 866 | 866 | // if no cached registrations, then check the db |
| 867 | - $registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, false ); |
|
| 867 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 868 | 868 | // still nothing ? well as long as this isn't a revisit |
| 869 | - if ( empty( $registrations ) && ! $this->checkout->revisit ) { |
|
| 869 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 870 | 870 | // generate new registrations from scratch |
| 871 | - $registrations = $this->_initialize_registrations( $transaction ); |
|
| 871 | + $registrations = $this->_initialize_registrations($transaction); |
|
| 872 | 872 | } |
| 873 | 873 | } |
| 874 | 874 | // sort by their original registration order |
| 875 | - usort( $registrations, array( 'EED_Single_Page_Checkout', 'sort_registrations_by_REG_count' )); |
|
| 875 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 876 | 876 | // then loop thru the array |
| 877 | - foreach ( $registrations as $registration ) { |
|
| 877 | + foreach ($registrations as $registration) { |
|
| 878 | 878 | // verify each registration |
| 879 | - if ( $registration instanceof EE_Registration ) { |
|
| 879 | + if ($registration instanceof EE_Registration) { |
|
| 880 | 880 | // we display all attendee info for the primary registrant |
| 881 | - if ( $this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 881 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 882 | 882 | && $registration->is_primary_registrant() |
| 883 | 883 | ) { |
| 884 | 884 | $this->checkout->primary_revisit = true; |
| 885 | 885 | break; |
| 886 | - } else if ( $this->checkout->revisit |
|
| 886 | + } else if ($this->checkout->revisit |
|
| 887 | 887 | && $this->checkout->reg_url_link !== $registration->reg_url_link() |
| 888 | 888 | ) { |
| 889 | 889 | // but hide info if it doesn't belong to you |
| 890 | - $transaction->clear_cache( 'Registration', $registration->ID() ); |
|
| 890 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
| 891 | 891 | } |
| 892 | - $this->checkout->set_reg_status_updated( $registration->ID(), false ); |
|
| 892 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 893 | 893 | } |
| 894 | 894 | } |
| 895 | 895 | } |
@@ -905,17 +905,17 @@ discard block |
||
| 905 | 905 | * @throws \EventEspresso\core\exceptions\InvalidEntityException |
| 906 | 906 | * @throws \EE_Error |
| 907 | 907 | */ |
| 908 | - private function _initialize_registrations( EE_Transaction $transaction ) { |
|
| 908 | + private function _initialize_registrations(EE_Transaction $transaction) { |
|
| 909 | 909 | $att_nmbr = 0; |
| 910 | 910 | $registrations = array(); |
| 911 | - if ( $transaction instanceof EE_Transaction ) { |
|
| 911 | + if ($transaction instanceof EE_Transaction) { |
|
| 912 | 912 | /** @type EE_Registration_Processor $registration_processor */ |
| 913 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
| 913 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 914 | 914 | $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
| 915 | 915 | // now let's add the cart items to the $transaction |
| 916 | - foreach ( $this->checkout->cart->get_tickets() as $line_item ) { |
|
| 916 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 917 | 917 | //do the following for each ticket of this type they selected |
| 918 | - for ( $x = 1; $x <= $line_item->quantity(); $x++ ) { |
|
| 918 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 919 | 919 | $att_nmbr++; |
| 920 | 920 | /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
| 921 | 921 | $CreateRegistrationCommand = EE_Registry::instance() |
@@ -931,17 +931,17 @@ discard block |
||
| 931 | 931 | // override capabilities for frontend registrations |
| 932 | 932 | if ( ! is_admin()) { |
| 933 | 933 | $CreateRegistrationCommand->setCapCheck( |
| 934 | - new PublicCapabilities( '', 'create_new_registration' ) |
|
| 934 | + new PublicCapabilities('', 'create_new_registration') |
|
| 935 | 935 | ); |
| 936 | 936 | } |
| 937 | - $registration = EE_Registry::instance()->BUS->execute( $CreateRegistrationCommand ); |
|
| 938 | - if ( ! $registration instanceof EE_Registration ) { |
|
| 939 | - throw new InvalidEntityException( $registration, 'EE_Registration' ); |
|
| 937 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 938 | + if ( ! $registration instanceof EE_Registration) { |
|
| 939 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 940 | 940 | } |
| 941 | - $registrations[ $registration->ID() ] = $registration; |
|
| 941 | + $registrations[$registration->ID()] = $registration; |
|
| 942 | 942 | } |
| 943 | 943 | } |
| 944 | - $registration_processor->fix_reg_final_price_rounding_issue( $transaction ); |
|
| 944 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 945 | 945 | } |
| 946 | 946 | return $registrations; |
| 947 | 947 | } |
@@ -956,12 +956,12 @@ discard block |
||
| 956 | 956 | * @param EE_Registration $reg_B |
| 957 | 957 | * @return int |
| 958 | 958 | */ |
| 959 | - public static function sort_registrations_by_REG_count( EE_Registration $reg_A, EE_Registration $reg_B ) { |
|
| 959 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) { |
|
| 960 | 960 | // this shouldn't ever happen within the same TXN, but oh well |
| 961 | - if ( $reg_A->count() === $reg_B->count() ) { |
|
| 961 | + if ($reg_A->count() === $reg_B->count()) { |
|
| 962 | 962 | return 0; |
| 963 | 963 | } |
| 964 | - return ( $reg_A->count() > $reg_B->count() ) ? 1 : -1; |
|
| 964 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
@@ -976,21 +976,21 @@ discard block |
||
| 976 | 976 | */ |
| 977 | 977 | private function _final_verifications() { |
| 978 | 978 | // filter checkout |
| 979 | - $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout ); |
|
| 979 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
| 980 | 980 | //verify that current step is still set correctly |
| 981 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step ) { |
|
| 982 | - EE_Error::add_error( __( 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 981 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 982 | + EE_Error::add_error(__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 983 | 983 | return false; |
| 984 | 984 | } |
| 985 | 985 | // if returning to SPCO, then verify that primary registrant is set |
| 986 | - if ( ! empty( $this->checkout->reg_url_link )) { |
|
| 986 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
| 987 | 987 | $valid_registrant = $this->checkout->transaction->primary_registration(); |
| 988 | - if ( ! $valid_registrant instanceof EE_Registration ) { |
|
| 989 | - EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 988 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 989 | + EE_Error::add_error(__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 990 | 990 | return false; |
| 991 | 991 | } |
| 992 | 992 | $valid_registrant = null; |
| 993 | - foreach ( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) as $registration ) { |
|
| 993 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
| 994 | 994 | if ( |
| 995 | 995 | $registration instanceof EE_Registration |
| 996 | 996 | && $registration->reg_url_link() === $this->checkout->reg_url_link |
@@ -998,9 +998,9 @@ discard block |
||
| 998 | 998 | $valid_registrant = $registration; |
| 999 | 999 | } |
| 1000 | 1000 | } |
| 1001 | - if ( ! $valid_registrant instanceof EE_Registration ) { |
|
| 1001 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1002 | 1002 | // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
| 1003 | - if ( EED_Single_Page_Checkout::$_checkout_verified ) { |
|
| 1003 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1004 | 1004 | // clear the session, mark the checkout as unverified, and try again |
| 1005 | 1005 | EE_Registry::instance()->SSN->clear_session(); |
| 1006 | 1006 | EED_Single_Page_Checkout::$_initialized = false; |
@@ -1009,13 +1009,13 @@ discard block |
||
| 1009 | 1009 | EE_Error::reset_notices(); |
| 1010 | 1010 | return false; |
| 1011 | 1011 | } |
| 1012 | - EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1012 | + EE_Error::add_error(__('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1013 | 1013 | return false; |
| 1014 | 1014 | } |
| 1015 | 1015 | } |
| 1016 | 1016 | // now that things have been kinda sufficiently verified, |
| 1017 | 1017 | // let's add the checkout to the session so that's available other systems |
| 1018 | - EE_Registry::instance()->SSN->set_checkout( $this->checkout ); |
|
| 1018 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1019 | 1019 | return true; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
@@ -1030,15 +1030,15 @@ discard block |
||
| 1030 | 1030 | * @param bool $reinitializing |
| 1031 | 1031 | * @throws \EE_Error |
| 1032 | 1032 | */ |
| 1033 | - private function _initialize_reg_steps( $reinitializing = false ) { |
|
| 1034 | - $this->checkout->set_reg_step_initiated( $this->checkout->current_step ); |
|
| 1033 | + private function _initialize_reg_steps($reinitializing = false) { |
|
| 1034 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1035 | 1035 | // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
| 1036 | - foreach ( $this->checkout->reg_steps as $reg_step ) { |
|
| 1037 | - if ( ! $reg_step->initialize_reg_step() ) { |
|
| 1036 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1037 | + if ( ! $reg_step->initialize_reg_step()) { |
|
| 1038 | 1038 | // if not initialized then maybe this step is being removed... |
| 1039 | - if ( ! $reinitializing && $reg_step->is_current_step() ) { |
|
| 1039 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1040 | 1040 | // if it was the current step, then we need to start over here |
| 1041 | - $this->_initialize_reg_steps( true ); |
|
| 1041 | + $this->_initialize_reg_steps(true); |
|
| 1042 | 1042 | return; |
| 1043 | 1043 | } |
| 1044 | 1044 | continue; |
@@ -1047,13 +1047,13 @@ discard block |
||
| 1047 | 1047 | $reg_step->enqueue_styles_and_scripts(); |
| 1048 | 1048 | // i18n |
| 1049 | 1049 | $reg_step->translate_js_strings(); |
| 1050 | - if ( $reg_step->is_current_step() ) { |
|
| 1050 | + if ($reg_step->is_current_step()) { |
|
| 1051 | 1051 | // the text that appears on the reg step form submit button |
| 1052 | 1052 | $reg_step->set_submit_button_text(); |
| 1053 | 1053 | } |
| 1054 | 1054 | } |
| 1055 | 1055 | // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
| 1056 | - do_action( "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step ); |
|
| 1056 | + do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | |
@@ -1066,43 +1066,43 @@ discard block |
||
| 1066 | 1066 | */ |
| 1067 | 1067 | private function _check_form_submission() { |
| 1068 | 1068 | //does this request require the reg form to be generated ? |
| 1069 | - if ( $this->checkout->generate_reg_form ) { |
|
| 1069 | + if ($this->checkout->generate_reg_form) { |
|
| 1070 | 1070 | // ever heard that song by Blue Rodeo ? |
| 1071 | 1071 | try { |
| 1072 | 1072 | $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
| 1073 | 1073 | // if not displaying a form, then check for form submission |
| 1074 | - if ( $this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted() ) { |
|
| 1074 | + if ($this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted()) { |
|
| 1075 | 1075 | // clear out any old data in case this step is being run again |
| 1076 | - $this->checkout->current_step->set_valid_data( array() ); |
|
| 1076 | + $this->checkout->current_step->set_valid_data(array()); |
|
| 1077 | 1077 | // capture submitted form data |
| 1078 | 1078 | $this->checkout->current_step->reg_form->receive_form_submission( |
| 1079 | - apply_filters( 'FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout ) |
|
| 1079 | + apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
| 1080 | 1080 | ); |
| 1081 | 1081 | // validate submitted form data |
| 1082 | - if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid() ) { |
|
| 1082 | + if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1083 | 1083 | // thou shall not pass !!! |
| 1084 | 1084 | $this->checkout->continue_reg = FALSE; |
| 1085 | 1085 | // any form validation errors? |
| 1086 | - if ( $this->checkout->current_step->reg_form->submission_error_message() !== '' ) { |
|
| 1086 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1087 | 1087 | $submission_error_messages = array(); |
| 1088 | 1088 | // bad, bad, bad registrant |
| 1089 | - foreach( $this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error ){ |
|
| 1090 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
| 1089 | + foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1090 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1091 | 1091 | $submission_error_messages[] = sprintf( |
| 1092 | - __( '%s : %s', 'event_espresso' ), |
|
| 1092 | + __('%s : %s', 'event_espresso'), |
|
| 1093 | 1093 | $validation_error->get_form_section()->html_label_text(), |
| 1094 | 1094 | $validation_error->getMessage() |
| 1095 | 1095 | ); |
| 1096 | 1096 | } |
| 1097 | 1097 | } |
| 1098 | - EE_Error::add_error( implode( '<br />', $submission_error_messages ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 1098 | + EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | // well not really... what will happen is we'll just get redirected back to redo the current step |
| 1101 | 1101 | $this->go_to_next_step(); |
| 1102 | 1102 | return; |
| 1103 | 1103 | } |
| 1104 | 1104 | } |
| 1105 | - } catch( EE_Error $e ) { |
|
| 1105 | + } catch (EE_Error $e) { |
|
| 1106 | 1106 | $e->get_error(); |
| 1107 | 1107 | } |
| 1108 | 1108 | } |
@@ -1119,22 +1119,22 @@ discard block |
||
| 1119 | 1119 | */ |
| 1120 | 1120 | private function _process_form_action() { |
| 1121 | 1121 | // what cha wanna do? |
| 1122 | - switch( $this->checkout->action ) { |
|
| 1122 | + switch ($this->checkout->action) { |
|
| 1123 | 1123 | // AJAX next step reg form |
| 1124 | 1124 | case 'display_spco_reg_step' : |
| 1125 | 1125 | $this->checkout->redirect = FALSE; |
| 1126 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
| 1127 | - $this->checkout->json_response->set_reg_step_html( $this->checkout->current_step->display_reg_form() ); |
|
| 1126 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1127 | + $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | break; |
| 1130 | 1130 | |
| 1131 | 1131 | default : |
| 1132 | 1132 | // meh... do one of those other steps first |
| 1133 | - if ( ! empty( $this->checkout->action ) && is_callable( array( $this->checkout->current_step, $this->checkout->action ))) { |
|
| 1133 | + if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1134 | 1134 | // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
| 1135 | - do_action( "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step ); |
|
| 1135 | + do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
| 1136 | 1136 | // call action on current step |
| 1137 | - if ( call_user_func( array( $this->checkout->current_step, $this->checkout->action )) ) { |
|
| 1137 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1138 | 1138 | // good registrant, you get to proceed |
| 1139 | 1139 | if ( |
| 1140 | 1140 | $this->checkout->current_step->success_message() !== '' |
@@ -1145,7 +1145,7 @@ discard block |
||
| 1145 | 1145 | ) { |
| 1146 | 1146 | EE_Error::add_success( |
| 1147 | 1147 | $this->checkout->current_step->success_message() |
| 1148 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1148 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
| 1149 | 1149 | ); |
| 1150 | 1150 | |
| 1151 | 1151 | } |
@@ -1153,12 +1153,12 @@ discard block |
||
| 1153 | 1153 | $this->_setup_redirect(); |
| 1154 | 1154 | } |
| 1155 | 1155 | // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
| 1156 | - do_action( "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step ); |
|
| 1156 | + do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
| 1157 | 1157 | |
| 1158 | 1158 | } else { |
| 1159 | 1159 | EE_Error::add_error( |
| 1160 | 1160 | sprintf( |
| 1161 | - __( 'The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso' ), |
|
| 1161 | + __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
| 1162 | 1162 | $this->checkout->action, |
| 1163 | 1163 | $this->checkout->current_step->name() |
| 1164 | 1164 | ), |
@@ -1184,10 +1184,10 @@ discard block |
||
| 1184 | 1184 | public function add_styles_and_scripts() { |
| 1185 | 1185 | // i18n |
| 1186 | 1186 | $this->translate_js_strings(); |
| 1187 | - if ( $this->checkout->admin_request ) { |
|
| 1188 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10 ); |
|
| 1187 | + if ($this->checkout->admin_request) { |
|
| 1188 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1189 | 1189 | } else { |
| 1190 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_and_scripts' ), 10 ); |
|
| 1190 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1191 | 1191 | } |
| 1192 | 1192 | } |
| 1193 | 1193 | |
@@ -1203,42 +1203,42 @@ discard block |
||
| 1203 | 1203 | EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
| 1204 | 1204 | EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
| 1205 | 1205 | EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
| 1206 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso' ); |
|
| 1207 | - EE_Registry::$i18n_js_strings['validation_error'] = __( 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso' ); |
|
| 1208 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso' ); |
|
| 1206 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1207 | + EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
| 1208 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
| 1209 | 1209 | EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
| 1210 | 1210 | EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
| 1211 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( __( 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso' ), '<br/>', '<br/>' ); |
|
| 1212 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo( 'language' ); |
|
| 1211 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf(__('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), '<br/>', '<br/>'); |
|
| 1212 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1213 | 1213 | EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
| 1214 | 1214 | EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
| 1215 | 1215 | EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
| 1216 | - EE_Registry::$i18n_js_strings['timer_years'] = __( 'years', 'event_espresso' ); |
|
| 1217 | - EE_Registry::$i18n_js_strings['timer_months'] = __( 'months', 'event_espresso' ); |
|
| 1218 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __( 'weeks', 'event_espresso' ); |
|
| 1219 | - EE_Registry::$i18n_js_strings['timer_days'] = __( 'days', 'event_espresso' ); |
|
| 1220 | - EE_Registry::$i18n_js_strings['timer_hours'] = __( 'hours', 'event_espresso' ); |
|
| 1221 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __( 'minutes', 'event_espresso' ); |
|
| 1222 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __( 'seconds', 'event_espresso' ); |
|
| 1223 | - EE_Registry::$i18n_js_strings['timer_year'] = __( 'year', 'event_espresso' ); |
|
| 1224 | - EE_Registry::$i18n_js_strings['timer_month'] = __( 'month', 'event_espresso' ); |
|
| 1225 | - EE_Registry::$i18n_js_strings['timer_week'] = __( 'week', 'event_espresso' ); |
|
| 1226 | - EE_Registry::$i18n_js_strings['timer_day'] = __( 'day', 'event_espresso' ); |
|
| 1227 | - EE_Registry::$i18n_js_strings['timer_hour'] = __( 'hour', 'event_espresso' ); |
|
| 1228 | - EE_Registry::$i18n_js_strings['timer_minute'] = __( 'minute', 'event_espresso' ); |
|
| 1229 | - EE_Registry::$i18n_js_strings['timer_second'] = __( 'second', 'event_espresso' ); |
|
| 1216 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1217 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1218 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1219 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1220 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1221 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1222 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1223 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1224 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1225 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1226 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1227 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1228 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1229 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1230 | 1230 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
| 1231 | - __( '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso' ), |
|
| 1231 | + __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso'), |
|
| 1232 | 1232 | '<h4 class="important-notice">', |
| 1233 | 1233 | '</h4>', |
| 1234 | 1234 | '<br />', |
| 1235 | 1235 | '<p>', |
| 1236 | - '<a href="'. get_post_type_archive_link( 'espresso_events' ) . '" title="', |
|
| 1236 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 1237 | 1237 | '">', |
| 1238 | 1238 | '</a>', |
| 1239 | 1239 | '</p>' |
| 1240 | 1240 | ); |
| 1241 | - EE_Registry::$i18n_js_strings[ 'ajax_submit' ] = apply_filters( 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true ); |
|
| 1241 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | |
@@ -1252,26 +1252,26 @@ discard block |
||
| 1252 | 1252 | */ |
| 1253 | 1253 | public function enqueue_styles_and_scripts() { |
| 1254 | 1254 | // load css |
| 1255 | - wp_register_style( 'single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 1256 | - wp_enqueue_style( 'single_page_checkout' ); |
|
| 1255 | + wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 1256 | + wp_enqueue_style('single_page_checkout'); |
|
| 1257 | 1257 | // load JS |
| 1258 | - wp_register_script( 'jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array( 'jquery' ), '1.0.1', TRUE ); |
|
| 1259 | - wp_register_script( 'jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array( 'jquery_plugin' ), '2.0.2', TRUE ); |
|
| 1260 | - wp_register_script( 'single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array( 'espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown' ), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 1258 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery .plugin.min.js', array('jquery'), '1.0.1', TRUE); |
|
| 1259 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', TRUE); |
|
| 1260 | + wp_register_script('single_page_checkout', SPCO_JS_URL.'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 1261 | 1261 | $this->checkout->registration_form->enqueue_js(); |
| 1262 | - wp_enqueue_script( 'single_page_checkout' ); |
|
| 1262 | + wp_enqueue_script('single_page_checkout'); |
|
| 1263 | 1263 | |
| 1264 | 1264 | /** |
| 1265 | 1265 | * global action hook for enqueueing styles and scripts with |
| 1266 | 1266 | * spco calls. |
| 1267 | 1267 | */ |
| 1268 | - do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this ); |
|
| 1268 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1269 | 1269 | |
| 1270 | 1270 | /** |
| 1271 | 1271 | * dynamic action hook for enqueueing styles and scripts with spco calls. |
| 1272 | 1272 | * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
| 1273 | 1273 | */ |
| 1274 | - do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this ); |
|
| 1274 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this); |
|
| 1275 | 1275 | |
| 1276 | 1276 | } |
| 1277 | 1277 | |
@@ -1286,19 +1286,19 @@ discard block |
||
| 1286 | 1286 | */ |
| 1287 | 1287 | private function _display_spco_reg_form() { |
| 1288 | 1288 | // if registering via the admin, just display the reg form for the current step |
| 1289 | - if ( $this->checkout->admin_request ) { |
|
| 1290 | - EE_Registry::instance()->REQ->add_output( $this->checkout->current_step->display_reg_form() ); |
|
| 1289 | + if ($this->checkout->admin_request) { |
|
| 1290 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1291 | 1291 | } else { |
| 1292 | 1292 | // add powered by EE msg |
| 1293 | - add_action( 'AHEE__SPCO__reg_form_footer', array( 'EED_Single_Page_Checkout', 'display_registration_footer' )); |
|
| 1293 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1294 | 1294 | |
| 1295 | - $empty_cart = count( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) ) < 1 ? true : false; |
|
| 1295 | + $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 ? true : false; |
|
| 1296 | 1296 | $cookies_not_set_msg = ''; |
| 1297 | - if ( $empty_cart && ! isset( $_COOKIE[ 'ee_cookie_test' ] ) ) { |
|
| 1297 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
| 1298 | 1298 | $cookies_not_set_msg = apply_filters( |
| 1299 | 1299 | 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
| 1300 | 1300 | sprintf( |
| 1301 | - __( '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', 'event_espresso' ), |
|
| 1301 | + __('%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', 'event_espresso'), |
|
| 1302 | 1302 | '<div class="ee-attention">', |
| 1303 | 1303 | '</div>', |
| 1304 | 1304 | '<h6 class="important-notice">', |
@@ -1318,7 +1318,7 @@ discard block |
||
| 1318 | 1318 | 'layout_strategy' => |
| 1319 | 1319 | new EE_Template_Layout( |
| 1320 | 1320 | array( |
| 1321 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1321 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
| 1322 | 1322 | 'template_args' => array( |
| 1323 | 1323 | 'empty_cart' => $empty_cart, |
| 1324 | 1324 | 'revisit' => $this->checkout->revisit, |
@@ -1327,8 +1327,8 @@ discard block |
||
| 1327 | 1327 | 'empty_msg' => apply_filters( |
| 1328 | 1328 | 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
| 1329 | 1329 | sprintf( |
| 1330 | - __( 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso' ), |
|
| 1331 | - '<a href="' . get_post_type_archive_link( 'espresso_events' ) . '" title="', |
|
| 1330 | + __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso'), |
|
| 1331 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 1332 | 1332 | '">', |
| 1333 | 1333 | '</a>' |
| 1334 | 1334 | ) |
@@ -1336,14 +1336,14 @@ discard block |
||
| 1336 | 1336 | 'cookies_not_set_msg' => $cookies_not_set_msg, |
| 1337 | 1337 | 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
| 1338 | 1338 | 'session_expiration' => |
| 1339 | - date( 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) |
|
| 1339 | + date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 1340 | 1340 | ) |
| 1341 | 1341 | ) |
| 1342 | 1342 | ) |
| 1343 | 1343 | ) |
| 1344 | 1344 | ); |
| 1345 | 1345 | // load template and add to output sent that gets filtered into the_content() |
| 1346 | - EE_Registry::instance()->REQ->add_output( $this->checkout->registration_form->get_html() ); |
|
| 1346 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1347 | 1347 | } |
| 1348 | 1348 | } |
| 1349 | 1349 | |
@@ -1357,8 +1357,8 @@ discard block |
||
| 1357 | 1357 | * @internal param string $label |
| 1358 | 1358 | * @return void |
| 1359 | 1359 | */ |
| 1360 | - public function add_extra_finalize_registration_inputs( $next_step ) { |
|
| 1361 | - if ( $next_step === 'finalize_registration' ) { |
|
| 1360 | + public function add_extra_finalize_registration_inputs($next_step) { |
|
| 1361 | + if ($next_step === 'finalize_registration') { |
|
| 1362 | 1362 | echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
| 1363 | 1363 | } |
| 1364 | 1364 | } |
@@ -1380,8 +1380,8 @@ discard block |
||
| 1380 | 1380 | ) { |
| 1381 | 1381 | add_filter( |
| 1382 | 1382 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
| 1383 | - function( $url) { |
|
| 1384 | - return apply_filters( 'FHEE__EE_Front_Controller__registration_footer__url', $url ); |
|
| 1383 | + function($url) { |
|
| 1384 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1385 | 1385 | } |
| 1386 | 1386 | ); |
| 1387 | 1387 | echo apply_filters( |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | \EEH_Template::powered_by_event_espresso( |
| 1390 | 1390 | '', |
| 1391 | 1391 | 'espresso-registration-footer-dv', |
| 1392 | - array( 'utm_content' => 'registration_checkout' ) |
|
| 1392 | + array('utm_content' => 'registration_checkout') |
|
| 1393 | 1393 | ) |
| 1394 | 1394 | ); |
| 1395 | 1395 | } |
@@ -1406,7 +1406,7 @@ discard block |
||
| 1406 | 1406 | * @throws \EE_Error |
| 1407 | 1407 | */ |
| 1408 | 1408 | public function unlock_transaction() { |
| 1409 | - if ( $this->checkout->transaction instanceof EE_Transaction ) { |
|
| 1409 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1410 | 1410 | $this->checkout->transaction->unlock(); |
| 1411 | 1411 | } |
| 1412 | 1412 | } |
@@ -1421,9 +1421,9 @@ discard block |
||
| 1421 | 1421 | * @return void |
| 1422 | 1422 | */ |
| 1423 | 1423 | private function _setup_redirect() { |
| 1424 | - if ( $this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
| 1424 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1425 | 1425 | $this->checkout->redirect = TRUE; |
| 1426 | - if ( empty( $this->checkout->redirect_url )) { |
|
| 1426 | + if (empty($this->checkout->redirect_url)) { |
|
| 1427 | 1427 | $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
| 1428 | 1428 | } |
| 1429 | 1429 | $this->checkout->redirect_url = apply_filters( |
@@ -1444,9 +1444,9 @@ discard block |
||
| 1444 | 1444 | * @throws \EE_Error |
| 1445 | 1445 | */ |
| 1446 | 1446 | public function go_to_next_step() { |
| 1447 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
| 1447 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1448 | 1448 | // capture contents of output buffer we started earlier in the request, and insert into JSON response |
| 1449 | - $this->checkout->json_response->set_unexpected_errors( ob_get_clean() ); |
|
| 1449 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | $this->unlock_transaction(); |
| 1452 | 1452 | // just return for these conditions |
@@ -1475,7 +1475,7 @@ discard block |
||
| 1475 | 1475 | */ |
| 1476 | 1476 | protected function _handle_json_response() { |
| 1477 | 1477 | // if this is an ajax request |
| 1478 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
| 1478 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1479 | 1479 | // DEBUG LOG |
| 1480 | 1480 | //$this->checkout->log( |
| 1481 | 1481 | // __CLASS__, __FUNCTION__, __LINE__, |
@@ -1488,7 +1488,7 @@ discard block |
||
| 1488 | 1488 | $this->checkout->json_response->set_registration_time_limit( |
| 1489 | 1489 | $this->checkout->get_registration_time_limit() |
| 1490 | 1490 | ); |
| 1491 | - $this->checkout->json_response->set_payment_amount( $this->checkout->amount_owing ); |
|
| 1491 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1492 | 1492 | // just send the ajax ( |
| 1493 | 1493 | $json_response = apply_filters( |
| 1494 | 1494 | 'FHEE__EE_Single_Page_Checkout__JSON_response', |
@@ -1509,9 +1509,9 @@ discard block |
||
| 1509 | 1509 | */ |
| 1510 | 1510 | protected function _handle_html_redirects() { |
| 1511 | 1511 | // going somewhere ? |
| 1512 | - if ( $this->checkout->redirect && ! empty( $this->checkout->redirect_url ) ) { |
|
| 1512 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1513 | 1513 | // store notices in a transient |
| 1514 | - EE_Error::get_notices( false, true, true ); |
|
| 1514 | + EE_Error::get_notices(false, true, true); |
|
| 1515 | 1515 | // DEBUG LOG |
| 1516 | 1516 | //$this->checkout->log( |
| 1517 | 1517 | // __CLASS__, __FUNCTION__, __LINE__, |
@@ -1521,7 +1521,7 @@ discard block |
||
| 1521 | 1521 | // 'headers_list' => headers_list(), |
| 1522 | 1522 | // ) |
| 1523 | 1523 | //); |
| 1524 | - wp_safe_redirect( $this->checkout->redirect_url ); |
|
| 1524 | + wp_safe_redirect($this->checkout->redirect_url); |
|
| 1525 | 1525 | exit(); |
| 1526 | 1526 | } |
| 1527 | 1527 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @throws \EE_Error |
| 203 | 203 | */ |
| 204 | 204 | public static function set_definitions() { |
| 205 | - define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS ); |
|
| 205 | + define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS ); |
|
| 206 | 206 | define( 'SPCO_CSS_URL', plugin_dir_url( __FILE__ ) . 'css' . DS ); |
| 207 | 207 | define( 'SPCO_IMG_URL', plugin_dir_url( __FILE__ ) . 'img' . DS ); |
| 208 | 208 | define( 'SPCO_JS_URL', plugin_dir_url( __FILE__ ) . 'js' . DS ); |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * process_registration_from_admin |
|
| 326 | - * |
|
| 327 | - * @access public |
|
| 325 | + * process_registration_from_admin |
|
| 326 | + * |
|
| 327 | + * @access public |
|
| 328 | 328 | * @return \EE_Transaction |
| 329 | 329 | * @throws \EE_Error |
| 330 | 330 | */ |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @throws \EE_Error |
| 360 | 360 | */ |
| 361 | 361 | public function run( $WP_Query ) { |
| 362 | - if ( |
|
| 362 | + if ( |
|
| 363 | 363 | $WP_Query instanceof WP_Query |
| 364 | 364 | && $WP_Query->is_main_query() |
| 365 | 365 | && apply_filters( 'FHEE__EED_Single_Page_Checkout__run', true ) |
@@ -371,38 +371,38 @@ discard block |
||
| 371 | 371 | |
| 372 | 372 | |
| 373 | 373 | |
| 374 | - /** |
|
| 375 | - * determines whether current url matches reg page url |
|
| 376 | - * |
|
| 377 | - * @return bool |
|
| 378 | - */ |
|
| 379 | - protected function _is_reg_checkout() { |
|
| 380 | - // get current permalink for reg page without any extra query args |
|
| 381 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 382 | - // get request URI for current request, but without the scheme or host |
|
| 383 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 384 | - $current_request_uri = html_entity_decode( $current_request_uri ); |
|
| 385 | - // get array of query args from the current request URI |
|
| 386 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 387 | - // grab page id if it is set |
|
| 388 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 389 | - // and remove the page id from the query args (we will re-add it later) |
|
| 390 | - unset($query_args['page_id']); |
|
| 391 | - // now strip all query args from current request URI |
|
| 392 | - $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
|
| 393 | - // and re-add the page id if it was set |
|
| 394 | - if ($page_id){ |
|
| 395 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 396 | - } |
|
| 397 | - // remove slashes and ? |
|
| 398 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
| 399 | - // is current request URI part of the known full reg page URL ? |
|
| 400 | - return strpos($reg_page_url, $current_request_uri) !== false; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 374 | + /** |
|
| 375 | + * determines whether current url matches reg page url |
|
| 376 | + * |
|
| 377 | + * @return bool |
|
| 378 | + */ |
|
| 379 | + protected function _is_reg_checkout() { |
|
| 380 | + // get current permalink for reg page without any extra query args |
|
| 381 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 382 | + // get request URI for current request, but without the scheme or host |
|
| 383 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 384 | + $current_request_uri = html_entity_decode( $current_request_uri ); |
|
| 385 | + // get array of query args from the current request URI |
|
| 386 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 387 | + // grab page id if it is set |
|
| 388 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 389 | + // and remove the page id from the query args (we will re-add it later) |
|
| 390 | + unset($query_args['page_id']); |
|
| 391 | + // now strip all query args from current request URI |
|
| 392 | + $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri); |
|
| 393 | + // and re-add the page id if it was set |
|
| 394 | + if ($page_id){ |
|
| 395 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 396 | + } |
|
| 397 | + // remove slashes and ? |
|
| 398 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
| 399 | + // is current request URI part of the known full reg page URL ? |
|
| 400 | + return strpos($reg_page_url, $current_request_uri) !== false; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | 406 | * run |
| 407 | 407 | * |
| 408 | 408 | * @access public |
@@ -428,16 +428,16 @@ discard block |
||
| 428 | 428 | if ( EED_Single_Page_Checkout::$_initialized ) { |
| 429 | 429 | return; |
| 430 | 430 | } |
| 431 | - try { |
|
| 431 | + try { |
|
| 432 | 432 | // setup the EE_Checkout object |
| 433 | 433 | $this->checkout = $this->_initialize_checkout(); |
| 434 | 434 | // filter checkout |
| 435 | 435 | $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout ); |
| 436 | 436 | // get the $_GET |
| 437 | 437 | $this->_get_request_vars(); |
| 438 | - if ($this->_block_bots()) { |
|
| 439 | - return; |
|
| 440 | - } |
|
| 438 | + if ($this->_block_bots()) { |
|
| 439 | + return; |
|
| 440 | + } |
|
| 441 | 441 | // filter continue_reg |
| 442 | 442 | $this->checkout->continue_reg = apply_filters( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout ); |
| 443 | 443 | // load the reg steps array |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
| 599 | 599 | * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
| 600 | 600 | * then where you coming from man? |
| 601 | - * |
|
| 602 | - * @return boolean |
|
| 601 | + * |
|
| 602 | + * @return boolean |
|
| 603 | 603 | */ |
| 604 | 604 | private function _block_bots() { |
| 605 | 605 | $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
@@ -854,15 +854,15 @@ discard block |
||
| 854 | 854 | |
| 855 | 855 | |
| 856 | 856 | |
| 857 | - /** |
|
| 858 | - * _get_registrations |
|
| 859 | - * |
|
| 860 | - * @access private |
|
| 861 | - * @param EE_Transaction $transaction |
|
| 862 | - * @return void |
|
| 863 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 864 | - * @throws \EE_Error |
|
| 865 | - */ |
|
| 857 | + /** |
|
| 858 | + * _get_registrations |
|
| 859 | + * |
|
| 860 | + * @access private |
|
| 861 | + * @param EE_Transaction $transaction |
|
| 862 | + * @return void |
|
| 863 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 864 | + * @throws \EE_Error |
|
| 865 | + */ |
|
| 866 | 866 | private function _get_registrations( EE_Transaction $transaction ) { |
| 867 | 867 | // first step: grab the registrants { : o |
| 868 | 868 | $registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, true ); |
@@ -884,12 +884,12 @@ discard block |
||
| 884 | 884 | if ( $registration instanceof EE_Registration ) { |
| 885 | 885 | // we display all attendee info for the primary registrant |
| 886 | 886 | if ( $this->checkout->reg_url_link === $registration->reg_url_link() |
| 887 | - && $registration->is_primary_registrant() |
|
| 887 | + && $registration->is_primary_registrant() |
|
| 888 | 888 | ) { |
| 889 | 889 | $this->checkout->primary_revisit = true; |
| 890 | 890 | break; |
| 891 | 891 | } else if ( $this->checkout->revisit |
| 892 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
| 892 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
| 893 | 893 | ) { |
| 894 | 894 | // but hide info if it doesn't belong to you |
| 895 | 895 | $transaction->clear_cache( 'Registration', $registration->ID() ); |
@@ -901,15 +901,15 @@ discard block |
||
| 901 | 901 | |
| 902 | 902 | |
| 903 | 903 | |
| 904 | - /** |
|
| 905 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 906 | - * |
|
| 907 | - * @access private |
|
| 908 | - * @param EE_Transaction $transaction |
|
| 909 | - * @return array |
|
| 910 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 911 | - * @throws \EE_Error |
|
| 912 | - */ |
|
| 904 | + /** |
|
| 905 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 906 | + * |
|
| 907 | + * @access private |
|
| 908 | + * @param EE_Transaction $transaction |
|
| 909 | + * @return array |
|
| 910 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 911 | + * @throws \EE_Error |
|
| 912 | + */ |
|
| 913 | 913 | private function _initialize_registrations( EE_Transaction $transaction ) { |
| 914 | 914 | $att_nmbr = 0; |
| 915 | 915 | $registrations = array(); |
@@ -922,23 +922,23 @@ discard block |
||
| 922 | 922 | //do the following for each ticket of this type they selected |
| 923 | 923 | for ( $x = 1; $x <= $line_item->quantity(); $x++ ) { |
| 924 | 924 | $att_nmbr++; |
| 925 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 926 | - $CreateRegistrationCommand = EE_Registry::instance() |
|
| 927 | - ->create( |
|
| 928 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 929 | - array( |
|
| 930 | - $transaction, |
|
| 931 | - $line_item, |
|
| 932 | - $att_nmbr, |
|
| 933 | - $this->checkout->total_ticket_count |
|
| 934 | - ) |
|
| 935 | - ); |
|
| 936 | - // override capabilities for frontend registrations |
|
| 937 | - if ( ! is_admin()) { |
|
| 938 | - $CreateRegistrationCommand->setCapCheck( |
|
| 939 | - new PublicCapabilities( '', 'create_new_registration' ) |
|
| 940 | - ); |
|
| 941 | - } |
|
| 925 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 926 | + $CreateRegistrationCommand = EE_Registry::instance() |
|
| 927 | + ->create( |
|
| 928 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 929 | + array( |
|
| 930 | + $transaction, |
|
| 931 | + $line_item, |
|
| 932 | + $att_nmbr, |
|
| 933 | + $this->checkout->total_ticket_count |
|
| 934 | + ) |
|
| 935 | + ); |
|
| 936 | + // override capabilities for frontend registrations |
|
| 937 | + if ( ! is_admin()) { |
|
| 938 | + $CreateRegistrationCommand->setCapCheck( |
|
| 939 | + new PublicCapabilities( '', 'create_new_registration' ) |
|
| 940 | + ); |
|
| 941 | + } |
|
| 942 | 942 | $registration = EE_Registry::instance()->BUS->execute( $CreateRegistrationCommand ); |
| 943 | 943 | if ( ! $registration instanceof EE_Registration ) { |
| 944 | 944 | throw new InvalidEntityException( $registration, 'EE_Registration' ); |
@@ -1433,10 +1433,10 @@ discard block |
||
| 1433 | 1433 | $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
| 1434 | 1434 | } |
| 1435 | 1435 | $this->checkout->redirect_url = apply_filters( |
| 1436 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1437 | - $this->checkout->redirect_url, |
|
| 1438 | - $this->checkout |
|
| 1439 | - ); |
|
| 1436 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1437 | + $this->checkout->redirect_url, |
|
| 1438 | + $this->checkout |
|
| 1439 | + ); |
|
| 1440 | 1440 | } |
| 1441 | 1441 | } |
| 1442 | 1442 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | foreach ( $query as $query_args ) { |
| 140 | 140 | // break apart the key value pairs |
| 141 | 141 | $query_args = explode( '=', $query_args ); |
| 142 | - // and add to our results array |
|
| 142 | + // and add to our results array |
|
| 143 | 143 | $query_params[ $query_args[0] ] = $query_args[1]; |
| 144 | 144 | } |
| 145 | 145 | return $query_params; |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | $server_variable = strtoupper( $server_variable ); |
| 205 | 205 | // whitelist INPUT_SERVER var |
| 206 | 206 | if ( isset( $server_variables[ $server_variable ] ) ) { |
| 207 | - $URL = filter_input( INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE ); |
|
| 208 | - if ( empty( $URL ) ) { |
|
| 209 | - // fallback sanitization if the above fails |
|
| 207 | + $URL = filter_input( INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE ); |
|
| 208 | + if ( empty( $URL ) ) { |
|
| 209 | + // fallback sanitization if the above fails |
|
| 210 | 210 | $URL = wp_sanitize_redirect( $_SERVER[ $server_variable ] ); |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * ------------------------------------------------------------------------ |
| 11 | 11 | */ |
| 12 | -class EEH_URL{ |
|
| 12 | +class EEH_URL { |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * _add_query_arg |
@@ -21,30 +21,30 @@ discard block |
||
| 21 | 21 | * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
| 22 | 22 | * @return string |
| 23 | 23 | */ |
| 24 | - public static function add_query_args_and_nonce( $args = array(), $url = '', $exclude_nonce = false ) { |
|
| 25 | - if ( empty( $url ) ) { |
|
| 26 | - $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', 'event_espresso' ); |
|
| 27 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 28 | - __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', 'event_espresso' ), |
|
| 24 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) { |
|
| 25 | + if (empty($url)) { |
|
| 26 | + $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', 'event_espresso'); |
|
| 27 | + $dev_msg = $user_msg."\n".sprintf( |
|
| 28 | + __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', 'event_espresso'), |
|
| 29 | 29 | __CLASS__ |
| 30 | 30 | ); |
| 31 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 31 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 32 | 32 | } |
| 33 | 33 | // check that an action exists and add nonce |
| 34 | - if ( ! $exclude_nonce ) { |
|
| 35 | - if ( isset( $args['action'] ) && ! empty( $args['action'] ) ) { |
|
| 36 | - $args = array_merge( $args, array( $args['action'] . '_nonce' => wp_create_nonce( $args['action'] . '_nonce' ) ) ); |
|
| 34 | + if ( ! $exclude_nonce) { |
|
| 35 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 36 | + $args = array_merge($args, array($args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce'))); |
|
| 37 | 37 | } else { |
| 38 | - $args = array_merge( $args, array( 'action' => 'default', 'default_nonce' => wp_create_nonce( 'default_nonce' ) ) ); |
|
| 38 | + $args = array_merge($args, array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce'))); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | //finally, let's always add a return address (if present) :) |
| 43 | - $args = ! empty( $_REQUEST['action'] ) && ! isset( $_REQUEST[ 'return' ] ) |
|
| 44 | - ? array_merge( $args, array( 'return' => $_REQUEST['action'] ) ) |
|
| 43 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 44 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 45 | 45 | : $args; |
| 46 | 46 | |
| 47 | - return add_query_arg( $args, $url ); |
|
| 47 | + return add_query_arg($args, $url); |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -57,17 +57,17 @@ discard block |
||
| 57 | 57 | * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly |
| 58 | 58 | * @return boolean |
| 59 | 59 | */ |
| 60 | - public static function remote_file_exists( $url, $args = array() ){ |
|
| 61 | - $results = wp_remote_request($url,array_merge( array( |
|
| 60 | + public static function remote_file_exists($url, $args = array()) { |
|
| 61 | + $results = wp_remote_request($url, array_merge(array( |
|
| 62 | 62 | 'method'=>'GET', |
| 63 | 63 | 'redirection'=>1 |
| 64 | - ), $args ) ); |
|
| 65 | - if( ! $results instanceof WP_Error && |
|
| 64 | + ), $args)); |
|
| 65 | + if ( ! $results instanceof WP_Error && |
|
| 66 | 66 | isset($results['response']) && |
| 67 | 67 | isset($results['response']['code']) && |
| 68 | - $results['response']['code'] == '200'){ |
|
| 68 | + $results['response']['code'] == '200') { |
|
| 69 | 69 | return true; |
| 70 | - }else{ |
|
| 70 | + } else { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -83,29 +83,29 @@ discard block |
||
| 83 | 83 | * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
| 84 | 84 | * @return string |
| 85 | 85 | */ |
| 86 | - public static function refactor_url( $url = '', $remove_query = TRUE, $base_url_only = FALSE ) { |
|
| 86 | + public static function refactor_url($url = '', $remove_query = TRUE, $base_url_only = FALSE) { |
|
| 87 | 87 | // break apart incoming URL |
| 88 | - $url_bits = parse_url( $url ); |
|
| 88 | + $url_bits = parse_url($url); |
|
| 89 | 89 | // HTTP or HTTPS ? |
| 90 | - $scheme = isset( $url_bits[ 'scheme' ] ) ? $url_bits[ 'scheme' ] . '://' : 'http://'; |
|
| 90 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 91 | 91 | // domain |
| 92 | - $host = isset( $url_bits[ 'host' ] ) ? $url_bits[ 'host' ] : ''; |
|
| 92 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 93 | 93 | // if only the base URL is requested, then return that now |
| 94 | - if ( $base_url_only ) { |
|
| 95 | - return $scheme . $host; |
|
| 94 | + if ($base_url_only) { |
|
| 95 | + return $scheme.$host; |
|
| 96 | 96 | } |
| 97 | - $port = isset( $url_bits[ 'port' ] ) ? ':' . $url_bits[ 'port' ] : ''; |
|
| 98 | - $user = isset( $url_bits[ 'user' ] ) ? $url_bits[ 'user' ] : ''; |
|
| 99 | - $pass = isset( $url_bits[ 'pass' ] ) ? ':' . $url_bits[ 'pass' ] : ''; |
|
| 100 | - $pass = ( $user || $pass ) ? $pass . '@' : ''; |
|
| 101 | - $path = isset( $url_bits[ 'path' ] ) ? $url_bits[ 'path' ] : ''; |
|
| 97 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 98 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 99 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 100 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 101 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 102 | 102 | // if the query string is not required, then return what we have so far |
| 103 | - if ( $remove_query ) { |
|
| 104 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 103 | + if ($remove_query) { |
|
| 104 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 105 | 105 | } |
| 106 | - $query = isset( $url_bits[ 'query' ] ) ? '?' . $url_bits[ 'query' ] : ''; |
|
| 107 | - $fragment = isset( $url_bits[ 'fragment' ] ) ? '#' . $url_bits[ 'fragment' ] : ''; |
|
| 108 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 106 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 107 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 108 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
@@ -118,29 +118,29 @@ discard block |
||
| 118 | 118 | * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will simply return the query string |
| 119 | 119 | * @return string|array |
| 120 | 120 | */ |
| 121 | - public static function get_query_string( $url = '', $as_array = TRUE ) { |
|
| 121 | + public static function get_query_string($url = '', $as_array = TRUE) { |
|
| 122 | 122 | // decode, then break apart incoming URL |
| 123 | - $url_bits = parse_url( html_entity_decode( $url ) ); |
|
| 123 | + $url_bits = parse_url(html_entity_decode($url)); |
|
| 124 | 124 | // grab query string from URL |
| 125 | - $query = isset( $url_bits[ 'query' ] ) ? $url_bits[ 'query' ] : ''; |
|
| 125 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 126 | 126 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 127 | - if ( ! $as_array ) { |
|
| 127 | + if ( ! $as_array) { |
|
| 128 | 128 | return $query; |
| 129 | 129 | } |
| 130 | 130 | // if no query string exists then just return an empty array now |
| 131 | - if ( empty( $query )) { |
|
| 131 | + if (empty($query)) { |
|
| 132 | 132 | return array(); |
| 133 | 133 | } |
| 134 | 134 | // empty array to hold results |
| 135 | 135 | $query_params = array(); |
| 136 | 136 | // now break apart the query string into separate params |
| 137 | - $query = explode( '&', $query ); |
|
| 137 | + $query = explode('&', $query); |
|
| 138 | 138 | // loop thru our query params |
| 139 | - foreach ( $query as $query_args ) { |
|
| 139 | + foreach ($query as $query_args) { |
|
| 140 | 140 | // break apart the key value pairs |
| 141 | - $query_args = explode( '=', $query_args ); |
|
| 141 | + $query_args = explode('=', $query_args); |
|
| 142 | 142 | // and add to our results array |
| 143 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 143 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 144 | 144 | } |
| 145 | 145 | return $query_params; |
| 146 | 146 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * prevent_prefetching |
| 152 | 152 | * @return void |
| 153 | 153 | */ |
| 154 | - public static function prevent_prefetching(){ |
|
| 154 | + public static function prevent_prefetching() { |
|
| 155 | 155 | // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
| 156 | 156 | remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
| 157 | 157 | } |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | * @param string $prefix Use this to prefix the string with something. |
| 167 | 167 | * @return string |
| 168 | 168 | */ |
| 169 | - public static function generate_unique_token( $prefix = '' ) { |
|
| 170 | - $token = md5( uniqid() . mt_rand() ); |
|
| 171 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 169 | + public static function generate_unique_token($prefix = '') { |
|
| 170 | + $token = md5(uniqid().mt_rand()); |
|
| 171 | + return $prefix ? $prefix.'_'.$token : $token; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * add_nocache_headers |
| 178 | 178 | * @return void |
| 179 | 179 | */ |
| 180 | - public static function add_nocache_headers(){ |
|
| 180 | + public static function add_nocache_headers() { |
|
| 181 | 181 | // add no cache headers |
| 182 | 182 | // add_action( 'wp_head' , array( 'EED_Single_Page_Checkout', 'nocache_headers' ), 10 ); |
| 183 | 183 | // plus a little extra for nginx |
@@ -194,20 +194,20 @@ discard block |
||
| 194 | 194 | * @param string $server_variable |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - public static function filter_input_server_url( $server_variable = 'REQUEST_URI' ){ |
|
| 197 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') { |
|
| 198 | 198 | $URL = ''; |
| 199 | 199 | $server_variables = array( |
| 200 | 200 | 'REQUEST_URI' => 1, |
| 201 | 201 | 'HTTP_HOST' => 1, |
| 202 | 202 | 'PHP_SELF' => 1, |
| 203 | 203 | ); |
| 204 | - $server_variable = strtoupper( $server_variable ); |
|
| 204 | + $server_variable = strtoupper($server_variable); |
|
| 205 | 205 | // whitelist INPUT_SERVER var |
| 206 | - if ( isset( $server_variables[ $server_variable ] ) ) { |
|
| 207 | - $URL = filter_input( INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE ); |
|
| 208 | - if ( empty( $URL ) ) { |
|
| 206 | + if (isset($server_variables[$server_variable])) { |
|
| 207 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 208 | + if (empty($URL)) { |
|
| 209 | 209 | // fallback sanitization if the above fails |
| 210 | - $URL = wp_sanitize_redirect( $_SERVER[ $server_variable ] ); |
|
| 210 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | return $URL; |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | public static function current_url() { |
| 223 | - if ( isset( $_SERVER[ 'HTTP_HOST' ], $_SERVER[ 'REQUEST_URI' ] ) ) { |
|
| 223 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 224 | 224 | $url = is_ssl() ? 'https://' : 'http://'; |
| 225 | - $url .= \EEH_URL::filter_input_server_url( 'HTTP_HOST' ); |
|
| 226 | - $url .= \EEH_URL::filter_input_server_url( 'REQUEST_URI' ); |
|
| 225 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 226 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 227 | 227 | } else { |
| 228 | 228 | $url = 'unknown'; |
| 229 | 229 | } |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | if ( |
| 40 | 40 | ! ( $checkout->uts || $checkout->reg_url_link ) |
| 41 | 41 | && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
| 42 | - && \EE_Config::instance()->registration->track_invalid_checkout_access() |
|
| 43 | - ) { |
|
| 42 | + && \EE_Config::instance()->registration->track_invalid_checkout_access() |
|
| 43 | + ) { |
|
| 44 | 44 | /** @var \EE_Request $request */ |
| 45 | 45 | $request = \EE_Registry::instance()->load_core( 'EE_Request' ); |
| 46 | 46 | $ip_address = $request->ip_address(); |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
| 62 | 62 | update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout ); |
| 63 | - if (WP_DEBUG) { |
|
| 64 | - \EE_Error::add_error( |
|
| 65 | - esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
| 66 | - __FILE__, |
|
| 67 | - __FUNCTION__, |
|
| 68 | - __LINE__ |
|
| 69 | - ); |
|
| 70 | - } |
|
| 63 | + if (WP_DEBUG) { |
|
| 64 | + \EE_Error::add_error( |
|
| 65 | + esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
| 66 | + __FILE__, |
|
| 67 | + __FUNCTION__, |
|
| 68 | + __LINE__ |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | return true; |
| 72 | 72 | } |
| 73 | 73 | return false; |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\modules\invalid_checkout_access; |
| 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 | |
@@ -35,31 +35,31 @@ discard block |
||
| 35 | 35 | * @param \EE_Checkout $checkout |
| 36 | 36 | * @return bool true if access to registration checkout appears to be invalid |
| 37 | 37 | */ |
| 38 | - public function checkoutAccessIsInvalid( \EE_Checkout $checkout ) { |
|
| 38 | + public function checkoutAccessIsInvalid(\EE_Checkout $checkout) { |
|
| 39 | 39 | if ( |
| 40 | - ! ( $checkout->uts || $checkout->reg_url_link ) |
|
| 41 | - && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
| 40 | + ! ($checkout->uts || $checkout->reg_url_link) |
|
| 41 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 42 | 42 | && \EE_Config::instance()->registration->track_invalid_checkout_access() |
| 43 | 43 | ) { |
| 44 | 44 | /** @var \EE_Request $request */ |
| 45 | - $request = \EE_Registry::instance()->load_core( 'EE_Request' ); |
|
| 45 | + $request = \EE_Registry::instance()->load_core('EE_Request'); |
|
| 46 | 46 | $ip_address = $request->ip_address(); |
| 47 | - $ee_bot_checkout = get_option( InvalidCheckoutAccess::OPTION_KEY ); |
|
| 48 | - if ( $ee_bot_checkout === false ) { |
|
| 47 | + $ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY); |
|
| 48 | + if ($ee_bot_checkout === false) { |
|
| 49 | 49 | $ee_bot_checkout = array(); |
| 50 | - add_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false ); |
|
| 50 | + add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false); |
|
| 51 | 51 | } |
| 52 | - if ( ! isset( $ee_bot_checkout[ $ip_address ] ) ) { |
|
| 53 | - $ee_bot_checkout[ $ip_address ] = array(); |
|
| 52 | + if ( ! isset($ee_bot_checkout[$ip_address])) { |
|
| 53 | + $ee_bot_checkout[$ip_address] = array(); |
|
| 54 | 54 | } |
| 55 | - $http_referer = isset( $_SERVER['HTTP_REFERER'] ) |
|
| 56 | - ? esc_attr( $_SERVER['HTTP_REFERER'] ) |
|
| 55 | + $http_referer = isset($_SERVER['HTTP_REFERER']) |
|
| 56 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
| 57 | 57 | : 0; |
| 58 | - if ( ! isset( $ee_bot_checkout[ $ip_address ][ $http_referer ] ) ) { |
|
| 59 | - $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0; |
|
| 58 | + if ( ! isset($ee_bot_checkout[$ip_address][$http_referer])) { |
|
| 59 | + $ee_bot_checkout[$ip_address][$http_referer] = 0; |
|
| 60 | 60 | } |
| 61 | - $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
|
| 62 | - update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout ); |
|
| 61 | + $ee_bot_checkout[$ip_address][$http_referer]++; |
|
| 62 | + update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout); |
|
| 63 | 63 | if (WP_DEBUG) { |
| 64 | 64 | \EE_Error::add_error( |
| 65 | 65 | esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | 'layout_strategy' => new \EE_Admin_Two_Column_Layout(), |
| 89 | 89 | 'subsections' => array( |
| 90 | 90 | 'invalid_checkout_access_hdr' => new \EE_Form_Section_HTML( |
| 91 | - \EEH_HTML::h2( esc_html__( 'Invalid Checkout Access', 'event_espresso' ) ) |
|
| 91 | + \EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso')) |
|
| 92 | 92 | ), |
| 93 | 93 | 'ee_bot_checkout_data' => new \EE_Text_Area_Input( |
| 94 | 94 | array( |
| 95 | - 'html_label_text' => esc_html__( 'Invalid Checkout Data', 'event_espresso' ), |
|
| 95 | + 'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'), |
|
| 96 | 96 | 'default' => var_export( |
| 97 | - get_option( InvalidCheckoutAccess::OPTION_KEY, array() ), |
|
| 97 | + get_option(InvalidCheckoutAccess::OPTION_KEY, array()), |
|
| 98 | 98 | true |
| 99 | 99 | ), |
| 100 | 100 | 'required' => false, |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ), |
| 107 | 107 | 'track_invalid_checkout_access' => new \EE_Yes_No_Input( |
| 108 | 108 | array( |
| 109 | - 'html_label_text' => __( 'Track Invalid Checkout Access?', 'event_espresso' ), |
|
| 109 | + 'html_label_text' => __('Track Invalid Checkout Access?', 'event_espresso'), |
|
| 110 | 110 | 'html_help_text' => esc_html__( |
| 111 | 111 | 'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.', |
| 112 | 112 | 'event_espresso' |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | ), |
| 120 | 120 | 'delete_invalid_checkout_data' => new \EE_Yes_No_Input( |
| 121 | 121 | array( |
| 122 | - 'html_label_text' => __( 'Reset Invalid Checkout Data', 'event_espresso' ), |
|
| 122 | + 'html_label_text' => __('Reset Invalid Checkout Data', 'event_espresso'), |
|
| 123 | 123 | 'html_help_text' => esc_html__( |
| 124 | 124 | 'Setting this to "Yes" will delete all existing invalid checkout access data.', |
| 125 | 125 | 'event_espresso' |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | * @param \EE_Registration_Config $EE_Registration_Config |
| 142 | 142 | * @return \EE_Registration_Config |
| 143 | 143 | */ |
| 144 | - public function processForm( \EE_Registration_Config $EE_Registration_Config ) { |
|
| 144 | + public function processForm(\EE_Registration_Config $EE_Registration_Config) { |
|
| 145 | 145 | try { |
| 146 | 146 | $invalid_checkout_access_form = $this->getForm(); |
| 147 | 147 | // if not displaying a form, then check for form submission |
| 148 | - if ( $invalid_checkout_access_form->was_submitted() ) { |
|
| 148 | + if ($invalid_checkout_access_form->was_submitted()) { |
|
| 149 | 149 | // capture form data |
| 150 | 150 | $invalid_checkout_access_form->receive_form_submission(); |
| 151 | 151 | // validate form data |
| 152 | - if ( $invalid_checkout_access_form->is_valid() ) { |
|
| 152 | + if ($invalid_checkout_access_form->is_valid()) { |
|
| 153 | 153 | // grab validated data from form |
| 154 | 154 | $valid_data = $invalid_checkout_access_form->valid_data(); |
| 155 | 155 | // ensure form inputs we want are set |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | $valid_data['track_invalid_checkout_access'] |
| 164 | 164 | ); |
| 165 | 165 | // if deleting, then update option with empty array |
| 166 | - if ( filter_var( $valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 167 | - update_option( InvalidCheckoutAccess::OPTION_KEY, array() ); |
|
| 166 | + if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) { |
|
| 167 | + update_option(InvalidCheckoutAccess::OPTION_KEY, array()); |
|
| 168 | 168 | } |
| 169 | 169 | } else { |
| 170 | 170 | \EE_Error::add_error( |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | ); |
| 179 | 179 | } |
| 180 | 180 | } else { |
| 181 | - if ( $invalid_checkout_access_form->submission_error_message() !== '' ) { |
|
| 181 | + if ($invalid_checkout_access_form->submission_error_message() !== '') { |
|
| 182 | 182 | \EE_Error::add_error( |
| 183 | 183 | $invalid_checkout_access_form->submission_error_message(), |
| 184 | 184 | __FILE__, |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | - } catch ( \EE_Error $e ) { |
|
| 191 | + } catch (\EE_Error $e) { |
|
| 192 | 192 | $e->get_error(); |
| 193 | 193 | } |
| 194 | 194 | return $EE_Registration_Config; |
@@ -370,7 +370,7 @@ |
||
| 370 | 370 | * with construction finalize being called later |
| 371 | 371 | * (realizing that the subsections' html names |
| 372 | 372 | * might not be set yet, etc.) |
| 373 | - * @return EE_Form_Section_Base |
|
| 373 | + * @return EE_Form_Section_Validatable|null |
|
| 374 | 374 | * @throws \EE_Error |
| 375 | 375 | */ |
| 376 | 376 | public function get_subsection($name, $require_construction_to_be_finalized = true) |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function __construct($options_array = array()) |
| 88 | 88 | { |
| 89 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 89 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | 90 | $this); |
| 91 | 91 | //call parent first, as it may be setting the name |
| 92 | 92 | parent::__construct($options_array); |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | add_filter('FHEE_load_jquery_validate', '__return_true'); |
| 607 | 607 | wp_register_script( |
| 608 | 608 | 'ee_form_section_validation', |
| 609 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 609 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
| 610 | 610 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
| 611 | 611 | EVENT_ESPRESSO_VERSION, |
| 612 | 612 | true |
@@ -848,8 +848,8 @@ discard block |
||
| 848 | 848 | protected function _validate() |
| 849 | 849 | { |
| 850 | 850 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
| 851 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 852 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 851 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 852 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
| 853 | 853 | } |
| 854 | 854 | $subsection->_validate(); |
| 855 | 855 | } |
@@ -1215,7 +1215,7 @@ discard block |
||
| 1215 | 1215 | public function html_name_prefix() |
| 1216 | 1216 | { |
| 1217 | 1217 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
| 1218 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1218 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
| 1219 | 1219 | } else { |
| 1220 | 1220 | return $this->name(); |
| 1221 | 1221 | } |
@@ -13,1349 +13,1349 @@ |
||
| 13 | 13 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Subsections |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Validatable[] |
|
| 22 | - */ |
|
| 23 | - protected $_subsections = array(); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Strategy for laying out the form |
|
| 27 | - * |
|
| 28 | - * @var EE_Form_Section_Layout_Base |
|
| 29 | - */ |
|
| 30 | - protected $_layout_strategy; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Whether or not this form has received and validated a form submission yet |
|
| 34 | - * |
|
| 35 | - * @var boolean |
|
| 36 | - */ |
|
| 37 | - protected $_received_submission = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * message displayed to users upon successful form submission |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - protected $_form_submission_success_message = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * message displayed to users upon unsuccessful form submission |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - protected $_form_submission_error_message = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Stores all the data that will localized for form validation |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - static protected $_js_localization = array(); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * whether or not the form's localized validation JS vars have been set |
|
| 62 | - * |
|
| 63 | - * @type boolean |
|
| 64 | - */ |
|
| 65 | - static protected $_scripts_localized = false; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | - * so that they know who their parent is, and what name they've been given. |
|
| 72 | - * |
|
| 73 | - * @param array $options_array { |
|
| 74 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | - * and in that order. This is handy if you want |
|
| 77 | - * the subsections to be ordered differently than the default, and if you override |
|
| 78 | - * which fields are shown |
|
| 79 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | - * items from that list of inclusions) |
|
| 83 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | - * @throws \EE_Error |
|
| 86 | - */ |
|
| 87 | - public function __construct($options_array = array()) |
|
| 88 | - { |
|
| 89 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | - $this); |
|
| 91 | - //call parent first, as it may be setting the name |
|
| 92 | - parent::__construct($options_array); |
|
| 93 | - //if they've included subsections in the constructor, add them now |
|
| 94 | - if (isset($options_array['include'])) { |
|
| 95 | - //we are going to make sure we ONLY have those subsections to include |
|
| 96 | - //AND we are going to make sure they're in that specified order |
|
| 97 | - $reordered_subsections = array(); |
|
| 98 | - foreach ($options_array['include'] as $input_name) { |
|
| 99 | - if (isset($this->_subsections[$input_name])) { |
|
| 100 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - $this->_subsections = $reordered_subsections; |
|
| 104 | - } |
|
| 105 | - if (isset($options_array['exclude'])) { |
|
| 106 | - $exclude = $options_array['exclude']; |
|
| 107 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 108 | - } |
|
| 109 | - if (isset($options_array['layout_strategy'])) { |
|
| 110 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 111 | - } |
|
| 112 | - if ( ! $this->_layout_strategy) { |
|
| 113 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 114 | - } |
|
| 115 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 116 | - //ok so we are definitely going to want the forms JS, |
|
| 117 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 118 | - if (did_action('wp_enqueue_scripts') |
|
| 119 | - || did_action('admin_enqueue_scripts') |
|
| 120 | - ) { |
|
| 121 | - //ok so they've constructed this object after when they should have. |
|
| 122 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 123 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 124 | - } else { |
|
| 125 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 126 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | - } |
|
| 128 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 129 | - if (isset($options_array['name'])) { |
|
| 130 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Finishes construction given the parent form section and this form section's name |
|
| 138 | - * |
|
| 139 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 140 | - * @param string $name |
|
| 141 | - * @throws \EE_Error |
|
| 142 | - */ |
|
| 143 | - public function _construct_finalize($parent_form_section, $name) |
|
| 144 | - { |
|
| 145 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 146 | - $this->_set_default_name_if_empty(); |
|
| 147 | - $this->_set_default_html_id_if_empty(); |
|
| 148 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 149 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 150 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 151 | - } else { |
|
| 152 | - throw new EE_Error( |
|
| 153 | - sprintf( |
|
| 154 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 155 | - 'event_espresso'), |
|
| 156 | - $subsection_name, |
|
| 157 | - get_class($this), |
|
| 158 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Gets the layout strategy for this form section |
|
| 170 | - * |
|
| 171 | - * @return EE_Form_Section_Layout_Base |
|
| 172 | - */ |
|
| 173 | - public function get_layout_strategy() |
|
| 174 | - { |
|
| 175 | - return $this->_layout_strategy; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Gets the HTML for a single input for this form section according |
|
| 182 | - * to the layout strategy |
|
| 183 | - * |
|
| 184 | - * @param EE_Form_Input_Base $input |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function get_html_for_input($input) |
|
| 188 | - { |
|
| 189 | - return $this->_layout_strategy->layout_input($input); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * was_submitted - checks if form inputs are present in request data |
|
| 196 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 197 | - * proper form sections and form inputs) |
|
| 198 | - * |
|
| 199 | - * @param null $form_data |
|
| 200 | - * @return boolean |
|
| 201 | - */ |
|
| 202 | - public function was_submitted($form_data = null) |
|
| 203 | - { |
|
| 204 | - return $this->form_data_present_in($form_data); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 211 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 212 | - * |
|
| 213 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 214 | - * However, you CAN supply a different array. |
|
| 215 | - * Consider using set_defaults() instead however. |
|
| 216 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 217 | - * the inputs will have the correct name in the request data for this function |
|
| 218 | - * to find them and populate the form with them. |
|
| 219 | - * If you have a flat form (with only input subsections), |
|
| 220 | - * you can supply a flat array where keys |
|
| 221 | - * are the form input names and values are their values) |
|
| 222 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 223 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 224 | - * But if the data has already been validated |
|
| 225 | - * (eg you validated the data then stored it in the DB) |
|
| 226 | - * you may want to skip this step. |
|
| 227 | - */ |
|
| 228 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 229 | - { |
|
| 230 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 231 | - $validate); |
|
| 232 | - if ($req_data === null) { |
|
| 233 | - $req_data = array_merge($_GET, $_POST); |
|
| 234 | - } |
|
| 235 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 236 | - $this); |
|
| 237 | - $this->_normalize($req_data); |
|
| 238 | - if ($validate) { |
|
| 239 | - $this->_validate(); |
|
| 240 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 241 | - if ( ! $this->is_valid()) { |
|
| 242 | - $this->store_submitted_form_data_in_session(); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * caches the originally submitted input values in the session |
|
| 252 | - * so that they can be used to repopulate the form if it failed validation |
|
| 253 | - * |
|
| 254 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 255 | - */ |
|
| 256 | - protected function store_submitted_form_data_in_session() |
|
| 257 | - { |
|
| 258 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 259 | - array( |
|
| 260 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * retrieves the originally submitted input values in the session |
|
| 269 | - * so that they can be used to repopulate the form if it failed validation |
|
| 270 | - * |
|
| 271 | - * @return array |
|
| 272 | - */ |
|
| 273 | - protected function get_submitted_form_data_from_session() |
|
| 274 | - { |
|
| 275 | - $session = EE_Registry::instance()->SSN; |
|
| 276 | - if ($session instanceof EE_Session) { |
|
| 277 | - return $session->get_session_data( |
|
| 278 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 279 | - ); |
|
| 280 | - } else { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * flushed the originally submitted input values from the session |
|
| 289 | - * |
|
| 290 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 291 | - */ |
|
| 292 | - protected function flush_submitted_form_data_from_session() |
|
| 293 | - { |
|
| 294 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 295 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Populates this form and its subsections with data from the session. |
|
| 303 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 304 | - * validation errors when displaying too) |
|
| 305 | - * Returns true if the form was populated from the session, false otherwise |
|
| 306 | - * |
|
| 307 | - * @return boolean |
|
| 308 | - */ |
|
| 309 | - public function populate_from_session() |
|
| 310 | - { |
|
| 311 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 312 | - if (empty($form_data_in_session)) { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - $this->receive_form_submission($form_data_in_session); |
|
| 316 | - $this->flush_submitted_form_data_from_session(); |
|
| 317 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 318 | - return true; |
|
| 319 | - } else { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Populates the default data for the form, given an array where keys are |
|
| 328 | - * the input names, and values are their values (preferably normalized to be their |
|
| 329 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 330 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 331 | - * the value being an array formatted in teh same way |
|
| 332 | - * |
|
| 333 | - * @param array $default_data |
|
| 334 | - */ |
|
| 335 | - public function populate_defaults($default_data) |
|
| 336 | - { |
|
| 337 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 338 | - if (isset($default_data[$subsection_name])) { |
|
| 339 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 340 | - $subsection->set_default($default_data[$subsection_name]); |
|
| 341 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 342 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * returns true if subsection exists |
|
| 352 | - * |
|
| 353 | - * @param string $name |
|
| 354 | - * @return boolean |
|
| 355 | - */ |
|
| 356 | - public function subsection_exists($name) |
|
| 357 | - { |
|
| 358 | - return isset($this->_subsections[$name]) ? true : false; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Gets the subsection specified by its name |
|
| 365 | - * |
|
| 366 | - * @param string $name |
|
| 367 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 368 | - * so that the inputs will be properly configured. |
|
| 369 | - * However, some client code may be ok |
|
| 370 | - * with construction finalize being called later |
|
| 371 | - * (realizing that the subsections' html names |
|
| 372 | - * might not be set yet, etc.) |
|
| 373 | - * @return EE_Form_Section_Base |
|
| 374 | - * @throws \EE_Error |
|
| 375 | - */ |
|
| 376 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 377 | - { |
|
| 378 | - if ($require_construction_to_be_finalized) { |
|
| 379 | - $this->ensure_construct_finalized_called(); |
|
| 380 | - } |
|
| 381 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Gets all the validatable subsections of this form section |
|
| 388 | - * |
|
| 389 | - * @return EE_Form_Section_Validatable[] |
|
| 390 | - */ |
|
| 391 | - public function get_validatable_subsections() |
|
| 392 | - { |
|
| 393 | - $validatable_subsections = array(); |
|
| 394 | - foreach ($this->subsections() as $name => $obj) { |
|
| 395 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 396 | - $validatable_subsections[$name] = $obj; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - return $validatable_subsections; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 406 | - * throw an EE_Error. |
|
| 407 | - * |
|
| 408 | - * @param string $name |
|
| 409 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 410 | - * leave this as TRUE so that the inputs will be properly |
|
| 411 | - * configured. However, some client code may be ok with |
|
| 412 | - * construction finalize being called later |
|
| 413 | - * (realizing that the subsections' html names might not be |
|
| 414 | - * set yet, etc.) |
|
| 415 | - * @return EE_Form_Input_Base |
|
| 416 | - * @throws EE_Error |
|
| 417 | - */ |
|
| 418 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 419 | - { |
|
| 420 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 421 | - if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 422 | - throw new EE_Error( |
|
| 423 | - sprintf( |
|
| 424 | - __( |
|
| 425 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 426 | - 'event_espresso' |
|
| 427 | - ), |
|
| 428 | - $name, |
|
| 429 | - get_class($this), |
|
| 430 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 431 | - ) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return $subsection; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 441 | - * otherwise throws an EE_Error |
|
| 442 | - * |
|
| 443 | - * @param string $name |
|
| 444 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 445 | - * leave this as TRUE so that the inputs will be properly |
|
| 446 | - * configured. However, some client code may be ok with |
|
| 447 | - * construction finalize being called later |
|
| 448 | - * (realizing that the subsections' html names might not be |
|
| 449 | - * set yet, etc.) |
|
| 450 | - * @return EE_Form_Section_Proper |
|
| 451 | - * @throws EE_Error |
|
| 452 | - */ |
|
| 453 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 454 | - { |
|
| 455 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 456 | - if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 457 | - throw new EE_Error( |
|
| 458 | - sprintf( |
|
| 459 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 460 | - $name, |
|
| 461 | - get_class($this) |
|
| 462 | - ) |
|
| 463 | - ); |
|
| 464 | - } |
|
| 465 | - return $subsection; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 472 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 473 | - * |
|
| 474 | - * @param string $name |
|
| 475 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 476 | - * @throws \EE_Error |
|
| 477 | - */ |
|
| 478 | - public function get_input_value($name) |
|
| 479 | - { |
|
| 480 | - $input = $this->get_input($name); |
|
| 481 | - return $input->normalized_value(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 488 | - * |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @return boolean |
|
| 491 | - */ |
|
| 492 | - public function is_valid() |
|
| 493 | - { |
|
| 494 | - if ( ! $this->has_received_submission()) { |
|
| 495 | - throw new EE_Error( |
|
| 496 | - sprintf( |
|
| 497 | - __( |
|
| 498 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 499 | - "event_espresso" |
|
| 500 | - ) |
|
| 501 | - ) |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - if ( ! parent::is_valid()) { |
|
| 505 | - return false; |
|
| 506 | - } |
|
| 507 | - // ok so no general errors to this entire form section. |
|
| 508 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 509 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 510 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 511 | - if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 512 | - if ($set_submission_errors) { |
|
| 513 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 514 | - } |
|
| 515 | - return false; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - return true; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * gets teh default name of this form section if none is specified |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - */ |
|
| 528 | - protected function _set_default_name_if_empty() |
|
| 529 | - { |
|
| 530 | - if ( ! $this->_name) { |
|
| 531 | - $classname = get_class($this); |
|
| 532 | - $default_name = str_replace("EE_", "", $classname); |
|
| 533 | - $this->_name = $default_name; |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Returns the JS for validating the form (and subsections) inside script tags. |
|
| 541 | - * Also returns the HTML for the form, except for the form opening and closing tags |
|
| 542 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 543 | - * and except for a submit button. |
|
| 544 | - * |
|
| 545 | - * @deprecated since 4.9.0. You should instead call enqueue_js during the "wp_enqueue_scripts" |
|
| 546 | - * and get_html when you are about to display the form. |
|
| 547 | - * @throws \EE_Error |
|
| 548 | - */ |
|
| 549 | - public function get_html_and_js() |
|
| 550 | - { |
|
| 551 | - //no doing_it_wrong yet because we ourselves are still doing it wrong... |
|
| 552 | - //and theoretically this CAN be used properly, provided its used during "wp_enqueue_scripts" |
|
| 553 | - $this->enqueue_js(); |
|
| 554 | - return $this->get_html(); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 561 | - * |
|
| 562 | - * @param bool $display_previously_submitted_data |
|
| 563 | - * @return string |
|
| 564 | - */ |
|
| 565 | - public function get_html($display_previously_submitted_data = true) |
|
| 566 | - { |
|
| 567 | - $this->ensure_construct_finalized_called(); |
|
| 568 | - if ($display_previously_submitted_data) { |
|
| 569 | - $this->populate_from_session(); |
|
| 570 | - } |
|
| 571 | - return $this->_layout_strategy->layout_form(); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * enqueues JS for the form |
|
| 578 | - * |
|
| 579 | - * @return string |
|
| 580 | - * @throws \EE_Error |
|
| 581 | - */ |
|
| 582 | - public function enqueue_js() |
|
| 583 | - { |
|
| 584 | - $this->_enqueue_and_localize_form_js(); |
|
| 585 | - foreach ($this->subsections() as $subsection) { |
|
| 586 | - $subsection->enqueue_js(); |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 594 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 595 | - * the wp_enqueue_scripts hook. |
|
| 596 | - * However, registering the form js and localizing it can happen when we |
|
| 597 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 598 | - * could change until it's actually outputted) |
|
| 599 | - * |
|
| 600 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 601 | - * to be triggered automatically or not |
|
| 602 | - * @return void |
|
| 603 | - */ |
|
| 604 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 605 | - { |
|
| 606 | - add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 607 | - wp_register_script( |
|
| 608 | - 'ee_form_section_validation', |
|
| 609 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 610 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 611 | - EVENT_ESPRESSO_VERSION, |
|
| 612 | - true |
|
| 613 | - ); |
|
| 614 | - wp_localize_script( |
|
| 615 | - 'ee_form_section_validation', |
|
| 616 | - 'ee_form_section_validation_init', |
|
| 617 | - array('init' => $init_form_validation_automatically ? true : false) |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * gets the variables used by form_section_validation.js. |
|
| 625 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 626 | - * but before the wordpress hook wp_loaded |
|
| 627 | - * |
|
| 628 | - * @throws \EE_Error |
|
| 629 | - */ |
|
| 630 | - public function _enqueue_and_localize_form_js() |
|
| 631 | - { |
|
| 632 | - $this->ensure_construct_finalized_called(); |
|
| 633 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 634 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
| 635 | - //and localize it just before the footer |
|
| 636 | - $this->localize_validation_rules(); |
|
| 637 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 638 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * add our form section data to a static variable accessible by all form sections |
|
| 645 | - * |
|
| 646 | - * @param bool $return_for_subsection |
|
| 647 | - * @return void |
|
| 648 | - * @throws \EE_Error |
|
| 649 | - */ |
|
| 650 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 651 | - { |
|
| 652 | - // we only want to localize vars ONCE for the entire form, |
|
| 653 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 654 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 655 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 656 | - 'form_section_id' => $this->html_id(true), |
|
| 657 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 658 | - 'other_data' => $this->get_other_js_data(), |
|
| 659 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 660 | - ); |
|
| 661 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 669 | - * This is primarily data added by inputs and forms in addition to any |
|
| 670 | - * scripts they might enqueue |
|
| 671 | - * |
|
| 672 | - * @param array $form_other_js_data |
|
| 673 | - * @return array |
|
| 674 | - */ |
|
| 675 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 676 | - { |
|
| 677 | - foreach ($this->subsections() as $subsection) { |
|
| 678 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 679 | - } |
|
| 680 | - return $form_other_js_data; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 687 | - * Keys are their form names, and values are the inputs themselves |
|
| 688 | - * |
|
| 689 | - * @return EE_Form_Input_Base |
|
| 690 | - */ |
|
| 691 | - public function inputs_in_subsections() |
|
| 692 | - { |
|
| 693 | - $inputs = array(); |
|
| 694 | - foreach ($this->subsections() as $subsection) { |
|
| 695 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 696 | - $inputs[$subsection->html_name()] = $subsection; |
|
| 697 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 698 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - return $inputs; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Gets a flat array of all the validation errors. |
|
| 708 | - * Keys are html names (because those should be unique) |
|
| 709 | - * and values are a string of all their validation errors |
|
| 710 | - * |
|
| 711 | - * @return string[] |
|
| 712 | - */ |
|
| 713 | - public function subsection_validation_errors_by_html_name() |
|
| 714 | - { |
|
| 715 | - $inputs = $this->inputs(); |
|
| 716 | - $errors = array(); |
|
| 717 | - foreach ($inputs as $form_input) { |
|
| 718 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 719 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - return $errors; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 729 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 730 | - */ |
|
| 731 | - public static function localize_script_for_all_forms() |
|
| 732 | - { |
|
| 733 | - //allow inputs and stuff to hook in their JS and stuff here |
|
| 734 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 735 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 736 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 737 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 738 | - : 'wp_default'; |
|
| 739 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 740 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 741 | - wp_localize_script( |
|
| 742 | - 'ee_form_section_validation', |
|
| 743 | - 'ee_form_section_vars', |
|
| 744 | - EE_Form_Section_Proper::$_js_localization |
|
| 745 | - ); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * ensure_scripts_localized |
|
| 752 | - */ |
|
| 753 | - public function ensure_scripts_localized() |
|
| 754 | - { |
|
| 755 | - if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 756 | - $this->_enqueue_and_localize_form_js(); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 764 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 765 | - * |
|
| 766 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 767 | - */ |
|
| 768 | - private static function _get_localized_error_messages() |
|
| 769 | - { |
|
| 770 | - return array( |
|
| 771 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 772 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
| 773 | - ); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * @return array |
|
| 780 | - */ |
|
| 781 | - public static function js_localization() |
|
| 782 | - { |
|
| 783 | - return self::$_js_localization; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * @return array |
|
| 790 | - */ |
|
| 791 | - public static function reset_js_localization() |
|
| 792 | - { |
|
| 793 | - self::$_js_localization = array(); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 800 | - * See parent function for more... |
|
| 801 | - * |
|
| 802 | - * @return array |
|
| 803 | - */ |
|
| 804 | - public function get_jquery_validation_rules() |
|
| 805 | - { |
|
| 806 | - $jquery_validation_rules = array(); |
|
| 807 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 808 | - $jquery_validation_rules = array_merge( |
|
| 809 | - $jquery_validation_rules, |
|
| 810 | - $subsection->get_jquery_validation_rules() |
|
| 811 | - ); |
|
| 812 | - } |
|
| 813 | - return $jquery_validation_rules; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 820 | - * |
|
| 821 | - * @param array $req_data like $_POST |
|
| 822 | - * @return void |
|
| 823 | - */ |
|
| 824 | - protected function _normalize($req_data) |
|
| 825 | - { |
|
| 826 | - $this->_received_submission = true; |
|
| 827 | - $this->_validation_errors = array(); |
|
| 828 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 829 | - try { |
|
| 830 | - $subsection->_normalize($req_data); |
|
| 831 | - } catch (EE_Validation_Error $e) { |
|
| 832 | - $subsection->add_validation_error($e); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * Performs validation on this form section and its subsections. |
|
| 841 | - * For each subsection, |
|
| 842 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 843 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 844 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 845 | - * you would be best to override this _validate method, |
|
| 846 | - * calling parent::_validate() first. |
|
| 847 | - */ |
|
| 848 | - protected function _validate() |
|
| 849 | - { |
|
| 850 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 851 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 852 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 853 | - } |
|
| 854 | - $subsection->_validate(); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Gets all the validated inputs for the form section |
|
| 862 | - * |
|
| 863 | - * @return array |
|
| 864 | - */ |
|
| 865 | - public function valid_data() |
|
| 866 | - { |
|
| 867 | - $inputs = array(); |
|
| 868 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 869 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 870 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 871 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 872 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - return $inputs; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Gets all the inputs on this form section |
|
| 882 | - * |
|
| 883 | - * @return EE_Form_Input_Base[] |
|
| 884 | - */ |
|
| 885 | - public function inputs() |
|
| 886 | - { |
|
| 887 | - $inputs = array(); |
|
| 888 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 889 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 890 | - $inputs[$subsection_name] = $subsection; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - return $inputs; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * Gets all the subsections which are a proper form |
|
| 900 | - * |
|
| 901 | - * @return EE_Form_Section_Proper[] |
|
| 902 | - */ |
|
| 903 | - public function subforms() |
|
| 904 | - { |
|
| 905 | - $form_sections = array(); |
|
| 906 | - foreach ($this->subsections() as $name => $obj) { |
|
| 907 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 908 | - $form_sections[$name] = $obj; |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - return $form_sections; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 918 | - * Consider using inputs() or subforms() |
|
| 919 | - * if you only want form inputs or proper form sections. |
|
| 920 | - * |
|
| 921 | - * @return EE_Form_Section_Proper[] |
|
| 922 | - */ |
|
| 923 | - public function subsections() |
|
| 924 | - { |
|
| 925 | - $this->ensure_construct_finalized_called(); |
|
| 926 | - return $this->_subsections; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 933 | - * values. (Similar to calling get_input_value on inputs) |
|
| 934 | - * |
|
| 935 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 936 | - * or just this forms' direct children inputs |
|
| 937 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 938 | - * or allow multidimensional array |
|
| 939 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 940 | - * with array keys being input names |
|
| 941 | - * (regardless of whether they are from a subsection or not), |
|
| 942 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 943 | - * where keys are always subsection names and values are either |
|
| 944 | - * the input's normalized value, or an array like the top-level array |
|
| 945 | - */ |
|
| 946 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 947 | - { |
|
| 948 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 955 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 956 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 957 | - * where keys are the input names, and values are their display values |
|
| 958 | - * |
|
| 959 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 960 | - * or just this forms' direct children inputs |
|
| 961 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 962 | - * or allow multidimensional array |
|
| 963 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 964 | - * with array keys being input names |
|
| 965 | - * (regardless of whether they are from a subsection or not), |
|
| 966 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 967 | - * where keys are always subsection names and values are either |
|
| 968 | - * the input's normalized value, or an array like the top-level array |
|
| 969 | - */ |
|
| 970 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 971 | - { |
|
| 972 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * Gets the input values from the form |
|
| 979 | - * |
|
| 980 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 981 | - * or just the normalized value |
|
| 982 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 983 | - * or just this forms' direct children inputs |
|
| 984 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 985 | - * or allow multidimensional array |
|
| 986 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 987 | - * input names (regardless of whether they are from a subsection or not), |
|
| 988 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 989 | - * where keys are always subsection names and values are either |
|
| 990 | - * the input's normalized value, or an array like the top-level array |
|
| 991 | - */ |
|
| 992 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 993 | - { |
|
| 994 | - $input_values = array(); |
|
| 995 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 996 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 997 | - $input_values[$subsection_name] = $pretty |
|
| 998 | - ? $subsection->pretty_value() |
|
| 999 | - : $subsection->normalized_value(); |
|
| 1000 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1001 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1002 | - if ($flatten) { |
|
| 1003 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1004 | - } else { |
|
| 1005 | - $input_values[$subsection_name] = $subform_input_values; |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 1008 | - } |
|
| 1009 | - return $input_values; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Gets the originally submitted input values from the form |
|
| 1016 | - * |
|
| 1017 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1018 | - * or just this forms' direct children inputs |
|
| 1019 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1020 | - * with array keys being input names |
|
| 1021 | - * (regardless of whether they are from a subsection or not), |
|
| 1022 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1023 | - * where keys are always subsection names and values are either |
|
| 1024 | - * the input's normalized value, or an array like the top-level array |
|
| 1025 | - */ |
|
| 1026 | - public function submitted_values($include_subforms = false) |
|
| 1027 | - { |
|
| 1028 | - $submitted_values = array(); |
|
| 1029 | - foreach ($this->subsections() as $subsection) { |
|
| 1030 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1031 | - // is this input part of an array of inputs? |
|
| 1032 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1033 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1034 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1035 | - $subsection->raw_value() |
|
| 1036 | - ); |
|
| 1037 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1038 | - } else { |
|
| 1039 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1040 | - } |
|
| 1041 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1042 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1043 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - return $submitted_values; |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * Indicates whether or not this form has received a submission yet |
|
| 1053 | - * (ie, had receive_form_submission called on it yet) |
|
| 1054 | - * |
|
| 1055 | - * @return boolean |
|
| 1056 | - * @throws \EE_Error |
|
| 1057 | - */ |
|
| 1058 | - public function has_received_submission() |
|
| 1059 | - { |
|
| 1060 | - $this->ensure_construct_finalized_called(); |
|
| 1061 | - return $this->_received_submission; |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1068 | - * Removes the listed inputs from the form |
|
| 1069 | - * |
|
| 1070 | - * @param array $inputs_to_exclude values are the input names |
|
| 1071 | - * @return void |
|
| 1072 | - */ |
|
| 1073 | - public function exclude($inputs_to_exclude = array()) |
|
| 1074 | - { |
|
| 1075 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1076 | - unset($this->_subsections[$input_to_exclude_name]); |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - /** |
|
| 1083 | - * @param array $inputs_to_hide |
|
| 1084 | - * @throws \EE_Error |
|
| 1085 | - */ |
|
| 1086 | - public function hide($inputs_to_hide = array()) |
|
| 1087 | - { |
|
| 1088 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1089 | - $input = $this->get_input($input_to_hide); |
|
| 1090 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * add_subsections |
|
| 1098 | - * Adds the listed subsections to the form section. |
|
| 1099 | - * If $subsection_name_to_target is provided, |
|
| 1100 | - * then new subsections are added before or after that subsection, |
|
| 1101 | - * otherwise to the start or end of the entire subsections array. |
|
| 1102 | - * |
|
| 1103 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1104 | - * where keys are their names |
|
| 1105 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1106 | - * should be added before or after |
|
| 1107 | - * IF $subsection_name_to_target is null, |
|
| 1108 | - * then $new_subsections will be added to |
|
| 1109 | - * the beginning or end of the entire subsections array |
|
| 1110 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1111 | - * $subsection_name_to_target, |
|
| 1112 | - * or if $subsection_name_to_target is null, |
|
| 1113 | - * before or after entire subsections array |
|
| 1114 | - * @return void |
|
| 1115 | - * @throws \EE_Error |
|
| 1116 | - */ |
|
| 1117 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1118 | - { |
|
| 1119 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1120 | - if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1121 | - EE_Error::add_error( |
|
| 1122 | - sprintf( |
|
| 1123 | - __( |
|
| 1124 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1125 | - "event_espresso" |
|
| 1126 | - ), |
|
| 1127 | - get_class($subsection), |
|
| 1128 | - $subsection_name, |
|
| 1129 | - $this->name() |
|
| 1130 | - ) |
|
| 1131 | - ); |
|
| 1132 | - unset($new_subsections[$subsection_name]); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1136 | - $this->_subsections, |
|
| 1137 | - $new_subsections, |
|
| 1138 | - $subsection_name_to_target, |
|
| 1139 | - $add_before |
|
| 1140 | - ); |
|
| 1141 | - if ($this->_construction_finalized) { |
|
| 1142 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1143 | - $subsection->_construct_finalize($this, $name); |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1152 | - */ |
|
| 1153 | - public function clean_sensitive_data() |
|
| 1154 | - { |
|
| 1155 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1156 | - $subsection->clean_sensitive_data(); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - |
|
| 1161 | - |
|
| 1162 | - /** |
|
| 1163 | - * @param string $form_submission_error_message |
|
| 1164 | - */ |
|
| 1165 | - public function set_submission_error_message($form_submission_error_message = '') |
|
| 1166 | - { |
|
| 1167 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1168 | - ? $form_submission_error_message |
|
| 1169 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * @return string |
|
| 1176 | - */ |
|
| 1177 | - public function submission_error_message() |
|
| 1178 | - { |
|
| 1179 | - return $this->_form_submission_error_message; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * @param string $form_submission_success_message |
|
| 1186 | - */ |
|
| 1187 | - public function set_submission_success_message($form_submission_success_message) |
|
| 1188 | - { |
|
| 1189 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1190 | - ? $form_submission_success_message |
|
| 1191 | - : __('Form submitted successfully', 'event_espresso'); |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * @return string |
|
| 1198 | - */ |
|
| 1199 | - public function submission_success_message() |
|
| 1200 | - { |
|
| 1201 | - return $this->_form_submission_success_message; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * Returns the prefix that should be used on child of this form section for |
|
| 1208 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1209 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1210 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1211 | - * |
|
| 1212 | - * @return string |
|
| 1213 | - * @throws \EE_Error |
|
| 1214 | - */ |
|
| 1215 | - public function html_name_prefix() |
|
| 1216 | - { |
|
| 1217 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1218 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1219 | - } else { |
|
| 1220 | - return $this->name(); |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - /** |
|
| 1227 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1228 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1229 | - * was set, which is probably nothing, or the classname) |
|
| 1230 | - * |
|
| 1231 | - * @return string |
|
| 1232 | - * @throws \EE_Error |
|
| 1233 | - */ |
|
| 1234 | - public function name() |
|
| 1235 | - { |
|
| 1236 | - $this->ensure_construct_finalized_called(); |
|
| 1237 | - return parent::name(); |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - /** |
|
| 1243 | - * @return EE_Form_Section_Proper |
|
| 1244 | - * @throws \EE_Error |
|
| 1245 | - */ |
|
| 1246 | - public function parent_section() |
|
| 1247 | - { |
|
| 1248 | - $this->ensure_construct_finalized_called(); |
|
| 1249 | - return parent::parent_section(); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1256 | - * |
|
| 1257 | - * @return void |
|
| 1258 | - * @throws \EE_Error |
|
| 1259 | - */ |
|
| 1260 | - public function ensure_construct_finalized_called() |
|
| 1261 | - { |
|
| 1262 | - if ( ! $this->_construction_finalized) { |
|
| 1263 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1271 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1272 | - * |
|
| 1273 | - * @param array $req_data |
|
| 1274 | - * @return boolean |
|
| 1275 | - */ |
|
| 1276 | - public function form_data_present_in($req_data = null) |
|
| 1277 | - { |
|
| 1278 | - if ($req_data === null) { |
|
| 1279 | - $req_data = $_POST; |
|
| 1280 | - } |
|
| 1281 | - foreach ($this->subsections() as $subsection) { |
|
| 1282 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1283 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1284 | - return true; |
|
| 1285 | - } |
|
| 1286 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1287 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1288 | - return true; |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - } |
|
| 1292 | - return false; |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - |
|
| 1297 | - /** |
|
| 1298 | - * Gets validation errors for this form section and subsections |
|
| 1299 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1300 | - * gets the validation errors for ALL subsection |
|
| 1301 | - * |
|
| 1302 | - * @return EE_Validation_Error[] |
|
| 1303 | - */ |
|
| 1304 | - public function get_validation_errors_accumulated() |
|
| 1305 | - { |
|
| 1306 | - $validation_errors = $this->get_validation_errors(); |
|
| 1307 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1308 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1309 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1310 | - } else { |
|
| 1311 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1312 | - } |
|
| 1313 | - if ($validation_errors_on_this_subsection) { |
|
| 1314 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - return $validation_errors; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1324 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1325 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1326 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1327 | - * which will be returned. |
|
| 1328 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1329 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1330 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1331 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1332 | - * Etc |
|
| 1333 | - * |
|
| 1334 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1335 | - * @return EE_Form_Section_Base |
|
| 1336 | - */ |
|
| 1337 | - public function find_section_from_path($form_section_path) |
|
| 1338 | - { |
|
| 1339 | - //check if we can find the input from purely going straight up the tree |
|
| 1340 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1341 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1342 | - return $input; |
|
| 1343 | - } |
|
| 1344 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1345 | - if ($next_slash_pos !== false) { |
|
| 1346 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1347 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1348 | - } else { |
|
| 1349 | - $child_section_name = $form_section_path; |
|
| 1350 | - $subpath = ''; |
|
| 1351 | - } |
|
| 1352 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1353 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1354 | - return $child_section->find_section_from_path($subpath); |
|
| 1355 | - } else { |
|
| 1356 | - return null; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 16 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Subsections |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Validatable[] |
|
| 22 | + */ |
|
| 23 | + protected $_subsections = array(); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Strategy for laying out the form |
|
| 27 | + * |
|
| 28 | + * @var EE_Form_Section_Layout_Base |
|
| 29 | + */ |
|
| 30 | + protected $_layout_strategy; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Whether or not this form has received and validated a form submission yet |
|
| 34 | + * |
|
| 35 | + * @var boolean |
|
| 36 | + */ |
|
| 37 | + protected $_received_submission = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * message displayed to users upon successful form submission |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + protected $_form_submission_success_message = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * message displayed to users upon unsuccessful form submission |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + protected $_form_submission_error_message = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Stores all the data that will localized for form validation |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + static protected $_js_localization = array(); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * whether or not the form's localized validation JS vars have been set |
|
| 62 | + * |
|
| 63 | + * @type boolean |
|
| 64 | + */ |
|
| 65 | + static protected $_scripts_localized = false; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | + * so that they know who their parent is, and what name they've been given. |
|
| 72 | + * |
|
| 73 | + * @param array $options_array { |
|
| 74 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | + * and in that order. This is handy if you want |
|
| 77 | + * the subsections to be ordered differently than the default, and if you override |
|
| 78 | + * which fields are shown |
|
| 79 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | + * items from that list of inclusions) |
|
| 83 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | + * @throws \EE_Error |
|
| 86 | + */ |
|
| 87 | + public function __construct($options_array = array()) |
|
| 88 | + { |
|
| 89 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
| 90 | + $this); |
|
| 91 | + //call parent first, as it may be setting the name |
|
| 92 | + parent::__construct($options_array); |
|
| 93 | + //if they've included subsections in the constructor, add them now |
|
| 94 | + if (isset($options_array['include'])) { |
|
| 95 | + //we are going to make sure we ONLY have those subsections to include |
|
| 96 | + //AND we are going to make sure they're in that specified order |
|
| 97 | + $reordered_subsections = array(); |
|
| 98 | + foreach ($options_array['include'] as $input_name) { |
|
| 99 | + if (isset($this->_subsections[$input_name])) { |
|
| 100 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + $this->_subsections = $reordered_subsections; |
|
| 104 | + } |
|
| 105 | + if (isset($options_array['exclude'])) { |
|
| 106 | + $exclude = $options_array['exclude']; |
|
| 107 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 108 | + } |
|
| 109 | + if (isset($options_array['layout_strategy'])) { |
|
| 110 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 111 | + } |
|
| 112 | + if ( ! $this->_layout_strategy) { |
|
| 113 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 114 | + } |
|
| 115 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 116 | + //ok so we are definitely going to want the forms JS, |
|
| 117 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 118 | + if (did_action('wp_enqueue_scripts') |
|
| 119 | + || did_action('admin_enqueue_scripts') |
|
| 120 | + ) { |
|
| 121 | + //ok so they've constructed this object after when they should have. |
|
| 122 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 123 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 124 | + } else { |
|
| 125 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 126 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | + } |
|
| 128 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 129 | + if (isset($options_array['name'])) { |
|
| 130 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Finishes construction given the parent form section and this form section's name |
|
| 138 | + * |
|
| 139 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 140 | + * @param string $name |
|
| 141 | + * @throws \EE_Error |
|
| 142 | + */ |
|
| 143 | + public function _construct_finalize($parent_form_section, $name) |
|
| 144 | + { |
|
| 145 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 146 | + $this->_set_default_name_if_empty(); |
|
| 147 | + $this->_set_default_html_id_if_empty(); |
|
| 148 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 149 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 150 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 151 | + } else { |
|
| 152 | + throw new EE_Error( |
|
| 153 | + sprintf( |
|
| 154 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 155 | + 'event_espresso'), |
|
| 156 | + $subsection_name, |
|
| 157 | + get_class($this), |
|
| 158 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Gets the layout strategy for this form section |
|
| 170 | + * |
|
| 171 | + * @return EE_Form_Section_Layout_Base |
|
| 172 | + */ |
|
| 173 | + public function get_layout_strategy() |
|
| 174 | + { |
|
| 175 | + return $this->_layout_strategy; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Gets the HTML for a single input for this form section according |
|
| 182 | + * to the layout strategy |
|
| 183 | + * |
|
| 184 | + * @param EE_Form_Input_Base $input |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function get_html_for_input($input) |
|
| 188 | + { |
|
| 189 | + return $this->_layout_strategy->layout_input($input); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * was_submitted - checks if form inputs are present in request data |
|
| 196 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 197 | + * proper form sections and form inputs) |
|
| 198 | + * |
|
| 199 | + * @param null $form_data |
|
| 200 | + * @return boolean |
|
| 201 | + */ |
|
| 202 | + public function was_submitted($form_data = null) |
|
| 203 | + { |
|
| 204 | + return $this->form_data_present_in($form_data); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 211 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 212 | + * |
|
| 213 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 214 | + * However, you CAN supply a different array. |
|
| 215 | + * Consider using set_defaults() instead however. |
|
| 216 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 217 | + * the inputs will have the correct name in the request data for this function |
|
| 218 | + * to find them and populate the form with them. |
|
| 219 | + * If you have a flat form (with only input subsections), |
|
| 220 | + * you can supply a flat array where keys |
|
| 221 | + * are the form input names and values are their values) |
|
| 222 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 223 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 224 | + * But if the data has already been validated |
|
| 225 | + * (eg you validated the data then stored it in the DB) |
|
| 226 | + * you may want to skip this step. |
|
| 227 | + */ |
|
| 228 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 229 | + { |
|
| 230 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
| 231 | + $validate); |
|
| 232 | + if ($req_data === null) { |
|
| 233 | + $req_data = array_merge($_GET, $_POST); |
|
| 234 | + } |
|
| 235 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
| 236 | + $this); |
|
| 237 | + $this->_normalize($req_data); |
|
| 238 | + if ($validate) { |
|
| 239 | + $this->_validate(); |
|
| 240 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 241 | + if ( ! $this->is_valid()) { |
|
| 242 | + $this->store_submitted_form_data_in_session(); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * caches the originally submitted input values in the session |
|
| 252 | + * so that they can be used to repopulate the form if it failed validation |
|
| 253 | + * |
|
| 254 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 255 | + */ |
|
| 256 | + protected function store_submitted_form_data_in_session() |
|
| 257 | + { |
|
| 258 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 259 | + array( |
|
| 260 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * retrieves the originally submitted input values in the session |
|
| 269 | + * so that they can be used to repopulate the form if it failed validation |
|
| 270 | + * |
|
| 271 | + * @return array |
|
| 272 | + */ |
|
| 273 | + protected function get_submitted_form_data_from_session() |
|
| 274 | + { |
|
| 275 | + $session = EE_Registry::instance()->SSN; |
|
| 276 | + if ($session instanceof EE_Session) { |
|
| 277 | + return $session->get_session_data( |
|
| 278 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 279 | + ); |
|
| 280 | + } else { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * flushed the originally submitted input values from the session |
|
| 289 | + * |
|
| 290 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 291 | + */ |
|
| 292 | + protected function flush_submitted_form_data_from_session() |
|
| 293 | + { |
|
| 294 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 295 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Populates this form and its subsections with data from the session. |
|
| 303 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 304 | + * validation errors when displaying too) |
|
| 305 | + * Returns true if the form was populated from the session, false otherwise |
|
| 306 | + * |
|
| 307 | + * @return boolean |
|
| 308 | + */ |
|
| 309 | + public function populate_from_session() |
|
| 310 | + { |
|
| 311 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 312 | + if (empty($form_data_in_session)) { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + $this->receive_form_submission($form_data_in_session); |
|
| 316 | + $this->flush_submitted_form_data_from_session(); |
|
| 317 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 318 | + return true; |
|
| 319 | + } else { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Populates the default data for the form, given an array where keys are |
|
| 328 | + * the input names, and values are their values (preferably normalized to be their |
|
| 329 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 330 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 331 | + * the value being an array formatted in teh same way |
|
| 332 | + * |
|
| 333 | + * @param array $default_data |
|
| 334 | + */ |
|
| 335 | + public function populate_defaults($default_data) |
|
| 336 | + { |
|
| 337 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 338 | + if (isset($default_data[$subsection_name])) { |
|
| 339 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 340 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 341 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 342 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * returns true if subsection exists |
|
| 352 | + * |
|
| 353 | + * @param string $name |
|
| 354 | + * @return boolean |
|
| 355 | + */ |
|
| 356 | + public function subsection_exists($name) |
|
| 357 | + { |
|
| 358 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Gets the subsection specified by its name |
|
| 365 | + * |
|
| 366 | + * @param string $name |
|
| 367 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 368 | + * so that the inputs will be properly configured. |
|
| 369 | + * However, some client code may be ok |
|
| 370 | + * with construction finalize being called later |
|
| 371 | + * (realizing that the subsections' html names |
|
| 372 | + * might not be set yet, etc.) |
|
| 373 | + * @return EE_Form_Section_Base |
|
| 374 | + * @throws \EE_Error |
|
| 375 | + */ |
|
| 376 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 377 | + { |
|
| 378 | + if ($require_construction_to_be_finalized) { |
|
| 379 | + $this->ensure_construct_finalized_called(); |
|
| 380 | + } |
|
| 381 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Gets all the validatable subsections of this form section |
|
| 388 | + * |
|
| 389 | + * @return EE_Form_Section_Validatable[] |
|
| 390 | + */ |
|
| 391 | + public function get_validatable_subsections() |
|
| 392 | + { |
|
| 393 | + $validatable_subsections = array(); |
|
| 394 | + foreach ($this->subsections() as $name => $obj) { |
|
| 395 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 396 | + $validatable_subsections[$name] = $obj; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + return $validatable_subsections; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 406 | + * throw an EE_Error. |
|
| 407 | + * |
|
| 408 | + * @param string $name |
|
| 409 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 410 | + * leave this as TRUE so that the inputs will be properly |
|
| 411 | + * configured. However, some client code may be ok with |
|
| 412 | + * construction finalize being called later |
|
| 413 | + * (realizing that the subsections' html names might not be |
|
| 414 | + * set yet, etc.) |
|
| 415 | + * @return EE_Form_Input_Base |
|
| 416 | + * @throws EE_Error |
|
| 417 | + */ |
|
| 418 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 419 | + { |
|
| 420 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 421 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 422 | + throw new EE_Error( |
|
| 423 | + sprintf( |
|
| 424 | + __( |
|
| 425 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 426 | + 'event_espresso' |
|
| 427 | + ), |
|
| 428 | + $name, |
|
| 429 | + get_class($this), |
|
| 430 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
| 431 | + ) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return $subsection; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 441 | + * otherwise throws an EE_Error |
|
| 442 | + * |
|
| 443 | + * @param string $name |
|
| 444 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 445 | + * leave this as TRUE so that the inputs will be properly |
|
| 446 | + * configured. However, some client code may be ok with |
|
| 447 | + * construction finalize being called later |
|
| 448 | + * (realizing that the subsections' html names might not be |
|
| 449 | + * set yet, etc.) |
|
| 450 | + * @return EE_Form_Section_Proper |
|
| 451 | + * @throws EE_Error |
|
| 452 | + */ |
|
| 453 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 454 | + { |
|
| 455 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
| 456 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 457 | + throw new EE_Error( |
|
| 458 | + sprintf( |
|
| 459 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
| 460 | + $name, |
|
| 461 | + get_class($this) |
|
| 462 | + ) |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | + return $subsection; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 472 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 473 | + * |
|
| 474 | + * @param string $name |
|
| 475 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 476 | + * @throws \EE_Error |
|
| 477 | + */ |
|
| 478 | + public function get_input_value($name) |
|
| 479 | + { |
|
| 480 | + $input = $this->get_input($name); |
|
| 481 | + return $input->normalized_value(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 488 | + * |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @return boolean |
|
| 491 | + */ |
|
| 492 | + public function is_valid() |
|
| 493 | + { |
|
| 494 | + if ( ! $this->has_received_submission()) { |
|
| 495 | + throw new EE_Error( |
|
| 496 | + sprintf( |
|
| 497 | + __( |
|
| 498 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
| 499 | + "event_espresso" |
|
| 500 | + ) |
|
| 501 | + ) |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + if ( ! parent::is_valid()) { |
|
| 505 | + return false; |
|
| 506 | + } |
|
| 507 | + // ok so no general errors to this entire form section. |
|
| 508 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 509 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
| 510 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 511 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 512 | + if ($set_submission_errors) { |
|
| 513 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
| 514 | + } |
|
| 515 | + return false; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + return true; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * gets teh default name of this form section if none is specified |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + */ |
|
| 528 | + protected function _set_default_name_if_empty() |
|
| 529 | + { |
|
| 530 | + if ( ! $this->_name) { |
|
| 531 | + $classname = get_class($this); |
|
| 532 | + $default_name = str_replace("EE_", "", $classname); |
|
| 533 | + $this->_name = $default_name; |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Returns the JS for validating the form (and subsections) inside script tags. |
|
| 541 | + * Also returns the HTML for the form, except for the form opening and closing tags |
|
| 542 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 543 | + * and except for a submit button. |
|
| 544 | + * |
|
| 545 | + * @deprecated since 4.9.0. You should instead call enqueue_js during the "wp_enqueue_scripts" |
|
| 546 | + * and get_html when you are about to display the form. |
|
| 547 | + * @throws \EE_Error |
|
| 548 | + */ |
|
| 549 | + public function get_html_and_js() |
|
| 550 | + { |
|
| 551 | + //no doing_it_wrong yet because we ourselves are still doing it wrong... |
|
| 552 | + //and theoretically this CAN be used properly, provided its used during "wp_enqueue_scripts" |
|
| 553 | + $this->enqueue_js(); |
|
| 554 | + return $this->get_html(); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 561 | + * |
|
| 562 | + * @param bool $display_previously_submitted_data |
|
| 563 | + * @return string |
|
| 564 | + */ |
|
| 565 | + public function get_html($display_previously_submitted_data = true) |
|
| 566 | + { |
|
| 567 | + $this->ensure_construct_finalized_called(); |
|
| 568 | + if ($display_previously_submitted_data) { |
|
| 569 | + $this->populate_from_session(); |
|
| 570 | + } |
|
| 571 | + return $this->_layout_strategy->layout_form(); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * enqueues JS for the form |
|
| 578 | + * |
|
| 579 | + * @return string |
|
| 580 | + * @throws \EE_Error |
|
| 581 | + */ |
|
| 582 | + public function enqueue_js() |
|
| 583 | + { |
|
| 584 | + $this->_enqueue_and_localize_form_js(); |
|
| 585 | + foreach ($this->subsections() as $subsection) { |
|
| 586 | + $subsection->enqueue_js(); |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 594 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 595 | + * the wp_enqueue_scripts hook. |
|
| 596 | + * However, registering the form js and localizing it can happen when we |
|
| 597 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 598 | + * could change until it's actually outputted) |
|
| 599 | + * |
|
| 600 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 601 | + * to be triggered automatically or not |
|
| 602 | + * @return void |
|
| 603 | + */ |
|
| 604 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 605 | + { |
|
| 606 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
| 607 | + wp_register_script( |
|
| 608 | + 'ee_form_section_validation', |
|
| 609 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 610 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 611 | + EVENT_ESPRESSO_VERSION, |
|
| 612 | + true |
|
| 613 | + ); |
|
| 614 | + wp_localize_script( |
|
| 615 | + 'ee_form_section_validation', |
|
| 616 | + 'ee_form_section_validation_init', |
|
| 617 | + array('init' => $init_form_validation_automatically ? true : false) |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * gets the variables used by form_section_validation.js. |
|
| 625 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 626 | + * but before the wordpress hook wp_loaded |
|
| 627 | + * |
|
| 628 | + * @throws \EE_Error |
|
| 629 | + */ |
|
| 630 | + public function _enqueue_and_localize_form_js() |
|
| 631 | + { |
|
| 632 | + $this->ensure_construct_finalized_called(); |
|
| 633 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 634 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
| 635 | + //and localize it just before the footer |
|
| 636 | + $this->localize_validation_rules(); |
|
| 637 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 638 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * add our form section data to a static variable accessible by all form sections |
|
| 645 | + * |
|
| 646 | + * @param bool $return_for_subsection |
|
| 647 | + * @return void |
|
| 648 | + * @throws \EE_Error |
|
| 649 | + */ |
|
| 650 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 651 | + { |
|
| 652 | + // we only want to localize vars ONCE for the entire form, |
|
| 653 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 654 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 655 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 656 | + 'form_section_id' => $this->html_id(true), |
|
| 657 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 658 | + 'other_data' => $this->get_other_js_data(), |
|
| 659 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 660 | + ); |
|
| 661 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 669 | + * This is primarily data added by inputs and forms in addition to any |
|
| 670 | + * scripts they might enqueue |
|
| 671 | + * |
|
| 672 | + * @param array $form_other_js_data |
|
| 673 | + * @return array |
|
| 674 | + */ |
|
| 675 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 676 | + { |
|
| 677 | + foreach ($this->subsections() as $subsection) { |
|
| 678 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 679 | + } |
|
| 680 | + return $form_other_js_data; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 687 | + * Keys are their form names, and values are the inputs themselves |
|
| 688 | + * |
|
| 689 | + * @return EE_Form_Input_Base |
|
| 690 | + */ |
|
| 691 | + public function inputs_in_subsections() |
|
| 692 | + { |
|
| 693 | + $inputs = array(); |
|
| 694 | + foreach ($this->subsections() as $subsection) { |
|
| 695 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 696 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 697 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 698 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + return $inputs; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Gets a flat array of all the validation errors. |
|
| 708 | + * Keys are html names (because those should be unique) |
|
| 709 | + * and values are a string of all their validation errors |
|
| 710 | + * |
|
| 711 | + * @return string[] |
|
| 712 | + */ |
|
| 713 | + public function subsection_validation_errors_by_html_name() |
|
| 714 | + { |
|
| 715 | + $inputs = $this->inputs(); |
|
| 716 | + $errors = array(); |
|
| 717 | + foreach ($inputs as $form_input) { |
|
| 718 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 719 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + return $errors; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 729 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 730 | + */ |
|
| 731 | + public static function localize_script_for_all_forms() |
|
| 732 | + { |
|
| 733 | + //allow inputs and stuff to hook in their JS and stuff here |
|
| 734 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 735 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 736 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 737 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 738 | + : 'wp_default'; |
|
| 739 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 740 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 741 | + wp_localize_script( |
|
| 742 | + 'ee_form_section_validation', |
|
| 743 | + 'ee_form_section_vars', |
|
| 744 | + EE_Form_Section_Proper::$_js_localization |
|
| 745 | + ); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * ensure_scripts_localized |
|
| 752 | + */ |
|
| 753 | + public function ensure_scripts_localized() |
|
| 754 | + { |
|
| 755 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 756 | + $this->_enqueue_and_localize_form_js(); |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 764 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 765 | + * |
|
| 766 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 767 | + */ |
|
| 768 | + private static function _get_localized_error_messages() |
|
| 769 | + { |
|
| 770 | + return array( |
|
| 771 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
| 772 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * @return array |
|
| 780 | + */ |
|
| 781 | + public static function js_localization() |
|
| 782 | + { |
|
| 783 | + return self::$_js_localization; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * @return array |
|
| 790 | + */ |
|
| 791 | + public static function reset_js_localization() |
|
| 792 | + { |
|
| 793 | + self::$_js_localization = array(); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 800 | + * See parent function for more... |
|
| 801 | + * |
|
| 802 | + * @return array |
|
| 803 | + */ |
|
| 804 | + public function get_jquery_validation_rules() |
|
| 805 | + { |
|
| 806 | + $jquery_validation_rules = array(); |
|
| 807 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 808 | + $jquery_validation_rules = array_merge( |
|
| 809 | + $jquery_validation_rules, |
|
| 810 | + $subsection->get_jquery_validation_rules() |
|
| 811 | + ); |
|
| 812 | + } |
|
| 813 | + return $jquery_validation_rules; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 820 | + * |
|
| 821 | + * @param array $req_data like $_POST |
|
| 822 | + * @return void |
|
| 823 | + */ |
|
| 824 | + protected function _normalize($req_data) |
|
| 825 | + { |
|
| 826 | + $this->_received_submission = true; |
|
| 827 | + $this->_validation_errors = array(); |
|
| 828 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 829 | + try { |
|
| 830 | + $subsection->_normalize($req_data); |
|
| 831 | + } catch (EE_Validation_Error $e) { |
|
| 832 | + $subsection->add_validation_error($e); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * Performs validation on this form section and its subsections. |
|
| 841 | + * For each subsection, |
|
| 842 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 843 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 844 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 845 | + * you would be best to override this _validate method, |
|
| 846 | + * calling parent::_validate() first. |
|
| 847 | + */ |
|
| 848 | + protected function _validate() |
|
| 849 | + { |
|
| 850 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 851 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 852 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 853 | + } |
|
| 854 | + $subsection->_validate(); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Gets all the validated inputs for the form section |
|
| 862 | + * |
|
| 863 | + * @return array |
|
| 864 | + */ |
|
| 865 | + public function valid_data() |
|
| 866 | + { |
|
| 867 | + $inputs = array(); |
|
| 868 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 869 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 870 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 871 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
| 872 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + return $inputs; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Gets all the inputs on this form section |
|
| 882 | + * |
|
| 883 | + * @return EE_Form_Input_Base[] |
|
| 884 | + */ |
|
| 885 | + public function inputs() |
|
| 886 | + { |
|
| 887 | + $inputs = array(); |
|
| 888 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 889 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 890 | + $inputs[$subsection_name] = $subsection; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + return $inputs; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * Gets all the subsections which are a proper form |
|
| 900 | + * |
|
| 901 | + * @return EE_Form_Section_Proper[] |
|
| 902 | + */ |
|
| 903 | + public function subforms() |
|
| 904 | + { |
|
| 905 | + $form_sections = array(); |
|
| 906 | + foreach ($this->subsections() as $name => $obj) { |
|
| 907 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 908 | + $form_sections[$name] = $obj; |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + return $form_sections; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 918 | + * Consider using inputs() or subforms() |
|
| 919 | + * if you only want form inputs or proper form sections. |
|
| 920 | + * |
|
| 921 | + * @return EE_Form_Section_Proper[] |
|
| 922 | + */ |
|
| 923 | + public function subsections() |
|
| 924 | + { |
|
| 925 | + $this->ensure_construct_finalized_called(); |
|
| 926 | + return $this->_subsections; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 933 | + * values. (Similar to calling get_input_value on inputs) |
|
| 934 | + * |
|
| 935 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 936 | + * or just this forms' direct children inputs |
|
| 937 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 938 | + * or allow multidimensional array |
|
| 939 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 940 | + * with array keys being input names |
|
| 941 | + * (regardless of whether they are from a subsection or not), |
|
| 942 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 943 | + * where keys are always subsection names and values are either |
|
| 944 | + * the input's normalized value, or an array like the top-level array |
|
| 945 | + */ |
|
| 946 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 947 | + { |
|
| 948 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 955 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 956 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 957 | + * where keys are the input names, and values are their display values |
|
| 958 | + * |
|
| 959 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 960 | + * or just this forms' direct children inputs |
|
| 961 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 962 | + * or allow multidimensional array |
|
| 963 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 964 | + * with array keys being input names |
|
| 965 | + * (regardless of whether they are from a subsection or not), |
|
| 966 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 967 | + * where keys are always subsection names and values are either |
|
| 968 | + * the input's normalized value, or an array like the top-level array |
|
| 969 | + */ |
|
| 970 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 971 | + { |
|
| 972 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * Gets the input values from the form |
|
| 979 | + * |
|
| 980 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 981 | + * or just the normalized value |
|
| 982 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 983 | + * or just this forms' direct children inputs |
|
| 984 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 985 | + * or allow multidimensional array |
|
| 986 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 987 | + * input names (regardless of whether they are from a subsection or not), |
|
| 988 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 989 | + * where keys are always subsection names and values are either |
|
| 990 | + * the input's normalized value, or an array like the top-level array |
|
| 991 | + */ |
|
| 992 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 993 | + { |
|
| 994 | + $input_values = array(); |
|
| 995 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 996 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 997 | + $input_values[$subsection_name] = $pretty |
|
| 998 | + ? $subsection->pretty_value() |
|
| 999 | + : $subsection->normalized_value(); |
|
| 1000 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1001 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
| 1002 | + if ($flatten) { |
|
| 1003 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1004 | + } else { |
|
| 1005 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | + } |
|
| 1009 | + return $input_values; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Gets the originally submitted input values from the form |
|
| 1016 | + * |
|
| 1017 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1018 | + * or just this forms' direct children inputs |
|
| 1019 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1020 | + * with array keys being input names |
|
| 1021 | + * (regardless of whether they are from a subsection or not), |
|
| 1022 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1023 | + * where keys are always subsection names and values are either |
|
| 1024 | + * the input's normalized value, or an array like the top-level array |
|
| 1025 | + */ |
|
| 1026 | + public function submitted_values($include_subforms = false) |
|
| 1027 | + { |
|
| 1028 | + $submitted_values = array(); |
|
| 1029 | + foreach ($this->subsections() as $subsection) { |
|
| 1030 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1031 | + // is this input part of an array of inputs? |
|
| 1032 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1033 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
| 1034 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
| 1035 | + $subsection->raw_value() |
|
| 1036 | + ); |
|
| 1037 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1038 | + } else { |
|
| 1039 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1040 | + } |
|
| 1041 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1042 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1043 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + return $submitted_values; |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * Indicates whether or not this form has received a submission yet |
|
| 1053 | + * (ie, had receive_form_submission called on it yet) |
|
| 1054 | + * |
|
| 1055 | + * @return boolean |
|
| 1056 | + * @throws \EE_Error |
|
| 1057 | + */ |
|
| 1058 | + public function has_received_submission() |
|
| 1059 | + { |
|
| 1060 | + $this->ensure_construct_finalized_called(); |
|
| 1061 | + return $this->_received_submission; |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1068 | + * Removes the listed inputs from the form |
|
| 1069 | + * |
|
| 1070 | + * @param array $inputs_to_exclude values are the input names |
|
| 1071 | + * @return void |
|
| 1072 | + */ |
|
| 1073 | + public function exclude($inputs_to_exclude = array()) |
|
| 1074 | + { |
|
| 1075 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1076 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + /** |
|
| 1083 | + * @param array $inputs_to_hide |
|
| 1084 | + * @throws \EE_Error |
|
| 1085 | + */ |
|
| 1086 | + public function hide($inputs_to_hide = array()) |
|
| 1087 | + { |
|
| 1088 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1089 | + $input = $this->get_input($input_to_hide); |
|
| 1090 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * add_subsections |
|
| 1098 | + * Adds the listed subsections to the form section. |
|
| 1099 | + * If $subsection_name_to_target is provided, |
|
| 1100 | + * then new subsections are added before or after that subsection, |
|
| 1101 | + * otherwise to the start or end of the entire subsections array. |
|
| 1102 | + * |
|
| 1103 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1104 | + * where keys are their names |
|
| 1105 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1106 | + * should be added before or after |
|
| 1107 | + * IF $subsection_name_to_target is null, |
|
| 1108 | + * then $new_subsections will be added to |
|
| 1109 | + * the beginning or end of the entire subsections array |
|
| 1110 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1111 | + * $subsection_name_to_target, |
|
| 1112 | + * or if $subsection_name_to_target is null, |
|
| 1113 | + * before or after entire subsections array |
|
| 1114 | + * @return void |
|
| 1115 | + * @throws \EE_Error |
|
| 1116 | + */ |
|
| 1117 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1118 | + { |
|
| 1119 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1120 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1121 | + EE_Error::add_error( |
|
| 1122 | + sprintf( |
|
| 1123 | + __( |
|
| 1124 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1125 | + "event_espresso" |
|
| 1126 | + ), |
|
| 1127 | + get_class($subsection), |
|
| 1128 | + $subsection_name, |
|
| 1129 | + $this->name() |
|
| 1130 | + ) |
|
| 1131 | + ); |
|
| 1132 | + unset($new_subsections[$subsection_name]); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1136 | + $this->_subsections, |
|
| 1137 | + $new_subsections, |
|
| 1138 | + $subsection_name_to_target, |
|
| 1139 | + $add_before |
|
| 1140 | + ); |
|
| 1141 | + if ($this->_construction_finalized) { |
|
| 1142 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1143 | + $subsection->_construct_finalize($this, $name); |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1152 | + */ |
|
| 1153 | + public function clean_sensitive_data() |
|
| 1154 | + { |
|
| 1155 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1156 | + $subsection->clean_sensitive_data(); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + |
|
| 1161 | + |
|
| 1162 | + /** |
|
| 1163 | + * @param string $form_submission_error_message |
|
| 1164 | + */ |
|
| 1165 | + public function set_submission_error_message($form_submission_error_message = '') |
|
| 1166 | + { |
|
| 1167 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1168 | + ? $form_submission_error_message |
|
| 1169 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * @return string |
|
| 1176 | + */ |
|
| 1177 | + public function submission_error_message() |
|
| 1178 | + { |
|
| 1179 | + return $this->_form_submission_error_message; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * @param string $form_submission_success_message |
|
| 1186 | + */ |
|
| 1187 | + public function set_submission_success_message($form_submission_success_message) |
|
| 1188 | + { |
|
| 1189 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1190 | + ? $form_submission_success_message |
|
| 1191 | + : __('Form submitted successfully', 'event_espresso'); |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * @return string |
|
| 1198 | + */ |
|
| 1199 | + public function submission_success_message() |
|
| 1200 | + { |
|
| 1201 | + return $this->_form_submission_success_message; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * Returns the prefix that should be used on child of this form section for |
|
| 1208 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1209 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1210 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1211 | + * |
|
| 1212 | + * @return string |
|
| 1213 | + * @throws \EE_Error |
|
| 1214 | + */ |
|
| 1215 | + public function html_name_prefix() |
|
| 1216 | + { |
|
| 1217 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1218 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1219 | + } else { |
|
| 1220 | + return $this->name(); |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + /** |
|
| 1227 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1228 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1229 | + * was set, which is probably nothing, or the classname) |
|
| 1230 | + * |
|
| 1231 | + * @return string |
|
| 1232 | + * @throws \EE_Error |
|
| 1233 | + */ |
|
| 1234 | + public function name() |
|
| 1235 | + { |
|
| 1236 | + $this->ensure_construct_finalized_called(); |
|
| 1237 | + return parent::name(); |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + /** |
|
| 1243 | + * @return EE_Form_Section_Proper |
|
| 1244 | + * @throws \EE_Error |
|
| 1245 | + */ |
|
| 1246 | + public function parent_section() |
|
| 1247 | + { |
|
| 1248 | + $this->ensure_construct_finalized_called(); |
|
| 1249 | + return parent::parent_section(); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1256 | + * |
|
| 1257 | + * @return void |
|
| 1258 | + * @throws \EE_Error |
|
| 1259 | + */ |
|
| 1260 | + public function ensure_construct_finalized_called() |
|
| 1261 | + { |
|
| 1262 | + if ( ! $this->_construction_finalized) { |
|
| 1263 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1271 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1272 | + * |
|
| 1273 | + * @param array $req_data |
|
| 1274 | + * @return boolean |
|
| 1275 | + */ |
|
| 1276 | + public function form_data_present_in($req_data = null) |
|
| 1277 | + { |
|
| 1278 | + if ($req_data === null) { |
|
| 1279 | + $req_data = $_POST; |
|
| 1280 | + } |
|
| 1281 | + foreach ($this->subsections() as $subsection) { |
|
| 1282 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1283 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1284 | + return true; |
|
| 1285 | + } |
|
| 1286 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1287 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1288 | + return true; |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1291 | + } |
|
| 1292 | + return false; |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + |
|
| 1297 | + /** |
|
| 1298 | + * Gets validation errors for this form section and subsections |
|
| 1299 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1300 | + * gets the validation errors for ALL subsection |
|
| 1301 | + * |
|
| 1302 | + * @return EE_Validation_Error[] |
|
| 1303 | + */ |
|
| 1304 | + public function get_validation_errors_accumulated() |
|
| 1305 | + { |
|
| 1306 | + $validation_errors = $this->get_validation_errors(); |
|
| 1307 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1308 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1309 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1310 | + } else { |
|
| 1311 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1312 | + } |
|
| 1313 | + if ($validation_errors_on_this_subsection) { |
|
| 1314 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + return $validation_errors; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1324 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1325 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1326 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1327 | + * which will be returned. |
|
| 1328 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1329 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1330 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1331 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1332 | + * Etc |
|
| 1333 | + * |
|
| 1334 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1335 | + * @return EE_Form_Section_Base |
|
| 1336 | + */ |
|
| 1337 | + public function find_section_from_path($form_section_path) |
|
| 1338 | + { |
|
| 1339 | + //check if we can find the input from purely going straight up the tree |
|
| 1340 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1341 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1342 | + return $input; |
|
| 1343 | + } |
|
| 1344 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1345 | + if ($next_slash_pos !== false) { |
|
| 1346 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1347 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1348 | + } else { |
|
| 1349 | + $child_section_name = $form_section_path; |
|
| 1350 | + $subpath = ''; |
|
| 1351 | + } |
|
| 1352 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1353 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1354 | + return $child_section->find_section_from_path($subpath); |
|
| 1355 | + } else { |
|
| 1356 | + return null; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | 1359 | |
| 1360 | 1360 | } |
| 1361 | 1361 | |
@@ -2640,7 +2640,7 @@ discard block |
||
| 2640 | 2640 | * @param int $GRP_ID The group being deleted |
| 2641 | 2641 | * @param bool $include_group whether to delete the Message Template Group as well. |
| 2642 | 2642 | * |
| 2643 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2643 | + * @return integer boolean to indicate the success of the deletes or not. |
|
| 2644 | 2644 | */ |
| 2645 | 2645 | private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
| 2646 | 2646 | { |
@@ -2772,7 +2772,7 @@ discard block |
||
| 2772 | 2772 | * This just prepares the content for the message type settings |
| 2773 | 2773 | * |
| 2774 | 2774 | * @param object $message_type The message type object |
| 2775 | - * @param object $messenger The messenger object |
|
| 2775 | + * @param EE_messenger|null $messenger The messenger object |
|
| 2776 | 2776 | * @param boolean $active Whether the message type is active or not |
| 2777 | 2777 | * |
| 2778 | 2778 | * @return string html output for the content |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('NO direct script access allowed'); |
|
| 2 | + exit('NO direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -17,2203 +17,2203 @@ discard block |
||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | - */ |
|
| 23 | - protected $_message_resource_manager; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @type string $_active_message_type_name |
|
| 27 | - */ |
|
| 28 | - protected $_active_message_type_name = ''; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @type EE_messenger $_active_messenger |
|
| 32 | - */ |
|
| 33 | - protected $_active_messenger; |
|
| 34 | - protected $_activate_state; |
|
| 35 | - protected $_activate_meta_box_type; |
|
| 36 | - protected $_current_message_meta_box; |
|
| 37 | - protected $_current_message_meta_box_object; |
|
| 38 | - protected $_context_switcher; |
|
| 39 | - protected $_shortcodes = array(); |
|
| 40 | - protected $_active_messengers = array(); |
|
| 41 | - protected $_active_message_types = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | - */ |
|
| 46 | - protected $_message_template_group; |
|
| 47 | - protected $_m_mt_settings = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | - * |
|
| 54 | - * @since 4.5.0 |
|
| 55 | - * |
|
| 56 | - * @var EE_Messages_Template_Pack |
|
| 57 | - */ |
|
| 58 | - protected $_template_pack; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | - * group is. If there is no group then it automatically gets set to default. |
|
| 64 | - * |
|
| 65 | - * @since 4.5.0 |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $_variation; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param bool $routing |
|
| 74 | - */ |
|
| 75 | - public function __construct($routing = true) |
|
| 76 | - { |
|
| 77 | - //make sure messages autoloader is running |
|
| 78 | - EED_Messages::set_autoloaders(); |
|
| 79 | - parent::__construct($routing); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - protected function _init_page_props() |
|
| 84 | - { |
|
| 85 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | - $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | - |
|
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | - |
|
| 92 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | - $this->_load_message_resource_manager(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function _load_message_resource_manager() |
|
| 104 | - { |
|
| 105 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated 4.9.9.rc.014 |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_messengers_for_list_table() |
|
| 114 | - { |
|
| 115 | - EE_Error::doing_it_wrong( |
|
| 116 | - __METHOD__, |
|
| 117 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 20 | + /** |
|
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | + */ |
|
| 23 | + protected $_message_resource_manager; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @type string $_active_message_type_name |
|
| 27 | + */ |
|
| 28 | + protected $_active_message_type_name = ''; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @type EE_messenger $_active_messenger |
|
| 32 | + */ |
|
| 33 | + protected $_active_messenger; |
|
| 34 | + protected $_activate_state; |
|
| 35 | + protected $_activate_meta_box_type; |
|
| 36 | + protected $_current_message_meta_box; |
|
| 37 | + protected $_current_message_meta_box_object; |
|
| 38 | + protected $_context_switcher; |
|
| 39 | + protected $_shortcodes = array(); |
|
| 40 | + protected $_active_messengers = array(); |
|
| 41 | + protected $_active_message_types = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | + */ |
|
| 46 | + protected $_message_template_group; |
|
| 47 | + protected $_m_mt_settings = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | + * |
|
| 54 | + * @since 4.5.0 |
|
| 55 | + * |
|
| 56 | + * @var EE_Messages_Template_Pack |
|
| 57 | + */ |
|
| 58 | + protected $_template_pack; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | + * group is. If there is no group then it automatically gets set to default. |
|
| 64 | + * |
|
| 65 | + * @since 4.5.0 |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $_variation; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param bool $routing |
|
| 74 | + */ |
|
| 75 | + public function __construct($routing = true) |
|
| 76 | + { |
|
| 77 | + //make sure messages autoloader is running |
|
| 78 | + EED_Messages::set_autoloaders(); |
|
| 79 | + parent::__construct($routing); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + protected function _init_page_props() |
|
| 84 | + { |
|
| 85 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | + $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | + |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | + |
|
| 92 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | + $this->_load_message_resource_manager(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function _load_message_resource_manager() |
|
| 104 | + { |
|
| 105 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated 4.9.9.rc.014 |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_messengers_for_list_table() |
|
| 114 | + { |
|
| 115 | + EE_Error::doing_it_wrong( |
|
| 116 | + __METHOD__, |
|
| 117 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 118 | 118 | values for use in creating a messenger filter dropdown which is now generated differently via |
| 119 | 119 | Messages_Admin_Page::get_messengers_select_input', 'event_espresso'), |
| 120 | - '4.9.9.rc.014' |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $m_values = array(); |
|
| 124 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | - //setup messengers for selects |
|
| 126 | - $i = 1; |
|
| 127 | - foreach ($active_messengers as $active_messenger) { |
|
| 128 | - if ($active_messenger instanceof EE_Message) { |
|
| 129 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | - $i++; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $m_values; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @deprecated 4.9.9.rc.014 |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function get_message_types_for_list_table() |
|
| 144 | - { |
|
| 145 | - EE_Error::doing_it_wrong( |
|
| 146 | - __METHOD__, |
|
| 147 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 120 | + '4.9.9.rc.014' |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $m_values = array(); |
|
| 124 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | + //setup messengers for selects |
|
| 126 | + $i = 1; |
|
| 127 | + foreach ($active_messengers as $active_messenger) { |
|
| 128 | + if ($active_messenger instanceof EE_Message) { |
|
| 129 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | + $i++; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $m_values; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @deprecated 4.9.9.rc.014 |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function get_message_types_for_list_table() |
|
| 144 | + { |
|
| 145 | + EE_Error::doing_it_wrong( |
|
| 146 | + __METHOD__, |
|
| 147 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 148 | 148 | values for use in creating a message type filter dropdown which is now generated differently via |
| 149 | 149 | Messages_Admin_Page::get_message_types_select_input', 'event_espresso'), |
| 150 | - '4.9.9.rc.014' |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $mt_values = array(); |
|
| 154 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | - $i = 1; |
|
| 156 | - foreach ($active_messages as $active_message) { |
|
| 157 | - if ($active_message instanceof EE_Message) { |
|
| 158 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | - $i++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $mt_values; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @deprecated 4.9.9.rc.014 |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function get_contexts_for_message_types_for_list_table() |
|
| 173 | - { |
|
| 174 | - EE_Error::doing_it_wrong( |
|
| 175 | - __METHOD__, |
|
| 176 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 150 | + '4.9.9.rc.014' |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $mt_values = array(); |
|
| 154 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | + $i = 1; |
|
| 156 | + foreach ($active_messages as $active_message) { |
|
| 157 | + if ($active_message instanceof EE_Message) { |
|
| 158 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | + $i++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $mt_values; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @deprecated 4.9.9.rc.014 |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function get_contexts_for_message_types_for_list_table() |
|
| 173 | + { |
|
| 174 | + EE_Error::doing_it_wrong( |
|
| 175 | + __METHOD__, |
|
| 176 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 177 | 177 | values for use in creating a message type context filter dropdown which is now generated differently via |
| 178 | 178 | Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'), |
| 179 | - '4.9.9.rc.014' |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $contexts = array(); |
|
| 183 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | - foreach ($active_message_contexts as $active_message) { |
|
| 185 | - if ($active_message instanceof EE_Message) { |
|
| 186 | - $message_type = $active_message->message_type_object(); |
|
| 187 | - if ($message_type instanceof EE_message_type) { |
|
| 188 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | - $contexts[$context] = $context_details['label']; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $contexts; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Generate select input with provided messenger options array. |
|
| 202 | - * |
|
| 203 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | - * labels. |
|
| 205 | - * |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function get_messengers_select_input($messenger_options) |
|
| 209 | - { |
|
| 210 | - //if empty or just one value then just return an empty string |
|
| 211 | - if (empty($messenger_options) |
|
| 212 | - || ! is_array($messenger_options) |
|
| 213 | - || count($messenger_options) === 1 |
|
| 214 | - ) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - //merge in default |
|
| 218 | - $messenger_options = array_merge( |
|
| 219 | - array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | - $messenger_options |
|
| 221 | - ); |
|
| 222 | - $input = new EE_Select_Input( |
|
| 223 | - $messenger_options, |
|
| 224 | - array( |
|
| 225 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | - 'html_class' => 'wide', |
|
| 228 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | - : 'none_selected' |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - return $input->get_html_for_input(); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Generate select input with provided message type options array. |
|
| 240 | - * |
|
| 241 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | - * message type labels |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_message_types_select_input($message_type_options) |
|
| 247 | - { |
|
| 248 | - //if empty or count of options is 1 then just return an empty string |
|
| 249 | - if (empty($message_type_options) |
|
| 250 | - || ! is_array($message_type_options) |
|
| 251 | - || count($message_type_options) === 1 |
|
| 252 | - ) { |
|
| 253 | - return ''; |
|
| 254 | - } |
|
| 255 | - //merge in default |
|
| 256 | - $message_type_options = array_merge( |
|
| 257 | - array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | - $message_type_options |
|
| 259 | - ); |
|
| 260 | - $input = new EE_Select_Input( |
|
| 261 | - $message_type_options, |
|
| 262 | - array( |
|
| 263 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | - 'html_class' => 'wide', |
|
| 266 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | - : 'none_selected', |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return $input->get_html_for_input(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Generate select input with provide message type contexts array. |
|
| 278 | - * |
|
| 279 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | - * context label. |
|
| 281 | - * |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | - { |
|
| 286 | - //if empty or count of options is one then just return empty string |
|
| 287 | - if (empty($context_options) |
|
| 288 | - || ! is_array($context_options) |
|
| 289 | - || count($context_options) === 1 |
|
| 290 | - ) { |
|
| 291 | - return ''; |
|
| 292 | - } |
|
| 293 | - //merge in default |
|
| 294 | - $context_options = array_merge( |
|
| 295 | - array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | - $context_options |
|
| 297 | - ); |
|
| 298 | - $input = new EE_Select_Input( |
|
| 299 | - $context_options, |
|
| 300 | - array( |
|
| 301 | - 'html_name' => 'ee_context_filter_by', |
|
| 302 | - 'html_id' => 'ee_context_filter_by', |
|
| 303 | - 'html_class' => 'wide', |
|
| 304 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | - : 'none_selected', |
|
| 307 | - ) |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - return $input->get_html_for_input(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - protected function _ajax_hooks() |
|
| 315 | - { |
|
| 316 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - protected function _define_page_props() |
|
| 325 | - { |
|
| 326 | - $this->_admin_page_title = $this->page_label; |
|
| 327 | - $this->_labels = array( |
|
| 328 | - 'buttons' => array( |
|
| 329 | - 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | - 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | - 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | - ), |
|
| 333 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | - * @access protected |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - protected function _set_page_routes() |
|
| 344 | - { |
|
| 345 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | - ? $this->_req_data['GRP_ID'] |
|
| 347 | - : 0; |
|
| 348 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | - ? $this->_req_data['id'] |
|
| 350 | - : $grp_id; |
|
| 351 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | - ? $this->_req_data['MSG_ID'] |
|
| 353 | - : 0; |
|
| 354 | - |
|
| 355 | - $this->_page_routes = array( |
|
| 356 | - 'default' => array( |
|
| 357 | - 'func' => '_message_queue_list_table', |
|
| 358 | - 'capability' => 'ee_read_global_messages' |
|
| 359 | - ), |
|
| 360 | - 'global_mtps' => array( |
|
| 361 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | - 'capability' => 'ee_read_global_messages' |
|
| 363 | - ), |
|
| 364 | - 'custom_mtps' => array( |
|
| 365 | - 'func' => '_custom_mtps_preview', |
|
| 366 | - 'capability' => 'ee_read_messages' |
|
| 367 | - ), |
|
| 368 | - 'add_new_message_template' => array( |
|
| 369 | - 'func' => '_add_message_template', |
|
| 370 | - 'capability' => 'ee_edit_messages', |
|
| 371 | - 'noheader' => true |
|
| 372 | - ), |
|
| 373 | - 'edit_message_template' => array( |
|
| 374 | - 'func' => '_edit_message_template', |
|
| 375 | - 'capability' => 'ee_edit_message', |
|
| 376 | - 'obj_id' => $grp_id |
|
| 377 | - ), |
|
| 378 | - 'preview_message' => array( |
|
| 379 | - 'func' => '_preview_message', |
|
| 380 | - 'capability' => 'ee_read_message', |
|
| 381 | - 'obj_id' => $grp_id, |
|
| 382 | - 'noheader' => true, |
|
| 383 | - 'headers_sent_route' => 'display_preview_message' |
|
| 384 | - ), |
|
| 385 | - 'display_preview_message' => array( |
|
| 386 | - 'func' => '_display_preview_message', |
|
| 387 | - 'capability' => 'ee_read_message', |
|
| 388 | - 'obj_id' => $grp_id |
|
| 389 | - ), |
|
| 390 | - 'insert_message_template' => array( |
|
| 391 | - 'func' => '_insert_or_update_message_template', |
|
| 392 | - 'capability' => 'ee_edit_messages', |
|
| 393 | - 'args' => array('new_template' => true), |
|
| 394 | - 'noheader' => true |
|
| 395 | - ), |
|
| 396 | - 'update_message_template' => array( |
|
| 397 | - 'func' => '_insert_or_update_message_template', |
|
| 398 | - 'capability' => 'ee_edit_message', |
|
| 399 | - 'obj_id' => $grp_id, |
|
| 400 | - 'args' => array('new_template' => false), |
|
| 401 | - 'noheader' => true |
|
| 402 | - ), |
|
| 403 | - 'trash_message_template' => array( |
|
| 404 | - 'func' => '_trash_or_restore_message_template', |
|
| 405 | - 'capability' => 'ee_delete_message', |
|
| 406 | - 'obj_id' => $grp_id, |
|
| 407 | - 'args' => array('trash' => true, 'all' => true), |
|
| 408 | - 'noheader' => true |
|
| 409 | - ), |
|
| 410 | - 'trash_message_template_context' => array( |
|
| 411 | - 'func' => '_trash_or_restore_message_template', |
|
| 412 | - 'capability' => 'ee_delete_message', |
|
| 413 | - 'obj_id' => $grp_id, |
|
| 414 | - 'args' => array('trash' => true), |
|
| 415 | - 'noheader' => true |
|
| 416 | - ), |
|
| 417 | - 'restore_message_template' => array( |
|
| 418 | - 'func' => '_trash_or_restore_message_template', |
|
| 419 | - 'capability' => 'ee_delete_message', |
|
| 420 | - 'obj_id' => $grp_id, |
|
| 421 | - 'args' => array('trash' => false, 'all' => true), |
|
| 422 | - 'noheader' => true |
|
| 423 | - ), |
|
| 424 | - 'restore_message_template_context' => array( |
|
| 425 | - 'func' => '_trash_or_restore_message_template', |
|
| 426 | - 'capability' => 'ee_delete_message', |
|
| 427 | - 'obj_id' => $grp_id, |
|
| 428 | - 'args' => array('trash' => false), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'delete_message_template' => array( |
|
| 432 | - 'func' => '_delete_message_template', |
|
| 433 | - 'capability' => 'ee_delete_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'reset_to_default' => array( |
|
| 438 | - 'func' => '_reset_to_default_template', |
|
| 439 | - 'capability' => 'ee_edit_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'noheader' => true |
|
| 442 | - ), |
|
| 443 | - 'settings' => array( |
|
| 444 | - 'func' => '_settings', |
|
| 445 | - 'capability' => 'manage_options' |
|
| 446 | - ), |
|
| 447 | - 'update_global_settings' => array( |
|
| 448 | - 'func' => '_update_global_settings', |
|
| 449 | - 'capability' => 'manage_options', |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'generate_now' => array( |
|
| 453 | - 'func' => '_generate_now', |
|
| 454 | - 'capability' => 'ee_send_message', |
|
| 455 | - 'noheader' => true |
|
| 456 | - ), |
|
| 457 | - 'generate_and_send_now' => array( |
|
| 458 | - 'func' => '_generate_and_send_now', |
|
| 459 | - 'capability' => 'ee_send_message', |
|
| 460 | - 'noheader' => true |
|
| 461 | - ), |
|
| 462 | - 'queue_for_resending' => array( |
|
| 463 | - 'func' => '_queue_for_resending', |
|
| 464 | - 'capability' => 'ee_send_message', |
|
| 465 | - 'noheader' => true |
|
| 466 | - ), |
|
| 467 | - 'send_now' => array( |
|
| 468 | - 'func' => '_send_now', |
|
| 469 | - 'capability' => 'ee_send_message', |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'delete_ee_message' => array( |
|
| 473 | - 'func' => '_delete_ee_messages', |
|
| 474 | - 'capability' => 'ee_delete_message', |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'delete_ee_messages' => array( |
|
| 478 | - 'func' => '_delete_ee_messages', |
|
| 479 | - 'capability' => 'ee_delete_messages', |
|
| 480 | - 'noheader' => true, |
|
| 481 | - 'obj_id' => $msg_id |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - protected function _set_page_config() |
|
| 488 | - { |
|
| 489 | - $this->_page_config = array( |
|
| 490 | - 'default' => array( |
|
| 491 | - 'nav' => array( |
|
| 492 | - 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | - 'order' => 10 |
|
| 494 | - ), |
|
| 495 | - 'list_table' => 'EE_Message_List_Table', |
|
| 496 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | - 'require_nonce' => false |
|
| 498 | - ), |
|
| 499 | - 'global_mtps' => array( |
|
| 500 | - 'nav' => array( |
|
| 501 | - 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | - 'order' => 20 |
|
| 503 | - ), |
|
| 504 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | - 'help_tabs' => array( |
|
| 506 | - 'messages_overview_help_tab' => array( |
|
| 507 | - 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | - 'filename' => 'messages_overview' |
|
| 509 | - ), |
|
| 510 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | - 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | - ), |
|
| 514 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | - 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | - 'filename' => 'messages_overview_filters' |
|
| 517 | - ), |
|
| 518 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | - 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | - 'filename' => 'messages_overview_views' |
|
| 521 | - ), |
|
| 522 | - 'message_overview_message_types_help_tab' => array( |
|
| 523 | - 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | - 'filename' => 'messages_overview_types' |
|
| 525 | - ), |
|
| 526 | - 'messages_overview_messengers_help_tab' => array( |
|
| 527 | - 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | - 'filename' => 'messages_overview_messengers', |
|
| 529 | - ), |
|
| 530 | - 'messages_overview_other_help_tab' => array( |
|
| 531 | - 'title' => __('Messages Other', 'event_espresso'), |
|
| 532 | - 'filename' => 'messages_overview_other', |
|
| 533 | - ), |
|
| 534 | - ), |
|
| 535 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 536 | - 'require_nonce' => false |
|
| 537 | - ), |
|
| 538 | - 'custom_mtps' => array( |
|
| 539 | - 'nav' => array( |
|
| 540 | - 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 541 | - 'order' => 30 |
|
| 542 | - ), |
|
| 543 | - 'help_tabs' => array(), |
|
| 544 | - 'help_tour' => array(), |
|
| 545 | - 'require_nonce' => false |
|
| 546 | - ), |
|
| 547 | - 'add_new_message_template' => array( |
|
| 548 | - 'nav' => array( |
|
| 549 | - 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 550 | - 'order' => 5, |
|
| 551 | - 'persistent' => false |
|
| 552 | - ), |
|
| 553 | - 'require_nonce' => false |
|
| 554 | - ), |
|
| 555 | - 'edit_message_template' => array( |
|
| 556 | - 'labels' => array( |
|
| 557 | - 'buttons' => array( |
|
| 558 | - 'reset' => __('Reset Templates'), |
|
| 559 | - ), |
|
| 560 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 561 | - ), |
|
| 562 | - 'nav' => array( |
|
| 563 | - 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 564 | - 'order' => 5, |
|
| 565 | - 'persistent' => false, |
|
| 566 | - 'url' => '' |
|
| 567 | - ), |
|
| 568 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 569 | - 'has_metaboxes' => true, |
|
| 570 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 571 | - 'help_tabs' => array( |
|
| 572 | - 'edit_message_template' => array( |
|
| 573 | - 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 574 | - 'callback' => 'edit_message_template_help_tab' |
|
| 575 | - ), |
|
| 576 | - 'message_templates_help_tab' => array( |
|
| 577 | - 'title' => __('Message Templates', 'event_espresso'), |
|
| 578 | - 'filename' => 'messages_templates' |
|
| 579 | - ), |
|
| 580 | - 'message_template_shortcodes' => array( |
|
| 581 | - 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 582 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 583 | - ), |
|
| 584 | - 'message_preview_help_tab' => array( |
|
| 585 | - 'title' => __('Message Preview', 'event_espresso'), |
|
| 586 | - 'filename' => 'messages_preview' |
|
| 587 | - ), |
|
| 588 | - ), |
|
| 589 | - 'require_nonce' => false |
|
| 590 | - ), |
|
| 591 | - 'display_preview_message' => array( |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'url' => '', |
|
| 596 | - 'persistent' => false |
|
| 597 | - ), |
|
| 598 | - 'help_tabs' => array( |
|
| 599 | - 'preview_message' => array( |
|
| 600 | - 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | - 'callback' => 'preview_message_help_tab' |
|
| 602 | - ) |
|
| 603 | - ), |
|
| 604 | - 'require_nonce' => false |
|
| 605 | - ), |
|
| 606 | - 'settings' => array( |
|
| 607 | - 'nav' => array( |
|
| 608 | - 'label' => __('Settings', 'event_espresso'), |
|
| 609 | - 'order' => 40 |
|
| 610 | - ), |
|
| 611 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | - 'help_tabs' => array( |
|
| 613 | - 'messages_settings_help_tab' => array( |
|
| 614 | - 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | - 'filename' => 'messages_settings' |
|
| 616 | - ), |
|
| 617 | - 'messages_settings_message_types_help_tab' => array( |
|
| 618 | - 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | - 'filename' => 'messages_settings_message_types' |
|
| 620 | - ), |
|
| 621 | - 'messages_settings_messengers_help_tab' => array( |
|
| 622 | - 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | - 'filename' => 'messages_settings_messengers' |
|
| 624 | - ), |
|
| 625 | - ), |
|
| 626 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | - 'require_nonce' => false |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - protected function _add_screen_options() |
|
| 634 | - { |
|
| 635 | - //todo |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - protected function _add_screen_options_global_mtps() |
|
| 640 | - { |
|
| 641 | - /** |
|
| 642 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | - */ |
|
| 645 | - $page_title = $this->_admin_page_title; |
|
| 646 | - $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | - $this->_per_page_screen_option(); |
|
| 648 | - $this->_admin_page_title = $page_title; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - protected function _add_screen_options_default() |
|
| 653 | - { |
|
| 654 | - $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | - $this->_per_page_screen_option(); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - //none of the below group are currently used for Messages |
|
| 660 | - protected function _add_feature_pointers() |
|
| 661 | - { |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - public function admin_init() |
|
| 665 | - { |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - public function admin_notices() |
|
| 669 | - { |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - public function admin_footer_scripts() |
|
| 673 | - { |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - public function messages_help_tab() |
|
| 678 | - { |
|
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - public function messengers_help_tab() |
|
| 684 | - { |
|
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function message_types_help_tab() |
|
| 690 | - { |
|
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - public function messages_overview_help_tab() |
|
| 696 | - { |
|
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - public function message_templates_help_tab() |
|
| 702 | - { |
|
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - public function edit_message_template_help_tab() |
|
| 708 | - { |
|
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | - $args); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - public function message_template_shortcodes_help_tab() |
|
| 725 | - { |
|
| 726 | - $this->_set_shortcodes(); |
|
| 727 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | - $args); |
|
| 730 | - } |
|
| 179 | + '4.9.9.rc.014' |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $contexts = array(); |
|
| 183 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | + foreach ($active_message_contexts as $active_message) { |
|
| 185 | + if ($active_message instanceof EE_Message) { |
|
| 186 | + $message_type = $active_message->message_type_object(); |
|
| 187 | + if ($message_type instanceof EE_message_type) { |
|
| 188 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | + $contexts[$context] = $context_details['label']; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $contexts; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Generate select input with provided messenger options array. |
|
| 202 | + * |
|
| 203 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | + * labels. |
|
| 205 | + * |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function get_messengers_select_input($messenger_options) |
|
| 209 | + { |
|
| 210 | + //if empty or just one value then just return an empty string |
|
| 211 | + if (empty($messenger_options) |
|
| 212 | + || ! is_array($messenger_options) |
|
| 213 | + || count($messenger_options) === 1 |
|
| 214 | + ) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + //merge in default |
|
| 218 | + $messenger_options = array_merge( |
|
| 219 | + array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | + $messenger_options |
|
| 221 | + ); |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | + $messenger_options, |
|
| 224 | + array( |
|
| 225 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | + 'html_class' => 'wide', |
|
| 228 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | + : 'none_selected' |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + return $input->get_html_for_input(); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Generate select input with provided message type options array. |
|
| 240 | + * |
|
| 241 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | + * message type labels |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_message_types_select_input($message_type_options) |
|
| 247 | + { |
|
| 248 | + //if empty or count of options is 1 then just return an empty string |
|
| 249 | + if (empty($message_type_options) |
|
| 250 | + || ! is_array($message_type_options) |
|
| 251 | + || count($message_type_options) === 1 |
|
| 252 | + ) { |
|
| 253 | + return ''; |
|
| 254 | + } |
|
| 255 | + //merge in default |
|
| 256 | + $message_type_options = array_merge( |
|
| 257 | + array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | + $message_type_options |
|
| 259 | + ); |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | + $message_type_options, |
|
| 262 | + array( |
|
| 263 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | + 'html_class' => 'wide', |
|
| 266 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | + : 'none_selected', |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return $input->get_html_for_input(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Generate select input with provide message type contexts array. |
|
| 278 | + * |
|
| 279 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | + * context label. |
|
| 281 | + * |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | + { |
|
| 286 | + //if empty or count of options is one then just return empty string |
|
| 287 | + if (empty($context_options) |
|
| 288 | + || ! is_array($context_options) |
|
| 289 | + || count($context_options) === 1 |
|
| 290 | + ) { |
|
| 291 | + return ''; |
|
| 292 | + } |
|
| 293 | + //merge in default |
|
| 294 | + $context_options = array_merge( |
|
| 295 | + array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | + $context_options |
|
| 297 | + ); |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | + $context_options, |
|
| 300 | + array( |
|
| 301 | + 'html_name' => 'ee_context_filter_by', |
|
| 302 | + 'html_id' => 'ee_context_filter_by', |
|
| 303 | + 'html_class' => 'wide', |
|
| 304 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | + : 'none_selected', |
|
| 307 | + ) |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + return $input->get_html_for_input(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + protected function _ajax_hooks() |
|
| 315 | + { |
|
| 316 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + protected function _define_page_props() |
|
| 325 | + { |
|
| 326 | + $this->_admin_page_title = $this->page_label; |
|
| 327 | + $this->_labels = array( |
|
| 328 | + 'buttons' => array( |
|
| 329 | + 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | + 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | + 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | + ), |
|
| 333 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | + * @access protected |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + protected function _set_page_routes() |
|
| 344 | + { |
|
| 345 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | + ? $this->_req_data['GRP_ID'] |
|
| 347 | + : 0; |
|
| 348 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | + ? $this->_req_data['id'] |
|
| 350 | + : $grp_id; |
|
| 351 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | + ? $this->_req_data['MSG_ID'] |
|
| 353 | + : 0; |
|
| 354 | + |
|
| 355 | + $this->_page_routes = array( |
|
| 356 | + 'default' => array( |
|
| 357 | + 'func' => '_message_queue_list_table', |
|
| 358 | + 'capability' => 'ee_read_global_messages' |
|
| 359 | + ), |
|
| 360 | + 'global_mtps' => array( |
|
| 361 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | + 'capability' => 'ee_read_global_messages' |
|
| 363 | + ), |
|
| 364 | + 'custom_mtps' => array( |
|
| 365 | + 'func' => '_custom_mtps_preview', |
|
| 366 | + 'capability' => 'ee_read_messages' |
|
| 367 | + ), |
|
| 368 | + 'add_new_message_template' => array( |
|
| 369 | + 'func' => '_add_message_template', |
|
| 370 | + 'capability' => 'ee_edit_messages', |
|
| 371 | + 'noheader' => true |
|
| 372 | + ), |
|
| 373 | + 'edit_message_template' => array( |
|
| 374 | + 'func' => '_edit_message_template', |
|
| 375 | + 'capability' => 'ee_edit_message', |
|
| 376 | + 'obj_id' => $grp_id |
|
| 377 | + ), |
|
| 378 | + 'preview_message' => array( |
|
| 379 | + 'func' => '_preview_message', |
|
| 380 | + 'capability' => 'ee_read_message', |
|
| 381 | + 'obj_id' => $grp_id, |
|
| 382 | + 'noheader' => true, |
|
| 383 | + 'headers_sent_route' => 'display_preview_message' |
|
| 384 | + ), |
|
| 385 | + 'display_preview_message' => array( |
|
| 386 | + 'func' => '_display_preview_message', |
|
| 387 | + 'capability' => 'ee_read_message', |
|
| 388 | + 'obj_id' => $grp_id |
|
| 389 | + ), |
|
| 390 | + 'insert_message_template' => array( |
|
| 391 | + 'func' => '_insert_or_update_message_template', |
|
| 392 | + 'capability' => 'ee_edit_messages', |
|
| 393 | + 'args' => array('new_template' => true), |
|
| 394 | + 'noheader' => true |
|
| 395 | + ), |
|
| 396 | + 'update_message_template' => array( |
|
| 397 | + 'func' => '_insert_or_update_message_template', |
|
| 398 | + 'capability' => 'ee_edit_message', |
|
| 399 | + 'obj_id' => $grp_id, |
|
| 400 | + 'args' => array('new_template' => false), |
|
| 401 | + 'noheader' => true |
|
| 402 | + ), |
|
| 403 | + 'trash_message_template' => array( |
|
| 404 | + 'func' => '_trash_or_restore_message_template', |
|
| 405 | + 'capability' => 'ee_delete_message', |
|
| 406 | + 'obj_id' => $grp_id, |
|
| 407 | + 'args' => array('trash' => true, 'all' => true), |
|
| 408 | + 'noheader' => true |
|
| 409 | + ), |
|
| 410 | + 'trash_message_template_context' => array( |
|
| 411 | + 'func' => '_trash_or_restore_message_template', |
|
| 412 | + 'capability' => 'ee_delete_message', |
|
| 413 | + 'obj_id' => $grp_id, |
|
| 414 | + 'args' => array('trash' => true), |
|
| 415 | + 'noheader' => true |
|
| 416 | + ), |
|
| 417 | + 'restore_message_template' => array( |
|
| 418 | + 'func' => '_trash_or_restore_message_template', |
|
| 419 | + 'capability' => 'ee_delete_message', |
|
| 420 | + 'obj_id' => $grp_id, |
|
| 421 | + 'args' => array('trash' => false, 'all' => true), |
|
| 422 | + 'noheader' => true |
|
| 423 | + ), |
|
| 424 | + 'restore_message_template_context' => array( |
|
| 425 | + 'func' => '_trash_or_restore_message_template', |
|
| 426 | + 'capability' => 'ee_delete_message', |
|
| 427 | + 'obj_id' => $grp_id, |
|
| 428 | + 'args' => array('trash' => false), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'delete_message_template' => array( |
|
| 432 | + 'func' => '_delete_message_template', |
|
| 433 | + 'capability' => 'ee_delete_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'reset_to_default' => array( |
|
| 438 | + 'func' => '_reset_to_default_template', |
|
| 439 | + 'capability' => 'ee_edit_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'noheader' => true |
|
| 442 | + ), |
|
| 443 | + 'settings' => array( |
|
| 444 | + 'func' => '_settings', |
|
| 445 | + 'capability' => 'manage_options' |
|
| 446 | + ), |
|
| 447 | + 'update_global_settings' => array( |
|
| 448 | + 'func' => '_update_global_settings', |
|
| 449 | + 'capability' => 'manage_options', |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'generate_now' => array( |
|
| 453 | + 'func' => '_generate_now', |
|
| 454 | + 'capability' => 'ee_send_message', |
|
| 455 | + 'noheader' => true |
|
| 456 | + ), |
|
| 457 | + 'generate_and_send_now' => array( |
|
| 458 | + 'func' => '_generate_and_send_now', |
|
| 459 | + 'capability' => 'ee_send_message', |
|
| 460 | + 'noheader' => true |
|
| 461 | + ), |
|
| 462 | + 'queue_for_resending' => array( |
|
| 463 | + 'func' => '_queue_for_resending', |
|
| 464 | + 'capability' => 'ee_send_message', |
|
| 465 | + 'noheader' => true |
|
| 466 | + ), |
|
| 467 | + 'send_now' => array( |
|
| 468 | + 'func' => '_send_now', |
|
| 469 | + 'capability' => 'ee_send_message', |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'delete_ee_message' => array( |
|
| 473 | + 'func' => '_delete_ee_messages', |
|
| 474 | + 'capability' => 'ee_delete_message', |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'delete_ee_messages' => array( |
|
| 478 | + 'func' => '_delete_ee_messages', |
|
| 479 | + 'capability' => 'ee_delete_messages', |
|
| 480 | + 'noheader' => true, |
|
| 481 | + 'obj_id' => $msg_id |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + protected function _set_page_config() |
|
| 488 | + { |
|
| 489 | + $this->_page_config = array( |
|
| 490 | + 'default' => array( |
|
| 491 | + 'nav' => array( |
|
| 492 | + 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | + 'order' => 10 |
|
| 494 | + ), |
|
| 495 | + 'list_table' => 'EE_Message_List_Table', |
|
| 496 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | + 'require_nonce' => false |
|
| 498 | + ), |
|
| 499 | + 'global_mtps' => array( |
|
| 500 | + 'nav' => array( |
|
| 501 | + 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | + 'order' => 20 |
|
| 503 | + ), |
|
| 504 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | + 'help_tabs' => array( |
|
| 506 | + 'messages_overview_help_tab' => array( |
|
| 507 | + 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | + 'filename' => 'messages_overview' |
|
| 509 | + ), |
|
| 510 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | + 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | + ), |
|
| 514 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | + 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | + 'filename' => 'messages_overview_filters' |
|
| 517 | + ), |
|
| 518 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | + 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | + 'filename' => 'messages_overview_views' |
|
| 521 | + ), |
|
| 522 | + 'message_overview_message_types_help_tab' => array( |
|
| 523 | + 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | + 'filename' => 'messages_overview_types' |
|
| 525 | + ), |
|
| 526 | + 'messages_overview_messengers_help_tab' => array( |
|
| 527 | + 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | + 'filename' => 'messages_overview_messengers', |
|
| 529 | + ), |
|
| 530 | + 'messages_overview_other_help_tab' => array( |
|
| 531 | + 'title' => __('Messages Other', 'event_espresso'), |
|
| 532 | + 'filename' => 'messages_overview_other', |
|
| 533 | + ), |
|
| 534 | + ), |
|
| 535 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 536 | + 'require_nonce' => false |
|
| 537 | + ), |
|
| 538 | + 'custom_mtps' => array( |
|
| 539 | + 'nav' => array( |
|
| 540 | + 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 541 | + 'order' => 30 |
|
| 542 | + ), |
|
| 543 | + 'help_tabs' => array(), |
|
| 544 | + 'help_tour' => array(), |
|
| 545 | + 'require_nonce' => false |
|
| 546 | + ), |
|
| 547 | + 'add_new_message_template' => array( |
|
| 548 | + 'nav' => array( |
|
| 549 | + 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 550 | + 'order' => 5, |
|
| 551 | + 'persistent' => false |
|
| 552 | + ), |
|
| 553 | + 'require_nonce' => false |
|
| 554 | + ), |
|
| 555 | + 'edit_message_template' => array( |
|
| 556 | + 'labels' => array( |
|
| 557 | + 'buttons' => array( |
|
| 558 | + 'reset' => __('Reset Templates'), |
|
| 559 | + ), |
|
| 560 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 561 | + ), |
|
| 562 | + 'nav' => array( |
|
| 563 | + 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 564 | + 'order' => 5, |
|
| 565 | + 'persistent' => false, |
|
| 566 | + 'url' => '' |
|
| 567 | + ), |
|
| 568 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 569 | + 'has_metaboxes' => true, |
|
| 570 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 571 | + 'help_tabs' => array( |
|
| 572 | + 'edit_message_template' => array( |
|
| 573 | + 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 574 | + 'callback' => 'edit_message_template_help_tab' |
|
| 575 | + ), |
|
| 576 | + 'message_templates_help_tab' => array( |
|
| 577 | + 'title' => __('Message Templates', 'event_espresso'), |
|
| 578 | + 'filename' => 'messages_templates' |
|
| 579 | + ), |
|
| 580 | + 'message_template_shortcodes' => array( |
|
| 581 | + 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 582 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 583 | + ), |
|
| 584 | + 'message_preview_help_tab' => array( |
|
| 585 | + 'title' => __('Message Preview', 'event_espresso'), |
|
| 586 | + 'filename' => 'messages_preview' |
|
| 587 | + ), |
|
| 588 | + ), |
|
| 589 | + 'require_nonce' => false |
|
| 590 | + ), |
|
| 591 | + 'display_preview_message' => array( |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'url' => '', |
|
| 596 | + 'persistent' => false |
|
| 597 | + ), |
|
| 598 | + 'help_tabs' => array( |
|
| 599 | + 'preview_message' => array( |
|
| 600 | + 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | + 'callback' => 'preview_message_help_tab' |
|
| 602 | + ) |
|
| 603 | + ), |
|
| 604 | + 'require_nonce' => false |
|
| 605 | + ), |
|
| 606 | + 'settings' => array( |
|
| 607 | + 'nav' => array( |
|
| 608 | + 'label' => __('Settings', 'event_espresso'), |
|
| 609 | + 'order' => 40 |
|
| 610 | + ), |
|
| 611 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | + 'help_tabs' => array( |
|
| 613 | + 'messages_settings_help_tab' => array( |
|
| 614 | + 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | + 'filename' => 'messages_settings' |
|
| 616 | + ), |
|
| 617 | + 'messages_settings_message_types_help_tab' => array( |
|
| 618 | + 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | + 'filename' => 'messages_settings_message_types' |
|
| 620 | + ), |
|
| 621 | + 'messages_settings_messengers_help_tab' => array( |
|
| 622 | + 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | + 'filename' => 'messages_settings_messengers' |
|
| 624 | + ), |
|
| 625 | + ), |
|
| 626 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | + 'require_nonce' => false |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + protected function _add_screen_options() |
|
| 634 | + { |
|
| 635 | + //todo |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + protected function _add_screen_options_global_mtps() |
|
| 640 | + { |
|
| 641 | + /** |
|
| 642 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | + */ |
|
| 645 | + $page_title = $this->_admin_page_title; |
|
| 646 | + $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | + $this->_per_page_screen_option(); |
|
| 648 | + $this->_admin_page_title = $page_title; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + protected function _add_screen_options_default() |
|
| 653 | + { |
|
| 654 | + $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | + $this->_per_page_screen_option(); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + //none of the below group are currently used for Messages |
|
| 660 | + protected function _add_feature_pointers() |
|
| 661 | + { |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + public function admin_init() |
|
| 665 | + { |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + public function admin_notices() |
|
| 669 | + { |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + public function admin_footer_scripts() |
|
| 673 | + { |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + public function messages_help_tab() |
|
| 678 | + { |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + public function messengers_help_tab() |
|
| 684 | + { |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function message_types_help_tab() |
|
| 690 | + { |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + public function messages_overview_help_tab() |
|
| 696 | + { |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + public function message_templates_help_tab() |
|
| 702 | + { |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + public function edit_message_template_help_tab() |
|
| 708 | + { |
|
| 709 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso') . '" />'; |
|
| 711 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso') . '" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso') . '" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso') . '" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso') . '" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | + $args); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + public function message_template_shortcodes_help_tab() |
|
| 725 | + { |
|
| 726 | + $this->_set_shortcodes(); |
|
| 727 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | + $args); |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | - public function preview_message_help_tab() |
|
| 734 | - { |
|
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | - } |
|
| 733 | + public function preview_message_help_tab() |
|
| 734 | + { |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - |
|
| 739 | - public function settings_help_tab() |
|
| 740 | - { |
|
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 745 | - $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | - $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | - } |
|
| 738 | + |
|
| 739 | + public function settings_help_tab() |
|
| 740 | + { |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso') . '" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso') . '" />'; |
|
| 745 | + $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
|
| 746 | + $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | - public function load_scripts_styles() |
|
| 752 | - { |
|
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 751 | + public function load_scripts_styles() |
|
| 752 | + { |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | - } |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | 762 | |
| 763 | - public function load_scripts_styles_default() |
|
| 764 | - { |
|
| 765 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | - } |
|
| 763 | + public function load_scripts_styles_default() |
|
| 764 | + { |
|
| 765 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | - public function wp_editor_css($mce_css) |
|
| 770 | - { |
|
| 771 | - //if we're on the edit_message_template route |
|
| 772 | - if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | - $message_type_name = $this->_active_message_type_name; |
|
| 769 | + public function wp_editor_css($mce_css) |
|
| 770 | + { |
|
| 771 | + //if we're on the edit_message_template route |
|
| 772 | + if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | + $message_type_name = $this->_active_message_type_name; |
|
| 774 | 774 | |
| 775 | - //we're going to REPLACE the existing mce css |
|
| 776 | - //we need to get the css file location from the active messenger |
|
| 777 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | - 'wpeditor', $this->_variation); |
|
| 779 | - } |
|
| 775 | + //we're going to REPLACE the existing mce css |
|
| 776 | + //we need to get the css file location from the active messenger |
|
| 777 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | + 'wpeditor', $this->_variation); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - return $mce_css; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - |
|
| 785 | - public function load_scripts_styles_edit_message_template() |
|
| 786 | - { |
|
| 787 | - |
|
| 788 | - $this->_set_shortcodes(); |
|
| 781 | + return $mce_css; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + |
|
| 785 | + public function load_scripts_styles_edit_message_template() |
|
| 786 | + { |
|
| 787 | + |
|
| 788 | + $this->_set_shortcodes(); |
|
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | - __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | - 'event_espresso'), |
|
| 793 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | - ); |
|
| 796 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | - 'event_espresso'); |
|
| 798 | - |
|
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | - EVENT_ESPRESSO_VERSION); |
|
| 801 | - |
|
| 802 | - wp_enqueue_script('ee_admin_js'); |
|
| 803 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | - |
|
| 805 | - //add in special css for tiny_mce |
|
| 806 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - public function load_scripts_styles_display_preview_message() |
|
| 811 | - { |
|
| 812 | - |
|
| 813 | - $this->_set_message_template_group(); |
|
| 814 | - |
|
| 815 | - if (isset($this->_req_data['messenger'])) { |
|
| 816 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - wp_enqueue_style('espresso_preview_css', |
|
| 823 | - $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | - $this->_variation)); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - public function load_scripts_styles_settings() |
|
| 829 | - { |
|
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | - EVENT_ESPRESSO_VERSION); |
|
| 832 | - wp_enqueue_style('ee-text-links'); |
|
| 833 | - wp_enqueue_style('ee-message-settings'); |
|
| 834 | - |
|
| 835 | - wp_enqueue_script('ee-messages-settings'); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * set views array for List Table |
|
| 841 | - */ |
|
| 842 | - public function _set_list_table_views_global_mtps() |
|
| 843 | - { |
|
| 844 | - $this->_views = array( |
|
| 845 | - 'in_use' => array( |
|
| 846 | - 'slug' => 'in_use', |
|
| 847 | - 'label' => __('In Use', 'event_espresso'), |
|
| 848 | - 'count' => 0, |
|
| 849 | - 'bulk_action' => array( |
|
| 850 | - 'trash_message_template' => __('Move to Trash', 'event_espresso') |
|
| 851 | - ) |
|
| 852 | - ) |
|
| 853 | - ); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * set views array for message queue list table |
|
| 859 | - */ |
|
| 860 | - public function _set_list_table_views_default() |
|
| 861 | - { |
|
| 862 | - EE_Registry::instance()->load_helper('Template'); |
|
| 863 | - |
|
| 864 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 865 | - 'message_list_table_bulk_actions') |
|
| 866 | - ? array( |
|
| 867 | - 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 868 | - 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 869 | - 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 870 | - 'send_now' => __('Send Now', 'event_espresso') |
|
| 871 | - ) |
|
| 872 | - : array(); |
|
| 873 | - |
|
| 874 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 875 | - 'message_list_table_bulk_actions') |
|
| 876 | - ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 877 | - : array(); |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - $this->_views = array( |
|
| 881 | - 'all' => array( |
|
| 882 | - 'slug' => 'all', |
|
| 883 | - 'label' => __('All', 'event_espresso'), |
|
| 884 | - 'count' => 0, |
|
| 885 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 886 | - ) |
|
| 887 | - ); |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 891 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 892 | - continue; |
|
| 893 | - } |
|
| 894 | - $status_bulk_actions = $common_bulk_actions; |
|
| 895 | - //unset bulk actions not applying to status |
|
| 896 | - if ( ! empty($status_bulk_actions)) { |
|
| 897 | - switch ($status) { |
|
| 898 | - case EEM_Message::status_idle : |
|
| 899 | - case EEM_Message::status_resend : |
|
| 900 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 901 | - break; |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | + __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 792 | + 'event_espresso'), |
|
| 793 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | + ); |
|
| 796 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 797 | + 'event_espresso'); |
|
| 798 | + |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | + EVENT_ESPRESSO_VERSION); |
|
| 801 | + |
|
| 802 | + wp_enqueue_script('ee_admin_js'); |
|
| 803 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | + |
|
| 805 | + //add in special css for tiny_mce |
|
| 806 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + public function load_scripts_styles_display_preview_message() |
|
| 811 | + { |
|
| 812 | + |
|
| 813 | + $this->_set_message_template_group(); |
|
| 814 | + |
|
| 815 | + if (isset($this->_req_data['messenger'])) { |
|
| 816 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + wp_enqueue_style('espresso_preview_css', |
|
| 823 | + $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | + $this->_variation)); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + public function load_scripts_styles_settings() |
|
| 829 | + { |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | + EVENT_ESPRESSO_VERSION); |
|
| 832 | + wp_enqueue_style('ee-text-links'); |
|
| 833 | + wp_enqueue_style('ee-message-settings'); |
|
| 834 | + |
|
| 835 | + wp_enqueue_script('ee-messages-settings'); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * set views array for List Table |
|
| 841 | + */ |
|
| 842 | + public function _set_list_table_views_global_mtps() |
|
| 843 | + { |
|
| 844 | + $this->_views = array( |
|
| 845 | + 'in_use' => array( |
|
| 846 | + 'slug' => 'in_use', |
|
| 847 | + 'label' => __('In Use', 'event_espresso'), |
|
| 848 | + 'count' => 0, |
|
| 849 | + 'bulk_action' => array( |
|
| 850 | + 'trash_message_template' => __('Move to Trash', 'event_espresso') |
|
| 851 | + ) |
|
| 852 | + ) |
|
| 853 | + ); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * set views array for message queue list table |
|
| 859 | + */ |
|
| 860 | + public function _set_list_table_views_default() |
|
| 861 | + { |
|
| 862 | + EE_Registry::instance()->load_helper('Template'); |
|
| 863 | + |
|
| 864 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 865 | + 'message_list_table_bulk_actions') |
|
| 866 | + ? array( |
|
| 867 | + 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 868 | + 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 869 | + 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 870 | + 'send_now' => __('Send Now', 'event_espresso') |
|
| 871 | + ) |
|
| 872 | + : array(); |
|
| 873 | + |
|
| 874 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 875 | + 'message_list_table_bulk_actions') |
|
| 876 | + ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 877 | + : array(); |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + $this->_views = array( |
|
| 881 | + 'all' => array( |
|
| 882 | + 'slug' => 'all', |
|
| 883 | + 'label' => __('All', 'event_espresso'), |
|
| 884 | + 'count' => 0, |
|
| 885 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 886 | + ) |
|
| 887 | + ); |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 891 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 892 | + continue; |
|
| 893 | + } |
|
| 894 | + $status_bulk_actions = $common_bulk_actions; |
|
| 895 | + //unset bulk actions not applying to status |
|
| 896 | + if ( ! empty($status_bulk_actions)) { |
|
| 897 | + switch ($status) { |
|
| 898 | + case EEM_Message::status_idle : |
|
| 899 | + case EEM_Message::status_resend : |
|
| 900 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 901 | + break; |
|
| 902 | 902 | |
| 903 | - case EEM_Message::status_failed : |
|
| 904 | - case EEM_Message::status_debug_only : |
|
| 905 | - $status_bulk_actions = array(); |
|
| 906 | - break; |
|
| 903 | + case EEM_Message::status_failed : |
|
| 904 | + case EEM_Message::status_debug_only : |
|
| 905 | + $status_bulk_actions = array(); |
|
| 906 | + break; |
|
| 907 | 907 | |
| 908 | - case EEM_Message::status_incomplete : |
|
| 909 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 910 | - break; |
|
| 908 | + case EEM_Message::status_incomplete : |
|
| 909 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 910 | + break; |
|
| 911 | 911 | |
| 912 | - case EEM_Message::status_retry : |
|
| 913 | - case EEM_Message::status_sent : |
|
| 914 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 915 | - break; |
|
| 916 | - } |
|
| 917 | - } |
|
| 912 | + case EEM_Message::status_retry : |
|
| 913 | + case EEM_Message::status_sent : |
|
| 914 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 915 | + break; |
|
| 916 | + } |
|
| 917 | + } |
|
| 918 | 918 | |
| 919 | - $this->_views[strtolower($status)] = array( |
|
| 920 | - 'slug' => strtolower($status), |
|
| 921 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 922 | - 'count' => 0, |
|
| 923 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 924 | - ); |
|
| 925 | - } |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - protected function _ee_default_messages_overview_list_table() |
|
| 930 | - { |
|
| 931 | - $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 932 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - protected function _message_queue_list_table() |
|
| 937 | - { |
|
| 938 | - $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 939 | - $this->_template_args['per_column'] = 6; |
|
| 940 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 941 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 942 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - protected function _message_legend_items() |
|
| 947 | - { |
|
| 948 | - |
|
| 949 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 950 | - $action_items = array(); |
|
| 951 | - |
|
| 952 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 953 | - if ($action_item === 'see_notifications_for') { |
|
| 954 | - continue; |
|
| 955 | - } |
|
| 956 | - $action_items[$action_item] = array( |
|
| 957 | - 'class' => $action_details['css_class'], |
|
| 958 | - 'desc' => $action_details['label'] |
|
| 959 | - ); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - /** @type array $status_items status legend setup */ |
|
| 963 | - $status_items = array( |
|
| 964 | - 'sent_status' => array( |
|
| 965 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 966 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 967 | - ), |
|
| 968 | - 'idle_status' => array( |
|
| 969 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 970 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 971 | - ), |
|
| 972 | - 'failed_status' => array( |
|
| 973 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 974 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 975 | - ), |
|
| 976 | - 'resend_status' => array( |
|
| 977 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 978 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 979 | - ), |
|
| 980 | - 'incomplete_status' => array( |
|
| 981 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 982 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 983 | - ), |
|
| 984 | - 'retry_status' => array( |
|
| 985 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 986 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 987 | - ) |
|
| 988 | - ); |
|
| 989 | - if (EEM_Message::debug()) { |
|
| 990 | - $status_items['debug_only_status'] = array( |
|
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 992 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 993 | - ); |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - return array_merge($action_items, $status_items); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - protected function _custom_mtps_preview() |
|
| 1001 | - { |
|
| 1002 | - $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1003 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1004 | - 'event_espresso') . '" />'; |
|
| 1005 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso. With the Custom Message Templates feature, you are able to create custom templates and set them per event.', |
|
| 1006 | - 'event_espresso') . '</strong>'; |
|
| 1007 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * get_message_templates |
|
| 1013 | - * This gets all the message templates for listing on the overview list. |
|
| 1014 | - * |
|
| 1015 | - * @access public |
|
| 1016 | - * |
|
| 1017 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1018 | - * @param string $type the current _view we're getting templates for |
|
| 1019 | - * @param bool $count return count? |
|
| 1020 | - * @param bool $all disregard any paging info (get all data); |
|
| 1021 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1022 | - * |
|
| 1023 | - * @return array |
|
| 1024 | - */ |
|
| 1025 | - public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1026 | - { |
|
| 1027 | - |
|
| 1028 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1029 | - |
|
| 1030 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1031 | - $orderby = $this->_req_data['orderby']; |
|
| 1032 | - |
|
| 1033 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1034 | - |
|
| 1035 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1036 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1037 | - |
|
| 1038 | - $offset = ($current_page - 1) * $per_page; |
|
| 1039 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1040 | - |
|
| 1041 | - |
|
| 1042 | - //options will match what is in the _views array property |
|
| 1043 | - switch ($type) { |
|
| 919 | + $this->_views[strtolower($status)] = array( |
|
| 920 | + 'slug' => strtolower($status), |
|
| 921 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 922 | + 'count' => 0, |
|
| 923 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 924 | + ); |
|
| 925 | + } |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + protected function _ee_default_messages_overview_list_table() |
|
| 930 | + { |
|
| 931 | + $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 932 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + protected function _message_queue_list_table() |
|
| 937 | + { |
|
| 938 | + $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 939 | + $this->_template_args['per_column'] = 6; |
|
| 940 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 941 | + $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 942 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + protected function _message_legend_items() |
|
| 947 | + { |
|
| 948 | + |
|
| 949 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 950 | + $action_items = array(); |
|
| 951 | + |
|
| 952 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 953 | + if ($action_item === 'see_notifications_for') { |
|
| 954 | + continue; |
|
| 955 | + } |
|
| 956 | + $action_items[$action_item] = array( |
|
| 957 | + 'class' => $action_details['css_class'], |
|
| 958 | + 'desc' => $action_details['label'] |
|
| 959 | + ); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + /** @type array $status_items status legend setup */ |
|
| 963 | + $status_items = array( |
|
| 964 | + 'sent_status' => array( |
|
| 965 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 966 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 967 | + ), |
|
| 968 | + 'idle_status' => array( |
|
| 969 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 970 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 971 | + ), |
|
| 972 | + 'failed_status' => array( |
|
| 973 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 974 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 975 | + ), |
|
| 976 | + 'resend_status' => array( |
|
| 977 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 978 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 979 | + ), |
|
| 980 | + 'incomplete_status' => array( |
|
| 981 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 982 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 983 | + ), |
|
| 984 | + 'retry_status' => array( |
|
| 985 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 986 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 987 | + ) |
|
| 988 | + ); |
|
| 989 | + if (EEM_Message::debug()) { |
|
| 990 | + $status_items['debug_only_status'] = array( |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 992 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 993 | + ); |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + return array_merge($action_items, $status_items); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + protected function _custom_mtps_preview() |
|
| 1001 | + { |
|
| 1002 | + $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1003 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1004 | + 'event_espresso') . '" />'; |
|
| 1005 | + $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso. With the Custom Message Templates feature, you are able to create custom templates and set them per event.', |
|
| 1006 | + 'event_espresso') . '</strong>'; |
|
| 1007 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * get_message_templates |
|
| 1013 | + * This gets all the message templates for listing on the overview list. |
|
| 1014 | + * |
|
| 1015 | + * @access public |
|
| 1016 | + * |
|
| 1017 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1018 | + * @param string $type the current _view we're getting templates for |
|
| 1019 | + * @param bool $count return count? |
|
| 1020 | + * @param bool $all disregard any paging info (get all data); |
|
| 1021 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1022 | + * |
|
| 1023 | + * @return array |
|
| 1024 | + */ |
|
| 1025 | + public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1026 | + { |
|
| 1027 | + |
|
| 1028 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1029 | + |
|
| 1030 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1031 | + $orderby = $this->_req_data['orderby']; |
|
| 1032 | + |
|
| 1033 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1034 | + |
|
| 1035 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1036 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1037 | + |
|
| 1038 | + $offset = ($current_page - 1) * $per_page; |
|
| 1039 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1040 | + |
|
| 1041 | + |
|
| 1042 | + //options will match what is in the _views array property |
|
| 1043 | + switch ($type) { |
|
| 1044 | 1044 | |
| 1045 | - case 'in_use': |
|
| 1046 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1047 | - break; |
|
| 1045 | + case 'in_use': |
|
| 1046 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1047 | + break; |
|
| 1048 | 1048 | |
| 1049 | - default: |
|
| 1050 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1049 | + default: |
|
| 1050 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1051 | 1051 | |
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - return $templates; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * filters etc might need a list of installed message_types |
|
| 1060 | - * @return array an array of message type objects |
|
| 1061 | - */ |
|
| 1062 | - public function get_installed_message_types() |
|
| 1063 | - { |
|
| 1064 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1065 | - $installed = array(); |
|
| 1066 | - |
|
| 1067 | - foreach ($installed_message_types as $message_type) { |
|
| 1068 | - $installed[$message_type->name] = $message_type; |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - return $installed; |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * _add_message_template |
|
| 1077 | - * |
|
| 1078 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1079 | - * |
|
| 1080 | - * @param string $message_type |
|
| 1081 | - * @param string $messenger |
|
| 1082 | - * @param string $GRP_ID |
|
| 1083 | - * |
|
| 1084 | - * @throws EE_error |
|
| 1085 | - */ |
|
| 1086 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1087 | - { |
|
| 1088 | - //set values override any request data |
|
| 1089 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1090 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1091 | - |
|
| 1092 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1093 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1094 | - |
|
| 1095 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1096 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1097 | - |
|
| 1098 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1099 | - if (empty($message_type) || empty($messenger)) { |
|
| 1100 | - throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1101 | - 'event_espresso')); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1105 | - if (empty($GRP_ID)) { |
|
| 1106 | - throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1107 | - 'event_espresso')); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - //let's just make sure the template gets generated! |
|
| 1111 | - |
|
| 1112 | - //we need to reassign some variables for what the insert is expecting |
|
| 1113 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1114 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1115 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1116 | - $this->_insert_or_update_message_template(true); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * public wrapper for the _add_message_template method |
|
| 1122 | - * |
|
| 1123 | - * @param string $message_type message type slug |
|
| 1124 | - * @param string $messenger messenger slug |
|
| 1125 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1126 | - * off of. |
|
| 1127 | - */ |
|
| 1128 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1129 | - { |
|
| 1130 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * _edit_message_template |
|
| 1136 | - * |
|
| 1137 | - * @access protected |
|
| 1138 | - * @return void |
|
| 1139 | - */ |
|
| 1140 | - protected function _edit_message_template() |
|
| 1141 | - { |
|
| 1142 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1143 | - $template_fields = ''; |
|
| 1144 | - $sidebar_fields = ''; |
|
| 1145 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1146 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1147 | - |
|
| 1148 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1149 | - ? absint($this->_req_data['id']) |
|
| 1150 | - : false; |
|
| 1151 | - |
|
| 1152 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1153 | - $message_template_group = $this->_message_template_group; |
|
| 1154 | - $c_label = $message_template_group->context_label(); |
|
| 1155 | - $c_config = $message_template_group->contexts_config(); |
|
| 1156 | - |
|
| 1157 | - reset($c_config); |
|
| 1158 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1159 | - ? strtolower($this->_req_data['context']) |
|
| 1160 | - : key($c_config); |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - if (empty($GRP_ID)) { |
|
| 1164 | - $action = 'insert_message_template'; |
|
| 1165 | - //$button_both = false; |
|
| 1166 | - //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1167 | - //$button_actions = array('something_different'); |
|
| 1168 | - //$referrer = false; |
|
| 1169 | - $edit_message_template_form_url = add_query_arg( |
|
| 1170 | - array('action' => $action, 'noheader' => true), |
|
| 1171 | - EE_MSG_ADMIN_URL |
|
| 1172 | - ); |
|
| 1173 | - } else { |
|
| 1174 | - $action = 'update_message_template'; |
|
| 1175 | - //$button_both = true; |
|
| 1176 | - //$button_text = array(); |
|
| 1177 | - //$button_actions = array(); |
|
| 1178 | - //$referrer = $this->_admin_base_url; |
|
| 1179 | - $edit_message_template_form_url = add_query_arg( |
|
| 1180 | - array('action' => $action, 'noheader' => true), |
|
| 1181 | - EE_MSG_ADMIN_URL |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - //set active messenger for this view |
|
| 1186 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1187 | - $message_template_group->messenger() |
|
| 1188 | - ); |
|
| 1189 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - //Do we have any validation errors? |
|
| 1193 | - $validators = $this->_get_transient(); |
|
| 1194 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1195 | - |
|
| 1196 | - |
|
| 1197 | - //we need to assemble the title from Various details |
|
| 1198 | - $context_label = sprintf( |
|
| 1199 | - __('(%s %s)', 'event_espresso'), |
|
| 1200 | - $c_config[$context]['label'], |
|
| 1201 | - ucwords($c_label['label']) |
|
| 1202 | - ); |
|
| 1203 | - |
|
| 1204 | - $title = sprintf( |
|
| 1205 | - __(' %s %s Template %s', 'event_espresso'), |
|
| 1206 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1207 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1208 | - $context_label |
|
| 1209 | - ); |
|
| 1210 | - |
|
| 1211 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1212 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1213 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1217 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1218 | - $message_template_group->messenger(), |
|
| 1219 | - $message_template_group->message_type() |
|
| 1220 | - ); |
|
| 1221 | - |
|
| 1222 | - if ( ! $template_field_structure) { |
|
| 1223 | - $template_field_structure = false; |
|
| 1224 | - $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1225 | - 'event_espresso'); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - $message_templates = $message_template_group->context_templates(); |
|
| 1230 | - |
|
| 1231 | - |
|
| 1232 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1233 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1234 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1235 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1240 | - if ( ! empty($template_field_structure)) { |
|
| 1241 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1242 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1243 | - if ($template_field == 'extra') { |
|
| 1244 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1245 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1246 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1247 | - $content = $message_template instanceof EE_Message_Template |
|
| 1248 | - ? $message_template->get('MTP_content') |
|
| 1249 | - : ''; |
|
| 1250 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1251 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1252 | - $continue = false; |
|
| 1253 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1254 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1255 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1256 | - $continue = true; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - if ($continue) { |
|
| 1260 | - continue; |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + return $templates; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * filters etc might need a list of installed message_types |
|
| 1060 | + * @return array an array of message type objects |
|
| 1061 | + */ |
|
| 1062 | + public function get_installed_message_types() |
|
| 1063 | + { |
|
| 1064 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1065 | + $installed = array(); |
|
| 1066 | + |
|
| 1067 | + foreach ($installed_message_types as $message_type) { |
|
| 1068 | + $installed[$message_type->name] = $message_type; |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + return $installed; |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * _add_message_template |
|
| 1077 | + * |
|
| 1078 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1079 | + * |
|
| 1080 | + * @param string $message_type |
|
| 1081 | + * @param string $messenger |
|
| 1082 | + * @param string $GRP_ID |
|
| 1083 | + * |
|
| 1084 | + * @throws EE_error |
|
| 1085 | + */ |
|
| 1086 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1087 | + { |
|
| 1088 | + //set values override any request data |
|
| 1089 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1090 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1091 | + |
|
| 1092 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1093 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1094 | + |
|
| 1095 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1096 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1097 | + |
|
| 1098 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1099 | + if (empty($message_type) || empty($messenger)) { |
|
| 1100 | + throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1101 | + 'event_espresso')); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1105 | + if (empty($GRP_ID)) { |
|
| 1106 | + throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1107 | + 'event_espresso')); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + //let's just make sure the template gets generated! |
|
| 1111 | + |
|
| 1112 | + //we need to reassign some variables for what the insert is expecting |
|
| 1113 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1114 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1115 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1116 | + $this->_insert_or_update_message_template(true); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + |
|
| 1120 | + /** |
|
| 1121 | + * public wrapper for the _add_message_template method |
|
| 1122 | + * |
|
| 1123 | + * @param string $message_type message type slug |
|
| 1124 | + * @param string $messenger messenger slug |
|
| 1125 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1126 | + * off of. |
|
| 1127 | + */ |
|
| 1128 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1129 | + { |
|
| 1130 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * _edit_message_template |
|
| 1136 | + * |
|
| 1137 | + * @access protected |
|
| 1138 | + * @return void |
|
| 1139 | + */ |
|
| 1140 | + protected function _edit_message_template() |
|
| 1141 | + { |
|
| 1142 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1143 | + $template_fields = ''; |
|
| 1144 | + $sidebar_fields = ''; |
|
| 1145 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1146 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1147 | + |
|
| 1148 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1149 | + ? absint($this->_req_data['id']) |
|
| 1150 | + : false; |
|
| 1151 | + |
|
| 1152 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1153 | + $message_template_group = $this->_message_template_group; |
|
| 1154 | + $c_label = $message_template_group->context_label(); |
|
| 1155 | + $c_config = $message_template_group->contexts_config(); |
|
| 1156 | + |
|
| 1157 | + reset($c_config); |
|
| 1158 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1159 | + ? strtolower($this->_req_data['context']) |
|
| 1160 | + : key($c_config); |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + if (empty($GRP_ID)) { |
|
| 1164 | + $action = 'insert_message_template'; |
|
| 1165 | + //$button_both = false; |
|
| 1166 | + //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1167 | + //$button_actions = array('something_different'); |
|
| 1168 | + //$referrer = false; |
|
| 1169 | + $edit_message_template_form_url = add_query_arg( |
|
| 1170 | + array('action' => $action, 'noheader' => true), |
|
| 1171 | + EE_MSG_ADMIN_URL |
|
| 1172 | + ); |
|
| 1173 | + } else { |
|
| 1174 | + $action = 'update_message_template'; |
|
| 1175 | + //$button_both = true; |
|
| 1176 | + //$button_text = array(); |
|
| 1177 | + //$button_actions = array(); |
|
| 1178 | + //$referrer = $this->_admin_base_url; |
|
| 1179 | + $edit_message_template_form_url = add_query_arg( |
|
| 1180 | + array('action' => $action, 'noheader' => true), |
|
| 1181 | + EE_MSG_ADMIN_URL |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + //set active messenger for this view |
|
| 1186 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1187 | + $message_template_group->messenger() |
|
| 1188 | + ); |
|
| 1189 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + //Do we have any validation errors? |
|
| 1193 | + $validators = $this->_get_transient(); |
|
| 1194 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1195 | + |
|
| 1196 | + |
|
| 1197 | + //we need to assemble the title from Various details |
|
| 1198 | + $context_label = sprintf( |
|
| 1199 | + __('(%s %s)', 'event_espresso'), |
|
| 1200 | + $c_config[$context]['label'], |
|
| 1201 | + ucwords($c_label['label']) |
|
| 1202 | + ); |
|
| 1203 | + |
|
| 1204 | + $title = sprintf( |
|
| 1205 | + __(' %s %s Template %s', 'event_espresso'), |
|
| 1206 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1207 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1208 | + $context_label |
|
| 1209 | + ); |
|
| 1210 | + |
|
| 1211 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1212 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1213 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1217 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1218 | + $message_template_group->messenger(), |
|
| 1219 | + $message_template_group->message_type() |
|
| 1220 | + ); |
|
| 1221 | + |
|
| 1222 | + if ( ! $template_field_structure) { |
|
| 1223 | + $template_field_structure = false; |
|
| 1224 | + $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1225 | + 'event_espresso'); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + $message_templates = $message_template_group->context_templates(); |
|
| 1230 | + |
|
| 1231 | + |
|
| 1232 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
|
| 1233 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1234 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1235 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1240 | + if ( ! empty($template_field_structure)) { |
|
| 1241 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1242 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
|
| 1243 | + if ($template_field == 'extra') { |
|
| 1244 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1245 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1246 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1247 | + $content = $message_template instanceof EE_Message_Template |
|
| 1248 | + ? $message_template->get('MTP_content') |
|
| 1249 | + : ''; |
|
| 1250 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1251 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1252 | + $continue = false; |
|
| 1253 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1254 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1255 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1256 | + $continue = true; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + if ($continue) { |
|
| 1260 | + continue; |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | 1263 | |
| 1264 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1265 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1266 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1267 | - $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1264 | + $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1265 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1266 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1267 | + $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1268 | 1268 | |
| 1269 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1270 | - && in_array($extra_field, $v_fields) |
|
| 1271 | - && |
|
| 1272 | - ( |
|
| 1273 | - is_array($validators[$extra_field]) |
|
| 1274 | - && isset($validators[$extra_field]['msg']) |
|
| 1275 | - ) |
|
| 1276 | - ? 'validate-error ' . $css_class |
|
| 1277 | - : $css_class; |
|
| 1269 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1270 | + && in_array($extra_field, $v_fields) |
|
| 1271 | + && |
|
| 1272 | + ( |
|
| 1273 | + is_array($validators[$extra_field]) |
|
| 1274 | + && isset($validators[$extra_field]['msg']) |
|
| 1275 | + ) |
|
| 1276 | + ? 'validate-error ' . $css_class |
|
| 1277 | + : $css_class; |
|
| 1278 | 1278 | |
| 1279 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1280 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1281 | - : ''; |
|
| 1279 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1280 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1281 | + : ''; |
|
| 1282 | 1282 | |
| 1283 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1284 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1283 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1284 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1285 | 1285 | |
| 1286 | 1286 | |
| 1287 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1287 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1288 | 1288 | |
| 1289 | - //shortcode selector |
|
| 1290 | - $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1291 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1292 | - $field_name_to_use, |
|
| 1293 | - $field_id |
|
| 1294 | - ); |
|
| 1289 | + //shortcode selector |
|
| 1290 | + $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1291 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1292 | + $field_name_to_use, |
|
| 1293 | + $field_id |
|
| 1294 | + ); |
|
| 1295 | 1295 | |
| 1296 | - if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1297 | - //we want to decode the entities |
|
| 1298 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1299 | - html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1300 | - ); |
|
| 1296 | + if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1297 | + //we want to decode the entities |
|
| 1298 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1299 | + html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1300 | + ); |
|
| 1301 | 1301 | |
| 1302 | - }/**/ |
|
| 1303 | - } |
|
| 1304 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1305 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1302 | + }/**/ |
|
| 1303 | + } |
|
| 1304 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1305 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1306 | 1306 | |
| 1307 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1308 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1309 | - 'label' => null, |
|
| 1310 | - 'input' => 'hidden', |
|
| 1311 | - 'type' => 'int', |
|
| 1312 | - 'required' => false, |
|
| 1313 | - 'validation' => false, |
|
| 1314 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1315 | - 'css_class' => '', |
|
| 1316 | - 'format' => '%d', |
|
| 1317 | - 'db-col' => 'MTP_ID' |
|
| 1318 | - ); |
|
| 1307 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1308 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1309 | + 'label' => null, |
|
| 1310 | + 'input' => 'hidden', |
|
| 1311 | + 'type' => 'int', |
|
| 1312 | + 'required' => false, |
|
| 1313 | + 'validation' => false, |
|
| 1314 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1315 | + 'css_class' => '', |
|
| 1316 | + 'format' => '%d', |
|
| 1317 | + 'db-col' => 'MTP_ID' |
|
| 1318 | + ); |
|
| 1319 | 1319 | |
| 1320 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1321 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1322 | - 'label' => null, |
|
| 1323 | - 'input' => 'hidden', |
|
| 1324 | - 'type' => 'string', |
|
| 1325 | - 'required' => false, |
|
| 1326 | - 'validation' => true, |
|
| 1327 | - 'value' => $reference_field, |
|
| 1328 | - 'css_class' => '', |
|
| 1329 | - 'format' => '%s', |
|
| 1330 | - 'db-col' => 'MTP_template_field' |
|
| 1331 | - ); |
|
| 1332 | - } |
|
| 1333 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1334 | - } else { |
|
| 1335 | - $field_id = $template_field . '-content'; |
|
| 1336 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1337 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1338 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1339 | - ? $message_templates[$context][$template_field] |
|
| 1340 | - : null; |
|
| 1341 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1342 | - && is_array($message_templates[$context]) |
|
| 1343 | - && $message_template instanceof EE_Message_Template |
|
| 1344 | - ? $message_template->get('MTP_content') |
|
| 1345 | - : ''; |
|
| 1320 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1321 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1322 | + 'label' => null, |
|
| 1323 | + 'input' => 'hidden', |
|
| 1324 | + 'type' => 'string', |
|
| 1325 | + 'required' => false, |
|
| 1326 | + 'validation' => true, |
|
| 1327 | + 'value' => $reference_field, |
|
| 1328 | + 'css_class' => '', |
|
| 1329 | + 'format' => '%s', |
|
| 1330 | + 'db-col' => 'MTP_template_field' |
|
| 1331 | + ); |
|
| 1332 | + } |
|
| 1333 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1334 | + } else { |
|
| 1335 | + $field_id = $template_field . '-content'; |
|
| 1336 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1337 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1338 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1339 | + ? $message_templates[$context][$template_field] |
|
| 1340 | + : null; |
|
| 1341 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1342 | + && is_array($message_templates[$context]) |
|
| 1343 | + && $message_template instanceof EE_Message_Template |
|
| 1344 | + ? $message_template->get('MTP_content') |
|
| 1345 | + : ''; |
|
| 1346 | 1346 | |
| 1347 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1348 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1349 | - ? $validators[$template_field]['value'] |
|
| 1350 | - : $template_form_fields[$field_id]['value']; |
|
| 1347 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1348 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1349 | + ? $validators[$template_field]['value'] |
|
| 1350 | + : $template_form_fields[$field_id]['value']; |
|
| 1351 | 1351 | |
| 1352 | 1352 | |
| 1353 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1354 | - $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1355 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1356 | - && in_array($template_field, $v_fields) |
|
| 1357 | - && isset($validators[$template_field]['msg']) |
|
| 1358 | - ? 'validate-error ' . $css_class |
|
| 1359 | - : $css_class; |
|
| 1353 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1354 | + $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1355 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1356 | + && in_array($template_field, $v_fields) |
|
| 1357 | + && isset($validators[$template_field]['msg']) |
|
| 1358 | + ? 'validate-error ' . $css_class |
|
| 1359 | + : $css_class; |
|
| 1360 | 1360 | |
| 1361 | - //shortcode selector |
|
| 1362 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1363 | - $template_field, $field_id |
|
| 1364 | - ); |
|
| 1365 | - } |
|
| 1361 | + //shortcode selector |
|
| 1362 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1363 | + $template_field, $field_id |
|
| 1364 | + ); |
|
| 1365 | + } |
|
| 1366 | 1366 | |
| 1367 | - //k took care of content field(s) now let's take care of others. |
|
| 1367 | + //k took care of content field(s) now let's take care of others. |
|
| 1368 | 1368 | |
| 1369 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1370 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1369 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1370 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1371 | 1371 | |
| 1372 | - //foreach template field there are actually two form fields created |
|
| 1373 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1374 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1375 | - 'label' => null, |
|
| 1376 | - 'input' => 'hidden', |
|
| 1377 | - 'type' => 'int', |
|
| 1378 | - 'required' => false, |
|
| 1379 | - 'validation' => true, |
|
| 1380 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1381 | - 'css_class' => '', |
|
| 1382 | - 'format' => '%d', |
|
| 1383 | - 'db-col' => 'MTP_ID' |
|
| 1384 | - ); |
|
| 1372 | + //foreach template field there are actually two form fields created |
|
| 1373 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1374 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1375 | + 'label' => null, |
|
| 1376 | + 'input' => 'hidden', |
|
| 1377 | + 'type' => 'int', |
|
| 1378 | + 'required' => false, |
|
| 1379 | + 'validation' => true, |
|
| 1380 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1381 | + 'css_class' => '', |
|
| 1382 | + 'format' => '%d', |
|
| 1383 | + 'db-col' => 'MTP_ID' |
|
| 1384 | + ); |
|
| 1385 | 1385 | |
| 1386 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1387 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1388 | - 'label' => null, |
|
| 1389 | - 'input' => 'hidden', |
|
| 1390 | - 'type' => 'string', |
|
| 1391 | - 'required' => false, |
|
| 1392 | - 'validation' => true, |
|
| 1393 | - 'value' => $template_field, |
|
| 1394 | - 'css_class' => '', |
|
| 1395 | - 'format' => '%s', |
|
| 1396 | - 'db-col' => 'MTP_template_field' |
|
| 1397 | - ); |
|
| 1386 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1387 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1388 | + 'label' => null, |
|
| 1389 | + 'input' => 'hidden', |
|
| 1390 | + 'type' => 'string', |
|
| 1391 | + 'required' => false, |
|
| 1392 | + 'validation' => true, |
|
| 1393 | + 'value' => $template_field, |
|
| 1394 | + 'css_class' => '', |
|
| 1395 | + 'format' => '%s', |
|
| 1396 | + 'db-col' => 'MTP_template_field' |
|
| 1397 | + ); |
|
| 1398 | 1398 | |
| 1399 | - } |
|
| 1399 | + } |
|
| 1400 | 1400 | |
| 1401 | - //add other fields |
|
| 1402 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1403 | - 'name' => 'MTP_context', |
|
| 1404 | - 'label' => null, |
|
| 1405 | - 'input' => 'hidden', |
|
| 1406 | - 'type' => 'string', |
|
| 1407 | - 'required' => false, |
|
| 1408 | - 'validation' => true, |
|
| 1409 | - 'value' => $context, |
|
| 1410 | - 'css_class' => '', |
|
| 1411 | - 'format' => '%s', |
|
| 1412 | - 'db-col' => 'MTP_context' |
|
| 1413 | - ); |
|
| 1401 | + //add other fields |
|
| 1402 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1403 | + 'name' => 'MTP_context', |
|
| 1404 | + 'label' => null, |
|
| 1405 | + 'input' => 'hidden', |
|
| 1406 | + 'type' => 'string', |
|
| 1407 | + 'required' => false, |
|
| 1408 | + 'validation' => true, |
|
| 1409 | + 'value' => $context, |
|
| 1410 | + 'css_class' => '', |
|
| 1411 | + 'format' => '%s', |
|
| 1412 | + 'db-col' => 'MTP_context' |
|
| 1413 | + ); |
|
| 1414 | 1414 | |
| 1415 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1416 | - 'name' => 'GRP_ID', |
|
| 1417 | - 'label' => null, |
|
| 1418 | - 'input' => 'hidden', |
|
| 1419 | - 'type' => 'int', |
|
| 1420 | - 'required' => false, |
|
| 1421 | - 'validation' => true, |
|
| 1422 | - 'value' => $GRP_ID, |
|
| 1423 | - 'css_class' => '', |
|
| 1424 | - 'format' => '%d', |
|
| 1425 | - 'db-col' => 'GRP_ID' |
|
| 1426 | - ); |
|
| 1415 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1416 | + 'name' => 'GRP_ID', |
|
| 1417 | + 'label' => null, |
|
| 1418 | + 'input' => 'hidden', |
|
| 1419 | + 'type' => 'int', |
|
| 1420 | + 'required' => false, |
|
| 1421 | + 'validation' => true, |
|
| 1422 | + 'value' => $GRP_ID, |
|
| 1423 | + 'css_class' => '', |
|
| 1424 | + 'format' => '%d', |
|
| 1425 | + 'db-col' => 'GRP_ID' |
|
| 1426 | + ); |
|
| 1427 | 1427 | |
| 1428 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1429 | - 'name' => 'MTP_messenger', |
|
| 1430 | - 'label' => null, |
|
| 1431 | - 'input' => 'hidden', |
|
| 1432 | - 'type' => 'string', |
|
| 1433 | - 'required' => false, |
|
| 1434 | - 'validation' => true, |
|
| 1435 | - 'value' => $message_template_group->messenger(), |
|
| 1436 | - 'css_class' => '', |
|
| 1437 | - 'format' => '%s', |
|
| 1438 | - 'db-col' => 'MTP_messenger' |
|
| 1439 | - ); |
|
| 1428 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1429 | + 'name' => 'MTP_messenger', |
|
| 1430 | + 'label' => null, |
|
| 1431 | + 'input' => 'hidden', |
|
| 1432 | + 'type' => 'string', |
|
| 1433 | + 'required' => false, |
|
| 1434 | + 'validation' => true, |
|
| 1435 | + 'value' => $message_template_group->messenger(), |
|
| 1436 | + 'css_class' => '', |
|
| 1437 | + 'format' => '%s', |
|
| 1438 | + 'db-col' => 'MTP_messenger' |
|
| 1439 | + ); |
|
| 1440 | 1440 | |
| 1441 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1442 | - 'name' => 'MTP_message_type', |
|
| 1443 | - 'label' => null, |
|
| 1444 | - 'input' => 'hidden', |
|
| 1445 | - 'type' => 'string', |
|
| 1446 | - 'required' => false, |
|
| 1447 | - 'validation' => true, |
|
| 1448 | - 'value' => $message_template_group->message_type(), |
|
| 1449 | - 'css_class' => '', |
|
| 1450 | - 'format' => '%s', |
|
| 1451 | - 'db-col' => 'MTP_message_type' |
|
| 1452 | - ); |
|
| 1441 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1442 | + 'name' => 'MTP_message_type', |
|
| 1443 | + 'label' => null, |
|
| 1444 | + 'input' => 'hidden', |
|
| 1445 | + 'type' => 'string', |
|
| 1446 | + 'required' => false, |
|
| 1447 | + 'validation' => true, |
|
| 1448 | + 'value' => $message_template_group->message_type(), |
|
| 1449 | + 'css_class' => '', |
|
| 1450 | + 'format' => '%s', |
|
| 1451 | + 'db-col' => 'MTP_message_type' |
|
| 1452 | + ); |
|
| 1453 | 1453 | |
| 1454 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1455 | - 'name' => 'MTP_is_global', |
|
| 1456 | - 'label' => __('Global Template', 'event_espresso'), |
|
| 1457 | - 'input' => 'hidden', |
|
| 1458 | - 'type' => 'int', |
|
| 1459 | - 'required' => false, |
|
| 1460 | - 'validation' => true, |
|
| 1461 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1462 | - 'css_class' => '', |
|
| 1463 | - 'format' => '%d', |
|
| 1464 | - 'db-col' => 'MTP_is_global' |
|
| 1465 | - ); |
|
| 1454 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1455 | + 'name' => 'MTP_is_global', |
|
| 1456 | + 'label' => __('Global Template', 'event_espresso'), |
|
| 1457 | + 'input' => 'hidden', |
|
| 1458 | + 'type' => 'int', |
|
| 1459 | + 'required' => false, |
|
| 1460 | + 'validation' => true, |
|
| 1461 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1462 | + 'css_class' => '', |
|
| 1463 | + 'format' => '%d', |
|
| 1464 | + 'db-col' => 'MTP_is_global' |
|
| 1465 | + ); |
|
| 1466 | 1466 | |
| 1467 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1468 | - 'name' => 'MTP_is_override', |
|
| 1469 | - 'label' => __('Override all custom', 'event_espresso'), |
|
| 1470 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1471 | - 'type' => 'int', |
|
| 1472 | - 'required' => false, |
|
| 1473 | - 'validation' => true, |
|
| 1474 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1475 | - 'css_class' => '', |
|
| 1476 | - 'format' => '%d', |
|
| 1477 | - 'db-col' => 'MTP_is_override' |
|
| 1478 | - ); |
|
| 1467 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1468 | + 'name' => 'MTP_is_override', |
|
| 1469 | + 'label' => __('Override all custom', 'event_espresso'), |
|
| 1470 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1471 | + 'type' => 'int', |
|
| 1472 | + 'required' => false, |
|
| 1473 | + 'validation' => true, |
|
| 1474 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1475 | + 'css_class' => '', |
|
| 1476 | + 'format' => '%d', |
|
| 1477 | + 'db-col' => 'MTP_is_override' |
|
| 1478 | + ); |
|
| 1479 | 1479 | |
| 1480 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1481 | - 'name' => 'MTP_is_active', |
|
| 1482 | - 'label' => __('Active Template', 'event_espresso'), |
|
| 1483 | - 'input' => 'hidden', |
|
| 1484 | - 'type' => 'int', |
|
| 1485 | - 'required' => false, |
|
| 1486 | - 'validation' => true, |
|
| 1487 | - 'value' => $message_template_group->is_active(), |
|
| 1488 | - 'css_class' => '', |
|
| 1489 | - 'format' => '%d', |
|
| 1490 | - 'db-col' => 'MTP_is_active' |
|
| 1491 | - ); |
|
| 1480 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1481 | + 'name' => 'MTP_is_active', |
|
| 1482 | + 'label' => __('Active Template', 'event_espresso'), |
|
| 1483 | + 'input' => 'hidden', |
|
| 1484 | + 'type' => 'int', |
|
| 1485 | + 'required' => false, |
|
| 1486 | + 'validation' => true, |
|
| 1487 | + 'value' => $message_template_group->is_active(), |
|
| 1488 | + 'css_class' => '', |
|
| 1489 | + 'format' => '%d', |
|
| 1490 | + 'db-col' => 'MTP_is_active' |
|
| 1491 | + ); |
|
| 1492 | 1492 | |
| 1493 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1494 | - 'name' => 'MTP_deleted', |
|
| 1495 | - 'label' => null, |
|
| 1496 | - 'input' => 'hidden', |
|
| 1497 | - 'type' => 'int', |
|
| 1498 | - 'required' => false, |
|
| 1499 | - 'validation' => true, |
|
| 1500 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1501 | - 'css_class' => '', |
|
| 1502 | - 'format' => '%d', |
|
| 1503 | - 'db-col' => 'MTP_deleted' |
|
| 1504 | - ); |
|
| 1505 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1506 | - 'name' => 'MTP_user_id', |
|
| 1507 | - 'label' => __('Author', 'event_espresso'), |
|
| 1508 | - 'input' => 'hidden', |
|
| 1509 | - 'type' => 'int', |
|
| 1510 | - 'required' => false, |
|
| 1511 | - 'validation' => false, |
|
| 1512 | - 'value' => $message_template_group->user(), |
|
| 1513 | - 'format' => '%d', |
|
| 1514 | - 'db-col' => 'MTP_user_id' |
|
| 1515 | - ); |
|
| 1493 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1494 | + 'name' => 'MTP_deleted', |
|
| 1495 | + 'label' => null, |
|
| 1496 | + 'input' => 'hidden', |
|
| 1497 | + 'type' => 'int', |
|
| 1498 | + 'required' => false, |
|
| 1499 | + 'validation' => true, |
|
| 1500 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1501 | + 'css_class' => '', |
|
| 1502 | + 'format' => '%d', |
|
| 1503 | + 'db-col' => 'MTP_deleted' |
|
| 1504 | + ); |
|
| 1505 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1506 | + 'name' => 'MTP_user_id', |
|
| 1507 | + 'label' => __('Author', 'event_espresso'), |
|
| 1508 | + 'input' => 'hidden', |
|
| 1509 | + 'type' => 'int', |
|
| 1510 | + 'required' => false, |
|
| 1511 | + 'validation' => false, |
|
| 1512 | + 'value' => $message_template_group->user(), |
|
| 1513 | + 'format' => '%d', |
|
| 1514 | + 'db-col' => 'MTP_user_id' |
|
| 1515 | + ); |
|
| 1516 | 1516 | |
| 1517 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1518 | - 'name' => 'action', |
|
| 1519 | - 'input' => 'hidden', |
|
| 1520 | - 'type' => 'string', |
|
| 1521 | - 'value' => $action |
|
| 1522 | - ); |
|
| 1517 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1518 | + 'name' => 'action', |
|
| 1519 | + 'input' => 'hidden', |
|
| 1520 | + 'type' => 'string', |
|
| 1521 | + 'value' => $action |
|
| 1522 | + ); |
|
| 1523 | 1523 | |
| 1524 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1525 | - 'name' => 'id', |
|
| 1526 | - 'input' => 'hidden', |
|
| 1527 | - 'type' => 'int', |
|
| 1528 | - 'value' => $GRP_ID |
|
| 1529 | - ); |
|
| 1530 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1531 | - 'name' => $action . '_nonce', |
|
| 1532 | - 'input' => 'hidden', |
|
| 1533 | - 'type' => 'string', |
|
| 1534 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1535 | - ); |
|
| 1524 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1525 | + 'name' => 'id', |
|
| 1526 | + 'input' => 'hidden', |
|
| 1527 | + 'type' => 'int', |
|
| 1528 | + 'value' => $GRP_ID |
|
| 1529 | + ); |
|
| 1530 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1531 | + 'name' => $action . '_nonce', |
|
| 1532 | + 'input' => 'hidden', |
|
| 1533 | + 'type' => 'string', |
|
| 1534 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1535 | + ); |
|
| 1536 | 1536 | |
| 1537 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1538 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1539 | - 'name' => 'template_switch', |
|
| 1540 | - 'input' => 'hidden', |
|
| 1541 | - 'type' => 'int', |
|
| 1542 | - 'value' => 1 |
|
| 1543 | - ); |
|
| 1544 | - } |
|
| 1537 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1538 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1539 | + 'name' => 'template_switch', |
|
| 1540 | + 'input' => 'hidden', |
|
| 1541 | + 'type' => 'int', |
|
| 1542 | + 'value' => 1 |
|
| 1543 | + ); |
|
| 1544 | + } |
|
| 1545 | 1545 | |
| 1546 | 1546 | |
| 1547 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1548 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1547 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1548 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1549 | 1549 | |
| 1550 | 1550 | |
| 1551 | - } //end if ( !empty($template_field_structure) ) |
|
| 1551 | + } //end if ( !empty($template_field_structure) ) |
|
| 1552 | 1552 | |
| 1553 | - //set extra content for publish box |
|
| 1554 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1555 | - $this->_set_publish_post_box_vars( |
|
| 1556 | - 'id', |
|
| 1557 | - $GRP_ID, |
|
| 1558 | - false, |
|
| 1559 | - add_query_arg( |
|
| 1560 | - array('action' => 'global_mtps'), |
|
| 1561 | - $this->_admin_base_url |
|
| 1562 | - ) |
|
| 1563 | - ); |
|
| 1564 | - |
|
| 1565 | - //add preview button |
|
| 1566 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1567 | - array( |
|
| 1568 | - 'message_type' => $message_template_group->message_type(), |
|
| 1569 | - 'messenger' => $message_template_group->messenger(), |
|
| 1570 | - 'context' => $context, |
|
| 1571 | - 'GRP_ID' => $GRP_ID, |
|
| 1572 | - 'action' => 'preview_message' |
|
| 1573 | - ), |
|
| 1574 | - $this->_admin_base_url |
|
| 1575 | - ); |
|
| 1576 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1577 | - 'event_espresso') . '</a>'; |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - //setup context switcher |
|
| 1581 | - $context_switcher_args = array( |
|
| 1582 | - 'page' => 'espresso_messages', |
|
| 1583 | - 'action' => 'edit_message_template', |
|
| 1584 | - 'id' => $GRP_ID, |
|
| 1585 | - 'context' => $context, |
|
| 1586 | - 'extra' => $preview_button |
|
| 1587 | - ); |
|
| 1588 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1589 | - |
|
| 1590 | - |
|
| 1591 | - //main box |
|
| 1592 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1593 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1594 | - $this->_template_args['action'] = $action; |
|
| 1595 | - $this->_template_args['context'] = $context; |
|
| 1596 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1597 | - $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1601 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1602 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1603 | - |
|
| 1604 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1605 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1606 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1607 | - |
|
| 1608 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1609 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1610 | - |
|
| 1611 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1612 | - $this->_template_args, true); |
|
| 1613 | - |
|
| 1614 | - |
|
| 1615 | - //finally, let's set the admin_page title |
|
| 1616 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1617 | - |
|
| 1618 | - |
|
| 1619 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1620 | - $this->_set_shortcodes(); |
|
| 1621 | - |
|
| 1622 | - |
|
| 1623 | - //final template wrapper |
|
| 1624 | - $this->display_admin_page_with_sidebar(); |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - |
|
| 1628 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1629 | - { |
|
| 1630 | - return $mceInit; |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - public function add_context_switcher() |
|
| 1635 | - { |
|
| 1636 | - return $this->_context_switcher; |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - public function _add_form_element_before() |
|
| 1640 | - { |
|
| 1641 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - public function _add_form_element_after() |
|
| 1645 | - { |
|
| 1646 | - return '</form>'; |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - |
|
| 1650 | - /** |
|
| 1651 | - * This executes switching the template pack for a message template. |
|
| 1652 | - * |
|
| 1653 | - * @since 4.5.0 |
|
| 1654 | - * |
|
| 1655 | - */ |
|
| 1656 | - public function switch_template_pack() |
|
| 1657 | - { |
|
| 1658 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1659 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1660 | - |
|
| 1661 | - //verify we have needed values. |
|
| 1662 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1663 | - $this->_template_args['error'] = true; |
|
| 1664 | - EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1665 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1666 | - } else { |
|
| 1667 | - //get template, set the new template_pack and then reset to default |
|
| 1668 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1669 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1553 | + //set extra content for publish box |
|
| 1554 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1555 | + $this->_set_publish_post_box_vars( |
|
| 1556 | + 'id', |
|
| 1557 | + $GRP_ID, |
|
| 1558 | + false, |
|
| 1559 | + add_query_arg( |
|
| 1560 | + array('action' => 'global_mtps'), |
|
| 1561 | + $this->_admin_base_url |
|
| 1562 | + ) |
|
| 1563 | + ); |
|
| 1564 | + |
|
| 1565 | + //add preview button |
|
| 1566 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1567 | + array( |
|
| 1568 | + 'message_type' => $message_template_group->message_type(), |
|
| 1569 | + 'messenger' => $message_template_group->messenger(), |
|
| 1570 | + 'context' => $context, |
|
| 1571 | + 'GRP_ID' => $GRP_ID, |
|
| 1572 | + 'action' => 'preview_message' |
|
| 1573 | + ), |
|
| 1574 | + $this->_admin_base_url |
|
| 1575 | + ); |
|
| 1576 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1577 | + 'event_espresso') . '</a>'; |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + //setup context switcher |
|
| 1581 | + $context_switcher_args = array( |
|
| 1582 | + 'page' => 'espresso_messages', |
|
| 1583 | + 'action' => 'edit_message_template', |
|
| 1584 | + 'id' => $GRP_ID, |
|
| 1585 | + 'context' => $context, |
|
| 1586 | + 'extra' => $preview_button |
|
| 1587 | + ); |
|
| 1588 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1589 | + |
|
| 1590 | + |
|
| 1591 | + //main box |
|
| 1592 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1593 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1594 | + $this->_template_args['action'] = $action; |
|
| 1595 | + $this->_template_args['context'] = $context; |
|
| 1596 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1597 | + $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1601 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1602 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1603 | + |
|
| 1604 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1605 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1606 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1607 | + |
|
| 1608 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1609 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1610 | + |
|
| 1611 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1612 | + $this->_template_args, true); |
|
| 1613 | + |
|
| 1614 | + |
|
| 1615 | + //finally, let's set the admin_page title |
|
| 1616 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1617 | + |
|
| 1618 | + |
|
| 1619 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1620 | + $this->_set_shortcodes(); |
|
| 1621 | + |
|
| 1622 | + |
|
| 1623 | + //final template wrapper |
|
| 1624 | + $this->display_admin_page_with_sidebar(); |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + |
|
| 1628 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1629 | + { |
|
| 1630 | + return $mceInit; |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + public function add_context_switcher() |
|
| 1635 | + { |
|
| 1636 | + return $this->_context_switcher; |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + public function _add_form_element_before() |
|
| 1640 | + { |
|
| 1641 | + return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + public function _add_form_element_after() |
|
| 1645 | + { |
|
| 1646 | + return '</form>'; |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + |
|
| 1650 | + /** |
|
| 1651 | + * This executes switching the template pack for a message template. |
|
| 1652 | + * |
|
| 1653 | + * @since 4.5.0 |
|
| 1654 | + * |
|
| 1655 | + */ |
|
| 1656 | + public function switch_template_pack() |
|
| 1657 | + { |
|
| 1658 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1659 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1660 | + |
|
| 1661 | + //verify we have needed values. |
|
| 1662 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1663 | + $this->_template_args['error'] = true; |
|
| 1664 | + EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1665 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1666 | + } else { |
|
| 1667 | + //get template, set the new template_pack and then reset to default |
|
| 1668 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1669 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1670 | 1670 | |
| 1671 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1672 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1673 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1671 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1672 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1673 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1674 | 1674 | |
| 1675 | - $query_args = $this->_reset_to_default_template(); |
|
| 1675 | + $query_args = $this->_reset_to_default_template(); |
|
| 1676 | 1676 | |
| 1677 | - if (empty($query_args['id'])) { |
|
| 1678 | - EE_Error::add_error( |
|
| 1679 | - __( |
|
| 1680 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1681 | - 'event_espresso' |
|
| 1682 | - ), |
|
| 1683 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1684 | - ); |
|
| 1685 | - $this->_template_args['error'] = true; |
|
| 1686 | - } else { |
|
| 1687 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1688 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1689 | - EE_Error::add_success( |
|
| 1690 | - sprintf( |
|
| 1691 | - __( |
|
| 1692 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1693 | - 'event_espresso' |
|
| 1694 | - ), |
|
| 1695 | - $template_label, |
|
| 1696 | - $template_pack_labels->template_pack |
|
| 1697 | - ) |
|
| 1698 | - ); |
|
| 1699 | - //generate the redirect url for js. |
|
| 1700 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1701 | - $this->_admin_base_url); |
|
| 1702 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1703 | - $this->_template_args['success'] = true; |
|
| 1704 | - } |
|
| 1677 | + if (empty($query_args['id'])) { |
|
| 1678 | + EE_Error::add_error( |
|
| 1679 | + __( |
|
| 1680 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1681 | + 'event_espresso' |
|
| 1682 | + ), |
|
| 1683 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1684 | + ); |
|
| 1685 | + $this->_template_args['error'] = true; |
|
| 1686 | + } else { |
|
| 1687 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1688 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1689 | + EE_Error::add_success( |
|
| 1690 | + sprintf( |
|
| 1691 | + __( |
|
| 1692 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1693 | + 'event_espresso' |
|
| 1694 | + ), |
|
| 1695 | + $template_label, |
|
| 1696 | + $template_pack_labels->template_pack |
|
| 1697 | + ) |
|
| 1698 | + ); |
|
| 1699 | + //generate the redirect url for js. |
|
| 1700 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1701 | + $this->_admin_base_url); |
|
| 1702 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1703 | + $this->_template_args['success'] = true; |
|
| 1704 | + } |
|
| 1705 | 1705 | |
| 1706 | - $this->_return_json(); |
|
| 1706 | + $this->_return_json(); |
|
| 1707 | 1707 | |
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1714 | - * they want. |
|
| 1715 | - * |
|
| 1716 | - * @access protected |
|
| 1717 | - * @return array|null |
|
| 1718 | - */ |
|
| 1719 | - protected function _reset_to_default_template() |
|
| 1720 | - { |
|
| 1721 | - |
|
| 1722 | - $templates = array(); |
|
| 1723 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1724 | - //we need to make sure we've got the info we need. |
|
| 1725 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1726 | - EE_Error::add_error( |
|
| 1727 | - __( |
|
| 1728 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1729 | - 'event_espresso' |
|
| 1730 | - ), |
|
| 1731 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1732 | - ); |
|
| 1733 | - } |
|
| 1734 | - |
|
| 1735 | - // all templates will be reset to whatever the defaults are |
|
| 1736 | - // for the global template matching the messenger and message type. |
|
| 1737 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 1738 | - |
|
| 1739 | - if ($success) { |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1714 | + * they want. |
|
| 1715 | + * |
|
| 1716 | + * @access protected |
|
| 1717 | + * @return array|null |
|
| 1718 | + */ |
|
| 1719 | + protected function _reset_to_default_template() |
|
| 1720 | + { |
|
| 1721 | + |
|
| 1722 | + $templates = array(); |
|
| 1723 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1724 | + //we need to make sure we've got the info we need. |
|
| 1725 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1726 | + EE_Error::add_error( |
|
| 1727 | + __( |
|
| 1728 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 1729 | + 'event_espresso' |
|
| 1730 | + ), |
|
| 1731 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1732 | + ); |
|
| 1733 | + } |
|
| 1734 | + |
|
| 1735 | + // all templates will be reset to whatever the defaults are |
|
| 1736 | + // for the global template matching the messenger and message type. |
|
| 1737 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 1738 | + |
|
| 1739 | + if ($success) { |
|
| 1740 | 1740 | |
| 1741 | - //let's first determine if the incoming template is a global template, |
|
| 1742 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1743 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1741 | + //let's first determine if the incoming template is a global template, |
|
| 1742 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1743 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1744 | 1744 | |
| 1745 | 1745 | |
| 1746 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1747 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1746 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1747 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1748 | 1748 | |
| 1749 | - if ($success) { |
|
| 1750 | - // if successfully deleted, lets generate the new ones. |
|
| 1751 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1752 | - // will use the related global template defaults for regeneration. |
|
| 1753 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1754 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 1755 | - // for the current custom template when resetting. |
|
| 1756 | - $templates = $this->_generate_new_templates( |
|
| 1757 | - $this->_req_data['msgr'], |
|
| 1758 | - $this->_req_data['mt'], |
|
| 1759 | - $GRP_ID, |
|
| 1760 | - true |
|
| 1761 | - ); |
|
| 1762 | - } |
|
| 1749 | + if ($success) { |
|
| 1750 | + // if successfully deleted, lets generate the new ones. |
|
| 1751 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1752 | + // will use the related global template defaults for regeneration. |
|
| 1753 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1754 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 1755 | + // for the current custom template when resetting. |
|
| 1756 | + $templates = $this->_generate_new_templates( |
|
| 1757 | + $this->_req_data['msgr'], |
|
| 1758 | + $this->_req_data['mt'], |
|
| 1759 | + $GRP_ID, |
|
| 1760 | + true |
|
| 1761 | + ); |
|
| 1762 | + } |
|
| 1763 | 1763 | |
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - //any error messages? |
|
| 1767 | - if ( ! $success) { |
|
| 1768 | - EE_Error::add_error( |
|
| 1769 | - __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1770 | - 'event_espresso'), |
|
| 1771 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1772 | - ); |
|
| 1773 | - } |
|
| 1774 | - |
|
| 1775 | - //all good, let's add a success message! |
|
| 1776 | - if ($success && ! empty($templates)) { |
|
| 1777 | - $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1778 | - EE_Error::overwrite_success(); |
|
| 1779 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - |
|
| 1783 | - $query_args = array( |
|
| 1784 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1785 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1786 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1787 | - ); |
|
| 1788 | - |
|
| 1789 | - //if called via ajax then we return query args otherwise redirect |
|
| 1790 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1791 | - return $query_args; |
|
| 1792 | - } else { |
|
| 1793 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + //any error messages? |
|
| 1767 | + if ( ! $success) { |
|
| 1768 | + EE_Error::add_error( |
|
| 1769 | + __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1770 | + 'event_espresso'), |
|
| 1771 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1772 | + ); |
|
| 1773 | + } |
|
| 1774 | + |
|
| 1775 | + //all good, let's add a success message! |
|
| 1776 | + if ($success && ! empty($templates)) { |
|
| 1777 | + $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1778 | + EE_Error::overwrite_success(); |
|
| 1779 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + |
|
| 1783 | + $query_args = array( |
|
| 1784 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1785 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1786 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1787 | + ); |
|
| 1788 | + |
|
| 1789 | + //if called via ajax then we return query args otherwise redirect |
|
| 1790 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1791 | + return $query_args; |
|
| 1792 | + } else { |
|
| 1793 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1794 | 1794 | |
| 1795 | - return null; |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * Retrieve and set the message preview for display. |
|
| 1802 | - * |
|
| 1803 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1804 | - * |
|
| 1805 | - * @return string |
|
| 1806 | - */ |
|
| 1807 | - public function _preview_message($send = false) |
|
| 1808 | - { |
|
| 1809 | - //first make sure we've got the necessary parameters |
|
| 1810 | - if ( |
|
| 1811 | - ! isset( |
|
| 1812 | - $this->_req_data['message_type'], |
|
| 1813 | - $this->_req_data['messenger'], |
|
| 1814 | - $this->_req_data['messenger'], |
|
| 1815 | - $this->_req_data['GRP_ID'] |
|
| 1816 | - ) |
|
| 1817 | - ) { |
|
| 1818 | - EE_Error::add_error( |
|
| 1819 | - __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1820 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1821 | - ); |
|
| 1822 | - } |
|
| 1823 | - |
|
| 1824 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1825 | - |
|
| 1826 | - |
|
| 1827 | - //get the preview! |
|
| 1828 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1829 | - $this->_req_data['messenger'], $send); |
|
| 1830 | - |
|
| 1831 | - if ($send) { |
|
| 1832 | - return $preview; |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - //let's add a button to go back to the edit view |
|
| 1836 | - $query_args = array( |
|
| 1837 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 1838 | - 'context' => $this->_req_data['context'], |
|
| 1839 | - 'action' => 'edit_message_template' |
|
| 1840 | - ); |
|
| 1841 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1842 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1843 | - 'event_espresso') . '</a>'; |
|
| 1844 | - $message_types = $this->get_installed_message_types(); |
|
| 1845 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1846 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1847 | - ? ucwords($active_messenger->label['singular']) |
|
| 1848 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1849 | - //let's provide a helpful title for context |
|
| 1850 | - $preview_title = sprintf( |
|
| 1851 | - __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1852 | - $active_messenger_label, |
|
| 1853 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1854 | - ); |
|
| 1855 | - //setup display of preview. |
|
| 1856 | - $this->_admin_page_title = $preview_title; |
|
| 1857 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1858 | - $this->_template_args['data']['force_json'] = true; |
|
| 1859 | - |
|
| 1860 | - return ''; |
|
| 1861 | - } |
|
| 1862 | - |
|
| 1863 | - |
|
| 1864 | - /** |
|
| 1865 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1866 | - * gets called automatically. |
|
| 1867 | - * |
|
| 1868 | - * @since 4.5.0 |
|
| 1869 | - * |
|
| 1870 | - * @return string |
|
| 1871 | - */ |
|
| 1872 | - protected function _display_preview_message() |
|
| 1873 | - { |
|
| 1874 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1880 | - * |
|
| 1881 | - * @access protected |
|
| 1882 | - * @return void |
|
| 1883 | - */ |
|
| 1884 | - protected function _register_edit_meta_boxes() |
|
| 1885 | - { |
|
| 1886 | - add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1887 | - array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1888 | - add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1889 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1890 | - add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1891 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * metabox content for all template pack and variation selection. |
|
| 1897 | - * |
|
| 1898 | - * @since 4.5.0 |
|
| 1899 | - * |
|
| 1900 | - * @return string |
|
| 1901 | - */ |
|
| 1902 | - public function template_pack_meta_box() |
|
| 1903 | - { |
|
| 1904 | - $this->_set_message_template_group(); |
|
| 1905 | - |
|
| 1906 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1907 | - |
|
| 1908 | - $tp_select_values = array(); |
|
| 1909 | - |
|
| 1910 | - foreach ($tp_collection as $tp) { |
|
| 1911 | - //only include template packs that support this messenger and message type! |
|
| 1912 | - $supports = $tp->get_supports(); |
|
| 1913 | - if ( |
|
| 1914 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1915 | - || ! in_array( |
|
| 1916 | - $this->_message_template_group->message_type(), |
|
| 1917 | - $supports[$this->_message_template_group->messenger()] |
|
| 1918 | - ) |
|
| 1919 | - ) { |
|
| 1920 | - //not supported |
|
| 1921 | - continue; |
|
| 1922 | - } |
|
| 1795 | + return null; |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * Retrieve and set the message preview for display. |
|
| 1802 | + * |
|
| 1803 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1804 | + * |
|
| 1805 | + * @return string |
|
| 1806 | + */ |
|
| 1807 | + public function _preview_message($send = false) |
|
| 1808 | + { |
|
| 1809 | + //first make sure we've got the necessary parameters |
|
| 1810 | + if ( |
|
| 1811 | + ! isset( |
|
| 1812 | + $this->_req_data['message_type'], |
|
| 1813 | + $this->_req_data['messenger'], |
|
| 1814 | + $this->_req_data['messenger'], |
|
| 1815 | + $this->_req_data['GRP_ID'] |
|
| 1816 | + ) |
|
| 1817 | + ) { |
|
| 1818 | + EE_Error::add_error( |
|
| 1819 | + __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1820 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1821 | + ); |
|
| 1822 | + } |
|
| 1823 | + |
|
| 1824 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1825 | + |
|
| 1826 | + |
|
| 1827 | + //get the preview! |
|
| 1828 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1829 | + $this->_req_data['messenger'], $send); |
|
| 1830 | + |
|
| 1831 | + if ($send) { |
|
| 1832 | + return $preview; |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + //let's add a button to go back to the edit view |
|
| 1836 | + $query_args = array( |
|
| 1837 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 1838 | + 'context' => $this->_req_data['context'], |
|
| 1839 | + 'action' => 'edit_message_template' |
|
| 1840 | + ); |
|
| 1841 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1842 | + $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1843 | + 'event_espresso') . '</a>'; |
|
| 1844 | + $message_types = $this->get_installed_message_types(); |
|
| 1845 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1846 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1847 | + ? ucwords($active_messenger->label['singular']) |
|
| 1848 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1849 | + //let's provide a helpful title for context |
|
| 1850 | + $preview_title = sprintf( |
|
| 1851 | + __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1852 | + $active_messenger_label, |
|
| 1853 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1854 | + ); |
|
| 1855 | + //setup display of preview. |
|
| 1856 | + $this->_admin_page_title = $preview_title; |
|
| 1857 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1858 | + $this->_template_args['data']['force_json'] = true; |
|
| 1859 | + |
|
| 1860 | + return ''; |
|
| 1861 | + } |
|
| 1862 | + |
|
| 1863 | + |
|
| 1864 | + /** |
|
| 1865 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1866 | + * gets called automatically. |
|
| 1867 | + * |
|
| 1868 | + * @since 4.5.0 |
|
| 1869 | + * |
|
| 1870 | + * @return string |
|
| 1871 | + */ |
|
| 1872 | + protected function _display_preview_message() |
|
| 1873 | + { |
|
| 1874 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1880 | + * |
|
| 1881 | + * @access protected |
|
| 1882 | + * @return void |
|
| 1883 | + */ |
|
| 1884 | + protected function _register_edit_meta_boxes() |
|
| 1885 | + { |
|
| 1886 | + add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1887 | + array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1888 | + add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1889 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1890 | + add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1891 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * metabox content for all template pack and variation selection. |
|
| 1897 | + * |
|
| 1898 | + * @since 4.5.0 |
|
| 1899 | + * |
|
| 1900 | + * @return string |
|
| 1901 | + */ |
|
| 1902 | + public function template_pack_meta_box() |
|
| 1903 | + { |
|
| 1904 | + $this->_set_message_template_group(); |
|
| 1905 | + |
|
| 1906 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1907 | + |
|
| 1908 | + $tp_select_values = array(); |
|
| 1909 | + |
|
| 1910 | + foreach ($tp_collection as $tp) { |
|
| 1911 | + //only include template packs that support this messenger and message type! |
|
| 1912 | + $supports = $tp->get_supports(); |
|
| 1913 | + if ( |
|
| 1914 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1915 | + || ! in_array( |
|
| 1916 | + $this->_message_template_group->message_type(), |
|
| 1917 | + $supports[$this->_message_template_group->messenger()] |
|
| 1918 | + ) |
|
| 1919 | + ) { |
|
| 1920 | + //not supported |
|
| 1921 | + continue; |
|
| 1922 | + } |
|
| 1923 | 1923 | |
| 1924 | - $tp_select_values[] = array( |
|
| 1925 | - 'text' => $tp->label, |
|
| 1926 | - 'id' => $tp->dbref |
|
| 1927 | - ); |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1931 | - if (empty($tp_select_values)) { |
|
| 1932 | - $tp_select_values[] = array( |
|
| 1933 | - 'text' => __('Default', 'event_espresso'), |
|
| 1934 | - 'id' => 'default' |
|
| 1935 | - ); |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - //setup variation select values for the currently selected template. |
|
| 1939 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1940 | - $this->_message_template_group->messenger(), |
|
| 1941 | - $this->_message_template_group->message_type() |
|
| 1942 | - ); |
|
| 1943 | - $variations_select_values = array(); |
|
| 1944 | - foreach ($variations as $variation => $label) { |
|
| 1945 | - $variations_select_values[] = array( |
|
| 1946 | - 'text' => $label, |
|
| 1947 | - 'id' => $variation |
|
| 1948 | - ); |
|
| 1949 | - } |
|
| 1950 | - |
|
| 1951 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1952 | - |
|
| 1953 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1954 | - 'MTP_template_pack', |
|
| 1955 | - $tp_select_values, |
|
| 1956 | - $this->_message_template_group->get_template_pack_name() |
|
| 1957 | - ); |
|
| 1958 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1959 | - 'MTP_template_variation', |
|
| 1960 | - $variations_select_values, |
|
| 1961 | - $this->_message_template_group->get_template_pack_variation() |
|
| 1962 | - ); |
|
| 1963 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1964 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1965 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1966 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1967 | - |
|
| 1968 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1969 | - |
|
| 1970 | - EEH_Template::display_template($template, $template_args); |
|
| 1971 | - } |
|
| 1972 | - |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * This meta box holds any extra actions related to Message Templates |
|
| 1976 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1977 | - * |
|
| 1978 | - * @access public |
|
| 1979 | - * @return void |
|
| 1980 | - * @throws \EE_Error |
|
| 1981 | - */ |
|
| 1982 | - public function extra_actions_meta_box() |
|
| 1983 | - { |
|
| 1984 | - $template_form_fields = array(); |
|
| 1985 | - |
|
| 1986 | - $extra_args = array( |
|
| 1987 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 1988 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 1989 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 1990 | - ); |
|
| 1991 | - //first we need to see if there are any fields |
|
| 1992 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 1993 | - |
|
| 1994 | - if ( ! empty($fields)) { |
|
| 1995 | - //yup there be fields |
|
| 1996 | - foreach ($fields as $field => $config) { |
|
| 1997 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 1998 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 1999 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2000 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 1924 | + $tp_select_values[] = array( |
|
| 1925 | + 'text' => $tp->label, |
|
| 1926 | + 'id' => $tp->dbref |
|
| 1927 | + ); |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
|
| 1931 | + if (empty($tp_select_values)) { |
|
| 1932 | + $tp_select_values[] = array( |
|
| 1933 | + 'text' => __('Default', 'event_espresso'), |
|
| 1934 | + 'id' => 'default' |
|
| 1935 | + ); |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + //setup variation select values for the currently selected template. |
|
| 1939 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1940 | + $this->_message_template_group->messenger(), |
|
| 1941 | + $this->_message_template_group->message_type() |
|
| 1942 | + ); |
|
| 1943 | + $variations_select_values = array(); |
|
| 1944 | + foreach ($variations as $variation => $label) { |
|
| 1945 | + $variations_select_values[] = array( |
|
| 1946 | + 'text' => $label, |
|
| 1947 | + 'id' => $variation |
|
| 1948 | + ); |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1952 | + |
|
| 1953 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1954 | + 'MTP_template_pack', |
|
| 1955 | + $tp_select_values, |
|
| 1956 | + $this->_message_template_group->get_template_pack_name() |
|
| 1957 | + ); |
|
| 1958 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1959 | + 'MTP_template_variation', |
|
| 1960 | + $variations_select_values, |
|
| 1961 | + $this->_message_template_group->get_template_pack_variation() |
|
| 1962 | + ); |
|
| 1963 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1964 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1965 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1966 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1967 | + |
|
| 1968 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1969 | + |
|
| 1970 | + EEH_Template::display_template($template, $template_args); |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * This meta box holds any extra actions related to Message Templates |
|
| 1976 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1977 | + * |
|
| 1978 | + * @access public |
|
| 1979 | + * @return void |
|
| 1980 | + * @throws \EE_Error |
|
| 1981 | + */ |
|
| 1982 | + public function extra_actions_meta_box() |
|
| 1983 | + { |
|
| 1984 | + $template_form_fields = array(); |
|
| 1985 | + |
|
| 1986 | + $extra_args = array( |
|
| 1987 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 1988 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 1989 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 1990 | + ); |
|
| 1991 | + //first we need to see if there are any fields |
|
| 1992 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 1993 | + |
|
| 1994 | + if ( ! empty($fields)) { |
|
| 1995 | + //yup there be fields |
|
| 1996 | + foreach ($fields as $field => $config) { |
|
| 1997 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 1998 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 1999 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2000 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2001 | 2001 | |
| 2002 | - // if type is hidden and the value is empty |
|
| 2003 | - // something may have gone wrong so let's correct with the defaults |
|
| 2004 | - $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2005 | - ? $default |
|
| 2006 | - : ''; |
|
| 2007 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2008 | - ? $existing[$field] |
|
| 2009 | - : $fix; |
|
| 2002 | + // if type is hidden and the value is empty |
|
| 2003 | + // something may have gone wrong so let's correct with the defaults |
|
| 2004 | + $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2005 | + ? $default |
|
| 2006 | + : ''; |
|
| 2007 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2008 | + ? $existing[$field] |
|
| 2009 | + : $fix; |
|
| 2010 | 2010 | |
| 2011 | - $template_form_fields[$field_id] = array( |
|
| 2012 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2013 | - 'label' => $config['label'], |
|
| 2014 | - 'input' => $config['input'], |
|
| 2015 | - 'type' => $config['type'], |
|
| 2016 | - 'required' => $config['required'], |
|
| 2017 | - 'validation' => $config['validation'], |
|
| 2018 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2019 | - 'css_class' => $config['css_class'], |
|
| 2020 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2021 | - 'default' => $default, |
|
| 2022 | - 'format' => $config['format'] |
|
| 2023 | - ); |
|
| 2024 | - } |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2028 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2029 | - : ''; |
|
| 2030 | - |
|
| 2031 | - $test_settings_html = ''; |
|
| 2032 | - //print out $test_settings_fields |
|
| 2033 | - if ( ! empty($test_settings_fields)) { |
|
| 2034 | - echo $test_settings_fields; |
|
| 2035 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2036 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2037 | - $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2038 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - //and button |
|
| 2042 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2043 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2044 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2045 | - 'reset_to_default', |
|
| 2046 | - 'reset', |
|
| 2047 | - $extra_args, |
|
| 2048 | - 'button-primary reset-default-button' |
|
| 2049 | - ); |
|
| 2050 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2051 | - echo $test_settings_html; |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - |
|
| 2055 | - /** |
|
| 2056 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2057 | - * |
|
| 2058 | - * @since 4.9.rc.000 |
|
| 2059 | - * |
|
| 2060 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2061 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2062 | - * |
|
| 2063 | - * @return string |
|
| 2064 | - */ |
|
| 2065 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2066 | - { |
|
| 2067 | - $template_args = array( |
|
| 2068 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2069 | - 'fieldname' => $field, |
|
| 2070 | - 'linked_input_id' => $linked_input_id |
|
| 2071 | - ); |
|
| 2072 | - |
|
| 2073 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2074 | - $template_args, true); |
|
| 2075 | - } |
|
| 2076 | - |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2080 | - * page) |
|
| 2081 | - * |
|
| 2082 | - * @access public |
|
| 2083 | - * @return void |
|
| 2084 | - */ |
|
| 2085 | - public function shortcode_meta_box() |
|
| 2086 | - { |
|
| 2087 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2088 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2089 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2090 | - if (empty($shortcodes)) { |
|
| 2091 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2092 | - echo $content; |
|
| 2093 | - } else { |
|
| 2094 | - //$alt = 0; |
|
| 2095 | - ?> |
|
| 2011 | + $template_form_fields[$field_id] = array( |
|
| 2012 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2013 | + 'label' => $config['label'], |
|
| 2014 | + 'input' => $config['input'], |
|
| 2015 | + 'type' => $config['type'], |
|
| 2016 | + 'required' => $config['required'], |
|
| 2017 | + 'validation' => $config['validation'], |
|
| 2018 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2019 | + 'css_class' => $config['css_class'], |
|
| 2020 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2021 | + 'default' => $default, |
|
| 2022 | + 'format' => $config['format'] |
|
| 2023 | + ); |
|
| 2024 | + } |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2028 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2029 | + : ''; |
|
| 2030 | + |
|
| 2031 | + $test_settings_html = ''; |
|
| 2032 | + //print out $test_settings_fields |
|
| 2033 | + if ( ! empty($test_settings_fields)) { |
|
| 2034 | + echo $test_settings_fields; |
|
| 2035 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2036 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2037 | + $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2038 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2039 | + } |
|
| 2040 | + |
|
| 2041 | + //and button |
|
| 2042 | + $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2043 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2044 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2045 | + 'reset_to_default', |
|
| 2046 | + 'reset', |
|
| 2047 | + $extra_args, |
|
| 2048 | + 'button-primary reset-default-button' |
|
| 2049 | + ); |
|
| 2050 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2051 | + echo $test_settings_html; |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + |
|
| 2055 | + /** |
|
| 2056 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2057 | + * |
|
| 2058 | + * @since 4.9.rc.000 |
|
| 2059 | + * |
|
| 2060 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2061 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2062 | + * |
|
| 2063 | + * @return string |
|
| 2064 | + */ |
|
| 2065 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2066 | + { |
|
| 2067 | + $template_args = array( |
|
| 2068 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2069 | + 'fieldname' => $field, |
|
| 2070 | + 'linked_input_id' => $linked_input_id |
|
| 2071 | + ); |
|
| 2072 | + |
|
| 2073 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2074 | + $template_args, true); |
|
| 2075 | + } |
|
| 2076 | + |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2080 | + * page) |
|
| 2081 | + * |
|
| 2082 | + * @access public |
|
| 2083 | + * @return void |
|
| 2084 | + */ |
|
| 2085 | + public function shortcode_meta_box() |
|
| 2086 | + { |
|
| 2087 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2088 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2089 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2090 | + if (empty($shortcodes)) { |
|
| 2091 | + $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2092 | + echo $content; |
|
| 2093 | + } else { |
|
| 2094 | + //$alt = 0; |
|
| 2095 | + ?> |
|
| 2096 | 2096 | <div |
| 2097 | 2097 | style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2098 | 2098 | <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
| 2099 | - 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2099 | + 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2100 | 2100 | <?php |
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - |
|
| 2107 | - /** |
|
| 2108 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2109 | - * |
|
| 2110 | - * @access protected |
|
| 2111 | - * @return void |
|
| 2112 | - */ |
|
| 2113 | - protected function _set_shortcodes() |
|
| 2114 | - { |
|
| 2115 | - |
|
| 2116 | - //no need to run this if the property is already set |
|
| 2117 | - if ( ! empty($this->_shortcodes)) { |
|
| 2118 | - return; |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2122 | - } |
|
| 2123 | - |
|
| 2124 | - |
|
| 2125 | - /** |
|
| 2126 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2127 | - * property) |
|
| 2128 | - * |
|
| 2129 | - * @access protected |
|
| 2130 | - * |
|
| 2131 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2132 | - * for. Defaults to all (for the given context) |
|
| 2133 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2134 | - * |
|
| 2135 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2136 | - * true just an array of shortcode/label pairs. |
|
| 2137 | - */ |
|
| 2138 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2139 | - { |
|
| 2140 | - $this->_set_message_template_group(); |
|
| 2141 | - |
|
| 2142 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2143 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2144 | - $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2145 | - |
|
| 2146 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2147 | - } |
|
| 2148 | - |
|
| 2149 | - |
|
| 2150 | - /** |
|
| 2151 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2152 | - * |
|
| 2153 | - * @access protected |
|
| 2154 | - * @return void |
|
| 2155 | - */ |
|
| 2156 | - protected function _set_message_template_group() |
|
| 2157 | - { |
|
| 2158 | - |
|
| 2159 | - if ( ! empty($this->_message_template_group)) { |
|
| 2160 | - return; |
|
| 2161 | - } //get out if this is already set. |
|
| 2162 | - |
|
| 2163 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2164 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2165 | - |
|
| 2166 | - //let's get the message templates |
|
| 2167 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2168 | - |
|
| 2169 | - if (empty($GRP_ID)) { |
|
| 2170 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2171 | - } else { |
|
| 2172 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2173 | - } |
|
| 2174 | - |
|
| 2175 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2176 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2177 | - |
|
| 2178 | - } |
|
| 2179 | - |
|
| 2180 | - |
|
| 2181 | - /** |
|
| 2182 | - * sets up a context switcher for edit forms |
|
| 2183 | - * |
|
| 2184 | - * @access protected |
|
| 2185 | - * |
|
| 2186 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2187 | - * @param array $args various things the context switcher needs. |
|
| 2188 | - * |
|
| 2189 | - */ |
|
| 2190 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2191 | - { |
|
| 2192 | - $context_details = $template_group_object->contexts_config(); |
|
| 2193 | - $context_label = $template_group_object->context_label(); |
|
| 2194 | - ob_start(); |
|
| 2195 | - ?> |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + |
|
| 2107 | + /** |
|
| 2108 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2109 | + * |
|
| 2110 | + * @access protected |
|
| 2111 | + * @return void |
|
| 2112 | + */ |
|
| 2113 | + protected function _set_shortcodes() |
|
| 2114 | + { |
|
| 2115 | + |
|
| 2116 | + //no need to run this if the property is already set |
|
| 2117 | + if ( ! empty($this->_shortcodes)) { |
|
| 2118 | + return; |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2122 | + } |
|
| 2123 | + |
|
| 2124 | + |
|
| 2125 | + /** |
|
| 2126 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2127 | + * property) |
|
| 2128 | + * |
|
| 2129 | + * @access protected |
|
| 2130 | + * |
|
| 2131 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2132 | + * for. Defaults to all (for the given context) |
|
| 2133 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2134 | + * |
|
| 2135 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2136 | + * true just an array of shortcode/label pairs. |
|
| 2137 | + */ |
|
| 2138 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2139 | + { |
|
| 2140 | + $this->_set_message_template_group(); |
|
| 2141 | + |
|
| 2142 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2143 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2144 | + $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2145 | + |
|
| 2146 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2147 | + } |
|
| 2148 | + |
|
| 2149 | + |
|
| 2150 | + /** |
|
| 2151 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2152 | + * |
|
| 2153 | + * @access protected |
|
| 2154 | + * @return void |
|
| 2155 | + */ |
|
| 2156 | + protected function _set_message_template_group() |
|
| 2157 | + { |
|
| 2158 | + |
|
| 2159 | + if ( ! empty($this->_message_template_group)) { |
|
| 2160 | + return; |
|
| 2161 | + } //get out if this is already set. |
|
| 2162 | + |
|
| 2163 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2164 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2165 | + |
|
| 2166 | + //let's get the message templates |
|
| 2167 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2168 | + |
|
| 2169 | + if (empty($GRP_ID)) { |
|
| 2170 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2171 | + } else { |
|
| 2172 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2173 | + } |
|
| 2174 | + |
|
| 2175 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2176 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2177 | + |
|
| 2178 | + } |
|
| 2179 | + |
|
| 2180 | + |
|
| 2181 | + /** |
|
| 2182 | + * sets up a context switcher for edit forms |
|
| 2183 | + * |
|
| 2184 | + * @access protected |
|
| 2185 | + * |
|
| 2186 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2187 | + * @param array $args various things the context switcher needs. |
|
| 2188 | + * |
|
| 2189 | + */ |
|
| 2190 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2191 | + { |
|
| 2192 | + $context_details = $template_group_object->contexts_config(); |
|
| 2193 | + $context_label = $template_group_object->context_label(); |
|
| 2194 | + ob_start(); |
|
| 2195 | + ?> |
|
| 2196 | 2196 | <div class="ee-msg-switcher-container"> |
| 2197 | 2197 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2198 | 2198 | <?php |
| 2199 | - foreach ($args as $name => $value) { |
|
| 2200 | - if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2201 | - continue; |
|
| 2202 | - } |
|
| 2203 | - ?> |
|
| 2199 | + foreach ($args as $name => $value) { |
|
| 2200 | + if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2201 | + continue; |
|
| 2202 | + } |
|
| 2203 | + ?> |
|
| 2204 | 2204 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2205 | 2205 | <?php |
| 2206 | - } |
|
| 2207 | - //setup nonce_url |
|
| 2208 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2209 | - ?> |
|
| 2206 | + } |
|
| 2207 | + //setup nonce_url |
|
| 2208 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2209 | + ?> |
|
| 2210 | 2210 | <select name="context"> |
| 2211 | 2211 | <?php |
| 2212 | - $context_templates = $template_group_object->context_templates(); |
|
| 2213 | - if (is_array($context_templates)) : |
|
| 2214 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2215 | - $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2216 | - ?> |
|
| 2212 | + $context_templates = $template_group_object->context_templates(); |
|
| 2213 | + if (is_array($context_templates)) : |
|
| 2214 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2215 | + $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2216 | + ?> |
|
| 2217 | 2217 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2218 | 2218 | <?php echo $context_details[$context]['label']; ?> |
| 2219 | 2219 | </option> |
@@ -2226,1554 +2226,1554 @@ discard block |
||
| 2226 | 2226 | <?php echo $args['extra']; ?> |
| 2227 | 2227 | </div> <!-- end .ee-msg-switcher-container --> |
| 2228 | 2228 | <?php |
| 2229 | - $output = ob_get_contents(); |
|
| 2230 | - ob_clean(); |
|
| 2231 | - $this->_context_switcher = $output; |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - |
|
| 2235 | - /** |
|
| 2236 | - * utility for sanitizing new values coming in. |
|
| 2237 | - * Note: this is only used when updating a context. |
|
| 2238 | - * |
|
| 2239 | - * @access protected |
|
| 2240 | - * |
|
| 2241 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2242 | - * |
|
| 2243 | - * @return array |
|
| 2244 | - */ |
|
| 2245 | - protected function _set_message_template_column_values($index) |
|
| 2246 | - { |
|
| 2247 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2248 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2249 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2250 | - } |
|
| 2251 | - } /*else { |
|
| 2229 | + $output = ob_get_contents(); |
|
| 2230 | + ob_clean(); |
|
| 2231 | + $this->_context_switcher = $output; |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + |
|
| 2235 | + /** |
|
| 2236 | + * utility for sanitizing new values coming in. |
|
| 2237 | + * Note: this is only used when updating a context. |
|
| 2238 | + * |
|
| 2239 | + * @access protected |
|
| 2240 | + * |
|
| 2241 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2242 | + * |
|
| 2243 | + * @return array |
|
| 2244 | + */ |
|
| 2245 | + protected function _set_message_template_column_values($index) |
|
| 2246 | + { |
|
| 2247 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2248 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2249 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2250 | + } |
|
| 2251 | + } /*else { |
|
| 2252 | 2252 | $this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content']; |
| 2253 | 2253 | }*/ |
| 2254 | 2254 | |
| 2255 | 2255 | |
| 2256 | - $set_column_values = array( |
|
| 2257 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2258 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2259 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2260 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2261 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2262 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2263 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2264 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2265 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2266 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2267 | - : 0, |
|
| 2268 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2269 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2270 | - : 0, |
|
| 2271 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2272 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2273 | - ); |
|
| 2274 | - |
|
| 2275 | - |
|
| 2276 | - return $set_column_values; |
|
| 2277 | - } |
|
| 2278 | - |
|
| 2279 | - |
|
| 2280 | - protected function _insert_or_update_message_template($new = false) |
|
| 2281 | - { |
|
| 2282 | - |
|
| 2283 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2284 | - $success = 0; |
|
| 2285 | - $override = false; |
|
| 2286 | - |
|
| 2287 | - //setup notices description |
|
| 2288 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2289 | - |
|
| 2290 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2291 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2292 | - $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2293 | - |
|
| 2294 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2295 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2296 | - |
|
| 2297 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2298 | - ? ucwords($message_type_object->label['singular']) |
|
| 2299 | - : ''; |
|
| 2300 | - |
|
| 2301 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2302 | - ? $this->_req_data['MTP_context'] |
|
| 2303 | - : ''; |
|
| 2304 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2305 | - |
|
| 2306 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2307 | - $item_desc .= 'Message Template'; |
|
| 2308 | - $query_args = array(); |
|
| 2309 | - $edit_array = array(); |
|
| 2310 | - $action_desc = ''; |
|
| 2311 | - |
|
| 2312 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2313 | - if ($new) { |
|
| 2314 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2315 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2316 | - if (empty($edit_array)) { |
|
| 2317 | - $success = 0; |
|
| 2318 | - } else { |
|
| 2319 | - $success = 1; |
|
| 2320 | - $edit_array = $edit_array[0]; |
|
| 2321 | - $query_args = array( |
|
| 2322 | - 'id' => $edit_array['GRP_ID'], |
|
| 2323 | - 'context' => $edit_array['MTP_context'], |
|
| 2324 | - 'action' => 'edit_message_template' |
|
| 2325 | - ); |
|
| 2326 | - } |
|
| 2327 | - } |
|
| 2328 | - $action_desc = 'created'; |
|
| 2329 | - } else { |
|
| 2330 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2331 | - $MTP = EEM_Message_Template::instance(); |
|
| 2256 | + $set_column_values = array( |
|
| 2257 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2258 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2259 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2260 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2261 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2262 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2263 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2264 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2265 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2266 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2267 | + : 0, |
|
| 2268 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2269 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2270 | + : 0, |
|
| 2271 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2272 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2273 | + ); |
|
| 2274 | + |
|
| 2275 | + |
|
| 2276 | + return $set_column_values; |
|
| 2277 | + } |
|
| 2278 | + |
|
| 2279 | + |
|
| 2280 | + protected function _insert_or_update_message_template($new = false) |
|
| 2281 | + { |
|
| 2282 | + |
|
| 2283 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2284 | + $success = 0; |
|
| 2285 | + $override = false; |
|
| 2286 | + |
|
| 2287 | + //setup notices description |
|
| 2288 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2289 | + |
|
| 2290 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2291 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2292 | + $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2293 | + |
|
| 2294 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2295 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2296 | + |
|
| 2297 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2298 | + ? ucwords($message_type_object->label['singular']) |
|
| 2299 | + : ''; |
|
| 2300 | + |
|
| 2301 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2302 | + ? $this->_req_data['MTP_context'] |
|
| 2303 | + : ''; |
|
| 2304 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2305 | + |
|
| 2306 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2307 | + $item_desc .= 'Message Template'; |
|
| 2308 | + $query_args = array(); |
|
| 2309 | + $edit_array = array(); |
|
| 2310 | + $action_desc = ''; |
|
| 2311 | + |
|
| 2312 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2313 | + if ($new) { |
|
| 2314 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2315 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2316 | + if (empty($edit_array)) { |
|
| 2317 | + $success = 0; |
|
| 2318 | + } else { |
|
| 2319 | + $success = 1; |
|
| 2320 | + $edit_array = $edit_array[0]; |
|
| 2321 | + $query_args = array( |
|
| 2322 | + 'id' => $edit_array['GRP_ID'], |
|
| 2323 | + 'context' => $edit_array['MTP_context'], |
|
| 2324 | + 'action' => 'edit_message_template' |
|
| 2325 | + ); |
|
| 2326 | + } |
|
| 2327 | + } |
|
| 2328 | + $action_desc = 'created'; |
|
| 2329 | + } else { |
|
| 2330 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2331 | + $MTP = EEM_Message_Template::instance(); |
|
| 2332 | 2332 | |
| 2333 | 2333 | |
| 2334 | - //run update for each template field in displayed context |
|
| 2335 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2336 | - EE_Error::add_error( |
|
| 2337 | - __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2338 | - 'event_espresso'), |
|
| 2339 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2340 | - ); |
|
| 2341 | - $success = 0; |
|
| 2334 | + //run update for each template field in displayed context |
|
| 2335 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2336 | + EE_Error::add_error( |
|
| 2337 | + __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2338 | + 'event_espresso'), |
|
| 2339 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2340 | + ); |
|
| 2341 | + $success = 0; |
|
| 2342 | 2342 | |
| 2343 | - } else { |
|
| 2344 | - //first validate all fields! |
|
| 2345 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2346 | - $message_type_slug); |
|
| 2343 | + } else { |
|
| 2344 | + //first validate all fields! |
|
| 2345 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2346 | + $message_type_slug); |
|
| 2347 | 2347 | |
| 2348 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2349 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2350 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2351 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2348 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
|
| 2349 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2350 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2351 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2352 | 2352 | |
| 2353 | - $success = 0; |
|
| 2353 | + $success = 0; |
|
| 2354 | 2354 | |
| 2355 | - //setup notices |
|
| 2356 | - foreach ($validates as $field => $error) { |
|
| 2357 | - if (isset($error['msg'])) { |
|
| 2358 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2355 | + //setup notices |
|
| 2356 | + foreach ($validates as $field => $error) { |
|
| 2357 | + if (isset($error['msg'])) { |
|
| 2358 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | 2361 | |
| 2362 | - } else { |
|
| 2363 | - $set_column_values = array(); |
|
| 2364 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2365 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2362 | + } else { |
|
| 2363 | + $set_column_values = array(); |
|
| 2364 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2365 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2366 | 2366 | |
| 2367 | - $where_cols_n_values = array( |
|
| 2368 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2369 | - ); |
|
| 2367 | + $where_cols_n_values = array( |
|
| 2368 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2369 | + ); |
|
| 2370 | 2370 | |
| 2371 | - $message_template_fields = array( |
|
| 2372 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2373 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2374 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2375 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2376 | - ); |
|
| 2377 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2378 | - if ($updated === false) { |
|
| 2379 | - EE_Error::add_error( |
|
| 2380 | - sprintf( |
|
| 2381 | - __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2382 | - $template_field |
|
| 2383 | - ), |
|
| 2384 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2385 | - ); |
|
| 2386 | - } else { |
|
| 2387 | - $success = 1; |
|
| 2388 | - } |
|
| 2389 | - } |
|
| 2390 | - $action_desc = 'updated'; |
|
| 2391 | - } |
|
| 2371 | + $message_template_fields = array( |
|
| 2372 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2373 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2374 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2375 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2376 | + ); |
|
| 2377 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2378 | + if ($updated === false) { |
|
| 2379 | + EE_Error::add_error( |
|
| 2380 | + sprintf( |
|
| 2381 | + __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2382 | + $template_field |
|
| 2383 | + ), |
|
| 2384 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2385 | + ); |
|
| 2386 | + } else { |
|
| 2387 | + $success = 1; |
|
| 2388 | + } |
|
| 2389 | + } |
|
| 2390 | + $action_desc = 'updated'; |
|
| 2391 | + } |
|
| 2392 | 2392 | |
| 2393 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2394 | - $mtpg_fields = array( |
|
| 2395 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2396 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2397 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2398 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2399 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2400 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2401 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2402 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2403 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2404 | - : '', |
|
| 2405 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2406 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2407 | - : '' |
|
| 2408 | - ); |
|
| 2393 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2394 | + $mtpg_fields = array( |
|
| 2395 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2396 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2397 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2398 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2399 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2400 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2401 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2402 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2403 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2404 | + : '', |
|
| 2405 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2406 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2407 | + : '' |
|
| 2408 | + ); |
|
| 2409 | 2409 | |
| 2410 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2411 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2410 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2411 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2412 | 2412 | |
| 2413 | - if ($updated === false) { |
|
| 2414 | - EE_Error::add_error( |
|
| 2415 | - sprintf( |
|
| 2416 | - __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2417 | - $set_column_values['GRP_ID'] |
|
| 2418 | - ), |
|
| 2419 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2420 | - ); |
|
| 2421 | - } else { |
|
| 2422 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2423 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2424 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2425 | - : 'default'; |
|
| 2413 | + if ($updated === false) { |
|
| 2414 | + EE_Error::add_error( |
|
| 2415 | + sprintf( |
|
| 2416 | + __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2417 | + $set_column_values['GRP_ID'] |
|
| 2418 | + ), |
|
| 2419 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2420 | + ); |
|
| 2421 | + } else { |
|
| 2422 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2423 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2424 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2425 | + : 'default'; |
|
| 2426 | 2426 | |
| 2427 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2428 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2429 | - : 'default'; |
|
| 2427 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2428 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2429 | + : 'default'; |
|
| 2430 | 2430 | |
| 2431 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2432 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2433 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2434 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2435 | - } |
|
| 2436 | - $success = 1; |
|
| 2437 | - } |
|
| 2438 | - } |
|
| 2439 | - } |
|
| 2431 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2432 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2433 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2434 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2435 | + } |
|
| 2436 | + $success = 1; |
|
| 2437 | + } |
|
| 2438 | + } |
|
| 2439 | + } |
|
| 2440 | 2440 | |
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - //we return things differently if doing ajax |
|
| 2444 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2445 | - $this->_template_args['success'] = $success; |
|
| 2446 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2447 | - $this->_template_args['content'] = ''; |
|
| 2448 | - $this->_template_args['data'] = array( |
|
| 2449 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2450 | - 'templateName' => $edit_array['template_name'] |
|
| 2451 | - ); |
|
| 2452 | - if ($success) { |
|
| 2453 | - EE_Error::overwrite_success(); |
|
| 2454 | - EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2455 | - 'event_espresso')); |
|
| 2456 | - } |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + //we return things differently if doing ajax |
|
| 2444 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2445 | + $this->_template_args['success'] = $success; |
|
| 2446 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2447 | + $this->_template_args['content'] = ''; |
|
| 2448 | + $this->_template_args['data'] = array( |
|
| 2449 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2450 | + 'templateName' => $edit_array['template_name'] |
|
| 2451 | + ); |
|
| 2452 | + if ($success) { |
|
| 2453 | + EE_Error::overwrite_success(); |
|
| 2454 | + EE_Error::add_success(__('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2455 | + 'event_espresso')); |
|
| 2456 | + } |
|
| 2457 | 2457 | |
| 2458 | - $this->_return_json(); |
|
| 2459 | - } |
|
| 2460 | - |
|
| 2461 | - |
|
| 2462 | - //was a test send triggered? |
|
| 2463 | - if (isset($this->_req_data['test_button'])) { |
|
| 2464 | - EE_Error::overwrite_success(); |
|
| 2465 | - $this->_do_test_send($context, $messenger_slug, $message_type_slug); |
|
| 2466 | - $override = true; |
|
| 2467 | - } |
|
| 2468 | - |
|
| 2469 | - if (empty($query_args)) { |
|
| 2470 | - $query_args = array( |
|
| 2471 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2472 | - 'context' => $context_slug, |
|
| 2473 | - 'action' => 'edit_message_template' |
|
| 2474 | - ); |
|
| 2475 | - } |
|
| 2476 | - |
|
| 2477 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2478 | - } |
|
| 2479 | - |
|
| 2480 | - |
|
| 2481 | - /** |
|
| 2482 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2483 | - * |
|
| 2484 | - * @param string $context what context being tested |
|
| 2485 | - * @param string $messenger messenger being tested |
|
| 2486 | - * @param string $message_type message type being tested |
|
| 2487 | - * |
|
| 2488 | - */ |
|
| 2489 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2490 | - { |
|
| 2491 | - //set things up for preview |
|
| 2492 | - $this->_req_data['messenger'] = $messenger; |
|
| 2493 | - $this->_req_data['message_type'] = $message_type; |
|
| 2494 | - $this->_req_data['context'] = $context; |
|
| 2495 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2496 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2497 | - |
|
| 2498 | - //let's save any existing fields that might be required by the messenger |
|
| 2499 | - if ( |
|
| 2500 | - isset($this->_req_data['test_settings_fld']) |
|
| 2501 | - && $active_messenger instanceof EE_messenger |
|
| 2502 | - ) { |
|
| 2503 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2504 | - } |
|
| 2505 | - |
|
| 2506 | - $success = $this->_preview_message(true); |
|
| 2507 | - |
|
| 2508 | - if ($success) { |
|
| 2509 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2510 | - } else { |
|
| 2511 | - EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2512 | - __LINE__); |
|
| 2513 | - } |
|
| 2514 | - } |
|
| 2515 | - |
|
| 2516 | - |
|
| 2517 | - /** |
|
| 2518 | - * _generate_new_templates |
|
| 2519 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2520 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2521 | - * for the event. |
|
| 2522 | - * |
|
| 2523 | - * |
|
| 2524 | - * @param string $messenger the messenger we are generating templates for |
|
| 2525 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2526 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2527 | - * indicate the message_template_group being used as the base. |
|
| 2528 | - * |
|
| 2529 | - * @param bool $global |
|
| 2530 | - * |
|
| 2531 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2532 | - * encountering problems. |
|
| 2533 | - * @throws \EE_Error |
|
| 2534 | - */ |
|
| 2535 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2536 | - { |
|
| 2537 | - |
|
| 2538 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2539 | - if (empty($message_types)) { |
|
| 2540 | - return true; |
|
| 2541 | - } |
|
| 2542 | - |
|
| 2543 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - |
|
| 2547 | - /** |
|
| 2548 | - * [_trash_or_restore_message_template] |
|
| 2549 | - * |
|
| 2550 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2551 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2552 | - * an individual context (FALSE). |
|
| 2553 | - * |
|
| 2554 | - * @return void |
|
| 2555 | - */ |
|
| 2556 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2557 | - { |
|
| 2558 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2559 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2560 | - |
|
| 2561 | - $success = 1; |
|
| 2562 | - |
|
| 2563 | - //incoming GRP_IDs |
|
| 2564 | - if ($all) { |
|
| 2565 | - //Checkboxes |
|
| 2566 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2567 | - //if array has more than one element then success message should be plural. |
|
| 2568 | - //todo: what about nonce? |
|
| 2569 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2458 | + $this->_return_json(); |
|
| 2459 | + } |
|
| 2460 | + |
|
| 2461 | + |
|
| 2462 | + //was a test send triggered? |
|
| 2463 | + if (isset($this->_req_data['test_button'])) { |
|
| 2464 | + EE_Error::overwrite_success(); |
|
| 2465 | + $this->_do_test_send($context, $messenger_slug, $message_type_slug); |
|
| 2466 | + $override = true; |
|
| 2467 | + } |
|
| 2468 | + |
|
| 2469 | + if (empty($query_args)) { |
|
| 2470 | + $query_args = array( |
|
| 2471 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2472 | + 'context' => $context_slug, |
|
| 2473 | + 'action' => 'edit_message_template' |
|
| 2474 | + ); |
|
| 2475 | + } |
|
| 2476 | + |
|
| 2477 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2478 | + } |
|
| 2479 | + |
|
| 2480 | + |
|
| 2481 | + /** |
|
| 2482 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2483 | + * |
|
| 2484 | + * @param string $context what context being tested |
|
| 2485 | + * @param string $messenger messenger being tested |
|
| 2486 | + * @param string $message_type message type being tested |
|
| 2487 | + * |
|
| 2488 | + */ |
|
| 2489 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2490 | + { |
|
| 2491 | + //set things up for preview |
|
| 2492 | + $this->_req_data['messenger'] = $messenger; |
|
| 2493 | + $this->_req_data['message_type'] = $message_type; |
|
| 2494 | + $this->_req_data['context'] = $context; |
|
| 2495 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2496 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2497 | + |
|
| 2498 | + //let's save any existing fields that might be required by the messenger |
|
| 2499 | + if ( |
|
| 2500 | + isset($this->_req_data['test_settings_fld']) |
|
| 2501 | + && $active_messenger instanceof EE_messenger |
|
| 2502 | + ) { |
|
| 2503 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2504 | + } |
|
| 2505 | + |
|
| 2506 | + $success = $this->_preview_message(true); |
|
| 2507 | + |
|
| 2508 | + if ($success) { |
|
| 2509 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2510 | + } else { |
|
| 2511 | + EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2512 | + __LINE__); |
|
| 2513 | + } |
|
| 2514 | + } |
|
| 2515 | + |
|
| 2516 | + |
|
| 2517 | + /** |
|
| 2518 | + * _generate_new_templates |
|
| 2519 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2520 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2521 | + * for the event. |
|
| 2522 | + * |
|
| 2523 | + * |
|
| 2524 | + * @param string $messenger the messenger we are generating templates for |
|
| 2525 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2526 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2527 | + * indicate the message_template_group being used as the base. |
|
| 2528 | + * |
|
| 2529 | + * @param bool $global |
|
| 2530 | + * |
|
| 2531 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2532 | + * encountering problems. |
|
| 2533 | + * @throws \EE_Error |
|
| 2534 | + */ |
|
| 2535 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2536 | + { |
|
| 2537 | + |
|
| 2538 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
|
| 2539 | + if (empty($message_types)) { |
|
| 2540 | + return true; |
|
| 2541 | + } |
|
| 2542 | + |
|
| 2543 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + |
|
| 2547 | + /** |
|
| 2548 | + * [_trash_or_restore_message_template] |
|
| 2549 | + * |
|
| 2550 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2551 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2552 | + * an individual context (FALSE). |
|
| 2553 | + * |
|
| 2554 | + * @return void |
|
| 2555 | + */ |
|
| 2556 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2557 | + { |
|
| 2558 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2559 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2560 | + |
|
| 2561 | + $success = 1; |
|
| 2562 | + |
|
| 2563 | + //incoming GRP_IDs |
|
| 2564 | + if ($all) { |
|
| 2565 | + //Checkboxes |
|
| 2566 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2567 | + //if array has more than one element then success message should be plural. |
|
| 2568 | + //todo: what about nonce? |
|
| 2569 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2570 | 2570 | |
| 2571 | - //cycle through checkboxes |
|
| 2572 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2573 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2574 | - if ( ! $trashed_or_restored) { |
|
| 2575 | - $success = 0; |
|
| 2576 | - } |
|
| 2577 | - } |
|
| 2578 | - } else { |
|
| 2579 | - //grab single GRP_ID and handle |
|
| 2580 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2581 | - if ( ! empty($GRP_ID)) { |
|
| 2582 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2583 | - if ( ! $trashed_or_restored) { |
|
| 2584 | - $success = 0; |
|
| 2585 | - } |
|
| 2586 | - } else { |
|
| 2587 | - $success = 0; |
|
| 2588 | - } |
|
| 2589 | - } |
|
| 2571 | + //cycle through checkboxes |
|
| 2572 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2573 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2574 | + if ( ! $trashed_or_restored) { |
|
| 2575 | + $success = 0; |
|
| 2576 | + } |
|
| 2577 | + } |
|
| 2578 | + } else { |
|
| 2579 | + //grab single GRP_ID and handle |
|
| 2580 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2581 | + if ( ! empty($GRP_ID)) { |
|
| 2582 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2583 | + if ( ! $trashed_or_restored) { |
|
| 2584 | + $success = 0; |
|
| 2585 | + } |
|
| 2586 | + } else { |
|
| 2587 | + $success = 0; |
|
| 2588 | + } |
|
| 2589 | + } |
|
| 2590 | 2590 | |
| 2591 | - } |
|
| 2591 | + } |
|
| 2592 | 2592 | |
| 2593 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2593 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2594 | 2594 | |
| 2595 | - $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2595 | + $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2596 | 2596 | |
| 2597 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2598 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2597 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2598 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2599 | 2599 | |
| 2600 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2601 | - 'event_espresso') : $item_desc; |
|
| 2600 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2601 | + 'event_espresso') : $item_desc; |
|
| 2602 | 2602 | |
| 2603 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2603 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2604 | 2604 | |
| 2605 | - } |
|
| 2605 | + } |
|
| 2606 | 2606 | |
| 2607 | 2607 | |
| 2608 | - /** |
|
| 2609 | - * [_delete_message_template] |
|
| 2610 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2611 | - * @return void |
|
| 2612 | - */ |
|
| 2613 | - protected function _delete_message_template() |
|
| 2614 | - { |
|
| 2615 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2608 | + /** |
|
| 2609 | + * [_delete_message_template] |
|
| 2610 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2611 | + * @return void |
|
| 2612 | + */ |
|
| 2613 | + protected function _delete_message_template() |
|
| 2614 | + { |
|
| 2615 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2616 | 2616 | |
| 2617 | - //checkboxes |
|
| 2618 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2619 | - //if array has more than one element then success message should be plural |
|
| 2620 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2617 | + //checkboxes |
|
| 2618 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2619 | + //if array has more than one element then success message should be plural |
|
| 2620 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2621 | 2621 | |
| 2622 | - //cycle through bulk action checkboxes |
|
| 2623 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2624 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2625 | - } |
|
| 2626 | - } else { |
|
| 2627 | - //grab single grp_id and delete |
|
| 2628 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 2629 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2630 | - } |
|
| 2631 | - |
|
| 2632 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2633 | - |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - |
|
| 2637 | - /** |
|
| 2638 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 2639 | - * |
|
| 2640 | - * @param int $GRP_ID The group being deleted |
|
| 2641 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2642 | - * |
|
| 2643 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2644 | - */ |
|
| 2645 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2646 | - { |
|
| 2647 | - $success = 1; |
|
| 2648 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2649 | - //first let's GET this group |
|
| 2650 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2651 | - //then delete permanently all the related Message Templates |
|
| 2652 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2653 | - |
|
| 2654 | - if ($deleted === 0) { |
|
| 2655 | - $success = 0; |
|
| 2656 | - } |
|
| 2657 | - |
|
| 2658 | - //now delete permanently this particular group |
|
| 2659 | - |
|
| 2660 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2661 | - $success = 0; |
|
| 2662 | - } |
|
| 2663 | - |
|
| 2664 | - return $success; |
|
| 2665 | - } |
|
| 2666 | - |
|
| 2667 | - |
|
| 2668 | - /** |
|
| 2669 | - * _learn_more_about_message_templates_link |
|
| 2670 | - * @access protected |
|
| 2671 | - * @return string |
|
| 2672 | - */ |
|
| 2673 | - protected function _learn_more_about_message_templates_link() |
|
| 2674 | - { |
|
| 2675 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2676 | - 'event_espresso') . '</a>'; |
|
| 2677 | - } |
|
| 2678 | - |
|
| 2679 | - |
|
| 2680 | - /** |
|
| 2681 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2682 | - * ajax and other routes. |
|
| 2683 | - * @return void |
|
| 2684 | - */ |
|
| 2685 | - protected function _settings() |
|
| 2686 | - { |
|
| 2687 | - |
|
| 2688 | - |
|
| 2689 | - $this->_set_m_mt_settings(); |
|
| 2690 | - |
|
| 2691 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2692 | - |
|
| 2693 | - //let's setup the messenger tabs |
|
| 2694 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2695 | - 'messenger_links', '|', $selected_messenger); |
|
| 2696 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2697 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2698 | - |
|
| 2699 | - $this->display_admin_page_with_sidebar(); |
|
| 2700 | - |
|
| 2701 | - } |
|
| 2702 | - |
|
| 2703 | - |
|
| 2704 | - /** |
|
| 2705 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2706 | - * |
|
| 2707 | - * @access protected |
|
| 2708 | - * @return void |
|
| 2709 | - */ |
|
| 2710 | - protected function _set_m_mt_settings() |
|
| 2711 | - { |
|
| 2712 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 2713 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 2714 | - return; |
|
| 2715 | - } |
|
| 2716 | - |
|
| 2717 | - //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2718 | - |
|
| 2719 | - //get all installed messengers and message_types |
|
| 2720 | - /** @type EE_messenger[] $messengers */ |
|
| 2721 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2722 | - /** @type EE_message_type[] $message_types */ |
|
| 2723 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2724 | - |
|
| 2725 | - |
|
| 2726 | - //assemble the array for the _tab_text_links helper |
|
| 2727 | - |
|
| 2728 | - foreach ($messengers as $messenger) { |
|
| 2729 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2730 | - 'label' => ucwords($messenger->label['singular']), |
|
| 2731 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2732 | - 'href' => $messenger->name, |
|
| 2733 | - 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2734 | - 'slug' => $messenger->name, |
|
| 2735 | - 'obj' => $messenger |
|
| 2736 | - ); |
|
| 2622 | + //cycle through bulk action checkboxes |
|
| 2623 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2624 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2625 | + } |
|
| 2626 | + } else { |
|
| 2627 | + //grab single grp_id and delete |
|
| 2628 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 2629 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2630 | + } |
|
| 2631 | + |
|
| 2632 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2633 | + |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + |
|
| 2637 | + /** |
|
| 2638 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 2639 | + * |
|
| 2640 | + * @param int $GRP_ID The group being deleted |
|
| 2641 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2642 | + * |
|
| 2643 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 2644 | + */ |
|
| 2645 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2646 | + { |
|
| 2647 | + $success = 1; |
|
| 2648 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2649 | + //first let's GET this group |
|
| 2650 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2651 | + //then delete permanently all the related Message Templates |
|
| 2652 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2653 | + |
|
| 2654 | + if ($deleted === 0) { |
|
| 2655 | + $success = 0; |
|
| 2656 | + } |
|
| 2657 | + |
|
| 2658 | + //now delete permanently this particular group |
|
| 2659 | + |
|
| 2660 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2661 | + $success = 0; |
|
| 2662 | + } |
|
| 2663 | + |
|
| 2664 | + return $success; |
|
| 2665 | + } |
|
| 2666 | + |
|
| 2667 | + |
|
| 2668 | + /** |
|
| 2669 | + * _learn_more_about_message_templates_link |
|
| 2670 | + * @access protected |
|
| 2671 | + * @return string |
|
| 2672 | + */ |
|
| 2673 | + protected function _learn_more_about_message_templates_link() |
|
| 2674 | + { |
|
| 2675 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2676 | + 'event_espresso') . '</a>'; |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + |
|
| 2680 | + /** |
|
| 2681 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2682 | + * ajax and other routes. |
|
| 2683 | + * @return void |
|
| 2684 | + */ |
|
| 2685 | + protected function _settings() |
|
| 2686 | + { |
|
| 2687 | + |
|
| 2688 | + |
|
| 2689 | + $this->_set_m_mt_settings(); |
|
| 2690 | + |
|
| 2691 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2692 | + |
|
| 2693 | + //let's setup the messenger tabs |
|
| 2694 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2695 | + 'messenger_links', '|', $selected_messenger); |
|
| 2696 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2697 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2698 | + |
|
| 2699 | + $this->display_admin_page_with_sidebar(); |
|
| 2700 | + |
|
| 2701 | + } |
|
| 2702 | + |
|
| 2703 | + |
|
| 2704 | + /** |
|
| 2705 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2706 | + * |
|
| 2707 | + * @access protected |
|
| 2708 | + * @return void |
|
| 2709 | + */ |
|
| 2710 | + protected function _set_m_mt_settings() |
|
| 2711 | + { |
|
| 2712 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 2713 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 2714 | + return; |
|
| 2715 | + } |
|
| 2716 | + |
|
| 2717 | + //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2718 | + |
|
| 2719 | + //get all installed messengers and message_types |
|
| 2720 | + /** @type EE_messenger[] $messengers */ |
|
| 2721 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2722 | + /** @type EE_message_type[] $message_types */ |
|
| 2723 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2724 | + |
|
| 2725 | + |
|
| 2726 | + //assemble the array for the _tab_text_links helper |
|
| 2727 | + |
|
| 2728 | + foreach ($messengers as $messenger) { |
|
| 2729 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2730 | + 'label' => ucwords($messenger->label['singular']), |
|
| 2731 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2732 | + 'href' => $messenger->name, |
|
| 2733 | + 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2734 | + 'slug' => $messenger->name, |
|
| 2735 | + 'obj' => $messenger |
|
| 2736 | + ); |
|
| 2737 | 2737 | |
| 2738 | 2738 | |
| 2739 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2739 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2740 | 2740 | |
| 2741 | - foreach ($message_types as $message_type) { |
|
| 2742 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2743 | - if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2744 | - continue; |
|
| 2745 | - } |
|
| 2741 | + foreach ($message_types as $message_type) { |
|
| 2742 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
|
| 2743 | + if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2744 | + continue; |
|
| 2745 | + } |
|
| 2746 | 2746 | |
| 2747 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2748 | - $message_type->name) ? 'active' : 'inactive'; |
|
| 2747 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2748 | + $message_type->name) ? 'active' : 'inactive'; |
|
| 2749 | 2749 | |
| 2750 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2751 | - 'label' => ucwords($message_type->label['singular']), |
|
| 2752 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2753 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2754 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2755 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2756 | - 'title' => $a_or_i == 'active' |
|
| 2757 | - ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2758 | - : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2759 | - 'content' => $a_or_i == 'active' |
|
| 2760 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2761 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2762 | - 'slug' => $message_type->name, |
|
| 2763 | - 'active' => $a_or_i == 'active' ? true : false, |
|
| 2764 | - 'obj' => $message_type |
|
| 2765 | - ); |
|
| 2766 | - } |
|
| 2767 | - } |
|
| 2768 | - } |
|
| 2769 | - |
|
| 2770 | - |
|
| 2771 | - /** |
|
| 2772 | - * This just prepares the content for the message type settings |
|
| 2773 | - * |
|
| 2774 | - * @param object $message_type The message type object |
|
| 2775 | - * @param object $messenger The messenger object |
|
| 2776 | - * @param boolean $active Whether the message type is active or not |
|
| 2777 | - * |
|
| 2778 | - * @return string html output for the content |
|
| 2779 | - */ |
|
| 2780 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2781 | - { |
|
| 2782 | - //get message type fields |
|
| 2783 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 2784 | - $settings_template_args['template_form_fields'] = ''; |
|
| 2785 | - |
|
| 2786 | - if ( ! empty($fields) && $active) { |
|
| 2750 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2751 | + 'label' => ucwords($message_type->label['singular']), |
|
| 2752 | + 'class' => 'message-type-' . $a_or_i, |
|
| 2753 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2754 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2755 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2756 | + 'title' => $a_or_i == 'active' |
|
| 2757 | + ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2758 | + : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2759 | + 'content' => $a_or_i == 'active' |
|
| 2760 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2761 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2762 | + 'slug' => $message_type->name, |
|
| 2763 | + 'active' => $a_or_i == 'active' ? true : false, |
|
| 2764 | + 'obj' => $message_type |
|
| 2765 | + ); |
|
| 2766 | + } |
|
| 2767 | + } |
|
| 2768 | + } |
|
| 2769 | + |
|
| 2770 | + |
|
| 2771 | + /** |
|
| 2772 | + * This just prepares the content for the message type settings |
|
| 2773 | + * |
|
| 2774 | + * @param object $message_type The message type object |
|
| 2775 | + * @param object $messenger The messenger object |
|
| 2776 | + * @param boolean $active Whether the message type is active or not |
|
| 2777 | + * |
|
| 2778 | + * @return string html output for the content |
|
| 2779 | + */ |
|
| 2780 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2781 | + { |
|
| 2782 | + //get message type fields |
|
| 2783 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 2784 | + $settings_template_args['template_form_fields'] = ''; |
|
| 2785 | + |
|
| 2786 | + if ( ! empty($fields) && $active) { |
|
| 2787 | 2787 | |
| 2788 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2788 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2789 | 2789 | |
| 2790 | - foreach ($fields as $fldname => $fldprops) { |
|
| 2791 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2792 | - $template_form_field[$field_id] = array( |
|
| 2793 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2794 | - 'label' => $fldprops['label'], |
|
| 2795 | - 'input' => $fldprops['field_type'], |
|
| 2796 | - 'type' => $fldprops['value_type'], |
|
| 2797 | - 'required' => $fldprops['required'], |
|
| 2798 | - 'validation' => $fldprops['validation'], |
|
| 2799 | - 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2800 | - 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2801 | - 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2802 | - 'css_class' => 'no-drag', |
|
| 2803 | - 'format' => $fldprops['format'] |
|
| 2804 | - ); |
|
| 2805 | - } |
|
| 2790 | + foreach ($fields as $fldname => $fldprops) { |
|
| 2791 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2792 | + $template_form_field[$field_id] = array( |
|
| 2793 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2794 | + 'label' => $fldprops['label'], |
|
| 2795 | + 'input' => $fldprops['field_type'], |
|
| 2796 | + 'type' => $fldprops['value_type'], |
|
| 2797 | + 'required' => $fldprops['required'], |
|
| 2798 | + 'validation' => $fldprops['validation'], |
|
| 2799 | + 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2800 | + 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2801 | + 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2802 | + 'css_class' => 'no-drag', |
|
| 2803 | + 'format' => $fldprops['format'] |
|
| 2804 | + ); |
|
| 2805 | + } |
|
| 2806 | 2806 | |
| 2807 | 2807 | |
| 2808 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2809 | - 'string', 'ee_mt_activate_form') : ''; |
|
| 2810 | - } |
|
| 2811 | - |
|
| 2812 | - $settings_template_args['description'] = $message_type->description; |
|
| 2813 | - //we also need some hidden fields |
|
| 2814 | - $settings_template_args['hidden_fields'] = array( |
|
| 2815 | - 'message_type_settings[messenger]' => array( |
|
| 2816 | - 'type' => 'hidden', |
|
| 2817 | - 'value' => $messenger->name |
|
| 2818 | - ), |
|
| 2819 | - 'message_type_settings[message_type]' => array( |
|
| 2820 | - 'type' => 'hidden', |
|
| 2821 | - 'value' => $message_type->name |
|
| 2822 | - ), |
|
| 2823 | - 'type' => array( |
|
| 2824 | - 'type' => 'hidden', |
|
| 2825 | - 'value' => 'message_type' |
|
| 2826 | - ) |
|
| 2827 | - ); |
|
| 2828 | - |
|
| 2829 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2830 | - 'array'); |
|
| 2831 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2832 | - |
|
| 2833 | - |
|
| 2834 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2835 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2836 | - |
|
| 2837 | - return $content; |
|
| 2838 | - } |
|
| 2839 | - |
|
| 2840 | - |
|
| 2841 | - /** |
|
| 2842 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2843 | - * |
|
| 2844 | - * @access protected |
|
| 2845 | - * @return void |
|
| 2846 | - */ |
|
| 2847 | - protected function _messages_settings_metaboxes() |
|
| 2848 | - { |
|
| 2849 | - $this->_set_m_mt_settings(); |
|
| 2850 | - $m_boxes = $mt_boxes = array(); |
|
| 2851 | - $m_template_args = $mt_template_args = array(); |
|
| 2852 | - |
|
| 2853 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2854 | - |
|
| 2855 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2856 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2857 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2858 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2859 | - //messenger meta boxes |
|
| 2860 | - $active = $selected_messenger == $messenger ? true : false; |
|
| 2861 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2862 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2863 | - : ''; |
|
| 2864 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2865 | - __('%s Settings', 'event_espresso'), |
|
| 2866 | - $tab_array['label'] |
|
| 2867 | - ); |
|
| 2868 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2869 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2870 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2871 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2872 | - : '', |
|
| 2873 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2874 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2875 | - 'hide_on_message' => $hide_on_message, |
|
| 2876 | - 'messenger' => $messenger, |
|
| 2877 | - 'active' => $active |
|
| 2878 | - ); |
|
| 2879 | - // message type meta boxes |
|
| 2880 | - // (which is really just the inactive container for each messenger |
|
| 2881 | - // showing inactive message types for that messenger) |
|
| 2882 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2883 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2884 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2885 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2886 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2887 | - : '', |
|
| 2888 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2889 | - 'hide_on_message' => $hide_on_message, |
|
| 2890 | - 'hide_off_message' => $hide_off_message, |
|
| 2891 | - 'messenger' => $messenger, |
|
| 2892 | - 'active' => $active |
|
| 2893 | - ); |
|
| 2894 | - } |
|
| 2895 | - } |
|
| 2896 | - |
|
| 2897 | - |
|
| 2898 | - //register messenger metaboxes |
|
| 2899 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2900 | - foreach ($m_boxes as $box => $label) { |
|
| 2901 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2902 | - $msgr = str_replace('_a_box', '', $box); |
|
| 2903 | - add_meta_box( |
|
| 2904 | - 'espresso_' . $msgr . '_settings', |
|
| 2905 | - $label, |
|
| 2906 | - function ($post, $metabox) { |
|
| 2907 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2908 | - $metabox["args"]["template_args"], true); |
|
| 2909 | - }, |
|
| 2910 | - $this->_current_screen->id, |
|
| 2911 | - 'normal', |
|
| 2912 | - 'high', |
|
| 2913 | - $callback_args |
|
| 2914 | - ); |
|
| 2915 | - } |
|
| 2916 | - |
|
| 2917 | - //register message type metaboxes |
|
| 2918 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2919 | - foreach ($mt_boxes as $box => $label) { |
|
| 2920 | - $callback_args = array( |
|
| 2921 | - 'template_path' => $mt_template_path, |
|
| 2922 | - 'template_args' => $mt_template_args[$box] |
|
| 2923 | - ); |
|
| 2924 | - $mt = str_replace('_i_box', '', $box); |
|
| 2925 | - add_meta_box( |
|
| 2926 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2927 | - $label, |
|
| 2928 | - function ($post, $metabox) { |
|
| 2929 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2930 | - $metabox["args"]["template_args"], true); |
|
| 2931 | - }, |
|
| 2932 | - $this->_current_screen->id, |
|
| 2933 | - 'side', |
|
| 2934 | - 'high', |
|
| 2935 | - $callback_args |
|
| 2936 | - ); |
|
| 2937 | - } |
|
| 2938 | - |
|
| 2939 | - //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2940 | - //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2941 | - if (is_main_site()) { |
|
| 2942 | - add_meta_box( |
|
| 2943 | - 'espresso_global_message_settings', |
|
| 2944 | - __('Global Message Settings', 'event_espresso'), |
|
| 2945 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 2946 | - $this->_current_screen->id, |
|
| 2947 | - 'normal', |
|
| 2948 | - 'low', |
|
| 2949 | - array() |
|
| 2950 | - ); |
|
| 2951 | - } |
|
| 2952 | - |
|
| 2953 | - } |
|
| 2954 | - |
|
| 2955 | - |
|
| 2956 | - /** |
|
| 2957 | - * This generates the content for the global messages settings metabox. |
|
| 2958 | - * @return string |
|
| 2959 | - */ |
|
| 2960 | - public function global_messages_settings_metabox_content() |
|
| 2961 | - { |
|
| 2962 | - $form = $this->_generate_global_settings_form(); |
|
| 2963 | - echo $form->form_open( |
|
| 2964 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2965 | - 'POST' |
|
| 2966 | - ) |
|
| 2967 | - . $form->get_html() |
|
| 2968 | - . $form->form_close(); |
|
| 2969 | - } |
|
| 2970 | - |
|
| 2971 | - |
|
| 2972 | - /** |
|
| 2973 | - * This generates and returns the form object for the global messages settings. |
|
| 2974 | - * @return EE_Form_Section_Proper |
|
| 2975 | - */ |
|
| 2976 | - protected function _generate_global_settings_form() |
|
| 2977 | - { |
|
| 2978 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 2979 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 2980 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 2981 | - |
|
| 2982 | - return new EE_Form_Section_Proper( |
|
| 2983 | - array( |
|
| 2984 | - 'name' => 'global_messages_settings', |
|
| 2985 | - 'html_id' => 'global_messages_settings', |
|
| 2986 | - 'html_class' => 'form-table', |
|
| 2987 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2988 | - 'subsections' => apply_filters( |
|
| 2989 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 2990 | - array( |
|
| 2991 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 2992 | - array( |
|
| 2993 | - true => __("On the same request", "event_espresso"), |
|
| 2994 | - false => __("On a separate request", "event_espresso") |
|
| 2995 | - ), |
|
| 2996 | - array( |
|
| 2997 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 2998 | - 'html_label_text' => __('Generate and send all messages:', 'event_espresso'), |
|
| 2999 | - 'html_help_text' => __('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3000 | - 'event_espresso'), |
|
| 3001 | - ) |
|
| 3002 | - ), |
|
| 3003 | - 'update_settings' => new EE_Submit_Input( |
|
| 3004 | - array( |
|
| 3005 | - 'default' => __('Update', 'event_espresso'), |
|
| 3006 | - 'html_label_text' => ' ' |
|
| 3007 | - ) |
|
| 3008 | - ) |
|
| 3009 | - ) |
|
| 3010 | - ) |
|
| 3011 | - ) |
|
| 3012 | - ); |
|
| 3013 | - } |
|
| 3014 | - |
|
| 3015 | - |
|
| 3016 | - /** |
|
| 3017 | - * This handles updating the global settings set on the admin page. |
|
| 3018 | - * @throws \EE_Error |
|
| 3019 | - */ |
|
| 3020 | - protected function _update_global_settings() |
|
| 3021 | - { |
|
| 3022 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3023 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3024 | - $form = $this->_generate_global_settings_form(); |
|
| 3025 | - if ($form->was_submitted()) { |
|
| 3026 | - $form->receive_form_submission(); |
|
| 3027 | - if ($form->is_valid()) { |
|
| 3028 | - $valid_data = $form->valid_data(); |
|
| 3029 | - foreach ($valid_data as $property => $value) { |
|
| 3030 | - $setter = 'set_' . $property; |
|
| 3031 | - if (method_exists($network_config, $setter)) { |
|
| 3032 | - $network_config->{$setter}($value); |
|
| 3033 | - } else if ( |
|
| 3034 | - property_exists($network_config, $property) |
|
| 3035 | - && $network_config->{$property} !== $value |
|
| 3036 | - ) { |
|
| 3037 | - $network_config->{$property} = $value; |
|
| 3038 | - } |
|
| 3039 | - } |
|
| 3040 | - //only update if the form submission was valid! |
|
| 3041 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3042 | - EE_Error::overwrite_success(); |
|
| 3043 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3044 | - } |
|
| 3045 | - } |
|
| 3046 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3047 | - } |
|
| 3048 | - |
|
| 3049 | - |
|
| 3050 | - /** |
|
| 3051 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3052 | - * |
|
| 3053 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3054 | - * |
|
| 3055 | - * @return string html formatted tabs |
|
| 3056 | - */ |
|
| 3057 | - protected function _get_mt_tabs($tab_array) |
|
| 3058 | - { |
|
| 3059 | - $tab_array = (array)$tab_array; |
|
| 3060 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3061 | - $tabs = ''; |
|
| 3062 | - |
|
| 3063 | - foreach ($tab_array as $tab) { |
|
| 3064 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3065 | - } |
|
| 3066 | - |
|
| 3067 | - return $tabs; |
|
| 3068 | - } |
|
| 3069 | - |
|
| 3070 | - |
|
| 3071 | - /** |
|
| 3072 | - * This prepares the content of the messenger meta box admin settings |
|
| 3073 | - * |
|
| 3074 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3075 | - * |
|
| 3076 | - * @return string html formatted content |
|
| 3077 | - */ |
|
| 3078 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3079 | - { |
|
| 3080 | - |
|
| 3081 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3082 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3083 | - |
|
| 3084 | - //is $messenger active? |
|
| 3085 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3086 | - |
|
| 3087 | - |
|
| 3088 | - if ( ! empty($fields)) { |
|
| 2808 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2809 | + 'string', 'ee_mt_activate_form') : ''; |
|
| 2810 | + } |
|
| 2811 | + |
|
| 2812 | + $settings_template_args['description'] = $message_type->description; |
|
| 2813 | + //we also need some hidden fields |
|
| 2814 | + $settings_template_args['hidden_fields'] = array( |
|
| 2815 | + 'message_type_settings[messenger]' => array( |
|
| 2816 | + 'type' => 'hidden', |
|
| 2817 | + 'value' => $messenger->name |
|
| 2818 | + ), |
|
| 2819 | + 'message_type_settings[message_type]' => array( |
|
| 2820 | + 'type' => 'hidden', |
|
| 2821 | + 'value' => $message_type->name |
|
| 2822 | + ), |
|
| 2823 | + 'type' => array( |
|
| 2824 | + 'type' => 'hidden', |
|
| 2825 | + 'value' => 'message_type' |
|
| 2826 | + ) |
|
| 2827 | + ); |
|
| 2828 | + |
|
| 2829 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2830 | + 'array'); |
|
| 2831 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2832 | + |
|
| 2833 | + |
|
| 2834 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2835 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2836 | + |
|
| 2837 | + return $content; |
|
| 2838 | + } |
|
| 2839 | + |
|
| 2840 | + |
|
| 2841 | + /** |
|
| 2842 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2843 | + * |
|
| 2844 | + * @access protected |
|
| 2845 | + * @return void |
|
| 2846 | + */ |
|
| 2847 | + protected function _messages_settings_metaboxes() |
|
| 2848 | + { |
|
| 2849 | + $this->_set_m_mt_settings(); |
|
| 2850 | + $m_boxes = $mt_boxes = array(); |
|
| 2851 | + $m_template_args = $mt_template_args = array(); |
|
| 2852 | + |
|
| 2853 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2854 | + |
|
| 2855 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2856 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2857 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2858 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2859 | + //messenger meta boxes |
|
| 2860 | + $active = $selected_messenger == $messenger ? true : false; |
|
| 2861 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2862 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2863 | + : ''; |
|
| 2864 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2865 | + __('%s Settings', 'event_espresso'), |
|
| 2866 | + $tab_array['label'] |
|
| 2867 | + ); |
|
| 2868 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 2869 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2870 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2871 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2872 | + : '', |
|
| 2873 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2874 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2875 | + 'hide_on_message' => $hide_on_message, |
|
| 2876 | + 'messenger' => $messenger, |
|
| 2877 | + 'active' => $active |
|
| 2878 | + ); |
|
| 2879 | + // message type meta boxes |
|
| 2880 | + // (which is really just the inactive container for each messenger |
|
| 2881 | + // showing inactive message types for that messenger) |
|
| 2882 | + $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2883 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2884 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2885 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2886 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2887 | + : '', |
|
| 2888 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2889 | + 'hide_on_message' => $hide_on_message, |
|
| 2890 | + 'hide_off_message' => $hide_off_message, |
|
| 2891 | + 'messenger' => $messenger, |
|
| 2892 | + 'active' => $active |
|
| 2893 | + ); |
|
| 2894 | + } |
|
| 2895 | + } |
|
| 2896 | + |
|
| 2897 | + |
|
| 2898 | + //register messenger metaboxes |
|
| 2899 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2900 | + foreach ($m_boxes as $box => $label) { |
|
| 2901 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2902 | + $msgr = str_replace('_a_box', '', $box); |
|
| 2903 | + add_meta_box( |
|
| 2904 | + 'espresso_' . $msgr . '_settings', |
|
| 2905 | + $label, |
|
| 2906 | + function ($post, $metabox) { |
|
| 2907 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2908 | + $metabox["args"]["template_args"], true); |
|
| 2909 | + }, |
|
| 2910 | + $this->_current_screen->id, |
|
| 2911 | + 'normal', |
|
| 2912 | + 'high', |
|
| 2913 | + $callback_args |
|
| 2914 | + ); |
|
| 2915 | + } |
|
| 2916 | + |
|
| 2917 | + //register message type metaboxes |
|
| 2918 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2919 | + foreach ($mt_boxes as $box => $label) { |
|
| 2920 | + $callback_args = array( |
|
| 2921 | + 'template_path' => $mt_template_path, |
|
| 2922 | + 'template_args' => $mt_template_args[$box] |
|
| 2923 | + ); |
|
| 2924 | + $mt = str_replace('_i_box', '', $box); |
|
| 2925 | + add_meta_box( |
|
| 2926 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 2927 | + $label, |
|
| 2928 | + function ($post, $metabox) { |
|
| 2929 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2930 | + $metabox["args"]["template_args"], true); |
|
| 2931 | + }, |
|
| 2932 | + $this->_current_screen->id, |
|
| 2933 | + 'side', |
|
| 2934 | + 'high', |
|
| 2935 | + $callback_args |
|
| 2936 | + ); |
|
| 2937 | + } |
|
| 2938 | + |
|
| 2939 | + //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2940 | + //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2941 | + if (is_main_site()) { |
|
| 2942 | + add_meta_box( |
|
| 2943 | + 'espresso_global_message_settings', |
|
| 2944 | + __('Global Message Settings', 'event_espresso'), |
|
| 2945 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 2946 | + $this->_current_screen->id, |
|
| 2947 | + 'normal', |
|
| 2948 | + 'low', |
|
| 2949 | + array() |
|
| 2950 | + ); |
|
| 2951 | + } |
|
| 2952 | + |
|
| 2953 | + } |
|
| 2954 | + |
|
| 2955 | + |
|
| 2956 | + /** |
|
| 2957 | + * This generates the content for the global messages settings metabox. |
|
| 2958 | + * @return string |
|
| 2959 | + */ |
|
| 2960 | + public function global_messages_settings_metabox_content() |
|
| 2961 | + { |
|
| 2962 | + $form = $this->_generate_global_settings_form(); |
|
| 2963 | + echo $form->form_open( |
|
| 2964 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2965 | + 'POST' |
|
| 2966 | + ) |
|
| 2967 | + . $form->get_html() |
|
| 2968 | + . $form->form_close(); |
|
| 2969 | + } |
|
| 2970 | + |
|
| 2971 | + |
|
| 2972 | + /** |
|
| 2973 | + * This generates and returns the form object for the global messages settings. |
|
| 2974 | + * @return EE_Form_Section_Proper |
|
| 2975 | + */ |
|
| 2976 | + protected function _generate_global_settings_form() |
|
| 2977 | + { |
|
| 2978 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 2979 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 2980 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 2981 | + |
|
| 2982 | + return new EE_Form_Section_Proper( |
|
| 2983 | + array( |
|
| 2984 | + 'name' => 'global_messages_settings', |
|
| 2985 | + 'html_id' => 'global_messages_settings', |
|
| 2986 | + 'html_class' => 'form-table', |
|
| 2987 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2988 | + 'subsections' => apply_filters( |
|
| 2989 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 2990 | + array( |
|
| 2991 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 2992 | + array( |
|
| 2993 | + true => __("On the same request", "event_espresso"), |
|
| 2994 | + false => __("On a separate request", "event_espresso") |
|
| 2995 | + ), |
|
| 2996 | + array( |
|
| 2997 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 2998 | + 'html_label_text' => __('Generate and send all messages:', 'event_espresso'), |
|
| 2999 | + 'html_help_text' => __('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3000 | + 'event_espresso'), |
|
| 3001 | + ) |
|
| 3002 | + ), |
|
| 3003 | + 'update_settings' => new EE_Submit_Input( |
|
| 3004 | + array( |
|
| 3005 | + 'default' => __('Update', 'event_espresso'), |
|
| 3006 | + 'html_label_text' => ' ' |
|
| 3007 | + ) |
|
| 3008 | + ) |
|
| 3009 | + ) |
|
| 3010 | + ) |
|
| 3011 | + ) |
|
| 3012 | + ); |
|
| 3013 | + } |
|
| 3014 | + |
|
| 3015 | + |
|
| 3016 | + /** |
|
| 3017 | + * This handles updating the global settings set on the admin page. |
|
| 3018 | + * @throws \EE_Error |
|
| 3019 | + */ |
|
| 3020 | + protected function _update_global_settings() |
|
| 3021 | + { |
|
| 3022 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3023 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3024 | + $form = $this->_generate_global_settings_form(); |
|
| 3025 | + if ($form->was_submitted()) { |
|
| 3026 | + $form->receive_form_submission(); |
|
| 3027 | + if ($form->is_valid()) { |
|
| 3028 | + $valid_data = $form->valid_data(); |
|
| 3029 | + foreach ($valid_data as $property => $value) { |
|
| 3030 | + $setter = 'set_' . $property; |
|
| 3031 | + if (method_exists($network_config, $setter)) { |
|
| 3032 | + $network_config->{$setter}($value); |
|
| 3033 | + } else if ( |
|
| 3034 | + property_exists($network_config, $property) |
|
| 3035 | + && $network_config->{$property} !== $value |
|
| 3036 | + ) { |
|
| 3037 | + $network_config->{$property} = $value; |
|
| 3038 | + } |
|
| 3039 | + } |
|
| 3040 | + //only update if the form submission was valid! |
|
| 3041 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3042 | + EE_Error::overwrite_success(); |
|
| 3043 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3044 | + } |
|
| 3045 | + } |
|
| 3046 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3047 | + } |
|
| 3048 | + |
|
| 3049 | + |
|
| 3050 | + /** |
|
| 3051 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3052 | + * |
|
| 3053 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3054 | + * |
|
| 3055 | + * @return string html formatted tabs |
|
| 3056 | + */ |
|
| 3057 | + protected function _get_mt_tabs($tab_array) |
|
| 3058 | + { |
|
| 3059 | + $tab_array = (array)$tab_array; |
|
| 3060 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3061 | + $tabs = ''; |
|
| 3062 | + |
|
| 3063 | + foreach ($tab_array as $tab) { |
|
| 3064 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3065 | + } |
|
| 3066 | + |
|
| 3067 | + return $tabs; |
|
| 3068 | + } |
|
| 3069 | + |
|
| 3070 | + |
|
| 3071 | + /** |
|
| 3072 | + * This prepares the content of the messenger meta box admin settings |
|
| 3073 | + * |
|
| 3074 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3075 | + * |
|
| 3076 | + * @return string html formatted content |
|
| 3077 | + */ |
|
| 3078 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3079 | + { |
|
| 3080 | + |
|
| 3081 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3082 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3083 | + |
|
| 3084 | + //is $messenger active? |
|
| 3085 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3086 | + |
|
| 3087 | + |
|
| 3088 | + if ( ! empty($fields)) { |
|
| 3089 | 3089 | |
| 3090 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3090 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3091 | 3091 | |
| 3092 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3093 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3094 | - $template_form_field[$field_id] = array( |
|
| 3095 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3096 | - 'label' => $fldprops['label'], |
|
| 3097 | - 'input' => $fldprops['field_type'], |
|
| 3098 | - 'type' => $fldprops['value_type'], |
|
| 3099 | - 'required' => $fldprops['required'], |
|
| 3100 | - 'validation' => $fldprops['validation'], |
|
| 3101 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3102 | - ? $existing_settings[$field_id] |
|
| 3103 | - : $fldprops['default'], |
|
| 3104 | - 'css_class' => '', |
|
| 3105 | - 'format' => $fldprops['format'] |
|
| 3106 | - ); |
|
| 3107 | - } |
|
| 3092 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3093 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3094 | + $template_form_field[$field_id] = array( |
|
| 3095 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3096 | + 'label' => $fldprops['label'], |
|
| 3097 | + 'input' => $fldprops['field_type'], |
|
| 3098 | + 'type' => $fldprops['value_type'], |
|
| 3099 | + 'required' => $fldprops['required'], |
|
| 3100 | + 'validation' => $fldprops['validation'], |
|
| 3101 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3102 | + ? $existing_settings[$field_id] |
|
| 3103 | + : $fldprops['default'], |
|
| 3104 | + 'css_class' => '', |
|
| 3105 | + 'format' => $fldprops['format'] |
|
| 3106 | + ); |
|
| 3107 | + } |
|
| 3108 | 3108 | |
| 3109 | 3109 | |
| 3110 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3111 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3112 | - : ''; |
|
| 3113 | - } |
|
| 3114 | - |
|
| 3115 | - //we also need some hidden fields |
|
| 3116 | - $settings_template_args['hidden_fields'] = array( |
|
| 3117 | - 'messenger_settings[messenger]' => array( |
|
| 3118 | - 'type' => 'hidden', |
|
| 3119 | - 'value' => $messenger->name |
|
| 3120 | - ), |
|
| 3121 | - 'type' => array( |
|
| 3122 | - 'type' => 'hidden', |
|
| 3123 | - 'value' => 'messenger' |
|
| 3124 | - ) |
|
| 3125 | - ); |
|
| 3126 | - |
|
| 3127 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3128 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3129 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3130 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3131 | - 'type' => 'hidden', |
|
| 3132 | - 'value' => $mt |
|
| 3133 | - ); |
|
| 3134 | - } |
|
| 3135 | - } |
|
| 3136 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3137 | - $settings_template_args['hidden_fields'], |
|
| 3138 | - 'array' |
|
| 3139 | - ); |
|
| 3140 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3141 | - |
|
| 3142 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3143 | - $settings_template_args['description'] = $messenger->description; |
|
| 3144 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3145 | - |
|
| 3146 | - |
|
| 3147 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3148 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3149 | - : ' hidden'; |
|
| 3150 | - |
|
| 3151 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3152 | - ? ' hidden' |
|
| 3153 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3154 | - |
|
| 3155 | - |
|
| 3156 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3157 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3158 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3159 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3160 | - $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3161 | - true); |
|
| 3162 | - |
|
| 3163 | - return $content; |
|
| 3164 | - } |
|
| 3165 | - |
|
| 3166 | - |
|
| 3167 | - /** |
|
| 3168 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3169 | - */ |
|
| 3170 | - public function activate_messenger_toggle() |
|
| 3171 | - { |
|
| 3172 | - $success = true; |
|
| 3173 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3174 | - //let's check that we have required data |
|
| 3175 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3176 | - EE_Error::add_error( |
|
| 3177 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3178 | - __FILE__, |
|
| 3179 | - __FUNCTION__, |
|
| 3180 | - __LINE__ |
|
| 3181 | - ); |
|
| 3182 | - $success = false; |
|
| 3183 | - } |
|
| 3184 | - |
|
| 3185 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3186 | - $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3187 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3188 | - |
|
| 3189 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3190 | - |
|
| 3191 | - |
|
| 3192 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3193 | - EE_Error::add_error( |
|
| 3194 | - __( |
|
| 3195 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3196 | - 'event_espresso' |
|
| 3197 | - ), |
|
| 3198 | - __FILE__, |
|
| 3199 | - __FUNCTION__, |
|
| 3200 | - __LINE__ |
|
| 3201 | - ); |
|
| 3202 | - $success = false; |
|
| 3203 | - } |
|
| 3204 | - |
|
| 3205 | - //do check to verify we have a valid status. |
|
| 3206 | - $status = $this->_req_data['status']; |
|
| 3207 | - |
|
| 3208 | - if ($status != 'off' && $status != 'on') { |
|
| 3209 | - EE_Error::add_error( |
|
| 3210 | - sprintf( |
|
| 3211 | - __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3212 | - $this->_req_data['status'] |
|
| 3213 | - ), |
|
| 3214 | - __FILE__, |
|
| 3215 | - __FUNCTION__, |
|
| 3216 | - __LINE__ |
|
| 3217 | - ); |
|
| 3218 | - $success = false; |
|
| 3219 | - } |
|
| 3220 | - |
|
| 3221 | - if ($success) { |
|
| 3222 | - //made it here? Stop dawdling then!! |
|
| 3223 | - $success = $status == 'off' |
|
| 3224 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3225 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3226 | - } |
|
| 3227 | - |
|
| 3228 | - $this->_template_args['success'] = $success; |
|
| 3229 | - |
|
| 3230 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3231 | - $this->_return_json(); |
|
| 3232 | - |
|
| 3233 | - } |
|
| 3234 | - |
|
| 3235 | - |
|
| 3236 | - /** |
|
| 3237 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3238 | - * |
|
| 3239 | - */ |
|
| 3240 | - public function activate_mt_toggle() |
|
| 3241 | - { |
|
| 3242 | - $success = true; |
|
| 3243 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3244 | - |
|
| 3245 | - //let's make sure we have the necessary data |
|
| 3246 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3247 | - EE_Error::add_error( |
|
| 3248 | - __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3249 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3250 | - ); |
|
| 3251 | - $success = false; |
|
| 3252 | - } |
|
| 3253 | - |
|
| 3254 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3255 | - EE_Error::add_error( |
|
| 3256 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3257 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3258 | - ); |
|
| 3259 | - $success = false; |
|
| 3260 | - } |
|
| 3261 | - |
|
| 3262 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3263 | - EE_Error::add_error( |
|
| 3264 | - __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3265 | - 'event_espresso'), |
|
| 3266 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3267 | - ); |
|
| 3268 | - $success = false; |
|
| 3269 | - } |
|
| 3270 | - |
|
| 3271 | - |
|
| 3272 | - //do check to verify we have a valid status. |
|
| 3273 | - $status = $this->_req_data['status']; |
|
| 3274 | - |
|
| 3275 | - if ($status != 'activate' && $status != 'deactivate') { |
|
| 3276 | - EE_Error::add_error( |
|
| 3277 | - sprintf( |
|
| 3278 | - __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3279 | - $this->_req_data['status'] |
|
| 3280 | - ), |
|
| 3281 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3282 | - ); |
|
| 3283 | - $success = false; |
|
| 3284 | - } |
|
| 3285 | - |
|
| 3286 | - |
|
| 3287 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3288 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3289 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3290 | - |
|
| 3291 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3292 | - |
|
| 3293 | - if ($success) { |
|
| 3294 | - //made it here? um, what are you waiting for then? |
|
| 3295 | - $success = $status == 'deactivate' |
|
| 3296 | - ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3297 | - $this->_req_data['message_type']) |
|
| 3298 | - : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3299 | - $this->_req_data['message_type']); |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - $this->_template_args['success'] = $success; |
|
| 3303 | - $this->_return_json(); |
|
| 3304 | - } |
|
| 3305 | - |
|
| 3306 | - |
|
| 3307 | - /** |
|
| 3308 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3309 | - * |
|
| 3310 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3311 | - * |
|
| 3312 | - * @return bool |
|
| 3313 | - */ |
|
| 3314 | - protected function _activate_messenger($messenger_name) |
|
| 3315 | - { |
|
| 3316 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3317 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3318 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3319 | - |
|
| 3320 | - //ensure is active |
|
| 3321 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3322 | - |
|
| 3323 | - //set response_data for reload |
|
| 3324 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3325 | - /** @var EE_message_type $message_type */ |
|
| 3326 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3327 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3328 | - $message_type_name) |
|
| 3329 | - && $message_type instanceof EE_message_type |
|
| 3330 | - ) { |
|
| 3331 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3332 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3333 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3334 | - } |
|
| 3335 | - } |
|
| 3336 | - } |
|
| 3337 | - |
|
| 3338 | - //add success message for activating messenger |
|
| 3339 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3340 | - |
|
| 3341 | - } |
|
| 3342 | - |
|
| 3343 | - |
|
| 3344 | - /** |
|
| 3345 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3346 | - * |
|
| 3347 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3348 | - * |
|
| 3349 | - * @return bool |
|
| 3350 | - */ |
|
| 3351 | - protected function _deactivate_messenger($messenger_name) |
|
| 3352 | - { |
|
| 3353 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3354 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3355 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3356 | - |
|
| 3357 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3358 | - } |
|
| 3359 | - |
|
| 3360 | - |
|
| 3361 | - /** |
|
| 3362 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3363 | - * |
|
| 3364 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3365 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3366 | - * |
|
| 3367 | - * @return bool |
|
| 3368 | - */ |
|
| 3369 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3370 | - { |
|
| 3371 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3372 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3373 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3374 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3375 | - |
|
| 3376 | - //ensure is active |
|
| 3377 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3378 | - |
|
| 3379 | - //set response for load |
|
| 3380 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3381 | - $message_type_name) |
|
| 3382 | - ) { |
|
| 3383 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3384 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3385 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3386 | - } |
|
| 3387 | - } |
|
| 3388 | - |
|
| 3389 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3390 | - $message_type_to_activate); |
|
| 3391 | - } |
|
| 3392 | - |
|
| 3393 | - |
|
| 3394 | - /** |
|
| 3395 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3396 | - * |
|
| 3397 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3398 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3399 | - * |
|
| 3400 | - * @return bool |
|
| 3401 | - */ |
|
| 3402 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3403 | - { |
|
| 3404 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3405 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3406 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3407 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3408 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3409 | - |
|
| 3410 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3411 | - $message_type_to_deactivate); |
|
| 3412 | - } |
|
| 3413 | - |
|
| 3414 | - |
|
| 3415 | - /** |
|
| 3416 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3417 | - */ |
|
| 3418 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3419 | - { |
|
| 3420 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 3421 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 3422 | - } |
|
| 3423 | - |
|
| 3424 | - |
|
| 3425 | - /** |
|
| 3426 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 3427 | - * |
|
| 3428 | - * @param EE_messenger $messenger |
|
| 3429 | - * @param EE_message_type|null $message_type |
|
| 3430 | - * |
|
| 3431 | - * @return bool |
|
| 3432 | - * @throws EE_Error |
|
| 3433 | - */ |
|
| 3434 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3435 | - $messenger, |
|
| 3436 | - EE_Message_Type $message_type = null |
|
| 3437 | - ) { |
|
| 3438 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3439 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3440 | - EE_Error::add_error( |
|
| 3441 | - __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3442 | - __FILE__, |
|
| 3443 | - __FUNCTION__, |
|
| 3444 | - __LINE__ |
|
| 3445 | - ); |
|
| 3110 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3111 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3112 | + : ''; |
|
| 3113 | + } |
|
| 3114 | + |
|
| 3115 | + //we also need some hidden fields |
|
| 3116 | + $settings_template_args['hidden_fields'] = array( |
|
| 3117 | + 'messenger_settings[messenger]' => array( |
|
| 3118 | + 'type' => 'hidden', |
|
| 3119 | + 'value' => $messenger->name |
|
| 3120 | + ), |
|
| 3121 | + 'type' => array( |
|
| 3122 | + 'type' => 'hidden', |
|
| 3123 | + 'value' => 'messenger' |
|
| 3124 | + ) |
|
| 3125 | + ); |
|
| 3126 | + |
|
| 3127 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3128 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3129 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3130 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3131 | + 'type' => 'hidden', |
|
| 3132 | + 'value' => $mt |
|
| 3133 | + ); |
|
| 3134 | + } |
|
| 3135 | + } |
|
| 3136 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3137 | + $settings_template_args['hidden_fields'], |
|
| 3138 | + 'array' |
|
| 3139 | + ); |
|
| 3140 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3141 | + |
|
| 3142 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3143 | + $settings_template_args['description'] = $messenger->description; |
|
| 3144 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3145 | + |
|
| 3146 | + |
|
| 3147 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3148 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3149 | + : ' hidden'; |
|
| 3150 | + |
|
| 3151 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3152 | + ? ' hidden' |
|
| 3153 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3154 | + |
|
| 3155 | + |
|
| 3156 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3157 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3158 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3159 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3160 | + $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3161 | + true); |
|
| 3162 | + |
|
| 3163 | + return $content; |
|
| 3164 | + } |
|
| 3165 | + |
|
| 3166 | + |
|
| 3167 | + /** |
|
| 3168 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3169 | + */ |
|
| 3170 | + public function activate_messenger_toggle() |
|
| 3171 | + { |
|
| 3172 | + $success = true; |
|
| 3173 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3174 | + //let's check that we have required data |
|
| 3175 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3176 | + EE_Error::add_error( |
|
| 3177 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3178 | + __FILE__, |
|
| 3179 | + __FUNCTION__, |
|
| 3180 | + __LINE__ |
|
| 3181 | + ); |
|
| 3182 | + $success = false; |
|
| 3183 | + } |
|
| 3184 | + |
|
| 3185 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3186 | + $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3187 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3188 | + |
|
| 3189 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3190 | + |
|
| 3191 | + |
|
| 3192 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3193 | + EE_Error::add_error( |
|
| 3194 | + __( |
|
| 3195 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3196 | + 'event_espresso' |
|
| 3197 | + ), |
|
| 3198 | + __FILE__, |
|
| 3199 | + __FUNCTION__, |
|
| 3200 | + __LINE__ |
|
| 3201 | + ); |
|
| 3202 | + $success = false; |
|
| 3203 | + } |
|
| 3204 | + |
|
| 3205 | + //do check to verify we have a valid status. |
|
| 3206 | + $status = $this->_req_data['status']; |
|
| 3207 | + |
|
| 3208 | + if ($status != 'off' && $status != 'on') { |
|
| 3209 | + EE_Error::add_error( |
|
| 3210 | + sprintf( |
|
| 3211 | + __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3212 | + $this->_req_data['status'] |
|
| 3213 | + ), |
|
| 3214 | + __FILE__, |
|
| 3215 | + __FUNCTION__, |
|
| 3216 | + __LINE__ |
|
| 3217 | + ); |
|
| 3218 | + $success = false; |
|
| 3219 | + } |
|
| 3220 | + |
|
| 3221 | + if ($success) { |
|
| 3222 | + //made it here? Stop dawdling then!! |
|
| 3223 | + $success = $status == 'off' |
|
| 3224 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3225 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3226 | + } |
|
| 3227 | + |
|
| 3228 | + $this->_template_args['success'] = $success; |
|
| 3229 | + |
|
| 3230 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3231 | + $this->_return_json(); |
|
| 3232 | + |
|
| 3233 | + } |
|
| 3234 | + |
|
| 3235 | + |
|
| 3236 | + /** |
|
| 3237 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3238 | + * |
|
| 3239 | + */ |
|
| 3240 | + public function activate_mt_toggle() |
|
| 3241 | + { |
|
| 3242 | + $success = true; |
|
| 3243 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3244 | + |
|
| 3245 | + //let's make sure we have the necessary data |
|
| 3246 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3247 | + EE_Error::add_error( |
|
| 3248 | + __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3249 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3250 | + ); |
|
| 3251 | + $success = false; |
|
| 3252 | + } |
|
| 3253 | + |
|
| 3254 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3255 | + EE_Error::add_error( |
|
| 3256 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3257 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3258 | + ); |
|
| 3259 | + $success = false; |
|
| 3260 | + } |
|
| 3261 | + |
|
| 3262 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3263 | + EE_Error::add_error( |
|
| 3264 | + __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3265 | + 'event_espresso'), |
|
| 3266 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3267 | + ); |
|
| 3268 | + $success = false; |
|
| 3269 | + } |
|
| 3270 | + |
|
| 3271 | + |
|
| 3272 | + //do check to verify we have a valid status. |
|
| 3273 | + $status = $this->_req_data['status']; |
|
| 3274 | + |
|
| 3275 | + if ($status != 'activate' && $status != 'deactivate') { |
|
| 3276 | + EE_Error::add_error( |
|
| 3277 | + sprintf( |
|
| 3278 | + __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3279 | + $this->_req_data['status'] |
|
| 3280 | + ), |
|
| 3281 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3282 | + ); |
|
| 3283 | + $success = false; |
|
| 3284 | + } |
|
| 3285 | + |
|
| 3286 | + |
|
| 3287 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3288 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3289 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3290 | + |
|
| 3291 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3292 | + |
|
| 3293 | + if ($success) { |
|
| 3294 | + //made it here? um, what are you waiting for then? |
|
| 3295 | + $success = $status == 'deactivate' |
|
| 3296 | + ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3297 | + $this->_req_data['message_type']) |
|
| 3298 | + : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3299 | + $this->_req_data['message_type']); |
|
| 3300 | + } |
|
| 3301 | + |
|
| 3302 | + $this->_template_args['success'] = $success; |
|
| 3303 | + $this->_return_json(); |
|
| 3304 | + } |
|
| 3305 | + |
|
| 3306 | + |
|
| 3307 | + /** |
|
| 3308 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3309 | + * |
|
| 3310 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3311 | + * |
|
| 3312 | + * @return bool |
|
| 3313 | + */ |
|
| 3314 | + protected function _activate_messenger($messenger_name) |
|
| 3315 | + { |
|
| 3316 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3317 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3318 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3319 | + |
|
| 3320 | + //ensure is active |
|
| 3321 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3322 | + |
|
| 3323 | + //set response_data for reload |
|
| 3324 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3325 | + /** @var EE_message_type $message_type */ |
|
| 3326 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3327 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3328 | + $message_type_name) |
|
| 3329 | + && $message_type instanceof EE_message_type |
|
| 3330 | + ) { |
|
| 3331 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3332 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3333 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3334 | + } |
|
| 3335 | + } |
|
| 3336 | + } |
|
| 3337 | + |
|
| 3338 | + //add success message for activating messenger |
|
| 3339 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3340 | + |
|
| 3341 | + } |
|
| 3342 | + |
|
| 3343 | + |
|
| 3344 | + /** |
|
| 3345 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3346 | + * |
|
| 3347 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3348 | + * |
|
| 3349 | + * @return bool |
|
| 3350 | + */ |
|
| 3351 | + protected function _deactivate_messenger($messenger_name) |
|
| 3352 | + { |
|
| 3353 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3354 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3355 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3356 | + |
|
| 3357 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3358 | + } |
|
| 3359 | + |
|
| 3360 | + |
|
| 3361 | + /** |
|
| 3362 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3363 | + * |
|
| 3364 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3365 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3366 | + * |
|
| 3367 | + * @return bool |
|
| 3368 | + */ |
|
| 3369 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3370 | + { |
|
| 3371 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3372 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3373 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3374 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3375 | + |
|
| 3376 | + //ensure is active |
|
| 3377 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3378 | + |
|
| 3379 | + //set response for load |
|
| 3380 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3381 | + $message_type_name) |
|
| 3382 | + ) { |
|
| 3383 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3384 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3385 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3386 | + } |
|
| 3387 | + } |
|
| 3388 | + |
|
| 3389 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3390 | + $message_type_to_activate); |
|
| 3391 | + } |
|
| 3392 | + |
|
| 3393 | + |
|
| 3394 | + /** |
|
| 3395 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3396 | + * |
|
| 3397 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3398 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3399 | + * |
|
| 3400 | + * @return bool |
|
| 3401 | + */ |
|
| 3402 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3403 | + { |
|
| 3404 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3405 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3406 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3407 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3408 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3409 | + |
|
| 3410 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3411 | + $message_type_to_deactivate); |
|
| 3412 | + } |
|
| 3413 | + |
|
| 3414 | + |
|
| 3415 | + /** |
|
| 3416 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3417 | + */ |
|
| 3418 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3419 | + { |
|
| 3420 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 3421 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 3422 | + } |
|
| 3423 | + |
|
| 3424 | + |
|
| 3425 | + /** |
|
| 3426 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 3427 | + * |
|
| 3428 | + * @param EE_messenger $messenger |
|
| 3429 | + * @param EE_message_type|null $message_type |
|
| 3430 | + * |
|
| 3431 | + * @return bool |
|
| 3432 | + * @throws EE_Error |
|
| 3433 | + */ |
|
| 3434 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3435 | + $messenger, |
|
| 3436 | + EE_Message_Type $message_type = null |
|
| 3437 | + ) { |
|
| 3438 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3439 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3440 | + EE_Error::add_error( |
|
| 3441 | + __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3442 | + __FILE__, |
|
| 3443 | + __FUNCTION__, |
|
| 3444 | + __LINE__ |
|
| 3445 | + ); |
|
| 3446 | 3446 | |
| 3447 | - return false; |
|
| 3448 | - } |
|
| 3449 | - //activated |
|
| 3450 | - if ($this->_template_args['data']['active_mts']) { |
|
| 3451 | - EE_Error::overwrite_success(); |
|
| 3452 | - //activated a message type with the messenger |
|
| 3453 | - if ($message_type instanceof EE_message_type) { |
|
| 3454 | - EE_Error::add_success( |
|
| 3455 | - sprintf( |
|
| 3456 | - __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3457 | - ucwords($message_type->label['singular']), |
|
| 3458 | - ucwords($messenger->label['singular']) |
|
| 3459 | - ) |
|
| 3460 | - ); |
|
| 3447 | + return false; |
|
| 3448 | + } |
|
| 3449 | + //activated |
|
| 3450 | + if ($this->_template_args['data']['active_mts']) { |
|
| 3451 | + EE_Error::overwrite_success(); |
|
| 3452 | + //activated a message type with the messenger |
|
| 3453 | + if ($message_type instanceof EE_message_type) { |
|
| 3454 | + EE_Error::add_success( |
|
| 3455 | + sprintf( |
|
| 3456 | + __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3457 | + ucwords($message_type->label['singular']), |
|
| 3458 | + ucwords($messenger->label['singular']) |
|
| 3459 | + ) |
|
| 3460 | + ); |
|
| 3461 | 3461 | |
| 3462 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3463 | - if ($message_type->name == 'invoice') { |
|
| 3464 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3465 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3466 | - if ($pm instanceof EE_Payment_Method) { |
|
| 3467 | - EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3468 | - 'event_espresso')); |
|
| 3469 | - } |
|
| 3470 | - } |
|
| 3471 | - //just toggles the entire messenger |
|
| 3472 | - } else { |
|
| 3473 | - EE_Error::add_success( |
|
| 3474 | - sprintf( |
|
| 3475 | - __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3476 | - ucwords($messenger->label['singular']) |
|
| 3477 | - ) |
|
| 3478 | - ); |
|
| 3479 | - } |
|
| 3462 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3463 | + if ($message_type->name == 'invoice') { |
|
| 3464 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3465 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3466 | + if ($pm instanceof EE_Payment_Method) { |
|
| 3467 | + EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 3468 | + 'event_espresso')); |
|
| 3469 | + } |
|
| 3470 | + } |
|
| 3471 | + //just toggles the entire messenger |
|
| 3472 | + } else { |
|
| 3473 | + EE_Error::add_success( |
|
| 3474 | + sprintf( |
|
| 3475 | + __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3476 | + ucwords($messenger->label['singular']) |
|
| 3477 | + ) |
|
| 3478 | + ); |
|
| 3479 | + } |
|
| 3480 | 3480 | |
| 3481 | - return true; |
|
| 3481 | + return true; |
|
| 3482 | 3482 | |
| 3483 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3484 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3485 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 3486 | - } else { |
|
| 3487 | - if ( ! $messenger->get_default_message_types()) { |
|
| 3488 | - //messenger doesn't have any default message types so still a success. |
|
| 3489 | - EE_Error::add_success( |
|
| 3490 | - sprintf( |
|
| 3491 | - __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3492 | - ucwords($messenger->label['singular']) |
|
| 3493 | - ) |
|
| 3494 | - ); |
|
| 3483 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3484 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3485 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 3486 | + } else { |
|
| 3487 | + if ( ! $messenger->get_default_message_types()) { |
|
| 3488 | + //messenger doesn't have any default message types so still a success. |
|
| 3489 | + EE_Error::add_success( |
|
| 3490 | + sprintf( |
|
| 3491 | + __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3492 | + ucwords($messenger->label['singular']) |
|
| 3493 | + ) |
|
| 3494 | + ); |
|
| 3495 | 3495 | |
| 3496 | - return true; |
|
| 3497 | - } else { |
|
| 3498 | - EE_Error::add_error( |
|
| 3499 | - $message_type instanceof EE_message_type |
|
| 3500 | - ? sprintf( |
|
| 3501 | - __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3502 | - ucwords($message_type->label['singular']), |
|
| 3503 | - ucwords($messenger->label['singular']) |
|
| 3504 | - ) |
|
| 3505 | - : sprintf( |
|
| 3506 | - __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3507 | - ucwords($messenger->label['singular']) |
|
| 3508 | - ), |
|
| 3509 | - __FILE__, |
|
| 3510 | - __FUNCTION__, |
|
| 3511 | - __LINE__ |
|
| 3512 | - ); |
|
| 3496 | + return true; |
|
| 3497 | + } else { |
|
| 3498 | + EE_Error::add_error( |
|
| 3499 | + $message_type instanceof EE_message_type |
|
| 3500 | + ? sprintf( |
|
| 3501 | + __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3502 | + ucwords($message_type->label['singular']), |
|
| 3503 | + ucwords($messenger->label['singular']) |
|
| 3504 | + ) |
|
| 3505 | + : sprintf( |
|
| 3506 | + __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3507 | + ucwords($messenger->label['singular']) |
|
| 3508 | + ), |
|
| 3509 | + __FILE__, |
|
| 3510 | + __FUNCTION__, |
|
| 3511 | + __LINE__ |
|
| 3512 | + ); |
|
| 3513 | 3513 | |
| 3514 | - return false; |
|
| 3515 | - } |
|
| 3516 | - } |
|
| 3517 | - } |
|
| 3518 | - |
|
| 3519 | - |
|
| 3520 | - /** |
|
| 3521 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3522 | - * |
|
| 3523 | - * @param EE_messenger $messenger |
|
| 3524 | - * @param EE_message_type|null $message_type |
|
| 3525 | - * |
|
| 3526 | - * @return bool |
|
| 3527 | - */ |
|
| 3528 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3529 | - $messenger, |
|
| 3530 | - EE_message_type $message_type = null |
|
| 3531 | - ) { |
|
| 3532 | - EE_Error::overwrite_success(); |
|
| 3533 | - |
|
| 3534 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3535 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3536 | - EE_Error::add_error( |
|
| 3537 | - __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3538 | - __FILE__, |
|
| 3539 | - __FUNCTION__, |
|
| 3540 | - __LINE__ |
|
| 3541 | - ); |
|
| 3514 | + return false; |
|
| 3515 | + } |
|
| 3516 | + } |
|
| 3517 | + } |
|
| 3518 | + |
|
| 3519 | + |
|
| 3520 | + /** |
|
| 3521 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3522 | + * |
|
| 3523 | + * @param EE_messenger $messenger |
|
| 3524 | + * @param EE_message_type|null $message_type |
|
| 3525 | + * |
|
| 3526 | + * @return bool |
|
| 3527 | + */ |
|
| 3528 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3529 | + $messenger, |
|
| 3530 | + EE_message_type $message_type = null |
|
| 3531 | + ) { |
|
| 3532 | + EE_Error::overwrite_success(); |
|
| 3533 | + |
|
| 3534 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3535 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3536 | + EE_Error::add_error( |
|
| 3537 | + __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3538 | + __FILE__, |
|
| 3539 | + __FUNCTION__, |
|
| 3540 | + __LINE__ |
|
| 3541 | + ); |
|
| 3542 | 3542 | |
| 3543 | - return false; |
|
| 3544 | - } |
|
| 3545 | - |
|
| 3546 | - if ($message_type instanceof EE_message_type) { |
|
| 3547 | - $message_type_name = $message_type->name; |
|
| 3548 | - EE_Error::add_success( |
|
| 3549 | - sprintf( |
|
| 3550 | - __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3551 | - ucwords($message_type->label['singular']), |
|
| 3552 | - ucwords($messenger->label['singular']) |
|
| 3553 | - ) |
|
| 3554 | - ); |
|
| 3555 | - } else { |
|
| 3556 | - $message_type_name = ''; |
|
| 3557 | - EE_Error::add_success( |
|
| 3558 | - sprintf( |
|
| 3559 | - __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3560 | - ucwords($messenger->label['singular']) |
|
| 3561 | - ) |
|
| 3562 | - ); |
|
| 3563 | - } |
|
| 3564 | - |
|
| 3565 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3566 | - if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3567 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3568 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3569 | - if ($count_updated > 0) { |
|
| 3570 | - $msg = $message_type_name == 'invoice' |
|
| 3571 | - ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3572 | - 'event_espresso') |
|
| 3573 | - : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3574 | - 'event_espresso'); |
|
| 3575 | - EE_Error::add_attention($msg); |
|
| 3576 | - } |
|
| 3577 | - } |
|
| 3578 | - |
|
| 3579 | - return true; |
|
| 3580 | - } |
|
| 3581 | - |
|
| 3582 | - |
|
| 3583 | - /** |
|
| 3584 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3585 | - */ |
|
| 3586 | - public function update_mt_form() |
|
| 3587 | - { |
|
| 3588 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3589 | - EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3590 | - __LINE__); |
|
| 3591 | - $this->_return_json(); |
|
| 3592 | - } |
|
| 3593 | - |
|
| 3594 | - $message_types = $this->get_installed_message_types(); |
|
| 3595 | - |
|
| 3596 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3597 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3598 | - |
|
| 3599 | - $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3600 | - $this->_template_args['success'] = true; |
|
| 3601 | - $this->_template_args['content'] = $content; |
|
| 3602 | - $this->_return_json(); |
|
| 3603 | - } |
|
| 3604 | - |
|
| 3605 | - |
|
| 3606 | - /** |
|
| 3607 | - * this handles saving the settings for a messenger or message type |
|
| 3608 | - * |
|
| 3609 | - */ |
|
| 3610 | - public function save_settings() |
|
| 3611 | - { |
|
| 3612 | - if ( ! isset($this->_req_data['type'])) { |
|
| 3613 | - EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3614 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3615 | - $this->_template_args['error'] = true; |
|
| 3616 | - $this->_return_json(); |
|
| 3617 | - } |
|
| 3618 | - |
|
| 3619 | - |
|
| 3620 | - if ($this->_req_data['type'] == 'messenger') { |
|
| 3621 | - $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3622 | - $messenger = $settings['messenger']; |
|
| 3623 | - //let's setup the settings data |
|
| 3624 | - foreach ($settings as $key => $value) { |
|
| 3625 | - switch ($key) { |
|
| 3626 | - case 'messenger' : |
|
| 3627 | - unset($settings['messenger']); |
|
| 3628 | - break; |
|
| 3629 | - case 'message_types' : |
|
| 3630 | - unset($settings['message_types']); |
|
| 3631 | - break; |
|
| 3632 | - default : |
|
| 3633 | - $settings[$key] = $value; |
|
| 3634 | - break; |
|
| 3635 | - } |
|
| 3636 | - } |
|
| 3637 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3638 | - } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3639 | - $settings = $this->_req_data['message_type_settings']; |
|
| 3640 | - $messenger = $settings['messenger']; |
|
| 3641 | - $message_type = $settings['message_type']; |
|
| 3543 | + return false; |
|
| 3544 | + } |
|
| 3545 | + |
|
| 3546 | + if ($message_type instanceof EE_message_type) { |
|
| 3547 | + $message_type_name = $message_type->name; |
|
| 3548 | + EE_Error::add_success( |
|
| 3549 | + sprintf( |
|
| 3550 | + __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3551 | + ucwords($message_type->label['singular']), |
|
| 3552 | + ucwords($messenger->label['singular']) |
|
| 3553 | + ) |
|
| 3554 | + ); |
|
| 3555 | + } else { |
|
| 3556 | + $message_type_name = ''; |
|
| 3557 | + EE_Error::add_success( |
|
| 3558 | + sprintf( |
|
| 3559 | + __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3560 | + ucwords($messenger->label['singular']) |
|
| 3561 | + ) |
|
| 3562 | + ); |
|
| 3563 | + } |
|
| 3564 | + |
|
| 3565 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3566 | + if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3567 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3568 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3569 | + if ($count_updated > 0) { |
|
| 3570 | + $msg = $message_type_name == 'invoice' |
|
| 3571 | + ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3572 | + 'event_espresso') |
|
| 3573 | + : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3574 | + 'event_espresso'); |
|
| 3575 | + EE_Error::add_attention($msg); |
|
| 3576 | + } |
|
| 3577 | + } |
|
| 3578 | + |
|
| 3579 | + return true; |
|
| 3580 | + } |
|
| 3581 | + |
|
| 3582 | + |
|
| 3583 | + /** |
|
| 3584 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3585 | + */ |
|
| 3586 | + public function update_mt_form() |
|
| 3587 | + { |
|
| 3588 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3589 | + EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3590 | + __LINE__); |
|
| 3591 | + $this->_return_json(); |
|
| 3592 | + } |
|
| 3593 | + |
|
| 3594 | + $message_types = $this->get_installed_message_types(); |
|
| 3595 | + |
|
| 3596 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3597 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3598 | + |
|
| 3599 | + $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3600 | + $this->_template_args['success'] = true; |
|
| 3601 | + $this->_template_args['content'] = $content; |
|
| 3602 | + $this->_return_json(); |
|
| 3603 | + } |
|
| 3604 | + |
|
| 3605 | + |
|
| 3606 | + /** |
|
| 3607 | + * this handles saving the settings for a messenger or message type |
|
| 3608 | + * |
|
| 3609 | + */ |
|
| 3610 | + public function save_settings() |
|
| 3611 | + { |
|
| 3612 | + if ( ! isset($this->_req_data['type'])) { |
|
| 3613 | + EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3614 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3615 | + $this->_template_args['error'] = true; |
|
| 3616 | + $this->_return_json(); |
|
| 3617 | + } |
|
| 3618 | + |
|
| 3619 | + |
|
| 3620 | + if ($this->_req_data['type'] == 'messenger') { |
|
| 3621 | + $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3622 | + $messenger = $settings['messenger']; |
|
| 3623 | + //let's setup the settings data |
|
| 3624 | + foreach ($settings as $key => $value) { |
|
| 3625 | + switch ($key) { |
|
| 3626 | + case 'messenger' : |
|
| 3627 | + unset($settings['messenger']); |
|
| 3628 | + break; |
|
| 3629 | + case 'message_types' : |
|
| 3630 | + unset($settings['message_types']); |
|
| 3631 | + break; |
|
| 3632 | + default : |
|
| 3633 | + $settings[$key] = $value; |
|
| 3634 | + break; |
|
| 3635 | + } |
|
| 3636 | + } |
|
| 3637 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3638 | + } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3639 | + $settings = $this->_req_data['message_type_settings']; |
|
| 3640 | + $messenger = $settings['messenger']; |
|
| 3641 | + $message_type = $settings['message_type']; |
|
| 3642 | 3642 | |
| 3643 | - foreach ($settings as $key => $value) { |
|
| 3644 | - switch ($key) { |
|
| 3645 | - case 'messenger' : |
|
| 3646 | - unset($settings['messenger']); |
|
| 3647 | - break; |
|
| 3648 | - case 'message_type' : |
|
| 3649 | - unset($settings['message_type']); |
|
| 3650 | - break; |
|
| 3651 | - default : |
|
| 3652 | - $settings[$key] = $value; |
|
| 3653 | - break; |
|
| 3654 | - } |
|
| 3655 | - } |
|
| 3643 | + foreach ($settings as $key => $value) { |
|
| 3644 | + switch ($key) { |
|
| 3645 | + case 'messenger' : |
|
| 3646 | + unset($settings['messenger']); |
|
| 3647 | + break; |
|
| 3648 | + case 'message_type' : |
|
| 3649 | + unset($settings['message_type']); |
|
| 3650 | + break; |
|
| 3651 | + default : |
|
| 3652 | + $settings[$key] = $value; |
|
| 3653 | + break; |
|
| 3654 | + } |
|
| 3655 | + } |
|
| 3656 | 3656 | |
| 3657 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3658 | - } |
|
| 3659 | - |
|
| 3660 | - //okay we should have the data all setup. Now we just update! |
|
| 3661 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3662 | - |
|
| 3663 | - if ($success) { |
|
| 3664 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3665 | - } else { |
|
| 3666 | - EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3667 | - } |
|
| 3668 | - |
|
| 3669 | - $this->_template_args['success'] = $success; |
|
| 3670 | - $this->_return_json(); |
|
| 3671 | - } |
|
| 3672 | - |
|
| 3673 | - |
|
| 3674 | - |
|
| 3675 | - |
|
| 3676 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3677 | - |
|
| 3678 | - |
|
| 3679 | - /** |
|
| 3680 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3681 | - * However, this does not send immediately, it just queues for sending. |
|
| 3682 | - * |
|
| 3683 | - * @since 4.9.0 |
|
| 3684 | - */ |
|
| 3685 | - protected function _generate_now() |
|
| 3686 | - { |
|
| 3687 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3688 | - EED_Messages::generate_now($msg_ids); |
|
| 3689 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3690 | - } |
|
| 3691 | - |
|
| 3692 | - |
|
| 3693 | - /** |
|
| 3694 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3695 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3696 | - * |
|
| 3697 | - * @since 4.9.0 |
|
| 3698 | - * |
|
| 3699 | - */ |
|
| 3700 | - protected function _generate_and_send_now() |
|
| 3701 | - { |
|
| 3702 | - $this->_generate_now(); |
|
| 3703 | - $this->_send_now(); |
|
| 3704 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3705 | - } |
|
| 3706 | - |
|
| 3707 | - |
|
| 3708 | - /** |
|
| 3709 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3710 | - * |
|
| 3711 | - * @since 4.9.0 |
|
| 3712 | - */ |
|
| 3713 | - protected function _queue_for_resending() |
|
| 3714 | - { |
|
| 3715 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3716 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 3717 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3718 | - } |
|
| 3719 | - |
|
| 3720 | - |
|
| 3721 | - /** |
|
| 3722 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3723 | - * |
|
| 3724 | - * @since 4.9.0 |
|
| 3725 | - */ |
|
| 3726 | - protected function _send_now() |
|
| 3727 | - { |
|
| 3728 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3729 | - EED_Messages::send_now($msg_ids); |
|
| 3730 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3731 | - } |
|
| 3732 | - |
|
| 3733 | - |
|
| 3734 | - /** |
|
| 3735 | - * Deletes EE_messages for IDs in the request. |
|
| 3736 | - * |
|
| 3737 | - * @since 4.9.0 |
|
| 3738 | - */ |
|
| 3739 | - protected function _delete_ee_messages() |
|
| 3740 | - { |
|
| 3741 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3742 | - $deleted_count = 0; |
|
| 3743 | - foreach ($msg_ids as $msg_id) { |
|
| 3744 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3745 | - $deleted_count++; |
|
| 3746 | - } |
|
| 3747 | - } |
|
| 3748 | - if ($deleted_count) { |
|
| 3749 | - $this->_redirect_after_action( |
|
| 3750 | - true, |
|
| 3751 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3752 | - __('deleted', 'event_espresso') |
|
| 3753 | - ); |
|
| 3754 | - } else { |
|
| 3755 | - EE_Error::add_error( |
|
| 3756 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3757 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3758 | - ); |
|
| 3759 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3760 | - } |
|
| 3761 | - } |
|
| 3762 | - |
|
| 3763 | - |
|
| 3764 | - /** |
|
| 3765 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3766 | - * @since 4.9.0 |
|
| 3767 | - * @return array |
|
| 3768 | - */ |
|
| 3769 | - protected function _get_msg_ids_from_request() |
|
| 3770 | - { |
|
| 3771 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3772 | - return array(); |
|
| 3773 | - } |
|
| 3774 | - |
|
| 3775 | - return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3776 | - } |
|
| 3657 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3658 | + } |
|
| 3659 | + |
|
| 3660 | + //okay we should have the data all setup. Now we just update! |
|
| 3661 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3662 | + |
|
| 3663 | + if ($success) { |
|
| 3664 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3665 | + } else { |
|
| 3666 | + EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3667 | + } |
|
| 3668 | + |
|
| 3669 | + $this->_template_args['success'] = $success; |
|
| 3670 | + $this->_return_json(); |
|
| 3671 | + } |
|
| 3672 | + |
|
| 3673 | + |
|
| 3674 | + |
|
| 3675 | + |
|
| 3676 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3677 | + |
|
| 3678 | + |
|
| 3679 | + /** |
|
| 3680 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3681 | + * However, this does not send immediately, it just queues for sending. |
|
| 3682 | + * |
|
| 3683 | + * @since 4.9.0 |
|
| 3684 | + */ |
|
| 3685 | + protected function _generate_now() |
|
| 3686 | + { |
|
| 3687 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3688 | + EED_Messages::generate_now($msg_ids); |
|
| 3689 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3690 | + } |
|
| 3691 | + |
|
| 3692 | + |
|
| 3693 | + /** |
|
| 3694 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3695 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3696 | + * |
|
| 3697 | + * @since 4.9.0 |
|
| 3698 | + * |
|
| 3699 | + */ |
|
| 3700 | + protected function _generate_and_send_now() |
|
| 3701 | + { |
|
| 3702 | + $this->_generate_now(); |
|
| 3703 | + $this->_send_now(); |
|
| 3704 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3705 | + } |
|
| 3706 | + |
|
| 3707 | + |
|
| 3708 | + /** |
|
| 3709 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3710 | + * |
|
| 3711 | + * @since 4.9.0 |
|
| 3712 | + */ |
|
| 3713 | + protected function _queue_for_resending() |
|
| 3714 | + { |
|
| 3715 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3716 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 3717 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3718 | + } |
|
| 3719 | + |
|
| 3720 | + |
|
| 3721 | + /** |
|
| 3722 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3723 | + * |
|
| 3724 | + * @since 4.9.0 |
|
| 3725 | + */ |
|
| 3726 | + protected function _send_now() |
|
| 3727 | + { |
|
| 3728 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3729 | + EED_Messages::send_now($msg_ids); |
|
| 3730 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3731 | + } |
|
| 3732 | + |
|
| 3733 | + |
|
| 3734 | + /** |
|
| 3735 | + * Deletes EE_messages for IDs in the request. |
|
| 3736 | + * |
|
| 3737 | + * @since 4.9.0 |
|
| 3738 | + */ |
|
| 3739 | + protected function _delete_ee_messages() |
|
| 3740 | + { |
|
| 3741 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3742 | + $deleted_count = 0; |
|
| 3743 | + foreach ($msg_ids as $msg_id) { |
|
| 3744 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3745 | + $deleted_count++; |
|
| 3746 | + } |
|
| 3747 | + } |
|
| 3748 | + if ($deleted_count) { |
|
| 3749 | + $this->_redirect_after_action( |
|
| 3750 | + true, |
|
| 3751 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3752 | + __('deleted', 'event_espresso') |
|
| 3753 | + ); |
|
| 3754 | + } else { |
|
| 3755 | + EE_Error::add_error( |
|
| 3756 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3757 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3758 | + ); |
|
| 3759 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3760 | + } |
|
| 3761 | + } |
|
| 3762 | + |
|
| 3763 | + |
|
| 3764 | + /** |
|
| 3765 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3766 | + * @since 4.9.0 |
|
| 3767 | + * @return array |
|
| 3768 | + */ |
|
| 3769 | + protected function _get_msg_ids_from_request() |
|
| 3770 | + { |
|
| 3771 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3772 | + return array(); |
|
| 3773 | + } |
|
| 3774 | + |
|
| 3775 | + return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3776 | + } |
|
| 3777 | 3777 | |
| 3778 | 3778 | |
| 3779 | 3779 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 88 | 88 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 89 | 89 | |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 91 | 91 | |
| 92 | 92 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 93 | 93 | $this->_load_message_resource_manager(); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | array('none_selected' => __('Show All Messengers', 'event_espresso')), |
| 220 | 220 | $messenger_options |
| 221 | 221 | ); |
| 222 | - $input = new EE_Select_Input( |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | 223 | $messenger_options, |
| 224 | 224 | array( |
| 225 | 225 | 'html_name' => 'ee_messenger_filter_by', |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | array('none_selected' => __('Show All Message Types', 'event_espresso')), |
| 258 | 258 | $message_type_options |
| 259 | 259 | ); |
| 260 | - $input = new EE_Select_Input( |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | 261 | $message_type_options, |
| 262 | 262 | array( |
| 263 | 263 | 'html_name' => 'ee_message_type_filter_by', |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | array('none_selected' => __('Show all Contexts', 'event_espresso')), |
| 296 | 296 | $context_options |
| 297 | 297 | ); |
| 298 | - $input = new EE_Select_Input( |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | 299 | $context_options, |
| 300 | 300 | array( |
| 301 | 301 | 'html_name' => 'ee_context_filter_by', |
@@ -676,47 +676,47 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | public function messages_help_tab() |
| 678 | 678 | { |
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | public function messengers_help_tab() |
| 684 | 684 | { |
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | public function message_types_help_tab() |
| 690 | 690 | { |
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | public function messages_overview_help_tab() |
| 696 | 696 | { |
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | public function message_templates_help_tab() |
| 702 | 702 | { |
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | public function edit_message_template_help_tab() |
| 708 | 708 | { |
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 709 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso').'" />'; |
|
| 711 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso').'" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso').'" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso').'" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso').'" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | 720 | $args); |
| 721 | 721 | } |
| 722 | 722 | |
@@ -725,37 +725,37 @@ discard block |
||
| 725 | 725 | { |
| 726 | 726 | $this->_set_shortcodes(); |
| 727 | 727 | $args['shortcodes'] = $this->_shortcodes; |
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | 729 | $args); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | public function preview_message_help_tab() |
| 734 | 734 | { |
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | public function settings_help_tab() |
| 740 | 740 | { |
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso').'" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso').'" />'; |
|
| 745 | 745 | $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
| 746 | 746 | $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | public function load_scripts_styles() |
| 752 | 752 | { |
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | 754 | wp_enqueue_style('espresso_ee_msg'); |
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 757 | 757 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 759 | 759 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 760 | 760 | } |
| 761 | 761 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | |
| 788 | 788 | $this->_set_shortcodes(); |
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | 791 | __('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
| 792 | 792 | 'event_espresso'), |
| 793 | 793 | $this->_message_template_group->messenger_obj()->label['singular'], |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
| 797 | 797 | 'event_espresso'); |
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'), |
|
| 800 | 800 | EVENT_ESPRESSO_VERSION); |
| 801 | 801 | |
| 802 | 802 | wp_enqueue_script('ee_admin_js'); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | public function load_scripts_styles_settings() |
| 829 | 829 | { |
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(), |
|
| 831 | 831 | EVENT_ESPRESSO_VERSION); |
| 832 | 832 | wp_enqueue_style('ee-text-links'); |
| 833 | 833 | wp_enqueue_style('ee-message-settings'); |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
| 939 | 939 | $this->_template_args['per_column'] = 6; |
| 940 | 940 | $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
| 941 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 941 | + $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>'; |
|
| 942 | 942 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 943 | 943 | } |
| 944 | 944 | |
@@ -962,33 +962,33 @@ discard block |
||
| 962 | 962 | /** @type array $status_items status legend setup */ |
| 963 | 963 | $status_items = array( |
| 964 | 964 | 'sent_status' => array( |
| 965 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 965 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 966 | 966 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 967 | 967 | ), |
| 968 | 968 | 'idle_status' => array( |
| 969 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 969 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 970 | 970 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 971 | 971 | ), |
| 972 | 972 | 'failed_status' => array( |
| 973 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 973 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 974 | 974 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 975 | 975 | ), |
| 976 | 976 | 'resend_status' => array( |
| 977 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 977 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 978 | 978 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 979 | 979 | ), |
| 980 | 980 | 'incomplete_status' => array( |
| 981 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 981 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 982 | 982 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 983 | 983 | ), |
| 984 | 984 | 'retry_status' => array( |
| 985 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 985 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 986 | 986 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 987 | 987 | ) |
| 988 | 988 | ); |
| 989 | 989 | if (EEM_Message::debug()) { |
| 990 | 990 | $status_items['debug_only_status'] = array( |
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 992 | 992 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 993 | 993 | ); |
| 994 | 994 | } |
@@ -1000,10 +1000,10 @@ discard block |
||
| 1000 | 1000 | protected function _custom_mtps_preview() |
| 1001 | 1001 | { |
| 1002 | 1002 | $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
| 1003 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1004 | - 'event_espresso') . '" />'; |
|
| 1005 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso. With the Custom Message Templates feature, you are able to create custom templates and set them per event.', |
|
| 1006 | - 'event_espresso') . '</strong>'; |
|
| 1003 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1004 | + 'event_espresso').'" />'; |
|
| 1005 | + $this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso. With the Custom Message Templates feature, you are able to create custom templates and set them per event.', |
|
| 1006 | + 'event_espresso').'</strong>'; |
|
| 1007 | 1007 | $this->display_admin_caf_preview_page('custom_message_types', false); |
| 1008 | 1008 | } |
| 1009 | 1009 | |
@@ -1251,7 +1251,7 @@ discard block |
||
| 1251 | 1251 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1252 | 1252 | $continue = false; |
| 1253 | 1253 | if (isset($extra_array['shortcodes_required'])) { |
| 1254 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1254 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1255 | 1255 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1256 | 1256 | $continue = true; |
| 1257 | 1257 | } |
@@ -1261,9 +1261,9 @@ discard block |
||
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1264 | + $field_id = $reference_field.'-'.$extra_field.'-content'; |
|
| 1265 | 1265 | $template_form_fields[$field_id] = $extra_array; |
| 1266 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1266 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']'; |
|
| 1267 | 1267 | $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
| 1268 | 1268 | |
| 1269 | 1269 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
@@ -1273,7 +1273,7 @@ discard block |
||
| 1273 | 1273 | is_array($validators[$extra_field]) |
| 1274 | 1274 | && isset($validators[$extra_field]['msg']) |
| 1275 | 1275 | ) |
| 1276 | - ? 'validate-error ' . $css_class |
|
| 1276 | + ? 'validate-error '.$css_class |
|
| 1277 | 1277 | : $css_class; |
| 1278 | 1278 | |
| 1279 | 1279 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
@@ -1301,11 +1301,11 @@ discard block |
||
| 1301 | 1301 | |
| 1302 | 1302 | }/**/ |
| 1303 | 1303 | } |
| 1304 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1305 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1304 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1305 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1306 | 1306 | |
| 1307 | 1307 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1308 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1308 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1309 | 1309 | 'label' => null, |
| 1310 | 1310 | 'input' => 'hidden', |
| 1311 | 1311 | 'type' => 'int', |
@@ -1318,7 +1318,7 @@ discard block |
||
| 1318 | 1318 | ); |
| 1319 | 1319 | |
| 1320 | 1320 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1321 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1321 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1322 | 1322 | 'label' => null, |
| 1323 | 1323 | 'input' => 'hidden', |
| 1324 | 1324 | 'type' => 'string', |
@@ -1332,9 +1332,9 @@ discard block |
||
| 1332 | 1332 | } |
| 1333 | 1333 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1334 | 1334 | } else { |
| 1335 | - $field_id = $template_field . '-content'; |
|
| 1335 | + $field_id = $template_field.'-content'; |
|
| 1336 | 1336 | $template_form_fields[$field_id] = $field_setup_array; |
| 1337 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1337 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1338 | 1338 | $message_template = isset($message_templates[$context][$template_field]) |
| 1339 | 1339 | ? $message_templates[$context][$template_field] |
| 1340 | 1340 | : null; |
@@ -1355,7 +1355,7 @@ discard block |
||
| 1355 | 1355 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1356 | 1356 | && in_array($template_field, $v_fields) |
| 1357 | 1357 | && isset($validators[$template_field]['msg']) |
| 1358 | - ? 'validate-error ' . $css_class |
|
| 1358 | + ? 'validate-error '.$css_class |
|
| 1359 | 1359 | : $css_class; |
| 1360 | 1360 | |
| 1361 | 1361 | //shortcode selector |
@@ -1366,12 +1366,12 @@ discard block |
||
| 1366 | 1366 | |
| 1367 | 1367 | //k took care of content field(s) now let's take care of others. |
| 1368 | 1368 | |
| 1369 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1370 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1369 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1370 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1371 | 1371 | |
| 1372 | 1372 | //foreach template field there are actually two form fields created |
| 1373 | 1373 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1374 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1374 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1375 | 1375 | 'label' => null, |
| 1376 | 1376 | 'input' => 'hidden', |
| 1377 | 1377 | 'type' => 'int', |
@@ -1384,7 +1384,7 @@ discard block |
||
| 1384 | 1384 | ); |
| 1385 | 1385 | |
| 1386 | 1386 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1387 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1387 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1388 | 1388 | 'label' => null, |
| 1389 | 1389 | 'input' => 'hidden', |
| 1390 | 1390 | 'type' => 'string', |
@@ -1502,7 +1502,7 @@ discard block |
||
| 1502 | 1502 | 'format' => '%d', |
| 1503 | 1503 | 'db-col' => 'MTP_deleted' |
| 1504 | 1504 | ); |
| 1505 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1505 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1506 | 1506 | 'name' => 'MTP_user_id', |
| 1507 | 1507 | 'label' => __('Author', 'event_espresso'), |
| 1508 | 1508 | 'input' => 'hidden', |
@@ -1521,17 +1521,17 @@ discard block |
||
| 1521 | 1521 | 'value' => $action |
| 1522 | 1522 | ); |
| 1523 | 1523 | |
| 1524 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1524 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1525 | 1525 | 'name' => 'id', |
| 1526 | 1526 | 'input' => 'hidden', |
| 1527 | 1527 | 'type' => 'int', |
| 1528 | 1528 | 'value' => $GRP_ID |
| 1529 | 1529 | ); |
| 1530 | 1530 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1531 | - 'name' => $action . '_nonce', |
|
| 1531 | + 'name' => $action.'_nonce', |
|
| 1532 | 1532 | 'input' => 'hidden', |
| 1533 | 1533 | 'type' => 'string', |
| 1534 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1534 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1535 | 1535 | ); |
| 1536 | 1536 | |
| 1537 | 1537 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1563,7 +1563,7 @@ discard block |
||
| 1563 | 1563 | ); |
| 1564 | 1564 | |
| 1565 | 1565 | //add preview button |
| 1566 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1566 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1567 | 1567 | array( |
| 1568 | 1568 | 'message_type' => $message_template_group->message_type(), |
| 1569 | 1569 | 'messenger' => $message_template_group->messenger(), |
@@ -1573,8 +1573,8 @@ discard block |
||
| 1573 | 1573 | ), |
| 1574 | 1574 | $this->_admin_base_url |
| 1575 | 1575 | ); |
| 1576 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1577 | - 'event_espresso') . '</a>'; |
|
| 1576 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview', |
|
| 1577 | + 'event_espresso').'</a>'; |
|
| 1578 | 1578 | |
| 1579 | 1579 | |
| 1580 | 1580 | //setup context switcher |
@@ -1602,8 +1602,8 @@ discard block |
||
| 1602 | 1602 | $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
| 1603 | 1603 | |
| 1604 | 1604 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1605 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1606 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1605 | + ? EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1606 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1607 | 1607 | |
| 1608 | 1608 | //send along EE_Message_Template_Group object for further template use. |
| 1609 | 1609 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1638,7 +1638,7 @@ discard block |
||
| 1638 | 1638 | |
| 1639 | 1639 | public function _add_form_element_before() |
| 1640 | 1640 | { |
| 1641 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1641 | + return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">'; |
|
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | 1644 | public function _add_form_element_after() |
@@ -1833,14 +1833,14 @@ discard block |
||
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | //let's add a button to go back to the edit view |
| 1836 | - $query_args = array( |
|
| 1836 | + $query_args = array( |
|
| 1837 | 1837 | 'id' => $this->_req_data['GRP_ID'], |
| 1838 | 1838 | 'context' => $this->_req_data['context'], |
| 1839 | 1839 | 'action' => 'edit_message_template' |
| 1840 | 1840 | ); |
| 1841 | 1841 | $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
| 1842 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1843 | - 'event_espresso') . '</a>'; |
|
| 1842 | + $preview_button = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit', |
|
| 1843 | + 'event_espresso').'</a>'; |
|
| 1844 | 1844 | $message_types = $this->get_installed_message_types(); |
| 1845 | 1845 | $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 1846 | 1846 | $active_messenger_label = $active_messenger instanceof EE_messenger |
@@ -1854,7 +1854,7 @@ discard block |
||
| 1854 | 1854 | ); |
| 1855 | 1855 | //setup display of preview. |
| 1856 | 1856 | $this->_admin_page_title = $preview_title; |
| 1857 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1857 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 1858 | 1858 | $this->_template_args['data']['force_json'] = true; |
| 1859 | 1859 | |
| 1860 | 1860 | return ''; |
@@ -1936,7 +1936,7 @@ discard block |
||
| 1936 | 1936 | } |
| 1937 | 1937 | |
| 1938 | 1938 | //setup variation select values for the currently selected template. |
| 1939 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1939 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1940 | 1940 | $this->_message_template_group->messenger(), |
| 1941 | 1941 | $this->_message_template_group->message_type() |
| 1942 | 1942 | ); |
@@ -1950,12 +1950,12 @@ discard block |
||
| 1950 | 1950 | |
| 1951 | 1951 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 1952 | 1952 | |
| 1953 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1953 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1954 | 1954 | 'MTP_template_pack', |
| 1955 | 1955 | $tp_select_values, |
| 1956 | 1956 | $this->_message_template_group->get_template_pack_name() |
| 1957 | 1957 | ); |
| 1958 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1958 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1959 | 1959 | 'MTP_template_variation', |
| 1960 | 1960 | $variations_select_values, |
| 1961 | 1961 | $this->_message_template_group->get_template_pack_variation() |
@@ -1965,7 +1965,7 @@ discard block |
||
| 1965 | 1965 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 1966 | 1966 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 1967 | 1967 | |
| 1968 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1968 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 1969 | 1969 | |
| 1970 | 1970 | EEH_Template::display_template($template, $template_args); |
| 1971 | 1971 | } |
@@ -1994,7 +1994,7 @@ discard block |
||
| 1994 | 1994 | if ( ! empty($fields)) { |
| 1995 | 1995 | //yup there be fields |
| 1996 | 1996 | foreach ($fields as $field => $config) { |
| 1997 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 1997 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 1998 | 1998 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 1999 | 1999 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2000 | 2000 | $default = isset($config['value']) ? $config['value'] : $default; |
@@ -2009,7 +2009,7 @@ discard block |
||
| 2009 | 2009 | : $fix; |
| 2010 | 2010 | |
| 2011 | 2011 | $template_form_fields[$field_id] = array( |
| 2012 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2012 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2013 | 2013 | 'label' => $config['label'], |
| 2014 | 2014 | 'input' => $config['input'], |
| 2015 | 2015 | 'type' => $config['type'], |
@@ -2039,7 +2039,7 @@ discard block |
||
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | 2041 | //and button |
| 2042 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2042 | + $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>'; |
|
| 2043 | 2043 | $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
| 2044 | 2044 | $test_settings_html .= $this->get_action_link_or_button( |
| 2045 | 2045 | 'reset_to_default', |
@@ -2070,7 +2070,7 @@ discard block |
||
| 2070 | 2070 | 'linked_input_id' => $linked_input_id |
| 2071 | 2071 | ); |
| 2072 | 2072 | |
| 2073 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2073 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2074 | 2074 | $template_args, true); |
| 2075 | 2075 | } |
| 2076 | 2076 | |
@@ -2088,7 +2088,7 @@ discard block |
||
| 2088 | 2088 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2089 | 2089 | //now let's set the content depending on the status of the shortcodes array |
| 2090 | 2090 | if (empty($shortcodes)) { |
| 2091 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2091 | + $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2092 | 2092 | echo $content; |
| 2093 | 2093 | } else { |
| 2094 | 2094 | //$alt = 0; |
@@ -2205,7 +2205,7 @@ discard block |
||
| 2205 | 2205 | <?php |
| 2206 | 2206 | } |
| 2207 | 2207 | //setup nonce_url |
| 2208 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2208 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2209 | 2209 | ?> |
| 2210 | 2210 | <select name="context"> |
| 2211 | 2211 | <?php |
@@ -2303,7 +2303,7 @@ discard block |
||
| 2303 | 2303 | : ''; |
| 2304 | 2304 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2305 | 2305 | |
| 2306 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2306 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : ''; |
|
| 2307 | 2307 | $item_desc .= 'Message Template'; |
| 2308 | 2308 | $query_args = array(); |
| 2309 | 2309 | $edit_array = array(); |
@@ -2672,8 +2672,8 @@ discard block |
||
| 2672 | 2672 | */ |
| 2673 | 2673 | protected function _learn_more_about_message_templates_link() |
| 2674 | 2674 | { |
| 2675 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2676 | - 'event_espresso') . '</a>'; |
|
| 2675 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works', |
|
| 2676 | + 'event_espresso').'</a>'; |
|
| 2677 | 2677 | } |
| 2678 | 2678 | |
| 2679 | 2679 | |
@@ -2749,10 +2749,10 @@ discard block |
||
| 2749 | 2749 | |
| 2750 | 2750 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 2751 | 2751 | 'label' => ucwords($message_type->label['singular']), |
| 2752 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2753 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2754 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2755 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2752 | + 'class' => 'message-type-'.$a_or_i, |
|
| 2753 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 2754 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 2755 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 2756 | 2756 | 'title' => $a_or_i == 'active' |
| 2757 | 2757 | ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 2758 | 2758 | : __('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -2788,9 +2788,9 @@ discard block |
||
| 2788 | 2788 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 2789 | 2789 | |
| 2790 | 2790 | foreach ($fields as $fldname => $fldprops) { |
| 2791 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2791 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 2792 | 2792 | $template_form_field[$field_id] = array( |
| 2793 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2793 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 2794 | 2794 | 'label' => $fldprops['label'], |
| 2795 | 2795 | 'input' => $fldprops['field_type'], |
| 2796 | 2796 | 'type' => $fldprops['value_type'], |
@@ -2831,7 +2831,7 @@ discard block |
||
| 2831 | 2831 | $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
| 2832 | 2832 | |
| 2833 | 2833 | |
| 2834 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2834 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 2835 | 2835 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 2836 | 2836 | |
| 2837 | 2837 | return $content; |
@@ -2861,11 +2861,11 @@ discard block |
||
| 2861 | 2861 | $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
| 2862 | 2862 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 2863 | 2863 | : ''; |
| 2864 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2864 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 2865 | 2865 | __('%s Settings', 'event_espresso'), |
| 2866 | 2866 | $tab_array['label'] |
| 2867 | 2867 | ); |
| 2868 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2868 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 2869 | 2869 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2870 | 2870 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2871 | 2871 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2879,8 +2879,8 @@ discard block |
||
| 2879 | 2879 | // message type meta boxes |
| 2880 | 2880 | // (which is really just the inactive container for each messenger |
| 2881 | 2881 | // showing inactive message types for that messenger) |
| 2882 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2883 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2882 | + $mt_boxes[$messenger.'_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2883 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 2884 | 2884 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2885 | 2885 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2886 | 2886 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2896,14 +2896,14 @@ discard block |
||
| 2896 | 2896 | |
| 2897 | 2897 | |
| 2898 | 2898 | //register messenger metaboxes |
| 2899 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2899 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2900 | 2900 | foreach ($m_boxes as $box => $label) { |
| 2901 | 2901 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 2902 | 2902 | $msgr = str_replace('_a_box', '', $box); |
| 2903 | 2903 | add_meta_box( |
| 2904 | - 'espresso_' . $msgr . '_settings', |
|
| 2904 | + 'espresso_'.$msgr.'_settings', |
|
| 2905 | 2905 | $label, |
| 2906 | - function ($post, $metabox) { |
|
| 2906 | + function($post, $metabox) { |
|
| 2907 | 2907 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2908 | 2908 | $metabox["args"]["template_args"], true); |
| 2909 | 2909 | }, |
@@ -2915,17 +2915,17 @@ discard block |
||
| 2915 | 2915 | } |
| 2916 | 2916 | |
| 2917 | 2917 | //register message type metaboxes |
| 2918 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2918 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2919 | 2919 | foreach ($mt_boxes as $box => $label) { |
| 2920 | 2920 | $callback_args = array( |
| 2921 | 2921 | 'template_path' => $mt_template_path, |
| 2922 | 2922 | 'template_args' => $mt_template_args[$box] |
| 2923 | 2923 | ); |
| 2924 | - $mt = str_replace('_i_box', '', $box); |
|
| 2924 | + $mt = str_replace('_i_box', '', $box); |
|
| 2925 | 2925 | add_meta_box( |
| 2926 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2926 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 2927 | 2927 | $label, |
| 2928 | - function ($post, $metabox) { |
|
| 2928 | + function($post, $metabox) { |
|
| 2929 | 2929 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2930 | 2930 | $metabox["args"]["template_args"], true); |
| 2931 | 2931 | }, |
@@ -3027,7 +3027,7 @@ discard block |
||
| 3027 | 3027 | if ($form->is_valid()) { |
| 3028 | 3028 | $valid_data = $form->valid_data(); |
| 3029 | 3029 | foreach ($valid_data as $property => $value) { |
| 3030 | - $setter = 'set_' . $property; |
|
| 3030 | + $setter = 'set_'.$property; |
|
| 3031 | 3031 | if (method_exists($network_config, $setter)) { |
| 3032 | 3032 | $network_config->{$setter}($value); |
| 3033 | 3033 | } else if ( |
@@ -3056,8 +3056,8 @@ discard block |
||
| 3056 | 3056 | */ |
| 3057 | 3057 | protected function _get_mt_tabs($tab_array) |
| 3058 | 3058 | { |
| 3059 | - $tab_array = (array)$tab_array; |
|
| 3060 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3059 | + $tab_array = (array) $tab_array; |
|
| 3060 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3061 | 3061 | $tabs = ''; |
| 3062 | 3062 | |
| 3063 | 3063 | foreach ($tab_array as $tab) { |
@@ -3090,9 +3090,9 @@ discard block |
||
| 3090 | 3090 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3091 | 3091 | |
| 3092 | 3092 | foreach ($fields as $fldname => $fldprops) { |
| 3093 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3093 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3094 | 3094 | $template_form_field[$field_id] = array( |
| 3095 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3095 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3096 | 3096 | 'label' => $fldprops['label'], |
| 3097 | 3097 | 'input' => $fldprops['field_type'], |
| 3098 | 3098 | 'type' => $fldprops['value_type'], |
@@ -3127,7 +3127,7 @@ discard block |
||
| 3127 | 3127 | //make sure any active message types that are existing are included in the hidden fields |
| 3128 | 3128 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3129 | 3129 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3130 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3130 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3131 | 3131 | 'type' => 'hidden', |
| 3132 | 3132 | 'value' => $mt |
| 3133 | 3133 | ); |
@@ -3137,7 +3137,7 @@ discard block |
||
| 3137 | 3137 | $settings_template_args['hidden_fields'], |
| 3138 | 3138 | 'array' |
| 3139 | 3139 | ); |
| 3140 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3140 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3141 | 3141 | |
| 3142 | 3142 | $settings_template_args['messenger'] = $messenger->name; |
| 3143 | 3143 | $settings_template_args['description'] = $messenger->description; |
@@ -3154,9 +3154,9 @@ discard block |
||
| 3154 | 3154 | |
| 3155 | 3155 | |
| 3156 | 3156 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3157 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3157 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3158 | 3158 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3159 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3159 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3160 | 3160 | $content = EEH_Template::display_template($template, $settings_template_args, |
| 3161 | 3161 | true); |
| 3162 | 3162 | |
@@ -3184,7 +3184,7 @@ discard block |
||
| 3184 | 3184 | |
| 3185 | 3185 | //do a nonce check here since we're not arriving via a normal route |
| 3186 | 3186 | $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
| 3187 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3187 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3188 | 3188 | |
| 3189 | 3189 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3190 | 3190 | |
@@ -3286,7 +3286,7 @@ discard block |
||
| 3286 | 3286 | |
| 3287 | 3287 | //do a nonce check here since we're not arriving via a normal route |
| 3288 | 3288 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3289 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3289 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3290 | 3290 | |
| 3291 | 3291 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3292 | 3292 | |
@@ -1421,7 +1421,6 @@ discard block |
||
| 1421 | 1421 | * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
| 1422 | 1422 | * and sets it as the featured image on the CPT event |
| 1423 | 1423 | * |
| 1424 | - * @param type $old_event |
|
| 1425 | 1424 | * @param type $new_cpt_id |
| 1426 | 1425 | * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
| 1427 | 1426 | * @return boolean whether or not we had to do the big job of creating an image attachment |
@@ -1483,7 +1482,7 @@ discard block |
||
| 1483 | 1482 | * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
| 1484 | 1483 | * thumbnails) |
| 1485 | 1484 | * |
| 1486 | - * @param type $guid |
|
| 1485 | + * @param string $guid |
|
| 1487 | 1486 | * @param EE_Data_Migration_Script_Stage $migration_stage |
| 1488 | 1487 | * @return int |
| 1489 | 1488 | */ |
@@ -1571,7 +1570,7 @@ discard block |
||
| 1571 | 1570 | * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
| 1572 | 1571 | * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
| 1573 | 1572 | * |
| 1574 | - * @param EE_Data_Migration_Script_base $stage |
|
| 1573 | + * @param EE_Data_Migration_Script_Stage $stage |
|
| 1575 | 1574 | * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
| 1576 | 1575 | * UTC time for |
| 1577 | 1576 | * @param string $DATETIME_string |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
| 13 | 13 | $class_to_filepath = array(); |
| 14 | 14 | if ( ! empty($stages)) { |
| 15 | - foreach ($stages as $filepath) { |
|
| 16 | - $matches = array(); |
|
| 17 | - preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | - $class_to_filepath[$matches[1]] = $filepath; |
|
| 19 | - } |
|
| 15 | + foreach ($stages as $filepath) { |
|
| 16 | + $matches = array(); |
|
| 17 | + preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 18 | + $class_to_filepath[$matches[1]] = $filepath; |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | //give addons a chance to autoload their stages too |
| 22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath); |
@@ -44,98 +44,98 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | - * |
|
| 50 | - * @param TableManager $table_manager |
|
| 51 | - * @param TableAnalysis $table_analysis |
|
| 52 | - */ |
|
| 53 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | - { |
|
| 55 | - $this->_pretty_name = __("Data Migration to Event Espresso 4.1.0P", "event_espresso"); |
|
| 56 | - $this->_priority = 10; |
|
| 57 | - $this->_migration_stages = array( |
|
| 58 | - new EE_DMS_4_1_0_org_options(), |
|
| 59 | - new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | - new EE_DMS_4_1_0_gateways(), |
|
| 61 | - new EE_DMS_4_1_0_events(), |
|
| 62 | - new EE_DMS_4_1_0_prices(), |
|
| 63 | - new EE_DMS_4_1_0_category_details(), |
|
| 64 | - new EE_DMS_4_1_0_event_category(), |
|
| 65 | - new EE_DMS_4_1_0_venues(), |
|
| 66 | - new EE_DMS_4_1_0_event_venue(), |
|
| 67 | - new EE_DMS_4_1_0_question_groups(), |
|
| 68 | - new EE_DMS_4_1_0_questions(), |
|
| 69 | - new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | - new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | - new EE_DMS_4_1_0_attendees(), |
|
| 72 | - new EE_DMS_4_1_0_line_items(), |
|
| 73 | - new EE_DMS_4_1_0_answers(), |
|
| 74 | - new EE_DMS_4_1_0_checkins(), |
|
| 75 | - ); |
|
| 76 | - parent::__construct($table_manager, $table_analysis); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | - * |
|
| 84 | - * @global wpdb $wpdb |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - private function _checkin_table_exists() |
|
| 88 | - { |
|
| 89 | - global $wpdb; |
|
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | - if ($results) { |
|
| 92 | - return true; |
|
| 93 | - } else { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - public function can_migrate_from_version($version_array) |
|
| 101 | - { |
|
| 102 | - $version_string = $version_array['Core']; |
|
| 103 | - if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 47 | + /** |
|
| 48 | + * EE_DMS_Core_4_1_0 constructor. |
|
| 49 | + * |
|
| 50 | + * @param TableManager $table_manager |
|
| 51 | + * @param TableAnalysis $table_analysis |
|
| 52 | + */ |
|
| 53 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 54 | + { |
|
| 55 | + $this->_pretty_name = __("Data Migration to Event Espresso 4.1.0P", "event_espresso"); |
|
| 56 | + $this->_priority = 10; |
|
| 57 | + $this->_migration_stages = array( |
|
| 58 | + new EE_DMS_4_1_0_org_options(), |
|
| 59 | + new EE_DMS_4_1_0_shortcodes(), |
|
| 60 | + new EE_DMS_4_1_0_gateways(), |
|
| 61 | + new EE_DMS_4_1_0_events(), |
|
| 62 | + new EE_DMS_4_1_0_prices(), |
|
| 63 | + new EE_DMS_4_1_0_category_details(), |
|
| 64 | + new EE_DMS_4_1_0_event_category(), |
|
| 65 | + new EE_DMS_4_1_0_venues(), |
|
| 66 | + new EE_DMS_4_1_0_event_venue(), |
|
| 67 | + new EE_DMS_4_1_0_question_groups(), |
|
| 68 | + new EE_DMS_4_1_0_questions(), |
|
| 69 | + new EE_DMS_4_1_0_question_group_question(), |
|
| 70 | + new EE_DMS_4_1_0_event_question_group(), |
|
| 71 | + new EE_DMS_4_1_0_attendees(), |
|
| 72 | + new EE_DMS_4_1_0_line_items(), |
|
| 73 | + new EE_DMS_4_1_0_answers(), |
|
| 74 | + new EE_DMS_4_1_0_checkins(), |
|
| 75 | + ); |
|
| 76 | + parent::__construct($table_manager, $table_analysis); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
| 83 | + * |
|
| 84 | + * @global wpdb $wpdb |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + private function _checkin_table_exists() |
|
| 88 | + { |
|
| 89 | + global $wpdb; |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 91 | + if ($results) { |
|
| 92 | + return true; |
|
| 93 | + } else { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + public function can_migrate_from_version($version_array) |
|
| 101 | + { |
|
| 102 | + $version_string = $version_array['Core']; |
|
| 103 | + if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
| 104 | 104 | // echo "$version_string can be migrated fro"; |
| 105 | - return true; |
|
| 106 | - } elseif ( ! $version_string) { |
|
| 105 | + return true; |
|
| 106 | + } elseif ( ! $version_string) { |
|
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | - //no version string provided... this must be pre 4.1 |
|
| 109 | - //because since 4.1 we're |
|
| 110 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | - } else { |
|
| 108 | + //no version string provided... this must be pre 4.1 |
|
| 109 | + //because since 4.1 we're |
|
| 110 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | + } else { |
|
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - } |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | - public function pretty_name() |
|
| 120 | - { |
|
| 121 | - return __("Core Data Migration to version 4.1.0", "event_espresso"); |
|
| 122 | - } |
|
| 119 | + public function pretty_name() |
|
| 120 | + { |
|
| 121 | + return __("Core Data Migration to version 4.1.0", "event_espresso"); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | |
| 126 | - public function schema_changes_before_migration() |
|
| 127 | - { |
|
| 128 | - //relies on 4.1's EEH_Activation::create_table |
|
| 129 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 130 | - $table_name = 'esp_answer'; |
|
| 131 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 126 | + public function schema_changes_before_migration() |
|
| 127 | + { |
|
| 128 | + //relies on 4.1's EEH_Activation::create_table |
|
| 129 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 130 | + $table_name = 'esp_answer'; |
|
| 131 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 132 | 132 | REG_ID INT UNSIGNED NOT NULL, |
| 133 | 133 | QST_ID INT UNSIGNED NOT NULL, |
| 134 | 134 | ANS_value TEXT NOT NULL, |
| 135 | 135 | PRIMARY KEY (ANS_ID)"; |
| 136 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 137 | - $table_name = 'esp_attendee_meta'; |
|
| 138 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 136 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 137 | + $table_name = 'esp_attendee_meta'; |
|
| 138 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 139 | 139 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 140 | 140 | ATT_fname VARCHAR(45) NOT NULL, |
| 141 | 141 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | KEY ATT_fname (ATT_fname), |
| 152 | 152 | KEY ATT_lname (ATT_lname), |
| 153 | 153 | KEY ATT_email (ATT_email)"; |
| 154 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 155 | - $table_name = 'esp_country'; |
|
| 156 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
| 154 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 155 | + $table_name = 'esp_country'; |
|
| 156 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
| 157 | 157 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
| 158 | 158 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
| 159 | 159 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | CNT_is_EU TINYINT(1) DEFAULT '0', |
| 170 | 170 | CNT_active TINYINT(1) DEFAULT '0', |
| 171 | 171 | PRIMARY KEY (CNT_ISO)"; |
| 172 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 173 | - $table_name = 'esp_datetime'; |
|
| 174 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 172 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 173 | + $table_name = 'esp_datetime'; |
|
| 174 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 175 | 175 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 176 | 176 | DTT_EVT_start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 177 | 177 | DTT_EVT_end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | PRIMARY KEY (DTT_ID), |
| 185 | 185 | KEY EVT_ID (EVT_ID), |
| 186 | 186 | KEY DTT_is_primary (DTT_is_primary)"; |
| 187 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 188 | - $table_name = 'esp_event_meta'; |
|
| 189 | - $sql = " |
|
| 187 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 188 | + $table_name = 'esp_event_meta'; |
|
| 189 | + $sql = " |
|
| 190 | 190 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
| 191 | 191 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 192 | 192 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -201,31 +201,31 @@ discard block |
||
| 201 | 201 | EVT_external_URL VARCHAR(200) NULL, |
| 202 | 202 | EVT_donations TINYINT(1) NULL, |
| 203 | 203 | PRIMARY KEY (EVTM_ID)"; |
| 204 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | - $table_name = 'esp_event_question_group'; |
|
| 206 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 204 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 205 | + $table_name = 'esp_event_question_group'; |
|
| 206 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 207 | 207 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 208 | 208 | QSG_ID INT UNSIGNED NOT NULL, |
| 209 | 209 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 210 | 210 | PRIMARY KEY (EQG_ID)"; |
| 211 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | - $table_name = 'esp_event_venue'; |
|
| 213 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 211 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 212 | + $table_name = 'esp_event_venue'; |
|
| 213 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 214 | 214 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 215 | 215 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
| 216 | 216 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 217 | 217 | PRIMARY KEY (EVV_ID)"; |
| 218 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 219 | - $table_name = 'esp_extra_meta'; |
|
| 220 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 218 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 219 | + $table_name = 'esp_extra_meta'; |
|
| 220 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 221 | 221 | OBJ_ID INT(11) DEFAULT NULL, |
| 222 | 222 | EXM_type VARCHAR(45) DEFAULT NULL, |
| 223 | 223 | EXM_key VARCHAR(45) DEFAULT NULL, |
| 224 | 224 | EXM_value TEXT, |
| 225 | 225 | PRIMARY KEY (EXM_ID)"; |
| 226 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 227 | - $table_name = 'esp_line_item'; |
|
| 228 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 226 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 227 | + $table_name = 'esp_line_item'; |
|
| 228 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 229 | 229 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
| 230 | 230 | TXN_ID INT(11) DEFAULT NULL, |
| 231 | 231 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -241,18 +241,18 @@ discard block |
||
| 241 | 241 | OBJ_ID INT(11) DEFAULT NULL, |
| 242 | 242 | OBJ_type VARCHAR(45)DEFAULT NULL, |
| 243 | 243 | PRIMARY KEY (LIN_ID)"; |
| 244 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 245 | - $table_name = 'esp_message_template'; |
|
| 246 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 244 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 245 | + $table_name = 'esp_message_template'; |
|
| 246 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 247 | 247 | GRP_ID INT(10) UNSIGNED NOT NULL, |
| 248 | 248 | MTP_context VARCHAR(50) NOT NULL, |
| 249 | 249 | MTP_template_field VARCHAR(30) NOT NULL, |
| 250 | 250 | MTP_content TEXT NOT NULL, |
| 251 | 251 | PRIMARY KEY (MTP_ID), |
| 252 | 252 | KEY GRP_ID (GRP_ID)"; |
| 253 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 254 | - $table_name = 'esp_message_template_group'; |
|
| 255 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 253 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 254 | + $table_name = 'esp_message_template_group'; |
|
| 255 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 256 | 256 | EVT_ID BIGINT(20) UNSIGNED DEFAULT NULL, |
| 257 | 257 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
| 258 | 258 | MTP_messenger VARCHAR(30) NOT NULL, |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | PRIMARY KEY (GRP_ID), |
| 265 | 265 | KEY EVT_ID (EVT_ID), |
| 266 | 266 | KEY MTP_user_id (MTP_user_id)"; |
| 267 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 268 | - $table_name = 'esp_payment'; |
|
| 269 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 267 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 268 | + $table_name = 'esp_payment'; |
|
| 269 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 270 | 270 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
| 271 | 271 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
| 272 | 272 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | PRIMARY KEY (PAY_ID), |
| 283 | 283 | KEY TXN_ID (TXN_ID), |
| 284 | 284 | KEY PAY_timestamp (PAY_timestamp)"; |
| 285 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 286 | - $table_name = "esp_ticket"; |
|
| 287 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 285 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 286 | + $table_name = "esp_ticket"; |
|
| 287 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 288 | 288 | TTM_ID INT(10) UNSIGNED NOT NULL, |
| 289 | 289 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
| 290 | 290 | TKT_description TEXT NOT NULL, |
@@ -303,28 +303,28 @@ discard block |
||
| 303 | 303 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
| 304 | 304 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
| 305 | 305 | PRIMARY KEY (TKT_ID)"; |
| 306 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 307 | - $table_name = "esp_ticket_price"; |
|
| 308 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 306 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 307 | + $table_name = "esp_ticket_price"; |
|
| 308 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 309 | 309 | TKT_ID INT(10) UNSIGNED NOT NULL, |
| 310 | 310 | PRC_ID INT(10) UNSIGNED NOT NULL, |
| 311 | 311 | PRIMARY KEY (TKP_ID)"; |
| 312 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 313 | - $table_name = "esp_datetime_ticket"; |
|
| 314 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 312 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 313 | + $table_name = "esp_datetime_ticket"; |
|
| 314 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 315 | 315 | DTT_ID INT(10) UNSIGNED NOT NULL, |
| 316 | 316 | TKT_ID INT(10) UNSIGNED NOT NULL, |
| 317 | 317 | PRIMARY KEY (DTK_ID)"; |
| 318 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | - $table_name = "esp_ticket_template"; |
|
| 320 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 318 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 319 | + $table_name = "esp_ticket_template"; |
|
| 320 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 321 | 321 | TTM_name VARCHAR(45) NOT NULL, |
| 322 | 322 | TTM_description TEXT, |
| 323 | 323 | TTM_file VARCHAR(45), |
| 324 | 324 | PRIMARY KEY (TTM_ID)"; |
| 325 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 326 | - $table_name = "esp_price"; |
|
| 327 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 325 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 326 | + $table_name = "esp_price"; |
|
| 327 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 328 | 328 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
| 329 | 329 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
| 330 | 330 | PRC_name VARCHAR(245) NOT NULL, |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', |
| 336 | 336 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
| 337 | 337 | PRIMARY KEY (PRC_ID)"; |
| 338 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 339 | - $table_name = "esp_price_type"; |
|
| 340 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 338 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 339 | + $table_name = "esp_price_type"; |
|
| 340 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 341 | 341 | PRT_name VARCHAR(45) NOT NULL, |
| 342 | 342 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
| 343 | 343 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
| 346 | 346 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 347 | 347 | PRIMARY KEY (PRT_ID)"; |
| 348 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 349 | - $table_name = 'esp_question'; |
|
| 350 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 348 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 349 | + $table_name = 'esp_question'; |
|
| 350 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 351 | 351 | QST_display_text TEXT NOT NULL, |
| 352 | 352 | QST_admin_label VARCHAR(255) NOT NULL, |
| 353 | 353 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -359,10 +359,10 @@ discard block |
||
| 359 | 359 | QST_wp_user BIGINT UNSIGNED NULL, |
| 360 | 360 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
| 361 | 361 | PRIMARY KEY (QST_ID)'; |
| 362 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 363 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 364 | - $table_name = 'esp_question_group'; |
|
| 365 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 362 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 363 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 364 | + $table_name = 'esp_question_group'; |
|
| 365 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 366 | 366 | QSG_name VARCHAR(255) NOT NULL, |
| 367 | 367 | QSG_identifier VARCHAR(100) NOT NULL, |
| 368 | 368 | QSG_desc TEXT NULL, |
@@ -373,23 +373,23 @@ discard block |
||
| 373 | 373 | QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 374 | 374 | PRIMARY KEY (QSG_ID), |
| 375 | 375 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
| 376 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 377 | - $table_name = 'esp_question_group_question'; |
|
| 378 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 376 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 377 | + $table_name = 'esp_question_group_question'; |
|
| 378 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 379 | 379 | QSG_ID INT UNSIGNED NOT NULL, |
| 380 | 380 | QST_ID INT UNSIGNED NOT NULL, |
| 381 | 381 | PRIMARY KEY (QGQ_ID) "; |
| 382 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 383 | - $table_name = 'esp_question_option'; |
|
| 384 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 382 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 383 | + $table_name = 'esp_question_option'; |
|
| 384 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 385 | 385 | QSO_value VARCHAR(255) NOT NULL, |
| 386 | 386 | QSO_desc TEXT NOT NULL, |
| 387 | 387 | QST_ID INT UNSIGNED NOT NULL, |
| 388 | 388 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 389 | 389 | PRIMARY KEY (QSO_ID)"; |
| 390 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 391 | - $table_name = 'esp_registration'; |
|
| 392 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 390 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 391 | + $table_name = 'esp_registration'; |
|
| 392 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 393 | 393 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 394 | 394 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 395 | 395 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -412,25 +412,25 @@ discard block |
||
| 412 | 412 | KEY STS_ID (STS_ID), |
| 413 | 413 | KEY REG_url_link (REG_url_link), |
| 414 | 414 | KEY REG_code (REG_code)"; |
| 415 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 416 | - $table_name = 'esp_checkin'; |
|
| 417 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 415 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 416 | + $table_name = 'esp_checkin'; |
|
| 417 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 418 | 418 | REG_ID INT(10) UNSIGNED NOT NULL, |
| 419 | 419 | DTT_ID INT(10) UNSIGNED NOT NULL, |
| 420 | 420 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
| 421 | 421 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 422 | 422 | PRIMARY KEY (CHK_ID)"; |
| 423 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 424 | - $table_name = 'esp_state'; |
|
| 425 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 423 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 424 | + $table_name = 'esp_state'; |
|
| 425 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 426 | 426 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
| 427 | 427 | STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL, |
| 428 | 428 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
| 429 | 429 | STA_active TINYINT(1) DEFAULT '1', |
| 430 | 430 | PRIMARY KEY (STA_ID)"; |
| 431 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 432 | - $table_name = 'esp_status'; |
|
| 433 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
| 431 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 432 | + $table_name = 'esp_status'; |
|
| 433 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
| 434 | 434 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
| 435 | 435 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
| 436 | 436 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -438,9 +438,9 @@ discard block |
||
| 438 | 438 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
| 439 | 439 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
| 440 | 440 | KEY STS_type (STS_type)"; |
| 441 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 442 | - $table_name = 'esp_transaction'; |
|
| 443 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 441 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 442 | + $table_name = 'esp_transaction'; |
|
| 443 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 444 | 444 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 445 | 445 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
| 446 | 446 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -450,9 +450,9 @@ discard block |
||
| 450 | 450 | PRIMARY KEY (TXN_ID), |
| 451 | 451 | KEY TXN_timestamp (TXN_timestamp), |
| 452 | 452 | KEY STS_ID (STS_ID)"; |
| 453 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 454 | - $table_name = 'esp_venue_meta'; |
|
| 455 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 453 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 454 | + $table_name = 'esp_venue_meta'; |
|
| 455 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 456 | 456 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
| 457 | 457 | VNU_address VARCHAR(255) DEFAULT NULL, |
| 458 | 458 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -470,52 +470,52 @@ discard block |
||
| 470 | 470 | PRIMARY KEY (VNUM_ID), |
| 471 | 471 | KEY STA_ID (STA_ID), |
| 472 | 472 | KEY CNT_ISO (CNT_ISO)"; |
| 473 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 474 | - //setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
| 475 | - //(because many need to convert old string states to foreign keys into the states table) |
|
| 476 | - $this->insert_default_states(); |
|
| 477 | - $this->insert_default_countries(); |
|
| 478 | - //setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
| 479 | - $this->insert_default_price_types(); |
|
| 480 | - $this->insert_default_prices(); |
|
| 481 | - $this->insert_default_tickets(); |
|
| 482 | - //setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 483 | - EE_Config::instance()->update_espresso_config(false, true); |
|
| 484 | - return true; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 491 | - * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 492 | - * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 493 | - * |
|
| 494 | - * @return boolean |
|
| 495 | - */ |
|
| 496 | - public function schema_changes_after_migration() |
|
| 497 | - { |
|
| 498 | - return true; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * insert_default_states |
|
| 505 | - * |
|
| 506 | - * @access public |
|
| 507 | - * @static |
|
| 508 | - * @return void |
|
| 509 | - */ |
|
| 510 | - public function insert_default_states() |
|
| 511 | - { |
|
| 512 | - global $wpdb; |
|
| 513 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 514 | - if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 515 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 516 | - $states = $wpdb->get_var($SQL); |
|
| 517 | - if ( ! $states) { |
|
| 518 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 473 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 474 | + //setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
| 475 | + //(because many need to convert old string states to foreign keys into the states table) |
|
| 476 | + $this->insert_default_states(); |
|
| 477 | + $this->insert_default_countries(); |
|
| 478 | + //setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
| 479 | + $this->insert_default_price_types(); |
|
| 480 | + $this->insert_default_prices(); |
|
| 481 | + $this->insert_default_tickets(); |
|
| 482 | + //setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
| 483 | + EE_Config::instance()->update_espresso_config(false, true); |
|
| 484 | + return true; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
| 491 | + * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
| 492 | + * leave them for now. Mayeb remove them in 4.5 or something. |
|
| 493 | + * |
|
| 494 | + * @return boolean |
|
| 495 | + */ |
|
| 496 | + public function schema_changes_after_migration() |
|
| 497 | + { |
|
| 498 | + return true; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * insert_default_states |
|
| 505 | + * |
|
| 506 | + * @access public |
|
| 507 | + * @static |
|
| 508 | + * @return void |
|
| 509 | + */ |
|
| 510 | + public function insert_default_states() |
|
| 511 | + { |
|
| 512 | + global $wpdb; |
|
| 513 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 514 | + if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
| 515 | + $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 516 | + $states = $wpdb->get_var($SQL); |
|
| 517 | + if ( ! $states) { |
|
| 518 | + $SQL = "INSERT INTO " . $state_table . " |
|
| 519 | 519 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 520 | 520 | (1, 'US', 'AK', 'Alaska', 1), |
| 521 | 521 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -586,29 +586,29 @@ discard block |
||
| 586 | 586 | (67, 'CA', 'PE', 'Prince Edward Island', 1), |
| 587 | 587 | (68, 'CA', 'QC', 'Quebec', 1), |
| 588 | 588 | (69, 'CA', 'SK', 'Saskatchewan', 1);"; |
| 589 | - $wpdb->query($SQL); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * insert_default_countries |
|
| 598 | - * |
|
| 599 | - * @access public |
|
| 600 | - * @static |
|
| 601 | - * @return void |
|
| 602 | - */ |
|
| 603 | - public function insert_default_countries() |
|
| 604 | - { |
|
| 605 | - global $wpdb; |
|
| 606 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 607 | - if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 608 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 609 | - $countries = $wpdb->get_var($SQL); |
|
| 610 | - if ( ! $countries) { |
|
| 611 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 589 | + $wpdb->query($SQL); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * insert_default_countries |
|
| 598 | + * |
|
| 599 | + * @access public |
|
| 600 | + * @static |
|
| 601 | + * @return void |
|
| 602 | + */ |
|
| 603 | + public function insert_default_countries() |
|
| 604 | + { |
|
| 605 | + global $wpdb; |
|
| 606 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 607 | + if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
| 608 | + $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 609 | + $countries = $wpdb->get_var($SQL); |
|
| 610 | + if ( ! $countries) { |
|
| 611 | + $SQL = "INSERT INTO " . $country_table . " |
|
| 612 | 612 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 613 | 613 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 614 | 614 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -836,924 +836,924 @@ discard block |
||
| 836 | 836 | ('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0), |
| 837 | 837 | ('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0), |
| 838 | 838 | ('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);"; |
| 839 | - $wpdb->query($SQL); |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * insert_default_price_types |
|
| 848 | - * |
|
| 849 | - * @access public |
|
| 850 | - * @static |
|
| 851 | - * @return void |
|
| 852 | - */ |
|
| 853 | - public function insert_default_price_types() |
|
| 854 | - { |
|
| 855 | - global $wpdb; |
|
| 856 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 857 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 858 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 859 | - $price_types_exist = $wpdb->get_var($SQL); |
|
| 860 | - if ( ! $price_types_exist) { |
|
| 861 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 839 | + $wpdb->query($SQL); |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * insert_default_price_types |
|
| 848 | + * |
|
| 849 | + * @access public |
|
| 850 | + * @static |
|
| 851 | + * @return void |
|
| 852 | + */ |
|
| 853 | + public function insert_default_price_types() |
|
| 854 | + { |
|
| 855 | + global $wpdb; |
|
| 856 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 857 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 858 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 859 | + $price_types_exist = $wpdb->get_var($SQL); |
|
| 860 | + if ( ! $price_types_exist) { |
|
| 861 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
| 862 | 862 | (1, '" . __('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
| 863 | 863 | (2, '" . __('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
| 864 | 864 | (3, '" . __('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
| 865 | 865 | (4, '" . __('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
| 866 | 866 | (5, '" . __('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
| 867 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 868 | - $wpdb->query($SQL); |
|
| 869 | - } |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * insert_default_prices. We assume we're upgrading to regular here. |
|
| 877 | - * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
| 878 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 879 | - * EE_BRewing_regular |
|
| 880 | - * |
|
| 881 | - * @access public |
|
| 882 | - * @static |
|
| 883 | - * @return void |
|
| 884 | - */ |
|
| 885 | - public function insert_default_prices() |
|
| 886 | - { |
|
| 887 | - global $wpdb; |
|
| 888 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 889 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 890 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 891 | - $prices_exist = $wpdb->get_var($SQL); |
|
| 892 | - if ( ! $prices_exist) { |
|
| 893 | - $SQL = "INSERT INTO $price_table |
|
| 867 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
| 868 | + $wpdb->query($SQL); |
|
| 869 | + } |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * insert_default_prices. We assume we're upgrading to regular here. |
|
| 877 | + * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
| 878 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
| 879 | + * EE_BRewing_regular |
|
| 880 | + * |
|
| 881 | + * @access public |
|
| 882 | + * @static |
|
| 883 | + * @return void |
|
| 884 | + */ |
|
| 885 | + public function insert_default_prices() |
|
| 886 | + { |
|
| 887 | + global $wpdb; |
|
| 888 | + $price_table = $wpdb->prefix . "esp_price"; |
|
| 889 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
| 890 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 891 | + $prices_exist = $wpdb->get_var($SQL); |
|
| 892 | + if ( ! $prices_exist) { |
|
| 893 | + $SQL = "INSERT INTO $price_table |
|
| 894 | 894 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
| 895 | 895 | (1, 1, '0.00', 'Free Admission', '', 1, NULL, 0, 0, 0);"; |
| 896 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 897 | - $wpdb->query($SQL); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * insert DEFAULT ticket |
|
| 906 | - * |
|
| 907 | - * @access public |
|
| 908 | - * @static |
|
| 909 | - * @return void |
|
| 910 | - */ |
|
| 911 | - public function insert_default_tickets() |
|
| 912 | - { |
|
| 913 | - global $wpdb; |
|
| 914 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 915 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 916 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 917 | - $tickets_exist = $wpdb->get_var($SQL); |
|
| 918 | - if ( ! $tickets_exist) { |
|
| 919 | - $SQL = "INSERT INTO $ticket_table |
|
| 896 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
| 897 | + $wpdb->query($SQL); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * insert DEFAULT ticket |
|
| 906 | + * |
|
| 907 | + * @access public |
|
| 908 | + * @static |
|
| 909 | + * @return void |
|
| 910 | + */ |
|
| 911 | + public function insert_default_tickets() |
|
| 912 | + { |
|
| 913 | + global $wpdb; |
|
| 914 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 915 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
| 916 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 917 | + $tickets_exist = $wpdb->get_var($SQL); |
|
| 918 | + if ( ! $tickets_exist) { |
|
| 919 | + $SQL = "INSERT INTO $ticket_table |
|
| 920 | 920 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
| 921 | 921 | ( 1, 0, '" |
| 922 | - . __("Free Ticket", "event_espresso") |
|
| 923 | - . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 924 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 925 | - $wpdb->query($SQL); |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 929 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 930 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 931 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 932 | - if ( ! $ticket_prc_exist) { |
|
| 933 | - $SQL = "INSERT INTO $ticket_price_table |
|
| 922 | + . __("Free Ticket", "event_espresso") |
|
| 923 | + . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
| 924 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
| 925 | + $wpdb->query($SQL); |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 929 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
| 930 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 931 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
| 932 | + if ( ! $ticket_prc_exist) { |
|
| 933 | + $SQL = "INSERT INTO $ticket_price_table |
|
| 934 | 934 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
| 935 | 935 | ( 1, 1, 1 ) |
| 936 | 936 | "; |
| 937 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 938 | - $wpdb->query($SQL); |
|
| 939 | - } |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 947 | - * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 948 | - * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 949 | - * |
|
| 950 | - * @global type $wpdb |
|
| 951 | - * @param string $country_name |
|
| 952 | - * @return array where keys are columns, values are column values |
|
| 953 | - */ |
|
| 954 | - public function get_or_create_country($country_name) |
|
| 955 | - { |
|
| 956 | - if ( ! $country_name) { |
|
| 957 | - throw new EE_Error(__("Could not get a country because country name is blank", "event_espresso")); |
|
| 958 | - } |
|
| 959 | - global $wpdb; |
|
| 960 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 961 | - if (is_int($country_name)) { |
|
| 962 | - $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 963 | - } |
|
| 964 | - $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 937 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
| 938 | + $wpdb->query($SQL); |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
| 947 | + * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
| 948 | + * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
| 949 | + * |
|
| 950 | + * @global type $wpdb |
|
| 951 | + * @param string $country_name |
|
| 952 | + * @return array where keys are columns, values are column values |
|
| 953 | + */ |
|
| 954 | + public function get_or_create_country($country_name) |
|
| 955 | + { |
|
| 956 | + if ( ! $country_name) { |
|
| 957 | + throw new EE_Error(__("Could not get a country because country name is blank", "event_espresso")); |
|
| 958 | + } |
|
| 959 | + global $wpdb; |
|
| 960 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 961 | + if (is_int($country_name)) { |
|
| 962 | + $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
| 963 | + } |
|
| 964 | + $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
| 965 | 965 | CNT_ISO LIKE %s OR |
| 966 | 966 | CNT_ISO3 LIKE %s OR |
| 967 | 967 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
| 968 | - if ( ! $country) { |
|
| 969 | - //insert a new one then |
|
| 970 | - $cols_n_values = array( |
|
| 971 | - 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 972 | - 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 973 | - 'RGN_ID' => 0, |
|
| 974 | - 'CNT_name' => $country_name, |
|
| 975 | - 'CNT_cur_code' => 'USD', |
|
| 976 | - 'CNT_cur_single' => 'Dollar', |
|
| 977 | - 'CNT_cur_plural' => 'Dollars', |
|
| 978 | - 'CNT_cur_sign' => '$', |
|
| 979 | - 'CNT_cur_sign_b4' => true, |
|
| 980 | - 'CNT_cur_dec_plc' => 2, |
|
| 981 | - 'CNT_cur_dec_mrk' => '.', |
|
| 982 | - 'CNT_cur_thsnds' => ',', |
|
| 983 | - 'CNT_tel_code' => '+1', |
|
| 984 | - 'CNT_is_EU' => false, |
|
| 985 | - 'CNT_active' => true, |
|
| 986 | - ); |
|
| 987 | - $data_types = array( |
|
| 988 | - '%s',//CNT_ISO |
|
| 989 | - '%s',//CNT_ISO3 |
|
| 990 | - '%d',//RGN_ID |
|
| 991 | - '%s',//CNT_name |
|
| 992 | - '%s',//CNT_cur_code |
|
| 993 | - '%s',//CNT_cur_single |
|
| 994 | - '%s',//CNT_cur_plural |
|
| 995 | - '%s',//CNT_cur_sign |
|
| 996 | - '%d',//CNT_cur_sign_b4 |
|
| 997 | - '%d',//CNT_cur_dec_plc |
|
| 998 | - '%s',//CNT_cur_dec_mrk |
|
| 999 | - '%s',//CNT_cur_thsnds |
|
| 1000 | - '%s',//CNT_tel_code |
|
| 1001 | - '%d',//CNT_is_EU |
|
| 1002 | - '%d',//CNT_active |
|
| 1003 | - ); |
|
| 1004 | - $success = $wpdb->insert($country_table, |
|
| 1005 | - $cols_n_values, |
|
| 1006 | - $data_types); |
|
| 1007 | - if ( ! $success) { |
|
| 1008 | - throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1009 | - array('country_id' => $country_name), $country_table, $cols_n_values, $data_types)); |
|
| 1010 | - } |
|
| 1011 | - $country = $cols_n_values; |
|
| 1012 | - } |
|
| 1013 | - return $country; |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * finds a country iso which hasnt been used yet |
|
| 1020 | - * |
|
| 1021 | - * @global type $wpdb |
|
| 1022 | - * @return string |
|
| 1023 | - */ |
|
| 1024 | - private function _find_available_country_iso($num_letters = 2) |
|
| 1025 | - { |
|
| 1026 | - global $wpdb; |
|
| 1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1028 | - $attempts = 0; |
|
| 1029 | - do { |
|
| 1030 | - $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1031 | - $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1032 | - . $country_table |
|
| 1033 | - . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1034 | - $attempts++; |
|
| 1035 | - //keep going until we find an available country code, or we arbitrarily |
|
| 1036 | - //decide we've tried this enough. Somehow they have way too many countries |
|
| 1037 | - //(probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | - return $current_iso; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1046 | - * is independent of outside code which can change in future versions of EE |
|
| 1047 | - * |
|
| 1048 | - * @global type $wpdb |
|
| 1049 | - * @param string $state_name |
|
| 1050 | - * @return array where keys are columns, values are column values |
|
| 1051 | - */ |
|
| 1052 | - public function get_or_create_state($state_name, $country_name = '') |
|
| 1053 | - { |
|
| 1054 | - if ( ! $state_name) { |
|
| 1055 | - throw new EE_Error(__("Could not get-or-create state because no state name was provided", |
|
| 1056 | - "event_espresso")); |
|
| 1057 | - } |
|
| 1058 | - try { |
|
| 1059 | - $country = $this->get_or_create_country($country_name); |
|
| 1060 | - $country_iso = $country['CNT_ISO']; |
|
| 1061 | - } catch (EE_Error $e) { |
|
| 1062 | - $country_iso = $this->get_default_country_iso(); |
|
| 1063 | - } |
|
| 1064 | - global $wpdb; |
|
| 1065 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1066 | - $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 968 | + if ( ! $country) { |
|
| 969 | + //insert a new one then |
|
| 970 | + $cols_n_values = array( |
|
| 971 | + 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
| 972 | + 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
| 973 | + 'RGN_ID' => 0, |
|
| 974 | + 'CNT_name' => $country_name, |
|
| 975 | + 'CNT_cur_code' => 'USD', |
|
| 976 | + 'CNT_cur_single' => 'Dollar', |
|
| 977 | + 'CNT_cur_plural' => 'Dollars', |
|
| 978 | + 'CNT_cur_sign' => '$', |
|
| 979 | + 'CNT_cur_sign_b4' => true, |
|
| 980 | + 'CNT_cur_dec_plc' => 2, |
|
| 981 | + 'CNT_cur_dec_mrk' => '.', |
|
| 982 | + 'CNT_cur_thsnds' => ',', |
|
| 983 | + 'CNT_tel_code' => '+1', |
|
| 984 | + 'CNT_is_EU' => false, |
|
| 985 | + 'CNT_active' => true, |
|
| 986 | + ); |
|
| 987 | + $data_types = array( |
|
| 988 | + '%s',//CNT_ISO |
|
| 989 | + '%s',//CNT_ISO3 |
|
| 990 | + '%d',//RGN_ID |
|
| 991 | + '%s',//CNT_name |
|
| 992 | + '%s',//CNT_cur_code |
|
| 993 | + '%s',//CNT_cur_single |
|
| 994 | + '%s',//CNT_cur_plural |
|
| 995 | + '%s',//CNT_cur_sign |
|
| 996 | + '%d',//CNT_cur_sign_b4 |
|
| 997 | + '%d',//CNT_cur_dec_plc |
|
| 998 | + '%s',//CNT_cur_dec_mrk |
|
| 999 | + '%s',//CNT_cur_thsnds |
|
| 1000 | + '%s',//CNT_tel_code |
|
| 1001 | + '%d',//CNT_is_EU |
|
| 1002 | + '%d',//CNT_active |
|
| 1003 | + ); |
|
| 1004 | + $success = $wpdb->insert($country_table, |
|
| 1005 | + $cols_n_values, |
|
| 1006 | + $data_types); |
|
| 1007 | + if ( ! $success) { |
|
| 1008 | + throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1009 | + array('country_id' => $country_name), $country_table, $cols_n_values, $data_types)); |
|
| 1010 | + } |
|
| 1011 | + $country = $cols_n_values; |
|
| 1012 | + } |
|
| 1013 | + return $country; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * finds a country iso which hasnt been used yet |
|
| 1020 | + * |
|
| 1021 | + * @global type $wpdb |
|
| 1022 | + * @return string |
|
| 1023 | + */ |
|
| 1024 | + private function _find_available_country_iso($num_letters = 2) |
|
| 1025 | + { |
|
| 1026 | + global $wpdb; |
|
| 1027 | + $country_table = $wpdb->prefix . "esp_country"; |
|
| 1028 | + $attempts = 0; |
|
| 1029 | + do { |
|
| 1030 | + $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
| 1031 | + $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
| 1032 | + . $country_table |
|
| 1033 | + . " WHERE CNT_ISO=%s", $current_iso)); |
|
| 1034 | + $attempts++; |
|
| 1035 | + //keep going until we find an available country code, or we arbitrarily |
|
| 1036 | + //decide we've tried this enough. Somehow they have way too many countries |
|
| 1037 | + //(probably because they're mis-using the EE3 country_id like a custom question) |
|
| 1038 | + } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | + return $current_iso; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
| 1046 | + * is independent of outside code which can change in future versions of EE |
|
| 1047 | + * |
|
| 1048 | + * @global type $wpdb |
|
| 1049 | + * @param string $state_name |
|
| 1050 | + * @return array where keys are columns, values are column values |
|
| 1051 | + */ |
|
| 1052 | + public function get_or_create_state($state_name, $country_name = '') |
|
| 1053 | + { |
|
| 1054 | + if ( ! $state_name) { |
|
| 1055 | + throw new EE_Error(__("Could not get-or-create state because no state name was provided", |
|
| 1056 | + "event_espresso")); |
|
| 1057 | + } |
|
| 1058 | + try { |
|
| 1059 | + $country = $this->get_or_create_country($country_name); |
|
| 1060 | + $country_iso = $country['CNT_ISO']; |
|
| 1061 | + } catch (EE_Error $e) { |
|
| 1062 | + $country_iso = $this->get_default_country_iso(); |
|
| 1063 | + } |
|
| 1064 | + global $wpdb; |
|
| 1065 | + $state_table = $wpdb->prefix . "esp_state"; |
|
| 1066 | + $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
| 1067 | 1067 | (STA_abbrev LIKE %s OR |
| 1068 | 1068 | STA_name LIKE %s) AND |
| 1069 | 1069 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
| 1070 | - if ( ! $state) { |
|
| 1071 | - //insert a new one then |
|
| 1072 | - $cols_n_values = array( |
|
| 1073 | - 'CNT_ISO' => $country_iso, |
|
| 1074 | - 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1075 | - 'STA_name' => $state_name, |
|
| 1076 | - 'STA_active' => true, |
|
| 1077 | - ); |
|
| 1078 | - $data_types = array( |
|
| 1079 | - '%s',//CNT_ISO |
|
| 1080 | - '%s',//STA_abbrev |
|
| 1081 | - '%s',//STA_name |
|
| 1082 | - '%d',//STA_active |
|
| 1083 | - ); |
|
| 1084 | - $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1085 | - if ( ! $success) { |
|
| 1086 | - throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1087 | - array('state' => $state_name, 'country_id' => $country_name), $state_table, $cols_n_values, |
|
| 1088 | - $data_types)); |
|
| 1089 | - } |
|
| 1090 | - $state = $cols_n_values; |
|
| 1091 | - $state['STA_ID'] = $wpdb->insert_id; |
|
| 1092 | - } |
|
| 1093 | - return $state; |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1100 | - * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1101 | - * |
|
| 1102 | - * @param type $timeString |
|
| 1103 | - * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1104 | - * with leading zeros) |
|
| 1105 | - */ |
|
| 1106 | - public function convertTimeFromAMPM($timeString) |
|
| 1107 | - { |
|
| 1108 | - $matches = array(); |
|
| 1109 | - preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1110 | - if ( ! $matches || count($matches) < 3) { |
|
| 1111 | - $hour = '00'; |
|
| 1112 | - $minutes = '00'; |
|
| 1113 | - } else { |
|
| 1114 | - $hour = intval($matches[1]); |
|
| 1115 | - $minutes = $matches[2]; |
|
| 1116 | - } |
|
| 1117 | - if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1118 | - $hour = intval($hour) + 12; |
|
| 1119 | - } |
|
| 1120 | - $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1121 | - $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1122 | - return "$hour:$minutes"; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1129 | - * |
|
| 1130 | - * @param int $country_id |
|
| 1131 | - * @return string the country's ISO3 code |
|
| 1132 | - */ |
|
| 1133 | - public function get_iso_from_3_1_country_id($country_id) |
|
| 1134 | - { |
|
| 1135 | - $old_countries = array( |
|
| 1136 | - array(64, 'United States', 'US', 'USA', 1), |
|
| 1137 | - array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1138 | - array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1139 | - array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1140 | - array(70, 'France', 'FR', 'FRA', 2), |
|
| 1141 | - array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1142 | - array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1143 | - array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1144 | - array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1145 | - array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1146 | - array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1147 | - array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1148 | - array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1149 | - array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1150 | - array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1151 | - array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1152 | - array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1153 | - array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1154 | - array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1155 | - array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1156 | - array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1157 | - array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1158 | - array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1159 | - array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1160 | - array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1161 | - array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1162 | - array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1163 | - array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1164 | - array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1165 | - array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1166 | - array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1167 | - array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1168 | - array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1169 | - array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1170 | - array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1171 | - array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1172 | - array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1173 | - array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1174 | - array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1175 | - array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1176 | - array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1177 | - array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1178 | - array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1179 | - array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1180 | - array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1181 | - array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1182 | - array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1183 | - array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1184 | - array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1185 | - array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1186 | - array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1187 | - array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1188 | - array(42, 'China', 'CN', 'CHN', 1), |
|
| 1189 | - array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1190 | - array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1191 | - array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1192 | - array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1193 | - array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1194 | - array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1195 | - array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1196 | - array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1197 | - array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1198 | - array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1199 | - array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1200 | - array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1201 | - array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1202 | - array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1203 | - array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1204 | - array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1205 | - array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1206 | - array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1207 | - array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1208 | - array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1209 | - array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1210 | - array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1211 | - array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1212 | - array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1213 | - array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1214 | - array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1215 | - array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1216 | - array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1217 | - array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1218 | - array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1219 | - array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1220 | - array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1221 | - array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1222 | - array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1223 | - array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1224 | - array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1225 | - array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1226 | - array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1227 | - array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1228 | - array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1229 | - array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1230 | - array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1231 | - array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1232 | - array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1233 | - array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1234 | - array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1235 | - array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1236 | - array(91, 'India', 'IN', 'IND', 1), |
|
| 1237 | - array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1238 | - array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1239 | - array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1240 | - array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1241 | - array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1242 | - array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1243 | - array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1244 | - array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1245 | - array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1246 | - array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1247 | - array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1248 | - array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1249 | - array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1250 | - array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1251 | - array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1252 | - array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1253 | - array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1254 | - // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1255 | - array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1256 | - array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1257 | - array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1258 | - array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1259 | - array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1260 | - array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1261 | - array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1262 | - array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1263 | - array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1264 | - array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1265 | - array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1266 | - array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1267 | - array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1268 | - array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1269 | - array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1270 | - array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1271 | - array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1272 | - array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1273 | - array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1274 | - array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1275 | - array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1276 | - array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1277 | - array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1278 | - array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1279 | - array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1280 | - array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1281 | - array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1282 | - array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1283 | - array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1284 | - array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1285 | - array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1286 | - array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1287 | - array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1288 | - array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1289 | - array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1290 | - array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1291 | - array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1292 | - array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1293 | - array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1294 | - array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1295 | - array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1296 | - array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1297 | - array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1298 | - array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1299 | - array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1300 | - array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1301 | - array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1302 | - array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1303 | - array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1304 | - array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1305 | - array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1306 | - array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1307 | - array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1308 | - array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1309 | - array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1310 | - array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1311 | - array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1312 | - array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1313 | - array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1314 | - array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1315 | - array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1316 | - array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1317 | - array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1318 | - array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1319 | - array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1320 | - array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1321 | - array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1322 | - array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1323 | - array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1324 | - array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1325 | - array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1326 | - array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1327 | - array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1328 | - array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1329 | - array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1330 | - array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1331 | - array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1332 | - array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1333 | - array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1334 | - array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1335 | - array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1336 | - array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1337 | - array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1338 | - array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1339 | - array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1340 | - array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1341 | - array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1342 | - array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1343 | - array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1344 | - array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1345 | - array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1346 | - array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1347 | - array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1348 | - array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1349 | - array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1350 | - array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1351 | - array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1352 | - array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1353 | - array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1354 | - array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1355 | - array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1356 | - array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1357 | - array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1358 | - array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1359 | - ); |
|
| 1360 | - $country_iso = 'US'; |
|
| 1361 | - foreach ($old_countries as $country_array) { |
|
| 1362 | - //note: index 0 is the 3.1 country ID |
|
| 1363 | - if ($country_array[0] == $country_id) { |
|
| 1364 | - //note: index 2 is the ISO |
|
| 1365 | - $country_iso = $country_array[2]; |
|
| 1366 | - break; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - return $country_iso; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * Gets the ISO3 for the |
|
| 1376 | - * |
|
| 1377 | - * @return string |
|
| 1378 | - */ |
|
| 1379 | - public function get_default_country_iso() |
|
| 1380 | - { |
|
| 1381 | - $old_org_options = get_option('events_organization_settings'); |
|
| 1382 | - $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1383 | - return $iso; |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1390 | - * |
|
| 1391 | - * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1392 | - * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1393 | - * DEFAULT payment status, the event's DEFAULT payment status, or |
|
| 1394 | - * the attendee's payment status) required pre-approval. |
|
| 1395 | - * @return string STS_ID for use in 4.1 |
|
| 1396 | - */ |
|
| 1397 | - public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1398 | - { |
|
| 1399 | - //EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1400 | - if ($this_thing_required_pre_approval) { |
|
| 1401 | - return 'RNA'; |
|
| 1402 | - } else { |
|
| 1403 | - $mapping = $default_reg_stati_conversions = array( |
|
| 1404 | - 'Completed' => 'RAP', |
|
| 1405 | - '' => 'RPP', |
|
| 1406 | - 'Incomplete' => 'RPP', |
|
| 1407 | - 'Pending' => 'RAP', |
|
| 1408 | - //stati that only occurred on 3.1 attendees: |
|
| 1409 | - 'Payment Declined' => 'RPP', |
|
| 1410 | - 'Not Completed' => 'RPP', |
|
| 1411 | - 'Cancelled' => 'RPP', |
|
| 1412 | - 'Declined' => 'RPP', |
|
| 1413 | - ); |
|
| 1414 | - } |
|
| 1415 | - return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - |
|
| 1419 | - |
|
| 1420 | - /** |
|
| 1421 | - * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1422 | - * and sets it as the featured image on the CPT event |
|
| 1423 | - * |
|
| 1424 | - * @param type $old_event |
|
| 1425 | - * @param type $new_cpt_id |
|
| 1426 | - * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1427 | - * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1428 | - */ |
|
| 1429 | - public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1430 | - $guid, |
|
| 1431 | - $new_cpt_id, |
|
| 1432 | - EE_Data_Migration_Script_Stage $migration_stage |
|
| 1433 | - ) { |
|
| 1434 | - $created_attachment_post = false; |
|
| 1435 | - $guid = $this->_get_original_guid($guid); |
|
| 1436 | - if ($guid) { |
|
| 1437 | - //check for an existing attachment post with this guid |
|
| 1438 | - $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1439 | - if ( ! $attachment_post_id) { |
|
| 1440 | - //post thumbnail with that GUID doesn't exist, we should create one |
|
| 1441 | - $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1442 | - $created_attachment_post = true; |
|
| 1443 | - } |
|
| 1444 | - //double-check we actually have an attachment post |
|
| 1445 | - if ($attachment_post_id) { |
|
| 1446 | - update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1447 | - } else { |
|
| 1448 | - $migration_stage->add_error(sprintf(__("Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1449 | - "event_espresso"), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1450 | - } |
|
| 1451 | - } |
|
| 1452 | - return $created_attachment_post; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1459 | - * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1460 | - * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1461 | - * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1462 | - * exists |
|
| 1463 | - * |
|
| 1464 | - * @param string $guid_in_old_event |
|
| 1465 | - * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1466 | - */ |
|
| 1467 | - private function _get_original_guid($guid_in_old_event) |
|
| 1468 | - { |
|
| 1469 | - $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1470 | - //do a head request to verify the file exists |
|
| 1471 | - $head_response = wp_remote_head($original_guid); |
|
| 1472 | - if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1473 | - return $original_guid; |
|
| 1474 | - } else { |
|
| 1475 | - return $guid_in_old_event; |
|
| 1476 | - } |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1483 | - * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1484 | - * thumbnails) |
|
| 1485 | - * |
|
| 1486 | - * @param type $guid |
|
| 1487 | - * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1488 | - * @return int |
|
| 1489 | - */ |
|
| 1490 | - private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1491 | - { |
|
| 1492 | - if ( ! $guid) { |
|
| 1493 | - $migration_stage->add_error(sprintf(__("Cannot create image attachment for a blank GUID!", |
|
| 1494 | - "event_espresso"))); |
|
| 1495 | - return 0; |
|
| 1496 | - } |
|
| 1497 | - $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1498 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1499 | - //if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1500 | - if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1501 | - //image is located remotely. download it and place it in the uploads directory |
|
| 1502 | - if ( ! is_readable($guid)) { |
|
| 1503 | - $migration_stage->add_error(sprintf(__("Could not create image attachment from non-existent file: %s", |
|
| 1504 | - "event_espresso"), $guid)); |
|
| 1505 | - return 0; |
|
| 1506 | - } |
|
| 1507 | - $contents = file_get_contents($guid); |
|
| 1508 | - if ($contents === false) { |
|
| 1509 | - $migration_stage->add_error(sprintf(__("Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1510 | - "event_espresso"), $guid)); |
|
| 1511 | - return false; |
|
| 1512 | - } |
|
| 1513 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
| 1514 | - $savefile = fopen($local_filepath, 'w'); |
|
| 1515 | - fwrite($savefile, $contents); |
|
| 1516 | - fclose($savefile); |
|
| 1517 | - $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1518 | - } else { |
|
| 1519 | - $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1520 | - } |
|
| 1521 | - $attachment = array( |
|
| 1522 | - 'guid' => $guid, |
|
| 1523 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1524 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1525 | - 'post_content' => '', |
|
| 1526 | - 'post_status' => 'inherit', |
|
| 1527 | - ); |
|
| 1528 | - $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1529 | - if ( ! $attach_id) { |
|
| 1530 | - $migration_stage->add_error(sprintf(__("Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1531 | - "event_espresso"), $guid, $this->_json_encode($attachment))); |
|
| 1532 | - return $attach_id; |
|
| 1533 | - } |
|
| 1534 | - // you must first include the image.php file |
|
| 1535 | - // for the function wp_generate_attachment_metadata() to work |
|
| 1536 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1537 | - $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1538 | - if ( ! $attach_data) { |
|
| 1539 | - $migration_stage->add_error(sprintf(__("Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1540 | - "event_espresso"), $attach_id, $local_filepath, $guid)); |
|
| 1541 | - return $attach_id; |
|
| 1542 | - } |
|
| 1543 | - $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1544 | - if ( ! $metadata_save_result) { |
|
| 1545 | - $migration_stage->add_error(sprintf(__("Could not update attachment metadata for attachment %d with data %s", |
|
| 1546 | - "event_espresso"), $attach_id, $this->_json_encode($attach_data))); |
|
| 1547 | - } |
|
| 1548 | - return $attach_id; |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - |
|
| 1552 | - |
|
| 1553 | - /** |
|
| 1554 | - * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1555 | - * and returns its ID. |
|
| 1556 | - * |
|
| 1557 | - * @global type $wpdb |
|
| 1558 | - * @param string $guid |
|
| 1559 | - * @return int |
|
| 1560 | - */ |
|
| 1561 | - private function _get_image_attachment_id_by_GUID($guid) |
|
| 1562 | - { |
|
| 1563 | - global $wpdb; |
|
| 1564 | - $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1565 | - return $attachment_id; |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1572 | - * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
| 1573 | - * |
|
| 1574 | - * @param EE_Data_Migration_Script_base $stage |
|
| 1575 | - * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1576 | - * UTC time for |
|
| 1577 | - * @param string $DATETIME_string |
|
| 1578 | - * @param string $timezone |
|
| 1579 | - * @return string |
|
| 1580 | - */ |
|
| 1581 | - public function convert_date_string_to_utc( |
|
| 1582 | - EE_Data_Migration_Script_Stage $stage, |
|
| 1583 | - $row_of_data, |
|
| 1584 | - $DATETIME_string, |
|
| 1585 | - $timezone = null |
|
| 1586 | - ) { |
|
| 1587 | - $original_tz = $timezone; |
|
| 1588 | - if ( ! $timezone) { |
|
| 1589 | - $timezone = $this->_get_wp_timezone(); |
|
| 1590 | - } |
|
| 1591 | - if ( ! $timezone) { |
|
| 1592 | - $stage->add_error(sprintf(__("Could not find timezone given %s for %s", "event_espresso"), $original_tz, |
|
| 1593 | - $row_of_data)); |
|
| 1594 | - $timezone = 'UTC'; |
|
| 1595 | - } |
|
| 1596 | - try { |
|
| 1597 | - $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1598 | - $date_obj->setTimezone(new DateTimeZone('UTC')); |
|
| 1599 | - } catch (Exception $e) { |
|
| 1600 | - $stage->add_error(sprintf(__("Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1601 | - "event_espresso"), $DATETIME_string, $timezone)); |
|
| 1602 | - $date_obj = new DateTime(); |
|
| 1603 | - } |
|
| 1604 | - return $date_obj->format('Y-m-d H:i:s'); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
| 1611 | - * |
|
| 1612 | - * @return string |
|
| 1613 | - */ |
|
| 1614 | - private function _get_wp_timezone() |
|
| 1615 | - { |
|
| 1616 | - $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1617 | - //if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1618 | - if (empty($timezone)) { |
|
| 1619 | - //let's get a the WordPress UTC offset |
|
| 1620 | - $offset = get_option('gmt_offset'); |
|
| 1621 | - $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1622 | - } |
|
| 1623 | - return $timezone; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - |
|
| 1627 | - |
|
| 1628 | - /** |
|
| 1629 | - * Gets the wordpress timezone string from a UTC offset |
|
| 1630 | - * |
|
| 1631 | - * @param int $offset |
|
| 1632 | - * @return boolean |
|
| 1633 | - */ |
|
| 1634 | - private function timezone_convert_to_string_from_offset($offset) |
|
| 1635 | - { |
|
| 1636 | - //shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
| 1637 | - $offset *= 3600; // convert hour offset to seconds |
|
| 1638 | - $abbrarray = timezone_abbreviations_list(); |
|
| 1639 | - foreach ($abbrarray as $abbr) { |
|
| 1640 | - foreach ($abbr as $city) { |
|
| 1641 | - if ($city['offset'] == $offset) { |
|
| 1642 | - return $city['timezone_id']; |
|
| 1643 | - } |
|
| 1644 | - } |
|
| 1645 | - } |
|
| 1646 | - return false; |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - |
|
| 1650 | - |
|
| 1651 | - public function migration_page_hooks() |
|
| 1652 | - { |
|
| 1653 | - add_filter( |
|
| 1654 | - 'FHEE__ee_migration_page__header', |
|
| 1655 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1656 | - 10, |
|
| 1657 | - 3 |
|
| 1658 | - ); |
|
| 1659 | - add_filter( |
|
| 1660 | - 'FHEE__ee_migration_page__p_after_header', |
|
| 1661 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1662 | - 10, |
|
| 1663 | - 2 |
|
| 1664 | - ); |
|
| 1665 | - add_filter( |
|
| 1666 | - 'FHEE__ee_migration_page__option_1_main', |
|
| 1667 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1668 | - 10, |
|
| 1669 | - 3 |
|
| 1670 | - ); |
|
| 1671 | - add_filter( |
|
| 1672 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1673 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1674 | - 10, |
|
| 1675 | - 3 |
|
| 1676 | - ); |
|
| 1677 | - add_action( |
|
| 1678 | - 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1679 | - array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1680 | - 10, |
|
| 1681 | - 3 |
|
| 1682 | - ); |
|
| 1683 | - add_filter( |
|
| 1684 | - 'FHEE__ee_migration_page__option_2_main', |
|
| 1685 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1686 | - 10, |
|
| 1687 | - 4 |
|
| 1688 | - ); |
|
| 1689 | - add_filter( |
|
| 1690 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1691 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1692 | - 10, |
|
| 1693 | - 2 |
|
| 1694 | - ); |
|
| 1695 | - add_filter( |
|
| 1696 | - 'FHEE__ee_migration_page__option_2_details', |
|
| 1697 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1698 | - 10, |
|
| 1699 | - 2 |
|
| 1700 | - ); |
|
| 1701 | - add_action( |
|
| 1702 | - 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1703 | - array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1704 | - ); |
|
| 1705 | - add_filter( |
|
| 1706 | - 'FHEE__ee_migration_page__done_migration_header', |
|
| 1707 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1708 | - 10, |
|
| 1709 | - 2 |
|
| 1710 | - ); |
|
| 1711 | - add_filter( |
|
| 1712 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1713 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1714 | - 10, |
|
| 1715 | - 2 |
|
| 1716 | - ); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - public function _migrate_page_hook_simplify_version_strings( |
|
| 1722 | - $old_content, |
|
| 1723 | - $current_db_state, |
|
| 1724 | - $next_db_state, |
|
| 1725 | - $ultimate_db_state = null |
|
| 1726 | - ) { |
|
| 1727 | - return str_replace(array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1728 | - array(__('EE3', 'event_espresso'), __('EE4', 'event_espresso'), __("EE4", 'event_espresso')), |
|
| 1729 | - $old_content); |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1735 | - { |
|
| 1736 | - return str_replace($next_db_state, __("EE4", 'event_espresso'), $old_content); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - |
|
| 1741 | - public function _migration_page_hook_option_1_extra_details() |
|
| 1742 | - { |
|
| 1743 | - ?> |
|
| 1070 | + if ( ! $state) { |
|
| 1071 | + //insert a new one then |
|
| 1072 | + $cols_n_values = array( |
|
| 1073 | + 'CNT_ISO' => $country_iso, |
|
| 1074 | + 'STA_abbrev' => substr($state_name, 0, 6), |
|
| 1075 | + 'STA_name' => $state_name, |
|
| 1076 | + 'STA_active' => true, |
|
| 1077 | + ); |
|
| 1078 | + $data_types = array( |
|
| 1079 | + '%s',//CNT_ISO |
|
| 1080 | + '%s',//STA_abbrev |
|
| 1081 | + '%s',//STA_name |
|
| 1082 | + '%d',//STA_active |
|
| 1083 | + ); |
|
| 1084 | + $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
| 1085 | + if ( ! $success) { |
|
| 1086 | + throw new EE_Error($this->_create_error_message_for_db_insertion('N/A', |
|
| 1087 | + array('state' => $state_name, 'country_id' => $country_name), $state_table, $cols_n_values, |
|
| 1088 | + $data_types)); |
|
| 1089 | + } |
|
| 1090 | + $state = $cols_n_values; |
|
| 1091 | + $state['STA_ID'] = $wpdb->insert_id; |
|
| 1092 | + } |
|
| 1093 | + return $state; |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
| 1100 | + * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
| 1101 | + * |
|
| 1102 | + * @param type $timeString |
|
| 1103 | + * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
| 1104 | + * with leading zeros) |
|
| 1105 | + */ |
|
| 1106 | + public function convertTimeFromAMPM($timeString) |
|
| 1107 | + { |
|
| 1108 | + $matches = array(); |
|
| 1109 | + preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
| 1110 | + if ( ! $matches || count($matches) < 3) { |
|
| 1111 | + $hour = '00'; |
|
| 1112 | + $minutes = '00'; |
|
| 1113 | + } else { |
|
| 1114 | + $hour = intval($matches[1]); |
|
| 1115 | + $minutes = $matches[2]; |
|
| 1116 | + } |
|
| 1117 | + if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
| 1118 | + $hour = intval($hour) + 12; |
|
| 1119 | + } |
|
| 1120 | + $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
| 1121 | + $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
| 1122 | + return "$hour:$minutes"; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * Gets the ISO3 fora country given its 3.1 country ID. |
|
| 1129 | + * |
|
| 1130 | + * @param int $country_id |
|
| 1131 | + * @return string the country's ISO3 code |
|
| 1132 | + */ |
|
| 1133 | + public function get_iso_from_3_1_country_id($country_id) |
|
| 1134 | + { |
|
| 1135 | + $old_countries = array( |
|
| 1136 | + array(64, 'United States', 'US', 'USA', 1), |
|
| 1137 | + array(15, 'Australia', 'AU', 'AUS', 1), |
|
| 1138 | + array(39, 'Canada', 'CA', 'CAN', 1), |
|
| 1139 | + array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
| 1140 | + array(70, 'France', 'FR', 'FRA', 2), |
|
| 1141 | + array(111, 'Italy', 'IT', 'ITA', 2), |
|
| 1142 | + array(63, 'Spain', 'ES', 'ESP', 2), |
|
| 1143 | + array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
| 1144 | + array(2, 'Albania', 'AL', 'ALB', 1), |
|
| 1145 | + array(3, 'Germany', 'DE', 'DEU', 2), |
|
| 1146 | + array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
| 1147 | + array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
| 1148 | + array(197, 'Sweden', 'SE', 'SWE', 1), |
|
| 1149 | + array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
| 1150 | + array(4, 'Andorra', 'AD', 'AND', 2), |
|
| 1151 | + array(5, 'Angola', 'AO', 'AGO', 1), |
|
| 1152 | + array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
| 1153 | + array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
| 1154 | + array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
| 1155 | + array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
| 1156 | + array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
| 1157 | + array(12, 'Argentina', 'AR', 'ARG', 1), |
|
| 1158 | + array(13, 'Armenia', 'AM', 'ARM', 1), |
|
| 1159 | + array(14, 'Aruba', 'AW', 'ABW', 1), |
|
| 1160 | + array(16, 'Austria', 'AT', 'AUT', 2), |
|
| 1161 | + array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
| 1162 | + array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
| 1163 | + array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
| 1164 | + array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
| 1165 | + array(21, 'Barbados', 'BB', 'BRB', 1), |
|
| 1166 | + array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
| 1167 | + array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
| 1168 | + array(24, 'Benin', 'BJ', 'BEN', 1), |
|
| 1169 | + array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
| 1170 | + array(26, 'Belarus', 'BY', 'BLR', 1), |
|
| 1171 | + array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
| 1172 | + array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
| 1173 | + array(29, 'Botswana', 'BW', 'BWA', 1), |
|
| 1174 | + array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
| 1175 | + array(30, 'Brazil', 'BR', 'BRA', 1), |
|
| 1176 | + array(31, 'Brunei', 'BN', 'BRN', 1), |
|
| 1177 | + array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
| 1178 | + array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
| 1179 | + array(34, 'Burundi', 'BI', 'BDI', 1), |
|
| 1180 | + array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
| 1181 | + array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
| 1182 | + array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
| 1183 | + array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
| 1184 | + array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
| 1185 | + array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
| 1186 | + array(40, 'Chad', 'TD', 'TCD', 1), |
|
| 1187 | + array(41, 'Chile', 'CL', 'CHL', 1), |
|
| 1188 | + array(42, 'China', 'CN', 'CHN', 1), |
|
| 1189 | + array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
| 1190 | + array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
| 1191 | + array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
| 1192 | + array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
| 1193 | + array(44, 'Colombia', 'CO', 'COL', 1), |
|
| 1194 | + array(45, 'Comoros', 'KM', 'COM', 1), |
|
| 1195 | + array(46, 'Congo', 'CG', 'COG', 1), |
|
| 1196 | + array(47, 'North Korea', 'KP', 'PRK', 1), |
|
| 1197 | + array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
| 1198 | + array(51, 'Croatia', 'HR', 'HRV', 1), |
|
| 1199 | + array(52, 'Cuba', 'CU', 'CUB', 1), |
|
| 1200 | + array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
| 1201 | + array(53, 'Denmark', 'DK', 'DNK', 1), |
|
| 1202 | + array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
| 1203 | + array(55, 'Dominica', 'DM', 'DMA', 1), |
|
| 1204 | + array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
| 1205 | + array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
| 1206 | + array(57, 'Egypt', 'EG', 'EGY', 1), |
|
| 1207 | + array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
| 1208 | + array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
| 1209 | + array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
| 1210 | + array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
| 1211 | + array(65, 'Estonia', 'EE', 'EST', 2), |
|
| 1212 | + array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
| 1213 | + array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
| 1214 | + array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
| 1215 | + array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
| 1216 | + array(69, 'Finland', 'FI', 'FIN', 2), |
|
| 1217 | + array(71, 'Gabon', 'GA', 'GAB', 1), |
|
| 1218 | + array(72, 'Gambia', 'GM', 'GMB', 1), |
|
| 1219 | + array(73, 'Georgia', 'GE', 'GEO', 1), |
|
| 1220 | + array(74, 'Ghana', 'GH', 'GHA', 1), |
|
| 1221 | + array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
| 1222 | + array(76, 'Greece', 'GR', 'GRC', 2), |
|
| 1223 | + array(77, 'Grenada', 'GD', 'GRD', 1), |
|
| 1224 | + array(78, 'Greenland', 'GL', 'GRL', 1), |
|
| 1225 | + array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
| 1226 | + array(80, 'Guam', 'GU', 'GUM', 1), |
|
| 1227 | + array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
| 1228 | + array(82, 'Guinea', 'GN', 'GIN', 1), |
|
| 1229 | + array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
| 1230 | + array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
| 1231 | + array(85, 'Guyana', 'GY', 'GUY', 1), |
|
| 1232 | + array(86, 'Haiti', 'HT', 'HTI', 1), |
|
| 1233 | + array(88, 'Honduras', 'HN', 'HND', 1), |
|
| 1234 | + array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
| 1235 | + array(90, 'Hungary', 'HU', 'HUN', 1), |
|
| 1236 | + array(91, 'India', 'IN', 'IND', 1), |
|
| 1237 | + array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
| 1238 | + array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
| 1239 | + array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
| 1240 | + array(94, 'Iran', 'IR', 'IRN', 1), |
|
| 1241 | + array(95, 'Ireland', 'IE', 'IRL', 2), |
|
| 1242 | + array(97, 'Iceland', 'IS', 'ISL', 1), |
|
| 1243 | + array(110, 'Israel', 'IL', 'ISR', 1), |
|
| 1244 | + array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
| 1245 | + array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
| 1246 | + array(113, 'Japan', 'JP', 'JPN', 1), |
|
| 1247 | + array(114, 'Jordan', 'JO', 'JOR', 1), |
|
| 1248 | + array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
| 1249 | + array(116, 'Kenya', 'KE', 'KEN', 1), |
|
| 1250 | + array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
| 1251 | + array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
| 1252 | + array(48, 'South Korea', 'KR', 'KOR', 1), |
|
| 1253 | + array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
| 1254 | + // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
| 1255 | + array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
| 1256 | + array(120, 'Laos', 'LA', 'LAO', 1), |
|
| 1257 | + array(121, 'Latvia', 'LV', 'LVA', 2), |
|
| 1258 | + array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
| 1259 | + array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
| 1260 | + array(124, 'Liberia', 'LR', 'LBR', 1), |
|
| 1261 | + array(125, 'Libya', 'LY', 'LBY', 1), |
|
| 1262 | + array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
| 1263 | + array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
| 1264 | + array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
| 1265 | + array(129, 'Macao', 'MO', 'MAC', 1), |
|
| 1266 | + array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
| 1267 | + array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
| 1268 | + array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
| 1269 | + array(133, 'Malawi', 'MW', 'MWI', 1), |
|
| 1270 | + array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
| 1271 | + array(135, 'Mali', 'ML', 'MLI', 1), |
|
| 1272 | + array(136, 'Malta', 'MT', 'MLT', 2), |
|
| 1273 | + array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
| 1274 | + array(137, 'Morocco', 'MA', 'MAR', 1), |
|
| 1275 | + array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
| 1276 | + array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
| 1277 | + array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
| 1278 | + array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
| 1279 | + array(141, 'Mayote', 'YT', 'MYT', 2), |
|
| 1280 | + array(142, 'Mexico', 'MX', 'MEX', 1), |
|
| 1281 | + array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
| 1282 | + array(144, 'Moldova', 'MD', 'MDA', 1), |
|
| 1283 | + array(145, 'Monaco', 'MC', 'MCO', 2), |
|
| 1284 | + array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
| 1285 | + array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
| 1286 | + array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
| 1287 | + array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
| 1288 | + array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
| 1289 | + array(150, 'Namibia', 'NA', 'NAM', 1), |
|
| 1290 | + array(151, 'Nauru', 'NR', 'NRU', 1), |
|
| 1291 | + array(152, 'Nepal', 'NP', 'NPL', 1), |
|
| 1292 | + array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
| 1293 | + array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
| 1294 | + array(154, 'Niger', 'NE', 'NER', 1), |
|
| 1295 | + array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
| 1296 | + array(156, 'Niue', 'NU', 'NIU', 1), |
|
| 1297 | + array(157, 'Norway', 'NO', 'NOR', 1), |
|
| 1298 | + array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
| 1299 | + array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
| 1300 | + array(160, 'Oman', 'OM', 'OMN', 1), |
|
| 1301 | + array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
| 1302 | + array(162, 'Palau', 'PW', 'PLW', 1), |
|
| 1303 | + array(163, 'Panama', 'PA', 'PAN', 1), |
|
| 1304 | + array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
| 1305 | + array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
| 1306 | + array(166, 'Peru', 'PE', 'PER', 1), |
|
| 1307 | + array(68, 'Philippines', 'PH', 'PHL', 1), |
|
| 1308 | + array(167, 'Poland', 'PL', 'POL', 1), |
|
| 1309 | + array(168, 'Portugal', 'PT', 'PRT', 2), |
|
| 1310 | + array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
| 1311 | + array(170, 'Qatar', 'QA', 'QAT', 1), |
|
| 1312 | + array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
| 1313 | + array(177, 'Romania', 'RO', 'ROM', 2), |
|
| 1314 | + array(178, 'Russia', 'RU', 'RUS', 1), |
|
| 1315 | + array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
| 1316 | + array(180, 'Samoa', 'WS', 'WSM', 1), |
|
| 1317 | + array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
| 1318 | + array(183, 'San Marino', 'SM', 'SMR', 2), |
|
| 1319 | + array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
| 1320 | + array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
| 1321 | + array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
| 1322 | + array(188, 'Senegal', 'SN', 'SEN', 1), |
|
| 1323 | + array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
| 1324 | + array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
| 1325 | + array(191, 'Singapore', 'SG', 'SGP', 1), |
|
| 1326 | + array(192, 'Syria', 'SY', 'SYR', 1), |
|
| 1327 | + array(193, 'Somalia', 'SO', 'SOM', 1), |
|
| 1328 | + array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
| 1329 | + array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
| 1330 | + array(196, 'Sudan', 'SD', 'SDN', 1), |
|
| 1331 | + array(199, 'Suriname', 'SR', 'SUR', 1), |
|
| 1332 | + array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
| 1333 | + array(201, 'Thailand', 'TH', 'THA', 1), |
|
| 1334 | + array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
| 1335 | + array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
| 1336 | + array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
| 1337 | + array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
| 1338 | + array(207, 'Togo', 'TG', 'TGO', 1), |
|
| 1339 | + array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
| 1340 | + array(209, 'Tonga', 'TO', 'TON', 1), |
|
| 1341 | + array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
| 1342 | + array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
| 1343 | + array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
| 1344 | + array(213, 'Turkey', 'TR', 'TUR', 1), |
|
| 1345 | + array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
| 1346 | + array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
| 1347 | + array(216, 'Uganda', 'UG', 'UGA', 1), |
|
| 1348 | + array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
| 1349 | + array(217, 'Uruguay', 'UY', 'URY', 1), |
|
| 1350 | + array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
| 1351 | + array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
| 1352 | + array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
| 1353 | + array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
| 1354 | + array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
| 1355 | + array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
| 1356 | + array(223, 'Yemen', 'YE', 'YEM', 1), |
|
| 1357 | + array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
| 1358 | + array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
| 1359 | + ); |
|
| 1360 | + $country_iso = 'US'; |
|
| 1361 | + foreach ($old_countries as $country_array) { |
|
| 1362 | + //note: index 0 is the 3.1 country ID |
|
| 1363 | + if ($country_array[0] == $country_id) { |
|
| 1364 | + //note: index 2 is the ISO |
|
| 1365 | + $country_iso = $country_array[2]; |
|
| 1366 | + break; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + return $country_iso; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * Gets the ISO3 for the |
|
| 1376 | + * |
|
| 1377 | + * @return string |
|
| 1378 | + */ |
|
| 1379 | + public function get_default_country_iso() |
|
| 1380 | + { |
|
| 1381 | + $old_org_options = get_option('events_organization_settings'); |
|
| 1382 | + $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
| 1383 | + return $iso; |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
| 1390 | + * |
|
| 1391 | + * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
| 1392 | + * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
| 1393 | + * DEFAULT payment status, the event's DEFAULT payment status, or |
|
| 1394 | + * the attendee's payment status) required pre-approval. |
|
| 1395 | + * @return string STS_ID for use in 4.1 |
|
| 1396 | + */ |
|
| 1397 | + public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
| 1398 | + { |
|
| 1399 | + //EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
| 1400 | + if ($this_thing_required_pre_approval) { |
|
| 1401 | + return 'RNA'; |
|
| 1402 | + } else { |
|
| 1403 | + $mapping = $default_reg_stati_conversions = array( |
|
| 1404 | + 'Completed' => 'RAP', |
|
| 1405 | + '' => 'RPP', |
|
| 1406 | + 'Incomplete' => 'RPP', |
|
| 1407 | + 'Pending' => 'RAP', |
|
| 1408 | + //stati that only occurred on 3.1 attendees: |
|
| 1409 | + 'Payment Declined' => 'RPP', |
|
| 1410 | + 'Not Completed' => 'RPP', |
|
| 1411 | + 'Cancelled' => 'RPP', |
|
| 1412 | + 'Declined' => 'RPP', |
|
| 1413 | + ); |
|
| 1414 | + } |
|
| 1415 | + return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + |
|
| 1419 | + |
|
| 1420 | + /** |
|
| 1421 | + * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
| 1422 | + * and sets it as the featured image on the CPT event |
|
| 1423 | + * |
|
| 1424 | + * @param type $old_event |
|
| 1425 | + * @param type $new_cpt_id |
|
| 1426 | + * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
| 1427 | + * @return boolean whether or not we had to do the big job of creating an image attachment |
|
| 1428 | + */ |
|
| 1429 | + public function convert_image_url_to_attachment_and_attach_to_post( |
|
| 1430 | + $guid, |
|
| 1431 | + $new_cpt_id, |
|
| 1432 | + EE_Data_Migration_Script_Stage $migration_stage |
|
| 1433 | + ) { |
|
| 1434 | + $created_attachment_post = false; |
|
| 1435 | + $guid = $this->_get_original_guid($guid); |
|
| 1436 | + if ($guid) { |
|
| 1437 | + //check for an existing attachment post with this guid |
|
| 1438 | + $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
| 1439 | + if ( ! $attachment_post_id) { |
|
| 1440 | + //post thumbnail with that GUID doesn't exist, we should create one |
|
| 1441 | + $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
| 1442 | + $created_attachment_post = true; |
|
| 1443 | + } |
|
| 1444 | + //double-check we actually have an attachment post |
|
| 1445 | + if ($attachment_post_id) { |
|
| 1446 | + update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
| 1447 | + } else { |
|
| 1448 | + $migration_stage->add_error(sprintf(__("Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
| 1449 | + "event_espresso"), $guid, $new_cpt_id, $attachment_post_id)); |
|
| 1450 | + } |
|
| 1451 | + } |
|
| 1452 | + return $created_attachment_post; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
| 1459 | + * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
| 1460 | + * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
| 1461 | + * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
| 1462 | + * exists |
|
| 1463 | + * |
|
| 1464 | + * @param string $guid_in_old_event |
|
| 1465 | + * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
| 1466 | + */ |
|
| 1467 | + private function _get_original_guid($guid_in_old_event) |
|
| 1468 | + { |
|
| 1469 | + $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
| 1470 | + //do a head request to verify the file exists |
|
| 1471 | + $head_response = wp_remote_head($original_guid); |
|
| 1472 | + if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
| 1473 | + return $original_guid; |
|
| 1474 | + } else { |
|
| 1475 | + return $guid_in_old_event; |
|
| 1476 | + } |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
| 1483 | + * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
| 1484 | + * thumbnails) |
|
| 1485 | + * |
|
| 1486 | + * @param type $guid |
|
| 1487 | + * @param EE_Data_Migration_Script_Stage $migration_stage |
|
| 1488 | + * @return int |
|
| 1489 | + */ |
|
| 1490 | + private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
| 1491 | + { |
|
| 1492 | + if ( ! $guid) { |
|
| 1493 | + $migration_stage->add_error(sprintf(__("Cannot create image attachment for a blank GUID!", |
|
| 1494 | + "event_espresso"))); |
|
| 1495 | + return 0; |
|
| 1496 | + } |
|
| 1497 | + $wp_filetype = wp_check_filetype(basename($guid), null); |
|
| 1498 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1499 | + //if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
| 1500 | + if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
| 1501 | + //image is located remotely. download it and place it in the uploads directory |
|
| 1502 | + if ( ! is_readable($guid)) { |
|
| 1503 | + $migration_stage->add_error(sprintf(__("Could not create image attachment from non-existent file: %s", |
|
| 1504 | + "event_espresso"), $guid)); |
|
| 1505 | + return 0; |
|
| 1506 | + } |
|
| 1507 | + $contents = file_get_contents($guid); |
|
| 1508 | + if ($contents === false) { |
|
| 1509 | + $migration_stage->add_error(sprintf(__("Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
| 1510 | + "event_espresso"), $guid)); |
|
| 1511 | + return false; |
|
| 1512 | + } |
|
| 1513 | + $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
| 1514 | + $savefile = fopen($local_filepath, 'w'); |
|
| 1515 | + fwrite($savefile, $contents); |
|
| 1516 | + fclose($savefile); |
|
| 1517 | + $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
| 1518 | + } else { |
|
| 1519 | + $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
| 1520 | + } |
|
| 1521 | + $attachment = array( |
|
| 1522 | + 'guid' => $guid, |
|
| 1523 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1524 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
| 1525 | + 'post_content' => '', |
|
| 1526 | + 'post_status' => 'inherit', |
|
| 1527 | + ); |
|
| 1528 | + $attach_id = wp_insert_attachment($attachment, $guid); |
|
| 1529 | + if ( ! $attach_id) { |
|
| 1530 | + $migration_stage->add_error(sprintf(__("Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
| 1531 | + "event_espresso"), $guid, $this->_json_encode($attachment))); |
|
| 1532 | + return $attach_id; |
|
| 1533 | + } |
|
| 1534 | + // you must first include the image.php file |
|
| 1535 | + // for the function wp_generate_attachment_metadata() to work |
|
| 1536 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1537 | + $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
| 1538 | + if ( ! $attach_data) { |
|
| 1539 | + $migration_stage->add_error(sprintf(__("Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
| 1540 | + "event_espresso"), $attach_id, $local_filepath, $guid)); |
|
| 1541 | + return $attach_id; |
|
| 1542 | + } |
|
| 1543 | + $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1544 | + if ( ! $metadata_save_result) { |
|
| 1545 | + $migration_stage->add_error(sprintf(__("Could not update attachment metadata for attachment %d with data %s", |
|
| 1546 | + "event_espresso"), $attach_id, $this->_json_encode($attach_data))); |
|
| 1547 | + } |
|
| 1548 | + return $attach_id; |
|
| 1549 | + } |
|
| 1550 | + |
|
| 1551 | + |
|
| 1552 | + |
|
| 1553 | + /** |
|
| 1554 | + * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
| 1555 | + * and returns its ID. |
|
| 1556 | + * |
|
| 1557 | + * @global type $wpdb |
|
| 1558 | + * @param string $guid |
|
| 1559 | + * @return int |
|
| 1560 | + */ |
|
| 1561 | + private function _get_image_attachment_id_by_GUID($guid) |
|
| 1562 | + { |
|
| 1563 | + global $wpdb; |
|
| 1564 | + $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
| 1565 | + return $attachment_id; |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
| 1572 | + * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
| 1573 | + * |
|
| 1574 | + * @param EE_Data_Migration_Script_base $stage |
|
| 1575 | + * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
| 1576 | + * UTC time for |
|
| 1577 | + * @param string $DATETIME_string |
|
| 1578 | + * @param string $timezone |
|
| 1579 | + * @return string |
|
| 1580 | + */ |
|
| 1581 | + public function convert_date_string_to_utc( |
|
| 1582 | + EE_Data_Migration_Script_Stage $stage, |
|
| 1583 | + $row_of_data, |
|
| 1584 | + $DATETIME_string, |
|
| 1585 | + $timezone = null |
|
| 1586 | + ) { |
|
| 1587 | + $original_tz = $timezone; |
|
| 1588 | + if ( ! $timezone) { |
|
| 1589 | + $timezone = $this->_get_wp_timezone(); |
|
| 1590 | + } |
|
| 1591 | + if ( ! $timezone) { |
|
| 1592 | + $stage->add_error(sprintf(__("Could not find timezone given %s for %s", "event_espresso"), $original_tz, |
|
| 1593 | + $row_of_data)); |
|
| 1594 | + $timezone = 'UTC'; |
|
| 1595 | + } |
|
| 1596 | + try { |
|
| 1597 | + $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
| 1598 | + $date_obj->setTimezone(new DateTimeZone('UTC')); |
|
| 1599 | + } catch (Exception $e) { |
|
| 1600 | + $stage->add_error(sprintf(__("Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
| 1601 | + "event_espresso"), $DATETIME_string, $timezone)); |
|
| 1602 | + $date_obj = new DateTime(); |
|
| 1603 | + } |
|
| 1604 | + return $date_obj->format('Y-m-d H:i:s'); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
| 1611 | + * |
|
| 1612 | + * @return string |
|
| 1613 | + */ |
|
| 1614 | + private function _get_wp_timezone() |
|
| 1615 | + { |
|
| 1616 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
| 1617 | + //if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
| 1618 | + if (empty($timezone)) { |
|
| 1619 | + //let's get a the WordPress UTC offset |
|
| 1620 | + $offset = get_option('gmt_offset'); |
|
| 1621 | + $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
| 1622 | + } |
|
| 1623 | + return $timezone; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + |
|
| 1627 | + |
|
| 1628 | + /** |
|
| 1629 | + * Gets the wordpress timezone string from a UTC offset |
|
| 1630 | + * |
|
| 1631 | + * @param int $offset |
|
| 1632 | + * @return boolean |
|
| 1633 | + */ |
|
| 1634 | + private function timezone_convert_to_string_from_offset($offset) |
|
| 1635 | + { |
|
| 1636 | + //shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
| 1637 | + $offset *= 3600; // convert hour offset to seconds |
|
| 1638 | + $abbrarray = timezone_abbreviations_list(); |
|
| 1639 | + foreach ($abbrarray as $abbr) { |
|
| 1640 | + foreach ($abbr as $city) { |
|
| 1641 | + if ($city['offset'] == $offset) { |
|
| 1642 | + return $city['timezone_id']; |
|
| 1643 | + } |
|
| 1644 | + } |
|
| 1645 | + } |
|
| 1646 | + return false; |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + |
|
| 1650 | + |
|
| 1651 | + public function migration_page_hooks() |
|
| 1652 | + { |
|
| 1653 | + add_filter( |
|
| 1654 | + 'FHEE__ee_migration_page__header', |
|
| 1655 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1656 | + 10, |
|
| 1657 | + 3 |
|
| 1658 | + ); |
|
| 1659 | + add_filter( |
|
| 1660 | + 'FHEE__ee_migration_page__p_after_header', |
|
| 1661 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1662 | + 10, |
|
| 1663 | + 2 |
|
| 1664 | + ); |
|
| 1665 | + add_filter( |
|
| 1666 | + 'FHEE__ee_migration_page__option_1_main', |
|
| 1667 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1668 | + 10, |
|
| 1669 | + 3 |
|
| 1670 | + ); |
|
| 1671 | + add_filter( |
|
| 1672 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
| 1673 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1674 | + 10, |
|
| 1675 | + 3 |
|
| 1676 | + ); |
|
| 1677 | + add_action( |
|
| 1678 | + 'AHEE__ee_migration_page__option_1_extra_details', |
|
| 1679 | + array($this, '_migration_page_hook_option_1_extra_details'), |
|
| 1680 | + 10, |
|
| 1681 | + 3 |
|
| 1682 | + ); |
|
| 1683 | + add_filter( |
|
| 1684 | + 'FHEE__ee_migration_page__option_2_main', |
|
| 1685 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
| 1686 | + 10, |
|
| 1687 | + 4 |
|
| 1688 | + ); |
|
| 1689 | + add_filter( |
|
| 1690 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
| 1691 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1692 | + 10, |
|
| 1693 | + 2 |
|
| 1694 | + ); |
|
| 1695 | + add_filter( |
|
| 1696 | + 'FHEE__ee_migration_page__option_2_details', |
|
| 1697 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1698 | + 10, |
|
| 1699 | + 2 |
|
| 1700 | + ); |
|
| 1701 | + add_action( |
|
| 1702 | + 'AHEE__ee_migration_page__after_migration_options_table', |
|
| 1703 | + array($this, '_migration_page_hook_after_migration_options_table') |
|
| 1704 | + ); |
|
| 1705 | + add_filter( |
|
| 1706 | + 'FHEE__ee_migration_page__done_migration_header', |
|
| 1707 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1708 | + 10, |
|
| 1709 | + 2 |
|
| 1710 | + ); |
|
| 1711 | + add_filter( |
|
| 1712 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 1713 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
| 1714 | + 10, |
|
| 1715 | + 2 |
|
| 1716 | + ); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + public function _migrate_page_hook_simplify_version_strings( |
|
| 1722 | + $old_content, |
|
| 1723 | + $current_db_state, |
|
| 1724 | + $next_db_state, |
|
| 1725 | + $ultimate_db_state = null |
|
| 1726 | + ) { |
|
| 1727 | + return str_replace(array($current_db_state, $next_db_state, $ultimate_db_state), |
|
| 1728 | + array(__('EE3', 'event_espresso'), __('EE4', 'event_espresso'), __("EE4", 'event_espresso')), |
|
| 1729 | + $old_content); |
|
| 1730 | + } |
|
| 1731 | + |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
| 1735 | + { |
|
| 1736 | + return str_replace($next_db_state, __("EE4", 'event_espresso'), $old_content); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + |
|
| 1741 | + public function _migration_page_hook_option_1_extra_details() |
|
| 1742 | + { |
|
| 1743 | + ?> |
|
| 1744 | 1744 | <p><?php printf(__("Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
| 1745 | - "event_espresso")); ?></p><?php |
|
| 1746 | - } |
|
| 1745 | + "event_espresso")); ?></p><?php |
|
| 1746 | + } |
|
| 1747 | 1747 | |
| 1748 | 1748 | |
| 1749 | 1749 | |
| 1750 | - public function _migration_page_hook_after_migration_options_table() |
|
| 1751 | - { |
|
| 1752 | - ?><p class="ee-attention"> |
|
| 1750 | + public function _migration_page_hook_after_migration_options_table() |
|
| 1751 | + { |
|
| 1752 | + ?><p class="ee-attention"> |
|
| 1753 | 1753 | <strong><span class="reminder-spn"><?php _e("Important note to those using Event Espresso 3 addons: ", |
| 1754 | - "event_espresso"); ?></span></strong> |
|
| 1754 | + "event_espresso"); ?></span></strong> |
|
| 1755 | 1755 | <br/><?php _e("Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
| 1756 | - "event_espresso"); ?> |
|
| 1756 | + "event_espresso"); ?> |
|
| 1757 | 1757 | </p><?php |
| 1758 | - } |
|
| 1758 | + } |
|
| 1759 | 1759 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | //unfortunately, this needs to be done upon INCLUSION of this file, |
| 10 | 10 | //instead of construction, because it only gets constructed on first page load |
| 11 | 11 | //(all other times it gets resurrected from a wordpress option) |
| 12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
|
| 12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_1_0_stages/*'); |
|
| 13 | 13 | $class_to_filepath = array(); |
| 14 | 14 | if ( ! empty($stages)) { |
| 15 | 15 | foreach ($stages as $filepath) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | private function _checkin_table_exists() |
| 88 | 88 | { |
| 89 | 89 | global $wpdb; |
| 90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
| 90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix."events_attendee_checkin"."'"); |
|
| 91 | 91 | if ($results) { |
| 92 | 92 | return true; |
| 93 | 93 | } else { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | // echo "no version string provided: $version_string"; |
| 108 | 108 | //no version string provided... this must be pre 4.1 |
| 109 | 109 | //because since 4.1 we're |
| 110 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
| 110 | + return false; //changed mind. dont want people thinking they should migrate yet because they cant |
|
| 111 | 111 | } else { |
| 112 | 112 | // echo "$version_string doesnt apply"; |
| 113 | 113 | return false; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | public function schema_changes_before_migration() |
| 127 | 127 | { |
| 128 | 128 | //relies on 4.1's EEH_Activation::create_table |
| 129 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 129 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
| 130 | 130 | $table_name = 'esp_answer'; |
| 131 | 131 | $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 132 | 132 | REG_ID INT UNSIGNED NOT NULL, |
@@ -510,12 +510,12 @@ discard block |
||
| 510 | 510 | public function insert_default_states() |
| 511 | 511 | { |
| 512 | 512 | global $wpdb; |
| 513 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 513 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 514 | 514 | if ($this->_get_table_analysis()->tableExists($state_table)) { |
| 515 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
| 515 | + $SQL = "SELECT COUNT('STA_ID') FROM ".$state_table; |
|
| 516 | 516 | $states = $wpdb->get_var($SQL); |
| 517 | 517 | if ( ! $states) { |
| 518 | - $SQL = "INSERT INTO " . $state_table . " |
|
| 518 | + $SQL = "INSERT INTO ".$state_table." |
|
| 519 | 519 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
| 520 | 520 | (1, 'US', 'AK', 'Alaska', 1), |
| 521 | 521 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -603,12 +603,12 @@ discard block |
||
| 603 | 603 | public function insert_default_countries() |
| 604 | 604 | { |
| 605 | 605 | global $wpdb; |
| 606 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 606 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 607 | 607 | if ($this->_get_table_analysis()->tableExists($country_table)) { |
| 608 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
| 608 | + $SQL = "SELECT COUNT('CNT_ISO') FROM ".$country_table; |
|
| 609 | 609 | $countries = $wpdb->get_var($SQL); |
| 610 | 610 | if ( ! $countries) { |
| 611 | - $SQL = "INSERT INTO " . $country_table . " |
|
| 611 | + $SQL = "INSERT INTO ".$country_table." |
|
| 612 | 612 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
| 613 | 613 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
| 614 | 614 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -853,17 +853,17 @@ discard block |
||
| 853 | 853 | public function insert_default_price_types() |
| 854 | 854 | { |
| 855 | 855 | global $wpdb; |
| 856 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 856 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
| 857 | 857 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
| 858 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
| 858 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table; |
|
| 859 | 859 | $price_types_exist = $wpdb->get_var($SQL); |
| 860 | 860 | if ( ! $price_types_exist) { |
| 861 | 861 | $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
| 862 | - (1, '" . __('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
|
| 863 | - (2, '" . __('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
|
| 864 | - (3, '" . __('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
|
| 865 | - (4, '" . __('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
|
| 866 | - (5, '" . __('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
|
| 862 | + (1, '".__('Base Price', 'event_espresso')."', 1, 0, 0, 0), |
|
| 863 | + (2, '" . __('Percent Discount', 'event_espresso')."', 2, 1, 20, 0), |
|
| 864 | + (3, '" . __('Fixed Discount', 'event_espresso')."', 2, 0, 30, 0), |
|
| 865 | + (4, '" . __('Percent Surcharge', 'event_espresso')."', 3, 1, 40, 0), |
|
| 866 | + (5, '" . __('Fixed Surcharge', 'event_espresso')."', 3, 0, 50, 0);"; |
|
| 867 | 867 | $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
| 868 | 868 | $wpdb->query($SQL); |
| 869 | 869 | } |
@@ -885,9 +885,9 @@ discard block |
||
| 885 | 885 | public function insert_default_prices() |
| 886 | 886 | { |
| 887 | 887 | global $wpdb; |
| 888 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 888 | + $price_table = $wpdb->prefix."esp_price"; |
|
| 889 | 889 | if ($this->_get_table_analysis()->tableExists($price_table)) { |
| 890 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
| 890 | + $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table; |
|
| 891 | 891 | $prices_exist = $wpdb->get_var($SQL); |
| 892 | 892 | if ( ! $prices_exist) { |
| 893 | 893 | $SQL = "INSERT INTO $price_table |
@@ -911,9 +911,9 @@ discard block |
||
| 911 | 911 | public function insert_default_tickets() |
| 912 | 912 | { |
| 913 | 913 | global $wpdb; |
| 914 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
| 914 | + $ticket_table = $wpdb->prefix."esp_ticket"; |
|
| 915 | 915 | if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
| 916 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
| 916 | + $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table; |
|
| 917 | 917 | $tickets_exist = $wpdb->get_var($SQL); |
| 918 | 918 | if ( ! $tickets_exist) { |
| 919 | 919 | $SQL = "INSERT INTO $ticket_table |
@@ -925,9 +925,9 @@ discard block |
||
| 925 | 925 | $wpdb->query($SQL); |
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
| 928 | + $ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
| 929 | 929 | if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
| 930 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
| 930 | + $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table; |
|
| 931 | 931 | $ticket_prc_exist = $wpdb->get_var($SQL); |
| 932 | 932 | if ( ! $ticket_prc_exist) { |
| 933 | 933 | $SQL = "INSERT INTO $ticket_price_table |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | throw new EE_Error(__("Could not get a country because country name is blank", "event_espresso")); |
| 958 | 958 | } |
| 959 | 959 | global $wpdb; |
| 960 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 960 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 961 | 961 | if (is_int($country_name)) { |
| 962 | 962 | $country_name = $this->get_iso_from_3_1_country_id($country_name); |
| 963 | 963 | } |
@@ -985,21 +985,21 @@ discard block |
||
| 985 | 985 | 'CNT_active' => true, |
| 986 | 986 | ); |
| 987 | 987 | $data_types = array( |
| 988 | - '%s',//CNT_ISO |
|
| 989 | - '%s',//CNT_ISO3 |
|
| 990 | - '%d',//RGN_ID |
|
| 991 | - '%s',//CNT_name |
|
| 992 | - '%s',//CNT_cur_code |
|
| 993 | - '%s',//CNT_cur_single |
|
| 994 | - '%s',//CNT_cur_plural |
|
| 995 | - '%s',//CNT_cur_sign |
|
| 996 | - '%d',//CNT_cur_sign_b4 |
|
| 997 | - '%d',//CNT_cur_dec_plc |
|
| 998 | - '%s',//CNT_cur_dec_mrk |
|
| 999 | - '%s',//CNT_cur_thsnds |
|
| 1000 | - '%s',//CNT_tel_code |
|
| 1001 | - '%d',//CNT_is_EU |
|
| 1002 | - '%d',//CNT_active |
|
| 988 | + '%s', //CNT_ISO |
|
| 989 | + '%s', //CNT_ISO3 |
|
| 990 | + '%d', //RGN_ID |
|
| 991 | + '%s', //CNT_name |
|
| 992 | + '%s', //CNT_cur_code |
|
| 993 | + '%s', //CNT_cur_single |
|
| 994 | + '%s', //CNT_cur_plural |
|
| 995 | + '%s', //CNT_cur_sign |
|
| 996 | + '%d', //CNT_cur_sign_b4 |
|
| 997 | + '%d', //CNT_cur_dec_plc |
|
| 998 | + '%s', //CNT_cur_dec_mrk |
|
| 999 | + '%s', //CNT_cur_thsnds |
|
| 1000 | + '%s', //CNT_tel_code |
|
| 1001 | + '%d', //CNT_is_EU |
|
| 1002 | + '%d', //CNT_active |
|
| 1003 | 1003 | ); |
| 1004 | 1004 | $success = $wpdb->insert($country_table, |
| 1005 | 1005 | $cols_n_values, |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | private function _find_available_country_iso($num_letters = 2) |
| 1025 | 1025 | { |
| 1026 | 1026 | global $wpdb; |
| 1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
| 1027 | + $country_table = $wpdb->prefix."esp_country"; |
|
| 1028 | 1028 | $attempts = 0; |
| 1029 | 1029 | do { |
| 1030 | 1030 | $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | //keep going until we find an available country code, or we arbitrarily |
| 1036 | 1036 | //decide we've tried this enough. Somehow they have way too many countries |
| 1037 | 1037 | //(probably because they're mis-using the EE3 country_id like a custom question) |
| 1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1038 | + }while (intval($country_with_that_iso) && $attempts < 200); |
|
| 1039 | 1039 | return $current_iso; |
| 1040 | 1040 | } |
| 1041 | 1041 | |
@@ -1062,7 +1062,7 @@ discard block |
||
| 1062 | 1062 | $country_iso = $this->get_default_country_iso(); |
| 1063 | 1063 | } |
| 1064 | 1064 | global $wpdb; |
| 1065 | - $state_table = $wpdb->prefix . "esp_state"; |
|
| 1065 | + $state_table = $wpdb->prefix."esp_state"; |
|
| 1066 | 1066 | $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
| 1067 | 1067 | (STA_abbrev LIKE %s OR |
| 1068 | 1068 | STA_name LIKE %s) AND |
@@ -1076,10 +1076,10 @@ discard block |
||
| 1076 | 1076 | 'STA_active' => true, |
| 1077 | 1077 | ); |
| 1078 | 1078 | $data_types = array( |
| 1079 | - '%s',//CNT_ISO |
|
| 1080 | - '%s',//STA_abbrev |
|
| 1081 | - '%s',//STA_name |
|
| 1082 | - '%d',//STA_active |
|
| 1079 | + '%s', //CNT_ISO |
|
| 1080 | + '%s', //STA_abbrev |
|
| 1081 | + '%s', //STA_name |
|
| 1082 | + '%d', //STA_active |
|
| 1083 | 1083 | ); |
| 1084 | 1084 | $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
| 1085 | 1085 | if ( ! $success) { |
@@ -1510,7 +1510,7 @@ discard block |
||
| 1510 | 1510 | "event_espresso"), $guid)); |
| 1511 | 1511 | return false; |
| 1512 | 1512 | } |
| 1513 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
| 1513 | + $local_filepath = $wp_upload_dir['path'].DS.basename($guid); |
|
| 1514 | 1514 | $savefile = fopen($local_filepath, 'w'); |
| 1515 | 1515 | fwrite($savefile, $contents); |
| 1516 | 1516 | fclose($savefile); |
@@ -1533,7 +1533,7 @@ discard block |
||
| 1533 | 1533 | } |
| 1534 | 1534 | // you must first include the image.php file |
| 1535 | 1535 | // for the function wp_generate_attachment_metadata() to work |
| 1536 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 1536 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
| 1537 | 1537 | $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
| 1538 | 1538 | if ( ! $attach_data) { |
| 1539 | 1539 | $migration_stage->add_error(sprintf(__("Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @since 4.5.0 |
| 806 | 806 | * |
| 807 | 807 | * @param string $meta_cap What meta capability is this mapping. |
| 808 | - * @param array $map_values array { |
|
| 808 | + * @param string[] $map_values array { |
|
| 809 | 809 | * //array of values that MUST match a count of 4. It's okay to send an empty string for |
| 810 | 810 | * capabilities that don't get mapped to. |
| 811 | 811 | * |
@@ -880,8 +880,8 @@ discard block |
||
| 880 | 880 | * @since 4.6.x |
| 881 | 881 | * |
| 882 | 882 | * @param $caps |
| 883 | - * @param $cap |
|
| 884 | - * @param $user_id |
|
| 883 | + * @param string $cap |
|
| 884 | + * @param integer $user_id |
|
| 885 | 885 | * @param $args |
| 886 | 886 | * |
| 887 | 887 | * @return array |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @subpackage core, capabilities |
| 9 | 9 | */ |
| 10 | 10 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 11 | - exit('No direct script access allowed'); |
|
| 11 | + exit('No direct script access allowed'); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | |
@@ -27,751 +27,751 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * instance of EE_Capabilities object |
|
| 32 | - * |
|
| 33 | - * @var EE_Capabilities |
|
| 34 | - */ |
|
| 35 | - private static $_instance = null; |
|
| 30 | + /** |
|
| 31 | + * instance of EE_Capabilities object |
|
| 32 | + * |
|
| 33 | + * @var EE_Capabilities |
|
| 34 | + */ |
|
| 35 | + private static $_instance = null; |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * This is a map of caps that correspond to a default WP_Role. |
|
| 40 | - * Array is indexed by Role and values are ee capabilities. |
|
| 41 | - * |
|
| 42 | - * @since 4.5.0 |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - private $_caps_map = array(); |
|
| 38 | + /** |
|
| 39 | + * This is a map of caps that correspond to a default WP_Role. |
|
| 40 | + * Array is indexed by Role and values are ee capabilities. |
|
| 41 | + * |
|
| 42 | + * @since 4.5.0 |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + private $_caps_map = array(); |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for |
|
| 51 | - * a user depending on context. |
|
| 52 | - * |
|
| 53 | - * @var EE_Meta_Capability_Map[] |
|
| 54 | - */ |
|
| 55 | - private $_meta_caps = array(); |
|
| 49 | + /** |
|
| 50 | + * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for |
|
| 51 | + * a user depending on context. |
|
| 52 | + * |
|
| 53 | + * @var EE_Meta_Capability_Map[] |
|
| 54 | + */ |
|
| 55 | + private $_meta_caps = array(); |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * the name of the wp option used to store caps previously initialized |
|
| 59 | - */ |
|
| 60 | - const option_name = 'ee_caps_initialized'; |
|
| 57 | + /** |
|
| 58 | + * the name of the wp option used to store caps previously initialized |
|
| 59 | + */ |
|
| 60 | + const option_name = 'ee_caps_initialized'; |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * singleton method used to instantiate class object |
|
| 65 | - * |
|
| 66 | - * @since 4.5.0 |
|
| 67 | - * |
|
| 68 | - * @return EE_Capabilities |
|
| 69 | - */ |
|
| 70 | - public static function instance() |
|
| 71 | - { |
|
| 72 | - //check if instantiated, and if not do so. |
|
| 73 | - if ( ! self::$_instance instanceof EE_Capabilities) { |
|
| 74 | - self::$_instance = new self(); |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * singleton method used to instantiate class object |
|
| 65 | + * |
|
| 66 | + * @since 4.5.0 |
|
| 67 | + * |
|
| 68 | + * @return EE_Capabilities |
|
| 69 | + */ |
|
| 70 | + public static function instance() |
|
| 71 | + { |
|
| 72 | + //check if instantiated, and if not do so. |
|
| 73 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
| 74 | + self::$_instance = new self(); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return self::$_instance; |
|
| 78 | - } |
|
| 77 | + return self::$_instance; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * private constructor |
|
| 83 | - * |
|
| 84 | - * @since 4.5.0 |
|
| 85 | - * |
|
| 86 | - * @return \EE_Capabilities |
|
| 87 | - */ |
|
| 88 | - private function __construct() |
|
| 89 | - { |
|
| 90 | - } |
|
| 81 | + /** |
|
| 82 | + * private constructor |
|
| 83 | + * |
|
| 84 | + * @since 4.5.0 |
|
| 85 | + * |
|
| 86 | + * @return \EE_Capabilities |
|
| 87 | + */ |
|
| 88 | + private function __construct() |
|
| 89 | + { |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 95 | - * |
|
| 96 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 97 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 98 | - * ensures that they are up to date. |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @since 4.5.0 |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function init_caps($reset = false) |
|
| 105 | - { |
|
| 106 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 107 | - $this->_caps_map = $this->_init_caps_map(); |
|
| 108 | - $this->init_role_caps($reset); |
|
| 109 | - $this->_set_meta_caps(); |
|
| 110 | - } |
|
| 111 | - } |
|
| 93 | + /** |
|
| 94 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 95 | + * |
|
| 96 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 97 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 98 | + * ensures that they are up to date. |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @since 4.5.0 |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function init_caps($reset = false) |
|
| 105 | + { |
|
| 106 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 107 | + $this->_caps_map = $this->_init_caps_map(); |
|
| 108 | + $this->init_role_caps($reset); |
|
| 109 | + $this->_set_meta_caps(); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * This sets the meta caps property. |
|
| 116 | - * @since 4.5.0 |
|
| 117 | - * |
|
| 118 | - * @return void |
|
| 119 | - */ |
|
| 120 | - private function _set_meta_caps() |
|
| 121 | - { |
|
| 122 | - //make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 123 | - $this->_meta_caps = $this->_get_default_meta_caps_array(); |
|
| 114 | + /** |
|
| 115 | + * This sets the meta caps property. |
|
| 116 | + * @since 4.5.0 |
|
| 117 | + * |
|
| 118 | + * @return void |
|
| 119 | + */ |
|
| 120 | + private function _set_meta_caps() |
|
| 121 | + { |
|
| 122 | + //make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 123 | + $this->_meta_caps = $this->_get_default_meta_caps_array(); |
|
| 124 | 124 | |
| 125 | - $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
|
| 125 | + $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
|
| 126 | 126 | |
| 127 | - //add filter for map_meta_caps but only if models can query. |
|
| 128 | - if (EE_Maintenance_Mode::instance()->models_can_query() && ! has_filter('map_meta_cap', |
|
| 129 | - array($this, 'map_meta_caps')) |
|
| 130 | - ) { |
|
| 131 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 132 | - } |
|
| 133 | - } |
|
| 127 | + //add filter for map_meta_caps but only if models can query. |
|
| 128 | + if (EE_Maintenance_Mode::instance()->models_can_query() && ! has_filter('map_meta_cap', |
|
| 129 | + array($this, 'map_meta_caps')) |
|
| 130 | + ) { |
|
| 131 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * This builds and returns the default meta_caps array only once. |
|
| 138 | - * |
|
| 139 | - * @since 4.8.28.rc.012 |
|
| 140 | - * @return array |
|
| 141 | - */ |
|
| 142 | - private function _get_default_meta_caps_array() |
|
| 143 | - { |
|
| 144 | - static $default_meta_caps = array(); |
|
| 145 | - if (empty($default_meta_caps)) { |
|
| 146 | - $default_meta_caps = array( |
|
| 147 | - //edits |
|
| 148 | - new EE_Meta_Capability_Map_Edit('ee_edit_event', |
|
| 149 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')), |
|
| 150 | - new EE_Meta_Capability_Map_Edit('ee_edit_venue', |
|
| 151 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')), |
|
| 152 | - new EE_Meta_Capability_Map_Edit('ee_edit_registration', |
|
| 153 | - array('Registration', '', 'ee_edit_others_registrations', '')), |
|
| 154 | - new EE_Meta_Capability_Map_Edit('ee_edit_checkin', |
|
| 155 | - array('Registration', '', 'ee_edit_others_checkins', '')), |
|
| 156 | - new EE_Meta_Capability_Map_Messages_Cap('ee_edit_message', |
|
| 157 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')), |
|
| 158 | - new EE_Meta_Capability_Map_Edit('ee_edit_default_ticket', |
|
| 159 | - array('Ticket', '', 'ee_edit_others_default_tickets', '')), |
|
| 160 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question', |
|
| 161 | - array('Question', '', '', 'ee_edit_system_questions')), |
|
| 162 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question_group', |
|
| 163 | - array('Question_Group', '', '', 'ee_edit_system_question_groups')), |
|
| 164 | - new EE_Meta_Capability_Map_Edit('ee_edit_payment_method', |
|
| 165 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '')), |
|
| 166 | - //reads |
|
| 167 | - new EE_Meta_Capability_Map_Read('ee_read_event', |
|
| 168 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events')), |
|
| 169 | - new EE_Meta_Capability_Map_Read('ee_read_venue', |
|
| 170 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')), |
|
| 171 | - new EE_Meta_Capability_Map_Read('ee_read_registration', |
|
| 172 | - array('Registration', '', '', 'ee_edit_others_registrations')), |
|
| 173 | - new EE_Meta_Capability_Map_Read('ee_read_checkin', |
|
| 174 | - array('Registration', '', '', 'ee_read_others_checkins')), |
|
| 175 | - new EE_Meta_Capability_Map_Messages_Cap('ee_read_message', |
|
| 176 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')), |
|
| 177 | - new EE_Meta_Capability_Map_Read('ee_read_default_ticket', |
|
| 178 | - array('Ticket', '', '', 'ee_read_others_default_tickets')), |
|
| 179 | - new EE_Meta_Capability_Map_Read('ee_read_payment_method', |
|
| 180 | - array('Payment_Method', '', '', 'ee_read_others_payment_methods')), |
|
| 136 | + /** |
|
| 137 | + * This builds and returns the default meta_caps array only once. |
|
| 138 | + * |
|
| 139 | + * @since 4.8.28.rc.012 |
|
| 140 | + * @return array |
|
| 141 | + */ |
|
| 142 | + private function _get_default_meta_caps_array() |
|
| 143 | + { |
|
| 144 | + static $default_meta_caps = array(); |
|
| 145 | + if (empty($default_meta_caps)) { |
|
| 146 | + $default_meta_caps = array( |
|
| 147 | + //edits |
|
| 148 | + new EE_Meta_Capability_Map_Edit('ee_edit_event', |
|
| 149 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')), |
|
| 150 | + new EE_Meta_Capability_Map_Edit('ee_edit_venue', |
|
| 151 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')), |
|
| 152 | + new EE_Meta_Capability_Map_Edit('ee_edit_registration', |
|
| 153 | + array('Registration', '', 'ee_edit_others_registrations', '')), |
|
| 154 | + new EE_Meta_Capability_Map_Edit('ee_edit_checkin', |
|
| 155 | + array('Registration', '', 'ee_edit_others_checkins', '')), |
|
| 156 | + new EE_Meta_Capability_Map_Messages_Cap('ee_edit_message', |
|
| 157 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')), |
|
| 158 | + new EE_Meta_Capability_Map_Edit('ee_edit_default_ticket', |
|
| 159 | + array('Ticket', '', 'ee_edit_others_default_tickets', '')), |
|
| 160 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question', |
|
| 161 | + array('Question', '', '', 'ee_edit_system_questions')), |
|
| 162 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question_group', |
|
| 163 | + array('Question_Group', '', '', 'ee_edit_system_question_groups')), |
|
| 164 | + new EE_Meta_Capability_Map_Edit('ee_edit_payment_method', |
|
| 165 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '')), |
|
| 166 | + //reads |
|
| 167 | + new EE_Meta_Capability_Map_Read('ee_read_event', |
|
| 168 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events')), |
|
| 169 | + new EE_Meta_Capability_Map_Read('ee_read_venue', |
|
| 170 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')), |
|
| 171 | + new EE_Meta_Capability_Map_Read('ee_read_registration', |
|
| 172 | + array('Registration', '', '', 'ee_edit_others_registrations')), |
|
| 173 | + new EE_Meta_Capability_Map_Read('ee_read_checkin', |
|
| 174 | + array('Registration', '', '', 'ee_read_others_checkins')), |
|
| 175 | + new EE_Meta_Capability_Map_Messages_Cap('ee_read_message', |
|
| 176 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')), |
|
| 177 | + new EE_Meta_Capability_Map_Read('ee_read_default_ticket', |
|
| 178 | + array('Ticket', '', '', 'ee_read_others_default_tickets')), |
|
| 179 | + new EE_Meta_Capability_Map_Read('ee_read_payment_method', |
|
| 180 | + array('Payment_Method', '', '', 'ee_read_others_payment_methods')), |
|
| 181 | 181 | |
| 182 | - //deletes |
|
| 183 | - new EE_Meta_Capability_Map_Delete('ee_delete_event', array( |
|
| 184 | - 'Event', |
|
| 185 | - 'ee_delete_published_events', |
|
| 186 | - 'ee_delete_others_events', |
|
| 187 | - 'ee_delete_private_events' |
|
| 188 | - )), |
|
| 189 | - new EE_Meta_Capability_Map_Delete('ee_delete_venue', array( |
|
| 190 | - 'Venue', |
|
| 191 | - 'ee_delete_published_venues', |
|
| 192 | - 'ee_delete_others_venues', |
|
| 193 | - 'ee_delete_private_venues' |
|
| 194 | - )), |
|
| 195 | - new EE_Meta_Capability_Map_Delete('ee_delete_registration', |
|
| 196 | - array('Registration', '', 'ee_delete_others_registrations', '')), |
|
| 197 | - new EE_Meta_Capability_Map_Delete('ee_delete_checkin', |
|
| 198 | - array('Registration', '', 'ee_delete_others_checkins', '')), |
|
| 199 | - new EE_Meta_Capability_Map_Messages_Cap('ee_delete_message', |
|
| 200 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')), |
|
| 201 | - new EE_Meta_Capability_Map_Delete('ee_delete_default_ticket', |
|
| 202 | - array('Ticket', '', 'ee_delete_others_default_tickets', '')), |
|
| 203 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question', |
|
| 204 | - array('Question', '', '', 'delete_system_questions')), |
|
| 205 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question_group', |
|
| 206 | - array('Question_Group', '', '', 'delete_system_question_groups')), |
|
| 207 | - new EE_Meta_Capability_Map_Delete('ee_delete_payment_method', |
|
| 208 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '')), |
|
| 209 | - ); |
|
| 210 | - } |
|
| 182 | + //deletes |
|
| 183 | + new EE_Meta_Capability_Map_Delete('ee_delete_event', array( |
|
| 184 | + 'Event', |
|
| 185 | + 'ee_delete_published_events', |
|
| 186 | + 'ee_delete_others_events', |
|
| 187 | + 'ee_delete_private_events' |
|
| 188 | + )), |
|
| 189 | + new EE_Meta_Capability_Map_Delete('ee_delete_venue', array( |
|
| 190 | + 'Venue', |
|
| 191 | + 'ee_delete_published_venues', |
|
| 192 | + 'ee_delete_others_venues', |
|
| 193 | + 'ee_delete_private_venues' |
|
| 194 | + )), |
|
| 195 | + new EE_Meta_Capability_Map_Delete('ee_delete_registration', |
|
| 196 | + array('Registration', '', 'ee_delete_others_registrations', '')), |
|
| 197 | + new EE_Meta_Capability_Map_Delete('ee_delete_checkin', |
|
| 198 | + array('Registration', '', 'ee_delete_others_checkins', '')), |
|
| 199 | + new EE_Meta_Capability_Map_Messages_Cap('ee_delete_message', |
|
| 200 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')), |
|
| 201 | + new EE_Meta_Capability_Map_Delete('ee_delete_default_ticket', |
|
| 202 | + array('Ticket', '', 'ee_delete_others_default_tickets', '')), |
|
| 203 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question', |
|
| 204 | + array('Question', '', '', 'delete_system_questions')), |
|
| 205 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question_group', |
|
| 206 | + array('Question_Group', '', '', 'delete_system_question_groups')), |
|
| 207 | + new EE_Meta_Capability_Map_Delete('ee_delete_payment_method', |
|
| 208 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '')), |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - return $default_meta_caps; |
|
| 213 | - } |
|
| 212 | + return $default_meta_caps; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 218 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 219 | - * |
|
| 220 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 221 | - * |
|
| 222 | - * @since 4.5.0 |
|
| 223 | - * @see wp-includes/capabilities.php |
|
| 224 | - * |
|
| 225 | - * @param array $caps actual users capabilities |
|
| 226 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 227 | - * @param int $user_id The user id |
|
| 228 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 229 | - * |
|
| 230 | - * @return array actual users capabilities |
|
| 231 | - */ |
|
| 232 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 233 | - { |
|
| 234 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 235 | - //loop through our _meta_caps array |
|
| 236 | - foreach ($this->_meta_caps as $meta_map) { |
|
| 237 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 238 | - continue; |
|
| 239 | - } |
|
| 240 | - $meta_map->ensure_is_model(); |
|
| 216 | + /** |
|
| 217 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 218 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 219 | + * |
|
| 220 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 221 | + * |
|
| 222 | + * @since 4.5.0 |
|
| 223 | + * @see wp-includes/capabilities.php |
|
| 224 | + * |
|
| 225 | + * @param array $caps actual users capabilities |
|
| 226 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 227 | + * @param int $user_id The user id |
|
| 228 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 229 | + * |
|
| 230 | + * @return array actual users capabilities |
|
| 231 | + */ |
|
| 232 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 233 | + { |
|
| 234 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 235 | + //loop through our _meta_caps array |
|
| 236 | + foreach ($this->_meta_caps as $meta_map) { |
|
| 237 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 238 | + continue; |
|
| 239 | + } |
|
| 240 | + $meta_map->ensure_is_model(); |
|
| 241 | 241 | |
| 242 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 243 | - } |
|
| 244 | - } |
|
| 242 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return $caps; |
|
| 247 | - } |
|
| 246 | + return $caps; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
| 252 | - * |
|
| 253 | - * @since 4.5.0 |
|
| 254 | - * |
|
| 255 | - * @return array |
|
| 256 | - */ |
|
| 257 | - private function _init_caps_map() |
|
| 258 | - { |
|
| 259 | - $caps = array( |
|
| 260 | - 'administrator' => array( |
|
| 261 | - //basic access |
|
| 262 | - 'ee_read_ee', |
|
| 263 | - //gateways |
|
| 264 | - /** |
|
| 265 | - * note that with payment method capabilities, although we've implemented |
|
| 266 | - * capability mapping which will be used for accessing payment methods owned by |
|
| 267 | - * other users. This is not fully implemented yet in the payment method ui. |
|
| 268 | - * Currently only the "plural" caps are in active use. (Specific payment method caps are in use as well). |
|
| 269 | - **/ |
|
| 270 | - 'ee_manage_gateways', |
|
| 271 | - 'ee_read_payment_method', |
|
| 272 | - 'ee_read_payment_methods', |
|
| 273 | - 'ee_read_others_payment_methods', |
|
| 274 | - 'ee_edit_payment_method', |
|
| 275 | - 'ee_edit_payment_methods', |
|
| 276 | - 'ee_edit_others_payment_methods', |
|
| 277 | - 'ee_delete_payment_method', |
|
| 278 | - 'ee_delete_payment_methods', |
|
| 279 | - //events |
|
| 280 | - 'ee_publish_events', |
|
| 281 | - 'ee_read_private_events', |
|
| 282 | - 'ee_read_others_events', |
|
| 283 | - 'ee_read_event', |
|
| 284 | - 'ee_read_events', |
|
| 285 | - 'ee_edit_event', |
|
| 286 | - 'ee_edit_events', |
|
| 287 | - 'ee_edit_published_events', |
|
| 288 | - 'ee_edit_others_events', |
|
| 289 | - 'ee_edit_private_events', |
|
| 290 | - 'ee_delete_published_events', |
|
| 291 | - 'ee_delete_private_events', |
|
| 292 | - 'ee_delete_event', |
|
| 293 | - 'ee_delete_events', |
|
| 294 | - 'ee_delete_others_events', |
|
| 295 | - //event categories |
|
| 296 | - 'ee_manage_event_categories', |
|
| 297 | - 'ee_edit_event_category', |
|
| 298 | - 'ee_delete_event_category', |
|
| 299 | - 'ee_assign_event_category', |
|
| 300 | - //venues |
|
| 301 | - 'ee_publish_venues', |
|
| 302 | - 'ee_read_venue', |
|
| 303 | - 'ee_read_venues', |
|
| 304 | - 'ee_read_others_venues', |
|
| 305 | - 'ee_read_private_venues', |
|
| 306 | - 'ee_edit_venue', |
|
| 307 | - 'ee_edit_venues', |
|
| 308 | - 'ee_edit_others_venues', |
|
| 309 | - 'ee_edit_published_venues', |
|
| 310 | - 'ee_edit_private_venues', |
|
| 311 | - 'ee_delete_venue', |
|
| 312 | - 'ee_delete_venues', |
|
| 313 | - 'ee_delete_others_venues', |
|
| 314 | - 'ee_delete_private_venues', |
|
| 315 | - 'ee_delete_published_venues', |
|
| 316 | - //venue categories |
|
| 317 | - 'ee_manage_venue_categories', |
|
| 318 | - 'ee_edit_venue_category', |
|
| 319 | - 'ee_delete_venue_category', |
|
| 320 | - 'ee_assign_venue_category', |
|
| 321 | - //contacts |
|
| 322 | - 'ee_read_contact', |
|
| 323 | - 'ee_read_contacts', |
|
| 324 | - 'ee_edit_contact', |
|
| 325 | - 'ee_edit_contacts', |
|
| 326 | - 'ee_delete_contact', |
|
| 327 | - 'ee_delete_contacts', |
|
| 328 | - //registrations |
|
| 329 | - 'ee_read_registration', |
|
| 330 | - 'ee_read_registrations', |
|
| 331 | - 'ee_read_others_registrations', |
|
| 332 | - 'ee_edit_registration', |
|
| 333 | - 'ee_edit_registrations', |
|
| 334 | - 'ee_edit_others_registrations', |
|
| 335 | - 'ee_delete_registration', |
|
| 336 | - 'ee_delete_registrations', |
|
| 337 | - //checkins |
|
| 338 | - 'ee_read_checkin', |
|
| 339 | - 'ee_read_others_checkins', |
|
| 340 | - 'ee_read_checkins', |
|
| 341 | - 'ee_edit_checkin', |
|
| 342 | - 'ee_edit_checkins', |
|
| 343 | - 'ee_edit_others_checkins', |
|
| 344 | - 'ee_delete_checkin', |
|
| 345 | - 'ee_delete_checkins', |
|
| 346 | - 'ee_delete_others_checkins', |
|
| 347 | - //transactions && payments |
|
| 348 | - 'ee_read_transaction', |
|
| 349 | - 'ee_read_transactions', |
|
| 350 | - 'ee_edit_payments', |
|
| 351 | - 'ee_delete_payments', |
|
| 352 | - //messages |
|
| 353 | - 'ee_read_message', |
|
| 354 | - 'ee_read_messages', |
|
| 355 | - 'ee_read_others_messages', |
|
| 356 | - 'ee_read_global_messages', |
|
| 357 | - 'ee_edit_global_messages', |
|
| 358 | - 'ee_edit_message', |
|
| 359 | - 'ee_edit_messages', |
|
| 360 | - 'ee_edit_others_messages', |
|
| 361 | - 'ee_delete_message', |
|
| 362 | - 'ee_delete_messages', |
|
| 363 | - 'ee_delete_others_messages', |
|
| 364 | - 'ee_delete_global_messages', |
|
| 365 | - 'ee_send_message', |
|
| 366 | - //tickets |
|
| 367 | - 'ee_read_default_ticket', |
|
| 368 | - 'ee_read_default_tickets', |
|
| 369 | - 'ee_read_others_default_tickets', |
|
| 370 | - 'ee_edit_default_ticket', |
|
| 371 | - 'ee_edit_default_tickets', |
|
| 372 | - 'ee_edit_others_default_tickets', |
|
| 373 | - 'ee_delete_default_ticket', |
|
| 374 | - 'ee_delete_default_tickets', |
|
| 375 | - 'ee_delete_others_default_tickets', |
|
| 376 | - //prices |
|
| 377 | - 'ee_edit_default_price', |
|
| 378 | - 'ee_edit_default_prices', |
|
| 379 | - 'ee_delete_default_price', |
|
| 380 | - 'ee_delete_default_prices', |
|
| 381 | - 'ee_edit_default_price_type', |
|
| 382 | - 'ee_edit_default_price_types', |
|
| 383 | - 'ee_delete_default_price_type', |
|
| 384 | - 'ee_delete_default_price_types', |
|
| 385 | - 'ee_read_default_prices', |
|
| 386 | - 'ee_read_default_price_types', |
|
| 387 | - //registration form |
|
| 388 | - 'ee_edit_question', |
|
| 389 | - 'ee_edit_questions', |
|
| 390 | - 'ee_edit_system_questions', |
|
| 391 | - 'ee_read_questions', |
|
| 392 | - 'ee_delete_question', |
|
| 393 | - 'ee_delete_questions', |
|
| 394 | - 'ee_edit_question_group', |
|
| 395 | - 'ee_edit_question_groups', |
|
| 396 | - 'ee_read_question_groups', |
|
| 397 | - 'ee_edit_system_question_groups', |
|
| 398 | - 'ee_delete_question_group', |
|
| 399 | - 'ee_delete_question_groups', |
|
| 400 | - //event_type taxonomy |
|
| 401 | - 'ee_assign_event_type', |
|
| 402 | - 'ee_manage_event_types', |
|
| 403 | - 'ee_edit_event_type', |
|
| 404 | - 'ee_delete_event_type', |
|
| 405 | - ), |
|
| 406 | - 'ee_events_administrator' => array( |
|
| 407 | - //core wp caps |
|
| 408 | - 'read', |
|
| 409 | - 'read_private_pages', |
|
| 410 | - 'read_private_posts', |
|
| 411 | - 'edit_users', |
|
| 412 | - 'edit_posts', |
|
| 413 | - 'edit_pages', |
|
| 414 | - 'edit_published_posts', |
|
| 415 | - 'edit_published_pages', |
|
| 416 | - 'edit_private_pages', |
|
| 417 | - 'edit_private_posts', |
|
| 418 | - 'edit_others_posts', |
|
| 419 | - 'edit_others_pages', |
|
| 420 | - 'publish_posts', |
|
| 421 | - 'publish_pages', |
|
| 422 | - 'delete_posts', |
|
| 423 | - 'delete_pages', |
|
| 424 | - 'delete_private_pages', |
|
| 425 | - 'delete_private_posts', |
|
| 426 | - 'delete_published_pages', |
|
| 427 | - 'delete_published_posts', |
|
| 428 | - 'delete_others_posts', |
|
| 429 | - 'delete_others_pages', |
|
| 430 | - 'manage_categories', |
|
| 431 | - 'manage_links', |
|
| 432 | - 'moderate_comments', |
|
| 433 | - 'unfiltered_html', |
|
| 434 | - 'upload_files', |
|
| 435 | - 'export', |
|
| 436 | - 'import', |
|
| 437 | - 'list_users', |
|
| 438 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
| 439 | - //basic ee access |
|
| 440 | - 'ee_read_ee', |
|
| 441 | - //events |
|
| 442 | - 'ee_publish_events', |
|
| 443 | - 'ee_read_private_events', |
|
| 444 | - 'ee_read_others_events', |
|
| 445 | - 'ee_read_event', |
|
| 446 | - 'ee_read_events', |
|
| 447 | - 'ee_edit_event', |
|
| 448 | - 'ee_edit_events', |
|
| 449 | - 'ee_edit_published_events', |
|
| 450 | - 'ee_edit_others_events', |
|
| 451 | - 'ee_edit_private_events', |
|
| 452 | - 'ee_delete_published_events', |
|
| 453 | - 'ee_delete_private_events', |
|
| 454 | - 'ee_delete_event', |
|
| 455 | - 'ee_delete_events', |
|
| 456 | - 'ee_delete_others_events', |
|
| 457 | - //event categories |
|
| 458 | - 'ee_manage_event_categories', |
|
| 459 | - 'ee_edit_event_category', |
|
| 460 | - 'ee_delete_event_category', |
|
| 461 | - 'ee_assign_event_category', |
|
| 462 | - //venues |
|
| 463 | - 'ee_publish_venues', |
|
| 464 | - 'ee_read_venue', |
|
| 465 | - 'ee_read_venues', |
|
| 466 | - 'ee_read_others_venues', |
|
| 467 | - 'ee_read_private_venues', |
|
| 468 | - 'ee_edit_venue', |
|
| 469 | - 'ee_edit_venues', |
|
| 470 | - 'ee_edit_others_venues', |
|
| 471 | - 'ee_edit_published_venues', |
|
| 472 | - 'ee_edit_private_venues', |
|
| 473 | - 'ee_delete_venue', |
|
| 474 | - 'ee_delete_venues', |
|
| 475 | - 'ee_delete_others_venues', |
|
| 476 | - 'ee_delete_private_venues', |
|
| 477 | - 'ee_delete_published_venues', |
|
| 478 | - //venue categories |
|
| 479 | - 'ee_manage_venue_categories', |
|
| 480 | - 'ee_edit_venue_category', |
|
| 481 | - 'ee_delete_venue_category', |
|
| 482 | - 'ee_assign_venue_category', |
|
| 483 | - //contacts |
|
| 484 | - 'ee_read_contact', |
|
| 485 | - 'ee_read_contacts', |
|
| 486 | - 'ee_edit_contact', |
|
| 487 | - 'ee_edit_contacts', |
|
| 488 | - 'ee_delete_contact', |
|
| 489 | - 'ee_delete_contacts', |
|
| 490 | - //registrations |
|
| 491 | - 'ee_read_registration', |
|
| 492 | - 'ee_read_registrations', |
|
| 493 | - 'ee_read_others_registrations', |
|
| 494 | - 'ee_edit_registration', |
|
| 495 | - 'ee_edit_registrations', |
|
| 496 | - 'ee_edit_others_registrations', |
|
| 497 | - 'ee_delete_registration', |
|
| 498 | - 'ee_delete_registrations', |
|
| 499 | - //checkins |
|
| 500 | - 'ee_read_checkin', |
|
| 501 | - 'ee_read_others_checkins', |
|
| 502 | - 'ee_read_checkins', |
|
| 503 | - 'ee_edit_checkin', |
|
| 504 | - 'ee_edit_checkins', |
|
| 505 | - 'ee_edit_others_checkins', |
|
| 506 | - 'ee_delete_checkin', |
|
| 507 | - 'ee_delete_checkins', |
|
| 508 | - 'ee_delete_others_checkins', |
|
| 509 | - //transactions && payments |
|
| 510 | - 'ee_read_transaction', |
|
| 511 | - 'ee_read_transactions', |
|
| 512 | - 'ee_edit_payments', |
|
| 513 | - 'ee_delete_payments', |
|
| 514 | - //messages |
|
| 515 | - 'ee_read_message', |
|
| 516 | - 'ee_read_messages', |
|
| 517 | - 'ee_read_others_messages', |
|
| 518 | - 'ee_read_global_messages', |
|
| 519 | - 'ee_edit_global_messages', |
|
| 520 | - 'ee_edit_message', |
|
| 521 | - 'ee_edit_messages', |
|
| 522 | - 'ee_edit_others_messages', |
|
| 523 | - 'ee_delete_message', |
|
| 524 | - 'ee_delete_messages', |
|
| 525 | - 'ee_delete_others_messages', |
|
| 526 | - 'ee_delete_global_messages', |
|
| 527 | - 'ee_send_message', |
|
| 528 | - //tickets |
|
| 529 | - 'ee_read_default_ticket', |
|
| 530 | - 'ee_read_default_tickets', |
|
| 531 | - 'ee_read_others_default_tickets', |
|
| 532 | - 'ee_edit_default_ticket', |
|
| 533 | - 'ee_edit_default_tickets', |
|
| 534 | - 'ee_edit_others_default_tickets', |
|
| 535 | - 'ee_delete_default_ticket', |
|
| 536 | - 'ee_delete_default_tickets', |
|
| 537 | - 'ee_delete_others_default_tickets', |
|
| 538 | - //prices |
|
| 539 | - 'ee_edit_default_price', |
|
| 540 | - 'ee_edit_default_prices', |
|
| 541 | - 'ee_delete_default_price', |
|
| 542 | - 'ee_delete_default_prices', |
|
| 543 | - 'ee_edit_default_price_type', |
|
| 544 | - 'ee_edit_default_price_types', |
|
| 545 | - 'ee_delete_default_price_type', |
|
| 546 | - 'ee_delete_default_price_types', |
|
| 547 | - 'ee_read_default_prices', |
|
| 548 | - 'ee_read_default_price_types', |
|
| 549 | - //registration form |
|
| 550 | - 'ee_edit_question', |
|
| 551 | - 'ee_edit_questions', |
|
| 552 | - 'ee_edit_system_questions', |
|
| 553 | - 'ee_read_questions', |
|
| 554 | - 'ee_delete_question', |
|
| 555 | - 'ee_delete_questions', |
|
| 556 | - 'ee_edit_question_group', |
|
| 557 | - 'ee_edit_question_groups', |
|
| 558 | - 'ee_read_question_groups', |
|
| 559 | - 'ee_edit_system_question_groups', |
|
| 560 | - 'ee_delete_question_group', |
|
| 561 | - 'ee_delete_question_groups', |
|
| 562 | - //event_type taxonomy |
|
| 563 | - 'ee_assign_event_type', |
|
| 564 | - 'ee_manage_event_types', |
|
| 565 | - 'ee_edit_event_type', |
|
| 566 | - 'ee_delete_event_type', |
|
| 567 | - ) |
|
| 568 | - ); |
|
| 250 | + /** |
|
| 251 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
| 252 | + * |
|
| 253 | + * @since 4.5.0 |
|
| 254 | + * |
|
| 255 | + * @return array |
|
| 256 | + */ |
|
| 257 | + private function _init_caps_map() |
|
| 258 | + { |
|
| 259 | + $caps = array( |
|
| 260 | + 'administrator' => array( |
|
| 261 | + //basic access |
|
| 262 | + 'ee_read_ee', |
|
| 263 | + //gateways |
|
| 264 | + /** |
|
| 265 | + * note that with payment method capabilities, although we've implemented |
|
| 266 | + * capability mapping which will be used for accessing payment methods owned by |
|
| 267 | + * other users. This is not fully implemented yet in the payment method ui. |
|
| 268 | + * Currently only the "plural" caps are in active use. (Specific payment method caps are in use as well). |
|
| 269 | + **/ |
|
| 270 | + 'ee_manage_gateways', |
|
| 271 | + 'ee_read_payment_method', |
|
| 272 | + 'ee_read_payment_methods', |
|
| 273 | + 'ee_read_others_payment_methods', |
|
| 274 | + 'ee_edit_payment_method', |
|
| 275 | + 'ee_edit_payment_methods', |
|
| 276 | + 'ee_edit_others_payment_methods', |
|
| 277 | + 'ee_delete_payment_method', |
|
| 278 | + 'ee_delete_payment_methods', |
|
| 279 | + //events |
|
| 280 | + 'ee_publish_events', |
|
| 281 | + 'ee_read_private_events', |
|
| 282 | + 'ee_read_others_events', |
|
| 283 | + 'ee_read_event', |
|
| 284 | + 'ee_read_events', |
|
| 285 | + 'ee_edit_event', |
|
| 286 | + 'ee_edit_events', |
|
| 287 | + 'ee_edit_published_events', |
|
| 288 | + 'ee_edit_others_events', |
|
| 289 | + 'ee_edit_private_events', |
|
| 290 | + 'ee_delete_published_events', |
|
| 291 | + 'ee_delete_private_events', |
|
| 292 | + 'ee_delete_event', |
|
| 293 | + 'ee_delete_events', |
|
| 294 | + 'ee_delete_others_events', |
|
| 295 | + //event categories |
|
| 296 | + 'ee_manage_event_categories', |
|
| 297 | + 'ee_edit_event_category', |
|
| 298 | + 'ee_delete_event_category', |
|
| 299 | + 'ee_assign_event_category', |
|
| 300 | + //venues |
|
| 301 | + 'ee_publish_venues', |
|
| 302 | + 'ee_read_venue', |
|
| 303 | + 'ee_read_venues', |
|
| 304 | + 'ee_read_others_venues', |
|
| 305 | + 'ee_read_private_venues', |
|
| 306 | + 'ee_edit_venue', |
|
| 307 | + 'ee_edit_venues', |
|
| 308 | + 'ee_edit_others_venues', |
|
| 309 | + 'ee_edit_published_venues', |
|
| 310 | + 'ee_edit_private_venues', |
|
| 311 | + 'ee_delete_venue', |
|
| 312 | + 'ee_delete_venues', |
|
| 313 | + 'ee_delete_others_venues', |
|
| 314 | + 'ee_delete_private_venues', |
|
| 315 | + 'ee_delete_published_venues', |
|
| 316 | + //venue categories |
|
| 317 | + 'ee_manage_venue_categories', |
|
| 318 | + 'ee_edit_venue_category', |
|
| 319 | + 'ee_delete_venue_category', |
|
| 320 | + 'ee_assign_venue_category', |
|
| 321 | + //contacts |
|
| 322 | + 'ee_read_contact', |
|
| 323 | + 'ee_read_contacts', |
|
| 324 | + 'ee_edit_contact', |
|
| 325 | + 'ee_edit_contacts', |
|
| 326 | + 'ee_delete_contact', |
|
| 327 | + 'ee_delete_contacts', |
|
| 328 | + //registrations |
|
| 329 | + 'ee_read_registration', |
|
| 330 | + 'ee_read_registrations', |
|
| 331 | + 'ee_read_others_registrations', |
|
| 332 | + 'ee_edit_registration', |
|
| 333 | + 'ee_edit_registrations', |
|
| 334 | + 'ee_edit_others_registrations', |
|
| 335 | + 'ee_delete_registration', |
|
| 336 | + 'ee_delete_registrations', |
|
| 337 | + //checkins |
|
| 338 | + 'ee_read_checkin', |
|
| 339 | + 'ee_read_others_checkins', |
|
| 340 | + 'ee_read_checkins', |
|
| 341 | + 'ee_edit_checkin', |
|
| 342 | + 'ee_edit_checkins', |
|
| 343 | + 'ee_edit_others_checkins', |
|
| 344 | + 'ee_delete_checkin', |
|
| 345 | + 'ee_delete_checkins', |
|
| 346 | + 'ee_delete_others_checkins', |
|
| 347 | + //transactions && payments |
|
| 348 | + 'ee_read_transaction', |
|
| 349 | + 'ee_read_transactions', |
|
| 350 | + 'ee_edit_payments', |
|
| 351 | + 'ee_delete_payments', |
|
| 352 | + //messages |
|
| 353 | + 'ee_read_message', |
|
| 354 | + 'ee_read_messages', |
|
| 355 | + 'ee_read_others_messages', |
|
| 356 | + 'ee_read_global_messages', |
|
| 357 | + 'ee_edit_global_messages', |
|
| 358 | + 'ee_edit_message', |
|
| 359 | + 'ee_edit_messages', |
|
| 360 | + 'ee_edit_others_messages', |
|
| 361 | + 'ee_delete_message', |
|
| 362 | + 'ee_delete_messages', |
|
| 363 | + 'ee_delete_others_messages', |
|
| 364 | + 'ee_delete_global_messages', |
|
| 365 | + 'ee_send_message', |
|
| 366 | + //tickets |
|
| 367 | + 'ee_read_default_ticket', |
|
| 368 | + 'ee_read_default_tickets', |
|
| 369 | + 'ee_read_others_default_tickets', |
|
| 370 | + 'ee_edit_default_ticket', |
|
| 371 | + 'ee_edit_default_tickets', |
|
| 372 | + 'ee_edit_others_default_tickets', |
|
| 373 | + 'ee_delete_default_ticket', |
|
| 374 | + 'ee_delete_default_tickets', |
|
| 375 | + 'ee_delete_others_default_tickets', |
|
| 376 | + //prices |
|
| 377 | + 'ee_edit_default_price', |
|
| 378 | + 'ee_edit_default_prices', |
|
| 379 | + 'ee_delete_default_price', |
|
| 380 | + 'ee_delete_default_prices', |
|
| 381 | + 'ee_edit_default_price_type', |
|
| 382 | + 'ee_edit_default_price_types', |
|
| 383 | + 'ee_delete_default_price_type', |
|
| 384 | + 'ee_delete_default_price_types', |
|
| 385 | + 'ee_read_default_prices', |
|
| 386 | + 'ee_read_default_price_types', |
|
| 387 | + //registration form |
|
| 388 | + 'ee_edit_question', |
|
| 389 | + 'ee_edit_questions', |
|
| 390 | + 'ee_edit_system_questions', |
|
| 391 | + 'ee_read_questions', |
|
| 392 | + 'ee_delete_question', |
|
| 393 | + 'ee_delete_questions', |
|
| 394 | + 'ee_edit_question_group', |
|
| 395 | + 'ee_edit_question_groups', |
|
| 396 | + 'ee_read_question_groups', |
|
| 397 | + 'ee_edit_system_question_groups', |
|
| 398 | + 'ee_delete_question_group', |
|
| 399 | + 'ee_delete_question_groups', |
|
| 400 | + //event_type taxonomy |
|
| 401 | + 'ee_assign_event_type', |
|
| 402 | + 'ee_manage_event_types', |
|
| 403 | + 'ee_edit_event_type', |
|
| 404 | + 'ee_delete_event_type', |
|
| 405 | + ), |
|
| 406 | + 'ee_events_administrator' => array( |
|
| 407 | + //core wp caps |
|
| 408 | + 'read', |
|
| 409 | + 'read_private_pages', |
|
| 410 | + 'read_private_posts', |
|
| 411 | + 'edit_users', |
|
| 412 | + 'edit_posts', |
|
| 413 | + 'edit_pages', |
|
| 414 | + 'edit_published_posts', |
|
| 415 | + 'edit_published_pages', |
|
| 416 | + 'edit_private_pages', |
|
| 417 | + 'edit_private_posts', |
|
| 418 | + 'edit_others_posts', |
|
| 419 | + 'edit_others_pages', |
|
| 420 | + 'publish_posts', |
|
| 421 | + 'publish_pages', |
|
| 422 | + 'delete_posts', |
|
| 423 | + 'delete_pages', |
|
| 424 | + 'delete_private_pages', |
|
| 425 | + 'delete_private_posts', |
|
| 426 | + 'delete_published_pages', |
|
| 427 | + 'delete_published_posts', |
|
| 428 | + 'delete_others_posts', |
|
| 429 | + 'delete_others_pages', |
|
| 430 | + 'manage_categories', |
|
| 431 | + 'manage_links', |
|
| 432 | + 'moderate_comments', |
|
| 433 | + 'unfiltered_html', |
|
| 434 | + 'upload_files', |
|
| 435 | + 'export', |
|
| 436 | + 'import', |
|
| 437 | + 'list_users', |
|
| 438 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
| 439 | + //basic ee access |
|
| 440 | + 'ee_read_ee', |
|
| 441 | + //events |
|
| 442 | + 'ee_publish_events', |
|
| 443 | + 'ee_read_private_events', |
|
| 444 | + 'ee_read_others_events', |
|
| 445 | + 'ee_read_event', |
|
| 446 | + 'ee_read_events', |
|
| 447 | + 'ee_edit_event', |
|
| 448 | + 'ee_edit_events', |
|
| 449 | + 'ee_edit_published_events', |
|
| 450 | + 'ee_edit_others_events', |
|
| 451 | + 'ee_edit_private_events', |
|
| 452 | + 'ee_delete_published_events', |
|
| 453 | + 'ee_delete_private_events', |
|
| 454 | + 'ee_delete_event', |
|
| 455 | + 'ee_delete_events', |
|
| 456 | + 'ee_delete_others_events', |
|
| 457 | + //event categories |
|
| 458 | + 'ee_manage_event_categories', |
|
| 459 | + 'ee_edit_event_category', |
|
| 460 | + 'ee_delete_event_category', |
|
| 461 | + 'ee_assign_event_category', |
|
| 462 | + //venues |
|
| 463 | + 'ee_publish_venues', |
|
| 464 | + 'ee_read_venue', |
|
| 465 | + 'ee_read_venues', |
|
| 466 | + 'ee_read_others_venues', |
|
| 467 | + 'ee_read_private_venues', |
|
| 468 | + 'ee_edit_venue', |
|
| 469 | + 'ee_edit_venues', |
|
| 470 | + 'ee_edit_others_venues', |
|
| 471 | + 'ee_edit_published_venues', |
|
| 472 | + 'ee_edit_private_venues', |
|
| 473 | + 'ee_delete_venue', |
|
| 474 | + 'ee_delete_venues', |
|
| 475 | + 'ee_delete_others_venues', |
|
| 476 | + 'ee_delete_private_venues', |
|
| 477 | + 'ee_delete_published_venues', |
|
| 478 | + //venue categories |
|
| 479 | + 'ee_manage_venue_categories', |
|
| 480 | + 'ee_edit_venue_category', |
|
| 481 | + 'ee_delete_venue_category', |
|
| 482 | + 'ee_assign_venue_category', |
|
| 483 | + //contacts |
|
| 484 | + 'ee_read_contact', |
|
| 485 | + 'ee_read_contacts', |
|
| 486 | + 'ee_edit_contact', |
|
| 487 | + 'ee_edit_contacts', |
|
| 488 | + 'ee_delete_contact', |
|
| 489 | + 'ee_delete_contacts', |
|
| 490 | + //registrations |
|
| 491 | + 'ee_read_registration', |
|
| 492 | + 'ee_read_registrations', |
|
| 493 | + 'ee_read_others_registrations', |
|
| 494 | + 'ee_edit_registration', |
|
| 495 | + 'ee_edit_registrations', |
|
| 496 | + 'ee_edit_others_registrations', |
|
| 497 | + 'ee_delete_registration', |
|
| 498 | + 'ee_delete_registrations', |
|
| 499 | + //checkins |
|
| 500 | + 'ee_read_checkin', |
|
| 501 | + 'ee_read_others_checkins', |
|
| 502 | + 'ee_read_checkins', |
|
| 503 | + 'ee_edit_checkin', |
|
| 504 | + 'ee_edit_checkins', |
|
| 505 | + 'ee_edit_others_checkins', |
|
| 506 | + 'ee_delete_checkin', |
|
| 507 | + 'ee_delete_checkins', |
|
| 508 | + 'ee_delete_others_checkins', |
|
| 509 | + //transactions && payments |
|
| 510 | + 'ee_read_transaction', |
|
| 511 | + 'ee_read_transactions', |
|
| 512 | + 'ee_edit_payments', |
|
| 513 | + 'ee_delete_payments', |
|
| 514 | + //messages |
|
| 515 | + 'ee_read_message', |
|
| 516 | + 'ee_read_messages', |
|
| 517 | + 'ee_read_others_messages', |
|
| 518 | + 'ee_read_global_messages', |
|
| 519 | + 'ee_edit_global_messages', |
|
| 520 | + 'ee_edit_message', |
|
| 521 | + 'ee_edit_messages', |
|
| 522 | + 'ee_edit_others_messages', |
|
| 523 | + 'ee_delete_message', |
|
| 524 | + 'ee_delete_messages', |
|
| 525 | + 'ee_delete_others_messages', |
|
| 526 | + 'ee_delete_global_messages', |
|
| 527 | + 'ee_send_message', |
|
| 528 | + //tickets |
|
| 529 | + 'ee_read_default_ticket', |
|
| 530 | + 'ee_read_default_tickets', |
|
| 531 | + 'ee_read_others_default_tickets', |
|
| 532 | + 'ee_edit_default_ticket', |
|
| 533 | + 'ee_edit_default_tickets', |
|
| 534 | + 'ee_edit_others_default_tickets', |
|
| 535 | + 'ee_delete_default_ticket', |
|
| 536 | + 'ee_delete_default_tickets', |
|
| 537 | + 'ee_delete_others_default_tickets', |
|
| 538 | + //prices |
|
| 539 | + 'ee_edit_default_price', |
|
| 540 | + 'ee_edit_default_prices', |
|
| 541 | + 'ee_delete_default_price', |
|
| 542 | + 'ee_delete_default_prices', |
|
| 543 | + 'ee_edit_default_price_type', |
|
| 544 | + 'ee_edit_default_price_types', |
|
| 545 | + 'ee_delete_default_price_type', |
|
| 546 | + 'ee_delete_default_price_types', |
|
| 547 | + 'ee_read_default_prices', |
|
| 548 | + 'ee_read_default_price_types', |
|
| 549 | + //registration form |
|
| 550 | + 'ee_edit_question', |
|
| 551 | + 'ee_edit_questions', |
|
| 552 | + 'ee_edit_system_questions', |
|
| 553 | + 'ee_read_questions', |
|
| 554 | + 'ee_delete_question', |
|
| 555 | + 'ee_delete_questions', |
|
| 556 | + 'ee_edit_question_group', |
|
| 557 | + 'ee_edit_question_groups', |
|
| 558 | + 'ee_read_question_groups', |
|
| 559 | + 'ee_edit_system_question_groups', |
|
| 560 | + 'ee_delete_question_group', |
|
| 561 | + 'ee_delete_question_groups', |
|
| 562 | + //event_type taxonomy |
|
| 563 | + 'ee_assign_event_type', |
|
| 564 | + 'ee_manage_event_types', |
|
| 565 | + 'ee_edit_event_type', |
|
| 566 | + 'ee_delete_event_type', |
|
| 567 | + ) |
|
| 568 | + ); |
|
| 569 | 569 | |
| 570 | - $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps); |
|
| 570 | + $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps); |
|
| 571 | 571 | |
| 572 | - return $caps; |
|
| 573 | - } |
|
| 572 | + return $caps; |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | 575 | |
| 576 | - /** |
|
| 577 | - * This adds all the default caps to roles as registered in the _caps_map property. |
|
| 578 | - * |
|
| 579 | - * @since 4.5.0 |
|
| 580 | - * |
|
| 581 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 582 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles |
|
| 583 | - * and ensures that they are up to date. |
|
| 584 | - * @param array $custom_map Optional. Can be used to send a custom map of roles and capabilities for setting them |
|
| 585 | - * up. Note that this should ONLY be called on activation hook or some other one-time |
|
| 586 | - * task otherwise the caps will be added on every request. |
|
| 587 | - * |
|
| 588 | - * @return void |
|
| 589 | - */ |
|
| 590 | - public function init_role_caps($reset = false, $custom_map = array()) |
|
| 591 | - { |
|
| 576 | + /** |
|
| 577 | + * This adds all the default caps to roles as registered in the _caps_map property. |
|
| 578 | + * |
|
| 579 | + * @since 4.5.0 |
|
| 580 | + * |
|
| 581 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 582 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles |
|
| 583 | + * and ensures that they are up to date. |
|
| 584 | + * @param array $custom_map Optional. Can be used to send a custom map of roles and capabilities for setting them |
|
| 585 | + * up. Note that this should ONLY be called on activation hook or some other one-time |
|
| 586 | + * task otherwise the caps will be added on every request. |
|
| 587 | + * |
|
| 588 | + * @return void |
|
| 589 | + */ |
|
| 590 | + public function init_role_caps($reset = false, $custom_map = array()) |
|
| 591 | + { |
|
| 592 | 592 | |
| 593 | - $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map; |
|
| 593 | + $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map; |
|
| 594 | 594 | |
| 595 | - //first let's determine if these caps have already been set. |
|
| 596 | - $caps_set_before = get_option(self::option_name, array()); |
|
| 597 | - //if not reset, see what caps are new for each role. if they're new, add them. |
|
| 598 | - foreach ($caps_map as $role => $caps_for_role) { |
|
| 599 | - foreach ($caps_for_role as $cap) { |
|
| 600 | - //first check we haven't already added this cap before, or it's a reset |
|
| 601 | - if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) { |
|
| 602 | - if ($this->add_cap_to_role($role, $cap)) { |
|
| 603 | - $caps_set_before[$role][] = $cap; |
|
| 604 | - } |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - } |
|
| 595 | + //first let's determine if these caps have already been set. |
|
| 596 | + $caps_set_before = get_option(self::option_name, array()); |
|
| 597 | + //if not reset, see what caps are new for each role. if they're new, add them. |
|
| 598 | + foreach ($caps_map as $role => $caps_for_role) { |
|
| 599 | + foreach ($caps_for_role as $cap) { |
|
| 600 | + //first check we haven't already added this cap before, or it's a reset |
|
| 601 | + if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) { |
|
| 602 | + if ($this->add_cap_to_role($role, $cap)) { |
|
| 603 | + $caps_set_before[$role][] = $cap; |
|
| 604 | + } |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | 608 | |
| 609 | - //now let's just save the cap that has been set. |
|
| 610 | - update_option(self::option_name, $caps_set_before); |
|
| 611 | - do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before); |
|
| 612 | - } |
|
| 609 | + //now let's just save the cap that has been set. |
|
| 610 | + update_option(self::option_name, $caps_set_before); |
|
| 611 | + do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before); |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | 614 | |
| 615 | - /** |
|
| 616 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 617 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 618 | - * this is a wrapper for $wp_role->add_cap() |
|
| 619 | - * |
|
| 620 | - * @see wp-includes/capabilities.php |
|
| 621 | - * |
|
| 622 | - * @since 4.5.0 |
|
| 623 | - * |
|
| 624 | - * @param string $role A WordPress role the capability is being added to |
|
| 625 | - * @param string $cap The capability being added to the role |
|
| 626 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
| 627 | - * |
|
| 628 | - * @return bool |
|
| 629 | - */ |
|
| 630 | - public function add_cap_to_role($role, $cap, $grant = true) |
|
| 631 | - { |
|
| 632 | - $role_object = get_role($role); |
|
| 633 | - //if the role isn't available then we create it. |
|
| 634 | - if ( ! $role_object instanceof WP_Role) { |
|
| 635 | - //if a plugin wants to create a specific role name then they should create the role before |
|
| 636 | - //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 637 | - // - removes any `ee_` namespacing from the start of the slug. |
|
| 638 | - // - replaces `_` with ` ` (empty space). |
|
| 639 | - // - sentence case on the resulting string. |
|
| 640 | - $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role))); |
|
| 641 | - $role_object = add_role($role, $role_label); |
|
| 642 | - } |
|
| 643 | - if ($role_object instanceof WP_Role) { |
|
| 644 | - $role_object->add_cap($cap, $grant); |
|
| 615 | + /** |
|
| 616 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 617 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 618 | + * this is a wrapper for $wp_role->add_cap() |
|
| 619 | + * |
|
| 620 | + * @see wp-includes/capabilities.php |
|
| 621 | + * |
|
| 622 | + * @since 4.5.0 |
|
| 623 | + * |
|
| 624 | + * @param string $role A WordPress role the capability is being added to |
|
| 625 | + * @param string $cap The capability being added to the role |
|
| 626 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
| 627 | + * |
|
| 628 | + * @return bool |
|
| 629 | + */ |
|
| 630 | + public function add_cap_to_role($role, $cap, $grant = true) |
|
| 631 | + { |
|
| 632 | + $role_object = get_role($role); |
|
| 633 | + //if the role isn't available then we create it. |
|
| 634 | + if ( ! $role_object instanceof WP_Role) { |
|
| 635 | + //if a plugin wants to create a specific role name then they should create the role before |
|
| 636 | + //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 637 | + // - removes any `ee_` namespacing from the start of the slug. |
|
| 638 | + // - replaces `_` with ` ` (empty space). |
|
| 639 | + // - sentence case on the resulting string. |
|
| 640 | + $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role))); |
|
| 641 | + $role_object = add_role($role, $role_label); |
|
| 642 | + } |
|
| 643 | + if ($role_object instanceof WP_Role) { |
|
| 644 | + $role_object->add_cap($cap, $grant); |
|
| 645 | 645 | |
| 646 | - return true; |
|
| 647 | - } |
|
| 646 | + return true; |
|
| 647 | + } |
|
| 648 | 648 | |
| 649 | - return false; |
|
| 650 | - } |
|
| 649 | + return false; |
|
| 650 | + } |
|
| 651 | 651 | |
| 652 | 652 | |
| 653 | - /** |
|
| 654 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 655 | - * Wrapper for $wp_role->remove_cap() |
|
| 656 | - * |
|
| 657 | - * @see wp-includes/capabilities.php |
|
| 658 | - * @since 4.5.0 |
|
| 659 | - * |
|
| 660 | - * @param string $role A WordPress role the capability is being removed from. |
|
| 661 | - * @param string $cap The capability being removed |
|
| 662 | - * |
|
| 663 | - * @return void |
|
| 664 | - */ |
|
| 665 | - public function remove_cap_from_role($role, $cap) |
|
| 666 | - { |
|
| 667 | - $role = get_role($role); |
|
| 668 | - if ($role instanceof WP_Role) { |
|
| 669 | - $role->remove_cap($cap); |
|
| 670 | - } |
|
| 671 | - } |
|
| 653 | + /** |
|
| 654 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 655 | + * Wrapper for $wp_role->remove_cap() |
|
| 656 | + * |
|
| 657 | + * @see wp-includes/capabilities.php |
|
| 658 | + * @since 4.5.0 |
|
| 659 | + * |
|
| 660 | + * @param string $role A WordPress role the capability is being removed from. |
|
| 661 | + * @param string $cap The capability being removed |
|
| 662 | + * |
|
| 663 | + * @return void |
|
| 664 | + */ |
|
| 665 | + public function remove_cap_from_role($role, $cap) |
|
| 666 | + { |
|
| 667 | + $role = get_role($role); |
|
| 668 | + if ($role instanceof WP_Role) { |
|
| 669 | + $role->remove_cap($cap); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | 673 | |
| 674 | - /** |
|
| 675 | - * Wrapper for the native WP current_user_can() method. |
|
| 676 | - * This is provided as a handy method for a couple things: |
|
| 677 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 678 | - * write those filters wherever current_user_can is called). |
|
| 679 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 680 | - * |
|
| 681 | - * @since 4.5.0 |
|
| 682 | - * |
|
| 683 | - * @param string $cap The cap being checked. |
|
| 684 | - * @param string $context The context where the current_user_can is being called from. |
|
| 685 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 686 | - * filters. |
|
| 687 | - * |
|
| 688 | - * @return bool Whether user can or not. |
|
| 689 | - */ |
|
| 690 | - public function current_user_can($cap, $context, $id = 0) |
|
| 691 | - { |
|
| 692 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 693 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 694 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
|
| 695 | - $id); |
|
| 674 | + /** |
|
| 675 | + * Wrapper for the native WP current_user_can() method. |
|
| 676 | + * This is provided as a handy method for a couple things: |
|
| 677 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 678 | + * write those filters wherever current_user_can is called). |
|
| 679 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 680 | + * |
|
| 681 | + * @since 4.5.0 |
|
| 682 | + * |
|
| 683 | + * @param string $cap The cap being checked. |
|
| 684 | + * @param string $context The context where the current_user_can is being called from. |
|
| 685 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 686 | + * filters. |
|
| 687 | + * |
|
| 688 | + * @return bool Whether user can or not. |
|
| 689 | + */ |
|
| 690 | + public function current_user_can($cap, $context, $id = 0) |
|
| 691 | + { |
|
| 692 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 693 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 694 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
|
| 695 | + $id); |
|
| 696 | 696 | |
| 697 | - return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
|
| 698 | - } |
|
| 697 | + return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | 700 | |
| 701 | - /** |
|
| 702 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 703 | - * |
|
| 704 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 705 | - * @param string $cap The capability string being checked |
|
| 706 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
| 707 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 708 | - * filters) |
|
| 709 | - * |
|
| 710 | - * @return bool Whether user can or not. |
|
| 711 | - */ |
|
| 712 | - public function user_can($user, $cap, $context, $id = 0) |
|
| 713 | - { |
|
| 714 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 715 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 716 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
|
| 717 | - $id); |
|
| 701 | + /** |
|
| 702 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 703 | + * |
|
| 704 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 705 | + * @param string $cap The capability string being checked |
|
| 706 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
| 707 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 708 | + * filters) |
|
| 709 | + * |
|
| 710 | + * @return bool Whether user can or not. |
|
| 711 | + */ |
|
| 712 | + public function user_can($user, $cap, $context, $id = 0) |
|
| 713 | + { |
|
| 714 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 715 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 716 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
|
| 717 | + $id); |
|
| 718 | 718 | |
| 719 | - return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
|
| 720 | - } |
|
| 719 | + return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | 722 | |
| 723 | - /** |
|
| 724 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 725 | - * This is provided as a handy method for a couple things: |
|
| 726 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 727 | - * write those filters wherever current_user_can is called). |
|
| 728 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 729 | - * |
|
| 730 | - * @since 4.5.0 |
|
| 731 | - * |
|
| 732 | - * @param int $blog_id The blog id that is being checked for. |
|
| 733 | - * @param string $cap The cap being checked. |
|
| 734 | - * @param string $context The context where the current_user_can is being called from. |
|
| 735 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 736 | - * filters. |
|
| 737 | - * |
|
| 738 | - * @return bool Whether user can or not. |
|
| 739 | - */ |
|
| 740 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 741 | - { |
|
| 742 | - $user_can = ! empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap); |
|
| 723 | + /** |
|
| 724 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 725 | + * This is provided as a handy method for a couple things: |
|
| 726 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 727 | + * write those filters wherever current_user_can is called). |
|
| 728 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 729 | + * |
|
| 730 | + * @since 4.5.0 |
|
| 731 | + * |
|
| 732 | + * @param int $blog_id The blog id that is being checked for. |
|
| 733 | + * @param string $cap The cap being checked. |
|
| 734 | + * @param string $context The context where the current_user_can is being called from. |
|
| 735 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 736 | + * filters. |
|
| 737 | + * |
|
| 738 | + * @return bool Whether user can or not. |
|
| 739 | + */ |
|
| 740 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 741 | + { |
|
| 742 | + $user_can = ! empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap); |
|
| 743 | 743 | |
| 744 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 745 | - $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, |
|
| 746 | - $blog_id, $cap, $id); |
|
| 747 | - $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, |
|
| 748 | - $blog_id, $cap, $id); |
|
| 744 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 745 | + $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, |
|
| 746 | + $blog_id, $cap, $id); |
|
| 747 | + $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, |
|
| 748 | + $blog_id, $cap, $id); |
|
| 749 | 749 | |
| 750 | - return $user_can; |
|
| 751 | - } |
|
| 750 | + return $user_can; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | 753 | |
| 754 | - /** |
|
| 755 | - * This helper method just returns an array of registered EE capabilities. |
|
| 756 | - * Note this array is filtered. It is assumed that all available EE capabilities are assigned to the administrator |
|
| 757 | - * role. |
|
| 758 | - * |
|
| 759 | - * @since 4.5.0 |
|
| 760 | - * |
|
| 761 | - * @param string $role If empty then the entire role/capability map is returned. Otherwise just the capabilities |
|
| 762 | - * for the given role are returned. |
|
| 763 | - * |
|
| 764 | - * @return array |
|
| 765 | - */ |
|
| 766 | - public function get_ee_capabilities($role = 'administrator') |
|
| 767 | - { |
|
| 768 | - $capabilities = $this->_init_caps_map(); |
|
| 769 | - if (empty($role)) { |
|
| 770 | - return $capabilities; |
|
| 771 | - } |
|
| 754 | + /** |
|
| 755 | + * This helper method just returns an array of registered EE capabilities. |
|
| 756 | + * Note this array is filtered. It is assumed that all available EE capabilities are assigned to the administrator |
|
| 757 | + * role. |
|
| 758 | + * |
|
| 759 | + * @since 4.5.0 |
|
| 760 | + * |
|
| 761 | + * @param string $role If empty then the entire role/capability map is returned. Otherwise just the capabilities |
|
| 762 | + * for the given role are returned. |
|
| 763 | + * |
|
| 764 | + * @return array |
|
| 765 | + */ |
|
| 766 | + public function get_ee_capabilities($role = 'administrator') |
|
| 767 | + { |
|
| 768 | + $capabilities = $this->_init_caps_map(); |
|
| 769 | + if (empty($role)) { |
|
| 770 | + return $capabilities; |
|
| 771 | + } |
|
| 772 | 772 | |
| 773 | - return isset($capabilities[$role]) ? $capabilities[$role] : array(); |
|
| 774 | - } |
|
| 773 | + return isset($capabilities[$role]) ? $capabilities[$role] : array(); |
|
| 774 | + } |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | |
@@ -787,126 +787,126 @@ discard block |
||
| 787 | 787 | */ |
| 788 | 788 | abstract class EE_Meta_Capability_Map |
| 789 | 789 | { |
| 790 | - public $meta_cap; |
|
| 791 | - /** |
|
| 792 | - * @var EEM_Base |
|
| 793 | - */ |
|
| 794 | - protected $_model; |
|
| 795 | - protected $_model_name; |
|
| 796 | - public $published_cap = ''; |
|
| 797 | - public $others_cap = ''; |
|
| 798 | - public $private_cap = ''; |
|
| 790 | + public $meta_cap; |
|
| 791 | + /** |
|
| 792 | + * @var EEM_Base |
|
| 793 | + */ |
|
| 794 | + protected $_model; |
|
| 795 | + protected $_model_name; |
|
| 796 | + public $published_cap = ''; |
|
| 797 | + public $others_cap = ''; |
|
| 798 | + public $private_cap = ''; |
|
| 799 | 799 | |
| 800 | 800 | |
| 801 | - /** |
|
| 802 | - * constructor. |
|
| 803 | - * Receives the setup arguments for the map. |
|
| 804 | - * |
|
| 805 | - * @since 4.5.0 |
|
| 806 | - * |
|
| 807 | - * @param string $meta_cap What meta capability is this mapping. |
|
| 808 | - * @param array $map_values array { |
|
| 809 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 810 | - * capabilities that don't get mapped to. |
|
| 811 | - * |
|
| 812 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 813 | - * should always be used when Menu Maps are registered via the |
|
| 814 | - * plugin API as models are not allowed to be instantiated when |
|
| 815 | - * in maintenance mode 2 (migrations). |
|
| 816 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 817 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 818 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 819 | - * } |
|
| 820 | - * @throws EE_Error |
|
| 821 | - */ |
|
| 822 | - public function __construct($meta_cap, $map_values) |
|
| 823 | - { |
|
| 824 | - $this->meta_cap = $meta_cap; |
|
| 825 | - //verify there are four args in the $map_values array; |
|
| 826 | - if (count($map_values) !== 4) { |
|
| 827 | - throw new EE_Error(sprintf(__('Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 828 | - 'event_espresso'), '<br>' . print_r($map_values, true))); |
|
| 829 | - } |
|
| 801 | + /** |
|
| 802 | + * constructor. |
|
| 803 | + * Receives the setup arguments for the map. |
|
| 804 | + * |
|
| 805 | + * @since 4.5.0 |
|
| 806 | + * |
|
| 807 | + * @param string $meta_cap What meta capability is this mapping. |
|
| 808 | + * @param array $map_values array { |
|
| 809 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 810 | + * capabilities that don't get mapped to. |
|
| 811 | + * |
|
| 812 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 813 | + * should always be used when Menu Maps are registered via the |
|
| 814 | + * plugin API as models are not allowed to be instantiated when |
|
| 815 | + * in maintenance mode 2 (migrations). |
|
| 816 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 817 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 818 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 819 | + * } |
|
| 820 | + * @throws EE_Error |
|
| 821 | + */ |
|
| 822 | + public function __construct($meta_cap, $map_values) |
|
| 823 | + { |
|
| 824 | + $this->meta_cap = $meta_cap; |
|
| 825 | + //verify there are four args in the $map_values array; |
|
| 826 | + if (count($map_values) !== 4) { |
|
| 827 | + throw new EE_Error(sprintf(__('Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 828 | + 'event_espresso'), '<br>' . print_r($map_values, true))); |
|
| 829 | + } |
|
| 830 | 830 | |
| 831 | - //set properties |
|
| 832 | - $this->_model = null; |
|
| 833 | - $this->_model_name = $map_values[0]; |
|
| 834 | - $this->published_cap = (string)$map_values[1]; |
|
| 835 | - $this->others_cap = (string)$map_values[2]; |
|
| 836 | - $this->private_cap = (string)$map_values[3]; |
|
| 837 | - } |
|
| 831 | + //set properties |
|
| 832 | + $this->_model = null; |
|
| 833 | + $this->_model_name = $map_values[0]; |
|
| 834 | + $this->published_cap = (string)$map_values[1]; |
|
| 835 | + $this->others_cap = (string)$map_values[2]; |
|
| 836 | + $this->private_cap = (string)$map_values[3]; |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | - /** |
|
| 840 | - * Makes it so this object stops filtering caps |
|
| 841 | - */ |
|
| 842 | - public function remove_filters() |
|
| 843 | - { |
|
| 844 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 845 | - } |
|
| 839 | + /** |
|
| 840 | + * Makes it so this object stops filtering caps |
|
| 841 | + */ |
|
| 842 | + public function remove_filters() |
|
| 843 | + { |
|
| 844 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | 847 | |
| 848 | - /** |
|
| 849 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 850 | - * |
|
| 851 | - * @since 4.5.0 |
|
| 852 | - * @throws EE_Error |
|
| 853 | - * |
|
| 854 | - * @return void |
|
| 855 | - */ |
|
| 856 | - public function ensure_is_model() |
|
| 857 | - { |
|
| 858 | - //is it already instantiated? |
|
| 859 | - if ($this->_model instanceof EEM_Base) { |
|
| 860 | - return; |
|
| 861 | - } |
|
| 848 | + /** |
|
| 849 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 850 | + * |
|
| 851 | + * @since 4.5.0 |
|
| 852 | + * @throws EE_Error |
|
| 853 | + * |
|
| 854 | + * @return void |
|
| 855 | + */ |
|
| 856 | + public function ensure_is_model() |
|
| 857 | + { |
|
| 858 | + //is it already instantiated? |
|
| 859 | + if ($this->_model instanceof EEM_Base) { |
|
| 860 | + return; |
|
| 861 | + } |
|
| 862 | 862 | |
| 863 | - //ensure model name is string |
|
| 864 | - $this->_model_name = (string)$this->_model_name; |
|
| 865 | - //error proof if the name has EEM in it |
|
| 866 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 863 | + //ensure model name is string |
|
| 864 | + $this->_model_name = (string)$this->_model_name; |
|
| 865 | + //error proof if the name has EEM in it |
|
| 866 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 867 | 867 | |
| 868 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 868 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 869 | 869 | |
| 870 | - if ( ! $this->_model instanceof EEM_Base) { |
|
| 871 | - throw new EE_Error(sprintf(__('This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 872 | - 'event_espresso'), get_class($this), $this->_model)); |
|
| 873 | - } |
|
| 874 | - } |
|
| 870 | + if ( ! $this->_model instanceof EEM_Base) { |
|
| 871 | + throw new EE_Error(sprintf(__('This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 872 | + 'event_espresso'), get_class($this), $this->_model)); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | 875 | |
| 876 | 876 | |
| 877 | - /** |
|
| 878 | - * |
|
| 879 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 880 | - * @since 4.6.x |
|
| 881 | - * |
|
| 882 | - * @param $caps |
|
| 883 | - * @param $cap |
|
| 884 | - * @param $user_id |
|
| 885 | - * @param $args |
|
| 886 | - * |
|
| 887 | - * @return array |
|
| 888 | - */ |
|
| 889 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 890 | - { |
|
| 891 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 892 | - } |
|
| 877 | + /** |
|
| 878 | + * |
|
| 879 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 880 | + * @since 4.6.x |
|
| 881 | + * |
|
| 882 | + * @param $caps |
|
| 883 | + * @param $cap |
|
| 884 | + * @param $user_id |
|
| 885 | + * @param $args |
|
| 886 | + * |
|
| 887 | + * @return array |
|
| 888 | + */ |
|
| 889 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 890 | + { |
|
| 891 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 892 | + } |
|
| 893 | 893 | |
| 894 | 894 | |
| 895 | - /** |
|
| 896 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 897 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 898 | - * |
|
| 899 | - * @since 4.5.0 |
|
| 900 | - * @see wp-includes/capabilities.php |
|
| 901 | - * |
|
| 902 | - * @param array $caps actual users capabilities |
|
| 903 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 904 | - * @param int $user_id The user id |
|
| 905 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 906 | - * |
|
| 907 | - * @return array actual users capabilities |
|
| 908 | - */ |
|
| 909 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 895 | + /** |
|
| 896 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 897 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 898 | + * |
|
| 899 | + * @since 4.5.0 |
|
| 900 | + * @see wp-includes/capabilities.php |
|
| 901 | + * |
|
| 902 | + * @param array $caps actual users capabilities |
|
| 903 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 904 | + * @param int $user_id The user id |
|
| 905 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 906 | + * |
|
| 907 | + * @return array actual users capabilities |
|
| 908 | + */ |
|
| 909 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | |
@@ -922,81 +922,81 @@ discard block |
||
| 922 | 922 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
| 923 | 923 | { |
| 924 | 924 | |
| 925 | - /** |
|
| 926 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 927 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 928 | - * |
|
| 929 | - * @since 4.5.0 |
|
| 930 | - * @see wp-includes/capabilities.php |
|
| 931 | - * |
|
| 932 | - * @param array $caps actual users capabilities |
|
| 933 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 934 | - * @param int $user_id The user id |
|
| 935 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 936 | - * |
|
| 937 | - * @return array actual users capabilities |
|
| 938 | - */ |
|
| 939 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 940 | - { |
|
| 941 | - //only process if we're checking our mapped_cap |
|
| 942 | - if ($cap !== $this->meta_cap) { |
|
| 943 | - return $caps; |
|
| 944 | - } |
|
| 925 | + /** |
|
| 926 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 927 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 928 | + * |
|
| 929 | + * @since 4.5.0 |
|
| 930 | + * @see wp-includes/capabilities.php |
|
| 931 | + * |
|
| 932 | + * @param array $caps actual users capabilities |
|
| 933 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 934 | + * @param int $user_id The user id |
|
| 935 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 936 | + * |
|
| 937 | + * @return array actual users capabilities |
|
| 938 | + */ |
|
| 939 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 940 | + { |
|
| 941 | + //only process if we're checking our mapped_cap |
|
| 942 | + if ($cap !== $this->meta_cap) { |
|
| 943 | + return $caps; |
|
| 944 | + } |
|
| 945 | 945 | |
| 946 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 946 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 947 | 947 | |
| 948 | - //if no obj then let's just do cap |
|
| 949 | - if ( ! $obj instanceof EE_Base_Class) { |
|
| 950 | - $caps[] = $cap; |
|
| 948 | + //if no obj then let's just do cap |
|
| 949 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 950 | + $caps[] = $cap; |
|
| 951 | 951 | |
| 952 | - return $caps; |
|
| 953 | - } |
|
| 952 | + return $caps; |
|
| 953 | + } |
|
| 954 | 954 | |
| 955 | - if ($obj instanceof EE_CPT_Base) { |
|
| 956 | - //if the item author is set and the user is the author... |
|
| 957 | - if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
| 958 | - if (empty($this->published_cap)) { |
|
| 959 | - $caps[] = $cap; |
|
| 960 | - } else { |
|
| 961 | - //if obj is published... |
|
| 962 | - if ($obj->status() == 'publish') { |
|
| 963 | - $caps[] = $this->published_cap; |
|
| 964 | - } else { |
|
| 965 | - $caps[] = $cap; |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - } else { |
|
| 969 | - //the user is trying to edit someone else's obj |
|
| 970 | - if ( ! empty($this->others_cap)) { |
|
| 971 | - $caps[] = $this->others_cap; |
|
| 972 | - } |
|
| 973 | - if ( ! empty($this->published_cap) && $obj->status() == 'publish') { |
|
| 974 | - $caps[] = $this->published_cap; |
|
| 975 | - } elseif ( ! empty($this->private_cap) && $obj->status() == 'private') { |
|
| 976 | - $caps[] = $this->private_cap; |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - } else { |
|
| 980 | - //not a cpt object so handled differently |
|
| 981 | - $has_cap = false; |
|
| 982 | - try { |
|
| 983 | - $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
| 984 | - } catch (Exception $e) { |
|
| 985 | - if (WP_DEBUG) { |
|
| 986 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - if ($has_cap) { |
|
| 990 | - $caps[] = $cap; |
|
| 991 | - } else { |
|
| 992 | - if ( ! empty($this->others_cap)) { |
|
| 993 | - $caps[] = $this->others_cap; |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - } |
|
| 955 | + if ($obj instanceof EE_CPT_Base) { |
|
| 956 | + //if the item author is set and the user is the author... |
|
| 957 | + if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
| 958 | + if (empty($this->published_cap)) { |
|
| 959 | + $caps[] = $cap; |
|
| 960 | + } else { |
|
| 961 | + //if obj is published... |
|
| 962 | + if ($obj->status() == 'publish') { |
|
| 963 | + $caps[] = $this->published_cap; |
|
| 964 | + } else { |
|
| 965 | + $caps[] = $cap; |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + } else { |
|
| 969 | + //the user is trying to edit someone else's obj |
|
| 970 | + if ( ! empty($this->others_cap)) { |
|
| 971 | + $caps[] = $this->others_cap; |
|
| 972 | + } |
|
| 973 | + if ( ! empty($this->published_cap) && $obj->status() == 'publish') { |
|
| 974 | + $caps[] = $this->published_cap; |
|
| 975 | + } elseif ( ! empty($this->private_cap) && $obj->status() == 'private') { |
|
| 976 | + $caps[] = $this->private_cap; |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + } else { |
|
| 980 | + //not a cpt object so handled differently |
|
| 981 | + $has_cap = false; |
|
| 982 | + try { |
|
| 983 | + $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
| 984 | + } catch (Exception $e) { |
|
| 985 | + if (WP_DEBUG) { |
|
| 986 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + if ($has_cap) { |
|
| 990 | + $caps[] = $cap; |
|
| 991 | + } else { |
|
| 992 | + if ( ! empty($this->others_cap)) { |
|
| 993 | + $caps[] = $this->others_cap; |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | 997 | |
| 998 | - return $caps; |
|
| 999 | - } |
|
| 998 | + return $caps; |
|
| 999 | + } |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | |
@@ -1013,24 +1013,24 @@ discard block |
||
| 1013 | 1013 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
| 1014 | 1014 | { |
| 1015 | 1015 | |
| 1016 | - /** |
|
| 1017 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1018 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1019 | - * |
|
| 1020 | - * @since 4.5.0 |
|
| 1021 | - * @see wp-includes/capabilities.php |
|
| 1022 | - * |
|
| 1023 | - * @param array $caps actual users capabilities |
|
| 1024 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1025 | - * @param int $user_id The user id |
|
| 1026 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1027 | - * |
|
| 1028 | - * @return array actual users capabilities |
|
| 1029 | - */ |
|
| 1030 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1031 | - { |
|
| 1032 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1033 | - } |
|
| 1016 | + /** |
|
| 1017 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1018 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1019 | + * |
|
| 1020 | + * @since 4.5.0 |
|
| 1021 | + * @see wp-includes/capabilities.php |
|
| 1022 | + * |
|
| 1023 | + * @param array $caps actual users capabilities |
|
| 1024 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1025 | + * @param int $user_id The user id |
|
| 1026 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1027 | + * |
|
| 1028 | + * @return array actual users capabilities |
|
| 1029 | + */ |
|
| 1030 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1031 | + { |
|
| 1032 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1033 | + } |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | |
@@ -1046,78 +1046,78 @@ discard block |
||
| 1046 | 1046 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
| 1047 | 1047 | { |
| 1048 | 1048 | |
| 1049 | - /** |
|
| 1050 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1051 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1052 | - * |
|
| 1053 | - * @since 4.5.0 |
|
| 1054 | - * @see wp-includes/capabilities.php |
|
| 1055 | - * |
|
| 1056 | - * @param array $caps actual users capabilities |
|
| 1057 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1058 | - * @param int $user_id The user id |
|
| 1059 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1060 | - * |
|
| 1061 | - * @return array actual users capabilities |
|
| 1062 | - */ |
|
| 1063 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1064 | - { |
|
| 1065 | - //only process if we're checking our mapped cap; |
|
| 1066 | - if ($cap !== $this->meta_cap) { |
|
| 1067 | - return $caps; |
|
| 1068 | - } |
|
| 1049 | + /** |
|
| 1050 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1051 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1052 | + * |
|
| 1053 | + * @since 4.5.0 |
|
| 1054 | + * @see wp-includes/capabilities.php |
|
| 1055 | + * |
|
| 1056 | + * @param array $caps actual users capabilities |
|
| 1057 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1058 | + * @param int $user_id The user id |
|
| 1059 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1060 | + * |
|
| 1061 | + * @return array actual users capabilities |
|
| 1062 | + */ |
|
| 1063 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1064 | + { |
|
| 1065 | + //only process if we're checking our mapped cap; |
|
| 1066 | + if ($cap !== $this->meta_cap) { |
|
| 1067 | + return $caps; |
|
| 1068 | + } |
|
| 1069 | 1069 | |
| 1070 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1070 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1071 | 1071 | |
| 1072 | - //if no obj then let's just do cap |
|
| 1073 | - if ( ! $obj instanceof EE_Base_Class) { |
|
| 1074 | - $caps[] = $cap; |
|
| 1072 | + //if no obj then let's just do cap |
|
| 1073 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1074 | + $caps[] = $cap; |
|
| 1075 | 1075 | |
| 1076 | - return $caps; |
|
| 1077 | - } |
|
| 1076 | + return $caps; |
|
| 1077 | + } |
|
| 1078 | 1078 | |
| 1079 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1080 | - $status_obj = get_post_status_object($obj->status()); |
|
| 1081 | - if ($status_obj->public) { |
|
| 1082 | - $caps[] = $cap; |
|
| 1079 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1080 | + $status_obj = get_post_status_object($obj->status()); |
|
| 1081 | + if ($status_obj->public) { |
|
| 1082 | + $caps[] = $cap; |
|
| 1083 | 1083 | |
| 1084 | - return $caps; |
|
| 1085 | - } |
|
| 1084 | + return $caps; |
|
| 1085 | + } |
|
| 1086 | 1086 | |
| 1087 | - //if the item author is set and the user is the author... |
|
| 1088 | - if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
| 1089 | - $caps[] = $cap; |
|
| 1090 | - } elseif ($status_obj->private && ! empty($this->private_cap)) { |
|
| 1091 | - //the user is trying to view someone else's obj |
|
| 1092 | - $caps[] = $this->private_cap; |
|
| 1093 | - } elseif ( ! empty($this->others_cap)) { |
|
| 1094 | - $caps[] = $this->others_cap; |
|
| 1095 | - } else { |
|
| 1096 | - $caps[] = $cap; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - //not a cpt object so handled differently |
|
| 1100 | - $has_cap = false; |
|
| 1101 | - try { |
|
| 1102 | - $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
| 1103 | - } catch (Exception $e) { |
|
| 1104 | - if (WP_DEBUG) { |
|
| 1105 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - if ($has_cap) { |
|
| 1109 | - $caps[] = $cap; |
|
| 1110 | - } elseif ( ! empty($this->private_cap)) { |
|
| 1111 | - $caps[] = $this->private_cap; |
|
| 1112 | - } elseif ( ! empty($this->others_cap)) { |
|
| 1113 | - $caps[] = $this->others_cap; |
|
| 1114 | - } else { |
|
| 1115 | - $caps[] = $cap; |
|
| 1116 | - } |
|
| 1117 | - } |
|
| 1087 | + //if the item author is set and the user is the author... |
|
| 1088 | + if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
| 1089 | + $caps[] = $cap; |
|
| 1090 | + } elseif ($status_obj->private && ! empty($this->private_cap)) { |
|
| 1091 | + //the user is trying to view someone else's obj |
|
| 1092 | + $caps[] = $this->private_cap; |
|
| 1093 | + } elseif ( ! empty($this->others_cap)) { |
|
| 1094 | + $caps[] = $this->others_cap; |
|
| 1095 | + } else { |
|
| 1096 | + $caps[] = $cap; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + //not a cpt object so handled differently |
|
| 1100 | + $has_cap = false; |
|
| 1101 | + try { |
|
| 1102 | + $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
| 1103 | + } catch (Exception $e) { |
|
| 1104 | + if (WP_DEBUG) { |
|
| 1105 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + if ($has_cap) { |
|
| 1109 | + $caps[] = $cap; |
|
| 1110 | + } elseif ( ! empty($this->private_cap)) { |
|
| 1111 | + $caps[] = $this->private_cap; |
|
| 1112 | + } elseif ( ! empty($this->others_cap)) { |
|
| 1113 | + $caps[] = $this->others_cap; |
|
| 1114 | + } else { |
|
| 1115 | + $caps[] = $cap; |
|
| 1116 | + } |
|
| 1117 | + } |
|
| 1118 | 1118 | |
| 1119 | - return $caps; |
|
| 1120 | - } |
|
| 1119 | + return $caps; |
|
| 1120 | + } |
|
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | |
@@ -1134,54 +1134,54 @@ discard block |
||
| 1134 | 1134 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
| 1135 | 1135 | { |
| 1136 | 1136 | |
| 1137 | - /** |
|
| 1138 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1139 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1140 | - * |
|
| 1141 | - * @since 4.5.0 |
|
| 1142 | - * @see wp-includes/capabilities.php |
|
| 1143 | - * |
|
| 1144 | - * @param array $caps actual users capabilities |
|
| 1145 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1146 | - * @param int $user_id The user id |
|
| 1147 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1148 | - * |
|
| 1149 | - * @return array actual users capabilities |
|
| 1150 | - */ |
|
| 1151 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1152 | - { |
|
| 1153 | - //only process if we're checking our mapped_cap |
|
| 1154 | - if ($cap !== $this->meta_cap) { |
|
| 1155 | - return $caps; |
|
| 1156 | - } |
|
| 1137 | + /** |
|
| 1138 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1139 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1140 | + * |
|
| 1141 | + * @since 4.5.0 |
|
| 1142 | + * @see wp-includes/capabilities.php |
|
| 1143 | + * |
|
| 1144 | + * @param array $caps actual users capabilities |
|
| 1145 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1146 | + * @param int $user_id The user id |
|
| 1147 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1148 | + * |
|
| 1149 | + * @return array actual users capabilities |
|
| 1150 | + */ |
|
| 1151 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1152 | + { |
|
| 1153 | + //only process if we're checking our mapped_cap |
|
| 1154 | + if ($cap !== $this->meta_cap) { |
|
| 1155 | + return $caps; |
|
| 1156 | + } |
|
| 1157 | 1157 | |
| 1158 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1158 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1159 | 1159 | |
| 1160 | - //if no obj then let's just do cap |
|
| 1161 | - if ( ! $obj instanceof EE_Message_Template_Group) { |
|
| 1162 | - $caps[] = $cap; |
|
| 1160 | + //if no obj then let's just do cap |
|
| 1161 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
| 1162 | + $caps[] = $cap; |
|
| 1163 | 1163 | |
| 1164 | - return $caps; |
|
| 1165 | - } |
|
| 1164 | + return $caps; |
|
| 1165 | + } |
|
| 1166 | 1166 | |
| 1167 | - $is_global = $obj->is_global(); |
|
| 1167 | + $is_global = $obj->is_global(); |
|
| 1168 | 1168 | |
| 1169 | - if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
| 1170 | - if ($is_global) { |
|
| 1171 | - $caps[] = $this->private_cap; |
|
| 1172 | - } else { |
|
| 1173 | - $caps[] = $cap; |
|
| 1174 | - } |
|
| 1175 | - } else { |
|
| 1176 | - if ($is_global) { |
|
| 1177 | - $caps[] = $this->private_cap; |
|
| 1178 | - } else { |
|
| 1179 | - $caps[] = $this->others_cap; |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1169 | + if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
| 1170 | + if ($is_global) { |
|
| 1171 | + $caps[] = $this->private_cap; |
|
| 1172 | + } else { |
|
| 1173 | + $caps[] = $cap; |
|
| 1174 | + } |
|
| 1175 | + } else { |
|
| 1176 | + if ($is_global) { |
|
| 1177 | + $caps[] = $this->private_cap; |
|
| 1178 | + } else { |
|
| 1179 | + $caps[] = $this->others_cap; |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | 1182 | |
| 1183 | - return $caps; |
|
| 1184 | - } |
|
| 1183 | + return $caps; |
|
| 1184 | + } |
|
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | |
@@ -1198,45 +1198,45 @@ discard block |
||
| 1198 | 1198 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
| 1199 | 1199 | { |
| 1200 | 1200 | |
| 1201 | - /** |
|
| 1202 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1203 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1204 | - * |
|
| 1205 | - * @since 4.5.0 |
|
| 1206 | - * @see wp-includes/capabilities.php |
|
| 1207 | - * |
|
| 1208 | - * @param array $caps actual users capabilities |
|
| 1209 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1210 | - * @param int $user_id The user id |
|
| 1211 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1212 | - * |
|
| 1213 | - * @return array actual users capabilities |
|
| 1214 | - */ |
|
| 1215 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1216 | - { |
|
| 1217 | - //only process if we're checking our mapped_cap |
|
| 1218 | - if ($cap !== $this->meta_cap) { |
|
| 1219 | - return $caps; |
|
| 1220 | - } |
|
| 1201 | + /** |
|
| 1202 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1203 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1204 | + * |
|
| 1205 | + * @since 4.5.0 |
|
| 1206 | + * @see wp-includes/capabilities.php |
|
| 1207 | + * |
|
| 1208 | + * @param array $caps actual users capabilities |
|
| 1209 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1210 | + * @param int $user_id The user id |
|
| 1211 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1212 | + * |
|
| 1213 | + * @return array actual users capabilities |
|
| 1214 | + */ |
|
| 1215 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1216 | + { |
|
| 1217 | + //only process if we're checking our mapped_cap |
|
| 1218 | + if ($cap !== $this->meta_cap) { |
|
| 1219 | + return $caps; |
|
| 1220 | + } |
|
| 1221 | 1221 | |
| 1222 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1222 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1223 | 1223 | |
| 1224 | - //if no obj then let's just do cap |
|
| 1225 | - if ( ! $obj instanceof EE_Base_Class) { |
|
| 1226 | - $caps[] = $cap; |
|
| 1224 | + //if no obj then let's just do cap |
|
| 1225 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1226 | + $caps[] = $cap; |
|
| 1227 | 1227 | |
| 1228 | - return $caps; |
|
| 1229 | - } |
|
| 1228 | + return $caps; |
|
| 1229 | + } |
|
| 1230 | 1230 | |
| 1231 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1232 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1231 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1232 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1233 | 1233 | |
| 1234 | - if ($is_system) { |
|
| 1235 | - $caps[] = $this->private_cap; |
|
| 1236 | - } else { |
|
| 1237 | - $caps[] = $cap; |
|
| 1238 | - } |
|
| 1234 | + if ($is_system) { |
|
| 1235 | + $caps[] = $this->private_cap; |
|
| 1236 | + } else { |
|
| 1237 | + $caps[] = $cap; |
|
| 1238 | + } |
|
| 1239 | 1239 | |
| 1240 | - return $caps; |
|
| 1241 | - } |
|
| 1240 | + return $caps; |
|
| 1241 | + } |
|
| 1242 | 1242 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
| 235 | 235 | //loop through our _meta_caps array |
| 236 | 236 | foreach ($this->_meta_caps as $meta_map) { |
| 237 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 237 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 238 | 238 | continue; |
| 239 | 239 | } |
| 240 | 240 | $meta_map->ensure_is_model(); |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | public function current_user_can($cap, $context, $id = 0) |
| 691 | 691 | { |
| 692 | 692 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 693 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 693 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
| 694 | 694 | $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
| 695 | 695 | $id); |
| 696 | 696 | |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | public function user_can($user, $cap, $context, $id = 0) |
| 713 | 713 | { |
| 714 | 714 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 715 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 715 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
| 716 | 716 | $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
| 717 | 717 | $id); |
| 718 | 718 | |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | $user_can = ! empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap); |
| 743 | 743 | |
| 744 | 744 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 745 | - $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, |
|
| 745 | + $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, $user_can, |
|
| 746 | 746 | $blog_id, $cap, $id); |
| 747 | 747 | $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, |
| 748 | 748 | $blog_id, $cap, $id); |
@@ -825,15 +825,15 @@ discard block |
||
| 825 | 825 | //verify there are four args in the $map_values array; |
| 826 | 826 | if (count($map_values) !== 4) { |
| 827 | 827 | throw new EE_Error(sprintf(__('Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
| 828 | - 'event_espresso'), '<br>' . print_r($map_values, true))); |
|
| 828 | + 'event_espresso'), '<br>'.print_r($map_values, true))); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | //set properties |
| 832 | 832 | $this->_model = null; |
| 833 | 833 | $this->_model_name = $map_values[0]; |
| 834 | - $this->published_cap = (string)$map_values[1]; |
|
| 835 | - $this->others_cap = (string)$map_values[2]; |
|
| 836 | - $this->private_cap = (string)$map_values[3]; |
|
| 834 | + $this->published_cap = (string) $map_values[1]; |
|
| 835 | + $this->others_cap = (string) $map_values[2]; |
|
| 836 | + $this->private_cap = (string) $map_values[3]; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | //ensure model name is string |
| 864 | - $this->_model_name = (string)$this->_model_name; |
|
| 864 | + $this->_model_name = (string) $this->_model_name; |
|
| 865 | 865 | //error proof if the name has EEM in it |
| 866 | 866 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
| 867 | 867 | |
@@ -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 | |
@@ -16,1364 +16,1364 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 21 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 22 | - */ |
|
| 23 | - const req_type_normal = 0; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Indicates this is a brand new installation of EE so we should install |
|
| 27 | - * tables and default data etc |
|
| 28 | - */ |
|
| 29 | - const req_type_new_activation = 1; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 33 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 34 | - * and that default data is setup too |
|
| 35 | - */ |
|
| 36 | - const req_type_reactivation = 2; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * indicates that EE has been upgraded since its previous request. |
|
| 40 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 41 | - */ |
|
| 42 | - const req_type_upgrade = 3; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 46 | - */ |
|
| 47 | - const req_type_downgrade = 4; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @deprecated since version 4.6.0.dev.006 |
|
| 51 | - * Now whenever a new_activation is detected the request type is still just |
|
| 52 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 53 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 54 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 55 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 56 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 57 | - */ |
|
| 58 | - const req_type_activation_but_not_installed = 5; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 62 | - */ |
|
| 63 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * instance of the EE_System object |
|
| 68 | - * |
|
| 69 | - * @var $_instance |
|
| 70 | - * @access private |
|
| 71 | - */ |
|
| 72 | - private static $_instance = null; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type EE_Registry $Registry |
|
| 76 | - * @access protected |
|
| 77 | - */ |
|
| 78 | - protected $registry; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 82 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 83 | - * |
|
| 84 | - * @var int |
|
| 85 | - */ |
|
| 86 | - private $_req_type; |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @singleton method used to instantiate class object |
|
| 92 | - * @access public |
|
| 93 | - * @param \EE_Registry $Registry |
|
| 94 | - * @return \EE_System |
|
| 95 | - */ |
|
| 96 | - public static function instance(EE_Registry $Registry = null) |
|
| 97 | - { |
|
| 98 | - // check if class object is instantiated |
|
| 99 | - if ( ! self::$_instance instanceof EE_System) { |
|
| 100 | - self::$_instance = new self($Registry); |
|
| 101 | - } |
|
| 102 | - return self::$_instance; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * resets the instance and returns it |
|
| 109 | - * |
|
| 110 | - * @return EE_System |
|
| 111 | - */ |
|
| 112 | - public static function reset() |
|
| 113 | - { |
|
| 114 | - self::$_instance->_req_type = null; |
|
| 115 | - //make sure none of the old hooks are left hanging around |
|
| 116 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 117 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 118 | - EE_Data_Migration_Manager::reset(); |
|
| 119 | - self::instance()->detect_activations_or_upgrades(); |
|
| 120 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 121 | - return self::instance(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * sets hooks for running rest of system |
|
| 128 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 129 | - * starting EE Addons from any other point may lead to problems |
|
| 130 | - * |
|
| 131 | - * @access private |
|
| 132 | - * @param \EE_Registry $Registry |
|
| 133 | - */ |
|
| 134 | - private function __construct(EE_Registry $Registry) |
|
| 135 | - { |
|
| 136 | - $this->registry = $Registry; |
|
| 137 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 138 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 139 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
| 140 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 141 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 142 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 143 | - // detect whether install or upgrade |
|
| 144 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
| 145 | - 3); |
|
| 146 | - // load EE_Config, EE_Textdomain, etc |
|
| 147 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
| 148 | - // load EE_Config, EE_Textdomain, etc |
|
| 149 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 150 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
| 151 | - // you wanna get going? I wanna get going... let's get going! |
|
| 152 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
| 153 | - //other housekeeping |
|
| 154 | - //exclude EE critical pages from wp_list_pages |
|
| 155 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
| 156 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 157 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 158 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * load_espresso_addons |
|
| 165 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 166 | - * this is hooked into both: |
|
| 167 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 168 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 169 | - * and the WP 'activate_plugin' hookpoint |
|
| 170 | - * |
|
| 171 | - * @access public |
|
| 172 | - * @return void |
|
| 173 | - */ |
|
| 174 | - public function load_espresso_addons() |
|
| 175 | - { |
|
| 176 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 177 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 178 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 179 | - //load and setup EE_Capabilities |
|
| 180 | - $this->registry->load_core('Capabilities'); |
|
| 181 | - //caps need to be initialized on every request so that capability maps are set. |
|
| 182 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 183 | - $this->registry->CAP->init_caps(); |
|
| 184 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 185 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 186 | - //We want it for mobile apps. Just include the entire plugin |
|
| 187 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
| 188 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 189 | - //and causes a fatal error |
|
| 190 | - if ( ! function_exists('json_basic_auth_handler') |
|
| 191 | - && ! function_exists('json_basic_auth_error') |
|
| 192 | - && ! ( |
|
| 193 | - isset($_GET['action']) |
|
| 194 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
| 195 | - ) |
|
| 196 | - && ! ( |
|
| 197 | - isset($_GET['activate']) |
|
| 198 | - && $_GET['activate'] === 'true' |
|
| 199 | - ) |
|
| 200 | - ) { |
|
| 201 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 202 | - } |
|
| 19 | + /** |
|
| 20 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 21 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 22 | + */ |
|
| 23 | + const req_type_normal = 0; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Indicates this is a brand new installation of EE so we should install |
|
| 27 | + * tables and default data etc |
|
| 28 | + */ |
|
| 29 | + const req_type_new_activation = 1; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 33 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 34 | + * and that default data is setup too |
|
| 35 | + */ |
|
| 36 | + const req_type_reactivation = 2; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * indicates that EE has been upgraded since its previous request. |
|
| 40 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 41 | + */ |
|
| 42 | + const req_type_upgrade = 3; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 46 | + */ |
|
| 47 | + const req_type_downgrade = 4; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @deprecated since version 4.6.0.dev.006 |
|
| 51 | + * Now whenever a new_activation is detected the request type is still just |
|
| 52 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 53 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 54 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 55 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 56 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 57 | + */ |
|
| 58 | + const req_type_activation_but_not_installed = 5; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 62 | + */ |
|
| 63 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * instance of the EE_System object |
|
| 68 | + * |
|
| 69 | + * @var $_instance |
|
| 70 | + * @access private |
|
| 71 | + */ |
|
| 72 | + private static $_instance = null; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type EE_Registry $Registry |
|
| 76 | + * @access protected |
|
| 77 | + */ |
|
| 78 | + protected $registry; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 82 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 83 | + * |
|
| 84 | + * @var int |
|
| 85 | + */ |
|
| 86 | + private $_req_type; |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @singleton method used to instantiate class object |
|
| 92 | + * @access public |
|
| 93 | + * @param \EE_Registry $Registry |
|
| 94 | + * @return \EE_System |
|
| 95 | + */ |
|
| 96 | + public static function instance(EE_Registry $Registry = null) |
|
| 97 | + { |
|
| 98 | + // check if class object is instantiated |
|
| 99 | + if ( ! self::$_instance instanceof EE_System) { |
|
| 100 | + self::$_instance = new self($Registry); |
|
| 101 | + } |
|
| 102 | + return self::$_instance; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * resets the instance and returns it |
|
| 109 | + * |
|
| 110 | + * @return EE_System |
|
| 111 | + */ |
|
| 112 | + public static function reset() |
|
| 113 | + { |
|
| 114 | + self::$_instance->_req_type = null; |
|
| 115 | + //make sure none of the old hooks are left hanging around |
|
| 116 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 117 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 118 | + EE_Data_Migration_Manager::reset(); |
|
| 119 | + self::instance()->detect_activations_or_upgrades(); |
|
| 120 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 121 | + return self::instance(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * sets hooks for running rest of system |
|
| 128 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 129 | + * starting EE Addons from any other point may lead to problems |
|
| 130 | + * |
|
| 131 | + * @access private |
|
| 132 | + * @param \EE_Registry $Registry |
|
| 133 | + */ |
|
| 134 | + private function __construct(EE_Registry $Registry) |
|
| 135 | + { |
|
| 136 | + $this->registry = $Registry; |
|
| 137 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 138 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 139 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
| 140 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 141 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 142 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 143 | + // detect whether install or upgrade |
|
| 144 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
| 145 | + 3); |
|
| 146 | + // load EE_Config, EE_Textdomain, etc |
|
| 147 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
| 148 | + // load EE_Config, EE_Textdomain, etc |
|
| 149 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 150 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
| 151 | + // you wanna get going? I wanna get going... let's get going! |
|
| 152 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
| 153 | + //other housekeeping |
|
| 154 | + //exclude EE critical pages from wp_list_pages |
|
| 155 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
| 156 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 157 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 158 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * load_espresso_addons |
|
| 165 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 166 | + * this is hooked into both: |
|
| 167 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 168 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 169 | + * and the WP 'activate_plugin' hookpoint |
|
| 170 | + * |
|
| 171 | + * @access public |
|
| 172 | + * @return void |
|
| 173 | + */ |
|
| 174 | + public function load_espresso_addons() |
|
| 175 | + { |
|
| 176 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 177 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 178 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 179 | + //load and setup EE_Capabilities |
|
| 180 | + $this->registry->load_core('Capabilities'); |
|
| 181 | + //caps need to be initialized on every request so that capability maps are set. |
|
| 182 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 183 | + $this->registry->CAP->init_caps(); |
|
| 184 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 185 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 186 | + //We want it for mobile apps. Just include the entire plugin |
|
| 187 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
| 188 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 189 | + //and causes a fatal error |
|
| 190 | + if ( ! function_exists('json_basic_auth_handler') |
|
| 191 | + && ! function_exists('json_basic_auth_error') |
|
| 192 | + && ! ( |
|
| 193 | + isset($_GET['action']) |
|
| 194 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
| 195 | + ) |
|
| 196 | + && ! ( |
|
| 197 | + isset($_GET['activate']) |
|
| 198 | + && $_GET['activate'] === 'true' |
|
| 199 | + ) |
|
| 200 | + ) { |
|
| 201 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * detect_activations_or_upgrades |
|
| 211 | - * Checks for activation or upgrade of core first; |
|
| 212 | - * then also checks if any registered addons have been activated or upgraded |
|
| 213 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 214 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 215 | - * |
|
| 216 | - * @access public |
|
| 217 | - * @return void |
|
| 218 | - */ |
|
| 219 | - public function detect_activations_or_upgrades() |
|
| 220 | - { |
|
| 221 | - //first off: let's make sure to handle core |
|
| 222 | - $this->detect_if_activation_or_upgrade(); |
|
| 223 | - foreach ($this->registry->addons as $addon) { |
|
| 224 | - //detect teh request type for that addon |
|
| 225 | - $addon->detect_activation_or_upgrade(); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * detect_if_activation_or_upgrade |
|
| 233 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 234 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 235 | - * |
|
| 236 | - * @access public |
|
| 237 | - * @return void |
|
| 238 | - */ |
|
| 239 | - public function detect_if_activation_or_upgrade() |
|
| 240 | - { |
|
| 241 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 242 | - // load M-Mode class |
|
| 243 | - $this->registry->load_core('Maintenance_Mode'); |
|
| 244 | - // check if db has been updated, or if its a brand-new installation |
|
| 245 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 246 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 247 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 248 | - switch ($request_type) { |
|
| 249 | - case EE_System::req_type_new_activation: |
|
| 250 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 251 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 252 | - break; |
|
| 253 | - case EE_System::req_type_reactivation: |
|
| 254 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 255 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 256 | - break; |
|
| 257 | - case EE_System::req_type_upgrade: |
|
| 258 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 259 | - //migrations may be required now that we've upgraded |
|
| 260 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 261 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 204 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * detect_activations_or_upgrades |
|
| 211 | + * Checks for activation or upgrade of core first; |
|
| 212 | + * then also checks if any registered addons have been activated or upgraded |
|
| 213 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 214 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 215 | + * |
|
| 216 | + * @access public |
|
| 217 | + * @return void |
|
| 218 | + */ |
|
| 219 | + public function detect_activations_or_upgrades() |
|
| 220 | + { |
|
| 221 | + //first off: let's make sure to handle core |
|
| 222 | + $this->detect_if_activation_or_upgrade(); |
|
| 223 | + foreach ($this->registry->addons as $addon) { |
|
| 224 | + //detect teh request type for that addon |
|
| 225 | + $addon->detect_activation_or_upgrade(); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * detect_if_activation_or_upgrade |
|
| 233 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 234 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 235 | + * |
|
| 236 | + * @access public |
|
| 237 | + * @return void |
|
| 238 | + */ |
|
| 239 | + public function detect_if_activation_or_upgrade() |
|
| 240 | + { |
|
| 241 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 242 | + // load M-Mode class |
|
| 243 | + $this->registry->load_core('Maintenance_Mode'); |
|
| 244 | + // check if db has been updated, or if its a brand-new installation |
|
| 245 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 246 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 247 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 248 | + switch ($request_type) { |
|
| 249 | + case EE_System::req_type_new_activation: |
|
| 250 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 251 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 252 | + break; |
|
| 253 | + case EE_System::req_type_reactivation: |
|
| 254 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 255 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 256 | + break; |
|
| 257 | + case EE_System::req_type_upgrade: |
|
| 258 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 259 | + //migrations may be required now that we've upgraded |
|
| 260 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 261 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 262 | 262 | // echo "done upgrade";die; |
| 263 | - break; |
|
| 264 | - case EE_System::req_type_downgrade: |
|
| 265 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 266 | - //its possible migrations are no longer required |
|
| 267 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 268 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 269 | - break; |
|
| 270 | - case EE_System::req_type_normal: |
|
| 271 | - default: |
|
| 263 | + break; |
|
| 264 | + case EE_System::req_type_downgrade: |
|
| 265 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 266 | + //its possible migrations are no longer required |
|
| 267 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 268 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 269 | + break; |
|
| 270 | + case EE_System::req_type_normal: |
|
| 271 | + default: |
|
| 272 | 272 | // $this->_maybe_redirect_to_ee_about(); |
| 273 | - break; |
|
| 274 | - } |
|
| 275 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Updates the list of installed versions and sets hooks for |
|
| 282 | - * initializing the database later during the request |
|
| 283 | - * |
|
| 284 | - * @param array $espresso_db_update |
|
| 285 | - */ |
|
| 286 | - protected function _handle_core_version_change($espresso_db_update) |
|
| 287 | - { |
|
| 288 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 289 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 290 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 291 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 298 | - * information about what versions of EE have been installed and activated, |
|
| 299 | - * NOT necessarily the state of the database |
|
| 300 | - * |
|
| 301 | - * @param null $espresso_db_update |
|
| 302 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
| 303 | - * from the options table |
|
| 304 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 305 | - */ |
|
| 306 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 307 | - { |
|
| 308 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 309 | - if ( ! $espresso_db_update) { |
|
| 310 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 311 | - } |
|
| 312 | - // check that option is an array |
|
| 313 | - if ( ! is_array($espresso_db_update)) { |
|
| 314 | - // if option is FALSE, then it never existed |
|
| 315 | - if ($espresso_db_update === false) { |
|
| 316 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 317 | - $espresso_db_update = array(); |
|
| 318 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 319 | - } else { |
|
| 320 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 321 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 322 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 323 | - } |
|
| 324 | - } else { |
|
| 325 | - $corrected_db_update = array(); |
|
| 326 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 327 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 328 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 329 | - //the key is an int, and the value IS NOT an array |
|
| 330 | - //so it must be numerically-indexed, where values are versions installed... |
|
| 331 | - //fix it! |
|
| 332 | - $version_string = $should_be_array; |
|
| 333 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 334 | - } else { |
|
| 335 | - //ok it checks out |
|
| 336 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - $espresso_db_update = $corrected_db_update; |
|
| 340 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 341 | - } |
|
| 342 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 343 | - return $espresso_db_update; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 350 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 351 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 352 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 353 | - * so that it will be done when migrations are finished |
|
| 354 | - * |
|
| 355 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 356 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 357 | - * This is a resource-intensive job |
|
| 358 | - * so we prefer to only do it when necessary |
|
| 359 | - * @return void |
|
| 360 | - */ |
|
| 361 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 362 | - { |
|
| 363 | - $request_type = $this->detect_req_type(); |
|
| 364 | - //only initialize system if we're not in maintenance mode. |
|
| 365 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 366 | - update_option('ee_flush_rewrite_rules', true); |
|
| 367 | - if ($verify_schema) { |
|
| 368 | - EEH_Activation::initialize_db_and_folders(); |
|
| 369 | - } |
|
| 370 | - EEH_Activation::initialize_db_content(); |
|
| 371 | - EEH_Activation::system_initialization(); |
|
| 372 | - if ($initialize_addons_too) { |
|
| 373 | - $this->initialize_addons(); |
|
| 374 | - } |
|
| 375 | - } else { |
|
| 376 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 377 | - } |
|
| 378 | - if ($request_type == EE_System::req_type_new_activation |
|
| 379 | - || $request_type == EE_System::req_type_reactivation |
|
| 380 | - || $request_type == EE_System::req_type_upgrade |
|
| 381 | - ) { |
|
| 382 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Initializes the db for all registered addons |
|
| 390 | - */ |
|
| 391 | - public function initialize_addons() |
|
| 392 | - { |
|
| 393 | - //foreach registered addon, make sure its db is up-to-date too |
|
| 394 | - foreach ($this->registry->addons as $addon) { |
|
| 395 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 403 | - * |
|
| 404 | - * @param array $version_history |
|
| 405 | - * @param string $current_version_to_add version to be added to the version history |
|
| 406 | - * @return boolean success as to whether or not this option was changed |
|
| 407 | - */ |
|
| 408 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 409 | - { |
|
| 410 | - if ( ! $version_history) { |
|
| 411 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 412 | - } |
|
| 413 | - if ($current_version_to_add == null) { |
|
| 414 | - $current_version_to_add = espresso_version(); |
|
| 415 | - } |
|
| 416 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 417 | - // re-save |
|
| 418 | - return update_option('espresso_db_update', $version_history); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Detects if the current version indicated in the has existed in the list of |
|
| 425 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 426 | - * |
|
| 427 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 428 | - * If not supplied, fetches it from the options table. |
|
| 429 | - * Also, caches its result so later parts of the code can also know whether |
|
| 430 | - * there's been an update or not. This way we can add the current version to |
|
| 431 | - * espresso_db_update, but still know if this is a new install or not |
|
| 432 | - * @return int one of the constants on EE_System::req_type_ |
|
| 433 | - */ |
|
| 434 | - public function detect_req_type($espresso_db_update = null) |
|
| 435 | - { |
|
| 436 | - if ($this->_req_type === null) { |
|
| 437 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 438 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 439 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
| 440 | - 'ee_espresso_activation', espresso_version()); |
|
| 441 | - } |
|
| 442 | - return $this->_req_type; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 449 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
| 450 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 451 | - * just activated to (for core that will always be espresso_version()) |
|
| 452 | - * |
|
| 453 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 454 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 455 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
| 456 | - * indicate that this plugin was just activated |
|
| 457 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 458 | - * espresso_version()) |
|
| 459 | - * @return int one of the constants on EE_System::req_type_* |
|
| 460 | - */ |
|
| 461 | - public static function detect_req_type_given_activation_history( |
|
| 462 | - $activation_history_for_addon, |
|
| 463 | - $activation_indicator_option_name, |
|
| 464 | - $version_to_upgrade_to |
|
| 465 | - ) { |
|
| 466 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 467 | - if ($activation_history_for_addon) { |
|
| 468 | - //it exists, so this isn't a completely new install |
|
| 469 | - //check if this version already in that list of previously installed versions |
|
| 470 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 471 | - //it a version we haven't seen before |
|
| 472 | - if ($version_is_higher === 1) { |
|
| 473 | - $req_type = EE_System::req_type_upgrade; |
|
| 474 | - } else { |
|
| 475 | - $req_type = EE_System::req_type_downgrade; |
|
| 476 | - } |
|
| 477 | - delete_option($activation_indicator_option_name); |
|
| 478 | - } else { |
|
| 479 | - // its not an update. maybe a reactivation? |
|
| 480 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 481 | - if ($version_is_higher === -1) { |
|
| 482 | - $req_type = EE_System::req_type_downgrade; |
|
| 483 | - } elseif ($version_is_higher === 0) { |
|
| 484 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
| 485 | - $req_type = EE_System::req_type_reactivation; |
|
| 486 | - } else {//$version_is_higher === 1 |
|
| 487 | - $req_type = EE_System::req_type_upgrade; |
|
| 488 | - } |
|
| 489 | - delete_option($activation_indicator_option_name); |
|
| 490 | - } else { |
|
| 491 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 492 | - if ($version_is_higher === -1) { |
|
| 493 | - $req_type = EE_System::req_type_downgrade; |
|
| 494 | - } elseif ($version_is_higher === 0) { |
|
| 495 | - //we've seen this version before and it's not an activation. its normal request |
|
| 496 | - $req_type = EE_System::req_type_normal; |
|
| 497 | - } else {//$version_is_higher === 1 |
|
| 498 | - $req_type = EE_System::req_type_upgrade; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } else { |
|
| 503 | - //brand new install |
|
| 504 | - $req_type = EE_System::req_type_new_activation; |
|
| 505 | - delete_option($activation_indicator_option_name); |
|
| 506 | - } |
|
| 507 | - return $req_type; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 514 | - * the $activation_history_for_addon |
|
| 515 | - * |
|
| 516 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 517 | - * sometimes containing 'unknown-date' |
|
| 518 | - * @param string $version_to_upgrade_to (current version) |
|
| 519 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 520 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 521 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 522 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 523 | - */ |
|
| 524 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 525 | - { |
|
| 526 | - //find the most recently-activated version |
|
| 527 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 528 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 529 | - if (is_array($activation_history_for_addon)) { |
|
| 530 | - foreach ($activation_history_for_addon as $version => $times_activated) { |
|
| 531 | - //check there is a record of when this version was activated. Otherwise, |
|
| 532 | - //mark it as unknown |
|
| 533 | - if ( ! $times_activated) { |
|
| 534 | - $times_activated = array('unknown-date'); |
|
| 535 | - } |
|
| 536 | - if (is_string($times_activated)) { |
|
| 537 | - $times_activated = array($times_activated); |
|
| 538 | - } |
|
| 539 | - foreach ($times_activated as $an_activation) { |
|
| 540 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 541 | - $most_recently_active_version = $version; |
|
| 542 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
| 543 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * This redirects to the about EE page after activation |
|
| 555 | - * |
|
| 556 | - * @return void |
|
| 557 | - */ |
|
| 558 | - public function redirect_to_about_ee() |
|
| 559 | - { |
|
| 560 | - $notices = EE_Error::get_notices(false); |
|
| 561 | - //if current user is an admin and it's not an ajax request |
|
| 562 | - if ( |
|
| 563 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 564 | - && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 565 | - && ! isset($notices['errors']) |
|
| 566 | - ) { |
|
| 567 | - $query_params = array('page' => 'espresso_about'); |
|
| 568 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
| 569 | - $query_params['new_activation'] = true; |
|
| 570 | - } |
|
| 571 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
| 572 | - $query_params['reactivation'] = true; |
|
| 573 | - } |
|
| 574 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 575 | - wp_safe_redirect($url); |
|
| 576 | - exit(); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * load_core_configuration |
|
| 584 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 585 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 586 | - * |
|
| 587 | - * @return void |
|
| 588 | - */ |
|
| 589 | - public function load_core_configuration() |
|
| 590 | - { |
|
| 591 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 592 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
| 593 | - //load textdomain |
|
| 594 | - EE_Load_Textdomain::load_textdomain(); |
|
| 595 | - // load and setup EE_Config and EE_Network_Config |
|
| 596 | - $this->registry->load_core('Config'); |
|
| 597 | - $this->registry->load_core('Network_Config'); |
|
| 598 | - // setup autoloaders |
|
| 599 | - // enable logging? |
|
| 600 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
| 601 | - $this->registry->load_core('Log'); |
|
| 602 | - } |
|
| 603 | - // check for activation errors |
|
| 604 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 605 | - if ($activation_errors) { |
|
| 606 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 607 | - update_option('ee_plugin_activation_errors', false); |
|
| 608 | - } |
|
| 609 | - // get model names |
|
| 610 | - $this->_parse_model_names(); |
|
| 611 | - //load caf stuff a chance to play during the activation process too. |
|
| 612 | - $this->_maybe_brew_regular(); |
|
| 613 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 620 | - * |
|
| 621 | - * @return void |
|
| 622 | - */ |
|
| 623 | - private function _parse_model_names() |
|
| 624 | - { |
|
| 625 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
| 626 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 627 | - $model_names = array(); |
|
| 628 | - $non_abstract_db_models = array(); |
|
| 629 | - foreach ($models as $model) { |
|
| 630 | - // get model classname |
|
| 631 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 632 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 633 | - $reflectionClass = new ReflectionClass($classname); |
|
| 634 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 635 | - $non_abstract_db_models[$short_name] = $classname; |
|
| 636 | - } |
|
| 637 | - $model_names[$short_name] = $classname; |
|
| 638 | - } |
|
| 639 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 640 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 641 | - $non_abstract_db_models); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 648 | - * that need to be setup before our EE_System launches. |
|
| 649 | - * |
|
| 650 | - * @return void |
|
| 651 | - */ |
|
| 652 | - private function _maybe_brew_regular() |
|
| 653 | - { |
|
| 654 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 655 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * register_shortcodes_modules_and_widgets |
|
| 663 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 664 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 665 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 666 | - * |
|
| 667 | - * @access public |
|
| 668 | - * @return void |
|
| 669 | - */ |
|
| 670 | - public function register_shortcodes_modules_and_widgets() |
|
| 671 | - { |
|
| 672 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 673 | - // check for addons using old hookpoint |
|
| 674 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 675 | - $this->_incompatible_addon_error(); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * _incompatible_addon_error |
|
| 683 | - * |
|
| 684 | - * @access public |
|
| 685 | - * @return void |
|
| 686 | - */ |
|
| 687 | - private function _incompatible_addon_error() |
|
| 688 | - { |
|
| 689 | - // get array of classes hooking into here |
|
| 690 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 691 | - if ( ! empty($class_names)) { |
|
| 692 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 693 | - 'event_espresso'); |
|
| 694 | - $msg .= '<ul>'; |
|
| 695 | - foreach ($class_names as $class_name) { |
|
| 696 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 697 | - $class_name) . '</b></li>'; |
|
| 698 | - } |
|
| 699 | - $msg .= '</ul>'; |
|
| 700 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 701 | - 'event_espresso'); |
|
| 702 | - // save list of incompatible addons to wp-options for later use |
|
| 703 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 704 | - if (is_admin()) { |
|
| 705 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * brew_espresso |
|
| 714 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 715 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
| 716 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 717 | - * |
|
| 718 | - * @return void |
|
| 719 | - */ |
|
| 720 | - public function brew_espresso() |
|
| 721 | - { |
|
| 722 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 723 | - // load some final core systems |
|
| 724 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 725 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 726 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 727 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 728 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 729 | - add_action('init', array($this, 'initialize'), 10); |
|
| 730 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 731 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25); |
|
| 732 | - add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25); |
|
| 733 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 734 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 735 | - // pew pew pew |
|
| 736 | - $this->registry->load_core('PUE'); |
|
| 737 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 738 | - } |
|
| 739 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * set_hooks_for_core |
|
| 746 | - * |
|
| 747 | - * @access public |
|
| 748 | - * @return void |
|
| 749 | - */ |
|
| 750 | - public function set_hooks_for_core() |
|
| 751 | - { |
|
| 752 | - $this->_deactivate_incompatible_addons(); |
|
| 753 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 760 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 761 | - */ |
|
| 762 | - private function _deactivate_incompatible_addons() |
|
| 763 | - { |
|
| 764 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 765 | - if ( ! empty($incompatible_addons)) { |
|
| 766 | - $active_plugins = get_option('active_plugins', array()); |
|
| 767 | - foreach ($active_plugins as $active_plugin) { |
|
| 768 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 769 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 770 | - unset($_GET['activate']); |
|
| 771 | - espresso_deactivate_plugin($active_plugin); |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - /** |
|
| 781 | - * perform_activations_upgrades_and_migrations |
|
| 782 | - * |
|
| 783 | - * @access public |
|
| 784 | - * @return void |
|
| 785 | - */ |
|
| 786 | - public function perform_activations_upgrades_and_migrations() |
|
| 787 | - { |
|
| 788 | - //first check if we had previously attempted to setup EE's directories but failed |
|
| 789 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
| 790 | - EEH_Activation::create_upload_directories(); |
|
| 791 | - } |
|
| 792 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * load_CPTs_and_session |
|
| 799 | - * |
|
| 800 | - * @access public |
|
| 801 | - * @return void |
|
| 802 | - */ |
|
| 803 | - public function load_CPTs_and_session() |
|
| 804 | - { |
|
| 805 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 806 | - // register Custom Post Types |
|
| 807 | - $this->registry->load_core('Register_CPTs'); |
|
| 808 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * load_controllers |
|
| 815 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 816 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 817 | - * time |
|
| 818 | - * |
|
| 819 | - * @access public |
|
| 820 | - * @return void |
|
| 821 | - */ |
|
| 822 | - public function load_controllers() |
|
| 823 | - { |
|
| 824 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 825 | - // let's get it started |
|
| 826 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 827 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 828 | - $this->registry->load_core('Front_Controller', array(), false, true); |
|
| 829 | - } else if ( ! EE_FRONT_AJAX) { |
|
| 830 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 831 | - EE_Registry::instance()->load_core('Admin'); |
|
| 832 | - } |
|
| 833 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * core_loaded_and_ready |
|
| 840 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 841 | - * |
|
| 842 | - * @access public |
|
| 843 | - * @return void |
|
| 844 | - */ |
|
| 845 | - public function core_loaded_and_ready() |
|
| 846 | - { |
|
| 847 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 848 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 849 | - $this->registry->load_core('Session'); |
|
| 850 | - // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * initialize |
|
| 857 | - * this is the best place to begin initializing client code |
|
| 858 | - * |
|
| 859 | - * @access public |
|
| 860 | - * @return void |
|
| 861 | - */ |
|
| 862 | - public function initialize() |
|
| 863 | - { |
|
| 864 | - do_action('AHEE__EE_System__initialize'); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * initialize_last |
|
| 871 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
| 872 | - * initialize has done so |
|
| 873 | - * |
|
| 874 | - * @access public |
|
| 875 | - * @return void |
|
| 876 | - */ |
|
| 877 | - public function initialize_last() |
|
| 878 | - { |
|
| 879 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * set_hooks_for_shortcodes_modules_and_addons |
|
| 886 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 887 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
| 888 | - * |
|
| 889 | - * @access public |
|
| 890 | - * @return void |
|
| 891 | - */ |
|
| 892 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 893 | - { |
|
| 273 | + break; |
|
| 274 | + } |
|
| 275 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Updates the list of installed versions and sets hooks for |
|
| 282 | + * initializing the database later during the request |
|
| 283 | + * |
|
| 284 | + * @param array $espresso_db_update |
|
| 285 | + */ |
|
| 286 | + protected function _handle_core_version_change($espresso_db_update) |
|
| 287 | + { |
|
| 288 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 289 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 290 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 291 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 298 | + * information about what versions of EE have been installed and activated, |
|
| 299 | + * NOT necessarily the state of the database |
|
| 300 | + * |
|
| 301 | + * @param null $espresso_db_update |
|
| 302 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
| 303 | + * from the options table |
|
| 304 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 305 | + */ |
|
| 306 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 307 | + { |
|
| 308 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 309 | + if ( ! $espresso_db_update) { |
|
| 310 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 311 | + } |
|
| 312 | + // check that option is an array |
|
| 313 | + if ( ! is_array($espresso_db_update)) { |
|
| 314 | + // if option is FALSE, then it never existed |
|
| 315 | + if ($espresso_db_update === false) { |
|
| 316 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 317 | + $espresso_db_update = array(); |
|
| 318 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 319 | + } else { |
|
| 320 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 321 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 322 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 323 | + } |
|
| 324 | + } else { |
|
| 325 | + $corrected_db_update = array(); |
|
| 326 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 327 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 328 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 329 | + //the key is an int, and the value IS NOT an array |
|
| 330 | + //so it must be numerically-indexed, where values are versions installed... |
|
| 331 | + //fix it! |
|
| 332 | + $version_string = $should_be_array; |
|
| 333 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 334 | + } else { |
|
| 335 | + //ok it checks out |
|
| 336 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + $espresso_db_update = $corrected_db_update; |
|
| 340 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 341 | + } |
|
| 342 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 343 | + return $espresso_db_update; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 350 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 351 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 352 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 353 | + * so that it will be done when migrations are finished |
|
| 354 | + * |
|
| 355 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 356 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 357 | + * This is a resource-intensive job |
|
| 358 | + * so we prefer to only do it when necessary |
|
| 359 | + * @return void |
|
| 360 | + */ |
|
| 361 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 362 | + { |
|
| 363 | + $request_type = $this->detect_req_type(); |
|
| 364 | + //only initialize system if we're not in maintenance mode. |
|
| 365 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 366 | + update_option('ee_flush_rewrite_rules', true); |
|
| 367 | + if ($verify_schema) { |
|
| 368 | + EEH_Activation::initialize_db_and_folders(); |
|
| 369 | + } |
|
| 370 | + EEH_Activation::initialize_db_content(); |
|
| 371 | + EEH_Activation::system_initialization(); |
|
| 372 | + if ($initialize_addons_too) { |
|
| 373 | + $this->initialize_addons(); |
|
| 374 | + } |
|
| 375 | + } else { |
|
| 376 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 377 | + } |
|
| 378 | + if ($request_type == EE_System::req_type_new_activation |
|
| 379 | + || $request_type == EE_System::req_type_reactivation |
|
| 380 | + || $request_type == EE_System::req_type_upgrade |
|
| 381 | + ) { |
|
| 382 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Initializes the db for all registered addons |
|
| 390 | + */ |
|
| 391 | + public function initialize_addons() |
|
| 392 | + { |
|
| 393 | + //foreach registered addon, make sure its db is up-to-date too |
|
| 394 | + foreach ($this->registry->addons as $addon) { |
|
| 395 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 403 | + * |
|
| 404 | + * @param array $version_history |
|
| 405 | + * @param string $current_version_to_add version to be added to the version history |
|
| 406 | + * @return boolean success as to whether or not this option was changed |
|
| 407 | + */ |
|
| 408 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 409 | + { |
|
| 410 | + if ( ! $version_history) { |
|
| 411 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 412 | + } |
|
| 413 | + if ($current_version_to_add == null) { |
|
| 414 | + $current_version_to_add = espresso_version(); |
|
| 415 | + } |
|
| 416 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 417 | + // re-save |
|
| 418 | + return update_option('espresso_db_update', $version_history); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Detects if the current version indicated in the has existed in the list of |
|
| 425 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 426 | + * |
|
| 427 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 428 | + * If not supplied, fetches it from the options table. |
|
| 429 | + * Also, caches its result so later parts of the code can also know whether |
|
| 430 | + * there's been an update or not. This way we can add the current version to |
|
| 431 | + * espresso_db_update, but still know if this is a new install or not |
|
| 432 | + * @return int one of the constants on EE_System::req_type_ |
|
| 433 | + */ |
|
| 434 | + public function detect_req_type($espresso_db_update = null) |
|
| 435 | + { |
|
| 436 | + if ($this->_req_type === null) { |
|
| 437 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 438 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 439 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
| 440 | + 'ee_espresso_activation', espresso_version()); |
|
| 441 | + } |
|
| 442 | + return $this->_req_type; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 449 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
| 450 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 451 | + * just activated to (for core that will always be espresso_version()) |
|
| 452 | + * |
|
| 453 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 454 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 455 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
| 456 | + * indicate that this plugin was just activated |
|
| 457 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 458 | + * espresso_version()) |
|
| 459 | + * @return int one of the constants on EE_System::req_type_* |
|
| 460 | + */ |
|
| 461 | + public static function detect_req_type_given_activation_history( |
|
| 462 | + $activation_history_for_addon, |
|
| 463 | + $activation_indicator_option_name, |
|
| 464 | + $version_to_upgrade_to |
|
| 465 | + ) { |
|
| 466 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 467 | + if ($activation_history_for_addon) { |
|
| 468 | + //it exists, so this isn't a completely new install |
|
| 469 | + //check if this version already in that list of previously installed versions |
|
| 470 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 471 | + //it a version we haven't seen before |
|
| 472 | + if ($version_is_higher === 1) { |
|
| 473 | + $req_type = EE_System::req_type_upgrade; |
|
| 474 | + } else { |
|
| 475 | + $req_type = EE_System::req_type_downgrade; |
|
| 476 | + } |
|
| 477 | + delete_option($activation_indicator_option_name); |
|
| 478 | + } else { |
|
| 479 | + // its not an update. maybe a reactivation? |
|
| 480 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 481 | + if ($version_is_higher === -1) { |
|
| 482 | + $req_type = EE_System::req_type_downgrade; |
|
| 483 | + } elseif ($version_is_higher === 0) { |
|
| 484 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
| 485 | + $req_type = EE_System::req_type_reactivation; |
|
| 486 | + } else {//$version_is_higher === 1 |
|
| 487 | + $req_type = EE_System::req_type_upgrade; |
|
| 488 | + } |
|
| 489 | + delete_option($activation_indicator_option_name); |
|
| 490 | + } else { |
|
| 491 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 492 | + if ($version_is_higher === -1) { |
|
| 493 | + $req_type = EE_System::req_type_downgrade; |
|
| 494 | + } elseif ($version_is_higher === 0) { |
|
| 495 | + //we've seen this version before and it's not an activation. its normal request |
|
| 496 | + $req_type = EE_System::req_type_normal; |
|
| 497 | + } else {//$version_is_higher === 1 |
|
| 498 | + $req_type = EE_System::req_type_upgrade; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + //brand new install |
|
| 504 | + $req_type = EE_System::req_type_new_activation; |
|
| 505 | + delete_option($activation_indicator_option_name); |
|
| 506 | + } |
|
| 507 | + return $req_type; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 514 | + * the $activation_history_for_addon |
|
| 515 | + * |
|
| 516 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 517 | + * sometimes containing 'unknown-date' |
|
| 518 | + * @param string $version_to_upgrade_to (current version) |
|
| 519 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 520 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 521 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 522 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 523 | + */ |
|
| 524 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 525 | + { |
|
| 526 | + //find the most recently-activated version |
|
| 527 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 528 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 529 | + if (is_array($activation_history_for_addon)) { |
|
| 530 | + foreach ($activation_history_for_addon as $version => $times_activated) { |
|
| 531 | + //check there is a record of when this version was activated. Otherwise, |
|
| 532 | + //mark it as unknown |
|
| 533 | + if ( ! $times_activated) { |
|
| 534 | + $times_activated = array('unknown-date'); |
|
| 535 | + } |
|
| 536 | + if (is_string($times_activated)) { |
|
| 537 | + $times_activated = array($times_activated); |
|
| 538 | + } |
|
| 539 | + foreach ($times_activated as $an_activation) { |
|
| 540 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 541 | + $most_recently_active_version = $version; |
|
| 542 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
| 543 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * This redirects to the about EE page after activation |
|
| 555 | + * |
|
| 556 | + * @return void |
|
| 557 | + */ |
|
| 558 | + public function redirect_to_about_ee() |
|
| 559 | + { |
|
| 560 | + $notices = EE_Error::get_notices(false); |
|
| 561 | + //if current user is an admin and it's not an ajax request |
|
| 562 | + if ( |
|
| 563 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 564 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 565 | + && ! isset($notices['errors']) |
|
| 566 | + ) { |
|
| 567 | + $query_params = array('page' => 'espresso_about'); |
|
| 568 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
| 569 | + $query_params['new_activation'] = true; |
|
| 570 | + } |
|
| 571 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
| 572 | + $query_params['reactivation'] = true; |
|
| 573 | + } |
|
| 574 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 575 | + wp_safe_redirect($url); |
|
| 576 | + exit(); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * load_core_configuration |
|
| 584 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 585 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 586 | + * |
|
| 587 | + * @return void |
|
| 588 | + */ |
|
| 589 | + public function load_core_configuration() |
|
| 590 | + { |
|
| 591 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 592 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
| 593 | + //load textdomain |
|
| 594 | + EE_Load_Textdomain::load_textdomain(); |
|
| 595 | + // load and setup EE_Config and EE_Network_Config |
|
| 596 | + $this->registry->load_core('Config'); |
|
| 597 | + $this->registry->load_core('Network_Config'); |
|
| 598 | + // setup autoloaders |
|
| 599 | + // enable logging? |
|
| 600 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
| 601 | + $this->registry->load_core('Log'); |
|
| 602 | + } |
|
| 603 | + // check for activation errors |
|
| 604 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 605 | + if ($activation_errors) { |
|
| 606 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 607 | + update_option('ee_plugin_activation_errors', false); |
|
| 608 | + } |
|
| 609 | + // get model names |
|
| 610 | + $this->_parse_model_names(); |
|
| 611 | + //load caf stuff a chance to play during the activation process too. |
|
| 612 | + $this->_maybe_brew_regular(); |
|
| 613 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 620 | + * |
|
| 621 | + * @return void |
|
| 622 | + */ |
|
| 623 | + private function _parse_model_names() |
|
| 624 | + { |
|
| 625 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
| 626 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 627 | + $model_names = array(); |
|
| 628 | + $non_abstract_db_models = array(); |
|
| 629 | + foreach ($models as $model) { |
|
| 630 | + // get model classname |
|
| 631 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 632 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 633 | + $reflectionClass = new ReflectionClass($classname); |
|
| 634 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 635 | + $non_abstract_db_models[$short_name] = $classname; |
|
| 636 | + } |
|
| 637 | + $model_names[$short_name] = $classname; |
|
| 638 | + } |
|
| 639 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 640 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 641 | + $non_abstract_db_models); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 648 | + * that need to be setup before our EE_System launches. |
|
| 649 | + * |
|
| 650 | + * @return void |
|
| 651 | + */ |
|
| 652 | + private function _maybe_brew_regular() |
|
| 653 | + { |
|
| 654 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 655 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * register_shortcodes_modules_and_widgets |
|
| 663 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 664 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 665 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 666 | + * |
|
| 667 | + * @access public |
|
| 668 | + * @return void |
|
| 669 | + */ |
|
| 670 | + public function register_shortcodes_modules_and_widgets() |
|
| 671 | + { |
|
| 672 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 673 | + // check for addons using old hookpoint |
|
| 674 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 675 | + $this->_incompatible_addon_error(); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * _incompatible_addon_error |
|
| 683 | + * |
|
| 684 | + * @access public |
|
| 685 | + * @return void |
|
| 686 | + */ |
|
| 687 | + private function _incompatible_addon_error() |
|
| 688 | + { |
|
| 689 | + // get array of classes hooking into here |
|
| 690 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 691 | + if ( ! empty($class_names)) { |
|
| 692 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 693 | + 'event_espresso'); |
|
| 694 | + $msg .= '<ul>'; |
|
| 695 | + foreach ($class_names as $class_name) { |
|
| 696 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 697 | + $class_name) . '</b></li>'; |
|
| 698 | + } |
|
| 699 | + $msg .= '</ul>'; |
|
| 700 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 701 | + 'event_espresso'); |
|
| 702 | + // save list of incompatible addons to wp-options for later use |
|
| 703 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 704 | + if (is_admin()) { |
|
| 705 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * brew_espresso |
|
| 714 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 715 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
| 716 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 717 | + * |
|
| 718 | + * @return void |
|
| 719 | + */ |
|
| 720 | + public function brew_espresso() |
|
| 721 | + { |
|
| 722 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 723 | + // load some final core systems |
|
| 724 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 725 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 726 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 727 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 728 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 729 | + add_action('init', array($this, 'initialize'), 10); |
|
| 730 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 731 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25); |
|
| 732 | + add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 25); |
|
| 733 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 734 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 735 | + // pew pew pew |
|
| 736 | + $this->registry->load_core('PUE'); |
|
| 737 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 738 | + } |
|
| 739 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * set_hooks_for_core |
|
| 746 | + * |
|
| 747 | + * @access public |
|
| 748 | + * @return void |
|
| 749 | + */ |
|
| 750 | + public function set_hooks_for_core() |
|
| 751 | + { |
|
| 752 | + $this->_deactivate_incompatible_addons(); |
|
| 753 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 760 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 761 | + */ |
|
| 762 | + private function _deactivate_incompatible_addons() |
|
| 763 | + { |
|
| 764 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 765 | + if ( ! empty($incompatible_addons)) { |
|
| 766 | + $active_plugins = get_option('active_plugins', array()); |
|
| 767 | + foreach ($active_plugins as $active_plugin) { |
|
| 768 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 769 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 770 | + unset($_GET['activate']); |
|
| 771 | + espresso_deactivate_plugin($active_plugin); |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + /** |
|
| 781 | + * perform_activations_upgrades_and_migrations |
|
| 782 | + * |
|
| 783 | + * @access public |
|
| 784 | + * @return void |
|
| 785 | + */ |
|
| 786 | + public function perform_activations_upgrades_and_migrations() |
|
| 787 | + { |
|
| 788 | + //first check if we had previously attempted to setup EE's directories but failed |
|
| 789 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
| 790 | + EEH_Activation::create_upload_directories(); |
|
| 791 | + } |
|
| 792 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * load_CPTs_and_session |
|
| 799 | + * |
|
| 800 | + * @access public |
|
| 801 | + * @return void |
|
| 802 | + */ |
|
| 803 | + public function load_CPTs_and_session() |
|
| 804 | + { |
|
| 805 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 806 | + // register Custom Post Types |
|
| 807 | + $this->registry->load_core('Register_CPTs'); |
|
| 808 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * load_controllers |
|
| 815 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 816 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 817 | + * time |
|
| 818 | + * |
|
| 819 | + * @access public |
|
| 820 | + * @return void |
|
| 821 | + */ |
|
| 822 | + public function load_controllers() |
|
| 823 | + { |
|
| 824 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 825 | + // let's get it started |
|
| 826 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 827 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 828 | + $this->registry->load_core('Front_Controller', array(), false, true); |
|
| 829 | + } else if ( ! EE_FRONT_AJAX) { |
|
| 830 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 831 | + EE_Registry::instance()->load_core('Admin'); |
|
| 832 | + } |
|
| 833 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * core_loaded_and_ready |
|
| 840 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 841 | + * |
|
| 842 | + * @access public |
|
| 843 | + * @return void |
|
| 844 | + */ |
|
| 845 | + public function core_loaded_and_ready() |
|
| 846 | + { |
|
| 847 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 848 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 849 | + $this->registry->load_core('Session'); |
|
| 850 | + // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * initialize |
|
| 857 | + * this is the best place to begin initializing client code |
|
| 858 | + * |
|
| 859 | + * @access public |
|
| 860 | + * @return void |
|
| 861 | + */ |
|
| 862 | + public function initialize() |
|
| 863 | + { |
|
| 864 | + do_action('AHEE__EE_System__initialize'); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * initialize_last |
|
| 871 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
| 872 | + * initialize has done so |
|
| 873 | + * |
|
| 874 | + * @access public |
|
| 875 | + * @return void |
|
| 876 | + */ |
|
| 877 | + public function initialize_last() |
|
| 878 | + { |
|
| 879 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * set_hooks_for_shortcodes_modules_and_addons |
|
| 886 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 887 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
| 888 | + * |
|
| 889 | + * @access public |
|
| 890 | + * @return void |
|
| 891 | + */ |
|
| 892 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 893 | + { |
|
| 894 | 894 | // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * do_not_cache |
|
| 901 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 902 | - * |
|
| 903 | - * @access public |
|
| 904 | - * @return void |
|
| 905 | - */ |
|
| 906 | - public static function do_not_cache() |
|
| 907 | - { |
|
| 908 | - // set no cache constants |
|
| 909 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
| 910 | - define('DONOTCACHEPAGE', true); |
|
| 911 | - } |
|
| 912 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 913 | - define('DONOTCACHCEOBJECT', true); |
|
| 914 | - } |
|
| 915 | - if ( ! defined('DONOTCACHEDB')) { |
|
| 916 | - define('DONOTCACHEDB', true); |
|
| 917 | - } |
|
| 918 | - // add no cache headers |
|
| 919 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 920 | - // plus a little extra for nginx and Google Chrome |
|
| 921 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 922 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 923 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * extra_nocache_headers |
|
| 930 | - * |
|
| 931 | - * @access public |
|
| 932 | - * @param $headers |
|
| 933 | - * @return array |
|
| 934 | - */ |
|
| 935 | - public static function extra_nocache_headers($headers) |
|
| 936 | - { |
|
| 937 | - // for NGINX |
|
| 938 | - $headers['X-Accel-Expires'] = 0; |
|
| 939 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 940 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 941 | - return $headers; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * nocache_headers |
|
| 948 | - * |
|
| 949 | - * @access public |
|
| 950 | - * @return void |
|
| 951 | - */ |
|
| 952 | - public static function nocache_headers() |
|
| 953 | - { |
|
| 954 | - nocache_headers(); |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * espresso_toolbar_items |
|
| 961 | - * |
|
| 962 | - * @access public |
|
| 963 | - * @param WP_Admin_Bar $admin_bar |
|
| 964 | - * @return void |
|
| 965 | - */ |
|
| 966 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 967 | - { |
|
| 968 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 969 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 970 | - || defined('DOING_AJAX') |
|
| 971 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 972 | - ) { |
|
| 973 | - return; |
|
| 974 | - } |
|
| 975 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 976 | - $menu_class = 'espresso_menu_item_class'; |
|
| 977 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 978 | - //because they're only defined in each of their respective constructors |
|
| 979 | - //and this might be a frontend request, in which case they aren't available |
|
| 980 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
| 981 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
| 982 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
| 983 | - //Top Level |
|
| 984 | - $admin_bar->add_menu(array( |
|
| 985 | - 'id' => 'espresso-toolbar', |
|
| 986 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 987 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 988 | - . '</span>', |
|
| 989 | - 'href' => $events_admin_url, |
|
| 990 | - 'meta' => array( |
|
| 991 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
| 992 | - 'class' => $menu_class . 'first', |
|
| 993 | - ), |
|
| 994 | - )); |
|
| 995 | - //Events |
|
| 996 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 997 | - $admin_bar->add_menu(array( |
|
| 998 | - 'id' => 'espresso-toolbar-events', |
|
| 999 | - 'parent' => 'espresso-toolbar', |
|
| 1000 | - 'title' => __('Events', 'event_espresso'), |
|
| 1001 | - 'href' => $events_admin_url, |
|
| 1002 | - 'meta' => array( |
|
| 1003 | - 'title' => __('Events', 'event_espresso'), |
|
| 1004 | - 'target' => '', |
|
| 1005 | - 'class' => $menu_class, |
|
| 1006 | - ), |
|
| 1007 | - )); |
|
| 1008 | - } |
|
| 1009 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1010 | - //Events Add New |
|
| 1011 | - $admin_bar->add_menu(array( |
|
| 1012 | - 'id' => 'espresso-toolbar-events-new', |
|
| 1013 | - 'parent' => 'espresso-toolbar-events', |
|
| 1014 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1015 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1016 | - 'meta' => array( |
|
| 1017 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1018 | - 'target' => '', |
|
| 1019 | - 'class' => $menu_class, |
|
| 1020 | - ), |
|
| 1021 | - )); |
|
| 1022 | - } |
|
| 1023 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
| 1024 | - //Current post |
|
| 1025 | - global $post; |
|
| 1026 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1027 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1028 | - ) { |
|
| 1029 | - //Events Edit Current Event |
|
| 1030 | - $admin_bar->add_menu(array( |
|
| 1031 | - 'id' => 'espresso-toolbar-events-edit', |
|
| 1032 | - 'parent' => 'espresso-toolbar-events', |
|
| 1033 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1034 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1035 | - $events_admin_url), |
|
| 1036 | - 'meta' => array( |
|
| 1037 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1038 | - 'target' => '', |
|
| 1039 | - 'class' => $menu_class, |
|
| 1040 | - ), |
|
| 1041 | - )); |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1044 | - //Events View |
|
| 1045 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1046 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1047 | - ) { |
|
| 1048 | - $admin_bar->add_menu(array( |
|
| 1049 | - 'id' => 'espresso-toolbar-events-view', |
|
| 1050 | - 'parent' => 'espresso-toolbar-events', |
|
| 1051 | - 'title' => __('View', 'event_espresso'), |
|
| 1052 | - 'href' => $events_admin_url, |
|
| 1053 | - 'meta' => array( |
|
| 1054 | - 'title' => __('View', 'event_espresso'), |
|
| 1055 | - 'target' => '', |
|
| 1056 | - 'class' => $menu_class, |
|
| 1057 | - ), |
|
| 1058 | - )); |
|
| 1059 | - } |
|
| 1060 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1061 | - //Events View All |
|
| 1062 | - $admin_bar->add_menu(array( |
|
| 1063 | - 'id' => 'espresso-toolbar-events-all', |
|
| 1064 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1065 | - 'title' => __('All', 'event_espresso'), |
|
| 1066 | - 'href' => $events_admin_url, |
|
| 1067 | - 'meta' => array( |
|
| 1068 | - 'title' => __('All', 'event_espresso'), |
|
| 1069 | - 'target' => '', |
|
| 1070 | - 'class' => $menu_class, |
|
| 1071 | - ), |
|
| 1072 | - )); |
|
| 1073 | - } |
|
| 1074 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1075 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1076 | - ) { |
|
| 1077 | - //Events View Today |
|
| 1078 | - $admin_bar->add_menu(array( |
|
| 1079 | - 'id' => 'espresso-toolbar-events-today', |
|
| 1080 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1081 | - 'title' => __('Today', 'event_espresso'), |
|
| 1082 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1083 | - $events_admin_url), |
|
| 1084 | - 'meta' => array( |
|
| 1085 | - 'title' => __('Today', 'event_espresso'), |
|
| 1086 | - 'target' => '', |
|
| 1087 | - 'class' => $menu_class, |
|
| 1088 | - ), |
|
| 1089 | - )); |
|
| 1090 | - } |
|
| 1091 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1092 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1093 | - ) { |
|
| 1094 | - //Events View This Month |
|
| 1095 | - $admin_bar->add_menu(array( |
|
| 1096 | - 'id' => 'espresso-toolbar-events-month', |
|
| 1097 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1098 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1099 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1100 | - $events_admin_url), |
|
| 1101 | - 'meta' => array( |
|
| 1102 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1103 | - 'target' => '', |
|
| 1104 | - 'class' => $menu_class, |
|
| 1105 | - ), |
|
| 1106 | - )); |
|
| 1107 | - } |
|
| 1108 | - //Registration Overview |
|
| 1109 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1110 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1111 | - ) { |
|
| 1112 | - $admin_bar->add_menu(array( |
|
| 1113 | - 'id' => 'espresso-toolbar-registrations', |
|
| 1114 | - 'parent' => 'espresso-toolbar', |
|
| 1115 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1116 | - 'href' => $reg_admin_url, |
|
| 1117 | - 'meta' => array( |
|
| 1118 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1119 | - 'target' => '', |
|
| 1120 | - 'class' => $menu_class, |
|
| 1121 | - ), |
|
| 1122 | - )); |
|
| 1123 | - } |
|
| 1124 | - //Registration Overview Today |
|
| 1125 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1126 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1127 | - ) { |
|
| 1128 | - $admin_bar->add_menu(array( |
|
| 1129 | - 'id' => 'espresso-toolbar-registrations-today', |
|
| 1130 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1131 | - 'title' => __('Today', 'event_espresso'), |
|
| 1132 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1133 | - $reg_admin_url), |
|
| 1134 | - 'meta' => array( |
|
| 1135 | - 'title' => __('Today', 'event_espresso'), |
|
| 1136 | - 'target' => '', |
|
| 1137 | - 'class' => $menu_class, |
|
| 1138 | - ), |
|
| 1139 | - )); |
|
| 1140 | - } |
|
| 1141 | - //Registration Overview Today Completed |
|
| 1142 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1143 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1144 | - ) { |
|
| 1145 | - $admin_bar->add_menu(array( |
|
| 1146 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1147 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1148 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1149 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1150 | - 'action' => 'default', |
|
| 1151 | - 'status' => 'today', |
|
| 1152 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1153 | - ), $reg_admin_url), |
|
| 1154 | - 'meta' => array( |
|
| 1155 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1156 | - 'target' => '', |
|
| 1157 | - 'class' => $menu_class, |
|
| 1158 | - ), |
|
| 1159 | - )); |
|
| 1160 | - } |
|
| 1161 | - //Registration Overview Today Pending\ |
|
| 1162 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1163 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1164 | - ) { |
|
| 1165 | - $admin_bar->add_menu(array( |
|
| 1166 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1167 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1168 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1169 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1170 | - 'action' => 'default', |
|
| 1171 | - 'status' => 'today', |
|
| 1172 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1173 | - ), $reg_admin_url), |
|
| 1174 | - 'meta' => array( |
|
| 1175 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1176 | - 'target' => '', |
|
| 1177 | - 'class' => $menu_class, |
|
| 1178 | - ), |
|
| 1179 | - )); |
|
| 1180 | - } |
|
| 1181 | - //Registration Overview Today Incomplete |
|
| 1182 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1183 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1184 | - ) { |
|
| 1185 | - $admin_bar->add_menu(array( |
|
| 1186 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1187 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1188 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1189 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1190 | - 'action' => 'default', |
|
| 1191 | - 'status' => 'today', |
|
| 1192 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1193 | - ), $reg_admin_url), |
|
| 1194 | - 'meta' => array( |
|
| 1195 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1196 | - 'target' => '', |
|
| 1197 | - 'class' => $menu_class, |
|
| 1198 | - ), |
|
| 1199 | - )); |
|
| 1200 | - } |
|
| 1201 | - //Registration Overview Today Incomplete |
|
| 1202 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1203 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1204 | - ) { |
|
| 1205 | - $admin_bar->add_menu(array( |
|
| 1206 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1207 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1208 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1209 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1210 | - 'action' => 'default', |
|
| 1211 | - 'status' => 'today', |
|
| 1212 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1213 | - ), $reg_admin_url), |
|
| 1214 | - 'meta' => array( |
|
| 1215 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1216 | - 'target' => '', |
|
| 1217 | - 'class' => $menu_class, |
|
| 1218 | - ), |
|
| 1219 | - )); |
|
| 1220 | - } |
|
| 1221 | - //Registration Overview This Month |
|
| 1222 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1223 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1224 | - ) { |
|
| 1225 | - $admin_bar->add_menu(array( |
|
| 1226 | - 'id' => 'espresso-toolbar-registrations-month', |
|
| 1227 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1228 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1229 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1230 | - $reg_admin_url), |
|
| 1231 | - 'meta' => array( |
|
| 1232 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1233 | - 'target' => '', |
|
| 1234 | - 'class' => $menu_class, |
|
| 1235 | - ), |
|
| 1236 | - )); |
|
| 1237 | - } |
|
| 1238 | - //Registration Overview This Month Approved |
|
| 1239 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1240 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1241 | - ) { |
|
| 1242 | - $admin_bar->add_menu(array( |
|
| 1243 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1244 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1245 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1246 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1247 | - 'action' => 'default', |
|
| 1248 | - 'status' => 'month', |
|
| 1249 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1250 | - ), $reg_admin_url), |
|
| 1251 | - 'meta' => array( |
|
| 1252 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1253 | - 'target' => '', |
|
| 1254 | - 'class' => $menu_class, |
|
| 1255 | - ), |
|
| 1256 | - )); |
|
| 1257 | - } |
|
| 1258 | - //Registration Overview This Month Pending |
|
| 1259 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1260 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1261 | - ) { |
|
| 1262 | - $admin_bar->add_menu(array( |
|
| 1263 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1264 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1265 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1266 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1267 | - 'action' => 'default', |
|
| 1268 | - 'status' => 'month', |
|
| 1269 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1270 | - ), $reg_admin_url), |
|
| 1271 | - 'meta' => array( |
|
| 1272 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1273 | - 'target' => '', |
|
| 1274 | - 'class' => $menu_class, |
|
| 1275 | - ), |
|
| 1276 | - )); |
|
| 1277 | - } |
|
| 1278 | - //Registration Overview This Month Not Approved |
|
| 1279 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1280 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1281 | - ) { |
|
| 1282 | - $admin_bar->add_menu(array( |
|
| 1283 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1284 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1285 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1286 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1287 | - 'action' => 'default', |
|
| 1288 | - 'status' => 'month', |
|
| 1289 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1290 | - ), $reg_admin_url), |
|
| 1291 | - 'meta' => array( |
|
| 1292 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1293 | - 'target' => '', |
|
| 1294 | - 'class' => $menu_class, |
|
| 1295 | - ), |
|
| 1296 | - )); |
|
| 1297 | - } |
|
| 1298 | - //Registration Overview This Month Cancelled |
|
| 1299 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1300 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1301 | - ) { |
|
| 1302 | - $admin_bar->add_menu(array( |
|
| 1303 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1304 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1305 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1306 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1307 | - 'action' => 'default', |
|
| 1308 | - 'status' => 'month', |
|
| 1309 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1310 | - ), $reg_admin_url), |
|
| 1311 | - 'meta' => array( |
|
| 1312 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1313 | - 'target' => '', |
|
| 1314 | - 'class' => $menu_class, |
|
| 1315 | - ), |
|
| 1316 | - )); |
|
| 1317 | - } |
|
| 1318 | - //Extensions & Services |
|
| 1319 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1320 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1321 | - ) { |
|
| 1322 | - $admin_bar->add_menu(array( |
|
| 1323 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1324 | - 'parent' => 'espresso-toolbar', |
|
| 1325 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1326 | - 'href' => $extensions_admin_url, |
|
| 1327 | - 'meta' => array( |
|
| 1328 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1329 | - 'target' => '', |
|
| 1330 | - 'class' => $menu_class, |
|
| 1331 | - ), |
|
| 1332 | - )); |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - |
|
| 1337 | - |
|
| 1338 | - /** |
|
| 1339 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1340 | - * never returned with the function. |
|
| 1341 | - * |
|
| 1342 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1343 | - * @return array |
|
| 1344 | - */ |
|
| 1345 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1346 | - { |
|
| 1347 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - |
|
| 1354 | - |
|
| 1355 | - /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
| 1356 | - /** |
|
| 1357 | - * wp_enqueue_scripts |
|
| 1358 | - * |
|
| 1359 | - * @access public |
|
| 1360 | - * @return void |
|
| 1361 | - */ |
|
| 1362 | - public function wp_enqueue_scripts() |
|
| 1363 | - { |
|
| 1364 | - // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
| 1365 | - if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
| 1366 | - // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
| 1367 | - if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
| 1368 | - // register jQuery Validate and additional methods |
|
| 1369 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 1370 | - array('jquery'), '1.15.0', true); |
|
| 1371 | - wp_register_script('jquery-validate-extra-methods', |
|
| 1372 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 1373 | - array('jquery', 'jquery-validate'), '1.15.0', true); |
|
| 1374 | - } |
|
| 1375 | - } |
|
| 1376 | - } |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * do_not_cache |
|
| 901 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 902 | + * |
|
| 903 | + * @access public |
|
| 904 | + * @return void |
|
| 905 | + */ |
|
| 906 | + public static function do_not_cache() |
|
| 907 | + { |
|
| 908 | + // set no cache constants |
|
| 909 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
| 910 | + define('DONOTCACHEPAGE', true); |
|
| 911 | + } |
|
| 912 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 913 | + define('DONOTCACHCEOBJECT', true); |
|
| 914 | + } |
|
| 915 | + if ( ! defined('DONOTCACHEDB')) { |
|
| 916 | + define('DONOTCACHEDB', true); |
|
| 917 | + } |
|
| 918 | + // add no cache headers |
|
| 919 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 920 | + // plus a little extra for nginx and Google Chrome |
|
| 921 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 922 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 923 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * extra_nocache_headers |
|
| 930 | + * |
|
| 931 | + * @access public |
|
| 932 | + * @param $headers |
|
| 933 | + * @return array |
|
| 934 | + */ |
|
| 935 | + public static function extra_nocache_headers($headers) |
|
| 936 | + { |
|
| 937 | + // for NGINX |
|
| 938 | + $headers['X-Accel-Expires'] = 0; |
|
| 939 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 940 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 941 | + return $headers; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * nocache_headers |
|
| 948 | + * |
|
| 949 | + * @access public |
|
| 950 | + * @return void |
|
| 951 | + */ |
|
| 952 | + public static function nocache_headers() |
|
| 953 | + { |
|
| 954 | + nocache_headers(); |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * espresso_toolbar_items |
|
| 961 | + * |
|
| 962 | + * @access public |
|
| 963 | + * @param WP_Admin_Bar $admin_bar |
|
| 964 | + * @return void |
|
| 965 | + */ |
|
| 966 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 967 | + { |
|
| 968 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 969 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 970 | + || defined('DOING_AJAX') |
|
| 971 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 972 | + ) { |
|
| 973 | + return; |
|
| 974 | + } |
|
| 975 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 976 | + $menu_class = 'espresso_menu_item_class'; |
|
| 977 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 978 | + //because they're only defined in each of their respective constructors |
|
| 979 | + //and this might be a frontend request, in which case they aren't available |
|
| 980 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
| 981 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
| 982 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
| 983 | + //Top Level |
|
| 984 | + $admin_bar->add_menu(array( |
|
| 985 | + 'id' => 'espresso-toolbar', |
|
| 986 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 987 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 988 | + . '</span>', |
|
| 989 | + 'href' => $events_admin_url, |
|
| 990 | + 'meta' => array( |
|
| 991 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
| 992 | + 'class' => $menu_class . 'first', |
|
| 993 | + ), |
|
| 994 | + )); |
|
| 995 | + //Events |
|
| 996 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 997 | + $admin_bar->add_menu(array( |
|
| 998 | + 'id' => 'espresso-toolbar-events', |
|
| 999 | + 'parent' => 'espresso-toolbar', |
|
| 1000 | + 'title' => __('Events', 'event_espresso'), |
|
| 1001 | + 'href' => $events_admin_url, |
|
| 1002 | + 'meta' => array( |
|
| 1003 | + 'title' => __('Events', 'event_espresso'), |
|
| 1004 | + 'target' => '', |
|
| 1005 | + 'class' => $menu_class, |
|
| 1006 | + ), |
|
| 1007 | + )); |
|
| 1008 | + } |
|
| 1009 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1010 | + //Events Add New |
|
| 1011 | + $admin_bar->add_menu(array( |
|
| 1012 | + 'id' => 'espresso-toolbar-events-new', |
|
| 1013 | + 'parent' => 'espresso-toolbar-events', |
|
| 1014 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1015 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1016 | + 'meta' => array( |
|
| 1017 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1018 | + 'target' => '', |
|
| 1019 | + 'class' => $menu_class, |
|
| 1020 | + ), |
|
| 1021 | + )); |
|
| 1022 | + } |
|
| 1023 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
| 1024 | + //Current post |
|
| 1025 | + global $post; |
|
| 1026 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1027 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1028 | + ) { |
|
| 1029 | + //Events Edit Current Event |
|
| 1030 | + $admin_bar->add_menu(array( |
|
| 1031 | + 'id' => 'espresso-toolbar-events-edit', |
|
| 1032 | + 'parent' => 'espresso-toolbar-events', |
|
| 1033 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1034 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1035 | + $events_admin_url), |
|
| 1036 | + 'meta' => array( |
|
| 1037 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1038 | + 'target' => '', |
|
| 1039 | + 'class' => $menu_class, |
|
| 1040 | + ), |
|
| 1041 | + )); |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | + //Events View |
|
| 1045 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1046 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1047 | + ) { |
|
| 1048 | + $admin_bar->add_menu(array( |
|
| 1049 | + 'id' => 'espresso-toolbar-events-view', |
|
| 1050 | + 'parent' => 'espresso-toolbar-events', |
|
| 1051 | + 'title' => __('View', 'event_espresso'), |
|
| 1052 | + 'href' => $events_admin_url, |
|
| 1053 | + 'meta' => array( |
|
| 1054 | + 'title' => __('View', 'event_espresso'), |
|
| 1055 | + 'target' => '', |
|
| 1056 | + 'class' => $menu_class, |
|
| 1057 | + ), |
|
| 1058 | + )); |
|
| 1059 | + } |
|
| 1060 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1061 | + //Events View All |
|
| 1062 | + $admin_bar->add_menu(array( |
|
| 1063 | + 'id' => 'espresso-toolbar-events-all', |
|
| 1064 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1065 | + 'title' => __('All', 'event_espresso'), |
|
| 1066 | + 'href' => $events_admin_url, |
|
| 1067 | + 'meta' => array( |
|
| 1068 | + 'title' => __('All', 'event_espresso'), |
|
| 1069 | + 'target' => '', |
|
| 1070 | + 'class' => $menu_class, |
|
| 1071 | + ), |
|
| 1072 | + )); |
|
| 1073 | + } |
|
| 1074 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1075 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1076 | + ) { |
|
| 1077 | + //Events View Today |
|
| 1078 | + $admin_bar->add_menu(array( |
|
| 1079 | + 'id' => 'espresso-toolbar-events-today', |
|
| 1080 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1081 | + 'title' => __('Today', 'event_espresso'), |
|
| 1082 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1083 | + $events_admin_url), |
|
| 1084 | + 'meta' => array( |
|
| 1085 | + 'title' => __('Today', 'event_espresso'), |
|
| 1086 | + 'target' => '', |
|
| 1087 | + 'class' => $menu_class, |
|
| 1088 | + ), |
|
| 1089 | + )); |
|
| 1090 | + } |
|
| 1091 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1092 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1093 | + ) { |
|
| 1094 | + //Events View This Month |
|
| 1095 | + $admin_bar->add_menu(array( |
|
| 1096 | + 'id' => 'espresso-toolbar-events-month', |
|
| 1097 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1098 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1099 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1100 | + $events_admin_url), |
|
| 1101 | + 'meta' => array( |
|
| 1102 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1103 | + 'target' => '', |
|
| 1104 | + 'class' => $menu_class, |
|
| 1105 | + ), |
|
| 1106 | + )); |
|
| 1107 | + } |
|
| 1108 | + //Registration Overview |
|
| 1109 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1110 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1111 | + ) { |
|
| 1112 | + $admin_bar->add_menu(array( |
|
| 1113 | + 'id' => 'espresso-toolbar-registrations', |
|
| 1114 | + 'parent' => 'espresso-toolbar', |
|
| 1115 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1116 | + 'href' => $reg_admin_url, |
|
| 1117 | + 'meta' => array( |
|
| 1118 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1119 | + 'target' => '', |
|
| 1120 | + 'class' => $menu_class, |
|
| 1121 | + ), |
|
| 1122 | + )); |
|
| 1123 | + } |
|
| 1124 | + //Registration Overview Today |
|
| 1125 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1126 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1127 | + ) { |
|
| 1128 | + $admin_bar->add_menu(array( |
|
| 1129 | + 'id' => 'espresso-toolbar-registrations-today', |
|
| 1130 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1131 | + 'title' => __('Today', 'event_espresso'), |
|
| 1132 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1133 | + $reg_admin_url), |
|
| 1134 | + 'meta' => array( |
|
| 1135 | + 'title' => __('Today', 'event_espresso'), |
|
| 1136 | + 'target' => '', |
|
| 1137 | + 'class' => $menu_class, |
|
| 1138 | + ), |
|
| 1139 | + )); |
|
| 1140 | + } |
|
| 1141 | + //Registration Overview Today Completed |
|
| 1142 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1143 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1144 | + ) { |
|
| 1145 | + $admin_bar->add_menu(array( |
|
| 1146 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1147 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1148 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1149 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1150 | + 'action' => 'default', |
|
| 1151 | + 'status' => 'today', |
|
| 1152 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1153 | + ), $reg_admin_url), |
|
| 1154 | + 'meta' => array( |
|
| 1155 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1156 | + 'target' => '', |
|
| 1157 | + 'class' => $menu_class, |
|
| 1158 | + ), |
|
| 1159 | + )); |
|
| 1160 | + } |
|
| 1161 | + //Registration Overview Today Pending\ |
|
| 1162 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1163 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1164 | + ) { |
|
| 1165 | + $admin_bar->add_menu(array( |
|
| 1166 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1167 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1168 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1169 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1170 | + 'action' => 'default', |
|
| 1171 | + 'status' => 'today', |
|
| 1172 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1173 | + ), $reg_admin_url), |
|
| 1174 | + 'meta' => array( |
|
| 1175 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1176 | + 'target' => '', |
|
| 1177 | + 'class' => $menu_class, |
|
| 1178 | + ), |
|
| 1179 | + )); |
|
| 1180 | + } |
|
| 1181 | + //Registration Overview Today Incomplete |
|
| 1182 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1183 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1184 | + ) { |
|
| 1185 | + $admin_bar->add_menu(array( |
|
| 1186 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1187 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1188 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1189 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1190 | + 'action' => 'default', |
|
| 1191 | + 'status' => 'today', |
|
| 1192 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1193 | + ), $reg_admin_url), |
|
| 1194 | + 'meta' => array( |
|
| 1195 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1196 | + 'target' => '', |
|
| 1197 | + 'class' => $menu_class, |
|
| 1198 | + ), |
|
| 1199 | + )); |
|
| 1200 | + } |
|
| 1201 | + //Registration Overview Today Incomplete |
|
| 1202 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1203 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1204 | + ) { |
|
| 1205 | + $admin_bar->add_menu(array( |
|
| 1206 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1207 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1208 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1209 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1210 | + 'action' => 'default', |
|
| 1211 | + 'status' => 'today', |
|
| 1212 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1213 | + ), $reg_admin_url), |
|
| 1214 | + 'meta' => array( |
|
| 1215 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1216 | + 'target' => '', |
|
| 1217 | + 'class' => $menu_class, |
|
| 1218 | + ), |
|
| 1219 | + )); |
|
| 1220 | + } |
|
| 1221 | + //Registration Overview This Month |
|
| 1222 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1223 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1224 | + ) { |
|
| 1225 | + $admin_bar->add_menu(array( |
|
| 1226 | + 'id' => 'espresso-toolbar-registrations-month', |
|
| 1227 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1228 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1229 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1230 | + $reg_admin_url), |
|
| 1231 | + 'meta' => array( |
|
| 1232 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1233 | + 'target' => '', |
|
| 1234 | + 'class' => $menu_class, |
|
| 1235 | + ), |
|
| 1236 | + )); |
|
| 1237 | + } |
|
| 1238 | + //Registration Overview This Month Approved |
|
| 1239 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1240 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1241 | + ) { |
|
| 1242 | + $admin_bar->add_menu(array( |
|
| 1243 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1244 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1245 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1246 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1247 | + 'action' => 'default', |
|
| 1248 | + 'status' => 'month', |
|
| 1249 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1250 | + ), $reg_admin_url), |
|
| 1251 | + 'meta' => array( |
|
| 1252 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1253 | + 'target' => '', |
|
| 1254 | + 'class' => $menu_class, |
|
| 1255 | + ), |
|
| 1256 | + )); |
|
| 1257 | + } |
|
| 1258 | + //Registration Overview This Month Pending |
|
| 1259 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1260 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1261 | + ) { |
|
| 1262 | + $admin_bar->add_menu(array( |
|
| 1263 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1264 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1265 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1266 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1267 | + 'action' => 'default', |
|
| 1268 | + 'status' => 'month', |
|
| 1269 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1270 | + ), $reg_admin_url), |
|
| 1271 | + 'meta' => array( |
|
| 1272 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1273 | + 'target' => '', |
|
| 1274 | + 'class' => $menu_class, |
|
| 1275 | + ), |
|
| 1276 | + )); |
|
| 1277 | + } |
|
| 1278 | + //Registration Overview This Month Not Approved |
|
| 1279 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1280 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1281 | + ) { |
|
| 1282 | + $admin_bar->add_menu(array( |
|
| 1283 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1284 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1285 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1286 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1287 | + 'action' => 'default', |
|
| 1288 | + 'status' => 'month', |
|
| 1289 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1290 | + ), $reg_admin_url), |
|
| 1291 | + 'meta' => array( |
|
| 1292 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1293 | + 'target' => '', |
|
| 1294 | + 'class' => $menu_class, |
|
| 1295 | + ), |
|
| 1296 | + )); |
|
| 1297 | + } |
|
| 1298 | + //Registration Overview This Month Cancelled |
|
| 1299 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1300 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1301 | + ) { |
|
| 1302 | + $admin_bar->add_menu(array( |
|
| 1303 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1304 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1305 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1306 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1307 | + 'action' => 'default', |
|
| 1308 | + 'status' => 'month', |
|
| 1309 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1310 | + ), $reg_admin_url), |
|
| 1311 | + 'meta' => array( |
|
| 1312 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1313 | + 'target' => '', |
|
| 1314 | + 'class' => $menu_class, |
|
| 1315 | + ), |
|
| 1316 | + )); |
|
| 1317 | + } |
|
| 1318 | + //Extensions & Services |
|
| 1319 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1320 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1321 | + ) { |
|
| 1322 | + $admin_bar->add_menu(array( |
|
| 1323 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1324 | + 'parent' => 'espresso-toolbar', |
|
| 1325 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1326 | + 'href' => $extensions_admin_url, |
|
| 1327 | + 'meta' => array( |
|
| 1328 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1329 | + 'target' => '', |
|
| 1330 | + 'class' => $menu_class, |
|
| 1331 | + ), |
|
| 1332 | + )); |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + |
|
| 1337 | + |
|
| 1338 | + /** |
|
| 1339 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1340 | + * never returned with the function. |
|
| 1341 | + * |
|
| 1342 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1343 | + * @return array |
|
| 1344 | + */ |
|
| 1345 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1346 | + { |
|
| 1347 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + |
|
| 1354 | + |
|
| 1355 | + /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
| 1356 | + /** |
|
| 1357 | + * wp_enqueue_scripts |
|
| 1358 | + * |
|
| 1359 | + * @access public |
|
| 1360 | + * @return void |
|
| 1361 | + */ |
|
| 1362 | + public function wp_enqueue_scripts() |
|
| 1363 | + { |
|
| 1364 | + // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
| 1365 | + if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
| 1366 | + // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
| 1367 | + if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
| 1368 | + // register jQuery Validate and additional methods |
|
| 1369 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 1370 | + array('jquery'), '1.15.0', true); |
|
| 1371 | + wp_register_script('jquery-validate-extra-methods', |
|
| 1372 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 1373 | + array('jquery', 'jquery-validate'), '1.15.0', true); |
|
| 1374 | + } |
|
| 1375 | + } |
|
| 1376 | + } |
|
| 1377 | 1377 | |
| 1378 | 1378 | |
| 1379 | 1379 | |
@@ -1612,7 +1612,7 @@ discard block |
||
| 1612 | 1612 | * @param \EE_Payment $payment |
| 1613 | 1613 | * @param array $REG_IDs |
| 1614 | 1614 | * |
| 1615 | - * @return bool |
|
| 1615 | + * @return boolean|null |
|
| 1616 | 1616 | */ |
| 1617 | 1617 | protected function _update_registration_payments( |
| 1618 | 1618 | EE_Transaction $transaction, |
@@ -1821,6 +1821,7 @@ discard block |
||
| 1821 | 1821 | * @access protected |
| 1822 | 1822 | * |
| 1823 | 1823 | * @param \EE_Payment | null $payment |
| 1824 | + * @param EE_Payment $payment |
|
| 1824 | 1825 | */ |
| 1825 | 1826 | protected function _maybe_send_notifications($payment = null) |
| 1826 | 1827 | { |
@@ -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 | /** |
@@ -27,1975 +27,1975 @@ discard block |
||
| 27 | 27 | class Transactions_Admin_Page extends EE_Admin_Page |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var EE_Transaction |
|
| 32 | - */ |
|
| 33 | - private $_transaction; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var EE_Session |
|
| 37 | - */ |
|
| 38 | - private $_session; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array $_txn_status |
|
| 42 | - */ |
|
| 43 | - private static $_txn_status; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var array $_pay_status |
|
| 47 | - */ |
|
| 48 | - private static $_pay_status; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 52 | - */ |
|
| 53 | - protected $_existing_reg_payment_REG_IDs = null; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @Constructor |
|
| 58 | - * @access public |
|
| 59 | - * |
|
| 60 | - * @param bool $routing |
|
| 61 | - * |
|
| 62 | - * @return Transactions_Admin_Page |
|
| 63 | - */ |
|
| 64 | - public function __construct($routing = true) |
|
| 65 | - { |
|
| 66 | - parent::__construct($routing); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * _init_page_props |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _init_page_props() |
|
| 75 | - { |
|
| 76 | - $this->page_slug = TXN_PG_SLUG; |
|
| 77 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 78 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 79 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ajax_hooks |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - protected function _ajax_hooks() |
|
| 88 | - { |
|
| 89 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 90 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 91 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * _define_page_props |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - protected function _define_page_props() |
|
| 100 | - { |
|
| 101 | - $this->_admin_page_title = $this->page_label; |
|
| 102 | - $this->_labels = array( |
|
| 103 | - 'buttons' => array( |
|
| 104 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 105 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 106 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * grab url requests and route them |
|
| 114 | - * @access private |
|
| 115 | - * @return void |
|
| 116 | - */ |
|
| 117 | - public function _set_page_routes() |
|
| 118 | - { |
|
| 119 | - |
|
| 120 | - $this->_set_transaction_status_array(); |
|
| 121 | - |
|
| 122 | - $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 123 | - |
|
| 124 | - $this->_page_routes = array( |
|
| 30 | + /** |
|
| 31 | + * @var EE_Transaction |
|
| 32 | + */ |
|
| 33 | + private $_transaction; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var EE_Session |
|
| 37 | + */ |
|
| 38 | + private $_session; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array $_txn_status |
|
| 42 | + */ |
|
| 43 | + private static $_txn_status; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var array $_pay_status |
|
| 47 | + */ |
|
| 48 | + private static $_pay_status; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 52 | + */ |
|
| 53 | + protected $_existing_reg_payment_REG_IDs = null; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @Constructor |
|
| 58 | + * @access public |
|
| 59 | + * |
|
| 60 | + * @param bool $routing |
|
| 61 | + * |
|
| 62 | + * @return Transactions_Admin_Page |
|
| 63 | + */ |
|
| 64 | + public function __construct($routing = true) |
|
| 65 | + { |
|
| 66 | + parent::__construct($routing); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * _init_page_props |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _init_page_props() |
|
| 75 | + { |
|
| 76 | + $this->page_slug = TXN_PG_SLUG; |
|
| 77 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 78 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 79 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ajax_hooks |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + protected function _ajax_hooks() |
|
| 88 | + { |
|
| 89 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 90 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 91 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * _define_page_props |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + protected function _define_page_props() |
|
| 100 | + { |
|
| 101 | + $this->_admin_page_title = $this->page_label; |
|
| 102 | + $this->_labels = array( |
|
| 103 | + 'buttons' => array( |
|
| 104 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 105 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 106 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * grab url requests and route them |
|
| 114 | + * @access private |
|
| 115 | + * @return void |
|
| 116 | + */ |
|
| 117 | + public function _set_page_routes() |
|
| 118 | + { |
|
| 119 | + |
|
| 120 | + $this->_set_transaction_status_array(); |
|
| 121 | + |
|
| 122 | + $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; |
|
| 123 | + |
|
| 124 | + $this->_page_routes = array( |
|
| 125 | 125 | |
| 126 | - 'default' => array( |
|
| 127 | - 'func' => '_transactions_overview_list_table', |
|
| 128 | - 'capability' => 'ee_read_transactions' |
|
| 129 | - ), |
|
| 126 | + 'default' => array( |
|
| 127 | + 'func' => '_transactions_overview_list_table', |
|
| 128 | + 'capability' => 'ee_read_transactions' |
|
| 129 | + ), |
|
| 130 | 130 | |
| 131 | - 'view_transaction' => array( |
|
| 132 | - 'func' => '_transaction_details', |
|
| 133 | - 'capability' => 'ee_read_transaction', |
|
| 134 | - 'obj_id' => $txn_id |
|
| 135 | - ), |
|
| 131 | + 'view_transaction' => array( |
|
| 132 | + 'func' => '_transaction_details', |
|
| 133 | + 'capability' => 'ee_read_transaction', |
|
| 134 | + 'obj_id' => $txn_id |
|
| 135 | + ), |
|
| 136 | 136 | |
| 137 | - 'send_payment_reminder' => array( |
|
| 138 | - 'func' => '_send_payment_reminder', |
|
| 139 | - 'noheader' => true, |
|
| 140 | - 'capability' => 'ee_send_message' |
|
| 141 | - ), |
|
| 137 | + 'send_payment_reminder' => array( |
|
| 138 | + 'func' => '_send_payment_reminder', |
|
| 139 | + 'noheader' => true, |
|
| 140 | + 'capability' => 'ee_send_message' |
|
| 141 | + ), |
|
| 142 | 142 | |
| 143 | - 'espresso_apply_payment' => array( |
|
| 144 | - 'func' => 'apply_payments_or_refunds', |
|
| 145 | - 'noheader' => true, |
|
| 146 | - 'capability' => 'ee_edit_payments' |
|
| 147 | - ), |
|
| 143 | + 'espresso_apply_payment' => array( |
|
| 144 | + 'func' => 'apply_payments_or_refunds', |
|
| 145 | + 'noheader' => true, |
|
| 146 | + 'capability' => 'ee_edit_payments' |
|
| 147 | + ), |
|
| 148 | 148 | |
| 149 | - 'espresso_apply_refund' => array( |
|
| 150 | - 'func' => 'apply_payments_or_refunds', |
|
| 151 | - 'noheader' => true, |
|
| 152 | - 'capability' => 'ee_edit_payments' |
|
| 153 | - ), |
|
| 149 | + 'espresso_apply_refund' => array( |
|
| 150 | + 'func' => 'apply_payments_or_refunds', |
|
| 151 | + 'noheader' => true, |
|
| 152 | + 'capability' => 'ee_edit_payments' |
|
| 153 | + ), |
|
| 154 | 154 | |
| 155 | - 'espresso_delete_payment' => array( |
|
| 156 | - 'func' => 'delete_payment', |
|
| 157 | - 'noheader' => true, |
|
| 158 | - 'capability' => 'ee_delete_payments' |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - protected function _set_page_config() |
|
| 167 | - { |
|
| 168 | - $this->_page_config = array( |
|
| 169 | - 'default' => array( |
|
| 170 | - 'nav' => array( |
|
| 171 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 172 | - 'order' => 10 |
|
| 173 | - ), |
|
| 174 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 175 | - 'help_tabs' => array( |
|
| 176 | - 'transactions_overview_help_tab' => array( |
|
| 177 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 178 | - 'filename' => 'transactions_overview' |
|
| 179 | - ), |
|
| 180 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 181 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 182 | - 'filename' => 'transactions_overview_table_column_headings' |
|
| 183 | - ), |
|
| 184 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 185 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 186 | - 'filename' => 'transactions_overview_views_filters_search' |
|
| 187 | - ), |
|
| 188 | - ), |
|
| 189 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 190 | - /** |
|
| 191 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 192 | - * may change in a later iteration so want to keep the code for then. |
|
| 193 | - */ |
|
| 194 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 195 | - 'require_nonce' => false |
|
| 196 | - ), |
|
| 197 | - 'view_transaction' => array( |
|
| 198 | - 'nav' => array( |
|
| 199 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 200 | - 'order' => 5, |
|
| 201 | - 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
| 202 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 203 | - 'persistent' => false |
|
| 204 | - ), |
|
| 205 | - 'help_tabs' => array( |
|
| 206 | - 'transactions_view_transaction_help_tab' => array( |
|
| 207 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 208 | - 'filename' => 'transactions_view_transaction' |
|
| 209 | - ), |
|
| 210 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 211 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 212 | - 'filename' => 'transactions_view_transaction_transaction_details_table' |
|
| 213 | - ), |
|
| 214 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 215 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 216 | - 'filename' => 'transactions_view_transaction_attendees_registered' |
|
| 217 | - ), |
|
| 218 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 219 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 220 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
|
| 221 | - ), |
|
| 222 | - ), |
|
| 223 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 224 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 225 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 155 | + 'espresso_delete_payment' => array( |
|
| 156 | + 'func' => 'delete_payment', |
|
| 157 | + 'noheader' => true, |
|
| 158 | + 'capability' => 'ee_delete_payments' |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + protected function _set_page_config() |
|
| 167 | + { |
|
| 168 | + $this->_page_config = array( |
|
| 169 | + 'default' => array( |
|
| 170 | + 'nav' => array( |
|
| 171 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 172 | + 'order' => 10 |
|
| 173 | + ), |
|
| 174 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 175 | + 'help_tabs' => array( |
|
| 176 | + 'transactions_overview_help_tab' => array( |
|
| 177 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 178 | + 'filename' => 'transactions_overview' |
|
| 179 | + ), |
|
| 180 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 181 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 182 | + 'filename' => 'transactions_overview_table_column_headings' |
|
| 183 | + ), |
|
| 184 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 185 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 186 | + 'filename' => 'transactions_overview_views_filters_search' |
|
| 187 | + ), |
|
| 188 | + ), |
|
| 189 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 190 | + /** |
|
| 191 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 192 | + * may change in a later iteration so want to keep the code for then. |
|
| 193 | + */ |
|
| 194 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 195 | + 'require_nonce' => false |
|
| 196 | + ), |
|
| 197 | + 'view_transaction' => array( |
|
| 198 | + 'nav' => array( |
|
| 199 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 200 | + 'order' => 5, |
|
| 201 | + 'url' => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), |
|
| 202 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 203 | + 'persistent' => false |
|
| 204 | + ), |
|
| 205 | + 'help_tabs' => array( |
|
| 206 | + 'transactions_view_transaction_help_tab' => array( |
|
| 207 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 208 | + 'filename' => 'transactions_view_transaction' |
|
| 209 | + ), |
|
| 210 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 211 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 212 | + 'filename' => 'transactions_view_transaction_transaction_details_table' |
|
| 213 | + ), |
|
| 214 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 215 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 216 | + 'filename' => 'transactions_view_transaction_attendees_registered' |
|
| 217 | + ), |
|
| 218 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 219 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 220 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' |
|
| 221 | + ), |
|
| 222 | + ), |
|
| 223 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 224 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 225 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 226 | 226 | |
| 227 | - 'require_nonce' => false |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * The below methods aren't used by this class currently |
|
| 235 | - */ |
|
| 236 | - protected function _add_screen_options() |
|
| 237 | - { |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - protected function _add_feature_pointers() |
|
| 241 | - { |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function admin_init() |
|
| 245 | - { |
|
| 246 | - // IF a registration was JUST added via the admin... |
|
| 247 | - if ( |
|
| 248 | - isset( |
|
| 249 | - $this->_req_data['redirect_from'], |
|
| 250 | - $this->_req_data['EVT_ID'], |
|
| 251 | - $this->_req_data['event_name'] |
|
| 252 | - ) |
|
| 253 | - ) { |
|
| 254 | - // then set a cookie so that we can block any attempts to use |
|
| 255 | - // the back button as a way to enter another registration. |
|
| 256 | - setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
| 257 | - // and update the global |
|
| 258 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 259 | - } |
|
| 260 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 261 | - 'event_espresso'); |
|
| 262 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
| 263 | - 'event_espresso'); |
|
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
| 268 | - 'event_espresso'); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - public function admin_notices() |
|
| 272 | - { |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function admin_footer_scripts() |
|
| 276 | - { |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * _set_transaction_status_array |
|
| 282 | - * sets list of transaction statuses |
|
| 283 | - * |
|
| 284 | - * @access private |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - private function _set_transaction_status_array() |
|
| 288 | - { |
|
| 289 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * get_transaction_status_array |
|
| 295 | - * return the transaction status array for wp_list_table |
|
| 296 | - * |
|
| 297 | - * @access public |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function get_transaction_status_array() |
|
| 301 | - { |
|
| 302 | - return self::$_txn_status; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * get list of payment statuses |
|
| 308 | - * |
|
| 309 | - * @access private |
|
| 310 | - * @return void |
|
| 311 | - */ |
|
| 312 | - private function _get_payment_status_array() |
|
| 313 | - { |
|
| 314 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 315 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 316 | - |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * _add_screen_options_default |
|
| 322 | - * |
|
| 323 | - * @access protected |
|
| 324 | - * @return void |
|
| 325 | - */ |
|
| 326 | - protected function _add_screen_options_default() |
|
| 327 | - { |
|
| 328 | - $this->_per_page_screen_option(); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * load_scripts_styles |
|
| 334 | - * |
|
| 335 | - * @access public |
|
| 336 | - * @return void |
|
| 337 | - */ |
|
| 338 | - public function load_scripts_styles() |
|
| 339 | - { |
|
| 340 | - //enqueue style |
|
| 341 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 342 | - EVENT_ESPRESSO_VERSION); |
|
| 343 | - wp_enqueue_style('espresso_txn'); |
|
| 344 | - |
|
| 345 | - //scripts |
|
| 346 | - add_filter('FHEE_load_accounting_js', '__return_true'); |
|
| 347 | - |
|
| 348 | - //scripts |
|
| 349 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 350 | - 'ee_admin_js', |
|
| 351 | - 'ee-datepicker', |
|
| 352 | - 'jquery-ui-datepicker', |
|
| 353 | - 'jquery-ui-draggable', |
|
| 354 | - 'ee-dialog', |
|
| 355 | - 'ee-accounting', |
|
| 356 | - 'ee-serialize-full-array' |
|
| 357 | - ), EVENT_ESPRESSO_VERSION, true); |
|
| 358 | - wp_enqueue_script('espresso_txn'); |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * load_scripts_styles_view_transaction |
|
| 365 | - * |
|
| 366 | - * @access public |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function load_scripts_styles_view_transaction() |
|
| 370 | - { |
|
| 371 | - //styles |
|
| 372 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * load_scripts_styles_default |
|
| 378 | - * |
|
| 379 | - * @access public |
|
| 380 | - * @return void |
|
| 381 | - */ |
|
| 382 | - public function load_scripts_styles_default() |
|
| 383 | - { |
|
| 384 | - //styles |
|
| 385 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * _set_list_table_views_default |
|
| 391 | - * |
|
| 392 | - * @access protected |
|
| 393 | - * @return void |
|
| 394 | - */ |
|
| 395 | - protected function _set_list_table_views_default() |
|
| 396 | - { |
|
| 397 | - $this->_views = array( |
|
| 398 | - 'all' => array( |
|
| 399 | - 'slug' => 'all', |
|
| 400 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 401 | - 'count' => 0 |
|
| 402 | - ), |
|
| 403 | - 'abandoned' => array( |
|
| 404 | - 'slug' => 'abandoned', |
|
| 405 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 406 | - 'count' => 0 |
|
| 407 | - ), |
|
| 408 | - 'failed' => array( |
|
| 409 | - 'slug' => 'failed', |
|
| 410 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 411 | - 'count' => 0 |
|
| 412 | - ) |
|
| 413 | - ); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * _set_transaction_object |
|
| 419 | - * This sets the _transaction property for the transaction details screen |
|
| 420 | - * |
|
| 421 | - * @access private |
|
| 422 | - * @return void |
|
| 423 | - */ |
|
| 424 | - private function _set_transaction_object() |
|
| 425 | - { |
|
| 426 | - if (is_object($this->_transaction)) { |
|
| 427 | - return; |
|
| 428 | - } //get out we've already set the object |
|
| 429 | - |
|
| 430 | - $TXN = EEM_Transaction::instance(); |
|
| 431 | - |
|
| 432 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 433 | - |
|
| 434 | - //get transaction object |
|
| 435 | - $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
| 436 | - $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
| 437 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 438 | - |
|
| 439 | - if (empty($this->_transaction)) { |
|
| 440 | - $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
| 441 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 442 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * _transaction_legend_items |
|
| 449 | - * |
|
| 450 | - * @access protected |
|
| 451 | - * @return array |
|
| 452 | - */ |
|
| 453 | - protected function _transaction_legend_items() |
|
| 454 | - { |
|
| 455 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 456 | - $items = array(); |
|
| 457 | - |
|
| 458 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 459 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 460 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 461 | - $items['view_related_messages'] = array( |
|
| 462 | - 'class' => $related_for_icon['css_class'], |
|
| 463 | - 'desc' => $related_for_icon['label'], |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - $items = apply_filters( |
|
| 469 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 470 | - array_merge($items, |
|
| 471 | - array( |
|
| 472 | - 'view_details' => array( |
|
| 473 | - 'class' => 'dashicons dashicons-cart', |
|
| 474 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso') |
|
| 475 | - ), |
|
| 476 | - 'view_invoice' => array( |
|
| 477 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 478 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso') |
|
| 479 | - ), |
|
| 480 | - 'view_receipt' => array( |
|
| 481 | - 'class' => 'dashicons dashicons-media-default', |
|
| 482 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso') |
|
| 483 | - ), |
|
| 484 | - 'view_registration' => array( |
|
| 485 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 486 | - 'desc' => esc_html__('View Registration Details', 'event_espresso') |
|
| 487 | - ) |
|
| 488 | - ) |
|
| 489 | - ) |
|
| 490 | - ); |
|
| 491 | - |
|
| 492 | - if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 493 | - 'espresso_transactions_send_payment_reminder') |
|
| 494 | - ) { |
|
| 495 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 496 | - $items['send_payment_reminder'] = array( |
|
| 497 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 498 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso') |
|
| 499 | - ); |
|
| 500 | - } else { |
|
| 501 | - $items['blank*'] = array( |
|
| 502 | - 'class' => '', |
|
| 503 | - 'desc' => '' |
|
| 504 | - ); |
|
| 505 | - } |
|
| 506 | - } else { |
|
| 507 | - $items['blank*'] = array( |
|
| 508 | - 'class' => '', |
|
| 509 | - 'desc' => '' |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - $more_items = apply_filters( |
|
| 513 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 514 | - array( |
|
| 515 | - 'overpaid' => array( |
|
| 516 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 517 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
|
| 518 | - ), |
|
| 519 | - 'complete' => array( |
|
| 520 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 521 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
|
| 522 | - ), |
|
| 523 | - 'incomplete' => array( |
|
| 524 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 525 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
|
| 526 | - ), |
|
| 527 | - 'abandoned' => array( |
|
| 528 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 529 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
|
| 530 | - ), |
|
| 531 | - 'failed' => array( |
|
| 532 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 533 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
|
| 534 | - ) |
|
| 535 | - ) |
|
| 536 | - ); |
|
| 537 | - |
|
| 538 | - return array_merge($items, $more_items); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * _transactions_overview_list_table |
|
| 544 | - * |
|
| 545 | - * @access protected |
|
| 546 | - * @return void |
|
| 547 | - */ |
|
| 548 | - protected function _transactions_overview_list_table() |
|
| 549 | - { |
|
| 550 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 551 | - $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
| 552 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
| 553 | - 'event_espresso'), '<h3>', |
|
| 554 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 555 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 556 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 557 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 558 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * _transaction_details |
|
| 564 | - * generates HTML for the View Transaction Details Admin page |
|
| 565 | - * |
|
| 566 | - * @access protected |
|
| 567 | - * @return void |
|
| 568 | - */ |
|
| 569 | - protected function _transaction_details() |
|
| 570 | - { |
|
| 571 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 572 | - |
|
| 573 | - $this->_set_transaction_status_array(); |
|
| 574 | - |
|
| 575 | - $this->_template_args = array(); |
|
| 576 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 577 | - |
|
| 578 | - $this->_set_transaction_object(); |
|
| 579 | - |
|
| 580 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 581 | - $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
| 582 | - |
|
| 583 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 584 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 585 | - |
|
| 586 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 587 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 588 | - |
|
| 589 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 590 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 591 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 592 | - |
|
| 593 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 594 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 595 | - |
|
| 596 | - if ( |
|
| 597 | - $attendee instanceof EE_Attendee |
|
| 598 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 599 | - 'ee_send_message', |
|
| 600 | - 'espresso_transactions_send_payment_reminder' |
|
| 601 | - ) |
|
| 602 | - ) { |
|
| 603 | - $this->_template_args['send_payment_reminder_button'] = |
|
| 604 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 605 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
| 606 | - && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
| 607 | - ? EEH_Template::get_button_or_link( |
|
| 608 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 609 | - array( |
|
| 610 | - 'action' => 'send_payment_reminder', |
|
| 611 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 612 | - 'redirect_to' => 'view_transaction' |
|
| 613 | - ), |
|
| 614 | - TXN_ADMIN_URL |
|
| 615 | - ), |
|
| 616 | - __(' Send Payment Reminder', 'event_espresso'), |
|
| 617 | - 'button secondary-button right', |
|
| 618 | - 'dashicons dashicons-email-alt' |
|
| 619 | - ) |
|
| 620 | - : ''; |
|
| 621 | - } else { |
|
| 622 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 626 | - $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
| 627 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 628 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 629 | - } else { |
|
| 630 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 631 | - } |
|
| 632 | - $this->_template_args['amount_due_class'] = ''; |
|
| 633 | - |
|
| 634 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 635 | - // paid in full |
|
| 636 | - $this->_template_args['amount_due'] = false; |
|
| 637 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 638 | - // overpaid |
|
| 639 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 640 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 641 | - // monies owing |
|
| 642 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 643 | - } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 644 | - // no payments made yet |
|
| 645 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 646 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 647 | - // free event |
|
| 648 | - $this->_template_args['amount_due'] = false; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - $payment_method = $this->_transaction->payment_method(); |
|
| 652 | - |
|
| 653 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 654 | - ? $payment_method->admin_name() |
|
| 655 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 656 | - |
|
| 657 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 658 | - // link back to overview |
|
| 659 | - $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
| 660 | - ? $_SERVER['HTTP_REFERER'] |
|
| 661 | - : TXN_ADMIN_URL; |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - // next link |
|
| 665 | - $next_txn = $this->_transaction->next( |
|
| 666 | - null, |
|
| 667 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 668 | - 'TXN_ID' |
|
| 669 | - ); |
|
| 670 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 671 | - ? $this->_next_link( |
|
| 672 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 673 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 674 | - TXN_ADMIN_URL |
|
| 675 | - ), |
|
| 676 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 677 | - ) |
|
| 678 | - : ''; |
|
| 679 | - // previous link |
|
| 680 | - $previous_txn = $this->_transaction->previous( |
|
| 681 | - null, |
|
| 682 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 683 | - 'TXN_ID' |
|
| 684 | - ); |
|
| 685 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 686 | - ? $this->_previous_link( |
|
| 687 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 688 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 689 | - TXN_ADMIN_URL |
|
| 690 | - ), |
|
| 691 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 692 | - ) |
|
| 693 | - : ''; |
|
| 694 | - |
|
| 695 | - // were we just redirected here after adding a new registration ??? |
|
| 696 | - if ( |
|
| 697 | - isset( |
|
| 698 | - $this->_req_data['redirect_from'], |
|
| 699 | - $this->_req_data['EVT_ID'], |
|
| 700 | - $this->_req_data['event_name'] |
|
| 701 | - ) |
|
| 702 | - ) { |
|
| 703 | - if ( |
|
| 704 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 705 | - 'ee_edit_registrations', |
|
| 706 | - 'espresso_registrations_new_registration', |
|
| 707 | - $this->_req_data['EVT_ID'] |
|
| 708 | - ) |
|
| 709 | - ) { |
|
| 710 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 711 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 712 | - array( |
|
| 713 | - 'page' => 'espresso_registrations', |
|
| 714 | - 'action' => 'new_registration', |
|
| 715 | - 'return' => 'default', |
|
| 716 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 717 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 718 | - ), |
|
| 719 | - REG_ADMIN_URL |
|
| 720 | - ); |
|
| 721 | - $this->_admin_page_title .= '">'; |
|
| 227 | + 'require_nonce' => false |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * The below methods aren't used by this class currently |
|
| 235 | + */ |
|
| 236 | + protected function _add_screen_options() |
|
| 237 | + { |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + protected function _add_feature_pointers() |
|
| 241 | + { |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function admin_init() |
|
| 245 | + { |
|
| 246 | + // IF a registration was JUST added via the admin... |
|
| 247 | + if ( |
|
| 248 | + isset( |
|
| 249 | + $this->_req_data['redirect_from'], |
|
| 250 | + $this->_req_data['EVT_ID'], |
|
| 251 | + $this->_req_data['event_name'] |
|
| 252 | + ) |
|
| 253 | + ) { |
|
| 254 | + // then set a cookie so that we can block any attempts to use |
|
| 255 | + // the back button as a way to enter another registration. |
|
| 256 | + setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); |
|
| 257 | + // and update the global |
|
| 258 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 259 | + } |
|
| 260 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 261 | + 'event_espresso'); |
|
| 262 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__('An error occurred! Please refresh the page and try again.', |
|
| 263 | + 'event_espresso'); |
|
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__('This transaction has been overpaid ! Payments Total', |
|
| 268 | + 'event_espresso'); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + public function admin_notices() |
|
| 272 | + { |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function admin_footer_scripts() |
|
| 276 | + { |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * _set_transaction_status_array |
|
| 282 | + * sets list of transaction statuses |
|
| 283 | + * |
|
| 284 | + * @access private |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + private function _set_transaction_status_array() |
|
| 288 | + { |
|
| 289 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * get_transaction_status_array |
|
| 295 | + * return the transaction status array for wp_list_table |
|
| 296 | + * |
|
| 297 | + * @access public |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function get_transaction_status_array() |
|
| 301 | + { |
|
| 302 | + return self::$_txn_status; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * get list of payment statuses |
|
| 308 | + * |
|
| 309 | + * @access private |
|
| 310 | + * @return void |
|
| 311 | + */ |
|
| 312 | + private function _get_payment_status_array() |
|
| 313 | + { |
|
| 314 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 315 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 316 | + |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * _add_screen_options_default |
|
| 322 | + * |
|
| 323 | + * @access protected |
|
| 324 | + * @return void |
|
| 325 | + */ |
|
| 326 | + protected function _add_screen_options_default() |
|
| 327 | + { |
|
| 328 | + $this->_per_page_screen_option(); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * load_scripts_styles |
|
| 334 | + * |
|
| 335 | + * @access public |
|
| 336 | + * @return void |
|
| 337 | + */ |
|
| 338 | + public function load_scripts_styles() |
|
| 339 | + { |
|
| 340 | + //enqueue style |
|
| 341 | + wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 342 | + EVENT_ESPRESSO_VERSION); |
|
| 343 | + wp_enqueue_style('espresso_txn'); |
|
| 344 | + |
|
| 345 | + //scripts |
|
| 346 | + add_filter('FHEE_load_accounting_js', '__return_true'); |
|
| 347 | + |
|
| 348 | + //scripts |
|
| 349 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 350 | + 'ee_admin_js', |
|
| 351 | + 'ee-datepicker', |
|
| 352 | + 'jquery-ui-datepicker', |
|
| 353 | + 'jquery-ui-draggable', |
|
| 354 | + 'ee-dialog', |
|
| 355 | + 'ee-accounting', |
|
| 356 | + 'ee-serialize-full-array' |
|
| 357 | + ), EVENT_ESPRESSO_VERSION, true); |
|
| 358 | + wp_enqueue_script('espresso_txn'); |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * load_scripts_styles_view_transaction |
|
| 365 | + * |
|
| 366 | + * @access public |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function load_scripts_styles_view_transaction() |
|
| 370 | + { |
|
| 371 | + //styles |
|
| 372 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * load_scripts_styles_default |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + * @return void |
|
| 381 | + */ |
|
| 382 | + public function load_scripts_styles_default() |
|
| 383 | + { |
|
| 384 | + //styles |
|
| 385 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * _set_list_table_views_default |
|
| 391 | + * |
|
| 392 | + * @access protected |
|
| 393 | + * @return void |
|
| 394 | + */ |
|
| 395 | + protected function _set_list_table_views_default() |
|
| 396 | + { |
|
| 397 | + $this->_views = array( |
|
| 398 | + 'all' => array( |
|
| 399 | + 'slug' => 'all', |
|
| 400 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 401 | + 'count' => 0 |
|
| 402 | + ), |
|
| 403 | + 'abandoned' => array( |
|
| 404 | + 'slug' => 'abandoned', |
|
| 405 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 406 | + 'count' => 0 |
|
| 407 | + ), |
|
| 408 | + 'failed' => array( |
|
| 409 | + 'slug' => 'failed', |
|
| 410 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 411 | + 'count' => 0 |
|
| 412 | + ) |
|
| 413 | + ); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * _set_transaction_object |
|
| 419 | + * This sets the _transaction property for the transaction details screen |
|
| 420 | + * |
|
| 421 | + * @access private |
|
| 422 | + * @return void |
|
| 423 | + */ |
|
| 424 | + private function _set_transaction_object() |
|
| 425 | + { |
|
| 426 | + if (is_object($this->_transaction)) { |
|
| 427 | + return; |
|
| 428 | + } //get out we've already set the object |
|
| 429 | + |
|
| 430 | + $TXN = EEM_Transaction::instance(); |
|
| 431 | + |
|
| 432 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 433 | + |
|
| 434 | + //get transaction object |
|
| 435 | + $this->_transaction = $TXN->get_one_by_ID($TXN_ID); |
|
| 436 | + $this->_session = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; |
|
| 437 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 438 | + |
|
| 439 | + if (empty($this->_transaction)) { |
|
| 440 | + $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
|
| 441 | + 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 442 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * _transaction_legend_items |
|
| 449 | + * |
|
| 450 | + * @access protected |
|
| 451 | + * @return array |
|
| 452 | + */ |
|
| 453 | + protected function _transaction_legend_items() |
|
| 454 | + { |
|
| 455 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 456 | + $items = array(); |
|
| 457 | + |
|
| 458 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 459 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 460 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 461 | + $items['view_related_messages'] = array( |
|
| 462 | + 'class' => $related_for_icon['css_class'], |
|
| 463 | + 'desc' => $related_for_icon['label'], |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + $items = apply_filters( |
|
| 469 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 470 | + array_merge($items, |
|
| 471 | + array( |
|
| 472 | + 'view_details' => array( |
|
| 473 | + 'class' => 'dashicons dashicons-cart', |
|
| 474 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso') |
|
| 475 | + ), |
|
| 476 | + 'view_invoice' => array( |
|
| 477 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 478 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso') |
|
| 479 | + ), |
|
| 480 | + 'view_receipt' => array( |
|
| 481 | + 'class' => 'dashicons dashicons-media-default', |
|
| 482 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso') |
|
| 483 | + ), |
|
| 484 | + 'view_registration' => array( |
|
| 485 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 486 | + 'desc' => esc_html__('View Registration Details', 'event_espresso') |
|
| 487 | + ) |
|
| 488 | + ) |
|
| 489 | + ) |
|
| 490 | + ); |
|
| 491 | + |
|
| 492 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 493 | + 'espresso_transactions_send_payment_reminder') |
|
| 494 | + ) { |
|
| 495 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 496 | + $items['send_payment_reminder'] = array( |
|
| 497 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 498 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso') |
|
| 499 | + ); |
|
| 500 | + } else { |
|
| 501 | + $items['blank*'] = array( |
|
| 502 | + 'class' => '', |
|
| 503 | + 'desc' => '' |
|
| 504 | + ); |
|
| 505 | + } |
|
| 506 | + } else { |
|
| 507 | + $items['blank*'] = array( |
|
| 508 | + 'class' => '', |
|
| 509 | + 'desc' => '' |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + $more_items = apply_filters( |
|
| 513 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 514 | + array( |
|
| 515 | + 'overpaid' => array( |
|
| 516 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 517 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
|
| 518 | + ), |
|
| 519 | + 'complete' => array( |
|
| 520 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 521 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
|
| 522 | + ), |
|
| 523 | + 'incomplete' => array( |
|
| 524 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 525 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
|
| 526 | + ), |
|
| 527 | + 'abandoned' => array( |
|
| 528 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 529 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
|
| 530 | + ), |
|
| 531 | + 'failed' => array( |
|
| 532 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 533 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
|
| 534 | + ) |
|
| 535 | + ) |
|
| 536 | + ); |
|
| 537 | + |
|
| 538 | + return array_merge($items, $more_items); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * _transactions_overview_list_table |
|
| 544 | + * |
|
| 545 | + * @access protected |
|
| 546 | + * @return void |
|
| 547 | + */ |
|
| 548 | + protected function _transactions_overview_list_table() |
|
| 549 | + { |
|
| 550 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 551 | + $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
|
| 552 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
|
| 553 | + 'event_espresso'), '<h3>', |
|
| 554 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 555 | + EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 556 | + 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 557 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 558 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * _transaction_details |
|
| 564 | + * generates HTML for the View Transaction Details Admin page |
|
| 565 | + * |
|
| 566 | + * @access protected |
|
| 567 | + * @return void |
|
| 568 | + */ |
|
| 569 | + protected function _transaction_details() |
|
| 570 | + { |
|
| 571 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 572 | + |
|
| 573 | + $this->_set_transaction_status_array(); |
|
| 574 | + |
|
| 575 | + $this->_template_args = array(); |
|
| 576 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 577 | + |
|
| 578 | + $this->_set_transaction_object(); |
|
| 579 | + |
|
| 580 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 581 | + $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; |
|
| 582 | + |
|
| 583 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 584 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 585 | + |
|
| 586 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 587 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 588 | + |
|
| 589 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 590 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 591 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 592 | + |
|
| 593 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 594 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 595 | + |
|
| 596 | + if ( |
|
| 597 | + $attendee instanceof EE_Attendee |
|
| 598 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 599 | + 'ee_send_message', |
|
| 600 | + 'espresso_transactions_send_payment_reminder' |
|
| 601 | + ) |
|
| 602 | + ) { |
|
| 603 | + $this->_template_args['send_payment_reminder_button'] = |
|
| 604 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 605 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code |
|
| 606 | + && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code |
|
| 607 | + ? EEH_Template::get_button_or_link( |
|
| 608 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 609 | + array( |
|
| 610 | + 'action' => 'send_payment_reminder', |
|
| 611 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 612 | + 'redirect_to' => 'view_transaction' |
|
| 613 | + ), |
|
| 614 | + TXN_ADMIN_URL |
|
| 615 | + ), |
|
| 616 | + __(' Send Payment Reminder', 'event_espresso'), |
|
| 617 | + 'button secondary-button right', |
|
| 618 | + 'dashicons dashicons-email-alt' |
|
| 619 | + ) |
|
| 620 | + : ''; |
|
| 621 | + } else { |
|
| 622 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 626 | + $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
|
| 627 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 628 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 629 | + } else { |
|
| 630 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 631 | + } |
|
| 632 | + $this->_template_args['amount_due_class'] = ''; |
|
| 633 | + |
|
| 634 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 635 | + // paid in full |
|
| 636 | + $this->_template_args['amount_due'] = false; |
|
| 637 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 638 | + // overpaid |
|
| 639 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 640 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { |
|
| 641 | + // monies owing |
|
| 642 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 643 | + } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { |
|
| 644 | + // no payments made yet |
|
| 645 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 646 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 647 | + // free event |
|
| 648 | + $this->_template_args['amount_due'] = false; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + $payment_method = $this->_transaction->payment_method(); |
|
| 652 | + |
|
| 653 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 654 | + ? $payment_method->admin_name() |
|
| 655 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 656 | + |
|
| 657 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 658 | + // link back to overview |
|
| 659 | + $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) |
|
| 660 | + ? $_SERVER['HTTP_REFERER'] |
|
| 661 | + : TXN_ADMIN_URL; |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + // next link |
|
| 665 | + $next_txn = $this->_transaction->next( |
|
| 666 | + null, |
|
| 667 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 668 | + 'TXN_ID' |
|
| 669 | + ); |
|
| 670 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 671 | + ? $this->_next_link( |
|
| 672 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 673 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 674 | + TXN_ADMIN_URL |
|
| 675 | + ), |
|
| 676 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 677 | + ) |
|
| 678 | + : ''; |
|
| 679 | + // previous link |
|
| 680 | + $previous_txn = $this->_transaction->previous( |
|
| 681 | + null, |
|
| 682 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 683 | + 'TXN_ID' |
|
| 684 | + ); |
|
| 685 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 686 | + ? $this->_previous_link( |
|
| 687 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 688 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 689 | + TXN_ADMIN_URL |
|
| 690 | + ), |
|
| 691 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 692 | + ) |
|
| 693 | + : ''; |
|
| 694 | + |
|
| 695 | + // were we just redirected here after adding a new registration ??? |
|
| 696 | + if ( |
|
| 697 | + isset( |
|
| 698 | + $this->_req_data['redirect_from'], |
|
| 699 | + $this->_req_data['EVT_ID'], |
|
| 700 | + $this->_req_data['event_name'] |
|
| 701 | + ) |
|
| 702 | + ) { |
|
| 703 | + if ( |
|
| 704 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 705 | + 'ee_edit_registrations', |
|
| 706 | + 'espresso_registrations_new_registration', |
|
| 707 | + $this->_req_data['EVT_ID'] |
|
| 708 | + ) |
|
| 709 | + ) { |
|
| 710 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 711 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 712 | + array( |
|
| 713 | + 'page' => 'espresso_registrations', |
|
| 714 | + 'action' => 'new_registration', |
|
| 715 | + 'return' => 'default', |
|
| 716 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 717 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 718 | + ), |
|
| 719 | + REG_ADMIN_URL |
|
| 720 | + ); |
|
| 721 | + $this->_admin_page_title .= '">'; |
|
| 722 | 722 | |
| 723 | - $this->_admin_page_title .= sprintf( |
|
| 724 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 725 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 726 | - ); |
|
| 727 | - $this->_admin_page_title .= '</a>'; |
|
| 728 | - } |
|
| 729 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 730 | - } |
|
| 731 | - // grab messages at the last second |
|
| 732 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 733 | - // path to template |
|
| 734 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 735 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 736 | - $this->_template_args, true); |
|
| 737 | - |
|
| 738 | - // the details template wrapper |
|
| 739 | - $this->display_admin_page_with_sidebar(); |
|
| 740 | - |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * _transaction_details_metaboxes |
|
| 746 | - * |
|
| 747 | - * @access protected |
|
| 748 | - * @return void |
|
| 749 | - */ |
|
| 750 | - protected function _transaction_details_metaboxes() |
|
| 751 | - { |
|
| 752 | - |
|
| 753 | - $this->_set_transaction_object(); |
|
| 754 | - |
|
| 755 | - add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
| 756 | - array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 757 | - add_meta_box( |
|
| 758 | - 'edit-txn-attendees-mbox', |
|
| 759 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 760 | - array($this, 'txn_attendees_meta_box'), |
|
| 761 | - $this->_wp_page_slug, |
|
| 762 | - 'normal', |
|
| 763 | - 'high', |
|
| 764 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 765 | - ); |
|
| 766 | - add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
| 767 | - array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 768 | - add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
| 769 | - array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 770 | - |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * txn_details_meta_box |
|
| 776 | - * generates HTML for the Transaction main meta box |
|
| 777 | - * |
|
| 778 | - * @access public |
|
| 779 | - * @return void |
|
| 780 | - */ |
|
| 781 | - public function txn_details_meta_box() |
|
| 782 | - { |
|
| 783 | - |
|
| 784 | - $this->_set_transaction_object(); |
|
| 785 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 786 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
| 787 | - |
|
| 788 | - //get line table |
|
| 789 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 790 | - $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
| 791 | - 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 792 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 793 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
| 794 | - |
|
| 795 | - // process taxes |
|
| 796 | - $taxes = $this->_transaction->get_many_related('Line_Item', |
|
| 797 | - array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 798 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 799 | - |
|
| 800 | - $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
| 801 | - false, false); |
|
| 802 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 803 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 723 | + $this->_admin_page_title .= sprintf( |
|
| 724 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 725 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 726 | + ); |
|
| 727 | + $this->_admin_page_title .= '</a>'; |
|
| 728 | + } |
|
| 729 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 730 | + } |
|
| 731 | + // grab messages at the last second |
|
| 732 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 733 | + // path to template |
|
| 734 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 735 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 736 | + $this->_template_args, true); |
|
| 737 | + |
|
| 738 | + // the details template wrapper |
|
| 739 | + $this->display_admin_page_with_sidebar(); |
|
| 740 | + |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * _transaction_details_metaboxes |
|
| 746 | + * |
|
| 747 | + * @access protected |
|
| 748 | + * @return void |
|
| 749 | + */ |
|
| 750 | + protected function _transaction_details_metaboxes() |
|
| 751 | + { |
|
| 752 | + |
|
| 753 | + $this->_set_transaction_object(); |
|
| 754 | + |
|
| 755 | + add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), |
|
| 756 | + array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); |
|
| 757 | + add_meta_box( |
|
| 758 | + 'edit-txn-attendees-mbox', |
|
| 759 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 760 | + array($this, 'txn_attendees_meta_box'), |
|
| 761 | + $this->_wp_page_slug, |
|
| 762 | + 'normal', |
|
| 763 | + 'high', |
|
| 764 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 765 | + ); |
|
| 766 | + add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), |
|
| 767 | + array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 768 | + add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), |
|
| 769 | + array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); |
|
| 770 | + |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * txn_details_meta_box |
|
| 776 | + * generates HTML for the Transaction main meta box |
|
| 777 | + * |
|
| 778 | + * @access public |
|
| 779 | + * @return void |
|
| 780 | + */ |
|
| 781 | + public function txn_details_meta_box() |
|
| 782 | + { |
|
| 783 | + |
|
| 784 | + $this->_set_transaction_object(); |
|
| 785 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 786 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; |
|
| 787 | + |
|
| 788 | + //get line table |
|
| 789 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 790 | + $Line_Item_Display = new EE_Line_Item_Display('admin_table', |
|
| 791 | + 'EE_Admin_Table_Line_Item_Display_Strategy'); |
|
| 792 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); |
|
| 793 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration')->get('REG_code'); |
|
| 794 | + |
|
| 795 | + // process taxes |
|
| 796 | + $taxes = $this->_transaction->get_many_related('Line_Item', |
|
| 797 | + array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 798 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 799 | + |
|
| 800 | + $this->_template_args['grand_total'] = EEH_Template::format_currency($this->_transaction->get('TXN_total'), |
|
| 801 | + false, false); |
|
| 802 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 803 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 804 | 804 | |
| 805 | 805 | // $txn_status_class = 'status-' . $this->_transaction->get('STS_ID'); |
| 806 | 806 | |
| 807 | - // process payment details |
|
| 808 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
| 809 | - if ( ! empty($payments)) { |
|
| 810 | - $this->_template_args['payments'] = $payments; |
|
| 811 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 812 | - } else { |
|
| 813 | - $this->_template_args['payments'] = false; |
|
| 814 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 818 | - $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
| 819 | - TXN_ADMIN_URL); |
|
| 820 | - |
|
| 821 | - if (isset($txn_details['invoice_number'])) { |
|
| 822 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 823 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
| 824 | - 'event_espresso'); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
| 828 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
| 829 | - 'event_espresso'); |
|
| 830 | - |
|
| 831 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 832 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
| 833 | - 'event_espresso'); |
|
| 834 | - |
|
| 835 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 836 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 837 | - 'event_espresso'); |
|
| 838 | - |
|
| 839 | - $reg_steps = '<ul>'; |
|
| 840 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 841 | - if ($reg_step_status === true) { |
|
| 842 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 843 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 844 | - } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 845 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 846 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 847 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 848 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 849 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 850 | - ) . '</li>'; |
|
| 851 | - } else { |
|
| 852 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 853 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - $reg_steps .= '</ul>'; |
|
| 857 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 858 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
| 859 | - 'event_espresso'); |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 863 | - $this->_get_payment_methods($payments); |
|
| 864 | - $this->_get_payment_status_array(); |
|
| 865 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 866 | - |
|
| 867 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 868 | - 'action' => 'edit_transaction', |
|
| 869 | - 'process' => 'transaction' |
|
| 870 | - ), TXN_ADMIN_URL); |
|
| 871 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 872 | - 'page' => 'espresso_transactions', |
|
| 873 | - 'action' => 'espresso_apply_payment' |
|
| 874 | - ), WP_AJAX_URL); |
|
| 875 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 876 | - 'page' => 'espresso_transactions', |
|
| 877 | - 'action' => 'espresso_delete_payment' |
|
| 878 | - ), WP_AJAX_URL); |
|
| 879 | - |
|
| 880 | - // 'espresso_delete_payment_nonce' |
|
| 881 | - |
|
| 882 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 883 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 884 | - |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * _get_registration_payment_IDs |
|
| 890 | - * |
|
| 891 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 892 | - * |
|
| 893 | - * @access protected |
|
| 894 | - * |
|
| 895 | - * @param EE_Payment[] $payments |
|
| 896 | - * |
|
| 897 | - * @return array |
|
| 898 | - */ |
|
| 899 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 900 | - { |
|
| 901 | - $existing_reg_payments = array(); |
|
| 902 | - // get all reg payments for these payments |
|
| 903 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 904 | - array( |
|
| 905 | - 'PAY_ID' => array( |
|
| 906 | - 'IN', |
|
| 907 | - array_keys($payments) |
|
| 908 | - ) |
|
| 909 | - ) |
|
| 910 | - )); |
|
| 911 | - if ( ! empty($reg_payments)) { |
|
| 912 | - foreach ($payments as $payment) { |
|
| 913 | - if ( ! $payment instanceof EE_Payment) { |
|
| 914 | - continue; |
|
| 915 | - } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 916 | - $existing_reg_payments[$payment->ID()] = array(); |
|
| 917 | - } |
|
| 918 | - foreach ($reg_payments as $reg_payment) { |
|
| 919 | - if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 920 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - return $existing_reg_payments; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * _get_registrations_to_apply_payment_to |
|
| 932 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 933 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 934 | - * |
|
| 935 | - * @access protected |
|
| 936 | - * @return void |
|
| 937 | - * @throws \EE_Error |
|
| 938 | - */ |
|
| 939 | - protected function _get_registrations_to_apply_payment_to() |
|
| 940 | - { |
|
| 941 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 942 | - $query_params = array( |
|
| 943 | - array( |
|
| 944 | - 'STS_ID' => array( |
|
| 945 | - 'IN', |
|
| 946 | - array( |
|
| 947 | - EEM_Registration::status_id_approved, |
|
| 948 | - EEM_Registration::status_id_pending_payment, |
|
| 949 | - EEM_Registration::status_id_not_approved, |
|
| 950 | - ) |
|
| 951 | - ) |
|
| 952 | - ) |
|
| 953 | - ); |
|
| 954 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 955 | - '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 956 | - ); |
|
| 957 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 958 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 959 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 960 | - EEH_HTML::tr( |
|
| 961 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 962 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 963 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 964 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 965 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 966 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 967 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 968 | - ) |
|
| 969 | - ); |
|
| 970 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 971 | - // get registrations for TXN |
|
| 972 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 973 | - foreach ($registrations as $registration) { |
|
| 974 | - if ($registration instanceof EE_Registration) { |
|
| 975 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 976 | - ? $registration->attendee()->full_name() |
|
| 977 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 978 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 979 | - $taxable = $registration->ticket()->taxable() |
|
| 980 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 981 | - : ''; |
|
| 982 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 983 | - ? ' checked="checked"' |
|
| 984 | - : ''; |
|
| 985 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 986 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 987 | - EEH_HTML::td($registration->ID()) . |
|
| 988 | - EEH_HTML::td($attendee_name) . |
|
| 989 | - EEH_HTML::td( |
|
| 990 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 991 | - ) . |
|
| 992 | - EEH_HTML::td($registration->event_name()) . |
|
| 993 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 994 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 995 | - EEH_HTML::td( |
|
| 996 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 997 | - . '" name="txn_admin_payment[registrations]"' |
|
| 998 | - . $checked . $disabled . '>', |
|
| 999 | - '', 'jst-cntr' |
|
| 1000 | - ), |
|
| 1001 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1002 | - ); |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 1005 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1006 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1007 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1008 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1009 | - esc_html__( |
|
| 1010 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1011 | - 'event_espresso' |
|
| 1012 | - ), |
|
| 1013 | - '', 'clear description' |
|
| 1014 | - ); |
|
| 1015 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1016 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - |
|
| 1020 | - /** |
|
| 1021 | - * _get_reg_status_selection |
|
| 1022 | - * |
|
| 1023 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1024 | - * instead of events. |
|
| 1025 | - * @access protected |
|
| 1026 | - * @return void |
|
| 1027 | - */ |
|
| 1028 | - protected function _get_reg_status_selection() |
|
| 1029 | - { |
|
| 1030 | - //first get all possible statuses |
|
| 1031 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1032 | - //let's add a "don't change" option. |
|
| 1033 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1034 | - $status_array = array_merge($status_array, $statuses); |
|
| 1035 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
| 1036 | - $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 1037 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
| 1038 | - $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 1039 | - |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * _get_payment_methods |
|
| 1045 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1046 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1047 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1048 | - * @access private |
|
| 1049 | - * |
|
| 1050 | - * @param EE_Payment[] to show on this page |
|
| 1051 | - * |
|
| 1052 | - * @return void |
|
| 1053 | - */ |
|
| 1054 | - private function _get_payment_methods($payments = array()) |
|
| 1055 | - { |
|
| 1056 | - $payment_methods_of_payments = array(); |
|
| 1057 | - foreach ($payments as $payment) { |
|
| 1058 | - if ($payment instanceof EE_Payment) { |
|
| 1059 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - if ($payment_methods_of_payments) { |
|
| 1063 | - $query_args = array( |
|
| 1064 | - array( |
|
| 1065 | - 'OR*payment_method_for_payment' => array( |
|
| 1066 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1067 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1068 | - ) |
|
| 1069 | - ) |
|
| 1070 | - ); |
|
| 1071 | - } else { |
|
| 1072 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1073 | - } |
|
| 1074 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * txn_attendees_meta_box |
|
| 1080 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1081 | - * |
|
| 1082 | - * @access public |
|
| 1083 | - * |
|
| 1084 | - * @param WP_Post $post |
|
| 1085 | - * @param array $metabox |
|
| 1086 | - * |
|
| 1087 | - * @return void |
|
| 1088 | - */ |
|
| 1089 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1090 | - { |
|
| 1091 | - |
|
| 1092 | - extract($metabox['args']); |
|
| 1093 | - $this->_template_args['post'] = $post; |
|
| 1094 | - $this->_template_args['event_attendees'] = array(); |
|
| 1095 | - // process items in cart |
|
| 1096 | - $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 1097 | - if ( ! empty($line_items)) { |
|
| 1098 | - foreach ($line_items as $item) { |
|
| 1099 | - if ($item instanceof EE_Line_Item) { |
|
| 1100 | - switch ($item->OBJ_type()) { |
|
| 807 | + // process payment details |
|
| 808 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
| 809 | + if ( ! empty($payments)) { |
|
| 810 | + $this->_template_args['payments'] = $payments; |
|
| 811 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 812 | + } else { |
|
| 813 | + $this->_template_args['payments'] = false; |
|
| 814 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 818 | + $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), |
|
| 819 | + TXN_ADMIN_URL); |
|
| 820 | + |
|
| 821 | + if (isset($txn_details['invoice_number'])) { |
|
| 822 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 823 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', |
|
| 824 | + 'event_espresso'); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); |
|
| 828 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', |
|
| 829 | + 'event_espresso'); |
|
| 830 | + |
|
| 831 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; |
|
| 832 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', |
|
| 833 | + 'event_espresso'); |
|
| 834 | + |
|
| 835 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; |
|
| 836 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 837 | + 'event_espresso'); |
|
| 838 | + |
|
| 839 | + $reg_steps = '<ul>'; |
|
| 840 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 841 | + if ($reg_step_status === true) { |
|
| 842 | + $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 843 | + ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 844 | + } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 845 | + $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 846 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 847 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 848 | + date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 849 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
|
| 850 | + ) . '</li>'; |
|
| 851 | + } else { |
|
| 852 | + $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 853 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + $reg_steps .= '</ul>'; |
|
| 857 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 858 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', |
|
| 859 | + 'event_espresso'); |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 863 | + $this->_get_payment_methods($payments); |
|
| 864 | + $this->_get_payment_status_array(); |
|
| 865 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 866 | + |
|
| 867 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 868 | + 'action' => 'edit_transaction', |
|
| 869 | + 'process' => 'transaction' |
|
| 870 | + ), TXN_ADMIN_URL); |
|
| 871 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 872 | + 'page' => 'espresso_transactions', |
|
| 873 | + 'action' => 'espresso_apply_payment' |
|
| 874 | + ), WP_AJAX_URL); |
|
| 875 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 876 | + 'page' => 'espresso_transactions', |
|
| 877 | + 'action' => 'espresso_delete_payment' |
|
| 878 | + ), WP_AJAX_URL); |
|
| 879 | + |
|
| 880 | + // 'espresso_delete_payment_nonce' |
|
| 881 | + |
|
| 882 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 883 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 884 | + |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * _get_registration_payment_IDs |
|
| 890 | + * |
|
| 891 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 892 | + * |
|
| 893 | + * @access protected |
|
| 894 | + * |
|
| 895 | + * @param EE_Payment[] $payments |
|
| 896 | + * |
|
| 897 | + * @return array |
|
| 898 | + */ |
|
| 899 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 900 | + { |
|
| 901 | + $existing_reg_payments = array(); |
|
| 902 | + // get all reg payments for these payments |
|
| 903 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 904 | + array( |
|
| 905 | + 'PAY_ID' => array( |
|
| 906 | + 'IN', |
|
| 907 | + array_keys($payments) |
|
| 908 | + ) |
|
| 909 | + ) |
|
| 910 | + )); |
|
| 911 | + if ( ! empty($reg_payments)) { |
|
| 912 | + foreach ($payments as $payment) { |
|
| 913 | + if ( ! $payment instanceof EE_Payment) { |
|
| 914 | + continue; |
|
| 915 | + } else if ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 916 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 917 | + } |
|
| 918 | + foreach ($reg_payments as $reg_payment) { |
|
| 919 | + if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { |
|
| 920 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + return $existing_reg_payments; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * _get_registrations_to_apply_payment_to |
|
| 932 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 933 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 934 | + * |
|
| 935 | + * @access protected |
|
| 936 | + * @return void |
|
| 937 | + * @throws \EE_Error |
|
| 938 | + */ |
|
| 939 | + protected function _get_registrations_to_apply_payment_to() |
|
| 940 | + { |
|
| 941 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 942 | + $query_params = array( |
|
| 943 | + array( |
|
| 944 | + 'STS_ID' => array( |
|
| 945 | + 'IN', |
|
| 946 | + array( |
|
| 947 | + EEM_Registration::status_id_approved, |
|
| 948 | + EEM_Registration::status_id_pending_payment, |
|
| 949 | + EEM_Registration::status_id_not_approved, |
|
| 950 | + ) |
|
| 951 | + ) |
|
| 952 | + ) |
|
| 953 | + ); |
|
| 954 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 955 | + '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 956 | + ); |
|
| 957 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 958 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 959 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 960 | + EEH_HTML::tr( |
|
| 961 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 962 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 963 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 964 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 965 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 966 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 967 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 968 | + ) |
|
| 969 | + ); |
|
| 970 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 971 | + // get registrations for TXN |
|
| 972 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 973 | + foreach ($registrations as $registration) { |
|
| 974 | + if ($registration instanceof EE_Registration) { |
|
| 975 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 976 | + ? $registration->attendee()->full_name() |
|
| 977 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 978 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 979 | + $taxable = $registration->ticket()->taxable() |
|
| 980 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 981 | + : ''; |
|
| 982 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 983 | + ? ' checked="checked"' |
|
| 984 | + : ''; |
|
| 985 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 986 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 987 | + EEH_HTML::td($registration->ID()) . |
|
| 988 | + EEH_HTML::td($attendee_name) . |
|
| 989 | + EEH_HTML::td( |
|
| 990 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 991 | + ) . |
|
| 992 | + EEH_HTML::td($registration->event_name()) . |
|
| 993 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 994 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 995 | + EEH_HTML::td( |
|
| 996 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 997 | + . '" name="txn_admin_payment[registrations]"' |
|
| 998 | + . $checked . $disabled . '>', |
|
| 999 | + '', 'jst-cntr' |
|
| 1000 | + ), |
|
| 1001 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1002 | + ); |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1006 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1007 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1008 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1009 | + esc_html__( |
|
| 1010 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1011 | + 'event_espresso' |
|
| 1012 | + ), |
|
| 1013 | + '', 'clear description' |
|
| 1014 | + ); |
|
| 1015 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1016 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + |
|
| 1020 | + /** |
|
| 1021 | + * _get_reg_status_selection |
|
| 1022 | + * |
|
| 1023 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1024 | + * instead of events. |
|
| 1025 | + * @access protected |
|
| 1026 | + * @return void |
|
| 1027 | + */ |
|
| 1028 | + protected function _get_reg_status_selection() |
|
| 1029 | + { |
|
| 1030 | + //first get all possible statuses |
|
| 1031 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1032 | + //let's add a "don't change" option. |
|
| 1033 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1034 | + $status_array = array_merge($status_array, $statuses); |
|
| 1035 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', |
|
| 1036 | + $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); |
|
| 1037 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', |
|
| 1038 | + $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); |
|
| 1039 | + |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * _get_payment_methods |
|
| 1045 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1046 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1047 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1048 | + * @access private |
|
| 1049 | + * |
|
| 1050 | + * @param EE_Payment[] to show on this page |
|
| 1051 | + * |
|
| 1052 | + * @return void |
|
| 1053 | + */ |
|
| 1054 | + private function _get_payment_methods($payments = array()) |
|
| 1055 | + { |
|
| 1056 | + $payment_methods_of_payments = array(); |
|
| 1057 | + foreach ($payments as $payment) { |
|
| 1058 | + if ($payment instanceof EE_Payment) { |
|
| 1059 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + if ($payment_methods_of_payments) { |
|
| 1063 | + $query_args = array( |
|
| 1064 | + array( |
|
| 1065 | + 'OR*payment_method_for_payment' => array( |
|
| 1066 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1067 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1068 | + ) |
|
| 1069 | + ) |
|
| 1070 | + ); |
|
| 1071 | + } else { |
|
| 1072 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1073 | + } |
|
| 1074 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * txn_attendees_meta_box |
|
| 1080 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1081 | + * |
|
| 1082 | + * @access public |
|
| 1083 | + * |
|
| 1084 | + * @param WP_Post $post |
|
| 1085 | + * @param array $metabox |
|
| 1086 | + * |
|
| 1087 | + * @return void |
|
| 1088 | + */ |
|
| 1089 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1090 | + { |
|
| 1091 | + |
|
| 1092 | + extract($metabox['args']); |
|
| 1093 | + $this->_template_args['post'] = $post; |
|
| 1094 | + $this->_template_args['event_attendees'] = array(); |
|
| 1095 | + // process items in cart |
|
| 1096 | + $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); |
|
| 1097 | + if ( ! empty($line_items)) { |
|
| 1098 | + foreach ($line_items as $item) { |
|
| 1099 | + if ($item instanceof EE_Line_Item) { |
|
| 1100 | + switch ($item->OBJ_type()) { |
|
| 1101 | 1101 | |
| 1102 | - case 'Event' : |
|
| 1103 | - break; |
|
| 1102 | + case 'Event' : |
|
| 1103 | + break; |
|
| 1104 | 1104 | |
| 1105 | - case 'Ticket' : |
|
| 1106 | - $ticket = $item->ticket(); |
|
| 1107 | - //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
| 1108 | - if ( ! $ticket instanceof EE_Ticket) { |
|
| 1109 | - continue; |
|
| 1110 | - } |
|
| 1111 | - try { |
|
| 1112 | - $event_name = $ticket->get_event_name(); |
|
| 1113 | - } catch (Exception $e) { |
|
| 1114 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1116 | - } |
|
| 1117 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1118 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1119 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1120 | - $registrations = $ticket->get_many_related('Registration', |
|
| 1121 | - array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 1122 | - foreach ($registrations as $registration) { |
|
| 1123 | - if ( ! $registration instanceof EE_Registration) { |
|
| 1124 | - continue; |
|
| 1125 | - } |
|
| 1126 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
| 1127 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
| 1128 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 1129 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 1130 | - // attendee info |
|
| 1131 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1132 | - if ($attendee instanceof EE_Attendee) { |
|
| 1133 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
| 1134 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
| 1135 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1136 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1137 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
| 1138 | - 'inline', false, false); |
|
| 1139 | - } else { |
|
| 1140 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1141 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1142 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1143 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - break; |
|
| 1105 | + case 'Ticket' : |
|
| 1106 | + $ticket = $item->ticket(); |
|
| 1107 | + //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? |
|
| 1108 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1109 | + continue; |
|
| 1110 | + } |
|
| 1111 | + try { |
|
| 1112 | + $event_name = $ticket->get_event_name(); |
|
| 1113 | + } catch (Exception $e) { |
|
| 1114 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1115 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1116 | + } |
|
| 1117 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1118 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1119 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1120 | + $registrations = $ticket->get_many_related('Registration', |
|
| 1121 | + array(array('TXN_ID' => $this->_transaction->ID()))); |
|
| 1122 | + foreach ($registrations as $registration) { |
|
| 1123 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1124 | + continue; |
|
| 1125 | + } |
|
| 1126 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); |
|
| 1127 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); |
|
| 1128 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; |
|
| 1129 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; |
|
| 1130 | + // attendee info |
|
| 1131 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1132 | + if ($attendee instanceof EE_Attendee) { |
|
| 1133 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
|
| 1134 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
|
| 1135 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1136 | + 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1137 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
|
| 1138 | + 'inline', false, false); |
|
| 1139 | + } else { |
|
| 1140 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1141 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1142 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1143 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + break; |
|
| 1147 | 1147 | |
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | 1151 | |
| 1152 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1153 | - 'action' => 'edit_transaction', |
|
| 1154 | - 'process' => 'attendees' |
|
| 1155 | - ), TXN_ADMIN_URL); |
|
| 1156 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1157 | - $this->_template_args, true); |
|
| 1152 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1153 | + 'action' => 'edit_transaction', |
|
| 1154 | + 'process' => 'attendees' |
|
| 1155 | + ), TXN_ADMIN_URL); |
|
| 1156 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1157 | + $this->_template_args, true); |
|
| 1158 | 1158 | |
| 1159 | - } else { |
|
| 1160 | - echo sprintf( |
|
| 1161 | - esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1162 | - 'event_espresso'), |
|
| 1163 | - '<p class="important-notice">', |
|
| 1164 | - '</p>' |
|
| 1165 | - ); |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * txn_registrant_side_meta_box |
|
| 1172 | - * generates HTML for the Edit Transaction side meta box |
|
| 1173 | - * |
|
| 1174 | - * @access public |
|
| 1175 | - * @throws \EE_Error |
|
| 1176 | - * @return void |
|
| 1177 | - */ |
|
| 1178 | - public function txn_registrant_side_meta_box() |
|
| 1179 | - { |
|
| 1180 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
| 1181 | - if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1182 | - $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1183 | - 'event_espresso'); |
|
| 1184 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1185 | - } |
|
| 1186 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1187 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1188 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1189 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1190 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1191 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1192 | - 'action' => 'edit_attendee', |
|
| 1193 | - 'post' => $primary_att->ID() |
|
| 1194 | - ), REG_ADMIN_URL); |
|
| 1195 | - // get formatted address for registrant |
|
| 1196 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1197 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1198 | - $this->_template_args, true); |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - |
|
| 1202 | - /** |
|
| 1203 | - * txn_billing_info_side_meta_box |
|
| 1204 | - * generates HTML for the Edit Transaction side meta box |
|
| 1205 | - * |
|
| 1206 | - * @access public |
|
| 1207 | - * @return void |
|
| 1208 | - */ |
|
| 1209 | - public function txn_billing_info_side_meta_box() |
|
| 1210 | - { |
|
| 1211 | - |
|
| 1212 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1213 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1214 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1215 | - TXN_ADMIN_URL |
|
| 1216 | - ); |
|
| 1217 | - |
|
| 1218 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1219 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * apply_payments_or_refunds |
|
| 1225 | - * registers a payment or refund made towards a transaction |
|
| 1226 | - * |
|
| 1227 | - * @access public |
|
| 1228 | - * @return void |
|
| 1229 | - */ |
|
| 1230 | - public function apply_payments_or_refunds() |
|
| 1231 | - { |
|
| 1232 | - $json_response_data = array('return_data' => false); |
|
| 1233 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1234 | - if ( ! empty($valid_data)) { |
|
| 1235 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1236 | - //save the new payment |
|
| 1237 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1238 | - // get the TXN for this payment |
|
| 1239 | - $transaction = $payment->transaction(); |
|
| 1240 | - // verify transaction |
|
| 1241 | - if ($transaction instanceof EE_Transaction) { |
|
| 1242 | - // calculate_total_payments_and_update_status |
|
| 1243 | - $this->_process_transaction_payments($transaction); |
|
| 1244 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1245 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1246 | - // apply payment to registrations (if applicable) |
|
| 1247 | - if ( ! empty($REG_IDs)) { |
|
| 1248 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1249 | - $this->_maybe_send_notifications(); |
|
| 1250 | - // now process status changes for the same registrations |
|
| 1251 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1252 | - } |
|
| 1253 | - $this->_maybe_send_notifications($payment); |
|
| 1254 | - //prepare to render page |
|
| 1255 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1256 | - do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
| 1257 | - $payment); |
|
| 1258 | - } else { |
|
| 1259 | - EE_Error::add_error( |
|
| 1260 | - esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1261 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1262 | - ); |
|
| 1263 | - } |
|
| 1264 | - } else { |
|
| 1265 | - EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
| 1266 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1270 | - $this->_template_args = array( |
|
| 1271 | - 'data' => $json_response_data, |
|
| 1272 | - 'error' => $notices['errors'], |
|
| 1273 | - 'success' => $notices['success'] |
|
| 1274 | - ); |
|
| 1275 | - $this->_return_json(); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * _validate_payment_request_data |
|
| 1281 | - * |
|
| 1282 | - * @return array |
|
| 1283 | - */ |
|
| 1284 | - protected function _validate_payment_request_data() |
|
| 1285 | - { |
|
| 1286 | - if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1287 | - return false; |
|
| 1288 | - } |
|
| 1289 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1290 | - try { |
|
| 1291 | - if ($payment_form->was_submitted()) { |
|
| 1292 | - $payment_form->receive_form_submission(); |
|
| 1293 | - if ( ! $payment_form->is_valid()) { |
|
| 1294 | - $submission_error_messages = array(); |
|
| 1295 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1296 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1297 | - $submission_error_messages[] = sprintf( |
|
| 1298 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1299 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1300 | - $validation_error->getMessage() |
|
| 1301 | - ); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1159 | + } else { |
|
| 1160 | + echo sprintf( |
|
| 1161 | + esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1162 | + 'event_espresso'), |
|
| 1163 | + '<p class="important-notice">', |
|
| 1164 | + '</p>' |
|
| 1165 | + ); |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * txn_registrant_side_meta_box |
|
| 1172 | + * generates HTML for the Edit Transaction side meta box |
|
| 1173 | + * |
|
| 1174 | + * @access public |
|
| 1175 | + * @throws \EE_Error |
|
| 1176 | + * @return void |
|
| 1177 | + */ |
|
| 1178 | + public function txn_registrant_side_meta_box() |
|
| 1179 | + { |
|
| 1180 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; |
|
| 1181 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1182 | + $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1183 | + 'event_espresso'); |
|
| 1184 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1185 | + } |
|
| 1186 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1187 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1188 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1189 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1190 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1191 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1192 | + 'action' => 'edit_attendee', |
|
| 1193 | + 'post' => $primary_att->ID() |
|
| 1194 | + ), REG_ADMIN_URL); |
|
| 1195 | + // get formatted address for registrant |
|
| 1196 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1197 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1198 | + $this->_template_args, true); |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + |
|
| 1202 | + /** |
|
| 1203 | + * txn_billing_info_side_meta_box |
|
| 1204 | + * generates HTML for the Edit Transaction side meta box |
|
| 1205 | + * |
|
| 1206 | + * @access public |
|
| 1207 | + * @return void |
|
| 1208 | + */ |
|
| 1209 | + public function txn_billing_info_side_meta_box() |
|
| 1210 | + { |
|
| 1211 | + |
|
| 1212 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1213 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1214 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1215 | + TXN_ADMIN_URL |
|
| 1216 | + ); |
|
| 1217 | + |
|
| 1218 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1219 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * apply_payments_or_refunds |
|
| 1225 | + * registers a payment or refund made towards a transaction |
|
| 1226 | + * |
|
| 1227 | + * @access public |
|
| 1228 | + * @return void |
|
| 1229 | + */ |
|
| 1230 | + public function apply_payments_or_refunds() |
|
| 1231 | + { |
|
| 1232 | + $json_response_data = array('return_data' => false); |
|
| 1233 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1234 | + if ( ! empty($valid_data)) { |
|
| 1235 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1236 | + //save the new payment |
|
| 1237 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1238 | + // get the TXN for this payment |
|
| 1239 | + $transaction = $payment->transaction(); |
|
| 1240 | + // verify transaction |
|
| 1241 | + if ($transaction instanceof EE_Transaction) { |
|
| 1242 | + // calculate_total_payments_and_update_status |
|
| 1243 | + $this->_process_transaction_payments($transaction); |
|
| 1244 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1245 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1246 | + // apply payment to registrations (if applicable) |
|
| 1247 | + if ( ! empty($REG_IDs)) { |
|
| 1248 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1249 | + $this->_maybe_send_notifications(); |
|
| 1250 | + // now process status changes for the same registrations |
|
| 1251 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1252 | + } |
|
| 1253 | + $this->_maybe_send_notifications($payment); |
|
| 1254 | + //prepare to render page |
|
| 1255 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1256 | + do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, |
|
| 1257 | + $payment); |
|
| 1258 | + } else { |
|
| 1259 | + EE_Error::add_error( |
|
| 1260 | + esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), |
|
| 1261 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1262 | + ); |
|
| 1263 | + } |
|
| 1264 | + } else { |
|
| 1265 | + EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', |
|
| 1266 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1270 | + $this->_template_args = array( |
|
| 1271 | + 'data' => $json_response_data, |
|
| 1272 | + 'error' => $notices['errors'], |
|
| 1273 | + 'success' => $notices['success'] |
|
| 1274 | + ); |
|
| 1275 | + $this->_return_json(); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * _validate_payment_request_data |
|
| 1281 | + * |
|
| 1282 | + * @return array |
|
| 1283 | + */ |
|
| 1284 | + protected function _validate_payment_request_data() |
|
| 1285 | + { |
|
| 1286 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1287 | + return false; |
|
| 1288 | + } |
|
| 1289 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1290 | + try { |
|
| 1291 | + if ($payment_form->was_submitted()) { |
|
| 1292 | + $payment_form->receive_form_submission(); |
|
| 1293 | + if ( ! $payment_form->is_valid()) { |
|
| 1294 | + $submission_error_messages = array(); |
|
| 1295 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1296 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1297 | + $submission_error_messages[] = sprintf( |
|
| 1298 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1299 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1300 | + $validation_error->getMessage() |
|
| 1301 | + ); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
| 1305 | 1305 | |
| 1306 | - return array(); |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - } catch (EE_Error $e) { |
|
| 1310 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1306 | + return array(); |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + } catch (EE_Error $e) { |
|
| 1310 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1311 | 1311 | |
| 1312 | - return array(); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - return $payment_form->valid_data(); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * _generate_payment_form_section |
|
| 1321 | - * |
|
| 1322 | - * @return EE_Form_Section_Proper |
|
| 1323 | - */ |
|
| 1324 | - protected function _generate_payment_form_section() |
|
| 1325 | - { |
|
| 1326 | - return new EE_Form_Section_Proper( |
|
| 1327 | - array( |
|
| 1328 | - 'name' => 'txn_admin_payment', |
|
| 1329 | - 'subsections' => array( |
|
| 1330 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1331 | - array( |
|
| 1332 | - 'default' => 0, |
|
| 1333 | - 'required' => false, |
|
| 1334 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1335 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1336 | - ) |
|
| 1337 | - ), |
|
| 1338 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1339 | - array( |
|
| 1340 | - 'default' => 0, |
|
| 1341 | - 'required' => true, |
|
| 1342 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1343 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1344 | - ) |
|
| 1345 | - ), |
|
| 1346 | - 'type' => new EE_Text_Input( |
|
| 1347 | - array( |
|
| 1348 | - 'default' => 1, |
|
| 1349 | - 'required' => true, |
|
| 1350 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1351 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1352 | - ) |
|
| 1353 | - ), |
|
| 1354 | - 'amount' => new EE_Text_Input( |
|
| 1355 | - array( |
|
| 1356 | - 'default' => 0, |
|
| 1357 | - 'required' => true, |
|
| 1358 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1359 | - 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1360 | - ) |
|
| 1361 | - ), |
|
| 1362 | - 'status' => new EE_Text_Input( |
|
| 1363 | - array( |
|
| 1364 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1365 | - 'required' => true, |
|
| 1366 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1367 | - ) |
|
| 1368 | - ), |
|
| 1369 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1370 | - array( |
|
| 1371 | - 'default' => 2, |
|
| 1372 | - 'required' => true, |
|
| 1373 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1374 | - 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1375 | - ) |
|
| 1376 | - ), |
|
| 1377 | - 'date' => new EE_Text_Input( |
|
| 1378 | - array( |
|
| 1379 | - 'default' => time(), |
|
| 1380 | - 'required' => true, |
|
| 1381 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1382 | - ) |
|
| 1383 | - ), |
|
| 1384 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1385 | - array( |
|
| 1386 | - 'default' => '', |
|
| 1387 | - 'required' => false, |
|
| 1388 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1389 | - 'validation_strategies' => array( |
|
| 1390 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1391 | - 100), |
|
| 1392 | - ) |
|
| 1393 | - ) |
|
| 1394 | - ), |
|
| 1395 | - 'po_number' => new EE_Text_Input( |
|
| 1396 | - array( |
|
| 1397 | - 'default' => '', |
|
| 1398 | - 'required' => false, |
|
| 1399 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1400 | - 'validation_strategies' => array( |
|
| 1401 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1402 | - 100), |
|
| 1403 | - ) |
|
| 1404 | - ) |
|
| 1405 | - ), |
|
| 1406 | - 'accounting' => new EE_Text_Input( |
|
| 1407 | - array( |
|
| 1408 | - 'default' => '', |
|
| 1409 | - 'required' => false, |
|
| 1410 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1411 | - 'validation_strategies' => array( |
|
| 1412 | - new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1413 | - 100), |
|
| 1414 | - ) |
|
| 1415 | - ) |
|
| 1416 | - ), |
|
| 1417 | - ) |
|
| 1418 | - ) |
|
| 1419 | - ); |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - |
|
| 1423 | - /** |
|
| 1424 | - * _create_payment_from_request_data |
|
| 1425 | - * |
|
| 1426 | - * @param array $valid_data |
|
| 1427 | - * |
|
| 1428 | - * @return EE_Payment |
|
| 1429 | - */ |
|
| 1430 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1431 | - { |
|
| 1432 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1433 | - // get payment amount |
|
| 1434 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1435 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1436 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1437 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1438 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1439 | - $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
| 1440 | - current_time('timestamp')); |
|
| 1441 | - $payment = EE_Payment::new_instance( |
|
| 1442 | - array( |
|
| 1443 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1444 | - 'STS_ID' => $valid_data['status'], |
|
| 1445 | - 'PAY_timestamp' => $date, |
|
| 1446 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1447 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1448 | - 'PAY_amount' => $amount, |
|
| 1449 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1450 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1451 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1452 | - 'PAY_details' => $valid_data, |
|
| 1453 | - 'PAY_ID' => $PAY_ID |
|
| 1454 | - ), |
|
| 1455 | - '', |
|
| 1456 | - array('Y-m-d', 'g:i a') |
|
| 1457 | - ); |
|
| 1458 | - |
|
| 1459 | - if ( ! $payment->save()) { |
|
| 1460 | - EE_Error::add_error( |
|
| 1461 | - sprintf( |
|
| 1462 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1463 | - $payment->ID() |
|
| 1464 | - ), |
|
| 1465 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1466 | - ); |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - return $payment; |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * _process_transaction_payments |
|
| 1475 | - * |
|
| 1476 | - * @param \EE_Transaction $transaction |
|
| 1477 | - * |
|
| 1478 | - * @return array |
|
| 1479 | - */ |
|
| 1480 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1481 | - { |
|
| 1482 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1483 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1484 | - //update the transaction with this payment |
|
| 1485 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1486 | - EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
| 1487 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1488 | - } else { |
|
| 1489 | - EE_Error::add_error( |
|
| 1490 | - esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1491 | - 'event_espresso') |
|
| 1492 | - , __FILE__, __FUNCTION__, __LINE__ |
|
| 1493 | - ); |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1500 | - * |
|
| 1501 | - * returns a list of registration IDs that the payment will apply to |
|
| 1502 | - * |
|
| 1503 | - * @param \EE_Payment $payment |
|
| 1504 | - * |
|
| 1505 | - * @return array |
|
| 1506 | - */ |
|
| 1507 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1508 | - { |
|
| 1509 | - $REG_IDs = array(); |
|
| 1510 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1511 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1512 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1513 | - } |
|
| 1514 | - //nothing specified ? then get all reg IDs |
|
| 1515 | - if (empty($REG_IDs)) { |
|
| 1516 | - $registrations = $payment->transaction()->registrations(); |
|
| 1517 | - $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1521 | - return array_map('intval', $REG_IDs); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - |
|
| 1525 | - /** |
|
| 1526 | - * @return array |
|
| 1527 | - */ |
|
| 1528 | - public function existing_reg_payment_REG_IDs() |
|
| 1529 | - { |
|
| 1530 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1531 | - } |
|
| 1532 | - |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1536 | - */ |
|
| 1537 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1538 | - { |
|
| 1539 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - /** |
|
| 1544 | - * _get_existing_reg_payment_REG_IDs |
|
| 1545 | - * |
|
| 1546 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1547 | - * as recorded in the database |
|
| 1548 | - * |
|
| 1549 | - * @param \EE_Payment $payment |
|
| 1550 | - * |
|
| 1551 | - * @return array |
|
| 1552 | - */ |
|
| 1553 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1554 | - { |
|
| 1555 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1556 | - // let's get any existing reg payment records for this payment |
|
| 1557 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1558 | - // but we only want the REG IDs, so grab the array keys |
|
| 1559 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1560 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 1564 | - } |
|
| 1565 | - |
|
| 1566 | - |
|
| 1567 | - /** |
|
| 1568 | - * _remove_existing_registration_payments |
|
| 1569 | - * |
|
| 1570 | - * this calculates the difference between existing relations |
|
| 1571 | - * to the supplied payment and the new list registration IDs, |
|
| 1572 | - * removes any related registrations that no longer apply, |
|
| 1573 | - * and then updates the registration paid fields |
|
| 1574 | - * |
|
| 1575 | - * @param \EE_Payment $payment |
|
| 1576 | - * @param int $PAY_ID |
|
| 1577 | - * |
|
| 1578 | - * @return bool; |
|
| 1579 | - */ |
|
| 1580 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1581 | - { |
|
| 1582 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 1583 | - if ($PAY_ID == 0) { |
|
| 1584 | - return false; |
|
| 1585 | - } |
|
| 1586 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1587 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1588 | - return false; |
|
| 1589 | - } |
|
| 1590 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1591 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1592 | - |
|
| 1593 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1594 | - $payment, |
|
| 1595 | - array( |
|
| 1596 | - array( |
|
| 1597 | - 'PAY_ID' => $payment->ID(), |
|
| 1598 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1599 | - ) |
|
| 1600 | - ) |
|
| 1601 | - ); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - |
|
| 1605 | - /** |
|
| 1606 | - * _update_registration_payments |
|
| 1607 | - * |
|
| 1608 | - * this applies the payments to the selected registrations |
|
| 1609 | - * but only if they have not already been paid for |
|
| 1610 | - * |
|
| 1611 | - * @param EE_Transaction $transaction |
|
| 1612 | - * @param \EE_Payment $payment |
|
| 1613 | - * @param array $REG_IDs |
|
| 1614 | - * |
|
| 1615 | - * @return bool |
|
| 1616 | - */ |
|
| 1617 | - protected function _update_registration_payments( |
|
| 1618 | - EE_Transaction $transaction, |
|
| 1619 | - EE_Payment $payment, |
|
| 1620 | - $REG_IDs = array() |
|
| 1621 | - ) { |
|
| 1622 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1623 | - // so let's do that using our set of REG_IDs from the form |
|
| 1624 | - $registration_query_where_params = array( |
|
| 1625 | - 'REG_ID' => array('IN', $REG_IDs) |
|
| 1626 | - ); |
|
| 1627 | - // but add in some conditions regarding payment, |
|
| 1628 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1629 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1630 | - if ( ! $payment->is_a_refund()) { |
|
| 1631 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1632 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1633 | - } |
|
| 1634 | - //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
| 1635 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1636 | - if ( ! empty($registrations)) { |
|
| 1637 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 1638 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1639 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1640 | - } |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * _process_registration_status_change |
|
| 1646 | - * |
|
| 1647 | - * This processes requested registration status changes for all the registrations |
|
| 1648 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1649 | - * |
|
| 1650 | - * @param EE_Transaction $transaction |
|
| 1651 | - * @param array $REG_IDs |
|
| 1652 | - * |
|
| 1653 | - * @return bool |
|
| 1654 | - */ |
|
| 1655 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1656 | - { |
|
| 1657 | - // first if there is no change in status then we get out. |
|
| 1658 | - if ( |
|
| 1659 | - ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1660 | - || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
| 1661 | - ) { |
|
| 1662 | - //no error message, no change requested, just nothing to do man. |
|
| 1663 | - return false; |
|
| 1664 | - } |
|
| 1665 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1666 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1667 | - |
|
| 1668 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1669 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 1670 | - $transaction, |
|
| 1671 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1672 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1673 | - ); |
|
| 1674 | - } |
|
| 1675 | - |
|
| 1676 | - |
|
| 1677 | - /** |
|
| 1678 | - * _build_payment_json_response |
|
| 1679 | - * |
|
| 1680 | - * @access public |
|
| 1681 | - * |
|
| 1682 | - * @param \EE_Payment $payment |
|
| 1683 | - * @param array $REG_IDs |
|
| 1684 | - * @param bool | null $delete_txn_reg_status_change |
|
| 1685 | - * |
|
| 1686 | - * @return array |
|
| 1687 | - */ |
|
| 1688 | - protected function _build_payment_json_response( |
|
| 1689 | - EE_Payment $payment, |
|
| 1690 | - $REG_IDs = array(), |
|
| 1691 | - $delete_txn_reg_status_change = null |
|
| 1692 | - ) { |
|
| 1693 | - // was the payment deleted ? |
|
| 1694 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 1695 | - return array( |
|
| 1696 | - 'PAY_ID' => $payment->ID(), |
|
| 1697 | - 'amount' => $payment->amount(), |
|
| 1698 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 1699 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1700 | - 'pay_status' => $payment->STS_ID(), |
|
| 1701 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1702 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 1703 | - ); |
|
| 1704 | - } else { |
|
| 1705 | - $this->_get_payment_status_array(); |
|
| 1312 | + return array(); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + return $payment_form->valid_data(); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * _generate_payment_form_section |
|
| 1321 | + * |
|
| 1322 | + * @return EE_Form_Section_Proper |
|
| 1323 | + */ |
|
| 1324 | + protected function _generate_payment_form_section() |
|
| 1325 | + { |
|
| 1326 | + return new EE_Form_Section_Proper( |
|
| 1327 | + array( |
|
| 1328 | + 'name' => 'txn_admin_payment', |
|
| 1329 | + 'subsections' => array( |
|
| 1330 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1331 | + array( |
|
| 1332 | + 'default' => 0, |
|
| 1333 | + 'required' => false, |
|
| 1334 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1335 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1336 | + ) |
|
| 1337 | + ), |
|
| 1338 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1339 | + array( |
|
| 1340 | + 'default' => 0, |
|
| 1341 | + 'required' => true, |
|
| 1342 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1343 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1344 | + ) |
|
| 1345 | + ), |
|
| 1346 | + 'type' => new EE_Text_Input( |
|
| 1347 | + array( |
|
| 1348 | + 'default' => 1, |
|
| 1349 | + 'required' => true, |
|
| 1350 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1351 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1352 | + ) |
|
| 1353 | + ), |
|
| 1354 | + 'amount' => new EE_Text_Input( |
|
| 1355 | + array( |
|
| 1356 | + 'default' => 0, |
|
| 1357 | + 'required' => true, |
|
| 1358 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1359 | + 'validation_strategies' => array(new EE_Float_Normalization()) |
|
| 1360 | + ) |
|
| 1361 | + ), |
|
| 1362 | + 'status' => new EE_Text_Input( |
|
| 1363 | + array( |
|
| 1364 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1365 | + 'required' => true, |
|
| 1366 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1367 | + ) |
|
| 1368 | + ), |
|
| 1369 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1370 | + array( |
|
| 1371 | + 'default' => 2, |
|
| 1372 | + 'required' => true, |
|
| 1373 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1374 | + 'validation_strategies' => array(new EE_Int_Normalization()) |
|
| 1375 | + ) |
|
| 1376 | + ), |
|
| 1377 | + 'date' => new EE_Text_Input( |
|
| 1378 | + array( |
|
| 1379 | + 'default' => time(), |
|
| 1380 | + 'required' => true, |
|
| 1381 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1382 | + ) |
|
| 1383 | + ), |
|
| 1384 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1385 | + array( |
|
| 1386 | + 'default' => '', |
|
| 1387 | + 'required' => false, |
|
| 1388 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1389 | + 'validation_strategies' => array( |
|
| 1390 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1391 | + 100), |
|
| 1392 | + ) |
|
| 1393 | + ) |
|
| 1394 | + ), |
|
| 1395 | + 'po_number' => new EE_Text_Input( |
|
| 1396 | + array( |
|
| 1397 | + 'default' => '', |
|
| 1398 | + 'required' => false, |
|
| 1399 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1400 | + 'validation_strategies' => array( |
|
| 1401 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1402 | + 100), |
|
| 1403 | + ) |
|
| 1404 | + ) |
|
| 1405 | + ), |
|
| 1406 | + 'accounting' => new EE_Text_Input( |
|
| 1407 | + array( |
|
| 1408 | + 'default' => '', |
|
| 1409 | + 'required' => false, |
|
| 1410 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1411 | + 'validation_strategies' => array( |
|
| 1412 | + new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), |
|
| 1413 | + 100), |
|
| 1414 | + ) |
|
| 1415 | + ) |
|
| 1416 | + ), |
|
| 1417 | + ) |
|
| 1418 | + ) |
|
| 1419 | + ); |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + |
|
| 1423 | + /** |
|
| 1424 | + * _create_payment_from_request_data |
|
| 1425 | + * |
|
| 1426 | + * @param array $valid_data |
|
| 1427 | + * |
|
| 1428 | + * @return EE_Payment |
|
| 1429 | + */ |
|
| 1430 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1431 | + { |
|
| 1432 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1433 | + // get payment amount |
|
| 1434 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1435 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1436 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1437 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1438 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1439 | + $date = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', |
|
| 1440 | + current_time('timestamp')); |
|
| 1441 | + $payment = EE_Payment::new_instance( |
|
| 1442 | + array( |
|
| 1443 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1444 | + 'STS_ID' => $valid_data['status'], |
|
| 1445 | + 'PAY_timestamp' => $date, |
|
| 1446 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1447 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1448 | + 'PAY_amount' => $amount, |
|
| 1449 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1450 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1451 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1452 | + 'PAY_details' => $valid_data, |
|
| 1453 | + 'PAY_ID' => $PAY_ID |
|
| 1454 | + ), |
|
| 1455 | + '', |
|
| 1456 | + array('Y-m-d', 'g:i a') |
|
| 1457 | + ); |
|
| 1458 | + |
|
| 1459 | + if ( ! $payment->save()) { |
|
| 1460 | + EE_Error::add_error( |
|
| 1461 | + sprintf( |
|
| 1462 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1463 | + $payment->ID() |
|
| 1464 | + ), |
|
| 1465 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1466 | + ); |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + return $payment; |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * _process_transaction_payments |
|
| 1475 | + * |
|
| 1476 | + * @param \EE_Transaction $transaction |
|
| 1477 | + * |
|
| 1478 | + * @return array |
|
| 1479 | + */ |
|
| 1480 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1481 | + { |
|
| 1482 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1483 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1484 | + //update the transaction with this payment |
|
| 1485 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1486 | + EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), |
|
| 1487 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1488 | + } else { |
|
| 1489 | + EE_Error::add_error( |
|
| 1490 | + esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1491 | + 'event_espresso') |
|
| 1492 | + , __FILE__, __FUNCTION__, __LINE__ |
|
| 1493 | + ); |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1500 | + * |
|
| 1501 | + * returns a list of registration IDs that the payment will apply to |
|
| 1502 | + * |
|
| 1503 | + * @param \EE_Payment $payment |
|
| 1504 | + * |
|
| 1505 | + * @return array |
|
| 1506 | + */ |
|
| 1507 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1508 | + { |
|
| 1509 | + $REG_IDs = array(); |
|
| 1510 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1511 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1512 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1513 | + } |
|
| 1514 | + //nothing specified ? then get all reg IDs |
|
| 1515 | + if (empty($REG_IDs)) { |
|
| 1516 | + $registrations = $payment->transaction()->registrations(); |
|
| 1517 | + $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1521 | + return array_map('intval', $REG_IDs); |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + |
|
| 1525 | + /** |
|
| 1526 | + * @return array |
|
| 1527 | + */ |
|
| 1528 | + public function existing_reg_payment_REG_IDs() |
|
| 1529 | + { |
|
| 1530 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1531 | + } |
|
| 1532 | + |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1536 | + */ |
|
| 1537 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1538 | + { |
|
| 1539 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + |
|
| 1543 | + /** |
|
| 1544 | + * _get_existing_reg_payment_REG_IDs |
|
| 1545 | + * |
|
| 1546 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1547 | + * as recorded in the database |
|
| 1548 | + * |
|
| 1549 | + * @param \EE_Payment $payment |
|
| 1550 | + * |
|
| 1551 | + * @return array |
|
| 1552 | + */ |
|
| 1553 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1554 | + { |
|
| 1555 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1556 | + // let's get any existing reg payment records for this payment |
|
| 1557 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1558 | + // but we only want the REG IDs, so grab the array keys |
|
| 1559 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); |
|
| 1560 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 1564 | + } |
|
| 1565 | + |
|
| 1566 | + |
|
| 1567 | + /** |
|
| 1568 | + * _remove_existing_registration_payments |
|
| 1569 | + * |
|
| 1570 | + * this calculates the difference between existing relations |
|
| 1571 | + * to the supplied payment and the new list registration IDs, |
|
| 1572 | + * removes any related registrations that no longer apply, |
|
| 1573 | + * and then updates the registration paid fields |
|
| 1574 | + * |
|
| 1575 | + * @param \EE_Payment $payment |
|
| 1576 | + * @param int $PAY_ID |
|
| 1577 | + * |
|
| 1578 | + * @return bool; |
|
| 1579 | + */ |
|
| 1580 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1581 | + { |
|
| 1582 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 1583 | + if ($PAY_ID == 0) { |
|
| 1584 | + return false; |
|
| 1585 | + } |
|
| 1586 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1587 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1588 | + return false; |
|
| 1589 | + } |
|
| 1590 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1591 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1592 | + |
|
| 1593 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1594 | + $payment, |
|
| 1595 | + array( |
|
| 1596 | + array( |
|
| 1597 | + 'PAY_ID' => $payment->ID(), |
|
| 1598 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1599 | + ) |
|
| 1600 | + ) |
|
| 1601 | + ); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + |
|
| 1605 | + /** |
|
| 1606 | + * _update_registration_payments |
|
| 1607 | + * |
|
| 1608 | + * this applies the payments to the selected registrations |
|
| 1609 | + * but only if they have not already been paid for |
|
| 1610 | + * |
|
| 1611 | + * @param EE_Transaction $transaction |
|
| 1612 | + * @param \EE_Payment $payment |
|
| 1613 | + * @param array $REG_IDs |
|
| 1614 | + * |
|
| 1615 | + * @return bool |
|
| 1616 | + */ |
|
| 1617 | + protected function _update_registration_payments( |
|
| 1618 | + EE_Transaction $transaction, |
|
| 1619 | + EE_Payment $payment, |
|
| 1620 | + $REG_IDs = array() |
|
| 1621 | + ) { |
|
| 1622 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1623 | + // so let's do that using our set of REG_IDs from the form |
|
| 1624 | + $registration_query_where_params = array( |
|
| 1625 | + 'REG_ID' => array('IN', $REG_IDs) |
|
| 1626 | + ); |
|
| 1627 | + // but add in some conditions regarding payment, |
|
| 1628 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1629 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1630 | + if ( ! $payment->is_a_refund()) { |
|
| 1631 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1632 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1633 | + } |
|
| 1634 | + //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); |
|
| 1635 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1636 | + if ( ! empty($registrations)) { |
|
| 1637 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 1638 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1639 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1640 | + } |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * _process_registration_status_change |
|
| 1646 | + * |
|
| 1647 | + * This processes requested registration status changes for all the registrations |
|
| 1648 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1649 | + * |
|
| 1650 | + * @param EE_Transaction $transaction |
|
| 1651 | + * @param array $REG_IDs |
|
| 1652 | + * |
|
| 1653 | + * @return bool |
|
| 1654 | + */ |
|
| 1655 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1656 | + { |
|
| 1657 | + // first if there is no change in status then we get out. |
|
| 1658 | + if ( |
|
| 1659 | + ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1660 | + || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' |
|
| 1661 | + ) { |
|
| 1662 | + //no error message, no change requested, just nothing to do man. |
|
| 1663 | + return false; |
|
| 1664 | + } |
|
| 1665 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1666 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1667 | + |
|
| 1668 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1669 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 1670 | + $transaction, |
|
| 1671 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1672 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1673 | + ); |
|
| 1674 | + } |
|
| 1675 | + |
|
| 1676 | + |
|
| 1677 | + /** |
|
| 1678 | + * _build_payment_json_response |
|
| 1679 | + * |
|
| 1680 | + * @access public |
|
| 1681 | + * |
|
| 1682 | + * @param \EE_Payment $payment |
|
| 1683 | + * @param array $REG_IDs |
|
| 1684 | + * @param bool | null $delete_txn_reg_status_change |
|
| 1685 | + * |
|
| 1686 | + * @return array |
|
| 1687 | + */ |
|
| 1688 | + protected function _build_payment_json_response( |
|
| 1689 | + EE_Payment $payment, |
|
| 1690 | + $REG_IDs = array(), |
|
| 1691 | + $delete_txn_reg_status_change = null |
|
| 1692 | + ) { |
|
| 1693 | + // was the payment deleted ? |
|
| 1694 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 1695 | + return array( |
|
| 1696 | + 'PAY_ID' => $payment->ID(), |
|
| 1697 | + 'amount' => $payment->amount(), |
|
| 1698 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 1699 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1700 | + 'pay_status' => $payment->STS_ID(), |
|
| 1701 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1702 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 1703 | + ); |
|
| 1704 | + } else { |
|
| 1705 | + $this->_get_payment_status_array(); |
|
| 1706 | 1706 | |
| 1707 | - return array( |
|
| 1708 | - 'amount' => $payment->amount(), |
|
| 1709 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 1710 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1711 | - 'pay_status' => $payment->STS_ID(), |
|
| 1712 | - 'PAY_ID' => $payment->ID(), |
|
| 1713 | - 'STS_ID' => $payment->STS_ID(), |
|
| 1714 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1715 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1716 | - 'method' => strtoupper($payment->source()), |
|
| 1717 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 1718 | - 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
| 1719 | - 'event_espresso'), |
|
| 1720 | - 'gateway_response' => $payment->gateway_response(), |
|
| 1721 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 1722 | - 'po_number' => $payment->po_number(), |
|
| 1723 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 1724 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1725 | - ); |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * delete_payment |
|
| 1732 | - * delete a payment or refund made towards a transaction |
|
| 1733 | - * |
|
| 1734 | - * @access public |
|
| 1735 | - * @return void |
|
| 1736 | - */ |
|
| 1737 | - public function delete_payment() |
|
| 1738 | - { |
|
| 1739 | - $json_response_data = array('return_data' => false); |
|
| 1740 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1741 | - if ($PAY_ID) { |
|
| 1742 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1743 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1744 | - if ($payment instanceof EE_Payment) { |
|
| 1745 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1746 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1747 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1748 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1749 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
| 1750 | - $delete_txn_reg_status_change); |
|
| 1751 | - if ($delete_txn_reg_status_change) { |
|
| 1752 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1753 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 1754 | - //$_REQUEST global because that's how messages will be looking for it. |
|
| 1755 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1756 | - $this->_maybe_send_notifications(); |
|
| 1757 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1758 | - } |
|
| 1759 | - } |
|
| 1760 | - } else { |
|
| 1761 | - EE_Error::add_error( |
|
| 1762 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1763 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1764 | - ); |
|
| 1765 | - } |
|
| 1766 | - } else { |
|
| 1767 | - EE_Error::add_error( |
|
| 1768 | - esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 1769 | - 'event_espresso'), |
|
| 1770 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1771 | - ); |
|
| 1772 | - } |
|
| 1773 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 1774 | - $this->_template_args = array( |
|
| 1775 | - 'data' => $json_response_data, |
|
| 1776 | - 'success' => $notices['success'], |
|
| 1777 | - 'error' => $notices['errors'], |
|
| 1778 | - 'attention' => $notices['attention'] |
|
| 1779 | - ); |
|
| 1780 | - $this->_return_json(); |
|
| 1781 | - } |
|
| 1782 | - |
|
| 1783 | - |
|
| 1784 | - /** |
|
| 1785 | - * _registration_payment_data_array |
|
| 1786 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 1787 | - * |
|
| 1788 | - * @access protected |
|
| 1789 | - * |
|
| 1790 | - * @param array $REG_IDs |
|
| 1791 | - * |
|
| 1792 | - * @return array |
|
| 1793 | - */ |
|
| 1794 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 1795 | - { |
|
| 1796 | - $registration_payment_data = array(); |
|
| 1797 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 1798 | - if ( ! empty($REG_IDs)) { |
|
| 1799 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1800 | - foreach ($registrations as $registration) { |
|
| 1801 | - if ($registration instanceof EE_Registration) { |
|
| 1802 | - $registration_payment_data[$registration->ID()] = array( |
|
| 1803 | - 'paid' => $registration->pretty_paid(), |
|
| 1804 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1805 | - ); |
|
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - return $registration_payment_data; |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - |
|
| 1814 | - /** |
|
| 1815 | - * _maybe_send_notifications |
|
| 1816 | - * |
|
| 1817 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 1818 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 1819 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 1820 | - * |
|
| 1821 | - * @access protected |
|
| 1822 | - * |
|
| 1823 | - * @param \EE_Payment | null $payment |
|
| 1824 | - */ |
|
| 1825 | - protected function _maybe_send_notifications($payment = null) |
|
| 1826 | - { |
|
| 1827 | - switch ($payment instanceof EE_Payment) { |
|
| 1828 | - // payment notifications |
|
| 1829 | - case true : |
|
| 1830 | - if ( |
|
| 1831 | - isset( |
|
| 1832 | - $this->_req_data['txn_payments'], |
|
| 1833 | - $this->_req_data['txn_payments']['send_notifications'] |
|
| 1834 | - ) && |
|
| 1835 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1836 | - ) { |
|
| 1837 | - $this->_process_payment_notification($payment); |
|
| 1838 | - } |
|
| 1839 | - break; |
|
| 1840 | - // registration notifications |
|
| 1841 | - case false : |
|
| 1842 | - if ( |
|
| 1843 | - isset( |
|
| 1844 | - $this->_req_data['txn_reg_status_change'], |
|
| 1845 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1846 | - ) && |
|
| 1847 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1848 | - ) { |
|
| 1849 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1850 | - } |
|
| 1851 | - break; |
|
| 1852 | - } |
|
| 1853 | - } |
|
| 1854 | - |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * _send_payment_reminder |
|
| 1858 | - * generates HTML for the View Transaction Details Admin page |
|
| 1859 | - * |
|
| 1860 | - * @access protected |
|
| 1861 | - * @return void |
|
| 1862 | - */ |
|
| 1863 | - protected function _send_payment_reminder() |
|
| 1864 | - { |
|
| 1865 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 1866 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1867 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 1868 | - 'action' => $this->_req_data['redirect_to'], |
|
| 1869 | - 'TXN_ID' => $this->_req_data['TXN_ID'] |
|
| 1870 | - ) : array(); |
|
| 1871 | - do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 1872 | - $transaction); |
|
| 1873 | - $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
| 1874 | - esc_html__('sent', 'event_espresso'), $query_args, true); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * get_transactions |
|
| 1880 | - * get transactions for given parameters (used by list table) |
|
| 1881 | - * |
|
| 1882 | - * @param int $perpage how many transactions displayed per page |
|
| 1883 | - * @param boolean $count return the count or objects |
|
| 1884 | - * @param string $view |
|
| 1885 | - * |
|
| 1886 | - * @return mixed int = count || array of transaction objects |
|
| 1887 | - */ |
|
| 1888 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 1889 | - { |
|
| 1890 | - |
|
| 1891 | - $TXN = EEM_Transaction::instance(); |
|
| 1892 | - |
|
| 1893 | - $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
| 1894 | - strtotime('-10 year')); |
|
| 1895 | - $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1896 | - |
|
| 1897 | - //make sure our timestamps start and end right at the boundaries for each day |
|
| 1898 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1899 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - //convert to timestamps |
|
| 1903 | - $start_date = strtotime($start_date); |
|
| 1904 | - $end_date = strtotime($end_date); |
|
| 1905 | - |
|
| 1906 | - //makes sure start date is the lowest value and vice versa |
|
| 1907 | - $start_date = min($start_date, $end_date); |
|
| 1908 | - $end_date = max($start_date, $end_date); |
|
| 1909 | - |
|
| 1910 | - //convert to correct format for query |
|
| 1911 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1912 | - date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1913 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1914 | - date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1915 | - |
|
| 1916 | - |
|
| 1917 | - //set orderby |
|
| 1918 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 1919 | - |
|
| 1920 | - switch ($this->_req_data['orderby']) { |
|
| 1921 | - case 'TXN_ID': |
|
| 1922 | - $orderby = 'TXN_ID'; |
|
| 1923 | - break; |
|
| 1924 | - case 'ATT_fname': |
|
| 1925 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 1926 | - break; |
|
| 1927 | - case 'event_name': |
|
| 1928 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 1929 | - break; |
|
| 1930 | - default: //'TXN_timestamp' |
|
| 1931 | - $orderby = 'TXN_timestamp'; |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1935 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1936 | - $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1937 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1938 | - |
|
| 1939 | - $offset = ($current_page - 1) * $per_page; |
|
| 1940 | - $limit = array($offset, $per_page); |
|
| 1941 | - |
|
| 1942 | - $_where = array( |
|
| 1943 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1944 | - 'Registration.REG_count' => 1 |
|
| 1945 | - ); |
|
| 1946 | - |
|
| 1947 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 1948 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 1949 | - } |
|
| 1950 | - |
|
| 1951 | - if (isset($this->_req_data['s'])) { |
|
| 1952 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1953 | - $_where['OR'] = array( |
|
| 1954 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1955 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1956 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1957 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1958 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1959 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1960 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1961 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1962 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1963 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1964 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1965 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1966 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1967 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1968 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1969 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1970 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1971 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1972 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1973 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1974 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1975 | - ); |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - //failed transactions |
|
| 1979 | - $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
| 1980 | - $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
| 1981 | - |
|
| 1982 | - if ($failed) { |
|
| 1983 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1984 | - } else if ($abandoned) { |
|
| 1985 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 1986 | - } else { |
|
| 1987 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1988 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); |
|
| 1992 | - |
|
| 1993 | - $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
| 1994 | - |
|
| 1995 | - |
|
| 1996 | - return $transactions; |
|
| 1997 | - |
|
| 1998 | - } |
|
| 1707 | + return array( |
|
| 1708 | + 'amount' => $payment->amount(), |
|
| 1709 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 1710 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 1711 | + 'pay_status' => $payment->STS_ID(), |
|
| 1712 | + 'PAY_ID' => $payment->ID(), |
|
| 1713 | + 'STS_ID' => $payment->STS_ID(), |
|
| 1714 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 1715 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 1716 | + 'method' => strtoupper($payment->source()), |
|
| 1717 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 1718 | + 'gateway' => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
|
| 1719 | + 'event_espresso'), |
|
| 1720 | + 'gateway_response' => $payment->gateway_response(), |
|
| 1721 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 1722 | + 'po_number' => $payment->po_number(), |
|
| 1723 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 1724 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 1725 | + ); |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * delete_payment |
|
| 1732 | + * delete a payment or refund made towards a transaction |
|
| 1733 | + * |
|
| 1734 | + * @access public |
|
| 1735 | + * @return void |
|
| 1736 | + */ |
|
| 1737 | + public function delete_payment() |
|
| 1738 | + { |
|
| 1739 | + $json_response_data = array('return_data' => false); |
|
| 1740 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; |
|
| 1741 | + if ($PAY_ID) { |
|
| 1742 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; |
|
| 1743 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 1744 | + if ($payment instanceof EE_Payment) { |
|
| 1745 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1746 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1747 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1748 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 1749 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, |
|
| 1750 | + $delete_txn_reg_status_change); |
|
| 1751 | + if ($delete_txn_reg_status_change) { |
|
| 1752 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1753 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 1754 | + //$_REQUEST global because that's how messages will be looking for it. |
|
| 1755 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 1756 | + $this->_maybe_send_notifications(); |
|
| 1757 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 1758 | + } |
|
| 1759 | + } |
|
| 1760 | + } else { |
|
| 1761 | + EE_Error::add_error( |
|
| 1762 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 1763 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1764 | + ); |
|
| 1765 | + } |
|
| 1766 | + } else { |
|
| 1767 | + EE_Error::add_error( |
|
| 1768 | + esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 1769 | + 'event_espresso'), |
|
| 1770 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1771 | + ); |
|
| 1772 | + } |
|
| 1773 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 1774 | + $this->_template_args = array( |
|
| 1775 | + 'data' => $json_response_data, |
|
| 1776 | + 'success' => $notices['success'], |
|
| 1777 | + 'error' => $notices['errors'], |
|
| 1778 | + 'attention' => $notices['attention'] |
|
| 1779 | + ); |
|
| 1780 | + $this->_return_json(); |
|
| 1781 | + } |
|
| 1782 | + |
|
| 1783 | + |
|
| 1784 | + /** |
|
| 1785 | + * _registration_payment_data_array |
|
| 1786 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 1787 | + * |
|
| 1788 | + * @access protected |
|
| 1789 | + * |
|
| 1790 | + * @param array $REG_IDs |
|
| 1791 | + * |
|
| 1792 | + * @return array |
|
| 1793 | + */ |
|
| 1794 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 1795 | + { |
|
| 1796 | + $registration_payment_data = array(); |
|
| 1797 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 1798 | + if ( ! empty($REG_IDs)) { |
|
| 1799 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 1800 | + foreach ($registrations as $registration) { |
|
| 1801 | + if ($registration instanceof EE_Registration) { |
|
| 1802 | + $registration_payment_data[$registration->ID()] = array( |
|
| 1803 | + 'paid' => $registration->pretty_paid(), |
|
| 1804 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 1805 | + ); |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + return $registration_payment_data; |
|
| 1811 | + } |
|
| 1812 | + |
|
| 1813 | + |
|
| 1814 | + /** |
|
| 1815 | + * _maybe_send_notifications |
|
| 1816 | + * |
|
| 1817 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 1818 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 1819 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 1820 | + * |
|
| 1821 | + * @access protected |
|
| 1822 | + * |
|
| 1823 | + * @param \EE_Payment | null $payment |
|
| 1824 | + */ |
|
| 1825 | + protected function _maybe_send_notifications($payment = null) |
|
| 1826 | + { |
|
| 1827 | + switch ($payment instanceof EE_Payment) { |
|
| 1828 | + // payment notifications |
|
| 1829 | + case true : |
|
| 1830 | + if ( |
|
| 1831 | + isset( |
|
| 1832 | + $this->_req_data['txn_payments'], |
|
| 1833 | + $this->_req_data['txn_payments']['send_notifications'] |
|
| 1834 | + ) && |
|
| 1835 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1836 | + ) { |
|
| 1837 | + $this->_process_payment_notification($payment); |
|
| 1838 | + } |
|
| 1839 | + break; |
|
| 1840 | + // registration notifications |
|
| 1841 | + case false : |
|
| 1842 | + if ( |
|
| 1843 | + isset( |
|
| 1844 | + $this->_req_data['txn_reg_status_change'], |
|
| 1845 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 1846 | + ) && |
|
| 1847 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 1848 | + ) { |
|
| 1849 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 1850 | + } |
|
| 1851 | + break; |
|
| 1852 | + } |
|
| 1853 | + } |
|
| 1854 | + |
|
| 1855 | + |
|
| 1856 | + /** |
|
| 1857 | + * _send_payment_reminder |
|
| 1858 | + * generates HTML for the View Transaction Details Admin page |
|
| 1859 | + * |
|
| 1860 | + * @access protected |
|
| 1861 | + * @return void |
|
| 1862 | + */ |
|
| 1863 | + protected function _send_payment_reminder() |
|
| 1864 | + { |
|
| 1865 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 1866 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 1867 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 1868 | + 'action' => $this->_req_data['redirect_to'], |
|
| 1869 | + 'TXN_ID' => $this->_req_data['TXN_ID'] |
|
| 1870 | + ) : array(); |
|
| 1871 | + do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 1872 | + $transaction); |
|
| 1873 | + $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), |
|
| 1874 | + esc_html__('sent', 'event_espresso'), $query_args, true); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * get_transactions |
|
| 1880 | + * get transactions for given parameters (used by list table) |
|
| 1881 | + * |
|
| 1882 | + * @param int $perpage how many transactions displayed per page |
|
| 1883 | + * @param boolean $count return the count or objects |
|
| 1884 | + * @param string $view |
|
| 1885 | + * |
|
| 1886 | + * @return mixed int = count || array of transaction objects |
|
| 1887 | + */ |
|
| 1888 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 1889 | + { |
|
| 1890 | + |
|
| 1891 | + $TXN = EEM_Transaction::instance(); |
|
| 1892 | + |
|
| 1893 | + $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', |
|
| 1894 | + strtotime('-10 year')); |
|
| 1895 | + $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
|
| 1896 | + |
|
| 1897 | + //make sure our timestamps start and end right at the boundaries for each day |
|
| 1898 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1899 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + //convert to timestamps |
|
| 1903 | + $start_date = strtotime($start_date); |
|
| 1904 | + $end_date = strtotime($end_date); |
|
| 1905 | + |
|
| 1906 | + //makes sure start date is the lowest value and vice versa |
|
| 1907 | + $start_date = min($start_date, $end_date); |
|
| 1908 | + $end_date = max($start_date, $end_date); |
|
| 1909 | + |
|
| 1910 | + //convert to correct format for query |
|
| 1911 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1912 | + date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 1913 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', |
|
| 1914 | + date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 1915 | + |
|
| 1916 | + |
|
| 1917 | + //set orderby |
|
| 1918 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 1919 | + |
|
| 1920 | + switch ($this->_req_data['orderby']) { |
|
| 1921 | + case 'TXN_ID': |
|
| 1922 | + $orderby = 'TXN_ID'; |
|
| 1923 | + break; |
|
| 1924 | + case 'ATT_fname': |
|
| 1925 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 1926 | + break; |
|
| 1927 | + case 'event_name': |
|
| 1928 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 1929 | + break; |
|
| 1930 | + default: //'TXN_timestamp' |
|
| 1931 | + $orderby = 'TXN_timestamp'; |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 1935 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1936 | + $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; |
|
| 1937 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 1938 | + |
|
| 1939 | + $offset = ($current_page - 1) * $per_page; |
|
| 1940 | + $limit = array($offset, $per_page); |
|
| 1941 | + |
|
| 1942 | + $_where = array( |
|
| 1943 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 1944 | + 'Registration.REG_count' => 1 |
|
| 1945 | + ); |
|
| 1946 | + |
|
| 1947 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 1948 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + if (isset($this->_req_data['s'])) { |
|
| 1952 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1953 | + $_where['OR'] = array( |
|
| 1954 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 1955 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1956 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1957 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1958 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1959 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1960 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1961 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1962 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1963 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1964 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1965 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 1966 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 1967 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 1968 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 1969 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1970 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1971 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 1972 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 1973 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 1974 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string) |
|
| 1975 | + ); |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + //failed transactions |
|
| 1979 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; |
|
| 1980 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; |
|
| 1981 | + |
|
| 1982 | + if ($failed) { |
|
| 1983 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 1984 | + } else if ($abandoned) { |
|
| 1985 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 1986 | + } else { |
|
| 1987 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 1988 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); |
|
| 1992 | + |
|
| 1993 | + $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); |
|
| 1994 | + |
|
| 1995 | + |
|
| 1996 | + return $transactions; |
|
| 1997 | + |
|
| 1998 | + } |
|
| 1999 | 1999 | |
| 2000 | 2000 | |
| 2001 | 2001 | } |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | public function load_scripts_styles() |
| 339 | 339 | { |
| 340 | 340 | //enqueue style |
| 341 | - wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), |
|
| 341 | + wp_register_style('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.css', array(), |
|
| 342 | 342 | EVENT_ESPRESSO_VERSION); |
| 343 | 343 | wp_enqueue_style('espresso_txn'); |
| 344 | 344 | |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | add_filter('FHEE_load_accounting_js', '__return_true'); |
| 347 | 347 | |
| 348 | 348 | //scripts |
| 349 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 349 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array( |
|
| 350 | 350 | 'ee_admin_js', |
| 351 | 351 | 'ee-datepicker', |
| 352 | 352 | 'jquery-ui-datepicker', |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | if (empty($this->_transaction)) { |
| 440 | 440 | $error_msg = esc_html__('An error occurred and the details for Transaction ID #', |
| 441 | - 'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 441 | + 'event_espresso').$TXN_ID.esc_html__(' could not be retrieved.', 'event_espresso'); |
|
| 442 | 442 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 443 | 443 | } |
| 444 | 444 | } |
@@ -513,23 +513,23 @@ discard block |
||
| 513 | 513 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 514 | 514 | array( |
| 515 | 515 | 'overpaid' => array( |
| 516 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 516 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 517 | 517 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') |
| 518 | 518 | ), |
| 519 | 519 | 'complete' => array( |
| 520 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 520 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 521 | 521 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') |
| 522 | 522 | ), |
| 523 | 523 | 'incomplete' => array( |
| 524 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 524 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 525 | 525 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') |
| 526 | 526 | ), |
| 527 | 527 | 'abandoned' => array( |
| 528 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 528 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 529 | 529 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') |
| 530 | 530 | ), |
| 531 | 531 | 'failed' => array( |
| 532 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 532 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 533 | 533 | 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') |
| 534 | 534 | ) |
| 535 | 535 | ) |
@@ -551,10 +551,10 @@ discard block |
||
| 551 | 551 | $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; |
| 552 | 552 | $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', |
| 553 | 553 | 'event_espresso'), '<h3>', |
| 554 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 555 | - EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', |
|
| 556 | - 'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; |
|
| 557 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 554 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), |
|
| 555 | + EVENTS_ADMIN_URL).'" title="'.esc_attr__('Click to Edit event', |
|
| 556 | + 'event_espresso').'">'.$event->get('EVT_name').'</a>', '</h3>') : ''; |
|
| 557 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 558 | 558 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 559 | 559 | } |
| 560 | 560 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | |
| 589 | 589 | $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
| 590 | 590 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
| 591 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 591 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
| 592 | 592 | |
| 593 | 593 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
| 594 | 594 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
@@ -625,9 +625,9 @@ discard block |
||
| 625 | 625 | $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
| 626 | 626 | $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); |
| 627 | 627 | if (EE_Registry::instance()->CFG->currency->sign_b4) { |
| 628 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; |
|
| 628 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign.$this->_template_args['amount_due']; |
|
| 629 | 629 | } else { |
| 630 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; |
|
| 630 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'].EE_Registry::instance()->CFG->currency->sign; |
|
| 631 | 631 | } |
| 632 | 632 | $this->_template_args['amount_due_class'] = ''; |
| 633 | 633 | |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | |
| 663 | 663 | |
| 664 | 664 | // next link |
| 665 | - $next_txn = $this->_transaction->next( |
|
| 665 | + $next_txn = $this->_transaction->next( |
|
| 666 | 666 | null, |
| 667 | 667 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 668 | 668 | 'TXN_ID' |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | ) |
| 678 | 678 | : ''; |
| 679 | 679 | // previous link |
| 680 | - $previous_txn = $this->_transaction->previous( |
|
| 680 | + $previous_txn = $this->_transaction->previous( |
|
| 681 | 681 | null, |
| 682 | 682 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 683 | 683 | 'TXN_ID' |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | // grab messages at the last second |
| 732 | 732 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 733 | 733 | // path to template |
| 734 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 734 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 735 | 735 | $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
| 736 | 736 | $this->_template_args, true); |
| 737 | 737 | |
@@ -839,18 +839,18 @@ discard block |
||
| 839 | 839 | $reg_steps = '<ul>'; |
| 840 | 840 | foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
| 841 | 841 | if ($reg_step_status === true) { |
| 842 | - $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 843 | - ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 842 | + $reg_steps .= '<li style="color:#70cc50">'.sprintf(esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 843 | + ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
| 844 | 844 | } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { |
| 845 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( |
|
| 845 | + $reg_steps .= '<li style="color:#2EA2CC">'.sprintf( |
|
| 846 | 846 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
| 847 | 847 | ucwords(str_replace('_', ' ', $reg_step)), |
| 848 | - date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 848 | + date(get_option('date_format').' '.get_option('time_format'), |
|
| 849 | 849 | ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) |
| 850 | - ) . '</li>'; |
|
| 850 | + ).'</li>'; |
|
| 851 | 851 | } else { |
| 852 | - $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', |
|
| 853 | - 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; |
|
| 852 | + $reg_steps .= '<li style="color:#E76700">'.sprintf(esc_html__('%1$s : Never Initiated', |
|
| 853 | + 'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>'; |
|
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | $reg_steps .= '</ul>'; |
@@ -864,11 +864,11 @@ discard block |
||
| 864 | 864 | $this->_get_payment_status_array(); |
| 865 | 865 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
| 866 | 866 | |
| 867 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 867 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 868 | 868 | 'action' => 'edit_transaction', |
| 869 | 869 | 'process' => 'transaction' |
| 870 | 870 | ), TXN_ADMIN_URL); |
| 871 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 871 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 872 | 872 | 'page' => 'espresso_transactions', |
| 873 | 873 | 'action' => 'espresso_apply_payment' |
| 874 | 874 | ), WP_AJAX_URL); |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | |
| 880 | 880 | // 'espresso_delete_payment_nonce' |
| 881 | 881 | |
| 882 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 882 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 883 | 883 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 884 | 884 | |
| 885 | 885 | } |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | protected function _get_registrations_to_apply_payment_to() |
| 940 | 940 | { |
| 941 | 941 | // we want any registration with an active status (ie: not deleted or cancelled) |
| 942 | - $query_params = array( |
|
| 942 | + $query_params = array( |
|
| 943 | 943 | array( |
| 944 | 944 | 'STS_ID' => array( |
| 945 | 945 | 'IN', |
@@ -951,19 +951,19 @@ discard block |
||
| 951 | 951 | ) |
| 952 | 952 | ) |
| 953 | 953 | ); |
| 954 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 954 | + $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div( |
|
| 955 | 955 | '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' |
| 956 | 956 | ); |
| 957 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 957 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 958 | 958 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
| 959 | 959 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
| 960 | 960 | EEH_HTML::tr( |
| 961 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 962 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 963 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 964 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 965 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 966 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 961 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
| 962 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
| 963 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
| 964 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
| 965 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 966 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 967 | 967 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
| 968 | 968 | ) |
| 969 | 969 | ); |
@@ -977,28 +977,28 @@ discard block |
||
| 977 | 977 | : esc_html__('Unknown Attendee', 'event_espresso'); |
| 978 | 978 | $owing = $registration->final_price() - $registration->paid(); |
| 979 | 979 | $taxable = $registration->ticket()->taxable() |
| 980 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 980 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
| 981 | 981 | : ''; |
| 982 | 982 | $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
| 983 | 983 | ? ' checked="checked"' |
| 984 | 984 | : ''; |
| 985 | 985 | $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
| 986 | 986 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
| 987 | - EEH_HTML::td($registration->ID()) . |
|
| 988 | - EEH_HTML::td($attendee_name) . |
|
| 987 | + EEH_HTML::td($registration->ID()). |
|
| 988 | + EEH_HTML::td($attendee_name). |
|
| 989 | 989 | EEH_HTML::td( |
| 990 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 991 | - ) . |
|
| 992 | - EEH_HTML::td($registration->event_name()) . |
|
| 993 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 994 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 990 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
| 991 | + ). |
|
| 992 | + EEH_HTML::td($registration->event_name()). |
|
| 993 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 994 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 995 | 995 | EEH_HTML::td( |
| 996 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 996 | + '<input type="checkbox" value="'.$registration->ID() |
|
| 997 | 997 | . '" name="txn_admin_payment[registrations]"' |
| 998 | - . $checked . $disabled . '>', |
|
| 998 | + . $checked.$disabled.'>', |
|
| 999 | 999 | '', 'jst-cntr' |
| 1000 | 1000 | ), |
| 1001 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1001 | + 'apply-payment-registration-row-'.$registration->ID() |
|
| 1002 | 1002 | ); |
| 1003 | 1003 | } |
| 1004 | 1004 | } |
@@ -1064,12 +1064,12 @@ discard block |
||
| 1064 | 1064 | array( |
| 1065 | 1065 | 'OR*payment_method_for_payment' => array( |
| 1066 | 1066 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
| 1067 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') |
|
| 1067 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%') |
|
| 1068 | 1068 | ) |
| 1069 | 1069 | ) |
| 1070 | 1070 | ); |
| 1071 | 1071 | } else { |
| 1072 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1072 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
| 1075 | 1075 | } |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1115 | 1115 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
| 1116 | 1116 | } |
| 1117 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1117 | + $event_name .= ' - '.$item->get('LIN_name'); |
|
| 1118 | 1118 | $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
| 1119 | 1119 | // now get all of the registrations for this transaction that use this ticket |
| 1120 | 1120 | $registrations = $ticket->get_many_related('Registration', |
@@ -1132,8 +1132,8 @@ discard block |
||
| 1132 | 1132 | if ($attendee instanceof EE_Attendee) { |
| 1133 | 1133 | $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); |
| 1134 | 1134 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); |
| 1135 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', |
|
| 1136 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; |
|
| 1135 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = '<a href="mailto:'.$attendee->email().'?subject='.$event_name.esc_html__(' Event', |
|
| 1136 | + 'event_espresso').'">'.$attendee->email().'</a>'; |
|
| 1137 | 1137 | $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, |
| 1138 | 1138 | 'inline', false, false); |
| 1139 | 1139 | } else { |
@@ -1153,7 +1153,7 @@ discard block |
||
| 1153 | 1153 | 'action' => 'edit_transaction', |
| 1154 | 1154 | 'process' => 'attendees' |
| 1155 | 1155 | ), TXN_ADMIN_URL); |
| 1156 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1156 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1157 | 1157 | $this->_template_args, true); |
| 1158 | 1158 | |
| 1159 | 1159 | } else { |
@@ -1194,7 +1194,7 @@ discard block |
||
| 1194 | 1194 | ), REG_ADMIN_URL); |
| 1195 | 1195 | // get formatted address for registrant |
| 1196 | 1196 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
| 1197 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1197 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1198 | 1198 | $this->_template_args, true); |
| 1199 | 1199 | } |
| 1200 | 1200 | |
@@ -1215,8 +1215,8 @@ discard block |
||
| 1215 | 1215 | TXN_ADMIN_URL |
| 1216 | 1216 | ); |
| 1217 | 1217 | |
| 1218 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1219 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1218 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1219 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/ |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | $REG_IDs = array(); |
| 1510 | 1510 | // grab array of IDs for specific registrations to apply changes to |
| 1511 | 1511 | if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
| 1512 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1512 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1513 | 1513 | } |
| 1514 | 1514 | //nothing specified ? then get all reg IDs |
| 1515 | 1515 | if (empty($REG_IDs)) { |
@@ -1895,8 +1895,8 @@ discard block |
||
| 1895 | 1895 | $end_date = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); |
| 1896 | 1896 | |
| 1897 | 1897 | //make sure our timestamps start and end right at the boundaries for each day |
| 1898 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 1899 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 1898 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 1899 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 1900 | 1900 | |
| 1901 | 1901 | |
| 1902 | 1902 | //convert to timestamps |
@@ -1949,7 +1949,7 @@ discard block |
||
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | if (isset($this->_req_data['s'])) { |
| 1952 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1952 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1953 | 1953 | $_where['OR'] = array( |
| 1954 | 1954 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
| 1955 | 1955 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |