WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#20138 closed defect (bug) (fixed)

What happens to get_current_theme()?

Reported by: nacin Owned by:
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: Cc:

Description (last modified by nacin)

After #20103, get_current_theme() is only useful for returning the theme name untranslated. It no longer serves as a key anywhere (like for get_themes()), and we previously phased it out in the theme mod functions.

The question is, what to do with it?

No theme in http://wpcom-themes.svn.automattic.com uses get_current_theme() in the footer (only on theme options pages), but that doesn't mean some other theme isn't doing exactly that. On one hand, if we eliminate the current_theme option, get_current_theme() will force style.css to be read, which normally does not happen on the frontend. But, if we keep the current_theme option, the name will not be translated.

My current thought is this:

  1. Deprecate get_current_theme(). Have it call wp_get_theme()->get('Name'), as it does now, but remove the current_theme option all together. No more caching the style.css read.
  2. Introduce a new way to get a theme name.

Point 2 is interesting. I think it could be solved with a fancy __toString() method on WP_Theme, which means that echo wp_get_theme() could actually echo wp_get_theme()->display('Name'). Or, another function.

Both points leave a conundrum, though — whether style.css reads (a single style.css read, not every theme) are not the end of the world on the frontend.

I had a cursory thought about forcing WP_Theme, wp_get_themes(), and wp_get_theme() to only be used in the admin, and force the includes/admin.php bootstrap to load for the very few situations where we'll need it (update checks, switch_theme(), the new customizer, and deprecated compat).

I am going to do some profiling to see how bad the fread is. We already do plenty of file_exists checks as part of the template loader, so one or two more of those are not the end of the world.

Change History (8)

#1 @nacin
6 years ago

  • Description modified (diff)

#2 @nacin
6 years ago

In [20033]:

Update switch_theme() to use wp_get_theme(). see #20103, #20138.

#3 @scribu
6 years ago

get_current_theme() still seems to be used in a few places in Core.

#4 @nacin
6 years ago

In [20039]:

(string) WP_Theme is now the theme name, translated. Good replacement for get_current_theme(); better than wp_get_theme()->display('Name'). see #20103, see #20138.

#5 @nacin
6 years ago

wp_get_theme() is mighty fast. Took 0.20% of processing time after adding it to the footer of Twenty Eleven as a test. get_current_theme() hitting get_option('current_theme') was five times faster, but this is a very safe trade-off for everything else we're getting in return.

#6 @nacin
6 years ago

In [20040]:

Deprecate get_current_theme(). Use (string) wp_get_theme() to get the translated name of the theme. Keep the current_theme option for now. see #20103, see #20138.

#6 @nacin
6 years ago

In [20042]:

Can haz recursion? get_current_theme() is deprecated in favor of wp_get_theme(), not itself. props duck_. see #20138.

#7 @nacin
6 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.