Last active
July 17, 2019 17:33
-
-
Save nathanielks/8910601 to your computer and use it in GitHub Desktop.
Simple method to add a notice to the WP Admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "nathanielks/wp-admin-notice", | |
"type": "library", | |
"license": "GPL-2.0+", | |
"description": "A simple class for displaying admin notices in the WordPress admin.", | |
"homepage": "https://gist.github.com/nathanielks/8910601.git", | |
"authors": [ | |
{ | |
"name": "Nathaniel Schweinberg", | |
"email": "nathaniel@fightthecurrent.org", | |
"homepage": "http://fightthecurrent.org" | |
} | |
], | |
"autoload": { | |
"psr-4": { "": "" } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WP_Admin_Notice { | |
public $class = ''; | |
public $message = ''; | |
function __construct( $message, $class = 'updated' ){ | |
$this->class = $class; | |
$this->message = $message; | |
add_action( 'admin_notices', array( $this, 'output' ) ); | |
add_action( 'network_admin_notices', array( $this, 'output' ) ); | |
} | |
function output(){ | |
echo '<div id="message" class="' . $this->class .'"><p>' . $this->message . '</p></div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment