WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#40034 closed enhancement (worksforme)

Add License and License URI as valid style.css headers to WP_Theme

Reported by: grapplerulrich Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: needs-patch
Focuses: Cc:

Description

The style.css headers License and License URI are required for WordPress.org theme repository but it is not possible to fetch the data using WP_Theme::get().

The reason I realized this is that I am working on an automated testing plugin for theme and wanted to check that the License and License URI were set.

Change History (7)

#1 @desrosj
2 years ago

  • Keywords needs-patch needs-screenshots added
  • Type changed from defect (bug) to enhancement

#2 @desrosj
2 years ago

  • Keywords needs-screenshots removed

#3 @dd32
2 years ago

In general, when core doesn't use the field I don't see the benefit in pulling it out - however it is an official field by the themes team.

As a workaround, Theme Check uses the filter to add the extra headers: #20897

#4 @grapplerulrich
2 years ago

@dd32 Actually that does not work anymore. I am not sure it ever worked. The reason is that there is a check in the beginning of WP_Theme::get().

if ( ! isset( $this->headers[ $header ] ) )
        return false;

The fix for this ticket would be to add the following to $file_headers

'License'     => 'License',
'LicenseURI'  => 'License URI',

#5 @dd32
2 years ago

It works for me:

add_filter( 'extra_theme_headers', 'tc_add_headers' );

function tc_add_headers( $extra_headers ) {
	$extra_headers = array( 'License', 'License URI', 'Template Version' );
	return $extra_headers;
}
var_dump( get_theme( 'Twenty Seventeen' )->get('License URI') );

That check you're referencing will contain the License key if whitelisted.

#6 @grapplerulrich
2 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Ok, I got it to work for me too now. The filter that is used for when using the class is https://developer.wordpress.org/reference/hooks/extra_context_headers/

#7 @netweb
2 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.