-1

First, I should say that I created a template file for wordpress. Now the problem is that I created a function and it does not work for no reason ! I could remove the function but I wonder why this is not working !

(I'm 100% sure that those 2 variables are different because I printed them)

The function always returns true even though my variables are different ! I tested it and I also wanted to echo the function out but the page does not load !

Very very strange !

The code :

global $wpdb;
$lid = $_GET['lid'];
$row = $wpdb->get_row($wpdb->prepare("SELECT * FROM wp_edit_gf WHERE lid = $lid"), ARRAY_A);
global $current_user;
$user_id = $current_user->ID;
$user = get_user_by('id', $user_id);
$user_email=$user->user_email; 
$lid_mail = $row['user_mail'];
function gfedit_verify_user_entry(){
    if(isset($_GET['lid']) && $lid_mail == $user_email){
        return true;
    }
    else{
        return false;
    }
}
if(!is_user_logged_in()){
    header("Location: https://example.com/my-account/?login=true&back=home&page=1");
    exit();
}
elseif(!gfedit_verify_user_entry()){
    echo "access denied!";
}
else{
.
.
.
Nima
  • 118
  • 9

1 Answers1

2

In your function gfedit_verify_user_entry(), you are using two variables ($lid_mail and $user_email) that are declared outside of the function. So nothing strange, they don't exist inside the function.

You should correct it easily:

function gfedit_verify_user_entry($lid_mail, $user_email){
    if(isset($_GET['lid']) && $lid_mail == $user_email){
        return true;
    }
    else{
        return false;
    }
}

Just an extra addition if a one line code will be preferable.

$lid = isset($_GET['lid']);
function gfedit_verify_user_entry($lid, $lid_mail, $user_email){
    return $lid && $lid_mail == $user_email;
}

@lagaart Sorry I had to edit your answer. Could not add it as comment because my current reputation score does not allow me to comment.

ibmgeniuz
  • 117
  • 10
Lagaart
  • 310
  • 1
  • 8
  • 2
    Note that for this to work, you need to also change this line: `elseif(!gfedit_verify_user_entry($lid_mail, $user_email)){` – rickdenhaan Oct 23 '21 at 10:08
  • Oh gosh. My mistake. So sorry but at least I hope I helped some other coders. I 've been through some serious tasks lately. Again sorry for this – Nima Oct 23 '21 at 10:36