#25334 closed defect (bug) (fixed)
With custom page templates set per page, surprising behavior after switching themes
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.2 | Priority: | normal |
| Severity: | normal | Version: | 3.8 |
| Component: | Themes | Keywords: | has-patch |
| Focuses: | administration | Cc: |
Description
If you have custom page templates set for a page, and you switch to a new theme that has no custom templates, bizarre behavior ensues.
When editing one of these pages, upon saving, everything looks fine. But actually, there was is a silent failure around post.php:2903:
if ( !empty($page_template) && 'page' == $data['post_type'] ) {
$post->page_template = $page_template;
$page_templates = wp_get_theme()->get_page_templates();
if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
if ( $wp_error )
return new WP_Error('invalid_page_template', __('The page template is invalid.'));
else
return 0;
}
update_post_meta($post_ID, '_wp_page_template', $page_template);
}
Since the page template is still set for this page, but does not exist in the theme, the function returns early, which means we don't hit a few crucial hooks - edit_post, save_post, and wp_insert_post.
Attachments (1)
Change History (8)
Note: See
TracTickets for help on using
tickets.
I was able to reproduce that as well. Creating a page and assigning a page template from a theme works OK, when switching to a new theme and updating the page it returns earlier in the code above. The problem exists "forever", i.e. if you save the page with the old template a couple times, it would still fall in that same block (and hooks such as
save_postare not fired at all).Any way we could always ignore that issue and just set the default template (or at least whenever
$wp_errorisfalse?)