1. Getting Started withWordPress JSON REST APITakuro Hishikawaconcrete5 Japan Inc.!An author of Really Simple CSV Importer plugin(20,000+ download! Thanks!) 2. What Is the JSON RESTAPI?• Started as GSOC project• Now provided as plugin• Planned merge into core at future release 3. “Access your WordPress site’s data throughan easy-to-use HTTP REST API.”–http://wp-api.org/ 4. “JSON is a data format based onJavascript’s representation of objects, butit’s widely used because it can be easilyrepresented in almost every programminglanguage.”–Ryan McCuehttp://wptavern.com/ryan-mccue-on-creating-the-json-rest-api-for-wordpress 5. Resources• Posts (Create/Retrieve/Edit/Delete)• Meta (Create/Retrieve/Edit/Delete)• Media (Create/Get)• Users (Create/Retrieve/Edit/Delete)• Taxonomy/Terms (Retrieve) 6. Building App Example• Framework = concrete5• Library = Zend_Oauth, Zend_Http_Client 7. Demo• Get posts from WordPress• Get the specific post from WordPress• Insert a new post to WordPress 8. Step by step 9. Set up the plugin• https://github.com/WP-API/WP-API/• https://github.com/WP-API/OAuth1/ 10. Get Access Token fromWordPress• Blog post (Japanese)• http://notnil-creative.com/blog/archives/3301 11. Send HTTP Request toWordPress$client = Loader::helper('wp_api','rest_wordpress')->getClient();$client->setUri($wp_rest_api_url.’/posts');$client->setMethod(Zend_Http_Client::GET);$client->setParameterGet('filter[posts_per_page]',$num);$client->setParameterGet(‘filter[cat]',$cat);$client->setParameterGet('filter[orderby]','title');$client->setParameterGet(‘filter[order]','ASC');$response = $client->request(); 12. Send HTTP Request toWordPress$client = Loader::helper('wp_api','rest_wordpress')->getClient();$client->setUri($wp_rest_api_url.'/posts');$client->setMethod(Zend_Http_Client::POST);$data = array('title' => $this->post('post_title'),'content_raw' => $this->post('post_body'),'status' => 'publish');$client->setRawData(Loader::helper('json')->encode($data),'application/json');$res = $client->request(); 13. Easy, right? 14. • As you can see, working with JSON REST API requireslittle knowledge of OAuth and building HTTPRequest…• Use library!JSON is a popular object type, OAuth is also popular• Some issues…https://github.com/WP-API/OAuth1/issues/37https://github.com/WP-API/OAuth1/issues/34 15. Thanks!Follow me!!Twitter: @HissyNCGitHub: @hissy

Getting Started with WordPress JSON REST API

  • Published on
    19-Jun-2015

  • View
    861

  • Download
    0

DESCRIPTION

1. Getting Started withWordPress JSON REST APITakuro Hishikawaconcrete5 Japan Inc.!An author of Really Simple CSV Importer plugin(20,000+ download! Thanks!) 2. What Is the…