vovan16m
10/29/2019 - 10:00 AM

ACF Blocks

ACF Blocks

/**
 * ACF Gutenberg Block "Сustom content box with title and subtitle"
 */
if (!function_exists('register_acf_block_custom_content_box_with_title_and_subtitle')) {

	function register_acf_block_custom_content_box_with_title_and_subtitle()
	{

		acf_register_block_type(
			array(
				'name' => 'acf_block_custom_content_box_with_title_and_subtitle',
				'title' => __('Сustom content box with title and subtitle'),
				'description' => __(''),
				'render_callback' => 'kelkoo_acf_blocks_render_callback',
				'category' => 'common',
				'icon' => 'layout',
				'keywords' => array('arbitrary', 'content', 'title', 'subtitle', 'images'),
				'mode' => 'edit',
			)
		);

	}

}

if (function_exists('register_acf_block_custom_content_box_with_title_and_subtitle')) {
	add_action('acf/init', 'register_acf_block_custom_content_box_with_title_and_subtitle');
}

/**
 * Enable ACF Blocks render function
 */
if (!function_exists('kelkoo_acf_blocks_render_callback')) {

	function kelkoo_acf_blocks_render_callback($block)
	{

		$slug = str_replace('acf/', '', $block['name']);
		$slug = str_replace('acf-block-', '', $slug);

		if (file_exists(get_theme_file_path("/blocks/acf-block-{$slug}.php"))) {
			include(get_theme_file_path("/blocks/acf-block-{$slug}.php"));
		}

	}

}

/**
 * Get unique block ID
 */
if (!function_exists('kelkoo_get_unique_block_id')) {

	function kelkoo_get_unique_block_id($text)
	{

		$block_unique_ID = ($text) ? mb_strtolower(preg_replace( '~[^0-9A-Za-z]+~', '_', strip_tags($text))) : time();
		$block_unique_ID = ($block_unique_ID) ? $block_unique_ID : time();

		return $block_unique_ID;

	}

}