Dave Rolsky > WP-API-0.01 > WP::API::Media



Annotate this POD



Open  1
View/Report Bugs
Module Version: 0.01   Source  


WP::API::Media - An interface for WordPress media objects


version 0.01


  use File::Slurp qw( read_file );

  my $content = read_file('path/to/file.jpg');

  my $media = $api->media()->create(
      name      => 'foo.jpg',
      type      => 'image/jpeg',
      bits      => $content,
      overwrite => 1,

  print $media->date_created_gmt()->date();

  my $other_media = $api->media()->new( attachment_id => 99 );
  print $other_media->title();


This class provides methods for creating new media objects and fetching data about existing media objects.

See the WordPress API documentation at http://codex.wordpress.org/XML-RPC_WordPress_API for more details on what all of the fields mean.


This class provides the following methods:

$api->media()->new( attachment_id => $value )

This method constructs a new media object based on data from the WordPress server. The only accepted parameter is a attachment_id, which is required.


This method creates a new media object on the WordPress server. It accepts a hash with the following keys as of WordPress 3.5:

Note that if future versions of WordPress accept more parameter, this API allows you to pass them. Any key/value pairs you pass will be sent to WordPress as-is.


Returns the media object's creation date and time as a DateTime object in the UTC time zone.


Returns the post_id of the media object's parent or 0 if it doesn't have one.


Returns the full URI of the media object as a URI object.


Returns the media object's title.


Returns the media object's caption if it has one, undef otherwise.


Returns the media object's description if it has one, undef otherwise.


Returns a rather complicated hash reference. See the WordPress API documentation for details.

Note that this might become a set of real objects in the future.


Returns the thumbnail URI of the media object as a URI object.


Dave Rolsky <autarch@urth.org>


This software is Copyright (c) 2013 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: