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 Title: Fix argument numbering in 'sprintf' #35338

Merged
merged 1 commit into from
Oct 5, 2021

Conversation

Mamaduka
Copy link
Member

@Mamaduka Mamaduka commented Oct 5, 2021

Description

PR fixes argument numbering for sprintf in Post Title block's link markup.

An integer followed by a dollar sign $, to specify which number argument to treat in the conversion.

Source: php.net: sprintf

How has this been tested?

Check linked post title block renders correctly.

Types of changes

Code Quality

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@Mamaduka Mamaduka requested a review from ajitbohra as a code owner October 5, 2021 08:10
@Mamaduka Mamaduka self-assigned this Oct 5, 2021
@Mamaduka Mamaduka added [Block] Post Title Affects the Post Title Block [Type] Code Quality Issues or PRs that relate to code quality labels Oct 5, 2021
@Mamaduka Mamaduka requested a review from ntsekouras October 5, 2021 08:11
@@ -29,7 +29,7 @@ function render_block_core_post_title( $attributes, $content, $block ) {

$title = get_the_title( $post_ID );
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
$title = sprintf( '<a href="%1s" target="%2s" rel="%3s">%4s</a>', get_the_permalink( $post_ID ), $attributes['linkTarget'], $attributes['rel'], $title );
$title = sprintf( '<a href="%1$s" target="%2$s" rel="%3$s">%4$s</a>', get_the_permalink( $post_ID ), $attributes['linkTarget'], $attributes['rel'], $title );
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this needed only if we reuse some arguments? If we use them just once (like here) and the order is correct the $ can be omitted, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's usually good practice to use them anyway, to avoid bugs in the future. This code was already using them, but with an incorrect format - %1s, the $ was missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

That what I meant - that the $ was not needed here. The % is needed and was there. Having said that I have no strong opinions on this one 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there was WPCS rule for it, but can find it right now 😅

@Mamaduka Mamaduka merged commit 95d9cdb into trunk Oct 5, 2021
@Mamaduka Mamaduka deleted the fix/post-title-argnum branch October 5, 2021 08:59
@github-actions github-actions bot added this to the Gutenberg 11.7 milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Title Affects the Post Title Block [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants