<?php
/**
 * Add custom settings and controls to the WordPress Customizer
 */


//---------------------Code to add the Upgrade to Pro button in the Customizer----------

function gardening_landscape_aura_customize_register_btn( $wp_customize ) {
    $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
    $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
    $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

    get_template_part('inc/customizer-button/upsell-section');

    if ( isset( $wp_customize->selective_refresh ) ) {
        $wp_customize->selective_refresh->add_partial( 'blogname', array(
            'selector'        => '.site-title a',
            'render_callback' => 'gardening_landscape_aura_customize_partial_blogname',
        ) );
        $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
            'selector'        => '.site-description',
            'render_callback' => 'gardening_landscape_aura_customize_partial_blogdescription',
        ) );
    }

    $wp_customize->register_section_type( 'Gardening_Landscape_Aura_Customize_Upsell_Section' );

    // Register section.
    $wp_customize->add_section(
        new Gardening_Landscape_Aura_Customize_Upsell_Section(
            $wp_customize,
            'theme_upsell',
            array(
                'title'    => esc_html__( 'Gardening Pro', 'gardening-landscape-aura' ),
                'pro_text' => esc_html__( 'Upgrade To Pro', 'gardening-landscape-aura' ),
                'pro_url'  => 'https://cawpthemes.com/gardening-landscape-aura-premium-wordpress-theme/',
                'priority' => 1,
            )
        )
    );
}
add_action( 'customize_register', 'gardening_landscape_aura_customize_register_btn' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function gardening_landscape_aura_customize_partial_blogname() {
    bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function gardening_landscape_aura_customize_partial_blogdescription() {
    bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function gardening_landscape_aura_customize_preview_js() {
    wp_enqueue_script( 'gardening-landscape-aura-customizer', get_template_directory_uri() . '/inc/customizer-button/customizer.js', array( 'customize-preview' ), '20151215', true );
}
add_action( 'customize_preview_init', 'gardening_landscape_aura_customize_preview_js' );

/**
 * Customizer control scripts and styles.
 *
 * @since 1.0.0
 */
function gardening_landscape_aura_customizer_control_scripts() {

    wp_enqueue_style( 'gardening-landscape-aura-customize-controls', get_template_directory_uri() . '/inc/customizer-button/customize-controls.css', '', '1.0.0' );

    wp_enqueue_script( 'gardening-landscape-aura-customize-controls', get_template_directory_uri() . '/inc/customizer-button/customize-controls.js', array( 'customize-controls' ), '1.0.0', true );
}
add_action( 'customize_controls_enqueue_scripts', 'gardening_landscape_aura_customizer_control_scripts', 0 );


//---------------------Code to add the Upgrade to Pro button in the Customizer End----------


//------------------Theme Information--------------------




function gardening_landscape_aura_customize_register( $wp_customize ) {

  
  // Add a custom setting for the primary color
  $wp_customize->add_setting( 'gardening_landscape_aura_primary_color', array(
    'default' => '#0073aa',
    'sanitize_callback' => 'sanitize_hex_color',
  ) );

  // Add a custom control for the primary color
  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'gardening_landscape_aura_primary_color', array(
    'label' => __( 'Primary Color', 'gardening-landscape-aura' ),
    'section' => 'colors',
    'settings' => 'gardening_landscape_aura_primary_color',
  ) ) );

  //-----------------------------------Home Front Page-------------------------------

  $wp_customize->add_panel( 'gardening_landscape_aura_panel', array(
    'title'    => __( 'Front Page Settings', 'gardening-landscape-aura' ),
    'priority' => 100,
  ) );


  //-------------------------------------Banner Image Section--------------

      $wp_customize->add_section( 'gardening_landscape_aura_section_banner', array(
        'title'    => __( 'Home First Section', 'gardening-landscape-aura' ),
        'priority' => 8,
        'panel'    => 'gardening_landscape_aura_panel',
    ) );


  //-----------------Enable Option banner-------------

  $wp_customize->add_setting('gardening_landscape_aura_section_banner',array(
      'default' => 'Enable',
      'sanitize_callback' => 'gardening_landscape_aura_sanitize_choices'
  ));
  $wp_customize->add_control('gardening_landscape_aura_section_banner',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'gardening-landscape-aura'),
        'section' => 'gardening_landscape_aura_section_banner',
        'choices' => array(
            'Enable' => __('Enable', 'gardening-landscape-aura'),
            'Disable' => __('Disable', 'gardening-landscape-aura')
  )));

  $wp_customize->add_setting('gardening_landscape_aura_section_bannerimage_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'gardening_landscape_aura_section_bannerimage_section',array(
    'label' => __('Section Background Image','gardening-landscape-aura'),
    'description' => __('Dimention 1600 * 600','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_section_banner',
    'settings' => 'gardening_landscape_aura_section_bannerimage_section'
  )));

    $wp_customize->add_setting('gardening_landscape_aura_section_bannerimage_section_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_section_bannerimage_section_title',array(
      'label' => __('Banner Title','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_section_banner',
      'setting' => 'gardening_landscape_aura_section_bannerimage_section_title',
      'type'    => 'text'
    )
  ); 

      $wp_customize->add_setting('gardening_landscape_aura_section_bannerimage_section_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_section_bannerimage_section_text',array(
      'label' => __('Banner Text','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_section_banner',
      'setting' => 'gardening_landscape_aura_section_bannerimage_section_text',
      'type'    => 'textarea'
    )
  );

    $wp_customize->add_setting('gardening_landscape_aura_banner_btn_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_banner_btn_text',array(
      'label' => __('Button Text','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_section_banner',
      'setting' => 'gardening_landscape_aura_banner_btn_text',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('gardening_landscape_aura_banner_btn_text_url',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_banner_btn_text_url',array(
      'label' => __('Button URL','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_section_banner',
      'setting' => 'gardening_landscape_aura_banner_btn_text_url',
      'type'    => 'text'
    )
  );





  //----------------------------------About Section----------------------------



    $wp_customize->add_section( 'gardening_landscape_aura_about', array(
        'title'    => __( 'About Section', 'gardening-landscape-aura' ),
        'priority' => 10,
        'panel'    => 'gardening_landscape_aura_panel',
    ) );

  //-----------------Enable Option Section about-------------

  $wp_customize->add_setting('gardening_landscape_aura_about_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'gardening_landscape_aura_sanitize_choices'
  ));
  $wp_customize->add_control('gardening_landscape_aura_about_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'gardening-landscape-aura'),
        'section' => 'gardening_landscape_aura_about',
        'choices' => array(
            'Enable' => __('Enable', 'gardening-landscape-aura'),
            'Disable' => __('Disable', 'gardening-landscape-aura')
  )));

    //--------------About Title-----------------------

    $wp_customize->add_setting('gardening_landscape_aura_about_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_about_title',array(
      'label' => __('Section Title','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_about',
      'setting' => 'gardening_landscape_aura_about_title',
      'type'    => 'text'
    )
  ); 


  //-----------------------------About Image-----------

  $wp_customize->add_setting('gardening_landscape_aura_aboutimage1_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'gardening_landscape_aura_aboutimage1_section',array(
    'label' => __('About Side Image 1','gardening-landscape-aura'),
    'description' => __('Dimention 230 * 250','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_about',
    'settings' => 'gardening_landscape_aura_aboutimage1_section'
  )));

  $wp_customize->add_setting('gardening_landscape_aura_aboutimage2_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'gardening_landscape_aura_aboutimage2_section',array(
    'label' => __('About Side Image 2','gardening-landscape-aura'),
    'description' => __('Dimention 230 * 250','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_about',
    'settings' => 'gardening_landscape_aura_aboutimage2_section'
  )));

  $wp_customize->add_setting('gardening_landscape_aura_aboutimage3_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'gardening_landscape_aura_aboutimage3_section',array(
    'label' => __('About Side Image 3','gardening-landscape-aura'),
    'description' => __('Dimention 230 * 250','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_about',
    'settings' => 'gardening_landscape_aura_aboutimage3_section'
  )));

  $wp_customize->add_setting('gardening_landscape_aura_aboutimage4_section',array(
    'default' => '',
    'sanitize_callback' => 'esc_url_raw',
  ));
  $wp_customize->add_control(
    new WP_Customize_Image_Control( $wp_customize,'gardening_landscape_aura_aboutimage4_section',array(
    'label' => __('About Side Image 4','gardening-landscape-aura'),
    'description' => __('Dimention 230 * 250','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_about',
    'settings' => 'gardening_landscape_aura_aboutimage4_section'
  )));


    $wp_customize->add_setting('gardening_landscape_aura_about_name',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_about_name',array(
      'label' => __('Main Heading','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_about',
      'setting' => 'gardening_landscape_aura_about_name',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('gardening_landscape_aura_about_title_second',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_about_title_second',array(
      'label' => __('Paragraph 1','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_about',
      'setting' => 'gardening_landscape_aura_about_title_second',
      'type'    => 'textarea'
    )
  );


    $wp_customize->add_setting('gardening_landscape_aura_about_para',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_about_para',array(
      'label' => __('Paragraph 2','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_about',
      'setting' => 'gardening_landscape_aura_about_para',
      'type'    => 'textarea'
    )
  );

    $wp_customize->add_setting('gardening_landscape_aura_about_btn_text',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_about_btn_text',array(
      'label' => __('Button Text','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_about',
      'setting' => 'gardening_landscape_aura_about_btn_text',
      'type'    => 'text'
    )
  );


    $wp_customize->add_setting('gardening_landscape_aura_about_btn_text_url',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_about_btn_text_url',array(
      'label' => __('Button URL','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_about',
      'setting' => 'gardening_landscape_aura_about_btn_text_url',
      'type'    => 'text'
    )
  );



  //-----------------------------------------------------------------Section One (Featured Post)------------------------------------------

  $wp_customize->add_section( 'gardening_landscape_aura_section1', array(
        'title'    => __( 'Latest Post', 'gardening-landscape-aura' ),
        'priority' => 10,
        'panel'    => 'gardening_landscape_aura_panel',
    ) );


  //-----------------Enable Option Section One-------------

  $wp_customize->add_setting('gardening_landscape_aura_section1_enable',array(
      'default' => 'Enable',
      'sanitize_callback' => 'gardening_landscape_aura_sanitize_choices'
  ));
  $wp_customize->add_control('gardening_landscape_aura_section1_enable',array(
        'type' => 'radio',
        'label' => __('Do you want this section', 'gardening-landscape-aura'),
        'section' => 'gardening_landscape_aura_section1',
        'choices' => array(
            'Enable' => __('Enable', 'gardening-landscape-aura'),
            'Disable' => __('Disable', 'gardening-landscape-aura')
  )));

    //--------------Section One Title-----------------------

    $wp_customize->add_setting('gardening_landscape_aura_section1_title',array(
      'default' => '',
      'sanitize_callback' => 'sanitize_text_field'
    )
  );
  $wp_customize->add_control('gardening_landscape_aura_section1_title',array(
      'label' => __('Section Title','gardening-landscape-aura'),
      'section' => 'gardening_landscape_aura_section1',
      'setting' => 'gardening_landscape_aura_section1_title',
      'type'    => 'text'
    )
  ); 

  //-----------Category------------

  $categories = get_categories();
  $cats = array();
  $i = 0;
  foreach($categories as $category){
    if($i==0){
      $default = $category->name;
      $i++;
    }
    $cats[$category->name] = $category->name;
  }

  $wp_customize->add_setting('gardening_landscape_aura_section1_category',array(
  'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('gardening_landscape_aura_section1_category',array(
    'type'    => 'select',
    'choices' => $cats,
    'label' => __('Select Category to Display Post','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_section1',
    'sanitize_callback' => 'sanitize_text_field',
  ));



    $wp_customize->add_setting('gardening_landscape_aura_section1_category_number_of_posts_setting',array(
    'default' => '8',
    'sanitize_callback' => 'sanitize_text_field'
  ));
  $wp_customize->add_control('gardening_landscape_aura_section1_category_number_of_posts_setting',array(
    'label' => __('Number of Posts','gardening-landscape-aura'),
    'section' => 'gardening_landscape_aura_section1',
    'setting' => 'gardening_landscape_aura_section1_category_number_of_posts_setting',
    'type'    => 'number'
  )); 



  //-------------------------Footer Settings------------------------------


    $wp_customize->add_section( 'gardening_landscape_aura_footer', array(
        'title'    => __( 'Footer Settings', 'gardening-landscape-aura' ),
        'priority' => 10,
        'panel'    => 'gardening_landscape_aura_panel',
    ) );


  // Add a custom setting for the footer text
  $wp_customize->add_setting( 'gardening_landscape_aura_footer_text', array(
    'default' => '',
    'sanitize_callback' => 'sanitize_text_field',
  ) );

  // Add a custom control for the footer text
  $wp_customize->add_control( 'gardening_landscape_aura_footer_text', array(
    'label' => __( 'Footer Text', 'gardening-landscape-aura' ),
    'section' => 'gardening_landscape_aura_footer',
    'type' => 'text',
  ) );


//--------------------------------------General Settings------------------------------------------

  $wp_customize->add_section( 'gardening_landscape_aura_general', array(
        'title'    => __( 'General Settings', 'gardening-landscape-aura' ),
        'panel'    => 'gardening_landscape_aura_panel',
    ) );

    $wp_customize->add_setting( 'gardening_landscape_aura_post_meta_toggle_switch_control', array(
        'default'   => true,
        'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs
        'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'gardening_landscape_aura_post_meta_toggle_switch_control', array(
        'label'    => __( 'Display Time/Author', 'gardening-landscape-aura' ),
        'section'  => 'gardening_landscape_aura_general',
        'settings' => 'gardening_landscape_aura_post_meta_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );


    $wp_customize->add_setting( 'gardening_landscape_aura_post_readmore_toggle_switch_control', array(
        'default'   => true,
        'sanitize_callback' => 'sanitize_text_field', // Use a suitable sanitization function based on your needs
        'transport' => 'refresh', // or 'postMessage' for instant preview without page refresh
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'gardening_landscape_aura_post_readmore_toggle_switch_control', array(
        'label'    => __( 'Display Readmore Link', 'gardening-landscape-aura' ),
        'section'  => 'gardening_landscape_aura_general',
        'settings' => 'gardening_landscape_aura_post_readmore_toggle_switch_control',
        'type'     => 'checkbox',
    ) ) );
  

}
add_action( 'customize_register', 'gardening_landscape_aura_customize_register' );


