Make WordPress Core

Opened 7 years ago

Last modified 4 years 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:
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.

Change History (3)

#1 @swissspidy
7 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
7 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
4 years ago

  • Summary changed from Overriding WordPress globals is prohibited to Twenty Seventeen: Overriding WordPress globals is prohibited
Note: See TracTickets for help on using tickets.