Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
WordPress Web Application Development - Second Edition
WordPress Web Application Development - Second Edition

WordPress Web Application Development - Second Edition: Build rapid web applications with cutting-edge technologies using WordPress

eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

WordPress Web Application Development - Second Edition

Chapter 2. Implementing Membership Roles, Permissions, and Features

The success of any web application or website depends heavily on its user base. There are plenty of great web applications that go unnoticed by many people due to the lack of user interaction. As developers, it's our responsibility to build a simple and interactive user management process, as visitors decide whether to stay on or leave a website by looking at the complexity of initial tasks such as registration and login.

In this chapter, we will be mainly concentrating on adapting existing user management functionalities into typical web applications. In order to accomplish our goal, we will execute some tasks outside the box to bring user management features from WordPress core to WordPress themes.

While striving to build a better user experience, we will also take a look at someadvanced aspects of web application development such as routing, controlling, and custom templating.

In this chapter, we will cover...

Introduction to user management

Usually, popular PHP development frameworks such as Zend, CakePHP, CodeIgniter, and Laravel don't provide a built-in user module. Developers tend to build their own user management modules and use it across many projects of the same framework. WordPress offers a built-in user management system to cater to common user management tasks found in web applications. Such things include the following:

  • Managing user roles and capabilities
  • A built-in user registration functionality
  • A built-in user login functionality
  • A built-in forgot password functionality

Developers are likely to encounter these tasks in almost all web applications. In most cases, these features and functions can be effectively used without significant changes in the code. However, web applications are much more advanced and hence, we might need various customizations on these existing features. It's important to explore the possibility of extending these functions in order to be compatible...

Getting started with user roles

In simple terms, user roles define the types of users in a system. WordPress offers built-in functions for working with every aspect of user roles. In this section, we will look at how we can manage these tasks by implementing the user roles for our application. We can create a new user role by calling the add_role function. The following code illustrates the basic form of user role creation:

$result = add_role( 'role_name', 'Display Name', array( 'read' => true, 'edit_posts' => true, 'delete_posts' => false ) );

The first parameter takes the role name, which is a unique key to identify the role. The second parameter will be the display name, which will be shown in the admin area. The final parameter will take the necessary capabilities of the user role. You can find out more about existing user roles at http://codex.wordpress.org/Roles_and_Capabilities. In this scenario, read, edit_posts, and delete_posts...

Understanding user capabilities

Capabilities can be considered as tasks, which users are permitted to perform inside the application. A single user role can perform many capabilities, while a single capability can be performed by many user roles. Typically, we use the term access control for handling capabilities in web applications. Let's see how capabilities work inside WordPress.

Creating your first capability

Capabilities are always associated with user roles and hence, we cannot create new capabilities without providing a user role. Let's look at the following code for associating custom capability with a follower user role, created in the earlier section, Creating application user roles:

public function add_application_user_capabilities(){
  $role = get_role( 'follower' );
  $role->add_cap( 'follow_developer_activities' );
}

First, we need to retrieve the user role as an object using the get_role function. Then, we can associate new or existing capability...

Registering application users

An administration panel is built into the WordPress framework, allowing us to log in through the admin screen. Therefore, we have a registration area, which can be used to add new users by providing a username and e-mail. In web applications, registration can become complex, compared to the simple registration process in WordPress. Let's consider some typical requirements of web application registration process in comparison with WordPress:

  • User-friendly interface: An application can have different types of user roles. Until registration is completed, everyone is treated as a normal application user with the ability to view public content. Typically, users are used to seeing fancy registration forms inside the main site rather than a completely different login area such as with WordPress. Therefore, we need to explore the possibilities of adding WordPress registration to the frontend.
  • Requesting detailed information: Most web applications will have at least...

Implementing frontend registration

Fortunately, we can make use of the existing functionalities to implement registration from the frontend. We can use a regular HTTP request or AJAX-based technique to implement this feature. In this book, I will focus on a normal process instead of using AJAX. Our first task is to create the registration form in the frontend.

There are various ways to implement such forms in the frontend. Let's look at some of the possibilities as described in the following section:

  • Shortcode implementation
  • Page template implementation
  • Custom template implementation

Now, let's look at the implementation of each of these techniques.

Shortcode implementation

Shortcodes are the quickest way to add dynamic content to your pages. In this situation, we need to create a page for registration. Therefore, we need to create a shortcode that generates the registration form, as shown in the following code:

add_shortcode( "register_form", "display_register_form&quot...

Introduction to user management


Usually, popular PHP development frameworks such as Zend, CakePHP, CodeIgniter, and Laravel don't provide a built-in user module. Developers tend to build their own user management modules and use it across many projects of the same framework. WordPress offers a built-in user management system to cater to common user management tasks found in web applications. Such things include the following:

  • Managing user roles and capabilities

  • A built-in user registration functionality

  • A built-in user login functionality

  • A built-in forgot password functionality

Developers are likely to encounter these tasks in almost all web applications. In most cases, these features and functions can be effectively used without significant changes in the code. However, web applications are much more advanced and hence, we might need various customizations on these existing features. It's important to explore the possibility of extending these functions in order to be compatible with advanced...

Getting started with user roles


In simple terms, user roles define the types of users in a system. WordPress offers built-in functions for working with every aspect of user roles. In this section, we will look at how we can manage these tasks by implementing the user roles for our application. We can create a new user role by calling the add_role function. The following code illustrates the basic form of user role creation:

$result = add_role( 'role_name', 'Display Name', array( 'read' => true, 'edit_posts' => true, 'delete_posts' => false ) );

The first parameter takes the role name, which is a unique key to identify the role. The second parameter will be the display name, which will be shown in the admin area. The final parameter will take the necessary capabilities of the user role. You can find out more about existing user roles at http://codex.wordpress.org/Roles_and_Capabilities. In this scenario, read, edit_posts, and delete_posts will be the capabilities while true and false...

Understanding user capabilities


Capabilities can be considered as tasks, which users are permitted to perform inside the application. A single user role can perform many capabilities, while a single capability can be performed by many user roles. Typically, we use the term access control for handling capabilities in web applications. Let's see how capabilities work inside WordPress.

Creating your first capability

Capabilities are always associated with user roles and hence, we cannot create new capabilities without providing a user role. Let's look at the following code for associating custom capability with a follower user role, created in the earlier section, Creating application user roles:

public function add_application_user_capabilities(){
  $role = get_role( 'follower' );
  $role->add_cap( 'follow_developer_activities' );
}

First, we need to retrieve the user role as an object using the get_role function. Then, we can associate new or existing capability using the add_cap function...

Left arrow icon Right arrow icon
Download code icon Download Code

Description

This 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.

Who is this book for?

This 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 28, 2015
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781782174394
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 28, 2015
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781782174394
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 153.97
WordPress Search Engine Optimization- Second Edition
$49.99
WordPress 4.0 Site Blueprints (Second Edition)
$48.99
WordPress Web Application Development - Second Edition
$54.99
Total $ 153.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. WordPress as a Web Application Framework Chevron down icon Chevron up icon
2. Implementing Membership Roles, Permissions, and Features Chevron down icon Chevron up icon
3. Planning and Customizing the Core Database Chevron down icon Chevron up icon
4. Building Blocks of Web Applications Chevron down icon Chevron up icon
5. Developing Pluggable Modules Chevron down icon Chevron up icon
6. Customizing the Dashboard for Powerful Backends Chevron down icon Chevron up icon
7. Adjusting Theme for Amazing Frontends Chevron down icon Chevron up icon
8. Enhancing the Power of Open Source Libraries and Plugins Chevron down icon Chevron up icon
9. Listening to Third-party Applications Chevron down icon Chevron up icon
10. Integrating and Finalizing the Portfolio Management Application Chevron down icon Chevron up icon
11. Supplementary Modules for Web Development Chevron down icon Chevron up icon
A. Configurations, Tools, and Resources Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(2 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
D. Stevenson Aug 08, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is awesome. It walks through building a web application on top of WordPress. I tried a few other books that I thought covered the same topic. This one was by far the best I have read on using WordPress as a web application. I actually came back to Amazon to order the print version because I want a paper copy for reference (I previously bought the kindle version).
Amazon Verified review Amazon
ab85 Aug 12, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book covers web app development using WordPress, anything from theme structure to advanced custom post types to working with APIs on the front end. The book shows that WordPress is way more than simple blogging platform or CMS, it can be used as a backend or platform to build web applications.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.