bbp_reply_admin_links
-
Hi, I want to adapt forum styles for my theme. For example function bbp_reply_admin_links calls a bunch of links with different classes, like bbp-topic-edit-link bb-topic-close link and go on.
Guess only proper way to it via functions.php, but i’m quite new to php. Can someone show an example?
-
not quite sure what you are asking.
If you just want to style, then you would use css rather than php. If you want to change what they do, then you would use php
Can you come back and explain with a specific example what you want to do.
eg I want x to look like this, or do that
Default output looks like
<span class="bbp-admin-links"> // inside different classes of links </span>
I would like change it to
<a class="button"></a>
So I want to delete span from output and use one style for each<a>
link, if its possible.And the thing is – I could do it by modifying forum files, but after update it will be overwritten. So I want to use bbpress functions php file to change output, but I don’t know how. I hope I’ve explained it well 😛
hmmm … if you want each link to be a button, I can point you to some code, but you’ll need to figure it out.
so
so for replies, the function is in
bbpress/includes/replies/template.php
which I think you found.
function bbp_get_reply_admin_links( $args = array() ) { // Parse arguments against default values $r = bbp_parse_args( $args, array( 'id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array() ), 'get_reply_admin_links' ); $r['id'] = bbp_get_reply_id( (int) $r['id'] ); // If post is a topic, return the topic admin links instead if ( bbp_is_topic( $r['id'] ) ) { return bbp_get_topic_admin_links( $args ); } // If post is not a reply, return if ( !bbp_is_reply( $r['id'] ) ) { return; } // If topic is trashed, do not show admin links if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) { return; } // If no links were passed, default to the standard if ( empty( $r['links'] ) ) { $r['links'] = apply_filters( 'bbp_reply_admin_links', array( 'edit' => bbp_get_reply_edit_link ( $r ), 'move' => bbp_get_reply_move_link ( $r ), 'split' => bbp_get_topic_split_link( $r ), 'trash' => bbp_get_reply_trash_link( $r ), 'spam' => bbp_get_reply_spam_link ( $r ), 'reply' => bbp_get_reply_to_link ( $r ) ), $r['id'] ); } // See if links need to be unset $reply_status = bbp_get_reply_status( $r['id'] ); if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id() ) ) ) { // Spam link shouldn't be visible on trashed topics if ( bbp_get_trash_status_id() === $reply_status ) { unset( $r['links']['spam'] ); // Trash link shouldn't be visible on spam topics } elseif ( bbp_get_spam_status_id() === $reply_status ) { unset( $r['links']['trash'] ); } } // Process the admin links $links = implode( $r['sep'], array_filter( $r['links'] ) ); $retval = $r['before'] . $links . $r['after']; return apply_filters( 'bbp_get_reply_admin_links', $retval, $r, $args ); }
which you can filter at the end, but how would depend on your skills.
the span part can be simply changed by putting a filter into your child theme’s function file
eg
add_filter ('bbp_before_get_reply_admin_links_parse_args', 'theredeclipse_change' ) ; function theredeclipse_change ($args) { $args['before'] = '<span class="bbp-admin-links">' ; $args['after'] = '</span>' ; return $args ; }
and just change whatever you want the span part to look like, or just remove it.
if you want to style each link, then you’ll see that there is a call to each separate function
'edit' => bbp_get_reply_edit_link ( $r ), 'move' => bbp_get_reply_move_link ( $r ), 'split' => bbp_get_topic_split_link( $r ), 'trash' => bbp_get_reply_trash_link( $r ), 'spam' => bbp_get_reply_spam_link ( $r ), 'reply' => bbp_get_reply_to_link ( $r )
so to do it in functions, you’d need to go to each one.
you’ll find these in the same file above
since the class is hard coded, you could add a final filter with a preg_replace
eg
add_filter( 'bbp_get_reply_move_link' , 'theredeclipse_move', 10 , 2 ) ; function theredeclipse_move ($retval, $r) { $retval = preg_replace(whatever args you need, with, $retval); return $retval ; }
so $retval will hold the line of code including the class.
so google preg-replace and see if you can get it working !!
I’ve tried at least to change
<span>
like in your example, but it doesn’t work. Aswell tried to pull this out in this way:add_filter ('bbp_reply_admin_links', 'theredeclipse_change' ) ; function theredeclipse_change ($retval, $r) { $r = bbp_parse_args( $args, array( 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', ), 'get_reply_admin_links' ); return $retval ; }
And several attempts more, but nothing happens :[
sorry, this was not meant to be a solution, but rather to point you to then code
'before' => '<span class="bbp-admin-links">', 'after' => '</span>',
is what it currently does, so if you wanted to take out the span entirely you would do
function theredeclipse_change ($args) { $args['before'] = '' ; $args['after'] = '' ; return $args ; }
Suggest you also read up
Thanks for the link, it explains. But can you tell me at least approximate way to call separately avatar and username by this function bbp_reply_author_link? It will help alot
Nvm, got solution:
<?php bbp_reply_author_link( array( 'sep' => '', 'show_role' => false, 'type' => 'name' ) ); ?>
and
<?php bbp_reply_author_link( array( 'sep' => '', 'show_role' => true, 'type' => 'avatar' ) ); ?>
great – glad you’re fixed
Tho still trying to figure out how to replace default classes.
Code in BBpress:
// Link class $link_class = ' class="bbp-author-' . esc_attr( $r['type'] ) . '"'; // Add links if not anonymous and existing user if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { // Assemble the links foreach ( $author_links as $link => $link_text ) { $link_class = ' class="bbp-author-' . $link . '"'; $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text ); }
Hook:
function hw_get_reply_author_link($link_class) { $link_class = preg_replace('/ class="bbp-author-"/','/ class="myclass" /',$link_class); return $link_class; } add_filter('bbp_get_reply_author_link','hw_get_reply_author_link');
Cant make this work. Well output itself works as should, but it doesn’t replace bbp-author- to myclass. Can you tell me what’s wrong with it?
where does that source code sit – file and line please
Oh, code located in /includes/replies/template.php, line 1241
Any idea how to do this please?
sorry, was over the weekend.
I will respond when I get a moment
just looked,
The foreach loop produces
class="bbp-author-avatar" class="bbp-author-name" class="bbp-author-role"
so
class="bbp-author-"
is never matched as you have ” at the end
function hw_get_reply_author_link($link_class) { $link_class = preg_replace('/ class="bbp-author-/',' class="myclass-',$link_class); return $link_class; } add_filter('bbp_get_reply_author_link','hw_get_reply_author_link');
will get you
class="myclass-avatar" class="myclass-name" class="myclass-role"
if that’s what you are after
Thanks a lot, it works now! I’ve removed “class=”bbp-author-” and rest of the code doesn’t display so its suits perfectly for me.
Now I trying to change args of bbp_get_reply_admin_links (stored in bbpress/includes/replies/template.php)
Thats my hook
function hw_get_reply_admin_links ($args) { $args = array ( 'before' => '<div class="list">', 'after' => '</div>', ); return $args; } add_filter ('bbp_get_reply_admin_links', 'hw_get_reply_admin_links' );
What’s wrong here?
$args is only the 3rd argument of the bbp_get_reply_admin_links function !
So if you want to deal with the args, it should be:function hw_get_reply_admin_links ($retval, $r, $args) { $args = array ( 'before' => '<div class="list">', 'after' => '</div>', ); return $retval; } add_filter ('bbp_get_reply_admin_links', 'hw_get_reply_admin_links', 10, 3 );
thanks for your input, but it still not working. :<
untested, but this should work
function hw_get_reply_admin_links($args) { args['before'] = '<div class="list">' ; args['after'] = '</div>' ; return $args ; } add_filter('bbp_before_get_reply_admin_links_parse_args','hw_get_reply_admin_links');
hm, it crashes site, appears just a blank page
try
function hw_get_reply_admin_links($args) { $args['before'] = '<div class="list">' ; $args['after'] = '</div>' ; return $args ; } add_filter('bbp_before_get_reply_admin_links_parse_args','hw_get_reply_admin_links');
Not working :[
Just my curiosity, but why html markup is included in code? I worked in past with DLE engine and all markup was purely inside of template.
ok, two things
1. what does not working mean ?
2. html is included because that’s what you put in your thread as what you wanted !Now I trying to change args of bbp_get_reply_admin_links (stored in bbpress/includes/replies/template.php)
Thats my hook
function hw_get_reply_admin_links ($args) {
$args = array (
‘before’ => ‘<div class=”list”>’,
‘after’ => ‘</div>’,
);
return $args;
}
add_filter (‘bbp_get_reply_admin_links’, ‘hw_get_reply_admin_links’ );
What’s wrong here?on 1. just rechecked, and the code works – make sure you are looking at a reply not a topic.
on 2. more seriously, there are no strict rules, as often you want to put in an #ID that related to say a topic number, so need to do this within the code.
By not working i mean it not replaces original <span class=”bbp-admin-links”></span> to <div class=”list”></div> To make sure its not a glitch of my theme I’ve installed a fresh copy of WP and BP on local drive, but nothing has changed.
- You must be logged in to reply to this topic.