WP Plugin for Terms of Use

I wrote something like that in the past that check for a cookie before loading the page and if the cookie wasn’t found the page would display something like the terms of services and a checkbox to agree, so only after the guest agrees he can see the content.

i’ll see if i can find that code.

UPDATE

O.k found most of it
so we create a function that checks if the user is logged in and if not we check to see if he has our cookie if not we display our T.O.S instead of the content so we hook that to the_content hook

function to add_filter('the_content','check_tos_656');

function  check_tos_656($content){
    //only for none logged in guests
    if (!is_user_logged_in()){
        //check if guest has agree cokkie
        if(!check_cookie_tos()){
            $content = show_tos();
        }
    }
    return $content;
}

no you can see two function in there

  • check_cookie_tos() a function to see if the cookie exists.
  • show_tos() a function to display our T.O.S and an agree checkbox and button.

so here they are:

function check_cookie_tos(){
    if (isset($_COOKIE['agreed_TOS'])){
        if ($_COOKIE['agreed_TOS'] =="I_aggre"){
            return true
        }
    }
    return false;
}

function show_tos(){
    $out="<h3>You Must Agree to our T.O.S blablabla</h3>
    //here you can put your TOS
    blablabla
    blablabla
    blablabla";

    $out .= '<form name="tos_check" method="POST" action="">
        <p>
            <input type="checkbox" name="tos_agree" id="tos_agree" value="yes" /> I Agree!<br />
            <input type="submit" name="submit_tos" id="submit_tos" value="submit">
        </p></form';
    return $out;
}

now you can see that we have a form that will submit the guest’s agreement to the T.O.S so we need to process that and create the cookie so here it is:

if (isset($_POST['check_cookie_tos']) && $_POST['check_cookie_tos'] == "yes"){
    setcookie("agreed_TOS", "I_aggre", time()+3600, "https://wordpress.stackexchange.com/", str_replace('http://www','',get_bloginfo('url')) );
}

you would have to set your own T.O.S in the code but if enough people will ask i’ll turn this into a plugin and add a simple admin panel.

Enjoy.

Leave a Comment