• While reviewing error logs we noticed WordPress is still using/referencing “TEMPLATEPATH” yet its depreciating in the next version of PHP?

    We should not be updating the core wordpress files so we were wondering if this code was to be updated in the next wordpress version?

    Example of error:
    Use of undefined constant STYLESHEETPATH – assumed ‘STYLESHEETPATH’ (this will throw an Error in a future version of PHP) in /wp-includes/template.php on line 634

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • STYLESHEETPATH and TEMPLATEPATH are not, as far as I can tell, deprecated. Regardless, since they are WordPress constants PHP itself cannot deprecate them.

    What’s been deprecated is the feature where PHP will interpret unquoted strings as strings if there’s no constant with that name.

    For example, if you try to do something like this:

    $variable = value

    The lack of quotes means value is interpreted as a Constant. In current versions of PHP however, if there is no constant named value then PHP will interpret it as 'value', a string. PHP will not do this anymore in the next major version. That’s what the warning is about. See the first section here.

    Why you’re seeing this error for constants that definitely are defined in WordPress is the real issue you need to solve. I’d start by performing a manual update, to make sure you have up-to-date versions of all core files.

    Thread Starter mract

    (@mract)

    I’m using quoted strings though in all my functions I’ve created and it’s referencing the file “template.php” not my functions.php?

    I have the most recent version of WordPress and it’s referencing the error on line 634 and 637 of this file: https://developer.www.ads-software.com/reference/functions/locate_template/

    I’m not certain what I’m supposed to change when it’s using the latest version and the error log is reporting this error every second?

    [13-Jul-2018 18:20:44 UTC] PHP Warning:  Use of undefined constant STYLESHEETPATH - assumed 'STYLESHEETPATH' (this will throw an Error in a future version of PHP) in /public_html/wp-includes/template.php on line 634
    
    [13-Jul-2018 18:20:44 UTC] PHP Warning:  Use of undefined constant TEMPLATEPATH - assumed 'TEMPLATEPATH' (this will throw an Error in a future version of PHP) in /public_html/wp-includes/template.php on line 637
    
    Thread Starter mract

    (@mract)

    Still trying to find a solution to this problem.. Jacob’s suggestion to look for unquoted strings didn’t help since this error references a specific WordPress function..

    PHP Warning: Use of undefined constant STYLESHEETPATH – assumed ‘STYLESHEETPATH’ (this will throw an Error in a future version of PHP) in /public_html/wp-includes/template.php on line 634

    Full Function

    function locate_template($template_names, $load = false, $require_once = true ) {
    	$located = '';
    	foreach ( (array) $template_names as $template_name ) {
    		if ( !$template_name )
    			continue;
    		if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
    			$located = STYLESHEETPATH . '/' . $template_name;
    			break;
    		} elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
    			$located = TEMPLATEPATH . '/' . $template_name;
    			break;
    		} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
    			$located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
    			break;
    		}
    	}
    
    	if ( $load && '' != $located )
    		load_template( $located, $require_once );
    
    	return $located;
    }

    Line 634:

    if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
    			$located = STYLESHEETPATH . '/' . $template_name;
    			break;
    		}
    • This reply was modified 6 years, 3 months ago by mract. Reason: Updated info

    I too am annoyed by this as it fills up the error log but I am equally annoyed by the PHP 7.2 rules…

    The solution to the problem might be considered as follows:
    https://stackoverflow.com/questions/48236765/undefined-constant-error-in-php-7-2

    The constants TEMPLATEPATH and STYLESHEETPATH in /wp-includes/theme.php on line 136 seem to not be declared at this time? very odd…

    This deserves a closer examination by WordPress Dev Team.

    Consider the following errors:

     function is_child_theme() {
           return ( TEMPLATEPATH !== STYLESHEETPATH );
    } 

    PHP Warning: Use of undefined constant TEMPLATEPATH – assumed ‘TEMPLATEPATH’ (this will throw an Error in a future version of PHP) in /wp-includes/theme.php on line 136

    This also causes an error

     function is_child_theme() {
    	$STYLESHEETPATH = constant("TEMPLATEPATH"); 
            $TEMPLATEPATH = constant("STYLESHEETPATH");
    	return ( $TEMPLATEPATH !== $STYLESHEETPATH );
    } 

    PHP Warning: constant(): Couldn’t find constant TEMPLATEPATH in /wp-includes/theme.php on line 136

    Very strange… only solution at this time is to disable logging and wait for a patch.

    Has anyone found a solution to this? Seems to be an issue in WordPress core…

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘“TEMPLATEPATH” depreciated but still included in multiple core WordPress Files?’ is closed to new replies.