wpcf7_sendinblue_get_lists() │ CF7 1.0

Retrieves contact lists from Brevo's database.

Хуков нет.

Возвращает

null. Ничего (null).

Использование

wpcf7_sendinblue_get_lists( $options ): ?array;
$options
.
По умолчанию: ''

Код wpcf7_sendinblue_get_lists() CF7 6.2.4.1

function wpcf7_sendinblue_get_lists( $options = '' ): ?array {
	$options = wp_parse_args( $options, array(
		'clear_cache' => false,
		'run_query' => true,
	) );

	static $lists = null;

	$service = WPCF7_Sendinblue::get_instance();

	if ( isset( $lists ) or ! $service->is_active() ) {
		return $lists;
	}

	if ( $options['clear_cache'] ) {
		delete_transient( 'wpcf7_sendinblue_lists' );
	}

	$cache = get_transient( 'wpcf7_sendinblue_lists' );

	if ( false !== $cache ) {
		return $lists = $cache;
	} elseif ( ! $options['run_query'] ) {
		return $lists = null;
	}

	$lists = array();

	$limit = 50;
	$offset = 0;

	while ( count( $lists ) < $limit * 10 ) {
		$lists_next = (array) $service->get_lists( array(
			'limit' => $limit,
			'offset' => $offset,
		) );

		if ( ! empty( $lists_next ) ) {
			$lists = array_merge( $lists, $lists_next );
		}

		if ( count( $lists_next ) < $limit ) {
			break;
		}

		$offset += $limit;
	}

	set_transient(
		'wpcf7_sendinblue_lists',
		$lists,
		12 * HOUR_IN_SECONDS
	);

	return $lists;
}