'yes-alt',
'warning' => 'warning',
'error' => 'dismiss',
'info' => 'info',
);
$icon = isset( $icons[ $type ] ) ? $icons[ $type ] : 'info';
$html = '
';
$html .= '';
$html .= '' . esc_html( $message ) . '';
$html .= '
';
if ( $echo ) {
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $html is assembled entirely from values escaped above with esc_attr() and esc_html()
} else {
return $html;
}
}
/**
* Render notice based on URL parameter
*
* @param array $notice_map Array of notice_key => ['type' => 'success', 'message' => 'Text']
*/
public static function render_from_url( $notice_map ) {
$notice_key = isset( $_GET['gp_notice'] ) ? sanitize_text_field( wp_unslash( $_GET['gp_notice'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display routing key, sanitized and only used to look up a static notice; no state change
if ( empty( $notice_key ) || ! isset( $notice_map[ $notice_key ] ) ) {
return;
}
$notice = $notice_map[ $notice_key ];
self::render( $notice['type'], $notice['message'] );
}
/**
* Render scan result notice
*/
public static function render_scan_result( $changed, $new, $deleted ) {
$total_issues = $changed + $new + $deleted;
$summary = sprintf(
/* translators: 1: number of changed files, 2: number of new files, 3: number of deleted files. */
__( 'Scan completed: %1$d changed, %2$d new, %3$d deleted', 'ai-cyberguard' ),
$changed, $new, $deleted
);
self::render( $total_issues > 0 ? 'warning' : 'success', $summary );
}
}