Advertisement
Guest User

bbp_topic_author_link

a guest
Jan 19th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.74 KB | None | 0 0
  1. /**
  2.  * Output the author link of the topic
  3.  *
  4.  * @since bbPress (r2717)
  5.  *
  6.  * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
  7.  * @uses bbp_get_topic_author_link() To get the topic author link
  8.  */
  9. function bbp_topic_author_link( $args = '' ) {
  10.     echo bbp_get_topic_author_link( $args );
  11. }
  12.     /**
  13.      * Return the author link of the topic
  14.      *
  15.      * @since bbPress (r2717)
  16.      *
  17.      * @param mixed|int $args If it is an integer, it is used as topic id.
  18.      *                         Optional.
  19.      * @uses bbp_get_topic_id() To get the topic id
  20.      * @uses bbp_get_topic_author_display_name() To get the topic author
  21.      * @uses bbp_is_topic_anonymous() To check if the topic is by an
  22.      *                                 anonymous user
  23.      * @uses bbp_get_topic_author_url() To get the topic author url
  24.      * @uses bbp_get_topic_author_avatar() To get the topic author avatar
  25.      * @uses bbp_get_topic_author_display_name() To get the topic author display
  26.      *                                      name
  27.      * @uses bbp_get_user_display_role() To get the topic author display role
  28.      * @uses bbp_get_topic_author_id() To get the topic author id
  29.      * @uses apply_filters() Calls 'bbp_get_topic_author_link' with the link
  30.      *                        and args
  31.      * @return string Author link of topic
  32.      */
  33.     function bbp_get_topic_author_link( $args = '' ) {
  34.  
  35.         // Parse arguments against default values
  36.         $r = bbp_parse_args( $args, array(
  37.             'post_id'    => 0,
  38.             'link_title' => '',
  39.             'type'       => 'both',
  40.             'size'       => 80,
  41.             'sep'        => ' ',
  42.             'show_role'  => false
  43.         ), 'get_topic_author_link' );
  44.  
  45.         // Used as topic_id
  46.         if ( is_numeric( $args ) ) {
  47.             $topic_id = bbp_get_topic_id( $args );
  48.         } else {
  49.             $topic_id = bbp_get_topic_id( $r['post_id'] );
  50.         }
  51.  
  52.         // Topic ID is good
  53.         if ( !empty( $topic_id ) ) {
  54.  
  55.             // Get some useful topic information
  56.             $author_url = bbp_get_topic_author_url( $topic_id );
  57.             $anonymous  = bbp_is_topic_anonymous( $topic_id );
  58.  
  59.             // Tweak link title if empty
  60.             if ( empty( $r['link_title'] ) ) {
  61.                 $link_title = sprintf( empty( $anonymous ) ? __( 'View %s\'s profile', 'bbpress' ) : __( 'Visit %s\'s website', 'bbpress' ), bbp_get_topic_author_display_name( $topic_id ) );
  62.  
  63.             // Use what was passed if not
  64.             } else {
  65.                 $link_title = $r['link_title'];
  66.             }
  67.  
  68.             // Setup title and author_links array
  69.             $link_title   = !empty( $link_title ) ? ' title="' . esc_attr( $link_title ) . '"' : '';
  70.             $author_links = array();
  71.  
  72.             // Get avatar
  73.             if ( 'avatar' === $r['type'] || 'both' === $r['type'] ) {
  74.                 $author_links['avatar'] = bbp_get_topic_author_avatar( $topic_id, $r['size'] );
  75.             }
  76.  
  77.             // Get display name
  78.             if ( 'name' === $r['type'] || 'both' === $r['type'] ) {
  79.                 $author_links['name'] = bbp_get_topic_author_display_name( $topic_id );
  80.             }
  81.  
  82.             // Link class
  83.             $link_class = ' class="bbp-author-' . esc_attr( $r['type'] ) . '"';
  84.  
  85.             // Add links if not anonymous
  86.             if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) {
  87.  
  88.                 // Assemble the links
  89.                 foreach ( $author_links as $link => $link_text ) {
  90.                     $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"';
  91.                     $author_link[] = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, $link_class, $link_text );
  92.                 }
  93.  
  94.                 if ( true === $r['show_role'] ) {
  95.                     $author_link[] = bbp_get_topic_author_role( array( 'topic_id' => $topic_id ) );
  96.                 }
  97.  
  98.                 $author_link = implode( $r['sep'], $author_link );
  99.  
  100.             // No links if anonymous
  101.             } else {
  102.                 $author_link = implode( $r['sep'], $author_links );
  103.             }
  104.  
  105.         } else {
  106.             $author_link = '';
  107.         }
  108.  
  109.         return apply_filters( 'bbp_get_topic_author_link', $author_link, $args );
  110.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement