PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/gonzo/functions.php

https://bitbucket.org/ssellek/saywhatnation.bitbucket
PHP | 372 lines | 249 code | 77 blank | 46 comment | 17 complexity | 256d5e44b37fb0e94d6ef2dbe5da6d19 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, GPL-3.0
  1. <?php
  2. require_once (TEMPLATEPATH . '/includes/user-rating.php');
  3. load_theme_textdomain('gonzo', TEMPLATEPATH . '/languages');
  4. $locale = get_locale();
  5. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  6. if (is_readable($locale_file))
  7. require_once($locale_file);
  8. if (!isset($content_width)) $content_width = 900;
  9. add_theme_support('post-thumbnails');
  10. add_theme_support('automatic-feed-links');
  11. register_nav_menus(array(
  12. 'primary' => __('Primary Navigation', 'gonzo'),
  13. 'mobile' => __('Mobile Navigation', 'gonzo'),
  14. 'copyright' => __('Footer Copyright Menu', 'gonzo'),
  15. 'toplevel' => __('Top Secondary Menu', 'gonzo')
  16. ));
  17. // Calls in All scripts & styles
  18. function load_gonzo_child_styles()
  19. {
  20. if (is_admin()) return;
  21. wp_dequeue_style('main_css');
  22. wp_enqueue_style('main_css', get_stylesheet_directory_uri() . '/style.css');
  23. }
  24. add_action('init', 'load_gonzo_child_styles', 11);
  25. function load_gonzo_scripts()
  26. {
  27. if (is_admin()) return;
  28. wp_enqueue_script('jquery');
  29. wp_register_script('modernizr', get_template_directory_uri() . '/js/libs/modernizr-2.0.6.min.js');
  30. wp_enqueue_script('modernizr');
  31. wp_register_script('scripts', get_template_directory_uri() . '/js/scripts.js');
  32. wp_enqueue_script('scripts');
  33. }
  34. add_action('init', 'load_gonzo_scripts');
  35. // Calls in metabox scripts/js
  36. function load_gonzo_metabox()
  37. {
  38. if (!is_admin()) return;
  39. wp_enqueue_style('metabox_css_load', get_template_directory_uri() . '/includes/classes/meta-box/css/style.css');
  40. wp_enqueue_style('metabox_color_load', get_template_directory_uri() . '/includes/classes/meta-box/css/color.css');
  41. wp_register_script('metabox-js-gonzo', get_template_directory_uri() . '/includes/classes/meta-box/js/gonzo.js');
  42. wp_enqueue_script('metabox-js-gonzo');
  43. wp_register_script('metabox-js-clone', get_template_directory_uri() . '/includes/classes/meta-box/js/clone.js');
  44. wp_enqueue_script('metabox-js-clone');
  45. wp_register_script('metabox-js-color', get_template_directory_uri() . '/includes/classes/meta-box/js/color.js');
  46. wp_enqueue_script('metabox-js-color');
  47. }
  48. add_action('init', 'load_gonzo_metabox', 11);
  49. // Enable threaded comments
  50. function enable_threaded_comments()
  51. {
  52. if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
  53. wp_enqueue_script('comment-reply');
  54. }
  55. }
  56. add_action('get_header', 'enable_threaded_comments');
  57. // Link to seperated functions
  58. require_once (TEMPLATEPATH . '/includes/widget_areas.php');
  59. require_once (TEMPLATEPATH . '/includes/multiple_excerpts.php');
  60. require_once (TEMPLATEPATH . '/includes/comments.php');
  61. require_once (TEMPLATEPATH . '/includes/kreisi_pagination.php');
  62. require_once (TEMPLATEPATH . '/includes/thumbnails.php');
  63. require_once (TEMPLATEPATH . '/includes/menu-alterations.php');
  64. require_once (TEMPLATEPATH . '/includes/classes/Tax-meta-class/class-usage.php');
  65. require_once (TEMPLATEPATH . '/includes/widget-video.php');
  66. require_once (TEMPLATEPATH . '/includes/widget-facebook-fans.php');
  67. require_once (TEMPLATEPATH . '/includes/widget-latest-posts.php');
  68. require_once (TEMPLATEPATH . '/includes/widget-best-reviews.php');
  69. require_once (TEMPLATEPATH . '/option-tree/option-tree.php');
  70. // Link to plugins
  71. require_once (TEMPLATEPATH . '/includes/plugins/socialbox/socialbox.php');
  72. require_once (TEMPLATEPATH . '/includes/plugins/gallery-to-slideshow/gallery-to-slideshow.php');
  73. require_once (TEMPLATEPATH . '/includes/plugins/dp-flickr-widget/dp-flickr-widget.php');
  74. require_once (TEMPLATEPATH . '/includes/plugins/tabber-tabs-widget/tabber-tabs.php');
  75. // Link to shortcodes
  76. require_once (TEMPLATEPATH . '/includes/shortcodes/columns-shortcode.php');
  77. require_once (TEMPLATEPATH . '/includes/shortcodes/buttons-shortcode.php');
  78. require_once (TEMPLATEPATH . '/includes/shortcodes/loops-shortcode.php');
  79. require_once (TEMPLATEPATH . '/includes/shortcodes/tabs-shortcode.php');
  80. require_once (TEMPLATEPATH . '/includes/shortcodes/toggle-shortcode.php');
  81. require_once (TEMPLATEPATH . '/includes/shortcodes/infobox-shortcode.php');
  82. require_once (TEMPLATEPATH . '/includes/shortcodes/embed-shortcode.php');
  83. require_once (TEMPLATEPATH . '/includes/shortcodes/soundcloud-shortcode.php');
  84. // Re-define meta box path and URL
  85. define('RWMB_URL', trailingslashit(get_template_directory() . '/includes/classes/meta-box'));
  86. define('RWMB_DIR', trailingslashit(get_template_directory() . '/includes/classes/meta-box'));
  87. // Include the meta box script
  88. require_once RWMB_DIR . 'meta-box.php';
  89. // Include the meta box definition (This is the file where you define meta boxes, see `demo/demo.php`)
  90. include get_template_directory() . '/includes/meta-box-config.php';
  91. // Remove image titles
  92. add_filter('the_content', 'remove_img_titles', 1000);
  93. add_filter('post_thumbnail_html', 'remove_img_titles', 1000);
  94. add_filter('wp_get_attachment_image', 'remove_img_titles', 1000);
  95. function remove_img_titles($text)
  96. {
  97. // Get all title="..." tags from the html.
  98. $result = array();
  99. preg_match_all('|title="[^"]*"|U', $text, $result);
  100. // Replace all occurances with an empty string.
  101. foreach ($result[0] as $img_tag) {
  102. $text = str_replace($img_tag, '', $text);
  103. }
  104. return $text;
  105. }
  106. // Get rid of the font-size on the tagcloud widget
  107. add_filter("widget_tag_cloud_args", 'my_tag_cloud_args');
  108. function my_tag_cloud_args($in)
  109. {
  110. return "smallest=0.9&largest=0.9&number=23&orderby=name&unit=em";
  111. }
  112. // Enable post thumbnail preview for custom columns
  113. if (!function_exists('fb_AddThumbColumn') && function_exists('add_theme_support')) {
  114. // for post and investments
  115. function fb_AddThumbColumn($cols)
  116. {
  117. $cols['thumbnail'] = __('Thumbnail', 'gonzo');
  118. return $cols;
  119. }
  120. function fb_AddThumbValue($column_name, $post_id)
  121. {
  122. if ('thumbnail' == $column_name) {
  123. // thumbnail of WP 2.9
  124. $thumbnail_id = get_post_meta($post_id, '_thumbnail_id', true);
  125. // image from gallery
  126. $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
  127. if ($thumbnail_id)
  128. $thumb = wp_get_attachment_image($thumbnail_id, 'small-square', true);
  129. elseif ($attachments) {
  130. foreach ($attachments as $attachment_id => $attachment) {
  131. $thumb = wp_get_attachment_image($attachment_id, 'small-square', true);
  132. }
  133. }
  134. if (isset($thumb) && $thumb) {
  135. echo $thumb;
  136. } else {
  137. echo __('None', 'gonzo');
  138. }
  139. }
  140. }
  141. // for posts
  142. add_filter('manage_posts_columns', 'fb_AddThumbColumn');
  143. add_action('manage_posts_custom_column', 'fb_AddThumbValue', 10, 2);
  144. // for investments
  145. add_filter('manage_investments_columns', 'fb_AddThumbColumn');
  146. add_action('manage_investments_custom_column', 'fb_AddThumbValue', 10, 2);
  147. }
  148. // Replace the default ellipsis
  149. function trim_excerpt($text)
  150. {
  151. return rtrim($text, '[...]');
  152. }
  153. add_filter('get_the_excerpt', 'trim_excerpt');
  154. class Description_Walker extends Walker_Nav_Menu
  155. {
  156. /**
  157. * Start the element output.
  158. *
  159. * @param string $output Passed by reference. Used to append additional content.
  160. * @param object $item Menu item data object.
  161. * @param int $depth Depth of menu item. May be used for padding.
  162. * @param array $args Additional strings.
  163. * @return void
  164. */
  165. function start_el(&$output, $item, $depth, $args)
  166. {
  167. $classes = empty ($item->classes) ? array() : (array)$item->classes;
  168. $class_names = join(
  169. ' '
  170. , apply_filters(
  171. 'nav_menu_css_class'
  172. , array_filter($classes), $item
  173. )
  174. );
  175. !empty ($class_names)
  176. and $class_names = ' class="' . esc_attr($class_names) . '"';
  177. $output .= "<li id='menu-item-$item->ID' $class_names>";
  178. $attributes = '';
  179. !empty($item->attr_title)
  180. and $attributes .= ' title="' . esc_attr($item->attr_title) . '"';
  181. !empty($item->target)
  182. and $attributes .= ' target="' . esc_attr($item->target) . '"';
  183. !empty($item->xfn)
  184. and $attributes .= ' rel="' . esc_attr($item->xfn) . '"';
  185. !empty($item->url)
  186. and $attributes .= ' href="' . esc_attr($item->url) . '"';
  187. !empty($item->description)
  188. and $attributes .= ' id="' . esc_attr($item->description) . '"';
  189. // insert description for top level elements only
  190. // you may change this
  191. $description = (!empty ($item->description) and 0 == $depth)
  192. ? '<small class="nav_desc">' . esc_attr($item->description) . '</small>' : '';
  193. $title = apply_filters('the_title', $item->title, $item->ID);
  194. $item_output = $args->before
  195. . "<a $attributes>"
  196. . $args->link_before
  197. . $title
  198. . '</a> '
  199. . $args->link_after
  200. . $description
  201. . $args->after;
  202. // Since $output is called by reference we don't need to return anything.
  203. $output .= apply_filters(
  204. 'walker_nav_menu_start_el'
  205. , $item_output
  206. , $item
  207. , $depth
  208. , $args
  209. );
  210. }
  211. }
  212. // Hide the admin bar for development
  213. //add_filter( 'show_admin_bar', '__return_false' );
  214. add_theme_support('post-formats', array('video', 'gallery', 'audio'));
  215. // add post-formats to posts
  216. add_post_type_support('post', 'post-formats');
  217. // Remove the image dimensions to make the theme responsive
  218. add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10);
  219. add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10);
  220. function remove_thumbnail_dimensions($html)
  221. {
  222. $html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
  223. return $html;
  224. }
  225. // Add social media links to the user page
  226. function add_social_contactmethod($contactmethods)
  227. {
  228. // Add Networks
  229. $contactmethods['twitter'] = 'Twitter URL';
  230. $contactmethods['facebook'] = 'Facebook URL';
  231. $contactmethods['linkedin'] = 'Linkedin URL';
  232. $contactmethods['soundcloud'] = 'Soundcloud URL';
  233. $contactmethods['youtube'] = 'YouTube URL';
  234. $contactmethods['google'] = 'Google+ URL';
  235. return $contactmethods;
  236. }
  237. add_filter('user_contactmethods', 'add_social_contactmethod', 10, 1);
  238. function dropcap($atts, $content = null)
  239. {
  240. return '<em class="omc-dropcap">' . $content . '</em>';
  241. }
  242. add_shortcode('dropcap', 'dropcap');
  243. /**
  244. * Register AdPress Styles
  245. *
  246. * @return bool
  247. */
  248. function register_adpress_styles()
  249. {
  250. if (!class_exists('wp_adpress_register_style')) {
  251. return false;
  252. }
  253. $gonzo_styles = array(
  254. 'pr-468x60' => array(
  255. 'list' => array('pr-468x60')
  256. ),
  257. 'pr-728x90' => array(
  258. 'list' => array('pr-728x90')
  259. ),
  260. 'pr-125x125' => array(
  261. 'list' => array('pr-125x125')
  262. ),
  263. 'pr-300x250' => array(
  264. 'list' => array('pr-300x250')
  265. ),
  266. 'pr-300x100' => array(
  267. 'list' => array('pr-300x100')
  268. ),
  269. 'pr-misc-a' => array(
  270. 'list' => array('pr-misc-a')
  271. ),
  272. 'pr-misc-b' => array(
  273. 'list' => array('pr-misc-b')
  274. ),
  275. 'pr-misc-c' => array(
  276. 'list' => array('pr-misc-c')
  277. ),
  278. 'pr-misc-d' => array(
  279. 'list' => array('pr-misc-d')
  280. ),
  281. );
  282. new wp_adpress_register_style('gonzo_468x60', 'Gonzo 468x60', $gonzo_styles['pr-468x60']);
  283. new wp_adpress_register_style('gonzo_728x90', 'Gonzo 728x90', $gonzo_styles['pr-728x90']);
  284. new wp_adpress_register_style('gonzo_125x125', 'Gonzo 125x125', $gonzo_styles['pr-125x125']);
  285. new wp_adpress_register_style('gonzo_300x250', 'Gonzo 300x250', $gonzo_styles['pr-300x250']);
  286. new wp_adpress_register_style('gonzo_300x100', 'Gonzo 300x100', $gonzo_styles['pr-300x100']);
  287. new wp_adpress_register_style('gonzo_misc-a', 'Gonzo Misc. A', $gonzo_styles['pr-misc-a']);
  288. new wp_adpress_register_style('gonzo_misc-b', 'Gonzo Misc. B', $gonzo_styles['pr-misc-b']);
  289. new wp_adpress_register_style('gonzo_misc-c', 'Gonzo Misc. C', $gonzo_styles['pr-misc-c']);
  290. new wp_adpress_register_style('gonzo_misc-d', 'Gonzo Misc. D', $gonzo_styles['pr-misc-d']);
  291. }
  292. /*
  293. * Calls the function during the init hook
  294. */
  295. add_action('init', 'register_adpress_styles');