Book Image

WordPress Plugin Development: Beginner's Guide

Book Image

WordPress Plugin Development: Beginner's Guide

Overview of this book

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.
Table of Contents (14 chapters)
WordPress Plugin Development
Credits
About the Author
About the Reviewer
Preface
Index

Creating plugin options page


It is always useful if the plugin allows you to customize it to your liking. Using external CSS and layout files makes it easier, but what about variables and functions we use in the code?

That is where the plugin options page comes to play. It can be loaded with settings that we can change, and is easily accessible from the WordPress administration panel.

Let's create a few options for our plugin:

  • Allow the user to choose whether they want to display posts, pages, or both

  • Start the archive view in mini mode

  • Allow the user to provide descriptions for each year

The options page may look like this:

In order to have an options page, we need to cover several key functionalities:

  • Manage our options

  • Set up the options page

  • Show the options

  • Save them after user input

It is actually easier than it may appear to be, and there is no excuse not to have an options page in our plugins anymore!

Time for action Create an options page

  1. First, we will declare the names for our options...