PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/strappress/includes/functions.php

https://github.com/bfay/maniacal-kitten
PHP | 480 lines | 317 code | 64 blank | 99 comment | 37 complexity | 414b3ec83070868ddc5c99a6d54d0246 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Theme's Functions and Definitions
  4. *
  5. *
  6. * @file functions.php
  7. * @package StrapPress
  8. * @author Brad Williams
  9. * @copyright 2011 - 2012 Brag Interactive
  10. * @license license.txt
  11. * @version Release: 2.3.0
  12. * @filesource wp-content/themes/responsive/includes/functions.php
  13. * @link http://codex.wordpress.org/Theme_Development#Functions_File
  14. * @since available since Release 1.0
  15. */
  16. ?>
  17. <?php
  18. /**
  19. * Fire up the engines boys and girls let's start theme setup.
  20. */
  21. add_action('after_setup_theme', 'responsive_setup');
  22. if (!function_exists('responsive_setup')):
  23. function responsive_setup() {
  24. global $content_width;
  25. /**
  26. * Global content width.
  27. */
  28. if (!isset($content_width))
  29. $content_width = 550;
  30. /**
  31. * Responsive is now available for translations.
  32. * Add your files into /languages/ directory.
  33. * @see http://codex.wordpress.org/Function_Reference/load_theme_textdomain
  34. */
  35. load_theme_textdomain('responsive', get_template_directory().'/languages');
  36. $locale = get_locale();
  37. $locale_file = get_template_directory().'/languages/$locale.php';
  38. if (is_readable( $locale_file))
  39. require_once( $locale_file);
  40. /**
  41. * Add callback for custom TinyMCE editor stylesheets. (editor-style.css)
  42. * @see http://codex.wordpress.org/Function_Reference/add_editor_style
  43. */
  44. add_editor_style();
  45. /**
  46. * This feature enables post and comment RSS feed links to head.
  47. * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Feed_Links
  48. */
  49. add_theme_support('automatic-feed-links');
  50. /**
  51. * This feature enables post-thumbnail support for a theme.
  52. * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  53. */
  54. add_theme_support('post-thumbnails');
  55. add_image_size( 'port-thumb', 250, 200 );
  56. add_image_size( 'port-full', 600, 400 );
  57. add_image_size( 'portfolio-two-column', 562, 380, true ); // portfolio column image
  58. add_image_size( 'portfolio-three-column', 362, 300, true ); // portfolio 3 column image
  59. add_image_size( 'portfolio-four-column', 262, 200, true ); // portfolio 4 column image
  60. $options = get_option('responsive_theme_options');
  61. register_nav_menus(array(
  62. 'footer-menu' => __('Footer Menu', 'responsive')
  63. )
  64. );
  65. }
  66. endif;
  67. /**
  68. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  69. */
  70. function responsive_page_menu_args( $args ) {
  71. $args['show_home'] = true;
  72. return $args;
  73. }
  74. add_filter( 'wp_page_menu_args', 'responsive_page_menu_args' );
  75. /**
  76. * Remove div from wp_page_menu() and replace with ul.
  77. */
  78. function responsive_wp_page_menu ($page_markup) {
  79. preg_match('/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches);
  80. $divclass = $matches[1];
  81. $replace = array('<div class="'.$divclass.'">', '</div>');
  82. $new_markup = str_replace($replace, '', $page_markup);
  83. $new_markup = preg_replace('/^<ul>/i', '<ul class="'.$divclass.'">', $new_markup);
  84. return $new_markup; }
  85. add_filter('wp_page_menu', 'responsive_wp_page_menu');
  86. /**
  87. * Filter 'get_comments_number'
  88. *
  89. * Filter 'get_comments_number' to display correct
  90. * number of comments (count only comments, not
  91. * trackbacks/pingbacks)
  92. *
  93. * Courtesy of Chip Bennett
  94. */
  95. function responsive_comment_count( $count ) {
  96. if ( ! is_admin() ) {
  97. global $id;
  98. $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
  99. return count($comments_by_type['comment']);
  100. } else {
  101. return $count;
  102. }
  103. }
  104. add_filter('get_comments_number', 'responsive_comment_count', 0);
  105. /**
  106. * wp_list_comments() Pings Callback
  107. *
  108. * wp_list_comments() Callback function for
  109. * Pings (Trackbacks/Pingbacks)
  110. */
  111. function responsive_comment_list_pings( $comment ) {
  112. $GLOBALS['comment'] = $comment;
  113. ?>
  114. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
  115. <?php }
  116. /**
  117. * Sets the post excerpt length to 40 characters.
  118. * Next few lines are adopted from Coraline
  119. */
  120. function responsive_excerpt_length($length) {
  121. return 40;
  122. }
  123. add_filter('excerpt_length', 'responsive_excerpt_length');
  124. /**
  125. * Returns a "Read more" link for excerpts
  126. */
  127. function responsive_read_more() {
  128. return ' <a href="' . get_permalink() . '">' . __('<div class="read-more">Read more &#8250;</div><!-- end of .read-more -->', 'responsive') . '</a>';
  129. }
  130. /**
  131. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and responsive_read_more_link().
  132. */
  133. function responsive_auto_excerpt_more($more) {
  134. return '<span class="ellipsis">&hellip;</span>' . responsive_read_more();
  135. }
  136. add_filter('excerpt_more', 'responsive_auto_excerpt_more');
  137. /**
  138. * Adds a pretty "Read more" link to custom post excerpts.
  139. */
  140. function responsive_custom_excerpt_more($output) {
  141. if (has_excerpt() && !is_attachment()) {
  142. $output .= responsive_read_more();
  143. }
  144. return $output;
  145. }
  146. add_filter('get_the_excerpt', 'responsive_custom_excerpt_more');
  147. /**
  148. * This function removes inline styles set by WordPress gallery.
  149. */
  150. function responsive_remove_gallery_css($css) {
  151. return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css);
  152. }
  153. add_filter('gallery_style', 'responsive_remove_gallery_css');
  154. /**
  155. * This function removes default styles set by WordPress recent comments widget.
  156. */
  157. function responsive_remove_recent_comments_style() {
  158. global $wp_widget_factory;
  159. remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  160. }
  161. add_action( 'widgets_init', 'responsive_remove_recent_comments_style' );
  162. /**
  163. * Breadcrumb Lists
  164. * Allows visitors to quickly navigate back to a previous section or the root page.
  165. *
  166. * Courtesy of Dimox
  167. *
  168. * bbPress compatibility patch by Dan Smith
  169. */
  170. function responsive_breadcrumb_lists() {
  171. $chevron = '<span class="divider">/</span>';
  172. $name = __('Home','responsive'); //text for the 'Home' link
  173. $currentBefore = '<li class="current">';
  174. $currentAfter = '</li>';
  175. echo '<ul class="breadcrumb">';
  176. global $post;
  177. $home = home_url();
  178. echo '<li><a href="' . $home . '">' . $name . '</a>' . $chevron . '</li>';
  179. if (is_category()) {
  180. global $wp_query;
  181. $cat_obj = $wp_query->get_queried_object();
  182. $thisCat = $cat_obj->term_id;
  183. $thisCat = get_category($thisCat);
  184. $parentCat = get_category($thisCat->parent);
  185. if ($thisCat->parent != 0)
  186. echo(get_category_parents($parentCat, TRUE, ' ' . $chevron . ' '));
  187. echo $currentBefore . 'Archive by category &#39;';
  188. single_cat_title();
  189. echo '&#39;' . $currentAfter;
  190. } elseif (is_day()) {
  191. echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $chevron . '</li> ';
  192. echo '<li><a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $chevron . '</li> ';
  193. echo $currentBefore . get_the_time('d') . $currentAfter;
  194. } elseif (is_month()) {
  195. echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $chevron . '</li> ';
  196. echo $currentBefore . get_the_time('F') . $currentAfter;
  197. } elseif (is_year()) {
  198. echo $currentBefore . get_the_time('Y') . $currentAfter;
  199. } elseif (is_single()) {
  200. $pid = $post->ID;
  201. $pdata = get_the_category($pid);
  202. $adata = get_post($pid);
  203. if(!empty($pdata)){
  204. echo '<li>' .get_category_parents($pdata[0]->cat_ID, TRUE, ' ' . $chevron . ' '). '</li> ';
  205. echo $currentBefore;
  206. }
  207. echo $adata->post_title;
  208. echo $currentAfter;
  209. } elseif (is_page() && !$post->post_parent) {
  210. echo $currentBefore;
  211. the_title();
  212. echo $currentAfter;
  213. } elseif (is_page() && $post->post_parent) {
  214. $parent_id = $post->post_parent;
  215. $breadcrumb_lists = array();
  216. while ($parent_id) {
  217. $page = get_page($parent_id);
  218. $breadcrumb_lists[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>';
  219. $parent_id = $page->post_parent;
  220. }
  221. $breadcrumb_lists = array_reverse($breadcrumb_lists);
  222. foreach ($breadcrumb_lists as $crumb)
  223. echo $crumb . ' ' . $chevron . ' ';
  224. echo $currentBefore;
  225. the_title();
  226. echo $currentAfter;
  227. } elseif (is_search()) {
  228. echo $currentBefore . __('Search results for &#39;','responsive') . get_search_query() . __('&#39;','responsive') . $currentAfter;
  229. } elseif (is_tag()) {
  230. echo $currentBefore . __('Posts tagged &#39;','responsive');
  231. single_tag_title();
  232. echo '&#39;' . $currentAfter;
  233. } elseif (is_author()) {
  234. global $author;
  235. $userdata = get_userdata($author);
  236. echo $currentBefore . __('Articles posted by ','responsive') . $userdata->display_name . $currentAfter;
  237. } elseif (is_404()) {
  238. echo $currentBefore . __('Error 404','responsive') . $currentAfter;
  239. }
  240. if (get_query_var('paged')) {
  241. if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
  242. echo ' (';
  243. echo __('Page','responsive') . ' ' . get_query_var('paged');
  244. if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
  245. echo ')';
  246. }
  247. echo '</ul>';
  248. }
  249. /**
  250. * A safe way of adding javascripts to a WordPress generated page.
  251. */
  252. if (!is_admin())
  253. add_action('wp_enqueue_scripts', 'responsive_js');
  254. if (!function_exists('responsive_js')) {
  255. function responsive_js() {
  256. // JS at the bottom for fast page loading.
  257. // except for Modernizr which enables HTML5 elements & feature detects.
  258. wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/responsive-modernizr.js', array('jquery'), '2.5.3', false);
  259. wp_enqueue_script('responsive-scripts', get_template_directory_uri() . '/js/responsive-scripts.js', array('jquery'), '1.1.0', true);
  260. wp_enqueue_script('responsive-plugins', get_template_directory_uri() . '/js/responsive-plugins.js', array('jquery'), '1.1.0', true);
  261. wp_enqueue_script('colorbox', get_template_directory_uri() . '/js/jquery.colorbox-min.js', array('jquery'), '1.3.19', true);
  262. }
  263. }
  264. /**
  265. * A comment reply.
  266. */
  267. function responsive_enqueue_comment_reply() {
  268. if ( is_singular() && comments_open() && get_option('thread_comments')) {
  269. wp_enqueue_script('comment-reply');
  270. }
  271. }
  272. add_action( 'wp_enqueue_scripts', 'responsive_enqueue_comment_reply' );
  273. /**
  274. * Where the post has no post title, but must still display a link to the single-page post view.
  275. */
  276. add_filter('the_title', 'responsive_title');
  277. function responsive_title($title) {
  278. if ($title == '') {
  279. return __('Untitled','responsive');
  280. } else {
  281. return $title;
  282. }
  283. }
  284. /**
  285. * WordPress Widgets start right here.
  286. */
  287. function responsive_widgets_init() {
  288. register_sidebar(array(
  289. 'name' => __('Main Sidebar', 'responsive'),
  290. 'description' => __('Area One - sidebar.php', 'responsive'),
  291. 'id' => 'main-sidebar',
  292. 'before_title' => '<div class="widget-title">',
  293. 'after_title' => '</div>',
  294. 'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  295. 'after_widget' => '</div>'
  296. ));
  297. register_sidebar(array(
  298. 'name' => __('Home Page Right Sidebar', 'responsive'),
  299. 'description' => __('Area One/2 - sidebar-home-right.php', 'responsive'),
  300. 'id' => 'sidebar-home-right',
  301. 'before_title' => '<div class="widget-title">',
  302. 'after_title' => '</div>',
  303. 'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  304. 'after_widget' => '</div>'
  305. ));
  306. register_sidebar(array(
  307. 'name' => __('Right Sidebar', 'responsive'),
  308. 'description' => __('Area Two - sidebar-right.php', 'responsive'),
  309. 'id' => 'right-sidebar',
  310. 'before_title' => '<div class="widget-title">',
  311. 'after_title' => '</div>',
  312. 'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  313. 'after_widget' => '</div>'
  314. ));
  315. register_sidebar(array(
  316. 'name' => __('Left Sidebar', 'responsive'),
  317. 'description' => __('Area Three - sidebar-left.php', 'responsive'),
  318. 'id' => 'left-sidebar',
  319. 'before_title' => '<div class="widget-title">',
  320. 'after_title' => '</div>',
  321. 'before_widget' => '<div id="%1$s" class="widget-wrapper-left %2$s">',
  322. 'after_widget' => '</div>'
  323. ));
  324. register_sidebar(array(
  325. 'name' => __('Left Sidebar Half Page', 'responsive'),
  326. 'description' => __('Area Four - sidebar-left-half.php', 'responsive'),
  327. 'id' => 'left-sidebar-half',
  328. 'before_title' => '<div class="widget-title">',
  329. 'after_title' => '</div>',
  330. 'before_widget' => '<div id="%1$s" class="widget-wrapper-left %2$s">',
  331. 'after_widget' => '</div>'
  332. ));
  333. register_sidebar(array(
  334. 'name' => __('Right Sidebar Half Page', 'responsive'),
  335. 'description' => __('Area Five - sidebar-right-half.php', 'responsive'),
  336. 'id' => 'right-sidebar-half',
  337. 'before_title' => '<div class="widget-title">',
  338. 'after_title' => '</div>',
  339. 'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
  340. 'after_widget' => '</div>'
  341. ));
  342. register_sidebar(array(
  343. 'name' => __('Home Widget 1', 'responsive'),
  344. 'description' => __('Area Six - sidebar-home.php', 'responsive'),
  345. 'id' => 'home-widget-1',
  346. 'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
  347. 'after_title' => '</h3></div>',
  348. 'before_widget' => '<div id="%1$s" class="%2$s">',
  349. 'after_widget' => '</div>'
  350. ));
  351. register_sidebar(array(
  352. 'name' => __('Home Widget 2', 'responsive'),
  353. 'description' => __('Area Seven - sidebar-home.php', 'responsive'),
  354. 'id' => 'home-widget-2',
  355. 'before_title' => '<div id="widget-title-two" class="widget-title-home"><h3>',
  356. 'after_title' => '</h3></div>',
  357. 'before_widget' => '<div id="%1$s" class="%2$s">',
  358. 'after_widget' => '</div>'
  359. ));
  360. register_sidebar(array(
  361. 'name' => __('Home Widget 3', 'responsive'),
  362. 'description' => __('Area Eight - sidebar-home.php', 'responsive'),
  363. 'id' => 'home-widget-3',
  364. 'before_title' => '<div id="widget-title-three" class="widget-title-home"><h3>',
  365. 'after_title' => '</h3></div>',
  366. 'before_widget' => '<div id="%1$s" class="%2$s">',
  367. 'after_widget' => '</div>'
  368. ));
  369. register_sidebar(array(
  370. 'name' => __('Home Widget Site Map', 'responsive'),
  371. 'description' => __('Area Eight - sidebar-home.php', 'responsive'),
  372. 'id' => 'home-site-map',
  373. 'before_title' => '<div id="widget-title-three" class="widget-title-home"><h4>',
  374. 'after_title' => '</h4></div>',
  375. 'before_widget' => '<div id="%1$s" class="span3 %2$s">',
  376. 'after_widget' => '</div>'
  377. ));
  378. register_sidebar(array(
  379. 'name' => __('Contact', 'responsive'),
  380. 'description' => __('Area Nine - contact.php', 'responsive'),
  381. 'id' => 'contact-widget',
  382. 'before_title' => '<div id="widget-title-three" class="widget-contact"><h3>',
  383. 'after_title' => '</h3></div>',
  384. 'before_widget' => '<div id="%1$s" class="%2$s">',
  385. 'after_widget' => '</div>'
  386. ));
  387. register_sidebar(array(
  388. 'name' => __('Membership Option Silver', 'responsive'),
  389. 'description' => __('Area Ten - sidebar-membership.php', 'responsive'),
  390. 'id' => 'membership-option-silver',
  391. 'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
  392. 'after_title' => '</h3></div>',
  393. 'before_widget' => '<div id="%1$s" class="%2$s">',
  394. 'after_widget' => '</div>'
  395. ));
  396. register_sidebar(array(
  397. 'name' => __('Membership Option Gold', 'responsive'),
  398. 'description' => __('Area Eleven - sidebar-membership.php', 'responsive'),
  399. 'id' => 'membership-option-gold',
  400. 'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
  401. 'after_title' => '</h3></div>',
  402. 'before_widget' => '<div id="%1$s" class="%2$s">',
  403. 'after_widget' => '</div>'
  404. ));
  405. register_sidebar(array(
  406. 'name' => __('Membership Option Platinum', 'responsive'),
  407. 'description' => __('Area Twelve - sidebar-membership.php', 'responsive'),
  408. 'id' => 'membership-option-platinum',
  409. 'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
  410. 'after_title' => '</h3></div>',
  411. 'before_widget' => '<div id="%1$s" class="%2$s">',
  412. 'after_widget' => '</div>'
  413. ));
  414. }
  415. add_action('widgets_init', 'responsive_widgets_init');
  416. ?>