Question

This is for a personal-use plugin I'm trying to make. I want to submit a comment from site A to my blog (sort of like sending trackbacks/pingbacks but a full comment).

For instance, on site A I have a form with a name, url, and comment field. The data I enter in site A, I want to submit to site B (my blog) via URL parameters or the POST method.

I assume that I'll need an action hook on my blog to retrieve data sent from site A and insert it in the wp comment table.

Is this possible?

Was it helpful?

Solution

In WordPress, almost anything is possible. It all depends at times how hard you want to work for it. :)

The Comment Post form of course uses HTTP POST to submit to /wp-comments-post.php so you could use that except for the NONCEs if you want to post unfiltered HTML. You'd have to write a page to give you an acceptable NONCE which Site A would need to HTTP GET in order to be able to submit back to to the comment post form but I think if you don't mind the filters it should work fine.

Another option is to use a function designed for AJAX but have it capture your HTTP POST from your form and then save your comment to Site B by calling wp_insert_comment(). Or you could use AJAX on Site B to talk to Site A. Of course you'll be opening up a bit of a security hole by doing that, but if your code isn't distributed you can decide if that creates a real concern or not.

(Normally I would write up an example but have run out of time today. Hopefully the above sends you in the right direction.)

OTHER TIPS

Ok I put together an example. I hope it will work :)

Passing data from site A to site B (the blog):

On site A I think I'll use the POST method, to send data to site B. I don't wan't to pass parameters in the url.

And on site B, I'll have

$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$content = $_POST['content'];
$time = current_time('mysql');

$data = array(
    'comment_author' => $name,
    'comment_author_email' => $email,
    'comment_author_url' => $url,
    'comment_content' => $content,
    'comment_date' => $time,
    'comment_approved' => 1,
);

wp_insert_comment($data);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top