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: //proc/self/cwd/wp-content/plugins/automatewoo/includes/Actions/Mailchimp_Update_Contact_Field.php
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * @class Action_Mailchimp_Update_Contact_Field
 * @since 2.9
 */
class Action_Mailchimp_Update_Contact_Field extends Action_Mailchimp_Abstract {

	function load_admin_details() {
		parent::load_admin_details();
		$this->title = __( 'Update List Contact Field', 'automatewoo' );
		$this->description = __( 'The contact must have been added to the list before updating any fields.', 'automatewoo' );
	}


	function load_fields() {

		$field = ( new Fields\Select() )
			->set_name( 'field' )
			->set_title( __( 'Field', 'automatewoo' ) )
			->set_required()
			->set_dynamic_options_reference( 'list' );

		$value = ( new Fields\Text() )
			->set_name( 'value' )
			->set_title( __( 'Field Value', 'automatewoo' ) )
			->set_variable_validation();

		$this->add_list_field();
		$this->add_field( $this->get_contact_email_field() );
		$this->add_field( $field );
		$this->add_field( $value );

	}


	/**
	 * @param $field_name
	 * @param $reference_field_value
	 * @return array
	 */
	function get_dynamic_field_options( $field_name, $reference_field_value = false ) {

		$options = [];
		/** @var Fields\Select $field */
		$field = $this->get_field( $field_name );

		if ( $field && $field_name !== 'field' ) {
			return [];
		}

		// if reference value is not set load the last saved value, used when initially loading an action page
		if ( ! $reference_field_value ) {
			$reference_field_value = $this->get_option( $field->dynamic_options_reference_field_name );
		}

		foreach ( Integrations::mailchimp()->get_list_fields( $reference_field_value ) as $field ) {
			$options[ $field['tag'] ] = "{$field['name']} - {$field['tag']}" ;
		}

		return $options;
	}


	/**
	 * @throws \Exception
	 */
	function run() {

		$list_id = $this->get_option( 'list' );
		$email = $this->get_contact_email_option();
		$field = $this->get_option( 'field' );
		$value = $this->get_option( 'value', true );

		if ( ! $list_id || ! $field || ! $email ) {
			return;
		}

		$this->validate_contact( $email, $list_id );

		$subscriber_hash = md5( $email );

		$args = [
			'email_address' => $email,
			'merge_fields' => []
		];

		$args['merge_fields'][ $field ] = $value;
		Integrations::mailchimp()->request( 'PATCH', "/lists/$list_id/members/$subscriber_hash", $args );
	}
}