builder
2 weeks ago
admin.php
2 weeks ago
ajax-actions.php
8 months ago
class-about.php
2 weeks ago
class-editor.php
1 year ago
class-menu.php
5 months ago
class-notices.php
1 year ago
class-review.php
5 months ago
class-settings.php
9 months ago
class-welcome.php
6 months ago
settings-api.php
2 months ago
class-notices.php
140 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Admin notices, on the fly. |
| 5 | * |
| 6 | * @example |
| 7 | * WPForms_Admin_Notice::success( 'All is good!' ); |
| 8 | * |
| 9 | * @example |
| 10 | * WPForms_Admin_Notice::warning( 'Do something please.' ); |
| 11 | * |
| 12 | * @since 1.3.9 |
| 13 | * @deprecated 1.7.2 |
| 14 | */ |
| 15 | class WPForms_Admin_Notice { |
| 16 | |
| 17 | /** |
| 18 | * Single instance holder. |
| 19 | * |
| 20 | * @since 1.3.9 |
| 21 | * @var mixed |
| 22 | */ |
| 23 | private static $_instance = null; |
| 24 | |
| 25 | /** |
| 26 | * Added notices. |
| 27 | * |
| 28 | * @since 1.3.9 |
| 29 | * @var array |
| 30 | */ |
| 31 | public $notices = []; |
| 32 | |
| 33 | /** |
| 34 | * Get the instance. |
| 35 | * |
| 36 | * @since 1.3.9 |
| 37 | * @return WPForms_Admin_Notice |
| 38 | */ |
| 39 | public static function getInstance() { |
| 40 | |
| 41 | if ( self::$_instance === null ) { |
| 42 | self::$_instance = new WPForms_Admin_Notice(); |
| 43 | } |
| 44 | |
| 45 | return self::$_instance; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Hook when called. |
| 50 | * |
| 51 | * @since 1.3.9 |
| 52 | */ |
| 53 | public function __construct() { |
| 54 | |
| 55 | _deprecated_function( __METHOD__, '1.7.2 of the WPForms plugin' ); |
| 56 | |
| 57 | add_action( 'admin_notices', [ &$this, 'display' ] ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Display the notices. |
| 62 | * |
| 63 | * @since 1.3.9 |
| 64 | */ |
| 65 | public function display() { |
| 66 | |
| 67 | // At least one WPForms capability is necessary to see admin notices. |
| 68 | if ( ! wpforms_current_user_can( 'any' ) ) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 73 | echo implode( ' ', $this->notices ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Add notice to instance property. |
| 78 | * |
| 79 | * @since 1.3.9 |
| 80 | * |
| 81 | * @param string $message Message to display. |
| 82 | * @param string $type Type of the notice (default: ''). |
| 83 | */ |
| 84 | public static function add( $message, $type = '' ) { |
| 85 | |
| 86 | _deprecated_function( __METHOD__, '1.7.2 of the WPForms plugin' ); |
| 87 | |
| 88 | $instance = self::getInstance(); |
| 89 | $id = 'wpforms-notice-' . ( count( $instance->notices ) + 1 ); |
| 90 | $type = ! empty( $type ) ? 'notice-' . $type : ''; |
| 91 | $notice = sprintf( '<div class="notice wpforms-notice %s" id="%s">%s</div>', $type, $id, wpautop( $message ) ); |
| 92 | |
| 93 | $instance->notices[] = $notice; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Add Info notice. |
| 98 | * |
| 99 | * @since 1.3.9 |
| 100 | * |
| 101 | * @param string $message Message to display. |
| 102 | */ |
| 103 | public static function info( $message ) { |
| 104 | self::add( $message, 'info' ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Add Error notice. |
| 109 | * |
| 110 | * @since 1.3.9 |
| 111 | * |
| 112 | * @param string $message Message to display. |
| 113 | */ |
| 114 | public static function error( $message ) { |
| 115 | self::add( $message, 'error' ); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Add Success notice. |
| 120 | * |
| 121 | * @since 1.3.9 |
| 122 | * |
| 123 | * @param string $message Message to display. |
| 124 | */ |
| 125 | public static function success( $message ) { |
| 126 | self::add( $message, 'success' ); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Add Warning notice. |
| 131 | * |
| 132 | * @since 1.3.9 |
| 133 | * |
| 134 | * @param string $message Message to display. |
| 135 | */ |
| 136 | public static function warning( $message ) { |
| 137 | self::add( $message, 'warning' ); |
| 138 | } |
| 139 | } |
| 140 |