'; echo recaptcha_get_html($publickey); print ''; } print displayFormEnd(); } } else{ } // } function enteredByPOST(){ global $captchaEnabled; global $privatekey, $publickey; global $anonUserName, $category, $enableComments; 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' => 'publish', 'post_author' => $user_id, 'post_category' => $category, 'comment_status' => ($enableComments ? 'open' : 'closed'), '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
Post title:

Your message:

FORMSTART; return $form; } function displayFormEnd(){ $form_end =<<< FORMEND

FORMEND; return $form_end; } function add_css(){ $css =<<< CSS CSS; return $css; } add_action('the_content', 'addAnonContent');