[wp-hackers] Admin notices
John 3:16 Media
wp at john316media.com
Mon Apr 11 06:37:33 UTC 2011
That is useful for turning 4 lines of code into one, but still a paint to
type for each message. I make it easier with this function in each of my
plugins:
if (!function_exists('_adminmsg')) {
// A function to hook into admin_notices and either display an updated or
error message.
function _adminmsg($msg, $type = 'msg') {
if (!isset($msg)) {
// No message was set, no point in displaying an empty notice box
return false;
}
if (($type === 'msg') || ($type === 'message')) {
add_action('admin_notices', create_function('', 'echo \'<div id="message"
class="updated"><p>' . $msg . '</p></div>\';'));
return true;
}
if (($type === 'err') || ($type === 'error')) {
add_action('admin_notices', create_function('', 'echo \'<div id="message"
class="error"><p>' . $msg . '</p></div>\';'));
return true;
}
// Not a valid type
return false;
}
}
Then I just call _adminmsg('my message here');
The purpose was to reallly make sure I wasn't reinventing someting core
already does, but apparantly not, though I think its useful and should be
part of the plugin API per scribu's comment it dosen't seem like such a
function would make it into core.
On Sun, Apr 10, 2011 at 11:26 PM, Ryan McCue <lists at rotorised.com> wrote:
> Rob Miller wrote:
> > No need to target 5.3+; you can do anonymous functions in PHP 4.0+:
> >
> > add_action('admin_notices', create_function('', 'echo "your message";'));
>
> True, and good point! They just don't look as nice. ;)
>
> --
> Ryan McCue
> <http://ryanmccue.info/>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
I'm working on a support ticket plugin and I'm looking for users to test and
provide feedback on it. Will bribe anyone who helps with a generous
discount on the final product. Email me off-list if interested.
More information about the wp-hackers
mailing list