";
$this_post_id = $wp_query->post->ID;
if(get_post_meta($this_post_id, 'anonPost', true) == 'true'){
//add css:
if($enable_css)
$form .= add_css();
if($_POST){
$form .= enteredByPOST();
}
else{
$form .= displayFormStart();
if($captchaEnabled){
$form .= '
';
$form .= recaptcha_get_html($publickey);
$form .= '';
}
$form .= displayFormEnd();
}
}
else{
return get_the_content();
}
if($display_content_after_post_created){
return get_the_content().$form;
}
else{
return $form;
}
//this should not happen
//return get_the_content();
}
function enteredByPOST(){
global $captchaEnabled;
global $privatekey, $publickey;
global $anonUserName, $category, $enableComments, $my_post_type;
$to_return = '';
if ((!$captchaEnabled) || recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'])->is_valid) {
//check if user exists, if not, add this user
if(username_exists($anonUserName)){
$user_id = get_profile( 'ID', $anonUserName );
}
else{
$user_id = wp_create_user($anonUserName, wp_generate_password(20, false), 'no@email.com' );
}
$my_post = array(
'post_title' => $_POST['Title'],
'post_content' => $_POST['Message'],
'post_status' => $my_post_type,
'post_author' => $user_id,
'post_category' => $category,
//this thing enables normal comments only when comments are open and using Anon Comment is turned off
'comment_status' => (($enableComments && !$use_anonComment) ? 'open' : 'closed'),
'ping_status' => 'closed'
);
// Insert the post into the database
$post_id = wp_insert_post( $my_post );
if($post_id === 0){
$to_return .= 'error adding post';
}
else{
//add meta tag, so AnonComment could add its comment field
if($use_anonComment){
add_post_meta($post_id, 'AnonComment', 'true', true);
}
//display new post link
//mod_rewrite will work with normal url's, like ?p=123
$urlArray = explode('?', $_SERVER['REQUEST_URI']);
$url = $urlArray[0];
$to_return .= 'post sucessfully added to database, post page: is here';
}
}
else{
//error validating captcha
$error = $resp->error;
$to_return .= $error;
$to_return .= 'reCAPTCHA validation failed, try again';
$to_return .= displayFormStart($_POST['Title'], $_POST['Message']);
$to_return .= recaptcha_get_html($publickey);
$to_return .= displayFormEnd();
}
return $to_return;
}
function displayFormStart($title = '', $message = ''){
$form =<<< FORMSTART
FORMEND;
return $form_end;
}
function add_css(){
$css =<<< CSS
CSS;
return $css;
}
add_action('the_content', 'addAnonContent');