<?php

defined('ABSPATH') || die("Can't access directly");
function wpbf_template_settings_post_type_array($third_party = false, $as_archives = false)
{
    $post_types = get_post_types(array('public' => true));
    if ($third_party) {
        unset($post_types['page'], $post_types['post']);
    }
    $post_types = apply_filters('wpbf_template_settings_post_type_array', $post_types);
    if ($as_archives) {
        foreach ($post_types as $post_type) {
            $post_types[$post_type . '-archive'] = ucfirst($post_type) . ' ' . __('Archives', 'wpbfpremium');
            unset($post_types[$post_type]);
        }
    }
    return $post_types;
}
function wpbf_blog_layouts_archive_array($third_party = false)
{
    $post_types = get_post_types(array('public' => true));
    if ($third_party) {
        unset($post_types['page'], $post_types['post']);
    }
    $post_types = apply_filters('wpbf_blog_layouts_archive_array', $post_types);
    foreach ($post_types as $post_type) {
        $post_types[$post_type . '-archive'] = ucfirst($post_type) . ' ' . __('Archives', 'wpbfpremium');
        unset($post_types[$post_type]);
    }
    return $post_types;
}
function wpbf_register_footer_widgets()
{
    $footer_widgets = get_theme_mod('footer_widgets', 0);
    if (!$footer_widgets) {
        return;
    }
    $footer_widgets_array = range(1, $footer_widgets);
    foreach ($footer_widgets_array as $footer_widget) {
        register_sidebar(array('name' => sprintf('Footer Widget %s', esc_attr($footer_widget)), 'id' => 'footer-' . esc_attr($footer_widget), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="wpbf-widgettitle">', 'after_title' => '</h4>'));
    }
}
add_action('widgets_init', 'wpbf_register_footer_widgets');
function wpbf_construct_widget_footer()
{
    $footer_widgets = get_theme_mod('footer_widgets', 0);
    if (!$footer_widgets) {
        return;
    }
    $footer_widgets_array = range(1, $footer_widgets);
    ?>

	<div class="wpbf-inner-widget-footer wpbf-container wpbf-container-center wpbf-padding-large">

		<div class="wpbf-grid wpbf-grid-small-1-2 wpbf-grid-medium-1-<?php 
    echo esc_attr($footer_widgets);
    ?>">

			<?php 
    foreach ($footer_widgets_array as $footer_widget) {
        echo '<div class="wpbf-footer-widget wpbf-footer-widget-' . esc_attr($footer_widget) . '">';
        if (!dynamic_sidebar('footer-' . esc_attr($footer_widget))) {
            if (current_user_can('edit_theme_options')) {
                ?>

						<div class="widget no-widgets">
							<?php 
                _e('Your Footer Widgets will appear here.', 'wpbfpremium');
                ?><br>

							<?php 
                if (is_customize_preview()) {
                    ?>
								<a href="javascript:void(0)" onclick="parent.wp.customize.panel( 'widgets' ).focus()"><?php 
                    _e('Add Widgets', 'wpbfpremium');
                    ?></a>
							<?php 
                } else {
                    ?>
								<a href='<?php 
                    echo esc_url(admin_url('widgets.php'));
                    ?>'><?php 
                    _e('Add Widgets', 'wpbfpremium');
                    ?></a>
							<?php 
                }
                ?>
						</div>

						<?php 
            }
        }
        echo '</div>';
    }
    ?>

		</div>

	</div>

	<?php 
}
function wpbf_widget_footer()
{
    $footer_widgets = get_theme_mod('footer_widgets', 0);
    if (!$footer_widgets) {
        return;
    }
    ?>

	<div class="wpbf-widget-footer">

	<?php 
    wpbf_construct_widget_footer();
    ?>

	</div>

	<?php 
}
add_action('wpbf_footer_open', 'wpbf_widget_footer');
function wpbf_sticky_navigation_attributes($attributes)
{
    $menu_sticky = get_theme_mod('menu_sticky');
    if ($menu_sticky) {
        $menu_active_delay = get_theme_mod('menu_active_delay');
        $menu_active_animation = get_theme_mod('menu_active_animation');
        $menu_active_animation_duration = get_theme_mod('menu_active_animation_duration');
        $attributes .= ' data-sticky="true"';
        $attributes .= $menu_active_delay ? ' data-sticky-delay="' . esc_attr($menu_active_delay) . '"' : ' data-sticky-delay="300px"';
        $attributes .= $menu_active_animation ? ' data-sticky-animation="' . esc_attr($menu_active_animation) . '"' : false;
        $attributes .= $menu_active_animation_duration ? ' data-sticky-animation-duration="' . esc_attr($menu_active_animation_duration) . '"' : ' data-sticky-animation-duration="200"';
    }
    return $attributes;
}
add_filter('wpbf_navigation_attributes', 'wpbf_sticky_navigation_attributes');
function wpbf_sticky_navigation_logo_attributes($attributes)
{
    $menu_active_logo = get_theme_mod('menu_active_logo');
    if ($menu_active_logo) {
        $attributes .= ' data-menu-active-logo="' . esc_url($menu_active_logo) . '"';
    }
    return $attributes;
}
add_filter('wpbf_logo_attributes', 'wpbf_sticky_navigation_logo_attributes');
function wpbf_transparent_header_body_class_2083582($classes)
{
    if (is_singular()) {
        $options = get_post_meta(get_the_ID(), 'wpbf_premium_options', true);
        $transparent_header = $options ? in_array('transparent-header', $options, true) : false;
        if ($transparent_header) {
            $classes[] = 'wpbf-transparent-header';
        } else {
            $wpbf_settings = get_option('wpbf_settings');
            $transparent_header_global = isset($wpbf_settings['wpbf_transparent_header_global']) ? $wpbf_settings['wpbf_transparent_header_global'] : array();
            if (in_array(get_post_type(), $transparent_header_global, true)) {
                $classes[] = 'wpbf-transparent-header';
            }
        }
    } else {
        $wpbf_settings = get_option('wpbf_settings');
        $transparent_headers_global = isset($wpbf_settings['wpbf_transparent_header_global']) ? $wpbf_settings['wpbf_transparent_header_global'] : array();
        $transparent_headers_global = array_diff($transparent_headers_global, get_post_types(array('public' => true)));
        if (!empty($transparent_headers_global)) {
            foreach ($transparent_headers_global as $transparent_header_global) {
                switch ($transparent_header_global) {
                    case '404_page':
                        if (is_404()) {
                            $classes[] = 'wpbf-transparent-header';
                        }
                        break;
                    case 'front_page':
                        if (is_home()) {
                            $classes[] = 'wpbf-transparent-header';
                        }
                        break;
                    case 'search':
                        if (is_search()) {
                            $classes[] = 'wpbf-transparent-header';
                        }
                        break;
                    case 'archives':
                        if (is_archive()) {
                            $classes[] = 'wpbf-transparent-header';
                        }
                        break;
                    case 'post_archives':
                        if (is_date() || is_category() || is_author() || is_tag()) {
                            $classes[] = 'wpbf-transparent-header';
                        }
                        break;
                    default:
                        $transparent_header_global = substr($transparent_header_global, 0, strpos($transparent_header_global, '_'));
                        if (is_post_type_archive($transparent_header_global)) {
                            $classes[] = 'wpbf-transparent-header';
                        }
                        $taxonomies = get_object_taxonomies($transparent_header_global, 'names');
                        if (!empty($taxonomies)) {
                            foreach ($taxonomies as $taxonomy) {
                                if (is_tax($taxonomy)) {
                                    $classes[] = 'wpbf-transparent-header';
                                }
                            }
                        }
                        break;
                }
            }
        }
    }
    return $classes;
}
add_filter('body_class', 'wpbf_transparent_header_body_class_2083582');
function wpbf_transparent_header_class($classes)
{
    $body_classes = get_body_class();
    if (in_array('wpbf-transparent-header', $body_classes, true)) {
        $classes .= ' wpbf-navigation-transparent';
    }
    return $classes;
}
add_filter('wpbf_navigation_classes', 'wpbf_transparent_header_class');
function wpbf_transparent_header_navigation_attributes($attributes)
{
    if (!in_array('wpbf-transparent-header', get_body_class(), true)) {
        return $attributes;
    }
    if (get_theme_mod('menu_transparent_mobile_disabled')) {
        $attributes .= 'data-transparent-header-disabled="mobile"';
    }
    return $attributes;
}
add_filter('wpbf_navigation_attributes', 'wpbf_transparent_header_navigation_attributes');
function wpbf_transparent_header_logo($logo_url)
{
    $classes = get_body_class();
    if (in_array('wpbf-transparent-header', $classes, true) && get_theme_mod('menu_transparent_logo')) {
        $logo_url = get_theme_mod('menu_transparent_logo');
    }
    return $logo_url;
}
add_filter('wpbf_logo', 'wpbf_transparent_header_logo', 20);
add_filter('wpbf_logo_mobile', 'wpbf_transparent_header_logo', 20);
function wpbf_transparent_header_logo_mobile_disabled($logo_url)
{
    if (!in_array('wpbf-transparent-header', get_body_class(), true)) {
        return $logo_url;
    }
    if (!get_theme_mod('menu_transparent_mobile_disabled')) {
        return $logo_url;
    }
    $logo_id = get_theme_mod('custom_logo');
    $logo_url = wp_get_attachment_image_src($logo_id, 'full');
    $logo_url = $logo_url[0];
    $mobile_logo_url = get_theme_mod('menu_mobile_logo');
    if ($mobile_logo_url) {
        $logo_url = $mobile_logo_url;
    }
    return $logo_url;
}
add_filter('wpbf_logo_mobile', 'wpbf_transparent_header_logo_mobile_disabled', 30);
if (!function_exists('wpbf_has_responsive_breakpoints')) {
    function wpbf_has_responsive_breakpoints()
    {
        $wpbf_settings = get_option('wpbf_settings');
        if (!empty($wpbf_settings['wpbf_breakpoint_medium']) || !empty($wpbf_settings['wpbf_breakpoint_desktop']) || !empty($wpbf_settings['wpbf_breakpoint_mobile'])) {
            return true;
        } else {
            return false;
        }
    }
}
function wpbf_breakpoint_desktop()
{
    $wpbf_settings = get_option('wpbf_settings');
    if (!empty($wpbf_settings['wpbf_breakpoint_desktop'])) {
        $desktop_breakpoint = (int) $wpbf_settings['wpbf_breakpoint_desktop'];
    } else {
        $desktop_breakpoint = 1024;
    }
    return $desktop_breakpoint;
}
function wpbf_breakpoint_medium()
{
    $wpbf_settings = get_option('wpbf_settings');
    if (!empty($wpbf_settings['wpbf_breakpoint_medium'])) {
        $medium_breakpoint = (int) $wpbf_settings['wpbf_breakpoint_medium'];
    } else {
        $medium_breakpoint = 768;
    }
    return $medium_breakpoint;
}
function wpbf_breakpoint_mobile()
{
    $wpbf_settings = get_option('wpbf_settings');
    if (!empty($wpbf_settings['wpbf_breakpoint_mobile'])) {
        $mobile_breakpoint = (int) $wpbf_settings['wpbf_breakpoint_mobile'];
    } else {
        $mobile_breakpoint = 480;
    }
    return $mobile_breakpoint;
}
function wpbf_remove_header_hooks()
{
    if (is_singular('wpbf_hooks')) {
        remove_action('wpbf_header', 'wpbf_do_header');
        remove_action('wpbf_footer', 'wpbf_do_footer');
    }
}
add_action('wp', 'wpbf_remove_header_hooks');
function wpbf_color_palette($print_defaults = false, $print_empty = false)
{
    $defaults = array('#000000', '#ffffff', '#dd3333', '#dd9933', '#eeee22', '#81d742', '#1e73be', '#8224e3');
    $settings = get_option('wpbf_settings');
    $colors = isset($settings['color_palette']) ? $settings['color_palette'] : $defaults;
    if ($colors === $defaults && !$print_defaults) {
        $colors = array();
    }
    if (!$print_empty) {
        $colors = array_filter($colors);
    }
    return apply_filters('wpbf_color_palette', $colors);
}
function wpbf_remove_core_post_types($post_types)
{
    unset($post_types['udb_admin_page'], $post_types['wpbf_hooks'], $post_types['attachment']);
    return $post_types;
}
add_filter('wpbf_template_settings_post_type_array', 'wpbf_remove_core_post_types');
add_filter('wpbf_blog_layouts_archive_array', 'wpbf_remove_core_post_types');