PageRenderTime 74ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

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

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