PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-classic-theme-helper / src / content-options / author-bio.php

author-bio.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at jetpack_vendor/automattic/jetpack-classic-theme-helper/src/content-options/author-bio.php

110 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Tools: Author Bio functions.
4 *
5 * @package automattic/jetpack-classic-theme-helper
6 */
7
8 if ( ! function_exists( 'jetpack_author_bio' ) ) {
9
10 /**
11 * The function to display Author Bio in a theme.
12 */
13 function jetpack_author_bio() {
14 // If the theme doesn't support 'jetpack-content-options', don't continue.
15 if ( ! current_theme_supports( 'jetpack-content-options' ) ) {
16 return;
17 }
18
19 $options = get_theme_support( 'jetpack-content-options' );
20 $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null;
21 $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1;
22 $avatar_default = ( isset( $options[0]['avatar-default'] ) && false === $options[0]['avatar-default'] ) ? '' : 1;
23
24 // If the theme doesn't support 'jetpack-content-options[ 'author-bio' ]', don't continue.
25 if ( true !== $author_bio ) {
26 return;
27 }
28
29 // If 'jetpack_content_author_bio' is false, don't continue.
30 if ( ! get_option( 'jetpack_content_author_bio', $author_bio_default ) ) {
31 return;
32 }
33
34 // If we aren't on a single post, don't continue.
35 if ( ! is_single() ) {
36 return;
37 }
38
39 // Define class for entry-author.
40 if ( ! $avatar_default && ! jetpack_has_gravatar( get_the_author_meta( 'user_email' ) ) ) {
41 $class = 'author-avatar-hide';
42 } else {
43 $class = 'author-avatar-show';
44 }
45 ?>
46 <div class="entry-author <?php echo esc_attr( $class ); ?>">
47 <?php if ( 'author-avatar-show' === $class ) : ?>
48 <div class="author-avatar">
49 <?php
50 /**
51 * Filter the author bio avatar size.
52 *
53 * @param int $size The avatar height and width size in pixels.
54 *
55 * @module theme-tools
56 *
57 * @since 4.5.0
58 */
59 $author_bio_avatar_size = apply_filters( 'jetpack_author_bio_avatar_size', 48 );
60
61 echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size );
62 ?>
63 </div><!-- .author-avatar -->
64 <?php endif; ?>
65
66 <div class="author-heading">
67 <h2 class="author-title">
68 <?php
69 /* translators: %s: post author */
70 printf( esc_html__( 'Published by %s', 'jetpack-classic-theme-helper' ), '<span class="author-name">' . get_the_author() . '</span>' );
71 ?>
72 </h2>
73 </div><!-- .author-heading -->
74
75 <p class="author-bio">
76 <?php the_author_meta( 'description' ); ?>
77 <a class="author-link" href="<?php echo esc_url( get_author_posts_url( (int) get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
78 <?php
79 /* translators: %s: post author */
80 printf( esc_html__( 'View all posts by %s', 'jetpack-classic-theme-helper' ), get_the_author() );
81 ?>
82 </a>
83 </p><!-- .author-bio -->
84 </div><!-- .entry-auhtor -->
85 <?php
86 }
87
88 }
89
90 if ( ! function_exists( 'jetpack_has_gravatar' ) ) {
91
92 /**
93 * Checks to see if the specified email address has a Gravatar image.
94 *
95 * @param string $email The email of the address of the user to check.
96 * @return bool Whether or not the user has a gravatar
97 */
98 function jetpack_has_gravatar( $email ) {
99
100 $url = get_avatar_url( $email, array( 'default' => '404' ) );
101 if ( ! is_string( $url ) ) {
102 return false;
103 }
104
105 // If 200 is returned, the user has a Gravatar; otherwise, they don't.
106 return wp_remote_retrieve_response_code( wp_remote_head( $url ) ) === 200;
107 }
108
109 }
110