ACF_Admin_Email_Opt_In_Banner::ajax_submit
AJAX handler that submits the opt-in and persists the submitted state on success.
Method of the class: ACF_Admin_Email_Opt_In_Banner{}
No Hooks.
Returns
null. Nothing (null).
Usage
$ACF_Admin_Email_Opt_In_Banner = new ACF_Admin_Email_Opt_In_Banner(); $ACF_Admin_Email_Opt_In_Banner->ajax_submit();
Changelog
| Since 6.8.6 | Introduced. |
ACF_Admin_Email_Opt_In_Banner::ajax_submit() ACF Admin Email Opt In Banner::ajax submit code ACF 6.8.8
public function ajax_submit() {
if ( ! acf_verify_ajax() || ! acf_current_user_can_admin() ) {
wp_send_json_error();
}
if ( self::STATE_SUBMITTED === get_option( self::STATE_OPTION, '' ) ) {
wp_send_json_success( array( 'state' => self::STATE_SUBMITTED ) );
}
$email = sanitize_email( (string) acf_request_arg( 'email', '' ) );
if ( ! is_email( $email ) ) {
wp_send_json_error();
}
$response = $this->send_opt_in( $this->build_opt_in_payload( $email ) );
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
wp_send_json_error();
}
update_option( self::STATE_OPTION, self::STATE_SUBMITTED, false );
wp_send_json_success( array( 'state' => self::STATE_SUBMITTED ) );
}