[e-Newsletter] Disable unsubscibe for particular membergroup

Hi,
We let users (un)subscibe for certain member-groups. But there is 1 member-group where we don't want the user to be able to unsubscribe. They always have to be subscribed to that group so they will receive all emails being sent to that group.
We allready removed the unsubscribe link in the newsletters which we mail to that group. But when a registered user is visiting his dashboard he can select "Unsubscribe all" or just uncheck the checkbox for that group.
How can we make sure they cannot unsubscribe for that group?
When searching the forum I noticed more people would appreciate such an option. Perhaps it's an idea for the developers to add a Yes or No radio-button with the text "May user unsubscribe this group?" when the admin is making a new member-group.

With kind regards,
Age

  • Predrag Dubajic
    • Support

    Hi Age,

    I'm afraid that something like this is not possible with e-Newsletter directly but with a bit of coding we should be able to make it happen.

    We can hide the Unsubscribe from all with some simple CSS and we need a bit of JS to remove the specific category.
    This code should do the trick:

    <?php
    function hide_my_group() { ?>
    
    	<script type="text/javascript">
    		jQuery( document ).ready(function() {
    		  jQuery("label:contains('hideme')").remove();
    		});
    	</script>
    
    	<style type="text/css">
    		#unsubscribe {display: none;}
    	</style>
    <?php }
    add_action( 'admin_head', 'hide_my_group');

    All you need to change in that code is text from "hideme" to the name of the group that you want to hide.

    Now go to wp-content/mu-plugins folder on your server (if you don't have one create it yourself) and inside that folder create a PHP file with any name you want, for example newsletter-hide-group.php.
    Paste the code inside that file, save it and that should be it.

    Hope this helps.

    Best regards,
    Predrag

  • jongag1
    • The Crimson Coder

    Hi,

    Sorry but I had to reopen this ticket.

    The code is working to good :slight_smile: because now we are not able to send out a newsletter to that particular group.

    A solution probably is that the code isn't executed for an user who has the rights to send out newsletters (in our case admin and a separate newsletter user-role).

    Is that possible?

    Gr, Age

  • Adam Czajczyk
    • Support Gorilla

    Hi jongag1

    The code that Predrag shared shouldn't affect the ability to send newsletters. By "we are not able to send out" you mean that this group doesn't even show up on a group list to select when you're trying to send newsletter? Or that you can select it but the mail doesn't go out?

    Have you confirmed that removing the code fixes it?

    Finally, would you mind enabling support access to the site so I could take a look? You can do this by going to the "WPMU DEV -> Support" page in your site's back-end and clicking on "Grant support access" button. I'll check the site and I'm pretty sure we'll be able to "work things out" :slight_smile:

    Best regards,
    Adam

  • jongag1
    • The Crimson Coder

    Hi Adam,

    Yes when the file as 'active' we can't select the hidden group. Other groups can be selected.

    Yes, I 'deactivated' the file so we were able to send out the newsletter and than the group showed up.

    Access is granted. The file is now active.

    Gr, Age

  • Predrag Dubajic
    • Support

    Hi jongag1,

    Can you try replacing the code with this one:

    <?php
    function hide_my_group() { 
    
    	if( !is_admin() ) { ?>
    
    		<script type="text/javascript">
    			jQuery( document ).ready(function() {
    			  jQuery("label:contains('hideme')").remove();
    			});
    		</script>
    
    		<style type="text/css">
    			#unsubscribe {display: none;}
    		</style>
    
    <?php }
    }
    add_action( 'admin_head', 'hide_my_group');

    I've added a condition to apply the code only for non-admin users so you shouldn't be affected while working on the plugin and its pages as an admin.

    Let us know if that does the trick.

    Best regards,
    Predrag

  • jongag1
    • The Crimson Coder

    Hello Predrag,

    Changed the code. Replaced 'hideme' into 'Verenigings info'.
    Now I can see "Verenigings info", but when I logged in as a subscriber I also see it...

    If I need to extend support access please let me know.
    Greetings, Age

  • jongag1
    • The Crimson Coder

    Hi Adam and Predrag,

    First thanks again for helping!
    And yes, that last change is working!

    I have 1 final question regarding this topic. I created an extra user-role (with User Role Editor plugin) for people to send out newsletters. But I don't want them to be able to mail the excluded group. I named the role "Send Newsletters (send_newsletters)"

    If I replace
    if ( !current_user_can( 'administrator' ) ) {
    with something like
    if ( !current_user_can( 'administrator') || !current_user_can( 'send_newsletters') ) {
    will that do the trick?

    With kind regards, Age

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.