| 775 | /** |
| 776 | * Plugin API Function to add a message in admin_notices using standard formatting. |
| 777 | * Plugin author calls this function passes is tthe type ('updated' or 'error') and |
| 778 | * the message, which is added to a global array for use by _display_admin_notices |
| 779 | * which is hooked into admin_notices and echo's out all notices in the array. |
| 780 | * |
| 781 | * @package WordPress |
| 782 | * @subpackage Plugin |
| 783 | * @access public |
| 784 | * @link http://core.trac.wordpress.org/ticket/12738 |
| 785 | * |
| 786 | * @global array $admin_notices |
| 787 | * @param string $type Identify's the type of message being displayed, should be either 'updated' or 'error'. |
| 788 | * @param string $message String to store the message contents, can use HTML. |
| 789 | * @return bool True on success, False on fail/error |
| 790 | */ |
| 791 | function add_admin_notice($type = 'updated', $message = '') { |
| 792 | global $admin_notices; |
| 793 | |
| 794 | if (strtolower($type) == 'updated' && $message != '') { |
| 795 | $admin_notices[] = array('updated', $message); |
| 796 | return true; |
| 797 | } |
| 798 | |
| 799 | if (strtolower($type) == 'error' && $message != '') { |
| 800 | $admin_notices[] = array ('error', $message); |
| 801 | return true; |
| 802 | } |
| 803 | |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Iterates though the global variable $admin_notices to be displayed and echo's |
| 809 | * out the notices in the standard formatted output. Executed by admin_notices hook. |
| 810 | * |
| 811 | * @package WordPress |
| 812 | * @subpackage Plugin |
| 813 | * @access private |
| 814 | * @link http://core.trac.wordpress.org/ticket/12738 |
| 815 | * |
| 816 | * @global array $admin_notices |
| 817 | */ |
| 818 | function _display_admin_notices() { |
| 819 | global $admin_notices; |
| 820 | |
| 821 | foreach ((array) $admin_notices as $notice) { |
| 822 | echo '<div id="message" class="' . $notice[0] . '"><p>' . $notice[1] . '</p></div>'; |
| 823 | } |
| 824 | } |
| 825 | add_action('admin_notices', '_display_admin_notices'); |