Filter uncanny-toolkit-pro

group_forum_widget_li

Filters the permalink for a group forum widget list item, allowing modification of the link before it's displayed.

add_filter( 'group_forum_widget_li', $callback, 10, 3 );

Description

Filters the permalink for a forum displayed in the group forum widget. Allows developers to modify the link for individual forums based on forum, group, or user context, providing custom navigation or tracking.


Usage

add_filter( 'group_forum_widget_li', 'your_function_name', 10, 3 );

Parameters

$permalink (mixed)
The permalink to the forum.
$forum (mixed)
The permalink to the specific forum within a group.
$group_id (mixed)
This parameter contains the forum object being iterated over within the widget.

Return Value

The filtered value.


Examples

add_filter( 'group_forum_widget_li', 'my_custom_group_forum_widget_li', 10, 4 );

/**
 * Customizes the HTML output for individual forum links in the group forum widget.
 *
 * This example adds a class to the list item if the current user is an administrator.
 *
 * @param string $li_html The default HTML for the list item.
 * @param WP_Post $forum The WP_Post object for the forum.
 * @param int $group_id The ID of the group the forum belongs to.
 * @param int $current_user_id The ID of the currently logged-in user.
 * @return string The modified HTML for the list item.
 */
function my_custom_group_forum_widget_li( $li_html, $forum, $group_id, $current_user_id ) {
	if ( user_can( $current_user_id, 'manage_options' ) ) {
		// Add a custom class to the list item for administrators
		$li_html = str_replace( '<li>', '<li class="admin-forum-link">', $li_html );
	}
	return $li_html;
}

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/includes/class-forum-group-widget.php:82

public function widget( $args, $instance ) {

		$user_forums = get_user_forum_group_access();

		$widget_content = '<div class="ld-group-forum-links-wrapper">';
		$widget_content .= '<h2 class="widget-title">' . $instance['title'] . '</h2>';
		$widget_content .= '<ul>';

		foreach ( $user_forums as $forum_id => $group_id ) {
			$forum = get_post( $forum_id );

			if ( $forum ) {
				$permalink      = get_the_permalink( $forum_id );
				$widget_content .= apply_filters( 'group_forum_widget_li', '<li><a href="' . $permalink . '">' . $forum->post_title . '</a></li>', $forum, $group_id, get_current_user_id() );
			}
		}

		$widget_content .= '</ul>';
		$widget_content .= "</div>";

		echo $args['before_widget'];
		if ( ! empty( $title ) ) {
			echo $args['before_title'] . $title . $args['after_title'];
		}

		echo $widget_content;
		echo $args['after_widget'];
	}

Scroll to Top