true ) ); CSDT_Ajax::register( 'wp_ajax_csdt_cve_checks_enable_lookups', array( 'CSDT_Cve_Checks', 'ajax_enable_lookups' ), array( 'refuse_test_session' => true ) ); CSDT_Ajax::register( 'wp_ajax_csdt_cve_checks_dismiss', array( 'CSDT_Cve_Checks', 'ajax_dismiss' ) ); } // ── State ────────────────────────────────────────────────────────────── /** * Which checks are on. Reads options only. * * @return array{php:bool,lookups:bool} */ public static function state(): array { return array( self::PHP => class_exists( 'CSDT_Php_Advisory' ) && CSDT_Php_Advisory::is_enabled(), self::LOOKUPS => class_exists( 'CSDT_Vuln_Recheck' ) && CSDT_Vuln_Recheck::is_enabled(), ); } /** * The checks that are off, in display order. * * @param array|null $state state(), or null to read it. * @return string[] Subset of PHP, LOOKUPS. */ public static function off( ?array $state = null ): array { $state = null === $state ? self::state() : $state; $out = array(); foreach ( array( self::LOOKUPS, self::PHP ) as $which ) { if ( empty( $state[ $which ] ) ) { $out[] = $which; } } return $out; } /** * A check's name, as the notice, the finding and the report print it. * * @param string $which PHP or LOOKUPS. * @return string */ public static function label( string $which ): string { return self::PHP === $which ? 'PHP advisory alerts' : 'CVE lookups'; } /** * What switching a check on sends, in one short sentence. One wording for the notice, the * panels, the finding and the report, matching readme.txt's External services entries. * * @param string $which PHP or LOOKUPS. * @return string */ public static function sends( string $which ): string { if ( self::PHP === $which ) { return 'Downloads a public list of php.net security releases from api.cloudscale.consulting every 6 hours. Sends nothing about this site.'; } return 'Once a day, sends each installed plugin and theme slug, your WordPress version and server software versions to api.cloudscale.consulting, one per request, never your site URL. Also turns on the own-IP lookup fallback.'; } /** The button text for a check. */ public static function button_text( string $which ): string { return self::PHP === $which ? 'Turn on PHP advisory alerts' : 'Turn on CVE lookups'; } // ── The notice ───────────────────────────────────────────────────────── /** * Whether a screen is one of this plugin's own. WordPress gives the one page three hook * suffixes (see CSDT_DevTools::enqueue_admin_assets()); the screen id is the same string. * * @param string $screen_id get_current_screen()->id. * @return bool */ public static function is_plugin_screen( string $screen_id ): bool { $slug = CSDT_DevTools::TOOLS_SLUG; return in_array( $screen_id, array( 'toplevel_page_' . $slug, 'tools_page_' . $slug, 'admin_page_' . $slug ), true ); } /** * Whether this user dismissed the notice less than SNOOZE ago. * * @param int $user_id User. * @param int $now Time. * @return bool */ public static function is_snoozed( int $user_id, int $now ): bool { if ( $user_id <= 0 ) { return false; } $at = (int) get_user_meta( $user_id, self::META_DISMISSED, true ); return $at > 0 && ( $now - $at ) < self::SNOOZE; } /** * Whether the notice shows. Read-only. * * @param string $screen_id Current screen id. * @param int $user_id Current user. * @return bool */ public static function should_show( string $screen_id, int $user_id ): bool { if ( ! self::is_plugin_screen( $screen_id ) || ! current_user_can( 'manage_options' ) ) { return false; } if ( array() === self::off() ) { return false; } return ! self::is_snoozed( $user_id, self::now() ); } /** admin_notices: the prompt, on this plugin's screens only. */ public static function render_notice(): void { try { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; $id = is_object( $screen ) && isset( $screen->id ) ? (string) $screen->id : ''; if ( ! self::should_show( $id, (int) get_current_user_id() ) ) { return; } $off = self::off(); } catch ( \Throwable $e ) { if ( class_exists( 'CSDT_Monitor' ) ) { CSDT_Monitor::log_exception( $e, __METHOD__ ); } return; } $names = array_map( array( __CLASS__, 'label' ), $off ); ?>
'What a default install checks', 'rec' => 'Info', 'html' => '
Nothing on a schedule. A CVE is looked up only when you start a security scan or click Check host software. A vulnerability published after that is not reported until you check again.
', ), array( 'name' => 'PHP advisory alerts', 'rec' => 'Recommended', 'html' => '' . esc_html( self::sends( self::PHP ) ) . ' Alerts when php.net announces or ships a security release for your PHP.
', ), array( 'name' => 'CVE lookups', 'rec' => 'Recommended', 'html' => '' . esc_html( self::sends( self::LOOKUPS ) ) . ' Alerts on a new known vulnerability in anything installed.
', ), array( 'name' => 'Turning them off again', 'rec' => 'Info', 'html' => 'Both switches are on the AI Security Scan tab: CVE Alerts and PHP Advisory Alerts. Untick and save to stop them. Remind me in 30 days hides this notice for you only.
', ), ), '', true ); ?>