January 31, 2021

Extend Your DAP Membership Site Functionality – Using WordPress Action Hooks!

Share this

What are WordPress Hooks?

WordPress hooks allow you to modify or add features to WordPress without touching the core files. Using hook functions, you can get WordPress to execute your custom code,  registered via a callback function, at different points. WordPress will allow you to augment or replace the feature that your callback is hooked to!

There are two types of hooks: Actions and Filters. To use either, you need to write a custom function known as a callback, and then register it with a WordPress hook for a specific action or filter.

Now you can Modify/Add Functionality without Updating Core DAP Files

Action hooks will allow you add your own custom code at certain predefined points. This way you can modify or add features to DAP without touching the core DAP files. 

DAP is already a pretty powerful membership plugin and you'll likely not have a need to extend it with custom code. However, if you want to extend certain feature or functionality, you can now do it easily, without updating core DAP files.

You can add custom callback code in your theme's functions.php file or use a plugin (such as code snippets) to add your callback. 

Please note that this document is a developer reference provided as a courtesy. Our support policy does not include customizations.

If you need any help with customizations, you can hire a developer to help you with it. If you need our help, just open a ticket and we'll let you know the cost of custom updates. 

Courses

Gamification

Registration / Purchase Events


Subscription Hooks

Name: dap_subscription_product_access

When is it triggered:

This is triggered after a user receives access to a subscription/membership level. DAP will first give user access to the subscription product, and then you can get DAP to execute your custom code. 

Parameters

$user_id
$product_id
$order_id

Example

add_action ( 'dap_subscription_product_access', 'dap_actions_subscription_access', 10, 3 );

function dap_actions_subscription_access ( $user_id, $product_id, $order_id ) {

include_once "PathToDAP/dap-config.php";
// your code
$product = Dap_Product::loadProduct( $product_id );
$name = $product->getName();
$user = Dap_User::loadUserById ( $user_id );
$email = $user->getEmail();
}

Name: dap_user_cancelled_subscription

When is it triggered:

This is triggered when users cancel their active subscription or when they request a subscription cancellation (depending on your DAP configuration).

Parameters

$order (array)

Example

add_action ( 'dap_user_cancelled_subscription', 'dap_actions_subscription_cancellation', 10, 1 );

function dap_actions_subscription_cancellation (  $order  )  {

include_once "PathToDAP/dap-config.php";
$productId = $order["productId"];
$recurringId = $order["recurringId"];
$paymentProcessor = $order["paymentProcessor"];
$transNum = $order["transNum"];
$reason = $order["cancelReason"];
$type = $order["cancelType"];

$product = Dap_Product::loadProduct ( $product_id );
$productName = $product->getName();
if ( $user_id != "" ) {
$user = Dap_User::loadUserById ( $user_id );
$email = $user->getEmail();
}
if (  ( $type =="self_cancel" ) || ( $type =="self_cancel_with_reason"  ) ) { //already cancelled }
else { // requested cancellation}
}

Name: dap_user_paused_subscription

When is it triggered:

This is triggered after users pause their active subscription

Parameters

$user_id
$product_id
$recurring_profile_id
$dap_order_number

Example

add_action( 'dap_user_paused_subscription', 'dap_actions_subscription_paused', 10, 4);

function dap_actions_subscription_paused( $user_id, $product_id, $recurring_profile_id, $dap_order_number )  {

  include_once "PathToDAP/dap-config.php";
  $product = Dap_Product::loadProduct ( $product_id );
  $productName = $product->getName();
  if ( $user_id != "" ) {
    $user = Dap_User::loadUserById ( $user_id );
   $email = $user->getEmail();
   }

Name: dap_user_resumed_subscription

When is it triggered:

This is triggered after users resumes their paused subscription

Parameters

$user_id
$product_id
$recurring_profile_id
$dap_order_number

Example

add_action( 'dap_user_resumed_subscription', 'dap_actions_subscription_resumed', 10, 4);

function dap_actions_subscription_resumed ( $user_id, $product_id, $recurring_profile_id, $dap_order_number )  {
  include_once "PathToDAP/dap-config.php"; 

  $product = Dap_Product::loadProduct ( $product_id );
  $productName = $product->getName();
  if ( $user_id != "" ) {
    $user = Dap_User::loadUserById ( $user_id );
   $email = $user->getEmail();
   }

Course Hooks

Name: dap_user_completed_lesson

When is it triggered:

This is triggered when a user clicks on the mark as complete button to complete the lesson.

Parameters

$user_id
$course_id
$module_id
$lesson_id

Example

add_action( 'dap_user_completed_lesson', 'dap_action_lesson_completed', 10, 4);

function dap_action_lesson_completed ( $user_id, $course_id, $module_id, $lesson_id  )  {

  include_once "PathToDAP/dap-config.php";
  $product = Dap_Product::loadProduct ( $course_id );
  $productName = $product->getName();
  if ( $user_id != "" ) {
    $user = Dap_User::loadUserById ( $user_id );
   $email = $user->getEmail();
   }

   if($lesson_id!="") {
       $lessonObj = Dap_FileResource::getResourceName  ( $lesson_id );
       if ( isset ( $lessonObj ) ) {
          $lessonName = $lessonObj['name'];
         $lessonURL = $lessonObj['url'];
       }
   }  

Name: dap_user_completed_module

When is it triggered:

This is triggered when a user complete all lessons in a module.

Parameters

$user_id
$course_id
$module_id
$lesson_id

Example

add_action( 'dap_user_completed_module', 'dap_action_module_completed', 10, 4);

function dap_action_module_completed ( $user_id, $course_id, $module_id, $lesson_id  )  {

  include_once "PathToDAP/dap-config.php";
  $product = Dap_Product::loadProduct ( $product_id );
  $productName = $product->getName();
  if ( $user_id != "" ) {
    $user = Dap_User::loadUserById ( $user_id );
   $email = $user->getEmail();
   }

   if ( isset ( $module_id ) ) {
    $moduledata = DAP_CourseModule::loadById ( $module_id );
    if ( isset ( $moduledata ) ) {
        if ( $course_id != "" ) {
            $product = Dap_Product::loadProduct ( $course_id );
            $courseName = $product->getName();
         }
        $module_name = $moduledata->getModuleName();
    }

    if ( $lesson_id != "" ) {
       $lessonObj = Dap_FileResource::getResourceName  ( $lesson_id );
       if ( isset ( $lessonObj ) ) {
          $lessonName = $lessonObj['name'];
         $lessonURL = $lessonObj['url'];
       }
    }  

Name: dap_user_completed_course

When is it triggered:

This is triggered when a user completes a course.

Parameters

$user_id
$course_id

Example

add_action( 'dap_user_completed_course', 'dap_action_course_completed', 10, 2);

function dap_action_course_completed ( $user_id, $course_id ) {
if ( $course_id != "" ) {

  include_once "PathToDAP/dap-config.php";
  $product = Dap_Product::loadProduct ( $course_id );
  $courseName = $product->getName();
  $user = Dap_User::loadUserById ( $user_id );
  $email = $user->getEmail();
}
}

Name: dap_user_lesson_time_spent

When is it triggered:

This is triggered when a user completes a lesson. It'll tell you how much time your users are spending on each lesson.

Parameters

$userCourseProgressObj 

Example

add_action( 'dap_user_lesson_time_spent', 'dap_action_lesson_time_spent', 10, 1);

function dap_action_lesson_time_spent ( $userCourseProgressObj  ) {
if ( isset ( $userCourseProgressObj  )  )  {

  include_once "PathToDAP/dap-config.php";
  $course_id = $userCourseProgressObj->getProductId();
  $module_id = $userCourseProgressObj->getModuleId();
  $lesson_id = $userCourseProgressObj->getUnitId();

  $initial_time = $userCourseProgressObj->getInitialTimeSpent();
  $total_time = $userCourseProgressObj->getTotalTimeSpent();
  $start_date = $userCourseProgressObj->getStartDate();
  $end_date = $userCourseProgressObj->getDate();
}

if($lesson_id!="") {
  $lessonObj = Dap_FileResource::getResourceName($lesson_id);
  if(isset($lessonObj)) {
    $lessonName=$lessonObj['name'];
    $lessonURL=$lessonObj['url'];
  }
}

}

Name: dap_user_earned_certificate

When is it triggered:

This is triggered when a user earns a certificate after completing a course

Parameters

$userCourseProgressObj 

Example

add_action ( 'dap_user_earned_certificate', 'dap_action_earned_certificate', 10, 2);

function dap_action_user_earned_certificate ( $user_id, $course_id ) {
if ($course_id != "" ) {

include_once "PathToDAP/dap-config.php";
$product = Dap_Product::loadProduct ( $course_id );
$courseName = $product->getName();
$user = Dap_User::loadUserById ( $user_id );
$email = $user->getEmail();
}
}

Gamification Hooks

Name: dap_user_has_earned_badge

When is it triggered:

This is triggered when a user earns a badge by completing a certain task 
(based on your configuration in our GameOfPoints.com plugin).

Parameters

$user_id
$badge_id
$product_id
$category 

Example

add_action( 'dap_user_has_earned_badge', 'dap_action_earned_badge' , 10, 4);

function dap_action_earned_badge ( $user_id, $badge_id, $product_id, $category ) {

include_once "PathToDAP/dap-config.php";
if ( $product_id != "" ) {
  $product = Dap_Product::loadProduct ( $product_id );
  $productName = $product->getName();
  $user = Dap_User::loadUserById ( $user_id );
  $email = $user->getEmail();
}
}

Name: dap_user_earned_course_points

When is it triggered:

This is triggered when a user earns points by completing your course.

Parameters

$user_id
$course_id
$points

Example

add_action( 'dap_user_earned_course_points', 'dap_action_earned_course_points', 10, 3 );

function dap_action_earned_course_points ( $user_id, $course_id, $points )  {
if ( $course_id != "" ) {

  include_once "PathToDAP/dap-config.php";
  $product = Dap_Product::loadProduct ( $course_id );
  $courseName = $product->getName();
  $user = Dap_User::loadUserById ( $user_id );
  $email = $user->getEmail();
}
}

Name: dap_user_earned_lesson_points

When is it triggered:

This is triggered when a user earns points by completing lessons in your course.

Parameters

$user_id
$course_id
$lesson_id
$points

Example

add_action( 'dap_user_earned_lesson_points', 'dap_action_earned_lesson_points', 10, 4);

function dap_action_earned_lesson_points ( $user_id, $course_id, $lesson_id, $points ) {
if ( $course_id != "" ) {

include_once "PathToDAP/dap-config.php";
$product = Dap_Product::loadProduct ( $course_id );
$courseName = $product->getName();
$user = Dap_User::loadUserById ( $user_id );
$email = $user->getEmail();
}
}

Registration / Purchase Hooks

Name: dap_free_product_access

When is it triggered:

This is triggered when a user signs up for your free product.

Parameters

$user_id
$product_id
$transaction_id

Example

add_action( 'dap_free_product_access', 'dap_actions_free_product_registration', 10, 3);

function dap_actions_free_product_registration ( $user_id, $product_id, $transaction_id) {

include_once "PathToDAP/dap-config.php";
$product = Dap_Product::loadProduct ( $product_id );
$productName = $product->getName();
$user = Dap_User::loadUserById ( $user_id );
$email = $user->getEmail();
}

Name: dap_onetime_product_access

When is it triggered:

This is triggered when a users purchases a one-off product.

Parameters

$user_id
$product_id
$transaction_id

Example

add_action( 'dap_onetime_product_access', 'dap_actions_onetime_product_access', 10, 3);

function dap_actions_onetime_product_access ( $user_id, $product_id, $transaction_id ) {

include_once "PathToDAP/dap-config.php";
$product = Dap_Product::loadProduct ( $product_id );
$productName = $product->getName();
$user = Dap_User::loadUserById ( $user_id );
$email = $user->getEmail();
}

Path to the DAP folder

Visit the URL below in a browser window (replace YourSite.com with your actual domain name):

https://YourSite.com/dap/getpath.php

This will show something like this in your browser:
/home/path/to/dap
This is your path to the DAP folder.

For e.g.:
include_once "PathToDAP/dap-config.php";

 // You can replace it with this path: 
include_once "/home/path/to/dap/dap-config.php";  

We've just gotten started with action hooks in DAP! We plan on adding a ton more action and filter hooks to this list. Stay tuned!


Membership Site in 30 Minutes!

Looking to build a membership site but feeling stressed about everything you need to do from content creation to the actual implementation, and not sure where to start?

Recently, we tested Digital Access Pass (DAP) on a new webhosting platform. We were able to fully setup and configure a DAP-powered membership site, with beautiful, elegant member-facing pages, in just 15 minutes!

Watch this video for a behind-the-scenes look at how to build a brand new membership site - with free products, paid products, membership levels, online courses, etc., quickly in just 30 minutes!


My Online Course Launch Strategy

The 3 main challenges that most people face when it comes to building and launching an online course: 

1. No list or small list.
2. Busy schedule.
3. Don't know how to put it all together, organize and deliver.


So I decided to create a FREE training video to show you the exact steps I follow to build my list, create and organize my course content, and the order in which I execute in every phase - from idea, planning, audience building, content creation, implementation to the actual launch.

No Audience? No List? No problem! 


FREE: Let's Build an Online Course

A-Z BlueprintFor Creating And Delivering A Wildly Successful Online Course!

In this FREE course, I've broken down the entire course creation process, from how to build an audience to how to create and launch a course, into easy-to-understand and implement steps.

Once your complete the course, you'll be able to build your own course confidently, without any stress or overwhelm!

Signup below to get instant access.


Need help with planning

 and implementation?

Done for YOU!

DAP is easy-to-use and setup. However, we also offer FREE 3 hours of one-on-one concierge calls with DAP's Elite License  (Monthly / Annual). We share our screen on the call so you can actually see and learn with us. 

The 3 hours of time can be used for membership site planning, brainstorm strategy and implementation.

So if you need a little extra help and don't have the time to figure it all out, we highly recommend the DAP Elite Package. Click on the button below to get started with the DAP Elite License. With all the plugins and extra help included in this package, there is no better investment for your business than this! 


Share with Friends & Followers

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"c162b":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"c162b":{"val":"var(--tcb-skin-color-0)"}},"gradients":[]},"original":{"colors":{"c162b":{"val":"rgb(19, 114, 211)","hsl":{"h":210,"s":0.83,"l":0.45,"a":1}}},"gradients":[]}}]}__CONFIG_colors_palette__
Previous Article
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"c162b":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"c162b":{"val":"var(--tcb-skin-color-0)"}},"gradients":[]},"original":{"colors":{"c162b":{"val":"rgb(19, 114, 211)","hsl":{"h":210,"s":0.83,"l":0.45,"a":1}}},"gradients":[]}}]}__CONFIG_colors_palette__
Next Article

Subscribe to our newsletter now!