WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 14 months ago

#12745 closed defect (bug) (fixed)

Call to undefined function get_post_thumbnail_id()

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

Description

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)

comment:1 dphiffer4 years ago

  • Cc dphiffer added

comment:2 kovshenin4 years ago

Can't reproduce, worksforme.

comment:3 jorbin4 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?

comment:4 nacin4 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.

comment:5 nacin4 years ago

This definitely causes confusion:

http://wordpress.org/support/topic/355685
http://www.google.com/search?q=get_post_thumbnail_id

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.

comment:6 dphiffer4 years ago

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

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

comment:7 nacin4 years ago

  • Milestone Unassigned deleted

comment:8 nacin4 years ago

Not a problem.

comment:9 christian_gnoth4 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 wordpress.org for the hook I can not find a documentation of that.

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

comment:10 blepoxp4 years ago

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

comment:11 markoheijnen2 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.

comment:12 markoheijnen2 years ago

  • Cc marko@… added

comment:13 SergeyBiryukov14 months ago

#23628 was marked as a duplicate.

Note: See TracTickets for help on using tickets.