I think my configuration for membership 2 pro plugin is all fouled up.

I have created a custom registration page and I am pointing to this page from the menu registration link. When I click on this link for users that are not logged in, they can see this page. However when a user hits a Protected Content page there is a link there for them to click on registration. This link takes them to a different registration page. This is a registration page generated by your plugin. How do I make changes to this link?

I am also having trouble with registered users not being able to access their protected content. The users have the correct membership role assigned to them and the pages have the correct membership role access assigned. The logged on user should be able to access the page but instead they are getting the protected content error message from the plugin.

One last thing, how do I modify the dynamic link generated from the plugin? For example in the Settings General panel for Registration I have a custom page assigned here. Now when I click the view page button it takes me to a link path of /register-3. Now if the user is logged on and they click on the register link it takes me to the membership list. I don't want this behavior so how can I change that?

Thanks,

Mike

  • Sajid

    Hi @Mike

    Hope you are doing good today and welcome to WPMUDEV :slight_smile:

    This is a registration page generated by your plugin. How do I make changes to this link?

    The easiest way to do this is by setting a 301 permanent redirect from default register page to your custom register page. You can do this by using Redirection plugin.

    I am also having trouble with registered users not being able to access their protected content. The users have the correct membership role assigned to them and the pages have the correct membership role access assigned. The logged on user should be able to access the page but instead they are getting the protected content error message from the plugin.

    I tested it out on my sandbox site quickly to make sure its not a bug but its seems to be working fine. I assume there might be plugin/theme/script that is interfering with Membership 2 protection rules. Run a quick plugin conflict test as illustrated in our getting support manual (flowchart).
    https://premium.wpmudev.org/manuals/using-wpmu-dev/getting-support/

    Clear the browser cache and cookies of the browser. Is it not working on a specific browser or on all browsers ?

    If its still not working then please grant support access so I can take a closer look and troubleshoot I will be activating/deactivating plugins/themes while troubleshooting. You can enable access by following steps mentioned in this manual.
    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    One last thing, how do I modify the dynamic link generated from the plugin?

    Do you want to change the slug "register-3"? If yes then click on edit page link under the option and change modify slug like you do in normal WordPress pages. You can also make some changes in content. Or create a new page and set that as register page from settings.

    Now when I click the view page button it takes me to a link path of /register-3. Now if the user is logged on and they click on the register link it takes me to the membership list. I don't want this behaviour so how can I change that?

    Its the default behaviour of Membership 2 plugin. It displays memberships to select and when you click on submit then it will show you registration page for not-logged users. If you want to force it to display registration page only then pass the query string in the URL to skip the memberships step and jump to registration. Now your URL will look like this:
    http://wptest.cp.crystalpoint.com/register-3?step=register

    For future reference please always post each question in separate ticket to get faster response and according to our forum posting rules.

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • Mike

    Hello Sajid,

    Thanks for your help.

    I have resolved other issues except for the logged in members not being able to access their content. I have followed your advice and deactivated all plugins except for membership 2 pro plugin and I am still having the same problem. I can't access the protected pages for registered members. I don't think it is a compatibility issue with other plugins as this is a new wordpress site and there isn't that many plugins in there. I have tried deleting and recreating the membership roles and re applying the Protection Rules and no luck either.

    When users reaches the website, they have to register with an active contract and login before they can access the protected content. In the registration page I have extra fields for contract number and serial number in addition to your regular fields that are used for a registration field. Now after user is registered with valid information they are then redirected to my custom login page. The user provides their username and password to login. In the back end the following functions are taking place:

    function custom_pre_submission3( $form ) {
    //take form values and call stored procedure to check if user has a valid contract for star support
    $serverName = "aServer";
    $uid = file_get_contents("C:\SQLUser\uid.txt");
    $pwd = file_get_contents("C:\SQLUser\pwd.txt");
    $connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"StartSupportDB");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    if( $conn === false )
    {
    // echo "Connection established.\n";
    $confirmation = "Connection could not be established. " + sqlsrv_errors();
    sqlsrv_close( $conn);
    $_POST['input_6'] = "false"; //update hidden field Contract_Valid
    $_POST['input_9'] = $confirmation; //update hidden field Error_Msg
    //echo "Connection could not be established.\n";
    //die( print_r( sqlsrv_errors(), true));
    }

    //-----------------------------------------------
    // Perform operations with connection.
    //-----------------------------------------------
    $tsql_callSP = '{call dbo.CheckContract(?, ?, ?, ?)}';

    $user = get_user_by( 'login', rgpost('input_7'));
    $userID = $user->ID;

    $contractNumber = $user->contract_number;
    $valid_Contract = $user->valid_contract;
    $serialNumber = $user->serial_number;
    $name = $user->first_name . ' ' . $user->last_name;
    $email = $user->user_email;
    $validContract = 3; //variable used to contain the value returned from the stored procedure

    $params = array(
    array($contractNumber, SQLSRV_PARAM_IN),
    array($email, SQLSRV_PARAM_IN),
    array($name, SQLSRV_PARAM_IN),
    array($validContract, SQLSRV_PARAM_OUT)
    );

    //execute the query
    $stmt = sqlsrv_query($conn, $tsql_callSP, $params);

    if($stmt === false)
    {
    //echo 'Error in executing statement dbo.CheckContract\n';
    $confirmation = "Error in executing statement CheckContract. " . sqlsrv_errors();
    $_POST['input_6'] = "false";
    $_POST['input_9'] = $confirmation;
    sqlsrv_free_stmt( $stmt );
    sqlsrv_close( $conn);
    //die( print_r(sqlsrv_errors(), true));
    }

    //display the return value
    sqlsrv_next_result($stmt);
    //'stored proc return result is: '. $validContract;

    //we have a valid service contract that hasn't expired yet from the sql server
    if($validContract == 1)
    {
    if($valid_Contract == "false") //update the database in wordpress for this meta tag
    update_user_meta($userID, 'valid_contract', "true");
    //set the hidden field valud to true
    $_POST['input_6'] = "true";
    //testing comment out when done
    }
    else
    {
    update_user_meta($userID, 'valid_contract', "false");
    //set the hidden field value to false
    $_POST['input_6'] = "false";
    }

    // Close the connection.
    sqlsrv_free_stmt( $stmt );
    sqlsrv_close( $conn);
    }

    In the second function we direct the user based on the support contract:

    function custom_confirmation( $confirmation, $form, $entry, $ajax ) {

    $validContract = rgar($entry, '6'); //rgpost('input_6');
    $errorMsg = rgar($entry, '9');//rgpost('input_9');

    //we have a valid service contract that hasn't expired yet.
    if($validContract == "true")
    {
    //update the membership role for Memberhip 2
    $user = get_user_by( 'login', rgpost('input_7'));
    $model = MS_Factory::load('MS_Model_Member', $user->ID);
    $model->add_membership('1083'); //change to paying membership
    //redirect user to the members only area landing page.
    $confirmation = array( 'redirect' => './star-support-resources-outsideview' );
    //$confirmation = "validContract: " . $validContract . " " . "userID: " . $entry['user_nicename'] . " " . "name: " . $name . " Contract Number: " . $contractNumber;
    }
    else
    {
    //Some sort of database error has occurred. Let user know or user doesn't have a valid support contract
    if($errorMsg == "null")
    {
    $confirmation = "Unfortunately you do not have a valid Star Support Contract to access members only area. Please contact XYZ, Inc. to update your Star Support Contract: </br>" . "Email: sales@sys.com </br>" . "Phone: 800.989.9998";
    //update the membership role for Memberhip 2
    $user = get_user_by( 'login', rgpost('input_7'));
    $model = MS_Factory::load('MS_Model_Member', $user->ID);
    $model->add_membership('1035'); //change to non paying membership
    }
    else //database error or something related...
    $confirmation = $errorMsg . "</br></br>" . "An error occured while retrieveing your information. Please notify: <b>support@zyz.com</b> with the error message and your username.";
    }

    return $confirmation;
    }

    All this logic works and I can see the correct membership role in the Wordpress Panel for Membership 2 -> All members section.

    Any suggestion as to how to get over the hump and use the plugin successfully so that registered members can access protected content?

    Thanks,

    Mike

  • Mike

    Hi Sajid,

    Today I took your suggestion. I manually deleted the users from the membership role. Then in the membership 2 add member panel I added the Star Support role to the two users that were already created from my code.

    I then went to my login page and logged into the website and I WAS able to access restricted content. This would lead me to believe that something is missing in my code when setting user membership role programmatically?

    Mike

  • Mike

    Well just and update on my testing as I haven't heard back from anyone. Perhaps someone can confirm to me is if we make changes to a user such as in my code below where I am adding a membership to the user:

    //update the membership role for Memberhip 2
    $user = get_user_by( 'login', rgpost('input_7'));
    $model = MS_Factory::load('MS_Model_Member', $user->ID);
    $model->add_membership('1083'); //change to paying membership
    //redirect user to the members only area landing page.
    $confirmation = array( 'redirect' => './star-support-resources-outsideview' );
    //$confirmation = "validContract: " . $validContract . " " . "userID: " . $entry['user_nicename'] . " " . "name: " . $name . " Contract Number: " . $contractNumber;

    When we make changes like adding a membership to user, do we need to make a call to $model->save()? I discovered when I added this 1 line of code, my code started to work correctly. Can someone provide some information regarding this?

    Thanks,

    Mike

  • Mike

    Hi Sajid,

    I tried your code and it did not work for me. However this worked for me:

    $user = get_user_by( 'login', rgpost('input_7'));
    		$model = MS_Factory::load('MS_Model_Member', $user->ID);
    		$model->add_membership('1083'); //change to paying membership
    		$model->save();

    By adding the save() action it somehow triggered the membership to become active and the user is able to access the restricted pages.

    Thanks,

    Mike

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.