Access Granted - Action hook

Introduced in Version 1.4

A new action hook has been added at the time of access being granted 

rup_sell_ind_posts_access_granted

This new action hook passes the following variables:

  1. user_id
  2. post_id
  3. order_id
  4. price_id
Note: This is triggered the first time access is granted to a post. If they reorder and already have access, it won't fire again to prevent multiple events for the same post and user. It is designed for removing access to a post after a given set of time, i.e a non-subscription event

Use Case:

You want to use WP cron to remove access after, say, 30 days from your use.r This can be achieved using a code snippet being triggered by that action hook. An example of that code is below

<?php
add_action( 'rup_sell_ind_posts_access_granted', 'rup_schedule_access_removal', 10, 1 );
function rup_schedule_access_removal( $payload ) {
// now everything is self-documenting:
$user_id = $payload['user_id'];
$post_id = $payload['post_id'];
$order_id = $payload['order_id'];
$price_id = $payload['price_id'];
 
rup_sell_ind_posts_log_debug(
sprintf(
'Scheduling removal &mdash; user_id: %d, post_id: %d, order_id: %s, price_id: %s',
$user_id, $post_id, $order_id, $price_id
)
);
 
if ( ! wp_next_scheduled( 'rup_remove_access_event', [ $user_id, $post_id ] ) ) {
wp_schedule_single_event(
time() + 30 * DAY_IN_SECONDS,
'rup_remove_access_event',
[ $user_id, $post_id ]
);
}
}

You will then get your Cron array looking like this 

In the above case, user 1 will get their access revoked to post 38 on the 24th May 2025

You can also use the plugin action method in automators such as flowmattic to automatically do this using a custom delay or to do something else using this information, i.e store it in a table.. The data received by this action hook in Flowmattic would look like the below

Post Access Subscriptions are now available in the alpha release of 1.5
Subscriptions & Cron Expiry can not be used together on he same site. Cron expiry will remove subscribers' access after the allotted period, regardless of their subscription status. If you are offering subscriptions, their access will be removed on cancellation or expiry, so Cron expiry isn't needed

 


Was this article helpful?