Guest User

functions.php

a guest
Nov 5th, 2014
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*-----------------------------------------------------------------------------------
  4.  
  5.     Here we have all the custom functions for the theme
  6.     Please be extremely cautious editing this file,
  7.     When things go wrong, they tend to go wrong in a big way.
  8.     You have been warned!
  9.  
  10. -----------------------------------------------------------------------------------*/
  11.  
  12. /*-----------------------------------------------------------------------------------*/
  13. /*  Exclude pages from search
  14. /*-----------------------------------------------------------------------------------*/
  15.  
  16. function tz_exclude_pages($query) {
  17.         if ($query->is_search) {
  18.         $query->set('post_type', 'post');
  19.                                 }
  20.         return $query;
  21. }
  22. add_filter('pre_get_posts','tz_exclude_pages');
  23.  
  24.  
  25. /*-----------------------------------------------------------------------------------*/
  26. /*  Register WP3.0+ Menus
  27. /*-----------------------------------------------------------------------------------*/
  28.  
  29. function register_menu() {
  30.     register_nav_menu('primary-menu', __('Primary Menu'));
  31. }
  32. add_action('init', 'register_menu');
  33.  
  34.  
  35. /*-----------------------------------------------------------------------------------*/
  36. /*  Load Translation Text Domain
  37. /*-----------------------------------------------------------------------------------*/
  38.  
  39. load_theme_textdomain ('framework');
  40.  
  41.  
  42. /*-----------------------------------------------------------------------------------*/
  43. /*  Set Max Content Width (use in conjuction with ".entry-content img" css)
  44. /*-----------------------------------------------------------------------------------*/
  45.  
  46. if ( ! isset( $content_width ) ) $content_width = 600;
  47.  
  48.  
  49. /*-----------------------------------------------------------------------------------*/
  50. /*  Register Sidebars
  51. /*-----------------------------------------------------------------------------------*/
  52.  
  53. if ( function_exists('register_sidebar') ) {
  54.    
  55.     register_sidebar(array(
  56.         'name' => 'Main Sidebar',
  57.         'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
  58.         'after_widget' => '</div><div class="seperator clearfix"><span class="line"></span></div>',
  59.         'before_title' => '<h3 class="widget-title">',
  60.         'after_title' => '</h3>',
  61.     ));
  62.    
  63.     register_sidebar(array(
  64.         'name' => 'Page Sidebar',
  65.         'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
  66.         'after_widget' => '</div><div class="seperator clearfix"><span class="line"></span></div>',
  67.         'before_title' => '<h3 class="widget-title">',
  68.         'after_title' => '</h3>',
  69.     ));
  70.    
  71.     register_sidebar(array(
  72.         'name' => 'Portfolio Sidebar',
  73.         'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
  74.         'after_widget' => '</div><div class="seperator clearfix"><span class="line"></span></div>',
  75.         'before_title' => '<h3 class="widget-title">',
  76.         'after_title' => '</h3>',
  77.     ));
  78. }
  79.  
  80.  
  81. /*-----------------------------------------------------------------------------------*/
  82. /*  Post Formats
  83. /*-----------------------------------------------------------------------------------*/
  84.  
  85. $formats = array(
  86.             'aside',
  87.             'gallery',
  88.             'link',
  89.             'image',
  90.             'quote',
  91.             'audio',
  92.             'video');
  93.  
  94. add_theme_support( 'post-formats', $formats );
  95.  
  96. add_post_type_support( 'post', 'post-formats' );
  97.  
  98.  
  99. /*-----------------------------------------------------------------------------------*/
  100. /*  Configure WP2.9+ Thumbnails
  101. /*-----------------------------------------------------------------------------------*/
  102.  
  103. if ( function_exists( 'add_theme_support' ) ) {
  104.     add_theme_support( 'post-thumbnails' );
  105.     set_post_thumbnail_size( 50, 50, true ); // Normal post thumbnails
  106.     add_image_size( 'thumbnail-portfolio', 220, 160, true ); // Portfolio thumbnails
  107.     add_image_size( 'image-thumb', 500, '', true ); // Image format thumbnails
  108.     add_image_size( 'gallery-thumb', 500, '', true ); // Gallery format thumbnails
  109. }
  110.  
  111.  
  112. /*-----------------------------------------------------------------------------------*/
  113. /*  Change Default Excerpt Length
  114. /*-----------------------------------------------------------------------------------*/
  115.  
  116. function tz_excerpt_length($length) {
  117. return 16; }
  118. add_filter('excerpt_length', 'tz_excerpt_length');
  119.  
  120.  
  121. /*-----------------------------------------------------------------------------------*/
  122. /*  Configure Excerpt String
  123. /*-----------------------------------------------------------------------------------*/
  124.  
  125. function tz_excerpt_more($excerpt) {
  126. return str_replace('[...]', '...', $excerpt); }
  127. add_filter('wp_trim_excerpt', 'tz_excerpt_more');
  128.  
  129.  
  130. /*-----------------------------------------------------------------------------------*/
  131. /*  Register and load common JS
  132. /*-----------------------------------------------------------------------------------*/
  133.  
  134. function tz_enqueue_scripts() {
  135.     // register our scripts
  136.     wp_register_script('superfish', get_template_directory_uri() . '/js/superfish.js', 'jquery');
  137.     wp_register_script('validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', 'jquery');
  138.     wp_register_script('easing', get_template_directory_uri() . '/js/jquery.easing.1.3.js', 'jquery');
  139.     wp_register_script('tz_custom', get_template_directory_uri() . '/js/jquery.custom.js', 'jquery', '1.0', TRUE);
  140.     wp_register_script('fancybox', get_template_directory_uri().'/js/jquery.fancybox-1.3.4.pack.js', 'jquery');
  141.     wp_register_script('slidesjs', get_template_directory_uri().'/js/slides.min.jquery.js', 'jquery');
  142.     wp_register_script('jPlayer', get_template_directory_uri().'/js/jquery.jplayer.min.js', 'jquery');
  143.    
  144.     // register our stylesheets
  145.     wp_register_style( 'fancybox', get_template_directory_uri() . '/css/fancybox/jquery.fancybox-1.3.4.css' );
  146.    
  147.     // enqueue our scripts
  148.     wp_enqueue_script('jquery');
  149.     wp_enqueue_script('jquery-ui-core');
  150.     wp_enqueue_script('jquery-ui-tabs');
  151.     wp_enqueue_script('jquery-ui-accordion');
  152.     wp_enqueue_script('jPlayer');
  153.     wp_enqueue_script('slidesjs');
  154.     wp_enqueue_script('fancybox');
  155.     wp_enqueue_script('easing');
  156.     wp_enqueue_script('superfish');
  157.     wp_enqueue_script('tz_custom');
  158.     if( is_page_template('template-contact.php') ) { wp_enqueue_script('validation'); }
  159.     if( is_singular() ) { wp_enqueue_script( 'comment-reply' ); }
  160.    
  161.     // enqueue our stylesheets
  162.     wp_enqueue_style( 'fancybox' );
  163. }
  164. add_action('wp_enqueue_scripts', 'tz_enqueue_scripts');
  165.  
  166.  
  167. /*-----------------------------------------------------------------------------------*/
  168. /*  Register and load admin javascript
  169. /*-----------------------------------------------------------------------------------*/
  170.  
  171. function tz_admin_js($hook) {
  172.     if ($hook == 'post.php' || $hook == 'post-new.php') {
  173.         wp_register_script('tz-admin', get_template_directory_uri() . '/js/jquery.custom.admin.js', 'jquery');
  174.         wp_enqueue_script('tz-admin');
  175.     }
  176. }
  177. add_action('admin_enqueue_scripts','tz_admin_js',10,1);
  178.  
  179.  
  180. /*-----------------------------------------------------------------------------------*/
  181. /*  Add Browser Detection Body Class
  182. /*-----------------------------------------------------------------------------------*/
  183.  
  184. add_filter('body_class','tz_browser_body_class');
  185. function tz_browser_body_class($classes) {
  186.     global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  187.  
  188.     if($is_lynx) $classes[] = 'lynx';
  189.     elseif($is_gecko) $classes[] = 'gecko';
  190.     elseif($is_opera) $classes[] = 'opera';
  191.     elseif($is_NS4) $classes[] = 'ns4';
  192.     elseif($is_safari) $classes[] = 'safari';
  193.     elseif($is_chrome) $classes[] = 'chrome';
  194.     elseif($is_IE) $classes[] = 'ie';
  195.     else $classes[] = 'unknown';
  196.  
  197.     if($is_iphone) $classes[] = 'iphone';
  198.     return $classes;
  199. }
  200.  
  201.  
  202. /*-----------------------------------------------------------------------------------*/
  203. /*  Comment Styling
  204. /*-----------------------------------------------------------------------------------*/
  205.  
  206. function tz_comment($comment, $args, $depth) {
  207.  
  208.    $GLOBALS['comment'] = $comment; ?>
  209.    
  210.    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  211.      
  212.      <div id="comment-<?php comment_ID(); ?>" class="comment-height">
  213.      
  214.         <div class="comment-meta commentmetadata">
  215.        
  216.             <span class="author">
  217.             <?php echo get_comment_author_link(); ?>
  218.             <span><a href="<?php comment_link() ?>" title="<?php _e('Permalink to this comment', 'framework'); ?>">#</a></span>
  219.             </span>
  220.            
  221.             <div class="comment-reply-wrap clearfix">
  222.                 <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  223.             </div>
  224.         </div>
  225.        
  226.         <div class="comment-body clearfix">
  227.        
  228.             <?php if ($comment->comment_approved == '0') : ?>
  229.                 <em class="moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
  230.             <?php endif; ?>
  231.             <?php comment_text() ?>
  232.         </div>
  233.        
  234.      </div>
  235.  
  236. <?php
  237. }
  238.  
  239.  
  240. /*-----------------------------------------------------------------------------------*/
  241. /*  Seperated Pings Styling
  242. /*-----------------------------------------------------------------------------------*/
  243.  
  244. function tz_list_pings($comment, $args, $depth) {
  245.        $GLOBALS['comment'] = $comment; ?>
  246. <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
  247. <?php }
  248.  
  249.  
  250. /*-----------------------------------------------------------------------------------*/
  251. /*  Custom Login Logo Support
  252. /*-----------------------------------------------------------------------------------*/
  253.  
  254. function tz_custom_login_logo() {
  255.     echo '<style type="text/css">
  256.        h1 a { background-image:url('.get_template_directory_uri().'/images/custom-login-logo.png) !important; background-size: auto auto !important; }
  257.    </style>';
  258. }
  259. function tz_wp_login_url() {
  260.     return home_url();
  261. }
  262. function tz_wp_login_title() {
  263.     return get_option('blogname');
  264. }
  265.  
  266. add_action('login_head', 'tz_custom_login_logo');
  267. add_filter('login_headerurl', 'tz_wp_login_url');
  268. add_filter('login_headertitle', 'tz_wp_login_title');
  269.  
  270.  
  271. /*-----------------------------------------------------------------------------------*/
  272. /*  Force Insert to Post button
  273. /*-----------------------------------------------------------------------------------*/
  274.  
  275. add_filter( 'get_media_item_args', 'tz_force_send' );
  276. function tz_force_send($args){
  277.     $args['send'] = true;
  278.     return $args;
  279. }
  280.  
  281. /*-----------------------------------------------------------------------------------*/
  282. /*  Load Widgets & Shortcodes
  283. /*-----------------------------------------------------------------------------------*/
  284.  
  285. // Add the Latest Tweets Custom Widget
  286. include("functions/widget-tweets.php");
  287.  
  288. // Add the Flickr Photos Custom Widget
  289. include("functions/widget-flickr.php");
  290.  
  291. // Add the Custom Video Widget
  292. include("functions/widget-video.php");
  293.  
  294. // Add the Theme Shortcodes
  295. include("functions/theme-shortcodes.php");
  296.  
  297. // Add the post meta
  298. include("functions/theme-postmeta.php");
  299.  
  300. // Add the post types
  301. include("functions/theme-posttypes.php");
  302.  
  303. // Add the portfolio meta
  304. include("functions/theme-portfoliometa.php");
  305.  
  306. // Add the page meta
  307. include("functions/theme-pagemeta.php");
  308.  
  309. /*-----------------------------------------------------------------------------------*/
  310. /*  Filters that allow shortcodes in Text Widgets
  311. /*-----------------------------------------------------------------------------------*/
  312.  
  313. add_filter('widget_text', 'shortcode_unautop');
  314. add_filter('widget_text', 'do_shortcode');
  315.  
  316. /*-----------------------------------------------------------------------------------*/
  317. /*  Load Theme Options
  318. /*-----------------------------------------------------------------------------------*/
  319.  
  320. define('TZ_FILEPATH', TEMPLATEPATH);
  321. define('TZ_DIRECTORY', get_template_directory_uri());
  322.  
  323. require_once (TZ_FILEPATH . '/admin/admin-functions.php');
  324. require_once (TZ_FILEPATH . '/admin/admin-interface.php');
  325. require_once (TZ_FILEPATH . '/functions/theme-options.php');
  326. require_once (TZ_FILEPATH . '/functions/theme-functions.php');
  327. require_once (TZ_FILEPATH . '/tinymce/tinymce.loader.php');
  328.  
  329.  
  330. //* Enqueue Headroom
  331. add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' );
  332. function sk_enqueue_scripts() {
  333.  
  334.     if ( wp_is_mobile() )
  335.         return;
  336.  
  337.     wp_enqueue_style( 'animations',  get_stylesheet_directory_uri() . '/css/animations.min.css' );
  338.  
  339.     wp_enqueue_script( 'headroom', get_stylesheet_directory_uri() . '/js/headroom.min.js', '', '', true );
  340.     wp_enqueue_script( 'jquery-headroom',  get_stylesheet_directory_uri() . '/js/jQuery.headroom.min.js', array( 'jquery' ), '1.0.0', true );
  341.     wp_enqueue_script( 'headroom-init',  get_stylesheet_directory_uri() . '/js/headroom-init.js', array( 'jquery-headroom' ), '1.0.0', true );
  342.  
  343. }
  344.  
  345.  
  346. ?>
RAW Paste Data