Advertisement
jegtheme

init-register.php

May 21st, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * - Register Menu Option
  5.  * - register sidebar
  6.  * - Register font on head section
  7.  * - set content width
  8.  *
  9.  * @author Jegbagus
  10.  */
  11.  
  12. // Add Theme Support for menu & automatic feed
  13. add_theme_support( 'menus' );
  14. add_theme_support( 'automatic-feed-links' );
  15.  
  16. // Locale & Translation
  17. load_theme_textdomain( 'jegtheme' , get_template_directory()  . '/lang' );
  18.  
  19. // Register Menu
  20. if(function_exists('register_nav_menu')):  
  21.    
  22.     // centered menu disabled, menu go to right
  23.     if (j_get_option('centered_menu', 1)) :
  24.         register_nav_menu( 'top_left_menu',     __( 'Top Left Menu' , 'jegtheme' ));
  25.         register_nav_menu( 'top_right_menu' ,   __( 'Top Right Menu'    , 'jegtheme' ));
  26.         register_nav_menu( 'mobile_menu'    ,   __( 'Mobile Menu'   , 'jegtheme' ));
  27.     else : 
  28.         register_nav_menu( 'top_left_menu',     __( 'Top  Menu' , 'jegtheme' ));
  29.         register_nav_menu( 'mobile_menu',   __( 'Mobile Menu'   , 'jegtheme' ));
  30.     endif;
  31.    
  32. endif;
  33.  
  34. function jeg_menu($pos)
  35. {
  36.     if(function_exists('wp_nav_menu') && has_nav_menu('top_right_menu') && $pos == "topright"):
  37.         wp_nav_menu(
  38.             array(
  39.                 'theme_location' => 'top_right_menu',
  40.                 'menu_class' => 'menu',
  41.                 'walker' => new jeg_top_menu_walker()
  42.             )
  43.         );
  44.     elseif (function_exists('wp_nav_menu') && has_nav_menu('top_left_menu') && $pos == "topleft") :
  45.         wp_nav_menu(
  46.             array(
  47.                 'theme_location' => 'top_left_menu',
  48.                 'menu_class' => 'menu',
  49.                 'walker' => new jeg_top_menu_walker()
  50.             )
  51.         );
  52.     elseif (function_exists('wp_nav_menu') && has_nav_menu('bottom_left_menu') && $pos == "bottomleft") :
  53.         wp_nav_menu(
  54.             array(
  55.                 'theme_location' => 'bottom_left_menu',
  56.                 'walker' => new jeg_bottom_menu_walker(),
  57.                 'depth' => 1
  58.             )
  59.         );
  60.     elseif (function_exists('wp_nav_menu') && has_nav_menu('bottom_right_menu') && $pos == "bottomright") :
  61.         wp_nav_menu(
  62.             array(
  63.                 'theme_location' => 'bottom_right_menu',
  64.                 'walker' => new jeg_bottom_menu_walker(),
  65.                 'depth' => 1
  66.             )
  67.         );
  68.     else :
  69.         /** don't show anything **/
  70.     endif ;
  71. }
  72.  
  73. function jeg_responsive_menu ()
  74. {
  75.     $responsemenu = "";
  76.    
  77.     if(has_nav_menu('mobile_menu')) {
  78.         $responsemenu .= wp_nav_menu(
  79.             array(
  80.                 'theme_location' => 'mobile_menu',
  81.                 'walker' => new jeg_responsive_menu_walker(),
  82.                 'depth' => 0,
  83.                 'container' => '',
  84.                 'items_wrap' => '%3$s'
  85.             )
  86.         );
  87.     } else {
  88.         if(function_exists('wp_nav_menu') && ( has_nav_menu('top_right_menu') || has_nav_menu('top_left_menu') ) ) :
  89.             if(has_nav_menu('top_left_menu')) :
  90.                 $responsemenu .= wp_nav_menu(
  91.                     array(
  92.                         'theme_location' => 'top_left_menu',
  93.                         'walker' => new jeg_responsive_menu_walker(),
  94.                         'depth' => 0,
  95.                         'container' => '',
  96.                         'items_wrap' => '%3$s'
  97.                     )
  98.                 );
  99.             endif; 
  100.             if(has_nav_menu('top_right_menu')) :
  101.                 $responsemenu .= wp_nav_menu(
  102.                     array(
  103.                         'theme_location' => 'top_right_menu',
  104.                         'walker' => new jeg_responsive_menu_walker(),
  105.                         'depth' => 0,
  106.                         'container' => '',
  107.                         'items_wrap' => '%3$s'
  108.                     )
  109.                 );
  110.             endif; 
  111.         endif;
  112.     }
  113.    
  114.     return $responsemenu;
  115. }
  116.  
  117. class jeg_responsive_menu_walker extends Walker_Nav_Menu {
  118.    
  119.     function start_lvl( &$output, $depth = 0, $args = array() ) {}
  120.     function end_lvl( &$output, $depth = 0, $args = array() ) {}
  121.     function end_el( &$output, $item, $depth = 0, $args = array() ) {}
  122.    
  123.     function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  124.                
  125.         $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  126.         $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  127.         $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  128.         $attributes .= ! empty( $item->url )        ? ' value="'   . esc_attr( $item->url        ) .'"' : '';
  129.        
  130.         $item_output = '';
  131.         $item_output .= '<option '. $attributes .'>'       
  132.             . str_repeat("&nbsp;&nbsp;", $depth)
  133.             . " "
  134.             . apply_filters( 'the_title', $item->title, $item->ID );
  135.            
  136.         $item_output .= '</option>';
  137.        
  138.         $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  139.     }
  140. }
  141.  
  142. // menu walker extends
  143. class jeg_bottom_menu_walker extends Walker_Nav_Menu
  144. {
  145.     function start_el( &$output, $item, $depth = 0, $args = array(), $current_object_id = 0 )
  146.     {
  147.         global $wp_query;
  148.         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  149.        
  150.         $class_names = $value = '';
  151.        
  152.         $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  153.         $classes[] = 'menu-item-' . $item->ID;
  154.        
  155.         $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  156.         $class_names = ' class="' . esc_attr( $class_names ) . '"';
  157.                
  158.         $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  159.         $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  160.        
  161.         $output .= $indent . '<li' . $id . $value . $class_names .'>';
  162.        
  163.         $attributes  = ! empty( $item->attr_title ) ? ' data-rel="tooltip" title="'  . esc_attr( $item->attr_title ) .'"' : '';
  164.         $attributes .= ! empty( $item->target )     ? ' target="'                    . esc_attr( $item->target     ) .'"' : '';
  165.         $attributes .= ! empty( $item->xfn )        ? ' rel="'                       . esc_attr( $item->xfn        ) .'"' : '';
  166.         $attributes .= ! empty( $item->url )        ? ' href="'                      . esc_attr( $item->url        ) .'"' : '';
  167.        
  168.         $nav_description = ! empty($item->description) ? '<span>' . esc_attr( $item->description ) . '</span>' : '';
  169.        
  170.         $item_output = $args->before;
  171.         $item_output .= '<a'. $attributes .'>';
  172.         $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) ;
  173.         $item_output .= $nav_description . $args->link_after;
  174.         $item_output .= '</a>';
  175.         $item_output .= $args->after;
  176.        
  177.         $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  178.     }
  179. }
  180.  
  181. // menu walker extends
  182. class jeg_top_menu_walker extends Walker_Nav_Menu
  183. {
  184.     function start_el( &$output, $item, $depth = 0, $args = array(), $current_object_id = 0 )
  185.     {
  186.         global $wp_query;
  187.         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  188.        
  189.         $class_names = $value = '';
  190.        
  191.         $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  192.         $classes[] = 'menu-item-' . $item->ID;
  193.         $classes[] = 'bgnav';
  194.        
  195.         $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  196.         $class_names = ' class="' . esc_attr( $class_names ) . '"';
  197.        
  198.         $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  199.         $id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
  200.        
  201.         $output .= $indent . '<li' . $id . $value . $class_names .'>';
  202.        
  203.         $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
  204.         $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
  205.         $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
  206.         $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
  207.        
  208.         $nav_description = ! empty($item->description) ? '<span>' . esc_attr( $item->description ) . '</span>' : '';
  209.        
  210.         $item_output = $args->before;
  211.         $item_output .= '<a'. $attributes .'>';
  212.         $item_output .= $args->link_before . '<h3>' . apply_filters( 'the_title', $item->title, $item->ID ) . '</h3>' ;
  213.         $item_output .= $nav_description . $args->link_after;
  214.         $item_output .= '</a>';
  215.         $item_output .= $args->after;
  216.        
  217.         $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  218.     }
  219.    
  220.     function start_lvl( &$output, $depth = 0, $args = array() ) {
  221.         $indent = str_repeat("\t", $depth);
  222.         $output .= "\n$indent<ul class=\"submenu\">\n";
  223.     }
  224. }
  225.  
  226. /** Side bar Begin ! **/
  227. add_action('init', 'jeg_init_sidebar');
  228.  
  229. function jeg_init_sidebar() {
  230.     $userSidebar = j_get_option("sidebar");
  231.     if(empty($userSidebar)) $userSidebar = array();
  232.     $jegSidebar = array_merge(array(JEG_DEFAULT_SIDEBAR), $userSidebar);
  233.     jeg_register_sidebars($jegSidebar);
  234. }
  235.  
  236. function jeg_register_sidebars($sidebars) {
  237.     foreach($sidebars as $sidebar) {
  238.         register_sidebar(array(
  239.             'name'          => $sidebar,
  240.             'id'            => jegGenId($sidebar),
  241.             'before_widget' => '<div class="containerborder %2$s" id="%1$s"><div class="inner-container">',
  242.             'after_widget'  => '</div></div>',
  243.             'before_title'  => '<h3>',
  244.             'after_title'   => '</h3><div class="widget-line"></div>',
  245.         ));
  246.     }
  247. }
  248.  
  249.  
  250. /** register menu head **/
  251. add_action('wp_head', 'jeg_put_og_image');
  252.  
  253. function jeg_put_og_image() {
  254.     global $post;
  255.     $posttype = $post->post_type;  
  256.     $cover = '';
  257.    
  258.     if($posttype == 'page' || $posttype == 'post') {
  259.         if(has_post_thumbnail()) {
  260.             $imagecover = j_get_post_header_image ($post, 'full');
  261.             $cover = $imagecover['src'];
  262.         }
  263.     } else if ($posttype == JEG_PORTFOLIO_POST_TYPE) {
  264.         $mediatype = j_get_meta('portfolio_media', '', $post->ID);
  265.         switch($mediatype) {
  266.             case 'gallery'  :
  267.                 $cover = j_get_meta('porto_gallery_cover', '', $post->ID);
  268.                 break;
  269.             case 'youtube'  :
  270.                 $cover = j_get_meta('porto_youtube_cover', '', $post->ID);
  271.                 break;
  272.             case 'vimeo'    :
  273.                 $cover = j_get_meta('porto_vimeo_cover', '', $post->ID);
  274.                 break;
  275.             case 'html-5-video' :
  276.                 $cover = j_get_meta('porto_video_cover', '', $post->ID);
  277.                 break;
  278.             case 'music'    :
  279.                 $cover = j_get_meta('porto_music_cover', '', $post->ID);
  280.                 break;
  281.         }
  282.     }
  283.    
  284.    
  285.     if($cover !== '') {
  286.         echo '<meta property="og:image" content="' . $cover . '"/>';
  287.     }
  288. }
  289.  
  290.  
  291.  
  292. /** register menu head **/
  293. add_action('wp_head', 'jeg_attach_font');
  294.  
  295. function jeg_build_fontface($face, $ff) {
  296.     $css =
  297.     "@font-face {
  298.         font-family: '". $face ."';
  299.         src: url('". $ff['0'] ."');
  300.         src: local('?'), url('" . $ff[1] . "') format('woff'), url('" . $ff[2] . "') format('truetype'), url('" . $ff[3] . "') format('svg');
  301.     }";
  302.     return $css;
  303. }
  304.  
  305.  
  306. function jeg_attach_font()
  307. {
  308.     $fontarray = array(
  309.         array(
  310.             'font' => j_get_themes_manager('heading_font')
  311.         ),
  312.         array(
  313.             'font' => j_get_themes_manager('heading_alt_font')
  314.         ),
  315.         array(
  316.             'font' => j_get_themes_manager('body_font')
  317.         ),
  318.         array(
  319.             'font' => j_get_themes_manager('front_slider_font')
  320.         ),
  321.     ); 
  322.    
  323.     $fontstring = "";
  324.     if(!empty($fontarray)) {
  325.         foreach ($fontarray as $f) {   
  326.             $font = $f['font'];
  327.             if(!empty($font['name'])) {
  328.                 $fn = urlencode($font['name']) . ':' . $font['variant'];
  329.                 $fontstring .= "\t\n<link href='http://fonts.googleapis.com/css?family=" . $fn .  "&amp;v1' rel='stylesheet' type='text/css'>";
  330.             } else if(!empty($font['face'])) {
  331.                 $fontstring .= "\n<style type='text/css'>\n
  332.                     ". jeg_build_fontface($font['face'], $font['facefont']) . "                    
  333.                 </style>";
  334.             } else {
  335.                 // nothing todo
  336.             }            
  337.         }
  338.     }
  339.    
  340.     echo $fontstring . "\n";
  341. }
  342.  
  343. /** set content width **/
  344. if ( ! isset( $content_width ) ) $content_width = 962;
  345.  
  346. /** don't show header **/
  347. add_action('init', 'jeg_hide_admin');
  348.  
  349.  
  350. function jeg_hide_admin() {
  351.     //show_admin_bar( false );
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement