-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better empty default for error log array; docblock; fixes #285
- Loading branch information
1 parent
e8254d3
commit d164e41
Showing
1 changed file
with
29 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
|
||
} | ||
} |