Website Membership: auto-subscribe original posts

By Deborah - March 13, 2015

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?


By Dave - March 17, 2015

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.


Dave Edis - Senior Developer

By Deborah - March 17, 2015

Dave, Everything I'm referring to is being built (so far, just by me) with CMSB and the two plugins, Website Membership (WM) and Website Comments (WC).

The Members Area of the site is only accessible to WM members.

Once logged in, the member can view general content or visit the forum.

Inside the Forum area:

  • There is a list of previously created forum post titles. The titles link to a detail page with the full post, display of any comments, and the WC comment form.
  • The original forum posts are submitted via a form that writes to the 'topics' table. (See attached PHP file.) This form is only used for posting a NEW topic.
  • The member viewing a post can comment, subscribe/unsubscribe (WC plugin).
  • When a member comments on a post (WC plugin), they are automatically subscribed via email to future post updates.

What I'm challenged with is that when the member starts a new topic (using the attached form), I would like them to be automatically subscribed to comments (comments made via the WC plugin).

I hope I'm describing that well enough. I'm really excited to have gotten this far along with building this!

~ Deborah


submit-new-topic.php 3K

By Dave - March 20, 2015

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