WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe Others to Comments? (5 posts)

  1. arickrol
    Member
    Posted 6 years ago #

    I have Subscribe to Comments 2.1.2 installed on my WP 2.3.3 blog. It works great. However, I'd like to know if it is possible for me, as an admin, to subscribe others to comments.

    I have users who need help with some things, such as this, and having the capability to do the subscription for them would help a lot.

    If this is possible how do I do it?

    http://wordpress.org/extend/plugins/subscribe-to-comments/

  2. arickrol
    Member
    Posted 6 years ago #

    Bumping this up in the hope that someone has an answer to this.

  3. greg57
    Member
    Posted 6 years ago #

    Bumping too... I'm interested.

  4. mshowman
    Member
    Posted 6 years ago #

    Do you want your users to have comment notifications on all posts or just certain posts?

    I was able to accomplish all posts by creating a new column in the wordpress _users table.
    I basically just "duplicated" the comment_subscribe column from the wordpress _comments table and put it in the _users table.

    Then in the plugin code, which you can edit from the plugins page in the dashboard (I would suggest backing up the original code before editing), there is a function send_notifications that calls another function subscriptions_from_post. I duplicated that function (function subscriptions_from_post) and changed it from this:

    function subscriptions_from_post($postid) {
    		if ( is_array($this->post_subscriptions[$postid]) )
    			return $this->post_subscriptions[$postid];
    		global $wpdb;
    		$postid = (int) $postid;
    		$this->post_subscriptions[$postid] = $wpdb->get_col("SELECT comment_author_email FROM $wpdb->comments WHERE comment_post_ID = '$postid' AND comment_subscribe='Y' AND comment_author_email != '' AND comment_approved = '1' GROUP BY LCASE(comment_author_email)");
    		$subscribed_without_comment = (array) get_post_meta($postid, '_sg_subscribe-to-comments');
    		$this->post_subscriptions[$postid] = array_merge((array) $this->post_subscriptions[$postid], (array) $subscribed_without_comment);
    		$this->post_subscriptions[$postid] = array_unique($this->post_subscriptions[$postid]);
    		return $this->post_subscriptions[$postid];
    	}

    to this:

    function subscriptions_from_users($postid) {
    		if ( is_array($this->post_subscriptions[$postid]) )
    			return $this->post_subscriptions[$postid];
    		global $wpdb;
    		$postid = (int) $postid;
    		$this->post_subscriptions[$postid] = $wpdb->get_col("SELECT user_email FROM $wpdb->users WHERE comment_subscribe='Y' AND user_email != '' GROUP BY LCASE(user_email)");
    		$subscribed_without_comment = (array) get_post_meta($postid, '_sg_subscribe-to-comments');
    		$this->post_subscriptions[$postid] = array_merge((array) $this->post_subscriptions[$postid], (array) $subscribed_without_comment);
    		$this->post_subscriptions[$postid] = array_unique($this->post_subscriptions[$postid]);
    		return $this->post_subscriptions[$postid];
    	}

    (don't forget to change the function that is called in function send_notifications)

    $subscriptions = $this->subscriptions_from_post($comment->comment_post_ID);

    to

    $subscriptions = $this->subscriptions_from_users($comment->comment_post_ID);

    Now when a comment is posted, it looks for comment_subscribe column to be 'Y' in the _users table and then pulls the user(s)'s email address(es) from the same row(s) so now it sends emails to any users that have comment_subscribe = 'Y'

    If you want to choose which posts the users receive comments from you could create a new table called _comment_notifications with columns "comment_post_ID", "users_email" and "comment_subscribe". Then you can insert a row in the new _comment_notifications table with the user's email, post ID, and then set the comment_subscribe to 'Y' or 'N'. Now for the function you could call something like this:

    function subscriptions_from_comment_notifications($postid) {
    		if ( is_array($this->post_subscriptions[$postid]) )
    			return $this->post_subscriptions[$postid];
    		global $wpdb;
    		$postid = (int) $postid;
    		$this->post_subscriptions[$postid] = $wpdb->get_col("SELECT users_email FROM $wpdb->comment_notifications WHERE comment_post_ID = '$postid' AND comment_subscribe='Y' AND users_email != '' GROUP BY LCASE(users_email)");
    		$subscribed_without_comment = (array) get_post_meta($postid, '_sg_subscribe-to-comments');
    		$this->post_subscriptions[$postid] = array_merge((array) $this->post_subscriptions[$postid], (array) $subscribed_without_comment);
    		$this->post_subscriptions[$postid] = array_unique($this->post_subscriptions[$postid]);
    		return $this->post_subscriptions[$postid];
    	}

    (don't forget to change the function that is called in function send_notifications)

    Now notifications will be sent to any user you have inserted into the new table _comment_notifications with comment_subscribe set to 'Y'

  5. arickrol
    Member
    Posted 5 years ago #

    Thank you for your help with this. What you said is honestly beyond me but I'm going to see if any of my friends understand it.

    I've noticed that people leave comments on my blog and forget about them. Having the ability to subscribe them to their own comments would be helpful. This way they will receive a notice when I, or someone else, posts a comment replying to their comment.

Topic Closed

This topic has been closed to new replies.

About this Topic