Created
August 17, 2015 19:15
-
-
Save joelstransky/c87cc56923abe15b144b to your computer and use it in GitHub Desktop.
Bypass Advanced Custom Fields acf_form() create/update post functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function acf_contact_form_head() { | |
// verify nonce | |
if( acf_verify_nonce('acf_form') ) { | |
// validate data | |
if( acf_validate_save_post(true) ) { | |
// form | |
$GLOBALS['acf_form'] = acf_extract_var($_POST, '_acf_form'); | |
$GLOBALS['acf_form'] = @json_decode(base64_decode($GLOBALS['acf_form']), true); | |
// validate | |
if( empty($GLOBALS['acf_form']) ) { | |
return; | |
} | |
$from_field = "field_55ccea67a2a49"; | |
$email_field = "field_55cceafca2a4a"; | |
$subject_field = "field_55cceb5aa2a4b"; | |
$message_field = "field_55ccec4ca2a4c"; | |
$from = $_POST['acf'][$from_field]; | |
$email = $_POST['acf'][$email_field]; | |
$acf_subject = get_field_object($subject_field); | |
$subject = $acf_subject['choices'][$_POST['acf'][$subject_field]]; | |
$message = $_POST['acf'][$message_field]; | |
send_mail($from, $email, $subject, $message); | |
// vars | |
//$return = acf_maybe_get( $GLOBALS['acf_form'], 'return', '' ); | |
// redirect | |
if( $return ) { | |
// update %placeholders% | |
$return = str_replace('%post_url%', get_permalink($post_id), $return); | |
// redirect | |
wp_redirect( $return ); | |
exit; | |
} | |
} | |
// if | |
} | |
// if | |
// load acf scripts | |
acf_enqueue_scripts(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just add this to your theme's functions.php and insert
acf_contact_form_head()
beforeget_header()
instead ofacf_form_head()