Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 2
CRAP
n/a
0 / 0
jetpack_author_bio
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 1
182
jetpack_has_gravatar
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Theme Tools: Author Bio functions.
4 *
5 * @package automattic/jetpack-classic-theme-helper
6 */
7
8if ( ! 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
90if ( ! 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}