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/admin/settings-tabs/mailchimp.php
<?php

namespace AutomateWoo;

defined( 'ABSPATH' ) || exit;

/**
 * Settings_Tab_Mailchimp class.
 */
class Settings_Tab_Mailchimp extends Admin_Settings_Tab_Abstract {

	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->id   = 'mailchimp';
		$this->name = __( 'MailChimp', 'automatewoo' );
	}

	/**
	 * Get tab settings.
	 *
	 * @return array
	 */
	public function get_settings() {
		return [
			[
				'type' => 'title',
				'id'   => 'automatewoo_mailchimp_integration',
				'desc' => __( 'Enabling the MailChimp integration does not automatically sync your data but makes three actions available when creating workflows. These actions can be used to automate how you add and remove members from your MailChimp lists and update your custom fields.', 'automatewoo' ),
			],
			[
				'title'    => __( 'Enable integration', 'automatewoo' ),
				'id'       => 'automatewoo_mailchimp_integration_enabled',
				'default'  => 'no',
				'autoload' => true,
				'type'     => 'checkbox',
			],
			[
				'title'    => __( 'API Key', 'automatewoo' ),
				'id'       => 'automatewoo_mailchimp_api_key',
				'tooltip'  => __( 'You can get your API key when logged in to MailChimp under Account > Extras > API Keys.', 'automatewoo' ),
				'type'     => 'password',
				'autoload' => false,
			],
			[
				'type' => 'sectionend',
				'id'   => 'automatewoo_mailchimp_integration',
			],
		];
	}

	/**
	 * Save settings.
	 */
	public function save() {

		$is_valid = self::validate_key();

		if ( $is_valid ) {
			$mailchimp = Integrations::mailchimp();

			if ( $mailchimp ) {
				$mailchimp->clear_cache_data();
			}

			parent::save();
		}

	}

	/**
	 * Validate the Mailchimp API key.
	 */
	public function validate_key() {
		$api_key = aw_get_post_var( 'automatewoo_mailchimp_api_key' );

		$err_msg = __( 'The MailChimp API Key you entered is not valid.', 'automatewoo' );

		// return true if empty so users can wipe out their key.
		if ( $api_key === '' ) {
			return true;
		}

		if ( false === $api_key ) {
			parent::add_error( $err_msg );

			return false;
		}

		if ( strpos( $api_key, '-' ) === false ) {
			parent::add_error( $err_msg );

			return false;
		}

		$mailchimp_test = new Integration_Mailchimp( Clean::string( $api_key ) );

		$response = $mailchimp_test->request( 'GET', '/' );

		if ( $response->is_successful() ) {
			return true;
		} else {
			parent::add_error( $err_msg );

			return false;
		}
	}
}

return new Settings_Tab_Mailchimp();