Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21755 closed defect (bug) (fixed)

wp_insert_post() cannot set a page template from the frontend

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

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 12 years ago.

Download all attachments as: .zip

Change History (4)

#1 @nacin
12 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.

@nacin
12 years ago

#2 @nacin
12 years ago

  • Keywords has-patch needs-testing added

#3 @nacin
12 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to 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.