Now that I got that out of the way I ran into another problem. I need to somehow pull the author id from the post that a user likes to give points/exp to the poster using jquery. How would I go about this though? Because there's no user id in the markup that I can pull using jquery. What I could pull however, was the author's username by doing the following (btw post_id is defined ahead of this and returns either "like-[ID]" or "dislike-[ID]" where [ID] is a number like 4.):
var user_id = jQuery("#" + post_id.replace("like-", "post-") + " .author a").text();
Once I pull the username, when the POST request gets sent to the php file I can convert it to the user id by doing (thanks to: http://wordpress.org/support/topic/getting-user-id-from-username):
$user = get_userdatabylogin($user_id);
var_dump($user);
echo $user->ID; // prints the id of the user
Currently I'm stuck on this next issue. My original idea was to create a new php file (levelpoints.php) just to handle the POST data with the user_id, instead of post_id, to update the level_points db. I've found that if I do this though I would have to rewrite the loops in the likedislike.php that check if the user is logged in, hasn't already voted, etc. So this means that I'm going to rename likedislike.php to handlelikedata.php because it seems more general than just covering the like and dislike db. It also means that I'm getting rid of the levelpoints.php.
Now that's out of the way I'm adding the user_id to the data getting sent. So far my handlelikedata.php looks like this: http://pastebin.com/VM8YxKt4
For whatever reason the success part of that code that's supposed to display the status messages is not working. I'm not sure why but I think it might be another simple fix. It's 1am now though and my brain is too far gone to even try looking for that solution. Hopefully I can finally finish this damn system tomorrow and just focus solely on styling.
No comments:
Post a Comment