[wp-trac] [WordPress Trac] #11515: Admin needs standardized way of handling messages (notices) displayed to the user
WordPress Trac
noreply at wordpress.org
Fri Mar 15 23:39:26 UTC 2013
#11515: Admin needs standardized way of handling messages (notices) displayed to
the user
------------------------------------------+-----------------------------
Reporter: filosofo | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Administration | Version: 3.0
Severity: normal | Resolution:
Keywords: error-message admin-messages |
------------------------------------------+-----------------------------
Comment (by obenland):
I thought about this a little bit and prepared a pretty big patch,
deprecating `*_settings_error()`, coming up with a way for a global
approach to this, and updating all existing notices to follow the new API
(which makes the patch fairly big).
[[BR]]
Given the size of the patch, I thought I'd test the waters with small
gist, outlining the essentials of what I had in mind:
'''https://gist.github.com/obenland/5173811'''
[[BR]]
* I chose the name "admin notice" because it is already fairly established
and can be used globally in the admin, outside of just settings pages.
* `do_admin_notices()` would run on every admin page load by default. That
means that admin notices should not be added unless they are indeed
supposed to be displayed. The global gets unset so it doesn't get saved on
shutdown.
* On shutdown, all "registered" (added) admin notices would be saved
(either to the database or to a cookie), specific to the current user.
* On init of the next page load, we check if any notices were saved, and
if so, add them back to the global array of notices.
* We would deprecate `add_settings_error()`, `get_settings_errors()`, and
`settings_errors()`.
Example for a use case where the admin notices would get saved:
{{{
#!php
// How it's currently done:
// See: http://core.trac.wordpress.org/browser/trunk/wp-
admin/comment.php#L96
if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
wp_redirect( admin_url('edit-comments.php?error=2') );
die();
}
//How it could be done:
// No error handling in edit-comments.php necessary.
if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) {
add_admin_notice( 'edit-comments', __( 'You are not allowed to
edit comments on this post.' ) );
wp_redirect( admin_url( 'edit-comments.php' ) );
die();
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11515#comment:18>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list