start_visual_composer(); } /** * Add theme support and register theme support */ public function theme_setup() { add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 825, 510, true ); add_image_size('blog-thumb', 370, 220, true); add_image_size('testimonials-thumb', 120, 120, true); register_nav_menus( array( 'main_menu' => __( 'Primary Menu', 'unik' ), ) ); register_nav_menus( array( 'footer_menu' => __( 'Footer Menu', 'unik' ), ) ); add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) ); add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'audio' ) ); } /** * Favicon Picker */ public function theme_favicon() { $favicon_pat = ''; $favicon = _go('favicon_link') ? _go('favicon_link') : TT_THEME_URI . '/images/favicon.ico'; echo "\r\n" . sprintf($favicon_pat, $favicon) . "\r\n"; } /** * Enqueue Fonts, Styles and JS (front-end) */ public function enqueue_goods() { $protocol = is_ssl() ? 'https' : 'http'; $gfont_changer = array( _go('global_typo_font'), _go('links_settings_font'), _go('logo_text_font'), _go('headings_settings_font') ); $default_css = array( 'base-font' => "$protocol://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800|Varela", 'main-style' => TT_THEME_URI . "/css/screen.css", 'heme-style' => get_stylesheet_uri() ); // Google font picker foreach($gfont_changer as $font){ $font = str_replace(' ', '+', $font); if($font !== '') { wp_enqueue_style( 'tt-custom-font-' . $font, "$protocol://fonts.googleapis.com/css?family=$font"); } } // Main CSS and Fonts foreach ($default_css as $k => $css) { wp_enqueue_style( 'tt-' . $k, $css); } if ( is_singular() ) { wp_enqueue_script( "comment-reply" ); } } public function request_js() { wp_enqueue_script('require.js', TT_THEME_URI . '/js/components/require.js', array('jquery'), false, true); //wp_enqueue_script('main.js', TT_THEME_URI . '/js/options.js', array('jquery'), false, true); $custom_js = _go('custom_js'); // Transfer data to js $send_js = array( 'dirUri' => get_template_directory_uri(), ); wp_localize_script('require.js', 'themeOptions', $send_js); } public function add_id_to_script($tag, $handle){ if( strpos($tag, '/js/components/require') ) { return ''; } else { return $tag; } } /** * Enqueue Fonts, Styles and JS (admin) */ public function admin_enqueue_goods($hook) { if ( $hook == 'post-new.php' || $hook == 'post.php' ) { wp_enqueue_style( 'wp-color-picker' ); } wp_enqueue_style('tt-admin', TT_THEME_URI . '/css/admin/admin.css'); wp_enqueue_script('admin.js', TT_THEME_URI . '/js/admin/admin.js', array('jquery'), false, true); } public function last_script() { global $wp_scripts; if(!empty($wp_scripts->registered['require.js']->src)) { printf("", $wp_scripts->registered['require.js']->src, TT_THEME_URI . '/js/options' ); } } /** * Theme custom CSS */ public function theme_custom_css() { // Main styles switches $custom_css = (_go('layout_style') == 'Boxed') ? '.main-container {max-width: 1300px; margin: 0 auto; overflow: hidden} ' : ''; $custom_css .= (_go('body_background') && (_go('body_color') || _go('body_background_repeat') || _go('body_background_position'))) ? 'body {' : ''; $custom_css .= (_go('body_background')) ? 'background-image: url('._go('body_background').'); ' : ''; $custom_css .= (_go('body_color')) ? 'background-color: '._go('body_color').'; ' : ''; $custom_css .= (_go('body_background') && _go('body_background_repeat')) ? 'background-repeat: '.strtolower(_go('body_background_repeat')).'; ' : ''; $custom_css .= ( _go('body_background') && _go('body_background_position')) ? 'background-attachment: '.strtolower(_go('body_background_position')).'; ' : ''; $custom_css .= (_go('body_background') && (_go('body_color') || _go('body_background_repeat') || _go('body_background_position'))) ? '}' : ''; // Main styles switches $custom_css .= (_go('header_color')) ? '.header-navbar {background-color: '._go('header_color').' !important;}' : ''; // Logo text $custom_css .= (_go('logo_text') && (_go('logo_text_color') || _go('logo_text_font') || _go('logo_text_size'))) ? '.logo-text{' : ''; $custom_css .= (_go('logo_text') && _go('logo_text_color')) ? 'color: '._go('logo_text_color').';' : ''; $custom_css .= (_go('logo_text') && _go('logo_text_font')) ? 'font-family: '._go('logo_text_font').';' : ''; $custom_css .= (_go('logo_text') && _go('logo_text_size')) ? 'font-size: '._go('logo_text_size').'px;' : ''; $custom_css .= (_go('logo_text') && (_go('logo_text_color') || _go('logo_text_font') || _go('logo_text_size'))) ? '}' : ''; // Page meta $page_meta = $this->get_custom_meta('page_meta'); $custom_css .= !empty($page_meta->bg_color)? '.box-intro-page {background-color: '.$page_meta->bg_color.';}' : ''; $custom_css .= !empty($page_meta->icon_color)? '.page-title-color {color: '.$page_meta->icon_color.';}' : ''; $custom_css .= (_go('canvas_color')) ? sprintf('.main-container { background: %s;}', _go('canvas_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('.bg-alpha, .vc_btn-alpha, .bg-alpha-hover:hover, .timeline-item > h6:before, .air-nav .current, .tabs-nav a:after, .featured-icon figure > a:hover, .big-tabs:before, .toggle-item input[type="radio"]:checked + h6, .sort-by > ul input[type=radio] + span:before, .portfolio-filters > ul > li label input:checked + span:hover, button.button-outline:hover, .portfolio-filters > ul > li label input:checked + span {background: %s !important;}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('body .text-alpha, .loop-facts .featured-icon:hover + *, .portfolio-filters > ul > li label input:checked + span:after, input[type=text]:focus + span, input[type=email]:focus + span, input[type=search]:focus + span, textarea:focus + span, .big-tabs-content:after, .social-networks > li a:hover i, .social-networks > li a:focus i, .main-nav > ul > li ul li a, .active-big-tab > .tab-item > div {color: %s !important;}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('a:hover {color: %s}', _go('primary_color')) : ''; $custom_css .= (_go('primary_color')) ? sprintf('.big-tabs, .portfolio-filters, input[type=text]:focus, input[type=email]:focus, input[type=search]:focus, textarea:focus {border-bottom-color: %s !important;}', _go('primary_color')) : ''; $custom_css .= (_go('secondary_color')) ? sprintf('.bg-beta {background: %s !important;}', _go('secondary_color')) : ''; $custom_css .= (_go('secondary_color')) ? sprintf('.text-beta {color: %s !important;}', _go('secondary_color')) : ''; $custom_css .= (_go('global_typo_color')) ? sprintf('body {color: %s;}', _go('global_typo_color')) : ''; $custom_css .= (_go('global_typo_size')) ? sprintf('body {font-size: %spx;}', _go('global_typo_size')) : ''; $custom_css .= (_go('global_typo_font')) ? sprintf('body {font-family: %s;}', _go('global_typo_font')) : ''; $custom_css .= (_go('links_settings_color')) ? sprintf('a {color: %s;}', _go('links_settings_color')) : ''; $custom_css .= (_go('links_settings_size')) ? sprintf('a {font-size: %spx;}', _go('links_settings_size')) : ''; $custom_css .= (_go('links_settings_font')) ? sprintf('a {font-family: %s;}', _go('links_settings_font')) : ''; $custom_css .= (_go('headings_settings_color')) ? sprintf('h1, h2, h3, h4, h5, h6 {color: %s;}', _go('headings_settings_color')) : ''; $custom_css .= (_go('headings_settings_font')) ? sprintf('h1, h2, h3, h4, h5, h6 {font-family: %s;}', _go('headings_settings_font')) : ''; $custom_css .= (_go('headings_one_settings_size')) ? sprintf('h1 {font-size: %spx;}', _go('headings_one_settings_size')) : ''; $custom_css .= (_go('headings_two_settings_size')) ? sprintf('h2 {font-size: %spx;}', _go('headings_two_settings_size')) : ''; $custom_css .= (_go('headings_three_settings_size')) ? sprintf('h3 {font-size: %spx;}', _go('headings_three_settings_size')) : ''; $custom_css .= (_go('headings_four_settings_size')) ? sprintf('h4 {font-size: %spx;}', _go('headings_four_settings_size')) : ''; $custom_css .= (_go('headings_five_settings_size')) ? sprintf('h5 {font-size: %spx;}', _go('headings_five_settings_size')) : ''; $custom_css .= (_go('headings_six_settings_size')) ? sprintf('h6 {font-size: %spx;}', _go('headings_six_settings_size')) : ''; $custom_css .= (_go('custom_css')) ? _go('custom_css') : ''; wp_add_inline_style('tt-main-style', $custom_css); } /** * Generate navigation */ public function theme_navigation($menu_name, $css_class=null, $menu=null) { $defaults = array( 'theme_location' => strtolower(str_replace(" ", "_", $menu_name)), 'menu' => $menu, 'container' => false, 'container_class' => '', 'container_id' => '', 'menu_class' => $css_class, 'menu_id' => '', 'echo' => false, 'fallback_cb' => array($this, 'menu_callback'), 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '', 'depth' => 0, 'walker' => '' ); return wp_nav_menu( $defaults ); } /** * Menu callback (default input) */ public function menu_callback($class = '') { $defaults = array( 'authors' => '', 'child_of' => 0, 'date_format' => get_option('date_format'), 'depth' => 0, 'echo' => 0, 'exclude' => '', 'include' => '', 'link_after' => '', 'link_before' => '', 'post_type' => 'page', 'post_status' => 'publish', 'show_date' => '', 'sort_column' => 'menu_order, post_title', 'title_li' => '', 'walker' => '' ); return sprintf('', $class['menu_class'], wp_list_pages($defaults)); } /** * Lazy images */ public function lazy_img($img, $alt=null, $width=null, $height=null) { if(is_array($img)) { $img = $img[0]; $width = $img[1]; $height = $img[2]; } $width = !empty($width) ? sprintf('width="%s"', $width) : ''; $height = !empty($height) ? sprintf('height="%s"', $height) : ''; $holder = get_template_directory_uri() . '/images/load.svg'; return sprintf('%s', $holder, $img, $alt, $width, $height); } /** * Main Logo */ public function theme_logo($logo_id = false) { $logo_url = _go('logo_image'); $logo_text = _go('logo_text'); $pattern = '
%s
'; if(!empty($logo_id)) { $logo_url = wp_get_attachment_url( $logo_id); } if(!empty($logo_text)) { return sprintf($pattern, esc_url( home_url( '/' ) ), '' . $logo_text . ''); } else { if(!empty($logo_url)) { $logo_image = sprintf('%s', get_bloginfo('name'), $logo_url); } else { $logo_image = sprintf('%s', get_bloginfo('name'), TT_THEME_URI . '/images/logo.png'); } return sprintf($pattern, esc_url( home_url( '/' ) ), $logo_image); } } /** * Helper to invoke template views */ public function tt_view($name = null, array $params = array(), $folder=false) { global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; do_action("get_template_part_tt", 'tt', $name); $templates = array(); if (isset($name)) { $template_container = isset($folder) ? 'templates/'.$folder : 'templates'; $templates[] = $template_container."/tt-{$name}.php"; } $_template_file = locate_template($templates, false, false); if (is_array($wp_query->query_vars)) { extract($wp_query->query_vars, EXTR_SKIP); } extract($params, EXTR_SKIP); require($_template_file); } /** * Build class attribute */ private function class_attr($class = null) { $pattern = 'class="%s"'; if(isset($class)) { return sprintf($pattern, $class); } } /** * Build breadcrumbs */ private function breadcrumbs() { global $post; $links = array(); $meta = $this->get_custom_meta('page_meta'); if(!empty($meta->hide_breadcrumbs) || is_404()) { return; } if(is_home()) { $page_id = get_option( 'page_for_posts' ); $links[] = get_the_title($page_id); } else if(is_singular('post')) { $page_id = get_option( 'page_for_posts' ); ($page_id !== '0') ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = get_the_title(); } else if(is_tag()) { $page_id = get_option( 'page_for_posts' ); ($page_id !== '0') ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = single_tag_title('', false); } else if(is_category()) { $page_id = get_option( 'page_for_posts' ); ($page_id !== '0') ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = single_cat_title("", false); } else if(is_archive()) { $page_id = get_option( 'page_for_posts' ); ($page_id !== '0') ? $links[get_permalink($page_id)] = get_the_title($page_id) : ''; $links[] = get_the_archive_title(); } else if(is_search()) { $page_id = get_option( 'page_for_posts' ); $links[] = __('Search', 'unik'); } else if(is_page()) { if($post->post_parent > 0) { $page_id = $post->post_parent; if($page_id !== (int) get_option('page_on_front')) { $links[get_permalink($page_id)] = get_the_title($page_id); } } $links[] = get_the_title(); } $defaults = array( 'links' => $links ); ob_start(); $this->tt_view('breadcrumbs', $defaults); return ob_get_clean(); } /** * Build header */ public function header_view() { $defaults = array( 'logo_class' => $this->class_attr('col-sm-2 col-xs-4'), 'navigation_class' => $this->class_attr('col-sm-10 col-xs-8'), 'logo' => $this->theme_logo(), 'navigation' => $this->theme_navigation('main_menu', 'inline-list uppercase align-right'), 'breadcrumbs' => $this->breadcrumbs() ); // Hide main header $page_content = get_queried_object(); $page_content = !empty($page_content->post_content) ? $page_content->post_content : ''; if(!empty($page_content) && has_shortcode($page_content, 'tt_header')) { return; } $nav_option = strtolower(_go('navigation')); switch ($nav_option) { case 'regular': $nav_settings = ''; break; case 'sticky': $nav_settings = 'data-sticky="true" data-nav-scroll="true"'; break; case 'sticky hide on scroll': $nav_settings = 'data-sticky="true"'; break; default: $nav_settings = 'data-sticky="true"'; break; } $defaults['nav_settings'] = $nav_settings; $this->tt_view('header', $defaults); } /** * Build footer menu section */ public function footer_content() { $page_meta = $this->get_custom_meta('page_meta'); if(!empty($page_meta->hide_footer)) { return ''; } $footer_social = $this-> global_socials(); if(!empty($footer_social)) { $footer_socials_pat = ''; echo sprintf($footer_socials_pat, $footer_social); } if(has_nav_menu('footer_menu')) { $menu_footer_pat = ''; echo sprintf($menu_footer_pat, $this->theme_navigation('footer_menu', 'inline-list footer-menu align-center uppercase')); } } /** * Global social networks */ public function global_socials() { $networks = array( '182' => 'facebook', '510' => 'twitter', '298' => 'linkedin', '397' => 'rss', '158' => 'dribbble', '244' => 'google' ); $social_buttons = ''; foreach ($networks as $icon => $item) { $network = _go('social_platforms_'.$item); if(!empty($network)) { $social_buttons .= sprintf('
  • ', $item, _go('social_platforms_'.$item), $icon); } } if(!empty($social_buttons)) { return sprintf('', $social_buttons); } } /** * Build view for page meta */ public function page_meta_view() { global $post; if(is_home() || is_singular('post') || is_tag() || is_archive()) { $id = get_option( 'page_for_posts' ); } else if(isset($post->ID)) { $id = $post->ID; } else { return; } $page_meta = $this->get_custom_meta('page_meta'); $blog_meta = $this->get_custom_meta('blog_meta'); if(!empty($blog_meta->post_image)) { $thumb_id = $blog_meta->post_image; $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true); $thumb_url = (!empty($thumb_url_array[0])) ? 'data-box-img="'.$thumb_url_array[0].'"' : ''; } else { $thumb_id = get_post_thumbnail_id($id); $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'full', true); $thumb_url = (!empty($thumb_url_array[0]) && has_post_thumbnail($id)) ? 'data-box-img="'.$thumb_url_array[0].'"' : ''; } if(is_archive()) { $alt_title = !empty($page_meta->description) ? sprintf('

    %s

    ', $page_meta->description) : sprintf('

    %s

    ', get_the_archive_title()); } else if(is_search()) { $alt_title = !empty($page_meta->description) ? sprintf('

    %s

    ', $page_meta->description) : sprintf( __( '

    Results for: %s

    ', 'unik' ), get_search_query() ); } else { $alt_title = !empty($page_meta->description) ? sprintf('

    %s

    ', $page_meta->description) : sprintf('

    %s

    ', get_the_title($id)); } $page_icon = !empty($page_meta->icon) ? sprintf(' ', $page_meta->icon) : ''; $defaults = array( 'thumbnail_url' => $thumb_url, 'alt_title' => $alt_title, 'page_icon' => $page_icon ); if(empty($page_meta->hide_meta)) { $this->tt_view('page-meta', $defaults); } } /** * Filter content by iframes */ public function filter_content($content) { $post_format = get_post_format(); if((is_home() || is_front_page()) && !is_singular()) { $content = preg_replace( '//is', '', $content ); return $content; } else if(is_singular('post') && $post_format === 'gallery' ) { $gallery = $this->get_content_shortcode('gallery', $content); $gallery = !empty($gallery[0][0]) ? $gallery[0][0] : ''; $content = str_replace($gallery, '', $content); return $content; } else { return $content; } } /** * Build content for different page instance */ public function create_pages_contents() { global $post; if(is_home() || is_singular('post') || is_tag() || is_category() || is_archive() || is_search()) { $thumb_id = get_post_thumbnail_id($post->ID); $thumb_size = is_singular('post') ? 'full' : 'blog-thumb'; $thumb_array = wp_get_attachment_image_src($thumb_id, $thumb_size, true); $alt_meta = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); $avatar = get_avatar(get_the_author_meta( 'ID' ), 50); $post_format = get_post_format(); $format_pat = '
    '; switch ($post_format) { case 'aside': $post_format_icon = sprintf($format_pat, '347'); break; case 'image': $post_format_icon = sprintf($format_pat, '265'); break; case 'video': $post_format_icon = sprintf($format_pat, '208'); break; case 'quote': $post_format_icon = sprintf($format_pat, '375'); break; case 'link': $post_format_icon = sprintf($format_pat, '296'); break; case 'gallery': $post_format_icon = sprintf($format_pat, '222'); break; case 'audio': $post_format_icon = sprintf($format_pat, '332'); break; default: $post_format_icon = ''; break; } $gallery = ''; if(is_singular('post')) { $post_format_icon = ''; } if( is_singular('post') && $post_format === 'gallery' ) { $gallery = get_post_gallery( get_the_ID(), false ); } $defaults = array( 'post_thumbnail' => $this->lazy_img($thumb_array[0], $alt_meta, $thumb_array[1], $thumb_array[2]), 'author_avatar' => $avatar, 'post_share' => '', 'post_format' => $post_format, 'post_format_icon' => $post_format_icon, 'gallery' => $gallery ); $format = get_post_format(); $posts_format = !empty($format) ? '-'.$format : ''; $this->tt_view('blog-loop', $defaults); } else { echo '
    '; the_content(); echo '
    '; } } /** * Get all kind of posts */ public function tt_get_post($post_type = 'post', $config = false) { $args = array( 'posts_per_page' => -1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => $post_type, 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true ); if(!empty($config)) { $args = wp_parse_args( $config, $args ); } return get_posts($args); } /** * Before page hook */ public function before_pages() { if(is_home() || is_singular('post') || is_tag() || is_category() || is_archive() || is_search()) { echo '
    '; if(is_active_sidebar('sidebar-1') && is_active_sidebar('sidebar-2')) { echo '
    '; echo '
    '; } else if(is_active_sidebar('sidebar-2')) { echo '
    '; echo '
    '; } else if(is_active_sidebar('sidebar-1')) { echo '
    '; } else { echo '
    '; } echo '
      '; } } /** * After page hook */ public function after_pages() { if(is_home() || is_singular('post') || is_tag() || is_category() || is_archive() || is_search()) { echo sprintf('
    %s', $this->pagination_links()); if(is_singular('post')) { the_tags( '
    • '.__('Tags:', 'unik').'
    • ', '
    • ', '
    ' ); comments_template(); } echo '
    '; if(is_active_sidebar('sidebar-1')) { echo '
    '; } echo '
    '; } } /** * Build pagination links */ public function pagination_links() { $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; $pagenum_link = html_entity_decode( get_pagenum_link() ); $query_args = array(); $url_parts = explode( '?', $pagenum_link ); if ( isset( $url_parts[1] ) ) { wp_parse_str( $url_parts[1], $query_args ); } $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%'; // Set up paginated links. $links = paginate_links( array( 'base' => $pagenum_link, 'format' => $format, 'total' => $GLOBALS['wp_query']->max_num_pages, 'current' => $paged, 'mid_size' => 1, 'add_args' => array_map( 'urlencode', $query_args ), 'prev_text' => '', 'next_text' => '', 'type' => 'array', ) ); $pagination_pat = '
    '; return !empty($links) ? sprintf($pagination_pat, join("\n\t
  • ", $links)) : ''; } /** * Comments pagination */ public function comments_pagination() { $default = array( 'echo' => false, 'prev_text' => '', 'next_text' => '' ); $pag_links = trim(preg_replace('/\s+/', ' ', paginate_comments_links($default))); if($pag_links) { $pag_links = str_replace('', '
  • ', $pag_links); $pag_links = str_replace('> ", "current bg-alpha'>", $pag_links); $pag_links = str_replace('', '
  • ', $pag_links); $pag_links = sprintf('
  • %s
  • ', $pag_links); $pag_links = str_replace('
  • ', '', $pag_links); echo sprintf('
    ', $pag_links); } } /** * Generate sidebars */ public function sidebar_init() { register_sidebar( array( 'name' => __( 'Main left sidebar', 'unik' ), 'id' => 'sidebar-1', 'description' => __( 'Use this sidebar for left side widgets', 'unik' ), 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '', 'after_title' => '', )); register_sidebar( array( 'name' => __( 'Main right sidebar', 'unik' ), 'id' => 'sidebar-2', 'description' => __( 'Use this sidebar for right side widgets', 'unik' ), 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '', 'after_title' => '', )); } /** * Separate title and widget content */ public function filter_widget_title($title, $instance, $id) { $class = ($id !== 'search') ? 'widget-content style-alpha' : ''; if(!empty($title)) { return sprintf('
    %s
    ', $title, $class); } else { return sprintf('
    ', $class); } } /** * Make better default widgets */ public function better_sidebr($sidebar_name) { add_filter( 'widget_title', array($this, 'filter_widget_title'), 10, 3 ); ob_start(); dynamic_sidebar($sidebar_name); $sidebar_content = ob_get_clean(); $sidebar_content = str_replace('
      ', '
        ', $sidebar_content); $sidebar_content = str_replace('', ' ', $sidebar_content); echo balanceTags($sidebar_content); remove_filter('widget_title', array($this, 'filter_widget_title'), 10, 3 ); } /** * Enable Visual Composer */ public function start_visual_composer() { if( class_exists('Vc_Manager') ) { vc_set_shortcodes_templates_dir( TEMPLATEPATH . '/theme_config/vc_shortcodes' ); include_once( TEMPLATEPATH . '/theme_config/vc_shortcodes/rewrite_map.php' ); } } /** * Detect shortcode */ public function detect_shortcode($shortcode = null, $content = null) { $pattern = get_shortcode_regex(); if ( preg_match_all( '/'. $pattern .'/s', $content, $matches ) && array_key_exists( 2, $matches ) && in_array( $shortcode, $matches[2] ) ) { return true; } } /** * Return shortcode from content */ public function get_content_shortcode($shortcode, $content) { $pattern = get_shortcode_regex(); preg_match_all( '/'. $pattern .'/s', $content, $matches ); return $matches; } /** * Create custom meta box */ public function generate_custom_meta() { $meta = new GenerateCustomMeta(); $meta->add_meta_box('page_meta', array( 'post_type' => array('page'), 'title' => __('Page meta', 'unik'), 'position' => 'side', 'fields' => array( 'bg_color' => array('color',__('Section background', 'unik')), 'description' => array('text',__('Page alternative title', 'unik')), 'icon' => array('icon',__('Selected icon: ', 'unik')), 'icon_color' => array('color',__('Icon color', 'unik')), 'hide_meta' => array('checkbox',__('Hide page meta', 'unik')), 'hide_footer' => array('checkbox',__('Hide main footer', 'unik')), 'hide_breadcrumbs' => array('checkbox',__('Hide breadcrumbs', 'unik')) ) )); $meta->add_meta_box('blog_meta', array( 'post_type' => array('post'), 'title' => __('Add page image', 'unik'), 'position' => 'side', 'fields' => array( 'post_image' => array('image',__('This image will appear at the top of sigle post.', 'unik')), ) )); } /** * Get custom meta box */ public function get_custom_meta($meta) { global $post; if(is_front_page()) { $id = get_option('page_on_front'); } else if(is_home() || is_singular('post')) { $id = get_option( 'page_for_posts' ); ($id === '0') ? $id = $post->ID : ''; } else if(isset($post->ID)) { $id = $post->ID; } else { return; } $custom_meta = get_post_meta($id, $meta); if(!empty($custom_meta)) return (object) $custom_meta[0]; } /** * Build search form */ public function filter_search_form($form) { $form = ''; return sprintf($form, esc_url(home_url( '/' )), get_search_query(), __('Search blog', 'unik')); } /** * Build comments feed */ public function comments() { $args = array( 'walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => array($this, 'comments_callback'), 'end-callback' => null, 'type' => 'all', 'reply_text' => 'Reply ', 'page' => '', 'per_page' => '', 'avatar_size' => 60, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => 'html5', //or html5 @since 3.6 'short_ping' => true // @since 3.6 ); echo '
          '; wp_list_comments($args); echo '
        '; } /** * Comments callbeack */ public function 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'; } $reply_url = get_comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); echo sprintf('<%s id="comment-%s" class="%s">', $tag, get_comment_ID(), ''); echo '
        '; echo sprintf('
        %s
        ', get_avatar( $comment, $args['avatar_size'] , false, 'avatar')); echo '
        '; if ($comment->comment_approved == '0') { _e('Your comment is awaiting moderation', 'unik'); } comment_text(); echo '
          '; echo get_comment_author_url() ? sprintf('
        1. %s
        2. ', get_comment_author_url(), get_comment_author()) : sprintf('
        3. %s
        4. ', get_comment_author()); echo sprintf('
        5. %s, %s
        6. ', get_comment_date(), get_comment_time()); echo !empty($reply_url) ? sprintf('
        7. %s
        8. ', $reply_url) : ''; edit_comment_link(__('Edit', 'unik'),'
        9. ','
        10. ' ); echo '
        '; echo '
        '; } /** * Contact form */ public function tt_contact_form () { $receiver_mail = is_email(base64_decode($_POST[ 'recivier' ])) ? base64_decode($_POST[ 'recivier' ]) : get_option('admin_email'); $mail_title = ( ! empty( $_POST[ 'subject' ] )) ? $_POST[ 'name' ] . __(' from ', 'unik') . $_POST[ 'subject' ] : ' '; /* SECTION II - CODE */ if ( !empty( $_POST[ 'name' ] ) && !empty( $_POST [ 'email' ] ) && !empty( $_POST [ 'message' ] ) ) { $email = $_POST[ 'email' ]; $message = $_POST[ 'message' ]; $message = wordwrap( $message, 70, "\r\n" ); $subject = $mail_title; $header = __('From: ', 'unik') . $_POST[ 'name' ] . "\r\n"; $header .= __('Reply-To: ', 'unik') . $email; if ( wp_mail( $receiver_mail, $subject, $message, $header ) ) $result = __('Message successfully sent.', 'unik'); else $result = __('Message could not be sent.', 'unik'); } else { $result = __('Please fill all the fields in the form.', 'unik'); } die($result); } /** * Comment form */ public function comment_form() { $user = wp_get_current_user(); $user_identity = $user->exists() ? $user->display_name : ''; $fields = array( 'author' => '

        ' . __( 'Name', 'unik' ) . '

        ', 'email' => '

        ' . __( 'E-mail', 'unik' ) . '

        ', 'url' => '

        ' . __( 'URL', 'unik' ) . '

        ' ); $comment_field = '

        '.__('Message', 'unik').'

        '; $must_log_in = '

        ' . sprintf( __( 'Logged in as %2$s. Log out?', 'unik'), get_edit_user_link(), $user_identity, wp_logout_url() ) . '

        '; $logged_in_as = ''; $comment_notes_before = '

        ' . __( 'If you want to share your opinion, leave a comment.', 'unik' ) . '

        '; $comment_notes_before = ''; $comment_notes_after = '

        ' . __( 'You may use these HTML tags and attributes:' , 'unik') . '

        ' . allowed_tags() . '
        ' . '
        '; $comment_notes_after = ''; $id_form = 'commentform'; $id_submit = 'comment-submit'; $title_reply = ' '.__( 'Leave a comment', 'unik' ); $title_reply_to = ' '.__( 'Leave a comment to %s', 'unik' ); $cancel_reply_link = __( 'Cancel reply', 'unik' ); $label_submit = 'a'; $format = 'html5'; $args = array( 'fields' => apply_filters( 'comment_form_default_fields', $fields ), 'comment_field' => $comment_field, 'must_log_in' => $must_log_in, 'logged_in_as' => $logged_in_as, 'comment_notes_before' => $comment_notes_before, 'comment_notes_after' => $comment_notes_after, 'id_form' => $id_form, 'id_submit' => $id_submit, 'title_reply' => $title_reply, 'title_reply_to' => $title_reply_to, 'cancel_reply_link' => $cancel_reply_link, 'label_submit' => $label_submit, 'format' => $format ); if(have_comments()) { $return_btn = ''; } else { $return_btn = ''; } ob_start(); comment_form($args); $form = str_replace('class="comment-form"','class="comment-form slim-form full-inputs row"',ob_get_clean()); echo balanceTags($form); } function theme_custom_js() { $custom_js = _go( 'custom_js' ); if( $custom_js ) { echo sprintf( '', $custom_js ); } } } global $tt_theme; $tt_theme = new Unik();