/** * @singleton method used to instantiate class object * @access public * @return EEH_Debug_Tools */ public static function instance() { // check if class object is instantiated, and instantiated properly if (!self::$_instance instanceof EEH_Debug_Tools) { self::$_instance = new self(); } return self::$_instance; }
/** * debug * * @param string $class * @param string $func * @param string $line * @param \EE_Transaction $transaction * @param array $info * @param bool $display_request */ protected function log($class = '', $func = '', $line = '', EE_Transaction $transaction, $info = array(), $display_request = false) { if (WP_DEBUG && false) { if ($transaction instanceof EE_Transaction) { // don't serialize objects $info = EEH_Debug_Tools::strip_objects($info); if ($transaction->ID()) { $info['TXN_status'] = $transaction->status_ID(); $info['TXN_reg_steps'] = $transaction->reg_steps(); $index = 'EE_Transaction: ' . $transaction->ID(); EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); } } } }
/** * espresso_load_error_handling * this function loads EE's class for handling exceptions and errors */ function espresso_load_error_handling() { // load debugging tools if (WP_DEBUG === TRUE) { require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; EEH_Debug_Tools::instance(); } // load error handling if (is_readable(EE_CORE . 'EE_Error.core.php')) { require_once EE_CORE . 'EE_Error.core.php'; } else { wp_die(__('The EE_Error core class could not be loaded.', 'event_espresso')); } }
/** * _display_request_vars * * @access protected * @return void */ protected function _display_request_vars() { if (!WP_DEBUG) { return; } EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); }
/** * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. * * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, but the code execution is done in a manner that could lead to unexpected results (i.e. running to early, or too late in WP or EE loading process). * * A good test for knowing whether to use this method is: * 1. Is there going to be a PHP error if something isn't setup/used correctly? Yes -> use EE_Error::add_error() or throw new EE_Error() * 2. If this is loaded before something else, it won't break anything, but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() * * @uses constant WP_DEBUG test if wp_debug is on or not * @param string $function The function that was called * @param string $message A message explaining what has been done incorrectly * @param string $version The version of Event Espresso where the error was added * @param int $error_type * @return void */ public static function doing_it_wrong($function, $message, $version, $error_type = E_USER_NOTICE) { if (defined('WP_DEBUG') && WP_DEBUG) { EE_Registry::instance()->load_helper('Debug_Tools'); EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $error_type); } }
/** * registration_status_changed * * @access public * @param EE_Registration $registration * @param array $additional_details * @return void */ public function trigger_registration_update_notifications($registration, $additional_details = array()) { try { if (!$registration instanceof EE_Registration) { throw new EE_Error(__('An invalid registration was received.', 'event_espresso')); } EE_Registry::instance()->load_helper('Debug_Tools'); EEH_Debug_Tools::log(__CLASS__, __FUNCTION__, __LINE__, array($registration->transaction(), $additional_details), false, 'EE_Transaction: ' . $registration->transaction()->ID()); do_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', $registration, $additional_details); } catch (Exception $e) { EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); } }
/** * registration_status_changed * * @access public * @param EE_Registration $registration * @param array $additional_details * @return void */ public function trigger_registration_update_notifications(EE_Registration $registration, $additional_details = array()) { try { //do_action( // 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', // $registration, // apply_filters( // 'FHEE__EE_Registration_Processor__trigger_registration_update_notifications__additional_conditions', // array_merge( // // defaults // array( // 'checkout_or_payment' => false, // 'manually_updated' => false, // 'payment_updates' => false, // //'status_updates' => $this->reg_status_updated( $registration->ID() ), // 'finalized' => false, // 'revisit' => false, // 'reg_steps' => $registration->transaction()->reg_steps(), // 'txn_status' => $registration->transaction()->status_ID(), // 'last_payment' => null, // 'old_reg_status' => $this->old_reg_status( $registration->ID() ), // 'new_reg_status' => $this->new_reg_status( $registration->ID() ) // ), // $additional_details // ) // ) //); EE_Registry::instance()->load_helper('Debug_Tools'); EEH_Debug_Tools::log(__CLASS__, __FUNCTION__, __LINE__, array($registration->transaction(), $additional_details), false, 'EE_Transaction: ' . $registration->transaction()->ID()); do_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', $registration, $additional_details); } catch (Exception $e) { EE_Error::add_error($e->getMessage(), $e->getFile(), 'function_added_from_exception', $e->getLine()); } }
/** * register_autoloader * * @access public * @param array | string $class_paths - array of key => value pairings between class names and paths * @param bool $read_check true if we need to check whether the file is readable or not. * @param bool $debug - set to true to display autoloader class => path mappings * @return void * @throws \EE_Error */ public static function register_autoloader($class_paths, $read_check = true, $debug = false) { $class_paths = is_array($class_paths) ? $class_paths : array($class_paths); foreach ($class_paths as $class => $path) { // don't give up! you gotta... // get some class if (empty($class)) { throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path)); } // one day you will find the path young grasshopper if (empty($path)) { throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class)); } // is file readable ? if ($read_check && !is_readable($path)) { throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path)); } if (!isset(self::$_autoloaders[$class])) { self::$_autoloaders[$class] = str_replace(array('/', '\\'), DS, $path); if (WP_DEBUG && $debug) { EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__); } } } }
/** * @param mixed $var * @param string $var_name * @param string $file * @param int $line * @param int $header * @param bool $die */ public static function printr($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { // return; $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); //$print_r = false; if (is_string($var)) { EEH_Debug_Tools::printv($var, $var_name, $file, $line, $header, $die); return; } else { if (is_object($var)) { $var_name = !$var_name ? 'object' : $var_name; //$print_r = true; } else { if (is_array($var)) { $var_name = !$var_name ? 'array' : $var_name; //$print_r = true; } else { if (is_numeric($var)) { $var_name = !$var_name ? 'numeric' : $var_name; } else { if (is_null($var)) { $var_name = !$var_name ? 'null' : $var_name; } } } } } $heading_tag = 'h'; $heading_tag .= is_int($header) ? $header : 5; $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); $margin = is_admin() ? ' 180px' : '0'; $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0' . $margin . ';"><b>' . $var_name . '</b>'; $result .= '<span style="color:#999;"> : </span><span style="color:#E76700;">'; $result .= '<pre style="color:#999; padding:1em; background: #fff">'; $result .= var_export($var, true); $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;' . $margin . '">' . $file; $result .= '<br />line no: ' . $line . '</span></' . $heading_tag . '>'; if ($die) { die($result); } else { echo $result; } }
/** * register_payment_method- makes core aware of this payment method * * @access public * @param string $payment_method_path - full path up to and including payment method folder * @return boolean */ public function register_payment_method($payment_method_path = '') { do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); $module_ext = '.pm.php'; // make all separators match $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); // grab and sanitize module name $module_dir = basename($payment_method_path); // create classname from module directory name $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); // add class prefix $module_class = 'EE_PMT_' . $module; // does the module exist ? if (!is_readable($payment_method_path . DS . $module_class . $module_ext)) { $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', 'event_espresso'), $module); EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); return FALSE; } if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->start_timer(); } // load the module class file require_once $payment_method_path . DS . $module_class . $module_ext; if (WP_DEBUG === TRUE) { EEH_Debug_Tools::instance()->stop_timer("Requiring payment method {$module_class}"); } // verify that class exists if (!class_exists($module_class)) { $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); return FALSE; } // add to array of registered modules $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; return TRUE; }
/** * display_template_parts * * just for debugging purposes * * @access public * @return string */ public function display_template_parts() { if (WP_DEBUG) { $this->template_parts->rewind(); while ($this->template_parts->valid()) { EEH_Debug_Tools::printr($this->template_parts->current(), 'template_part', __FILE__, __LINE__); $this->template_parts->next(); } } }
/** * @ print_r an array * @ access public * @ return void * * @param mixed $var * @param bool $var_name * @param string $file * @param int $line * @param int $header * @param bool $die */ public static function printr($var, $var_name = false, $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); //$print_r = false; if (is_string($var)) { EEH_Debug_Tools::printv($var, $var_name, $file, $line, $header, $die); return; } else { if (is_object($var)) { $var_name = !$var_name ? 'object' : $var_name; //$print_r = true; } else { if (is_array($var)) { $var_name = !$var_name ? 'array' : $var_name; //$print_r = true; } else { if (is_numeric($var)) { $var_name = !$var_name ? 'numeric' : $var_name; } else { if (is_null($var)) { $var_name = !$var_name ? 'null' : $var_name; } } } } } $heading_tag = 'h'; $heading_tag .= is_int($header) ? $header : 5; $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); ob_start(); echo '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0;"><b>' . $var_name . '</b>'; echo '<span style="color:#999"> : </span><span style="color:#E76700">'; var_dump($var); echo '</span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; echo '<br />line no: ' . $line . '</span></' . $heading_tag . '>'; $result = ob_get_clean(); if ($die) { die($result); } else { echo $result; } }
/** * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, * but the code execution is done in a manner that could lead to unexpected results * (i.e. running to early, or too late in WP or EE loading process). * A good test for knowing whether to use this method is: * 1. Is there going to be a PHP error if something isn't setup/used correctly? * Yes -> use EE_Error::add_error() or throw new EE_Error() * 2. If this is loaded before something else, it won't break anything, * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() * * @uses constant WP_DEBUG test if wp_debug is on or not * @param string $function The function that was called * @param string $message A message explaining what has been done incorrectly * @param string $version The version of Event Espresso where the error was added * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing * for a deprecated function. This allows deprecation to occur during one version, * but not have any notices appear until a later version. This allows developers * extra time to update their code before notices appear. * @param int $error_type */ public static function doing_it_wrong($function, $message, $version, $applies_when = '', $error_type = null) { if (defined('WP_DEBUG') && WP_DEBUG) { EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); } }
/** * Assumes all the files in this folder have the normal naming scheme (namely that their classname * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list. * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly. * Yes this has to scan the directory for files, but it only does it once -- not on EACH * time the autoloader is used * * @param string $folder name, with or without trailing /, doesn't matter * @param bool $recursive * @param bool $debug **deprecated** * @throws \EE_Error */ public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) { if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) { EEH_Debug_Tools::instance()->start_timer(basename($folder)); } // make sure last char is a / $folder .= $folder[strlen($folder) - 1] !== DS ? DS : ''; $class_to_filepath_map = array(); $exclude = array('index'); //get all the files in that folder that end in php $filepaths = glob($folder . '*'); if (empty($filepaths)) { return; } foreach ($filepaths as $filepath) { if (substr($filepath, -4, 4) === '.php') { $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath); if (!in_array($class_name, $exclude)) { $class_to_filepath_map[$class_name] = $filepath; } } else { if ($recursive) { EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug); } } } // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories. self::register_autoloader($class_to_filepath_map, false, $debug); if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') { EEH_Debug_Tools::instance()->stop_timer(basename($folder)); } }