/bp-themes/bp-default/functions.php

  1. <?php 
  2. /** 
  3. * BP-Default theme functions and definitions 
  4. * 
  5. * Sets up the theme and provides some helper functions. Some helper functions 
  6. * are used in the theme as custom template tags. Others are attached to action and 
  7. * filter hooks in WordPress and BuddyPress to change core functionality. 
  8. * 
  9. * The first function, bp_dtheme_setup(), sets up the theme by registering support 
  10. * for various features in WordPress, such as post thumbnails and navigation menus, and 
  11. * for BuddyPress, action buttons and javascript localisation. 
  12. * 
  13. * When using a child theme (see http://codex.wordpress.org/Theme_Development, http://codex.wordpress.org/Child_Themes 
  14. * and http://codex.buddypress.org/theme-development/building-a-buddypress-child-theme/), you can override 
  15. * certain functions (those wrapped in a function_exists() call) by defining them first in your 
  16. * child theme's functions.php file. The child theme's functions.php file is included before the 
  17. * parent theme's file, so the child theme functions would be used. 
  18. * 
  19. * Functions that are not pluggable (not wrapped in function_exists()) are instead attached 
  20. * to a filter or action hook. The hook can be removed by using remove_action() or 
  21. * remove_filter() and you can attach your own function to the hook. 
  22. * 
  23. * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API. 
  24. * 
  25. * @package BuddyPress 
  26. * @subpackage BP-Default 
  27. * @since BuddyPress (1.2) 
  28. */ 
  29.  
  30. // Exit if accessed directly 
  31. if ( ! defined( 'ABSPATH' ) ) exit; 
  32.  
  33. // If BuddyPress is not activated, switch back to the default WP theme and bail out 
  34. if ( ! function_exists( 'bp_is_active' ) ) { 
  35. switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); 
  36. return; 
  37.  
  38. /** 
  39. * Set the content width based on the theme's design and stylesheet. 
  40. * 
  41. * Used to set the width of images and content. Should be equal to the width the theme 
  42. * is designed for, generally via the style.css stylesheet. 
  43. */ 
  44. if ( ! isset( $content_width ) ) 
  45. $content_width = 591; 
  46.  
  47. if ( ! function_exists( 'bp_dtheme_setup' ) ) : 
  48. /** 
  49. * Sets up theme defaults and registers support for various WordPress and BuddyPress features. 
  50. * 
  51. * Note that this function is hooked into the after_setup_theme hook, which runs 
  52. * before the init hook. The init hook is too late for some features, such as indicating 
  53. * support post thumbnails. 
  54. * 
  55. * To override bp_dtheme_setup() in a child theme, add your own bp_dtheme_setup to your child theme's 
  56. * functions.php file. 
  57. * 
  58. * @global BuddyPress $bp The one true BuddyPress instance 
  59. * @since BuddyPress (1.5) 
  60. */ 
  61. function bp_dtheme_setup() { 
  62.  
  63. // Load the AJAX functions for the theme 
  64. require( get_template_directory() . '/_inc/ajax.php' ); 
  65.  
  66. // This theme styles the visual editor with editor-style.css to match the theme style. 
  67. add_editor_style(); 
  68.  
  69. // This theme comes with all the BuddyPress goodies 
  70. add_theme_support( 'buddypress' ); 
  71.  
  72. // This theme uses post thumbnails 
  73. add_theme_support( 'post-thumbnails' ); 
  74.  
  75. // Add default posts and comments RSS feed links to head 
  76. add_theme_support( 'automatic-feed-links' ); 
  77.  
  78. // Add responsive layout support to bp-default without forcing child 
  79. // themes to inherit it if they don't want to 
  80. add_theme_support( 'bp-default-responsive' ); 
  81.  
  82. // This theme uses wp_nav_menu() in one location. 
  83. register_nav_menus( array( 
  84. 'primary' => __( 'Primary Navigation', 'buddypress' ),  
  85. ) ); 
  86.  
  87. // This theme allows users to set a custom background 
  88. $custom_background_args = array( 
  89. 'wp-head-callback' => 'bp_dtheme_custom_background_style' 
  90. ); 
  91. add_theme_support( 'custom-background', $custom_background_args ); 
  92.  
  93. // Add custom header support if allowed 
  94. if ( !defined( 'BP_DTHEME_DISABLE_CUSTOM_HEADER' ) ) { 
  95. define( 'HEADER_TEXTCOLOR', 'FFFFFF' ); 
  96.  
  97. // The height and width of your custom header. You can hook into the theme's own filters to change these values. 
  98. // Add a filter to bp_dtheme_header_image_width and bp_dtheme_header_image_height to change these values. 
  99. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'bp_dtheme_header_image_width', 1250 ) ); 
  100. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'bp_dtheme_header_image_height', 133 ) ); 
  101.  
  102. // We'll be using post thumbnails for custom header images on posts and pages. We want them to be 1250 pixels wide by 133 pixels tall. 
  103. // Larger images will be auto-cropped to fit, smaller ones will be ignored. 
  104. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 
  105.  
  106. // Add a way for the custom header to be styled in the admin panel that controls custom headers. 
  107. $custom_header_args = array( 
  108. 'wp-head-callback' => 'bp_dtheme_header_style',  
  109. 'admin-head-callback' => 'bp_dtheme_admin_header_style' 
  110. ); 
  111. add_theme_support( 'custom-header', $custom_header_args ); 
  112.  
  113. if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 
  114. // Register buttons for the relevant component templates 
  115. // Friends button 
  116. if ( bp_is_active( 'friends' ) ) 
  117. add_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 ); 
  118.  
  119. // Activity button 
  120. if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) 
  121. add_action( 'bp_member_header_actions', 'bp_send_public_message_button', 20 ); 
  122.  
  123. // Messages button 
  124. if ( bp_is_active( 'messages' ) ) 
  125. add_action( 'bp_member_header_actions', 'bp_send_private_message_button', 20 ); 
  126.  
  127. // Group buttons 
  128. if ( bp_is_active( 'groups' ) ) { 
  129. add_action( 'bp_group_header_actions', 'bp_group_join_button', 5 ); 
  130. add_action( 'bp_group_header_actions', 'bp_group_new_topic_button', 20 ); 
  131. add_action( 'bp_directory_groups_actions', 'bp_group_join_button' ); 
  132.  
  133. // Blog button 
  134. if ( bp_is_active( 'blogs' ) ) 
  135. add_action( 'bp_directory_blogs_actions', 'bp_blogs_visit_blog_button' ); 
  136. add_action( 'after_setup_theme', 'bp_dtheme_setup' ); 
  137. endif; 
  138.  
  139. if ( !function_exists( 'bp_dtheme_enqueue_scripts' ) ) : 
  140. /** 
  141. * Enqueue theme javascript safely 
  142. * 
  143. * @see http://codex.wordpress.org/Function_Reference/wp_enqueue_script 
  144. * @since BuddyPress (1.5) 
  145. */ 
  146. function bp_dtheme_enqueue_scripts() { 
  147.  
  148. // Enqueue various scripts 
  149. wp_enqueue_script( 'bp-jquery-query' ); 
  150. wp_enqueue_script( 'bp-jquery-cookie' ); 
  151.  
  152. // Enqueue scrollTo only on activity pages 
  153. if ( bp_is_activity_component() ) { 
  154. wp_enqueue_script( 'bp-jquery-scroll-to' ); 
  155.  
  156. // A similar check is done in BP_Core_Members_Widget, but due to a load order 
  157. // issue, we do it again here 
  158. if ( is_active_widget( false, false, 'bp_core_members_widget' ) && ! is_admin() && ! is_network_admin() ) { 
  159. wp_enqueue_script( 'bp-widget-members' ); 
  160.  
  161. // Enqueue the global JS - Ajax will not work without it 
  162. wp_enqueue_script( 'dtheme-ajax-js', get_template_directory_uri() . '/_inc/global.js', array( 'jquery' ), bp_get_version() ); 
  163.  
  164. // Add words that we need to use in JS to the end of the page so they can be translated and still used. 
  165. $params = array( 
  166. 'my_favs' => __( 'My Favorites', 'buddypress' ),  
  167. 'accepted' => __( 'Accepted', 'buddypress' ),  
  168. 'rejected' => __( 'Rejected', 'buddypress' ),  
  169. 'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),  
  170. 'show_x_comments' => __( 'Show all %d comments', 'buddypress' ),  
  171. 'show_all' => __( 'Show all', 'buddypress' ),  
  172. 'comments' => __( 'comments', 'buddypress' ),  
  173. 'close' => __( 'Close', 'buddypress' ),  
  174. 'view' => __( 'View', 'buddypress' ),  
  175. 'mark_as_fav' => __( 'Favorite', 'buddypress' ),  
  176. 'remove_fav' => __( 'Remove Favorite', 'buddypress' ),  
  177. 'unsaved_changes' => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ),  
  178. ); 
  179. wp_localize_script( 'dtheme-ajax-js', 'BP_DTheme', $params ); 
  180.  
  181. // Maybe enqueue comment reply JS 
  182. if ( is_singular() && bp_is_blog_page() && get_option( 'thread_comments' ) ) 
  183. wp_enqueue_script( 'comment-reply' ); 
  184. add_action( 'wp_enqueue_scripts', 'bp_dtheme_enqueue_scripts' ); 
  185. endif; 
  186.  
  187. if ( !function_exists( 'bp_dtheme_enqueue_styles' ) ) : 
  188. /** 
  189. * Enqueue theme CSS safely 
  190. * 
  191. * For maximum flexibility, BuddyPress Default's stylesheet is enqueued, using wp_enqueue_style(). 
  192. * If you're building a child theme of bp-default, your stylesheet will also be enqueued,  
  193. * automatically, as dependent on bp-default's CSS. For this reason, bp-default child themes are 
  194. * not recommended to include bp-default's stylesheet using @import. 
  195. * 
  196. * If you would prefer to use @import, or would like to change the way in which stylesheets are 
  197. * enqueued, you can override bp_dtheme_enqueue_styles() in your theme's functions.php file. 
  198. * 
  199. * @see http://codex.wordpress.org/Function_Reference/wp_enqueue_style 
  200. * @see http://codex.buddypress.org/releases/1-5-developer-and-designer-information/ 
  201. * @since BuddyPress (1.5) 
  202. */ 
  203. function bp_dtheme_enqueue_styles() { 
  204.  
  205. // Register our main stylesheet 
  206. wp_register_style( 'bp-default-main', get_template_directory_uri() . '/_inc/css/default.css', array(), bp_get_version() ); 
  207.  
  208. // If the current theme is a child of bp-default, enqueue its stylesheet 
  209. if ( is_child_theme() && 'bp-default' == get_template() ) { 
  210. wp_enqueue_style( get_stylesheet(), get_stylesheet_uri(), array( 'bp-default-main' ), bp_get_version() ); 
  211.  
  212. // Enqueue the main stylesheet 
  213. wp_enqueue_style( 'bp-default-main' ); 
  214.  
  215. // Default CSS RTL 
  216. if ( is_rtl() ) 
  217. wp_enqueue_style( 'bp-default-main-rtl', get_template_directory_uri() . '/_inc/css/default-rtl.css', array( 'bp-default-main' ), bp_get_version() ); 
  218.  
  219. // Responsive layout 
  220. if ( current_theme_supports( 'bp-default-responsive' ) ) { 
  221. wp_enqueue_style( 'bp-default-responsive', get_template_directory_uri() . '/_inc/css/responsive.css', array( 'bp-default-main' ), bp_get_version() ); 
  222.  
  223. if ( is_rtl() ) { 
  224. wp_enqueue_style( 'bp-default-responsive-rtl', get_template_directory_uri() . '/_inc/css/responsive-rtl.css', array( 'bp-default-responsive' ), bp_get_version() ); 
  225. add_action( 'wp_enqueue_scripts', 'bp_dtheme_enqueue_styles' ); 
  226. endif; 
  227.  
  228. if ( !function_exists( 'bp_dtheme_admin_header_style' ) ) : 
  229. /** 
  230. * Styles the header image displayed on the Appearance > Header admin panel. 
  231. * 
  232. * Referenced via add_custom_image_header() in bp_dtheme_setup(). 
  233. * 
  234. * @since BuddyPress (1.2) 
  235. */ 
  236. function bp_dtheme_admin_header_style() { 
  237. ?> 
  238. <style type="text/css"> 
  239. #headimg { 
  240. position: relative; 
  241. color: #fff; 
  242. background: url(<?php header_image(); ?>); 
  243. -moz-border-radius-bottomleft: 6px; 
  244. -webkit-border-bottom-left-radius: 6px; 
  245. -moz-border-radius-bottomright: 6px; 
  246. -webkit-border-bottom-right-radius: 6px; 
  247. margin-bottom: 20px; 
  248. height: 133px; 
  249.  
  250. #headimg h1{ 
  251. position: absolute; 
  252. bottom: 15px; 
  253. left: 15px; 
  254. width: 44%; 
  255. margin: 0; 
  256. font-family: Arial, Tahoma, sans-serif; 
  257. #headimg h1 a{ 
  258. color:#<?php header_textcolor(); ?>; 
  259. text-decoration: none; 
  260. border-bottom: none; 
  261. #headimg #desc{ 
  262. color:#<?php header_textcolor(); ?>; 
  263. font-size:1em; 
  264. margin-top:-0.5em; 
  265.  
  266. #desc { 
  267. display: none; 
  268.  
  269. <?php if ( 'blank' == get_header_textcolor() ) { ?> 
  270. #headimg h1, #headimg #desc { 
  271. display: none; 
  272. #headimg h1 a, #headimg #desc { 
  273. color:#<?php echo HEADER_TEXTCOLOR; ?>; 
  274. <?php } ?> 
  275. </style> 
  276. <?php 
  277. endif; 
  278.  
  279. if ( !function_exists( 'bp_dtheme_custom_background_style' ) ) : 
  280. /** 
  281. * The style for the custom background image or colour. 
  282. * 
  283. * Referenced via add_custom_background() in bp_dtheme_setup(). 
  284. * 
  285. * @see _custom_background_cb() 
  286. * @since BuddyPress (1.5) 
  287. */ 
  288. function bp_dtheme_custom_background_style() { 
  289. $background = get_background_image(); 
  290. $color = get_background_color(); 
  291. if ( ! $background && ! $color ) 
  292. return; 
  293.  
  294. $style = $color ? "background-color: #$color;" : ''; 
  295.  
  296. if ( $style && !$background ) { 
  297. $style .= ' background-image: none;'; 
  298.  
  299. } elseif ( $background ) { 
  300. $image = " background-image: url('$background');"; 
  301.  
  302. $repeat = get_theme_mod( 'background_repeat', 'repeat' ); 
  303. if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) 
  304. $repeat = 'repeat'; 
  305. $repeat = " background-repeat: $repeat;"; 
  306.  
  307. $position = get_theme_mod( 'background_position_x', 'left' ); 
  308. if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) ) 
  309. $position = 'left'; 
  310. $position = " background-position: top $position;"; 
  311.  
  312. $attachment = get_theme_mod( 'background_attachment', 'scroll' ); 
  313. if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) ) 
  314. $attachment = 'scroll'; 
  315. $attachment = " background-attachment: $attachment;"; 
  316.  
  317. $style .= $image . $repeat . $position . $attachment; 
  318. ?> 
  319. <style type="text/css"> 
  320. body { <?php echo trim( $style ); ?> } 
  321. </style> 
  322. <?php 
  323. endif; 
  324.  
  325. if ( !function_exists( 'bp_dtheme_header_style' ) ) : 
  326. /** 
  327. * The styles for the post thumbnails / custom page headers. 
  328. * 
  329. * Referenced via add_custom_image_header() in bp_dtheme_setup(). 
  330. * 
  331. * @global WP_Query $post The current WP_Query object for the current post or page 
  332. * @since BuddyPress (1.2) 
  333. */ 
  334. function bp_dtheme_header_style() { 
  335. global $post; 
  336.  
  337. $header_image = ''; 
  338.  
  339. if ( is_singular() && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { 
  340. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ); 
  341.  
  342. // $src, $width, $height 
  343. if ( !empty( $image ) && $image[1] >= HEADER_IMAGE_WIDTH ) 
  344. $header_image = $image[0]; 
  345. else 
  346. $header_image = get_header_image(); 
  347.  
  348. } else { 
  349. $header_image = get_header_image(); 
  350. ?> 
  351.  
  352. <style type="text/css"> 
  353. <?php if ( !empty( $header_image ) ) : ?> 
  354. #header { background-image: url(<?php echo $header_image ?>); } 
  355. <?php endif; ?> 
  356.  
  357. <?php if ( 'blank' == get_header_textcolor() ) { ?> 
  358. #header h1, #header #desc { display: none; } 
  359. <?php } else { ?> 
  360. #header h1 a, #desc { color:#<?php header_textcolor(); ?>; } 
  361. <?php } ?> 
  362. </style> 
  363.  
  364. <?php 
  365. endif; 
  366.  
  367. if ( !function_exists( 'bp_dtheme_widgets_init' ) ) : 
  368. /** 
  369. * Register widgetised areas, including one sidebar and four widget-ready columns in the footer. 
  370. * 
  371. * To override bp_dtheme_widgets_init() in a child theme, remove the action hook and add your own 
  372. * function tied to the init hook. 
  373. * 
  374. * @since BuddyPress (1.5) 
  375. */ 
  376. function bp_dtheme_widgets_init() { 
  377.  
  378. // Area 1, located in the sidebar. Empty by default. 
  379. register_sidebar( array( 
  380. 'name' => 'Sidebar',  
  381. 'id' => 'sidebar-1',  
  382. 'description' => __( 'The sidebar widget area', 'buddypress' ),  
  383. 'before_widget' => '<div id="%1$s" class="widget %2$s">',  
  384. 'after_widget' => '</div>',  
  385. 'before_title' => '<h3 class="widgettitle">',  
  386. 'after_title' => '</h3>' 
  387. ) ); 
  388.  
  389. // Area 2, located in the footer. Empty by default. 
  390. register_sidebar( array( 
  391. 'name' => __( 'First Footer Widget Area', 'buddypress' ),  
  392. 'id' => 'first-footer-widget-area',  
  393. 'description' => __( 'The first footer widget area', 'buddypress' ),  
  394. 'before_widget' => '<li id="%1$s" class="widget %2$s">',  
  395. 'after_widget' => '</li>',  
  396. 'before_title' => '<h3 class="widgettitle">',  
  397. 'after_title' => '</h3>',  
  398. ) ); 
  399.  
  400. // Area 3, located in the footer. Empty by default. 
  401. register_sidebar( array( 
  402. 'name' => __( 'Second Footer Widget Area', 'buddypress' ),  
  403. 'id' => 'second-footer-widget-area',  
  404. 'description' => __( 'The second footer widget area', 'buddypress' ),  
  405. 'before_widget' => '<li id="%1$s" class="widget %2$s">',  
  406. 'after_widget' => '</li>',  
  407. 'before_title' => '<h3 class="widgettitle">',  
  408. 'after_title' => '</h3>',  
  409. ) ); 
  410.  
  411. // Area 4, located in the footer. Empty by default. 
  412. register_sidebar( array( 
  413. 'name' => __( 'Third Footer Widget Area', 'buddypress' ),  
  414. 'id' => 'third-footer-widget-area',  
  415. 'description' => __( 'The third footer widget area', 'buddypress' ),  
  416. 'before_widget' => '<li id="%1$s" class="widget %2$s">',  
  417. 'after_widget' => '</li>',  
  418. 'before_title' => '<h3 class="widgettitle">',  
  419. 'after_title' => '</h3>',  
  420. ) ); 
  421.  
  422. // Area 5, located in the footer. Empty by default. 
  423. register_sidebar( array( 
  424. 'name' => __( 'Fourth Footer Widget Area', 'buddypress' ),  
  425. 'id' => 'fourth-footer-widget-area',  
  426. 'description' => __( 'The fourth footer widget area', 'buddypress' ),  
  427. 'before_widget' => '<li id="%1$s" class="widget %2$s">',  
  428. 'after_widget' => '</li>',  
  429. 'before_title' => '<h3 class="widgettitle">',  
  430. 'after_title' => '</h3>',  
  431. ) ); 
  432. add_action( 'widgets_init', 'bp_dtheme_widgets_init' ); 
  433. endif; 
  434.  
  435. if ( !function_exists( 'bp_dtheme_blog_comments' ) ) : 
  436. /** 
  437. * Template for comments and pingbacks. 
  438. * 
  439. * To override this walker in a child theme without modifying the comments template 
  440. * simply create your own bp_dtheme_blog_comments(), and that function will be used instead. 
  441. * 
  442. * Used as a callback by wp_list_comments() for displaying the comments. 
  443. * 
  444. * @param mixed $comment Comment record from database 
  445. * @param array $args Arguments from wp_list_comments() call 
  446. * @param int $depth Comment nesting level 
  447. * @see wp_list_comments() 
  448. * @since BuddyPress (1.2) 
  449. */ 
  450. function bp_dtheme_blog_comments( $comment, $args, $depth ) { 
  451. $GLOBALS['comment'] = $comment; 
  452.  
  453. if ( 'pingback' == $comment->comment_type ) 
  454. return false; 
  455.  
  456. if ( 1 == $depth ) 
  457. $avatar_size = 50; 
  458. else 
  459. $avatar_size = 25; 
  460. ?> 
  461.  
  462. <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>"> 
  463. <div class="comment-avatar-box"> 
  464. <div class="avb"> 
  465. <a href="<?php echo get_comment_author_url(); ?>" rel="nofollow"> 
  466. <?php if ( $comment->user_id ) : ?> 
  467. <?php echo bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => $avatar_size, 'height' => $avatar_size, 'email' => $comment->comment_author_email ) ); ?> 
  468. <?php else : ?> 
  469. <?php echo get_avatar( $comment, $avatar_size ); ?> 
  470. <?php endif; ?> 
  471. </a> 
  472. </div> 
  473. </div> 
  474.  
  475. <div class="comment-content"> 
  476. <div class="comment-meta"> 
  477. <p> 
  478. <?php 
  479. /** translators: 1: comment author url, 2: comment author name, 3: comment permalink, 4: comment date/timestamp*/ 
  480. printf( __( '<a href="%1$s" rel="nofollow">%2$s</a> said on <a href="%3$s"><span class="time-since">%4$s</span></a>', 'buddypress' ), get_comment_author_url(), get_comment_author(), get_comment_link(), get_comment_date() ); 
  481. ?> 
  482. </p> 
  483. </div> 
  484.  
  485. <div class="comment-entry"> 
  486. <?php if ( $comment->comment_approved == '0' ) : ?> 
  487. <em class="moderate"><?php _e( 'Your comment is awaiting moderation.', 'buddypress' ); ?></em> 
  488. <?php endif; ?> 
  489.  
  490. <?php comment_text(); ?> 
  491. </div> 
  492.  
  493. <div class="comment-options"> 
  494. <?php if ( comments_open() ) : ?> 
  495. <?php comment_reply_link( array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ); ?> 
  496. <?php endif; ?> 
  497.  
  498. <?php if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) : ?> 
  499. <?php printf( '<a class="button comment-edit-link bp-secondary-action" href="%1$s" title="%2$s">%3$s</a> ', get_edit_comment_link( $comment->comment_ID ), esc_attr__( 'Edit comment', 'buddypress' ), __( 'Edit', 'buddypress' ) ); ?> 
  500. <?php endif; ?> 
  501.  
  502. </div> 
  503.  
  504. </div> 
  505.  
  506. <?php 
  507. endif; 
  508.  
  509. if ( !function_exists( 'bp_dtheme_page_on_front' ) ) : 
  510. /** 
  511. * Return the ID of a page set as the home page. 
  512. * 
  513. * @return int|bool ID of page set as the home page 
  514. * @since BuddyPress (1.2) 
  515. */ 
  516. function bp_dtheme_page_on_front() { 
  517. if ( 'page' != get_option( 'show_on_front' ) ) 
  518. return false; 
  519.  
  520. return apply_filters( 'bp_dtheme_page_on_front', get_option( 'page_on_front' ) ); 
  521. endif; 
  522.  
  523. if ( !function_exists( 'bp_dtheme_activity_secondary_avatars' ) ) : 
  524. /** 
  525. * Add secondary avatar image to this activity stream's record, if supported. 
  526. * 
  527. * @param string $action The text of this activity 
  528. * @param BP_Activity_Activity $activity Activity object 
  529. * @package BuddyPress Theme 
  530. * @return string 
  531. * @since BuddyPress (1.2.6) 
  532. */ 
  533. function bp_dtheme_activity_secondary_avatars( $action, $activity ) { 
  534. switch ( $activity->component ) { 
  535. case 'groups' : 
  536. case 'friends' : 
  537. // Only insert avatar if one exists 
  538. if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) { 
  539. $reverse_content = strrev( $action ); 
  540. $position = strpos( $reverse_content, 'a<' ); 
  541. $action = substr_replace( $action, $secondary_avatar, -$position - 2, 0 ); 
  542. break; 
  543.  
  544. return $action; 
  545. add_filter( 'bp_get_activity_action_pre_meta', 'bp_dtheme_activity_secondary_avatars', 10, 2 ); 
  546. endif; 
  547.  
  548. if ( !function_exists( 'bp_dtheme_show_notice' ) ) : 
  549. /** 
  550. * Show a notice when the theme is activated - workaround by Ozh (http://old.nabble.com/Activation-hook-exist-for-themes--td25211004.html) 
  551. * 
  552. * @since BuddyPress (1.2) 
  553. */ 
  554. function bp_dtheme_show_notice() { 
  555. global $pagenow; 
  556.  
  557. // Bail if bp-default theme was not just activated 
  558. if ( empty( $_GET['activated'] ) || ( 'themes.php' != $pagenow ) || !is_admin() ) 
  559. return; 
  560.  
  561. ?> 
  562.  
  563. <div id="message" class="updated fade"> 
  564. <p><?php printf( __( 'Theme activated! This theme contains <a href="%s">custom header image</a> support and <a href="%s">sidebar widgets</a>.', 'buddypress' ), admin_url( 'themes.php?page=custom-header' ), admin_url( 'widgets.php' ) ); ?></p> 
  565. </div> 
  566.  
  567. <style type="text/css">#message2, #message0 { display: none; }</style> 
  568.  
  569. <?php 
  570. add_action( 'admin_notices', 'bp_dtheme_show_notice' ); 
  571. endif; 
  572.  
  573. if ( !function_exists( 'bp_dtheme_main_nav' ) ) : 
  574. /** 
  575. * wp_nav_menu() callback from the main navigation in header.php 
  576. * 
  577. * Used when the custom menus haven't been configured. 
  578. * 
  579. * @param array Menu arguments from wp_nav_menu() 
  580. * @see wp_nav_menu() 
  581. * @since BuddyPress (1.5) 
  582. */ 
  583. function bp_dtheme_main_nav( $args ) { 
  584. $pages_args = array( 
  585. 'depth' => 0,  
  586. 'echo' => false,  
  587. 'exclude' => '',  
  588. 'title_li' => '' 
  589. ); 
  590. $menu = wp_page_menu( $pages_args ); 
  591. $menu = str_replace( array( '<div class="menu"><ul>', '</ul></div>' ), array( '<ul id="nav">', '</ul><!-- #nav -->' ), $menu ); 
  592. echo $menu; 
  593.  
  594. do_action( 'bp_nav_items' ); 
  595. endif; 
  596.  
  597. if ( !function_exists( 'bp_dtheme_page_menu_args' ) ) : 
  598. /** 
  599. * Get our wp_nav_menu() fallback, bp_dtheme_main_nav(), to show a home link. 
  600. * 
  601. * @param array $args Default values for wp_page_menu() 
  602. * @see wp_page_menu() 
  603. * @since BuddyPress (1.5) 
  604. */ 
  605. function bp_dtheme_page_menu_args( $args ) { 
  606. $args['show_home'] = true; 
  607. return $args; 
  608. add_filter( 'wp_page_menu_args', 'bp_dtheme_page_menu_args' ); 
  609. endif; 
  610.  
  611. if ( !function_exists( 'bp_dtheme_comment_form' ) ) : 
  612. /** 
  613. * Applies BuddyPress customisations to the post comment form. 
  614. * 
  615. * @param array $default_labels The default options for strings, fields etc in the form 
  616. * @see comment_form() 
  617. * @since BuddyPress (1.5) 
  618. */ 
  619. function bp_dtheme_comment_form( $default_labels ) { 
  620.  
  621. $commenter = wp_get_current_commenter(); 
  622. $req = get_option( 'require_name_email' ); 
  623. $aria_req = ( $req ? " aria-required='true'" : '' ); 
  624. $fields = array( 
  625. 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'buddypress' ) . ( $req ? '<span class="required"> *</span>' : '' ) . '</label> ' . 
  626. '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',  
  627. 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'buddypress' ) . ( $req ? '<span class="required"> *</span>' : '' ) . '</label> ' . 
  628. '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',  
  629. 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website', 'buddypress' ) . '</label>' . 
  630. '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',  
  631. ); 
  632.  
  633. $new_labels = array( 
  634. 'comment_field' => '<p class="form-textarea"><textarea name="comment" id="comment" cols="60" rows="10" aria-required="true"></textarea></p>',  
  635. 'fields' => apply_filters( 'comment_form_default_fields', $fields ),  
  636. 'logged_in_as' => '',  
  637. 'must_log_in' => '<p class="alert">' . sprintf( __( 'You must be <a href="%1$s">logged in</a> to post a comment.', 'buddypress' ), wp_login_url( get_permalink() ) ) . '</p>',  
  638. 'title_reply' => __( 'Leave a reply', 'buddypress' ) 
  639. ); 
  640.  
  641. return apply_filters( 'bp_dtheme_comment_form', array_merge( $default_labels, $new_labels ) ); 
  642. add_filter( 'comment_form_defaults', 'bp_dtheme_comment_form', 10 ); 
  643. endif; 
  644.  
  645. if ( !function_exists( 'bp_dtheme_before_comment_form' ) ) : 
  646. /** 
  647. * Adds the user's avatar before the comment form box. 
  648. * 
  649. * The 'comment_form_top' action is used to insert our HTML within <div id="reply"> 
  650. * so that the nested comments comment-reply javascript moves the entirety of the comment reply area. 
  651. * 
  652. * @see comment_form() 
  653. * @since BuddyPress (1.5) 
  654. */ 
  655. function bp_dtheme_before_comment_form() { 
  656. ?> 
  657. <div class="comment-avatar-box"> 
  658. <div class="avb"> 
  659. <?php if ( bp_loggedin_user_id() ) : ?> 
  660. <a href="<?php echo bp_loggedin_user_domain(); ?>"> 
  661. <?php echo get_avatar( bp_loggedin_user_id(), 50 ); ?> 
  662. </a> 
  663. <?php else : ?> 
  664. <?php echo get_avatar( 0, 50 ); ?> 
  665. <?php endif; ?> 
  666. </div> 
  667. </div> 
  668.  
  669. <div class="comment-content standard-form"> 
  670. <?php 
  671. add_action( 'comment_form_top', 'bp_dtheme_before_comment_form' ); 
  672. endif; 
  673.  
  674. if ( !function_exists( 'bp_dtheme_after_comment_form' ) ) : 
  675. /** 
  676. * Closes tags opened in bp_dtheme_before_comment_form(). 
  677. * 
  678. * @see bp_dtheme_before_comment_form() 
  679. * @see comment_form() 
  680. * @since BuddyPress (1.5) 
  681. */ 
  682. function bp_dtheme_after_comment_form() { 
  683. ?> 
  684.  
  685. </div><!-- .comment-content standard-form --> 
  686.  
  687. <?php 
  688. add_action( 'comment_form', 'bp_dtheme_after_comment_form' ); 
  689. endif; 
  690.  
  691. if ( !function_exists( 'bp_dtheme_sidebar_login_redirect_to' ) ) : 
  692. /** 
  693. * Adds a hidden "redirect_to" input field to the sidebar login form. 
  694. * 
  695. * @since BuddyPress (1.5) 
  696. */ 
  697. function bp_dtheme_sidebar_login_redirect_to() { 
  698. $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; 
  699. $redirect_to = apply_filters( 'bp_no_access_redirect', $redirect_to ); ?> 
  700.  
  701. <input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_to ); ?>" /> 
  702.  
  703. <?php 
  704. add_action( 'bp_sidebar_login_form', 'bp_dtheme_sidebar_login_redirect_to' ); 
  705. endif; 
  706.  
  707. if ( !function_exists( 'bp_dtheme_content_nav' ) ) : 
  708. /** 
  709. * Display navigation to next/previous pages when applicable 
  710. * 
  711. * @global WP_Query $wp_query 
  712. * @param string $nav_id DOM ID for this navigation 
  713. * @since BuddyPress (1.5) 
  714. */ 
  715. function bp_dtheme_content_nav( $nav_id ) { 
  716. global $wp_query; 
  717.  
  718. if ( !empty( $wp_query->max_num_pages ) && $wp_query->max_num_pages > 1 ) : ?> 
  719.  
  720. <div id="<?php echo $nav_id; ?>" class="navigation"> 
  721. <div class="alignleft"><?php next_posts_link( __( '← Previous Entries', 'buddypress' ) ); ?></div> 
  722. <div class="alignright"><?php previous_posts_link( __( 'Next Entries →', 'buddypress' ) ); ?></div> 
  723. </div><!-- #<?php echo $nav_id; ?> --> 
  724.  
  725. <?php endif; 
  726. endif; 
  727.  
  728. /** 
  729. * Adds the no-js class to the body tag. 
  730. * 
  731. * This function ensures that the <body> element will have the 'no-js' class by default. If you're 
  732. * using JavaScript for some visual functionality in your theme, and you want to provide noscript 
  733. * support, apply those styles to body.no-js. 
  734. * 
  735. * The no-js class is removed by the JavaScript created in bp_dtheme_remove_nojs_body_class(). 
  736. * 
  737. * @package BuddyPress 
  738. * @since BuddyPress (1.5).1 
  739. * @see bp_dtheme_remove_nojs_body_class() 
  740. */ 
  741. function bp_dtheme_add_nojs_body_class( $classes ) { 
  742. $classes[] = 'no-js'; 
  743. return array_unique( $classes ); 
  744. add_filter( 'bp_get_the_body_class', 'bp_dtheme_add_nojs_body_class' ); 
  745.  
  746. /** 
  747. * Dynamically removes the no-js class from the <body> element. 
  748. * 
  749. * By default, the no-js class is added to the body (see bp_dtheme_add_no_js_body_class()). The 
  750. * JavaScript in this function is loaded into the <body> element immediately after the <body> tag 
  751. * (note that it's hooked to bp_before_header), and uses JavaScript to switch the 'no-js' body class 
  752. * to 'js'. If your theme has styles that should only apply for JavaScript-enabled users, apply them 
  753. * to body.js. 
  754. * 
  755. * This technique is borrowed from WordPress, wp-admin/admin-header.php. 
  756. * 
  757. * @package BuddyPress 
  758. * @since BuddyPress (1.5).1 
  759. * @see bp_dtheme_add_nojs_body_class() 
  760. */ 
  761. function bp_dtheme_remove_nojs_body_class() { 
  762. ?><script type="text/javascript">//<![CDATA[ 
  763. (function() {var c=document.body.className;c=c.replace(/no-js/, 'js');document.body.className=c;})(); 
  764. //]]></script> 
  765. <?php 
  766. add_action( 'bp_before_header', 'bp_dtheme_remove_nojs_body_class' ); 
  767.  
  768. /** 
  769. * Ensure that multiselect boxes have trailing brackets in their 'id' and 'name' attributes. 
  770. * 
  771. * These brackets are required for an array of values to be sent in the POST 
  772. * request. Previously, bp_get_the_profile_field_input_name() contained the 
  773. * necessary logic, but since BP 2.0 that logic has been moved into 
  774. * BP_XProfile_Field_Type_Multiselectbox. Since bp-default does not use the 
  775. * BP_XProfile_Field_Type classes to build its markup, it did not inherit 
  776. * the brackets from their new location. Thus this workaround. 
  777. */ 
  778. function bp_dtheme_add_brackets_to_multiselectbox_attributes( $name ) { 
  779. global $field; 
  780.  
  781. if ( 'multiselectbox' === $field->type ) { 
  782. $name .= '[]'; 
  783.  
  784. return $name; 
  785. add_filter( 'bp_get_the_profile_field_input_name', 'bp_dtheme_add_brackets_to_multiselectbox_attributes' ); 
.