You are previewing WordPress Plugin Development Cookbook.
O'Reilly logo
WordPress Plugin Development Cookbook

Book Description

Why rely on third-party plugins for WordPress when you can create your own? This book shows you how with a series of brilliant recipes and code examples, taking your skills to a whole new level of customization.

  • Learn to create plugins and configuration panels in order to bring new capabilities to WordPress

  • Tailor WordPress to your needs with new content types, custom widgets, and fancy jQuery elements, without breaching security needs

  • Detailed instructions on how to achieve each task, followed by clear explanations of concepts featured in each recipe

  • In Detail

    WordPress is a popular, powerful, and open Content Management System. Learning to extend its core capabilities allows you to unleash its full potential, whether you're an administrator who cannot find the right extension, or a developer with a great idea to enhance the platform for the community, or a website designer/developer working to fulfill a client's needs.

    "WordPress Plugin Development Cookbook" is the perfect companion for plugin developers, offering easy-to-follow instructions to accomplish tasks that range from basic plugin creation and configuration to advanced customization techniques. Each topic is illustrated through realistic examples showing how it can be applied to solve common problems, followed by explanations of all concepts used.

    Create WordPress plugins of varying complexity, from a few lines that change a specific function to complex extensions that provide intricate new capabilities.

    From the creation of your first simple plugin to adding entire new sections and widgets in the administration interface, learn how to change and extend WordPress to perform virtually any task. After installing and configuring an efficient plugin development environment, you will discover how to register your own callbacks that WordPress will execute at key points, forming the basis of plugin creation. Armed with this essential knowledge, you'll explore how to create administration pages to allow users to configure your new creations and to add new content management sections to WordPress through custom post types and custom database tables. Once you have all these elements in place, improve your plugins by customizing the post and page editors, creating user-facing forms to populate new content sections, making your plugin output dynamic using Javascript and AJAX as well as adding new widgets to the platform. Finally, see how to add support for multiple languages and distribute your work to the global WordPress community.

    "WordPress Plugin Development Cookbook" provides you with tools to create any plugin you can imagine.

    Table of Contents

    1. WordPress Plugin Development Cookbook
      1. WordPress Plugin Development Cookbook
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      6. 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
          2. Errata
          3. Piracy
          4. Questions
      7. 1. Preparing a Local Development Environment
        1. Introduction
        2. Installing a web server on your computer
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Creating a remote web development environment
          4. See also
        3. Downloading and configuring a local WordPress installation
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Creating a local Subversion repository
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Manual repository creation
            2. Other version control systems
          4. See also
        5. Importing initial files to a local Subversion repository
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Checking out files from a Subversion repository
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Subversion file statuses
          5. See also
        7. Committing changes to a Subversion repository
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Viewing the differences in modified files
            2. Updating files to latest repository version
          5. See also
        8. Reverting uncommitted file changes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Configuring TortoiseSVN to use an external diff viewer
          5. See also
        9. Viewing file history and reverting content changes to older revisions
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Installing a dedicated code/text editor
          1. How to do it...
          2. How it works...
        11. Installing and configuring the NetBeans Integrated Development Environment
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        12. Interacting with a Subversion repository from the NetBeans interface
          1. Getting ready
          2. How to do it...
          3. How it works...
        13. Managing a MySQL database server from the NetBeans interface
          1. Getting ready
          2. How to do it...
          3. How it works...
      8. 2. Plugin Framework Basics
        1. Introduction
        2. Creating a plugin file and header
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Installing the WordPress plugin creation module in NetBeans
          5. See also
        3. Adding output content to page headers using plugin actions
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Action hooks online listings
            2. Searching for hooks in the WordPress source code
          4. See also
        4. Using WordPress path utility functions to load external files and images
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. Modifying the page title using plugin filters
          1. How to do it...
          2. How it works...
          3. There's more...
            1. is_front_page function
            2. get_post_type function
            3. Filter hooks online listings and the apply_filters function
          4. See also
        6. Adding text after each item's content using plugin filters
          1. How to do it...
          2. How it works...
          3. There's more...
            1. get_the_title and get_permalink functions
          4. See also
        7. Inserting link statistics tracking code in page body using plugin filters
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Troubleshooting coding errors and printing variable content
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Built-in WordPress debugging features
          4. See also
        9. Creating a new simple shortcode
          1. How to do it...
          2. How it works...
          3. See also
        10. Creating a new shortcode with parameters
          1. How to do it...
          2. How it works...
          3. See also
        11. Creating a new enclosing shortcode
          1. How to do it...
          2. How it works...
          3. See also
        12. Loading a stylesheet to format plugin output
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        13. Writing plugins using object-oriented PHP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      9. 3. User Settings and Administration Pages
        1. Introduction
        2. Creating default user settings on plugin initialization
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Adding new options when upgrading plugins
            2. Creating new tables and initializing custom post type data
            3. Deactivation function
          4. See also
        3. Storing user settings using arrays
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Removing plugin data on deletion
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
        5. Creating an administration page menu item in the Settings menu
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Settings hook priority to determine menu order
          5. See also
        6. Creating a multi-level administration menu
          1. How to do it...
          2. How it works...
          3. See also
        7. Hiding items which users should not access from the default menu
          1. How to do it...
          2. How it works...
        8. Rendering the admin page contents using HTML
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. wp_nonce_field
          5. See also
        9. Processing and storing plugin configuration data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        10. Displaying a confirmation message when options are saved
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        11. Adding custom help pages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        12. Rendering the admin page contents using the Settings API
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Rendering a drop-down list settings field
            2. Rendering a text area settings field
          4. See also
        13. Accessing user settings from action and filter hooks
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        14. Formatting admin pages using meta boxes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        15. Splitting admin code from the main plugin file to optimize site performance
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        16. Storing stylesheet data in user settings
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
          3. Managing multiple sets of user settings from a single admin page
            1. Getting ready
            2. How to do it...
              1. How it works...
              2. See also
      10. 4. The Power of Custom Post Types
        1. Introduction
        2. Creating a custom post type
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Changing the custom post type permalinks slug
        3. Adding a new section to the custom post type editor
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Displaying single custom post type items using custom templates
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Creating an archive page for custom post types
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Displaying custom post type data in shortcodes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. do_shortcode function
        7. Adding custom categories for custom post types
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Hiding the category editor from the custom post type editor
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Displaying additional columns in the custom post list page
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        10. Adding filters for custom categories to the custom post list page
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        11. Updating page title to include custom post data using plugin filters
          1. Getting ready
          2. How to do it...
          3. How it works...
      11. 5. Customizing Post and Page Editors
        1. Introduction
        2. Adding extra fields to the post editor using custom meta boxes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Adding a new meta box to all post types (including custom ones)
        3. Displaying custom post data in theme templates
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Hiding the Custom Field section in the post editor
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Extending the post editor to allow users to upload files directly
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      12. 6. Accepting User Content Submissions
        1. Introduction
        2. Creating a client-side content submission form
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Controlling access to client-side user form
          5. See also
        3. Saving user-submitted content in custom post types
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Moderating user-submitted content
          5. See also
        4. Sending e-mail notifications upon new submissions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Implementing a captcha on user forms
          1. Getting ready
          2. How to do it...
          3. How it works...
      13. 7. Creating Custom MySQL Database Tables
        1. Introduction
        2. Creating new database tables
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using phpMyAdmin to simplify code creation
            2. Create tables in network installation
        3. Deleting custom tables on plugin removal
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Updating custom table structure on plugin upgrade
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Displaying custom table data in an admin page
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Inserting and updating records in custom tables
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Deleting records from custom tables
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Displaying custom database table data in shortcodes
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Implementing a search function to retrieve custom table data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        10. Importing data from a user file into custom tables
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      14. 8. Leveraging JavaScript, jQuery, and AJAX Scripts
        1. Introduction
        2. Safely loading jQuery onto WordPress web pages
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. There's more...
              1. jQuery noconflict mode
        3. Displaying a pop-up dialog using the built-in ThickBox plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Removing the dialog close button
            2. Displaying pop-up dialogs on select pages
        4. Controlling pop-up dialog display using shortcodes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Displaying a calendar day selector using the Datepicker plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Adding tooltips to admin page form fields using the TipTip plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Using AJAX to dynamically update partial page contents
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      15. 9. Adding New Widgets to the WordPress Library
        1. Introduction
        2. Creating a new widget in WordPress
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Plugins extending other plugins
          5. See also
        3. Displaying configuration options
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Validating configuration options
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Implementing the widget display function
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Adding a custom dashboard widget
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      16. 10. Enabling Plugin Internationalization
        1. Introduction
        2. Changing the WordPress language configuration
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Adapting default user settings for translation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Making admin page code ready for translation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Modifying shortcode output for translation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Translating text strings using Poedit
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Translation template file
          5. See also
        7. Loading a language file in the plugin initialization
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Updating a translation file
            2. Advanced translation functions
            3. Localizing JavaScript files
          5. See also
      17. 11. Distributing Your Plugin on wordpress.org
        1. Introduction
        2. Creating a readme file for your plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Releasing specific plugin versions using tags
        3. Applying for your plugin to be hosted on wordpress.org
          1. How to do it...
          2. How it works...
          3. See also
        4. Uploading your plugin using Subversion
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Checking out plugins to your development installation
          5. See also
        5. Providing a plugin banner image
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also