<?php
/**
 * Theme functions and definitions
 *
 * @package SEO Agency Lite
 */ 

if ( ! function_exists( 'seo_agency_lite_enqueue_styles' ) ) :
	/**
	 * Load assets.
	 *
	 * @since 1.0.0
	 */
	function seo_agency_lite_enqueue_styles() {
		wp_enqueue_style( 'seo-agency-lite-block-patterns-style-frontend', get_theme_file_uri('/css/block-frontend.css') );
		wp_enqueue_style( 'bootstrap-css', esc_url(get_template_directory_uri()).'/css/bootstrap.css' );
		wp_enqueue_style( 'seo-agency-lite-style-parent', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'seo-agency-lite-style', get_stylesheet_directory_uri() . '/style.css', array( 'seo-agency-lite-style-parent' ), '1.0.0' );
		wp_enqueue_style( 'seo-agency-lite-font-awesome-css', esc_url(get_template_directory_uri()).'/css/fontawesome-all.css' );

		require get_theme_file_path( '/tc-style.php' );
		wp_add_inline_style( 'seo-agency-lite-style',$seo_agency_lite_custom_css );

		require get_parent_theme_file_path( '/tc-style.php' );
		wp_add_inline_style( 'seo-agency-lite-style-parent',$digital_advertising_custom_css );
	}
endif;
add_action( 'wp_enqueue_scripts', 'seo_agency_lite_enqueue_styles');

/**
 * Enqueue block editor style
 */
function seo_agency_lite_block_editor_styles() {
	wp_enqueue_style( 'digital-advertising-font', digital_advertising_font_url(), array() );
	wp_enqueue_style( 'seo-agency-lite-block-patterns-style-editor', get_theme_file_uri( '/css/block-editor.css' ), false, '1.0', 'all' );
    wp_enqueue_style( 'bootstrap-style', esc_url(get_template_directory_uri()).'/css/bootstrap.css' );
    wp_enqueue_style( 'seo-agency-lite-font-awesome-css', esc_url(get_template_directory_uri()).'/css/fontawesome-all.css' );
}
add_action( 'enqueue_block_editor_assets', 'seo_agency_lite_block_editor_styles' );

function seo_agency_lite_customize_register() {
	global $wp_customize;
	// $wp_customize->remove_setting( 'digital_advertising_show_topbar' );
	// $wp_customize->remove_control( 'digital_advertising_show_topbar' );
	$wp_customize->remove_setting( 'digital_advertising_hide_topbar_responsive' );
	$wp_customize->remove_control( 'digital_advertising_hide_topbar_responsive' );
	$wp_customize->remove_setting( 'digital_advertising_noof_list' );
	$wp_customize->remove_control( 'digital_advertising_noof_list' );
	$wp_customize->remove_setting( 'digital_advertising_topbar_location' );
	$wp_customize->remove_control( 'digital_advertising_topbar_location' );
	$wp_customize->remove_setting( 'digital_advertising_about_page' );
	$wp_customize->remove_control( 'digital_advertising_about_page' );
	$wp_customize->remove_setting( 'digital_advertising_primary_theme_color' );
	$wp_customize->remove_control( 'digital_advertising_primary_theme_color' );
	$wp_customize->remove_setting( 'digital_advertising_menu_settings_premium_features' );
	$wp_customize->remove_control( 'digital_advertising_menu_settings_premium_features' );
	$wp_customize->remove_setting( 'digital_advertising_about_settings_premium_features' );
	$wp_customize->remove_control( 'digital_advertising_about_settings_premium_features' );
	$wp_customize->remove_setting( 'digital_advertising_post_settings_premium_features' );
	$wp_customize->remove_control( 'digital_advertising_post_settings_premium_features' );


	$wp_customize->remove_section( 'digital_advertising_about_theme' );
	
    $wp_customize->add_setting('digital_advertising_phoneno_text',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('digital_advertising_phoneno_text',array(
		'label'	=> __('Add Phone Text','seo-agency-lite'),
		'section' => 'digital_advertising_topbar',
		'type'	=> 'text'
	));
	
    $wp_customize->add_setting('digital_advertising_email_text',array(
		'default'	=> '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
	$wp_customize->add_control('digital_advertising_email_text',array(
		'label'	=> __('Add Email Text','seo-agency-lite'),
		'section' => 'digital_advertising_topbar',
		'type'	=> 'text'
	));

	$args = array('numberposts' => -1);
	$post_list = get_posts($args);
	$i = 0;
	$posts[]='Select';	
	foreach($post_list as $post){
		$posts[$post->post_title] = $post->post_title;
	}

	$wp_customize->add_setting('seo_agency_lite_about_post',array(
		'sanitize_callback' => 'digital_advertising_sanitize_choices',
	));
	$wp_customize->add_control('seo_agency_lite_about_post',array(
		'type'    => 'select',
		'choices' => $posts,
		'label' => __('Select post','seo-agency-lite'),
		'section' => 'digital_advertising_about_section',
	));

	// Add the Theme Color Option section.
	$wp_customize->add_setting( 'seo_agency_lite_primary_theme_color', array(
	    'default' => '#1a73e8',
	    'sanitize_callback' => 'sanitize_hex_color',
  	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'seo_agency_lite_primary_theme_color', array(
  		'label' => __('Theme Color Option','seo-agency-lite'),
	    'section' => 'digital_advertising_typography',
	    'settings' => 'seo_agency_lite_primary_theme_color',
		'priority' => 1,
  	)));


	//About Section
		$wp_customize->add_section( 'seo_agency_lite_about_theme' , array(
	    	'title' => esc_html__( 'About Theme', 'seo-agency-lite' ),
	    	'priority' => 9,
		) );

		$wp_customize->add_setting('seo_agency_lite_demo_link',array(
			'sanitize_callback'	=> 'sanitize_text_field'
		));
		$wp_customize->add_control('seo_agency_lite_demo_link',array(
			'type'=> 'hidden',
			'description' => "<h3>". esc_html__('Theme Demo','seo-agency-lite') ."</h3><p>". esc_html__('Our premium version of Seo Agency Lite has unlimited sections with advanced control fields. Dedicated support and no limititation in any field.','seo-agency-lite') ."</p> <a target='_blank' href='". esc_url('https://preview.themescaliber.com/seo-agency-pro/') ." '>". esc_html__('View Demo','seo-agency-lite') ."</a>",
			'section'=> 'seo_agency_lite_about_theme'
		));
		
		$wp_customize->add_setting('seo_agency_lite_doc_link',array(
			'sanitize_callback'	=> 'sanitize_text_field'
		));
		$wp_customize->add_control('seo_agency_lite_doc_link',array(
			'type'=> 'hidden',
			'description' => "<h3>". esc_html__('Theme Documentation','seo-agency-lite') ."</h3><p>". esc_html__('We have well prepared documentation that provides the general guidelines and suggestions needed for this theme.','seo-agency-lite') ."</p> <a target='_blank' href='". esc_url('https://preview.themescaliber.com/doc/free-seo-agency/') ." '>". esc_html__('View Documentation','seo-agency-lite') ."</a>",
			'section'=> 'seo_agency_lite_about_theme'
		));

		$wp_customize->add_setting('seo_agency_lite_forum_link',array(
			'sanitize_callback'	=> 'sanitize_text_field'
		));
		$wp_customize->add_control('seo_agency_lite_forum_link',array(
			'type'=> 'hidden',
			'description' => "<h3>". esc_html__('Theme Support','seo-agency-lite') ."</h3><p>". esc_html__('Regarding any theme issue, we offer 24/7 support. You can get assistance from our support staff in resolving any problem. Please get in touch with us.','seo-agency-lite') ."</p><a target='_blank' href='". esc_url('https://wordpress.org/support/theme/seo-agency-lite/') ." '>". esc_html__('Support Forum','seo-agency-lite') ."</a>",
			'section'=> 'seo_agency_lite_about_theme'
		));

		$wp_customize->add_setting('seo_agency_lite_review_link',array(
			'sanitize_callback'	=> 'sanitize_text_field'
		));
		$wp_customize->add_control('seo_agency_lite_review_link',array(
			'type'=> 'hidden',
			'description' => "<h3>". esc_html__('Theme Review','seo-agency-lite') ."</h3><p>". esc_html__('If you enjoy using our theme, we’d love to hear your feedback. please leave us a review.','seo-agency-lite') ."</p><a target='_blank' href='". esc_url('https://wordpress.org/support/theme/seo-agency-lite/reviews/#new-post') ." '>". esc_html__('Rate & Review','seo-agency-lite') ."</a>",	
			'section'=> 'seo_agency_lite_about_theme'
		));

		$wp_customize->add_setting( 'seo_agency_lite_menu_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
    	));
    	$wp_customize->add_control('seo_agency_lite_menu_settings_premium_features', array(
	    	'type'=> 'hidden',
			'priority' => 1,
	        'description' => "<h3>". esc_html__('More Features in the Premium Version!','seo-agency-lite') ."</h3>
	        	<ul>
	        		<li>". esc_html__('Menu Background Colors','seo-agency-lite') ."</li>
	        		<li>". esc_html__('Menu Item Fonts','seo-agency-lite') ."</li>
	        		<li>". esc_html__('Responsive Menu Colors','seo-agency-lite') ."</li>
	        		<li>". esc_html__('Header Search Icons Colors','seo-agency-lite') ."</li>
	        		<li>". esc_html__('... and Other Premium Features','seo-agency-lite') ."</li>
	        	</ul>
	        	<a target='_blank' href='". esc_url('https://www.themescaliber.com/products/seo-agency-wordpress-theme') ." '>". esc_html__('Upgrade Now','seo-agency-lite') ."</a>",
        	'section' => 'digital_advertising_header'
        	)
    	);

    	$wp_customize->add_setting( 'seo_agency_lite_about_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
	    ));
	    $wp_customize->add_control('seo_agency_lite_about_settings_premium_features', array(
	    	'type'=> 'hidden',
			'priority' => 1,
	        'description' => "<h3>". esc_html__('More Features in the Premium Version!','seo-agency-lite') ."</h3>
	        	<ul>
	        		<li>". esc_html__('Section Background Image Option','seo-agency-lite') ."</li>
	        		<li>". esc_html__('Choose Tab Icon Options','seo-agency-lite') ."</li>
	        		<li>". esc_html__('... and Other Premium Features','seo-agency-lite') ."</li>
	        	</ul>
	        	<a target='_blank' href='". esc_url('https://www.themescaliber.com/products/seo-agency-wordpress-theme') ." '>". esc_html__('Upgrade Now','seo-agency-lite') ."</a>",
	        'section' => 'digital_advertising_about_section'
	        )
	    );

	    $wp_customize->add_setting( 'seo_agency_lite_post_settings_premium_features',array(
        'sanitize_callback' => 'sanitize_text_field'
	    ));
	    $wp_customize->add_control('seo_agency_lite_post_settings_premium_features', array(
	    	'type'=> 'hidden',
			'priority' => 1,
	        'description' => "<h3>". esc_html__('More Features in the Premium Version!','seo-agency-lite') ."</h3>
	        	<ul>
	        		<li>". esc_html__('Section Heading Option','seo-agency-lite') ."</li>
	        		<li>". esc_html__('Animated Elements Colors','seo-agency-lite') ."</li>
	        		<li>". esc_html__('... and Other Premium Features','seo-agency-lite') ."</li>
	        	</ul>
	        	<a target='_blank' href='". esc_url('https://www.themescaliber.com/products/seo-agency-wordpress-theme') ." '>". esc_html__('Upgrade Now','seo-agency-lite') ."</a>",
	        'section' => 'digital_advertising_blog_post'
	        )
	    );

}
add_action( 'customize_register', 'seo_agency_lite_customize_register', 11 );


require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );

class Advance_Consultancy_Customize_Section_Pro extends WP_Customize_Section {

    /**
     * Outputs the Underscore.js template.
     *
     * @since  1.0.0
     * @access public
     * @return void
     */
    protected function render_template() { ?>

        <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
            <h3 class="accordion-section-title">
                {{ data.title }}

                <# if ( data.pro_text && data.pro_url ) { #>
                    <a href="{{ data.pro_url }}" class="button button-secondary alignright" target="_blank">{{ data.pro_text }}</a>
                <# } #>
            </h3>
        </li>
    <?php }
}


/**
 * Singleton class for handling the theme's customizer integration.
 *
 * @since  1.0.0
 * @access public
 */
final class Advance_Consultancy_Customize {

    /**
     * Returns the instance.
     *
     * @since  1.0.0
     * @access public
     * @return object
     */
    public static function get_instance() {

        static $instance = null;

        if ( is_null( $instance ) ) {
            $instance = new self;
            $instance->setup_actions();
        }

        return $instance;
    }

    /**
     * Constructor method.
     *
     * @since  1.0.0
     * @access private
     * @return void
     */
    private function __construct() {}

    /**
     * Sets up initial actions.
     *
     * @since  1.0.0
     * @access private
     * @return void
     */
    private function setup_actions() {

        // Register panels, sections, settings, controls, and partials.
        add_action( 'customize_register', array( $this, 'sections' ) );

        // Register scripts and styles for the controls.
        add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ), 0 );
    }

    /**
     * Sets up the customizer sections.
     *
     * @since  1.0.0
     * @access public
     * @param  object  $manager
     * @return void
     */
    public function sections( $manager ) {

        // Register custom section types.
        $manager->register_section_type( 'Advance_Consultancy_Customize_Section_Pro' );

    }

    /**
     * Loads theme customizer CSS.
     *
     * @since  1.0.0
     * @access public
     * @return void
     */

    public function enqueue_control_scripts() {
        wp_enqueue_style( 'seo_agency_lite-customize-controls', get_stylesheet_directory_uri() . '/css/customize-controls-child.css' );
    }
}

// Doing this customizer thang!
Advance_Consultancy_Customize::get_instance();

/* Theme Setup */
if ( ! function_exists( 'seo_agency_lite_setup' ) ) :

function seo_agency_lite_setup() {

	$GLOBALS['content_width'] = apply_filters( 'seo_agency_lite_content_width', 640 );

	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	) );
	add_image_size('seo-agency-lite-homepage-thumb',240,145,true);
	
   	register_nav_menus( array(
		'primary' => __( 'Primary Menu', 'seo-agency-lite' ),
	) );

	add_theme_support( 'custom-background', array(
		'default-color' => 'f1f1f1'
	) );
	
	add_theme_support ('html5', array (
        'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
    ) );

	add_theme_support('responsive-embeds');

	/* Selective refresh for widgets */
	add_theme_support( 'customize-selective-refresh-widgets' );

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

	// Dashboard Theme Notification
	global $pagenow;
	
	if (
			is_admin()
			&&
			('themes.php' == $pagenow)
			// &&
			// isset( $_GET['activated'] )
		) {
			add_action('admin_notices', 'seo_agency_lite_activation_notice');
		}
	}
	endif;

add_action( 'after_setup_theme', 'seo_agency_lite_setup' );

// Dashboard Theme Notification  
function seo_agency_lite_activation_notice() {
	$seo_agency_lite_meta = get_option( 'seo_agency_lite_admin_notice' );

	if (!$seo_agency_lite_meta) {
	echo '<div id="seo-agency-lite-welcome-notice" class="notice is-dismissible digital-advertising-notice">';
		echo '<div class="digital-advertising-banner">';
			echo '<div class="digital-advertising-text">';
				echo '<h2>' . esc_html__( 'Thanks For Installing the "Seo Agency Lite" Theme !', 'seo-agency-lite' ) . '</h2>';
				echo '<p>' . esc_html__( 'We’re excited to help you get started with your new theme! Set up your website quickly and easily by importing our demo content and customizing it to suit your needs.', 'seo-agency-lite' ) . '</p>';
				echo '<div class="digital-advertising-buttons">';
					echo '<a href="' . esc_url( admin_url( 'themes.php?page=seo_agency_lite_guide' ) ) . '">' . esc_html__( 'Demo Import', 'seo-agency-lite' ) . '</a>';
					echo '<a href="'. esc_url( 'https://preview.themescaliber.com/doc/free-seo-agency/' ) .'" target=_blank>' . esc_html__( 'Documentation', 'seo-agency-lite' ) . '</a>';
					echo '<a href="'. esc_url( 'https://www.themescaliber.com/products/seo-agency-wordpress-theme' ) .'" target=_blank>' . esc_html__( 'Get Premium', 'seo-agency-lite' ) . '</a>';
					echo '<a class="bundle_btn" href="'. esc_url( 'https://www.themescaliber.com/products/wordpress-theme-bundle' ) .'" target=_blank>' . esc_html__( 'Bundle of 220+ Themes at $99', 'seo-agency-lite' ) . '</a>';
				echo '</div>';
			echo '</div>';
			echo '<div class="digital-advertising-image">';
				echo '<img src="' . esc_url(get_theme_file_uri()) . '/images/demo-preview.png">';
			echo '</div>';
		echo '</div>';
    echo '</div>';
}
}

function seo_agency_lite_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'seo-agency-lite' ),
		'description'   => __( 'Appears on blog page sidebar', 'seo-agency-lite' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s mb-4 p-2">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title pt-0">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'seo_agency_lite_widgets_init' );

function seo_agency_lite_enqueue_comments_reply() {
    if( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1) ) {
        wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
    }
}
add_action( 'wp_enqueue_scripts', 'seo_agency_lite_enqueue_comments_reply' );

add_action( 'init', 'seo_agency_lite_remove_action');
function seo_agency_lite_remove_action() {
    remove_action( 'admin_menu','digital_advertising_gettingstarted' );
    remove_action( 'admin_notices','digital_advertising_activation_notice' );
}
function seo_agency_lite_mysetup() {
	// URL DEFINES
	define('SEO_AGENCY_LITE_FREE_THEME_DOC',__('https://preview.themescaliber.com/doc/free-seo-agency/','seo-agency-lite'));
	define('SEO_AGENCY_LITE_SUPPORT',__('https://wordpress.org/support/theme/seo-agency-lite/','seo-agency-lite'));
	define('SEO_AGENCY_LITE_REVIEW',__('https://wordpress.org/support/theme/seo-agency-lite/reviews/','seo-agency-lite'));
	define('SEO_AGENCY_LITE_BUY_NOW',__('https://www.themescaliber.com/products/seo-agency-wordpress-theme','seo-agency-lite'));
	define('SEO_AGENCY_LITE_LIVE_DEMO',__('https://preview.themescaliber.com/seo-agency-pro/','seo-agency-lite'));
	define('SEO_AGENCY_LITE_PRO_DOC',__('https://preview.themescaliber.com/doc/seo-agency-pro/','seo-agency-lite'));
	define('SEO_AGENCY_LITE_CHILD_THEME',__('https://developer.wordpress.org/themes/advanced-topics/child-themes/','seo-agency-lite'));
	define('SEO_AGENCY_LITE_THEME_URL',__('https://www.themescaliber.com/products/free-seo-wordpress-theme', 'seo-agency-lite'));

	if ( ! defined( 'DIGITAL_ADVERTISING_PRO_NAME' ) ) {
		define( 'DIGITAL_ADVERTISING_PRO_NAME', esc_html__( 'SEO Agency Pro', 'seo-agency-lite' ));
	}
	if ( ! defined( 'DIGITAL_ADVERTISING_PRO_URL' ) ) {
		define( 'DIGITAL_ADVERTISING_PRO_URL', esc_url('https://www.themescaliber.com/products/seo-agency-wordpress-theme'));
	}
	/* Block Pattern */
	require get_theme_file_path() . '/block-patterns.php';
}
add_action( 'after_setup_theme', 'seo_agency_lite_mysetup' );

// if ( ! defined( 'digital_advertising_PRO_URL' ) ) {
// 	define( 'digital_advertising_PRO_URL', esc_url('https://www.themescaliber.com/products/seo-agency-wordpress-theme'));
// }

function seo_agency_lite_credit_link() {
    echo "<a href=".esc_url(SEO_AGENCY_LITE_THEME_URL)." target='_blank'>".esc_html__('Seo Agency WordPress Theme','seo-agency-lite')."</a>";
}

/* Webfonts */
require get_theme_file_path() . '/wptt-webfont-loader.php';

/* Implement the get started page */
require get_theme_file_path() . '/inc/dashboard/getstart.php';

// Admin notice code START
function seo_agency_lite_dismissed_notice() {
	update_option( 'seo_agency_lite_admin_notice', true );
}
add_action( 'wp_ajax_seo_agency_lite_dismissed_notice', 'seo_agency_lite_dismissed_notice' );

//After Switch theme function
add_action('after_switch_theme', 'seo_agency_lite_getstart_setup_options');
function seo_agency_lite_getstart_setup_options () {
    update_option('seo_agency_lite_admin_notice', false );
}
// Admin notice code END

// woocommerce page function
add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );

