Take me over?
NAME
WP::API::Media - An interface for WordPress media objects
VERSION
version 0.01
SYNOPSIS
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();
DESCRIPTION
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.
METHODS
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.
$api->media()->create(...)
This method creates a new media object on the WordPress server. It accepts a hash with the following keys as of WordPress 3.5:
name
The object's file name.
type
The object's MIME type.
bits
The raw media object content.
overwrite
A boolean indicating whether or not to overwrite an existing file with the same name.
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.
$media->date_created_gmt()
Returns the media object's creation date and time as a DateTime object in the UTC time zone.
$media->parent()
Returns the post_id of the media object's parent or 0 if it doesn't have one.
$media->link()
Returns the full URI of the media object as a URI object.
$media->title()
Returns the media object's title.
$media->caption()
Returns the media object's caption if it has one, undef
otherwise.
$media->description()
Returns the media object's description if it has one, undef
otherwise.
$media->metadata()
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.
$media->thumbnail()
Returns the thumbnail URI of the media object as a URI object.
AUTHOR
Dave Rolsky <autarch@urth.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)