BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 5
    Richard G4WKW on #46508

    Hi Brajesh,

    I understand your point regarding my second step, but the page is not linked to anywhere publicly and can only be loaded by finding the correct URL to go to, by a logged-in member (so safe enough, I think).

    The problem with getting T&C Acceptance AFTER login, is that without careful content control, once logged in a user would be able to bypass T&C Acceptance if they are knowledgeable or determined enough to do so.

    Although common BuddyPress stuff like /members/ and /groups/ are locked out on my site to anyone not logged in (using the free BuddyPress Private Community plugin from WPCOM), and pages and menu items locked out (using Content Control and User Menus plugins by Code Atlantic) nothing is perfect and a logged in user could load a BuddyPress page directly after login by entering the correct URL.

    Yes, I could prevent that, by only adding them to the correct BuddyPress member category (I have three), AFTER they have accepted the T&C, but that in itself produces a host more problems, and I do not consider it worth the effort!

    One of the key things is that although a lot of membership sites are happy to use paid Pro plugins, and specific Pro Membership themes, for content behind a “pay wall”, small clubs often want members-only content for free! A lot of membership sites earn money via their websites too, which offsets the costs of setting up and maintenance.

    Anyway, thanks for your help in pointing me in the right direction with your code.

    Kind regards
    Richard.

  • Participant
    Level: Initiated
    Posts: 5
    Richard G4WKW on #46477

    I just realized that I had left some redundant code in my first function, producing $user_lc which I then don’t use! I had duplicated a shortcode function I had written before which just returns that value to display a nice username like “G4WKW Richard” on various pages to personalise them for the logged in user.

  • Participant
    Level: Initiated
    Posts: 5
    Richard G4WKW on #46476

    Hi Brajesh,
    I am happy to say I have got it all working the way I want, without using forms, but shortcodes for functions I have written.

    After login, the user is taken to my “checktandc” page which calls [g4wkw_check_tanc]:

    // [g4wkw_check_tanc]
    // function to try and handle conditional T&C Display 
    // called from checktandc page /login-logout/checktandc/
    function g4wkw_check_tanc_field () {
        $user = wp_get_current_user();
    	$user_login = $user->user_login;
    	$my_str = $user_login;
    	$user_lc = strtolower($my_str);
    	
    	$term_page_id  = 3583;   // "T&C" page /login-logout/tc/ - post=3583
    	$welcome_page_id = 2661; // "Welcome!" page /login-logout/welcome/ - post=2661
    	$term_field_id = 15;     // field_id=15 from mouseover Edit on "T&C Accepted?" field in bp-profile-setup Base.
    	$tandc = 0;              // initialise variable
    	
    	$tandc = xprofile_get_field_data( $term_field_id, get_current_user_id() ); // value of either "Yes" or "No"
    	
    	// if T&C checkbox already set (ticked)
    	if ( $tandc == 'Yes' ) {
    		bp_core_redirect( get_permalink( $welcome_page_id ) );  // Redirect to "Welcome!" page
    		return;
    	}	else {
    		bp_core_redirect( get_permalink( $term_page_id ) );  // Redirect to "T&C" page
    		return;
    	}	
        return;
    }
    add_shortcode('g4wkw_check_tanc', 'g4wkw_check_tanc_field');

    That redirects to either the T&C page or Welcome page, depending on the field. The T&C page goes to a “T&C Rejected” page if they click “Reject T&C” button, or “Welcome” page if they click “Accept T&C”.

    The “Welcome” page calls another shortcode [g4wkw_process_accepttandc] to set the field and add the user to a ‘termsok’ usergroup (for use in content control).

    // [g4wkw_process_accepttandc]
    // shortcode to try and get value of the "T&C Accepted?" field
    function g4wkw_process_accepttandc_data () {
    	$welcome_page_id = 2661;          // "Welcome!" page /login-logout/welcome/ - post=2661
    	$term_field_id = 15;              // field_id=15 from mouseover Edit on "T&C Accepted?" (tandc) field in bp-profile-setup Base.
    	$user_id = get_current_user_id(); // get current user_id
    	$tandc = 1;                       // initialise variable for tandc field to 1 ('Yes')
    	
    	xprofile_set_field_data($term_field_id, $user_id, $tandc ); // sets tanc field to 1 ('Yes')
    	
    	// code to add logged-in user to 'termsok' usergroup (for content control enabling)
    	$user = get_user_by( 'ID', $user_id );
    	$user->add_role( 'termsok' );
    	
        return;
    }
    add_shortcode('g4wkw_process_accepttandc', 'g4wkw_process_accepttandc_data');

    Hope that makes sense.
    Regards,
    Richard.

  • Participant
    Level: Initiated
    Posts: 5
    Richard G4WKW on #46344

    Hi Brajesh,

    Thanks so much for your code! I really very much appreciate it and your quick response 🙂

    I think that I can handle the form (and I enjoy a challenge). I will try and get it all working, and let you know if I have, or have had a problem with something.

    Kind regards,

    Richard.

  • Participant
    Level: Initiated
    Posts: 5
    Richard G4WKW on #46336

    Thanks Brajesh 🙂

    I could have written my question better; sorry about that! Forget about checkbox on Welcome page. After thinking things though a bit more clearly, I think this is a better description of what I am trying to achieve.

    I would like to have a “checktandc” page, which everyone is taken to (very briefly) on logon, with the page load calling a function to read the value of the “T&C Accepted” field (as I have called it), and then depending on the state of the field:

    1) If the value of the checkbox is 0 or false, the user is immediately redirected to the proper “Terms & Conditions” page, which has “Accept” and “Reject” buttons at the bottom. Then:

    a) If “Accept” button clicked, user immediately redirected to the “Welcome” page (and a function using xprofile_set_field_data is used to update the “T&C Accepted” field), so the “Terms & Conditions” page is bypassed on next login and user taken to “Welcome” page almost immediately.

    b) If “Reject” accepted, user is taken to the “Home” page.

    2) If the value of the checkbox is 1 or true, then the user is redirected to the Welcome page.

    Calling the function: xprofile_set_field_data($field_id, $user_id, $value );
    looks great to set the value of the checkbox to 1 or true when someone clicks the “Accept” button on the “Terms and Conditions” page.

    —-

    What function do I need to use to READ the value of the field, from the “checktandc” page? I was expecting a something like “xprofile_read_field_data()” but that does not appear to exist?

    Also, I am not sure on the easiest way to set up the automatic redirect, depending on the state of the field, from the “checktandc” page?