Make WordPress Core

Changeset 7901 for trunk/xmlrpc.php


Ignore:
Timestamp:
05/06/2008 04:49:42 PM (18 years ago)
Author:
ryan
Message:

Expose page template functionality via XML-RPC. Props josephscott. fixes #6098

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r7847 r7901  
    8585                        'wp.getPostStatusList'  => 'this:wp_getPostStatusList',
    8686                        'wp.getPageStatusList'  => 'this:wp_getPageStatusList',
     87                        'wp.getPageTemplates'   => 'this:wp_getPageTemplates',
    8788
    8889                        // Blogger API
     
    267268                        // Get the author info.
    268269                        $author = get_userdata($page->post_author);
     270
     271                        $page_template = get_post_meta( $page->ID, '_wp_page_template', true );
     272                        if( empty( $page_template ) )
     273                                $page_template = 'default';
    269274
    270275                        $page_struct = array(
     
    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
     
    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
     
    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' ) {
     
    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' ) {
     
    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');
    1327 
    1328                 $post_ID = wp_insert_post($postdata);
     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');
     1358
     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());
     
    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' ) {
     
    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' ) {
     
    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');
    1592 
    1593                 $result = wp_update_post($newpost);
     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());
     1630
    15941631                if (!$result) {
    15951632                        return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
Note: See TracChangeset for help on using the changeset viewer.