Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix avatar id collision between user id and guest-author post type #960

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ public function coauthors_meta_box( $post ) {
<?php
foreach ( $coauthors as $coauthor ) :
$count++;
$avatar_url = get_avatar_url( $coauthor->ID );
$user_type = 'guest-user';
if ( $coauthor instanceof WP_User ) {
$user_type = 'wp-user';
}
$avatar_url = get_avatar_url( $coauthor->ID, array( 'user_type' => $user_type ) );
?>
<li>
<?php echo get_avatar( $coauthor->ID, $this->gravatar_size ); ?>
Expand Down Expand Up @@ -1833,9 +1837,29 @@ public function get_guest_author_post_count( $guest_author ) {
* @return string Avatar URL
*/
public function filter_pre_get_avatar_data_url( $args, $id ) {
global $wp_current_filter;

if ( ! $id || ! $this->is_guest_authors_enabled() || ! is_numeric( $id ) || isset( $args['url'] ) ) {
return $args;
}

// Do not filter the icon in the admin bar
if ( doing_filter( 'admin_bar_menu' ) ) {
return $args;
}

// Do not filter when we have a WordPress user sent from CAP meta box
if ( isset( $args['user_type'] ) && 'wp-user' === $args['user_type'] ) {
return $args;
}

// Do not filter when on the user screen
$current_screen = get_current_screen();
if ( isset( $current_screen->parent_base ) && 'users' == $current_screen->parent_base ) {
return $args;
}


$coauthor = $this->get_coauthor_by( 'id', $id );
if ( false !== $coauthor && isset( $coauthor->type ) && 'guest-author' === $coauthor->type ) {
if ( has_post_thumbnail( $id ) ) {
Expand Down