wpcf7_sendinblue_get_templates() │ CF7 1.0

Retrieves email templates from Brevo's database.

Хуков нет.

Возвращает

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

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

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

Код wpcf7_sendinblue_get_templates() CF7 6.2.4.1

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

	static $templates = null;

	$service = WPCF7_Sendinblue::get_instance();

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

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

	$cache = get_transient( 'wpcf7_sendinblue_templates' );

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

	$templates = array();

	$limit = 50;
	$offset = 0;

	while ( count( $templates ) < $limit * 10 ) {
		$templates_next = (array) $service->get_templates( array(
			'limit' => $limit,
			'offset' => $offset,
		) );

		if ( ! empty( $templates_next ) ) {
			$templates = array_merge( $templates, $templates_next );
		}

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

		$offset += $limit;
	}

	set_transient(
		'wpcf7_sendinblue_templates',
		$templates,
		12 * HOUR_IN_SECONDS
	);

	return $templates;
}