k;
case E_USER_WARNING:
$type = 'user_warning';
return;
break;
case E_USER_NOTICE:
$type = 'user_notice';
return;
break;
case E_STRICT:
$type = 'strict';
//TODO: enable strict errors logging
return;
break;
case E_RECOVERABLE_ERROR:
$type = 'recoverable_error';
break;
case E_DEPRECATED:
case E_USER_DEPRECATED:
$type = 'deprecated';
//TODO: enable deprecated errors logging
return;
break;
}
}
$errors = get_option( 'bs-backend-error-log', array() );
$errors[] = array(
'msg' => $message,
'file' => self::wp_content_basename( $file ),
'timestamp' => time(),
'line' => $line,
'type' => $type,
'trace' => $type === 'fatal' ? '' : print_r( self::get_debug_backtrace(), true )
);
$logged = update_option( 'bs-backend-error-log', array_slice( $errors, - 15 ), 'no' );
do_action( 'better-framework/oculus/logger/logged', $logged );
}
/**
* Get debug backtrace summary
*
* @return array
*/
public static function get_debug_backtrace() {
$result = array();
foreach ( array_slice( debug_backtrace(), 3, 3 ) as $idx => $trace ) {
if ( isset( $trace['object'] ) ) {
$trace['object'] = get_class( $trace['object'] );
}
$result[ $idx ] = $trace;
}
unset( $result[0]['args'][4] ); // unset bs_custom_error_handler fifth argument
return $result;
}
/**
* Log all php errors except fatal errors
*
* @param integer $errno
* @param string $errstr
* @param string $errfile
* @param integer $errline
*
* @see set_error_handler
*
* @return boolean false
*/
public static function bs_custom_error_handler( $errno, $errstr, $errfile, $errline ) {
self::bs_log_error( $errstr, $errfile, $errline, $errno );
return false;
}
/**
* Log only php fatal errors
*/
public static function bs_custom_fatal_error_handler() {
$last_error = error_get_last();
if ( $last_error && isset( $last_error['type'] ) && $last_error['type'] === E_ERROR ) {
self::bs_log_error( $last_error['message'], $last_error['file'], $last_error['line'], 'fatal' );
}
}
/**
* @param array $data
*
* @return array|mixed
*/
public static function _data( $data ) {
if ( $errors = get_option( 'bs-backend-error-log' ) ) {
$data['backend'] = $errors;
}
return $data;
}
/**
* @param object $obj
*/
public static function flush_log( $obj ) {
if ( ! empty( $obj->clean_backend_log ) ) {
update_option( 'bs-backend-error-log', array(), 'no' );
}
}
/**
* Catch file path after wp-content dir.
*
* @param string $file full path to file
*
* @return string
*/
public static function wp_content_basename( $file ) {
$file = wp_normalize_path( $file );
$content_dir = wp_normalize_path( WP_CONTENT_DIR );
$file = preg_replace( '#^' . preg_quote( $content_dir, '#' ) . '/#', '', $file ); // get relative path from wp-content dir
$file = trim( $file, '/' );
return $file;
}
}
BetterFramework_Oculus_Loader::register_custom_error_handler();
add_action( 'after_setup_theme', array( 'BetterFramework_Oculus_Loader', 'setup_library' ), 11 );
}
مواطن يخلع ملابسه ويسير عاريا في طرابلس - وكالة الخبر