* Admin notices, on the fly.
* WPForms_Admin_Notice::success( 'All is good!' );
* WPForms_Admin_Notice::warning( 'Do something please.' );
class WPForms_Admin_Notice {
* Single instance holder.
private static $_instance = null;
* @return WPForms_Admin_Notice
public static function getInstance() {
if ( self::$_instance === null ) {
self::$_instance = new WPForms_Admin_Notice();
public function __construct() {
_deprecated_function( __METHOD__, '1.7.2 of the WPForms plugin' );
add_action( 'admin_notices', [ &$this, 'display' ] );
public function display() {
// At least one WPForms capability is necessary to see admin notices.
if ( ! wpforms_current_user_can( 'any' ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo implode( ' ', $this->notices );
* Add notice to instance property.
* @param string $message Message to display.
* @param string $type Type of the notice (default: '').
public static function add( $message, $type = '' ) {
_deprecated_function( __METHOD__, '1.7.2 of the WPForms plugin' );
$instance = self::getInstance();
$id = 'wpforms-notice-' . ( count( $instance->notices ) + 1 );
$type = ! empty( $type ) ? 'notice-' . $type : '';
$notice = sprintf( '<div class="notice wpforms-notice %s" id="%s">%s</div>', $type, $id, wpautop( $message ) );
$instance->notices[] = $notice;
* @param string $message Message to display.
public static function info( $message ) {
self::add( $message, 'info' );
* @param string $message Message to display.
public static function error( $message ) {
self::add( $message, 'error' );
* @param string $message Message to display.
public static function success( $message ) {
self::add( $message, 'success' );
* @param string $message Message to display.
public static function warning( $message ) {
self::add( $message, 'warning' );