<?php
/**
 * Feminine Lifestyle Blog Custom functions and definitions
 *
 * @package Feminine_Lifestyle_Blog
 */

if ( ! function_exists( 'feminine_lifestyle_blog_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function feminine_lifestyle_blog_setup() {

    $build  = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '/unminified' : '/minified';
    $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on Feminine Lifestyle Blog, use a find and replace
	 * to change 'feminine-lifestyle-blog' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'feminine-lifestyle-blog', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
	 */
	add_theme_support( 'post-thumbnails' );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary'   => esc_html__( 'Primary', 'feminine-lifestyle-blog' ),
        'secondary' => esc_html__( 'Secondary', 'feminine-lifestyle-blog' ),
	) );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'search-form',
		'comment-list',
		'gallery',
		'caption',
	) );
    
    // Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'feminine_lifestyle_blog_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );
    
	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

	/**
	 * Add support for core custom logo.
	 *
	 * @link https://codex.wordpress.org/Theme_Logo
	 */
	add_theme_support( 
        'custom-logo', 
        apply_filters( 
            'feminine_lifestyle_blog_custom_logo_args', 
            array( 
                'height'      => 70, 
                'width'       => 70, 
                'flex-height' => true,
                'flex-width'  => true,
                'header-text' => array( 'site-title', 'site-description' ) 
            )
        ) 
    );
    
    /**
     * Add support for custom header.
    */
    add_theme_support( 
        'custom-header', 
        apply_filters( 
            'feminine_lifestyle_blog_custom_header_args', 
            array(
                'default-image' => '',
                'video'         => true,
                'width'         => 1920, 
                'height'        => 600, 
                'header-text'   => false
            ) 
        ) 
    );
 
    /**
     * SLIDER IMAGE SIZES
    */
    add_image_size( 'feminine-lifestyle-blog-slider-one', 1220, 600, true );
   
    add_image_size( 'feminine-lifestyle-blog-sidebar', 800, 530, true );
    
    //BlOG POST IMAGE SIZES
    add_image_size( 'feminine-lifestyle-blog-sm', 420, 280, true );
    add_image_size( 'feminine-lifestyle-blog-one', 900, 500, true );

    //SINGLE POSTS IMAGE SIZES
    add_image_size( 'feminine-lifestyle-blog-single-lay-one', 1140, 650, true ); 

     //ADDITIONAL IMAGE SIZES
     add_image_size( 'feminine-lifestyle-blog-about-sec', 425, 565, true );
     add_image_size( 'feminine-lifestyle-blog-latest-post', 360, 260, true );

    // Add theme support for Responsive Videos.
    add_theme_support( 'jetpack-responsive-videos' );

    // Add excerpt support for pages
    add_post_type_support( 'page', 'excerpt' );

    // Add support for full and wide align images.
    add_theme_support( 'align-wide' );

    // Add support for editor styles.
    add_theme_support( 'editor-styles' );

    // Add support for responsive embeds.
    add_theme_support( 'responsive-embeds' );

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

    // Add support for block editor styles.
    add_theme_support( 'wp-block-styles' );

}
endif;
add_action( 'after_setup_theme', 'feminine_lifestyle_blog_setup' );

if( ! function_exists( 'feminine_lifestyle_blog_post_content_width' ) ) :
/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function feminine_lifestyle_blog_post_content_width() {
	/** 
     * content width.
    */
    $GLOBALS['content_width'] = apply_filters( 'feminine_lifestyle_blog_post_content_width', 840 );
}
endif;
add_action( 'after_setup_theme', 'feminine_lifestyle_blog_post_content_width', 0 );

if( ! function_exists( 'feminine_lifestyle_blog_width_redirection' ) ) :
/**
* Adjust content_width value according to template.
*
* @return void
*/
function feminine_lifestyle_blog_width_redirection(){
	$sidebar = feminine_lifestyle_blog_sidebar();
    if( $sidebar ){	 
        $GLOBALS['content_width'] = 840;    
	}else{
        if( is_singular() ){
            if( feminine_lifestyle_blog_sidebar( true ) === 'full-width-centered' ){
                $GLOBALS['content_width'] = 840;
            }else{
                $GLOBALS['content_width'] = 1220;              
            }                
        }else{
            $GLOBALS['content_width'] = 1220;
        }
	}
}
endif;
add_action( 'template_redirect', 'feminine_lifestyle_blog_width_redirection' );

if( ! function_exists( 'feminine_lifestyle_blog_scripts' ) ) :
/**
 * Enqueue scripts and styles.
 */
function feminine_lifestyle_blog_scripts() {
	// Use minified libraries if SCRIPT_DEBUG is false
    $build  = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '/unminified' : '/minified';
    $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
    
    if( feminine_lifestyle_blog_is_woocommerce_activated() ){
        wp_enqueue_style( 
            'feminine-lifestyle-blog-woocommerce', 
            get_template_directory_uri(). '/assets/css' . $build . '/woocommerce' . $suffix . '.css', 
            array(), 
            FEMININE_LIFESTYLE_BLOG_THEME_VERSION 
        );
    }

    wp_enqueue_style( 
        'owl-carousel', 
        get_template_directory_uri(). '/assets/css' . $build . '/owl.carousel' . $suffix . '.css', 
        array(), 
        '2.3.4' 
    );

    wp_enqueue_style( 
        'feminine-lifestyle-blog-gutenberg', 
        get_template_directory_uri(). '/assets/css' . $build . '/gutenberg' . $suffix . '.css', 
        array(), 
        FEMININE_LIFESTYLE_BLOG_THEME_VERSION 
    );
    
    wp_enqueue_style( 
        'feminine-lifestyle-blog-google-fonts', 
        feminine_lifestyle_blog_google_fonts_url(), 
        array(), 
        null 
    );

    wp_enqueue_style( 
        'feminine-lifestyle-blog', 
        get_template_directory_uri() . '/style' . $suffix . '.css', 
        array(), 
        FEMININE_LIFESTYLE_BLOG_THEME_VERSION 
    );

    wp_enqueue_script( 
        'all', 
        get_template_directory_uri() . '/assets/js' . $build . '/all' . $suffix . '.js', 
        array( 'jquery' ), 
        '6.1.1', 
        true 
    );
    wp_enqueue_script( 
        'v4-shims', 
        get_template_directory_uri() . '/assets/js' . $build . '/v4-shims' . $suffix . '.js',
        array( 'jquery', 'all' ), 
        '6.1.1',
        true 
    );
	wp_enqueue_script( 
        'owl-carousel', 
        get_template_directory_uri() . '/assets/js' . $build . '/owl.carousel' . $suffix . '.js', 
        array( 'jquery' ), 
        '2.3.4', 
        true 
    );

	wp_enqueue_script( 
        'feminine-lifestyle-blog', 
        get_template_directory_uri() . '/assets/js' . $build . '/custom' . $suffix . '.js', 
        array( 'jquery' ), 
        FEMININE_LIFESTYLE_BLOG_THEME_VERSION, 
        true 
    );
    
    $array = array( 
        'rtl'   => is_rtl(),
        'auto'  => get_theme_mod( 'slider_auto', true ),
        'loop'  => get_theme_mod( 'slider_loop', true ),
        'speed' => get_theme_mod( 'slider_speed', 3000 ),
    );
    
    wp_localize_script( 
        'feminine-lifestyle-blog', 
        'feminine_lifestyle_blog_data', 
        $array 
    );
    
    wp_enqueue_script( 
        'feminine-lifestyle-blog-accessibility', 
        get_template_directory_uri() . '/assets/js' . $build . '/accessibility' . $suffix . '.js', 
        array('jquery'), 
        FEMININE_LIFESTYLE_BLOG_THEME_VERSION, 
        true 
    );
    
    wp_style_add_data( 'feminine-lifestyle-blog', 'rtl', 'replace' );

	if( $suffix ){
		wp_style_add_data( 'feminine-lifestyle-blog', 'suffix', $suffix );
	}

    if ( feminine_lifestyle_blog_is_jetpack_activated( true ) ) {
        wp_enqueue_style( 
            'tiled-gallery', 
            plugins_url() . '/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery.css' 
        );            
    }
    
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
endif;
add_action( 'wp_enqueue_scripts', 'feminine_lifestyle_blog_scripts' );

if( ! function_exists( 'feminine_lifestyle_blog_admin_scripts' ) ) :
/**
 * Enqueue admin scripts and styles.
*/
function feminine_lifestyle_blog_admin_scripts( $hook ){
    wp_enqueue_style( 'feminine-lifestyle-blog-admin', get_template_directory_uri() . '/inc/admin/css/admin.css', '', FEMININE_LIFESTYLE_BLOG_THEME_VERSION );
}
endif; 
add_action( 'admin_enqueue_scripts', 'feminine_lifestyle_blog_admin_scripts' );

if( ! function_exists( 'feminine_lifestyle_blog_block_editor_styles' ) ) :
/**
 * Enqueue editor styles for Gutenberg
 */
function feminine_lifestyle_blog_block_editor_styles() {
    // Use minified libraries if SCRIPT_DEBUG is false
    $build  = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '/unminified' : '/minified';
    $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
    
    // Block styles.
    wp_enqueue_style( 
        'feminine-lifestyle-blog-block-editor-style', 
        get_template_directory_uri() . '/assets/css' . $build . '/editor-block' . $suffix . '.css',
        array(),
        FEMININE_LIFESTYLE_BLOG_THEME_VERSION  
    );

    wp_add_inline_style( 
        'feminine-lifestyle-blog-block-editor-style', 
        feminine_lifestyle_blog_gutenberg_inline_style(),
        array(),
        FEMININE_LIFESTYLE_BLOG_THEME_VERSION  
    );

    wp_enqueue_style( 
        'feminine-lifestyle-blog-google-fonts', 
        feminine_lifestyle_blog_google_fonts_url(), 
        array(), 
        null 
    );
}
endif;
add_action( 'enqueue_block_editor_assets', 'feminine_lifestyle_blog_block_editor_styles' );

if( ! function_exists( 'feminine_lifestyle_blog_body_classes' ) ) :
/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function feminine_lifestyle_blog_body_classes( $classes ) {

    $editor_options = get_option( 'classic-editor-replace' );
    $allow_users_options = get_option( 'classic-editor-allow-users' );
    
    // Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}

    if( get_background_image() ) {
        $classes[] = 'custom-background-image';
    }

    // Adds a class of custom-background-color to sites with a custom background color.
    if( get_background_color() != 'ffffff' ) {
		$classes[] = 'custom-background-color';
	}

    if ( is_home() || (is_archive() && !( feminine_lifestyle_blog_is_woocommerce_activated() && ( is_shop() || is_product_category() || is_product_tag() ) ) ) || is_search() ) {
        $classes[] = 'post-layout-one';
    }
    
    if ( !feminine_lifestyle_blog_is_classic_editor_activated() || ( feminine_lifestyle_blog_is_classic_editor_activated() && $editor_options == 'block' ) || ( feminine_lifestyle_blog_is_classic_editor_activated() && $allow_users_options == 'allow' && has_blocks() ) ) {
        $classes[] = 'feminine-lifestyle-blog-has-blocks';
    }

    if( is_singular( 'post' ) ){        
        $classes[] = 'single-style-one' ;
    }

    $classes[] = feminine_lifestyle_blog_sidebar( true );
    
	return $classes;
}
endif;
add_filter( 'body_class', 'feminine_lifestyle_blog_body_classes' );

if( ! function_exists( 'feminine_lifestyle_blog_post_classes' ) ) :
/**
 * Add custom classes to the array of post classes.
*/
function feminine_lifestyle_blog_post_classes( $classes ){    

    global $wp_query;

    if( ( is_home() || is_archive() || is_search() ) && $wp_query->current_post == 0 ){
        $classes[] = 'large-post';
    }else {
        $classes[] = 'latest_post';
    }

    return $classes;
}
endif;
add_filter( 'post_class', 'feminine_lifestyle_blog_post_classes' );

/**
 * Add a pingback url auto-discovery header for singularly identifiable articles.
 */
function feminine_lifestyle_blog_pingback_header() {
	if ( is_singular() && pings_open() ) {
		echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
	}
}
add_action( 'wp_head', 'feminine_lifestyle_blog_pingback_header' );

if( ! function_exists( 'feminine_lifestyle_blog_change_comment_form_default_fields' ) ) :
/**
 * Change Comment form default fields i.e. author, email & url.
 * https://blog.josemcastaneda.com/2016/08/08/copy-paste-hurting-theme/
*/
function feminine_lifestyle_blog_change_comment_form_default_fields( $fields ){    
    // get the current commenter if available
    $commenter = wp_get_current_commenter();
 
    // core functionality
    $req = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );    
 
    // Change just the author field
    $fields['author'] = '<p class="comment-form-author"><label for="author">' . esc_html__( 'Name', 'feminine-lifestyle-blog' ) . '<span class="required">*</span></label><input id="author" name="author" placeholder="' . esc_attr__( 'Name*', 'feminine-lifestyle-blog' ) . '" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
    
    $fields['email'] = '<p class="comment-form-email"><label for="email">' . esc_html__( 'Email', 'feminine-lifestyle-blog' ) . '<span class="required">*</span></label><input id="email" name="email" placeholder="' . esc_attr__( 'Email*', 'feminine-lifestyle-blog' ) . '" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';
    
    $fields['url'] = '<p class="comment-form-url"><label for="url">' . esc_html__( 'Website', 'feminine-lifestyle-blog' ) . '</label><input id="url" name="url" placeholder="' . esc_attr__( 'Website', 'feminine-lifestyle-blog' ) . '" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>'; 
    
    return $fields;    
}
endif;
add_filter( 'comment_form_default_fields', 'feminine_lifestyle_blog_change_comment_form_default_fields' );

if( ! function_exists( 'feminine_lifestyle_blog_change_comment_form_defaults' ) ) :
/**
 * Change Comment Form defaults
 * https://blog.josemcastaneda.com/2016/08/08/copy-paste-hurting-theme/
*/
function feminine_lifestyle_blog_change_comment_form_defaults( $defaults ){    
    $defaults['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Comment', 'feminine-lifestyle-blog' ) . '</label><textarea id="comment" name="comment" placeholder="' . esc_attr__( 'Comment', 'feminine-lifestyle-blog' ) . '" cols="45" rows="8" aria-required="true"></textarea></p>';
    
    return $defaults;    
}
endif;
add_filter( 'comment_form_defaults', 'feminine_lifestyle_blog_change_comment_form_defaults' );

if ( ! function_exists( 'feminine_lifestyle_blog_excerpt_more_filter' ) ) :
/**
 * Replaces "[...]" (appended to automatically generated excerpts) with ... * 
 */
function feminine_lifestyle_blog_excerpt_more_filter( $more ) {
	return is_admin() ? $more : ' &hellip; ';
}

endif;
add_filter( 'excerpt_more', 'feminine_lifestyle_blog_excerpt_more_filter' );

if ( ! function_exists( 'feminine_lifestyle_blog_excerpt_length' ) ) :
/**
 * Changes the default 55 character in excerpt 
*/
function feminine_lifestyle_blog_excerpt_length( $length ) {
	$excerpt_length = get_theme_mod( 'excerpt_length', 25 );
    return is_admin() ? $length : absint( $excerpt_length );    
}
endif;
add_filter( 'excerpt_length', 'feminine_lifestyle_blog_excerpt_length', 999 );

if( ! function_exists( 'feminine_lifestyle_blog_search_form' ) ) :
/**
 * Search Form
*/
function feminine_lifestyle_blog_search_form(){ 

    if( ! is_search() ){
        $placeholder = is_404() ? _x( 'Try searching for what you were looking for&hellip;', 'placeholder', 'feminine-lifestyle-blog' ) : _x( 'Type & Hit Enter&hellip;', 'placeholder', 'feminine-lifestyle-blog' );
        $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
                    <label>
                        <span class="screen-reader-text">' . esc_html__( 'Looking for Something?', 'feminine-lifestyle-blog' ) . '
                        </span>
                        <input type="search" class="search-field" placeholder="' . esc_attr( $placeholder ) . '" value="' . esc_attr( get_search_query() ) . '" name="s" />
                    </label>                
                    <input type="submit" id="submit-field" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button', 'feminine-lifestyle-blog' ) .'" />
                </form>';
     
        return $form;
    }
}
endif;
add_filter( 'get_search_form', 'feminine_lifestyle_blog_search_form' );


if( ! function_exists( 'feminine_lifestyle_blog_get_the_archive_title' ) ) :
/**
 * Filter Archive Title
*/
function feminine_lifestyle_blog_get_the_archive_title( $title ){
    
    $ed_prefix = get_theme_mod( 'ed_prefix_archive', true );

    if( is_post_type_archive( 'product' ) ){
        $title = sprintf( __( '%1$s%2$s%3$s', 'feminine-lifestyle-blog' ), '<h1 class="page-title">', get_the_title( get_option( 'woocommerce_shop_page_id' ) ), '</h1>' );
    }else{
        if( is_category() ){
            if( $ed_prefix ){
                $title = '<h1 class="page-title">' .single_cat_title( '', false ). '</h1>';                                   
            }else{
                $title = sprintf( __( '%1$s Category: %2$s %3$s', 'feminine-lifestyle-blog'), '<span class="sub-title">','</span>', '<h1 class="page-title">' . single_cat_title( '', false ) . '</h1>') ;
            }
        }elseif ( is_tag() ){
            if( $ed_prefix ){
                $title = '<h1 class="page-title">' .single_cat_title( '', false ). '</h1>';                                   
            }else{
                $title = sprintf( __( '%1$s Tag: %2$s %3$s', 'feminine-lifestyle-blog'), '<span class="sub-title">','</span>', '<h1 class="page-title">' . single_tag_title( '', false ) . '</h1>') ;
            }
        }elseif( is_author() ){
            $title = '<span class="vcard">' . get_the_author() . '</span>';
        }elseif ( is_year() ) {
            if( $ed_prefix ){
                 $title = '<h1 class="page-title">' . get_the_date( _x( 'Y', 'yearly archives date format', 'feminine-lifestyle-blog' ) ) . '</h1>';                                   
            }else{
                $title = sprintf( __( '%1$s Year: %2$s %3$s', 'feminine-lifestyle-blog'), '<span class="sub-title">','</span>', '<h1 class="pate-title">' . get_the_date( _x( 'Y', 'yearly archives date format', 'feminine-lifestyle-blog' ) ) . '</h1>') ;
            }
        }elseif ( is_month() ) {
            if( $ed_prefix ){
                 $title = '<h1 class="page-title">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'feminine-lifestyle-blog' ) ) . '</h1>';                                   
            }else{
                $title = sprintf( __( '%1$s Month: %2$s %3$s', 'feminine-lifestyle-blog'), '<span class="sub-title">','</span>', '<h1 class="page-title">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'feminine-lifestyle-blog' ) ) . '</h1>') ;
            }
        }elseif ( is_day() ) {
            if( $ed_prefix ){
                 $title = '<h1 class="page-title">' . get_the_date( _x( 'F j, Y', 'daily archives date format', 'feminine-lifestyle-blog' ) ) . '</h1>';                                   
            }else{
                $title = sprintf( __( '%1$s Day: %2$s %3$s', 'feminine-lifestyle-blog'), '<span class="sub-title">','</span>', '<h1 class="page-title">' . get_the_date( _x( 'F j, Y', 'daily archives date format', 'feminine-lifestyle-blog' ) ) .  '</h1>') ;
            }
        }elseif ( is_post_type_archive() ) {
            if( $ed_prefix ){
                 $title = '<h1 class="page-title">'  . post_type_archive_title( '', false ) . '</h1>';                             
            }else{
                $title = sprintf( __( '%1$s Archives: %2$s %3$s', 'feminine-lifestyle-blog'), '<span class="sub-title">','</span>', '<h1 class="page-title">'  . post_type_archive_title( '', false ) . '</h1>') ;
            }
        }elseif ( is_tax() ) {
            $tax = get_taxonomy( get_queried_object()->taxonomy );
                if( $ed_prefix ){
                     $title = '<h1 class="page-title">' . single_term_title( '', false ) . '</h1>';                                 
                }else{
                    $title = sprintf( __( '%1$s: %2$s', 'feminine-lifestyle-blog' ), '<span>' . $tax->labels->singular_name . '</span>', '<h1 class="page-title">' . single_term_title( '', false ) . '</h1>' );
                }
        }else {
            $title = sprintf( __( '%1$sArchives%2$s', 'feminine-lifestyle-blog' ), '<h1 class="page-title">', '</h1>' );
        }
    }
    return $title;    
}
endif;
add_filter( 'get_the_archive_title', 'feminine_lifestyle_blog_get_the_archive_title' );

if( ! function_exists( 'feminine_lifestyle_blog_allowed_social_protocols' ) ) :
/**
 * List of allowed social protocols in HTML attributes.
 * @param  array $protocols Array of allowed protocols.
 * @return array
 */
function feminine_lifestyle_blog_allowed_social_protocols( $protocols ) {
    $social_protocols = array(
        'skype'
    );
    return array_merge( $protocols, $social_protocols );    
}
endif;
add_filter( 'kses_allowed_protocols' , 'feminine_lifestyle_blog_allowed_social_protocols' );

if( ! function_exists( 'feminine_lifestyle_blog_get_comment_author_link' ) ) :
/**
 * Filter to modify comment author link
 * @link https://developer.wordpress.org/reference/functions/get_comment_author_link/
 */
function feminine_lifestyle_blog_get_comment_author_link( $return, $author, $comment_ID ){
    $comment = get_comment( $comment_ID );
    $url     = get_comment_author_url( $comment );
    $author  = get_comment_author( $comment );
 
    if ( empty( $url ) || 'http://' == $url )
        $return = '<span itemprop="name">'. esc_html( $author ) .'</span>';
    else
        $return = '<span itemprop="name"><a href=' . esc_url( $url ) . ' rel="external nofollow noopener" class="url" itemprop="url">' . esc_html( $author ) . '</a></span>';

    return $return;
}
endif;
add_filter( 'get_comment_author_link', 'feminine_lifestyle_blog_get_comment_author_link', 10, 3 );

if( ! function_exists( 'feminine_lifestyle_blog_redirect_on_activation' ) ) :
/**
 * Redirect to Getting Started page on theme activation
*/
function feminine_lifestyle_blog_redirect_on_activation() {
    global $pagenow;
    if ( is_admin() && 'themes.php' == $pagenow && isset( $_GET['activated'] ) ) {
        wp_redirect( admin_url( "themes.php" ) );
    }
}
endif;
add_action( 'admin_init', 'feminine_lifestyle_blog_redirect_on_activation' );

if( ! function_exists( 'feminine_lifestyle_blog_exclude_cat' ) ) :
/**
 * Exclude post with Category from blog and archive page. 
*/
function feminine_lifestyle_blog_exclude_cat( $query ){

    $ed_banner      = get_theme_mod( 'ed_banner_section', 'static_banner' );
    $posts_per_page = get_theme_mod( 'no_of_slides', 3 );
    $repetitive_posts = get_theme_mod( 'include_repetitive_posts', false );
    
    if( ! is_admin() && $query->is_main_query() && $query->is_home() && $ed_banner == 'slider_banner' && !$repetitive_posts ){
        $args = array(
            'post_type'           => 'post',
            'post_status'         => 'publish',
            'posts_per_page'      => $posts_per_page,
            'ignore_sticky_posts' => true
        );
        $latest = get_posts( $args );
        $excludes = array();
        foreach( $latest as $l ){
            array_push( $excludes, $l->ID );
        }
        $query->set( 'post__not_in', $excludes ); 
    }      
}
endif;
add_filter( 'pre_get_posts', 'feminine_lifestyle_blog_exclude_cat' );

if ( ! function_exists( 'feminine_lifestyle_blog_get_fontawesome_ajax' ) ) :
/**
 * Return an array of all icons.
 */
function feminine_lifestyle_blog_get_fontawesome_ajax() {
    // Bail if the nonce doesn't check out
    if ( ! isset( $_POST['feminine_lifestyle_blog_customize_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['feminine_lifestyle_blog_customize_nonce'] ), 'feminine_lifestyle_blog_customize_nonce' ) ) {
        wp_die();
    }

    // Do another nonce check
    check_ajax_referer( 'feminine_lifestyle_blog_customize_nonce', 'feminine_lifestyle_blog_customize_nonce' );

    // Bail if user can't edit theme options
    if ( ! current_user_can( 'edit_theme_options' ) ) {
        wp_die();
    }

    // Get all of our fonts
    $fonts = feminine_lifestyle_blog_get_fontawesome_list();
    
    ob_start();
    if( $fonts ){ ?>
        <ul class="font-group">
            <?php 
                foreach( $fonts as $font ){
                    echo '<li data-font="' . esc_attr( $font ) . '"><i class="' . esc_attr( $font ) . '"></i></li>';                        
                }
            ?>
        </ul>
        <?php
    }
    echo ob_get_clean();

    // Exit
    wp_die();
}
endif;
add_action( 'wp_ajax_feminine_lifestyle_blog_get_fontawesome_ajax', 'feminine_lifestyle_blog_get_fontawesome_ajax' );

if ( ! function_exists( 'feminine_lifestyle_blog_dynamic_mce_css' ) ) :
/**
 * Add Editor Style 
 * Add Link Color Option in Editor Style (MCE CSS)
 */
function feminine_lifestyle_blog_dynamic_mce_css( $mce_css ){
    $mce_css .= ', ' . add_query_arg( array( 'action' => 'feminine_lifestyle_blog_dynamic_mce_css', '_nonce' => wp_create_nonce( 'feminine_lifestyle_blog_dynamic_mce_nonce', __FILE__ ) ), admin_url( 'admin-ajax.php' ) );
    return $mce_css;
}
endif;
add_filter( 'mce_css', 'feminine_lifestyle_blog_dynamic_mce_css' );
 
if ( ! function_exists( 'feminine_lifestyle_blog_dynamic_mce_css_ajax_callback' ) ) : 
/**
 * Ajax Callback
 */
function feminine_lifestyle_blog_dynamic_mce_css_ajax_callback(){
 
    /* Check nonce for security */
    $nonce = isset( $_REQUEST['_nonce'] ) ? $_REQUEST['_nonce'] : '';
    if( ! wp_verify_nonce( $nonce, 'feminine_lifestyle_blog_dynamic_mce_nonce' ) ){
        die(); // don't print anything
    }
    
    $primary_color = '#ff6030';
    $secondary_color = '#222222';
            
    $rgb  = feminine_lifestyle_blog_hex2rgb( feminine_lifestyle_blog_sanitize_hex_color( $primary_color ) );
    $rgb2  = feminine_lifestyle_blog_hex2rgb( feminine_lifestyle_blog_sanitize_hex_color( $secondary_color ) );
 
    /* Set File Type and Print the CSS Declaration */
    header( 'Content-type: text/css' );
    echo ':root .mce-content-body {
        --primary-color: ' . feminine_lifestyle_blog_sanitize_hex_color( $primary_color ) . ';
        --primary-color-rgb: ' . sprintf( '%1$s, %2$s, %3$s', $rgb[0], $rgb[1], $rgb[2] ) . ';
        --secondary-color: ' . feminine_lifestyle_blog_sanitize_hex_color( $secondary_color ) . ';
        --secondary-color-rgb: ' . sprintf( '%1$s, %2$s, %3$s', $rgb2[0], $rgb2[1], $rgb2[2] ) . ';
    }';
    die(); // end ajax process.
}
endif;
add_action( 'wp_ajax_feminine_lifestyle_blog_dynamic_mce_css', 'feminine_lifestyle_blog_dynamic_mce_css_ajax_callback' );
add_action( 'wp_ajax_no_priv_feminine_lifestyle_blog_dynamic_mce_css', 'feminine_lifestyle_blog_dynamic_mce_css_ajax_callback' );