<?php
/**
 * Adds the Sticky Post section and its fields to the Frontpage Settings panel.
 * 
 * @package Blogbuster
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

add_action( 'customize_register', 'blogbuster_register_front_sticky_post_options' );

if ( ! function_exists( 'blogbuster_register_front_sticky_post_options' ) ) :

    /**
     * Register theme options for Sticky Post section.
     * 
     * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function blogbuster_register_front_sticky_post_options( $wp_customize ) {

        /*
         * Failsafe is safe
         */
        if ( ! isset( $wp_customize ) ) {
            return;
        }

        /**
         * Add Sticky Post Section
         * 
         * Frontpage Settings > Sticky Post
         * 
         * @uses $wp_customize->add_section() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_section/
         * @since 1.0.0
         */
        $wp_customize->add_section( new Blogbuster_Customize_Section (
            $wp_customize, 'blogbuster_section_front_sticky_post',
                array(
                    'priority'  => 20,
                    'panel'     => 'blogbuster_panel_frontpage',
                    'title'     => __( 'Sticky Post', 'blogbuster' ),
                )
            )
        );

        /**
         * Toggle option for sticky post section.
         *
         * Frontpage Settings > Sticky Post
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_front_sticky_post_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_front_sticky_post_enable' ),
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_front_sticky_post_enable',
                array(
                    'priority'      => 5,
                    'section'       => 'blogbuster_section_front_sticky_post',
                    'settings'      => 'blogbuster_front_sticky_post_enable',
                    'label'         => __( 'Enable Sticky Post Section', 'blogbuster' )
                )
            )
        );

        /**
         * Text option for sticky post section title
         *
         * Frontpage Settings > Sticky Post
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_front_sticky_post_section_title',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_front_sticky_post_section_title' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( 'blogbuster_front_sticky_post_section_title',
            array(
                'priority'          => 10,
                'section'           => 'blogbuster_section_front_sticky_post',
                'settings'          => 'blogbuster_front_sticky_post_section_title',
                'label'             => __( 'Section Title', 'blogbuster' ),
                'type'              => 'text',
            )
        );

        /**
         * Upgrade field for sticky posts
         * 
         * Frontpage Settings > Sticky Post
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'blogbuster_upgrade_front_stikcy',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Upgrade(
            $wp_customize, 'blogbuster_upgrade_front_stikcy',
                array(
                    'priority'      => 70,
                    'section'       => 'blogbuster_section_front_sticky_post',
                    'settings'      => 'blogbuster_upgrade_front_stikcy',
                    'label'         => __( 'More features with Blogbuster Pro', 'blogbuster' ),
                    'choices'       => blogbuster_upgrade_choices( 'blogbuster_front_stikcy' )
                )
            )
        );

    }

endif;