From a031d97a0c9bf8ea49672a12d8798968cb32d53d Mon Sep 17 00:00:00 2001 From: Muhammad Zohaib Date: Thu, 5 Oct 2023 11:21:59 +0500 Subject: [PATCH] Implemented enqueue method --- helpers/class-helpers.php | 14 +++++++----- includes/class-scripts.php | 46 +++++++++++++------------------------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/helpers/class-helpers.php b/helpers/class-helpers.php index e0fddf8..006f1d0 100644 --- a/helpers/class-helpers.php +++ b/helpers/class-helpers.php @@ -92,7 +92,7 @@ public static function files_array( $prefix, $override = false ) { * # Get and list menu locations. * Will only work after init and wp hook. */ - public static function menu_locations($override = false) { + public static function menu_locations( $override = false ) { global $_wp_registered_nav_menus; @@ -116,18 +116,22 @@ public static function rev_sliders() { $data = array(); $data['none'] = esc_html__( 'None', '_xe' ); - if ( class_exists('RevSlider') ) : + if ( class_exists('RevSlider') ) { $slider = new \RevSliderSlider(); $sliders = $slider->getArrSlidersShort(); - if (!empty($sliders)) { - foreach ($sliders as $key => $val) { + if ( ! empty( $sliders ) ) { + + foreach ( $sliders as $key => $val ) { + $data[$key] = $val; + } + } - endif; + } return $data; diff --git a/includes/class-scripts.php b/includes/class-scripts.php index d30ea10..d7ac95e 100644 --- a/includes/class-scripts.php +++ b/includes/class-scripts.php @@ -9,6 +9,8 @@ namespace Xe_Theme\Includes; +use Xe_Theme\Helpers\Helpers; + class Scripts { function __construct() { @@ -23,43 +25,31 @@ function __construct() { */ public function frontend() { - global $xe_opt; - - // Version Control for CSS and JS - $style_css = filemtime(get_template_directory() . '/style.css'); - $main_css = filemtime(get_template_directory() . '/assets/css/main.css'); - $bootstrap_css = filemtime(get_template_directory() . '/assets/css/bootstrap.min.css'); - $fontawesome_css = filemtime(get_template_directory() . '/assets/css/all.min.css'); - - $bootstrap_js = filemtime(get_template_directory() . '/assets/js/bootstrap.bundle.min.js'); - $stellar_js = filemtime(get_template_directory() . '/assets/js/stellar.min.js'); - $sticky_js = filemtime(get_template_directory() . '/assets/js/sticky.min.js'); - $main_js = filemtime(get_template_directory() . '/assets/js/main.js'); - /** * Google Fonts */ - // wp_enqueue_style('google-fonts', ''); + // wp_enqueue_style( 'google-fonts', '' ); /** * # Styles */ - wp_enqueue_style('_xe-style', get_template_directory_uri() . '/style.css', array(), esc_attr($style_css)); - wp_enqueue_style('bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), esc_attr($bootstrap_css)); - wp_enqueue_style('fontawesome', get_template_directory_uri() . '/assets/css/all.min.css', array(), esc_attr($fontawesome_css)); - wp_enqueue_style('_xe-main', get_template_directory_uri() . '/assets/css/main.css', array(), esc_attr($main_css)); + Helpers::enqueue( 'style', '_xe-style', '/style.css' ); + Helpers::enqueue( 'style', 'bootstrap', '/assets/css/bootstrap.min.css' ); + Helpers::enqueue( 'style', 'fontawesome', '/assets/css/all.min.css' ); + Helpers::enqueue( 'style', '_xe-main', '/assets/css/main.css' ); /** * # Scripts */ - wp_enqueue_script('bootstrap', get_template_directory_uri() . "/assets/js/bootstrap.bundle.min.js", array('jquery'), esc_attr($bootstrap_js), true); - wp_enqueue_script('stellar', get_template_directory_uri() . "/assets/js/stellar.min.js", array('jquery'), esc_attr($stellar_js), true); - wp_enqueue_script('sticky', get_template_directory_uri() . "/assets/js/sticky.min.js", array('jquery'), esc_attr($sticky_js), true); + Helpers::enqueue( 'script', 'bootstrap', '/assets/js/bootstrap.bundle.min.js', ['jquery'] ); + Helpers::enqueue( 'script', 'stellar', '/assets/js/stellar.min.js', ['jquery'] ); + Helpers::enqueue( 'script', 'sticky', '/assets/js/sticky.min.js', ['jquery'] ); + Helpers::enqueue( 'script', '_xe-main', '/assets/js/main.js', ['jquery'] ); + + if ( is_singular() && comments_open() && get_option('thread_comments') ) { - wp_enqueue_script('_xe-main', get_template_directory_uri() . '/assets/js/main.js', array('jquery'), esc_attr($main_js), true); + wp_enqueue_script( 'comment-reply' ); - if (is_singular() && comments_open() && get_option('thread_comments')) { - wp_enqueue_script('comment-reply'); } } @@ -71,19 +61,15 @@ public function frontend() { */ public function backend() { - // Version Control for admin CSS and JS - $admin_css = filemtime(get_template_directory() . '/assets/css/admin.css'); - $admin_js = filemtime(get_template_directory() . '/assets/js/admin.js'); - /** * # Styles */ - wp_enqueue_style('_xe-admin', get_template_directory_uri() . '/assets/css/admin.css', array(), esc_attr($admin_css)); + Helpers::enqueue( 'style', '_xe-admin', '/assets/css/admin.css' ); /** * # Scripts */ - wp_enqueue_script('_xe-admin', get_template_directory_uri() . '/assets/js/admin.js', array(), esc_attr($admin_js), true); + Helpers::enqueue( 'script', '_xe-admin', '/assets/js/admin.js', ['jquery'] ); }