Skip to content

Instantly share code, notes, and snippets.

@nathanielks
Last active July 17, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanielks/8910601 to your computer and use it in GitHub Desktop.
Save nathanielks/8910601 to your computer and use it in GitHub Desktop.
Simple method to add a notice to the WP Admin
{
"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": { "": "" }
}
}
<?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