• Resolved dave9621

    (@dave9621)


    I have a site that we’re using a few different roles, administrator, editor, subscriber and substitute. We want Subscribe2 to EXCLUDE the users with the “substitute” role. Is this possible? Can you point me in the right direction? Thanks.

    https://wordpress.org/plugins/subscribe2/

Viewing 7 replies - 1 through 7 (of 7 total)
  • mattyrob

    (@mattyrob)

    @dave9621,

    Yes, this is possible with a little bit of code, you need to remove these subscribers from the list of recipient emails collected by the plugin using these filters:
    s2_send_plain_excerpt_subscribers
    s2_send_plain_fullcontent_subscribers
    s2_send_html_excerpt_subscribers
    s2_send_html_fullcontent_subscribers

    They are documented here:
    http://subscribe2.wordpress.com/support/api/

    Thread Starter dave9621

    (@dave9621)

    Thanks for your reply. I’ve looked over the documentation and I’m a bit confused on how this works. I’m by no means a PHP pro, I know enough to edit and be dangerous I guess. What is the PHP file I need to edit? what happens when an email is sent, will my client be given a choice what what “roles” get the emails? I’m sorry I’m not knowledgeable on how the API works. Any help would be greatly appreciated. Thanks.

    mattyrob

    (@mattyrob)

    @dave9621,

    What is the PHP file I need to edit?

    The best way is to create your own plugin in WordPress. Pluginception is great for first time attempts as it create the outline file for you. This will ensure your changes are preserved on plugin and theme updates.

    What happens for your client depends on what code you write but presenting choices probably isn’t wise or useful. Agree with your client what roles that want included in the email and write code so that emails only send to those users and exclude all other roles.

    Thread Starter dave9621

    (@dave9621)

    I’ll look into Pluginception, thanks. But we’re 99% of the way there with your plugin, it’s up and running and we only want to tweak it so that someone that has a role of “substitute” does not get the email. That’s it. If I can do that we’ll be all set. Starting from scratch by creating a new plugin seems like the long way around, no?

    mattyrob

    (@mattyrob)

    @dave9621,

    Starting from scratch by creating a new plugin seems like the long way around, no?

    Not really. You are altering the way Subscribe2 is intended to work for a specific client. You could edit the core Subscribe2 files but you’d need to make these changes every time a new version of Subscribe2 is released and finding the right part of the code, changing it and testing it will probably take longer than creating a mini-plugin. The plugin you need shouldn’t be much more 10 lines of code so maybe 20 lines in total including the header.

    Thread Starter dave9621

    (@dave9621)

    Thanks for your direction. I’m working with a colleague and I think we’re almost there. He said it looks like the email list is built from the function:

    function get_registered($args = ”)

    If so, all we need is the query clause to ignore the role, something like

    $AND .= ” AND role <> ‘subscriber’ “;

    Could you tell us what that line would look like, to skip any user with that role?
    Thanks for your help!

    mattyrob

    (@mattyrob)

    @dave9621,

    You are making this harder than it needs to be, use the get_users() function in WordPress:

    $args = array(
        'role' => 'subscriber',
        'fields' => array('user_email')
    );
    $subscriber_level = get_users($args);

    Then use the filters I directed you to above and array_diff() the $subscribers list passed with the above to remove all Subscriber level recipients.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Is it possible to send emails to users with a specific role?’ is closed to new replies.