%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/laviva/wp-content/themes/levelup/
Upload File :
Create Path :
Current File : /var/www/html/shaban/laviva/wp-content/themes/levelup/functions.php

<?php

// Require Files
// =============================================================================

define( 'LEVELUP_THEME_NAME', 'LEVELUP' );

define( 'LEVELUP_TEMPLATE_PATH', get_template_directory() );
define( 'LEVELUP_TEMPLATE_URL', get_template_directory_uri() );
define( 'LEVELUP_BASE_DIR', get_template_directory() . '/' );

define( 'LEVELUP_BUDDYPRESS_IS_ACTIVE', class_exists( 'BuddyPress' ) );
define( 'LEVELUP_WOOCOMMERCE_IS_ACTIVE', class_exists( 'WC_API' ) );
define( 'LEVELUP_CONTACT_FORM_7_IS_ACTIVE', class_exists( 'WPCF7_ContactForm' ) );
define( 'LEVELUP_VISUAL_COMOPSER_IS_ACTIVE', class_exists( 'WPBakeryVisualComposer' ) );
define( 'LEVELUP_REVOLUTION_SLIDER_IS_ACTIVE', class_exists( 'RevSlider' ) );


include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( ! is_plugin_active( 'levelup-core/levelup-core.php' ) && file_exists( get_template_directory() . '/admin/default-settings.php' ) ) {
    require_once get_template_directory() . '/admin/default-settings.php';

    if ( function_exists( "is_woocommerce" ) ) {
        require_once get_template_directory() . '/woocommerce/woocommerce-config.php';
    }
}

include_once get_template_directory() . '/admin/admin-init.php';
include_once get_template_directory() . '/inc/classes/levelup-options.php';

include_once get_template_directory() . '/inc/classes/rdy-config.php';

include_once get_template_directory() . '/inc/helpers.php';
include_once get_template_directory() . '/inc/ext/pagination.php';
include_once get_template_directory() . '/inc/ext/aq_resizer.php';
include_once get_template_directory() . '/inc/nav_menu/rdy_menu.php';
include_once get_template_directory() . '/inc/font-awesome.php';
include_once get_template_directory() . '/inc/theme-config.php';
include_once get_template_directory() . '/inc/sidebar-generator.php';


if ( file_exists( get_template_directory() . '/demo-functions.php' ) ) {
    include_once get_template_directory() . '/demo-functions.php';
}


function Levelup_Options() {
    return Levelup_Options::get_instance();
    //Levelup_Options()->getOption('back-to-top-main-icon');
}


function levelup_init() {

    if ( is_admin() ) {
        remove_post_type_support( 'rdy_testimonials', 'editor' );
    }

}
add_action( 'after_setup_theme', 'levelup_init' );


function levelup_init_wp_head()   {
    Levelup_Options::setGlobals();

//    do_action('levelup_config_base_init');
    levelup_config_base_init();
}
//add_action('wp_head', 'levelup_init_wp_head', 1);
add_action( 'wp_enqueue_scripts', 'levelup_init_wp_head', 1 );


function levelup_init_after_redux() {
    global $levelup_options;

    if ( $levelup_options['transition-layout'] == 1 && class_exists('Levelup_Page_Transition') ) {
        new Levelup_Page_Transition();
    }
}

if ( ! is_admin() ) {
    add_action( 'levelupredux/loaded', 'levelup_init_after_redux' );
}


if ( ! is_admin() ) {

    if ( ! function_exists( 'levelup_maintenance_mode' ) ) {

        function levelup_maintenance_mode() {

            global $levelup_options;

            $protocol = is_ssl() ? "https://" : "http://";
            if ( isset( $levelup_options['maintenance_mode'] ) && $levelup_options['maintenance_mode'] && isset( $levelup_options['maintenance_page'] ) && $levelup_options['maintenance_page'] != ""
                 && ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) )
                 && ! is_admin()
                 && ! is_user_logged_in()
                 && $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] != get_permalink( $levelup_options['maintenance_page'] )
            ) {

                wp_redirect( get_permalink( $levelup_options['maintenance_page'] ) );
                exit;
            }

        }

//        add_action( 'init', 'levelup_maintenance_mode', 1 );
        add_action( 'levelupredux/loaded', 'levelup_maintenance_mode' );
    }

}


function levelup_woocommerce_init(){
	if ( function_exists( "is_woocommerce" ) ) {
		require_once get_template_directory() . '/woocommerce/woocommerce-config.php';
	}
}
add_action( 'levelupredux/loaded', 'levelup_woocommerce_init' );


function levelup_custom_fonts_font_faces( $css = '' ) {
	global $levelup_options;

    $font_css = '';

    if ( isset( $levelup_options['custom_fonts'] ) ) {
        $custom_fonts = $levelup_options['custom_fonts'];

        if ( isset( $custom_fonts['name'] ) && is_array( $custom_fonts['name'] ) ) {
            foreach ( $custom_fonts['name'] as $key => $label ) {
                $label = trim( $label );

	            if ( empty( $label ) ) {
		            continue;
	            }

                if (
                    ( isset( $custom_fonts['woff'] ) && isset( $custom_fonts['woff'][ $key ] ) ) ||
                    ( isset( $custom_fonts['woff2'] ) && isset( $custom_fonts['woff2'][ $key ] ) ) ||
                    ( isset( $custom_fonts['ttf'] ) && isset( $custom_fonts['ttf'][ $key ] ) ) ||
                    ( isset( $custom_fonts['svg'] ) && isset( $custom_fonts['svg'][ $key ] ) ) ||
                    ( isset( $custom_fonts['eot'] ) && isset( $custom_fonts['eot'][ $key ] ) )
                ) {
                    $firstfile = true;
                    $font_css .= '@font-face{';
                    $font_css .= 'font-family:';

                    if ( false !== strpos( $label, ' ' ) ) {
                        $font_css .= '"' . $label . '";';
                    } else {
                        $font_css .= $label . ';';
                    }

                    $font_css .= 'src:';

                    if ( isset( $custom_fonts['eot'] ) && isset( $custom_fonts['eot'][ $key ] ) && $custom_fonts['eot'][ $key ]['url'] ) {
                        $font_css .= 'url("' . str_replace( array( 'http://', 'https://' ), '//', $custom_fonts['eot'][ $key ]['url'] ) . '?#iefix") format("embedded-opentype")';
                        $firstfile = false;
                    }

                    if ( isset( $custom_fonts['woff'] ) && isset( $custom_fonts['woff'][ $key ] ) && $custom_fonts['woff'][ $key ]['url'] ) {
                        $font_css .= ( $firstfile ) ? '' : ',';
                        $font_css .= 'url("' . str_replace( array( 'http://', 'https://' ), '//', $custom_fonts['woff'][ $key ]['url'] ) . '") format("woff")';
                        $firstfile = false;
                    }

                    if ( isset( $custom_fonts['woff2'] ) && isset( $custom_fonts['woff2'][ $key ]['url'] ) && $custom_fonts['woff2'][ $key ]['url'] ) {
                        $font_css .= ( $firstfile ) ? '' : ',';
                        $font_css .= 'url("' . str_replace( array( 'http://', 'https://' ), '//', $custom_fonts['woff2'][ $key ]['url'] ) . '") format("woff2")';
                        $firstfile = false;
                    }

                    if ( isset( $custom_fonts['ttf'] ) && isset( $custom_fonts['ttf'][ $key ] ) && $custom_fonts['ttf'][ $key ]['url'] ) {
                        $font_css .= ( $firstfile ) ? '' : ',';
                        $font_css .= 'url("' . str_replace( array( 'http://', 'https://' ), '//', $custom_fonts['ttf'][ $key ]['url'] ) . '") format("truetype")';
                        $firstfile = false;
                    }

                    if ( isset( $custom_fonts['svg'] ) && isset( $custom_fonts['svg'][ $key ] ) && $custom_fonts['svg'][ $key ]['url'] ) {
                        $font_css .= ( $firstfile ) ? '' : ',';
                        $font_css .= 'url("' . str_replace( array( 'http://', 'https://' ), '//', $custom_fonts['svg'][ $key ]['url'] ) . '") format("svg")';
                        $firstfile = false;
                    }
                    $font_css .= ';font-weight: normal;font-style: normal;';
                    $font_css .= '}';
                }
            }
        }
    }

    return $font_css . $css;
}
add_filter( 'levelup_dynamic_css', 'levelup_custom_fonts_font_faces' );


function levelup_is_realy_woocommerce_page() {
    if ( function_exists( "is_woocommerce" ) && is_woocommerce() ) {
        return false;
    }
    $woocommerce_keys = array(
        "woocommerce_shop_page_id",
        "woocommerce_terms_page_id",
        "woocommerce_cart_page_id",
        "woocommerce_checkout_page_id",
        "woocommerce_pay_page_id",
        "woocommerce_thanks_page_id",
        "woocommerce_myaccount_page_id",
        "woocommerce_edit_address_page_id",
        "woocommerce_view_order_page_id",
        "woocommerce_change_password_page_id",
        "woocommerce_logout_page_id",
        "woocommerce_lost_password_page_id"
    );
    foreach ( $woocommerce_keys as $wc_page_id ) {
        if ( get_the_ID() == get_option( $wc_page_id, 0 ) ) {
            return true;
        }
    }

    return false;
}


// Image sizes
// =============================================================================

if (!function_exists( 'levelup_add_image_sizes' )) {

    function levelup_add_image_sizes(){

        add_theme_support('post-thumbnails');
        add_image_size( 'levelup-blog-latest-box', 740, 410, true);

        add_image_size( 'levelup-portfolio-thumb-orig', 700, 700 );
        add_image_size( 'levelup-portfolio-thumb', 900, 600, true );
        add_image_size( 'levelup-portfolio-thumb-square', 700, 700, true );
        add_image_size( 'levelup-portfolio-big-thumb-orig', 1200, 1200 );
        add_image_size( 'levelup-portfolio-big-thumb', 1200, 800, true );
        add_image_size( 'levelup-portfolio-big-thumb-square', 1200, 1200, true );

        add_image_size( 'levelup-shop_special', 1240, 750, true );

    }

}


function levelup_vcSetAsTheme() {
    vc_set_as_theme();
}
add_action( 'vc_before_init', 'levelup_vcSetAsTheme' );


if ( class_exists( 'Vc_Manager', false ) ) {

    add_action( 'init', 'levelup_js_composer_load_bridge', 20 );
    if ( !function_exists( 'levelup_js_composer_load_bridge' ) ) {

        function levelup_js_composer_load_bridge() {

        }

    }


    function levelup_init_custom_vc_js() {
        global $levelup_options;

        wp_enqueue_style( 'levelup_visual_composer', get_template_directory_uri() . '/admin/assets/css/visual-composer.css', array(), "1.0", 'all' );
        wp_register_script( 'levelup_vc_extend', get_template_directory_uri() . '/admin/assets/js/vc_extend.js' );
        wp_enqueue_script( 'levelup_vc_extend' );
    }

    add_action('vc_frontend_editor_render', 'levelup_init_custom_vc_js');
    add_action('vc_backend_editor_render', 'levelup_init_custom_vc_js');


    if ( ! function_exists( 'levelup_vc_inline_editor_scripts' ) ) :

        /**
         * Visual Composer custom view scripts
         *
         * @since 4.1.5
         */
        function levelup_vc_inline_editor_scripts() {
            if ( ! function_exists('vc_is_inline') || ! vc_is_inline() ) {
                return;
            }
        }

    endif;

}


function levelup_is_vc_plugin() {
    if ( class_exists( 'Vc_Manager', false ) ) {
        return true;
    }

    return false;
}


function levelup_body_class( $classes ) {
    global $levelup_options;

    $config = Levelup_Config::get_instance();

    if ( $levelup_options['header-style-down-content'] && $config->get( 'siteheader.layout' ) == 'gamburg' ) {
        $classes[] = 'down_content_on_open';
    }

    if ( $levelup_options['header-topbar-enable'] ) {
        $classes[] = 'with-topbar';
    }

    if ( isset( $levelup_options['header-layout'] ) && ( $levelup_options['header-layout'] == 'fixed' || $levelup_options['header-layout'] == 'static' )
         && isset( $levelup_options['menu-animated-anchors'] ) && $levelup_options['menu-animated-anchors'] ) {
        $classes[] = 'animated-anchors';
    }

    if ( $levelup_options['header-topbar-enable'] && $config->get( 'siteheader.layout' ) == 'fixed' ) {

        if ( $levelup_options['header-topbar-position'] == 'sticky' ) {
            $classes[] = 'with-sticky-topbar';
        } else {
            $classes[] = 'with-slide-topbar';
        }

    }

    if ( levelup_get_options( 'footer-effects' ) == 'uncovering' ) {
        $classes[] = 'footer-uncovering';
    }

    if ( levelup_get_options( 'vc_row__padding_fix' ) == 'xs' ) {
        $classes[] = 'vc_row-padding-fix-xs';
    }


    if ( class_exists( 'Woocommerce' ) && is_product() && levelup_get_options('woo-product-content-image-zoom') ) {
        $classes[] = 'product-zoom';
    }

    if ( is_page() ) {
        $sidebar_position = ( levelup_get_options( 'page_sidebar' ) && ! $config->get( 'sidebar_position' ) ) ? levelup_get_options( 'page_sidebar' ) : $config->get( 'sidebar_position' );

        if ( $sidebar_position && $sidebar_position != 'disabled') {
            $classes[] = 'with-sidebar';
        }
    } else if ( is_singular('post') ) {
        if ( levelup_get_options( 'blog-post__sidebar' ) ) {
            $classes[] = 'with-sidebar';
        }
    }

    return $classes;
}

add_filter( 'body_class', 'levelup_body_class' );


function levelup_comments_callback( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    extract($args, EXTR_SKIP);

    if ( 'div' == $args['style'] ) {
        $tag = 'div';
        $add_below = 'comment';
    } else {
        $tag = 'li';
        $add_below = 'div-comment';
    }
    ?>
    <<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">

    <?php if ( 'div' != $args['style'] ) : ?>
        <div id="div-comment-<?php esc_attr( comment_ID() ); ?>" class="comment-body">
        <article>
    <?php endif; ?>

    <div class="comment-author vcard set-align-left">
        <?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
    </div>

    <div class="comment-info">
        <div class="comment-author"><?php comment_author_link();?></div>
        <?php if ( $comment->comment_approved == '0' ) : ?>
            <em class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'LEVELUP' ); ?></em>
            <br />
        <?php endif; ?>

        <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
                <?php
                /* translators: 1: date, 2: time */
                printf( esc_html__('%1$s at %2$s', 'LEVELUP'), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( esc_html__( '(Edit)', 'LEVELUP' ), '  ', '' );
            ?>
        </div>

        <div class="comment-content"><?php comment_text(); ?></div>

        <div class="reply">
            <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
        </div>
    </div>
    <?php if ( 'div' != $args['style'] ) : ?>
        </article>
        </div>
    <?php endif; ?>
<?php
}


if ( ! function_exists( 'levelup_setup_theme' ) ) {

    function levelup_setup_theme() {

        load_theme_textdomain( 'LEVELUP', get_template_directory() . '/languages' );

        levelup_add_image_sizes();

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

        add_theme_support( 'title-tag' );

        if ( function_exists( 'register_nav_menus' ) ) {
            register_nav_menus(
                array(
                    'menu1' => esc_html__( 'Primary Menu', 'LEVELUP'),
                    'menu2' => esc_html__( 'Column 2', 'LEVELUP'),
                    'menu3' => esc_html__( 'Column 3', 'LEVELUP'),
                    'menu4' => esc_html__( 'Column 4', 'LEVELUP'),
                    'topbar' => esc_html__( 'Top Bar', 'LEVELUP'),
                    'footerbar' => esc_html__( 'Footer Bar', 'LEVELUP'),
                )
            );
        }

        add_theme_support( 'html5', array(
            'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
        ) );

        add_theme_support( 'post-formats', array(
            'video', 'audio',
        ) );

        add_theme_support( 'custom-background', apply_filters( 'levelup_custom_background_args', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        ) ) );

        add_theme_support( 'woocommerce' );

        add_editor_style();

        if ( ! isset( $content_width ) ) $content_width = 1170;
    }

}
add_action( 'after_setup_theme', 'levelup_setup_theme' );


if ( ! function_exists( 'levelup_is_user_made_sidebar' ) ) {

    function levelup_is_user_made_sidebar( $name ) {

        if ( $name === 'Sidebar' ) {
            return false;
        } else if ( $name === 'Blog Sidebar' ) {
            return false;
        } else if ( $name === 'Menu Widget' ) {
            return false;
        } else if ( $name === 'Bottom Widget' ) {
            return false;
        } else if ( $name === 'Footer Area 1' ) {
            return false;
        } else if ( $name === 'Footer Area 2' ) {
            return false;
        } else if ( $name === 'Footer Area 3' ) {
            return false;
        } else if ( $name === 'Footer Area 4' ) {
            return false;
        } else if ( $name === 'Footer Copyright Area' ) {
            return false;
        } else if ( $name === 'Woocommerce' ) {
            return false;
        } else {
            return true;
        }
    }

}


require get_template_directory() . '/inc/custom-header.php';
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/extras.php';

if ( ! function_exists( 'levelup_enqueue_scripts' ) ) {

    function levelup_enqueue_scripts() {
        global $levelup_options;

        $theme_info = wp_get_theme();

	    if ( defined( 'LEVELUP_JS_SINGLE_PLUGINS' ) && LEVELUP_JS_SINGLE_PLUGINS ) {

		    wp_enqueue_script( 'levelup_plugins', get_template_directory_uri() . '/assets/js/plugins.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );

	    } else {

		    wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/assets/vendor/modernizr/modernizr.custom.72003.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/assets/vendor/imagesloaded.pkgd.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'superfish', get_template_directory_uri() . '/assets/vendor/superfish.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'midnight', get_template_directory_uri() . '/assets/vendor/midnight.jquery.src.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'jquery.smooth-scroll', get_template_directory_uri() . '/assets/vendor/jquery.smooth-scroll.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously', get_template_directory_uri() . '/assets/js/fx/seriously.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously.blend', get_template_directory_uri() . '/assets/js/fx/seriously.fx/seriously.blend.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously.edge', get_template_directory_uri() . '/assets/js/fx/seriously.fx/seriously.edge.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously.hue-saturation', get_template_directory_uri() . '/assets/js/fx/seriously.fx/seriously.hue-saturation.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously.layers', get_template_directory_uri() . '/assets/js/fx/seriously.fx/seriously.layers.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously.linear-transfer', get_template_directory_uri() . '/assets/js/fx/seriously.fx/seriously.linear-transfer.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'seriously.tone', get_template_directory_uri() . '/assets/js/fx/seriously.fx/seriously.tone.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'particles', get_template_directory_uri() . '/assets/js/fx/particles.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'three', get_template_directory_uri() . '/assets/js/fx/three.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'three.Projector', get_template_directory_uri() . '/assets/js/fx/renderers/Projector.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'three.CanvasRenderer', get_template_directory_uri() . '/assets/js/fx/renderers/CanvasRenderer.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'glitch', get_template_directory_uri() . '/assets/js/fx/glitch.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'levelup-counters', get_template_directory_uri() . '/assets/js/counters.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'levelup-graphic', get_template_directory_uri() . '/assets/js/graphic.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );

		    wp_enqueue_script( 'easy-pie-chart', get_template_directory_uri() . '/assets/vendor/easy-pie-chart.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'jquery.lazyload', get_template_directory_uri() . '/assets/vendor/jquery.lazyload.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'jquery.fitvids', get_template_directory_uri() . '/assets/vendor/jquery.fitvids.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'countup', get_template_directory_uri() . '/assets/vendor/countup.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'jquery.mousewheel', get_template_directory_uri() . '/assets/vendor/jquery.mousewheel.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'blast', get_template_directory_uri() . '/assets/vendor/blast.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'jquery.parallax-scroll', get_template_directory_uri() . '/assets/vendor/jquery.parallax-scroll.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'easyzoom', get_template_directory_uri() . '/assets/vendor/easyzoom.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'shaderloader', get_template_directory_uri() . '/assets/vendor/shaderloader.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'sine-waves', get_template_directory_uri() . '/assets/vendor/sine-waves.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'scrollspy', get_template_directory_uri() . '/assets/vendor/scrollspy.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'froogaloop2', get_template_directory_uri() . '/assets/vendor/froogaloop2.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'detect-element-resize', get_template_directory_uri() . '/assets/vendor/detect-element-resize.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'jquery.easing', get_template_directory_uri() . '/assets/vendor/jquery.easing.1.3.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
		    wp_enqueue_script( 'url', get_template_directory_uri() . '/assets/vendor/url.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );

	    }

        wp_enqueue_script( 'levelup_main_js', get_template_directory_uri() . '/assets/js/main.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
        wp_localize_script( 'levelup_main_js', 'levelup_js_vars', array('themePath' => get_template_directory_uri()) );

        if ( class_exists( 'Vc_Manager', false ) ) {
            wp_enqueue_style( 'isotope-css' );
        }

        /*if ( class_exists( 'Vc_Manager', false ) && wp_script_is('waypoints', 'registered') ) {
            wp_enqueue_script( 'waypoints' );
        } else {
            wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/assets/vendor/waypoints/jquery.waypoints.min.js' );
        }*/
	    wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/assets/vendor/waypoints/jquery.waypoints.min.js' );

        wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/vendor/isotope/isotope.pkgd.min.js', array( 'jquery' ), '3.0.0', true );

        if ( get_post_type() == 'rdy_project' ) {
            wp_enqueue_script( 'levelup_slides', get_template_directory_uri() . '/assets/js/slides.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );
        }

        wp_enqueue_script( 'hoverIntent', '/wp-includes/js/hoverIntent$suffix.js', array('jquery'), '1.8.1', true );
        if ( function_exists( 'vc_asset_url' ) ) {
            wp_register_script( 'vc_jquery_skrollr_js', vc_asset_url( 'lib/bower/skrollr/dist/skrollr.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
            wp_enqueue_script( 'vc_jquery_skrollr_js' );
        }

        wp_register_script( 'google_maps', '//maps.google.com/maps/api/js?' . ( isset( $levelup_options['google-maps-apikey'] ) ? '&key=' . esc_attr( $levelup_options['google-maps-apikey'] ) : '' ), array(), false );

        wp_register_script('infinite_scroll', get_template_directory_uri() . '/assets/vendor/jquery.infinitescroll.min.js', array('jquery'), $theme_info->get( 'Version' ), true);
        wp_enqueue_script('infinite_scroll');

        wp_enqueue_script( 'velocity', get_template_directory_uri() . '/assets/js/libs/velocity.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );

        wp_register_script( 'vivus', get_template_directory_uri() . '/assets/vendor/vivus.min.js', array( 'jquery' ), wp_get_theme()->get( 'Version' ), true );


        // CSS ---------------------------------------------------------------------------------------------------------

        wp_register_script('magnific_popup', get_template_directory_uri() . '/assets/vendor/magnific-popup/jquery.magnific-popup.min.js', array('jquery'));
        wp_register_style(
            'magnific_popup',
            get_template_directory_uri() . '/assets/vendor/magnific-popup/magnific-popup.css',
            array(),
            time(),
            'all'
        );

        wp_enqueue_style( 'levelup-style', get_stylesheet_uri(), array(), $theme_info->get( 'Version' ));

        wp_enqueue_style( 'levelup_main', get_template_directory_uri() . '/assets/css/style.css', array(), $theme_info->get( 'Version' ));
        wp_enqueue_style( 'levelup_font_sym', get_template_directory_uri() . '/assets/fonts/g79/styles.css', array(), $theme_info->get( 'Version' ));
        wp_enqueue_style( 'levelup_animated', get_template_directory_uri() . '/assets/vendor/animate.css', array(), $theme_info->get( 'Version' ));

        wp_enqueue_style( 'font-awesome-4', get_template_directory_uri() . '/assets/vendor/fa/css/font-awesome.min.css', array(), $theme_info->get( 'Version' ));


        // Other -------------------------------------------------------------------------------------------------------

        wp_register_script( 'select2', get_template_directory_uri() . '/assets/vendor/select2/select2.min.js', array(), $theme_info->get( 'Version' ));
        wp_register_style(
            'select2',
            get_template_directory_uri() . '/assets/vendor/select2/select2.css',
            array(),
            $theme_info->get( 'Version' ),
            'all'
        );

        wp_register_script( 'owl-carousel', get_template_directory_uri() . '/assets/vendor/owl-carousel/owl.carousel.min.js', array(
            'jquery',
        ), $theme_info->get( 'Version' ), true );

        wp_enqueue_script('owl-carousel');
        wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/assets/vendor/owl-carousel/assets/owl.carousel.css', array(), $theme_info->get( 'Version' ));

        if ( function_exists( 'levelup_enqueue_dynamic_stylesheets' ) ) {
            levelup_enqueue_dynamic_stylesheets();
        } else {
            wp_enqueue_style( 'levelup_custom_default', get_template_directory_uri() . '/assets/css/custom.css', array(), $theme_info->get( 'Version' ));
        }

        /*if ( is_archive() || is_home() || is_front_page() ) {
            wp_enqueue_script( 'isotope' );
            wp_enqueue_style( 'isotope-css' );
        }*/

        // the comment-reply script
        if ( is_singular() && get_option( 'thread_comments' ) ) {
            wp_enqueue_script( 'comment-reply' );
        }

        if ( ! ( defined( 'LEVELUP_THEME_DISABLE_FONTS' ) && LEVELUP_THEME_DISABLE_FONTS === true )/* && ! class_exists( 'LevelupReduxFramework' ) && ! class_exists( 'ReduxFramework' )*/ ) {
            wp_enqueue_style( 'levelup_font_open_sans', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,300,400,600,700,800&subset=latin,cyrillic');
        }

        if ( is_post_type_archive( 'rdy_project' ) ) {
            wp_enqueue_script( 'wp-mediaelement' );
            wp_enqueue_style( 'wp-mediaelement' );
        }

    }

}


function levelup_enqueue_scripts_add_async( $tag, $handle ) {
    return ( $handle == 'levelup_main_js' ) ? preg_replace( "/(><\/[a-zA-Z][^0-9](.*)>)$/", " async $1 ", $tag ) : $tag;
}
if ( ! is_admin() && ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
    add_action( 'wp_enqueue_scripts', 'levelup_enqueue_scripts', 15 );
//    add_action( 'script_loader_tag', 'levelup_enqueue_scripts_add_async', 10, 2 );
}


function levelup_page_specific_js() {

    global $post;
    global $options;

    if ( isset( $post ) ) {
        $post_content = $post->post_content;
        $posttype     = get_post_type( $post );

        if ( strpos( $post_content, 'type="svg"' ) !== false ) {
            wp_enqueue_script( 'vivus' );

        }
    }

}

add_action('wp_enqueue_scripts', 'levelup_page_specific_js', 15);


if ( ! function_exists( 'levelup_admin_scripts' ) ) :

    function levelup_admin_scripts( $hook ) {
        wp_enqueue_style( 'birdy-metabox', get_template_directory_uri() . '/admin/assets/css/admin_box.css' );

        wp_enqueue_script( 'jquery-tiptip', get_template_directory_uri() . '/admin/assets/js/jquery.tipTip.min.js', array( 'jquery' ), false, true );

        wp_enqueue_style( 'wp-color-picker' );
        wp_enqueue_script( 'wp-color-picker' );

        wp_enqueue_script( 'birdy-metabox', get_template_directory_uri() . '/inc/admin/assets/custom-metaboxes.js', array('jquery'), false, true );
        wp_localize_script( 'birdy-metabox', 'RDY', array(
            'iris' => array(
                'palettes' => array(
                    "#000",
                    "#fff",
                    levelup_get_options('accent-color'),
                    levelup_get_options('extra-color1'),
                    levelup_get_options('extra-color2'),
                    levelup_get_options('extra-color3'),
                    levelup_get_options('extra-color4'),
                    levelup_get_options('extra-color5'),
                    levelup_get_options('extra-color6'),
                )
            )
        ) );
    }

endif;

add_action( 'admin_enqueue_scripts', 'levelup_admin_scripts', 11 );


function levelup_admin_styles() {
    if ( is_admin() ) {
        wp_enqueue_style( 'font-awesome-4', get_template_directory_uri() . '/assets/vendor/fa/css/font-awesome.min.css');

        wp_dequeue_style( 'levelupredux-css' );
        wp_register_style(
            'levelupredux-custom-css',
            get_template_directory_uri() . '/admin/assets/css/options.css',
            array( 'farbtastic' ),
            time(),
            'all'
        );
        wp_enqueue_style('levelupredux-custom-css');
        wp_add_inline_style( 'levelupredux-custom-css', apply_filters( 'levelup_dynamic_css', '' ) );
    }
}
add_action( 'admin_enqueue_scripts', 'levelup_admin_styles' );


function levelup_header_classes($value){
    global $levelup_options;
    $config = Levelup_Config::get_instance();

    $header_class = array();

    if ( $levelup_options['menu-style'] == 'light' && ! is_404() ) {
        $header_class[] = 'white';
    }
    if ( $levelup_options['menu-buttons-style'] == 'light' && ! is_404() ) {
        $header_class[] = 'btn-white';
    }
    if ( $levelup_options['menu-style-opened'] == 'dark' ) {
        $header_class[] = 'bg-white';
    }
    if ( $levelup_options['header-side_icons-bg-enable'] ) {
        $header_class[] = 'side_icons-bg';
    }
    if ( $config->get( 'siteheader.layout' ) == 'static' ) {
        $header_class[] = 'static-layout';
    }
    if ( $config->get( 'siteheader.layout' ) == 'fixed' ) {
        $header_class[] = 'fixed-layout';
    }
    if ( $config->get( 'siteheader.mobile.stiky' ) ) {
        $header_class[] = 'stiky-mobile';
    }

    if ( ( $config->get( 'header.transparent' ) || ! $levelup_options['header-background'] ) && $config->get( 'header.transparent.style' ) ) {
        $header_class[] = 'mark-' . esc_attr( $config->get( 'header.transparent.style' ) ) . ' mark-logo-' . esc_attr( $config->get( 'header.transparent.style' ) );
    }

    if ( $config->get( 'siteheader.layout' ) == 'gamburg' ) {
        $header_class[] = 'slidedown-layout';
    }
    if ( $config->get( 'siteheader.layout' ) == 'gamburg_full' ) {
        $header_class[] = 'slidedown-full-layout';
    }

    if ( empty( $levelup_options['header-fullwidth'] ) ) {
        $header_class[] = 'boxed';
    }

    if ( $levelup_options['header-style-menu-columns'] && ( $config->get( 'siteheader.layout' ) == 'gamburg' || $config->get( 'siteheader.layout' ) == 'static' ) ) {
        $header_class[] = 'with-columns';
    }

    if ( levelup_get_options('header-mobile-bar') == 'button_right_logo_center' ) {
        $header_class[] = 'mobile-logo-center-br';
    } elseif ( levelup_get_options('header-mobile-bar') == 'button_left_logo_center' ) {
        $header_class[] = 'mobile-logo-center-bl';
    }

    if ( isset( $levelup_options['header-mobile_menu-animation'] ) && $levelup_options['header-mobile_menu-animation'] == 'fadein' ) {
        $header_class[] = 'mobile-fadein';
    }

    $header_classes = implode( ' ', array_filter( $header_class ) );

    return $header_classes;
}
add_filter('levelup_header_classes', 'levelup_header_classes', 10, 1);


function levelup_header_menu_mobile_classes($value){
    global $levelup_options;
    $config = Levelup_Config::get_instance();

    $header_class = array();
    if ( $config->get( 'siteheader.mobile.stiky' ) ) {
        $header_class[] = 'stiky-mobile';
    }

    if ( levelup_get_options( 'header-mobile-items-align' ) == 'center' ) {
        $header_class[] = 'align-center';
    } elseif ( levelup_get_options( 'header-mobile-items-align' ) == 'right' ) {
        $header_class[] = 'align-right';
    }

    if ( ! levelup_get_options( 'mobile_menu-items-divider' ) ) {
        $header_class[] = 'no-divider';
    }

    if ( isset( $levelup_options['header-mobile_menu-valign'] ) && $levelup_options['header-mobile_menu-valign'] == 'middle' ) {
        $header_class[] = ' valign-middle';
    }

    if ( isset( $levelup_options['header-mobile_menu-elements-valign'] ) && $levelup_options['header-mobile_menu-elements-valign'] == 'bottom' ) {
        $header_class[] = ' valign-el-bottom';
    }
    if ( isset( $levelup_options['header-mobile_menu-fullwidth'] ) && !$levelup_options['header-mobile_menu-fullwidth'] ) {
        $header_class[] = ' fixed-width';
    }

    $header_classes = implode( ' ', array_filter( $header_class ) );

    return $header_classes;
}
add_filter('levelup_header_menu_mobile_classes', 'levelup_header_menu_mobile_classes', 10, 1);


function levelup_header_search_classes($value){
    global $levelup_options;

    $header_classes = '';
    if ( levelup_get_options( 'header-search-color-style' ) == 'dark' ) {
        $header_classes = 'dark';
    }

    return $header_classes;
}
add_filter('levelup_header_search_classes', 'levelup_header_search_classes', 10, 1);


function levelup_header_menu_classes($value){
    global $levelup_options;
    $config = Levelup_Config::get_instance();

    $header_menu_class = array();

    if ( $levelup_options['menu-style'] == 'light' && ! is_404() ) {
        $header_menu_class[] = 'white';
    }
    if ( ( $config->get( 'header.transparent' ) || ! $levelup_options['header-background'] ) && $config->get( 'header.transparent.style' ) ) {
        $header_menu_class[] = 'mark-' . esc_attr( $config->get( 'header.transparent.style' ) );
    }

    if ( $config->get( 'siteheader.layout' ) == 'gamburg' ) {
        $header_menu_class[] = 'slidedown-layout';
    }
    if ( $config->get( 'siteheader.layout' ) == 'gamburg_full' ) {
        $header_menu_class[] = 'slidedown-full-layout';
    }
    if ( $config->get( 'siteheader.layout' ) == 'fixed' ) {
        $header_menu_class[] = 'menu-opened fixed-layout';
    } elseif ( $config->get( 'siteheader.layout' ) == 'static' ) {
        $header_menu_class[] = 'menu-opened static-layout';
    } else {
        $header_menu_class[] = 'menu-closed';
    }

    if ( $config->get( 'siteheader.layout.gamburg' ) ) {
        $header_menu_class[] = 'with-background';
    } elseif ( $levelup_options['header-background'] && ! $config->get( 'header.transparent' ) ) {
        $header_menu_class[] = 'with-background';
    }


    if ( $levelup_options['header-align'] ) {
        if ( ! ( ( $config->get( 'siteheader.layout' ) == 'static' || $config->get( 'siteheader.layout' ) == 'gamburg' ) && $levelup_options['header-style-menu-columns'] ) ) {
            $header_menu_class[] = 'align-' . esc_attr( $levelup_options['header-align'] );
        }
    }

    if ( empty( $levelup_options['header-fullwidth'] ) ) {
        $header_menu_class[] = 'boxed';
    }

    if ( $levelup_options['header-style-menu-columns'] && ( $config->get( 'siteheader.layout' ) == 'gamburg' || $config->get( 'siteheader.layout' ) == 'static' ) ) {
        $header_menu_class[] = 'with-columns';
    }

    if ( $levelup_options['header-style-menu-inline'] && $config->get( 'siteheader.layout' ) == 'gamburg_full' ) {
        $header_menu_class[] = 'menu-inline';
    }


    if ( $levelup_options['menu-hover-underline'] ) {
        $header_menu_class[] = 'menu-items-underline';
    }
    if ( $levelup_options['menu-drop-hover-underline'] ) {
        $header_menu_class[] = 'menu-drop-items-underline';
    }
    if ( $levelup_options['header-dividers-enable'] && $levelup_options['header-style-menu-widget'] ) {
        $header_menu_class[] = 'show_divider';
    }

    if ( $levelup_options['header-fullwidth'] ) {
        $header_menu_class[] = 'is_fullwidth';
    }

    if ( $levelup_options['header-bottom_line'] == 'line'
         && in_array( $config->get( 'siteheader.layout' ), array( 'fixed', 'static', 'gamburg' ) )
         && ! ( $config->get( 'siteheader.background_appear' ) > 0 && ( $levelup_options['header-background-appear-line'] || $config->get( 'header.transparent.appear_line_hide' ) ) )
         && ! (
                 $config->get( 'header.transparent' )
                 && ! $config->get( 'siteheader.background_appear' )
                 && ( ( $levelup_options['header-background-appear-enable'] && $levelup_options['header-background-appear-line'] ) || $config->get( 'header.transparent.appear_line_hide' ) ) )
    ) {
        $header_menu_class[] = 'show_bottomline';
    }

    if ( $levelup_options['header-bottom_line'] == 'shadow'
         && in_array( $config->get( 'siteheader.layout' ), array( 'fixed', 'static', 'gamburg' ) )
         && ! ( $config->get( 'siteheader.background_appear' ) > 0 && ( $levelup_options['header-background-appear-line'] || $config->get( 'header.transparent.appear_line_hide' ) ) )
         && ! (
                 $config->get( 'header.transparent' )
                 && ! $config->get( 'siteheader.background_appear' )
                 && ( ( $levelup_options['header-background-appear-enable'] && $levelup_options['header-background-appear-line'] ) || $config->get( 'header.transparent.appear_line_hide' ) )
        )
    ) {
        $header_menu_class[] = 'with-shadow';
    }

    if ( ! levelup_get_options( 'use-logo' ) ) {// && levelup_get_options( 'header-align' )
        $header_menu_class[] = 'without-logo';
    }

    if (
        ! (
        levelup_get_options( 'header-search-enable' )
        || ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && levelup_get_options( 'header-cart-enable' ) )
        || ( levelup_get_options('header-social-position') == 'right' && ( levelup_get_options('header-align') == 'left' || levelup_get_options('header-align') == 'center' ) )
        )
    ) {
        $header_menu_class[] = 'without-rightside';
    }

    $header_menu_classes = implode( ' ', array_filter( $header_menu_class ) );
    return $header_menu_classes;
}
add_filter('levelup_header_menu_classes', 'levelup_header_menu_classes', 10, 1);


function levelup_header_data( $value ) {
    global $levelup_options;
    $config = Levelup_Config::get_instance();

    $header_data = array();

    if ( is_404() ) {
        $header_data[] = 'data-color="dark"';
    }

    if ( $config->get( 'siteheader.layout' ) == 'fixed' ) {
        $header_data[] = 'data-fixed-menu="1"';
    }

    if ( ( $config->get( 'header.transparent' ) || ! $levelup_options['header-background'] ) && $config->get( 'header.transparent.style' ) ) {
        $header_data[] = 'data-items-color="' . esc_attr( $config->get( 'header.transparent.style' ) ) . '"';
    }

    if ( $config->get( 'siteheader.background_appear' ) > 0 && ( $config->get( 'siteheader.layout' ) == 'fixed' ) ) {
        $header_data[] = 'data-background-color="' . ( $levelup_options['header-background-color'] ? esc_attr( $levelup_options['header-background-color'] ) : '#fff' ) . '"';
        $header_data[] = 'data-background-appear="' . esc_attr( $config->get( 'siteheader.background_appear' ) ) . '"';
        if ( ( $levelup_options['header-background-appear-line'] || $config->get( 'header.transparent.appear_line_hide' ) ) && $levelup_options['header-bottom_line'] == 'line' ) {
            $header_data[] = 'data-line-appear="1"';
        }
        if ( ( $levelup_options['header-background-appear-line'] || $config->get( 'header.transparent.appear_line_hide' ) ) && $levelup_options['header-bottom_line'] == 'shadow' ) {
            $header_data[] = 'data-shadow-appear="1"';
        }
    }

    $header_datas = '';
    if ( $header_data ) {
        $header_datas = implode( ' ', array_filter( $header_data ) );
    }
    return $header_datas;
}
add_filter('levelup_header_data', 'levelup_header_data', 10, 1);


function levelup_header_is_appear( $value ) {
    global $levelup_options;
    $config = Levelup_Config::get_instance();

    $is_appear = false;

    if ( $config->get( 'siteheader.background_appear' ) > 0 && ( $config->get( 'siteheader.layout' ) == 'fixed' ) ) {
        $is_appear = true;
    }

    return $is_appear;
}
add_filter('levelup_header_is_appear', 'levelup_header_is_appear', 10, 1);


function levelup_excerpt_length( $length ) {
    global $levelup_options;
    $excerpt_length = (!empty($levelup_options['blog_excerpt_length'])) ? intval($levelup_options['blog_excerpt_length']) : 30;

    return $excerpt_length;
}

add_filter( 'excerpt_length', 'levelup_excerpt_length', 999 );


if ( !function_exists( 'levelup_header_socials' ) ) {

    function levelup_header_socials( $return = false ) {
        global $levelup_options;

        if ( ! $levelup_options['header-social-position'] ) {
            return false;
        }

        $echo = '';
        $echo .= '<div class="top-bar-social' . ( $levelup_options['social-icons-animation'] ? ' animation' : '' ) . ( $levelup_options['header-social-hover'] == 1 ? ' brand-hover' : '' ) . '">';

        $order = levelup_get_options('social-media-order');
        if ( isset( $order ) && is_array( $order ) ) {
            foreach ( $order as $key => $value ) {
                if ( empty( $value ) ) {
                    continue;
                }

                if ( ( isset( $levelup_options[ $key . '-url' ] ) ) && ( trim( $levelup_options[ $key . '-url' ] ) != "" ) && isset( $levelup_options[ 'header-social-' . $key ] ) && $levelup_options[ 'header-social-' . $key ] ) {
                    $echo .= '<a href="' . esc_url( $levelup_options[ $key . '-url' ] ) . '" target="_blank" class="social_media social_media_' . $key . '"><i class="fa fa-' . $key . '"></i></a>';
                }
            }
        }

        $echo .= '</div>';

        return $echo;
    }

    add_filter('levelup_header_socials', 'levelup_header_socials', 10, 1);

}


if ( !function_exists( 'levelup_header_topbar_socials' ) ) {

    function levelup_header_topbar_socials( $return = false ) {
        global $levelup_options;

        $echo = '';
        $echo .= '<div class="top-bar-social">';

        $order = levelup_get_options('social-media-order');
        if ( isset( $order ) && is_array( $order ) ) {
            foreach ( $order as $key => $value ) {
                if ( empty( $value ) ) {
                    continue;
                }

                if ( ( isset( $levelup_options[ $key . '-url' ] ) ) && ( trim( $levelup_options[ $key . '-url' ] ) != "" ) && isset($levelup_options['header-topbar-social-' . $key ]) && $levelup_options['header-topbar-social-' . $key ] ) {
                    $echo .= '<a href="' . esc_url( $levelup_options[ $key . '-url' ] ) . '" target="_blank" class="social_media social_media_' . $key . '"><i class="fa fa-' . $key . '"></i></a>';
                }
            }
        }

        $echo .= '</div>';

        if ( ! $return ) {
            echo $echo;
        } else {
            return $echo;
        }
    }

}


if ( !function_exists( 'levelup_footer_socials' ) ) {

    function levelup_footer_socials( $return = false, $bar = false ) {
        global $levelup_options;

        if ( ! $levelup_options['footer-sub-social'] && ! $bar ) {
            return false;
        }

        $echo = '';
        $echo .= '<div class="bottom-bar-social' . ( $levelup_options['social-icons-animation'] ? ' animation' : '' ) . '"><div' . ( $levelup_options['header-social-hover'] == 1 ? ' class="brand-hover"' : '' ) . '>';

        $order = levelup_get_options('social-media-order');
        if ( isset( $order ) && is_array( $order ) ) {
            foreach ( $order as $key => $value ) {
                if ( empty( $value ) ) {
                    continue;
                }

                if ( ( isset( $levelup_options[ $key . '-url' ] ) ) && ( trim( $levelup_options[ $key . '-url' ] ) != "" ) ) {
                    $echo .= '<a href="' . esc_url( $levelup_options[ $key . '-url' ] ) . '" target="_blank" class="social_media social_media_' . $key . '"><i class="fa fa-' . $key . '"></i></a>';
                }
            }
        }

        $echo .= '</div></div>';

        if ( ! $return ) {
            echo $echo;
        } else {
            return $echo;
        }
    }

}


$levelup_social_data = array(
    'facebook' => array(
        'title' => esc_html__( "Facebook", 'LEVELUP' )
    ),
    'twitter' => array(
        'title' => esc_html__( "Twitter", 'LEVELUP' )
    ),
    'google-plus'=> array(
        'title' => esc_html__( "Google+", 'LEVELUP' )
    ),
    'vimeo'=> array(
        'title' => esc_html__( "Vimeo", 'LEVELUP' )
    ),
    'pinterest'=> array(
        'title' => esc_html__( "Pinterest", 'LEVELUP' )
    ),
    'youtube'=> array(
        'title' => esc_html__( "Youtube", 'LEVELUP' )
    ),
    'tumblr'=> array(
        'title' => esc_html__( "Tumblr", 'LEVELUP' )
    ),
    'linkedin'=> array(
        'title' => esc_html__( "Linkedin", 'LEVELUP' )
    ),
    'xing'=> array(
        'title' => esc_html__( "Xing", 'LEVELUP' )
    ),
    'rss'=> array(
        'title' => esc_html__( "RSS", 'LEVELUP' )
    ),
    'behance'=> array(
        'title' => esc_html__( "Behance", 'LEVELUP' )
    ),
    'instagram'=> array(
        'title' => esc_html__( "Instagram", 'LEVELUP' )
    ),
    'github'=> array(
        'title' => esc_html__( "Github", 'LEVELUP' )
    ),
    'soundcloud'=> array(
        'title' => esc_html__( "Soundcloud", 'LEVELUP' )
    ),
    'vk'=> array(
        'title' => esc_html__( "VK", 'LEVELUP' )
    ),
    'wechat'=> array(
        'title' => esc_html__( "WeChat", 'LEVELUP' )
    ),
    'snapchat'=> array(
        'title' => esc_html__( "Snapchat", 'LEVELUP' )
    ),
    'flickr'=> array(
        'title' => esc_html__( "Flickr", 'LEVELUP' )
    ),
);


if ( !function_exists( 'levelup_header_mobile_socials' ) ) {

    function levelup_header_mobile_socials() {
        global $levelup_options, $levelup_social_data;

        if ( ! ( isset( $levelup_options['header-m-social-show'] ) && $levelup_options['header-m-social-show'] ) ) {
            return false;
        }

        echo '<div class="mobile_socials' . ( isset( $levelup_options['header-m-social-show'] ) && $levelup_options['header-m-social-show'] == 'icons' ? ' with-icons' : '' ) . '">';

        $order = levelup_get_options('social-media-order');
        if ( isset( $order ) && is_array( $order ) ) {
            foreach ( $order as $key => $value ) {
                if ( empty( $value ) ) {
                    continue;
                }

                $title = '';

                if ( isset( $levelup_social_data[ $key ] ) ) {
                    $title = $levelup_social_data[ $key ]['title'];
                }

                if ( ( isset( $levelup_options[ $key . '-url' ] ) ) && ( trim( $levelup_options[ $key . '-url' ] ) != "" ) && $levelup_options[ 'header-m-social-' . $key ] ) {
                    echo '<a href="' . esc_url( $levelup_options[$key . '-url'] ) . '" target="_blank" class="social_media social_media_' . $key . '">';

                    if ( $levelup_options['header-m-social-show'] == 'icons' ) {
                        echo '<i class="fa fa-' . $key . '"></i>';
                    } else {
                        echo $title;
                    }

                    echo '</a>';

                }
            }
        }

        echo '</div>';

        return 1;
    }

}


function levelup_wp_infinitepaginate(){
    $loopFile        = $_POST['loop_file'];
    $paged           = $_POST['page_no'];
    $posts_per_page  = get_option('posts_per_page');

    # Load the posts
    query_posts(array('paged' => $paged ));
    get_template_part( $loopFile );

    exit;
}

add_action('wp_ajax_infinite_scroll', 'levelup_wp_infinitepaginate');
add_action('wp_ajax_nopriv_infinite_scroll', 'levelup_wp_infinitepaginate');


/*if (!function_exists( 'levelup_blog_singlepost_before' )) {

    function levelup_blog_singlepost_before() {
        global $levelup_options;
        $layout_class = 'container-fluid';
        $html = '<div class="' . esc_attr( $layout_class ) . '">';

        echo $html;
    }
}


if (!function_exists( 'levelup_blog_singlepost_after' )) {

    function levelup_blog_singlepost_after() {
        $html = '</div>';

        echo $html;
    }
}

add_action('levelup_blog_singlepost_before', 'levelup_blog_singlepost_before');
add_action('levelup_blog_singlepost_after', 'levelup_blog_singlepost_after');*/


if ( ! function_exists( 'levelup_paginator_args_filter' ) ) {

	function levelup_paginator_args_filter( $args ) {
		global $post;
		$config = Levelup_Config::get_instance();

		// show all pages in paginator
		$show_all_pages = '0';

		if ( is_page() ) {
			$show_all_pages = $config->get( 'show_all_pages' );
		}

		if ( '0' != $show_all_pages ) {
			$args['num_pages'] = 9999;
		} else {
			$args['num_pages'] = 5;
		}

		$args['wrap']                = '
		<div class="%CLASS%" role="navigation"%DATA%>
			<div class="page-links">%LIST%
		';

		$args['pages_wrap']          = '
			</div>
			<div class="page-nav">
				%PREV%%NEXT%
			</div>
		</div>
		';

		$args['item_wrap']           = '<a href="%HREF%" %CLASS_ACT% data-page-num="%PAGE_NUM%"><span>%TEXT%</span></a>';
		$args['first_wrap']          = '<a href="%HREF%" %CLASS_ACT% data-page-num="%PAGE_NUM%"><span>%FIRST_PAGE%</span></a>';
		$args['last_wrap']           = '<a href="%HREF%" %CLASS_ACT% data-page-num="%PAGE_NUM%"><span>%LAST_PAGE%</span></a>';
		$args['dotleft_wrap']        = '<span class="dots">%TEXT%</span>';
		$args['dotright_wrap']       = '<span class="dots">%TEXT%</span>';// %TEXT%
		$args['pages_prev_class']    = 'nav-prev';
		$args['pages_next_class']    = 'nav-next';
		$args['act_class']           = 'act';
		$args['next_text']           = _x( 'Next page &#8594;', 'paginator', 'LEVELUP' );
		$args['prev_text']           = _x( '&#8592; Previous page', 'paginator', 'LEVELUP' );
		$args['no_next']             = '';
		$args['no_prev']             = '';
		$args['first_is_first_mode'] = true;

		return $args;
	}

}

add_filter( 'levelup_paginator_args', 'levelup_paginator_args_filter' );


function levelup_get_template_part( $slug = '', $name = '' ) {
    if ( empty( $slug ) ) {
        return;
    }

    $dir_base = '/templates/';
    get_template_part( $dir_base . $slug, $name );
}


function levelup_add_image_attachment_fields_to_edit($form_fields, $post) {
    $form_fields["link"] = array(
        "label" => esc_html__("Link", 'LEVELUP'),
        "input" => "text",
        "value" => get_post_meta($post->ID, "_link", true),
    );
    return $form_fields;
}
add_filter("attachment_fields_to_edit", "levelup_add_image_attachment_fields_to_edit", null, 2);


function levelup_add_image_attachment_fields_to_save($post, $attachment) {
	if ( isset( $attachment['link'] ) ) {
		update_post_meta( $post['ID'], '_link', $attachment['link'] );
	}
    return $post;
}
add_filter("attachment_fields_to_save", "levelup_add_image_attachment_fields_to_save", null , 2);


if ( ! function_exists( 'levelup_rewrite_rules_on_theme_activation' ) ) {

	function levelup_rewrite_rules_on_theme_activation() {
		flush_rewrite_rules();
	}

	add_action( 'after_switch_theme', 'levelup_rewrite_rules_on_theme_activation' );
}


function levelup_is_header_transparent(){
    global $levelup_options;
    $config = levelup_config();

	if (
		( $config->get( 'siteheader.layout' ) == 1 )
		|| (
			( $config->get( 'siteheader.layout' ) == 2 || $config->get( 'siteheader.layout' ) == 3 )
			&& ( $config->get( 'header.transparent' ) || ! $levelup_options['header-background'] || ( $config->get( 'siteheader.background_appear' ) > 0 ) )
		)
	) {
		return true;
	}

    return false;
}


function levelup_global_footer_spacing() {
    global $levelup_options;

    $config = levelup_config();

    $footer_margin_top = 0;

    $project_page = false;
    if ( 'rdy_project' == get_post_type() && ! is_single() ) {
        $project_page = true;
    }

    if ( class_exists( 'Woocommerce' ) && is_woocommerce() && is_product() ) {
        $info_fullscreen = get_post_meta(get_the_ID(), '_rdy_woocommerce_desc_fullscreen', true);
        if ( ! $info_fullscreen ) {
            $footer_margin_top = 40;
        }
    } else if ( $levelup_options['wc-custom-spacing'] && isset( $levelup_options['wc-footer-margin_top'] ) && $levelup_options['wc-footer-margin_top'] >= 0 && class_exists( 'Woocommerce' ) && is_woocommerce() ) {
        $footer_margin_top = $levelup_options['wc-footer-margin_top'];
    } else if ( isset( $levelup_options['page-title-bloglist-footer-spacing'] ) && $levelup_options['page-title-bloglist-footer-spacing'] >= 0 && $levelup_options['page-title-bloglist-footer-spacing'] != '' && ( is_home() || is_author() || is_category() || is_tag() || is_404()) ) {
        $footer_margin_top = $levelup_options['page-title-bloglist-footer-spacing'];
    } else if ( is_single() ) {
        // in single template before navigation bar
    } else {
        $footer_margin_top = $levelup_options['footer-margin_top'];
    }

    if ( $footer_margin_top >= 0 && $footer_margin_top != '' && ! $project_page && ! $config->get( 'disable_footer_margin' ) ) {
        echo '<div class="footer_spacer" style="height: ' . esc_attr( $footer_margin_top ) . 'px;"></div>';
    }
}
add_action('levelup_global_footer_spacing', 'levelup_global_footer_spacing');


function levelup_single_footer_spacing() {
    global $levelup_options;

    $levelup_config = Levelup_Config::get_instance();

    $levelup_footer_margin_top = '';
    if ( is_singular( 'post' ) ) {
        $levelup_footer_margin_top = $levelup_options['page-title-blog-footer-spacing'] ? esc_attr( $levelup_options['page-title-blog-footer-spacing'] ) : esc_attr( $levelup_options['footer-margin_top'] );
    } else {
        $levelup_footer_margin_top = esc_attr( $levelup_options['footer-margin_top'] );
    }

    if ( $levelup_footer_margin_top && ! $levelup_config->get( 'disable_footer_margin' ) ) {
        echo '<div class="footer_spacer" style="height: ' . esc_attr( $levelup_footer_margin_top ) . 'px;"></div>';
    }

}
add_action('levelup_single_footer_spacing', 'levelup_single_footer_spacing');


function levelup_global_content_spacing() {
	global $levelup_options;

	$config        = levelup_config();
	$margin_bottom = '';
	$title_margin_bottom = '';

	if ( $levelup_options['wc-custom-spacing'] && isset( $levelup_options['wc-page-title-margin-bottom'] ) && $levelup_options['wc-page-title-margin-bottom'] >= 0 && class_exists( 'Woocommerce' ) && is_woocommerce() ) {
		$title_margin_bottom = $levelup_options['wc-page-title-margin-bottom'];
	} else if ( ! $config->get( 'disable_content_padding' ) ) {
		if ( is_singular( 'post' ) ) {
			$title_margin_bottom = $levelup_options['page-title-blog-margin-bottom'] ? $levelup_options['page-title-blog-margin-bottom'] : $levelup_options['page-title-margin-bottom'];
		} elseif ( isset( $levelup_options['page-title-bloglist-margin-bottom'] ) && $levelup_options['page-title-bloglist-margin-bottom'] >= 0 && $levelup_options['page-title-bloglist-margin-bottom'] != '' && ( is_home() || is_author() || is_category() || is_tag() || is_404() )) {
			$title_margin_bottom = $levelup_options['page-title-bloglist-margin-bottom'];
		} else {
			$title_margin_bottom = $levelup_options['page-title-margin-bottom'];
		}
	}

	if ( class_exists( 'Woocommerce' ) && is_woocommerce() && is_product() ) {
		if ( $config->get( 'siteheader.layout' ) == 1 ) {
			$margin_bottom = 80 + 36;
		} elseif ( ! empty( $levelup_options['header-height'] ) && $levelup_options['header-height'] > 0 && levelup_is_header_transparent() ) {
			$margin_bottom = $levelup_options['header-height'] + 36;
		} else {
			$margin_bottom = 36;
		}
	} else {
		$margin_bottom = $title_margin_bottom;
	}

    if ( ! empty( $margin_bottom ) && $margin_bottom >= 0 ) {
		echo '<div class="page-title-margin-bottom" style="height: ' . esc_attr( $margin_bottom ) . 'px"></div>';
	}
}
add_action('levelup_global_content_spacing', 'levelup_global_content_spacing');


function levelup_archive_page_as_front_page( $query ) {
	global $levelup_options;
	if ( is_admin() || $levelup_options['front-page'] != 'project' ) {
		return;
	}
	if ( $query->get( 'page_id' ) == get_option( 'page_on_front' ) ) {
		$query->set( 'post_type', 'rdy_project' );
		$query->set( 'page_id', '' );
		$query->is_page    = $query->is_singular = 0;
		$query->is_archive = $query->is_post_type_archive = 1;
	}
}

add_action( "pre_get_posts", "levelup_archive_page_as_front_page" );


function levelup_remove_unnecessary_wordpress_menus(){
    global $submenu;
    
    if( isset($submenu['themes.php']) ){
        foreach ( $submenu['themes.php'] as $menu_index => $theme_menu ) {
            if ( $theme_menu[0] == 'Header' || $theme_menu[0] == 'Background' ) {
                unset( $submenu['themes.php'][ $menu_index ] );
            }
        }
	}
}

add_action('admin_menu', 'levelup_remove_unnecessary_wordpress_menus', 999);


function levelup_wbc_importer_label() {
    return esc_html__( 'Import Demo', 'LEVELUP' );
}

add_filter("wbc_importer_label", "levelup_wbc_importer_label", null , 2);


function levelup_wbc_importer_dir_path() {
    return trailingslashit( str_replace( '\\', '/', LEVELUP_BASE_DIR ) ) . 'inc/demo-data/';
}

add_filter("wbc_importer_dir_path", "levelup_wbc_importer_dir_path", null , 2);


function levelup_vc_iconpicker_type_etline( $icons ) {
    $etline_icons = array(
        array( 'etline-mobile' => esc_html__( 'Mobile', 'LEVELUP' ) ),
        array( 'etline-laptop' => esc_html__( 'Laptop', 'LEVELUP' ) ),
        array( 'etline-desktop' => esc_html__( 'desktop', 'LEVELUP' ) ),
        array( 'etline-phone' => esc_html__( 'phone', 'LEVELUP' ) ),
        array( 'etline-document' => esc_html__( 'document', 'LEVELUP' ) ),
        array( 'etline-documents' => esc_html__( 'documents', 'LEVELUP' ) ),
        array( 'etline-search' => esc_html__( 'search', 'LEVELUP' ) ),
        array( 'etline-clipboard' => esc_html__( 'clipboard', 'LEVELUP' ) ),
        array( 'etline-newspaper' => esc_html__( 'newspaper', 'LEVELUP' ) ),
        array( 'etline-notebook' => esc_html__( 'notebook', 'LEVELUP' ) ),
        array( 'etline-book-open' => esc_html__( 'book-open', 'LEVELUP' ) ),
        array( 'etline-browser' => esc_html__( 'browser', 'LEVELUP' ) ),
        array( 'etline-calendar' => esc_html__( 'calendar', 'LEVELUP' ) ),
        array( 'etline-presentation' => esc_html__( 'presentation', 'LEVELUP' ) ),
        array( 'etline-picture' => esc_html__( 'picture', 'LEVELUP' ) ),
        array( 'etline-pictures' => esc_html__( 'pictures', 'LEVELUP' ) ),
        array( 'etline-video' => esc_html__( 'video', 'LEVELUP' ) ),
        array( 'etline-camera' => esc_html__( 'camera', 'LEVELUP' ) ),
        array( 'etline-printer' => esc_html__( 'printer', 'LEVELUP' ) ),
        array( 'etline-toolbox' => esc_html__( 'toolbox', 'LEVELUP' ) ),
        array( 'etline-briefcase' => esc_html__( 'briefcase', 'LEVELUP' ) ),
        array( 'etline-wallet' => esc_html__( 'wallet', 'LEVELUP' ) ),
        array( 'etline-gift' => esc_html__( 'gift', 'LEVELUP' ) ),
        array( 'etline-bargraph' => esc_html__( 'bargraph', 'LEVELUP' ) ),
        array( 'etline-grid' => esc_html__( 'grid', 'LEVELUP' ) ),
        array( 'etline-expand' => esc_html__( 'expand', 'LEVELUP' ) ),
        array( 'etline-focus' => esc_html__( 'focus', 'LEVELUP' ) ),
        array( 'etline-edit' => esc_html__( 'edit', 'LEVELUP' ) ),
        array( 'etline-adjustments' => esc_html__( 'adjustments', 'LEVELUP' ) ),
        array( 'etline-ribbon' => esc_html__( 'ribbon', 'LEVELUP' ) ),
        array( 'etline-hourglass' => esc_html__( 'hourglass', 'LEVELUP' ) ),
        array( 'etline-lock' => esc_html__( 'lock', 'LEVELUP' ) ),
        array( 'etline-megaphone' => esc_html__( 'megaphone', 'LEVELUP' ) ),
        array( 'etline-shield' => esc_html__( 'shield', 'LEVELUP' ) ),
        array( 'etline-trophy' => esc_html__( 'trophy', 'LEVELUP' ) ),
        array( 'etline-flag' => esc_html__( 'flag', 'LEVELUP' ) ),
        array( 'etline-map' => esc_html__( 'map', 'LEVELUP' ) ),
        array( 'etline-puzzle' => esc_html__( 'puzzle', 'LEVELUP' ) ),
        array( 'etline-basket' => esc_html__( 'basket', 'LEVELUP' ) ),
        array( 'etline-envelope' => esc_html__( 'envelope', 'LEVELUP' ) ),
        array( 'etline-streetsign' => esc_html__( 'streetsign', 'LEVELUP' ) ),
        array( 'etline-telescope' => esc_html__( 'telescope', 'LEVELUP' ) ),
        array( 'etline-gears' => esc_html__( 'gears', 'LEVELUP' ) ),
        array( 'etline-key' => esc_html__( 'key', 'LEVELUP' ) ),
        array( 'etline-paperclip' => esc_html__( 'paperclip', 'LEVELUP' ) ),
        array( 'etline-attachment' => esc_html__( 'attachment', 'LEVELUP' ) ),
        array( 'etline-pricetags' => esc_html__( 'pricetags', 'LEVELUP' ) ),
        array( 'etline-lightbulb' => esc_html__( 'lightbulb', 'LEVELUP' ) ),
        array( 'etline-layers' => esc_html__( 'layers', 'LEVELUP' ) ),
        array( 'etline-pencil' => esc_html__( 'pencil', 'LEVELUP' ) ),
        array( 'etline-tools' => esc_html__( 'tools', 'LEVELUP' ) ),
        array( 'etline-tools-2' => esc_html__( 'tools-2', 'LEVELUP' ) ),
        array( 'etline-scissors' => esc_html__( 'scissors', 'LEVELUP' ) ),
        array( 'etline-paintbrush' => esc_html__( 'paintbrush', 'LEVELUP' ) ),
        array( 'etline-magnifying-glass' => esc_html__( 'magnifying-glass', 'LEVELUP' ) ),
        array( 'etline-circle-compass' => esc_html__( 'circle-compass', 'LEVELUP' ) ),
        array( 'etline-linegraph' => esc_html__( 'linegraph', 'LEVELUP' ) ),
        array( 'etline-mic' => esc_html__( 'mic', 'LEVELUP' ) ),
        array( 'etline-strategy' => esc_html__( 'strategy', 'LEVELUP' ) ),
        array( 'etline-beaker' => esc_html__( 'beaker', 'LEVELUP' ) ),
        array( 'etline-caution' => esc_html__( 'caution', 'LEVELUP' ) ),
        array( 'etline-recycle' => esc_html__( 'recycle', 'LEVELUP' ) ),
        array( 'etline-anchor' => esc_html__( 'anchor', 'LEVELUP' ) ),
        array( 'etline-profile-male' => esc_html__( 'profile-male', 'LEVELUP' ) ),
        array( 'etline-profile-female' => esc_html__( 'profile-female', 'LEVELUP' ) ),
        array( 'etline-bike' => esc_html__( 'bike', 'LEVELUP' ) ),
        array( 'etline-wine' => esc_html__( 'wine', 'LEVELUP' ) ),
        array( 'etline-hotairballoon' => esc_html__( 'hotairballoon', 'LEVELUP' ) ),
        array( 'etline-globe' => esc_html__( 'globe', 'LEVELUP' ) ),
        array( 'etline-genius' => esc_html__( 'genius', 'LEVELUP' ) ),
        array( 'etline-map-pin' => esc_html__( 'map-pin', 'LEVELUP' ) ),
        array( 'etline-dial' => esc_html__( 'dial', 'LEVELUP' ) ),
        array( 'etline-chat' => esc_html__( 'chat', 'LEVELUP' ) ),
        array( 'etline-heart' => esc_html__( 'heart', 'LEVELUP' ) ),
        array( 'etline-cloud' => esc_html__( 'cloud', 'LEVELUP' ) ),
        array( 'etline-upload' => esc_html__( 'upload', 'LEVELUP' ) ),
        array( 'etline-download' => esc_html__( 'download', 'LEVELUP' ) ),
        array( 'etline-target' => esc_html__( 'target', 'LEVELUP' ) ),
        array( 'etline-hazardous' => esc_html__( 'hazardous', 'LEVELUP' ) ),
        array( 'etline-piechart' => esc_html__( 'piechart', 'LEVELUP' ) ),
        array( 'etline-speedometer' => esc_html__( 'speedometer', 'LEVELUP' ) ),
        array( 'etline-global' => esc_html__( 'global', 'LEVELUP' ) ),
        array( 'etline-compass' => esc_html__( 'compass', 'LEVELUP' ) ),
        array( 'etline-lifesaver' => esc_html__( 'lifesaver', 'LEVELUP' ) ),
        array( 'etline-clock' => esc_html__( 'clock', 'LEVELUP' ) ),
        array( 'etline-aperture' => esc_html__( 'aperture', 'LEVELUP' ) ),
        array( 'etline-quote' => esc_html__( 'quote', 'LEVELUP' ) ),
        array( 'etline-scope' => esc_html__( 'scope', 'LEVELUP' ) ),
        array( 'etline-alarmclock' => esc_html__( 'alarmclock', 'LEVELUP' ) ),
        array( 'etline-refresh' => esc_html__( 'refresh', 'LEVELUP' ) ),
        array( 'etline-happy' => esc_html__( 'happy', 'LEVELUP' ) ),
        array( 'etline-sad' => esc_html__( 'sad', 'LEVELUP' ) ),
        array( 'etline-facebook' => esc_html__( 'facebook', 'LEVELUP' ) ),
        array( 'etline-twitter' => esc_html__( 'twitter', 'LEVELUP' ) ),
        array( 'etline-googleplus' => esc_html__( 'googleplus', 'LEVELUP' ) ),
        array( 'etline-rss' => esc_html__( 'rss', 'LEVELUP' ) ),
        array( 'etline-tumblr' => esc_html__( 'tumblr', 'LEVELUP' ) ),
        array( 'etline-linkedin' => esc_html__( 'linkedin', 'LEVELUP' ) ),
        array( 'etline-dribbble' => esc_html__( 'dribbble', 'LEVELUP' ) ),

    );

    return array_merge( $icons, $etline_icons );
}

add_filter( 'vc_iconpicker-type-etline', 'levelup_vc_iconpicker_type_etline' );


function levelup_vc_iconpicker_base_register_css(){
    wp_register_style( 'font-etline', get_template_directory_uri() . '/assets/fonts/et-line/style.css', array());
}

add_action( 'vc_base_register_front_css', 'levelup_vc_iconpicker_base_register_css' );
add_action( 'vc_base_register_admin_css', 'levelup_vc_iconpicker_base_register_css' );


function levelup_vc_icon_element_fonts_enqueue( $font ) {
    switch ( $font ) {
        case 'etline':
            wp_enqueue_style('font-etline');
    }
}

function levelup_vc_iconpicker_editor_jscss( $font ) {
    wp_enqueue_style('font-etline');
}

add_action('vc_enqueue_font_icon_element', 'levelup_vc_icon_element_fonts_enqueue');
add_action('vc_backend_editor_enqueue_js_css', 'levelup_vc_iconpicker_editor_jscss');
add_action('vc_frontend_editor_enqueue_js_css', 'levelup_vc_iconpicker_editor_jscss');


function levelup_new_royalslider_add_custom_skin($skins) {
    $skins['rdySkin1'] = array(
        'label' => esc_html__('LEVELUP Skin (Dark)', 'LEVELUP'),
        'path' =>  get_template_directory_uri() . '/assets/css/royal-skins/royal-custom-skin1.css'
    );
    $skins['rdySkin2'] = array(
        'label' => esc_html__('LEVELUP Skin (Light)', 'LEVELUP'),
        'path' =>  get_template_directory_uri() . '/assets/css/royal-skins/royal-custom-skin2.css'
    );
    return $skins;
}
add_filter('new_royalslider_skins', 'levelup_new_royalslider_add_custom_skin', 10, 2);


if ( function_exists( 'is_plugin_active' ) ) {
    if ( ! is_plugin_active( 'levelup-core/levelup-core.php' ) ) {
        function levelup_core_notice() {

            if ( isset( $_GET['page'] ) && $_GET['page'] == 'tgmpa-install-plugins' && isset( $_GET['tgmpa-install'] ) && $_GET['tgmpa-install'] == 'install-plugin' ) {
                return;
            }

            $plugin_slug = 'levelup-core';
            $plugin_file = 'levelup-core/levelup-core.php';

            $parent_url = esc_url( add_query_arg(
                array(
                    'page'          => urlencode( TGM_Plugin_Activation::$instance->menu ),
                ),
                admin_url( TGM_Plugin_Activation::$instance->parent_slug )
            ) );

            $core_install = wp_nonce_url(
                add_query_arg(
                    array(
                        'plugin'        => $plugin_slug,
                        'tgmpa-install' => 'install-plugin',
                    ),
                    $parent_url
                ),
                'tgmpa-install',
                'tgmpa-nonce'
            );

            $core_activate = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'activate-plugin_' . $plugin_file );


            if ( ! function_exists( 'get_plugins' ) ) {
                require_once ABSPATH . 'wp-admin/includes/plugin.php';
            }

            $installed_plugins = get_plugins();
            $is_installed = ( ! empty( $installed_plugins[ 'levelup-core/levelup-core.php' ] ) );

            $notice_title = '';
            $notice_link = '';
            $is_active = is_plugin_active( $plugin_slug );

            if ( ! $is_active || ! $is_installed ) {

                if( ! $is_active && ! $is_installed ) {
                    $notice_title = esc_attr__('Install the LEVELUP Core','LEVELUP');
                    $notice_link = $core_install;
                } else {
                    $notice_title = esc_attr__('Activate the LEVELUP Core','LEVELUP');
                    $notice_link = $core_activate;
                }

                ?>
                <div class="notice error is-dismissible">
                    <p><?php esc_attr_e( 'In order to run LEVELUP Theme you need first to install the LEVELUP Core.', 'LEVELUP' ); ?></p>
                    <p><a class="button button-primary button-hero activate-levelup-core" href="<?php echo $notice_link; ?>" aria-label="Install the LEVELUP Core"><?php echo $notice_title; ?></a></p>
                </div>
                <?php

            }
        }
        add_action( 'admin_notices', 'levelup_core_notice' );
    }
}

remove_action( 'admin_menu', 'levelup_core_init_redux_menu' );


function levelup_core_update_notice() {

	if ( isset( $_GET['page'] )
	     && $_GET['page'] == 'tgmpa-install-plugins'
	     && ( isset( $_GET['tgmpa-install'] ) || isset( $_GET['tgmpa-update'] ) || ( isset( $_GET['plugin_status'] ) && $_GET['plugin_status'] == 'update' ) )
	) {
		return;
	}

	$plugin_slug = 'levelup-core';
	$plugin_file = 'levelup-core/levelup-core.php';

	/*$parent_url = esc_url( add_query_arg(
		array(
			'page'          => urlencode( TGM_Plugin_Activation::$instance->menu ),
		),
		admin_url( TGM_Plugin_Activation::$instance->parent_slug )
	) );

	$core_update = wp_nonce_url(
		add_query_arg(
			array(
				'plugin'        => $plugin_slug,
				'tgmpa-update' => 'update-plugin',
			),
			$parent_url
		),
		'tgmpa-update',
		'tgmpa-nonce'
	);*/

	$installed_version = TGM_Plugin_Activation::$instance->get_installed_version( $plugin_slug );
	$available_version = TGM_Plugin_Activation::$instance->does_plugin_have_update( $plugin_slug );

	$core_update = TGM_Plugin_Activation::$instance->get_tgmpa_status_url( 'update' )

	?>
	<div class="notice error is-core-update">
		<p><?php echo wp_kses( sprintf(__('Attention! Please update the plugin to latest version <span class="available">%s</span>.', 'LEVELUP'),  $available_version), array('span' => array('class' => array()))); ?></p>
		<p><?php echo wp_kses( sprintf(__('Currently you are using <span class="installed">%s</span> version of the plugin.', 'LEVELUP'),  $installed_version), array('span' => array('class' => array()))); ?></p>
		<p><?php esc_html_e('Otherwise it may cause problem in the theme work.', 'LEVELUP'); ?></p>

		<p><a class="button button-primary button-hero activate-levelup-core" href="<?php echo esc_url($core_update); ?>" aria-label="Update the LEVELUP Core">Update the LEVELUP Core</a></p>
	</div>
	<?php

}


function levelup_core_admin_init(){

	if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'levelup-core/levelup-core.php' )
	     && class_exists('TGM_Plugin_Activation') && TGM_Plugin_Activation::TGMPA_VERSION == '2.6.1' && TGM_Plugin_Activation::$instance->is_plugin_updatetable('levelup-core') ) {
		add_action( 'admin_notices', 'levelup_core_update_notice' );
	}

}

add_action( 'admin_init', 'levelup_core_admin_init' );


if ( ! function_exists( 'levelup_wbc_importer_before_content_import' ) ) {

	function levelup_wbc_importer_before_content_import( $data ) {
		$first_key = key($data);
		$theme = $data[$first_key]['title'];
		$directory = $data[$first_key]['directory'];

		if ( $directory == 'Main' || $directory == 'Ecommerce_Shop' ) {
			if( class_exists('WooCommerce') ) {

				$shop_thumbnail = array(
					'width' 	=> '180',
					'height'	=> '180',
					'crop'		=> 1
				);
				$shop_catalog = array(
					'width' 	=> '600',
					'height'	=> '840',
					'crop'		=> 1
				);
				$shop_single = array(
					'width' 	=> '600',
					'height'	=> '600',
					'crop'		=> 1
				);

				update_option( 'shop_thumbnail_image_size', $shop_thumbnail );
				update_option( 'shop_catalog_image_size', $shop_catalog );
				update_option( 'shop_single_image_size', $shop_single );

				add_image_size( 'shop_thumbnail', $shop_thumbnail['width'], $shop_thumbnail['height'], $shop_thumbnail['crop'] );
				add_image_size( 'shop_catalog', $shop_catalog['width'], $shop_catalog['height'], $shop_catalog['crop'] );
				add_image_size( 'shop_single', $shop_single['width'], $shop_single['height'], $shop_single['crop'] );
			}
		}

	}

	add_action('wbc_importer_before_content_import', 'levelup_wbc_importer_before_content_import');

}


if ( ! function_exists( 'levelup_wbc_importer_before_widget_import' ) ) {

	function levelup_wbc_importer_before_widget_import($data) {
		global $wpdb;

		$locations = get_theme_mod( 'nav_menu_locations' );
		$menus = wp_get_nav_menus();

		$first_key = key($data);
		$theme = $data[$first_key]['title'];
		$directory = $data[$first_key]['directory'];

		$shop_demo = false;
		$sidebar_exists = false;
		$revslider_exists = false;

		switch($directory) {
			case 'Main': // 0
				$shop_demo = true;
				$revslider_exists = true;
				$homepage_title = 'Home';
				$blogpage_title = 'Blog';

//				$main_menu = array( 'demos', 'portfolio', 'elements', 'shop', 'blog' );
//				foreach ($main_menu as $post_title) {
//					$post_id = $wpdb->get_var( 'SELECT ID FROM ' . esc_sql( $wpdb->posts ) . ' WHERE post_excerpt="' . esc_sql( $post_title ) . '" AND post_type="nav_menu_item" AND post_status="publish"' );
//					update_post_meta($post_id, '_menu_item_rdy_mega_menu_enabled', 1);
//				}

				break;
			case 'Law_Firm': // 4
				$revslider_exists = true;

				$homepage_title = 'About Us';
				$blogpage_title = 'Journal';

				break;
			case 'Photographer': //6
				$homepage_title = 'Life';

				break;
			case 'Fitness': // 10
				$revslider_exists = true;

				$homepage_title = 'Home';

				break;
			case 'Architectural_Bureau': // 11
				$revslider_exists = true;

				$homepage_title = 'Home';
				$blogpage_title = 'News';

				break;
			case 'Creative_Agency': // 12
				$homepage_title = 'Home';

				break;
			case 'Design_Boutique': // 13
				$homepage_title = 'Home';

				break;
			case 'Coaching': //15
				$revslider_exists = true;

				$homepage_title = 'Home';
				$blogpage_title = 'Blog';

				break;
			case 'Slides_Design_Agency': // 18
				$revslider_exists = true;

				$homepage_title = 'Home';

				break;
			case 'Slides_Creative_Design_Agency': // 9
				$homepage_title = 'Slides';

				break;
			case 'Slides_Photo_Agency': // 3
				$revslider_exists = true;

				$homepage_title = 'Projects';

				break;
			case 'Coming_Soon': // 19
				$homepage_title = 'Home';

				break;
			case 'Creative_Director_Graphic_Designer': // 5
				$homepage_title = 'Home';

				break;
			case 'Digital_Agency': // 1
				$homepage_title = 'Home.';
				$blogpage_title = 'Blog.';

				break;
			case 'Ecommerce_Shop': // shop1
				$shop_demo = true;
				$revslider_exists = true;

				$homepage_title = 'Home';
				$blogpage_title = 'Blog';

//				$main_menu = array( 'women', 'men', 'kids' );
//				foreach ($main_menu as $post_title) {
//					$post_id = $wpdb->get_var( 'SELECT ID FROM ' . esc_sql( $wpdb->posts ) . ' WHERE post_excerpt="' . esc_sql( $post_title ) . '" AND post_type="nav_menu_item" AND post_status="publish"' );
//					update_post_meta($post_id, '_menu_item_rdy_mega_menu_enabled', 1);
//				}

				break;
			case 'Freelancer': // 16
				$homepage_title = 'Home';

				break;
			case 'Award_Winning_Agency': // 2
				$homepage_title = 'Work';

				break;
			case 'Branding_Agency': // 7
				$homepage_title = 'Home';

				break;
			case 'Film_Promotion': // 8
				$homepage_title = 'Home';

				break;
			default:

		}

		if($menus) {

			foreach($menus as $menu) { // assign menus to theme locations

				if ( $directory === 'Main' ) { // 0
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Photographer' ) { // 6
					if ( $menu->name === 'menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Coaching' ) { // 15
					if ( $menu->name === 'Main menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Creative_Agency' ) { // 12
					if ( $menu->name === 'header_menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Architectural_Bureau' ) { // 11
					if ( $menu->name === 'menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Law_Firm' ) { // 4
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Fitness' ) { // 10
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Design_Boutique' ) { // 13
					if ( $menu->name === 'agency_menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Slides_Design_Agency' ) { // 18
					if ( $menu->name === 'menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Slides_Creative_Design_Agency' ) { // 9
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Slides_Photo_Agency' ) { // 3
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
					if ( $menu->name === 'Menu 2' ) {
						$locations['menu3'] = $menu->term_id;
					}
				}

				if ( $directory === 'Creative_Director_Graphic_Designer' ) { // 5
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Digital_Agency' ) { // 1
					if ( $menu->name === 'Menu_top' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Ecommerce_Shop' ) { // shop1
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Freelancer' ) { // 16
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Award_Winning_Agency' ) { // 2
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Branding_Agency' ) { // 7
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

				if ( $directory === 'Film_Promotion' ) { // 8
					if ( $menu->name === 'Menu' ) {
						$locations['menu1'] = $menu->term_id;
					}
				}

			}

		}

		set_theme_mod( 'nav_menu_locations', $locations );


		if ( $homepage_title ) {
			$homepage = get_page_by_title( $homepage_title );
			if ( isset( $homepage ) && $homepage->ID ) {
				update_option( 'show_on_front', 'page' );
				update_option( 'page_on_front', $homepage->ID ); // Front Page
			}
		}

		if ( $blogpage_title ) {
			$blog = get_page_by_title( $blogpage_title );
			if ( isset( $blog ) && $blog->ID ) {
				update_option( 'page_for_posts', $blog->ID );
			}
		}


		/* Import Woocommerce if WooCommerce Exists */
		if( class_exists('WooCommerce') && $shop_demo == true ) {
			// Set pages
			$woopages = array(
				'woocommerce_shop_page_id' => 'Shop',
				'woocommerce_cart_page_id' => 'Cart',
				'woocommerce_checkout_page_id' => 'Checkout',
				'woocommerce_pay_page_id' => 'Checkout &#8594; Pay',
				'woocommerce_thanks_page_id' => 'Order Received',
				'woocommerce_myaccount_page_id' => 'My Account',
				'woocommerce_edit_address_page_id' => 'Edit My Address',
				'woocommerce_view_order_page_id' => 'View Order',
				'woocommerce_change_password_page_id' => 'Change Password',
				'woocommerce_logout_page_id' => 'Logout',
				'woocommerce_lost_password_page_id' => 'Lost Password'
			);
			foreach($woopages as $woo_page_name => $woo_page_title) {
				$woopage = get_page_by_title( $woo_page_title );
				if(isset( $woopage ) && $woopage->ID) {
					update_option($woo_page_name, $woopage->ID); // Front Page
				}
			}

			// We no longer need to install pages
			delete_option( '_wc_needs_pages' );
			delete_transient( '_wc_activation_redirect' );

			// Flush rules after install
			flush_rewrite_rules();
		}


		// Import Revslider
		if( class_exists('UniteFunctionsRev') && $revslider_exists === true ) { // if revslider is activated
			$rev_directory = LEVELUP_BASE_DIR . '/inc/demo-data/' . esc_attr( $directory ) . '/revsliders/';

			foreach( glob( $rev_directory . '*.zip' ) as $filename ) { // get all files from revsliders data dir
				$filename = basename($filename);
				$rev_files[] = $rev_directory . $filename;
			}

			foreach( $rev_files as $rev_file ) {
				$slider   = new RevSlider();
				$response = $slider->importSliderFromPost( $updateAnim = true, $updateStatic = true, $exactfilepath = $rev_file, $is_template = false, $single_slide = false, $updateNavigation = true );
			}

		}

	}

	add_action('wbc_importer_before_widget_import', 'levelup_wbc_importer_before_widget_import');

}


function levelup_pre_set_widget( $sidebar, $name, $args = array() ) { // @todo remove
	if ( ! $sidebars = get_option( 'sidebars_widgets' ) ) {
		$sidebars = array();
	}

	if ( ! isset( $sidebars[ $sidebar ] ) ) {
		$sidebars[ $sidebar ] = array();
	}

	if ( $widget_opts = get_option( "widget_$name" ) ) {
		ksort( $widget_opts );
		end( $widget_opts );
		$insert_id = key( $widget_opts );
	} else {
		$widget_opts = array( '_multiwidget' => 1 );
		$insert_id = 0;
	}

	$widget_opts[ ++$insert_id ] = $args;
	$sidebars[ $sidebar ][] = "$name-$insert_id";

	update_option( 'sidebars_widgets', $sidebars );
	update_option( "widget_$name", $widget_opts );
}


function levelup_find_menu_by_slug( $slug ) { // @todo remove
	$menus = wp_get_nav_menus();

	foreach ( $menus as $menu ) {
		if ( $menu->slug == $slug ) {
			return $menu->term_id;
		}
	}

	return false;
}


function levelup_mime_types( $mimes ) {
//	$mimes['svg'] = 'image/svg+xml';

    $mimes['ttf']  = 'font/ttf';
    $mimes['woff'] = 'font/woff';
    $mimes['woff2'] = 'font/woff2';
    $mimes['svg']  = 'font/svg';
    $mimes['eot']  = 'font/eot';

	return $mimes;
}

add_filter( 'upload_mimes', 'levelup_mime_types' );


function levelup_wp_check_filetype_and_ext($filetype_ext_data, $file, $filename, $mimes) {
	if ( substr($filename, -4) === '.svg' ) {
		$filetype_ext_data['ext'] = 'svg';
		$filetype_ext_data['type'] = 'image/svg+xml';
	}
	if ( substr($filename, -4) === '.ttf' ) {
		$filetype_ext_data['ext'] = 'ttf';
		$filetype_ext_data['type'] = 'font/ttf';
	}
	if ( substr($filename, -4) === '.woff' ) {
		$filetype_ext_data['ext'] = 'woff';
		$filetype_ext_data['type'] = 'font/woff';
	}
	if ( substr($filename, -4) === '.woff2' ) {
		$filetype_ext_data['ext'] = 'woff2';
		$filetype_ext_data['type'] = 'font/woff2';
	}
	if ( substr($filename, -4) === '.eot' ) {
		$filetype_ext_data['ext'] = 'eot';
		$filetype_ext_data['type'] = 'font/eot';
	}

	return $filetype_ext_data;
}

add_filter( 'wp_check_filetype_and_ext', 'levelup_wp_check_filetype_and_ext', 100, 4 );


if ( ! function_exists( 'levelup_autoload_components_list' ) ) {

    function levelup_autoload_components_list($components){
        unset($components['vendors/cf7.php']);

        return $components;
    }

    add_filter( 'vc_autoload_components_list', 'levelup_autoload_components_list' );
}


function levelup_get_page_title_custom( $title ) {
	if ( is_post_type_archive('costom_post_type_slug') ) {
		return 'Custom Post Type Title';
	}

	return $title;
}
add_filter( 'levelup_get_page_title', 'levelup_get_page_title_custom' );

Zerion Mini Shell 1.0