WordPress 3 Plugin Development Essentials

Book description

Create your own powerful, interactive plugins to extend and add features to your WordPress site

  • Everything you need to know to develop your own plugins for WordPress
  • Walk through the development of five plugins from ground up
  • Prepare and release your plugins to the WordPress community
  • Avoid common mistakes made by most plugin developers by learning more advanced development patterns

In Detail

WordPress is one of the most popular platforms for building blogs and general websites. By learning how to develop and integrate your own plugins, you can add functionality and extend WordPress in any way imaginable. By tapping into the additional power and functionality that plugins provide, you can make your site easier to administer, add new features, or even alter the very nature of how WordPress works. Covering WordPress version 3, this book makes it super easy for you to build a variety of plugins.

WordPress 3 Plugin Development Essentials is a practical hands-on tutorial for learning how to create your own plugins for WordPress. Using best coding practices, this book will walk you through the design and creation of a variety of original plugins.

WordPress 3 Plugin Development Essentials focuses on teaching you all aspects of modern WordPress development. The book uses real and published WordPress plugins and follows their creation from the idea to the finishing touches in a series of easy-to-follow and informative steps. You will discover how to deconstruct an existing plugin, use the WordPress API in typical scenarios, hook into the database, version your code with SVN, and deploy your new plugin to the world.

Each new chapter introduces different features of WordPress and how to put them to good use, allowing you to gradually advance your knowledge. WordPress 3 Plugin Development Essentials is packed with information, tips, and examples that will help you gain comfort and confidence in your ability to harness and extend the power of WordPress via plugins.

A step-by-step guide for creating feature-rich plug-ins for WordPress

Table of contents

  1. WordPress 3 Plugin Development Essentials
    1. Table of Contents
    2. WordPress 3 Plugin Development Essentials
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code for this book
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Preparing for WordPress Development
      1. WordPress background
      2. Extending WordPress
      3. Understanding WordPress architecture
        1. Templating
        2. Introducing plugins
      4. Summarizing architecture
      5. Tools for web development
        1. WordPress
        2. Mac
        3. Windows
        4. Text editor
        5. Using an IDE
        6. FTP client
        7. MySQL client
      6. Coding best practices
      7. Basic organization
        1. Isolate tasks into functions
        2. Use classes
        3. Use descriptive variable names
        4. Use descriptive function names
        5. Separate logic and display layers
        6. Go modular, to a point
        7. Avoid short tags
      8. Planning ahead / starting development
        1. Interfaces
        2. Localization
        3. Documentation for the developer
        4. Version control
        5. Environment
        6. Tests
        7. Security
          1. Printing user-supplied data to a page
          2. Using user-supplied data to construct database queries
      9. Debugging
        1. Clearing your browser cache
        2. Updating your php.ini file
        3. Configuring your wp-config.php file
        4. Checking your syntax
        5. Checking values
        6. Exercise
      10. Summary
    9. 2. Anatomy of a Plugin
      1. Deconstructing an existing plugin: "Hello Dolly"
        1. Activating the plugin
        2. Examining the hello.php file
      2. Information header
        1. Exercise—breaking the header
        2. Location, name, and format
      3. Understanding the Includes
        1. Exercise – parse errors
      4. Bonus for the curious
      5. User-defined functions
        1. Exercise—an evil functionless plugin
        2. What just happened
        3. Omitting the closing "?>" PHP tag
        4. A better example: Adding functions
      6. Referencing hooks via add_action() and add_filter()
      7. Actions versus Filters
        1. Exercise—actions and filters
        2. Exercise—filters
        3. Reading more
      8. Summary
    10. 3. Social Bookmarking
      1. The overall plan
      2. Proof of concept
        1. Avoiding conflicting function names
      3. The master plugin outline
        1. The plugin information header
          1. In your browser—information header
        2. Adding a link to the post content
          1. Documenting our functions
          2. In your browser—linking to the post content
        3. Adding JavaScript to the head
          1. Making our link dynamic
            1. In your browser—dynamic links
        4. Adding a button template
        5. Getting the post URL
          1. In your browser—getting the post URL
        6. Getting the post title
        7. Getting the description
        8. Getting the media type
        9. Getting the post topic
          1. In your browser—title, description, and topic
      4. Checking WordPress versions
      5. Summary
    11. 4. Ajax Search
      1. What is Ajax?
      2. The overall plan
      3. The proof of concept mock up
        1. Hooking up jQuery
          1. Test that jQuery has loaded
          2. What happened?
          3. Using the FireBug console directly
        2. Writing HTML dynamically to a target div
          1. Multi-line strings
          2. Viewing the generated page
          3. Anonymous functions
          4. Adding a div on the fly
        3. Create a listener
        4. Fetching data from another page
      4. Creating our plugin
        1. Creating index.php and activating the plugin
        2. Creating our first PHP class
        3. Updating index.php
        4. Testing your version of PHP
        5. Testing for searchable pages
        6. Adding your own CSS files
        7. Adding your search handler
        8. Adding your own JavaScript
        9. Handling Ajax search requests
        10. Formatting your search results
      5. Summary
    12. 5. Content Rotator
      1. The plan
      2. Widget overview
      3. Preparation
        1. Activating your plugin
        2. Activating the widget
          1. Having problems?
        3. Parents and children: extending classes
        4. Objects vs. libraries: when to use static functions
      4. Add custom text
      5. Adding widget options
      6. Generating random content
      7. Expiration dates: adding options to our widget
        1. Expiration dates: enforcing the shelf life
        2. Explaining the $instance
      8. Adding a custom manager page
        1. Adding options to the custom manager page
      9. Randomizing content from the database
      10. Review of PHP functions used
      11. Summary
    13. 6. Standardized Custom Content
      1. What WordPress does for you: custom fields
      2. What WordPress doesn't do for you
      3. Standardizing a post's custom fields
      4. Creating a new plugin
        1. Removing the default WordPress form for custom fields
        2. Creating our own custom meta box
        3. Defining custom fields
        4. Generating custom form elements
        5. Saving custom content
      5. Having trouble saving data?
      6. Displaying custom data in your Templates
        1. Copying a theme
        2. Modifying the theme
        3. Granular display of custom fields
        4. Bonus for the MySQL curious
      7. Known limitations
      8. Summary
    14. 7. Custom Post Types
      1. Background: What's in a name?
      2. Understanding register_post_type()
      3. Customizing our post type
        1. Using shortcodes
        2. Testing our shortcode
      4. Customizing our plugin
      5. Creating a settings shortcut link
      6. Cleaning up when uninstalling
      7. Summary
    15. 8. Versioning Your Code with Subversion (SVN)
      1. Why Subversion?
        1. Understanding the terminology and concepts
        2. Checking out a local working copy
        3. SVN folder structure
        4. Checkout, revisited
      2. Setting up an SVN repository
      3. Checking out a local working copy of our repo
      4. Adding files
      5. Committing changes to the repository
      6. Overcoming errors
        1. Verifying the new state of your repository
        2. Adding more files to your repository
        3. Removing files from the repository
        4. Updating your working copy
        5. Tagging a version
        6. Reverting an entire project
        7. Reverting a single file
      7. Moving files
      8. Exporting your working copy
      9. Quick reference
      10. Summary
    16. 9. Preparing Your Plugin for Distribution
      1. Public enemy number one: PHP notices
      2. PHP short tags
      3. Conflicting names
      4. Modifying loader.php
      5. Testing WordPress version
      6. Testing PHP version
      7. Testing MySQL version
      8. Testing PHP modules
      9. Testing WordPress installed plugins
      10. Custom tests
      11. Unit tests
      12. WordPress limitations
      13. Health check page
      14. Storing test results in the database
      15. Death to clippy: Use sensible configurations
      16. Double check your interface
      17. Documentation
        1. Identify the purpose
        2. Learning to drive: Keeping it relevant
        3. Phrasebooks vs. dictionaries: Give examples
        4. Analogy: The three bears
        5. Analogy: PC load letter
      18. The decalog of documentation
      19. Summary
    17. 10. Publishing Your Plugin
      1. Internationalization and localization
      2. Processing each message
        1. Choosing a textdomain
      3. Best practices
      4. Working with formatting
      5. More advanced messages
      6. Plural vs. singular
      7. More complex messages
        1. Notes to translators
      8. Language files
      9. Creating a POT file
      10. Creating translations: .po files
      11. Loading a textdomain
      12. Updating a translation
      13. Format for the readme.txt file
        1. Section – installation
        2. Section – Frequently Asked Questions
        3. Section – screenshots
        4. New addition – videos
        5. Section – summary
      14. Requesting and using SVN access
      15. Publicity and promotion
      16. Summary
    18. A. Recommended Resources
      1. PHP reference
      2. Function reference
      3. The WordPress forums
      4. WebDev Studios
      5. Viper007Bond
      6. Kovshenin
      7. SLTaylor
      8. XPlus3
      9. WP Engineer
      10. Other plugins
    19. B. WordPress API Reference
      1. PHP functions
        1. dirname
        2. file_get_contents
        3. preg_match
        4. preg_replace
        5. print_r
        6. sprintf
        7. strtolower
        8. substr
      2. WordPress Functions
        1. __
        2. _e
        3. add_action
        4. add_filter
        5. add_meta_box
        6. add_options_page
        7. check_admin_referer
        8. esc_html
        9. get_option
        10. get_post_meta
        11. get_the_ID
        12. register_post_type
        13. remove_meta_box
        14. screen_icon
        15. the_content
        16. the_meta
        17. update_post_meta
        18. wp_count_posts
        19. wp_die
        20. wp_nonce_field
      3. Actions
        1. admin_init
        2. admin_menu
        3. do_meta_boxes
        4. init
        5. save_post
        6. widgets_init
        7. wp_head
      4. Filters
        1. the_content
    20. Index

Product information

  • Title: WordPress 3 Plugin Development Essentials
  • Author(s): Brian Bondari, Everett Griffiths
  • Release date: March 2011
  • Publisher(s): Packt Publishing
  • ISBN: 9781849513524