Skip to:
Content
Pages
Categories
Search
Top
Bottom

Favorites and subscription count


  • Azinfiro
    Participant

    @azinfiro

    I’m trying to find a way to display a given user’s raw subscription or favorites count in a fashion similar to how bbp_get_user_reply_count_raw() and bbp_get_user_topic_count_raw() work.

    I’ve tried to use an existing function like bbp_get_user_subscriptions() with a counter but I figure I need to query the database. I’m still learning PHP though so if anyone sees a way to do it like that then please let me know.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    what are you planning to count, topics, forums or both?

    and if you count a forum as subscribed, do you want to count all the topics within that forum as subscribed?

    the list of forums/topics subscribed to is held in usermeta under WP__bbp_subscriptions and an example would look like

    5682,13255,13098,13394,13456,13497,13550,13575,13636,13652,13669,13705,13750,13769,13620,14017,14222,14375,14469

    so it would count a forum and a topic each as 1.

    you could add a check to see which were topics and which forums and display separately.

    You’d access it using a function like

    
    $user_id = wp_get_current_user()->ID;
    $check=get_user_meta( $user_id, 'WP__bbp_subscriptions' ,false);
    some if statement here in case it's blank
    then set a counter to zero
    foreach ( $check as $count ) {
    increment the counter in here
    maybe one count if it's a topic and another if its a reply?
    }
    then carry on to a display
    

    Favorites are held in ‘WP__bbp_favorites’

    If you want some code to display the results, look at my topic count plugin

    http://wordpress.org/plugins/bbp-topic-count/

    Hope that’s sufficient to get you going to a solution, come back if you need more help

    Also in terms of bbPress users can look at other users favorites:

    e.g. http://bbpress.org/forums/profile/azinfiro/favorites/

    But you cannot see other users subscriptions, only your own:

    e.g. http://bbpress.org/forums/profile/azinfiro/subscriptions/

    You can see your subscriptions, I cannot, you want to take this into account when showing these counts wherever you are planning on doing this so users only see their own subscription counts.


    Azinfiro
    Participant

    @azinfiro

    Thank you for the quick, helpful reply. Sorry I didn’t get back to you sooner.

    I would like to count each subscribed forum and subscribed/favorite topic but not every topic within a subscribed forum, though with a few technical exceptions.

    In my case, WP__bbp_subscriptions and WP__bbp_favorites only output topics, not forums or the topics of a subscribed forum.

    Fortunately, I found three functions that provide either subscribed forum ids or subscribed/favorite topic ids separately, based on a user id:

    bbp_get_user_subscribed_topic_ids()
    bbp_get_user_subscribed_forum_ids()
    bbp_get_user_favorites_topic_ids()

    Here is my solution in the form of two custom functions. The above functions obviously made it all very simple:

    // display bbPress subscription count
    function user_subscriptions_count( $user_id = null ) {
    
    	$topic_count = count(bbp_get_user_subscribed_topic_ids($user_id));
    	
    	$forum_count = count(bbp_get_user_subscribed_forum_ids($user_id));
    	
    	echo  $forum_count + $topic_count ;
    }
    // display bbpress favorites count
    function user_favorites_count( $user_id = null ) {
    
    	echo count(bbp_get_user_favorites_topic_ids($user_id));
    }

    I do realize that a user’s subscribed forums and topics are usually private, but I prefer to check for permissions outside functions.

    Thanks for the help, I hope this might be useful for someone in the future.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.