Support » Plugins and Hacks » Email Users » mailusers_get_roles() function to use the core get_editable_roles( )

  • Resolved Justin Fletcher

    (@justinticktock)


    Is there a chance that you can change the mailusers_get_roles() function to use the core get_editable_roles( ) function?

    Iโ€™d like to use email-users but I donโ€™t want to open up all the site roles/groups to users who just have the email_user_groups capability if they shouldn’t be able to see a particular role. The standard WordPress get_editable_roles( ) function allows for roles to be excluded from users and it would be great if email-users could take advantage of this flexibility.

    The current function mailusers_get_roles looks like this ..

    function mailusers_get_roles( $exclude_id='', $meta_filter = '') {
    	$roles = array();
    
    	$wp_roles = new WP_Roles();
    	foreach ($wp_roles->get_names() as $key => $value) {
    		$users_in_role = mailusers_get_recipients_from_roles(array($key), $exclude_id, $meta_filter);
    		if (!empty($users_in_role)) {
    			$roles[$key] = $value;
            }
    	}
    
    	return $roles;
    }

    I suggest this..

    function mailusers_get_roles( $exclude_id='', $meta_filter = '') {
    	$roles = array();
    
    	$wp_roles = get_editable_roles( );
    	$wp_roles['roles'] = $wp_roles;
    
    	foreach ($wp_roles as $key => $values) {
    		$users_in_role = mailusers_get_recipients_from_roles(array($key), $exclude_id, $meta_filter);
    		if (!empty($users_in_role)) {
    			$roles[$key] = $values['name'];
            }
    	}
    
    	return $roles;
    }

    https://wordpress.org/plugins/email-users/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is there any uptake on this?

    It would really help flexibility and would not change functionality for the installed base until sites start to use the core filter
    add_filter( 'editable_roles', 'my_custom_filter' );

    The core get_editable_roles() honours the editable_roles filter. So it would be great if email-users could take advantage of this so that certain roles could be filtered out as necessary from those selectable within the groups to email.

    Plugin Author Mike Walsh

    (@mpwalsh8)


    I have added this feature to Email Users. If you’d like to test it out, you can download Email Users v4.7.1-beta-1 from my web site.

    That’s awesome I’ll test it out tomorrow ๐Ÿ™‚

    Mike,

    Tested through and the beta version works great for working with editable_roles. Got a little tide up with the settings statement..”Only the groups having at least one user that accepts group mails appear here.” functionality but its working.

    I plan to add email-users as a suggested plugin of https://wordpress.org/plugins/role-based-help-notes/ with only the group-emails selectable for roles/help-notes that have been allocated to a user.

    I’ll keep watching for when you publish formally here. ๐Ÿ™‚

    Plugin Author Mike Walsh

    (@mpwalsh8)


    Thanks for testing it out and reporting back. If you have a suggestion for better wording I am happy to change it.

    you can remove the line..
    $wp_roles['roles'] = $wp_roles;

    its unnecessary, not sure what I was thinking off ;-). So what I have now is…

    function mailusers_get_roles( $exclude_id='', $meta_filter = '') {
    	$roles = array();
    
    	$wp_roles = get_editable_roles( );
    
    	foreach ($wp_roles as $key => $value) {
    		$users_in_role = mailusers_get_recipients_from_roles(array($key), $exclude_id, $meta_filter);
    		if (!empty($users_in_role)) {
    			$roles[$key] = $value['name'];
            }
    	}
    
    	return $roles;
    }
    Plugin Author Mike Walsh

    (@mpwalsh8)


    This change, plus a few others is now in 4.7.1-beta-2.

    Thanks for the release.

    I’ve just released the Role Based Help Notes version 1.4 which makes use of this feature in email-users. Very helpful Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘mailusers_get_roles() function to use the core get_editable_roles( )’ is closed to new replies.