Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/bf8aad1010e0d291ac05ab7b9647986e to your computer and use it in GitHub Desktop.
Save kimcoleman/bf8aad1010e0d291ac05ab7b9647986e to your computer and use it in GitHub Desktop.
Show a link to the profile user's author post archive on the Member Profile page.
@riadbz
Copy link

riadbz commented Jun 8, 2021

This code doesn't work correctly. It shows always the first WordPress user.
Here is a correction :

function link_to_author_archive_pmpro_member_profile_after( $pu ) {
// Get the profile user's author post archive URL.
$author_posts_url = get_author_posts_url( $pu->ID );

// If no link found, return nothing.
if ( empty( $author_posts_url ) ) {
	return;
}

// Show a link to the profile user's posts.
echo '<p class="pmpro_member_directory_author_posts_url">';
printf(
	'<a class="author-link" href="%1$s" rel="author">%2$s</a>',
	esc_url( $author_posts_url ),
	sprintf(
		/* translators: %s: Author name. */
		esc_html__( 'View the member\'s posts.', 'pmpro-customizations' )
	)
);
echo '</p>';

}
add_action( 'pmpro_member_profile_after', 'link_to_author_archive_pmpro_member_profile_after' );

@kimcoleman
Copy link
Author

Thank you - I have updated the recipe and now also check whether there are no posts by the user before displaying the link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment