isDir() || $template_file->getExtension() !== 'php') { continue; } // Получаем относительный путь (например, "pages/template-landing.php") $relative_path = str_replace($custom_templates_dir, '', $template_file->getPathname()); // Формируем имя шаблона (убираем .php и заменяем слэши на дефисы) $template_name = str_replace(['/', '.php'], [' - ', ''], $relative_path); // Добавляем в список шаблонов $templates['templates/' . $relative_path] = $template_name; } return $templates; }); includeFilesFromFolder(get_template_directory() . '/global-functions'); // Add the function to the Timber context add_filter('timber/context', function($context) { $context['template_path'] = get_template_directory_uri(); $current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $context['current_url'] = htmlspecialchars($current_url); return $context; }); /** * Подключает статические CSS и JS файлы из указанной директории * * @param string $dir_name Название директории в папке /static/ * @param array $options Дополнительные параметры: * - 'css' => false - отключить подключение CSS * - 'js' => false - отключить подключение JS * - 'version' => string - версия файлов (по умолчанию использует время модификации файла) */ function enqueue_static_assets($dir_name, $options = []) { // Устанавливаем пути к директориям $static_dir = get_template_directory() . '/static/' . $dir_name; $static_uri = get_template_directory_uri() . '/static/' . $dir_name; // Подключаем CSS файлы if (!isset($options['css']) || $options['css'] !== false) { $css_dir = $static_dir . '/css/'; if (file_exists($css_dir)) { $css_files = scandir($css_dir); foreach ($css_files as $file) { if (pathinfo($file, PATHINFO_EXTENSION) === 'css') { $handle = $dir_name . '-' . pathinfo($file, PATHINFO_FILENAME); $src = $static_uri . '/css/' . $file; $ver = isset($options['version']) ? $options['version'] : filemtime($css_dir . $file); wp_enqueue_style( $handle, $src, array(), $ver ); } } } } // Подключаем JS файлы if (!isset($options['js']) || $options['js'] !== false) { $js_dir = $static_dir . '/js/'; if (file_exists($js_dir)) { $js_files = scandir($js_dir); foreach ($js_files as $file) { if (pathinfo($file, PATHINFO_EXTENSION) === 'js') { $handle = $dir_name . '-' . pathinfo($file, PATHINFO_FILENAME); $src = $static_uri . '/js/' . $file; $ver = isset($options['version']) ? $options['version'] : filemtime($js_dir . $file); $in_footer = strpos($file, 'admin') === 0 ? false : true; wp_enqueue_script( $handle, $src, array(), $ver, $in_footer ); } } } } } $modules_path = get_template_directory() . '/modules/*/editor-blocks/*/editor-block-controller.php'; foreach (glob($modules_path) as $file) { require_once $file; // Подключаем каждый найденный файл } add_filter('timber/context', function($context) { $context['current_lang'] = pll_current_language(); return $context; }); requireShortcodes(get_template_directory() . '/modules'); require_once('modules/blog/module-ajax-controller.php'); require_once('modules/forms/module-ajax-controller.php'); include_module('forms'); include_module('layout');