#39771 closed enhancement (fixed)
Twenty Seventeen: Unused and duplicate variables in content-front-page.php
Reported by: | dayun123 | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.7.2 |
Component: | Bundled Theme | Keywords: | has-patch |
Focuses: | Cc: |
Description
<?php if ( has_post_thumbnail() ) : $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' ); $post_thumbnail_id = get_post_thumbnail_id( $post->ID ); $thumbnail_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' ); // Calculate aspect ratio: h / w * 100%. $ratio = $thumbnail_attributes[2] / $thumbnail_attributes[1] * 100; ?> <div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);"> <div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div> </div><!-- .panel-image --> <?php endif; ?>
I'm still a novice programmer, so maybe I'm missing something obvious, but I don't understand why the following two things happen:
- Why is the $post_thumbnail_id variable created but never used? Why not create it right away instead of constantly calling get_post_thumbnail_id( $post->ID )?
- $thumbnail and $thumbnail_attributes are the same, right? So why create both?
Wouldn't this make more sense:
<?php if ( has_post_thumbnail() ) : $post_thumbnail_id = get_post_thumbnail_id( $post->ID ); $thumbnail = wp_get_attachment_image_src( $post_thumbnail_id, 'twentyseventeen-featured-image' ); // Calculate aspect ratio: h / w * 100%. $ratio = $thumbnail[2] / $thumbnail[1] * 100; ?> <div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);"> <div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div> </div><!-- .panel-image --> <?php endif; ?>
Attachments (2)
Change History (12)
@
8 years ago
Replaced post thumbnail code in content-front-page.php with the one from content-front-page-panels.php, and escaped $twentyseventeencounter in content-front-page-panels.php
#2
@
8 years ago
- Milestone changed from Awaiting Review to 4.8
- Summary changed from Suggestion for edit to content-front-page.php in TwentySeventeen Theme to Twenty Seventeen: Unused and duplicate variables in content-front-page.php
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
@
7 years ago
Remove changes from content-front-page-panels.php and only keep changes for content-front-page.php
#7
@
7 years ago
- Keywords needs-testing removed
The old patch contained changes for 2 files. Only 1 of the files (content-front-page-panels.php) is related to the current track issue. Therefore, the patch only contains the changes for this ticket.
Tested it with @grapplerulrich and @ocean90
#8
@
7 years ago
- Owner set to ocean90
- Resolution set to fixed
- Status changed from new to closed
In 40904:
The odd thing is that the
content-front-page-panels.php
usesMaybe somebody missed that.