[wp-hackers] Re: Setting post enclosures via XML-RPC

Steve Winton stevewinton at gmail.com
Tue Nov 28 17:37:08 GMT 2006


On 11/28/06, Steve Winton <stevewinton at gmail.com> wrote:
> WP Gurus...
>
> Further to my previous post on metaWeblog.newMediaObject...
>
> I am trying to publish a podcast remotely via XML-RPC. It's all going
> well up to a point - I can upload the MP3 remotely, and publish a post
> containing a link to this MP3 in the 'Podcast' category. However, I've
> come across 1 issue. When the post is published via
> metaWeblog.newPost, the enclosures are not set, which is pretty
> crucial for a podcast.
>
> I'm happy to create my own XML-RPC function on the server to create
> the enclosures for a post (as far as I can see this is just a case of
> adding an 'enclosure' meta field to the post), but can anyone here
> give me some pointers of which WP functions I should hook in to, to
> achieve this? Or, has anyone got some other workaround for this?
>
> Many thanks,
> Steve
>

OK, add_post_meta is the answer, and I've hacked the following
together in xmlrpc.php, in mw_newPost()...

    $meta = $content_struct['meta'];
    if (is_array($meta)) {
      foreach($meta as $key=>$val){
        add_post_meta($post_ID, $key, $val, false);
      }
    }

This is doing the trick for me. I suppose the mw_editPost function
should be edited also for completeness, to allow the post meta to be
updated.

This approach also seems to be acceptable, according to the metaWeblog
API (http://www.xmlrpc.com/metaWeblogApi), i.e.

Where an element has attributes, for example, enclosure, pass a struct
with sub-elements whose names match the names of the attributes
according to the RSS 2.0 spec, url, length and type.

Any chances of getting this change into trunk?

Many thanks,
Steve


More information about the wp-hackers mailing list