add_email( $recipient ); } } else { $this->add_email( $recipients ); } $this->set_threshold( $threshold ); } /** * Set handler severity threshold. * * @param string $level emergency|alert|critical|error|warning|notice|info|debug */ public function set_threshold( $level ) { $this->threshold = WC_Log_Levels::get_level_severity( $level ); } /** * Determine whether handler should handle log. * * @param string $level emergency|alert|critical|error|warning|notice|info|debug * @return bool True if the log should be handled. */ public function should_handle( $level ) { return $this->threshold <= WC_Log_Levels::get_level_severity( $level ); } /** * Handle a log entry. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. * * @return bool True on success. */ public function handle( $timestamp, $level, $message, $context ) { if ( $this->should_handle( $level ) ) { $subject = $this->get_subject( $timestamp, $level, $message, $context ); $body = $this->get_body( $timestamp, $level, $message, $context ); return wp_mail( $this->recipients, $subject, $body ); } return true; } /** * Build subject for log email. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. * * @return string subject */ public function get_subject( $timestamp, $level, $message, $context ) { $site_name = get_bloginfo( 'name' ); return sprintf( __( '[%1$s] WooCommerce log message from %2$s', 'woocommerce' ), strtoupper( $level ), $site_name ); } /** * Build body for log email. * * @param int $timestamp Log timestamp. * @param string $level emergency|alert|critical|error|warning|notice|info|debug * @param string $message Log message. * @param array $context Optional. Additional information for log handlers. * * @return string body */ public function get_body( $timestamp, $level, $message, $context ) { $entry = $this->format_entry( $timestamp, $level, $message, $context ); return __( 'You have received the following WooCommerce log message:', 'woocommerce' ) . PHP_EOL . PHP_EOL . $entry; } /** * Adds an email to the list of recipients. * * @param string email Email address to add */ public function add_email( $email ) { array_push( $this->recipients, $email ); } }