SlideShare a Scribd company logo
Creating native apps
  with WordPress
             Marko Heijnen
 January 14, 2012 at WordCamp Norway
Marko Heijnen
Freelance developer
Mobile / WordPress


http://markoheijnen.com
info@markoheijnen.com
@markoheijnen
History
2006: Started with WordPress
2009: Started with iOS development
2010: First patch to WordPress ( 3.0 )
2011: Combined iOS development with WordPress
2012: First WordCamp presentation
Lets talk mobile
Mobile is the growing
There is a change you
 get involved with it
Native app vs
Web app/site
Native vs mobile
Build a native app when:
   People are going to use it quite often ( daily basis )
   Features that aren’t possible for web ( yet )
   A lot of users request for it ( 10.000 > )
   Customers really want an app
We need
a native app
What does it mean for you
You need to communicate with another developer
Need to build an API that the developer can use
So you need to understand what a mobile developer wants
Need to build additional fields in WordPress for information
that the mobile app can use
The API
Creating native apps with WordPress
API of the app
WordPress for iOS uses XML-RPC
WordPress support it by default
Supports: Blogger API, metaWeblog API, and the Movable
Type API
Where can you find it
/xmlrpc.php
   handles the request
/wp-includes/class-wp-xmlrpc.server.php
   Registers all the default methods
Methods for testing
/**                                                  /**
  * Test XMLRPC API by saying, "Hello!" to client.     * Test XMLRPC API by adding two numbers for client.
  *                                                    *
  * @since 1.5.0                                       * @since 1.5.0
  *                                                    *
  * @param array $args Method Parameters.              * @param array $args Method Parameters.
  * @return string                                     * @return int
  */                                                   */
function sayHello($args) {                           function addTwoNumbers($args) {
	       return 'Hello!';                             	       $number1 = $args[0];
}                                                    	       $number2 = $args[1];
                                                     	       return $number1 + $number2;
                                                     }
How to get recent post
function mw_getRecentPosts($args) {

	      $this->escape($args);

	      $blog_ID = (int) $args[0];
	      $username = $args[1];
	      $password = $args[2];
	      if ( isset( $args[3] ) )
	      	        $query = array( 'numberposts' => absint( $args[3] ) );
	      else
	      	        $query = array();

	      if ( !$user = $this->login($username, $password) )
	      	       return $this->error;

	      do_action('xmlrpc_call', 'metaWeblog.getRecentPosts');
How you can use it in your own way
Create your own methods
add_filter( 'xmlrpc_methods', 'add_own_methods' );

function add_own_methods( $methods ) {
           $methods['own.my_method'] = 'own_my_method';

         return $methods
}

function own_my_method( $args ) {
          return $some_data
}
How does it look like
Request
<?xml version="1.0"?>
<methodCall>
<methodName>metaWeblog.getRecentPosts</methodName>
<params>
<param><value><string></string></value></param>
<param><value><string>username</string></value></param>
<param><value><string>password</string></value></param>
</params></methodCall>
Response
<?xml version="1.0"?>
<methodResponse>
  <params>
   <param>
     <value>
     <array><data>
  <value><struct>
  <member><name>dateCreated</name><value><dateTime.iso8601>20110904T18:15:26</dateTime.iso8601></value></member>
  <member><name>userid</name><value><string>1</string></value></member>
  <member><name>postid</name><value><string>1</string></value></member>
  <member><name>description</name><value><string>Welcome to &lt;a href=&quot;http://network.nginx.markoheijnen.com/&quot;&gt;WordPress Network Sites&lt;/a&gt;. 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>
  <member><name>link</name><value><string>http://test.network.nginx.markoheijnen.com/2011/09/04/hello-world/</string></value></member>
  <member><name>permaLink</name><value><string>http://test.network.nginx.markoheijnen.com/2011/09/04/hello-world/</string></value></member>
  <member><name>categories</name><value><array><data>
  <value><string>Uncategorized</string></value>
</data></array></value></member>
  <member><name>mt_excerpt</name><value><string></string></value></member>
  <member><name>mt_text_more</name><value><string></string></value></member>
  <member><name>mt_allow_comments</name><value><int>1</int></value></member>
  <member><name>mt_allow_pings</name><value><int>1</int></value></member>
  <member><name>mt_keywords</name><value><string></string></value></member>
  <member><name>wp_slug</name><value><string>hello-world</string></value></member>
  <member><name>wp_password</name><value><string></string></value></member>
  <member><name>wp_author_id</name><value><string>1</string></value></member>
  <member><name>wp_author_display_name</name><value><string>marko</string></value></member>
  <member><name>date_created_gmt</name><value><dateTime.iso8601>20110904T18:15:26</dateTime.iso8601></value></member>
  <member><name>post_status</name><value><string>publish</string></value></member>
  <member><name>custom_fields</name><value><array><data>
</data></array></value></member>
  <member><name>wp_post_format</name><value><string>standard</string></value></member>
</struct></value>
</data></array>
     </value>
   </param>
  </params>
</methodResponse>
XML-RPC
Critics of XML-RPC argue that RPC calls can be made with
plain XML
XML-RPC uses about 4 times the number of bytes compared
to plain XML
Need a lot of code on the app side
In the end the size of requests/responses do mather
Is this the best way or
are there alternatives?
Alternatives
Just XML instead of XML-RPC
Use JSON
What is JSON
JavaScript Object Notation
Use JSON as alternative to XML
It is derived from the JavaScript scripting language
Lightweight text-based open standard
Why JSON
Lighter and faster than XML
JSON objects are typed
   Array, object, string, number, boolean and null
Great libraries for mobile platforms
   iOS 5 does have native support for JSON
Easy to parse on mobile platforms
JSON Example
{
        "firstName"    :   "Marko",
        "lastName"     :   "Heijnen",
        "age"          :   25,
        "address"      :   null,
        "newsletter" :     false,
        "phoneNumber" :
        [
            {
               "type" :    "home",
               "number":   "212 555-1234"
            },
            {
               "type" :    "fax",
               "number":   "646 555-4567"
            }
        ]
    }
WordPress doesn’t have
 native support (yet)
Plugins you can use
JSON RPC - http://wordpress.org/extend/plugins/wp-json-
rpc-api/
JSON API - http://wordpress.org/extend/plugins/json-api/
WP RESTful - http://wordpress.org/extend/plugins/wp-
restful/


Be aware that these plugins aren’t up to date
What do I use
JSON API
Great to use because of the use of hooks
Good information on the plugin page
Simple backend interface


I use a modified version of it
   Added consumer key/secret
Interface
How to implement
function add_hello_controller( $controllers ) {
           $controllers[] = 'hello';
           return $controllers;
}
add_filter( 'json_api_controllers', 'add_hello_controller' );

function set_hello_controller_path() {
           return "/path/to/theme/hello.php";
}
add_filter( 'json_api_hello_controller_path', 'set_hello_controller_path' );
How to implement
<?php
class JSON_API_Hello_Controller {
          public function hello_world() {
                return array( "message" => "Hello, world" );
          }
}
?>
Important to know
Only return data that is needed
Return as less HTML as possible
Don’t change the feed without notifying the app developer
A call shouldn’t take to long, speed is everything
Cache the data if possible
   Transients: http://codex.wordpress.org/Transients_API
Recap
How to manage
mobile content
Post types
Add separate meta box for mobile content
   Even the ability to overrule the title
Additional user capability, so not everyone can manage it
Maybe even create a special post type for mobile content
Special admin page
Only for mobile configuration
Store settings
Store default pages for mobile like privacy disclaimer
Push notifications
Create ability to send push notifications in a smart way
   Add to posttype
   Make a separate box on dashboard or admin page
You can handle the sending yourself
Or use for example the services of Urban Airship
Last word
WordPress is a CMS
Can be used in a lot of ways
Sometimes look further then the plugin section
Questions
@markoheijnen / info@markoheijnen.com

More Related Content

PPTX
Arrays &amp; functions in php
Ashish Chamoli
 
PPT
php 2 Function creating, calling, PHP built-in function
tumetr1
 
PDF
Object Oriented PHP - PART-2
Jalpesh Vasa
 
PDF
4.2 PHP Function
Jalpesh Vasa
 
ODP
PHP Basic
Yoeung Vibol
 
PDF
Functions in PHP
Vineet Kumar Saini
 
ODP
PHP Web Programming
Muthuselvam RS
 
PPTX
Licão 13 functions
Acácio Oliveira
 
Arrays &amp; functions in php
Ashish Chamoli
 
php 2 Function creating, calling, PHP built-in function
tumetr1
 
Object Oriented PHP - PART-2
Jalpesh Vasa
 
4.2 PHP Function
Jalpesh Vasa
 
PHP Basic
Yoeung Vibol
 
Functions in PHP
Vineet Kumar Saini
 
PHP Web Programming
Muthuselvam RS
 
Licão 13 functions
Acácio Oliveira
 

What's hot (20)

PPT
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
PPTX
Php string function
Ravi Bhadauria
 
PPTX
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
PDF
Merb
Yehuda Katz
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPTX
Php pattern matching
JIGAR MAKHIJA
 
PPT
Class 2 - Introduction to PHP
Ahmed Swilam
 
PPT
Php i basic chapter 3
Muhamad Al Imran
 
PPT
LPW: Beginners Perl
Dave Cross
 
PDF
PHP 8.1 - What's new and changed
Ayesh Karunaratne
 
PDF
DataMapper
Yehuda Katz
 
ODP
Advanced Perl Techniques
Dave Cross
 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
PPTX
Bioinformatics p1-perl-introduction v2013
Prof. Wim Van Criekinge
 
PPT
Basic PHP
Todd Barber
 
KEY
Introduction to Perl Best Practices
José Castro
 
PDF
PHP Unit 3 functions_in_php_2
Kumar
 
PPT
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
Php string function
Ravi Bhadauria
 
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Class 3 - PHP Functions
Ahmed Swilam
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Php pattern matching
JIGAR MAKHIJA
 
Class 2 - Introduction to PHP
Ahmed Swilam
 
Php i basic chapter 3
Muhamad Al Imran
 
LPW: Beginners Perl
Dave Cross
 
PHP 8.1 - What's new and changed
Ayesh Karunaratne
 
DataMapper
Yehuda Katz
 
Advanced Perl Techniques
Dave Cross
 
PHP FUNCTIONS
Zeeshan Ahmed
 
Introduction to PHP
Jussi Pohjolainen
 
Bioinformatics p1-perl-introduction v2013
Prof. Wim Van Criekinge
 
Basic PHP
Todd Barber
 
Introduction to Perl Best Practices
José Castro
 
PHP Unit 3 functions_in_php_2
Kumar
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Ad

Viewers also liked (20)

PPT
Direccion y liderazgo
Hector Fabián Perez Flores
 
PDF
Nota Makro
gusta100
 
PDF
Kundenrückgewinnung "lost&found"
Menschen im Vertrieb Beratungsgesellschaft
 
PPT
++Lo que recuerdo de la prehistoria gloria
Marisolfbc Morales
 
PDF
bt Gear de Bio Therapeutic
Pure Skincare Cosmecéutica S.L.
 
PDF
Informe de resultados innovacción 2012
ArsetInventio
 
PDF
Elcometer 3570-casting-knife-film-applicators
MM Naina Exports
 
PPTX
Merry web
mariacastilloveraok
 
PPT
Social Media Plan Sinerrata
Judparis
 
PDF
Star Advertiser Interview 160114
Herman Tam
 
DOCX
5596 5600.output
Иван Иванов
 
PDF
Witness tree text analysis
Cole Capital
 
PDF
Retirement Coach Flyer
dctyson
 
PDF
Competence Assessment Workshop Slides (27.10.14)
AU Career
 
DOTX
Curriculum vitac
Operator Warnet Vast Raha
 
DOC
Advisory Committee Minutes - September 2012
LSC-CyFair Academy for Lifelong Learning
 
PDF
Fujifilm - Thermoscale film
Bernard Genoud
 
PPT
Estrategias para enseñar a aprender aprender a aprender
Nestor Apaza
 
PDF
2016.10.14 fb science seed fund na
Ana José Varela
 
DOC
Comunicado definitivo
Victor Morales
 
Direccion y liderazgo
Hector Fabián Perez Flores
 
Nota Makro
gusta100
 
Kundenrückgewinnung "lost&found"
Menschen im Vertrieb Beratungsgesellschaft
 
++Lo que recuerdo de la prehistoria gloria
Marisolfbc Morales
 
bt Gear de Bio Therapeutic
Pure Skincare Cosmecéutica S.L.
 
Informe de resultados innovacción 2012
ArsetInventio
 
Elcometer 3570-casting-knife-film-applicators
MM Naina Exports
 
Social Media Plan Sinerrata
Judparis
 
Star Advertiser Interview 160114
Herman Tam
 
5596 5600.output
Иван Иванов
 
Witness tree text analysis
Cole Capital
 
Retirement Coach Flyer
dctyson
 
Competence Assessment Workshop Slides (27.10.14)
AU Career
 
Curriculum vitac
Operator Warnet Vast Raha
 
Advisory Committee Minutes - September 2012
LSC-CyFair Academy for Lifelong Learning
 
Fujifilm - Thermoscale film
Bernard Genoud
 
Estrategias para enseñar a aprender aprender a aprender
Nestor Apaza
 
2016.10.14 fb science seed fund na
Ana José Varela
 
Comunicado definitivo
Victor Morales
 
Ad

Similar to Creating native apps with WordPress (20)

PDF
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
PDF
PHP 5.3 Overview
jsmith92
 
PPT
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
KEY
Fatc
Wade Arnold
 
PDF
Giới thiệu PHP 7
ZendVN
 
PDF
PHP And Web Services: Perfect Partners
Lorna Mitchell
 
PDF
Doctrine For Beginners
Jonathan Wage
 
PPT
Introduction To Php For Wit2009
cwarren
 
PDF
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
PDF
lab4_php
tutorialsruby
 
PDF
lab4_php
tutorialsruby
 
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
ODP
Modern Web Development with Perl
Dave Cross
 
PDF
PHP and Rich Internet Applications
elliando dias
 
PPTX
REST API for your WP7 App
Agnius Paradnikas
 
PPTX
PHP: GraphQL consistency through code generation
Alexander Obukhov
 
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
PPT
Php Reusing Code And Writing Functions
mussawir20
 
PDF
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka
 
PDF
I Phone On Rails
John Wilker
 
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
PHP 5.3 Overview
jsmith92
 
Going crazy with Node.JS and CakePHP
Mariano Iglesias
 
Giới thiệu PHP 7
ZendVN
 
PHP And Web Services: Perfect Partners
Lorna Mitchell
 
Doctrine For Beginners
Jonathan Wage
 
Introduction To Php For Wit2009
cwarren
 
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
lab4_php
tutorialsruby
 
lab4_php
tutorialsruby
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Modern Web Development with Perl
Dave Cross
 
PHP and Rich Internet Applications
elliando dias
 
REST API for your WP7 App
Agnius Paradnikas
 
PHP: GraphQL consistency through code generation
Alexander Obukhov
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Php Reusing Code And Writing Functions
mussawir20
 
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka
 
I Phone On Rails
John Wilker
 

More from Marko Heijnen (20)

PDF
Custom coded projects
Marko Heijnen
 
PDF
Security, more important than ever!
Marko Heijnen
 
PDF
My Contributor Story
Marko Heijnen
 
PDF
WooCommerce & Apple TV
Marko Heijnen
 
PDF
The moment my site got hacked - WordCamp Sofia
Marko Heijnen
 
PDF
Mijn site beveiliging
Marko Heijnen
 
PDF
The moment my site got hacked
Marko Heijnen
 
PDF
My complicated WordPress site
Marko Heijnen
 
PDF
Node.js to the rescue
Marko Heijnen
 
PDF
Protecting your site by detection
Marko Heijnen
 
PDF
GlotPress aka translate.wordpress.org
Marko Heijnen
 
PDF
Writing clean and maintainable code
Marko Heijnen
 
PDF
Extending WordPress as a pro
Marko Heijnen
 
PDF
Let's create a multilingual site in WordPress
Marko Heijnen
 
PDF
Bootstrapping your plugin
Marko Heijnen
 
PDF
The development and future of GlotPress
Marko Heijnen
 
PDF
Why Javascript matters
Marko Heijnen
 
PDF
The code history of WordPress
Marko Heijnen
 
PDF
Building plugins like a pro
Marko Heijnen
 
PDF
Perfect your images using WordPress - WordCamp Europe 2013
Marko Heijnen
 
Custom coded projects
Marko Heijnen
 
Security, more important than ever!
Marko Heijnen
 
My Contributor Story
Marko Heijnen
 
WooCommerce & Apple TV
Marko Heijnen
 
The moment my site got hacked - WordCamp Sofia
Marko Heijnen
 
Mijn site beveiliging
Marko Heijnen
 
The moment my site got hacked
Marko Heijnen
 
My complicated WordPress site
Marko Heijnen
 
Node.js to the rescue
Marko Heijnen
 
Protecting your site by detection
Marko Heijnen
 
GlotPress aka translate.wordpress.org
Marko Heijnen
 
Writing clean and maintainable code
Marko Heijnen
 
Extending WordPress as a pro
Marko Heijnen
 
Let's create a multilingual site in WordPress
Marko Heijnen
 
Bootstrapping your plugin
Marko Heijnen
 
The development and future of GlotPress
Marko Heijnen
 
Why Javascript matters
Marko Heijnen
 
The code history of WordPress
Marko Heijnen
 
Building plugins like a pro
Marko Heijnen
 
Perfect your images using WordPress - WordCamp Europe 2013
Marko Heijnen
 

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
Software Development Methodologies in 2025
KodekX
 
Doc9.....................................
SofiaCollazos
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 

Creating native apps with WordPress

  • 1. Creating native apps with WordPress Marko Heijnen January 14, 2012 at WordCamp Norway
  • 2. Marko Heijnen Freelance developer Mobile / WordPress http://markoheijnen.com [email protected] @markoheijnen
  • 3. History 2006: Started with WordPress 2009: Started with iOS development 2010: First patch to WordPress ( 3.0 ) 2011: Combined iOS development with WordPress 2012: First WordCamp presentation
  • 5. Mobile is the growing
  • 6. There is a change you get involved with it
  • 7. Native app vs Web app/site
  • 8. Native vs mobile Build a native app when: People are going to use it quite often ( daily basis ) Features that aren’t possible for web ( yet ) A lot of users request for it ( 10.000 > ) Customers really want an app
  • 10. What does it mean for you You need to communicate with another developer Need to build an API that the developer can use So you need to understand what a mobile developer wants Need to build additional fields in WordPress for information that the mobile app can use
  • 13. API of the app WordPress for iOS uses XML-RPC WordPress support it by default Supports: Blogger API, metaWeblog API, and the Movable Type API
  • 14. Where can you find it /xmlrpc.php handles the request /wp-includes/class-wp-xmlrpc.server.php Registers all the default methods
  • 15. Methods for testing /** /** * Test XMLRPC API by saying, "Hello!" to client. * Test XMLRPC API by adding two numbers for client. * * * @since 1.5.0 * @since 1.5.0 * * * @param array $args Method Parameters. * @param array $args Method Parameters. * @return string * @return int */ */ function sayHello($args) { function addTwoNumbers($args) { return 'Hello!'; $number1 = $args[0]; } $number2 = $args[1]; return $number1 + $number2; }
  • 16. How to get recent post function mw_getRecentPosts($args) { $this->escape($args); $blog_ID = (int) $args[0]; $username = $args[1]; $password = $args[2]; if ( isset( $args[3] ) ) $query = array( 'numberposts' => absint( $args[3] ) ); else $query = array(); if ( !$user = $this->login($username, $password) ) return $this->error; do_action('xmlrpc_call', 'metaWeblog.getRecentPosts');
  • 17. How you can use it in your own way
  • 18. Create your own methods add_filter( 'xmlrpc_methods', 'add_own_methods' ); function add_own_methods( $methods ) { $methods['own.my_method'] = 'own_my_method'; return $methods } function own_my_method( $args ) { return $some_data }
  • 19. How does it look like
  • 21. Response <?xml version="1.0"?> <methodResponse> <params> <param> <value> <array><data> <value><struct> <member><name>dateCreated</name><value><dateTime.iso8601>20110904T18:15:26</dateTime.iso8601></value></member> <member><name>userid</name><value><string>1</string></value></member> <member><name>postid</name><value><string>1</string></value></member> <member><name>description</name><value><string>Welcome to &lt;a href=&quot;http://network.nginx.markoheijnen.com/&quot;&gt;WordPress Network Sites&lt;/a&gt;. 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> <member><name>link</name><value><string>http://test.network.nginx.markoheijnen.com/2011/09/04/hello-world/</string></value></member> <member><name>permaLink</name><value><string>http://test.network.nginx.markoheijnen.com/2011/09/04/hello-world/</string></value></member> <member><name>categories</name><value><array><data> <value><string>Uncategorized</string></value> </data></array></value></member> <member><name>mt_excerpt</name><value><string></string></value></member> <member><name>mt_text_more</name><value><string></string></value></member> <member><name>mt_allow_comments</name><value><int>1</int></value></member> <member><name>mt_allow_pings</name><value><int>1</int></value></member> <member><name>mt_keywords</name><value><string></string></value></member> <member><name>wp_slug</name><value><string>hello-world</string></value></member> <member><name>wp_password</name><value><string></string></value></member> <member><name>wp_author_id</name><value><string>1</string></value></member> <member><name>wp_author_display_name</name><value><string>marko</string></value></member> <member><name>date_created_gmt</name><value><dateTime.iso8601>20110904T18:15:26</dateTime.iso8601></value></member> <member><name>post_status</name><value><string>publish</string></value></member> <member><name>custom_fields</name><value><array><data> </data></array></value></member> <member><name>wp_post_format</name><value><string>standard</string></value></member> </struct></value> </data></array> </value> </param> </params> </methodResponse>
  • 22. XML-RPC Critics of XML-RPC argue that RPC calls can be made with plain XML XML-RPC uses about 4 times the number of bytes compared to plain XML Need a lot of code on the app side In the end the size of requests/responses do mather
  • 23. Is this the best way or are there alternatives?
  • 24. Alternatives Just XML instead of XML-RPC Use JSON
  • 25. What is JSON JavaScript Object Notation Use JSON as alternative to XML It is derived from the JavaScript scripting language Lightweight text-based open standard
  • 26. Why JSON Lighter and faster than XML JSON objects are typed Array, object, string, number, boolean and null Great libraries for mobile platforms iOS 5 does have native support for JSON Easy to parse on mobile platforms
  • 27. JSON Example { "firstName" : "Marko", "lastName" : "Heijnen", "age" : 25, "address" : null, "newsletter" : false, "phoneNumber" : [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ] }
  • 28. WordPress doesn’t have native support (yet)
  • 29. Plugins you can use JSON RPC - http://wordpress.org/extend/plugins/wp-json- rpc-api/ JSON API - http://wordpress.org/extend/plugins/json-api/ WP RESTful - http://wordpress.org/extend/plugins/wp- restful/ Be aware that these plugins aren’t up to date
  • 30. What do I use
  • 31. JSON API Great to use because of the use of hooks Good information on the plugin page Simple backend interface I use a modified version of it Added consumer key/secret
  • 33. How to implement function add_hello_controller( $controllers ) { $controllers[] = 'hello'; return $controllers; } add_filter( 'json_api_controllers', 'add_hello_controller' ); function set_hello_controller_path() { return "/path/to/theme/hello.php"; } add_filter( 'json_api_hello_controller_path', 'set_hello_controller_path' );
  • 34. How to implement <?php class JSON_API_Hello_Controller { public function hello_world() { return array( "message" => "Hello, world" ); } } ?>
  • 35. Important to know Only return data that is needed Return as less HTML as possible Don’t change the feed without notifying the app developer A call shouldn’t take to long, speed is everything Cache the data if possible Transients: http://codex.wordpress.org/Transients_API
  • 36. Recap
  • 38. Post types Add separate meta box for mobile content Even the ability to overrule the title Additional user capability, so not everyone can manage it Maybe even create a special post type for mobile content
  • 39. Special admin page Only for mobile configuration Store settings Store default pages for mobile like privacy disclaimer
  • 40. Push notifications Create ability to send push notifications in a smart way Add to posttype Make a separate box on dashboard or admin page You can handle the sending yourself Or use for example the services of Urban Airship
  • 41. Last word WordPress is a CMS Can be used in a lot of ways Sometimes look further then the plugin section