Mailchimp_Helpers::select_mctagslist_from_mclist()

Ajax callback for loading tags NAMES list.

Contents


Return Return

(Uncanny_Automatorvoid.)


Source Source

File: src/integrations/mailchimp/helpers/mailchimp-helpers.php

	public function select_mctagslist_from_mclist() {
		global $uncanny_automator;
		// Nonce and post object validation
		$uncanny_automator->utilities->ajax_auth_check( $_POST );
		$fields = array();
		if ( ! isset( $_POST ) ) {
			echo wp_json_encode( $fields );
			die();
		}
		$list_id = sanitize_text_field( $_POST['values']['MCLIST'] );
		$request_params = array(
			'action'  => 'get_list_segments',
			'list_id' => $list_id,
		);
		try {
			$response = $this->api_request( $request_params );
			if ( $response->statusCode !== 200 || empty( $response->data->segments ) ) {
				die();
			}
			foreach ( $response->data->segments as $segment ) {
				$fields[] = array(
					'value' => $segment->name,
					'text'  => $segment->name,
				);
			}
		} catch ( \Exception $e ) {
			// Do nothing
		}
		echo wp_json_encode( $fields );
		die();
	}