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

namespace AutomateWoo;

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

/**
 * @class Action_Mailchimp_Add_To_Group
 * @since 3.4.0
 */
class Action_Mailchimp_Add_To_Group extends Action_Mailchimp_Abstract {

	function load_admin_details() {
		parent::load_admin_details();
		$this->title = __( 'Add Contact To Group', 'automatewoo' );
	}


	function load_fields() {

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

		$allow_add_to_list = ( new Fields\Checkbox() )
			->set_name( 'allow_add_to_list' )
			->set_title( __( "Add contact to list if missing?", 'automatewoo' ) )
			->set_default_to_checked();

		$this->add_list_field();
		$this->add_field( $this->get_contact_email_field() );
		$this->add_field( $groups );
		$this->add_field( $allow_add_to_list );

	}


	/**
	 * @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 !== 'groups' ) {
			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_interest_categories( $reference_field_value ) as $interest_category ) {
			foreach( $interest_category['interests'] as $interest_id => $interest_name ) {
				$options[ $interest_id ] = "{$interest_category['title']} - {$interest_name}" ;
			}
		}

		return $options;
	}


	function run() {

		$list_id = $this->get_option( 'list' );
		$email = $this->get_contact_email_option();
		$interests = $this->get_option( 'groups' );
		$allow_add_to_list = $this->get_option( 'allow_add_to_list' );

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

		if ( ! Integrations::mailchimp()->is_contact( $email, $list_id ) && ! $allow_add_to_list ) {
			return;
		}

		$group_updates = [];

		foreach( $interests as $interest_id ) {
			$group_updates[ $interest_id ] = true;
		}

		Integrations::mailchimp()->update_contact_interest_groups( $email, $list_id, $group_updates );
	}

}