Skip to content

Commit 3bd59c7

Browse files
committed
Expose page template functionality via XML-RPC. Props josephscott. fixes WordPress#6098
git-svn-id: https://develop.svn.wordpress.org/trunk@7901 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2af2724 commit 3bd59c7

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

xmlrpc.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function wp_xmlrpc_server() {
8484
'wp.getCommentCount' => 'this:wp_getCommentCount',
8585
'wp.getPostStatusList' => 'this:wp_getPostStatusList',
8686
'wp.getPageStatusList' => 'this:wp_getPageStatusList',
87+
'wp.getPageTemplates' => 'this:wp_getPageTemplates',
8788

8889
// Blogger API
8990
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
@@ -267,6 +268,10 @@ function wp_getPage($args) {
267268
// Get the author info.
268269
$author = get_userdata($page->post_author);
269270

271+
$page_template = get_post_meta( $page->ID, '_wp_page_template', true );
272+
if( empty( $page_template ) )
273+
$page_template = 'default';
274+
270275
$page_struct = array(
271276
"dateCreated" => new IXR_Date($page_date),
272277
"userid" => $page->post_author,
@@ -290,7 +295,8 @@ function wp_getPage($args) {
290295
"wp_author_id" => $author->ID,
291296
"wp_author_display_name" => $author->display_name,
292297
"date_created_gmt" => new IXR_Date($page_date_gmt),
293-
"custom_fields" => $this->get_custom_fields($page_id)
298+
"custom_fields" => $this->get_custom_fields($page_id),
299+
"wp_page_template" => $page_template
294300
);
295301

296302
return($page_struct);
@@ -739,6 +745,28 @@ function wp_getPageStatusList( $args ) {
739745
return get_page_statuses( );
740746
}
741747

748+
function wp_getPageTemplates( $args ) {
749+
$this->escape( $args );
750+
751+
$blog_id = (int) $args[0];
752+
$username = $args[1];
753+
$password = $args[2];
754+
755+
if( !$this->login_pass_ok( $username, $password ) ) {
756+
return new IXR_Error( 403, __( 'Bad login/pass combination.' ) );
757+
}
758+
759+
set_current_user( 0, $username );
760+
if( !current_user_can( 'edit_pages' ) ) {
761+
return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
762+
}
763+
764+
$templates = get_page_templates( );
765+
$templates['Default'] = 'default';
766+
767+
return $templates;
768+
}
769+
742770

743771
/* Blogger API functions
744772
* specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/
@@ -1130,11 +1158,14 @@ function mw_newPost($args) {
11301158
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts';
11311159
$error_message = __( 'Sorry, you are not allowed to publish posts on this blog.' );
11321160
$post_type = 'post';
1161+
$page_template = '';
11331162
if( !empty( $content_struct['post_type'] ) ) {
11341163
if( $content_struct['post_type'] == 'page' ) {
11351164
$cap = ( $publish ) ? 'publish_pages' : 'edit_pages';
11361165
$error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' );
11371166
$post_type = 'page';
1167+
if( !empty( $content_struct['wp_page_template'] ) )
1168+
$page_template = $content_struct['wp_page_template'];
11381169
}
11391170
elseif( $content_struct['post_type'] == 'post' ) {
11401171
// This is the default, no changes needed
@@ -1323,9 +1354,9 @@ function mw_newPost($args) {
13231354
}
13241355

13251356
// We've got all the data -- post it:
1326-
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input');
1357+
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template');
13271358

1328-
$post_ID = wp_insert_post($postdata);
1359+
$post_ID = wp_insert_post($postdata, true);
13291360
if ( is_wp_error( $post_ID ) )
13301361
return new IXR_Error(500, $post_ID->get_error_message());
13311362

@@ -1385,11 +1416,14 @@ function mw_editPost($args) {
13851416
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts';
13861417
$error_message = __( 'Sorry, you are not allowed to publish posts on this blog.' );
13871418
$post_type = 'post';
1419+
$page_template = '';
13881420
if( !empty( $content_struct['post_type'] ) ) {
13891421
if( $content_struct['post_type'] == 'page' ) {
13901422
$cap = ( $publish ) ? 'publish_pages' : 'edit_pages';
13911423
$error_message = __( 'Sorry, you are not allowed to publish pages on this blog.' );
13921424
$post_type = 'page';
1425+
if( !empty( $content_struct['wp_page_template'] ) )
1426+
$page_template = $content_struct['wp_page_template'];
13931427
}
13941428
elseif( $content_struct['post_type'] == 'post' ) {
13951429
// This is the default, no changes needed
@@ -1588,9 +1622,12 @@ function mw_editPost($args) {
15881622
}
15891623

15901624
// We've got all the data -- post it:
1591-
$newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input');
1625+
$newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
1626+
1627+
$result = wp_update_post($newpost, true);
1628+
if ( is_wp_error( $result ) )
1629+
return new IXR_Error(500, $result->get_error_message());
15921630

1593-
$result = wp_update_post($newpost);
15941631
if (!$result) {
15951632
return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
15961633
}

0 commit comments

Comments
 (0)