[wp-trac] [WordPress Trac] #21268: _wp_page_template is getting 'stuck' to a page

WordPress Trac noreply at wordpress.org
Fri Oct 11 07:12:07 UTC 2013


#21268: _wp_page_template is getting 'stuck' to a page
--------------------------+------------------------------
 Reporter:  shawmutsteve  |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  3.4.1
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by cbaldelomar):

 This could be solved by changing the following line of code on line 659 in
 file 'wp-admin/includes/meta-boxes.php'

 {{{
         if ( 'page' == $post->post_type && 0 != count(
 get_page_templates() ) ) {
 }}}
 to
 {{{
         if ( 'page' == $post->post_type ) {
 }}}

 This would always cause a dropdown to be displayed in the Page Attributes
 Meta Box even if "Default Template" is the only page template option.

 [[Image(http://webplantmedia.com/assets/Screen-
 Shot-2013-10-11-at-2.06.27-AM.jpg)]]

 This could be a very frustrating experience for a new Wordpress user, who,
 after switching themes, will no longer be able to update their post_meta
 fields because their page template is "stuck" on some other themes page
 template.

 Consider this bit of code in 'wp-includes/post.php'. The code will fail
 when checking for a valid page template, and never run the function,
 update_post_meta(); So plugins like Yoast SEO or any other using custom
 meta fields will not be able to save new inputs.

 {{{
         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);
         }
 }}}

 I hope this is helpful for someone and that this problem can get solved.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/21268#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list