$event, 'milestone' => $hit, 'days' => $days ); /** * A countdown milestone was reached. Extensions can hook in here, e.g. to send chat alerts. */ do_action( 'sunsetly_milestone_reached', $event, $hit, $days, $report ); if ( Sunsetly_Settings::get( 'email_milestones' ) ) { $subject = 0 === $days /* translators: 1: event title, 2: site name. */ ? sprintf( __( '[Today] %1$s — %2$s', 'sunsetly' ), $event['title'], self::site_name() ) /* translators: 1: number of days left, 2: event title, 3: site name. */ : sprintf( _n( '[%1$d day left] %2$s — %3$s', '[%1$d days left] %2$s — %3$s', $days, 'sunsetly' ), $days, $event['title'], self::site_name() ); $intro = sprintf( /* translators: 1: title, 2: date, 3: days */ __( 'Advance notice: "%1$s" happens on %2$s (%3$s). Plan the upgrade now so it is a calm, scheduled job instead of an emergency.', 'sunsetly' ), $event['title'], $event['date'], /* translators: %d: number of days. */ 0 === $days ? __( 'today', 'sunsetly' ) : sprintf( _n( 'in %d day', 'in %d days', $days, 'sunsetly' ), $days ) ); $related = array_values( array_filter( $report['findings'], function ( $f ) { return 'lifecycle' === $f['category'] || 'readiness' === $f['category']; } ) ); self::send( $subject, $intro, $related, $report, 'milestone' ); } } update_option( self::SENT_MILESTONES, $sent, false ); return $fired; } /** * Weekly / monthly digest. * * @param array $report Report. */ public static function maybe_digest( $report ) { $freq = Sunsetly_Settings::get( 'digest' ); if ( 'never' === $freq ) { return; } $interval = 'monthly' === $freq ? 30 * DAY_IN_SECONDS : WEEK_IN_SECONDS; $last = (int) get_option( self::LAST_DIGEST, 0 ); if ( 0 === $last ) { // Don't send a digest on the very first scan; start the clock instead. update_option( self::LAST_DIGEST, time(), false ); return; } if ( ( time() - $last ) < $interval - HOUR_IN_SECONDS ) { return; } update_option( self::LAST_DIGEST, time(), false ); /* translators: 1: grade, 2: score, 3: site */ $subject = sprintf( __( 'Site health %1$s (%2$d/100) — %3$s maintenance digest', 'sunsetly' ), $report['grade'], $report['score'], self::site_name() ); $top = array_slice( array_values( array_filter( $report['findings'], function ( $f ) { return 'info' !== $f['severity']; } ) ), 0, 10 ); self::send( $subject, __( 'Here is your scheduled Sunsetly summary.', 'sunsetly' ), $top, $report, 'digest' ); } /** * Send an HTML email. * * @param string $subject Subject. * @param string $intro Intro. * @param array $findings Findings. * @param array $report Report. * @param string $context Context. * @return bool */ public static function send( $subject, $intro, $findings, $report, $context ) { $recipients = Sunsetly_Settings::recipients(); $html = self::email_html( $intro, $findings, $report ); $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $mail = apply_filters( 'sunsetly_email', array( 'to' => $recipients, 'subject' => $subject, 'html' => $html, 'headers' => $headers, ), $context, $findings, $report ); if ( empty( $mail['to'] ) ) { return false; } return wp_mail( $mail['to'], $mail['subject'], $mail['html'], $mail['headers'] ); } /** * Email body. * * @param string $intro Intro. * @param array $findings Findings. * @param array $report Report. * @return string */ public static function email_html( $intro, $findings, $report ) { $brand = apply_filters( 'sunsetly_branding', array( 'name' => 'Sunsetly', 'color' => '#2747d9', 'logo' => '', 'footer' => __( 'Sent by Sunsetly — vulnerability & PHP lifecycle early warning for WordPress.', 'sunsetly' ), ) ); $colors = array( 'critical' => '#b42318', 'high' => '#d9480f', 'medium' => '#b7791f', 'low' => '#2b6cb0', 'info' => '#4a5568', ); ob_start(); ?>
· PHP · WordPress

'#2f855a', 'B' => '#38a169', 'C' => '#d69e2e', 'D' => '#dd6b20', 'F' => '#c53030', ); return isset( $map[ $grade ] ) ? $map[ $grade ] : '#4a5568'; } /** * Site name. * * @return string */ public static function site_name() { $n = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); return $n ? $n : wp_parse_url( home_url(), PHP_URL_HOST ); } /** * The single most important admin notice (never more than one — no nagging). */ public static function admin_notice() { if ( ! current_user_can( 'manage_options' ) || ! Sunsetly_Settings::get( 'admin_notices' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( $screen && false !== strpos( (string) $screen->id, 'sunsetly' ) ) { return; // Dashboard already shows everything. } $report = Sunsetly_Scanner::report(); if ( ! $report ) { return; } $notice = self::pick_notice( $report ); if ( ! $notice ) { return; } $nkey = md5( $notice['key'] ); $snoozed = (array) get_user_meta( get_current_user_id(), 'sunsetly_snoozed', true ); if ( isset( $snoozed[ $nkey ] ) && $snoozed[ $nkey ] > time() ) { return; } $class = 'critical' === $notice['level'] ? 'notice-error' : 'notice-warning'; wp_enqueue_script( 'sunsetly-notice', SUNSETLY_URL . 'assets/notice.js', array(), SUNSETLY_VERSION, true ); ?>

Sunsetly:  

'vulns-' . $crit . '-' . $high, 'level' => 'critical', /* translators: 1: critical, 2: high */ 'text' => sprintf( __( '%1$d critical and %2$d high-severity vulnerabilities affect this site right now.', 'sunsetly' ), $crit, $high ), ); } $max = max( Sunsetly_Settings::milestones() ); foreach ( (array) $report['calendar'] as $e ) { $days = Sunsetly_Util::days_until( $e['date'] ); if ( 'high' === $e['severity'] && null !== $days && $days >= 0 && $days <= $max ) { return array( 'key' => $e['key'] . '-' . ( $days <= 7 ? 'final' : 'early' ), 'level' => $days <= 7 ? 'critical' : 'warning', /* translators: 1: title, 2: days */ 'text' => sprintf( _n( '%1$s in %2$d day.', '%1$s in %2$d days.', $days, 'sunsetly' ), $e['title'], $days ), ); } } foreach ( $report['findings'] as $f ) { if ( 'lifecycle' === $f['category'] && 'critical' === $f['severity'] ) { return array( 'key' => $f['id'], 'level' => 'critical', 'text' => $f['title'] . '.', ); } } return null; } /** * Snooze handler. */ public static function ajax_snooze() { check_ajax_referer( 'sunsetly_snooze' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } $key = isset( $_POST['key'] ) ? sanitize_key( wp_unslash( $_POST['key'] ) ) : ''; if ( ! preg_match( '/^[a-f0-9]{32}$/', $key ) ) { wp_send_json_error( null, 400 ); } $now = time(); $snoozed = array_filter( (array) get_user_meta( get_current_user_id(), 'sunsetly_snoozed', true ), static function ( $until ) use ( $now ) { return (int) $until > $now; } ); $snoozed[ $key ] = $now + WEEK_IN_SECONDS; update_user_meta( get_current_user_id(), 'sunsetly_snoozed', $snoozed ); wp_send_json_success(); } }