• Resolved giant slayer

    (@giant-slayer)


    I am trying to post any new comment left on my site to my facebook fanpage. I have added all the necessary fields to my comment form. I also have the code which posts the comment to my facebook fanpage.

    But I’m not sure how to add a hook/action command after the comment is submitted to execute the code.

    I think it has something to do with preprocess_comment or comment_post. But I really am not sure what to do. I’d really appreciate any help. Thanks.

    My fields I added to the comment form are as follows

    <input type="hidden" name="fbtoken" id="fbtoken" value="..." />
    <input type="hidden" name="fburl" id="fburl" value="https://graph.facebook.com/136789689670650_141764672506485/comments" />

    And the code to post to my facebook fan page is as follows

    <?php $access_tkn= $_POST['fbtoken'];?>
    <?php $message = trim($_POST['comment']); ?>
    <?php $fburl = $_POST['fburl']); ?>
    <?php   $fbargs = array('access_token' => $access_tkn, 'message' => $message);
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL, $fburl);
    	curl_setopt($ch, CURLOPT_HEADER, false);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	curl_setopt($ch, CURLOPT_POST, true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $fbargs);
    	$data = curl_exec($ch);
    	curl_close($ch);?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter giant slayer

    (@giant-slayer)

    Ok, I’ve pretty well scoured the wordpress docs looking for understanding on hooks/actions/filters, but have not found what I am looking for.
    My desire is to execute php code immediately after someone clicks on the submit comment button.

    I’d appreciate any help on this. Thanks.

    Thread Starter giant slayer

    (@giant-slayer)

    I got it to work by adding the following code to my functions.php

    function postCommentToFanPage( ){
        $access_tkn = $_POST['fbtoken'];
        $message = trim($_POST['comment']);
        $fburl = $_POST['fburl'];
        $fbargs = array('access_token' => $access_tkn, 'message' => $message);
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL, $fburl);
    	curl_setopt($ch, CURLOPT_HEADER, false);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	curl_setopt($ch, CURLOPT_POST, true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $fbargs);
    	$data = curl_exec($ch);
    	curl_close($ch);
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to post comment to facebook fanpage.’ is closed to new replies.