diff --git a/wp-content/themes/cosmopet/functions.php b/wp-content/themes/cosmopet/functions.php index 70f2100..d5e7caf 100644 --- a/wp-content/themes/cosmopet/functions.php +++ b/wp-content/themes/cosmopet/functions.php @@ -1,412 +1,31 @@ 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; -}); +// require once вместо include использовать! +require_once __DIR__ . '/temp-functions/cart-logic.php'; +require_once __DIR__ . '/temp-functions/timber-logic.php'; +require_once __DIR__ . '/temp-functions/woocommerce-logic.php'; +require_once __DIR__ . '/temp-functions/modules-logic.php'; +require_once __DIR__ . '/temp-functions/ajax-logic.php'; +require_once __DIR__ . '/temp-functions/shortcodes-logic.php'; -/* Подключаем все файлы с глобальными функциями */ -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 - ); - } - } - } - } -} - add_action('init', function() { if (function_exists('wpseo_load_textdomain')) { @@ -415,26 +34,25 @@ add_action('init', function() { if (function_exists('pll_load_textdomain')) { pll_load_textdomain(); } - add_filter('timber/context', function($context) { - $context['current_lang'] = pll_current_language(); - return $context; - }); }, 1); +/* Вставить в поиск по модулям */ $modules_path = get_template_directory() . '/modules/*/editor-blocks/*/editor-block-controller.php'; foreach (glob($modules_path) as $file) { require_once $file; // Подключаем каждый найденный файл } -requireShortcodes(get_template_directory() . '/modules'); +// include_module('blog'); +require_once('modules/blog/module-ajax-controller.php'); // !!! внутри него include_module('blog'); -require_once('modules/blog/module-ajax-controller.php'); require_once('modules/forms/module-ajax-controller.php'); require_once('modules/shop/module-ajax-controller.php'); require_once('modules/profile/module-ajax-controller.php'); require_once('modules/footer/module-ajax-controller.php'); +require_once('modules/author/module-ajax-controller.php'); + add_action('wp', 'my_custom_checkout_code'); function my_custom_checkout_code() { @@ -443,11 +61,16 @@ function my_custom_checkout_code() { } } -require_once('modules/author/module-ajax-controller.php'); - include_module('forms'); include_module('layout'); +// include_module('forms'); +// include_module('shop'); +// include_module('profile'); +// include_module('footer'); +// include_module('author'); +// include_module('layout'); + class WooProduct extends Timber\Post { protected $wc_product; diff --git a/wp-content/themes/cosmopet/modules/blog/module-ajax-controller.php b/wp-content/themes/cosmopet/modules/blog/module-ajax-controller.php index 820c75b..03cfffe 100644 --- a/wp-content/themes/cosmopet/modules/blog/module-ajax-controller.php +++ b/wp-content/themes/cosmopet/modules/blog/module-ajax-controller.php @@ -1,4 +1,10 @@ '; +// var_dump('author'); +// print_r('author'); +// echo ''; +// die(); + include_module('blog'); diff --git a/wp-content/themes/cosmopet/temp-functions/ajax-logic.php b/wp-content/themes/cosmopet/temp-functions/ajax-logic.php new file mode 100644 index 0000000..dbba447 --- /dev/null +++ b/wp-content/themes/cosmopet/temp-functions/ajax-logic.php @@ -0,0 +1,38 @@ +'; +var_dump($baseDir ); +print_r($modules ); +echo ''; +die(); + foreach ($modules as $module) { + $moduleController = $module . '/module-ajax-controller.php'; + if (file_exists($moduleController)) { + require_once $moduleController; + } + + $componentsDir = $module . '/components'; + if (is_dir($componentsDir)) { + $components = glob($componentsDir . '/*', GLOB_ONLYDIR); + foreach ($components as $component) { + $componentController = $component . '/component-ajax-controller.php'; + if (file_exists($componentController)) { + require_once $componentController; + } + } + } + } +} + +// requireAjaxControllers('modules'); // НЕ РАБОТАЕТ!!! + + +// require_once(__DIR__ . '../modules/blog/module-ajax-controller.php'); +// require_once('../modules/forms/module-ajax-controller.php'); +// require_once('../modules/shop/module-ajax-controller.php'); +// require_once('../modules/profile/module-ajax-controller.php'); +// require_once('../modules/footer/module-ajax-controller.php'); +// require_once('../modules/author/module-ajax-controller.php'); \ No newline at end of file diff --git a/wp-content/themes/cosmopet/temp-functions/cart-logic.php b/wp-content/themes/cosmopet/temp-functions/cart-logic.php new file mode 100644 index 0000000..ab4fa67 --- /dev/null +++ b/wp-content/themes/cosmopet/temp-functions/cart-logic.php @@ -0,0 +1,2 @@ +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; +}); + +/** + * Подключает статические CSS и JS файлы из указанной директории и прописываем version в src + * + * @param string $dir_name Название директории в папке /static/ + * @param array $options Дополнительные параметры: + * - 'css' => false - отключить подключение CSS + * - 'js' => false - отключить подключение JS + * - 'version' => string - версия файлов (по умолчанию использует время модификации файла) + */ + +/* +find ./ -not -path "*cache*" -type f -exec grep -Ho --color=always 'enqueue_static_assets' {} \; +./wp-content/themes/cosmopet/temp-functions/modules-logic.php:enqueue_static_assets +./wp-content/themes/cosmopet/templates/about/template-about.php:enqueue_static_assets +./wp-content/themes/cosmopet/templates/production/template-prod-page.php:enqueue_static_assets +*/ + +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 + ); + } + } + } + } +} + + diff --git a/wp-content/themes/cosmopet/temp-functions/shortcodes-logic.php b/wp-content/themes/cosmopet/temp-functions/shortcodes-logic.php new file mode 100644 index 0000000..a33c9ff --- /dev/null +++ b/wp-content/themes/cosmopet/temp-functions/shortcodes-logic.php @@ -0,0 +1,30 @@ +