Skip to content

Commit

Permalink
Better empty default for error log array; docblock; fixes #285
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jan 24, 2018
1 parent e8254d3 commit d164e41
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions lib/WP_Auth0_ErrorManager.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
<?php

/**
* Class WP_Auth0_ErrorManager
*/
class WP_Auth0_ErrorManager {

public static function insert_auth0_error( $section, $wp_error ) {

if ( $wp_error instanceof WP_Error ) {
$code = $wp_error->get_error_code();
$message = $wp_error->get_error_message();
} elseif ( $wp_error instanceof Exception ) {
$code = $wp_error->getCode();
$message = $wp_error->getMessage();
/**
* Create a row in the error log, up to 20 entries
*
* @param string $section - portion of the codebase that generated the error
* @param string|WP_Error|Exception $error - error message string or discoverable error type
*/
public static function insert_auth0_error( $section, $error ) {

if ( $error instanceof WP_Error ) {
$code = $error->get_error_code();
$message = $error->get_error_message();
} elseif ( $error instanceof Exception ) {
$code = $error->getCode();
$message = $error->getMessage();
} else {
$code = 'N/A';
$message = $wp_error;
$message = $error;
}

$log = get_option('auth0_error_log', array());
$log = get_option( 'auth0_error_log' );

if ( empty( $log ) ) {
$log = array();
}

array_unshift($log, array(
'section'=>$section,
'code'=>$code,
'message'=>$message,
array_unshift( $log, array(
'section' => $section,
'code' => $code,
'message' => $message,
'date' => time(),
));
) );

if (count($log) > 20) {
array_pop($log);
}

update_option( 'auth0_error_log', $log );
}

}
}

0 comments on commit d164e41

Please sign in to comment.