bbp_add_user_subscription help
-
I am trying to make a single page where users can choose to subscribe or unsubscribe to their forums (see https://bbpress.org/forums/topic/manage-subscriptions/). I’m pretty new to php/java, so please excuse me if this is obvious.
Basically, I have 3 forums (79, 80, 81). I have a button for each forum. When the user clicks a button, I use AJAX to run a php script. The php script is used to either subscribe or unsubscribe the user depending on whether they are already subscribed or not.
My problem is that when a user is subscribed, I’m not able to remove their subscription, and vice versa. When I click a subscribe button, the php code executes, it is able to determine if the user is subscribed, and the if statement executes properly. My problem is that bbp_add_user_subscription and bbp_remove_user_subscription return false every time.
Any help is greatly appreciated. The PHP and java script are below.
<?php if (isset($_POST[‘action’])) { $forum = $_POST[‘action’]; $forumint = 0 + $forum; $subs=bbp_is_user_subscribed_to_forum($user_id,$forum); if($subs==false) { //if user not subscribed, then subscribe $add=bbp_add_user_subscription($user_id,$forumint); } else { $rmv=bbp_remove_user_subscription($user_id,$forumint); //do_action(‘bbp_remove_user_subscription’, $user_id, $forumint) } echo ‘forum ‘; var_dump ($forum); echo ‘subscribed ‘; var_dump ($subs); echo ‘add ‘; var_dump ($add); echo ‘remove ‘; var_dump ($rmv); echo ‘foruminteger ‘; var_dump ($forumint); exit; } ?> <?php <!– initiate all buttons –> <button id=”790″ class=”button” onclick=”Subscriber(‘790’)”>Subscribe</button><br><br> <button id=”800″ class=”button” onclick=”Subscriber(‘800’)”>Subscribe</button><br><br> <button id=”810″ class=”button” onclick=”Subscriber(‘810’)”>Subscribe</button><br><br> <!– change button text on load based on user subscription –> <script> $( document ).ready(function() { $( “.button” ).click(function() { var ForumID = $(this).attr(“id”)/10; $.ajax({ //url: ”, // url is empty because I’m working in the same file data: {‘action’: ForumID}, type: ‘post’, success: function(result) { alert(“action performed successfully”); //this alert is fired $(‘div#result’).text(‘Button clicked: ‘ + result); } }); }); }); </script>
- You must be logged in to reply to this topic.