#2090 closed defect (bug) (fixed)
New Filters for Topic/Reply Admin Links
Reported by: | mordauk | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | 2.4 | Priority: | normal |
Severity: | normal | Version: | trunk |
Component: | API - Actions/Filters | Keywords: | has-patch |
Cc: |
Description
While working on a new bbPress [extension](https://twitter.com/pippinsplugins/status/277092946069831681) I found that I wanted to add new links to the Topic / Reply admin links.
The links are setup with the bbp_get_reply_admin_links()
and bbp_get_topic_admin_links()
functions, both of which send the final HTML through a filter before it is returned.
The problem with these two filters, is that anyone who wants to tie into them will have to do some hacky things to properly add a new admin link.
Let's assume I want to add a new "Add Note" link at the start or end of the admin links list. I would do something like this:
function sample_add_bbp_admin_link( $links, $args ) { $links .= '<a href="#">some link</a>'; return $links; } add_filter( 'bbp_get_topic_admin_links', 'sample_add_bbp_admin_link', 10, 2 );
But this will result in this:
<span class="bbp-admin-links"> <a href="forums/topic/i-found-a-bug/edit/">Edit</a> | <a href="/wpms/sub/forums/topic/i-found-a-bug/?action=bbp_toggle_topic_close&topic_id=90&_wpnonce=adbde4f67e">Close</a> | <a href="/wpms/sub/forums/topic/i-found-a-bug/?action=bbp_toggle_topic_stick&topic_id=90&_wpnonce=40ae9c144b">Stick</a> (<a href="/wpms/sub/forums/topic/i-found-a-bug/?action=bbp_toggle_topic_stick&topic_id=90&super=1&_wpnonce=40ae9c144b">to front</a>) | <a href="forums/topic/i-found-a-bug/edit/?action=merge">Merge</a> | <a title="Move this item to the Trash" href="/wpms/sub/forums/topic/i-found-a-bug/?action=bbp_toggle_topic_trash&sub_action=trash&topic_id=90&_wpnonce=62ad135be0">Trash</a> | <a href="/wpms/sub/forums/topic/i-found-a-bug/?action=bbp_toggle_topic_spam&topic_id=90&_wpnonce=49d9a0e0c0">Spam</a> </span> <a href="#">some link</a>
Note that the new HTML is outside of the SPAN tag.
In order to properly place my link inside of the before/after elements, I would have to do some hacky stuff with str_replace().
I propose that a new filter gets added for each admin links function where the links array is setup, like so:
if ( empty( $r['links'] ) ) { $r['links'] = apply_filters( 'bbp_topic_admin_links', array( 'edit' => bbp_get_topic_edit_link ( $r ), 'close' => bbp_get_topic_close_link( $r ), 'stick' => bbp_get_topic_stick_link( $r ), 'merge' => bbp_get_topic_merge_link( $r ), 'trash' => bbp_get_topic_trash_link( $r ), 'spam' => bbp_get_topic_spam_link ( $r ), ), $r['id'] ); }
This would make it much easier and practical to add new links. Instead of using str_replace (or some other hacky method), we could just do this:
function sample_add_bbp_admin_link( $links, $topic_id ) { $links['add_note'] = '<a href="' . some_function( $topic_id ) . '">some link</a>'; return $links; } add_filter( 'bbp_topic_admin_links', 'sample_add_bbp_admin_link', 10, 2 );
Attachments (1)
Change History (13)
#1
@
12 years ago
- Component changed from General to Actions/Filters
- Keywords has-patch added
- Version changed from 2.1 to trunk
#4
@
11 years ago
- Milestone changed from 2.3 to 2.3.3
- Resolution fixed deleted
- Status changed from closed to reopened
I'm loving the new filters on reply and topic admin links, with one exception. All of the admin buttons allow you to pass the button creation function an argument which allows the customization of the inner HTML. This is great because I can do cool things like put Font Awesome (or other icon fonts) inside the button link. For example:
bbp_get_topic_edit_link ( array( 'edit_text' => '<i class="icon-edit"></i>Edit' ) );
Unfortunately, bbp_get_topic_trash_link() runs esc_html() on this argument which escapes my icon. I suggest that esc_html() be removed from the trash link function as a developer supplied argument should hardly be treated as "untrusted" by its own theme.
The same problem affects a few other admin links as well: bbp_get_reply_trash_link(), bbp_get_topic_split_link(), and bbp_get_reply_move_link(). It would really be great to get these escapes removed. Considering it would be a super quick fix, I hope this could maybe be squeezed in for 2.4.
#5
@
11 years ago
On a very related note... it would be really nice to get rid of the mandatory parenthesis that wrap the super sticky button in bbp_get_topic_stick_link(). They aren't even inside an HTML element, so there's not even a easy way to hide them using CSS. At the moment I make the font color of the parent container transparent, but it would be nice if I had the option not to output them in the first place.
#6
@
11 years ago
- Milestone changed from 2.3.3 to 2.4
Moving to 2.4 to shift around some of the escaping for you.
#7
@
11 years ago
- Owner set to johnjamesjacoby
- Resolution set to fixed
- Status changed from reopened to closed
In 5069:
Adds filters to the admin links array