Professional WordPress Plugin Development

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

As one of the most popular open source content management systems available today, WordPress boasts a framework that allows you to easily customize and extend it through plugins. This comprehensive book shows you how plugins work, reviews the tools and APIs available in WordPress, and demonstrates how to extend the functionality of WordPress with plugins.The trio of established authors provides a practical, solutions-based approach along with a collection of timely examples and plenty of code, all aimed at clearly explaining how to create a plugin file, work with users, integrate widgets, add menus and submenus, secure your plugins, and more. You will quickly come to understand how to develop custom plugins so that you can take WordPress to the next corporate and enterprise level.Professional WordPress Plugin Development:Details the range of complexity in plugins, from a very simple plugin to an extremely elaborate social network packageAddresses how to integrate into WordPress, save settings, create widgets and shortcodes, and implement uninstallLearn the proper techniques for storing data, customizing user roles, and security best practicesShares techniques for using custom post types and creating and using custom taxonomiesHow to create plugins for WordPress Multisite networksIntegrate user and role managementExplores the HTTP API, JavaScript and AJAX, Cron, the Rewrite API, and more

Author(s): Brad Williams, Ozh Richard, Justin Tadlock
Edition: 1
Publisher: Wrox
Year: 2011

Language: English
Pages: 554
Tags: Библиотека;Компьютерная литература;Системы CMS / CMF;WordPress;

Content
......Page 3
Professional WordPress® Plugin Development......Page 5
CONTENTS......Page 11
FOREWORD......Page 23
INTRODUCTION......Page 25
What Is a Plugin?......Page 31
How Plugins Interact with WordPress......Page 32
Official Plugin Directory......Page 33
Popular Plugin Tags......Page 34
Why Reinvent the Wheel......Page 35
Easy Updates......Page 36
Installing a Plugin......Page 37
Plugin Directories......Page 38
Types of Plugins......Page 39
Summary......Page 40
Naming Your Plugin......Page 41
Prefix Everything......Page 42
Folder Structure......Page 43
Creating the Header......Page 44
Plugin Paths......Page 45
Local Paths......Page 46
URL Paths......Page 47
Plugin Activation Function......Page 48
Plugin Deactivation Function......Page 49
Why Uninstall Is Necessary......Page 50
Uninstall Hook......Page 51
Coding Standards......Page 52
Naming Variables, Functions, and Files......Page 53
Indentation......Page 54
Space Usage......Page 55
Plugin Development Checklist......Page 56
Summary......Page 57
CHAPTER 3: HOOKS......Page 59
Actions......Page 60
What Is an Action?......Page 61
Action Hook Functions......Page 62
Commonly Used Action Hooks......Page 66
Filters......Page 69
What Is a Filter?......Page 70
Filter Hook Functions......Page 71
Quick Return Functions......Page 76
Commonly Used Filter Hooks......Page 77
Using Hooks from Within a Class......Page 81
Creating Custom Hooks......Page 82
Custom Action Hook Example......Page 83
Custom Filter Hook Example......Page 84
How to Find Hooks......Page 85
Hook Reference Lists......Page 86
Summary......Page 87
Adding Menus and Submenus......Page 89
Creating a Top-Level Menu......Page 90
Adding a Submenu......Page 91
Adding a Menu Item to an Existing Menu......Page 92
Creating a Widget......Page 93
Advanced Widget......Page 98
Creating Dashboard Widgets......Page 104
Creating a Dashboard Widget with Options......Page 105
Adding a Custom Meta Box......Page 109
Saving Meta Box Data......Page 110
Advanced Meta Box......Page 114
Headings......Page 120
Messages......Page 121
Buttons......Page 122
Form Fields......Page 123
Tables......Page 124
Pagination......Page 125
Summary......Page 126
Internationalization and Localization......Page 127
Understanding Internationalization in Professional Work......Page 128
Echoing and Returning Strings......Page 129
Using Placeholders......Page 138
Internationalizing JavaScript......Page 140
Translation Tools......Page 143
How to Create a POT File......Page 144
Summary......Page 145
Securing Your Plugin......Page 147
How to Check current_ user_ can()......Page 148
Do Not Check Too Early......Page 149
Authority Versus Intention......Page 150
What Is a Nonce?......Page 151
How to Create and Verify Nonces......Page 152
The Need for Data Validation and Sanitization......Page 157
Good Practice: Identifying Potentially Tainted Data......Page 159
Validating or Sanitizing Input?......Page 160
Validating and Sanitizing Cookbook......Page 161
The $wpdb Object......Page 179
Why wpdb Methods Are Superior......Page 180
All-in-One Methods......Page 181
Common Methods......Page 183
Protecting Queries Against SQL Injections......Page 187
Miscellaneous wpdb Methods and Properties......Page 189
Security Good Habits......Page 190
Summary......Page 191
The Options API......Page 193
Saving an Array of Options......Page 194
Retrieving Options......Page 195
Loading an Array of Options......Page 196
The Autoload Parameter......Page 197
Settings API Functions......Page 199
Wrapping It Up: A Complete Plugin Management Page......Page 204
Improving Feedback on Validation Errors......Page 206
Adding Fields to an Existing Page......Page 207
The Transients API......Page 210
Deleting an Expiring Option......Page 211
Technical Details......Page 212
User Metadata......Page 213
Updating User Metadata......Page 214
Deleting User Metadata......Page 215
Adding Input Fields to a Profile Page......Page 216
BOJ's Admin Lang Plugin......Page 218
Per-User Settings: Best Practices......Page 220
Creating a Custom Table......Page 221
Updating the Structure of a Custom Table......Page 223
dbDelta() Tips for Success......Page 224
Summary......Page 226
CHAPTER 8: USERS......Page 227
User Functions......Page 228
Creating, Updating, and Deleting Users......Page 232
User Data......Page 237
User Metadata......Page 242
Roles and Capabilities......Page 249
Default Roles......Page 250
Limiting Access......Page 251
Checking User Permissions......Page 252
Is the User an Admin?......Page 256
Allowing Custom Permissions......Page 257
Creating a Role......Page 259
Deleting a Role......Page 260
Adding Capabilities to a Role......Page 261
Removing Capabilities from a Role......Page 262
A Custom Role and Capability Plugin......Page 263
Summary......Page 266
What Is an HTTP Request?......Page 267
How to Make HTTP Requests in PHP......Page 270
The wp_remote_Functions......Page 272
Advanced Configuration and Tips......Page 278
Practice: Reading JSON from a Remote API......Page 285
Getting and Reading JSON......Page 286
Your Functional Plugin......Page 287
Formatting Parameters for POST Requests......Page 289
Your Functional Plugin......Page 290
Practice: Reading Arbitrary Content......Page 292
How Plugin Upgrades Work in WordPress......Page 293
Polling an Alternative API from a Plugin......Page 294
Building the Alternative API......Page 298
Special Case: Fetching Remote Feeds......Page 299
Summary......Page 300
What Shortcodes Are......Page 301
Register Custom Shortcodes......Page 303
Think Simplicity for the User......Page 307
Remember the Dynamicity......Page 310
Look Under the Hoods......Page 311
A "bb code" for Comments Plugin......Page 313
Integrating Google Maps......Page 316
Accessing the Google Geocoding API......Page 317
Storing API Results......Page 318
Accessing the Google Maps API......Page 320
Display Member-Only Content......Page 325
Obfuscate Email Addresses......Page 326
Summary......Page 327
CHAPTER 11: EXTENDING POSTS: METADATA, CUSTOM POST TYPES, AND TAXONOMIES......Page 329
Registering a Post Type......Page 330
Setting Post Type Labels......Page 335
Using Custom Capabilities......Page 336
Attaching Existing Taxonomies......Page 338
Creating a Custom Post Type Loop......Page 339
Retrieving Custom Post Type Content......Page 341
Checking if a Post Type Exists......Page 342
Post Metadata......Page 343
Adding Post Metadata......Page 344
Retrieving Post Metadata......Page 345
Updating Post Metadata......Page 346
Deleting Post Metadata......Page 347
Understanding Taxonomies......Page 348
Registering a Custom Taxonomy......Page 349
Assigning a Taxonomy to a Post Type......Page 353
Retrieving a Taxonomy......Page 354
Using a Taxonomy with Posts......Page 355
Taxonomy Conditional Tags......Page 357
A Post Type and Taxonomy Plugin......Page 359
Summary......Page 362
jQuery–A Brief Introduction......Page 363
jQuery Crash Course......Page 364
Ajax......Page 367
What Is Ajax?......Page 368
A Proper Way to Include Scripts......Page 371
Where to Include Scripts......Page 378
Adding Scripts Only When Needed......Page 380
Dynamic Scripts in WordPress......Page 384
Ajax in WordPress: Principles......Page 388
A Complete Example: Instant "Read More" Links......Page 390
Another Example: Frontend Comment Deletion......Page 397
Debugging Ajax......Page 402
Summary......Page 403
How Is Cron Executed?......Page 405
Scheduling a Recurring Event......Page 406
Scheduling a Single Event......Page 409
Unscheduling an Event......Page 411
Viewing Cron Events Scheduled......Page 412
Deleting Post Revisions Weekly......Page 416
The Blog Pester Plugin......Page 421
The Delete Comments Plugin......Page 425
Summary......Page 431
Why Rewrite URLs......Page 433
Apache's mod_rewrite......Page 434
URL Rewriting in WordPress......Page 435
Overview of the Query Process......Page 436
The query Object......Page 437
Rewriting a URL to Create a List of Shops......Page 438
Creating a New Permalink Structure and Integrating Non-WordPress Pages......Page 445
Adding an Endpoint and Altering Output Format......Page 447
Adding a Custom Feed for the Latest Uploaded Images......Page 451
Summary......Page 453
CHAPTER 15: MULTISITE......Page 455
Understanding Multisite Terminology......Page 456
Enabling Multisite in WordPress......Page 457
The Power of Blog ID......Page 458
Common Functions......Page 459
Switching and Restoring Sites......Page 461
Network Content Shortcode Examples......Page 464
A Network Content Widget Example......Page 470
Creating a New Site......Page 476
Multisite Site Options......Page 482
Users in a Network......Page 483
Multisite Super Admin......Page 487
Checking the Site Owner......Page 488
Network Stats......Page 489
Site-Specific Tables......Page 490
Summary......Page 491
Supporting Old Versions ( Not)......Page 493
Keeping Current with WordPress Development......Page 494
Deprecated Functions......Page 495
Debugging......Page 496
Displaying Debug Messages......Page 497
Correcting Debug Messages......Page 498
Enabling Logging......Page 502
Caching......Page 503
Saving, Loading, and Deleting Cached Data......Page 504
Caching Data Within a Plugin......Page 505
Summary......Page 507
CHAPTER 17: MARKETING YOUR PLUGIN......Page 509
Different Options......Page 510
Why It Matters......Page 511
Submitting to WordPress.org......Page 512
Submitting a Plugin......Page 514
Setting Up SVN......Page 515
Creating a readme.txt File......Page 516
Naming Your Plugin......Page 519
Building a Web Site......Page 521
Creating a Page for Your Plugin......Page 522
Supporting Your Plugins......Page 523
Getting Feedback......Page 524
Other Promotion Methods......Page 525
Summary......Page 526
Inline Documentation......Page 527
Common Core Files......Page 529
Function Reference......Page 531
PHPXref......Page 532
Support Forums......Page 533
WordPress Chat......Page 534
Community News Sites......Page 535
Local Events......Page 536
Editor......Page 537
phpMyAdmin......Page 538
Summary......Page 539
INDEX......Page 541