• Resolved [email protected]

    (@thimmsdgmxde)


    Hello,

    first of: thanks for providing this plugin and the support here in the forum! I’m using version 8.9 of the plugin to allow subscriptions to my blog. I have it configured to send twice daily digests. Now I’ve been debugging the scripts trying to figure out what is going wrong – none of my subscribers have received updates for my recent posts, while all seemed fine in the past. Sending a preview works, just like sending manual messages works.
    Debugging led me to the following: the digest fails to send because it finds no subscribers. This in turn seems to be the case because the new posts are in a new category which did not exist at the time of subscription and thus no user seems to have an active subscription on. Now either I need to know a best practice, or I’ve been mishandling the configuration.

    My use case is as follows:
    I run a travel blog where registered users can read and subscribe. For each of my travels I create a new category that contains all posts specifically written for that trip. My subscribers have been subscribed for a year or two now.
    I’m looking to achieve:

    1. user chooses subscribe yes/no in general
    2. Administrator handles categories, by default users are subscribed to all categories

    Question:
    What do I need to do so that users are subscribed to the new categories? I found the setting ‘Compulsory Categories’ but from the mail I saw after activating it, it looked as if those users which are not subscribed to receive updates (see below) also receive notification.
    Then I looked into my account setting (“Your Subscriptions”). It only shows ‘Receive periodic summaries of new posts’ but no options to register or deregister for specific categories. But in turn I assume this to be the switch that I should respect so that not all users receive mail if they do not want to.
    Then I looked into the plugin settings and found ‘Option for Registered Users to auto-subscribe to new categories is checked by default’, which is activated. But still, I don’t know where I could even see or change this setting for a specific user?

    Can you please help me with any of the following:

    • Where to force-activate the option to automatically subscribe new categories for all users?
    • How to add the newly created category to the users’ current subscribed categories – it appears that toggling the ‘Receive periodic…’ seems to do that.

    And in all cases I still wish to allow the users an overall disabling of the digest mails.

    Thanks so much for your insight!
    Best regards,
    Rouven

    https://www.ads-software.com/extend/plugins/subscribe2/

Viewing 3 replies - 1 through 3 (of 3 total)
  • @rouven,

    I think you may have identified an area where the code can be improved.

    Making the category compulsory will indeed send emails to all Registered Users including those who have currently opted out.

    To fix this have a look in classes/class-s2-admin.php and find the new_category() function. As you’ll hopefully see, if a new category is added at the moment and you are in digest mode, this is no action is taken. Actually, what should probably happen is to add the new category to any opted in user.

    I’ve removed these lines:

    // don't subscribe to individual new categories if we are doing digest emails
    if ( $this->subscribe2_options['email_freq'] != 'never' ) { return; }
    global $wpdb;

    And replaced them with this:

    global $wpdb;
    if ( $this->subscribe2_options['email_freq'] != 'never' ) {
    	// if we are doing digests add new categories to users who are currently opted in
    	$sql = $wpdb->prepare("SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE meta_key=%s AND meta_value<>''", $this->get_usermeta_keyname('s2_subscribed'));
    	$user_IDs = $wpdb->get_col($sql);
    	foreach ( $user_IDs as $user_ID ) {
    		$old_cats = get_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), true);
    		$old_cats = explode(',', $old_cats);
    		$newcats = array_merge($old_cats, (array)$new_category);
    		update_user_meta($user_ID, $this->get_usermeta_keyname('s2_cat') . $new_category, $new_category);
    		update_user_meta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $newcats));
    	}
    	return;
    }

    That seems to work for me. Provided you can find the ID for any new categories you can use this same code to add the category id to the database entries for existing users too.

    Thread Starter [email protected]

    (@thimmsdgmxde)

    Hey there,

    thanks for the quick answer. Indeed, your fix works in my environment as well. I have created and removed a new category and a probe into the database table has produced the subscription settings I would have expected. I will now fire a series of statements to make sure that I get the current subscribers linked to the new category and then I should be fine.

    Many thanks again!

    Best regards,
    Rouven

    @rouven,

    Excellent, I’m glad it worked. Thanks for confirming this as a fix and thank you also for the donation you made.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘No digest – subscribers not subscribed to new categories’ is closed to new replies.