<?php
/**
 * Check and setup theme's default settings
 *
 * @package Bexplore
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'bexplore_setup_theme_default_settings' ) ) {
	/**
	 * Store default theme settings in database.
	 */
	function bexplore_setup_theme_default_settings() {
		$defaults = bexplore_get_theme_default_settings();
		$settings = get_theme_mods();
		foreach ( $defaults as $setting_id => $default_value ) {
			// Check if setting is set, if not set it to its default value.
			if ( ! isset( $settings[ $setting_id ] ) ) {
				set_theme_mod( $setting_id, $default_value );
			}
		}
	}
}

if ( ! function_exists( 'bexplore_get_theme_default_settings' ) ) {
	/**
	 * Retrieve default theme settings.
	 *
	 * @return array
	 */
	function bexplore_get_theme_default_settings() {
		$defaults = array(
			'bexplore_sidebar_position'  => 'right',     // Sidebar position.
			'bexplore_container_type'    => 'container', // Container width.
		);

		/**
		 * Filters the default theme settings.
		 *
		 * @param array $defaults Array of default theme settings.
		 */
		return apply_filters( 'bexplore_theme_default_settings', $defaults );
	}
}



add_filter( 'body_class', 'bexplore_body_classes' );

if ( ! function_exists( 'bexplore_body_classes' ) ) {
	/**
	 * Adds custom classes to the array of body classes.
	 *
	 * @param array $classes Classes for the body element.
	 *
	 * @return array
	 */
	function bexplore_body_classes( $classes ) {
		// Adds a class of group-blog to blogs with more than 1 published author.
		if ( is_multi_author() ) {
			$classes[] = 'group-blog';
		}
		// Adds a class of hfeed to non-singular pages.
		if ( ! is_singular() ) {
			$classes[] = 'hfeed';
		}

		// Adds a body class based on the presence of a sidebar.
		$sidebar_pos = get_theme_mod( 'bexplore_sidebar_position' );
		if ( is_page_template( 'page-templates/fullwidthpage.php' ) ) {
			$classes[] = 'bexplore-no-sidebar';
		} elseif (
		is_page_template(
			array(
				'page-templates/both-sidebarspage.php',
				'page-templates/left-sidebarpage.php',
				'page-templates/right-sidebarpage.php',
			)
		)
		) {
			$classes[] = 'bexplore-has-sidebar';
		} elseif ( 'none' !== $sidebar_pos ) {
			$classes[] = 'bexplore-has-sidebar';
		} else {
			$classes[] = 'bexplore-no-sidebar';
		}

		return $classes;
	}
}

if ( function_exists( 'bexplore_adjust_body_class' ) ) {
	/*
	 * bexplore_adjust_body_class() deprecated in v0.9.4. We keep adding the
	 * filter for child themes which use their own bexplore_adjust_body_class.
	 */
	add_filter( 'body_class', 'bexplore_adjust_body_class' );
}