Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SunShine PHP

184 views

Published on

  • Be the first to comment

  • Be the first to like this

SunShine PHP

  1. 1. T H E W O R D P R E S S R E S T A P I D A V I D B I S S E T @dimensionmedia
  2. 2. W H AT I S A R E S T A P I ?
  3. 3. REpresentational State Transfer Application Programing Interface
  4. 4. W H A T I S A R E S T A P I ? ‣ Separation Between Client and Server ‣ Stateless: No State, You Should Get Same Data From Same Requests ‣ Cacheable ‣ Layerable: Load-Balancing, etc. ‣ Uniform: REST APIs typically tell you how to access the data. ‣ Flexible: Doesn’t Matter Where Server/Client Area, Or What They Are ‣ Simple: Uses Standard/Established Methods
  5. 5. C R U D A N D H T T P M E T H O D S ‣ CREATE -> POST ‣ READ -> GET ‣ UPDATE -> PUT ‣ DELETE -> DELETE
  6. 6. W H AT I S T H E W P R E S T A P I ?
  7. 7. W O R D P R E S S + R E S T A P I = A W E S O M E S A U C E
  8. 8. R E Q U I R E M E N T S ‣ WordPress 4.4 ‣ WP REST API Plugin 2.0
  9. 9. L E T ’ S D I V E I N !
  10. 10. P O S T M A N https://www.getpostman.com/ Allows us to build and send requests to our API and also process and handle responses. A really great tool for working with any type of REST API, not just the WordPress API.
  11. 11. http://local.wordpress.dev/wp-json
  12. 12. davidbisset.com/wp-json/wp/v2/posts/
  13. 13. davidbisset.com/wp-json/wp/v2/comments/
  14. 14. davidbisset.com/wp-json/wp/v2/media/ davidbisset.com/wp-json/wp/v2/media/1792
  15. 15. U S I N G C U R L & W P _ H T T P
  16. 16. curl http://local.wordpress.dev/wp-json/wp/v2/posts
  17. 17. $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, 
 "http://local.wordpress.dev/wp-json/wp/v2/posts"); $json = curl_exec ($curl); curl_close ($curl); $data = json_decode($json); var_dump($data);
  18. 18. $json = wp_remote_get
 ( 'http://local.wordpress.dev/wp-json/wp/v2/posts' ); $return = json_decode( $json['body'] ); var_dump($return);
  19. 19. W O R K I N G W I T H P O S T S
  20. 20. davidbisset.com/wp-json/wp/v2/posts/
  21. 21. davidbisset.com/wp-json/wp/v2/posts/1805
  22. 22. F I LT E R I N G P O S T S
  23. 23. /wp-json/wp/v2/posts/?filter[orderby]=rand
  24. 24. davidbisset.com/wp-json/wp/v2/posts/?filter[s]=dradcast
  25. 25. /wp-json/wp/v2/posts/?filter[posts_per_page]=1&filter[paged]=1&filter[s]=dradcast
  26. 26. PA G E S
  27. 27. /wp-json/wp/v2/pages/
  28. 28. P O S T M E TA
  29. 29. P O S T M E TA ( F I LT E R I N G )
  30. 30. davidbisset.com/wp-json/wp/v2/posts/?filter[meta_key]=test_meta
  31. 31. A U T H E N T I C AT I O N
  32. 32. T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W: ‣ Basic Authentication – via a plugin ‣ Cookie Authentication – out of the box ‣ Oauth2 Authentication – via a plugin (third party) ‣ Oauth1 Authentication – via a plugin
  33. 33. T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W: ‣ Basic Authentication – via a plugin ‣ Cookie Authentication – out of the box ‣ Oauth2 Authentication – via a plugin (third party) ‣ Oauth1 Authentication – via a plugin
  34. 34. B A S I C - A U T H https://github.com/WP-API/Basic-Auth
  35. 35. TA D A ! B A S I C A U T H G E T S Y O U T H E S A M E A C C E S S / R O L E S A S Y O U R W P U S E R
  36. 36. F O R E X A M P L E , I F Y O U H A V E A D M I N A C C E S S Y O U C A N S E E A L L U S E R S
  37. 37. T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W: ‣ Basic Authentication – via a plugin ‣ Cookie Authentication – out of the box ‣ Oauth2 Authentication – via a plugin (third party) ‣ Oauth1 Authentication – via a plugin
  38. 38. T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W: ‣ Basic Authentication – via a plugin ‣ Cookie Authentication – out of the box ‣ Oauth2 Authentication – via a plugin (third party) ‣ Oauth1 Authentication – via a plugin
  39. 39. T H E R E A R E 4 B A S I C T Y P E S O F A U T H E N T I C A T I O N A VA I L A B L E F O R U S E R I G H T N O W: ‣ Basic Authentication – via a plugin ‣ Cookie Authentication – out of the box ‣ Oauth2 Authentication – via a plugin (third party) ‣ Oauth1 Authentication – via a plugin
  40. 40. D I G G I N G I N T O T H E A P I : C R E AT I N G A N E W P O S T
  41. 41. D I G G I N G I N T O T H E A P I : A D D N I N G & U P D AT I N G P O S T M E TA T O A P O S T
  42. 42. D I G G I N G I N T O T H E A P I : D E L E T I N G A P O S T
  43. 43. W H Y T H I S I S C O O L ‣ “Reverse Mullet”: Business in back, party in the front ‣ You don’t have to write PHP (write what you want) ‣ WordPress Can Now Power Native Mobile Applications ‣ Desktop Applications Possible ‣ More engaging user experience ‣ Offline: Control over failed connections, etc.
  44. 44. T H E M E S W I T H T H E W O R D P R E S S R E S T A P I
  45. 45. B U I L D I N G A P L U G I N U S I N G W P - A P I A N D A J A X
  46. 46. W H AT W E A R E B U I L D I N G
  47. 47. T H I N K A B O U T T H E A P I R E Q U E S T U R L
  48. 48. ‣ New WordPress 4.4 Install ‣ Used FakerPress To Add Random Content/ Categories ‣ Installed the WP REST API Plugin ‣ Using Popper As My Theme B U I L D T H E P L U G I N : S E T U P
  49. 49. B U I L D T H E P L U G I N : F I R S T S T E P S
  50. 50. B U I L D T H E P L U G I N : F I R S T S T E P S
  51. 51. B U I L D T H E P L U G I N : S E T U P F U N C T I O N S
  52. 52. S O O N 2 5 % O F T H E W E B W I L L H A V E A C C E S S T O T H E W O R D P R E S S R E S T A P I A N D W I L L B E U S E D F O R I N T E R E S T I N G T H I N G S
  53. 53. R E S O U R C E S http://wp-api.org/ Official Documentation
  54. 54. WordCamp Miami 2016 February 19-21 FIU College of Business
  55. 55. T H A N K Y O U D A V I D B I S S E T @dimensionmedia
  56. 56. david bisset D A V I D B I S S E T. C O M @ D I M E N S I O N M E D I A

×