getWidgetIds(); $scripts = []; $direction = is_rtl() ? '.rtl' : ''; foreach ( $widgets as $widget ) { $jsPath = BDTEP_PATH . 'assets/js/modules/ep-' . $widget . '.js'; $cssPath = BDTEP_PATH . 'assets/css/ep-' . $widget . $direction . '.css'; $script = []; if ( file_exists($jsPath) ) { $script['js'] = $jsPath; } if ( file_exists($cssPath) ) { $script['css'] = $cssPath; } if ( $script ) { $scripts[] = $script; } } return $scripts; } protected function getJsPaths() { return array_reduce($this->getAssets(), function ($results, $item) { if ( isset($item['js']) ) { $results[] = $item['js']; } return $results; }, []); } public function getCssPaths() { return array_reduce($this->getAssets(), function ($results, $item) { if ( isset($item['css']) ) { $results[] = $item['css']; } return $results; }, []); } public function minifyJs() { $scripts = array_merge([ // global js path goes there BDTEP_ASSETS_PATH . 'js/common/helper.js' ], $this->getJsPaths()); $scripts = apply_filters('elementpack/optimization/assets/scripts', $scripts); $minifier = new Minify\JS(); foreach ( $scripts as $item ) { $minifier->add($item); } $uploads_dir = trailingslashit(wp_upload_dir()['basedir']) . 'element-pack/minified/js'; wp_mkdir_p($uploads_dir); $minifiedPath = "$uploads_dir" . "/ep-scripts.js"; $minifier->minify($minifiedPath); } public function minifyCss() { $styles = array_merge($this->getCssPaths(), [ // global js path goes there BDTEP_ASSETS_PATH . 'css/ep-font.css' ]); $styles = apply_filters('elementpack/optimization/assets/styles', $styles); $minifier = new Minify\CSS(); foreach ( $styles as $item ) { $minifier->add($item); } $uploads_dir = trailingslashit(wp_upload_dir()['basedir']) . 'element-pack/minified/css'; wp_mkdir_p($uploads_dir); $minifiedPath = "$uploads_dir" . "/ep-styles.css"; $minifier->minify($minifiedPath); } }