-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace use of get_stylesheet_directory() with __DIR__ #221
Comments
Thank you @nickcernis for opening this ticket. I'd like to add a few things to the discussion: When loading files from where you are right now in the filesystem,
And then there's the performance side of calling /**
* Retrieve stylesheet directory path for current theme.
*
* @since 1.5.0
*
* @return string Path to current theme directory.
*/
function get_stylesheet_directory() {
$stylesheet = get_stylesheet();
$theme_root = get_theme_root( $stylesheet );
$stylesheet_dir = "$theme_root/$stylesheet";
/**
* Filters the stylesheet directory path for current theme.
*
* @since 1.5.0
*
* @param string $stylesheet_dir Absolute path to the current theme.
* @param string $stylesheet Directory name of the current theme.
* @param string $theme_root Absolute path to themes directory.
*/
return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root );
} Each time you invoke it, It calls multiple functions and fires a filter. Performance
|
Mixed feelings. I've always felt "get_stylesheet_directory" was the "WordPress Way" and should always be used. Thats said, you're right, it makes little sense in a child theme unless your anticipating someone deleting a file from a child theme with the expectation that it'll revert to the parent. Someone wiser than me should think about if/how this would affect Genesis 3.0 "as a plugin" though. Finally, no fallback. 5.3 is dead. WP 5.2 is in beta and is declaring PHP 5.6 as minimum supported version. "Genesis Sample" certainly doesn't need to support pre 5.6 anymore. |
+1 for using |
|
@hellofromtonya suggests that we consider replacing use of
get_stylesheet_directory()
with__DIR__
(ordirname( __FILE__ )
for pre PHP 5.3 support) in Genesis Sample and StudioPress child themes:Pros
__DIR__
is only faster by the tiniest fraction of a second, but it is still faster.)get_stylesheet_directory()
apparently causes confusion for some developers new to WordPress core functions as to what path it's relative to.__DIR__
is more explicit and clearly defined as “the directory of the file”.Cons
__DIR__
andget_stylesheet_directory()
require some knowledge/reading of docs for those new to development — there may be some who find__DIR__
more cryptic than the WP function.The text was updated successfully, but these errors were encountered: