How to check if a user has already submitted a file in Wordpress?

Asked

Viewed 46 times

0

I’m using the plugin WPForms, PRO version and added a button upload file in this form.

However, I need to make the following check:

  • A user sends a file through my form. When that same user comes back, and uploads another one, how do I check that he has already uploaded it? And how do I change the content of the page, given this condition?

Ps: I have already made a function that checks whether the user is logged in or not, and the form only appears for logged in users

1 answer

0


Guys, I found the answer. Basically, for you to track, just enjoy the database. I created a script to check if the user is logged in (all of this in functions.php):

function check_user ($params, $content = null){
//verifica se o usuario esta logado
if ( is_user_logged_in() ){
//coloque o que vc quer fazer...``
}

and within that block of code, I created a connection to the database, and also took the user ID, with the code (the connection is not here, but it’s very simple to do):

$id = get_current_user_id();

then created a query string, to give a SELECT in the table that made sense to check and I was able to bring the results with the following command (after executing the query string with the connection in a name result variable) :

$row = $mysqli_fetch_array($result, MYSQLI_ASSOC);

after that, I did the checking (I was looking at the 'action' column of my database):

if($row['action'] == "upload"){
$data = utf8_encode("Você já fez um upload");
echo($data);
}
else{
$data = utf8_encode("Você ainda não fez nenhum upload");
echo($data);
}`

I hope I’ve helped :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.