Hi. Using my first instance of the Website Membership plugin in conjunction with the Website Comments plugin and am stuck here...

1) The site has a forum accessible only by Website Membership users.

2) Users can post a new topic to the "topics" table. After a topic is submitted, Website Membership members can view the topic and post comments or subscribe to comment updates.

3) If a member posts a new topic, they are not automatically subscribed to that topic for receiving the email comment updates. The person would need to review their own post and click the subscribe link. I don't think most people would think to do this, and think they'll want/expect to receive an email alert when comments to their topic were made by other users.

Is there a way that I can set up the "topics" form submission to automatically subscribe that Website Membership user to Website Comments for that topic?

Deborah

Hi Deborah, 

Sounds like you have website membership, website comment AND a forum? 

How's it all built and who build it (was it us?) and how does it all work together?

Whatever the mechanism is for "subscribing" to a topic (not sure if that's in the forum or comments) it should be possible with a few lines of custom code to have a user automatically "subscribe" to the topic they just created.  You'd just need to call whatever code gets run as when they normally click on the subscribe link.

Let me know some more details and I'll try to help and/or point you in the right direction.

Thanks!

Dave Edis - Senior Developer
interactivetools.com

Hi Deborah, 

That's really great.  Ok, so obviously it's a lot of custom code and outside of what we typically support, but let's see if we can find something that will work for you.  

If you look in websiteComments.php there's a few functions that apply to subscriptions:

  • wsc_thread_isSubscribed($tableOrTag, $recordNum); // check if current user is subscribed to this thread
  • wsc_thread_subscribe();

wsc_thread_subscribe() is what we want, but it redirects and does some other things, but I can see that it calls _wsc_thread_subscribe() which looks like this:

// subscribe current user to current comment thread
function _wsc_thread_subscribe($tableOrTag, $recordNum) {
  global $CURRENT_USER;

  // subscribe user (if not already subscribed)
  $isSubscribed = wsc_thread_isSubscribed($tableOrTag, $recordNum);
  if (!$isSubscribed) {
    mysql_insert('_wsc_subscribers', array(
      'createdDate=' => 'NOW()',
      'userNum'      => $CURRENT_USER['num'],
      'tableOrTag'   => $tableOrTag,
      'recordNum'    => $recordNum,
    ));
  }
}

Now, we use a leading _ in function names to indicate it's a "private" function not intended to be called externally.  But you can call it, we just can't guarantee it won't change in future (but it probably won't).

But basically, if you can get these values:

  • tableOrTag - usually a form value in $_REQUEST['_wsc_tableOrTag']
  • recordNum - usually a form value in $_REQUEST['_wsc_recordNum']

Then you could just call the function after getting the new thread record num.

So adding that to you code might look like this (untested):

// add record
if (!@$errorsAndAlerts) {
mysql_query("INSERT INTO `{$TABLE_PREFIX}topics` SET
title            = '".mysql_real_escape_string( $_REQUEST['title'] )."',
content          = '".mysql_real_escape_string( $_REQUEST['content'] )."',
fullname         = '".mysql_real_escape_string( $_REQUEST['fullname'] )."',
usernum          = '".mysql_real_escape_string( $_REQUEST['usernum'] )."',
createdDate      = NOW(),
updatedDate      = NOW(),
createdByUserNum = '0',
updatedByUserNum = '0'")
    or die("MySQL Error Creating Record:<br>\n". htmlspecialchars(mysql_error()) . "\n");
    $recordNum = mysql_insert_id();

 // subscribe user to thread they just created
  $tableOrTag = "determine what this should be?"; 
 _wsc_thread_subscribe($tableOrTag, $recordNum);


 // display thanks msg, clear form
    $errorsAndAlerts = "Thanks, we've added that topic!";
    $_REQUEST = array();
  }
}

But you've got another table 'topics' in your setup, so you may need to create a new comment on the topic first.  Have a look at the code in wsc_comments_addRecord() for how to go about that.

Hope that helps!  Let me know any questions and if any of that information can get you any further.

Dave Edis - Senior Developer
interactivetools.com

Dave, your reply took some time for me to work through, but in the end, I've accomplished my goal! (And on a Friday... yes!)

This tip you provided was crucial:

But you've got another table 'topics' in your setup, so you may need to create a new comment on the topic first.  Have a look at the code in wsc_comments_addRecord() for how to go about that.

The relationships between CMSB, Website Membership, and Website Comments wasn't easy to figure out at first, but it is a complex and powerful relationship, in the end. This is my first install of Website Comments and I am impressed!

Your guidance was invaluable...thanks so much!

~ Deborah