1

What is the reason for using a style sheet header on page templates, where critcal values are assigned within a comments block in php, instead of just declaring constants, objects, or some other php structure?

The style sheet header is like this:

/*
Theme Name: Twenty Fifteen Child
Theme URI:  *
Description: Twenty Fifteen Child Theme
Author: John Doe
Author URI:  *
Template: twentyfifteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI:*  
Tags: light, dark, two-columns, right-sidebar, responsive-layout,     accessibility-ready
Text Domain: twenty-fifteen-child
*/

What is the advantage of the active code in the comments block over putting those values in an array, example below? Is there no php code that would be better than putting live values into the comments?

$child_theme_definition=array();
$child_theme_definition['theme_name']='Twenty Fifteen Child';
$child_theme_definition['theme_uri']=''*;
$child_theme_definition['Description']='Twenty Fifteen Child Theme';
$child_theme_definition['Author']='John Doe';
$child_theme_definition['Author URI']=''*;
$child_theme_definition['Template']='twentyfifteen';
$child_theme_definition['Version']='1.0.0';
$child_theme_definition['License']='GNU General Public License v2 or later';
$child_theme_definition['License URI']=''*;
$child_theme_definition['Tags']='light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-fifteen-child';

*urls omitted because my new account is not allowed to include more than two urls in a post.

2

The headers have to be read without the files being executed. The files are parsed to extract the headers without executing the php code they contain.

|improve this answer|||||
  • why? What difference does it make? Is this a common practice? – Scotty Jakes Nov 28 '16 at 1:49
  • I cannot come up with a reason why it would be necessary for the headers not to execute something. Something is executing on the headers, reading them into variables, parsing them, using the results. Instead of putting a header in a comment block of the style.css, why not have theme.config file, similar to wp-config.php? What is the problem caused by the headers being script that can execute? – Scotty Jakes Nov 28 '16 at 2:22
  • Why are themes the only part of the system requiring non-executing headers placed in comment blocks? Why disrupt the normal function of comments, which is to have no effect on what software does? These headers cannot possibly be the only way to provide this the information needed about child themes, and this way is confusing. – Scotty Jakes Nov 28 '16 at 2:35
  • the files containing the headers to create a child themes do not contain php. They are css files. – Scotty Jakes Nov 28 '16 at 2:39
  • You have template files that contain PHP that can only be run within a certain context- when that specific page is being viewed. You need to be able to read the headers without running that code, so they can't be executed as PHP files in any other context. CSS files can't contain PHP, they would be invalid CSS files. – Milo Nov 28 '16 at 2:47
0

The reason for using headers placed within comments is it gives WordPress core and WordPress libraries for themes and plugins a way read data they need in a secure and simple way. Alternatives, such as putting the data in configuration files, are seen as either more complicated, less secure or both. The WordPress development team puts more weight on "simple and secure" than on keeping required elements out of the comments within files.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.