/** * Get assets content of all selected view types in a page * by merging css files to public/assets/css/public.css, js files to public/assets/js/public.js */ static function assets_of_view_types() { global $pt_cv_glb, $pt_cv_id; // If already processed | have no View on this page -> return if (!empty($pt_cv_glb[$pt_cv_id]['applied_assets']) || !$pt_cv_id) { return; } // Mark as processed $pt_cv_glb[$pt_cv_id]['applied_assets'] = 1; // Print inline view styles & scripts if (apply_filters(PT_CV_PREFIX_ . 'assets_verbose_loading', 1)) { $assets = array('css', 'js'); $assets_output = $assets_files = array(); // Get content of asset files in directory of view type foreach (self::$view_type_dir as $idx => $view_type_dir) { // Get selected style of current view type $style = self::$style[$idx]; // With each type of asset (css, js), looking for suit file of selected style foreach ($assets as $type) { $file_path = $view_type_dir . '/' . $type . '/' . $style . '.' . $type; $content = PT_CV_Functions::file_include_content($file_path); if ($content) { $assets_output[$type][] = $content; } } } // Echo script, style inline if ($assets_output) { foreach ($assets_output as $type => $contents) { $content = implode("\n", $contents); if ($type == 'js') { echo '' . self::inline_script($content, false); } else { echo '' . self::inline_style($content); } } } } // Link to external files $assets_files = apply_filters(PT_CV_PREFIX_ . 'assets_files', array()); if (is_admin()) { // Include assets file in Preview foreach ($assets_files as $type => $srcs) { foreach ($srcs as $src) { PT_CV_Asset::include_inline('preview', $src, $type); } } } else { // Enqueue merged asset contents foreach ($assets_files as $type => $srcs) { foreach ($srcs as $src) { $type = $type == 'js' ? 'script' : 'style'; $function = "wp_enqueue_{$type}"; if (function_exists($function)) { $function(PT_CV_PREFIX . $type, $src); } } } } // Output custom inline style for Views if (apply_filters(PT_CV_PREFIX_ . 'output_view_style', 1)) { do_action(PT_CV_PREFIX_ . 'print_view_style'); } }
/** * Get assets content of all selected view types in a page * by merging css files to public/assets/css/public.css, js files to public/assets/js/public.js */ static function assets_of_view_types() { global $pt_cv_glb, $pt_cv_id; // If already processed | have no View on this page -> return if (!empty($pt_cv_glb[$pt_cv_id]['applied_assets']) || !$pt_cv_id) { return; } // Mark as processed $pt_cv_glb[$pt_cv_id]['applied_assets'] = 1; // Link to external files $assets_files = apply_filters(PT_CV_PREFIX_ . 'assets_files', array()); if (is_admin()) { // Include assets file in Preview foreach ($assets_files as $type => $srcs) { foreach ($srcs as $src) { PT_CV_Asset::include_inline('preview', $src, $type); } } } else { // Enqueue merged asset contents foreach ($assets_files as $type => $srcs) { foreach ($srcs as $src) { $type = $type == 'js' ? 'script' : 'style'; $function = "wp_enqueue_{$type}"; if (function_exists($function)) { $function(PT_CV_PREFIX . $type, $src); } } } } // Output custom inline style for Views if (apply_filters(PT_CV_PREFIX_ . 'output_view_style', 1)) { do_action(PT_CV_PREFIX_ . 'print_view_style'); } }