Help in code modification
-
Hello all,
I wanted to seek help in modifying the following piece of code. I have a site with buddypress groups inside which I have bbpress forums for the respective groups. I want the users of the group to be automatically subscribed to the forums within that group. I tried the following code:
add_filter( 'bbp_get_user_subscribe_link', 'invert_get_user_subscribe_link', 10, 4 ); //invert forum subscription add_filter( 'bbp_is_user_subscribed_to_forum', 'invert_is_user_subscribed_to_forum', 10, 4 ); //invert forum subscription add_filter( 'bbp_get_forum_subscribers', 'invert_get_forum_subscribers' ); //invert forum subscription add_filter( 'bbp_is_user_subscribed', 'invert_is_user_subscribed', 10, 4 ); //invert forum subscription function invert_is_user_subscribed($retval, $user_id, $object_id, $subscribed_ids) { if (get_post_type( $object_id ) == bbp_get_forum_post_type()) return !$retval; else return $retval; } function strContains($needle, $haystack) { if (strpos($haystack, $needle) !== false) { return true; } else { return false; } } function invert_get_user_subscribe_link ($html, $r, $user_id, $topic_id) { if (strContains( "bbp_unsubscribe", $html )) { $html = str_replace("bbp_unsubscribe", "bbp_subscribe", $html); } else { $html = str_replace("bbp_subscribe", "bbp_unsubscribe", $html); } return $html; } function invert_get_forum_subscribers( $users ) { $args = array('fields' => 'id'); $all_users = get_users($args); $send_to_users = array_diff($all_users, $users); return $send_to_users; } function invert_is_user_subscribed_to_forum( $retval, $user_id, $forum_id, $subscribed_ids ) { return !$retval; }
But there is a problem. Using the following code leads to the user getting subscribed to all the forums of all the groups (even those which they aren’t a part of). I just want them to be automatically subscribed to those forum topics created inside the group which they are a part of. Kindly help me in getting this right.
Thanks!
- You must be logged in to reply to this topic.