Mailpoet_Helpers::get_all_mailpoet_lists( $label = null,  $option_code = 'MAILPOETLISTS',  $args = array() )


Source Source

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

	public function get_all_mailpoet_lists( $label = null, $option_code = 'MAILPOETLISTS', $args = array() ) {
		if ( ! $this->load_options ) {


			return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
		}

		$any_option  = key_exists( 'any_option', $args ) ? $args['any_option'] : false;
		$all_include = key_exists( 'all_include', $args ) ? $args['all_include'] : false;

		if ( ! $label ) {
			$label = esc_attr__( 'List', 'uncanny-automator' );
		}

		$options = array();
		if ( $any_option === true ) {
			$options['-1'] = esc_attr__( 'Any list', 'uncanny-automator' );
		}

		if ( $all_include === true ) {
			$options['all'] = esc_attr__( 'All lists', 'uncanny-automator' );
		}


		$mailpoet  = \MailPoet\API\API::MP( 'v1' );
		$all_lists = $mailpoet->getLists();

		foreach ( $all_lists as $list ) {
			$options[ $list['id'] ] = $list['name'];
		}

		$option = [
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $options,
			'relevant_tokens' => [
				$option_code         => esc_attr__( 'List', 'uncanny-automator' ),
				$option_code . '_ID' => esc_attr__( 'List ID', 'uncanny-automator' ),
			],
		];

		return apply_filters( 'uap_option_get_all_mailpoet_lists', $option );
	}