bbp_get_topic_author_link( mixed|int $args = array() )
Return the author link of the topic
Description Description
Parameters Parameters
- $args
-
(Optional) If it is an integer, it is used as topic id. Optional.
Default value: array()
Return Return
(string) Author link of topic
Source Source
File: includes/topics/template.php
function bbp_get_topic_author_link( $args = array() ) {
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'post_id' => 0,
'link_title' => '',
'type' => 'both',
'size' => 80,
'sep' => '',
'show_role' => false
), 'get_topic_author_link' );
// Default return value
$author_link = '';
// Used as topic_id
$topic_id = is_numeric( $args )
? bbp_get_topic_id( $args )
: bbp_get_topic_id( $r['post_id'] );
// Topic ID is good
if ( ! empty( $topic_id ) ) {
// Get some useful topic information
$author_url = bbp_get_topic_author_url( $topic_id );
$anonymous = bbp_is_topic_anonymous( $topic_id );
// Tweak link title if empty
if ( empty( $r['link_title'] ) ) {
$author = bbp_get_topic_author_display_name( $topic_id );
$title = empty( $anonymous )
? esc_attr__( "View %s's profile", 'bbpress' )
: esc_attr__( "Visit %s's website", 'bbpress' );
$link_title = sprintf( $title, $author );
// Use what was passed if not
} else {
$link_title = $r['link_title'];
}
// Setup title and author_links array
$author_links = array();
$link_title = ! empty( $link_title )
? ' title="' . esc_attr( $link_title ) . '"'
: '';
// Get avatar (unescaped, because HTML)
if ( ( 'avatar' === $r['type'] ) || ( 'both' === $r['type'] ) ) {
$author_links['avatar'] = bbp_get_topic_author_avatar( $topic_id, $r['size'] );
}
// Get display name (escaped, because never HTML)
if ( ( 'name' === $r['type'] ) || ( 'both' === $r['type'] ) ) {
$author_links['name'] = esc_html( bbp_get_topic_author_display_name( $topic_id ) );
}
// Empty array
$links = array();
$sprint = '<span %1$s>%2$s</span>';
// Wrap each link
foreach ( $author_links as $link => $link_text ) {
$link_class = ' class="bbp-author-' . esc_attr( $link ) . '"';
$links[] = sprintf( $sprint, $link_class, $link_text );
}
// Juggle
$author_links = $links;
unset( $links );
// Filter sections
$sections = apply_filters( 'bbp_get_topic_author_links', $author_links, $r, $args );
// Assemble sections into author link
$author_link = implode( $r['sep'], $sections );
// Only wrap in link if profile exists
if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) {
$author_link = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, ' class="bbp-author-link"', $author_link );
}
// Role is not linked
if ( true === $r['show_role'] ) {
$author_link .= bbp_get_topic_author_role( array( 'topic_id' => $topic_id ) );
}
}
// Filter & return
return apply_filters( 'bbp_get_topic_author_link', $author_link, $r, $args );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |