balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-appside-init.php (16532B)


      1 <?php
      2 /**
      3  * @package Dizzcox
      4  * @author Ir Tech
      5  */
      6 if (!defined("ABSPATH")) {
      7 	exit(); //exit if access directly
      8 }
      9 
     10 if (!class_exists('Class_Appside_Init')) {
     11 
     12 	class Class_Appside_Init
     13 	{
     14 		/*
     15 		* $instance
     16 		* @since 1.0.0
     17 		* */
     18 		protected static $instance;
     19 
     20 		public function __construct()
     21 		{
     22 			/*
     23 			 * theme setup
     24 			 * */
     25 			add_action( 'after_setup_theme', array($this,'theme_setup') );
     26 			/**
     27 			 * Widget Init
     28 			 * */
     29 			add_action( 'widgets_init', array($this,'theme_widgets_init') );
     30 			/**
     31 			 * Theme Assets
     32 			 * */
     33 			add_action( 'wp_enqueue_scripts', array($this,'theme_assets') );
     34 			/**
     35 			 * Registers an editor stylesheet for the theme.
     36 			 */
     37 			add_action( 'admin_init', array($this,'add_editor_styles' ));
     38 			/**
     39 			 * Register gutenberg editor css
     40 			 * */
     41 			add_action('enqueue_block_editor_assets',array($this,'gutenberg_editor_assets'));
     42 		}
     43 
     44 		/**
     45 		 * getInstance()
     46 		 * */
     47 		public static function getInstance()
     48 		{
     49 			if (null == self::$instance) {
     50 				self::$instance = new self();
     51 			}
     52 			return self::$instance;
     53 		}
     54 
     55 		/**
     56 		 * Theme Setup
     57 		 * @since 1.0.0
     58 		 * */
     59 		public function theme_setup(){
     60 			/*
     61 		 * Make theme available for translation.
     62 		 * Translations can be filed in the /languages/ directory.
     63 		 * If you're building a theme based on appside, use a find and replace
     64 		 * to change 'aapside' to the name of your theme in all the template files.
     65 		 */
     66 			load_theme_textdomain( 'aapside', get_template_directory() . '/languages' );
     67 
     68 			// Add default posts and comments RSS feed links to head.
     69 			add_theme_support( 'automatic-feed-links' );
     70 
     71 			/*
     72 			 * Let WordPress manage the document title.
     73 			 * By adding theme support, we declare that this theme does not use a
     74 			 * hard-coded <title> tag in the document head, and expect WordPress to
     75 			 * provide it for us.
     76 			 */
     77 			add_theme_support( 'title-tag' );
     78 
     79 			/*
     80 			 * Enable support for Post Thumbnails on posts and pages.
     81 			 *
     82 			 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
     83 			 */
     84 			add_theme_support( 'post-thumbnails' );
     85 
     86 			// This theme uses wp_nav_menu() in one location.
     87 			register_nav_menus( array(
     88 				'main-menu' => esc_html__( 'Primary Menu', 'aapside' ),
     89 			) );
     90 
     91 			/*
     92 			 * Switch default core markup for search form, comment form, and comments
     93 			 * to output valid HTML5.
     94 			 */
     95 			add_theme_support( 'html5', array(
     96 				'search-form',
     97 				'comment-form',
     98 				'comment-list',
     99 				'gallery',
    100 				'caption',
    101 			) );
    102 
    103 			// Set up the WordPress core custom background feature.
    104 			add_theme_support( 'custom-background', apply_filters( 'appside_custom_background_args', array(
    105 				'default-color' => 'ffffff',
    106 				'default-image' => '',
    107 			) ) );
    108 
    109 			// Add theme support for selective refresh for widgets.
    110 			add_theme_support( 'customize-selective-refresh-widgets' );
    111 
    112 			add_theme_support( 'responsive-embeds' );
    113 			// -- Wide Images
    114 			add_theme_support( 'align-wide' );
    115 			// -- Disable custom font sizes
    116 			add_theme_support( 'disable-custom-font-sizes' );
    117 
    118 			/**
    119 			 * Add support for core custom logo.
    120 			 *
    121 			 * @link https://codex.wordpress.org/Theme_Logo
    122 			 */
    123 			add_theme_support( 'custom-logo', array(
    124 				'height'      => 250,
    125 				'width'       => 250,
    126 				'flex-width'  => true,
    127 				'flex-height' => true,
    128 			) );
    129 			// -- Editor Font Styles
    130 			add_theme_support( 'editor-font-sizes', array(
    131 				array(
    132 					'name'      => esc_html__( 'small', 'aapside' ),
    133 					'shortName' => esc_html__( 'S', 'aapside' ),
    134 					'size'      => 12,
    135 					'slug'      => 'small'
    136 				),
    137 				array(
    138 					'name'      => esc_html__( 'regular', 'aapside' ),
    139 					'shortName' => esc_html__( 'M', 'aapside' ),
    140 					'size'      => 16,
    141 					'slug'      => 'regular'
    142 				),
    143 				array(
    144 					'name'      => esc_html__( 'large', 'aapside' ),
    145 					'shortName' => esc_html__( 'L', 'aapside' ),
    146 					'size'      => 20,
    147 					'slug'      => 'large'
    148 				),
    149 			) );
    150 
    151 			// -- Disable Custom Colors
    152 			add_theme_support( 'disable-custom-colors' );
    153 			// -- Editor Color Palette
    154 			add_theme_support( 'editor-color-palette', array(
    155 				array(
    156 					'name'  => esc_html__( 'Blue', 'aapside' ),
    157 					'slug'  => 'blue',
    158 					'color'	=> '#59BACC',
    159 				),
    160 				array(
    161 					'name'  => esc_html__( 'Green', 'aapside' ),
    162 					'slug'  => 'green',
    163 					'color' => '#58AD69',
    164 				),
    165 				array(
    166 					'name'  => esc_html__( 'Orange', 'aapside' ),
    167 					'slug'  => 'orange',
    168 					'color' => '#FFBC49',
    169 				),
    170 				array(
    171 					'name'	=> esc_html__( 'Red', 'aapside' ),
    172 					'slug'	=> 'red',
    173 					'color'	=> '#E2574C',
    174 				),
    175 			) );
    176 			add_theme_support( 'wp-block-styles' );
    177 			//add theme support for post format
    178 			add_theme_support('post-formats',array('image','video','gallery','link','quote'));
    179 			// This variable is intended to be overruled from themes.
    180 			// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
    181 			// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
    182 			$GLOBALS['content_width'] = apply_filters( 'appside_content_width', 740 );
    183 			//add image sizes
    184 			add_image_size('appside_classic',750,350,true);
    185 			add_image_size('appside_medium',550,380,true);
    186 			add_image_size('appside_grid',370,270,true);
    187 			add_image_size('appside_portfolio',360,340,true);
    188 			add_image_size('appside_portfolio_single',750);
    189 
    190 			//woocommerce support
    191 			add_theme_support('woocommerce');
    192 			add_theme_support( 'wc-product-gallery-zoom' );
    193 			add_theme_support( 'wc-product-gallery-lightbox' );
    194 			add_theme_support( 'wc-product-gallery-slider' );
    195 
    196 			self::load_theme_dependency_files();
    197 		}
    198 
    199 		/**
    200 		 * Theme Widget Init
    201 		 * @since 1.0.0
    202 		 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
    203 		 * */
    204 		public function theme_widgets_init(){
    205 			register_sidebar( array(
    206 				'name'          => esc_html__( 'Sidebar', 'aapside' ),
    207 				'id'            => 'sidebar-1',
    208 				'description'   => esc_html__( 'Add widgets here.', 'aapside' ),
    209 				'before_widget' => '<div id="%1$s" class="widget %2$s">',
    210 				'after_widget'  => '</div>',
    211 				'before_title'  => '<h4 class="widget-title">',
    212 				'after_title'   => '</h4>',
    213 			) );
    214 			register_sidebar( array(
    215 				'name'          => esc_html__( 'Footer Widget Area', 'aapside' ),
    216 				'id'            => 'footer-widget',
    217 				'description'   => esc_html__( 'Add widgets here.', 'aapside' ),
    218 				'before_widget' => '<div class="col-lg-3 col-md-6"><div id="%1$s" class="widget footer-widget %2$s">',
    219 				'after_widget'  => '</div></div>',
    220 				'before_title'  => '<h4 class="widget-title">',
    221 				'after_title'   => '</h4>',
    222 			) );
    223 		}
    224 
    225 		/**
    226 		 * Theme Assets
    227 		 * @since 1.0.0
    228 		 * */
    229 		public function theme_assets(){
    230 			self::load_theme_css();
    231 			self::load_theme_js();
    232 		}
    233 		/*
    234 	   * load theme options google fonts css
    235 	   * @since 1.0.0
    236 	   * */
    237 		public static function load_google_fonts(){
    238 
    239 			$enqueue_fonts = array();
    240 			//body font enqueue
    241 			$body_font = cs_get_option('_body_font') ? cs_get_option('_body_font') : false;
    242 			$body_font_variant = cs_get_option('body_font_variant') ? cs_get_option('body_font_variant') : false;
    243 			$body_font['family'] = ( isset($body_font['font-family']) && !empty($body_font['font-family']) ) ? $body_font['font-family'] : 'Poppins';
    244 			$body_font['font'] = ( isset($body_font['type']) && !empty($body_font['type']) ) ? $body_font['type'] : 'google';
    245 			$body_font_variant = !empty($body_font_variant) ? $body_font_variant : array(400,700,600,500);
    246 			$google_fonts = array();
    247 
    248 			if ( !empty($body_font_variant) ){
    249 				foreach ($body_font_variant as $variant){
    250 					$google_fonts[] = array(
    251 						'family' => $body_font['family'],
    252 						'variant' => $variant,
    253 						'font' => $body_font['font']
    254 					);
    255 				}
    256 			}
    257 			//heading font enqueue
    258 			$heading_font_enable = false;
    259 			if (null == cs_get_option('heading_font_enable')){
    260 				$heading_font_enable = false;
    261 			}elseif ('0' == cs_get_option('heading_font_enable')){
    262 				$heading_font_enable = true;
    263 			}elseif('1' == cs_get_option('heading_font_enable')){
    264 				$heading_font_enable = false;
    265 			}
    266 			$heading_font = cs_get_option('heading_font') ? cs_get_option('heading_font') : false;
    267 			$heading_font_variant = cs_get_option('heading_font_variant') ? cs_get_option('heading_font_variant') : false;
    268 			$heading_font['family'] = ( isset($heading_font['font-family']) && !empty($heading_font['font-family']) ) ? $heading_font['font-family'] : 'Poppins';
    269 			$heading_font['font'] = ( isset($heading_font['type']) && !empty($heading_font['type']) ) ? $heading_font['type'] : 'google';
    270 			$heading_font_variant = !empty($heading_font_variant) ? $heading_font_variant : array(400,500,600,700,800);
    271 			if ( !empty($heading_font_variant) &&  !$heading_font_enable){
    272 				foreach ($heading_font_variant as $variant){
    273 					$google_fonts[] = array(
    274 						'family' => $heading_font['family'],
    275 						'variant' => $variant,
    276 						'font' => $heading_font['font']
    277 					);
    278 				}
    279 			}
    280 
    281 			if ( ! empty( $google_fonts ) ) {
    282 				foreach ( $google_fonts as $font ) {
    283 					if( !empty( $font['font'] ) && $font['font'] == 'google' ) {
    284 						$variant = ( !empty( $font['variant'] ) && $font['variant'] !== 'regular' ) ? ':'. $font['variant'] : '';
    285 						if( !empty($font['family']) ){
    286 							$enqueue_fonts[] = $font['family'] . $variant;
    287 						}
    288 					}
    289 				}
    290 			}
    291 
    292 			$enqueue_fonts = array_unique($enqueue_fonts);
    293 			return $enqueue_fonts;
    294 		}
    295 		/**
    296 		 * Load Theme Css
    297 		 * @since 1.0.0
    298 		 * */
    299 		public function load_theme_css(){
    300 			$theme_version = Appside()->get_theme_info('version');
    301 			//load google fonts
    302 			$enqueue_google_fonts = self::load_google_fonts();
    303 			if ( ! empty( $enqueue_google_fonts ) ) {
    304 				wp_enqueue_style( 'appside-google-fonts', esc_url( add_query_arg( 'family', urlencode( implode( '|', $enqueue_google_fonts ) ) , '//fonts.googleapis.com/css' ) ), array(), null );
    305 			}
    306 			$all_css_files = array(
    307 				array(
    308 					'handle' => 'animate',
    309 					'src' => APPSIDE_CSS .'/animate.css',
    310 					'deps' => array(),
    311 					'ver' => $theme_version,
    312 					'media' => 'all',
    313 				),
    314 				array(
    315 					'handle' => 'bootstrap',
    316 					'src' => APPSIDE_CSS .'/bootstrap.min.css',
    317 					'deps' => array(),
    318 					'ver' => $theme_version,
    319 					'media' => 'all',
    320 				),
    321 				array(
    322 					'handle' => 'font-awesome',
    323 					'src' => APPSIDE_CSS .'/font-awesome.min.css',
    324 					'deps' => array(),
    325 					'ver' => $theme_version,
    326 					'media' => 'all',
    327 				),
    328 				array(
    329 					'handle' => 'magnific-popup',
    330 					'src' => APPSIDE_CSS .'/magnific-popup.css',
    331 					'deps' => array(),
    332 					'ver' => $theme_version,
    333 					'media' => 'all',
    334 				),
    335 				array(
    336 					'handle' => 'appside-default-style',
    337 					'src' => APPSIDE_CSS .'/default-style.css',
    338 					'deps' => array(),
    339 					'ver' => $theme_version,
    340 					'media' => 'all',
    341 				),
    342 				array(
    343 					'handle' => 'appside-main-style',
    344 					'src' => APPSIDE_CSS .'/main-style.css',
    345 					'deps' => array(),
    346 					'ver' => $theme_version,
    347 					'media' => 'all',
    348 				),
    349 				array(
    350 					'handle' => 'appside-gutenberg-style',
    351 					'src' => APPSIDE_CSS .'/gutenberg.css',
    352 					'deps' => array(),
    353 					'ver' => $theme_version,
    354 					'media' => 'all',
    355 				),
    356 				array(
    357 					'handle' => 'woocommerce-style',
    358 					'src' => APPSIDE_CSS .'/woocommerce-style.css',
    359 					'deps' => array(),
    360 					'ver' => $theme_version,
    361 					'media' => 'all',
    362 				),
    363 				array(
    364 					'handle' => 'appside-responsive',
    365 					'src' => APPSIDE_CSS .'/responsive.css',
    366 					'deps' => array('appside-main-style'),
    367 					'ver' => $theme_version,
    368 					'media' => 'all',
    369 				),
    370 			);
    371 
    372 			$all_css_files = apply_filters('appside_theme_enqueue_style',$all_css_files);
    373 
    374 			if (is_array($all_css_files) && !empty($all_css_files)){
    375 				foreach ($all_css_files as $css){
    376 					call_user_func_array('wp_enqueue_style',$css);
    377 				}
    378 			}
    379 			wp_enqueue_style( 'appside-style', get_stylesheet_uri() );
    380 
    381 			if (Appside()->is_appside_master_active()){
    382 				if (file_exists(APPSIDE_DYNAMIC_STYLESHEETS .'/appside-inline-style.php')){
    383 					require_once APPSIDE_DYNAMIC_STYLESHEETS .'/appside-inline-style.php';
    384 					wp_add_inline_style('appside-style',Appside()->minify_css_lines($GLOBALS['appside_inline_css']));
    385 					wp_add_inline_style('appside-style',Appside()->minify_css_lines($GLOBALS['theme_customize_css']));
    386 				}
    387 
    388 			}
    389 		}
    390 
    391 		/**
    392 		 * Load Theme js
    393 		 * @since 1.0.0
    394 		 * */
    395 		public function load_theme_js(){
    396 			$theme_version = Appside()->get_theme_info('version');
    397 
    398 			$all_js_files = array(
    399 				array(
    400 					'handle' => 'popper',
    401 					'src' => APPSIDE_JS .'/popper.min.js',
    402 					'deps' => array('jquery'),
    403 					'ver' => $theme_version,
    404 					'in_footer' => true,
    405 				),
    406 				array(
    407 					'handle' => 'bootstrap',
    408 					'src' => APPSIDE_JS .'/bootstrap.min.js',
    409 					'deps' => array('jquery','popper'),
    410 					'ver' => $theme_version,
    411 					'in_footer' => true,
    412 				),
    413 				array(
    414 					'handle' => 'magnific-popup',
    415 					'src' => APPSIDE_JS .'/jquery.magnific-popup.js',
    416 					'deps' => array('jquery'),
    417 					'ver' => $theme_version,
    418 					'in_footer' => true,
    419 				),
    420 				array(
    421 					'handle' => 'appside-main-script',
    422 					'src' => APPSIDE_JS .'/main.js',
    423 					'deps' => array('jquery'),
    424 					'ver' => $theme_version,
    425 					'in_footer' => true,
    426 				),
    427 			);
    428 
    429 			$all_js_files = apply_filters('appside_theme_enqueue_script',$all_js_files);
    430 
    431 			if (is_array($all_js_files) && !empty($all_js_files)){
    432 				foreach ($all_js_files as $js){
    433 					call_user_func_array('wp_enqueue_script',$js);
    434 				}
    435 			}
    436 
    437 			if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    438 				wp_enqueue_script( 'comment-reply' );
    439 			}
    440 		}
    441 
    442 		/**
    443 		 * Load THeme Dependency Files
    444 		 * @since 1.0.0
    445 		 * */
    446 		public function load_theme_dependency_files(){
    447 			$includes_files = array(
    448 				array(
    449 					'file-name' => 'activation',
    450 					'file-path' => APPSIDE_TGMA
    451 				),
    452 				array(
    453 					'file-name' => 'breadcrumb',
    454 					'file-path' => APPSIDE_INC
    455 				),
    456 				array(
    457 					'file-name' => 'class-appside-excerpt',
    458 					'file-path' => APPSIDE_INC
    459 				),
    460 				array(
    461 					'file-name' => 'class-megamenu-walker',
    462 					'file-path' => APPSIDE_INC
    463 				),
    464 				array(
    465 					'file-name' => 'class-appside-hook-customize',
    466 					'file-path' => APPSIDE_INC
    467 				),
    468 				array(
    469 					'file-name' => 'comments-modifications',
    470 					'file-path' => APPSIDE_INC
    471 				),
    472 				array(
    473 					'file-name' => 'customizer',
    474 					'file-path' => APPSIDE_INC
    475 				),
    476 				array(
    477 					'file-name' => 'csf-group-fields',
    478 					'file-path' => APPSIDE_THEME_SETTINGS
    479 				),
    480 				array(
    481 					'file-name' => 'csf-group-fields-value',
    482 					'file-path' => APPSIDE_THEME_SETTINGS
    483 				),
    484 				array(
    485 					'file-name' => 'csf-metabox',
    486 					'file-path' => APPSIDE_THEME_SETTINGS
    487 				),
    488 				array(
    489 					'file-name' => 'csf-shortcode-options',
    490 					'file-path' => APPSIDE_THEME_SETTINGS
    491 				),
    492 				array(
    493 					'file-name' => 'csf-customizer',
    494 					'file-path' => APPSIDE_THEME_SETTINGS
    495 				),
    496 				array(
    497 					'file-name' => 'csf-options',
    498 					'file-path' => APPSIDE_THEME_SETTINGS
    499 				),
    500 			);
    501 
    502 			if (defined('APPSIDE_MASTER_SELF_PATH')){
    503 				$includes_files[] = array(
    504 					'file-name' => 'appside-options-style',
    505 					'file-path' => APPSIDE_DYNAMIC_STYLESHEETS
    506 				);
    507 			}
    508 			if (class_exists('WooCommerce')){
    509 				$includes_files[] = array(
    510 					'file-name' => 'class-woocommerce-customize',
    511 					'file-path' => APPSIDE_INC
    512 				);
    513 			}
    514 
    515 			if (is_array($includes_files) && !empty($includes_files)){
    516 				foreach ($includes_files as $file){
    517 					if (file_exists($file['file-path'].'/'.$file['file-name'].'.php')){
    518 						require_once $file['file-path'].'/'.$file['file-name'].'.php';
    519 					}
    520 				}
    521 			}
    522 		}
    523 
    524 
    525 		/**
    526 		 * add editor style
    527 		 * @since 1.0.0
    528 		 * */
    529 		public function add_editor_styles(){
    530 			add_editor_style(get_template_directory_uri().'/assets/css/editor-style.css');
    531 		}
    532 
    533 		/**
    534 		 * gutenberg editor style enqueue
    535 		 * */
    536 		public function gutenberg_editor_assets(){
    537 			//load google fonts
    538 			$enqueue_google_fonts = self::load_google_fonts();
    539 			if ( ! empty( $enqueue_google_fonts ) ) {
    540 				wp_enqueue_style( 'appside-google-fonts', esc_url( add_query_arg( 'family', urlencode( implode( '|', $enqueue_google_fonts ) ) , '//fonts.googleapis.com/css' ) ), array(), null );
    541 			}
    542 			wp_enqueue_style( 'fontawesome', get_theme_file_uri( '/assets/css/font-awesome.min.css' ), false, '1.0', 'all' );
    543 			wp_enqueue_style( 'appside-gutenberg', get_theme_file_uri( '/assets/css/gutenberg-editor-style.css' ), false, '1.0', 'all' );
    544 		}
    545 
    546 	}//end class
    547 	if (class_exists('Class_Appside_Init')){
    548 		Class_Appside_Init::getInstance();
    549 	}
    550 }