Page 1 of 1

Allow membership and ccaps by email domain

PostPosted: May 16th, 2011, 12:56 pm
by earthliz
Is it possible for s2Member to automatically grant a user access to specific custom capabilities by email domain?

So for example: We sell levels of membership to companies and universities - and give their employees individual access to the custom capabilities that they've paid for. So, we often receive emails about new employees or ones who don't yet have access to the site, and we have to go in and tweak all their settings. But they all have the same email address (firstname.lastname@company.com) - so it would save a lot of steps if s2member could recognize @company.com and just grant the appropriate access.

Any ideas? Thanks.

Liz

Re: Allow membership and ccaps by email domain

PostPosted: May 16th, 2011, 1:09 pm
by Cristián Lávaque
This is a great idea, Liz! Thanks!

I'll forward your suggestion to Jason (the Lead Developer of s2Member) to consider it, and maybe suggest how it could be done in the current s2Member. :)

Re: Allow membership and ccaps by email domain

PostPosted: May 18th, 2011, 1:29 am
by Jason Caldwell
Thanks for a great suggestion.

I'm not sure if we'll be able to address that specific need as a formal feature ( but we'll try ). We DO have plans to improve Custom Capabilities ( work is in progress now, could be another release or two away though ).

In the mean time, you could do something like this.
Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
Code: Select all
<?php
add_action 
("init", "custom_capabilities_by_domain", 1);
function custom_capabilities_by_domain ()
    {
        if (is_user_logged_in () && current_user_can ("access_s2member_level1") && ($user = wp_get_current_user ()))
            {
                if (stripos ($user->user_email, "@company-a.com") !== false)
                    $user->add_cap ("access_s2member_ccap_company_a");
            }
    }
?>
* This code is untested, but should work fine.