Make WordPress Core


Ignore:
Timestamp:
11/19/2010 01:57:05 PM (16 years ago)
Author:
josephscott
Message:

Expose post format details in XML-RPC:

  • New method: wp.getPostFormats
  • New field in methods dealing with posts: wp_post_format

props ericmann, fixes #15405

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r16438 r16484  
    6464                        'wp.getMediaItem'               => 'this:wp_getMediaItem',
    6565                        'wp.getMediaLibrary'    => 'this:wp_getMediaLibrary',
     66                        'wp.getPostFormats'     => 'this:wp_getPostFormats',
    6667
    6768                        // Blogger API
    … …  
    16021603                return $attachments_struct;
    16031604        }
     1605       
     1606        /**
     1607          * Retrives a list of post formats used by the site
     1608          *
     1609          * @since 3.1
     1610          *
     1611          * @param array $args Method parameters. Contains:
     1612          *  - blog_id
     1613          *  - username
     1614          *  - password
     1615          * @return array
     1616          */
     1617        function wp_getPostFormats( $args ) {
     1618                $this->escape( $args );
     1619
     1620                $blog_id = (int) $args[0];
     1621                $username = $args[1];
     1622                $password = $args[2];
     1623
     1624                if ( !$user = $this->login( $username, $password ) )
     1625                        return $this->error;
     1626           
     1627                do_action( 'xmlrpc_call', 'wp.getPostFormats' );
     1628                return get_post_format_strings();
     1629        }
    16041630
    16051631        /* Blogger API functions.
    … …  
    20832109                if ( !current_user_can( $cap ) )
    20842110                        return new IXR_Error( 401, $error_message );
     2111
     2112                // Check for a valid post format if one was given
     2113                if ( isset( $content_struct['wp_post_format'] ) ) {
     2114                        $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
     2115                        if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
     2116                                return new IXR_Error( 404, __( 'Invalid post format' ) );
     2117                        }
     2118                }
    20852119
    20862120                // Let WordPress generate the post_name (slug) unless
    … …  
    22672301
    22682302                $this->attach_uploads( $post_ID, $post_content );
     2303               
     2304                // Handle post formats if assigned, value is validated earlier
     2305                // in this function
     2306                if ( isset( $content_struct['wp_post_format'] ) )
     2307                        wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format' );
    22692308
    22702309                logIO('O', "Posted ! ID: $post_ID");
    … …  
    23582397                if ( !current_user_can( $cap ) )
    23592398                        return new IXR_Error( 401, $error_message );
     2399
     2400                // Check for a valid post format if one was given
     2401                if ( isset( $content_struct['wp_post_format'] ) ) {
     2402                        $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
     2403                        if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
     2404                                return new IXR_Error( 404, __( 'Invalid post format' ) );
     2405                        }
     2406                }
    23602407
    23612408                $postdata = wp_get_single_post($post_ID, ARRAY_A);
    … …  
    25532600
    25542601                $this->attach_uploads( $ID, $post_content );
     2602               
     2603                // Handle post formats if assigned, validation is handled
     2604                // earlier in this function
     2605                if ( isset( $content_struct['wp_post_format'] ) )
     2606                        wp_set_post_terms( $post_ID, array( 'post-format-' . $content_struct['wp_post_format'] ), 'post_format' );
    25552607
    25562608                logIO('O',"(MW) Edited ! ID: $post_ID");
    … …  
    26202672                        if ( $postdata['post_status'] === 'future' )
    26212673                                $postdata['post_status'] = 'publish';
     2674                               
     2675                        // Get post format
     2676                        $post_format = get_post_format( $post_ID );
     2677                        if ( empty( $post_format ) )
     2678                                $post_format = 'default';
    26222679
    26232680                        $sticky = false;
    … …  
    26612718                                'post_status' => $postdata['post_status'],
    26622719                                'custom_fields' => $this->get_custom_fields($post_ID),
     2720                                'wp_post_format' => $post_format,
    26632721                                'sticky' => $sticky
    26642722                        );
    … …  
    27412799                        if ( $entry['post_status'] === 'future' )
    27422800                                $entry['post_status'] = 'publish';
     2801                               
     2802                        // Get post format
     2803                        $post_format = get_post_format( $entry['ID'] );
     2804                        if ( empty( $post_format ) )
     2805                                $post_format = 'default';
    27432806
    27442807                        $struct[] = array(
    … …  
    27642827                                'date_created_gmt' => new IXR_Date($post_date_gmt),
    27652828                                'post_status' => $entry['post_status'],
    2766                                 'custom_fields' => $this->get_custom_fields($entry['ID'])
     2829                                'custom_fields' => $this->get_custom_fields($entry['ID']),
     2830                                'wp_post_format' => $post_format
    27672831                        );
    27682832
Note: See TracChangeset for help on using the changeset viewer.