WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#40467 new defect (bug)

Hardcoding Template and Stylesheet paths inside the wp-config.php leads to "constant already defined in default-constants.php"

Reported by: rkoller Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch reporter-feedback
Focuses: template, performance Cc:

Description

I've tried to hardcode the Template and Stylesheet directory inside the wp-config with:

<?php
define('TEMPLATEPATH', '/app/public/wp-content/themes/twentyseventeen');
define('STYLESHEETPATH', '/app/public/wp-content/themes/twentyseventeen');

The paths I've got from

get_template_directory()

and

get_stylesheet_directory()


I've tried with WP 4.7.3 on Local from Flywheel with Twentyseventeen as theme. But as soon as I save the two defines I get:

Notice: Constant TEMPLATEPATH already defined in /app/public/wp-includes/default-constants.php on line 343

Notice: Constant STYLESHEETPATH already defined in /app/public/wp-includes/default-constants.php on line 349

I've also tried with :

<?php
define( TEMPLATEPATH, get_template_directory() );
define( STYLESHEETPATH, get_stylesheet_directory() );

liked listed in the codex:

https://codex.wordpress.org/Editing_wp-config.php

But that resulted in

Fatal error: Call to undefined function get_template_directory() in /app/public/wp-config.php on line 75

But it could be easily fixed by adding if statements inside the default-constants.php function for TEMPLATEPATH and STYLESHEETPATH I suppose

Attachments (1)

40467.diff (787 bytes) - added by f.staude 2 years ago.
patch

Download all attachments as: .zip

Change History (3)

@f.staude
2 years ago

patch

#2 @ocean90
2 years ago

  • Keywords reporter-feedback added
  • Version 4.7.3 deleted

What's the use case for defining the TEMPLATEPATH and STYLESHEETPATH constants which are both kinda deprecated (#18298, #20027)?

I see you added the performance keyword, have you done any before/after tests? What are the results?

Note: See TracTickets for help on using tickets.