<?php
// Add custom Theme Functions here

/**
 * Classic Editor: tắt block editor khi sửa bài / trang (kể cả custom post type).
 */
add_filter( 'use_block_editor_for_post', '__return_false', 10 );
add_filter( 'use_block_editor_for_post_type', '__return_false', 10 );

/**
 * Classic Widgets: tắt block editor ở Giao diện → Tiện ích.
 */
add_filter( 'use_widgets_block_editor', '__return_false', 10 );

/**
 * Load custom UX Builder templates from this child theme.
 *
 * Flatsome's `add_ux_builder_shortcode()` expects `template` to be a string containing
 * Angular template markup, not a filesystem path.
 */
if ( ! function_exists( 'flatsome_child_ux_builder_template' ) ) {
	function flatsome_child_ux_builder_template( $template_file ) {
		$template_path = __DIR__ . '/inc/builder/shortcodes/templates/' . ltrim( $template_file, '/\\' );
		if ( ! file_exists( $template_path ) ) {
			return '';
		}

		ob_start();
		include $template_path;
		return ob_get_clean();
	}
}

// 1) Register the frontend shortcode renderers.
require_once __DIR__ . '/inc/shortcodes/numbes_value.php';
require_once __DIR__ . '/inc/shortcodes/icon_detail.php';
require_once __DIR__ . '/inc/shortcodes/criterion_item.php';
require_once __DIR__ . '/inc/shortcodes/grid_item_multiple.php';

// 2) Register the UX Builder elements (shown in the Elements picker).
add_action(
	'ux_builder_setup',
	function () {
		require_once __DIR__ . '/inc/builder/shortcodes/numbes_value.php';
		require_once __DIR__ . '/inc/builder/shortcodes/icon_detail.php';
		require_once __DIR__ . '/inc/builder/shortcodes/criterion_item.php';
		require_once __DIR__ . '/inc/builder/shortcodes/grid_item_multiple.php';
	},
	20
);
