[wp-trac] [WordPress Trac] #34669: Custom back_link in wp_die and provide a filter
WordPress Trac
noreply at wordpress.org
Thu Nov 12 17:21:18 UTC 2015
#34669: Custom back_link in wp_die and provide a filter
----------------------------+-----------------------------
Reporter: eventualo | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: trunk
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
At the moment, inside `_default_wp_die_handler` function, the
`$args['back_link']` (boolean) set to true allow to show a generic
javascript back link: `<a href='javascript:history.back()'>`.
I know that it's possibile to write own function handler using
`wp_die_handler` filter, but accepting a custom back url, and not only a
boolean, could be an easy way without rewrite all the function.
In some cases it could be useful, here is an example.
I wrote a plugin that creates custom roles with custom caps. I use the
meta cap filter to let user of custom roles to edit users of other roles,
but not admin users.
So when an user of custom roles tries to bulk edit/promote/delete admin
and not-admin users together, the user gets a wp_die message like: ''You
can’t edit that user.''.
When the user goes back with browser, the user will see again the old
users page with old (and wrong) info, because the bulk action has edited
properly the not-admin users and leave the admins untouch.
I think it could be useful to provide the back url to wp_die message, so
you can load the updated version of previous page.
I propose that `$args['back_link']` can accept 3 types of values:
- `false`: no back link shown (as now);
- `true`: show javascript back link shown (as now);
- `{url}`: show passed url.
In this way I can use `wp_die` for custom messages in my plugin pages,
like:
`wp_die( 'Error message', '', array( 'back_link' =>
admin_url('whatever.php') ) );`
Then, it could be useful to have a filter inside `_default_wp_die_handler`
function to customise error messages of default dashboard pages.
We could use the arguments (`$message`, `$title`, `$args`) to provide
context to the filter, e.g.:
`apply_filters( 'default_wp_die_handler_back_link', $r['back_link'],
$title, $args )`
`apply_filters( 'default_wp_die_handler_back_link_'.sanitize_key( $title
), $r['back_link'], $args )`
Or maybe use `wp_get_referer` to add more context.
I hope my explanation has been clear.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34669>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list