<?php

require get_stylesheet_directory() . '/customizer/customizer.php';

add_action( 'after_setup_theme', 'construction_renovation_after_setup_theme' );
function construction_renovation_after_setup_theme() {
    add_theme_support( 'title-tag' );
    add_theme_support( 'automatic-feed-links' );
    add_theme_support( 'responsive-embeds' );
    add_theme_support( 'wp-block-styles' );
    add_theme_support( 'align-wide' );
    add_theme_support( 'post-thumbnails' );
    add_image_size( 'construction-renovation-featured-image', 2000, 1200, true );
    add_image_size( 'construction-renovation-thumbnail-avatar', 100, 100, true );

    // Set the default content width.
    $GLOBALS['content_width'] = 525;

    // Add theme support for Custom Logo.
    add_theme_support( 'custom-logo', array(
        'width'       => 250,
        'height'      => 250,
        'flex-width'  => true,
    ) );

    add_theme_support( 'custom-background', array(
        'default-color' => 'ffffff'
    ) );

    add_theme_support( 'html5', array('comment-form','comment-list','gallery','caption',) );

    add_editor_style( array( 'assets/css/editor-style.css') );
}

/**
 * Register widget area.
 */
function construction_renovation_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Blog Sidebar', 'construction-renovation' ),
        'id'            => 'sidebar-1',
        'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Page Sidebar', 'construction-renovation' ),
        'id'            => 'sidebar-2',
        'description'   => __( 'Add widgets here to appear in your sidebar on pages.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Sidebar 3', 'construction-renovation' ),
        'id'            => 'sidebar-3',
        'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 1', 'construction-renovation' ),
        'id'            => 'footer-1',
        'description'   => __( 'Add widgets here to appear in your footer.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 2', 'construction-renovation' ),
        'id'            => 'footer-2',
        'description'   => __( 'Add widgets here to appear in your footer.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 3', 'construction-renovation' ),
        'id'            => 'footer-3',
        'description'   => __( 'Add widgets here to appear in your footer.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Footer 4', 'construction-renovation' ),
        'id'            => 'footer-4',
        'description'   => __( 'Add widgets here to appear in your footer.', 'construction-renovation' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ) );
}
add_action( 'widgets_init', 'construction_renovation_widgets_init' );

// enqueue styles for child theme
function construction_renovation_enqueue_styles() {

    // Bootstrap
    wp_enqueue_style( 'bootstrap-css', get_theme_file_uri( '/assets/css/bootstrap.css' ) );

    // Theme block stylesheet.
    wp_enqueue_style( 'construction-renovation-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'construction-renovation-child-style' ), '1.0' );
    
    // enqueue parent styles
    wp_enqueue_style('construction-hub-style', get_template_directory_uri() .'/style.css');
    
    // enqueue child styles
    wp_enqueue_style('construction-renovation-child-style', get_stylesheet_directory_uri() .'/style.css', array('construction-hub-style'));

    wp_style_add_data('construction-renovation-child-style', 'rtl', 'replace');

    wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
}
add_action('wp_enqueue_scripts', 'construction_renovation_enqueue_styles');

function construction_renovation_header_style() {
    if ( get_header_image() ) :
    $custom_header = "
        .header-main{
            background-image:url('".esc_url(get_header_image())."') !important;
            background-position: center top;
        }";
        wp_add_inline_style( 'construction-renovation-child-style', $custom_header );
    endif;
}
add_action( 'wp_enqueue_scripts', 'construction_renovation_header_style' );

define('CONSTRUCTION_RENOVATION_CREDIT',__('https://www.themespride.com/themes/free-renovation-wordpress-theme/','construction-renovation') );
if ( ! function_exists( 'construction_renovation_credit' ) ) {
    function construction_renovation_credit(){
        echo "<a href=".esc_url(CONSTRUCTION_RENOVATION_CREDIT)." target='_blank'>".esc_html__('Themespride','construction-renovation')."</a>";
    }
}

if ( ! defined( 'PRO_THEME_NAME' ) ) {
    define( 'PRO_THEME_NAME', esc_html__( 'Renovation Pro Theme', 'construction-renovation' ));
}
if ( ! defined( 'PRO_THEME_URL' ) ) {
    define( 'PRO_THEME_URL', esc_url('https://www.themespride.com/themes/renovation-wordpress-theme/'));
}
if ( ! defined( 'FREE_THEME_URL' ) ) {
    define( 'FREE_THEME_URL', 'https://www.themespride.com/themes/free-renovation-wordpress-theme/' );
}
if ( ! defined( 'DEMO_THEME_URL' ) ) {
    define( 'DEMO_THEME_URL', 'https://www.themespride.com/renovation-pro/' );
}
if ( ! defined( 'DOCS_THEME_URL' ) ) {
    define( 'DOCS_THEME_URL', 'https://www.themespride.com/demo/docs/construction-renovation-lite/' );
}
if ( ! defined( 'RATE_THEME_URL' ) ) {
    define( 'RATE_THEME_URL', 'https://wordpress.org/support/theme/construction-renovation/reviews/#new-post' );
}
if ( ! defined( 'CHANGELOG_THEME_URL' ) ) {
    define( 'CHANGELOG_THEME_URL', get_stylesheet_directory() . '/readme.txt' );
}
if ( ! defined( 'SUPPORT_THEME_URL' ) ) {
    define( 'SUPPORT_THEME_URL', 'https://wordpress.org/support/theme/construction-renovation/' );
}