Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#14720 closed defect (bug) (invalid)

get_bloginfo code, with get_template_* and get_stylesheet_*

Reported by: frumph's profile Frumph Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: close
Focuses: Cc:

Description (last modified by nacin)

wp-includes/general-template.php line 436 (WP 3.0.1)

		case 'stylesheet_url':
			$output = get_stylesheet_uri();
			break;
		case 'stylesheet_directory':
			$output = get_stylesheet_directory_uri();
			break;
		case 'template_directory':
		case 'template_url':
			$output = get_template_directory_uri();
			break;

The problem with this is, template_directory and stylesheet_directory should be getting the get_template_directory() and get_stylesheet_directory() and not the URI portion of it, since the difference between the two is major, if someone wants to get the path location on the system rather then the URI

I can recognize _url being used to get the URL of course, but the path isn't being represented, so in favor of of using the get_bloginfo() i've kept using the get_* functions instead.

Change History (10)

#1 @nacin
14 years ago

  • Keywords close added

I can recognize _url being used to get the URL of course, but the path isn't being represented, so in favor of of using the get_bloginfo() i've kept using the get_* functions instead.

Using the get_* functions is perfectly fine. We could even deprecate some of these bloginfo() arguments and point them to the proper alias functions, but it really doesn't matter much. The bloginfo() function handles URIs only (and it being a template tag, this makes sense); if you want the server paths you'll need to use those functions.

Yeah, the naming is a little goofy -- template_directory passed to bloginfo() gives you the URI, while get_template_directory() returns the server path... But other than that, I don't see a bug here. Suggesting worksforme, unless I'm missing something?

#2 @Frumph
14 years ago

You're missing this:

get_template_directory() - goes to the "path"
get_template_directory_uri() - goes to the "url"

get_stylesheet_directory() goes to the "path"
get_stylesheet_directory_uri() goes to the "url"

All of the above goes to the 'url' only.

When you look at it, and look at how people try to understand it's function including chip bennett's addition to the codex for the theme review: http://codex.wordpress.org/Theme_Review#Template_Tags_and_Hooks

People are expecting bloginfo( 'stylesheet_directory' ) and bloginfo( 'template_directory' ) to be the path.

While the codex here: http://codex.wordpress.org/Function_Reference/bloginfo
denotes they're exactly the same, the functionality (imo) should be that one is the path and the other the URL.

If you can notice that stylesheet_directory and stylesheet_url are both referencing the same url it is pretty much meaning you could use either, however logically you would think that URL means the URL and the directory would be the path.

Just trying to keep a semblance of standard of thinking that they should in fact mean two separate things.

#3 @nacin
14 years ago

I got that. I'm not arguing that the names between the functions and the bloginfo arguments are inconsistent. I agree. It *can* be confusing.

The reasoning for it is this. bloginfo() is a template tag, primarily used in themes. Theme developers will never need the path; they always want the URI. Thus why stylesheet_directory returns the publicly consumed URI instead of the path. If I had to guess, these were around for longer than the corresponding functions, which are named better for sure.

My point is, we're not changing the functionality of them, and there already exist more functions (with better names) that cover the functionality.

#4 @scribu
14 years ago

Related: #11215

#5 follow-up: @Frumph
14 years ago

I disagree with never needing the path, for the thought of for example checking if a file exists before including it to be one. I use it quite often with ComicPress.

*note* I do understand it when you say it handles URI's only, my thinking on it is that since bloginfo handles 'basic' structure information that it could also include paths like the wp_upload_dir does.

I also understand there are better functions and I get what your saying. With the following:

I'm not sure this is possible but worth a thought, an addition to the bloginfo might be a wp_set_cache that would retain the information for the page load instead of calling the functions every time, but I'm not sure the ramifications of that since i'm not familiar with how that all works, sort of like a way to speed up the calls? (unknown to me), in my mind (of what I know about how wp_cache_set works) I would think it would help with processing and speeding things up.

Which means that if the central location for information that is used within a theme that uses the bloginfo including the core code (that had all of the information present) processed it faster it would be a boone for all, but again i'm not really proficient in that area.

#6 in reply to: ↑ 5 @nacin
14 years ago

Replying to Frumph:

I disagree with never needing the path, for the thought of for example checking if a file exists before including it to be one. I use it quite often with ComicPress.

Sure. If you need the path, then use get_template_directory_uri()... User content shouldn't end up in a theme directory, but I'm sure there's a valid use case for needing to check if a file exists.

I'm not sure this is possible but worth a thought, an addition to the bloginfo might be a wp_set_cache that would retain the information for the page load instead of calling the functions every time, ...

These functions are cached at a lower level. Example:

get_template_directory() calls get_template() (wrapper for get_option(), in turn cached via autoloaded options). It also calls get_theme_root(), which calls get_theme_roots(), in turn is cached in a site transient, which is set by get_themes().

The _uri() functions call get_theme_root_uri() instead of get_theme_root(), which again ends up calling get_theme_roots().

Related: #11215

scribu: Actually, this is confusion over directory versus directory_uri, as opposed to child/stylesheet versus parent/template.

#7 @Frumph
14 years ago

Okay so let me get this straight, you're saying instead of having a central function that is recognizable to have quite a few options for theme developers, the template_directory and stylesheet_directory would be more logical to stick with as a URI instead of the server path to the directory.

Okay, well that's cool

My last thoughts before you close this. The bloginfo is recognizable as a function to use, inside themes. Theme developers utilize it *and* the other information like get_template_directory() which is different then get_template_directory_uri() one contains a path the other the URI, so just to make sure, of course there's no problem with themes to use multiple functions, but you're saying that it's not really that important we just need to make the distinction that bloginfo('template_directory') is *not* the path and to use get_template_directory() instead. While the general expectation would be that it is the path.

The purpose of the same 'template_directory' and 'template_directory_uri' being the same does not make sense. But hey again, I know what you're saying and I realize there are other ways of dealing with it, and it's not up to me but if it were, I would want bloginfo to be a central function that is recognized to have the information that theme users could use to develop with instead of a mixmatch of various different functions.

#8 @Frumph
14 years ago

My suggestion then is renaming the functions get_template_directory() and get_template_directory_uri() and get_stylesheet_directory() and get_stylesheet_directory_uri() since each counterpart gives a different return value, the naming convention makes bloginfo's naming convention of its variables counter-productive.

#9 @nacin
14 years ago

The general rule of thumb as I've seen it, is that most theme designers who dabble in WordPress template tags enjoy the idea of a single function they can call and they will know exactly what it does. Many WP template tags don't take or don't require function arguments, and that's partly because template tags are designed to be simple and not feel like PHP functions.

I don't like the idea of one-size-fits-all functions like bloginfo(). It's been around for a while, but if you look at its source, a lot of its arguments just call other functions. So ultimately it comes down to preference.

You were confused about bloginfo('template_directory') versus get_template_directory_uri() versus get_template_directory(), but most theme developers wouldn't be, because A) they have little purpose for the path and probably have no concept of the alternative, B) it's dead simple to echo the results of these functions and determine what determines what, and C) if they *do* need the path, there's a function for it and they'll find it.

The point is, 'template_directory' and 'template_directory_uri' are the same in bloginfo() and that simply won't change. Without even checking svn blame I am willing to bet that 'template_directory' came first, and that when we added the path functions, they added the URI argument so there was some consistency (or at least, not complete contradiction).

The functions themselves are named fine, so I see no reason to rename those either. There's no need to mix and match the concepts because the functions serve all of the purposes, while bloginfo() also happens to exist as an alternative. I'd think in terms of one or the other -- comparing them will be futile and we have far bigger (and less obvious) naming inconsistencies.

#10 @nacin
13 years ago

  • Description modified (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.