Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 11 years ago

#12745 closed defect (bug) (fixed)

Call to undefined function get_post_thumbnail_id()

Reported by: dphiffer's profile dphiffer Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: General Keywords: reporter-feedback
Focuses: Cc:


Hope this isn't a duplicate, but post thumbnails seem to be broken in the current trunk revision (13871). If I upload an image on a post I get:

Fatal error: Call to undefined function get_post_thumbnail_id() in /path/to/wp-admin/includes/media.php on line 1284

Change History (13)

#1 @dphiffer
14 years ago

  • Cc dphiffer added

#2 @kovshenin
14 years ago

Can't reproduce, worksforme.

#3 @jorbin
14 years ago

  • Cc aaron@… added
  • Keywords reporter-feedback added

also can't reproduce, works for me on php 5.2.9. can you provide some more information on your setup such as php version. Is it only when uploading images through the post thumbnail selector or through the regular media uploader as well?

#4 @nacin
14 years ago

get_post_thumbnail_id() is in a file (post-thumbnail-template.php) that is conditionally loaded, assuming the theme supports thumbnails. This requires add_theme_support('post-thumbnails') to be called on the after_setup_theme hook (or no hook), not init, which is too late for require_if_theme_supports().

Thus, whenever we call one of those functions, we first have to check for current_theme_supports. We do that on line 1284.

It's kind of confusing, and not entirely necessary to conditionally load these functions (we could simply have done if ( ! current_theme_supports('post-thumbnails') ) return false;) but it was designed with forward-thinking and scalability in mind.

#5 @nacin
14 years ago

This definitely causes confusion:

The other issue of course is removing support for thumbnails from a theme (i.e. from a child theme) will blow up the theme any time one of the post thumbnail template functions are used.

I'm questioning thus wrapping add_theme_support('post-thumbnails') in a function in twentyten that could be overridden in a child theme. If you wanted to *remove* thumbnail support, good portions of twentyten would generate fatal errors.

#6 @dphiffer
14 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Thanks nacin, et al. I was calling this within my 'init' hook.

#7 @nacin
14 years ago

  • Milestone Unassigned deleted

#8 @nacin
14 years ago

Not a problem.

#9 @christian_gnoth
13 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Type changed from defect (bug) to task (blessed)
  • Version set to 3.0.1

if I search on for the hook I can not find a documentation of that.

So the documentation on should contain that hint in which hook the theme support for post_thumbnails should be added.

#10 @blepoxp
13 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed
  • Type changed from task (blessed) to defect (bug)

#11 @markoheijnen
12 years ago

I think there should be a real solution for this. If this was just a front-end issue it would be fine with me but it isn't.
When using it in the back-end it also creates the error. I know you can/should check if the theme supports it because you can show a warning to the user.

#12 @markoheijnen
12 years ago

  • Cc marko@… added

#13 @SergeyBiryukov
11 years ago

#23628 was marked as a duplicate.

Note: See TracTickets for help on using tickets.