Opened 3 years ago
Closed 3 years ago
#54833 closed enhancement (fixed)
Twenty Eleven: screen_icon() and get_current_theme() are deprecated
Reported by: | Presskopp | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Bundled Theme | Keywords: | good-first-bug has-patch |
Focuses: | Cc: |
Description
In twentyeleven_theme_options_render_page()
get_current_theme() is used (\inc\theme-options.php), which is deprecated. wp_get_theme() should be used instead.
Attachments (4)
Change History (12)
#1
@
3 years ago
- Summary changed from Twenty Eleven: get_current_theme() is deprecated to Twenty Eleven: screen_icon() and get_current_theme() are deprecated
#2
@
3 years ago
Ah, just now it came into my mind, that this may be as it is to work with older core installations. But why is twenty eleven the only theme where this still is to find?
@
3 years ago
Removed the deprecated screen_size(), since it does produce any output during render, get_current_theme() replaced with static value, since a theme name is static.
@
3 years ago
Removed the deprecated screen_size(), since it does produce any output during render, get_current_theme() replaced with static value, since a theme name is static. Also, made small changes based on coding standard.
#4
@
3 years ago
@viralsampat I think get_current_theme()
is necessary when using child themes, where the name is not the same as the parent theme's name. I think it might be better to use the following snippet:
<?php if ( $theme = get_option( 'current_theme' ) ) return $theme; return wp_get_theme()->get('Name');
This ticket was mentioned in Slack in #core by sabernhardt. View the logs.
3 years ago
#6
follow-up:
↓ 7
@
3 years ago
- Milestone changed from Awaiting Review to 6.1
Hi there, thanks for the ticket and the patches!
I think 54833.3.diff should work here:
screen_icon()
is removed, as it was soft-deprecated in [26537] / #26119 and formally deprecated in [41274] / #41153.- The
current_theme
option was introduced for WordPress 2.5 in [6334] / #5346. Since Twenty Eleven requires WordPress 3.2 or later, I think we can rely on the option being available. wp_get_theme()
is replaced withwp_get_theme()->get( 'Name' )
. I thoughtwp_get_theme()
returns the theme object and not the theme name, so I was confused for a bit here. However, looking at [20039] / #20138, theWP_Theme
class has a__toString()
method, so this should work as expected. Still, usingwp_get_theme()->get( 'Name' )
explicitly would avoid the confusion, and that's what we use in other instances, e.g. inget_theme_mods()
,remove_theme_mods()
, or the deprecatedget_current_theme()
function.
#7
in reply to:
↑ 6
@
3 years ago
Replying to SergeyBiryukov:
wp_get_theme()
is replaced withwp_get_theme()->get( 'Name' )
.
Minor update on this in 54833.4.diff, wp_get_theme()->display( 'Name' )
appears to be a more accurate replacement that matches the WP_Theme::__toString()
method, returning the theme's translated name.
screen_icon()
is also deprecated so here's my patch: