Learning WordPress REST API
Learning WordPress REST API
Copyright Š 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: July 2016
Production reference: 1180716
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-924-3
www.packtpub.com
Sufyan bin Uzayr is a writer and web developer with experience and an interest in a lot of things related to web design and development. He has worked with numerous Content Management Systems and frameworks, and writes about web design, web development, content production, branding, and typography for several blogs and magazines of repute. He also has a background in Linux administration, database management, cloud computing, and web hosting.
Sufyan is an open source enthusiast. He can code in PHP, RoR, and Perl, and is also proficient in JavaScript, jQuery, and HTML5/CSS3, as well as several other web development trends.
Sufyan primarily uses WordPress and Drupal for both personal and client projects, and often turns towards MODX for the deployment of cloud sites. He has been working with Drupal, WordPress, and other CMSs for almost a decade by now.
Sufyan is a prolific author, and has written several books on a diverse range of topics, including concrete5 for developers (published by Packt Publishing in 2014). He is associated with various publications in the field of web design and development, both in writing and editorial capacity. He has also served as the News Editor and Technical Supervisor, as well as Editor-in-Chief, for multiple web development magazines, both online and in print.
Apart from technology and coding, Sufyan also takes a keen interest in topics such as History, Current Affairs, Foreign Policy and Politics, and regularly appears on television and radio shows around the world. He is also a featured columnist for multiple journals and news publications focusing on foreign policy and international relations. Sufyan's writings on contemporary issues are simultaneously translated into different languages, and his works are cited in academic and critical journals on a regular basis.
Sufyan manages https://codecarbon.com, which features an assortment of useful tools and resources for web developers. Updated regularly, Code Carbon offers JavaScript frameworks and libraries, as well as resources related to HTML/CSS, PHP, Python, Ruby, and of course, WordPress.
You can learn more about Sufyan's writings and other non-technical works at the following website: http://sufyanism.com.
Mathew Rooney is a coder with multiple years of experience in the web development industry. He works with PHP, JavaScript, and offers custom-coded WordPress themes and plugins. Mathew is a firm believer in open source software and has been using WordPress for nearly 5 years.
There are several people who deserve to be this page, because this book would not have come into existence without their support.
Some names deserve a special mention, and I am genuinely indebted to:
Mathew Rooney, for the help he offered by co-authoring sections of this book. A good part of the code in different segments and chapters of this book was handled by him. Reshma Raman, for ensuring that the book stays on track, and the outline and chapter division is in the best possible shape.
Prashanth G, for editing the book, and making sure that the content is in order, and also for formatting the manuscript to make it adhere to the Packt style guide.
Shivani Mistry, for the technical edits, and for taking care of the book during the production stage.
Joe Perkins, and all the great folks at Tap Managed WordPress hosting, for offering me a free WordPress setup with no restrictions, wherein I could implement and debug the code.
Stelian Subotin, for helping me remain calm by keeping track of the theoretical aspects of the book.
Ahmad Awais, for reviewing the manuscript, and for providing his helpful insight and critical assessment.
And of course, the core contributors of WordPress, the team behind WP REST API, as well as the millions within the WordPress community -- this book would not have existed had WordPress not been there, and WordPress itself would not be so popular if it were not for the amazing community.
-- Sufyan bin Uzayr
Ahmad Awais is a senior full stack web and business development strategist with substantial industrial experience in development, design, training, and writing everything about WordPress.
He blogs at https://AhmadAwais.com/ and tweets at @MrAhmadAwais
. He also contributes to projects such as WP-API, WP Customize Component, WooCommerce, TwentySixteen, Easy Digital Downloads, and the WordPress, PHP, and JS Communities.
Ahmad is also one of the keenest open source evangelists; a core contributor at WordPress; a maker of lots of FOSS (Free and Open Source Software), especially WPGulp Boilerplate being used by more than 100 developers, and Sublime Text WordPressCustomizer Package, helping about 1,000 developers write quality code with ease.
He is a published author and WordPress Content Lead at sites such as WPLift, Envato Tuts+, Torque Mag by WPEngine, SitePoint, SmashingMagazine, CreativeMarket, HongKiat, SpeckyBoy, wpMail, Post Status, WPBeginner, TheLayout by FlyWheel, ProductHunt Maker, and so on.
I'd like to thank my parents, Maedah Batool (WP Journalist) for their never-ending support; Packt Publishing, the WordPress Core Team, and the community (developers, designers, and users), without whom none of this would have been possible.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at
www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
The REST API is the next big thing in the world of WordPress development. Ever since its inception, it has been gaining popularity, and more and more developers are turning towards it.
Of course, the REST API comes with numerous benefits, such as the ability to interact with third-party platforms and apps. Have an application coded in Ruby and want to interact with a WordPress site based on PHP? The REST API is here to help you!
This book will help you get started with the REST API for WordPress. You will learn the basics as well as the advanced details of this new API so that you can use it in your projects.
Chapter 1, Getting Started with REST API, gives you an overview of what the REST API is, how it functions, and all that it is capable of doing. You will also find information about other platforms if you are new to WordPress.
Chapter 2, Interacting with REST API in WordPress, is where you will learn the basics of the REST API in WordPress. General POST and GET commands shall be covered here.
Chapter 3, Working with Taxonomies and Users with REST API, moves to taxonomies such as categories and tags. Users and user roles will also be covered.
Chapter 4, Working with Forms Using REST API, will show you how the REST API can be used to work with custom forms for your WP platform. This chapter will teach you how to get the most out of it.
Chapter 5, Custom Routes in WordPress REST API, progresses beyond default roles and teaches you how to add and work with custom routes using the REST API.
Chapter 6, Creating a Simple Web App Using WordPress REST API, is where you learn how to create a web app. Plus, you will also learn how to pass commands to your web app.
Chapter 7, Mastering REST API for Your Projects, is where you will learn how to master the REST API for your projects. Obviously, this chapter requires that you have a working knowledge of the REST API, as well as experience with WordPress development.
Chapter 8, WordPress REST API in Practice, teaches you the practical aspects of the WP REST API and its development.
Chapter 9, Summing It Up, wraps up our journey with the WordPress REST API. We will have a recap of all that we have learned so far and an overview of what the REST API can do for us.
What you need for this book
Obviously, you will need a working installation of WordPress to begin with. The latest version of WordPress is recommended so that you do not miss out on security updates.
You will also need to install and activate the WordPress REST API plugin on your site. Free download and installation instructions are here: https://wordpress.org/plugins/rest-api/.
At least PHP 5.4 or higher is recommended. The latest supported version of MySQL is required as well, and enhancements such as MariaDB are also allowed.
You can run WP on a generic LAMP or WAMP stack. For further instructions, consider reading the WordPress documentation.
This book is for WordPress developers and designers who want to get a complete practical understanding of the WordPress REST API and leverage it to create fully featured web apps.
2323__perleg...