ld_topic_access_from__visible_after_specific_date
Filters whether a lesson topic is visible after a specific date based on user and topic IDs.
add_filter( 'ld_topic_access_from__visible_after_specific_date', $callback, 10, 3 );
Description
Filters the visibility of a LearnDash topic based on a specific date. Developers can use this hook to dynamically control when a topic becomes accessible to a user, potentially based on user enrollment date, course start date, or other custom logic. The original return value determines if the topic is visible.
Usage
add_filter( 'ld_topic_access_from__visible_after_specific_date', 'your_function_name', 10, 3 );
Parameters
-
$visible_after_specific_date(mixed) - This parameter holds the calculated visibility status of the topic based on a specific date, which can be modified by the filter.
-
$topic_id(mixed) - This parameter contains a mixed value representing a specific date after which the topic should become visible, or null if no such restriction exists.
-
$user_id(mixed) - This parameter represents the unique identifier of the specific topic being checked.
Return Value
The filtered value.
Examples
add_filter(
'ld_topic_access_from__visible_after_specific_date',
'my_custom_topic_access_logic',
10,
3
);
/**
* Customizes topic access based on a specific future date.
*
* This function allows you to override the default behavior of the
* 'ld_topic_access_from__visible_after_specific_date' hook. It checks if the
* current time is before the specified 'visible_after_specific_date' for a
* LearnDash topic and, if so, returns that date as the timestamp from which
* access should be granted.
*
* @param int $visible_after_specific_date The timestamp representing the specific date after which the topic should be visible.
* @param int $topic_id The ID of the LearnDash topic.
* @param int $user_id The ID of the user.
*
* @return int|null The timestamp for topic visibility if the condition is met, otherwise null.
*/
function my_custom_topic_access_logic( $visible_after_specific_date, $topic_id, $user_id ) {
// In this example, we'll add an extra day if the user is a premium member.
// Replace with your actual custom logic.
// Assume we have a function to check for premium membership.
if ( function_exists( 'is_user_premium_member' ) && is_user_premium_member( $user_id ) ) {
// Add an extra day to the visibility date for premium members.
$modified_visible_after = $visible_after_specific_date + ( DAY_IN_SECONDS ); // DAY_IN_SECONDS is a WordPress constant for 86400 seconds.
return $modified_visible_after;
}
// If no custom logic applies, return the original value.
return $visible_after_specific_date;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/uncanny-drip-topics-by-group.php:738
public static function ld_topic_access_from_inherited_from_ld( $topic_id, $user_id, $course_id = null ) {
$return = null;
if ( is_null( $course_id ) ) {
$course_id = learndash_get_course_id( $topic_id );
}
$courses_access_from = ld_course_access_from( $course_id, $user_id );
if ( empty( $courses_access_from ) ) {
$courses_access_from = learndash_user_group_enrolled_to_course_from( $user_id, $course_id );
}
$visible_after = learndash_get_setting( $topic_id, 'visible_after' );
if ( $visible_after > 0 ) {
// Adjust the Course acces from by the number of days. Use abs() to ensure no negative days.
$topic_access_from = $courses_access_from + abs( $visible_after ) * 24 * 60 * 60;
$topic_access_from = apply_filters( 'ld_topic_access_from__visible_after', $topic_access_from, $topic_id, $user_id );
$current_timestamp = time();
if ( $current_timestamp < $topic_access_from ) {
$return = $topic_access_from;
}
} else {
$visible_after_specific_date = learndash_get_setting( $topic_id, 'visible_after_specific_date' );
if ( ! empty( $visible_after_specific_date ) ) {
if ( ! is_numeric( $visible_after_specific_date ) ) {
// If we a non-numberic value like a date stamp Y-m-d hh:mm:ss we want to convert it to a GMT timestamp
$visible_after_specific_date = learndash_get_timestamp_from_date_string( $visible_after_specific_date, true );
}
$current_time = time();
if ( $current_time < $visible_after_specific_date ) {
$return = apply_filters( 'ld_topic_access_from__visible_after_specific_date', $visible_after_specific_date, $topic_id, $user_id );
}
}
}
return $return;
}