learndash_users_groups_profile_title
Filters the title displayed on the LearnDash user profile's groups section.
add_filter( 'learndash_users_groups_profile_title', $callback, 10, 1 );
Description
Filters the title for the "LearnDash Groups" section on user profiles. Developers can change this title to customize the display. Fires after the default "LearnDash Groups" title is set, allowing for dynamic alterations.
Usage
add_filter( 'learndash_users_groups_profile_title', 'your_function_name', 10, 1 );
Parameters
-
$section_title(mixed) - This parameter contains the current title for the LearnDash Groups section on the user profile.
Return Value
The filtered value.
Examples
// Change the title of the "LearnDash Groups" section on the user profile page.
add_filter( 'learndash_users_groups_profile_title', 'my_custom_learndash_groups_profile_title', 10, 1 );
/**
* Custom function to modify the LearnDash Groups section title on the user profile.
*
* @param string $section_title The original section title.
* @return string The modified section title.
*/
function my_custom_learndash_groups_profile_title( $section_title ) {
// Example: Append a suffix to the default title.
$new_title = $section_title . ' (Managed)';
return $new_title;
}
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/learndash-group-user-profile.php:97
public static function show_users_groups_profile_fields( $user ) {
global $wpdb;
// title of section
$section_title = esc_html__( 'LearnDash Groups', 'uncanny-learndash-toolkit' );
// User ID of user being viewed/edited
$user_ID = $user->ID;
$groups = learndash_get_users_group_ids( $user_ID );
// If the user is part of at least one group... lets create the LearnDash Group Section
if ( ! empty( $groups ) ) {
// Happy Filtering!
$section_title = apply_filters( 'learndash_users_groups_profile_title', $section_title );
// Loop through all the user's group ids and collect the title and link
$list_groups = '';
foreach ( $groups as $group_ID ) {
if ( ! empty( $group_ID ) && is_numeric( $group_ID ) ) {
$group_permalink = add_query_arg(
array(
'post' => (int) $group_ID,
'action' => 'edit',
), admin_url( 'post.php' )
);
$group_title = get_the_title( (int) $group_ID ); // Get the group title
$list_groups .= sprintf( '<li><a href="%s">%s</a></li>', esc_url( $group_permalink ), esc_html( $group_title ) );// list of all the groups
}
}
?>
<table class="form-table">
<tbody>
<tr>
<th>
<h3><?php echo esc_html( $section_title ); ?></h3>
</th>
<td>
<ol>
<?php echo $list_groups; ?>
</ol>
</td>
</tr>
</tbody>
</table>
<?php
}
}