<?php
/**
 * Theme functions and definitions
 *
 * @package ovation_health_blog
 */

//enque files
if ( ! function_exists( 'ovation_health_blog_enqueue_styles' ) ) :
	/**
	 * Load assets.
	 *
	 * @since 1.0.0
	 */
	function ovation_health_blog_enqueue_styles() {
		wp_enqueue_style( 'ovation-blog-style-parent', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'ovation-health-blog-style', get_stylesheet_directory_uri() . '/style.css', array( 'ovation-blog-style-parent' ), '1.0.0' );
        // Theme Customize CSS.
        require get_parent_theme_file_path( 'inc/extra_customization.php' );
        wp_add_inline_style( 'ovation-health-blog-style',$ovation_blog_custom_style );

        require get_theme_file_path( 'inc/extra_customization.php' );
        wp_add_inline_style( 'ovation-health-blog-style',$ovation_blog_custom_style );

        // blocks css
        wp_enqueue_style( 'ovation-health-blog-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'ovation-health-blog-style' ), '1.0' );
	}
endif;
add_action( 'wp_enqueue_scripts', 'ovation_health_blog_enqueue_styles', 99 );

// theme setup
function ovation_health_blog_setup() {
    add_theme_support( "align-wide" );
    add_theme_support( "wp-block-styles" );
    add_theme_support( 'responsive-embeds' );
    add_theme_support( 'woocommerce' );
    add_theme_support( 'automatic-feed-links' );
    add_theme_support( 'post-thumbnails' );
    add_theme_support( 'title-tag' );
    add_theme_support('custom-background',array(
        'default-color' => 'ffffff',
    ));
    add_image_size( 'ovation-health-blog-featured-image', 2000, 1200, true );
    add_image_size( 'ovation-health-blog-thumbnail-avatar', 100, 100, true );

    $GLOBALS['content_width'] = 525;

    add_theme_support( 'html5', array(
        'comment-form',
        'comment-list',
        'gallery',
        'caption',
    ) );

    // Add theme support for Custom Logo.
    add_theme_support( 'custom-logo', array(
        'width'       => 250,
        'height'      => 250,
        'flex-width'  => true,
        'flex-height'  => true,
    ) );

    /*
     * This theme styles the visual editor to resemble the theme style,
     * specifically font, colors, and column width.
     */
    add_editor_style( array( 'assets/css/editor-style.css') );


            if ( ! defined( 'OVATION_BLOG_SUPPORT' ) ) {
            define('OVATION_BLOG_SUPPORT',__('https://wordpress.org/support/theme/ovation-blog/','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_REVIEW' ) ) {
            define('OVATION_BLOG_REVIEW',__('https://wordpress.org/support/theme/ovation-blog/reviews/','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_LIVE_DEMO' ) ) {
        define('OVATION_BLOG_LIVE_DEMO',__('https://trial.ovationthemes.com/ovation-blog-pro/','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_BUY_PRO' ) ) {
        define('OVATION_BLOG_BUY_PRO',__('https://www.ovationthemes.com/products/blog-wordpress-theme','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_PRO_DOC' ) ) {
        define('OVATION_BLOG_PRO_DOC',__('https://trial.ovationthemes.com/docs/ot-blog-pro/','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_FREE_DOC' ) ) {
        define('OVATION_BLOG_FREE_DOC',__('https://trial.ovationthemes.com/docs/ot-ovation-blog-free-doc/','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_THEME_NAME' ) ) {
        define('OVATION_BLOG_THEME_NAME',__('Premium Blog Theme','ovation-blog'));
        }
        if ( ! defined( 'OVATION_BLOG_BUNDLE_LINK' ) ) {
        define('OVATION_BLOG_BUNDLE_LINK',__('https://www.ovationthemes.com/products/wordpress-bundle','ovation-blog'));
        }
}
add_action( 'after_setup_theme', 'ovation_health_blog_setup' );

// custom header setup
function ovation_health_blog_custom_header_setup() {
    add_theme_support( 'custom-header', apply_filters( 'ovation_health_blog_custom_header_args', array(
        'default-image'          => get_parent_theme_file_uri( '/assets/images/header-img-2.jpg' ),
        'default-text-color'     => 'fff',
        'header-text'            => false,
        'width'                  => 1200,
        'height'                 => 80,
        'flex-width'             => true,
        'flex-height'            => true,
        'wp-head-callback'       => 'ovation_blog_header_style',
    ) ) );
}
add_action( 'after_setup_theme', 'ovation_health_blog_custom_header_setup' );

// widgets
function ovation_health_blog_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Sidebar', 'ovation-health-blog' ),
        'id'            => 'sidebar-1',
        'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow zoomIn %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<div class="widget_container"><h3 class="widget-title">',
        'after_title'   => '</h3></div>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Page Sidebar', 'ovation-health-blog' ),
        'id'            => 'sidebar-2',
        'description'   => __( 'Add widgets here to appear in your pages and posts', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow zoomIn %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<div class="widget_container"><h3 class="widget-title">',
        'after_title'   => '</h3></div>',
    ) );
    
    register_sidebar( array(
        'name'          => __( 'Sidebar 3', 'ovation-health-blog' ),
        'id'            => 'sidebar-3',
        'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow zoomIn %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<div class="widget_container"><h3 class="widget-title">',
        'after_title'   => '</h3></div>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 1', 'ovation-health-blog' ),
        'id'            => 'footer-1',
        'description'   => __( 'Add widgets here to appear in your footer.', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow slideInLeft %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 2', 'ovation-health-blog' ),
        'id'            => 'footer-2',
        'description'   => __( 'Add widgets here to appear in your footer.', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow slideInLeft %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 3', 'ovation-health-blog' ),
        'id'            => 'footer-3',
        'description'   => __( 'Add widgets here to appear in your footer.', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow slideInRight %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 4', 'ovation-health-blog' ),
        'id'            => 'footer-4',
        'description'   => __( 'Add widgets here to appear in your footer.', 'ovation-health-blog' ),
        'before_widget' => '<section id="%1$s" class="widget wow slideInRight %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
}
add_action( 'widgets_init', 'ovation_health_blog_widgets_init' );

// remove sections
function ovation_health_blog_customize_register() {
    global $wp_customize;
    $wp_customize->remove_section( 'ovation_blog_pro' );
    $wp_customize->remove_section( 'ovation_blog_post' );

    $wp_customize->remove_setting( 'ovation_blog_top_category_text' );
    $wp_customize->remove_control( 'ovation_blog_top_category_text' );

    $wp_customize->remove_setting( 'ovation_blog_top_category_heading' );
    $wp_customize->remove_control( 'ovation_blog_top_category_heading' );

    $wp_customize->remove_setting('ovation_blog_width_options');
    $wp_customize->remove_control('ovation_blog_width_options');

    $wp_customize->remove_setting('ovation_blog_section_theme_width_heading');
    $wp_customize->remove_control('ovation_blog_section_theme_width_heading');

    $wp_customize->remove_setting('ovation_blog_footer_text');
    $wp_customize->remove_control('ovation_blog_footer_text');

    $wp_customize->remove_setting('ovation_blog_primary_color');
    $wp_customize->remove_control('ovation_blog_primary_color');

    $wp_customize->remove_setting('ovation_blog_heading_color');
    $wp_customize->remove_control('ovation_blog_heading_color');

    $wp_customize->remove_setting('ovation_blog_text_color');
    $wp_customize->remove_control('ovation_blog_text_color');

    $wp_customize->remove_setting('ovation_blog_primary_fade');
    $wp_customize->remove_control('ovation_blog_primary_fade');

    $wp_customize->remove_setting('ovation_blog_top_head_color');
    $wp_customize->remove_control('ovation_blog_top_head_color');

    $wp_customize->remove_setting('ovation_blog_footer_bg');
    $wp_customize->remove_control('ovation_blog_footer_bg');

    $wp_customize->remove_setting('ovation_blog_slider_heading_color');
    $wp_customize->remove_control('ovation_blog_slider_heading_color');
}
add_action( 'customize_register', 'ovation_health_blog_customize_register', 11 );

// customizer
function ovation_health_blog_customize( $wp_customize ) {

    wp_enqueue_style('customizercustom_css', esc_url( get_stylesheet_directory_uri() ). '/assets/css/customizer.css');

    require get_theme_file_path( 'inc/custom-control.php' );

    // pro section
    $wp_customize->add_section('ovation_health_blog_pro', array(
        'title'    => __('UPGRADE HEALTH BLOG PREMIUM', 'ovation-health-blog'),
        'priority' => 1,
    ));
    $wp_customize->add_setting('ovation_health_blog_pro', array(
        'default'           => null,
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control(new Ovation_Health_Blog_Pro_Control($wp_customize, 'ovation_health_blog_pro', array(
        'label'    => __('HEALTH BLOG PREMIUM', 'ovation-health-blog'),
        'section'  => 'ovation_health_blog_pro',
        'settings' => 'ovation_health_blog_pro',
        'priority' => 1,
    )));

    //slider
    $wp_customize->add_setting(
        'ovation_health_blog_post_slider_show_hide',
        array(
            'type'                 => 'option',
            'capability'           => 'edit_theme_options',
            'theme_supports'       => '',
            'default'              => '1',
            'transport'            => 'refresh',
            'sanitize_callback'    => 'ovation_blog_callback_sanitize_switch',
        )
    );
    $wp_customize->add_control(
        new Ovation_Health_Blog_Customizer_Customcontrol_Switch(
            $wp_customize,
            'ovation_health_blog_post_slider_show_hide',
            array(
                'settings'        => 'ovation_health_blog_post_slider_show_hide',
                'section'         => 'ovation_blog_slider_section',
                'label'           => __( 'Check To Show Slider', 'ovation-health-blog' ),                
                'choices'         => array(
                    '1'      => __( 'On', 'ovation-health-blog' ),
                    'off'    => __( 'Off', 'ovation-health-blog' ),
                ),
                'active_callback' => '',
                'priority' => 2,
            )
        )
    );

    //meta 
    $wp_customize->add_setting('ovation_health_blog_front_date',
        array(
            'type'                 => 'option',
            'capability'           => 'edit_theme_options',
            'theme_supports'       => '',
            'default'              => '1',
            'transport'            => 'refresh',
            'sanitize_callback'    => 'ovation_blog_callback_sanitize_switch',
        )
    );
    $wp_customize->add_control(new Ovation_Health_Blog_Customizer_Customcontrol_Switch(
            $wp_customize,
            'ovation_health_blog_front_date',
            array(
                'settings'        => 'ovation_health_blog_front_date',
                'section'         => 'ovation_blog_slider_section',
                'label'           => __( 'Show Date', 'ovation-health-blog' ),             
                'choices'         => array(
                    '1'      => __( 'On', 'ovation-health-blog' ),
                    'off'    => __( 'Off', 'ovation-health-blog' ),
                ),
                'active_callback' => '',
                'priority' => 4,
            )
        )
    );
    $wp_customize->add_setting('ovation_health_blog_front_comment',
        array(
            'type'                 => 'option',
            'capability'           => 'edit_theme_options',
            'theme_supports'       => '',
            'default'              => '1',
            'transport'            => 'refresh',
            'sanitize_callback'    => 'ovation_blog_callback_sanitize_switch',
        )
    );
    $wp_customize->add_control(new Ovation_Health_Blog_Customizer_Customcontrol_Switch(
            $wp_customize,
            'ovation_health_blog_front_comment',
            array(
                'settings'        => 'ovation_health_blog_front_comment',
                'section'         => 'ovation_blog_slider_section',
                'label'           => __( 'Show comment', 'ovation-health-blog' ),             
                'choices'         => array(
                    '1'      => __( 'On', 'ovation-health-blog' ),
                    'off'    => __( 'Off', 'ovation-health-blog' ),
                ),
                'active_callback' => '',
                'priority' => 4,
            )
        )
    );

    //footer
    $wp_customize->add_setting('ovation_health_blog_footer_text',array(
        'default'   => 'Health Blog WordPress Theme',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('ovation_health_blog_footer_text',array(
        'label' => esc_html__('Copyright Text','ovation-health-blog'),
        'section'   => 'ovation_blog_footer_copyright',
        'type'      => 'textarea'
    ));

    $wp_customize->add_setting('ovation_health_blog_primary_color', array(
        'default' => '#dab768',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'refresh',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ovation_health_blog_primary_color', array(
        'section' => 'colors',
        'label' => esc_html__('Theme Color', 'ovation-health-blog'),
     
    )));

    $wp_customize->add_setting('ovation_health_blog_heading_color', array(
        'default' => '#000',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'refresh',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ovation_health_blog_heading_color', array(
        'section' => 'colors',
        'label' => esc_html__('Theme Heading Color', 'ovation-health-blog'),
     
    )));

    $wp_customize->add_setting('ovation_health_blog_text_color', array(
        'default' => '#7d7d7d',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'refresh',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ovation_health_blog_text_color', array(
        'section' => 'colors',
        'label' => esc_html__('Theme Text Color', 'ovation-health-blog'),
     
    )));

    $wp_customize->add_setting('ovation_health_blog_primary_fade', array(
        'default' => '#fff6e2',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'refresh',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ovation_health_blog_primary_fade', array(
        'section' => 'colors',
        'label' => esc_html__('theme Color Light', 'ovation-health-blog'),
     
    )));

    $wp_customize->add_setting('ovation_health_blog_footer_bg', array(
        'default' => '#000',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'refresh',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'ovation_health_blog_footer_bg', array(
        'section' => 'colors',
        'label' => esc_html__('Header/Footer Bg color', 'ovation-health-blog'),
    )));
}
add_action( 'customize_register', 'ovation_health_blog_customize' );

// comments
function ovation_health_blog_enqueue_comments_reply() {
    if( get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'comment_form_before', 'ovation_health_blog_enqueue_comments_reply' );

// Footer Text
function ovation_health_blog_copyright_link() {
    $ovation_health_blog_footer_text = get_theme_mod('ovation_health_blog_footer_text', esc_html__('Health Blog WordPress Theme', 'ovation-health-blog'));
    $ovation_health_blog_credit_link = esc_url('https://www.ovationthemes.com/products/free-health-wordpress-theme');

    echo '<a href="' . $ovation_health_blog_credit_link . '" target="_blank">' . esc_html($ovation_health_blog_footer_text) . '<span class="footer-copyright">' . esc_html__(' By Ovation Themes', 'ovation-health-blog') . '</span></a>';
}

/* Pro control */
if (class_exists('WP_Customize_Control') && !class_exists('Ovation_Health_Blog_Pro_Control')):
    class Ovation_Health_Blog_Pro_Control extends WP_Customize_Control{

    public function render_content(){?>
        <label style="overflow: hidden; zoom: 1;">
            <div class="col-md upsell-btn">
                <a href="<?php echo esc_url( OVATION_BLOG_BUY_PRO ); ?>" target="blank" class="btn btn-success btn"><?php esc_html_e('UPGRADE HEALTH BLOG PREMIUM','ovation-health-blog');?> </a>
            </div>
            <div class="col-md">
                <img class="ovation_health_blog_img_responsive " src="<?php echo esc_url( get_stylesheet_directory_uri() ); ?>/screenshot.png">
            </div>
            <div class="col-md">
                <h3 style="margin-top:10px; margin-left: 20px; font-size:12px; text-decoration:underline; color:#333;"><?php esc_html_e('HEALTH BLOG PREMIUM - Features', 'ovation-health-blog'); ?></h3>
                <ul style="padding-top:10px">
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Responsive Design', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Boxed or fullwidth layout', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Shortcode Support', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Demo Importer', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Section Reordering', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Contact Page Template', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Multiple Blog Layouts', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Unlimited Color Options', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Designed with HTML5 and CSS3', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Customizable Design & Code', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Cross Browser Support', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Detailed Documentation Included', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Stylish Custom Widgets', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Patterns Background', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('WPML Compatible (Translation Ready)', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Woo-commerce Compatible', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Full Support', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('10+ Sections', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Live Customizer', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('AMP Ready', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Clean Code', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('SEO Friendly', 'ovation-health-blog');?> </li>
                    <li class="upsell-ovation_health_blog"> <div class="dashicons dashicons-yes"></div> <?php esc_html_e('Supper Fast', 'ovation-health-blog');?> </li>
                </ul>
            </div>
            <div class="col-md upsell-btn upsell-btn-bottom">
                <a href="<?php echo esc_url( OVATION_BLOG_BUNDLE_LINK ); ?>" target="blank" class="btn btn-success btn"><?php esc_html_e('WP Theme Bundle (125+ Themes)','ovation-health-blog');?> </a>
            </div>
        </label>
    <?php } }
endif;
