Make WordPress Core

Opened 8 years ago

Last modified 3 months ago

#40796 new defect (bug)

Twenty Seventeen: Overriding WordPress globals is prohibited

Reported by: maneshtimilsina's profile maneshtimilsina Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.5
Component: Bundled Theme Keywords: dev-feedback has-patch needs-unit-tests
Focuses: Cc:

Description

In Twenty Seventeen theme, global variable $post is overridden at line 145 of /inc/template-tags.php

As per theme review guidelines Overriding WordPress globals is prohibited.

Attachments (1)

40796.patch (1.1 KB) - added by smit08 3 months ago.
Hi @swissspidy, As mentioned in my previous comment, the code line has been updated, and this issue can be resolved using the patch I provided. If we decide to proceed with the fix, we can apply my patch. I would appreciate it if a tester could review and test my patch. Thank you in advance.

Download all attachments as: .zip

Change History (7)

#1 @swissspidy
8 years ago

Hey there,

Thanks for your report and welcome to Trac!

They way themes like Twenty Seventeen need to set up front page sections, overriding $post is really to only way.

What isn't needed is the first global $post on line 142. Also, before the global post is set, it's not really checked if get_theme_mod( 'panel_' . $id ) really is a valid post.

#2 @maneshtimilsina
8 years ago

Hi @swissspidy

Thanks for reply.

Yes, global $post on line 142 has no use. Also, if $id returns integer value is not checked anywhere.

Next, $post is overridden to use its ID in content-front-page-panels.php we can get this option by creating custom global variable and assigning post ID. We need to change the_title() in content-front-page-panels.php to get_the_title( $global_variable )

If you like to test, I can provide you working code.

Thank you.

#3 @nielslange
5 years ago

  • Summary changed from Overriding WordPress globals is prohibited to Twenty Seventeen: Overriding WordPress globals is prohibited

#4 @karmatosed
12 months ago

  • Keywords dev-feedback added

#5 @smit08
3 months ago

Hi @swissspidy, I looked into the issue. I think we need to update the description. I checked the /inc/template-tags.php file and found that the $post variable is overridden, but it is now on line 155.

Here is the line I found, along with the comment:

global $post; // Modify the global post object before setting up post data.

@smit08
3 months ago

Hi @swissspidy, As mentioned in my previous comment, the code line has been updated, and this issue can be resolved using the patch I provided. If we decide to proceed with the fix, we can apply my patch. I would appreciate it if a tester could review and test my patch. Thank you in advance.

#6 @smit08
3 months ago

  • Keywords has-patch needs-unit-tests added
Note: See TracTickets for help on using tickets.