#12738 closed feature request (wontfix)
Notice Helper
Reported by: | andddd | Owned by: | john316media |
---|---|---|---|
Milestone: | Priority: | lowest | |
Severity: | minor | Version: | |
Component: | Plugins | Keywords: | has-patch |
Focuses: | Cc: |
Description
It would be useful if the next WP release will contain notice helper function in plugins API or somewhere in WP utils.
All plugin developers are often using standard WP admin notices which is simply a line of HTML:
<div class="updated fade"><p>Some message.</p></div>
I didn't find any function to produce this HTML code so I'm using my own but it's boring to move same function from one plugin to another.
My notice helper code:
function html_notice_helper($message, $type = 'updated', $echo = true) { $text = '<div class="' . $type . ' fade"><p>' . $message . '</p></div>'; if($echo) echo $text; return $text; }
Attachments (1)
Change History (16)
#1
@
15 years ago
- Milestone changed from 2.9.3 to Future Release
- Type changed from enhancement to feature request
#4
@
14 years ago
The function that I mentioned in my ticket is just an example. admin_notice looks good.
#6
@
14 years ago
THe one issue with this is you still have to hook into admin_notices and have a function that calls this helper function to generate the message. What I do in my plugins is I create a global array, each element of the array is then another array consisting of the message type "updated" or "error" the the message. I then hook into admin_noteces once and itterate though the array echoing out the appropriatie divs and messages. Perhaps that might be something that could be implimented, then its as simple as
global $admin_notices; $admin_notices[] = array('updated', 'Hello World!');
then core would handle the rest. Or you could have a function that you pass the message type and the message content into and it could add it to the global array for the developer than it's as easy as:
add_admin_notice('updated', 'Hello World!');
If this is something you think would work, I can attach a diff of the code I use in my plugins to do this.
#8
@
14 years ago
- Keywords has-patch added
- Owner set to john316media
- Status changed from assigned to accepted
I opted to include a function that handles adding the message to the global array for the plugin author, to make their life easy. Though thats just one function and can easily be removed if necessary.
#9
@
14 years ago
I really don't see why we need this.
Why do we need to store all these notices in another global rather than plugins hooking in a function as they have always done.
#10
@
14 years ago
As is each message I need to show requires 4 lines of code
add_action('admin_notices', 'some_function_name'); function some_function_name() { echo '<div id="message" class="updated"><p>Hello World!</p></div>'; }
At its simplest, this way to make the same message all it would take is
add_admin_notice('updated', 'Hello World!');
What looks simpler to you? 4 lines becomes 1 line, multiply this by the number fo messages a given plugin needs to display and thats alot of extra typing saved for the plugin authoer, makes things easier and does this really overbloat core? I personally don't think so.
#11
@
14 years ago
westi, we need this because every plugin has this function and it kinda frustrating to copy-n-paste this stuff from plugin to plugin.
#14
follow-up:
↓ 15
@
10 years ago
- Resolution set to maybelater
- Status changed from accepted to closed
This isn't something that is really core territory, and the advantage posed is extremely minimal
#15
in reply to:
↑ 14
@
10 years ago
- Milestone Future Release deleted
- Resolution changed from maybelater to wontfix
Replying to chriscct7:
This isn't something that is really core territory, and the advantage posed is extremely minimal
I agree, and the current admin_notices hook covers adding notices nicely, albeit duplicative.
I don't think there is a need for a function to output a div. If used it core, it would make the code harder to read in my opinion.
Also, 2.9.3 will be a bug fix release if necessary. And as we are past feature freeze for 3.0, I'm moving to future release milestone. I'll let someone else close it if they also think it has no place in core.