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(); $my_post['post_title'] = $_POST['Title']; $my_post['post_content'] = $_POST['Message']; $my_post['post_status'] = 'publish'; $my_post['post_author'] = $user_id; $my_post['post_category'] = $category; $my_post['comment_status'] = $enableComments ? 'open' : 'closed'; $my_post['ping_status'] = 'closed'; // Insert the post into the database $post_id = wp_insert_post( $my_post ); if($post_id === 0){ echo 'error adding post'; } else{ //unset($_GET); //$urlArray = explode($_SERVER['REQUEST_URI'], '?'); $urlArray = explode('?', $_SERVER['REQUEST_URI']); //var_dump($_SERVER['REQUEST_URI']); $url = $urlArray[0]; //var_dump($url); //var_dump($urlArray); echo 'post sucessfully added to database, post page: is here'; } //header('Location: http://www.example.com/'); } else{ //error validating captcha $error = $resp->error; print $error; //print 'asdfawsoefOWEIJAFAOFEOAIJOJA'; print 'reCAPTCHA validation failed, try again'; echo displayFormStart($_POST['Title'], $_POST['Message']); echo recaptcha_get_html($publickey); echo displayFormEnd(); } } function displayFormStart($title = '', $message = ''){ $form =<<< FORMSTART
Title:
Message:
FORMSTART; return $form; } function displayFormEnd(){ $form_end =<<< FORMEND
FORMEND; return $form_end; } add_action('the_content', 'addAnonContent'); ?>