WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#40796 new defect (bug)

Overriding WordPress globals is prohibited

Reported by: maneshtimilsina Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.5
Component: Bundled Theme Keywords:
Focuses: Cc:
PR Number:

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 (2)

#1 @swissspidy
2 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
2 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.

Note: See TracTickets for help on using tickets.