Advertisement
sorensen84

MeeWork

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