PluginProbe
WP Offload SES Lite / 1.8.0
WP Offload SES Lite v1.8.0
1.8.2 trunk 0.1.2 0.2.1 0.7.2.1 0.8.2 1.0 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
wp-ses / classes / Error.php

Error.php in WP Offload SES Lite 1.8.0, at classes/Error.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Extension of WP_Error for WP Offload SES.
4 *
5 * @author Delicious Brains
6 * @package WP Offload SES
7 */
8
9 namespace DeliciousBrains\WP_Offload_SES;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 use WP_Error;
16
17 /**
18 * Class Error
19 *
20 * @since 1.0.0
21 */
22 class Error extends WP_Error {
23
24 // Generic errors.
25 public static $mail_function_exists = 101;
26 public static $missing_access_keys = 102;
27
28 // API related errors.
29 public static $api_get_quota = 201;
30 public static $api_send = 202;
31 public static $api_get_identities = 203;
32 public static $api_verify_domain = 204;
33 public static $api_verify_email = 205;
34 public static $api_delete_identity = 206;
35 public static $api_get_identity_details = 207;
36 public static $api_get_account = 208;
37
38 // License related errors.
39 public static $licence_error = 301;
40
41 // Cron related errors.
42 public static $send_cron_email = 401;
43 public static $job_retrieval_failure = 402;
44 public static $cmd_construction_failure = 403;
45
46 /**
47 * Error constructor.
48 *
49 * @param string|int $code $error Error code.
50 * @param string|WP_Error $error Error message or instance of WP_Error.
51 * @param mixed $data Optional. Error data.
52 */
53 public function __construct( $code = '', $error = '', $data = '' ) {
54 if ( is_wp_error( $error ) ) {
55 $message = $error->get_error_code() . ': ' . $error->get_error_message();
56 $data = ( $data ) ?: $error->get_error_data();
57 } else {
58 $message = $error;
59 }
60
61 // Debug log.
62 $this->log_error( $code, $message, $data );
63
64 parent::__construct( $code, $message, $data );
65 }
66
67 /**
68 * Log error
69 *
70 * @param string $code The error code to log.
71 * @param string $message The message to log.
72 * @param string|array $data Any relevant data for the error.
73 */
74 private function log_error( string $code, string $message, $data ) {
75 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
76
77 if ( ! empty( $data ) && is_string( $data ) ) {
78 $message .= ' (' . $data . ')';
79 }
80
81 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
82 error_log( 'WP Offload SES #' . $code . ': ' . $message );
83
84 if ( is_array( $data ) || is_object( $data ) ) {
85 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
86 error_log( wp_json_encode( $data ) );
87 }
88 }
89 }
90
91 }
92