One way you can handle this would be to do the wp_sprintf when assigning the value of the $message
variable and then use wp_kses
when you want to output. You could also output the div and paragraph tags before and after the message, which would eliminate the need for wp_sprintf
in this instance.
add_action( 'admin_notices', function() {
$message = __( 'We suggest that you use the <b>API Key file</b> for your API Keys.', 'package-wordpress' );
echo '<div class="notice notice-warning is-dismissible"><p>' . wp_kses( $message, array( 'b' => array() ) ) . '</p></div>';
});
If you wanted to keep it closer to the original you could do something like:
add_action( 'admin_notices', function() {
$class="notice notice-warning is-dismissible";
$message = wp_sprintf( __( '<div class="%s"><p>We suggest that you use the <b>API Key file</b> for your API Keys.</p></div>', 'package-wordpress' ), $class );
echo wp_kses( $message, array(
'div' => array( 'class' => array() ),
'p' => array(),
'b' => array(),
));
});