wordpress apis

35
WordPress APIs Joseph Scott http://josephscott.org/

Upload: joseph-scott

Post on 18-Feb-2017

5.989 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: WordPress APIs

WordPress APIs

Joseph Scotthttp://josephscott.org/

Page 2: WordPress APIs

APIs - The Big Two

XML-RPC&

AtomPub

Page 3: WordPress APIs

XML-RPC Basics• XML over HTTP POST

• Basic data types (int, bool, string, double, dateTime.iso8601, base64) combined with structs and arrays

• Supports pipelining with system.multicall

• Authentication generally in request body

• Spec - xmlrpc.com/spec

Page 4: WordPress APIs

XML-RPC Request<?xml version="1.0"?> <methodCall>

<methodName>metaWeblog.getPost</methodName> <params>

<param> <value><int>1</int></value> </param>

<param> <value><string>admin</string></value> </param>

<param> <value><string>happiness</string></value> </param> </params> </methodCall>

Page 5: WordPress APIs

XML-RPC Response<?xml version="1.0"?> <methodResponse> <params> <param> <value> <struct> <member><name>postid</name><value><string>1</string></value></member> <member><name>description</name><value><string>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</string></value></member> <member><name>title</name><value><string>Hello world!</string><value></member> ... </struct> </value> </param> </params> </methodResponse>

Page 6: WordPress APIs

AtomPub Basics• XML over HTTP (GET, POST, PUT, DELETE)

• Shared base with Atom feeds

• Collections (Posts, Comments, Media), Entries (Individual posts and comments)

• Great intro from Joe Gregorio - http://bitworking.org/news/343/intro-to-atompub-on-youtube

• http://tools.ietf.org/html/rfc5023

Page 7: WordPress APIs

AtomPub Request

curl -u “admin:happiness” \http://localhost/~joseph/wp/trunk/wp-app.php/post/1

Page 8: WordPress APIs

AtomPub Response<?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xml:lang="en"> <id>http://localhost/~joseph/wp/trunk/?p=1</id> <title type="text">Hello world!</title> <updated>2008-08-08T01:01:03Z</updated> <published>2008-08-08T01:01:03Z</published> <app:edited>2008-08-08T01:01:03Z</app:edited> <app:control> <app:draft>no</app:draft> </app:control> <author><name>admin</name></author> <link href="http://localhost/~joseph/wp/trunk/?p=1" /> <content type="text">Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</content> <link rel="edit" href="http://localhost/~joseph/wp/trunk/wp-app.php/post/1" /> <category scheme="http://localhost/~joseph/wp/trunk" term="Uncategorized" /> <summary type="text">Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</summary> </entry>

Page 9: WordPress APIs

Discovery• Really Simple Discovery (RSD)

• http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html

<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/wp/xmlrpc.php?rsd" />

Page 10: WordPress APIs

RSD<?xml version="1.0" encoding="UTF-8"?><rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> <service> <engineName>WordPress</engineName> <engineLink>http://wordpress.org/</engineLink> <homePageLink>http://localhost/wp</homePageLink> <apis> <api name="WordPress" blogID="1" preferred="true" apiLink="http://localhost/wpxmlrpc.php" /> <api name="Movable Type" blogID="1" preferred="false" apiLink="http://localhost/wp/xmlrpc.php" /> <api name="MetaWeblog" blogID="1" preferred="false" apiLink="http://localhost/wp/xmlrpc.php" /> <api name="Blogger" blogID="1" preferred="false" apiLink="http://localhost/wp/xmlrpc.php" /> <api name="Atom" blogID="" preferred="false" apiLink="http://localhost/~joseph/wp/wp-app.php/service" /> </apis> </service></rsd>

Page 11: WordPress APIs

4,619

3,079,080

Page 12: WordPress APIs

2008 Totals

4,619

3,079,080

AtomPub

XML-RPC

Page 13: WordPress APIs

2009 Year To Date

3,312

703,673

AtomPub

XML-RPC

Page 14: WordPress APIs

XML-RPC Blog APIs

MetaWeblog(metaWeblog.*)

Movable Type(mt.*)

Blogger(blogger.*)

WordPress(wp.*)

Page 15: WordPress APIs

Extending MetaWeblog

• Many new fields to getPost/newPost/editPost

• wp_slug, wp_password, wp_author_id, wp_author_display_name, date_created_gmt, post_status, custom_fields, mt_keywords (tags)

• dateCreated vs. date_created_gmt

Page 16: WordPress APIs

WordPress Methods• Comment Management, new in 2.7

(wp.getComment, wp.newComment, wp.editComment, wp.deleteComment)

• Page management (wp.getPage, wp.editPage, wp.newPage, etc.)

• Category Management (wp.newCategory, wp.deleteCategory, etc.)

• Tag Management (wp.getTags - more to come)

Page 17: WordPress APIs

ApplicationsWindows Live Writer

MarsEdit

Page 18: WordPress APIs

More Applications

• Scribefire (Firefox Plugin)

• Windows- MS Word 2007, Blogdesk, Blogjet, Raven, Flock, Qumana

• Mac - Ecto, Blogo, MacJournal, TextMate

• Linux - QTM, Gnome Blog, Drivel, BloGTK

http://codex.wordpress.org/Weblog_Client

Page 19: WordPress APIs

iPhone App

• http://iphone.wordpress.org/

• Free & Open Source (GPL)

• ~ 165,000 downloads

• Uses XML-RPC to manage your blog

Page 20: WordPress APIs

iPhone App - 1.2

• Comment Moderation

• Landscape mode

• Link creation help

• Create/edit Pages

http://iphone.wordpress.org/2008/11/11/help-test-wordpress-for-iphone-version-12/

Page 21: WordPress APIs

iPhone App

Posts in the last 6 months

231,079

Page 22: WordPress APIs

Developer Tools - MacHTTPScoop http://www.tuffcode.com/

XML-RPC Clienthttp://ditchnet.org/xmlrpc/

Page 23: WordPress APIs

Developer Tools - WindowsFiddlerhttp://www.fiddlertool.com/fiddler/

Page 24: WordPress APIs

XML-RPC for WP Devs• Add your own XML-RPC methods

add_filter( 'xmlrpc_methods', 'joseph_attach_xmlrpc_methods' ); function joseph_attach_xmlrpc_methods( $methods ) { $methods['joseph.hello'] = 'joseph_xmlrpc_hello'; return $methods; }

Page 25: WordPress APIs

XML-RPC for WP Devs• Add your own XML-RPC methods

function joseph_xmlrpc_hello( $args ) { if ( empty( $args[0] ) ) return new IXR_Error( 2000, __( 'No name was provided.' ) );

$salutation = "Hello {$args[0]}, nice to see you!";

return $salutation;}

Page 26: WordPress APIs

XML-RPC for WP Devs• XML-RPC Client

$rpc = new IXR_Client( 'http://example.com/xmlrpc.php' );

$status = $rpc->query( ‘demo.addTwoNumbers’, 4, 5 );if ( !$status ) { print ‘Error ( ‘ . $rpc->getErrorCode( ) . ‘ ): ‘; print $rpc->getErrorMessage( ) . “\n”; exit;}

$result = $rpc->getResponse( );

Page 27: WordPress APIs

bbPress XML-RPC

• Part of version 1.0 (when it comes out)

• Pingback support

• bbPress Live - WordPress Plugin

• BuddyPress forums

Page 28: WordPress APIs

Going Forward

• More data/features exposed via XML-RPC & AtomPub

• Everything wp-admin can do?

• Likely a WordPress namespace for new AtomPub features

Page 29: WordPress APIs

UsernamePassword

Page 30: WordPress APIs

OAuth

UsernamePassword

Page 31: WordPress APIs

Applications On Topof WordPress

Page 32: WordPress APIs

InterPress

Page 33: WordPress APIs

XML-RPC Developers

http://lists.automattic.com/mailman/listinfo/wp-xmlrpc

Page 34: WordPress APIs

Thank You

Page 35: WordPress APIs

Find Me

• http://josephscott.org/

[email protected]

• http://twitter.com/josephscott/

• #wordpress-dev