Make WordPress Core

Opened 15 years ago

Closed 10 years ago

Last modified 10 years ago

#12738 closed feature request (wontfix)

Notice Helper

Reported by: andddd's profile andddd Owned by: john316media's profile 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)

plugin.diff (1.9 KB) - added by john316media 14 years ago.

Download all attachments as: .zip

Change History (16)

#1 @jorbin
15 years ago

  • Milestone changed from 2.9.3 to Future Release
  • Type changed from enhancement to feature request

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.

#2 @andddd
15 years ago

This function is like a selected/checked helper functions in WP.

#3 @scribu
14 years ago

I think this would be useful too. I would name it admin_notice() though.

#4 @andddd
14 years ago

The function that I mentioned in my ticket is just an example. admin_notice looks good.

#5 @westi
14 years ago

  • Owner westi deleted
  • Status changed from new to assigned

#6 @john316media
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.

Last edited 14 years ago by john316media (previous) (diff)

#7 @john316media
14 years ago

  • Cc john316media added

#8 @john316media
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.

@john316media
14 years ago

#9 @westi
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 @john316media
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.

Last edited 14 years ago by john316media (previous) (diff)

#11 @andddd
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.

#12 @andddd
14 years ago

<div class="updated">Oh, c'mon westi</div>

#13 @freshman66
13 years ago

  • Cc freshman66 added

#14 follow-up: @chriscct7
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 @DrewAPicture
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.

Note: See TracTickets for help on using tickets.