Make WordPress Core

Opened 7 years ago

Closed 2 years ago

#40467 closed defect (bug) (invalid)

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

Reported by: rkoller's profile rkoller Owned by:
Milestone: 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 7 years ago.
patch

Download all attachments as: .zip

Change History (4)

@f.staude
7 years ago

patch

#2 @ocean90
7 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?

#3 @hellofromTonya
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hello @rkoller,

Welcome back to WordPress Core Trac!

The notices you're seeing are because these two constants are defined in wp-includes/default-constants.php. The fatal error is because those functions have not yet been loaded into memory.

The constants are defined and populated during the initialization of WordPress.

WordPress automatically populates those constants using the activated theme. See the docs for `get_stylesheet_directory()` and `get_template_directory()`.

Why hardcode the absolute path to the current theme rather than activating the theme and letting WordPress automatically detect and set the absolute path? Is there a compelling reason?

As it's been over 4 years with no activity and the errors are doing it wrong, closing this ticket.

@rkoller if there's a compelling reason to hardcode the constants, please reopen and share the why and reasoning for further discussion and consideration.

Note: please don't be offended by the close reason of `invalid`, as this keyword means it's not a bug.

Note: See TracTickets for help on using tickets.