Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active May 4, 2016 13:11
Show Gist options
  • Save glueckpress/26b791ab52d5c197ef0c to your computer and use it in GitHub Desktop.
Save glueckpress/26b791ab52d5c197ef0c to your computer and use it in GitHub Desktop.
[WordPress] Mini plugin to display a random admin notice in the back-end. 📢 Use URL parameters to control count and type. Handy test tool for https://wordpress.org/plugins/wp-notification-center/
<?php
/**
* Plugin Name: Notifications FFS!
* Description: Gimme some dang old notifications to test that awesome <a href="https://wordpress.org/plugins/wp-notification-center/">WP Notification Center plugin</a>!
* Version: 0.1
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress
* License: GNU General Public License v3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Requires PHP: 5.3.0
* Requires WP: 4.3
*/
if( ! defined( 'ABSPATH' ) )
exit;
/**
* Displays a random notification in the backend.
* @return void
*/
function notifications_ffs() {
add_action( 'admin_notices', function () {
$hell_ya = (array) __gimme_notifications();
printf( '<div class="%2$s notice"><p>%1$s</p></div>', $hell_ya[ 'msg' ], $hell_ya[ 'class' ] );
} );
}
add_action( 'plugins_loaded', 'notifications_ffs' );
/**
* Random notification message.
* @return array Class name and text for message
*/
function __gimme_notifications() {
$messages = array(
array(
'class' => 'notice-success',
'msg' => 'Heck, yeah! You’ve DONE it!!! It’s all good! Whatever it was, this little box here is telling you right now that you’ve succeeded. Congrats, sweetheart! You’ve earned yourself a treat. <a href="https://www.youtube.com/watch?v=vnDTSq3HmNo">Take it!</a>'
),
array(
'class' => 'notice-error',
'msg' => 'BOOM, HA! Broken! Everything is! A bigass error has occurred, and here’s the freakin’ bill of service.<br /><br />Hm. Actually it can’t be that bad. This shit still works.<br />Whatever.'
),
array(
'class' => 'notice-warning',
'msg' => 'You’ve been warned! Right now. Of whatever. Mermaids, maybe? Anyway, this is a warning, and you should be thoughtful now.'
),
);
shuffle( $messages );
$randomized = mt_rand( 0, count( $messages ) - 1 );
return $messages[ $randomized ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment