<?php
/**
 * Subscription section
 *
 * This is the template for the content of subscription section
 *
 * @package Theme Palace
 * @subpackage Ultravel
 * @since Ultravel 1.0.0
 */
if ( ! function_exists( 'ultravel_add_subscribe_now_section' ) ) :
    /**
    * Add subscription section
    *
    *@since Ultravel 1.0.0
    */
    function ultravel_add_subscribe_now_section() {
        $options = ultravel_get_theme_options();
        // Check if subscription is enabled on frontpage
        $subscribe_now_enable = apply_filters( 'ultravel_section_status', true, 'subscribe_now_section_enable' );

        if ( true !== $subscribe_now_enable ) {
            return false;
        }

        // Render subscription section now.
        ultravel_render_subscribe_now_section();
    }
endif;

if ( ! function_exists( 'ultravel_render_subscribe_now_section' ) ) :
  /**
   * Start subscription section
   *
   * @return string subscription content
   * @since Ultravel 1.0.0
   *
   */
   function ultravel_render_subscribe_now_section() {
        if ( ! class_exists( 'Jetpack' ) ) {
            return;
        } elseif ( class_exists( 'Jetpack' ) ) {
            if ( ! Jetpack::is_module_active( 'subscriptions' ) )
                return;
        }

        $options = ultravel_get_theme_options();
        $btn_label = ! empty( $options['subscribe_now_btn'] ) ? $options['subscribe_now_btn'] : esc_html__( 'Send', 'ultravel' );

        ?>
        <div id="ultravel_subscribe_now_section" class="relative page-section same-background">
            <?php if ( is_customize_preview()):
                    ultravel_section_tooltip( 'ultravel_subscribe_now_section' );
                endif; ?>
            <div class="wrapper">
                <div class="section-header">
                    <?php if ( ! empty( $options['subscribe_now_title'] ) ) : ?>
                        <h2 class="section-title"><?php echo esc_html( $options['subscribe_now_title'] ); ?></h2>
                    <?php endif; ?>
                    <?php if ( ! empty( $options['subscribe_now_sub_title'] ) ) : ?>
                        <p class="section-subtitle"><?php echo esc_html( $options['subscribe_now_sub_title'] ); ?></p>
                    <?php endif; ?>
                </div><!-- .section-header -->

                <div class="subscribe-form-wrapper">
                 <?php 
                 $subscribe_now_shortcode = '[jetpack_subscription_form title="" subscribe_text="" subscribe_button="' . esc_html( $btn_label ) . '" show_subscribers_total="0"]';
                 echo do_shortcode( wp_kses_post( $subscribe_now_shortcode ) ); 
                 ?>
                </div><!-- .subscribe-form-wrapper -->
            </div><!-- .wrapper -->
        </div><!-- #subscribe-now -->  
    <?php }
endif;
