Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#21755 closed defect (bug) (fixed)

wp_insert_post() cannot set a page template from the frontend

Reported by: nacin Owned by: nacin
Priority: normal Milestone: 3.5
Component: Themes Version:
Severity: normal Keywords: has-patch needs-testing
Cc: Focuses:

Description

wp_insert_post(), when setting a page template with 'page_template', has a dependency on the get_page_templates() function.

Since WP_Theme is now available in wp-includes, we can use wp_get_theme()->get_page_templates(). Note that the keys and values are flipped, so we need to change from an in_array() to an isset().

Attachments (1)

21755.diff​ (704 bytes ) - added by nacin 14 years ago.

Download all attachments as: .zip

Change History (4)

#1 @nacin
14 years ago

P2 was able to trigger this, it seems:

Call to undefined function get_page_templates()
File: wp-includes/post.php
Line: 2779
Source: wp-admin/admin-ajax.php?p2ajax=true

Not sure how this happened, though, because admin-ajax.php does include includes/admin.php, which includes includes/theme.php.

#2 @nacin
14 years ago

  • Keywords has-patch needs-testing added

#3 @nacin
14 years ago

  • Owner set to nacin
  • Resolution → fixed
  • Status new → closed

In [21847]:

Use wp_get_theme()->get_page_templates() rather than get_page_templates() in wp_insert_post(),
to allow page template setting on the frontend without a fatal error. fixes #21755.

Note: See TracTickets for help on using tickets.