Guenni007

loop-about-author

Nov 21st, 2025
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.40 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  5.  
  6. /**
  7.  * Custom loop-about-author.php für Child-Theme
  8.  * Zählt Posts + Portfolio-Items für die Author-Bio
  9.  * Platziere diese Datei in: /wp-content/themes/enfold-child/includes/loop-about-author.php
  10.  */
  11.  
  12. global $avia_config;
  13. $author_id = get_query_var( 'author' );
  14. if( empty( $author_id ) )
  15. {
  16.     $author_id = get_the_author_meta( 'ID' );
  17. }
  18. $context = 'loop-about-author.php';
  19. $description_ori = get_the_author_meta( 'description', $author_id );
  20. /**
  21.  * Filter author data
  22.  *
  23.  * @param string
  24.  * @param int $author_id
  25.  * @param string $context       added with 4.7.5.1
  26.  * @return string
  27.  */
  28. $name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $author_id ), $author_id, $context );
  29. $email = apply_filters( 'avf_author_email', get_the_author_meta( 'email', $author_id ), $author_id, $context );
  30. $description = apply_filters( 'avf_author_description', $description_ori, $author_id, $context );
  31. $gravatar_alt = esc_html( $name );
  32. $gravatar = get_avatar( $email, '81', '', $gravatar_alt );
  33.  
  34. // Keep plain name for translations
  35. $name_plain = $name;
  36.  
  37. $name = "<span class='author-box-name' " . avia_markup_helper( array( 'context' => 'author_name', 'echo' => false ) ) . '>'. $name . '</span>';
  38. $heading = __( 'About', 'avia_framework' ) . ' ' . $name;
  39. $default_heading = 'h3';
  40. $args = array(
  41.             'heading'       => $default_heading,
  42.             'extra_class'   => ''
  43.         );
  44. /**
  45.  * @since 4.5.5
  46.  * @return array
  47.  */
  48. $args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_default_author', array() );
  49. $heading1 = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  50. $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  51.  
  52. // Count posts for all defined post types
  53. $default_args = array( 'post_types' => array('post') );
  54. $atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
  55.  
  56. $cnt_posts = 0;
  57. $post_type_counts = array();
  58.  
  59. if( ! empty( $atts['post_types'] ) && is_array( $atts['post_types'] ) ) {
  60.     foreach( $atts['post_types'] as $post_type ) {
  61.         $count = count_user_posts( $author_id, $post_type );
  62.         if( $count > 0 ) {
  63.             $cnt_posts += $count;
  64.            
  65.             // Get post type label
  66.             $post_type_obj = get_post_type_object( $post_type );
  67.             $post_type_label = $post_type_obj ? $post_type_obj->labels->name : $post_type;
  68.            
  69.             $post_type_counts[] = $count . ' ' . $post_type_label;
  70.         }
  71.     }
  72. } else {
  73.     // Fallback: count only posts
  74.     $cnt_posts = count_user_posts( $author_id );
  75. }
  76.  
  77. // Build entry count text
  78. $entry_text = '';
  79. if( $cnt_posts > 0 ) {
  80.     $breakdown = ! empty( $post_type_counts ) ? ' (' . implode( ', ', $post_type_counts ) . ')' : '';
  81.     // Use existing Enfold translation string - breakdown at the end
  82.     $entry_text = '<br />' . sprintf( __( 'But we are proud to say that %s contributed %s entries already.', 'avia_framework' ), $name, $cnt_posts ) . '<br />' . $breakdown;
  83. }
  84.  
  85. if( empty( $description ) )
  86. {
  87.     $description  = __( 'This author has not written his bio yet.', 'avia_framework' );
  88.     $description .= $entry_text;
  89.     if( current_user_can( 'edit_users' ) || get_current_user_id() == $author_id )
  90.     {
  91.         $description .= "<br /><a href='" . admin_url( 'profile.php?user_id=' . $author_id ) . "'>" . __( 'Edit the profile description here.', 'avia_framework' ) . '</a>';
  92.     }
  93. }
  94. else
  95. {
  96.     // Bio exists - append entry count
  97.     $description .= $entry_text;
  98. }
  99. /**
  100.  * Filter final output of author description or skip completly
  101.  *
  102.  * @since 4.7.5.1
  103.  * @param string $description
  104.  * @param string $description_ori
  105.  * @param int $author_id
  106.  * @return string|false                 false to skip output completely
  107.  */
  108. $description = apply_filters( 'avf_author_description_loop_about', $description, $description_ori, $author_id );
  109. if( false === $description )
  110. {
  111.     return;
  112. }
  113. echo '<section class="author-box" ' . avia_markup_helper( array( 'context' => 'author', 'echo' => false ) ) . '>';
  114. echo    "<span class='post-author-format-type blog-meta'><span class='rounded-container'>{$gravatar}</span></span>";
  115. echo    "<div class='author_description '>";
  116. echo        "<{$heading1} class='author-title {$css}'>{$heading}</{$heading1}>";
  117. echo        "<div class='author_description_text'" . avia_markup_helper( array( 'context' => 'description', 'echo' => false ) ) . '>' . wpautop( $description ) . '</div>';
  118. echo        '<span class="author-extra-border"></span>';
  119. echo    '</div>';
  120. echo '</section>';
  121.  
  122.  
Advertisement
Add Comment
Please, Sign In to add comment