Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#54833 closed enhancement (fixed)

Twenty Eleven: screen_icon() and get_current_theme() are deprecated

Reported by: presskopp's profile Presskopp Owned by: sergeybiryukov's profile 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)

54833.diff (716 bytes) - added by cu121 2 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.
54833.2.diff (6.3 KB) - added by viralsampat 2 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.
54833.3.diff (722 bytes) - added by SergeyBiryukov 2 years ago.
54833.4.diff (726 bytes) - added by SergeyBiryukov 2 years ago.

Download all attachments as: .zip

Change History (12)

#1 @Presskopp
2 years ago

  • Summary changed from Twenty Eleven: get_current_theme() is deprecated to Twenty Eleven: screen_icon() and get_current_theme() are deprecated

screen_icon() is also deprecated so here's my patch:

function twentyeleven_theme_options_render_page() {
        ?>
        <div class="wrap">
                <?php $theme_name = wp_get_theme(); ?>
                <h2>
...

#2 @Presskopp
2 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?

@cu121
2 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 @costdev
2 years ago

  • Keywords has-patch added; needs-patch removed

@viralsampat
2 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 @tomjdv
2 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.


2 years ago

#6 follow-up: @SergeyBiryukov
2 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 with wp_get_theme()->get( 'Name' ). I thought wp_get_theme() returns the theme object and not the theme name, so I was confused for a bit here. However, looking at [20039] / #20138, the WP_Theme class has a __toString() method, so this should work as expected. Still, using wp_get_theme()->get( 'Name' ) explicitly would avoid the confusion, and that's what we use in other instances, e.g. in get_theme_mods(), remove_theme_mods(), or the deprecated get_current_theme() function.
Last edited 2 years ago by SergeyBiryukov (previous) (diff)

#7 in reply to: ↑ 6 @SergeyBiryukov
2 years ago

Replying to SergeyBiryukov:

wp_get_theme() is replaced with wp_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.

#8 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 53626:

Twenty Eleven: Replace deprecated function calls on theme options page.

This includes:

  • Removing the deprecated screen_icon() function call.
  • Replacing the deprecated get_current_theme() function call with get_option( 'current_theme' ).
  • Using wp_get_theme()->display( 'Name' ) explicitly instead of relying on WP_Theme's __toString() method, for clarity.

Follow-up to [6334], [20039], [20040], [20042], [20508], [26537], [41274].

Props Presskopp, cu121, viralsampat, costdev, tomjdv, sabernhardt, SergeyBiryukov.
Fixes #54833.

Note: See TracTickets for help on using tickets.