Opened 13 years ago
Closed 13 years ago
#19814 closed defect (bug) (duplicate)
add_theme_support() inside init hook function breaks post attachments
Reported by: | jamesmehorter | Owned by: | James Mehorter |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.1 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
When adding post-thumbnail support to a theme via add_theme_support(), inside of an init hook function, the post media attachments no longer work. Simply placing the add_theme_support() call outside of the init hook function corrects this. See attached screenshots for display of the issue.
<?php //WORKS - The 'Add Media' panel works as expected //Initiate our theme setup add_action( 'init', 'baltimore_theme_setup' ); //Adding thumbnail image support to our 'Form' custom post type add_theme_support('post-thumbnails'); set_post_thumbnail_size( 150, 194, true ); // Normal post thumbnails function baltimore_theme_setup() { // This theme styles the visual editor with editor-style.css to match the theme style. add_editor_style(); // This theme uses wp_nav_menu() in one location. register_nav_menu( 'primary', __( 'Primary Menu', 'baltimore' ) ); //Create the 'form-page' post type register_post_type('form-page', 'supports' => array('thumbnail'); //Create the 'type' taxonomy for the 'form-page' post type register_taxonomy('form-page-type', 'form-page'); }//end baltimore_setup //------------------------------------------------- //DOES NOT WORK - Breaks the 'Add Media' panel //DETAILS: The 'Add Media' panel for the post type 'form-page' opens, and allows you to upload media, but the uploaded media is not attached to the post. You can upload a media item, but it halts at 'Crunching'. Going into the Media > Library does show the media item, but it's not attached to the post. Similarly, going into the post after uploaded, and going into the Gallery tab of 'Add Media', shows no media items. //Initiate our theme setup add_action( 'init', 'baltimore_theme_setup' ); function baltimore_theme_setup() { //Adding thumbnail image support to our 'Form' custom post type add_theme_support('post-thumbnails'); set_post_thumbnail_size( 150, 194, true ); // Normal post thumbnails // This theme styles the visual editor with editor-style.css to match the theme style. add_editor_style(); // This theme uses wp_nav_menu() in one location. register_nav_menu( 'primary', __( 'Primary Menu', 'baltimore' ) ); //Create the 'form-page' post type register_post_type('form-page', 'supports' => array('thumbnail'); //Create the 'type' taxonomy for the 'form-page' post type register_taxonomy('form-page-type', 'form-page'); }//end baltimore_setup ?>
Attachments (1)
Change History (3)
#1
@
13 years ago
Calling add_theme_support( 'post-thumbnails' )
on init
action and trying to upload an image on the Edit Post screen results in the error:
Fatal error: Call to undefined function get_post_thumbnail_id() in wp-admin/includes/media.php on line 1169
The reason is that post-thumbnail-template.php
is required before init
:
http://core.trac.wordpress.org/browser/tags/3.3.1/wp-settings.php#L291
So init
is too late to call add_theme_support( 'post-thumbnails' )
. That said, both uploading and attaching images to posts seem to work in current trunk (in spite of the error).
This file shows a screenshot of broken post attachments