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

Post Author block now includes option to link author archive #42670

Merged

Conversation

philwp
Copy link
Contributor

@philwp philwp commented Jul 25, 2022

What?

Adds a toggle option to add a link to the Author's archive page.

Why?

Resolves #41554

How?

If the linked attribute is true

Testing Instructions

  1. Open the Site Editor
  2. Select a template such as Home
  3. Add Post Author block.
  4. Toggle Link author name to author page

Screenshots or screencast

Screen Shot 2022-07-25 at 7 52 37 AM

@philwp philwp requested a review from ajitbohra as a code owner July 25, 2022 11:55
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jul 25, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @philwp! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@ndiego ndiego added [Block] Post Author Affects the Post Author Block [Type] Enhancement A suggestion for improvement. labels Jul 25, 2022
@paaljoachim
Copy link
Contributor

paaljoachim commented Aug 19, 2022

Thank you for creating this PR @philwp

@michalczaplinski and @c4rl0sbr4v0 Perhaps you can take a look at this PR?

Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution!! I added some small details.

@@ -23,6 +23,9 @@
},
"byline": {
"type": "string"
},
"linked": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may better use isLink, so that way is similar to other blocks like:

Also would be cool to have a default value here.

Comment on lines 32 to 34
$link = ! empty( $attributes['linked'] ) ? get_author_posts_url( $author_id ) : '';
$author_name = $link ? '<a href="' . $link . '">' . get_the_author_meta( 'display_name', $author_id ) . '</a>' : get_the_author_meta( 'display_name', $author_id );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is working fine, but, maybe, in order to keep consistency with other blocks, we could do:

  1. Define the default author name: $author_name = get_the_author_meta( 'display_name', $author_id );
  2. Update the value if the link attribute is enabled:
if ( ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
		$comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author );
	}
  1. Check if rel attribute is needed, add a target option.

Comment Author Name block is an example you can use 😄

if ( ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) {
$comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll update to match the implementation used in comment-author-name.

@cbravobernal
Copy link
Contributor

@philwp , we need to run in order to pass all the tests, thanks for your contribution to the project! 🎉

  • npm run docs:build when we add a new attribute to a block to update the documentation
  • npm run format:php to use the code standards on whitespace in PHP
  • npm run lint:js:fix to use the code standards on whitespace in JS

@cbravobernal
Copy link
Contributor

cbravobernal commented Aug 29, 2022

@philwp , sorry, in order to pass the JS unit tests, as you added new attributes to a block, you have to regenerate the fixtures.
Please, run npm run fixtures:regenerate and only add the files changed with core__post-author in the name.

Thanks!!

@cbravobernal cbravobernal merged commit dbe6e19 into WordPress:trunk Oct 3, 2022
@github-actions
Copy link

github-actions bot commented Oct 3, 2022

Congratulations on your first merged pull request, @philwp! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Author Affects the Post Author Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post Author: Wrap author name as a link
5 participants