Created
October 28, 2012 21:05
-
-
Save sandeepshetty/3969907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WP1 | |
* To Dos | |
* | |
* * sending comments needs to add current author data along with the comment data and thus register authorA ? on B along with the comment ? | |
* * send comment to a post on B from a post on A | |
* * send comment to a post on B from a comment on a post on A | |
* * parse url in post / comment | |
* * handle response from B @A so as to notify authorA | |
*/ | |
/* | |
Plugin Name: Ping | |
Description: Attempting to do this http://activitypingback.org/ | |
Author: Jigar Vyas | |
Version: 1.0 | |
*/ | |
require "/var/www/html/library/curl.php"; | |
add_action("publish_post", "send"); | |
if (!empty($_POST)) { | |
add_action("the_posts", "get"); | |
} | |
function get($post) { | |
return add_comment(array("post_id" => $post[0]->ID, "comment" => $_POST['comment'])); | |
exit; | |
} | |
function add_comment($comment_data) { | |
$commentdata['comment_post_ID'] = $comment_data['post_id']; | |
$commentdata['comment_content'] = $comment_data['comment']; | |
return wp_new_comment($commentdata); | |
} | |
function send($post_id) { | |
$_post_data = get_post($post_id); | |
$_urls = _parse_for_urls($_post_data->post_content); | |
if ($_urls) { | |
$curl = new Curl(); | |
foreach ($_urls as $_url) { | |
$params['url'] = $_url; | |
$comment = "MY 2 cents:<br>"; | |
$params['fields_data'] = array("comment" => $comment . $_post_data->post_content); | |
$curl->post($params); | |
} | |
} | |
return false; | |
} | |
function _parse_for_urls($str) { | |
$to_return = array("http://localhost/wp2/?p=1"); | |
return $to_return; | |
} | |
?> |
Author
sandeepshetty
commented
Oct 29, 2012
- What is $add_comment on line #27? Where is it getting initialized?
- Does curl.php come with Wordpress?
- $add_comment was a typo - its just calling add_comment() on line #31
- curl.php is custom : https://gist.github.com/3972260
Refactored it a bit. Why do you need the exit inside get()?
BTW does Wordpress have its own http client? If yes, then you could use that so don't have to bundle the curl.php dependency.
- the exit was during testing when I was sending a normal form post from a local link to a blog and that get would load the WP Blog header before getting $_POST data. Not reqd now
- haven't looked for a client within WP itself. Got to check. Will update
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment