post_content,'hg_contactform') && !has_shortcode($post->post_content,'mlh_contact'))) wp_die('Invalid form page', '', ['response'=>403]); $lang=hgcf_language($post->post_content); $error=hgcf_text('Het versturen is niet gelukt. Probeer het opnieuw of gebruik een andere contactmogelijkheid.','Your message could not be sent. Please try again or use another contact option.',$lang); $nonce=$_POST['mlhc_nonce']??''; $started=$_POST['mlhc_started']??''; $signature=$_POST['mlhc_signature']??''; if(!is_string($nonce) || !wp_verify_nonce($nonce,'hgcf_send') || !is_string($started) || !ctype_digit($started) || !is_string($signature) || !hash_equals(hash_hmac('sha256',$started,wp_salt('nonce')),$signature) || time()-(int)$started<2 || time()-(int)$started>DAY_IN_SECONDS || !empty($_POST['mlhc_website'])) { $GLOBALS['mlhc_errors']=new WP_Error('security',$error); return; } $submitted=[]; foreach(['name','email','phone','message','mode','massage','preferred_date','preferred_time','consent'] as $field) { if(isset($_POST['mlhc_'.$field])) $submitted[$field]=$_POST['mlhc_'.$field]; } $data=hgcf_validate($submitted,$lang); if(is_wp_error($data)) { $GLOBALS['mlhc_errors']=$data; return; } $ip=$_SERVER['REMOTE_ADDR']??'unknown'; $rate_key='mlhc_rate_'.hash_hmac('sha256',$ip,wp_salt('auth')); $rate=get_transient($rate_key); if($rate && ($rate['count']>=5 || time()-$rate['last']<30)) { $GLOBALS['mlhc_errors']=new WP_Error('rate',hgcf_text('Even geduld: probeer het over een minuut opnieuw of gebruik een andere contactmogelijkheid.','Please wait a minute before trying again, or use another contact option.',$lang)); return; } $rate=$rate?:['count'=>0,'last'=>0]; $rate['count']++;$rate['last']=time();set_transient($rate_key,$rate,15*MINUTE_IN_SECONDS); if(!hgcf_send($data,$lang)) { $GLOBALS['mlhc_errors']=new WP_Error('mail',$error); return; } $url=add_query_arg(['contact_status'=>'received','receipt'=>wp_create_nonce('mlhc_received_'.$id)],get_permalink($id)); wp_safe_redirect($url.'#contact-form',303);exit; }); add_shortcode('hg_contactform','hgcf_render'); add_shortcode('mlh_contact','hgcf_render'); add_action('wp_enqueue_scripts',function(){ $post=get_post();if(is_singular()&&$post&&(has_shortcode($post->post_content,'hg_contactform')||has_shortcode($post->post_content,'mlh_contact')))wp_enqueue_style('hgcf',plugins_url('assets/contact.css',__FILE__),[],HGCF_VERSION); });