1

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?

1 Answer 1

2

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.

6
  • Just wanted to share this link: codex.wordpress.org/Plugin_API/Action_Reference
    – ferenyl
    Commented Sep 24, 2013 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? Commented Sep 24, 2013 at 13:07
  • And after doing add_action() do i need to call do_action() or Wordpress automatically do that? Commented Sep 24, 2013 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". Commented Sep 25, 2013 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? Commented Sep 25, 2013 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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