wpsharks / s2member

s2Member® Framework (membership management for WordPress®).
64 stars 36 forks source link

Feature Request: Modification Form for Free Memberships #797

Open KTS915 opened 8 years ago

KTS915 commented 8 years ago

I am building a site that will have three levels of members (i.e. subsciber, s2member_level1, and s2member_level2), all of which will be free. There’s no problem with creating the necessary free registration forms, but there is no form for modifying a free membership.

Obviously, s2Member was created with the idea that members would go from free to paid, but this additional option would be very nice to have. Thanks for considering!

jaswrks commented 8 years ago

@KTS915 Thanks for the feature request.

but there is no form for modifying a free membership

So for instance, let's say that I sign up for a free membership and later I want to make a change. Can you give me an example of what modification would be needed? i.e., one that it not already covered by the [s2Member-Profile /] shortocode or an upgrade to paid status.

I'd love to hear about any example use cases for this. Thanks!

KTS915 commented 8 years ago

@jaswsinc,

Yes, what I'm looking for is a way to modify a role. That can't be done with the [s2Member-Profile /] shortcode. And, since none of the roles on this site will involve payment, a billing modification form won't do the trick either.

The different roles will simply allow the member to choose different types and frequency of notifications.

jaswrks commented 8 years ago

Copy that. Thank you! :-)

While you're waiting on this, you might find this KBA helpful. https://s2member.com/kb-article/rolescapabilities-via-php/

KTS915 commented 8 years ago

Yes, I'd seen that. But that means doing it programmatically, rather than by specific member input.

Thanks!

KTS915 commented 8 years ago

After some Googling and trial and error, this is what I have come up with:

<?php
// Change Role Form
function kts_change_role_form() {
    if( is_user_logged_in() && is_page('change-membership-preferences') ) {
        $current_user = wp_get_current_user();
        $user_id = $current_user->id;
        $old_role = $current_user->roles[0];
        if( $_POST['role']){
            if( $_POST['role'] == $old_role ) {
                $label = S2MEMBER_CURRENT_USER_ACCESS_LABEL;
                echo "<red>No change has been made because you have already chosen to " . $label . ".</red><br>";
            } else {
                $new_role = $_POST['role'];
                $userdata = array();
                $userdata['ID'] = $user_id;
                $userdata['role'] = $new_role;
                wp_update_user($userdata);
                if ( $new_role == "subscriber" ) {
                    echo "<green>Your membership has been changed so that you will now just be able to leave comments.</green><br>";
                } else if ( $new_role == "s2member_level1" ) {
                    echo "<green>Your membership has been changed so that you will now be notified of new posts, but not of members’ comments.</green><br>";
                } else if ( $new_role == "s2member_level2" ) {
                    echo "<green>Your membership has been changed so that you will now be notified of both new posts and members’ comments.</green><br>";
                }
            }
        }
    ?>

        <form method="post" action="">
            <strong>Choose which type of membership you would prefer:</strong><br/>
            <select name="role">
                <option value="subscriber" selected="I just want to be able to leave comments.">I just want to be able to leave comments.</option>
                <option value="s2member_level1">Please notify me of new posts.</option>
                <option value="s2member_level2">Please notify me of both new posts and members’ comments.</option>
            </select>
            <input type="submit" name="submit" value="Submit" />
        </form>

    <?php
    }
}

// change form shortcode
function kts_shortcode(){
    ob_start();
    tsk_change_role_form();
    return ob_get_clean();
}
add_shortcode( 'kts_contact_form', 'kts_shortcode' );

Then I can just add the shortcode [kts_contact_form] to a page called Change Membership Preferences. Just to make sure I don't lock myself out, I have also placed this shortcode between conditionals, so that it now looks like this:

[s2If !current_user_is(administrator)] [kts_contact_form] [/s2If]