mycred_sell_expire_calc

Codex / mycred/content / Filters / mycred_sell_expire_calc

Navigation:

  1. Description
  2. Used By
  3. Parameters
  4. Example

Description

By default, myCRED allows you to let purchases expire after a certain number of hours. This filter lets you change this calculation from hours to any other time measurement. If you use this filter you should also consult the mycred_sell_exp_title filter.

Remember! The returned number is added to the purchase time and compared to see if it is still in the future (purchase valid) or if that time has passed (purchase expired). For this reason the value you return must be in seconds.

Requires the Sell Content Add-on to be enabled.

 

Used By

  • Class: myCRED_Sell_Content Method: purchase_has_expired()

 

Parameters

  • expire (int)
    The number of seconds in which the content expires. Defaults to length x 3600 seconds.
  • length (int)
    The expiration length. For example 1 hour or 30 days.
  • user_id (int)
    The user who is purchasing the content.
  • post_id (int)
    The post id.

 

Example

Instead of Hours, use Days.

// Adjust calculation
add_filter( 'mycred_sell_expire_calc', 'adjust_expiration_length', 10, 4 );
function add_sitename_before_email_subject( $expire, $length, $user_id, $post_id )
{
	// Length x seconds in a day
	return abs( $length*86400 );
}
// Update title
add_filter( 'mycred_sell_exp_title', 'adjust_expiration_length_title' );
function adjust_expiration_length_title() { return 'Days'; }

Add this code to your themes functions.php file or in your plugin.

Last edited June 26, 2016