Below, you’ll find a detailed guide on how to add the Pmpro Bbpress Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Pmpro Bbpress Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Pmpro Bbpress Plugin and the shortcodes it provides:
"bbPress Restrict Membership Forum & Private Replies for Members Only with Paid Memberships Pro is a plugin that enhances forum privacy. It restricts forum access and private replies to paid members only, ensuring exclusivity and privacy."
- [bbp-user-activity]
Pmpro Bbpress [bbp-user-activity] Shortcode
The pmpro-bbpress plugin shortcode ‘bbp-user-activity’ displays the recent activity of a user. It shows topics or replies made by a specific or current user, with options to show date, excerpt, and title.
Shortcode: [bbp-user-activity]
Parameters
Here is a list of all possible bbp-user-activity shortcode parameters and attributes:
activity_type
– determines the type of activity to display, either ‘topic’ or ‘reply’.bbp_user_id
– specifies the user ID whose activities will be displayed.count
– sets the number of entries that will be shown.show_date
– if set to true, the date of the entries will be displayed.show_excerpt
– if set to true, an excerpt of the entry will be shown.title
– allows you to set a custom title for the activity display.
Examples and Usage
Basic example – Showcases the user activity with default parameters.
[bbp-user-activity]
Advanced examples
Displays the user activity of a specific user by referencing the user ID. The activity type is set to ‘reply’ and it will show the most recent 10 entries. The entry date and an excerpt of the entry will also be displayed, and the title is set as ‘User 1 Activity’.
[bbp-user-activity activity_type="reply" bbp_user_id="1" count="10" show_date="true" show_excerpt="true" title="User 1 Activity"]
Displays the user activity with the activity type set to ‘topic’. It will show the most recent 7 entries without the entry date or an excerpt of the entry. The title is set as ‘My Recent Topics’.
[bbp-user-activity activity_type="topic" count="7" show_date="false" show_excerpt="false" title="My Recent Topics"]
PHP Function Code
In case you have difficulties debugging what causing issues with [bbp-user-activity]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('bbp-user-activity', 'bbp_user_activity_shortcode');
Shortcode PHP function:
function bbp_user_activity_shortcode($atts, $content = null) {
global $current_user;
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// examples: [bbp-user-activity activity_type="topic" show_date="true" title="My Recent Topics"]
extract(shortcode_atts(array(
'activity_type' => 'topic', //set to topic or reply
'bbp_user_id' => $current_user->ID, //can set attribute to a specific user ID or omit for the current_user
'count' => 5, //number of entries to show
'show_date' => false, //optionally show the entry date
'show_excerpt' => false, //optionally show an excerpt of the entry
'title' => 'My Recent Activity', //an optional title, h2 class="widgettitle" format
), $atts));
$shortcode_query = new WP_Query( array(
'post_type' => $activity_type,
'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
'posts_per_page' => (int) $count,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'author' => $bbp_user_id,
) );
// Bail if no replies
if ( ! $shortcode_query->have_posts() ) {
return;
}
$r = '<div class="widget widget_display_topics">';
$r .= '<h2 class="widgettitle">' . __($title, 'pmprobb') . '</h2>';
$r .= '<ul>';
while ( $shortcode_query->have_posts() ) : $shortcode_query->the_post();
$r .= '<li>';
// Verify the reply ID
$reply_id = bbp_get_reply_id( $shortcode_query->post->ID );
$reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url( $reply_id ) ) . '" title="' . esc_attr( bbp_get_reply_excerpt( $reply_id, 50 ) ) . '">' . bbp_get_reply_topic_title( $reply_id ) . '</a>';
if ( ! empty( $show_excerpt ) ) :
$r .= esc_attr( bbp_get_reply_excerpt( $reply_id, 50 ) ) . ' ';
endif;
// Reply link and timestamp
if ( ! empty( $show_date ) ) :
// translators: 1: reply link, 2: reply timestamp
$r .= sprintf(_x( '%1$s %2$s', 'widgets', 'bbpress' ), $reply_link, '<em>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</em>');
// Only the reply title
else :
// translators: 1: reply link
$r .= sprintf(_x( '%1$s', 'widgets', 'bbpress' ), $reply_link);
endif;
$r .= '</li>';
endwhile;
$r .= '</ul>';
$r .= '</div>';
// Reset the $post global
wp_reset_postdata();
return $r;
}
Code file location:
pmpro-bbpress/pmpro-bbpress/includes/shortcodes.php
Conclusion
Now that you’ve learned how to embed the Pmpro Bbpress Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply