' . $n . ''; } } add_menu_page( 'Sunsetly', 'Sunsetly' . $badge, 'manage_options', 'sunsetly', array( __CLASS__, 'render' ), 'dashicons-shield-alt' ); } /** * Settings API. */ public static function register_settings() { register_setting( 'sunsetly', Sunsetly_Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'Sunsetly_Settings', 'sanitize' ), ) ); } /** * One-time setup hint, shown only on the Plugins screen until the plugin page has been opened. */ public static function setup_notice() { if ( ! current_user_can( 'manage_options' ) || get_option( 'sunsetly_onboarded' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || 'plugins' !== $screen->id ) { return; } printf( '

%s %s

', esc_html__( 'Sunsetly is active. Online checks are off until you turn them on.', 'sunsetly' ), esc_url( admin_url( 'admin.php?page=sunsetly' ) ), esc_html__( 'Review setup', 'sunsetly' ) ); } /** * Opt in to (or out of) online checks. */ public static function handle_consent() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'sunsetly' ) ); } check_admin_referer( 'sunsetly_consent' ); $enable = ! empty( $_POST['enable'] ); $settings = Sunsetly_Settings::all(); $settings['remote_checks'] = $enable ? 1 : 0; update_option( Sunsetly_Settings::OPTION, $settings, false ); if ( $enable ) { self::run_manual_scan(); } wp_safe_redirect( admin_url( 'admin.php?page=sunsetly' ) ); exit; } /** * Assets. * * @param string $hook Hook. */ public static function assets( $hook ) { $own_page = 'toplevel_page_sunsetly' === $hook; $dashboard = 'index.php' === $hook && Sunsetly_Settings::get( 'dashboard_widget' ) && current_user_can( 'manage_options' ); if ( ! $own_page && ! $dashboard ) { return; } // All selectors are prefixed, so the stylesheet only affects Sunsetly's own markup. wp_enqueue_style( 'sunsetly-admin', SUNSETLY_URL . 'assets/admin.css', array(), SUNSETLY_VERSION ); if ( $own_page ) { wp_enqueue_script( 'sunsetly-admin', SUNSETLY_URL . 'assets/admin.js', array(), SUNSETLY_VERSION, true ); } } /** * Settings link. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Dashboard', 'sunsetly' ) . '' ); return $links; } /** * "Scan now". */ public static function handle_scan() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'sunsetly' ) ); } check_admin_referer( 'sunsetly_scan' ); if ( ! empty( $_POST['refresh'] ) ) { Sunsetly_HTTP::flush(); } $result = self::run_manual_scan(); $arg = is_wp_error( $result ) ? 'locked' : 'done'; wp_safe_redirect( admin_url( 'admin.php?page=sunsetly&scan=' . $arg ) ); exit; } /** * Run a scan requested by an administrator. * * @return array|WP_Error */ private static function run_manual_scan() { // Uses the update information WordPress already keeps; no extra update checks are forced. return Sunsetly_Scanner::run( array( 'trigger' => 'manual' ) ); } /** * Tabs (filterable by extensions). * * @return array */ public static function tabs() { return apply_filters( 'sunsetly_admin_tabs', array( 'dashboard' => __( 'Dashboard', 'sunsetly' ), 'settings' => __( 'Settings', 'sunsetly' ), ) ); } /** * Page router. */ public static function render() { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( ! get_option( 'sunsetly_onboarded' ) ) { update_option( 'sunsetly_onboarded', 1, false ); } $tabs = self::tabs(); $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'dashboard'; // phpcs:ignore WordPress.Security.NonceVerification if ( ! isset( $tabs[ $tab ] ) ) { $tab = 'dashboard'; } echo '
'; echo '

Sunsetly ' . esc_html__( 'Know before it breaks', 'sunsetly' ) . '

'; echo ''; if ( 'dashboard' === $tab ) { self::render_dashboard(); } elseif ( 'settings' === $tab ) { self::render_settings(); } else { do_action( 'sunsetly_render_tab_' . $tab ); } echo '
'; } /** * Dashboard. */ private static function render_dashboard() { $report = Sunsetly_Scanner::report(); // phpcs:disable WordPress.Security.NonceVerification if ( isset( $_GET['scan'] ) && 'locked' === $_GET['scan'] ) { echo '

' . esc_html__( 'A scan is already in progress. Refresh in a minute.', 'sunsetly' ) . '

'; } // phpcs:enable if ( ! Sunsetly_Settings::remote_allowed() ) { self::consent_card(); } self::scan_button( $report ); if ( ! $report ) { echo '

' . esc_html__( 'No scan yet', 'sunsetly' ) . '

' . esc_html__( 'Run your first scan to see vulnerabilities, PHP end-of-life countdowns and your site health score.', 'sunsetly' ) . '

'; return; } if ( ! empty( $report['errors'] ) ) { echo '

' . esc_html__( 'Some data sources were unreachable:', 'sunsetly' ) . '
' . implode( '
', array_map( 'esc_html', $report['errors'] ) ) . '

'; } if ( 'none' === $report['source'] && Sunsetly_Settings::remote_allowed() ) { echo '

' . esc_html__( 'Vulnerability checks are switched off in Settings.', 'sunsetly' ) . '

'; } $php = $report['lifecycle']['php']; $db = $report['lifecycle']['db']; ?>
/100

WordPress

array( 'ok', __( 'Latest version', 'sunsetly' ) ), 'outdated' => array( 'warn', __( 'Update available', 'sunsetly' ) ), 'insecure' => array( 'bad', __( 'INSECURE — update now', 'sunsetly' ) ), 'unknown' => array( 'muted', __( 'Status unknown', 'sunsetly' ) ), ); $l = isset( $labels[ $report['core_state'] ] ) ? $labels[ $report['core_state'] ] : $labels['unknown']; ?>

✅

array( 'ok', __( 'Fully supported', 'sunsetly' ) ), 'security' => array( 'warn', __( 'Security fixes only', 'sunsetly' ) ), 'eol' => array( 'bad', __( 'END OF LIFE', 'sunsetly' ) ), 'unknown' => array( 'muted', __( 'No lifecycle data', 'sunsetly' ) ), ); $st = $states[ $s['state'] ] ?? $states['unknown']; $days = $s['days_security']; $pct = 0; if ( $s['released'] && $s['security_until'] ) { $total = max( 1, strtotime( $s['security_until'] ) - strtotime( $s['released'] ) ); $pct = max( 0, min( 100, round( 100 * ( time() - strtotime( $s['released'] ) ) / $total ) ) ); } ?>

= 0 ) : ?>

%

$p ) { $pts[] = round( $i * 200 / ( $n - 1 ), 1 ) . ',' . round( 40 - ( (int) $p['score'] * 0.38 ), 1 ); } echo '
' . esc_html__( 'Score trend', 'sunsetly' ) . '
'; } /** * Settings tab. */ private static function render_settings() { $s = Sunsetly_Settings::all(); $o = Sunsetly_Settings::OPTION; $wf_meta = get_option( Sunsetly_Vulnerabilities::WF_META, array() ); ?>

Wordfence account. The full feed is downloaded at most every 12 hours and reduced locally to the software installed here — your plugin list never leaves this server.', 'sunsetly' ) ); ?>





' . esc_html__( 'First scan pending…', 'sunsetly' ) . '

'; return; } $php = $report['lifecycle']['php']; ?>


= 0 ? sprintf( __( 'PHP %1$s: %2$d days until end-of-life', 'sunsetly' ), $php['branch'], $php['days_security'] ) : /* translators: %s: PHP branch. */ sprintf( __( 'PHP %s is end-of-life', 'sunsetly' ), $php['branch'] ) ); ?>

'; echo 'Sunsetly: '; $items = array(); foreach ( $by_slug[ $slug ] as $f ) { $items[] = esc_html( strtoupper( $f['severity'] ) . ' — ' . $f['title'] . '. ' . $f['fix'] ); } echo implode( '
', $items ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. echo '

'; }, 20 ); } }