forked from joshcanhelp/auth0-wp-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-test-avatars.php
78 lines (75 loc) · 2.14 KB
/
page-test-avatars.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Page template for testing avatar override
* Page slug should be 'test-avatars' for this template to be active.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-page
*
* @package WordPress
* @subpackage WP_Auth0_Testing
* @since 1.0
* @version 1.0
*/
get_template_part( 'template-parts/block', 'header' );
the_post();
?>
<article>
<?php get_template_part( 'template-parts/block', 'test-tpl-header' ); ?>
<div class="the-content">
<p>Tests avatar overrides. A yellow border means no Auth0 information for the user so no Auth0 avatar;
a red border means an Auth0 avatar is being used.</p>
</div>
<?php
$post_q = new WP_Query(
[
'post_type' => 'post',
'posts_per_page' => 1,
'ignore_sticky_posts' => true,
]
);
if ( $post_q->have_posts() ) {
while ( $post_q->have_posts() ) {
$post_q->the_post();
printf(
'<h4>Post used: <a href="%s">%s</a> [<a href="%s%d">edit</a>]</h4>',
esc_url( get_permalink() ),
esc_html( get_the_title() ),
esc_url( admin_url( 'post.php?action=edit&post=' ) ),
absint( get_the_ID() )
);
$this_author = $post->post_author;
$avatar_size = 80;
$a_comment = null;
if ( get_comments_number() ) {
$a_comment = current(
get_comments(
[
'post_id' => get_the_ID(),
'number' => 1,
]
)
);
}
printf(
'<p>%s - Avatar from email</p>
<p>%s - Avatar from user ID</p>
<p>%s - Avatar from <code>WP_Post</code> object</p>
<p>%s - Avatar from <code>WP_User</code> object</p>
<p>%s</p>',
get_avatar( $this_author, $avatar_size ),
get_avatar( get_the_author_meta( 'email', $this_author ), $avatar_size ),
get_avatar( $post, $avatar_size ),
get_avatar( new WP_User( $this_author ), $avatar_size ),
$a_comment
? get_avatar( $a_comment, $avatar_size ) . ' - Avatar from <code>WP_Comment</code> object'
: 'Add a comment to test comment avatars'
);
}
} else {
printf(
'<p><i>No posts found. Add a post to test avatar overrides</i></p>'
);
}
?>
</article>
<?php get_template_part( 'template-parts/block', 'footer' ); ?>