Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 20.02 KB  |  hits: 47  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. // Exit if accessed directly
  4. if ( !defined('ABSPATH')) exit;
  5.  
  6. /**
  7.  * Theme's Functions and Definitions
  8.  *
  9.  *
  10.  * @file           functions.php
  11.  * @package        Responsive
  12.  * @author         Emil Uzelac
  13.  * @copyright      2003 - 2012 ThemeID
  14.  * @license        license.txt
  15.  * @version        Release: 1.1.1
  16.  * @filesource     wp-content/themes/responsive/includes/functions.php
  17.  * @link           http://codex.wordpress.org/Theme_Development#Functions_File
  18.  * @since          available since Release 1.0
  19.  */
  20. ?>
  21. <?php
  22. /**
  23.  * Fire up the engines boys and girls let's start theme setup.
  24.  */
  25. add_action('after_setup_theme', 'responsive_setup');
  26.  
  27. if (!function_exists('responsive_setup')):
  28.  
  29.     function responsive_setup() {
  30.  
  31.         global $content_width;
  32.  
  33.         /**
  34.          * Global content width.
  35.          */
  36.         if (!isset($content_width))
  37.             $content_width = 550;
  38.  
  39.         /**
  40.          * Responsive is now available for translations.
  41.          * Add your files into /languages/ directory.
  42.                  * @see http://codex.wordpress.org/Function_Reference/load_theme_textdomain
  43.          */
  44.             load_theme_textdomain('responsive', get_template_directory().'/languages');
  45.  
  46.             $locale = get_locale();
  47.             $locale_file = get_template_directory().'/languages/$locale.php';
  48.             if (is_readable( $locale_file))
  49.                     require_once( $locale_file);
  50.                                                
  51.         /**
  52.          * Add callback for custom TinyMCE editor stylesheets. (editor-style.css)
  53.          * @see http://codex.wordpress.org/Function_Reference/add_editor_style
  54.          */
  55.         add_editor_style();
  56.  
  57.         /**
  58.          * This feature enables post and comment RSS feed links to head.
  59.          * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Feed_Links
  60.          */
  61.         add_theme_support('automatic-feed-links');
  62.  
  63.         /**
  64.          * This feature enables post-thumbnail support for a theme.
  65.          * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  66.          */
  67.         add_theme_support('post-thumbnails');
  68.  
  69.         /**
  70.          * This feature enables custom-menus support for a theme.
  71.          * @see http://codex.wordpress.org/Function_Reference/register_nav_menus
  72.          */    
  73.         register_nav_menus(array(
  74.                         'top-menu'         => __('Top Menu', 'responsive'),
  75.                 'header-menu'      => __('Header Menu', 'responsive'),
  76.                 'sub-header-menu'  => __('Sub-Header Menu', 'responsive'),
  77.                         'footer-menu'      => __('Footer Menu', 'responsive')
  78.                     )
  79.             );
  80.  
  81.                 if ( function_exists('get_custom_header')) {
  82.                        
  83.  
  84. add_theme_support('custom-background');
  85.                
  86.                 } else {
  87.                
  88.                 // < 3.4 Backward Compatibility
  89.                
  90.                 /**
  91.          * This feature allows users to use custom background for a theme.
  92.          * @see http://codex.wordpress.org/Function_Reference/add_custom_background
  93.          */
  94.                
  95.         add_custom_background();
  96.                
  97.                 }
  98.  
  99.                 // WordPress 3.4 >
  100.                 if (function_exists('get_custom_header')) {
  101.                        
  102.                 add_theme_support('custom-header', array (
  103.                 // Header image default
  104.                'default-image'                  => get_template_directory_uri() . '/images/default-logo.png',
  105.                 // Header text display default
  106.                'header-text'                    => false,
  107.                 // Header image flex width
  108.                    'flex-width'             => true,
  109.                 // Header image width (in pixels)
  110.                'width'                              => 300,
  111.                     // Header image flex height
  112.                    'flex-height'            => true,
  113.                 // Header image height (in pixels)
  114.                'height'                         => 100,
  115.                 // Admin header style callback
  116.                'admin-head-callback'    => 'responsive_admin_header_style'));
  117.                    
  118.                 // gets included in the admin header
  119.         function responsive_admin_header_style() {
  120.             ?><style type="text/css">
  121.                 .appearance_page_custom-header #headimg {
  122.                                         background-repeat:no-repeat;
  123.                                         border:none;
  124.                                 }
  125.              </style><?php
  126.         }                
  127.            
  128.             } else {
  129.                    
  130.         // Backward Compatibility
  131.                
  132.                 /**
  133.          * This feature adds a callbacks for image header display.
  134.                  * In our case we are using this to display logo.
  135.          * @see http://codex.wordpress.org/Function_Reference/add_custom_image_header
  136.          */
  137.         define('HEADER_TEXTCOLOR', '');
  138.         define('HEADER_IMAGE', '%s/images/default-logo.png'); // %s is the template dir uri
  139.         define('HEADER_IMAGE_WIDTH', 300); // use width and height appropriate for your theme
  140.         define('HEADER_IMAGE_HEIGHT', 100);
  141.         define('NO_HEADER_TEXT', true);
  142.                
  143.                
  144.                 // gets included in the admin header
  145.         function responsive_admin_header_style() {
  146.             ?><style type="text/css">
  147.                 #headimg {
  148.                         background-repeat:no-repeat;
  149.                     border:none !important;
  150.                     width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
  151.                     height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;
  152.                 }
  153.              </style><?php
  154.          }
  155.          
  156.                  add_custom_image_header('', 'responsive_admin_header_style');
  157.                
  158.             }
  159.     }
  160.  
  161. endif;
  162.  
  163. /**
  164.  * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  165.  */
  166. function responsive_page_menu_args( $args ) {
  167.         $args['show_home'] = true;
  168.         return $args;
  169. }
  170. add_filter( 'wp_page_menu_args', 'responsive_page_menu_args' );
  171.  
  172. /**
  173.  * Remove div from wp_page_menu() and replace with ul.
  174.  */
  175. function responsive_wp_page_menu ($page_markup) {
  176.     preg_match('/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches);
  177.         $divclass = $matches[1];
  178.         $replace = array('<div class="'.$divclass.'">', '</div>');
  179.         $new_markup = str_replace($replace, '', $page_markup);
  180.         $new_markup = preg_replace('/^<ul>/i', '<ul class="'.$divclass.'">', $new_markup);
  181.         return $new_markup; }
  182.  
  183. add_filter('wp_page_menu', 'responsive_wp_page_menu');
  184.  
  185. /**
  186.  * Filter 'get_comments_number'
  187.  *
  188.  * Filter 'get_comments_number' to display correct
  189.  * number of comments (count only comments, not
  190.  * trackbacks/pingbacks)
  191.  *
  192.  * Courtesy of Chip Bennett
  193.  */
  194. function responsive_comment_count( $count ) {  
  195.         if ( ! is_admin() ) {
  196.                 global $id;
  197.                 $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
  198.                 return count($comments_by_type['comment']);
  199.         } else {
  200.                 return $count;
  201.         }
  202. }
  203. add_filter('get_comments_number', 'responsive_comment_count', 0);
  204.  
  205. /**
  206.  * wp_list_comments() Pings Callback
  207.  *
  208.  * wp_list_comments() Callback function for
  209.  * Pings (Trackbacks/Pingbacks)
  210.  */
  211. function responsive_comment_list_pings( $comment ) {
  212.         $GLOBALS['comment'] = $comment;
  213. ?>
  214.         <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
  215. <?php }
  216.  
  217. /**
  218.  * Sets the post excerpt length to 40 characters.
  219.  * Next few lines are adopted from Coraline
  220.  */
  221. function responsive_excerpt_length($length) {
  222.     return 40;
  223. }
  224.  
  225. add_filter('excerpt_length', 'responsive_excerpt_length');
  226.  
  227. /**
  228.  * Returns a "Read more" link for excerpts
  229.  */
  230. function responsive_read_more() {
  231.     return '<div class="read-more"><a href="' . get_permalink() . '">' . __('Read more &#8250;', 'responsive') . '</a></div><!-- end of .read-more -->';
  232. }
  233.  
  234. /**
  235.  * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and responsive_read_more_link().
  236.  */
  237. function responsive_auto_excerpt_more($more) {
  238.     return '<span class="ellipsis">&hellip;</span>' . responsive_read_more();
  239. }
  240.  
  241. add_filter('excerpt_more', 'responsive_auto_excerpt_more');
  242.  
  243. /**
  244.  * Adds a pretty "Read more" link to custom post excerpts.
  245.  */
  246. function responsive_custom_excerpt_more($output) {
  247.     if (has_excerpt() && !is_attachment()) {
  248.         $output .= responsive_read_more();
  249.     }
  250.     return $output;
  251. }
  252.  
  253. add_filter('get_the_excerpt', 'responsive_custom_excerpt_more');
  254.  
  255.  
  256. /**
  257.  * This function removes inline styles set by WordPress gallery.
  258.  */
  259. function responsive_remove_gallery_css($css) {
  260.     return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css);
  261. }
  262.  
  263. add_filter('gallery_style', 'responsive_remove_gallery_css');
  264.  
  265.  
  266. /**
  267.  * This function removes default styles set by WordPress recent comments widget.
  268.  */
  269. function responsive_remove_recent_comments_style() {
  270.         global $wp_widget_factory;
  271.         remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  272. }
  273. add_action( 'widgets_init', 'responsive_remove_recent_comments_style' );
  274.  
  275.  
  276. /**
  277.  * Breadcrumb Lists
  278.  * Allows visitors to quickly navigate back to a previous section or the root page.
  279.  *
  280.  * Courtesy of Dimox
  281.  *
  282.  * bbPress compatibility patch by Dan Smith
  283.  */
  284. function responsive_breadcrumb_lists () {
  285.  
  286.   $chevron = '<span class="chevron">&#8250;</span>';
  287.   $home = __('Home','responsive'); // text for the 'Home' link
  288.   $before = '<span class="breadcrumb-current">'; // tag before the current crumb
  289.   $after = '</span>'; // tag after the current crumb
  290.  
  291.   if ( !is_home() && !is_front_page() || is_paged() ) {
  292.  
  293.     echo '<div class="breadcrumb-list">';
  294.  
  295.     global $post;
  296.     $homeLink = home_url();
  297.     echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $chevron . ' ';
  298.  
  299.     if ( is_category() ) {
  300.       global $wp_query;
  301.       $cat_obj = $wp_query->get_queried_object();
  302.       $thisCat = $cat_obj->term_id;
  303.       $thisCat = get_category($thisCat);
  304.       $parentCat = get_category($thisCat->parent);
  305.       if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $chevron . ' '));
  306.       echo $before . __('Archive for ','responsive') . single_cat_title('', false) . $after;
  307.  
  308.     } elseif ( is_day() ) {
  309.       echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $chevron . ' ';
  310.       echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $chevron . ' ';
  311.       echo $before . get_the_time('d') . $after;
  312.  
  313.     } elseif ( is_month() ) {
  314.       echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $chevron . ' ';
  315.       echo $before . get_the_time('F') . $after;
  316.  
  317.     } elseif ( is_year() ) {
  318.       echo $before . get_the_time('Y') . $after;
  319.  
  320.     } elseif ( is_single() && !is_attachment() ) {
  321.       if ( get_post_type() != 'post' ) {
  322.         $post_type = get_post_type_object(get_post_type());
  323.         $slug = $post_type->rewrite;
  324.         echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $chevron . ' ';
  325.         echo $before . get_the_title() . $after;
  326.       } else {
  327.         $cat = get_the_category(); $cat = $cat[0];
  328.         echo get_category_parents($cat, TRUE, ' ' . $chevron . ' ');
  329.         echo $before . get_the_title() . $after;
  330.       }
  331.  
  332.     } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  333.       $post_type = get_post_type_object(get_post_type());
  334.       echo $before . $post_type->labels->singular_name . $after;
  335.  
  336.     } elseif ( is_attachment() ) {
  337.       $parent = get_post($post->post_parent);
  338.       $cat = get_the_category($parent->ID); $cat = $cat[0];
  339.       echo get_category_parents($cat, TRUE, ' ' . $chevron . ' ');
  340.       echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $chevron . ' ';
  341.       echo $before . get_the_title() . $after;
  342.  
  343.     } elseif ( is_page() && !$post->post_parent ) {
  344.       echo $before . get_the_title() . $after;
  345.  
  346.     } elseif ( is_page() && $post->post_parent ) {
  347.       $parent_id  = $post->post_parent;
  348.       $breadcrumbs = array();
  349.       while ($parent_id) {
  350.         $page = get_page($parent_id);
  351.         $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  352.         $parent_id  = $page->post_parent;
  353.       }
  354.       $breadcrumbs = array_reverse($breadcrumbs);
  355.       foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $chevron . ' ';
  356.       echo $before . get_the_title() . $after;
  357.  
  358.     } elseif ( is_search() ) {
  359.       echo $before . __('Search results for ','responsive') . get_search_query() . $after;
  360.  
  361.     } elseif ( is_tag() ) {
  362.       echo $before . __('Posts tagged ','responsive') . single_tag_title('', false) . $after;
  363.  
  364.     } elseif ( is_author() ) {
  365.        global $author;
  366.       $userdata = get_userdata($author);
  367.       echo $before . __('All posts by ','responsive') . $userdata->display_name . $after;
  368.  
  369.     } elseif ( is_404() ) {
  370.       echo $before . __('Error 404 ','responsive') . $after;
  371.     }
  372.  
  373.     if ( get_query_var('paged') ) {
  374.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  375.       echo __('Page','responsive') . ' ' . get_query_var('paged');
  376.       if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  377.     }
  378.  
  379.     echo '</div>';
  380.  
  381.   }
  382. }
  383.  
  384.  
  385.     /**
  386.      * A safe way of adding JavaScripts to a WordPress generated page.
  387.      */
  388.     if (!is_admin())
  389.         add_action('wp_enqueue_scripts', 'responsive_js');
  390.  
  391.     if (!function_exists('responsive_js')) {
  392.  
  393.         function responsive_js() {
  394.                         // JS at the bottom for fast page loading.
  395.                         // except for Modernizr which enables HTML5 elements & feature detects.
  396.                         wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/responsive-modernizr.js', array('jquery'), '2.5.3', false);
  397.             wp_enqueue_script('responsive-scripts', get_template_directory_uri() . '/js/responsive-scripts.js', array('jquery'), '1.2.0', true);
  398.                         wp_enqueue_script('responsive-plugins', get_template_directory_uri() . '/js/responsive-plugins.js', array('jquery'), '1.1.0', true);
  399.         }
  400.  
  401.     }
  402.  
  403.     /**
  404.      * A comment reply.
  405.      */
  406.         function responsive_enqueue_comment_reply() {
  407.     if ( is_singular() && comments_open() && get_option('thread_comments')) {
  408.             wp_enqueue_script('comment-reply');
  409.         }
  410.     }
  411.  
  412.     add_action( 'wp_enqueue_scripts', 'responsive_enqueue_comment_reply' );
  413.        
  414.     /**
  415.      * Where the post has no post title, but must still display a link to the single-page post view.
  416.      */
  417.     add_filter('the_title', 'responsive_title');
  418.  
  419.     function responsive_title($title) {
  420.         if ($title == '') {
  421.             return __('Untitled','responsive');
  422.         } else {
  423.             return $title;
  424.         }
  425.     }
  426.  
  427.     /**
  428.      * Theme Options Support and Information
  429.      */
  430.     function responsive_theme_support () {
  431.     ?>
  432.    
  433.     <div id="info-box-wrapper" class="grid col-940">
  434.         <div class="info-box notice">
  435.             <a class="blue button" href="<?php echo esc_url(__('http://themeid.com/support/','responsive')); ?>" title="<?php esc_attr_e('Theme Support', 'responsive'); ?>" target="_blank">
  436.             <?php printf(__('Theme Support','responsive')); ?></a>
  437.            
  438.             <a class="gray button" href="<?php echo esc_url(__('http://themeid.com/themes/','responsive')); ?>" title="<?php esc_attr_e('More Themes', 'responsive'); ?>" target="_blank">
  439.             <?php printf(__('More Themes','responsive')); ?></a>
  440.            
  441.             <a class="gray button" href="<?php echo esc_url(__('http://themeid.com/showcase/','responsive')); ?>" title="<?php esc_attr_e('Showcase', 'responsive'); ?>" target="_blank">
  442.             <?php printf(__('Showcase','responsive')); ?></a>
  443.            
  444.             <a class="gold button" href="<?php echo esc_url(__('http://themeid.com/donate/','responsive')); ?>" title="<?php esc_attr_e('Donate Now', 'responsive'); ?>" target="_blank">
  445.             <?php printf(__('Donate Now','responsive')); ?></a>
  446.         </div>
  447.     </div>
  448.  
  449.     <?php }
  450.  
  451.     add_action('responsive_theme_options','responsive_theme_support');
  452.  
  453.          
  454.     /**
  455.      * WordPress Widgets start right here.
  456.      */
  457.     function responsive_widgets_init() {
  458.  
  459.         register_sidebar(array(
  460.             'name' => __('Main Sidebar', 'responsive'),
  461.             'description' => __('Area One - sidebar.php', 'responsive'),
  462.             'id' => 'main-sidebar',
  463.             'before_title' => '<div class="widget-title">',
  464.             'after_title' => '</div>',
  465.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  466.             'after_widget' => '</div>'
  467.         ));
  468.  
  469.         register_sidebar(array(
  470.             'name' => __('Right Sidebar', 'responsive'),
  471.             'description' => __('Area Two - sidebar-right.php', 'responsive'),
  472.             'id' => 'right-sidebar',
  473.             'before_title' => '<div class="widget-title">',
  474.             'after_title' => '</div>',
  475.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  476.             'after_widget' => '</div>'
  477.         ));
  478.                                
  479.         register_sidebar(array(
  480.             'name' => __('Left Sidebar', 'responsive'),
  481.             'description' => __('Area Three - sidebar-left.php', 'responsive'),
  482.             'id' => 'left-sidebar',
  483.             'before_title' => '<div class="widget-title">',
  484.             'after_title' => '</div>',
  485.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  486.             'after_widget' => '</div>'
  487.         ));
  488.                
  489.         register_sidebar(array(
  490.             'name' => __('Left Sidebar Half Page', 'responsive'),
  491.             'description' => __('Area Four - sidebar-left-half.php', 'responsive'),
  492.             'id' => 'left-sidebar-half',
  493.             'before_title' => '<div class="widget-title">',
  494.             'after_title' => '</div>',
  495.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  496.             'after_widget' => '</div>'
  497.         ));
  498.                
  499.         register_sidebar(array(
  500.             'name' => __('Right Sidebar Half Page', 'responsive'),
  501.             'description' => __('Area Five - sidebar-right-half.php', 'responsive'),
  502.             'id' => 'right-sidebar-half',
  503.             'before_title' => '<div class="widget-title">',
  504.             'after_title' => '</div>',
  505.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  506.             'after_widget' => '</div>'
  507.         ));
  508.  
  509.      register_sidebar(array(
  510.             'name' => __('Home Widget Single', 'responsive'),
  511.             'description' => __('Area Twelve - sidebar-home-widget-single.php', 'responsive'),
  512.             'id' => 'home-widget-single',
  513.             'before_title' => '<div id="widget-title-three" class="widget-title-home"><h3>',
  514.             'after_title' => '</h3></div>',
  515.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  516.             'after_widget' => '</div>'
  517.         ));  
  518.  
  519.                register_sidebar(array(
  520.             'name' => __('Home Widget Double 1', 'responsive'),
  521.             'description' => __('Area Thirteen - sidebar-home-widgets-double.php', 'responsive'),
  522.             'id' => 'home-widgets-double-1',
  523.             'before_title' => '<div id="widget-title-two" class="widget-title-home"><h3>',
  524.             'after_title' => '</h3></div>',
  525.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  526.             'after_widget' => '</div>'
  527.         ));
  528.  
  529.         register_sidebar(array(
  530.             'name' => __('Home Widget Double 2', 'responsive'),
  531.             'description' => __('Area Fourteen - sidebar-home-widgets-double.php', 'responsive'),
  532.             'id' => 'home-widgets-double-2',
  533.             'before_title' => '<div id="widget-title-three" class="widget-title-home"><h3>',
  534.             'after_title' => '</h3></div>',
  535.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  536.             'after_widget' => '</div>'
  537.         ));
  538.  
  539.         register_sidebar(array(
  540.             'name' => __('Gallery Sidebar', 'responsive'),
  541.             'description' => __('Area Nine - sidebar-gallery.php', 'responsive'),
  542.             'id' => 'gallery-widget',
  543.             'before_title' => '<div class="widget-title">',
  544.             'after_title' => '</div>',
  545.             'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  546.             'after_widget' => '</div>'
  547.         ));
  548.     }
  549.        
  550.     add_action('widgets_init', 'responsive_widgets_init');
  551. ?>