I am trying to make a small form, that just has a submit button, and on submission, it should toggle user meta for the WordPress user. The button exists on frontend after content of post, and has a action too.
<form action="" method="POST">
<input type="submit" name="test" id="test" onclick=""/><br/> </form>
The above was the html form code, i can assure that it echoes properly. Then i add the below line to trigger it. This is php
if (isset($_GET['dark'])){
testfun();
}
This calls a function called testfun, the function testfun is below:
function testfun(){
$user_id = get_current_user_id();
$theme= get_user_meta($user_id, 'theme', true);
if ($theme == 'dark') {
update_user_meta($user_id, 'theme', 'light');
}
else{
update_user_meta($user_id, 'theme', 'dark');
}
}
And obviously this code doesn't work, and i fail to figure our why. I have an intuition that the way i gey user id, can be wrong, because rest all seems to be fine. Anyhow please help me with this code.
I basically want to create a button that for the current logged in user, updated the user meta key 'theme' and toggles it between values 'light' and 'dark'
And as far as I am concerned i couldn't find anything wrong in it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745104100a4611453.html
评论列表(0条)