WordPress Plugin Development: Beginner's Guide
()
About this ebook
If you can write WordPress plug-ins, you can make WordPress do just about anything. From making the site easier to administer, to adding the odd tweak or new feature, to completely changing the way your blog works, plug-ins are the method WordPress offers to customize and extend its functionality. This book will show you how to build all sorts of WordPress plug-ins: admin plug-ins, Widgets, plug-ins that alter your post output, present custom "views" of your blog, and more.
WordPress Plug-in Development (Beginner's Guide) focuses on teaching you all aspects of modern WordPress development. The book uses real and published WordPress plug-ins and follows their creation from the idea to the finishing touches, in a series of carefully picked, easy-to-follow tutorials. You will discover how to use the WordPress API in all typical situations, from displaying output on the site in the beginning to turning WordPress into a CMS in the last chapter. In Chapters 2 to 7 you will develop six concrete plug-ins and conquer all aspects of WordPress development.
Each new chapter and each new plug-in introduces different features of WordPress and how to put them to good use, allowing you to gradually advance your knowledge. This book is written as a guide to take your WordPress skills from the very beginning to the level where you are able to completely understand how WordPress works and how you can use it to your advantage.
A fast-paced guide for PHP developers to creating feature-rich plug-ins for WordPress
ApproachThis is a Packt Beginners Guide, which means it focuses on practical examples and has a fast-paced but friendly approach, with the opportunity to learn by experiment and play. Each chapter builds a practical plug-in from the ground up using step-by-step instructions. Individual sections show you how to code some functionality into your plug-in and follow up with a discussion of concepts.
Who this book is forThis book is for programmers working with WordPress, who want to develop custom plug-ins and to hack the code base. You need to be familiar with the basics of WordPress and PHP programming and believe that code is poetry; this book will handle the rest.
Vladimir Prelovac
Vladimir Prelovac is the author of many popular WordPress plugins and articles about WordPress optimization, security and maintenance. He actively uses WordPress platform as a base for Internet development strategy for small & mid-sized businesses. For Vladimir, WordPress development is a full time job about which he happily blogs on his web site prelovac.com.
Related to WordPress Plugin Development
Related ebooks
WordPress Web Application Development - Second Edition Rating: 0 out of 5 stars0 ratingsWordPress 4.0 Site Blueprints - Second Edition Rating: 0 out of 5 stars0 ratingsWordPress 3.7 Complete Rating: 5 out of 5 stars5/5Social Media for WordPress Beginner's Guide Rating: 0 out of 5 stars0 ratingsResponsive Web Design by Example : Beginner's Guide - Second Edition Rating: 0 out of 5 stars0 ratingsjQuery for Designers Beginner's Guide Second Edition Rating: 5 out of 5 stars5/5Learning Website Development with Django Rating: 0 out of 5 stars0 ratingsLearning Node.js for .NET Developers Rating: 0 out of 5 stars0 ratingsWordpress Web Application Development - Third Edition Rating: 0 out of 5 stars0 ratingsProfessional WordPress Plugin Development Rating: 4 out of 5 stars4/5WordPress Web Application Development Rating: 5 out of 5 stars5/5WordPress For Dummies Rating: 0 out of 5 stars0 ratingsAdvance WORDPRESS Mastery Kit WITH ONLINE VIDEOS Rating: 0 out of 5 stars0 ratingsWordPress A Complete Guide - 2019 Edition Rating: 3 out of 5 stars3/5WordPress All-in-One For Dummies Rating: 3 out of 5 stars3/5Wordpress Websites for Business: How Anyone Can Maximize Website Performance and Results Rating: 0 out of 5 stars0 ratingsLearning Bootstrap 4 - Second Edition Rating: 5 out of 5 stars5/5Learn WordPress In 7 Days: Complete Step by Step Beginners Guide To Become WordPress Expert Rating: 2 out of 5 stars2/5HTML, CSS, Bootstrap, Php, Javascript and MySql: All you need to know to create a dynamic site Rating: 4 out of 5 stars4/5Learning WordPress REST API Rating: 0 out of 5 stars0 ratingsLearning PHP 7 Rating: 4 out of 5 stars4/5Responsive Web Design with HTML5 and CSS3 Essentials Rating: 5 out of 5 stars5/5WordPress E-Commerce Blueprint: How to Create and Manage WordPress Online Store for Beginner Rating: 3 out of 5 stars3/5phpMyAdmin Starter Rating: 0 out of 5 stars0 ratingsWordPress 2019: The Beginner's Complete Step-by-Step Guide to Creating a Mobile Friendly Website with WordPress Rating: 0 out of 5 stars0 ratingsWordpress for Beginners: The Easy Step-by-Step Guide to Creating a Website with WordPress Rating: 5 out of 5 stars5/5WordPress 3 Plugin Development Essentials Rating: 4 out of 5 stars4/5WooCommerce Cookbook Rating: 0 out of 5 stars0 ratingsResponsive Web Design with HTML5 and CSS3 - Second Edition Rating: 4 out of 5 stars4/5
Information Technology For You
CompTIA A+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Core 1 Exam 220-1101 Rating: 0 out of 5 stars0 ratingsLinux Command Line and Shell Scripting Bible Rating: 3 out of 5 stars3/5An Ultimate Guide to Kali Linux for Beginners Rating: 3 out of 5 stars3/5Supercommunicator: Explaining the Complicated So Anyone Can Understand Rating: 3 out of 5 stars3/5Summary of Super-Intelligence From Nick Bostrom Rating: 5 out of 5 stars5/5Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5How to Write Effective Emails at Work Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5CompTia Security 701: Fundamentals of Security Rating: 0 out of 5 stars0 ratingsHealth Informatics: Practical Guide Rating: 0 out of 5 stars0 ratings20 Windows Tools Every SysAdmin Should Know Rating: 5 out of 5 stars5/5Practical Ethical Hacking from Scratch Rating: 5 out of 5 stars5/5How To Use Chatgpt: Using Chatgpt To Make Money Online Has Never Been This Simple Rating: 0 out of 5 stars0 ratingsHow to Find a Wolf in Siberia (or, How to Troubleshoot Almost Anything) Rating: 0 out of 5 stars0 ratingsMicrosoft Access for Beginners and Intermediates Rating: 0 out of 5 stars0 ratingsRaspberry Pi :Raspberry Pi Guide On Python & Projects Programming In Easy Steps Rating: 3 out of 5 stars3/5Cybersecurity for Beginners : Learn the Fundamentals of Cybersecurity in an Easy, Step-by-Step Guide: 1 Rating: 0 out of 5 stars0 ratingsCompTIA ITF+ CertMike: Prepare. Practice. Pass the Test! Get Certified!: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsPersonal Knowledge Graphs: Connected thinking to boost productivity, creativity and discovery Rating: 0 out of 5 stars0 ratingsWho Says Elephants Can't Dance?: Leading a Great Enterprise Through Dramatic Change Rating: 4 out of 5 stars4/5Google SketchUp for Game Design: Beginner's Guide Rating: 5 out of 5 stars5/5Learning Microsoft Endpoint Manager: Unified Endpoint Management with Intune and the Enterprise Mobility + Security Suite Rating: 0 out of 5 stars0 ratingsA Practical Guide Wireshark Forensics Rating: 5 out of 5 stars5/5Getting started with Audacity 1.3 Rating: 5 out of 5 stars5/5A Mind at Play: How Claude Shannon Invented the Information Age Rating: 4 out of 5 stars4/5ChatGPT: The Future of Intelligent Conversation Rating: 4 out of 5 stars4/5
Reviews for WordPress Plugin Development
0 ratings0 reviews
Book preview
WordPress Plugin Development - Vladimir Prelovac
Table of Contents
WordPress Plugin Development
Credits
About the Author
About the Reviewer
Preface
What This Book Covers
Who is This Book For
Conventions
Reader Feedback
Customer Support
Downloading the Example Code for the Book
Errata
Piracy
Questions
1. Preparing for WordPress Development
How will you benefit?
WordPress features
More sites means more opportunities
Big players use it
Urgent response to security issues
Flexibility
Search engines friendly
Easy to use
Social aspect
Plugins as tool for promotion
Dogfooding WordPress plugins
Challenges involved
Development
Security
Work after development
Localization
Documentation
Support
Promotion
Plugins developed in this book
Digg This
Live Blogroll
The Wall
Snazzy Archives
Insights
Post Types
Development Goodies
Tools for the job
WordPress
Text editor
FTP client
Web browser
Firebug
Ubiquity
Screengrab
IE tab
Final notes
Installing and managing plugins
Searching documentation
Summary
2. Social Bookmarking
Plugging in your first plugin
Time for action – Create your first plugin
What just happened?
The plugin information header
Checking WordPress versions
Checking the plugin
Time for Action – Testing the version check
What just happened?
Have a go Hero
Displaying a Digg button
Time for Action – Implement a Digg link
What just happened?
Using the Digg API
Submit URL:
Submit URL Details:
Acquiring post information
Post permalink URL
Editing the theme files
Have a go Hero
WordPress plugin hooks
Time for Action – Use a filter hook
What just happened?
WordPress hooks
Filter hooks
Action hooks
Practical filters and actions examples
Upper case titles
Mailing list
Changing core WordPress functionality
Have a go Hero
Adding a Digg button using JavaScript code
Time for Action – Implement a Digg button
What just happened?
Conditional Tags
Styling the output
Time for Action – Use CSS to position the button
What just happened?
Have a go Hero
Summary
3. Live Blogroll
Starting up with the blogroll
Time for action – Roll into the blogroll
What just happened?
RSS Feed Processing
jQuery JavaScript library
Implementing a mouse hover event in jQuery
Time for action – Creating a hover event with jQuery
What just happened?
JavaScript and WordPress
Initializing jQuery
Expanding jQuery knowledge
Creating the pop-up with CSS
Time for action – Apply CSS to the popup
What just happened?
Demystifying Ajax
Simple example of using Ajax
Time for action – Use Ajax to dynamically retrieve feed posts
What just happened?
Using JavaScript with WordPress
Parsing parameters using wp_localize_script
Ajax and WordPress
Ajax in admin panel
jQuery.ajax method
Time for action – Use advanced Ajax call
What just happened?
Ajax script security using nonces
Time for action – Add a security nonce
What just happened?
Summary
4. The Wall
The main concepts behind the Wall plugin
Creating a widget
Time for action – Create a 'Hello World!' widget
What just happened?
Register widgets with description
Widget controls
Time for action – Expanding the widget with controls
What just happened?
WordPress options
Display widget control
Handling widget input
Handling widget output
Create a WordPress page from the code
Time for action – Insert a page
What just happened?
Handling user input
Time for action – Create the wall comment form
What just happened?
Managing Ajax comment submit
Time for action – Save the comments
What just happened?
Using Ajax to submit forms
Saving comments in WordPress post
Dynamically load comments
Time for action – Display the comments
What just happened?
WordPress database query
Comment output
Displaying the comments
Ajax security
Time for action – Display the comments
What just happened?
Have a go Hero
Summary
5. Snazzy Archives
Using a class for plugin
Time for action – Create a new plugin class
What just happened?
Showing template output with shortcodes
Time for action – Use a shortcode
What just happened?
Shortcode API
Enclosing shortcodes
Custom templates
Time for action – Create a custom template
What just happened?
Prepare archives
Time for action – Show archives of posts
What just happened?
Get all posts from database
Using a regular expression
Retrieve comment count for a post
Using output buffers
Apply styling and jQuery to archives
Time for action – Style the archive view
What just happened?
Time for action – Use jQuery to allow user interaction
What just happened?
Have a go Hero
Creating plugin options page
Time for action – Create an options page
What just happened?
Managing plugin options
Handling options form
Adding administration pages
Use plugin options
Time for action – Apply the plugin options
What just happened?
Caching the plugin output
Time for action – Create archives cache
What just happened?
Have a go Hero
Summary
6. Insights for WordPress
Creating custom panels in the editor screen
Time for action – Create a new plugin outline
What just happened?
Custom edit panels in WordPress
Searching the posts
Time for action – Display a list of matching posts
What just happened?
Interacting with tinyMCE
Time for action – Insert the link into tinyMCE
What just happened?
Using Flickr API
Time for action – Display Flickr photos
What just happened?
Using third-party solutions—phpFlickr
Creating a tinyMCE plugin
Time for action – Adding a button to tinyMCE
What just happened?
Create a functional tinyMCE plugin window
Time for action – Open a tinyMCE window
What just happened?
Have a go Hero
Summary
7. Post Types
Handling localization
Time for action – Create plugin and add localization
What just happened?
Optimizing localization usage
How does localization work?
Adding a post template
Time for action – Create 'add photo' post template
What just happened?
Backend CSS classes
Handling file and image uploads
Time for action – Handle uploaded image
What just happened?
Using custom fields
Adding custom fields
Retrieving custom fields
Quick post a link
Time for action – Add link template
What just happened?
Tinkering with WordPress backend menus
Time for action - Remove 'Link' from the Write page
What just happened?
Programming the Manage panel
Time for action – Add post type column in the Manage panel
What just happened?
Modifying an existing column
Manage screen search filter
Time for action – Add a search filter box
What just happened?
Handling error messages
Time for action – Adding support for errors
What just happened?
User roles and capabilities
Time for action – Add user capability checks
What just happened?
Have a go Hero
Summary
8. Development Goodies
Creating Localization files
Time for action - Create a POT file
What just happened?
Updating POT file
Time for action – Perform translation
What just happened?
Updating translation
Documentation and support
Plugin readme file
Time for action – Create a sample plugin readme.txt file
What just happened?
Sections of readme.txt
General information
Special codes
Screenshots
Installation instructions
Plugin homepage
Providing support
Code management and plugin repository
Requesting repository access
Using SVN
Time for action - Manage a local repository using SVN
What just happened?
Tagging a new version
Using WordPress development SVN
Local copy of plugin repository
Promotion
Plugin promotion checklist
General plugin development guidelines
Security
Performance
Re-using resources
Keeping API up-to-date
WordPress MU development
WordPress and GPL
Online resources
WordPress documentation (WordPress Codex)
WordPress development news
WordPress blog
WordPress development updates
WordPress Trac
WordPress dev IRC channel
Debugging and testing
Unit testing
Automated tests
Mailing Lists
WP hackers
WP professionals
Other mailing lists
Podcasts
WordCast
WordPress Weekly
Author's (Vladimir Prelovac's) web site
Summary
Index
WordPress Plugin Development
Beginner's Guide
Vladimir Prelovac
WordPress Plugin Development
Beginner's Guide
Copyright © 2009 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, Packt Publishing, nor its dealers or 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 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: February 2009
Production Reference: 2200209
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-847193-59-9
www.packtpub.com
Cover Image by Vinayak Chittar (<[email protected]>)
Credits
Author
Vladimir Prelovac
Reviewer
Junal Rahman
Senior Acquisition Editor
David Barnes
Development Editor
Nikhil Bangera
Technical Editor
Mehul Shetty
Copy Editor
Sumathi Sridhar
Indexer
Monica Ajmera
Production Editorial Manager
Abhijeet Deobhakta
Editorial Team Leader
Akshara Aware
Project Team Leader
Lata Basantani
Project Coordinator
Neelkanth Mehta
Proofreader
Lesley Harrison
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade
About the Author
Vladimir Prelovac is the author of many popular WordPress plugins and articles about WordPress optimization, security and maintenance. He actively uses WordPress platform as a base for Internet development strategy for small & mid-sized businesses.
For Vladimir, WordPress development is a full time job about which he happily blogs on his web site www.prelovac.com/vladimir.
I'd like to thank my editor Mr. Barnes, for leading me through the book writer's path. Dave, Ervin, and guys at Wordcast, for the professional support they showed in such a lovely way. My family for understanding the long, sleepless nights of writing. Finally, I wish to dedicate this book to my mother, Vera Prelovac (1949-2008), who was and will always be my beacon of light.
About the Reviewer
Junal Rahman is a Computer Science graduate from the Independent University of Bangladesh. His areas of expertise include programming with the PHP framework and creating Facebook applications. He has worked for several software companies as a Web Application Developer. During his undergraduate studies Junal fell in love with .NET programming, but as soon as he started his internship, he fell in love with PHP. He currently works as a Development Engineer at Trippert Labs. At Trippert, Junal collaboratively works to create Facebook applications. He also maintains a blog that can be found at http://junal.wordpress.com.
I would like to acknowledge my sister Shiuly, follow your dreams
Preface
If you can write WordPress plugins, you can make WordPress do just about anything. From making the site easier to administer, to adding the odd tweak or new feature, to completely changing the way your blog works; plugins are the method WordPress offers to customize and extend its functionality. This book will show you how to build all sorts of WordPress plugins: admin plugins, Widgets, plugins that alter your post output, present custom views
of your blog, and more.
This book focuses on teaching you all aspects of modern WordPress development and usage. The book uses real and published WordPress plugins and follows their creation from the idea to the finishing touches, in a series of carefully picked, easy-to-follow tutorials. You will discover how to use the WordPress API in all typical situations, from displaying output on the site in the beginning to turning WordPress into a CMS in the last chapter. In Chapters 2 to 7, you will develop six concrete plugins and conquer all aspects of WordPress plugin development.
Each new chapter and each new plugin introduces different features of WordPress and how to put them to good use, allowing you to gradually advance your knowledge. This book is written as a guide to take your WordPress skills from the very beginning to the level where you are able to completely understand how WordPress works and how you can use it to your advantage.
This is a Packt Beginners Guide, which means it focuses on practical examples and has a fast-paced but friendly approach, with the opportunity to learn by experimentation and play. Each chapter builds a practical plugin from the ground up using step-by-step instructions. Individual sections show you how to code some functionality into your plugin and follow up with a discussion of concepts.
What This Book Covers
Chapter 1 teaches the advantages of WordPress development, and what WordPress has to offer to plugin authors.
Chapter 2 creates a working, useful, and attractive WordPress plugin from scratch. It shows how to extract information using the WordPress API and how to use CSS to improve the look of our plugin.
Chapter 3 explores more cool things we can do with WordPress by livening up the default WordPress blogroll. The purpose of the plugin is to display the most recent posts from the sites listed in the blogroll using a nice pop-up window.
Chapter 4 uses the mixed approach, by taking advantage of creative WordPress and JavaScript techniques, in order to create an Ajax powered 'Wall’ for your blog’s sidebar. It introduces quite a few interesting techniques such as Widgets, interacting with the WordPress Database, and Ajax form submission.
Chapter 5 covers the creation of a very sleek and stylish looking WordPress enhancement. The purpose of the Snazzy Archives plugin will be to present your site archives in a unique visual way. It shows how to manipulate the layout of the template using shortcodes and custom templates.
Chapter 6 is all about digging a little deeper into WordPress and hacking the Write Post screen. It shows how to create custom panels in the various sections of the Write Post screen. It teaches how to access the current WordPress rich text editor, tinyMCE, and create a button on its toolbar.
Chapter 7 explores the possibilities of turning WordPress into a Content Management System (CMS), using methods provided to us by WordPress. It shows how to modify the Manage Posts panel to display the information we want. It also covers managing who can use your plugin by looking at the logged in user capabilities.
Chapter 8 covers the additional steps involved in localizing, documenting, publishing, and promoting your plugin. It also covers useful tips and ideas to improve your general WordPress knowledge further.
Who is This Book For
This book is for programmers working with WordPress, who want to develop custom plugins and to hack the code base. You need to be familiar with the basics of WordPress and PHP programming and believe that code is poetry; this book will handle the rest.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: Edit the insights.js file and add the functionality to insert the HTML directly into tinyMCE.
A block of code will be set as follows:
/* Add Digg link to the end of the post */
function WPDiggThis_ContentFilter($content)
{
return $content.WPDiggThis_Link();
}
When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:
serif>Read the rest of this entry »’); ?>
New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this:
Go to your WordPress Plugins admin panel.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader Feedback
Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply drop an email to <[email protected]>, making sure to mention the book title in the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer Support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the Example Code for the Book
Visit http://www.packtpub.com/files/code/3599_Code.zip to directly download the example code.
The downloadable files contain instructions on how to use them.
Errata
Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata are added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide the location address or website name immediately so we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <[email protected]> if you are having a problem with some aspect of the book, and we will do our best to address it.
Chapter 1. Preparing for WordPress Development
If you are holding this book in your hands now, you are probably aware—in one way or the other—of the tremendous success WordPress platform has seen over the past few years. It has become the most widespread blogging and publishing platform in the world today.
When I first installed WordPress, I was still looking around for a platform to start my personal site and also for an opportunity to do more online development work.
After seeing the simple installation procedure (which takes just a few minutes), I realized that the