WordPress.org

Make WordPress Core

Ticket #26809: 26809.1.patch

File 26809.1.patch, 1.1 KB (added by bobbingwide, 6 years ago)

Do not fail when theme does not support page templates

  • wp-includes/post.php

    diff --git a/wp-includes/post.php b/wp-includes/post.php
    index 5ef96b3..4b9c776 100644
    a b function wp_insert_post( $postarr, $wp_error = false ) { 
    29632963        if ( !empty($page_template) && 'page' == $data['post_type'] ) {
    29642964                $post->page_template = $page_template;
    29652965                $page_templates = wp_get_theme()->get_page_templates();
    2966                 if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
    2967                         if ( $wp_error )
    2968                                 return new WP_Error('invalid_page_template', __('The page template is invalid.'));
    2969                         else
    2970                                 return 0;
    2971                 }
    2972                 update_post_meta($post_ID, '_wp_page_template',  $page_template);
     2966    if ( count( $page_templates ) ) {
     2967                  if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
     2968                          if ( $wp_error )
     2969                                  return new WP_Error('invalid_page_template', __('The page template is invalid.'));
     2970                          else
     2971                                  return 0;
     2972                  }
     2973                  update_post_meta($post_ID, '_wp_page_template',  $page_template);
     2974    }
    29732975        }
    29742976
    29752977        wp_transition_post_status($data['post_status'], $previous_status, $post);