Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#30819 closed enhancement (wontfix)

Getting info on default theme(s)

Reported by: donutz's profile donutz Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2
Component: Themes Keywords:
Focuses: Cc:

Description

I was looking for an array of default WP themes, but found that $default_themes in the WP_Theme class is private. Easy access to info on default themes seems a bit lacking, so I wrote this little method for WP_Theme (named get_default(), in analogy to existing get_allowed()) which returns info based on a $key provided:

  • theme: returns default theme object
  • stylesheet: returns default theme "slug"
  • installed: returns array of installed default themes
  • active: returns theme object if a default theme is active, otherwise false
  • themes (or default): returns the $default_themes array

I attached a .diff file for your consideration.

Attachments (1)

30819.diff (1000 bytes) - added by donutz 10 years ago.

Download all attachments as: .zip

Change History (7)

@donutz
10 years ago

#1 @obenland
10 years ago

What's not working for you with wp_get_theme( WP_DEFAULT_THEME )?

Last edited 10 years ago by obenland (previous) (diff)

#2 @donutz
10 years ago

That works fine, not sure why you're asking? My main goal is to be able to access $default_themes, and use that data to check if a default (or bundled) theme is active. I'd be happy with a get_default_themes() method simply returning the value of $default_themes. I was thinking plugins could use that info to dynamically provide appropriate styling for whatever they print on the front end (add a body class selector, enqueue an extra stylesheet, ...).

#3 @obenland
10 years ago

I'm fairly hesitant to make that public, tbh. It's really not something theme or plugin authors can't work around, and I'd rather avoid creating confusion with the concept of a default theme for a site.

get_default_theme() could very well return a WP_Theme object of the default theme for a site (like I fist thought you were referring to). It's also not necessarily relevant information about the theme that's instantiated.

I honestly think we'd make it harder to use the API, not easier.

#4 @nacin
10 years ago

The sole purpose of $default_themes is to resolve conflicts when a default theme directory is copied or moved, and the theme name isn't changed. The name of such a "pretender" theme is appended with the directory name. It's otherwise not something that warrants any kind of exposure. If we weren't so picky about little details like this, it wouldn't exist.

I definitely wouldn't want to introduce a get_default() method with so much parameter complexity. I could perhaps go for a get_default_themes() method, but I'd question why. Someone using get_default_themes() may want to know that themes are allowed in a subdirectory, including default themes, so for example on wordpress.org, you'd be looking at core/twentyfifteen.

Of course, the alternative is people hardcode in a search for "twenty*" which isn't any better.

I suppose I just don't understand the use case. I needed access to $default_themes just last week, and then I realized I was doing something kind of stupid and shouldn't do that.

#5 @obenland
10 years ago

I don't think it would be good practice to instantiate a WP_Theme object to gain access to the name of default themes anyway. It's more likely than not unrelated to the theme instance itself.

It's otherwise not something that warrants any kind of exposure.

I agree.

#6 @obenland
10 years ago

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

Thanks for bringin up the idea, donutz.

At this time I think it's not something to add that to WP_Theme however, as it's not something that is necessarily in relation to the object the information is derived from.
I'd recommend checking against a defined list of default themes, or extending WP_Theme if necessary.

Note: See TracTickets for help on using tickets.