Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to trigger a function immidiately after a user posted a comment on a post. I want to read from session data, find the user ID and look his facebook_id if he/she has any. Then i will post the same comment on his/her Facebook page.

How can i immidiately know if a user has posted a comment?

How can i know which user is that?

How can i trigger a function after that?

share|improve this question

1 Answer 1

How can i immidiately know if a user has posted a comment?

There is a hook called "wp_insert_comment", that is executed right after the comment is added. This actions passes 2 arguements first the comment id and the second is the comment.

How can i know which user is that?

Well it depends on if the user is a registered subsriber of your blog. Use the hook "wp_insert_comment" in conjunction with the function "get_comment".

How can i trigger a function after that?

It's just php so you can do whatever you want in your function.

This is just a help to solve your problem by your own. The hardest part will be to work on with the Facebook API.

share|improve this answer
    
Just wanted to share this link: codex.wordpress.org/Plugin_API/Action_Reference –  ferenyl Sep 24 '13 at 9:24
    
I have solved the Facebook API part. Where will use the wp_insert_comment. Should i create a new PHP file? Which Wordrpess files should i include? –  user1002601 Sep 24 '13 at 13:07
    
And after doing add_action() do i need to call do_action() or Wordpress automatically do that? –  user1002601 Sep 24 '13 at 13:13
    
Also i can not use that with "get_comment". This function requires the "comment_id". What i need first is the "comment_id". –  user1002601 Sep 25 '13 at 8:12
    
@Horttcore if i write add_action("wp_insert_comment", "get_comment_custom") function get_comment_costom("$comment_id"){ echo $comment_id; } Does it automatically get the comment_id and assign it to get_comment_custom as an argument? –  user1002601 Sep 25 '13 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.