author-bio.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * The function to display Author Bio in a theme.
  4. */
  5. function jetpack_author_bio() {
  6. // If the theme doesn't support 'jetpack-content-options', don't continue.
  7. if ( ! current_theme_supports( 'jetpack-content-options' ) ) {
  8. return;
  9. }
  10. $options = get_theme_support( 'jetpack-content-options' );
  11. $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null;
  12. $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1;
  13. // If the theme doesn't support 'jetpack-content-options[ 'author-bio' ]', don't continue.
  14. if ( true !== $author_bio ) {
  15. return;
  16. }
  17. // If 'jetpack_content_author_bio' is false, don't continue.
  18. if ( ! get_option( 'jetpack_content_author_bio', $author_bio_default ) ) {
  19. return;
  20. }
  21. // If we aren't on a single post, don't continue.
  22. if ( ! is_single() ) {
  23. return;
  24. }
  25. ?>
  26. <div class="entry-author">
  27. <div class="author-avatar">
  28. <?php
  29. /**
  30. * Filter the author bio avatar size.
  31. *
  32. * @param int $size The avatar height and width size in pixels.
  33. *
  34. * @module theme-tools
  35. *
  36. * @since 4.5.0
  37. */
  38. $author_bio_avatar_size = apply_filters( 'jetpack_author_bio_avatar_size', 48 );
  39. echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size );
  40. ?>
  41. </div><!-- .author-avatar -->
  42. <div class="author-heading">
  43. <h2 class="author-title"><?php printf( esc_html__( 'Published by %s', 'jetpack' ), '<span class="author-name">' . get_the_author() . '</span>' ); ?></h2>
  44. </div><!-- .author-heading -->
  45. <p class="author-bio">
  46. <?php the_author_meta( 'description' ); ?>
  47. <a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
  48. <?php printf( esc_html__( 'View all posts by %s', 'jetpack' ), get_the_author() ); ?>
  49. </a>
  50. </p><!-- .author-bio -->
  51. </div><!-- .entry-auhtor -->
  52. <?php
  53. }