Help with verifying google recaptcha in a custom form

You need to validate the reCAPTCHA immediately once you POST the form. You’re just sending a POST to the same page, so it should be done before any other handling. If it does not validate, you need to show the form again, with an error message. function recaptcha_validated(){ if( empty( $_POST[‘g-recaptcha-response’] ) ) return FALSE; … Read more

How to return variables from admin-post.php

You can send GET variables in the URL using wp_redirect. For example: wp_redirect( home_url() .’/form?result=error&reason=3′); As far as I know, yes, admin-post is the best-practices way to handle POST data in WordPress.

Looking for a simple approach for handling user $_POST data without AJAX?

The best way to process the custom form is the following. If you are using nonce then you don’t really have to check $_POST[‘checkbox’], the code below can be used simply to verify_nonce and then process the form. function process_my_form() { if ( wp_verify_nonce( $_POST[‘my_nonce_field’], ‘my_nonce’ ) ) { // process your form here // … Read more

One comment per user per post

Simply add the post_id parameter to the get_comments arguments array something like: global $current_user,$post; $args = array(‘user_id’ => $current_user->ID,’post_id’ => $post->ID); $usercomment = get_comments($args); if(count($usercomment) >= 1){ echo ‘disabled’; } else { comment_form(); }

Checkbox won’t check when label is clicked

Okay, so in case this is of use to anyone else. The original checkbox hack tut that I was following came from here. I’ve got around the issue that I was having in WordPress by wrapping my checkboxes in the labels like <label><input id=”fieldjtdktry-0″ name=”cm-fo-jtdktry” value=”4469820″ type=”checkbox” /><span></span>Learn</label> and then just tweaking the CSS selector … Read more

$_POST empty on submit (same code, same form submits normally on local server)

The best way to deal with Form Posts in WordPress is to use a special endpoint, /wp-admin/admin-post.php. POST data can be messed up, both by the WP Query call, and by any redirects that happen. So you set up your form with this action: <form action=”<?= admin_url(‘admin-post.php’) ?>” method=”post”> <input type=”hidden” name=”action” value=”special_action”> <?php wp_nonce_field(‘special_action_nonce’, … Read more

Built-in data validation function for URLs

Use esc_url( $url ) for URLs that should be displayed and esc_url_raw( $url ) if the URL should be sent to the database. The first will replace bare ampersands & with &#038;. The second is a wrapper for the first; it will just suppress the escaping of ampersands. Both functions will check the protocol. See … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)