report = $report; $this->consent = $consent; } /** * Registers the tests. */ public function register(): void { add_filter( 'site_status_tests', array( $this, 'add_tests' ) ); } /** * Adds direct tests. The PHP test works locally; the plugin test needs consent. * * @param array> $tests Tests. * @return array> */ public function add_tests( $tests ) { if ( $this->consent->granted() ) { $tests['direct']['brachmelder_closed_plugins'] = array( 'label' => __( 'Closed plugins', 'brachmelder' ), 'test' => array( $this, 'test_closed_plugins' ), ); } $tests['direct']['brachmelder_php_support'] = array( 'label' => __( 'PHP security support', 'brachmelder' ), 'test' => array( $this, 'test_php_support' ), ); return $tests; } /** * Are plugins installed that WordPress.org has closed? * * @return array */ public function test_closed_plugins(): array { $closed = $this->report->rows_with_status( array( Status::CLOSED ) ); $result = array( 'label' => __( 'No closed plugins installed', 'brachmelder' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Security', 'brachmelder' ), 'color' => 'blue', ), 'description' => '

' . esc_html__( 'None of your plugins has been closed on WordPress.org.', 'brachmelder' ) . '

', 'actions' => sprintf( '

%s

', esc_url( Page::url() ), esc_html__( 'Open Brachmelder', 'brachmelder' ) ), 'test' => 'brachmelder_closed_plugins', ); if ( empty( $closed ) ) { return $result; } $critical = array_filter( $closed, static function ( array $row ): bool { return $row['critical']; } ); $items = ''; foreach ( $closed as $row ) { $items .= sprintf( '
  • %s – %s
  • ', esc_html( $row['local_name'] ), esc_html( Messages::closed_reason( $row ) ) ); } $result['status'] = empty( $critical ) ? 'recommended' : 'critical'; $result['badge']['color'] = 'red'; $result['label'] = empty( $critical ) ? __( 'Plugins that were closed on WordPress.org are installed', 'brachmelder' ) : __( 'A plugin that was closed because of a security issue is installed', 'brachmelder' ); $result['description'] = '

    ' . esc_html__( 'Closed plugins no longer receive updates. Replace them with actively maintained alternatives.', 'brachmelder' ) . '

      ' . $items . '
    '; return $result; } /** * Does the PHP version still receive security updates? * * @return array */ public function test_php_support(): array { $php = PhpSupport::evaluate( PHP_VERSION, time() ); $texts = Messages::php( $php, PhpSupport::recommended( time() ) ); $status_map = array( PhpSupport::ENDED => 'critical', PhpSupport::ENDING => 'recommended', ); $description = '

    ' . esc_html( $texts['text'] ) . '

    '; if ( isset( $status_map[ $php['status'] ] ) ) { $description .= '

    ' . esc_html( $texts['todo'] ) . '

    '; } return array( 'label' => $texts['title'], 'status' => $status_map[ $php['status'] ] ?? 'good', 'badge' => array( 'label' => __( 'Security', 'brachmelder' ), 'color' => isset( $status_map[ $php['status'] ] ) ? 'red' : 'blue', ), 'description' => $description, 'actions' => '', 'test' => 'brachmelder_php_support', ); } }