HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/automatewoo/includes/Frontend_Form_Handler.php
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

defined( 'ABSPATH' ) || exit;

/**
 * Class Frontend_Form_Handler
 * @since 3.9
 */
class Frontend_Form_Handler {

	/** @var string */
	public static $current_action = '';


	private static $actions = [
		'automatewoo_save_communication_preferences',
		'automatewoo_save_communication_signup',
	];



	/**
	 * Handle frontend form post
	 */
	static function handle() {
		$action              = Clean::string( $_POST['action'] );
		$honeypot_field_name = apply_filters( 'automatewoo/honeypot_field/name', 'firstname' );

		if ( ! in_array( $action, self::$actions ) || empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], $action ) ) {
			return;
		}

		if ( ! empty( $_POST[ $honeypot_field_name ] ) ) {
			wc_add_notice( sprintf( __( 'The form could not be submitted. Error code: %s', 'automatewoo' ), 1 ), 'error' );
			return;
		}

		$action = str_replace( 'automatewoo_', '', $action );
		self::$current_action = $action;

		nocache_headers();

		call_user_func( [ __CLASS__, $action ] );
	}



	static function save_communication_preferences() {
		$customer = isset( $_POST['customer_key'] ) ? Customer_Factory::get_by_key( $_POST['customer_key'] ): false;

		if ( ! $customer ) {
			return;
		}

		self::update_customer_preferences( $customer );

		wc_add_notice( __( 'Your communication preferences were updated.', 'automatewoo' ) );
	}



	static function save_communication_signup() {
		$customer = isset( $_POST['email'] ) ? Customer_Factory::get_by_email( $_POST['email'] ): false;

		if ( ! $customer ) {
			wc_add_notice( __( 'Please enter a valid email address.', 'automatewoo' ), 'error' );
			return;
		}

		self::update_customer_preferences( $customer );

		if ( $customer->is_opted_in() ) {
			wc_add_notice( __( 'Thanks! Your signup was successful.', 'automatewoo' ) );
		}
		else {
			wc_add_notice( __( "Saved successfully! You won't receive marketing communications from us.", 'automatewoo' ) );
		}

	}


	/**
	 * @param Customer $customer
	 */
	protected static function update_customer_preferences( $customer ) {
		if ( isset( $_POST['subscribe'] ) ) {
			$customer->opt_in();
		}
		else {
			$customer->opt_out();
		}

		// try and start session tracking the customer
		Session_Tracker::set_session_customer( $customer );

		do_action( 'automatewoo/communication_page/save_preferences', $customer );

	}




}