SlideShare a Scribd company logo
Wordpress Plugin Development Beginners Guide
Vladimir Prelovac download
https://ebookbell.com/product/wordpress-plugin-development-
beginners-guide-vladimir-prelovac-2310326
Explore and download more ebooks at ebookbell.com
Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Wordpress Plugin Development Cookbook Yannick Lefebvre
https://ebookbell.com/product/wordpress-plugin-development-cookbook-
yannick-lefebvre-2609128
Wordpress Plugin Development Cookbook Explore The Complete Set Of
Tools To Craft Powerful Plugins That Extend The Worlds Most Popular
Cms 3rd Edition Yannick Lefebvre
https://ebookbell.com/product/wordpress-plugin-development-cookbook-
explore-the-complete-set-of-tools-to-craft-powerful-plugins-that-
extend-the-worlds-most-popular-cms-3rd-edition-yannick-
lefebvre-42543230
Wordpress Plugin Development Cookbook Create Powerful Plugins To
Extend The Worlds Most Popular Cms 2nd Edition Yannick Lefebvre
https://ebookbell.com/product/wordpress-plugin-development-cookbook-
create-powerful-plugins-to-extend-the-worlds-most-popular-cms-2nd-
edition-yannick-lefebvre-11069084
Wordpress Plugin Development Cookbook Create Powerful Plugins To
Extend The Worlds Most Popular Cms 2nd Edition Yannick Lefebvre
https://ebookbell.com/product/wordpress-plugin-development-cookbook-
create-powerful-plugins-to-extend-the-worlds-most-popular-cms-2nd-
edition-yannick-lefebvre-11144406
Wordpress Plugin Development Cookbook Yannick Lefebvre
https://ebookbell.com/product/wordpress-plugin-development-cookbook-
yannick-lefebvre-47871558
Professional Wordpress Plugin Development 1st Edition Williams
https://ebookbell.com/product/professional-wordpress-plugin-
development-1st-edition-williams-55460870
Professional Wordpress Plugin Development 2nd Edition Brad Williams
https://ebookbell.com/product/professional-wordpress-plugin-
development-2nd-edition-brad-williams-11069544
Professional Wordpress Plugin Development Brad Williams Justin Tadlock
John James Jacoby
https://ebookbell.com/product/professional-wordpress-plugin-
development-brad-williams-justin-tadlock-john-james-jacoby-57410810
Professional Wordpress Plugin Development Brad Williams Justin Tadlock
https://ebookbell.com/product/professional-wordpress-plugin-
development-brad-williams-justin-tadlock-48507376
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
WordPress Plugin Development
Beginner's Guide
Build powerful, interactive plugins for your blog and to
share online
Vladimir Prelovac
BIRMINGHAM - MUMBAI
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 (vinayak.chittar@gmail.com)
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
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
Table of Contents
Preface 1
Chapter 1: Preparing for WordPress Development 7
How will you benefit? 7
WordPress features 7
More sites means more opportunities 8
Big players use it 8
Urgent response to security issues 8
Flexibility 8
Search engines friendly 9
Easy to use 9
Social aspect 9
Plugins as tool for promotion 9
Dogfooding WordPress plugins 10
Challenges involved 10
Development 10
Security 11
Work after development 11
Localization 11
Documentation 11
Support 11
Promotion 12
Plugins developed in this book 12
Digg This 12
Live Blogroll 13
The Wall 14
Snazzy Archives 14
Insights 15
Post Types 15
Development Goodies 16
Tools for the job 16
Table of Contents
[ ii ]
WordPress 16
Text editor 17
FTP client 17
Web browser 17
Firebug 17
Ubiquity 19
Screengrab 20
IE tab 21
Final notes 21
Installing and managing plugins 22
Searching documentation 23
Summary 25
Chapter 2: Social Bookmarking 27
Plugging in your first plugin 28
Time for action – Create your first plugin 28
The plugin information header 30
Checking WordPress versions 30
Checking the plugin 31
Time for Action – Testing the version check 31
Displaying a Digg button 32
Time for Action – Implement a Digg link 32
Using the Digg API 35
Acquiring post information 37
Post permalink URL 37
Editing the theme files 37
WordPress plugin hooks 39
Time for Action – Use a filter hook 40
WordPress hooks 41
Filter hooks 41
Action hooks 42
Practical filters and actions examples 44
Adding a Digg button using JavaScript code 46
Time for Action – Implement a Digg button 47
Conditional Tags 49
Styling the output 50
Time for Action – Use CSS to position the button 50
Summary 52
Chapter 3: Live Blogroll 55
Starting up with the blogroll 57
Time for action – Roll into the blogroll 58
RSS Feed Processing 62
jQuery JavaScript library 63
Implementing a mouse hover event in jQuery 63
Table of Contents
[ iii ]
Time for action – Creating a hover event with jQuery 63
JavaScript and WordPress 67
Initializing jQuery 68
Expanding jQuery knowledge 68
Creating the pop-up with CSS 70
Time for action – Apply CSS to the popup 70
Demystifying Ajax 73
Simple example of using Ajax 73
Time for action – Use Ajax to dynamically retrieve feed posts 73
Using JavaScript with WordPress 79
Parsing parameters using wp_localize_script 79
Ajax and WordPress 80
Ajax in admin panel 80
jQuery.ajax method 81
Time for action – Use advanced Ajax call 81
Ajax script security using nonces 82
Time for action – Add a security nonce 82
Summary 84
Chapter 4: The Wall 85
The main concepts behind the Wall plugin 87
Creating a widget 89
Time for action – Create a 'Hello World!' widget 89
Register widgets with description 93
Widget controls 94
Time for action – Expanding the widget with controls 94
WordPress options 97
Display widget control 97
Handling widget input 98
Handling widget output 98
Create a WordPress page from the code 100
Time for action – Insert a page 100
Handling user input 104
Time for action – Create the wall comment form 104
Managing Ajax comment submit 108
Time for action – Save the comments 109
Using Ajax to submit forms 113
Saving comments in WordPress post 115
Dynamically load comments 117
Time for action – Display the comments 118
WordPress database query 120
Comment output 121
Displaying the comments 122
Ajax security 123
Table of Contents
[ iv ]
Time for action – Display the comments 123
Summary 124
Chapter 5: Snazzy Archives 125
Using a class for plugin 126
Time for action – Create a new plugin class 126
Showing template output with shortcodes 130
Time for action – Use a shortcode 130
Shortcode API 132
Enclosing shortcodes 133
Custom templates 134
Time for action – Create a custom template 134
Prepare archives 136
Time for action – Show archives of posts 137
Get all posts from database 142
Using a regular expression 142
Retrieve comment count for a post 142
Using output buffers 143
Apply styling and jQuery to archives 143
Time for action – Style the archive view 143
Time for action – Use jQuery to allow user interaction 147
Creating plugin options page 149
Time for action – Create an options page 151
Managing plugin options 155
Handling options form 156
Adding administration pages 158
Use plugin options 159
Time for action – Apply the plugin options 160
Caching the plugin output 163
Time for action – Create archives cache 163
Summary 166
Chapter 6: Insights for WordPress 167
Creating custom panels in the editor screen 169
Time for action – Create a new plugin outline 169
Custom edit panels in WordPress 172
Searching the posts 174
Time for action – Display a list of matching posts 174
Interacting with tinyMCE 181
Time for action – Insert the link into tinyMCE 181
Using Flickr API 184
Time for action – Display Flickr photos 185
Using third-party solutions—phpFlickr 191
Creating a tinyMCE plugin 192
Time for action – Adding a button to tinyMCE 192
Table of Contents
[  ]
Create a functional tinyMCE plugin window 197
Time for action – Open a tinyMCE window 197
Summary 200
Chapter 7: Post Types 201
Handling localization 202
Time for action – Create plugin and add localization 203
Optimizing localization usage 206
How does localization work? 207
Adding a post template 208
Time for action – Create 'add photo' post template 208
Backend CSS classes 212
Handling file and image uploads 213
Time for action – Handle uploaded image 213
Using custom fields 223
Adding custom fields 223
Retrieving custom fields 224
Quick post a link 224
Time for action – Add link template 224
Tinkering with WordPress backend menus 228
Time for action - Remove 'Link' from the Write page 228
Programming the Manage panel 230
Time for action – Add post type column in the Manage panel 231
Modifying an existing column 233
Manage screen search filter 234
Time for action – Add a search filter box 235
Handling error messages 237
Time for action – Adding support for errors 237
User roles and capabilities 239
Time for action – Add user capability checks 240
Summary 241
Chapter 8: Development Goodies 243
Creating Localization files 243
Time for action - Create a POT file 244
Updating POT file 247
Time for action – Perform translation 248
Updating translation 249
Documentation and support 250
Plugin readme file 250
Time for action – Create a sample plugin readme.txt file 251
Sections of readme.txt 253
General information 254
Special codes 254
Screenshots 254
Installation instructions 255
Table of Contents
[ vi ]
Plugin homepage 255
Providing support 257
Code management and plugin repository 258
Requesting repository access 258
Using SVN 259
Time for action - Manage a local repository using SVN 260
Tagging a new version 261
Using WordPress development SVN 262
Local copy of plugin repository 262
Promotion 263
Plugin promotion checklist 264
General plugin development guidelines 264
Security 265
Performance 265
Re-using resources 265
Keeping API up-to-date 266
WordPress MU development 266
WordPress and GPL 268
Online resources 269
WordPress documentation (WordPress Codex) 269
WordPress development news 269
WordPress blog 269
WordPress development updates 269
WordPress Trac 269
WordPress dev IRC channel 269
Debugging and testing 270
Unit testing 270
Automated tests 270
Mailing Lists 270
WP hackers 270
WP professionals 270
Other mailing lists 270
Podcasts 271
WordCast 271
WordPress Weekly 271
Author's (Vladimir Prelovac's) web site 271
Summary 271
Index 273
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.
Preface
[  ]
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.
Preface
[  ]
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:
?php the_content('p class=serifRead the rest of this entry
raquo;/p’); ?
?php if (function_exists(WPDiggThis_Link)) echo WPDiggThis_Link(); ?
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.
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Preface
[  ]
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 feedback@packtpub.com, 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
suggest@packtpub.com.
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.
Preface
[  ]
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 copyright@packtpub.com 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 questions@packtpub.com if you are having a problem with some
aspect of the book, and we will do our best to address it.
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
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 guys behind WordPress are on to something big. It has indeed proven to be so, and
as the days passed by, I have enjoyed every aspect of WordPress—publishing, social,
and development.
And I am thrilled to share these nits and bits of WordPress development information with
you, showing you the power and flexibility that allowed WordPress to become so popular.
How will you benefit?
Thanks to its open source architecture, ease of use, and customization possibilities,
WordPress has succeeded in differentiating itself from other�����������������������������
����������������������������
weblog publishing platforms
and even other open source solutions.
WordPress features
The main WordPress features�������������������������������
������������������������������
of interest to developers are:
Its a huge community of users and developers
The millions of WordPress������
�����
blogs
Major sites using it, including a number of US government agencies



1
Preparing for WordPress Development
[  ]
Security��������������������������������
�������������������������������
issues treated almost instantly
Unmatched������������������������������������������������
�����������������������������������������������
flexibility with thousands of available plugins
High level of customizability with thousands��������������������
of ����������������
available themes
Search engine friendly functionalities
Ease of use,�������������������������
������������������������
maintenance,������������
�����������
and upgrade
A great way to meet new people!
With such a list, it is no wo����������������������������������������������������
nder that—every day—more and more private users and
companies are turning to WordPress for their publishing needs. This of course presents
a fertile ground for WordPress developers to show off their skills.
More sites means more opportunities
The opportunity for a WordPress developer in these circumstances becomes obvious.
With such a huge number of sites running it, the market is hungry for WordPress experts,
and not just development experts. If you are proficient in the installation and setup of
WordPress, you may easily have your hands full of work.
Big players use it
The fact that a number of major sites use WordPress means that there is also an opportunity
for high profile work.
This also means that you can be fairly certain about the future of WordPress. Your
investment in time and efforts, first in reading this book, and then in enhancing your
development skills, is likely to pay off with WordPress.
Urgent response to security issues
With online security becoming a bigger issue each day, it is a relief to see the WordPress
development team reacting promptly to newly discovered security issues.
This makes everyone even more comfortable and confident in using WordPress.
Flexibility
With WordPress, the plugin author is allowed total control over every aspect of the site.
You are able to completely customize the way the site looks and behaves.
The opportunity is there for everyone—from beginners (developing useful plugins)
to professionals (creating total WordPress makeovers such as e-commerce, marketing,
or job portal sites—where you can hardly recognize that the site is running a
WordPress installation).






Chapter 1
[  ]
Search engines friendly
Search Engine Optimization (SEO) is an important aspect of today's Internet presence. Just
creating a site is not enough anymore, as there are now hundreds of millions of competing
websites out there.
Using������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������
a platform such as WordPress will be really valuable, especially in the long term.
WordPress has significant built-in SEO features and also most of the other aspects of modern�
SEO��������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������
technologies available through custom plugins (and you can always write one to match�
your needs!)
Becoming proficient in SEO concepts can help��������������������������
�������������������������
you a lot as a WordPress
developer, as the need for both WordPress and SEO skills�����������������
����������������
is growing fast.
Easy to use
WordPress is meant for ��������������������������������������������������������������������
beginners and used by professionals. This mix is rarely seen in any
other open source platforms.
After the five minute installation, most users immediately feel comfortable in the WordPress
administration panels. Writing a post and organizing categories is as simple as it should be.
The whole WordPress installation consists of putting the files on the server and setting the
assigned database, and it is very easy to back up or move it to another server.
WordPress and its plugins can be upgraded with a click of a button; all this makes the job of
maintaining a WordPress website (��������������������������������������������
or even several at the same time), a breeze.
Social aspect
If you are a WordPress developer, the chances are that you will have your own hosted
WordPress�����������������������������������������������������������������������������
����������������������������������������������������������������������������
blog. Having a personal blog creates a great opportunity to create many new
contacts—both business and friends.
When you release a WordPress plugin,������������������������������������������������
�����������������������������������������������
you will meet hundreds of people who are going
to use it on their own sites. You will also have people visit you for support, or just to say
Thank you!
Plugins as tool for promotion
With such a huge user base, a well written plugin will��������������������������������
�������������������������������
probably be downloaded���������
��������
tens of
thousands of times.
This will create awareness about you as a plugin author and your site as a probable source
for some cool stuff. Having in mind how difficult it is to get noticed on the Internet today, this
becomes a very important aspect of plugin development that you get for free.
Preparing for WordPress Development
[ 10 ]
Creating������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������
fresh, new, and usable plugins can help you go a long way. It has really helped me
a lot in my field of work�����������������������������������������������������������������
����������������������������������������������������������������
and has created a lot of opportunities–one certainly being, the
pleasure of writing this������
�����
book.
Dogfooding WordPress plugins
You may sometimes wish to create a plugin just for yourself, to fulfil a specific need that can
arise at a given moment. This is how I started writing plugins initially, as I needed certain
functionalities that were not available in WordPress at the time.
The term dogfooding describes a dog food company that is ready to eat its own dog food.
It means the company is confident about its own product and uses it for the purpose it was�
produced for.
In WordPress'���������������������������������������������������������������������������������
��������������������������������������������������������������������������������
terms, it�����������������������������������������������������������������������
����������������������������������������������������������������������
means that you should always strive to create a plugin that satisfies
your needs.����������������������������������������������������������������������������������
���������������������������������������������������������������������������������
On my personal site, I still use almost all of the plugins I created, and I only
update them over time, as and when WordPress is updated, or my needs change.
This has�������������������������������������������������������������������������������������
������������������������������������������������������������������������������������
a�����������������������������������������������������������������������������������
����������������������������������������������������������������������������������
positive side effect of ensuring that your plugins will probably be attractive to�
many other users as well. Assuming that you are critical about your own work, and your
confidence in using your own plugins sends out a clear message on how good they�����
����
are.
Challenges involved
Developing WordPress���������������������������������������������������������������������
��������������������������������������������������������������������
plugins is����������������������������������������������������������
���������������������������������������������������������
not always an easy job. It brings a number of challenges
that���������������������������
��������������������������
you will need to overcome.
Development
WordPress�����������������������������������������������������������������������������
����������������������������������������������������������������������������
uses PHP and����������������������������������������������������������������
���������������������������������������������������������������
provides an API with its own functions. The API has grown over
time, and now covers all possible methods of communication between WordPress and
the plugin.
This book������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������
will cover all the aspects of the API with practical examples, and the development
of six concrete plugins (chapters 2-7).��������������������������������������������������������
�������������������������������������������������������
Through������������������������������������������������
�����������������������������������������������
step-by-step guides to creating these plugins,�
you will discover�����������������������������������������������������������������������������
����������������������������������������������������������������������������
how to use API in typical situations, from displaying output on the site����
���
in
the beginning,��������������������������������������������
�������������������������������������������
to turning���������������������������������
��������������������������������
WordPress into a CMS at the end.
Each�������������������������������������������������������������������������������������
������������������������������������������������������������������������������������
new chapter and each����������������������������������������������������������������
���������������������������������������������������������������
new������������������������������������������������������������
�����������������������������������������������������������
plugin will introduce different features of WordPress, and
how to��������������������������������������������������������������������������������
�������������������������������������������������������������������������������
put them to good use, thereby allowing you to gradually advance your knowledge.
Chapter 1
[ 11 ]
Security
As much as���������������������������������������������������������������������������
��������������������������������������������������������������������������
WordPress team������������������������������������������������������������
�����������������������������������������������������������
takes care of����������������������������������������������
���������������������������������������������
the WordPress core,��������������������������
�������������������������
you need to take care of
security in�����������������������������������������������������������������������������������
����������������������������������������������������������������������������������
your������������������������������������������������������������������������������
�����������������������������������������������������������������������������
plugins.���������������������������������������������������������������������
��������������������������������������������������������������������
Always��������������������������������������������������������������
�������������������������������������������������������������
remember that������������������������������������������������
�����������������������������������������������
your plugin is given the ultimate authority on
the user's site. This is a great������������������������������������������������������������
�����������������������������������������������������������
feature����������������������������������������������������
���������������������������������������������������
that allowed���������������������������������������
��������������������������������������
WordPress to become popular; but with
that it also carries a great������������������������
deal of ���������������
responsibility.
This�����������������������������������������������������������������������������������
����������������������������������������������������������������������������������
book������������������������������������������������������������������������������
�����������������������������������������������������������������������������
will show the methods and functions best suited to the given situations, and
underline the security implications.�������������������������������������������������������
������������������������������������������������������
There are not too many issues to worry about, so make
sure you remember the implications and best practices and apply����������������������
���������������������
them to your plugins.
Work after development
Once the development��������������������������������������������������������������������
work is done and the plugin is finished, a lot of authors face the
question: What now? If you plan to release the plugin to the public, there are a few extra
steps you need to take care of.
This book��������������������������������������������������������������
�������������������������������������������������������������
will give ���������������������������������������������������
you practical tips in this area—refer to Chapter 8�
.
It������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������
will cover the process ������������������������������������������������������������
that takes you from the end of the development phase to the
first users coming back to you with feedback and questions. I have learned much from my
own plugin development experience, and I will also be referencing�����������������������
some of the resources
available online .
Localization
At the moment, WordPress is translated��������������������������������������������
in�����������������������������������������
to more than 50 languages worldwide. The
number of users������������������������������������������������������������������������
�����������������������������������������������������������������������
using WordPress in their native language is growing each day, and they
usually prefer�����������������������������������������������
����������������������������������������������
using plugins that support their own language.
Localization in WordPress is��������������������������������������������������������������
�������������������������������������������������������������
easy, and the best thing is that you will not have to do any
translation. There will always be users interested in translating your plugin to their own
language and sending you the file back. This is the way it works, and it is mutually������������
�����������
beneficial.
Documentation
Writing documentation is often boring work but I will show�������������������������������
������������������������������
you templates which will help
you to do it more efficiently and also point out the benefits of writing good���������������
��������������
documentation.
I will also�������������������������������������������������������
������������������������������������������������������
cover the necessary steps to manage your plugin using SVN (Subversion), and
submit it to the WordPress Plugin Repository—the ������������������������������������
central ����������������������������
repository of all WordPress
plugins which currently hosts thousands of plugins and has served millions of downloads.
Support
Good documentation goes a long way when it comes to support.
Preparing for WordPress Development
[ 12 ]
You can expect hundreds of user questions pouring in after you release a plugin. So, making
sure that you have a well written documentation will save you a lot of time in answering
those questions.
I will also give some practical tips on how to organize your plugin page.
Promotion
Writing a good plugin that nobody knows about is a fruitless effort.
I will give you tips on how to promote your plugin once it is published. If you have created
a really useful plugin, you can expect a snowball effect when users start to write about it on
their blogs and tell their friends about it.
Plugins developed in this book
This introduction chapter is ������������������������������������������������������������������
followed by seven chapters; six of which describe the creation of
WordPress plugins and a final chapter��������������������������������������
dealing with post-development issues:
Digg This
Live Blogroll
The Wall
Snazzy Archives
Insights
Post Types
Development Goodies
Various ����������������������������������������������������������������������������������
development topics and WordPress specific functions are introduced throughout the
development of these plugins,��������������������������������������������������
using concrete, step-by-step practical examples.
Digg This







Chapter 1
[ 13 ]
This is the first plugin we will be developing. This plugin will show a Digg button in your
blog posts.
The purpose of this�������������������������������������������������������������������������
������������������������������������������������������������������������
plugin will also be to introduce you to the basic concepts of WordPress
plugin development.
We will access some of the basic WordPress API functions,������������������������������������
�����������������������������������
and talk about filters and actions
which are the WordPress�����������������������������������������������������
����������������������������������������������������
mechanisms for controlling the workflow of the site.
Live Blogroll
The second plugin comes from the idea of making the default blogroll look a little bit
more exciting.
We will expand our knowledge of WordPress API, but also introduce two very important
allies in WordPress plugin development, namely jQuery and Ajax.
jQuery and Ajax technologies help our plugins become more engaging, and we will learn the
basic concepts of using them through a series of practical examples.
Preparing for WordPress Development
[ 14 ]
The Wall
This chapter is all about WP Wall; a plugin that creates a shoutbox on your blog's sidebar,
where users can leave comments and shouts.
The ��������������������������������������������������������������������������������������
chapter t�����������������������������������������������������������������������������
eaches important lessons, including how to create a widget and interact with
the �������������������������������������������������������������������������������������
WordPress database�������������������������������������������������������������������
. It also expands the usage of Ajax to include dynamic interaction
with the������
�����
user.
I will ���������������������������������������������������������������������������������
also try�������������������������������������������������������������������������
to engage you to think about WordPress plugin development in a slightly
different way.
Snazzy Archives
Chapter 1
[ 15 ]
If ���������������������������������������������������������������������������������������������
plugins can be classified by beauty, this would be the most beautiful plugin in the book. It
will�����������������������������������������������������������������������
display your blog archives in a way you probably have not seen before.
During the creation �������������������������������������������������������������������������
of the plugin, we will explore how to interact with posts, create plugin
options, and manage them through a settings page in the administration. We will then use all
that knowledge to produce����������������������������������������������������
a beautiful representation of your blog's archives.
Insights
Insights plugin will add to the productivity of the blog owner by offering quick access to
common information in the Write Post screen.
In this chapter, we will learn how to change the WordPress Write Post screen and interact
with the built-in TinyMCE editor. We will use Ajax to get information delivered directly into
our post�������������������
������������������
while we write it!
Post Types
Preparing for WordPress Development
[ 16 ]
The final plu��������������������������������������������������������������������
gin of the book will see us working more closely with the WordPress
backend, and explore ways to transform����������������������������
WordPress into a versatile Content
Management System (CMS).
We ���
will learn how to customize the administration menus and pages, use custom fields to
store additional information, explore user capabilities system, and use localization�
.
Development Goodies
After all the hard work in developing those plugins, comes a chapter dedicated to all the
post-development work (after-hour���������
��������
party!).
The purpose����������������������������������������������������������������������
of this chapter will be to explain localization, documentation, code
management, and plugin promotion. It will also give you some information regarding
WordPress MU development. Wordpress MU is a multi user version of WordPress���������
that����
���
is
becoming more popular each day.
Tools for the job
Before we get started, we need to have some tools set up, so let's go through a short
check list.
Whatever way you decide to set up your development environment, make sure you are
comfortable using it. Plugin������������������������������������������������������������������
�����������������������������������������������������������������
development can be a full-time job, so make sure you enjoy it as
much as���������
��������
you can!
WordPress
Obviously, we will need WordPress installed. It is advisable to have a separate version of
WordPress for development purposes����������������������������������������������������������
���������������������������������������������������������
(that is, do not use your blog as a testing ground; your
visitors will �����������������������
not l������������������
ike it very much).
To����
���
prepare your local version, you can always download the latest version of WordPress from�
http://wordpress.org/download/.
Then you need to decide if you are going to host it on the Internet or locally. I prefer to have
it on Internet as I can easily show it to other people if necessary, no matter where I am at
that moment. The advantage of local installation is that it works much faster. You can of
course combine������
both.
If you are�����������������������������������������������������������������������������
����������������������������������������������������������������������������
going to set it up on your local computer, and you are using Windows, using
packages such as ���������
EasyPHP��
(http://www.easyphp.org) will����������������������������
���������������������������
make your job much easier.
This is �������������������������������������������������������������������������������
a software���������������������������������������������������������������������
package that incorporates PHP and MySQL for Windows systems, and is
free to use.
Chapter 1
[ 17 ]
Installing WordPress������������������������������������������
�����������������������������������������
is a simple matter. I recommend����������
���������
going to http://codex.wordpress.
org/Installing_WordPress �������������������������������������������������
for the latest guide to the installation process.
If you would like to set up the latest development version, I suggest you read the section
Using SVN in Chapter 8.
Text editor
Obviously, you are going to need a text editor. Any editor will do, and you probably have a
preference��������
�������
by now.
You do not����������������������������������������������������������������������������
���������������������������������������������������������������������������
need your text editor to do anything fancy. Indentation support and syntax
highlighting for PHP, HTML and����������������������������������������������������������������
���������������������������������������������������������������
JavaScript is almost all you need from an editor at this point.
I have been using UltraEdit for years, and it has been always my weapon of choice for a
quick, small, and powerful editor. There also are other text editors that are available for free,
such as, ���������������������������������������������
Netbeans IDE for PHP, Zend Studio, and so on.
FTP client
The second thing you will need to have is an FTP client. Uploading plugins can be a boring
job if you do it from the FTP command line; so visual FTP client is advisable.
For this matter, I've been using Total Commander as a proven tool. Again, you might have
your own preference.
Web browser
Finally, since we are developing web based software, we will need a web browser. You will be
spending a lot of time in the browser window; so make sure you are comfortable with it.
I do not �������������������������������������������������������������������������������������
want to instigate browser wars at this moment, but there is one browser that is very
flexible and has tons����������������������������������������������������������������������
of add-ons,����������������������������������������������������������
���������������������������������������������������������
much like WordPress in that respect, and that is Firefox.
There are some pretty cool �����������������������������������������������������������������
add-ons for Firefox that can really increase productivity to the
level of rapid web development. This step is optional if you do not use Firefox, but I would
nevertheless recommend giving����������
it a try.
Firebug
The most important Firefox add-on we want to install is called Firebug (you can download it
from http://getfirebug.com).
Preparing for WordPress Development
[ 18 ]
Firebug allows you to preview, edit and debug CSS, HTML, JavaScript and Ajax requests
in real time. This is really a great time saver. For example, when it comes to debugging,
JavaScript or misaligned CSS can be really troublesome, without the use of features
provided by Firebug.
In the next picture, you can see an example of Firebug in action, debugging JavaScript with a
breakpoint in the execution of the script.
Chapter 1
[ 19 ]
Ubiquity
This is an add-on produced by Mozilla Labs and it can do a lot of fancy stuff. But for
our�������������������������������������������������������������������������������
������������������������������������������������������������������������������
purposes, we are going to use it for two simple things—fast search of PHP and
WordPress���������������
��������������
documentation.
You will need to install Ubiquity from https://wiki.mozilla.org/Labs/Ubiquity and
also install these two plugins:
PHP Search: http://npattison.com/ubiquity/ubiq_php.html
WP Codex Search: http://www.prelovac.com/vladimir/ubiquity-
plugins/wp-codex-search
The way these two ����������������������������������������������
Ubiquity commands�����������������������������
work is that when you press Ctrl and Space in
the browser (this opens U������������������������������
biquit������������������������
y window) and then type php search_phrase or wp
search_phrase, it takes you immediately to the PHP or WordPress documentation
for the given phrase.
The amount of time this can save is huge, especially if you need to take a peek at the
documentation every minute or so like I do (I can't keep everything in my head!).
1.
2.
Preparing for WordPress Development
[ 20 ]
Screengrab
You can grab Screengrab from http://www.screengrab.org, ���������������������������
and this plugin allows you
to take screenshots from����������������������������������������������������������������������
���������������������������������������������������������������������
your�����������������������������������������������������������������
����������������������������������������������������������������
browser window easily. It can capture an entire page, a visible
portion, or a user selection on the page.
Once you get used it, you will use it extensively for creating images for your plugin
documentation. I have used it for almost all the images in this book.
Chapter 1
[ 21 ]
IE tab
This Firefox add-on allows you to quickly change the rendering engine between Firefox and
the installed���������������������������������������������������������������������������������
��������������������������������������������������������������������������������
version of the Internet ��������������������������������������������������������
Explorer. It allows you to quickly check if your plugin
behaves well in this ��������
browser.
You can������������
�����������
get it from ������������������������
http://ietab.mozdev.org/.
Quick reference
WordPress: http://www.wordpress.org/download
Installing WordPress: http://codex.wordpress.org/Installing_
WordPress
EasyPHP: http://www.easyphp.org
UltraEdit: http://www.ultraedit.com
Total Commander: http://www.ghisler.com
FireFox: http://getfirefox.com
FireBug: http://getfirebug.com
Ubiquity: https://wiki.mozilla.org/Labs/Ubiquity
PHP Search for Ubiquity: http://npattison.com/ubiquity/ubiq_
php.html
WP Codex Search for Ubiquity: http://www.prelovac.com/vladimir/
ubiquity-plugins/wp-codex-search
ScreenGrab: http://www.screengrab.org
IETab: http://ietab.mozdev.org/
Final notes
Before we start with development, let's have a quick reminder on how to install and manage
WordPress plugins. Also I'll mention a handy tip for quickly accessing code examples.
Preparing for WordPress Development
[ 22 ]
Installing and managing plugins
When you want to install a plugin, you need to follow these simple steps:
Upload the plugin folder (for example wp-wall) to your server's
wp-content/plugins/ folder.
1.
Chapter 1
[ 23 ]
2. Go to your WordPress administration section, and select Plugins from the menu. This
will give you a list of all the installed plugins. Scroll down the list until you find yours,
and click Activate.
If you intend to manually update the plugin files on a live site, it is advisable to deactivate the
plugin first using the Plugins menu.
Strictly speaking, on a development blog where you are the only user, this can be skipped to
save time�
.
If something goes ����������������������������������������������������
wrong with the plugin, and you are unable to access
your WordPress site anymore, deleting the plugin folder from the server
will deactivate the plugin automatically, and will instantly���������������
get your site
working again.
If you need more information regarding plugin management, you can refer to the latest
WordPress manual found at http://codex.wordpress.org/Managing_Plugins.
Searching documentation
During the plugin development, you will more or less need to refer to documentation.
Luckily, you ������������������������������������������������������������������������������
will have this book on your hand either in paper or in a PDF form, so you can
take a quick look. Then������������������������������������������������������������
, you also have the WordPress online documentation found at
http://codex.wordpress.org/Main_Page.
Due to the rapid speed at which WordPress has been developing, not all the functions have
been documented.
So, I keep a copy of the latest version of WordPress locally. This way, I am able to find the
reference to the function in the WordPress core quickly, and figure out how it is used.
Preparing for WordPress Development
[ 24 ]
I also tend to keep a local copy of the entire plugin repository on my computer (you can find
more details on how to do that in Chapter 8) so that I can search through the entire plugin
repository and find instances of this function used by other plugin authors (and you can
always find new����������������������������
and creative uses as well).
Chapter 1
[ 25 ]
Using other plugins for this �������������������������������������������������������������������
purpose can really save a lot of time, and it is often the easiest
way to learn how to perform certain functionalities�
.
Summary
We learned about the advantages of WordPress development, and what WordPress has to
offer to plugin authors. We have also seen that there are certain challenges along the way,
which we will address in this book.
The six plugins that we will create in the following chapters will show you exactly how to
create a WordPress plugin from scratch and have it perform the concrete functionality you
need, whether it's on the front page or in the administration backend.
Having armed ourselves with useful development tools, we are ready to start developing
some cool WordPress plugins!
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
2
Social Bookmarking
I hope the first chapter got you warmed up and prepared for WordPress plugin development,
and that you are as eager to start as I am.
In this chapter, we will create our first functional WordPress plugin and learn how to interact
with the WordPress API (this is the WordPress interface to PHP) on the way. The knowledge
you will gain in this chapter alone will allow you to write a lot of similar plugins.
Let's get moving! In this chapter, you will learn:
Creating a new plugin and having it displayed in the plugins admin panel
Checking the WordPress version and control activation of the plugin
Accessing API features—for example the title and permalink URL of each post
Using WordPress hooks to execute your plugin code when it's needed
Using conditional tags to control the flow of your plugins
You will learn these by:
Creating a 'social bookmarking' type of plugin that adds a Digg button to each post
on your blog
As you probably know, Digg is a very popular service for promoting interesting content on
the Internet. The purpose of a Digg button on your blog is to make it easier for Digg users to
vote for your article and also to bring in more visitors to your blog.






Social Bookmarking
[ 28 ]
The plugin we'll create in this chapter will automatically insert the necessary code to each of
your posts. So let's get started with WordPress plugin development!
Plugging in your first plugin
Usually, the first step in plugin creation is coming up with a plugin name. We usually want to
use a name that is associated with what the plugin does, so we will call this plugin, WP Digg
This. WP is a common prefix used to name WordPress plugins.
To introduce the plugin to WordPress, we need to create a standard plugin header. This
will always be the first piece of code in the plugin file and it is used to identify the plugin
to WordPress.
Time for action – Create your first plugin
In this example, we're going to write the code to register the plugin with WordPress ,
describe what the plugin does for the user, check whether it works on the currently installed
version of WordPress, and to activate it.
Create a file called wp-digg-this.php in your favourite text editor. It is common
practice to use the plugin name as the name for the plugin file, with dashes '-'
instead of spaces.
Next, add a plugin information header. The format of the header is always the same
and you only need to change the relevant information for every plugin:
?php
/*
Plugin Name: WP Digg This
Version: 0.1
Description: Automatically adds Digg This button to your posts.
Author: Vladimir Prelovac
Author URI: http://www.prelovac.com/vladimir
Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/
wp-digg-this
*/
?
3. Now add the code to check the WordPress version:
/* Version check */
global $wp_version;
$exit_msg='WP Digg This requires WordPress 2.5 or newer.
a href=http://codex.wordpress.org/Upgrading_WordPressPlease
update!/a';
1.
2.
Chapter 2
[ 29 ]
if (version_compare($wp_version,2.5,))
{
exit ($exit_msg);
}
?
4. Upload your plugin file to the wp-content/plugins folder on your server using
your FTP client.
5. Go to your WordPress Plugins admin ���������������������������������������������
panel. You should now see your plugin listed
among other plugins:
6. This means we have just completed the necessary steps to display our plugin in
WordPress. Our plugin can be even activated now—although it does not do
anything useful (yet).
Social Bookmarking
[ 30 ]
What just happened?
We created a working plugin template by using a plugin information header and the
version check code. The plugin header allows the plugin to be identified and displayed
properly in the plugins admin panel. The version check code will warn users of our plugin
who have older WordPress versions to upgrade their WordPress installation and prevent
compatibility problems.
The plugin information header
To identify the plugin to WordPress, we need to include a plugin information header with
each plugin.
The header is written as a PHP comment and contains several fields with
important information.
This code alone is enough for the plugin to be registered, displayed in the admin panel and
readied for activation.
If your future plugin has more than one PHP file, the plugin information
should be placed only in your main file, the one which will include() or
require() the other plugin PHP files.
Checking WordPress versions
To ensure that our plugin is not activated on incompatible WordPress versions, we will
perform a simple WordPress version check at the very beginning of our code.
WordPress provides the global variable $wp_version that provides the current WordPress
version in standard format. We can then use PHP function version_compare() to
compare this and our required version for the plugin, using the following code:
if (version_compare($wp_version,2.6,))
{
// do something if WordPress version is lower then 2.6
}
If we want to stop the execution of the plugin upon activation, we can use the exit()
function with the error message we want to show.
In our case, we want to show the required version information and display the link to the
WordPress upgrade site.
$exit_msg='WP Digg This requires WordPress 2.6 or newer. a
href=http://codex.wordpress.org/Upgrading_WordPressPlease
update!/a';
Chapter 2
[ 31 ]
if (version_compare($wp_version,2.6,))
{
exit ($exit_msg);
}
While being simple, this piece of code is also very effective. With the constant development
of WordPress, and newer versions evolving relatively often, you can use version checking to
prevent potential incompatibility problems.
The version number of your current WordPress installation can be found in the footer text
of the admin menu. To begin with, you can use that version in your plugin version check
(for example 2.6).
Later, when you learn about WordPress versions and their differences, you'll be able to
lower the version requirement to the minimal your plugin will be compatible with. This will
allow your plugin to be used on more blogs, as not all blogs always use the latest version of
WordPress.
Checking the plugin
You can go ahead and activate the plugin. The plugin will be activated but will do nothing at
this moment.
Time for Action – Testing the version check
Let's just make sure that the version check works, by requiring a fictional version of
WordPress that does not exist yet:
Deactivate the plugin and change the version check code to a higher version. For
example, replace 2.6 with 5.0.
if (version_compare($wp_version,5.0,))
2. Re-upload the plugin and try to activate it again. You will see a WordPress error and
a message from the plugin:
1.
Social Bookmarking
[ 32 ]
What just happened?
The version check fails and the plugin exits with our predefined error message. The same
thing will happen to a user trying to use your plugin with outdated WordPress installation,
requiring them to update to a newer version.
Have a go Hero
We created a basic plugin that you can now customize.
Change the plugin description to include HTML formatting (add bold or links to
the description).
Test your plugin to see what happens if you have two plugins with the same name
(upload a copy of the file under a different name).
Displaying a Digg button
Now it's time to expand our plugin with concrete functionality and add a Digg link to every
post on our blog.
In order to create a link we will need to extract post's permalink URL, title, and description.
Luckily, WordPress provides us with a variety of ways to do this.
Time for Action – Implement a Digg link
Let's create a function to display a Digg submit link using information from the post.
Then we will implement this function into our theme, to show the link just after the
post content.
1. Add a function to our plugin to display a Digg link:
/* Show a Digg This link */
function WPDiggThis_Link()
{
global $post;
// get the URL to the post
$link=urlencode(get_permalink($post-ID));
// get the post title
$title=urlencode($post-post_title);
// get first 350 characters of post and strip it off
// HTML tags


Chapter 2
[ 33 ]
$text=urlencode(substr(strip_tags($post-post_content),
0, 350));
// create a Digg link and return it
return 'a href=http://digg.com/submit?url='.$link.'amp;
title='.$title.'amp;bodytext='.$text.'Digg This/a';
}
2. Open your theme's single.php file and add a call to our function just below the
line with the_content(). If you are not sure how to do this, see the forthcoming
section on Editing the theme files.
?php if (function_exists(WPDiggThis_Link)) echo WPDiggThis_
Link(); ?
3. With the default WordPress theme, this change will look something like this (you can
also refer to the following image):
Social Bookmarking
[ 34 ]
4. After you save the theme file, your blog posts will now automatically have the Digg
This link shown after the content:
5. Clicking the link will take the user directly to the Digg site, with all the required
information already filled in:
Well done! You have created your first working WordPress plugin!
What just happened?
When WordPress loads a post, the single.php template file from the currently active
WordPress theme is ran. We added a line to this file that calls our plugin function
WPDiggThis_Link() just after the content of the post is displayed:
?php the_content('p class=serifRead the rest of this entry
raquo;/p'); ?
?php if (function_exists(WPDiggThis_Link)) echo WPDiggThis_
Link(); ?
We use function_exists()to check our function because it exists only if our plugin is
installed and activated. PHP will generate an error if we try to run a nonexistent function. But
if we deactivate the plugin later, we don't want to cause errors with our theme. So, we make
sure that the function exists before we attempt to run it.
Chapter 2
[ 35 ]
Assuming that the plugin is present and activated, the WPDiggThis_Link() function from
our plugin is ran. The first part of the following function gets information about our post and
assigns it to variables:
/* Show a Digg This link */
function WPDiggThis_Link()
{
global $post;
// get the URL to the post
$link=urlencode(get_permalink($post-ID));
// get the post title
$title=urlencode($post-post_title);
// get first 350 characters of post and strip it off HTML tags
$text=urlencode(substr(strip_tags($post-post_content),
0, 350));
We use the urlencode() PHP function for all the parameters that we will pass to the final
link. This will ensure that all the values are formatted properly.
The second part uses this information to construct a Digg submit link:
// create a Digg link and return it
return 'a href=http://digg.com/submit?url='.$link.'amp;
title='.$amp;title.'bodytext='.$text.'Digg This/a';
}
It returns this HTML text so that it gets added to the WordPress output at the point where
the function is called – just after the post is displayed. Therefore, the link appears right after
each post—which is convenient for the user who has just finished reading the post.
Using the Digg API
Usually, when using the functionalities of third-party sites, as we are doing in our example
with Digg, we would search for the API documentation first. Almost all the major sites have
extensive documentation available to help developers use their services in an effective way.
Digg is no exception, and if you search the Internet for the digg button api you will find a
page at http://digg.com/tools/integrate that will have all the details we need in
order to implement our Digg functionality.
Social Bookmarking
[ 36 ]
Digg allows us to use several different ways of using their service.
For the start, we will display just a Digg link. Later, we will expand it and also display a
normal button.
Here is what the Digg documentation says about formatting a submit link.
Submit URL:
http://digg.com/submit?url=example.comtitle=TITLEbodytext=DESCRIPTI
ONmedia=MEDIAtopic=TOPIC
Submit URL Details:
url=example.com
Maximum length is 255 characters
Story URL should be unique and devoid of session or user-specific data
Please URL-encode all strings as appropriate. For example:
https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttp%2Fyourwebsite%2Fyourstoryurl%2Fstorypagedetails.html
title=TITLE
Maximum length is 75 characters
Please also URL-encode the story title
bodytext=DESCRIPTION
Maximum length is 350 characters
Please also URL-encode the body text



Chapter 2
[ 37 ]
Using this information, we are able to create a valid link for the Digg service from the
information available in our post.
Acquiring post information
WordPress provides a number of ways to get information about the current post.
One of them involves using the global variable $post, which stores all the relevant
information for the current post. We have used it in our example to extract the post title and
content, but it can also be used to get other information such as post category, status and
so on.
WordPress also offers an array of functions we could have used to access post information
such as get_the_title() and get_the_content().
The main difference between using these functions and accessing post data directly
using $post variable is in the end information we get. The $post variable contains raw
information about the post, just as the user wrote it. The functions mentioned above take
the same raw information as a starting point, but could have the final output modified by
external factors such as other active plugins.
You can browse through the wp-includes/post-template.php file of
your WordPress installation to get a better understanding of the differences
between using the $post variable and the WordPress provided functions.
Post permalink URL
In order to obtain post URL we used the get_permalink() WordPress function. This
function accepts the post ID as a parameter, and as a result, returns post's actual URL on the
blog. It will always return a valid URL to your post no matter what permalink structure your
blog is using.
Editing the theme files
In our example, we had to edit our theme in order to place the Digg link under the post
content. WordPress allows for easy theme editing through the built-in Theme Editor panel.
After selecting the theme you want to edit, you will be presented with a number of
options. Every theme consists of various PHP template files, each covering different
blog functionalities.
Exploring the Variety of Random
Documents with Different Content
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
The Project Gutenberg eBook of Box and Cox:
A Romance of Real Life in One Act.
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Title: Box and Cox: A Romance of Real Life in One Act.
Author: John Maddison Morton
Release date: April 13, 2013 [eBook #42523]
Most recently updated: October 23, 2024
Language: English
Credits: Produced by Paul Haxo from page images generously
made
available by the Internet Archive and the Library of
Congress.
*** START OF THE PROJECT GUTENBERG EBOOK BOX AND COX: A
ROMANCE OF REAL LIFE IN ONE ACT. ***
Wordpress Plugin Development Beginners Guide Vladimir Prelovac
THE MINOR DRAMA.
No. XXI.
BOX AND COX.
A Romance of Real Life
IN ONE ACT.
BY JOHN MADDISON MORTON, ESQ.
WITH THE STAGE BUSINESS, CAST OF CHARACTERS, COSTUMES, RELATIVE
POSITIONS, c.
NEW YORK:
DOUGLAS, NO. 11 SPRUCE ST
AND FOR SALE BY ALL BOOKSELLERS.
1848.
CAST OF CHARACTERS.
Theatre,
London, 1847.
Olympic,
1848.
Palmo’s,
1848.
John Box, a Journeyman Printer, Mr. Buckstone. Mr. Holland. Mr. Povey.
James Cox, a Journeyman Hatter, “ Harley. “ Conover. “ Chapman.
Mrs. Bouncer, Mrs. M’Namara. Mrs. Henry. Mrs. Vernon.
COSTUMES.
BOX.—Small swallow-tailed black coat, short buff waistcoat, light
drab trowsers short, turned up at bottom, black stockings, white
canvass boots with black tips, cotton neckcloth, shabby black hat.
COX.—Brown Newmarket coat, long white waistcoat, dark plaid
trowsers, boots, white hat, black stock.
MRS. BOUNCER.—Coloured cotton gown, apron, cap, c.
First produced at the Royal Lyceum Theatre, November 1st, 1847
Time in Representation—35 Minutes.
EXITS AND ENTRANCES.
R. means Right; L. Left; R. D. Right Door; L. D. Left Door;
S. E. Second Entrance; U. E. Upper Entrance; M. D. Middle Door.
RELATIVE POSITIONS.
R., means Right; L., Left; C., Centre; R. C., Right of Centre;
L. C., Left of Centre.
BOX AND COX.
ACT I.
Scene I—A Room, decently furnished. At C., a bed, with curtains
closed, at L. C., a door, at L. 3d E., a door, at L. S. E., a chest of
drawers, at back, R., a window, at R. 3d E., a door, at R. S. E., a
fireplace, with mantel-piece, table and chairs, a few common
ornaments on chimney-piece. Cox, dressed, with the exception of
his coat, is looking at himself in a small looking-glass, which is in
his hand.
Cox. I’ve half a mind to register an oath that I’ll never have my
hair cut again! [His hair is very short.] I look as if I had just been
cropped for the militia! And I was particularly emphatic in my
instructions to the hair-dresser, only to cut the ends off. He must
have thought I meant the other ends! Never mind—I shan’t meet
anybody to care about so early. Eight o’clock, I declare! I haven’t a
moment to lose. Fate has placed me with the most punctual,
particular, and peremptory of hatters, and I must fulfil my destiny.
[Knock at L. D.] Open locks, whoever knocks!
Enter Mrs. Bouncer, L.
Mrs. B. Good-morning, Mr. Cox. I hope you slept comfortably, Mr.
Cox?
Cox. I can’t say I did, Mrs. B. I should feel obliged to you, if you
could accommodate me with a more protuberant bolster, Mrs. B. The
one I’ve got now seems to me to have about a handful and a half of
feathers at each end, and nothing whatever in the middle.
Mrs. B. Anything to accommodate you, Mr. Cox.
Cox. Thank you. Then, perhaps, you’ll be good enough to hold
this glass, while I finish my toilet.
Mrs. B. Certainly. [Holding glass before Cox, who ties his cravat.]
Why, I do declare, you’ve had your hair cut.
Cox. Cut? It strikes me I’ve had it mowed! It’s very kind of you to
mention it, but I’m sufficiently conscious of the absurdity of my
personal appearance already. [Puts on his coat.] Now for my hat.
[Puts on his hat, which comes over his eyes.] That’s the effect of
having one’s hair cut. This hat fitted me quite tight before. Luckily
I’ve got two or three more. [Goes in at L., and returns, with three
hats of different shapes, and puts them on, one after the other—all
of which are too big for him.] This is pleasant! Never mind. This one
appears to me to wabble about rather less than the others—[Puts on
hat,]—and now I’m off! By the bye, Mrs. Bouncer, I wish to call your
attention to a fact that has been evident to me for some time past—
and that is, that my coals go remarkably fast—
Mrs. B. Lor, Mr. Cox!
Cox. It is not the case only with the coals, Mrs. Bouncer, but I’ve
lately observed a gradual and steady increase of evaporation among
my candles, wood, sugar, and lucifer matches.
Mrs. B. Lor, Mr. Cox! you surely don’t suspect me?
Cox. I don’t say I do, Mrs. B.; only I wish you distinctly to
understand, that I don’t believe it’s the cat.
Mrs. B. Is there anything else you’ve got to grumble about, sir?
Cox. Grumble! Mrs. Bouncer, do you possess such a thing as a
dictionary?
Mrs. B. No, sir.
Cox. Then I’ll lend you one—and if you turn to the letter G, you’ll
find “Grumble, verb neuter—to complain without a cause.” Now
that’s not my case, Mrs. B., and now that we are upon the subject, I
wish to know how it is that I frequently find my apartment full of
smoke?
Mrs. B. Why—I suppose the chimney—
Cox. The chimney doesn’t smoke tobacco. I’m speaking of
tobacco smoke, Mrs. B. I hope, Mrs. Bouncer, you’re not guilty of
cheroots or Cubas?
Mrs. B. Not I, indeed, Mr. Cox.
Cox. Nor partial to a pipe?
Mrs. B. No, sir.
Cox. Then, how is it that—
Mrs. B. Why—I suppose—yes—that must be it—
Cox. At present I am entirely of your opinion—because I haven’t
the most distant particle of an idea what you mean.
Mrs. B. Why the gentleman who has got the attics, is hardly ever
without a pipe in his mouth—and there he sits, with his feet upon
the mantel-piece—
Cox. The mantel piece! That strikes me as being a considerable
stretch, either of your imagination, Mrs. B., or the gentleman’s legs.
I presume you mean the fender or the hob.
Mrs. B. Sometimes one, sometimes t’other. Well, there he sits for
hours, and puffs away into the fire-place.
Cox. Ah, then you mean to say that this gentleman’s smoke,
instead of emulating the example of all other sorts of smoke, and
going up the chimney, thinks proper to affect a singularity by taking
the contrary direction?
Mrs. B. Why—
Cox. Then, I suppose, the gentleman you are speaking of, is the
same individual that I invariably meet coming up stairs when I’m
going down, and going down stairs when I’m coming up!
Mrs. B. Why—yes—I—
Cox. From the appearance of his outward man, I should
unhesitatingly set him down as a gentleman connected with the
printing interest.
Mrs. B. Yes, sir—and a very respectable young gentleman he is.
Cox. Well, good-morning, Mrs. Bouncer!
Mrs. B. You’ll be back at your usual time, I suppose, sir?
Cox. Yes—nine o’clock. You needn’t light my fire in future, Mrs. B.
—I’ll do it myself. Don’t forget the bolster! [Going, stops.] A
halfpenny worth of milk, Mrs. Bouncer—and be good enough to let it
stand—I wish the cream to accumulate.
[Exit at L. C.
Mrs. B. He’s gone at last! I declare I was all in a tremble for fear
Mr. Box would come in before Mr. Cox went out. Luckily, they’ve
never met yet—and what’s more, they’re not very likely to do so; for
Mr. Box is hard at work at a newspaper office all night, and doesn’t
come home till the morning, and Mr. Cox is busy making hats all day
long, and doesn’t come home till night; so that I’m getting double
rent for my room, and neither of my lodgers are any the wiser for it.
It was a capital idea of mine—that it was! But I haven’t an instant to
lose. First of all, let me put Mr. Cox’s things out of Mr. Box’s way.
[She takes the three hats, Cox’s dressing gown and slippers, opens
door at L. and puts them in, then shuts door and locks it.] Now,
then, to put the key where Mr. Cox always finds it. [Puts the key on
the ledge of the door, L.] I really must beg Mr. Box not to smoke so
much. I was so dreadfully puzzled to know what to say when Mr. Cox
spoke about it. Now, then, to make the bed—and don’t let me forget
that what’s the head of the bed for Mr. Cox, becomes the foot of the
bed for Mr. Box—people’s tastes do differ so. [Goes behind the
curtains of the bed, and seems to be making it—then appears with a
very thin bolster in her hand.] The idea of Mr. Cox presuming to
complain of such a bolster as this! [She disappears again, behind
curtains.]
Box. [Without.] Pooh—pooh! Why don’t you keep your own side
of the staircase, sir? [Enters at back, dressed as a Printer. Puts his
head out at door again, shouting.] It was as much your fault as
mine, sir! I say, sir—it was as much your fault as mine, sir!
Mrs. B. [Emerging from behind the curtains of bed.] Lor, Mr. Box!
what is the matter?
Box. Mind your own business, Bouncer!
Mrs. B. Dear, dear, Mr. Box! what a temper you are in, to be sure!
I declare you’re quite pale in the face!
Box. What colour would you have a man be, who has been
setting up long leaders for a daily paper all night?
Mrs. B. But, then, you’ve all the day to yourself.
Box. [Looking significantly at Mrs. Bouncer.] So it seems! Far be it
from me, Bouncer, to hurry your movements, but I think it right to
acquaint you with my immediate intention of divesting myself of my
garments, and going to bed.
Mrs. B. Oh, Mr. Box!
[Going.
Box. Stop! Can you inform me who the individual is that I
invariably encounter going down stairs when I’m coming up, and
coming up stairs when I’m going down?
Mrs. B. [Confused.] Oh—yes—the gentleman in the attic, sir.
Box. Oh! There’s nothing particularly remarkable about him,
except his hats. I meet him in all sorts of hats—white hats and black
hats—hats with broad brims, and hats with narrow brims—hats with
naps, and hats without naps—in short, I have come to the
conclusion, that he must be individually and professionally
associated with the hatting interest.
Mrs. B. Yes, sir. And, by the bye, Mr. Box, he begged me to
request of you, as a particular favor, that you would not smoke quite
so much.
Box. Did he? Then you may tell the gentle hatter, with my
compliments, that if he objects to the effluvia of tobacco, he had
better domesticate himself in some adjoining parish.
Mrs. B. Oh, Mr. Box! You surely wouldn’t deprive me of a lodger?
[Pathetically.
Box. It would come to precisely the same thing, Bouncer,
because if I detect the slightest attempt to put my pipe out, I at
once give you warning that I shall give you warning at once.
Mrs. B. Well, Mr. Box—do you want anything more of me?
Box. On the contrary—I’ve had quite enough of you!
Mrs. B. Well, if ever! What next, I wonder?
[Goes out at L. C., slamming door after her.
Box. It’s quite extraordinary, the trouble I always have to get rid
of that venerable female! She knows I’m up all night, and yet she
seems to set her face against my indulging in a horizontal position
by day. Now, let me see—shall I take my nap before I swallow my
breakfast, or shall I take my breakfast before I swallow my nap—I
mean, shall I swallow my nap before—no—never mind! I’ve got a
rasher of bacon somewhere—[Feeling in his pockets]—I’ve the most
distinct and vivid recollection of having purchased a rasher of bacon
—Oh, here it is—[Produces it, wrapped in paper, and places it on
table.]—and a penny roll. The next thing is to light the fire. Where
are my lucifers? [Looking on mantel-piece R., and taking box, opens
it.] Now, ’pon my life, this is too bad of Bouncer—this is, by several
degrees, too bad! I had a whole box full, three days ago, and now
there’s only one! I’m perfectly aware that she purloins my coals and
my candles, and my sugar—but I did think—oh, yes, I did think that
my lucifers would be sacred! [Takes candlestick off the mantel-piece,
R., in which there is a very small end of candle—looks at it.] Now I
should like to ask any unprejudiced person or persons their opinion
touching this candle. In the first place, a candle is an article that I
don’t require, because I’m only at home in the day time—and I
bought this candle on the first of May—Chimney-sweepers’ Day—
calculating that it would last me three months, and here’s one week
not half over, and the candle three parts gone! [Lights the fire—then
takes down a gridiron, which is hanging over the fireplace, R.] Mrs.
Bouncer has been using my gridiron! The last article of consumption
that I cooked upon it was a pork chop, and now it is powerfully
impregnated with the odour of red herrings! [Places gridiron on fire,
and then, with a fork, lays rasher of bacon on the gridiron.] How
sleepy I am, to be sure! I’d indulge myself with a nap, if there was
anybody here to superintend the turning of my bacon. [Yawning
again.] Perhaps it will turn itself. I must lie down—so, here goes.
[Lies on the bed, closing the curtains round him—after a short pause
—
Enter Cox, hurriedly, L. C.
Cox. Well, wonders will never cease! Conscious of being eleven
minutes and a half behind time, I was sneaking into the shop, in a
state of considerable excitement, when my venerable employer, with
a smile of extreme benevolence on his aged countenance, said to
me—“Cox, I shan’t want you to-day—you can have a holiday.”—
Thoughts of “Gravesend and back—fare, One Shilling,” instantly
suggested themselves, intermingled with visions of “Greenwich for
Fourpence!” Then came the Twopenny Omnibuses, and the
Halfpenny boats—in short, I’m quite bewildered! However, I must
have my breakfast first—that’ll give me time to reflect. I’ve bought a
mutton chop, so I shan’t want any dinner. [Puts chop on table.]
Good gracious! I’ve forgot the bread. Holloa! what’s this? A roll, I
declare! Come, that’s lucky! Now, then, to light the fire. Holloa—
[Seeing the lucifer-box on table,]—who presumes to touch my box of
lucifers? Why, it’s empty! I left one in it—I’ll take my oath I did.
Heydey! why, the fire is lighted! Where’s the gridiron? On the fire, I
declare! And what’s that on it? Bacon? Bacon it is! Well, now, ’pon
my life, there is a quiet coolness about Mrs. Bouncer’s proceedings
that’s almost amusing. She takes my last lucifer—my coals, and my
gridiron, to cook her breakfast by! No, no—I can’t stand this! Come
out of that! [Pokes fork into bacon, and puts it on a plate on the
table, then places his chop on the gridiron, which he puts on the
fire.] Now, then, for my breakfast things. [Taking key, hung up, L.,
opens door L. and goes out, slamming the door after him, with a
loud noise.
Box. [Suddenly showing his head from behind the curtains.]
Come in! if it’s you, Mrs. Bouncer—you needn’t be afraid. I wonder
how long I’ve been asleep? [Suddenly recollecting.] Goodness
gracious—my bacon! [Leaps off bed, and runs to the fireplace.]
Holloa! what’s this? A chop! Whose chop? Mrs. Bouncer’s, I’ll be
bound.—She thought to cook her breakfast while I was asleep—with
my coals, too—and my gridiron! Ha, ha! But where’s my bacon?
[Seeing it on table.] Here it is. Well, ’pon my life, Bouncer’s going it!
And shall I curb my indignation? Shall I falter in my vengeance? No!
[Digs the fork into the chop, opens window, and throws chop out—
shuts window again.] So much for Bouncer’s breakfast, and now for
my own! [With the fork he puts the bacon on the gridiron again.] I
may as well lay my breakfast things.—[Goes to mantel-piece at R.,
takes key out of one of the ornaments, opens door at R. and exit,
slamming door after him.
Cox. [Putting his head in quickly at L.] Come in—come in! [Opens
door, L. C. Enters with a small tray, on which are tea things, c.,
which he places on drawers, L. and suddenly recollects.] Oh,
goodness! my chop! [Running to fireplace.] Holloa—what’s that? The
bacon again! Oh, pooh! Zounds—confound it—dash it—damn it—I
can’t stand this! [Pokes fork into bacon, opens window, and flings it
out, shuts window again, returns to drawers for tea things, and
encounters Box coming from his cupboard with his tea things—they
walk down C. of stage together.] Who are you, sir?
Box. If you come to that—who are you?
Cox. What do you want here, sir?
Box. If you come to that—what do you want?
Cox. [Aside.] It’s the printer! [Puts tea-things on the drawers.
Box. [Aside.] It’s the hatter! [Puts tea-things on table.
Cox. Go to your attic, sir—
Box. My attic, sir? Your attic, sir!
Cox. Printer, I shall do you a frightful injury, if you don’t instantly
leave my apartment.
Box. Your apartment? You mean my apartment, you contemptible
hatter, you!
Cox. Your apartment? Ha! ha!—come, I like that! Look here, sir—
[Produces a paper out of his pocket.] Mrs. Bouncer’s receipt for the
last week’s rent, sir—
Box. [Produces a paper, and holds it close to Cox’s face.] Ditto,
sir!
Cox. [Suddenly shouting.] Thieves!
Box. Murder!
Both. Mrs. Bouncer! [Each runs to door, L. C., calling.
Mrs. Bouncer runs in at door, L. C.
Mrs. B. What is the matter? [Cox and Box seize Mrs. Bouncer by
the arm, and drag her forward.
Box. Instantly remove that hatter!
Cox. Immediately turn out that printer!
Mrs. B. Well—but, gentlemen—
Cox. Explain!
[Pulling her round to him.
Box. Explain! [Pulling her round to him.] Whose room is this?
Cox. Yes, woman—whose room is this?
Box. Doesn’t it belong to me?
Mrs. B. No!
Cox. There! You hear, sir—it belongs to me!
Mrs. B. No—it belongs to both of you!
[Sobbing.
Cox  Box. Both of us?
Mrs. B. Oh, dear gentlemen, don’t be angry—but, you see, this
gentleman—[Pointing to Box,]—only being at home in the daytime,
and that gentleman—[Pointing to Cox,]—at night, I thought I might
venture, until my little back second floor room was ready—
Cox  Box. [Eagerly.] When will your little back second floor
room be ready?
Mrs. B. Why, to-morrow—
Cox. I’ll take it!
Box. So will I!
Mrs. B. Excuse me—but if you both take it, you may just as well
stop where you are.
Cox  Box. True.
Cox. I spoke first, sir—
Box. With all my heart, sir. The little back second floor room is
yours, sir—now, go—
Cox. Go? Pooh—pooh!
Mrs. B. Now don’t quarrel, gentlemen. You see, there used to be
a partition here—
Cox  Box. Then put it up!
Mrs. B. Nay, I’ll see if I can’t get the other room ready this very
day. Now do keep your tempers.
[Exit, L.
Cox. What a disgusting position!
[Walking rapidly round stage.
Box. [Sitting down on chair, at one side of table, and following
Cox’s movements.] Will you allow me to observe, if you have not had
any exercise to-day, you’d better go out and take it.
Cox. I shall not do anything of the sort, sir.
[Seating himself at the table opposite Box.
Box. Very well, sir.
Cox. Very well, sir! However, don’t let me prevent you from going
out.
Box. Don’t flatter yourself, sir. [Cox is about to break a piece of
the roll off.] Holloa! that’s my roll, sir— [Snatches it away—puts a
pipe in his mouth, lights it with a piece of tinder—and puffs smoke
across to Cox.
Cox. Holloa! What are you about, sir?
Box. What am I about? I’m about to smoke.
Cox. Wheugh!
[Goes and opens window at Box’s back.
Box. Holloa! [Turns round.] Put down that window, sir!
Cox. Then put your pipe out, sir!
Box. There!
[Puts pipe on table.
Cox. There!
[Slams down window and re-seats himself.
Box. I shall retire to my pillow. [Goes up, takes off his jacket,
then goes towards bed, and sits down upon it, L. C.
Cox. [Jumps up, goes to bed, and sits down on R. of Box.] I beg
your pardon, sir—I cannot allow any one to rumple my bed. [Both
rising.]
Box. Your bed? Hark ye, sir—can you fight?
Cox. No, sir.
Box. No? Then come on—
[Sparring at Cox.
Cox. Sit down, sir—or I’ll instantly vociferate “Police!”
Box. [Seats himself—Cox does the same.] I say, sir——
Cox. Well, sir?
Box. Although we are doomed to occupy the same room for a
few hours longer, I don’t see any necessity for our cutting each
other’s throats, sir.
Cox. Not at all. It’s an operation that I should decidedly object to.
Box. And, after all, I’ve no violent animosity to you, sir.
Cox. Nor have I any rooted antipathy to you, sir.
Box. Besides, it was all Mrs. Bouncer’s fault, sir.
Cox. Entirely, sir. [Gradually approaching chairs.]
Box. Very well, sir!
Cox. Very well, sir! [Pause.]
Box. Take a bit of roll, sir?
Cox. Thank ye, sir. [Breaking a bit off. Pause.]
Box. Do you sing, sir?
Cox. I sometimes join in a chorus.
Box. Then give us a chorus. [Pause.] Have you seen the
Bosjemans, sir?
Cox. No, sir—my wife wouldn’t let me.
Box. Your wife!
Cox. That is—my intended wife.
Box. Well, that’s the same thing! I congratulate you! [Shaking
hands.]
Cox. [With a deep sigh.] Thank ye. [Seeing Box about to get up.]
You needn’t disturb yourself, sir. She won’t come here.
Box. Oh! I understand. You’ve got a snug little establishment of
your own here—on the sly—cunning dog—[Nudging Cox.]
Cox. [Drawing himself up.] No such thing, sir—I repeat, sir—no
such thing, sir, but my wife—I mean, my intended wife—happens to
be the proprietor of a considerable number of bathing-machines——
Box. [Suddenly.] Ha! Where? [Grasping Cox’s arm.]
Cox. At a favorite watering-place. How curious you are!
Box. Not at all. Well?
Cox. Consequently, in the bathing season—which luckily is rather
a long one—we see but little of each other; but as that is now over, I
am daily indulging in the expectation of being blessed with the sight
of my beloved. [Very seriously.] Are you married?
Box. Me? Why—not exactly!
Cox. Ah—a happy bachelor!
Box. Why—not—precisely!
Cox. Oh! a—widower?
Box. No—not absolutely!
Cox. You’ll excuse me, sir—but at present I don’t exactly
understand how you can help being one of the three.
Box. Not help it?
Cox. No, sir—not you, nor any other man alive!
Box. Ah, that may be—but I’m not alive!
Cox. [Pushing back his chair.] You’ll excuse me, sir—but I don’t
like joking upon such subjects.
Box. I’m perfectly serious, sir. I’ve been defunct for the last three
years!
Cox. [Shouting.] Will you be quiet, sir?
Box. If you won’t believe me, I’ll refer you to a very large,
numerous, and respectable circle of disconsolate friends.
Cox. My dear sir—my very dear sir—if there does exist any
ingenious contrivance whereby a man on the eve of committing
matrimony can leave this world, and yet stop in it, I shouldn’t be
sorry to know it.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com

More Related Content

Similar to Wordpress Plugin Development Beginners Guide Vladimir Prelovac (20)

PPT
Kick start your career with wordpress
OpenDev
 
PDF
eMusic: WordPress in the Enterprise
Scott Taylor
 
PDF
Don't Put Your WordPress Site at Risk
Rupok Chowdhury Protik
 
PPT
Kick start your career with WordPress
Jignasa Naik
 
PDF
Best practices-wordpress-enterprise
Taylor Lovett
 
PPT
Newspapers with WordPress
Christopher Ross
 
PDF
Wordpress intro
the-colab
 
PPTX
There's A Plugin For That!
wcfay
 
PPTX
Wordpress Meetup
Codal
 
ODP
Wordpress
Moorthy Haribabu
 
PDF
Wordpress as a framework
Aggelos Synadakis
 
KEY
"Wordpress for web designers. What, when, how, where" por @nuriarai
webcat
 
PDF
WordPress Curriculum guide.pdf
awesomeveronica
 
PPTX
PEPY Wordpress workshop-01
Wei Peng
 
PDF
The PHP Anthology
gywbd
 
PDF
Learn word press-from-scratch
Emma Page
 
PDF
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
Evan Mullins
 
PPTX
Part1 learn thelingo
Taneya Koonce
 
PDF
WordPress Intermediate Workshop
The Toolbox, Inc.
 
PPTX
Meetup which approach to choose?
Joe Mbaya
 
Kick start your career with wordpress
OpenDev
 
eMusic: WordPress in the Enterprise
Scott Taylor
 
Don't Put Your WordPress Site at Risk
Rupok Chowdhury Protik
 
Kick start your career with WordPress
Jignasa Naik
 
Best practices-wordpress-enterprise
Taylor Lovett
 
Newspapers with WordPress
Christopher Ross
 
Wordpress intro
the-colab
 
There's A Plugin For That!
wcfay
 
Wordpress Meetup
Codal
 
Wordpress
Moorthy Haribabu
 
Wordpress as a framework
Aggelos Synadakis
 
"Wordpress for web designers. What, when, how, where" por @nuriarai
webcat
 
WordPress Curriculum guide.pdf
awesomeveronica
 
PEPY Wordpress workshop-01
Wei Peng
 
The PHP Anthology
gywbd
 
Learn word press-from-scratch
Emma Page
 
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
Evan Mullins
 
Part1 learn thelingo
Taneya Koonce
 
WordPress Intermediate Workshop
The Toolbox, Inc.
 
Meetup which approach to choose?
Joe Mbaya
 

Recently uploaded (20)

PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
'' IMPORTANCE OF EXCLUSIVE BREAST FEEDING ''
SHAHEEN SHAIKH
 
PPTX
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
'' IMPORTANCE OF EXCLUSIVE BREAST FEEDING ''
SHAHEEN SHAIKH
 
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
community health nursing question paper 2.pdf
Prince kumar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Ad

Wordpress Plugin Development Beginners Guide Vladimir Prelovac

  • 1. Wordpress Plugin Development Beginners Guide Vladimir Prelovac download https://ebookbell.com/product/wordpress-plugin-development- beginners-guide-vladimir-prelovac-2310326 Explore and download more ebooks at ebookbell.com
  • 2. Here are some recommended products that we believe you will be interested in. You can click the link to download. Wordpress Plugin Development Cookbook Yannick Lefebvre https://ebookbell.com/product/wordpress-plugin-development-cookbook- yannick-lefebvre-2609128 Wordpress Plugin Development Cookbook Explore The Complete Set Of Tools To Craft Powerful Plugins That Extend The Worlds Most Popular Cms 3rd Edition Yannick Lefebvre https://ebookbell.com/product/wordpress-plugin-development-cookbook- explore-the-complete-set-of-tools-to-craft-powerful-plugins-that- extend-the-worlds-most-popular-cms-3rd-edition-yannick- lefebvre-42543230 Wordpress Plugin Development Cookbook Create Powerful Plugins To Extend The Worlds Most Popular Cms 2nd Edition Yannick Lefebvre https://ebookbell.com/product/wordpress-plugin-development-cookbook- create-powerful-plugins-to-extend-the-worlds-most-popular-cms-2nd- edition-yannick-lefebvre-11069084 Wordpress Plugin Development Cookbook Create Powerful Plugins To Extend The Worlds Most Popular Cms 2nd Edition Yannick Lefebvre https://ebookbell.com/product/wordpress-plugin-development-cookbook- create-powerful-plugins-to-extend-the-worlds-most-popular-cms-2nd- edition-yannick-lefebvre-11144406
  • 3. Wordpress Plugin Development Cookbook Yannick Lefebvre https://ebookbell.com/product/wordpress-plugin-development-cookbook- yannick-lefebvre-47871558 Professional Wordpress Plugin Development 1st Edition Williams https://ebookbell.com/product/professional-wordpress-plugin- development-1st-edition-williams-55460870 Professional Wordpress Plugin Development 2nd Edition Brad Williams https://ebookbell.com/product/professional-wordpress-plugin- development-2nd-edition-brad-williams-11069544 Professional Wordpress Plugin Development Brad Williams Justin Tadlock John James Jacoby https://ebookbell.com/product/professional-wordpress-plugin- development-brad-williams-justin-tadlock-john-james-jacoby-57410810 Professional Wordpress Plugin Development Brad Williams Justin Tadlock https://ebookbell.com/product/professional-wordpress-plugin- development-brad-williams-justin-tadlock-48507376
  • 6. WordPress Plugin Development Beginner's Guide Build powerful, interactive plugins for your blog and to share online Vladimir Prelovac BIRMINGHAM - MUMBAI
  • 7. 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])
  • 8. 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
  • 9. 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.
  • 10. 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
  • 12. Table of Contents Preface 1 Chapter 1: Preparing for WordPress Development 7 How will you benefit? 7 WordPress features 7 More sites means more opportunities 8 Big players use it 8 Urgent response to security issues 8 Flexibility 8 Search engines friendly 9 Easy to use 9 Social aspect 9 Plugins as tool for promotion 9 Dogfooding WordPress plugins 10 Challenges involved 10 Development 10 Security 11 Work after development 11 Localization 11 Documentation 11 Support 11 Promotion 12 Plugins developed in this book 12 Digg This 12 Live Blogroll 13 The Wall 14 Snazzy Archives 14 Insights 15 Post Types 15 Development Goodies 16 Tools for the job 16
  • 13. Table of Contents [ ii ] WordPress 16 Text editor 17 FTP client 17 Web browser 17 Firebug 17 Ubiquity 19 Screengrab 20 IE tab 21 Final notes 21 Installing and managing plugins 22 Searching documentation 23 Summary 25 Chapter 2: Social Bookmarking 27 Plugging in your first plugin 28 Time for action – Create your first plugin 28 The plugin information header 30 Checking WordPress versions 30 Checking the plugin 31 Time for Action – Testing the version check 31 Displaying a Digg button 32 Time for Action – Implement a Digg link 32 Using the Digg API 35 Acquiring post information 37 Post permalink URL 37 Editing the theme files 37 WordPress plugin hooks 39 Time for Action – Use a filter hook 40 WordPress hooks 41 Filter hooks 41 Action hooks 42 Practical filters and actions examples 44 Adding a Digg button using JavaScript code 46 Time for Action – Implement a Digg button 47 Conditional Tags 49 Styling the output 50 Time for Action – Use CSS to position the button 50 Summary 52 Chapter 3: Live Blogroll 55 Starting up with the blogroll 57 Time for action – Roll into the blogroll 58 RSS Feed Processing 62 jQuery JavaScript library 63 Implementing a mouse hover event in jQuery 63
  • 14. Table of Contents [ iii ] Time for action – Creating a hover event with jQuery 63 JavaScript and WordPress 67 Initializing jQuery 68 Expanding jQuery knowledge 68 Creating the pop-up with CSS 70 Time for action – Apply CSS to the popup 70 Demystifying Ajax 73 Simple example of using Ajax 73 Time for action – Use Ajax to dynamically retrieve feed posts 73 Using JavaScript with WordPress 79 Parsing parameters using wp_localize_script 79 Ajax and WordPress 80 Ajax in admin panel 80 jQuery.ajax method 81 Time for action – Use advanced Ajax call 81 Ajax script security using nonces 82 Time for action – Add a security nonce 82 Summary 84 Chapter 4: The Wall 85 The main concepts behind the Wall plugin 87 Creating a widget 89 Time for action – Create a 'Hello World!' widget 89 Register widgets with description 93 Widget controls 94 Time for action – Expanding the widget with controls 94 WordPress options 97 Display widget control 97 Handling widget input 98 Handling widget output 98 Create a WordPress page from the code 100 Time for action – Insert a page 100 Handling user input 104 Time for action – Create the wall comment form 104 Managing Ajax comment submit 108 Time for action – Save the comments 109 Using Ajax to submit forms 113 Saving comments in WordPress post 115 Dynamically load comments 117 Time for action – Display the comments 118 WordPress database query 120 Comment output 121 Displaying the comments 122 Ajax security 123
  • 15. Table of Contents [ iv ] Time for action – Display the comments 123 Summary 124 Chapter 5: Snazzy Archives 125 Using a class for plugin 126 Time for action – Create a new plugin class 126 Showing template output with shortcodes 130 Time for action – Use a shortcode 130 Shortcode API 132 Enclosing shortcodes 133 Custom templates 134 Time for action – Create a custom template 134 Prepare archives 136 Time for action – Show archives of posts 137 Get all posts from database 142 Using a regular expression 142 Retrieve comment count for a post 142 Using output buffers 143 Apply styling and jQuery to archives 143 Time for action – Style the archive view 143 Time for action – Use jQuery to allow user interaction 147 Creating plugin options page 149 Time for action – Create an options page 151 Managing plugin options 155 Handling options form 156 Adding administration pages 158 Use plugin options 159 Time for action – Apply the plugin options 160 Caching the plugin output 163 Time for action – Create archives cache 163 Summary 166 Chapter 6: Insights for WordPress 167 Creating custom panels in the editor screen 169 Time for action – Create a new plugin outline 169 Custom edit panels in WordPress 172 Searching the posts 174 Time for action – Display a list of matching posts 174 Interacting with tinyMCE 181 Time for action – Insert the link into tinyMCE 181 Using Flickr API 184 Time for action – Display Flickr photos 185 Using third-party solutions—phpFlickr 191 Creating a tinyMCE plugin 192 Time for action – Adding a button to tinyMCE 192
  • 16. Table of Contents [ ] Create a functional tinyMCE plugin window 197 Time for action – Open a tinyMCE window 197 Summary 200 Chapter 7: Post Types 201 Handling localization 202 Time for action – Create plugin and add localization 203 Optimizing localization usage 206 How does localization work? 207 Adding a post template 208 Time for action – Create 'add photo' post template 208 Backend CSS classes 212 Handling file and image uploads 213 Time for action – Handle uploaded image 213 Using custom fields 223 Adding custom fields 223 Retrieving custom fields 224 Quick post a link 224 Time for action – Add link template 224 Tinkering with WordPress backend menus 228 Time for action - Remove 'Link' from the Write page 228 Programming the Manage panel 230 Time for action – Add post type column in the Manage panel 231 Modifying an existing column 233 Manage screen search filter 234 Time for action – Add a search filter box 235 Handling error messages 237 Time for action – Adding support for errors 237 User roles and capabilities 239 Time for action – Add user capability checks 240 Summary 241 Chapter 8: Development Goodies 243 Creating Localization files 243 Time for action - Create a POT file 244 Updating POT file 247 Time for action – Perform translation 248 Updating translation 249 Documentation and support 250 Plugin readme file 250 Time for action – Create a sample plugin readme.txt file 251 Sections of readme.txt 253 General information 254 Special codes 254 Screenshots 254 Installation instructions 255
  • 17. Table of Contents [ vi ] Plugin homepage 255 Providing support 257 Code management and plugin repository 258 Requesting repository access 258 Using SVN 259 Time for action - Manage a local repository using SVN 260 Tagging a new version 261 Using WordPress development SVN 262 Local copy of plugin repository 262 Promotion 263 Plugin promotion checklist 264 General plugin development guidelines 264 Security 265 Performance 265 Re-using resources 265 Keeping API up-to-date 266 WordPress MU development 266 WordPress and GPL 268 Online resources 269 WordPress documentation (WordPress Codex) 269 WordPress development news 269 WordPress blog 269 WordPress development updates 269 WordPress Trac 269 WordPress dev IRC channel 269 Debugging and testing 270 Unit testing 270 Automated tests 270 Mailing Lists 270 WP hackers 270 WP professionals 270 Other mailing lists 270 Podcasts 271 WordCast 271 WordPress Weekly 271 Author's (Vladimir Prelovac's) web site 271 Summary 271 Index 273
  • 18. 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.
  • 19. Preface [ ] 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.
  • 20. Preface [ ] 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: ?php the_content('p class=serifRead the rest of this entry raquo;/p’); ? ?php if (function_exists(WPDiggThis_Link)) echo WPDiggThis_Link(); ? 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. Warnings or important notes appear in a box like this. Tips and tricks appear like this.
  • 21. Preface [ ] 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 [email protected]. 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.
  • 22. Preface [ ] 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.
  • 24. 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 guys behind WordPress are on to something big. It has indeed proven to be so, and as the days passed by, I have enjoyed every aspect of WordPress—publishing, social, and development. And I am thrilled to share these nits and bits of WordPress development information with you, showing you the power and flexibility that allowed WordPress to become so popular. How will you benefit? Thanks to its open source architecture, ease of use, and customization possibilities, WordPress has succeeded in differentiating itself from other����������������������������� ���������������������������� weblog publishing platforms and even other open source solutions. WordPress features The main WordPress features������������������������������� ������������������������������ of interest to developers are: Its a huge community of users and developers The millions of WordPress������ ����� blogs Major sites using it, including a number of US government agencies    1
  • 25. Preparing for WordPress Development [ ] Security�������������������������������� ������������������������������� issues treated almost instantly Unmatched������������������������������������������������ ����������������������������������������������� flexibility with thousands of available plugins High level of customizability with thousands�������������������� of ���������������� available themes Search engine friendly functionalities Ease of use,������������������������� ������������������������ maintenance,������������ ����������� and upgrade A great way to meet new people! With such a list, it is no wo���������������������������������������������������� nder that—every day—more and more private users and companies are turning to WordPress for their publishing needs. This of course presents a fertile ground for WordPress developers to show off their skills. More sites means more opportunities The opportunity for a WordPress developer in these circumstances becomes obvious. With such a huge number of sites running it, the market is hungry for WordPress experts, and not just development experts. If you are proficient in the installation and setup of WordPress, you may easily have your hands full of work. Big players use it The fact that a number of major sites use WordPress means that there is also an opportunity for high profile work. This also means that you can be fairly certain about the future of WordPress. Your investment in time and efforts, first in reading this book, and then in enhancing your development skills, is likely to pay off with WordPress. Urgent response to security issues With online security becoming a bigger issue each day, it is a relief to see the WordPress development team reacting promptly to newly discovered security issues. This makes everyone even more comfortable and confident in using WordPress. Flexibility With WordPress, the plugin author is allowed total control over every aspect of the site. You are able to completely customize the way the site looks and behaves. The opportunity is there for everyone—from beginners (developing useful plugins) to professionals (creating total WordPress makeovers such as e-commerce, marketing, or job portal sites—where you can hardly recognize that the site is running a WordPress installation).      
  • 26. Chapter 1 [ ] Search engines friendly Search Engine Optimization (SEO) is an important aspect of today's Internet presence. Just creating a site is not enough anymore, as there are now hundreds of millions of competing websites out there. Using������������������������������������������������������������������������������������ ����������������������������������������������������������������������������������� a platform such as WordPress will be really valuable, especially in the long term. WordPress has significant built-in SEO features and also most of the other aspects of modern� SEO�������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������� technologies available through custom plugins (and you can always write one to match� your needs!) Becoming proficient in SEO concepts can help�������������������������� ������������������������� you a lot as a WordPress developer, as the need for both WordPress and SEO skills����������������� ���������������� is growing fast. Easy to use WordPress is meant for �������������������������������������������������������������������� beginners and used by professionals. This mix is rarely seen in any other open source platforms. After the five minute installation, most users immediately feel comfortable in the WordPress administration panels. Writing a post and organizing categories is as simple as it should be. The whole WordPress installation consists of putting the files on the server and setting the assigned database, and it is very easy to back up or move it to another server. WordPress and its plugins can be upgraded with a click of a button; all this makes the job of maintaining a WordPress website (�������������������������������������������� or even several at the same time), a breeze. Social aspect If you are a WordPress developer, the chances are that you will have your own hosted WordPress����������������������������������������������������������������������������� ���������������������������������������������������������������������������� blog. Having a personal blog creates a great opportunity to create many new contacts—both business and friends. When you release a WordPress plugin,������������������������������������������������ ����������������������������������������������� you will meet hundreds of people who are going to use it on their own sites. You will also have people visit you for support, or just to say Thank you! Plugins as tool for promotion With such a huge user base, a well written plugin will�������������������������������� ������������������������������� probably be downloaded��������� �������� tens of thousands of times. This will create awareness about you as a plugin author and your site as a probable source for some cool stuff. Having in mind how difficult it is to get noticed on the Internet today, this becomes a very important aspect of plugin development that you get for free.
  • 27. Preparing for WordPress Development [ 10 ] Creating������������������������������������������������������������������������������������ ����������������������������������������������������������������������������������� fresh, new, and usable plugins can help you go a long way. It has really helped me a lot in my field of work����������������������������������������������������������������� ���������������������������������������������������������������� and has created a lot of opportunities–one certainly being, the pleasure of writing this������ ����� book. Dogfooding WordPress plugins You may sometimes wish to create a plugin just for yourself, to fulfil a specific need that can arise at a given moment. This is how I started writing plugins initially, as I needed certain functionalities that were not available in WordPress at the time. The term dogfooding describes a dog food company that is ready to eat its own dog food. It means the company is confident about its own product and uses it for the purpose it was� produced for. In WordPress'��������������������������������������������������������������������������������� �������������������������������������������������������������������������������� terms, it����������������������������������������������������������������������� ���������������������������������������������������������������������� means that you should always strive to create a plugin that satisfies your needs.���������������������������������������������������������������������������������� ��������������������������������������������������������������������������������� On my personal site, I still use almost all of the plugins I created, and I only update them over time, as and when WordPress is updated, or my needs change. This has������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������ a����������������������������������������������������������������������������������� ���������������������������������������������������������������������������������� positive side effect of ensuring that your plugins will probably be attractive to� many other users as well. Assuming that you are critical about your own work, and your confidence in using your own plugins sends out a clear message on how good they����� ���� are. Challenges involved Developing WordPress��������������������������������������������������������������������� �������������������������������������������������������������������� plugins is���������������������������������������������������������� ��������������������������������������������������������� not always an easy job. It brings a number of challenges that��������������������������� �������������������������� you will need to overcome. Development WordPress����������������������������������������������������������������������������� ���������������������������������������������������������������������������� uses PHP and���������������������������������������������������������������� ��������������������������������������������������������������� provides an API with its own functions. The API has grown over time, and now covers all possible methods of communication between WordPress and the plugin. This book������������������������������������������������������������������������������������ ����������������������������������������������������������������������������������� will cover all the aspects of the API with practical examples, and the development of six concrete plugins (chapters 2-7).�������������������������������������������������������� ������������������������������������������������������� Through������������������������������������������������ ����������������������������������������������� step-by-step guides to creating these plugins,� you will discover����������������������������������������������������������������������������� ���������������������������������������������������������������������������� how to use API in typical situations, from displaying output on the site���� ��� in the beginning,�������������������������������������������� ������������������������������������������� to turning��������������������������������� �������������������������������� WordPress into a CMS at the end. Each������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������ new chapter and each���������������������������������������������������������������� ��������������������������������������������������������������� new������������������������������������������������������������ ����������������������������������������������������������� plugin will introduce different features of WordPress, and how to�������������������������������������������������������������������������������� ������������������������������������������������������������������������������� put them to good use, thereby allowing you to gradually advance your knowledge.
  • 28. Chapter 1 [ 11 ] Security As much as��������������������������������������������������������������������������� �������������������������������������������������������������������������� WordPress team������������������������������������������������������������ ����������������������������������������������������������� takes care of���������������������������������������������� ��������������������������������������������� the WordPress core,�������������������������� ������������������������� you need to take care of security in����������������������������������������������������������������������������������� ���������������������������������������������������������������������������������� your������������������������������������������������������������������������������ ����������������������������������������������������������������������������� plugins.��������������������������������������������������������������������� �������������������������������������������������������������������� Always�������������������������������������������������������������� ������������������������������������������������������������� remember that������������������������������������������������ ����������������������������������������������� your plugin is given the ultimate authority on the user's site. This is a great������������������������������������������������������������ ����������������������������������������������������������� feature���������������������������������������������������� ��������������������������������������������������� that allowed��������������������������������������� �������������������������������������� WordPress to become popular; but with that it also carries a great������������������������ deal of ��������������� responsibility. This����������������������������������������������������������������������������������� ���������������������������������������������������������������������������������� book������������������������������������������������������������������������������ ����������������������������������������������������������������������������� will show the methods and functions best suited to the given situations, and underline the security implications.������������������������������������������������������� ������������������������������������������������������ There are not too many issues to worry about, so make sure you remember the implications and best practices and apply���������������������� ��������������������� them to your plugins. Work after development Once the development�������������������������������������������������������������������� work is done and the plugin is finished, a lot of authors face the question: What now? If you plan to release the plugin to the public, there are a few extra steps you need to take care of. This book�������������������������������������������������������������� ������������������������������������������������������������� will give ��������������������������������������������������� you practical tips in this area—refer to Chapter 8� . It������������������������������������������������������������������������������������ ����������������������������������������������������������������������������������� will cover the process ������������������������������������������������������������ that takes you from the end of the development phase to the first users coming back to you with feedback and questions. I have learned much from my own plugin development experience, and I will also be referencing����������������������� some of the resources available online . Localization At the moment, WordPress is translated�������������������������������������������� in����������������������������������������� to more than 50 languages worldwide. The number of users������������������������������������������������������������������������ ����������������������������������������������������������������������� using WordPress in their native language is growing each day, and they usually prefer����������������������������������������������� ���������������������������������������������� using plugins that support their own language. Localization in WordPress is�������������������������������������������������������������� ������������������������������������������������������������� easy, and the best thing is that you will not have to do any translation. There will always be users interested in translating your plugin to their own language and sending you the file back. This is the way it works, and it is mutually������������ ����������� beneficial. Documentation Writing documentation is often boring work but I will show������������������������������� ������������������������������ you templates which will help you to do it more efficiently and also point out the benefits of writing good��������������� �������������� documentation. I will also������������������������������������������������������� ������������������������������������������������������ cover the necessary steps to manage your plugin using SVN (Subversion), and submit it to the WordPress Plugin Repository—the ������������������������������������ central ���������������������������� repository of all WordPress plugins which currently hosts thousands of plugins and has served millions of downloads. Support Good documentation goes a long way when it comes to support.
  • 29. Preparing for WordPress Development [ 12 ] You can expect hundreds of user questions pouring in after you release a plugin. So, making sure that you have a well written documentation will save you a lot of time in answering those questions. I will also give some practical tips on how to organize your plugin page. Promotion Writing a good plugin that nobody knows about is a fruitless effort. I will give you tips on how to promote your plugin once it is published. If you have created a really useful plugin, you can expect a snowball effect when users start to write about it on their blogs and tell their friends about it. Plugins developed in this book This introduction chapter is ������������������������������������������������������������������ followed by seven chapters; six of which describe the creation of WordPress plugins and a final chapter�������������������������������������� dealing with post-development issues: Digg This Live Blogroll The Wall Snazzy Archives Insights Post Types Development Goodies Various ���������������������������������������������������������������������������������� development topics and WordPress specific functions are introduced throughout the development of these plugins,�������������������������������������������������� using concrete, step-by-step practical examples. Digg This       
  • 30. Chapter 1 [ 13 ] This is the first plugin we will be developing. This plugin will show a Digg button in your blog posts. The purpose of this������������������������������������������������������������������������� ������������������������������������������������������������������������ plugin will also be to introduce you to the basic concepts of WordPress plugin development. We will access some of the basic WordPress API functions,������������������������������������ ����������������������������������� and talk about filters and actions which are the WordPress����������������������������������������������������� ���������������������������������������������������� mechanisms for controlling the workflow of the site. Live Blogroll The second plugin comes from the idea of making the default blogroll look a little bit more exciting. We will expand our knowledge of WordPress API, but also introduce two very important allies in WordPress plugin development, namely jQuery and Ajax. jQuery and Ajax technologies help our plugins become more engaging, and we will learn the basic concepts of using them through a series of practical examples.
  • 31. Preparing for WordPress Development [ 14 ] The Wall This chapter is all about WP Wall; a plugin that creates a shoutbox on your blog's sidebar, where users can leave comments and shouts. The �������������������������������������������������������������������������������������� chapter t����������������������������������������������������������������������������� eaches important lessons, including how to create a widget and interact with the ������������������������������������������������������������������������������������� WordPress database������������������������������������������������������������������� . It also expands the usage of Ajax to include dynamic interaction with the������ ����� user. I will ��������������������������������������������������������������������������������� also try������������������������������������������������������������������������� to engage you to think about WordPress plugin development in a slightly different way. Snazzy Archives
  • 32. Chapter 1 [ 15 ] If ��������������������������������������������������������������������������������������������� plugins can be classified by beauty, this would be the most beautiful plugin in the book. It will����������������������������������������������������������������������� display your blog archives in a way you probably have not seen before. During the creation ������������������������������������������������������������������������� of the plugin, we will explore how to interact with posts, create plugin options, and manage them through a settings page in the administration. We will then use all that knowledge to produce���������������������������������������������������� a beautiful representation of your blog's archives. Insights Insights plugin will add to the productivity of the blog owner by offering quick access to common information in the Write Post screen. In this chapter, we will learn how to change the WordPress Write Post screen and interact with the built-in TinyMCE editor. We will use Ajax to get information delivered directly into our post������������������� ������������������ while we write it! Post Types
  • 33. Preparing for WordPress Development [ 16 ] The final plu�������������������������������������������������������������������� gin of the book will see us working more closely with the WordPress backend, and explore ways to transform���������������������������� WordPress into a versatile Content Management System (CMS). We ��� will learn how to customize the administration menus and pages, use custom fields to store additional information, explore user capabilities system, and use localization� . Development Goodies After all the hard work in developing those plugins, comes a chapter dedicated to all the post-development work (after-hour��������� �������� party!). The purpose���������������������������������������������������������������������� of this chapter will be to explain localization, documentation, code management, and plugin promotion. It will also give you some information regarding WordPress MU development. Wordpress MU is a multi user version of WordPress��������� that���� ��� is becoming more popular each day. Tools for the job Before we get started, we need to have some tools set up, so let's go through a short check list. Whatever way you decide to set up your development environment, make sure you are comfortable using it. Plugin������������������������������������������������������������������ ����������������������������������������������������������������� development can be a full-time job, so make sure you enjoy it as much as��������� �������� you can! WordPress Obviously, we will need WordPress installed. It is advisable to have a separate version of WordPress for development purposes���������������������������������������������������������� ��������������������������������������������������������� (that is, do not use your blog as a testing ground; your visitors will ����������������������� not l������������������ ike it very much). To���� ��� prepare your local version, you can always download the latest version of WordPress from� http://wordpress.org/download/. Then you need to decide if you are going to host it on the Internet or locally. I prefer to have it on Internet as I can easily show it to other people if necessary, no matter where I am at that moment. The advantage of local installation is that it works much faster. You can of course combine������ both. If you are����������������������������������������������������������������������������� ���������������������������������������������������������������������������� going to set it up on your local computer, and you are using Windows, using packages such as ��������� EasyPHP�� (http://www.easyphp.org) will���������������������������� ��������������������������� make your job much easier. This is ������������������������������������������������������������������������������� a software��������������������������������������������������������������������� package that incorporates PHP and MySQL for Windows systems, and is free to use.
  • 34. Chapter 1 [ 17 ] Installing WordPress������������������������������������������ ����������������������������������������� is a simple matter. I recommend���������� ��������� going to http://codex.wordpress. org/Installing_WordPress ������������������������������������������������� for the latest guide to the installation process. If you would like to set up the latest development version, I suggest you read the section Using SVN in Chapter 8. Text editor Obviously, you are going to need a text editor. Any editor will do, and you probably have a preference�������� ������� by now. You do not���������������������������������������������������������������������������� ��������������������������������������������������������������������������� need your text editor to do anything fancy. Indentation support and syntax highlighting for PHP, HTML and���������������������������������������������������������������� ��������������������������������������������������������������� JavaScript is almost all you need from an editor at this point. I have been using UltraEdit for years, and it has been always my weapon of choice for a quick, small, and powerful editor. There also are other text editors that are available for free, such as, ��������������������������������������������� Netbeans IDE for PHP, Zend Studio, and so on. FTP client The second thing you will need to have is an FTP client. Uploading plugins can be a boring job if you do it from the FTP command line; so visual FTP client is advisable. For this matter, I've been using Total Commander as a proven tool. Again, you might have your own preference. Web browser Finally, since we are developing web based software, we will need a web browser. You will be spending a lot of time in the browser window; so make sure you are comfortable with it. I do not ������������������������������������������������������������������������������������� want to instigate browser wars at this moment, but there is one browser that is very flexible and has tons���������������������������������������������������������������������� of add-ons,���������������������������������������������������������� ��������������������������������������������������������� much like WordPress in that respect, and that is Firefox. There are some pretty cool ����������������������������������������������������������������� add-ons for Firefox that can really increase productivity to the level of rapid web development. This step is optional if you do not use Firefox, but I would nevertheless recommend giving���������� it a try. Firebug The most important Firefox add-on we want to install is called Firebug (you can download it from http://getfirebug.com).
  • 35. Preparing for WordPress Development [ 18 ] Firebug allows you to preview, edit and debug CSS, HTML, JavaScript and Ajax requests in real time. This is really a great time saver. For example, when it comes to debugging, JavaScript or misaligned CSS can be really troublesome, without the use of features provided by Firebug. In the next picture, you can see an example of Firebug in action, debugging JavaScript with a breakpoint in the execution of the script.
  • 36. Chapter 1 [ 19 ] Ubiquity This is an add-on produced by Mozilla Labs and it can do a lot of fancy stuff. But for our������������������������������������������������������������������������������� ������������������������������������������������������������������������������ purposes, we are going to use it for two simple things—fast search of PHP and WordPress��������������� �������������� documentation. You will need to install Ubiquity from https://wiki.mozilla.org/Labs/Ubiquity and also install these two plugins: PHP Search: http://npattison.com/ubiquity/ubiq_php.html WP Codex Search: http://www.prelovac.com/vladimir/ubiquity- plugins/wp-codex-search The way these two ���������������������������������������������� Ubiquity commands����������������������������� work is that when you press Ctrl and Space in the browser (this opens U������������������������������ biquit������������������������ y window) and then type php search_phrase or wp search_phrase, it takes you immediately to the PHP or WordPress documentation for the given phrase. The amount of time this can save is huge, especially if you need to take a peek at the documentation every minute or so like I do (I can't keep everything in my head!). 1. 2.
  • 37. Preparing for WordPress Development [ 20 ] Screengrab You can grab Screengrab from http://www.screengrab.org, ��������������������������� and this plugin allows you to take screenshots from���������������������������������������������������������������������� ��������������������������������������������������������������������� your����������������������������������������������������������������� ���������������������������������������������������������������� browser window easily. It can capture an entire page, a visible portion, or a user selection on the page. Once you get used it, you will use it extensively for creating images for your plugin documentation. I have used it for almost all the images in this book.
  • 38. Chapter 1 [ 21 ] IE tab This Firefox add-on allows you to quickly change the rendering engine between Firefox and the installed��������������������������������������������������������������������������������� �������������������������������������������������������������������������������� version of the Internet �������������������������������������������������������� Explorer. It allows you to quickly check if your plugin behaves well in this �������� browser. You can������������ ����������� get it from ������������������������ http://ietab.mozdev.org/. Quick reference WordPress: http://www.wordpress.org/download Installing WordPress: http://codex.wordpress.org/Installing_ WordPress EasyPHP: http://www.easyphp.org UltraEdit: http://www.ultraedit.com Total Commander: http://www.ghisler.com FireFox: http://getfirefox.com FireBug: http://getfirebug.com Ubiquity: https://wiki.mozilla.org/Labs/Ubiquity PHP Search for Ubiquity: http://npattison.com/ubiquity/ubiq_ php.html WP Codex Search for Ubiquity: http://www.prelovac.com/vladimir/ ubiquity-plugins/wp-codex-search ScreenGrab: http://www.screengrab.org IETab: http://ietab.mozdev.org/ Final notes Before we start with development, let's have a quick reminder on how to install and manage WordPress plugins. Also I'll mention a handy tip for quickly accessing code examples.
  • 39. Preparing for WordPress Development [ 22 ] Installing and managing plugins When you want to install a plugin, you need to follow these simple steps: Upload the plugin folder (for example wp-wall) to your server's wp-content/plugins/ folder. 1.
  • 40. Chapter 1 [ 23 ] 2. Go to your WordPress administration section, and select Plugins from the menu. This will give you a list of all the installed plugins. Scroll down the list until you find yours, and click Activate. If you intend to manually update the plugin files on a live site, it is advisable to deactivate the plugin first using the Plugins menu. Strictly speaking, on a development blog where you are the only user, this can be skipped to save time� . If something goes ���������������������������������������������������� wrong with the plugin, and you are unable to access your WordPress site anymore, deleting the plugin folder from the server will deactivate the plugin automatically, and will instantly��������������� get your site working again. If you need more information regarding plugin management, you can refer to the latest WordPress manual found at http://codex.wordpress.org/Managing_Plugins. Searching documentation During the plugin development, you will more or less need to refer to documentation. Luckily, you ������������������������������������������������������������������������������ will have this book on your hand either in paper or in a PDF form, so you can take a quick look. Then������������������������������������������������������������ , you also have the WordPress online documentation found at http://codex.wordpress.org/Main_Page. Due to the rapid speed at which WordPress has been developing, not all the functions have been documented. So, I keep a copy of the latest version of WordPress locally. This way, I am able to find the reference to the function in the WordPress core quickly, and figure out how it is used.
  • 41. Preparing for WordPress Development [ 24 ] I also tend to keep a local copy of the entire plugin repository on my computer (you can find more details on how to do that in Chapter 8) so that I can search through the entire plugin repository and find instances of this function used by other plugin authors (and you can always find new���������������������������� and creative uses as well).
  • 42. Chapter 1 [ 25 ] Using other plugins for this ������������������������������������������������������������������� purpose can really save a lot of time, and it is often the easiest way to learn how to perform certain functionalities� . Summary We learned about the advantages of WordPress development, and what WordPress has to offer to plugin authors. We have also seen that there are certain challenges along the way, which we will address in this book. The six plugins that we will create in the following chapters will show you exactly how to create a WordPress plugin from scratch and have it perform the concrete functionality you need, whether it's on the front page or in the administration backend. Having armed ourselves with useful development tools, we are ready to start developing some cool WordPress plugins!
  • 44. 2 Social Bookmarking I hope the first chapter got you warmed up and prepared for WordPress plugin development, and that you are as eager to start as I am. In this chapter, we will create our first functional WordPress plugin and learn how to interact with the WordPress API (this is the WordPress interface to PHP) on the way. The knowledge you will gain in this chapter alone will allow you to write a lot of similar plugins. Let's get moving! In this chapter, you will learn: Creating a new plugin and having it displayed in the plugins admin panel Checking the WordPress version and control activation of the plugin Accessing API features—for example the title and permalink URL of each post Using WordPress hooks to execute your plugin code when it's needed Using conditional tags to control the flow of your plugins You will learn these by: Creating a 'social bookmarking' type of plugin that adds a Digg button to each post on your blog As you probably know, Digg is a very popular service for promoting interesting content on the Internet. The purpose of a Digg button on your blog is to make it easier for Digg users to vote for your article and also to bring in more visitors to your blog.      
  • 45. Social Bookmarking [ 28 ] The plugin we'll create in this chapter will automatically insert the necessary code to each of your posts. So let's get started with WordPress plugin development! Plugging in your first plugin Usually, the first step in plugin creation is coming up with a plugin name. We usually want to use a name that is associated with what the plugin does, so we will call this plugin, WP Digg This. WP is a common prefix used to name WordPress plugins. To introduce the plugin to WordPress, we need to create a standard plugin header. This will always be the first piece of code in the plugin file and it is used to identify the plugin to WordPress. Time for action – Create your first plugin In this example, we're going to write the code to register the plugin with WordPress , describe what the plugin does for the user, check whether it works on the currently installed version of WordPress, and to activate it. Create a file called wp-digg-this.php in your favourite text editor. It is common practice to use the plugin name as the name for the plugin file, with dashes '-' instead of spaces. Next, add a plugin information header. The format of the header is always the same and you only need to change the relevant information for every plugin: ?php /* Plugin Name: WP Digg This Version: 0.1 Description: Automatically adds Digg This button to your posts. Author: Vladimir Prelovac Author URI: http://www.prelovac.com/vladimir Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/ wp-digg-this */ ? 3. Now add the code to check the WordPress version: /* Version check */ global $wp_version; $exit_msg='WP Digg This requires WordPress 2.5 or newer. a href=http://codex.wordpress.org/Upgrading_WordPressPlease update!/a'; 1. 2.
  • 46. Chapter 2 [ 29 ] if (version_compare($wp_version,2.5,)) { exit ($exit_msg); } ? 4. Upload your plugin file to the wp-content/plugins folder on your server using your FTP client. 5. Go to your WordPress Plugins admin ��������������������������������������������� panel. You should now see your plugin listed among other plugins: 6. This means we have just completed the necessary steps to display our plugin in WordPress. Our plugin can be even activated now—although it does not do anything useful (yet).
  • 47. Social Bookmarking [ 30 ] What just happened? We created a working plugin template by using a plugin information header and the version check code. The plugin header allows the plugin to be identified and displayed properly in the plugins admin panel. The version check code will warn users of our plugin who have older WordPress versions to upgrade their WordPress installation and prevent compatibility problems. The plugin information header To identify the plugin to WordPress, we need to include a plugin information header with each plugin. The header is written as a PHP comment and contains several fields with important information. This code alone is enough for the plugin to be registered, displayed in the admin panel and readied for activation. If your future plugin has more than one PHP file, the plugin information should be placed only in your main file, the one which will include() or require() the other plugin PHP files. Checking WordPress versions To ensure that our plugin is not activated on incompatible WordPress versions, we will perform a simple WordPress version check at the very beginning of our code. WordPress provides the global variable $wp_version that provides the current WordPress version in standard format. We can then use PHP function version_compare() to compare this and our required version for the plugin, using the following code: if (version_compare($wp_version,2.6,)) { // do something if WordPress version is lower then 2.6 } If we want to stop the execution of the plugin upon activation, we can use the exit() function with the error message we want to show. In our case, we want to show the required version information and display the link to the WordPress upgrade site. $exit_msg='WP Digg This requires WordPress 2.6 or newer. a href=http://codex.wordpress.org/Upgrading_WordPressPlease update!/a';
  • 48. Chapter 2 [ 31 ] if (version_compare($wp_version,2.6,)) { exit ($exit_msg); } While being simple, this piece of code is also very effective. With the constant development of WordPress, and newer versions evolving relatively often, you can use version checking to prevent potential incompatibility problems. The version number of your current WordPress installation can be found in the footer text of the admin menu. To begin with, you can use that version in your plugin version check (for example 2.6). Later, when you learn about WordPress versions and their differences, you'll be able to lower the version requirement to the minimal your plugin will be compatible with. This will allow your plugin to be used on more blogs, as not all blogs always use the latest version of WordPress. Checking the plugin You can go ahead and activate the plugin. The plugin will be activated but will do nothing at this moment. Time for Action – Testing the version check Let's just make sure that the version check works, by requiring a fictional version of WordPress that does not exist yet: Deactivate the plugin and change the version check code to a higher version. For example, replace 2.6 with 5.0. if (version_compare($wp_version,5.0,)) 2. Re-upload the plugin and try to activate it again. You will see a WordPress error and a message from the plugin: 1.
  • 49. Social Bookmarking [ 32 ] What just happened? The version check fails and the plugin exits with our predefined error message. The same thing will happen to a user trying to use your plugin with outdated WordPress installation, requiring them to update to a newer version. Have a go Hero We created a basic plugin that you can now customize. Change the plugin description to include HTML formatting (add bold or links to the description). Test your plugin to see what happens if you have two plugins with the same name (upload a copy of the file under a different name). Displaying a Digg button Now it's time to expand our plugin with concrete functionality and add a Digg link to every post on our blog. In order to create a link we will need to extract post's permalink URL, title, and description. Luckily, WordPress provides us with a variety of ways to do this. Time for Action – Implement a Digg link Let's create a function to display a Digg submit link using information from the post. Then we will implement this function into our theme, to show the link just after the post content. 1. Add a function to our plugin to display a Digg link: /* Show a Digg This link */ function WPDiggThis_Link() { global $post; // get the URL to the post $link=urlencode(get_permalink($post-ID)); // get the post title $title=urlencode($post-post_title); // get first 350 characters of post and strip it off // HTML tags  
  • 50. Chapter 2 [ 33 ] $text=urlencode(substr(strip_tags($post-post_content), 0, 350)); // create a Digg link and return it return 'a href=http://digg.com/submit?url='.$link.'amp; title='.$title.'amp;bodytext='.$text.'Digg This/a'; } 2. Open your theme's single.php file and add a call to our function just below the line with the_content(). If you are not sure how to do this, see the forthcoming section on Editing the theme files. ?php if (function_exists(WPDiggThis_Link)) echo WPDiggThis_ Link(); ? 3. With the default WordPress theme, this change will look something like this (you can also refer to the following image):
  • 51. Social Bookmarking [ 34 ] 4. After you save the theme file, your blog posts will now automatically have the Digg This link shown after the content: 5. Clicking the link will take the user directly to the Digg site, with all the required information already filled in: Well done! You have created your first working WordPress plugin! What just happened? When WordPress loads a post, the single.php template file from the currently active WordPress theme is ran. We added a line to this file that calls our plugin function WPDiggThis_Link() just after the content of the post is displayed: ?php the_content('p class=serifRead the rest of this entry raquo;/p'); ? ?php if (function_exists(WPDiggThis_Link)) echo WPDiggThis_ Link(); ? We use function_exists()to check our function because it exists only if our plugin is installed and activated. PHP will generate an error if we try to run a nonexistent function. But if we deactivate the plugin later, we don't want to cause errors with our theme. So, we make sure that the function exists before we attempt to run it.
  • 52. Chapter 2 [ 35 ] Assuming that the plugin is present and activated, the WPDiggThis_Link() function from our plugin is ran. The first part of the following function gets information about our post and assigns it to variables: /* Show a Digg This link */ function WPDiggThis_Link() { global $post; // get the URL to the post $link=urlencode(get_permalink($post-ID)); // get the post title $title=urlencode($post-post_title); // get first 350 characters of post and strip it off HTML tags $text=urlencode(substr(strip_tags($post-post_content), 0, 350)); We use the urlencode() PHP function for all the parameters that we will pass to the final link. This will ensure that all the values are formatted properly. The second part uses this information to construct a Digg submit link: // create a Digg link and return it return 'a href=http://digg.com/submit?url='.$link.'amp; title='.$amp;title.'bodytext='.$text.'Digg This/a'; } It returns this HTML text so that it gets added to the WordPress output at the point where the function is called – just after the post is displayed. Therefore, the link appears right after each post—which is convenient for the user who has just finished reading the post. Using the Digg API Usually, when using the functionalities of third-party sites, as we are doing in our example with Digg, we would search for the API documentation first. Almost all the major sites have extensive documentation available to help developers use their services in an effective way. Digg is no exception, and if you search the Internet for the digg button api you will find a page at http://digg.com/tools/integrate that will have all the details we need in order to implement our Digg functionality.
  • 53. Social Bookmarking [ 36 ] Digg allows us to use several different ways of using their service. For the start, we will display just a Digg link. Later, we will expand it and also display a normal button. Here is what the Digg documentation says about formatting a submit link. Submit URL: http://digg.com/submit?url=example.comtitle=TITLEbodytext=DESCRIPTI ONmedia=MEDIAtopic=TOPIC Submit URL Details: url=example.com Maximum length is 255 characters Story URL should be unique and devoid of session or user-specific data Please URL-encode all strings as appropriate. For example: https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttp%2Fyourwebsite%2Fyourstoryurl%2Fstorypagedetails.html title=TITLE Maximum length is 75 characters Please also URL-encode the story title bodytext=DESCRIPTION Maximum length is 350 characters Please also URL-encode the body text   
  • 54. Chapter 2 [ 37 ] Using this information, we are able to create a valid link for the Digg service from the information available in our post. Acquiring post information WordPress provides a number of ways to get information about the current post. One of them involves using the global variable $post, which stores all the relevant information for the current post. We have used it in our example to extract the post title and content, but it can also be used to get other information such as post category, status and so on. WordPress also offers an array of functions we could have used to access post information such as get_the_title() and get_the_content(). The main difference between using these functions and accessing post data directly using $post variable is in the end information we get. The $post variable contains raw information about the post, just as the user wrote it. The functions mentioned above take the same raw information as a starting point, but could have the final output modified by external factors such as other active plugins. You can browse through the wp-includes/post-template.php file of your WordPress installation to get a better understanding of the differences between using the $post variable and the WordPress provided functions. Post permalink URL In order to obtain post URL we used the get_permalink() WordPress function. This function accepts the post ID as a parameter, and as a result, returns post's actual URL on the blog. It will always return a valid URL to your post no matter what permalink structure your blog is using. Editing the theme files In our example, we had to edit our theme in order to place the Digg link under the post content. WordPress allows for easy theme editing through the built-in Theme Editor panel. After selecting the theme you want to edit, you will be presented with a number of options. Every theme consists of various PHP template files, each covering different blog functionalities.
  • 55. Exploring the Variety of Random Documents with Different Content
  • 59. The Project Gutenberg eBook of Box and Cox: A Romance of Real Life in One Act.
  • 60. This ebook is for the use of anyone anywhere in the United States and most other parts of the world at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this ebook or online at www.gutenberg.org. If you are not located in the United States, you will have to check the laws of the country where you are located before using this eBook. Title: Box and Cox: A Romance of Real Life in One Act. Author: John Maddison Morton Release date: April 13, 2013 [eBook #42523] Most recently updated: October 23, 2024 Language: English Credits: Produced by Paul Haxo from page images generously made available by the Internet Archive and the Library of Congress. *** START OF THE PROJECT GUTENBERG EBOOK BOX AND COX: A ROMANCE OF REAL LIFE IN ONE ACT. ***
  • 62. THE MINOR DRAMA. No. XXI. BOX AND COX. A Romance of Real Life IN ONE ACT. BY JOHN MADDISON MORTON, ESQ. WITH THE STAGE BUSINESS, CAST OF CHARACTERS, COSTUMES, RELATIVE POSITIONS, c. NEW YORK: DOUGLAS, NO. 11 SPRUCE ST AND FOR SALE BY ALL BOOKSELLERS. 1848.
  • 63. CAST OF CHARACTERS. Theatre, London, 1847. Olympic, 1848. Palmo’s, 1848. John Box, a Journeyman Printer, Mr. Buckstone. Mr. Holland. Mr. Povey. James Cox, a Journeyman Hatter, “ Harley. “ Conover. “ Chapman. Mrs. Bouncer, Mrs. M’Namara. Mrs. Henry. Mrs. Vernon. COSTUMES. BOX.—Small swallow-tailed black coat, short buff waistcoat, light drab trowsers short, turned up at bottom, black stockings, white canvass boots with black tips, cotton neckcloth, shabby black hat. COX.—Brown Newmarket coat, long white waistcoat, dark plaid trowsers, boots, white hat, black stock. MRS. BOUNCER.—Coloured cotton gown, apron, cap, c. First produced at the Royal Lyceum Theatre, November 1st, 1847 Time in Representation—35 Minutes. EXITS AND ENTRANCES. R. means Right; L. Left; R. D. Right Door; L. D. Left Door; S. E. Second Entrance; U. E. Upper Entrance; M. D. Middle Door. RELATIVE POSITIONS.
  • 64. R., means Right; L., Left; C., Centre; R. C., Right of Centre; L. C., Left of Centre.
  • 65. BOX AND COX. ACT I. Scene I—A Room, decently furnished. At C., a bed, with curtains closed, at L. C., a door, at L. 3d E., a door, at L. S. E., a chest of drawers, at back, R., a window, at R. 3d E., a door, at R. S. E., a fireplace, with mantel-piece, table and chairs, a few common ornaments on chimney-piece. Cox, dressed, with the exception of his coat, is looking at himself in a small looking-glass, which is in his hand. Cox. I’ve half a mind to register an oath that I’ll never have my hair cut again! [His hair is very short.] I look as if I had just been cropped for the militia! And I was particularly emphatic in my instructions to the hair-dresser, only to cut the ends off. He must have thought I meant the other ends! Never mind—I shan’t meet anybody to care about so early. Eight o’clock, I declare! I haven’t a moment to lose. Fate has placed me with the most punctual, particular, and peremptory of hatters, and I must fulfil my destiny. [Knock at L. D.] Open locks, whoever knocks! Enter Mrs. Bouncer, L. Mrs. B. Good-morning, Mr. Cox. I hope you slept comfortably, Mr. Cox? Cox. I can’t say I did, Mrs. B. I should feel obliged to you, if you could accommodate me with a more protuberant bolster, Mrs. B. The
  • 66. one I’ve got now seems to me to have about a handful and a half of feathers at each end, and nothing whatever in the middle. Mrs. B. Anything to accommodate you, Mr. Cox. Cox. Thank you. Then, perhaps, you’ll be good enough to hold this glass, while I finish my toilet. Mrs. B. Certainly. [Holding glass before Cox, who ties his cravat.] Why, I do declare, you’ve had your hair cut. Cox. Cut? It strikes me I’ve had it mowed! It’s very kind of you to mention it, but I’m sufficiently conscious of the absurdity of my personal appearance already. [Puts on his coat.] Now for my hat. [Puts on his hat, which comes over his eyes.] That’s the effect of having one’s hair cut. This hat fitted me quite tight before. Luckily I’ve got two or three more. [Goes in at L., and returns, with three hats of different shapes, and puts them on, one after the other—all of which are too big for him.] This is pleasant! Never mind. This one appears to me to wabble about rather less than the others—[Puts on hat,]—and now I’m off! By the bye, Mrs. Bouncer, I wish to call your attention to a fact that has been evident to me for some time past— and that is, that my coals go remarkably fast— Mrs. B. Lor, Mr. Cox! Cox. It is not the case only with the coals, Mrs. Bouncer, but I’ve lately observed a gradual and steady increase of evaporation among my candles, wood, sugar, and lucifer matches. Mrs. B. Lor, Mr. Cox! you surely don’t suspect me? Cox. I don’t say I do, Mrs. B.; only I wish you distinctly to understand, that I don’t believe it’s the cat. Mrs. B. Is there anything else you’ve got to grumble about, sir?
  • 67. Cox. Grumble! Mrs. Bouncer, do you possess such a thing as a dictionary? Mrs. B. No, sir. Cox. Then I’ll lend you one—and if you turn to the letter G, you’ll find “Grumble, verb neuter—to complain without a cause.” Now that’s not my case, Mrs. B., and now that we are upon the subject, I wish to know how it is that I frequently find my apartment full of smoke? Mrs. B. Why—I suppose the chimney— Cox. The chimney doesn’t smoke tobacco. I’m speaking of tobacco smoke, Mrs. B. I hope, Mrs. Bouncer, you’re not guilty of cheroots or Cubas? Mrs. B. Not I, indeed, Mr. Cox. Cox. Nor partial to a pipe? Mrs. B. No, sir. Cox. Then, how is it that— Mrs. B. Why—I suppose—yes—that must be it— Cox. At present I am entirely of your opinion—because I haven’t the most distant particle of an idea what you mean. Mrs. B. Why the gentleman who has got the attics, is hardly ever without a pipe in his mouth—and there he sits, with his feet upon the mantel-piece— Cox. The mantel piece! That strikes me as being a considerable stretch, either of your imagination, Mrs. B., or the gentleman’s legs. I presume you mean the fender or the hob.
  • 68. Mrs. B. Sometimes one, sometimes t’other. Well, there he sits for hours, and puffs away into the fire-place. Cox. Ah, then you mean to say that this gentleman’s smoke, instead of emulating the example of all other sorts of smoke, and going up the chimney, thinks proper to affect a singularity by taking the contrary direction? Mrs. B. Why— Cox. Then, I suppose, the gentleman you are speaking of, is the same individual that I invariably meet coming up stairs when I’m going down, and going down stairs when I’m coming up! Mrs. B. Why—yes—I— Cox. From the appearance of his outward man, I should unhesitatingly set him down as a gentleman connected with the printing interest. Mrs. B. Yes, sir—and a very respectable young gentleman he is. Cox. Well, good-morning, Mrs. Bouncer! Mrs. B. You’ll be back at your usual time, I suppose, sir? Cox. Yes—nine o’clock. You needn’t light my fire in future, Mrs. B. —I’ll do it myself. Don’t forget the bolster! [Going, stops.] A halfpenny worth of milk, Mrs. Bouncer—and be good enough to let it stand—I wish the cream to accumulate. [Exit at L. C. Mrs. B. He’s gone at last! I declare I was all in a tremble for fear Mr. Box would come in before Mr. Cox went out. Luckily, they’ve never met yet—and what’s more, they’re not very likely to do so; for Mr. Box is hard at work at a newspaper office all night, and doesn’t come home till the morning, and Mr. Cox is busy making hats all day
  • 69. long, and doesn’t come home till night; so that I’m getting double rent for my room, and neither of my lodgers are any the wiser for it. It was a capital idea of mine—that it was! But I haven’t an instant to lose. First of all, let me put Mr. Cox’s things out of Mr. Box’s way. [She takes the three hats, Cox’s dressing gown and slippers, opens door at L. and puts them in, then shuts door and locks it.] Now, then, to put the key where Mr. Cox always finds it. [Puts the key on the ledge of the door, L.] I really must beg Mr. Box not to smoke so much. I was so dreadfully puzzled to know what to say when Mr. Cox spoke about it. Now, then, to make the bed—and don’t let me forget that what’s the head of the bed for Mr. Cox, becomes the foot of the bed for Mr. Box—people’s tastes do differ so. [Goes behind the curtains of the bed, and seems to be making it—then appears with a very thin bolster in her hand.] The idea of Mr. Cox presuming to complain of such a bolster as this! [She disappears again, behind curtains.] Box. [Without.] Pooh—pooh! Why don’t you keep your own side of the staircase, sir? [Enters at back, dressed as a Printer. Puts his head out at door again, shouting.] It was as much your fault as mine, sir! I say, sir—it was as much your fault as mine, sir! Mrs. B. [Emerging from behind the curtains of bed.] Lor, Mr. Box! what is the matter? Box. Mind your own business, Bouncer! Mrs. B. Dear, dear, Mr. Box! what a temper you are in, to be sure! I declare you’re quite pale in the face! Box. What colour would you have a man be, who has been setting up long leaders for a daily paper all night? Mrs. B. But, then, you’ve all the day to yourself. Box. [Looking significantly at Mrs. Bouncer.] So it seems! Far be it from me, Bouncer, to hurry your movements, but I think it right to
  • 70. acquaint you with my immediate intention of divesting myself of my garments, and going to bed. Mrs. B. Oh, Mr. Box! [Going. Box. Stop! Can you inform me who the individual is that I invariably encounter going down stairs when I’m coming up, and coming up stairs when I’m going down? Mrs. B. [Confused.] Oh—yes—the gentleman in the attic, sir. Box. Oh! There’s nothing particularly remarkable about him, except his hats. I meet him in all sorts of hats—white hats and black hats—hats with broad brims, and hats with narrow brims—hats with naps, and hats without naps—in short, I have come to the conclusion, that he must be individually and professionally associated with the hatting interest. Mrs. B. Yes, sir. And, by the bye, Mr. Box, he begged me to request of you, as a particular favor, that you would not smoke quite so much. Box. Did he? Then you may tell the gentle hatter, with my compliments, that if he objects to the effluvia of tobacco, he had better domesticate himself in some adjoining parish. Mrs. B. Oh, Mr. Box! You surely wouldn’t deprive me of a lodger? [Pathetically. Box. It would come to precisely the same thing, Bouncer, because if I detect the slightest attempt to put my pipe out, I at once give you warning that I shall give you warning at once. Mrs. B. Well, Mr. Box—do you want anything more of me? Box. On the contrary—I’ve had quite enough of you!
  • 71. Mrs. B. Well, if ever! What next, I wonder? [Goes out at L. C., slamming door after her. Box. It’s quite extraordinary, the trouble I always have to get rid of that venerable female! She knows I’m up all night, and yet she seems to set her face against my indulging in a horizontal position by day. Now, let me see—shall I take my nap before I swallow my breakfast, or shall I take my breakfast before I swallow my nap—I mean, shall I swallow my nap before—no—never mind! I’ve got a rasher of bacon somewhere—[Feeling in his pockets]—I’ve the most distinct and vivid recollection of having purchased a rasher of bacon —Oh, here it is—[Produces it, wrapped in paper, and places it on table.]—and a penny roll. The next thing is to light the fire. Where are my lucifers? [Looking on mantel-piece R., and taking box, opens it.] Now, ’pon my life, this is too bad of Bouncer—this is, by several degrees, too bad! I had a whole box full, three days ago, and now there’s only one! I’m perfectly aware that she purloins my coals and my candles, and my sugar—but I did think—oh, yes, I did think that my lucifers would be sacred! [Takes candlestick off the mantel-piece, R., in which there is a very small end of candle—looks at it.] Now I should like to ask any unprejudiced person or persons their opinion touching this candle. In the first place, a candle is an article that I don’t require, because I’m only at home in the day time—and I bought this candle on the first of May—Chimney-sweepers’ Day— calculating that it would last me three months, and here’s one week not half over, and the candle three parts gone! [Lights the fire—then takes down a gridiron, which is hanging over the fireplace, R.] Mrs. Bouncer has been using my gridiron! The last article of consumption that I cooked upon it was a pork chop, and now it is powerfully impregnated with the odour of red herrings! [Places gridiron on fire, and then, with a fork, lays rasher of bacon on the gridiron.] How sleepy I am, to be sure! I’d indulge myself with a nap, if there was anybody here to superintend the turning of my bacon. [Yawning again.] Perhaps it will turn itself. I must lie down—so, here goes.
  • 72. [Lies on the bed, closing the curtains round him—after a short pause — Enter Cox, hurriedly, L. C. Cox. Well, wonders will never cease! Conscious of being eleven minutes and a half behind time, I was sneaking into the shop, in a state of considerable excitement, when my venerable employer, with a smile of extreme benevolence on his aged countenance, said to me—“Cox, I shan’t want you to-day—you can have a holiday.”— Thoughts of “Gravesend and back—fare, One Shilling,” instantly suggested themselves, intermingled with visions of “Greenwich for Fourpence!” Then came the Twopenny Omnibuses, and the Halfpenny boats—in short, I’m quite bewildered! However, I must have my breakfast first—that’ll give me time to reflect. I’ve bought a mutton chop, so I shan’t want any dinner. [Puts chop on table.] Good gracious! I’ve forgot the bread. Holloa! what’s this? A roll, I declare! Come, that’s lucky! Now, then, to light the fire. Holloa— [Seeing the lucifer-box on table,]—who presumes to touch my box of lucifers? Why, it’s empty! I left one in it—I’ll take my oath I did. Heydey! why, the fire is lighted! Where’s the gridiron? On the fire, I declare! And what’s that on it? Bacon? Bacon it is! Well, now, ’pon my life, there is a quiet coolness about Mrs. Bouncer’s proceedings that’s almost amusing. She takes my last lucifer—my coals, and my gridiron, to cook her breakfast by! No, no—I can’t stand this! Come out of that! [Pokes fork into bacon, and puts it on a plate on the table, then places his chop on the gridiron, which he puts on the fire.] Now, then, for my breakfast things. [Taking key, hung up, L., opens door L. and goes out, slamming the door after him, with a loud noise. Box. [Suddenly showing his head from behind the curtains.] Come in! if it’s you, Mrs. Bouncer—you needn’t be afraid. I wonder how long I’ve been asleep? [Suddenly recollecting.] Goodness gracious—my bacon! [Leaps off bed, and runs to the fireplace.]
  • 73. Holloa! what’s this? A chop! Whose chop? Mrs. Bouncer’s, I’ll be bound.—She thought to cook her breakfast while I was asleep—with my coals, too—and my gridiron! Ha, ha! But where’s my bacon? [Seeing it on table.] Here it is. Well, ’pon my life, Bouncer’s going it! And shall I curb my indignation? Shall I falter in my vengeance? No! [Digs the fork into the chop, opens window, and throws chop out— shuts window again.] So much for Bouncer’s breakfast, and now for my own! [With the fork he puts the bacon on the gridiron again.] I may as well lay my breakfast things.—[Goes to mantel-piece at R., takes key out of one of the ornaments, opens door at R. and exit, slamming door after him. Cox. [Putting his head in quickly at L.] Come in—come in! [Opens door, L. C. Enters with a small tray, on which are tea things, c., which he places on drawers, L. and suddenly recollects.] Oh, goodness! my chop! [Running to fireplace.] Holloa—what’s that? The bacon again! Oh, pooh! Zounds—confound it—dash it—damn it—I can’t stand this! [Pokes fork into bacon, opens window, and flings it out, shuts window again, returns to drawers for tea things, and encounters Box coming from his cupboard with his tea things—they walk down C. of stage together.] Who are you, sir? Box. If you come to that—who are you? Cox. What do you want here, sir? Box. If you come to that—what do you want? Cox. [Aside.] It’s the printer! [Puts tea-things on the drawers. Box. [Aside.] It’s the hatter! [Puts tea-things on table. Cox. Go to your attic, sir— Box. My attic, sir? Your attic, sir!
  • 74. Cox. Printer, I shall do you a frightful injury, if you don’t instantly leave my apartment. Box. Your apartment? You mean my apartment, you contemptible hatter, you! Cox. Your apartment? Ha! ha!—come, I like that! Look here, sir— [Produces a paper out of his pocket.] Mrs. Bouncer’s receipt for the last week’s rent, sir— Box. [Produces a paper, and holds it close to Cox’s face.] Ditto, sir! Cox. [Suddenly shouting.] Thieves! Box. Murder! Both. Mrs. Bouncer! [Each runs to door, L. C., calling. Mrs. Bouncer runs in at door, L. C. Mrs. B. What is the matter? [Cox and Box seize Mrs. Bouncer by the arm, and drag her forward. Box. Instantly remove that hatter! Cox. Immediately turn out that printer! Mrs. B. Well—but, gentlemen— Cox. Explain! [Pulling her round to him. Box. Explain! [Pulling her round to him.] Whose room is this? Cox. Yes, woman—whose room is this? Box. Doesn’t it belong to me? Mrs. B. No!
  • 75. Cox. There! You hear, sir—it belongs to me! Mrs. B. No—it belongs to both of you! [Sobbing. Cox Box. Both of us? Mrs. B. Oh, dear gentlemen, don’t be angry—but, you see, this gentleman—[Pointing to Box,]—only being at home in the daytime, and that gentleman—[Pointing to Cox,]—at night, I thought I might venture, until my little back second floor room was ready— Cox Box. [Eagerly.] When will your little back second floor room be ready? Mrs. B. Why, to-morrow— Cox. I’ll take it! Box. So will I! Mrs. B. Excuse me—but if you both take it, you may just as well stop where you are. Cox Box. True. Cox. I spoke first, sir— Box. With all my heart, sir. The little back second floor room is yours, sir—now, go— Cox. Go? Pooh—pooh! Mrs. B. Now don’t quarrel, gentlemen. You see, there used to be a partition here— Cox Box. Then put it up!
  • 76. Mrs. B. Nay, I’ll see if I can’t get the other room ready this very day. Now do keep your tempers. [Exit, L. Cox. What a disgusting position! [Walking rapidly round stage. Box. [Sitting down on chair, at one side of table, and following Cox’s movements.] Will you allow me to observe, if you have not had any exercise to-day, you’d better go out and take it. Cox. I shall not do anything of the sort, sir. [Seating himself at the table opposite Box. Box. Very well, sir. Cox. Very well, sir! However, don’t let me prevent you from going out. Box. Don’t flatter yourself, sir. [Cox is about to break a piece of the roll off.] Holloa! that’s my roll, sir— [Snatches it away—puts a pipe in his mouth, lights it with a piece of tinder—and puffs smoke across to Cox. Cox. Holloa! What are you about, sir? Box. What am I about? I’m about to smoke. Cox. Wheugh! [Goes and opens window at Box’s back. Box. Holloa! [Turns round.] Put down that window, sir! Cox. Then put your pipe out, sir! Box. There!
  • 77. [Puts pipe on table. Cox. There! [Slams down window and re-seats himself. Box. I shall retire to my pillow. [Goes up, takes off his jacket, then goes towards bed, and sits down upon it, L. C. Cox. [Jumps up, goes to bed, and sits down on R. of Box.] I beg your pardon, sir—I cannot allow any one to rumple my bed. [Both rising.] Box. Your bed? Hark ye, sir—can you fight? Cox. No, sir. Box. No? Then come on— [Sparring at Cox. Cox. Sit down, sir—or I’ll instantly vociferate “Police!” Box. [Seats himself—Cox does the same.] I say, sir—— Cox. Well, sir? Box. Although we are doomed to occupy the same room for a few hours longer, I don’t see any necessity for our cutting each other’s throats, sir. Cox. Not at all. It’s an operation that I should decidedly object to. Box. And, after all, I’ve no violent animosity to you, sir. Cox. Nor have I any rooted antipathy to you, sir. Box. Besides, it was all Mrs. Bouncer’s fault, sir. Cox. Entirely, sir. [Gradually approaching chairs.]
  • 78. Box. Very well, sir! Cox. Very well, sir! [Pause.] Box. Take a bit of roll, sir? Cox. Thank ye, sir. [Breaking a bit off. Pause.] Box. Do you sing, sir? Cox. I sometimes join in a chorus. Box. Then give us a chorus. [Pause.] Have you seen the Bosjemans, sir? Cox. No, sir—my wife wouldn’t let me. Box. Your wife! Cox. That is—my intended wife. Box. Well, that’s the same thing! I congratulate you! [Shaking hands.] Cox. [With a deep sigh.] Thank ye. [Seeing Box about to get up.] You needn’t disturb yourself, sir. She won’t come here. Box. Oh! I understand. You’ve got a snug little establishment of your own here—on the sly—cunning dog—[Nudging Cox.] Cox. [Drawing himself up.] No such thing, sir—I repeat, sir—no such thing, sir, but my wife—I mean, my intended wife—happens to be the proprietor of a considerable number of bathing-machines—— Box. [Suddenly.] Ha! Where? [Grasping Cox’s arm.] Cox. At a favorite watering-place. How curious you are! Box. Not at all. Well?
  • 79. Cox. Consequently, in the bathing season—which luckily is rather a long one—we see but little of each other; but as that is now over, I am daily indulging in the expectation of being blessed with the sight of my beloved. [Very seriously.] Are you married? Box. Me? Why—not exactly! Cox. Ah—a happy bachelor! Box. Why—not—precisely! Cox. Oh! a—widower? Box. No—not absolutely! Cox. You’ll excuse me, sir—but at present I don’t exactly understand how you can help being one of the three. Box. Not help it? Cox. No, sir—not you, nor any other man alive! Box. Ah, that may be—but I’m not alive! Cox. [Pushing back his chair.] You’ll excuse me, sir—but I don’t like joking upon such subjects. Box. I’m perfectly serious, sir. I’ve been defunct for the last three years! Cox. [Shouting.] Will you be quiet, sir? Box. If you won’t believe me, I’ll refer you to a very large, numerous, and respectable circle of disconsolate friends. Cox. My dear sir—my very dear sir—if there does exist any ingenious contrivance whereby a man on the eve of committing matrimony can leave this world, and yet stop in it, I shouldn’t be sorry to know it.
  • 80. Welcome to our website – the perfect destination for book lovers and knowledge seekers. We believe that every book holds a new world, offering opportunities for learning, discovery, and personal growth. That’s why we are dedicated to bringing you a diverse collection of books, ranging from classic literature and specialized publications to self-development guides and children's books. More than just a book-buying platform, we strive to be a bridge connecting you with timeless cultural and intellectual values. With an elegant, user-friendly interface and a smart search system, you can quickly find the books that best suit your interests. Additionally, our special promotions and home delivery services help you save time and fully enjoy the joy of reading. Join us on a journey of knowledge exploration, passion nurturing, and personal growth every day! ebookbell.com