', '' ); } return $message; }, 10, 2 ); add_filter( 'adminoptim_notification_banner_content_' . self::SECTION_ID, static function (): array { $content = [ [ 'message' => sprintf( /* translators: 1: Opening strong tag, 2: Closing strong tag. */ __( '%1$sStronger login protection, practical hardening, fewer unnecessary WordPress exposure points.%2$s Leave a ★★★★★ review on WordPress.org and help others to improve their site security.', 'admin-optimizer' ), '', '' ), 'cta_type' => 'review', ], [ 'message' => sprintf( /* translators: 1: Opening strong tag, 2: Closing strong tag. */ __( '%1$sHaving issues with Admin Optimizer security tools?%2$s', 'admin-optimizer' ), '', '' ), 'cta_type' => 'support', ], ]; return $content[ wp_rand( 0, 1 ) ]; }, ); } /** * Remove entries from the HTTP header * * @return void */ public function configure_http_header() { if ( headers_sent() ) { return; } if ( Module_Registry::is_enabled( 'remove_pingback_header' ) ) { header_remove( 'X-Pingback' ); } if ( Module_Registry::is_enabled( 'remove_powered_by_header' ) ) { header_remove( 'X-Powered-By' ); } } /** * Ordinary module IDs this Section owns, mapped to their navigation labels. * * @return array */ protected function section_nav_modules(): array { return [ 'security_monitor' => 'Security Monitor', 'block_login' => 'Block Failed Login', 'two_factor_authentication' => 'Two-factor Authentication', 'custom_login_url' => 'Custom Login URL', ]; } /** * Section-owned "Hardening" presentation group of lightweight * SECTION_FEATURE capabilities. * * @return array{label:string,description:string,members:array} */ protected function section_feature_group(): ?array { return [ 'label' => __( 'Hardening', 'admin-optimizer' ), 'description' => __( 'Strengthen WordPress security by reducing unnecessary exposure and disabling commonly abused features.', 'admin-optimizer' ), 'members' => [ 'disable_xmlrpc', 'hide_wp_version', 'remove_pingback_header', 'remove_powered_by_header', 'remove_rest_api_link', 'remove_rsd', 'remove_shortlink', ], ]; } /** * Report the Hardening group to Security Monitor's Site Health tab as one * aggregate row. Reads only each toggle's enabled state from the registry. * * @param array $items Items collected so far. * * @return array */ public function add_hardening_site_health_item( $items ) { $items = is_array( $items ) ? $items : []; $group = $this->section_feature_group(); $members = is_array( $group ) ? $group['members'] : []; $applied = 0; foreach ( $members as $module_id ) { if ( Module_Registry::is_enabled( $module_id ) ) { ++$applied; } } $items[] = self::build_hardening_site_health_item( $applied, count( $members ), admin_url( 'admin.php?page=' . self::PAGE_SLUG ) ); return $items; } /** * Build the Hardening Site Health row. Pure, so the wording can be tested. * * @param int $applied Hardening options turned on. * @param int $total Hardening options available. * @param string $url Link to the Security section. * * @return array */ public static function build_hardening_site_health_item( int $applied, int $total, string $url ): array { return [ 'id' => 'hardening', 'label' => __( 'Hardening', 'admin-optimizer' ), /* translators: 1: options applied, 2: options available. */ 'value' => sprintf( __( '%1$d of %2$d applied', 'admin-optimizer' ), $applied, $total ), 'status' => 'info', 'url' => $url, 'link_label' => __( 'Open Hardening', 'admin-optimizer' ), 'priority' => 50, ]; } }