
WordPress Web Application Development - Second Edition
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Book DescriptionThis book is intended for WordPress developers and designers who want to develop quality web applications within a limited time frame and for maximum profit. Prior knowledge of basic web development and design is assumed.What you will learn
Develop extendable plugins with the use of WordPress features in core modules
Develop pluggable modules to extend the core features of WordPress as independent modules
Follow WordPress coding standards to develop reusable and maintainable code
Build and customize themes beyond conventional web layouts
Explore the power of core database tables and understand the limitations when designing database tables for large applications
Integrate open source modules into WordPress applications to keep up with the latest open source technologies
Customize the WordPress admin section and themes to create the look and feel of a typical web application
Who this book is forThis book is intended for WordPress developers and designers who want to develop quality web applications within a limited time frame and for maximum profit. Prior knowledge of basic web development and design is assumed.
All prices
More details
Other editions
New editions

Additional editions

Previous edition

Person
Rakhitha Nimesh Ratnayake is a freelance web developer, writer, and open source enthusiast. He has over 9 years of experience in developing WordPress applications and plugins. He develops premium WordPress plugins for individual clients and the CodeCanyon marketplace. User Profiles Made Easy and WP Private Content Pro are the most popular plugins developed by him. Building Impressive Presentations with impress.js was his first book, which was published by Packt Publishing. He is also the author of the first three editions of WordPress Web Application Development. In his spare time, he likes to read books and spend time with his family
Content
WordPress As a Web Application Framework
Implementing Membership Roles Permissions and Features
Planning and Customizing the Core Database
The Building Blocks of Web Applications
Developing Pluggable Modules
Customizing the Dashboard for Powerful Backends
Adjusting Themes for Amazing Frontends
Enhancing the Power of Open Source Libraries and Plugins
Listening to Third-party Applications
Integrating and Finalizing the Portfolio Management Application
Supplementary Modules for Web Development
Appendix: Configurations Tools and Resources
Building a question-answer interface
Throughout the previous sections, we learned the basics of web application frameworks while looking at how WordPress fits into web development. By now, you should be able to visualize the potential of WordPress for application development and how it can change your career as developers. Being human, we always prefer practical approach to learn new things over the more conventional theoretical approach.
So, I will complete this chapter by converting default WordPress functionality into a simple question-answer interface such as Stack Overflow, to give you a glimpse of what we will develop throughout this book.
Prerequisites for building a question-answer interface
We will be using version 4.2.2 as the latest stable version; this is available at the time of writing this book. I suggest that you set up a fresh WordPress installation for this book, if you haven't already done so.
Tip
Also, we will be using the Twenty Fourteen theme, which is available with default WordPress installation. Make sure that you activate the Twenty Fourteen theme in your WordPress installation.
First, we have to create an outline containing the list of tasks to be implemented for this scenario:
- Create questions using the admin section of WordPress.
- Allow users to answer questions using comments.
- Allow question creators to mark each answer as correct or incorrect.
- Highlight the correct answers of each question.
- Customize the question list to include a number of answers and number of correct answers.
Now, it's time to get things started.
Creating questions
The goal of this application is to let people submit questions and get answers from various experts in the same field. First off, we need to create a method to add questions and answers. By default, WordPress allows us to create posts and submit comments to the posts. In this scenario, a post can be considered as the question and comments can be considered as the answers. Therefore, we have the capability of directly using normal post creation for building this interface.
However, I would like to choose a slightly different approach by using custom post types plugin, which you can find at http://codex.wordpress.org/Post_Types#Custom_Post_Types, in order to keep the default functionality of posts and let the new functionality be implemented separately without affecting the existing ones. We will create a plugin to implement the necessary tasks for our application:
- First off, create a folder called
wpwa-questionsinside the/wp-content/pluginsfolder and add a new file calledwpwa-questions.php. - Next, we need to add the block comment to define our file as a plugin: /* Plugin Name: WPWA Questions Plugin URI: - Description: Question and Answer interface for developers Version: 1.0 Author: Rakhitha Nimesh Author URI: http://www.innovativephp.com/ License: GPLv2 or later Text Domain: wpwa-questions */
- Having created the main plugin file, we can move into creating a custom post type called
wpwa-questionusing the following code snippet. - Include this code snippet in your
wpwa-questions.phpfile of the plugin: add_action('init', 'register_wp_questions'); function register_wp_questions() { $labels = array( 'name' => __( 'Questions', 'wpwa_questions' ), 'singular_name' => __( 'Question', 'wpwa_questions'), 'add_new' => __( 'Add New', 'wpwa_questions'), 'add_new_item' => __( 'Add New Question', 'wpwa_questions'), 'edit_item' => __( 'Edit Questions', 'wpwa_questions'), 'new_item' => __( 'New Question', 'wpwa_questions'), 'view_item' => __( 'View Question', 'wpwa_questions'), 'search_items' => __( 'Search Questions', 'wpwa_questions'), 'not_found' => __( 'No Questions found', 'wpwa_questions'), 'not_found_in_trash' => __( 'No Questions found in Trash', 'wpwa_questions'), 'parent_item_colon' => __( 'Parent Question:', 'wpwa_questions'), 'menu_name' => __( 'Questions', 'wpwa_questions'), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => __( 'Questions and Answers', 'wpwa_questions'), 'supports' => array( 'title', 'editor', 'comments' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post' ); register_post_type( 'wpwa_question', $args ); }This is the most basic and default code for custom post type creation, and I assume that you are familiar with the syntax. We have enabled title, editor, and comments in the support section of the configuration. These fields will act the role of question title, question description, and answers. Other configurations contain the default values and hence explanations will be omitted. If you are not familiar, make sure to have a look at documentation on custom post creation at http://codex.wordpress.org/Function_Reference/register_post_type.
Note
Beginner- to intermediate-level developers and designers tend to include the logic inside the
functions.phpfile in the theme. This is considered a bad practice as it becomes extremely difficult to maintain because your application becomes larger. So, we will be using plugins to add functionality throughout this book and drawbacks of thefunctions.phptechnique will be discussed in later chapters. - Once the code is included, you will get a new section on the admin area for creating questions. This section will be similar to the posts section inside the WordPress admin. Add few questions and insert some comments using different users before we move into the next stage.
Before we go into the development of questions and answers, we need to make some configurations so that our plugin works without any issues. Let's look at the configuration process:
- First, we have to look at the comment-related settings inside Discussion Settings the WordPress Settings section. Here, you can find a setting called Before a comment appears.
- Disable both checkboxes so that users can answer and get their answers displayed without approval process. Depending on the complexity of application, you can decide whether to enable these checkboxes and change the implementation.
- The second setting we have to change is the Permalinks. Once we create a new custom post type and view it on browser, it will redirect you to a
404 page not foundpage. Therefore, we have to go to the Permalinks section of WordPress Settings and update the Permalinks using the Save Changes button. This won't change the Permalinks. However, this will flush the rewrite rules so that we can use the new custom post type without404errors.
Now, we can start working with the answer-related features.
Customizing the comments template
Usually, the comments section is designed to show comments of a normal post.
While using comments for custom features such as answers, we need to customize the existing template and use our own designs.
- So, open the
comments.phpfile inside the Twenty Fourteen theme. - Navigate through the code and you will find a code section similar to the following one: wp_list_comments( array( 'style' => 'ol', 'short_ping' => true, 'avatar_size' => 34, ) );
- First, we need to customize the existing comments list to suit the requirements of the answers list. By default, WordPress will use the
wp_list_commentsfunction inside thecomments.phpfile to show the list of answers for each question. We need to modify the answers list in order to include the answer status button. So, we will change the previous implementation as following: if(get_post_type( $post ) == "wpwa_question"){ wp_list_comments('avatar_size=60&type=comment&callback=wpwa_comment_list&style=ol'); }else{ wp_list_comments( array( 'style' => 'ol', 'short_ping' => true, 'avatar_size' => 34, ) ); } - Here, we will include a conditional check for the post type in order to choose the correct answer list generation function. When the post type is
wpwa_question, we call thewp_list_commentsfunction with the callback parameter defined aswpwa_comment_list, which will be the custom function for generating answers list.Note
Arguments of the
wp_list_commentsfunction can be either an array or string. Here, we have preferred array-based arguments over string-based arguments.
In the next section, we will be completing the customization of comments template by adding answer statuses and allowing users to change the statuses.
Changing the status of answers
Once the users provide their...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: PDF
Copy-Protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (only limited: Kindle).
The file format PDF always displays a book page identically on any hardware. This makes PDF suitable for complex layouts such as those used in textbooks and reference books (images, tables, columns, footnotes). Unfortunately, on the small screens of e-readers or smartphones, PDFs are rather annoying, requiring too much scrolling.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our eBook Help page.