Skip to:
Content
Pages
Categories
Search
Top
Bottom

Subforum Function Stopped Working


  • TreeTrail
    Participant

    @aprilschmitt27

    Hello,

    My Versions:
    WP 5.7.2
    bbPress 2.6.6
    BuddyPress 8.0.0

    HOME

    This custom function stopped working fully when bbPress changed tables from usermeta to postmeta. Particularly, new users are no longer automatically subscribed to subforums. (We don’t use Groups yet, so I don’t know if that works or not.) Any help would be very greatly appreciated!

    /** GROUP AND FORUM SUBSCRIPTIONS
    * SUBSCRIBE NEW USERS TO GROUPS AND FORUMS
    * This critical code subscribes new users to BuddyPress Groups and bbPress Forums,
    * according to corresponding xProfile interest registration user choices!
    * “Add to BuddyPress groups and forums (including sub-forums) based on xProfile checkbox selection”
    * “add-to-buddypress-groups-based-on-xprofile-selection-upon-activation.php”
    * Author: Harsha Venkatesh (“Greathmaster”, formerly of Paid Memberships Pro)
    */

    //Subscribe a user to a group
    function my_bp_core_activated_user($user_id)
    {

    $groups = array(2 => “HIKING”,
    3 => “PADDLING”,
    4 => “CYCLING”,
    5 => “SKIING”,);

    $forums = array(“HIKING” => 7142,
    “PADDLING” => 7145,
    “CYCLING” => 7147,
    “SKIING” => 7066);

    $selected_groups = xprofile_get_field_data(‘149’, $user_id);

    if(!empty($selected_groups))
    {
    foreach($groups as $group_id => $group_name)
    {
    if(in_array($group_name, $selected_groups))
    {
    groups_join_group($group_id, $user_id );
    //bbp_add_user_forum_subscription( $user_id, $forums[$group_name] );
    subscribe_to_forums($user_id, $forums[$group_name]);
    }
    }
    }

    $overall_group_id = 1;
    $overall_forum_id = 7133;

    groups_join_group($overall_group_id, $user_id );
    //bbp_add_user_forum_subscription( $user_id, $overall_forum_id);
    subscribe_to_forums($user_id, $overall_forum_id);
    }

    //Subscribe a user to a forum and it’s sub forums
    function subscribe_to_forums($user_id, $forum_id)
    {
    //subscribe to the parent forum
    bbp_add_user_forum_subscription( $user_id, $forum_id);

    //subscribe to sub forums (if they exist)
    if (bbp_get_forum_subforum_count( $forum_id ) > 0)
    {
    $sub_forums = bbp_forum_get_subforums($forum_id);

    foreach($sub_forums as $sub_forum)
    {
    bbp_add_user_forum_subscription( $user_id, $sub_forum->ID);
    }
    }
    }

    function my_init()
    {
    add_action(‘bp_core_activated_user’, ‘my_bp_core_activated_user’,15, 1);
    }

    add_action(‘init’, ‘my_init’);

    ~end

  • You must be logged in to reply to this topic.
Skip to toolbar