Changeset 2688
- Timestamp:
- 12/06/2010 03:18:19 AM (16 years ago)
- Location:
- branches/plugin
- Files:
-
- 11 added
- 6 deleted
- 9 edited
- 2 moved
-
bbp-admin/bbp-admin.php (modified) (2 diffs)
-
bbp-includes/bbp-forum-template.php (added)
-
bbp-includes/bbp-functions.php (modified) (8 diffs)
-
bbp-includes/bbp-general-template.php (moved) (moved from branches/plugin/bbp-includes/bbp-template.php ) (5 diffs)
-
bbp-includes/bbp-loader.php (modified) (2 diffs)
-
bbp-includes/bbp-reply-template.php (added)
-
bbp-includes/bbp-topic-template.php (added)
-
bbp-includes/bbp-user-template.php (added)
-
bbp-includes/bbp-users.php (modified) (8 diffs)
-
bbp-themes/bbp-twentyten/author.php (deleted)
-
bbp-themes/bbp-twentyten/css/bbpress.css (modified) (1 diff)
-
bbp-themes/bbp-twentyten/functions.php (modified) (3 diffs)
-
bbp-themes/bbp-twentyten/loop-bbp_forums.php (modified) (1 diff)
-
bbp-themes/bbp-twentyten/loop-bbp_topics.php (modified) (3 diffs)
-
bbp-themes/bbp-twentyten/page-bbp_user.php (moved) (moved from branches/plugin/bbp-themes/bbp-twentyten/page-bbp_profile.php )
-
bbp-themes/bbp-twentyten/profile-bbp_details.php (deleted)
-
bbp-themes/bbp-twentyten/profile-bbp_favorites.php (deleted)
-
bbp-themes/bbp-twentyten/profile-bbp_subscriptions.php (deleted)
-
bbp-themes/bbp-twentyten/profile-bbp_topics_created.php (deleted)
-
bbp-themes/bbp-twentyten/profile-posts.php (deleted)
-
bbp-themes/bbp-twentyten/user-bbp_details.php (added)
-
bbp-themes/bbp-twentyten/user-bbp_favorites.php (added)
-
bbp-themes/bbp-twentyten/user-bbp_subscriptions.php (added)
-
bbp-themes/bbp-twentyten/user-bbp_topics_created.php (added)
-
bbp-themes/bbp-twentyten/user-edit.php (added)
-
bbp-themes/bbp-twentyten/user-posts.php (added)
-
bbp-themes/bbp-twentyten/user.php (added)
-
bbpress.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/bbp-admin.php
r2679 r2688 331 331 */ 332 332 function user_profile_update ( $user_id ) { 333 if ( !bbp_has_access() ) 334 return false; 333 return false; 335 334 336 335 // Add extra actions to bbPress profile update … … 346 345 */ 347 346 function user_profile_forums ( $profileuser ) { 348 349 if ( !bbp_has_access() ) 350 return false; 347 return false; 351 348 352 349 ?> -
branches/plugin/bbp-includes/bbp-functions.php
r2684 r2688 307 307 308 308 /** 309 * bbp_edit_user_handler () 310 * 311 * Handles the front end user editing 312 * 313 * @since bbPress (r2688) 314 */ 315 function bbp_edit_user_handler () { 316 317 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && 'bbp-update-user' == $_POST['action'] ) { 318 319 global $errors, $bbp; 320 321 // Execute confirmed email change. See send_confirmation_on_profile_email(). 322 if ( is_multisite() && bbp_is_user_home() && isset( $_GET['newuseremail'] ) && $bbp->displayed_user->ID ) { 323 324 $new_email = get_option( $bbp->displayed_user->ID . '_new_email' ); 325 326 if ( $new_email['hash'] == $_GET['newuseremail'] ) { 327 $user->ID = $bbp->displayed_user->ID; 328 $user->user_email = esc_html( trim( $new_email['newemail'] ) ); 329 330 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $bbp->displayed_user->user_login ) ) ) 331 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $bbp->displayed_user->user_login ) ); 332 333 wp_update_user( get_object_vars( $user ) ); 334 delete_option( $bbp->displayed_user->ID . '_new_email' ); 335 336 wp_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $bbp->displayed_user->ID ) ) ); 337 exit; 338 } 339 340 } elseif ( is_multisite() && bbp_is_user_home() && !empty( $_GET['dismiss'] ) && $bbp->displayed_user->ID . '_new_email' == $_GET['dismiss'] ) { 341 342 delete_option( $bbp->displayed_user->ID . '_new_email' ); 343 wp_redirect( add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $bbp->displayed_user->ID ) ) ); 344 exit; 345 346 } 347 348 check_admin_referer( 'update-user_' . $bbp->displayed_user->ID ); 349 350 if ( !current_user_can( 'edit_user', $bbp->displayed_user->ID ) ) 351 wp_die( __( 'What are you doing here? You don\'t have the permission to edit this user!', 'bbpress' ) ); 352 353 if ( bbp_is_user_home() ) 354 do_action( 'personal_options_update', $bbp->displayed_user->ID ); 355 else 356 do_action( 'edit_user_profile_update', $bbp->displayed_user->ID ); 357 358 if ( !is_multisite() ) { 359 $errors = edit_user( $bbp->displayed_user->ID ); // Handles the trouble for us ;) 360 } else { 361 $user = get_userdata( $bbp->displayed_user->ID ); 362 363 // Update the email address in signups, if present. 364 if ( $user->user_login && isset( $_POST['email'] ) && is_email( $_POST['email' ]) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $user->user_login ) ) ) 365 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $user_login ) ); 366 367 // WPMU must delete the user from the current blog if WP added him after editing. 368 $delete_role = false; 369 $blog_prefix = $wpdb->get_blog_prefix(); 370 371 if ( $bbp->displayed_user->ID != $bbp->displayed_user->ID ) { 372 $cap = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$bbp->displayed_user->ID}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" ); 373 if ( !is_network_admin() && null == $cap && $_POST['role'] == '' ) { 374 $_POST['role'] = 'contributor'; 375 $delete_role = true; 376 } 377 } 378 379 if ( !isset( $errors ) || ( isset( $errors ) && is_object( $errors ) && false == $errors->get_error_codes() ) ) 380 $errors = edit_user( $bbp->displayed_user->ID ); 381 382 if ( $delete_role ) // stops users being added to current blog when they are edited 383 delete_user_meta( $bbp->displayed_user->ID, $blog_prefix . 'capabilities' ); 384 385 if ( is_multisite() && is_network_admin() & !bbp_is_user_home() && current_user_can( 'manage_network_options' ) && !isset( $super_admins ) && empty( $_POST['super_admin'] ) == is_super_admin( $bbp->displayed_user->ID ) ) 386 empty( $_POST['super_admin'] ) ? revoke_super_admin( $bbp->displayed_user->ID ) : grant_super_admin( $bbp->displayed_user->ID ); 387 } 388 389 if ( !is_wp_error( $errors ) ) { 390 $redirect = add_query_arg( array( 'updated' => 'true' ), bbp_get_user_profile_edit_url( $bbp->displayed_user->ID ) ); 391 392 wp_redirect( $redirect ); 393 exit; 394 } 395 396 } 397 398 } 399 add_action( 'template_redirect', 'bbp_edit_user_handler', 1 ); 400 401 /** 309 402 * bbp_new_topic_update_topic () 310 403 * … … 353 446 354 447 /** 448 * bbp_check_for_profile_page () 449 * 450 * Add checks for a user page. If it is, then locate the user page template. 451 * 452 * @since bbPress (r2688) 453 */ 454 function bbp_check_for_profile_page ( $template = '' ) { 455 456 // Viewing a profile 457 if ( bbp_is_user_profile_page() ) { 458 $template = array( 'user.php', 'author.php', 'index.php' ); 459 460 // Editing a profile 461 } elseif ( bbp_is_user_profile_edit() ) { 462 $template = array( 'user-edit.php', 'user.php', 'author.php', 'index.php' ); 463 } 464 465 if ( !$template = apply_filters( 'bbp_check_for_profile_page', $template ) ) 466 return false; 467 468 // Try to load a template file 469 bbp_load_template( $template ); 470 } 471 add_action( 'template_redirect', 'bbp_check_for_profile_page', 2 ); 472 473 /** 474 * bbp_pre_get_posts () 475 * 476 * Add checks for a user page. If it is, then locate the user page template. 477 * 478 * @since bbPress (r2688) 479 */ 480 function bbp_pre_get_posts ( $wp_query ) { 481 global $bbp; 482 483 $bbp_user = get_query_var( 'bbp_user' ); 484 $is_user_edit = get_query_var( 'bbp_edit_profile' ); 485 486 if ( empty( $bbp_user ) ) 487 return; 488 489 // Create new user 490 $user = new WP_User( $bbp_user ); 491 492 // Stop if no user 493 if ( !isset( $user ) || empty( $user ) || empty( $user->ID ) ) { 494 $wp_query->set_404(); 495 return; 496 } 497 498 // Confirmed existence of the bbPress user 499 500 // Define new query variable 501 if ( !empty( $is_user_edit ) ) { 502 503 // Only allow super admins on multisite to edit every user. 504 if ( ( is_multisite() && !current_user_can( 'manage_network_users' ) && $user_id != $current_user->ID && ! apply_filters( 'enable_edit_any_user_configuration', true ) ) || !current_user_can( 'edit_user', $user->ID ) ) 505 wp_die( __( 'You do not have the permission to edit this user.', 'bbpress' ) ); 506 507 $wp_query->bbp_is_user_profile_edit = true; 508 509 // Load the required user editing functions 510 include_once( ABSPATH . 'wp-includes/registration.php' ); 511 require_once( ABSPATH . 'wp-admin/includes/user.php' ); 512 513 } else { 514 $wp_query->bbp_is_user_profile_page = true; 515 } 516 517 // Set query variables 518 $wp_query->is_home = false; // Correct is_home variable 519 $wp_query->query_vars['bbp_user_id'] = $user->ID; // Set bbp_user_id for future reference 520 $wp_query->query_vars['author_name'] = $user->user_nicename; // Set author_name as current user's nicename to get correct posts 521 522 // Set the displayed user global to this user 523 $bbp->displayed_user = $user; 524 525 add_filter( 'wp_title', 'bbp_profile_page_title', 10, 3 ); // Correct wp_title 526 } 527 add_action( 'pre_get_posts', 'bbp_pre_get_posts', 100 ); 528 529 /** 530 * bbp_profile_page_title () 531 * 532 * Custom wp_title for bbPress User Profile Pages 533 * 534 * @since bbPress (r2688) 535 * 536 * @param string $title Optional. The title (not used). 537 * @param string $sep Optional, default is '»'. How to separate the various items within the page title. 538 * @param string $seplocation Optional. Direction to display title, 'right'. 539 * @return string The tite 540 */ 541 function bbp_profile_page_title ( $title = '', $sep = '»', $seplocation = '' ) { 542 $userdata = get_userdata( get_query_var( 'bbp_user_id' ) ); 543 $title = apply_filters( 'bbp_profile_page_wp_raw_title', $userdata->display_name, $sep, $seplocation ); 544 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary 545 546 $prefix = ''; 547 if ( !empty( $title ) ) 548 $prefix = " $sep "; 549 550 // Determines position of the separator and direction of the breadcrumb 551 if ( 'right' == $seplocation ) { // sep on right, so reverse the order 552 $title_array = explode( $t_sep, $title ); 553 $title_array = array_reverse( $title_array ); 554 $title = implode( " $sep ", $title_array ) . $prefix; 555 } else { 556 $title_array = explode( $t_sep, $title ); 557 $title = $prefix . implode( " $sep ", $title_array ); 558 } 559 560 $title = apply_filters( 'bbp_profile_page_wp_title', $title, $sep, $seplocation ); 561 562 return $title; 563 } 564 565 /** 355 566 * bbp_load_template( $files ) 356 567 * … … 473 684 474 685 // Load user info 475 $current_user = wp_get_current_user(); 476 $user_id = $current_user->ID; 686 if ( bbp_is_favorites( false ) ) { 687 $user_id = get_query_var( 'bbp_user_id' ); 688 } else { 689 $current_user = wp_get_current_user(); 690 $user_id = $current_user->ID; 691 } 477 692 478 693 // Check current user's ability to edit the user … … 500 715 501 716 // Redirect back to new reply 502 $redirect = bbp_is_favorites( ) ? bbp_get_favorites_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id );717 $redirect = bbp_is_favorites( false ) ? bbp_get_favorites_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id ); 503 718 wp_redirect( $redirect ); 504 719 … … 509 724 } 510 725 } 511 add_action( 'template_redirect', 'bbp_favorites_handler' );726 add_action( 'template_redirect', 'bbp_favorites_handler', 1 ); 512 727 513 728 /** … … 569 784 570 785 // Load user info 571 $current_user = wp_get_current_user(); 572 $user_id = $current_user->ID; 786 if ( bbp_is_subscriptions( false ) ) { 787 $user_id = get_query_var( 'bbp_user_id' ); 788 } else { 789 $current_user = wp_get_current_user(); 790 $user_id = $current_user->ID; 791 } 573 792 574 793 // Check current user's ability to edit the user … … 595 814 596 815 // Redirect back to new reply 597 $redirect = bbp_ get_topic_permalink( $topic_id );816 $redirect = bbp_is_subscriptions( false ) ? bbp_get_subscriptions_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id ); 598 817 wp_redirect( $redirect ); 599 818 … … 604 823 } 605 824 } 606 add_action( 'template_redirect', 'bbp_subscriptions_handler' );825 add_action( 'template_redirect', 'bbp_subscriptions_handler', 1 ); 607 826 608 827 /** -
branches/plugin/bbp-includes/bbp-general-template.php
r2687 r2688 33 33 /** END - WordPress Add-on Actions ********************************************/ 34 34 35 /** START - Forum Loop Functions **********************************************/36 37 /**38 * bbp_has_forums ()39 *40 * The main forum loop. WordPress makes this easy for us41 *42 * @package bbPress43 * @subpackage Template Tags44 * @since bbPress (r2464)45 *46 * @global WP_Query $bbp_forums_template47 * @param array $args Possible arguments to change returned forums48 * @return object Multidimensional array of forum information49 */50 function bbp_has_forums ( $args = '' ) {51 global $wp_query, $bbp_forums_template, $bbp;52 53 $default = array (54 'post_type' => $bbp->forum_id,55 'post_parent' => bbp_get_forum_id(),56 'posts_per_page' => -1,57 'orderby' => 'menu_order',58 'order' => 'ASC'59 );60 61 $r = wp_parse_args( $args, $default );62 63 $bbp_forums_template = new WP_Query( $r );64 65 return apply_filters( 'bbp_has_forums', $bbp_forums_template->have_posts(), $bbp_forums_template );66 }67 68 /**69 * bbp_forums ()70 *71 * Whether there are more forums available in the loop72 *73 * @package bbPress74 * @subpackage Template Tags75 * @since bbPress (r2464)76 *77 * @global WP_Query $bbp_forums_template78 * @return object Forum information79 */80 function bbp_forums () {81 global $bbp_forums_template;82 return $bbp_forums_template->have_posts();83 }84 85 /**86 * bbp_the_forum ()87 *88 * Loads up the current forum in the loop89 *90 * @package bbPress91 * @subpackage Template Tags92 * @since bbPress (r2464)93 *94 * @global WP_Query $bbp_forums_template95 * @return object Forum information96 */97 function bbp_the_forum () {98 global $bbp_forums_template;99 return $bbp_forums_template->the_post();100 }101 102 /** FORUM *********************************************************************/103 104 /**105 * bbp_forum_id ()106 *107 * Output id from bbp_forum_id()108 *109 * @package bbPress110 * @subpackage Template Tags111 * @since bbPress (r2464)112 *113 * @uses bbp_get_forum_id()114 */115 function bbp_forum_id () {116 echo bbp_get_forum_id();117 }118 /**119 * bbp_get_forum_id ()120 *121 * Return the forum ID122 *123 * @package bbPress124 * @subpackage Template Tags125 * @since bbPress (r2464)126 *127 * @param $forum_id Use to check emptiness128 * @global object $forums_template129 * @return string Forum id130 */131 function bbp_get_forum_id ( $forum_id = 0 ) {132 global $bbp_forums_template, $wp_query, $bbp;133 134 // Easy empty checking135 if ( !empty( $forum_id ) && is_numeric( $forum_id ) )136 $bbp_forum_id = $forum_id;137 138 // Currently inside a forum loop139 elseif ( !empty( $bbp_forums_template->in_the_loop ) && isset( $bbp_forums_template->post->ID ) )140 $bbp_forum_id = $bbp_forums_template->post->ID;141 142 // Currently viewing a forum143 elseif ( bbp_is_forum() && isset( $wp_query->post->ID ) )144 $bbp_forum_id = $wp_query->post->ID;145 146 // Currently viewing a topic147 elseif ( bbp_is_topic() )148 $bbp_forum_id = bbp_get_topic_forum_id();149 150 // Fallback151 else152 $bbp_forum_id = 0;153 154 // Set global155 $bbp->current_forum_id = $bbp_forum_id;156 157 return apply_filters( 'bbp_get_forum_id', (int)$bbp_forum_id );158 }159 160 /**161 * bbp_forum_permalink ()162 *163 * Output the link to the forum164 *165 * @package bbPress166 * @subpackage Template Tags167 * @since bbPress (r2464)168 *169 * @param int $forum_id optional170 * @uses bbp_get_forum_permalink()171 */172 function bbp_forum_permalink ( $forum_id = 0 ) {173 echo bbp_get_forum_permalink( $forum_id );174 }175 /**176 * bbp_get_forum_permalink ()177 *178 * Return the link to the forum179 *180 * @package bbPress181 * @subpackage Template Tags182 * @since bbPress (r2464)183 *184 * @param int $forum_id optional185 * @uses apply_filters186 * @uses get_permalink187 * @return string Permanent link to forum188 */189 function bbp_get_forum_permalink ( $forum_id = 0 ) {190 $forum_id = bbp_get_forum_id( $forum_id );191 return apply_filters( 'bbp_get_forum_permalink', get_permalink( $forum_id ) );192 }193 194 /**195 * bbp_forum_title ()196 *197 * Output the title of the forum in the loop198 *199 * @package bbPress200 * @subpackage Template Tags201 * @since bbPress (r2464)202 *203 * @param int $forum_id optional204 * @uses bbp_get_forum_title()205 */206 function bbp_forum_title ( $forum_id = 0 ) {207 echo bbp_get_forum_title( $forum_id );208 }209 /**210 * bbp_get_forum_title ()211 *212 * Return the title of the forum in the loop213 *214 * @package bbPress215 * @subpackage Template Tags216 * @since bbPress (r2464)217 *218 * @param int $forum_id optional219 * @uses apply_filters220 * @uses get_the_title()221 * @return string Title of forum222 *223 */224 function bbp_get_forum_title ( $forum_id = 0 ) {225 $forum_id = bbp_get_forum_id( $forum_id );226 227 return apply_filters( 'bbp_get_forum_title', get_the_title( $forum_id ) );228 }229 230 /**231 * bbp_forum_last_active ()232 *233 * Output the forums last update date/time (aka freshness)234 *235 * @package bbPress236 * @subpackage Template Tags237 * @since bbPress (r2464)238 *239 * @uses bbp_get_forum_last_active()240 * @param int $forum_id optional241 */242 function bbp_forum_last_active ( $forum_id = 0 ) {243 echo bbp_get_forum_last_active( $forum_id );244 }245 /**246 * bbp_get_forum_last_active ()247 *248 * Return the forums last update date/time (aka freshness)249 *250 * @package bbPress251 * @subpackage Template Tags252 * @since bbPress (r2464)253 *254 * @return string255 * @param int $forum_id optional256 */257 function bbp_get_forum_last_active ( $forum_id = 0 ) {258 $forum_id = bbp_get_forum_id( $forum_id );259 260 if ( !$last_active = get_post_meta( $forum_id, '_bbp_forum_last_active', true ) ) {261 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {262 $last_active = get_post_field( 'post_date', $reply_id );263 } else {264 if ( $topic_id = bbp_get_forum_last_topic_id( $forum_id ) ) {265 $last_active = bbp_get_topic_last_active( $forum_id, '_bbp_forum_last_active', true );266 }267 }268 }269 270 $last_active = !empty( $last_active ) ? bbp_get_time_since( bbp_get_modified_time( $last_active ) ) : '';271 272 return apply_filters( 'bbp_get_forum_last_active', $last_active );273 }274 275 /**276 * bbp_get_forum_parent ()277 *278 * Return ID of forum parent, if exists279 *280 * @package bbPress281 * @subpackage Template Tags282 * @since bbPress (r2625)283 *284 * @param int $forum_id285 * @return int286 */287 function bbp_get_forum_parent ( $forum_id = 0 ) {288 $forum_id = bbp_get_forum_id( $forum_id );289 return apply_filters( 'bbp_get_forum_parent', (int)get_post_field( 'post_parent', $forum_id ) );290 }291 292 /**293 * bbp_get_forum_ancestors ()294 *295 * Return array of parent forums296 *297 * @package bbPress298 * @subpackage Template Tags299 * @since bbPress (r2625)300 *301 * @param int $forum_id302 * @return array303 */304 function bbp_get_forum_ancestors ( $forum_id = 0 ) {305 $forum_id = bbp_get_forum_id( $forum_id );306 307 if ( $forum = get_post( $forum_id ) ) {308 $ancestors = array();309 while ( 0 !== $forum->post_parent ) {310 $ancestors[] = $forum->post_parent;311 $forum = get_post( $forum->post_parent );312 }313 }314 315 return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );316 }317 318 /**319 * bbp_forum_has_sub_forums ()320 *321 * Return if forum has sub forums322 *323 * @package bbPress324 * @subpackage Template Tags325 * @since bbPress (r2625)326 *327 * @param int $forum_id328 * @return false if none, array of subs if yes329 */330 function bbp_forum_has_sub_forums( $forum_id = 0 ) {331 $forum_id = bbp_get_forum_id( $forum_id );332 $has_subs = false;333 334 if ( !empty( $forum_id ) )335 $has_subs = bbp_get_sub_forums( $forum_id );336 337 return apply_filters( 'bbp_forum_has_sub_forums', $has_subs );338 }339 340 /** FORUM LAST TOPIC **********************************************************/341 342 /**343 * bbp_forum_last_topic_id ()344 *345 * Output the forums last topic id346 *347 * @package bbPress348 * @subpackage Template Tags349 * @since bbPress (r2464)350 *351 * @uses bbp_get_forum_last_active()352 * @param int $forum_id optional353 */354 function bbp_forum_last_topic_id ( $forum_id = 0 ) {355 echo bbp_get_forum_last_topic_id( $forum_id );356 }357 /**358 * bbp_get_forum_last_topic_id ()359 *360 * Return the forums last topic361 *362 * @package bbPress363 * @subpackage Template Tags364 * @since bbPress (r2464)365 *366 * @return string367 * @param int $forum_id optional368 */369 function bbp_get_forum_last_topic_id ( $forum_id = 0 ) {370 $forum_id = bbp_get_forum_id( $forum_id );371 $topic_id = get_post_meta( $forum_id, '_bbp_forum_last_topic_id', true );372 373 return apply_filters( 'bbp_get_forum_last_topic_id', $topic_id );374 }375 376 /**377 * bbp_forum_last_topic_title ()378 *379 * Output the title of the last topic inside a forum380 *381 * @package bbPress382 * @subpackage Template Tags383 * @since bbPress (r2625)384 *385 * @param int $forum_id386 */387 function bbp_forum_last_topic_title ( $forum_id = 0 ) {388 echo bbp_get_forum_last_topic_title( $forum_id );389 }390 /**391 * bbp_get_forum_last_topic_title ()392 *393 * Return the title of the last topic inside a forum394 *395 * @package bbPress396 * @subpackage Template Tags397 * @since bbPress (r2625)398 *399 * @param int $forum_id400 * @return string401 */402 function bbp_get_forum_last_topic_title( $forum_id = 0 ) {403 $forum_id = bbp_get_forum_id( $forum_id );404 return apply_filters( 'bbp_get_forum_last_topic_title', bbp_get_topic_title( bbp_get_forum_last_topic_id( $forum_id ) ) );405 }406 407 /**408 * bbp_forum_last_topic_permalink ()409 *410 * Output the link to the last topic in a forum411 *412 * @package bbPress413 * @subpackage Template Tags414 * @since bbPress (r2464)415 *416 * @param int $forum_id optional417 * @uses bbp_get_forum_permalink()418 */419 function bbp_forum_last_topic_permalink ( $forum_id = 0 ) {420 echo bbp_get_forum_last_topic_permalink( $forum_id );421 }422 /**423 * bbp_get_forum_last_topic_permalink ()424 *425 * Return the link to the last topic in a forum426 *427 * @package bbPress428 * @subpackage Template Tags429 * @since bbPress (r2464)430 *431 * @param int $forum_id optional432 * @uses apply_filters433 * @uses get_permalink434 * @return string Permanent link to topic435 */436 function bbp_get_forum_last_topic_permalink ( $forum_id = 0 ) {437 $forum_id = bbp_get_forum_id( $forum_id );438 return apply_filters( 'bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink( bbp_get_forum_last_topic_id( $forum_id ) ) );439 }440 441 /** FORUM LAST REPLY **********************************************************/442 443 /**444 * bbp_forum_last_reply_id ()445 *446 * Output the forums last reply id447 *448 * @package bbPress449 * @subpackage Template Tags450 * @since bbPress (r2464)451 *452 * @uses bbp_get_forum_last_reply_id()453 * @param int $forum_id optional454 */455 function bbp_forum_last_reply_id ( $forum_id = 0 ) {456 echo bbp_get_forum_last_reply_id( $forum_id );457 }458 /**459 * bbp_get_forum_last_reply_id ()460 *461 * Return the forums last reply id462 *463 * @package bbPress464 * @subpackage Template Tags465 * @since bbPress (r2464)466 *467 * @return string468 * @param int $forum_id optional469 */470 function bbp_get_forum_last_reply_id ( $forum_id = 0 ) {471 $forum_id = bbp_get_forum_id( $forum_id );472 $reply_id = get_post_meta( $forum_id, '_bbp_forum_last_reply_id', true );473 474 if ( '' === $reply_id )475 $reply_id = bbp_update_forum_last_reply_id( $forum_id );476 477 return apply_filters( 'bbp_get_forum_last_reply_id', $reply_id );478 }479 480 /**481 * bbp_forum_last_reply_title ()482 *483 * Output the title of the last reply inside a forum484 *485 * @param int $forum_id486 */487 function bbp_forum_last_reply_title ( $forum_id = 0 ) {488 echo bbp_get_forum_last_reply_title( $forum_id );489 }490 /**491 * bbp_get_forum_last_reply_title ()492 *493 * Return the title of the last reply inside a forum494 *495 * @param int $forum_id496 * @return string497 */498 function bbp_get_forum_last_reply_title( $forum_id = 0 ) {499 $forum_id = bbp_get_forum_id( $forum_id );500 return apply_filters( 'bbp_get_forum_last_topic_title', bbp_get_reply_title( bbp_get_forum_last_reply_id( $forum_id ) ) );501 }502 503 /**504 * bbp_forum_last_reply_permalink ()505 *506 * Output the link to the last reply in a forum507 *508 * @package bbPress509 * @subpackage Template Tags510 * @since bbPress (r2464)511 *512 * @param int $forum_id optional513 * @uses bbp_get_forum_permalink()514 */515 function bbp_forum_last_reply_permalink ( $forum_id = 0 ) {516 echo bbp_get_forum_last_reply_permalink( $forum_id );517 }518 /**519 * bbp_get_forum_last_reply_permalink ()520 *521 * Return the link to the last reply in a forum522 *523 * @package bbPress524 * @subpackage Template Tags525 * @since bbPress (r2464)526 *527 * @param int $forum_id optional528 * @uses apply_filters529 * @uses get_permalink530 * @return string Permanent link to topic531 */532 function bbp_get_forum_last_reply_permalink ( $forum_id = 0 ) {533 $forum_id = bbp_get_forum_id( $forum_id );534 return apply_filters( 'bbp_get_forum_last_reply_permalink', bbp_get_reply_permalink( bbp_get_forum_last_reply_id( $forum_id ) ) );535 }536 537 /**538 * bbp_forum_last_reply_url ()539 *540 * Output the link to the last reply in a forum541 *542 * @package bbPress543 * @subpackage Template Tags544 * @since bbPress (r2683)545 *546 * @param int $forum_id optional547 * @uses bbp_get_forum_url()548 */549 function bbp_forum_last_reply_url ( $forum_id = 0 ) {550 echo bbp_get_forum_last_reply_url( $forum_id );551 }552 /**553 * bbp_get_forum_last_reply_url ()554 *555 * Return the link to the last reply in a forum556 *557 * @package bbPress558 * @subpackage Template Tags559 * @since bbPress (r2683)560 *561 * @param int $forum_id optional562 * @uses apply_filters563 * @uses get_url564 * @return string Paginated URL to latest reply565 */566 function bbp_get_forum_last_reply_url ( $forum_id = 0 ) {567 $forum_id = bbp_get_forum_id( $forum_id );568 569 // If forum has replies, get the last reply and use its url570 if ( $reply_id = bbp_get_forum_last_reply_id( $forum_id ) ) {571 $reply_url = bbp_get_reply_url( $reply_id );572 573 // No replies, so look for topics and use last permalink574 } else {575 if ( $topic_id = bbp_get_forum_last_topic_id( $forum_id ) ) {576 $reply_url = bbp_get_topic_permalink( $topic_id );577 578 // No topics either, so set $reply_url as empty579 } else {580 $reply_url = '';581 }582 }583 584 // Filter and return585 return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url );586 }587 588 /**589 * bbp_forum_freshness_link ()590 *591 * Output link to the most recent activity inside a forum, complete with592 * link attributes and content.593 *594 * @package bbPress595 * @subpackage Template Tags596 * @since bbPress (r2625)597 *598 * @param int $forum_id599 */600 function bbp_forum_freshness_link ( $forum_id = 0) {601 echo bbp_get_forum_freshness_link( $forum_id );602 }603 /**604 * bbp_get_forum_freshness_link ()605 *606 * Returns link to the most recent activity inside a forum, complete with607 * link attributes and content.608 *609 * @package bbPress610 * @subpackage Template Tags611 * @since bbPress (r2625)612 *613 * @param int $forum_id614 */615 function bbp_get_forum_freshness_link ( $forum_id = 0 ) {616 $forum_id = bbp_get_forum_id( $forum_id );617 $link_url = bbp_get_forum_last_reply_url( $forum_id );618 $title = bbp_get_forum_last_reply_title( $forum_id );619 $time_since = bbp_get_forum_last_active( $forum_id );620 621 if ( !empty( $time_since ) )622 $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>';623 else624 $anchor = __( 'No Topics', 'bbpress' );625 626 return apply_filters( 'bbp_get_forum_freshness_link', $anchor );627 }628 629 /**630 * bbp_get_forum_last_topic_author_id ()631 *632 * Return the author ID of the last topic of a forum633 *634 * @package bbPress635 * @subpackage Template Tags636 * @since bbPress (r2625)637 *638 * @param int $forum_id639 */640 function bbp_get_forum_last_topic_author_id ( $forum_id = 0 ) {641 $forum_id = bbp_get_forum_id( $forum_id );642 $author_id = get_post_field( 'post_author', bbp_get_forum_last_topic_id( $forum_id ) );643 return apply_filters( 'bbp_get_forum_last_topic_author', $author_id );644 }645 646 /**647 * bbp_forum_last_topic_author_link ()648 *649 * Output link to author of last topic of forum650 *651 * @package bbPress652 * @subpackage Template Tags653 * @since bbPress (r2625)654 *655 * @param int $forum_id656 */657 function bbp_forum_last_topic_author_link ( $forum_id = 0 ) {658 echo bbp_get_forum_last_topic_author_link( $forum_id );659 }660 /**661 * bbp_get_forum_last_topic_author_link ()662 *663 * Return link to author of last topic of forum664 *665 * @package bbPress666 * @subpackage Template Tags667 * @since bbPress (r2625)668 *669 * @param int $forum_id670 * @return string671 */672 function bbp_get_forum_last_topic_author_link ( $forum_id = 0 ) {673 $forum_id = bbp_get_forum_id( $forum_id );674 $author_id = bbp_get_forum_last_topic_author_id( $forum_id );675 $name = get_the_author_meta( 'display_name', $author_id );676 $author_link = '<a href="' . get_author_posts_url( $author_id ) . '" title="' . esc_attr( $name ) . '">' . $name . '</a>';677 return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link );678 }679 680 /**681 * bbp_forum_last_reply_author_id ()682 *683 * Output author ID of last reply of forum684 *685 * @package bbPress686 * @subpackage Template Tags687 * @since bbPress (r2625)688 *689 * @param int $forum_id690 */691 function bbp_forum_last_reply_author_id ( $forum_id = 0 ) {692 echo bbp_get_forum_last_reply_author_id( $forum_id );693 }694 /**695 * bbp_get_forum_last_reply_author_id ()696 *697 * Return author ID of last reply of forum698 *699 * @package bbPress700 * @subpackage Template Tags701 * @since bbPress (r2625)702 *703 * @param int $forum_id704 */705 function bbp_get_forum_last_reply_author_id ( $forum_id = 0 ) {706 $forum_id = bbp_get_forum_id( $forum_id );707 $author_id = get_post_field( 'post_author', bbp_get_forum_last_reply_id( $forum_id ) );708 return apply_filters( 'bbp_get_forum_last_reply_author', $author_id );709 }710 711 /**712 * bbp_forum_last_reply_author_link ()713 *714 * Output link to author of last reply of forum715 *716 * @package bbPress717 * @subpackage Template Tags718 * @since bbPress (r2625)719 *720 * @param int $forum_id721 */722 function bbp_forum_last_reply_author_link ( $forum_id = 0 ) {723 echo bbp_get_forum_last_reply_author_link( $forum_id );724 }725 /**726 * bbp_get_forum_last_reply_author_link ()727 *728 * Return link to author of last reply of forum729 *730 * @package bbPress731 * @subpackage Template Tags732 * @since bbPress (r2625)733 *734 * @param int $forum_id735 * @return string736 */737 function bbp_get_forum_last_reply_author_link ( $forum_id = 0 ) {738 $forum_id = bbp_get_forum_id( $forum_id );739 $author_id = bbp_get_forum_last_reply_author_id( $forum_id );740 $name = get_the_author_meta( 'display_name', $author_id );741 $author_link = '<a href="' . get_author_posts_url( $author_id ) . '" title="' . esc_attr( $name ) . '">' . $name . '</a>';742 return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link );743 }744 745 /** FORUM COUNTS **************************************************************/746 747 /**748 * bbp_forum_subforum_count ()749 *750 * Output total sub-forum count of a forum751 *752 * @package bbPress753 * @subpackage Template Tags754 * @since bbPress (r2464)755 *756 * @uses bbp_get_forum_subforum_count()757 * @param int $forum_id optional Forum ID to check758 */759 function bbp_forum_subforum_count ( $forum_id = 0 ) {760 echo bbp_get_forum_subforum_count( $forum_id );761 }762 /**763 * bbp_get_forum_subforum_count ()764 *765 * Return total sub-forum count of a forum766 *767 * @package bbPress768 * @subpackage Template Tags769 * @since bbPress (r2464)770 *771 * @uses bbp_get_forum_id772 * @uses get_pages773 * @uses apply_filters774 *775 * @param int $forum_id optional Forum ID to check776 */777 function bbp_get_forum_subforum_count ( $forum_id = 0 ) {778 $forum_id = bbp_get_forum_id( $forum_id );779 $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );780 781 if ( '' === $forum_count )782 $forum_count = bbp_update_forum_subforum_count( $forum_id );783 784 return apply_filters( 'bbp_get_forum_subforum_count', $forum_count );785 }786 787 /**788 * bbp_forum_topic_count ()789 *790 * Output total topic count of a forum791 *792 * @package bbPress793 * @subpackage Template Tags794 * @since bbPress (r2464)795 *796 * @uses bbp_get_forum_topic_count()797 * @param int $forum_id optional Forum ID to check798 */799 function bbp_forum_topic_count ( $forum_id = 0 ) {800 echo bbp_get_forum_topic_count( $forum_id );801 }802 /**803 * bbp_get_forum_topic_count ()804 *805 * Return total topic count of a forum806 *807 * @package bbPress808 * @subpackage Template Tags809 * @since bbPress (r2464)810 *811 * @todo stash and cache (see commented out code)812 *813 * @uses bbp_get_forum_id814 * @uses get_pages815 * @uses apply_filters816 *817 * @param int $forum_id optional Forum ID to check818 */819 function bbp_get_forum_topic_count ( $forum_id = 0 ) {820 $forum_id = bbp_get_forum_id( $forum_id );821 $topics = get_post_meta( $forum_id, '_bbp_forum_topic_count', true );822 823 if ( '' === $topics )824 $topics = bbp_update_forum_topic_count( $forum_id );825 826 return apply_filters( 'bbp_get_forum_topic_count', $topics );827 }828 829 /**830 * bbp_forum_reply_count ()831 *832 * Output total reply count of a forum833 *834 * @package bbPress835 * @subpackage Template Tags836 * @since bbPress (r2464)837 *838 * @uses bbp_get_forum_topic_reply_count()839 * @param int $forum_id optional840 */841 function bbp_forum_reply_count ( $forum_id = 0 ) {842 echo bbp_get_forum_reply_count( $forum_id );843 }844 /**845 * bbp_forum_reply_count ()846 *847 * Return total post count of a forum848 *849 * @package bbPress850 * @subpackage Template Tags851 * @since bbPress (r2464)852 *853 * @todo stash and cache (see commented out code)854 *855 * @uses bbp_get_forum_id()856 * @uses get_pages857 * @uses apply_filters858 *859 * @param int $forum_id optional860 */861 function bbp_get_forum_reply_count ( $forum_id = 0 ) {862 $forum_id = bbp_get_forum_id( $forum_id );863 $replies = get_post_meta( $forum_id, '_bbp_forum_reply_count', true );864 865 if ( '' === $replies )866 $replies = bbp_update_forum_reply_count( $forum_id );867 868 return apply_filters( 'bbp_get_forum_reply_count', (int)$replies );869 }870 871 /**872 * bbp_forum_voice_count ()873 *874 * Output total voice count of a forum875 *876 * @package bbPress877 * @subpackage Template Tags878 * @since bbPress (r2567)879 *880 * @uses bbp_get_forum_voice_count()881 * @uses apply_filters882 *883 * @param int $forum_id884 */885 function bbp_forum_voice_count ( $forum_id = 0 ) {886 echo bbp_get_forum_voice_count( $forum_id );887 }888 /**889 * bbp_get_forum_voice_count ()890 *891 * Return total voice count of a forum892 *893 * @package bbPress894 * @subpackage Template Tags895 * @since bbPress (r2567)896 *897 * @uses bbp_get_forum_id()898 * @uses apply_filters899 *900 * @param int $forum_id901 *902 * @return int Voice count of the forum903 */904 function bbp_get_forum_voice_count ( $forum_id = 0 ) {905 $forum_id = bbp_get_forum_id( $forum_id );906 $voices = get_post_meta( $forum_id, '_bbp_forum_voice_count', true );907 908 if ( '' === $voices )909 $voices = bbp_update_forum_voice_count( $forum_id );910 911 return apply_filters( 'bbp_get_forum_voice_count', (int)$voices, $forum_id );912 }913 914 /**915 * bbp_forum_status ()916 *917 * Output the status of the forum in the loop918 *919 * @package bbPress920 * @subpackage Template Tags921 * @since bbPress (r2667)922 * @param int $forum_id optional923 *924 * @uses bbp_get_forum_status()925 */926 function bbp_forum_status ( $forum_id = 0 ) {927 echo bbp_get_forum_status( $forum_id );928 }929 /**930 * bbp_get_forum_status ()931 *932 * Return the status of the forum in the loop933 *934 * @package bbPress935 * @subpackage Template Tags936 * @since bbPress (r2667)937 *938 * @uses apply_filters939 * @uses get_post_status()940 * @param int $forum_id optional941 *942 * @return string Status of forum943 */944 function bbp_get_forum_status ( $forum_id = 0 ) {945 $forum_id = bbp_get_forum_id( $forum_id );946 947 return apply_filters( 'bbp_get_forum_status', get_post_status( $forum_id ) );948 }949 950 /**951 * bbp_forum_class ()952 *953 * Output the row class of a forum954 *955 * @package bbPress956 * @subpackage Template Tags957 * @since bbPress (r2667)958 */959 function bbp_forum_class ( $forum_id = 0 ) {960 echo bbp_get_forum_class( $forum_id );961 }962 /**963 * bbp_get_forum_class ()964 *965 * Return the row class of a forum966 *967 * @package bbPress968 * @subpackage Template Tags969 * @since bbPress (r2667)970 *971 * @global WP_Query $bbp_forums_template972 * @param int $forum_id973 * @return string974 */975 function bbp_get_forum_class ( $forum_id = 0 ) {976 global $bbp_forums_template;977 978 $alternate = $bbp_forums_template->current_post % 2 ? '' : 'alternate';979 $status = 'status-' . bbp_get_forum_status();980 $post = post_class( array( $alternate, $status ) );981 982 return apply_filters( 'bbp_get_forum_class', $post );983 }984 985 /** Forum Updaters ************************************************************/986 987 /**988 * bbp_update_forum_last_topic_id ()989 *990 * Update the forum last topic id991 *992 * @package bbPress993 * @subpackage Template Tags994 * @since bbPress (r2625)995 *996 * @todo everything997 * @param int $forum_id998 */999 function bbp_update_forum_last_topic_id ( $forum_id = 0, $topic_id = 0 ) {1000 $forum_id = bbp_get_forum_id( $forum_id );1001 $topic_id = bbp_get_topic_id( $topic_id );1002 1003 // Update the last reply ID1004 if ( !empty( $topic_id ) ) {1005 update_post_meta( $forum_id, '_bbp_forum_last_topic_id', $topic_id );1006 return true;1007 }1008 1009 return false;1010 }1011 1012 /**1013 * bbp_update_forum_last_reply_id ()1014 *1015 * Update the forum last reply id1016 *1017 * @package bbPress1018 * @subpackage Template Tags1019 * @since bbPress (r2625)1020 *1021 * @todo everything1022 * @param int $forum_id1023 */1024 function bbp_update_forum_last_reply_id ( $forum_id = 0, $reply_id = 0 ) {1025 $forum_id = bbp_get_forum_id( $forum_id );1026 $reply_id = bbp_get_reply_id( $reply_id );1027 1028 // Update the last reply ID1029 if ( !empty( $reply_id ) ) {1030 update_post_meta( $forum_id, '_bbp_forum_last_reply_id', $reply_id );1031 return true;1032 }1033 1034 return false;1035 }1036 1037 /**1038 * bbp_update_forum_last_active ()1039 *1040 * Update the forums last active date/time (aka freshness)1041 *1042 * @package bbPress1043 * @subpackage Template Tags1044 * @since bbPress (r2680)1045 *1046 * @param int $forum_id optional1047 *1048 * @return string1049 */1050 function bbp_update_forum_last_active ( $forum_id = 0, $new_time = '' ) {1051 $forum_id = bbp_get_forum_id( $forum_id );1052 1053 // Check time and use current if empty1054 if ( empty( $new_time ) )1055 $new_time = current_time( 'mysql' );1056 1057 // Update the last reply ID1058 if ( !empty( $forum_id ) ) {1059 update_post_meta( $forum_id, '_bbp_forum_last_active', $new_time );1060 return true;1061 }1062 1063 return false;1064 }1065 1066 /**1067 * bbp_update_forum_subforum_count ()1068 *1069 * Update the forum sub-forum count1070 *1071 * @package bbPress1072 * @subpackage Template Tags1073 * @since bbPress (r2625)1074 *1075 * @todo everything1076 * @param int $forum_id1077 */1078 function bbp_update_forum_subforum_count ( $forum_id = 0 ) {1079 $forum_id = bbp_get_forum_id( $forum_id );1080 }1081 1082 /**1083 * bbp_update_forum_topic_count ()1084 *1085 * Adjust the total topic count of a forum1086 *1087 * @package bbPress1088 * @subpackage Template Tags1089 * @since bbPress (r2464)1090 *1091 * @param int $forum_id optional1092 * @return int1093 */1094 function bbp_update_forum_topic_count ( $forum_id = 0 ) {1095 global $wpdb, $bbp;1096 1097 $forum_id = bbp_get_forum_id( $forum_id );1098 1099 // If it's a reply, then get the parent (topic id)1100 if ( $bbp->topic_id == get_post_field( 'post_type', $forum_id ) )1101 $forum_id = get_post_field( 'post_parent', $forum_id );1102 1103 // Get topics count1104 $topics = count( $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->topic_id . "';", $forum_id ) ) );1105 1106 // Update the count1107 update_post_meta( $forum_id, '_bbp_forum_topic_count', (int)$topics );1108 1109 return apply_filters( 'bbp_update_forum_topic_count', (int)$topics );1110 }1111 1112 /**1113 * bbp_update_forum_reply_count ()1114 *1115 * Adjust the total post count of a forum1116 *1117 * @package bbPress1118 * @subpackage Template Tags1119 * @since bbPress (r2464)1120 *1121 * @uses bbp_get_forum_id(01122 * @uses apply_filters1123 *1124 * @param int $forum_id optional1125 *1126 * @return int1127 */1128 function bbp_update_forum_reply_count ( $forum_id = 0 ) {1129 global $wpdb, $bbp;1130 1131 $forum_id = bbp_get_forum_id( $forum_id );1132 1133 // If it's a reply, then get the parent (topic id)1134 if ( $bbp->reply_id == get_post_field( 'post_type', $forum_id ) )1135 $forum_id = get_post_field( 'post_parent', $forum_id );1136 1137 // There should always be at least 1 voice1138 $replies = count( $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "';", $forum_id ) ) );1139 1140 // Update the count1141 update_post_meta( $forum_id, '_bbp_forum_reply_count', (int)$replies );1142 1143 return apply_filters( 'bbp_update_forum_reply_count', (int)$replies );1144 }1145 1146 /**1147 * bbp_update_forum_voice_count ()1148 *1149 * Adjust the total voice count of a forum1150 *1151 * @package bbPress1152 * @subpackage Template Tags1153 * @since bbPress (r2567)1154 *1155 * @uses bbp_get_forum_id()1156 * @uses wpdb1157 * @uses apply_filters1158 *1159 * @todo cache1160 *1161 * @param int $forum_id optional Topic ID to update1162 *1163 * @return bool false on failure, voice count on success1164 */1165 function bbp_update_forum_voice_count ( $forum_id = 0 ) {1166 global $wpdb, $bbp;1167 1168 $forum_id = bbp_get_forum_id( $forum_id );1169 1170 // If it is not a forum or reply, then we don't need it1171 if ( !in_array( get_post_field( 'post_type', $forum_id ), array( $bbp->forum_id, $bbp->reply_id ) ) )1172 return false;1173 1174 // If it's a reply, then get the parent (forum id)1175 if ( $bbp->reply_id == get_post_field( 'post_type', $forum_id ) )1176 $forum_id = get_post_field( 'post_parent', $forum_id );1177 1178 // There should always be at least 1 voice1179 if ( !$voices = count( $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "' ) OR ( ID = %d AND post_type = '" . $bbp->forum_id . "' );", $forum_id, $forum_id ) ) ) )1180 $voices = 1;1181 1182 // Update the count1183 update_post_meta( $forum_id, '_bbp_forum_voice_count', (int)$voices );1184 1185 return apply_filters( 'bbp_update_forum_voice_count', (int)$voices );1186 }1187 1188 /** END - Forum Loop Functions ************************************************/1189 1190 /** START - Topic Loop Functions **********************************************/1191 1192 /**1193 * bbp_has_topics()1194 *1195 * The main topic loop. WordPress makes this easy for us1196 *1197 * @package bbPress1198 * @subpackage Template Tags1199 * @since bbPress (r2485)1200 *1201 * @global WP_Query $bbp_topics_template1202 * @param array $args Possible arguments to change returned topics1203 * @return object Multidimensional array of topic information1204 */1205 function bbp_has_topics ( $args = '' ) {1206 global $wp_rewrite, $bbp_topics_template, $bbp;1207 1208 $default = array (1209 // Narrow query down to bbPress topics1210 'post_type' => $bbp->topic_id,1211 1212 // Forum ID1213 'post_parent' => isset( $_REQUEST['forum_id'] ) ? $_REQUEST['forum_id'] : bbp_get_forum_id(),1214 1215 // Make sure topic has some last activity time1216 'meta_key' => '_bbp_topic_last_active',1217 1218 //'author', 'date', 'title', 'modified', 'parent', rand',1219 'orderby' => isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'meta_value',1220 1221 // 'ASC', 'DESC'1222 'order' => isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : 'DESC',1223 1224 // @todo replace 15 with setting1225 'posts_per_page' => isset( $_REQUEST['posts'] ) ? $_REQUEST['posts'] : 15,1226 1227 // Page Number1228 'paged' => bbp_get_paged(),1229 1230 // Topic Search1231 's' => empty( $_REQUEST['ts'] ) ? '' : $_REQUEST['ts'],1232 );1233 1234 // Don't pass post_parent if forum_id is empty or 01235 if ( empty( $default['post_parent'] ) ) {1236 unset( $default['post_parent'] );1237 $post_parent = get_the_ID();1238 }1239 1240 // Set up topic variables1241 $bbp_t = wp_parse_args( $args, $default );1242 $r = extract( $bbp_t );1243 1244 // If we're viewing a tax/term, use the existing query; if not, run our own1245 if ( !is_tax() ) {1246 $bbp_topics_template = new WP_Query( $bbp_t );1247 } else {1248 global $wp_query;1249 $bbp_topics_template = $wp_query;1250 }1251 1252 if ( -1 == $posts_per_page )1253 $posts_per_page = $bbp_topics_template->post_count;1254 1255 // Add pagination values to query object1256 $bbp_topics_template->posts_per_page = $posts_per_page;1257 $bbp_topics_template->paged = $paged;1258 1259 // Only add pagination if query returned results1260 if ( ( (int)$bbp_topics_template->post_count || (int)$bbp_topics_template->found_posts ) && (int)$bbp_topics_template->posts_per_page ) {1261 1262 // If pretty permalinks are enabled, make our pagination pretty1263 if ( $wp_rewrite->using_permalinks() )1264 $base = user_trailingslashit( trailingslashit( get_permalink( $post_parent ) ) . 'page/%#%/' );1265 else1266 $base = add_query_arg( 'page', '%#%' );1267 1268 // Pagination settings with filter1269 $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array (1270 'base' => $base,1271 'format' => '',1272 'total' => $posts_per_page == $bbp_topics_template->found_posts ? 1 : ceil( (int)$bbp_topics_template->found_posts / (int)$posts_per_page ),1273 'current' => (int)$bbp_topics_template->paged,1274 'prev_text' => '←',1275 'next_text' => '→',1276 'mid_size' => 11277 ) );1278 1279 // Add pagination to query object1280 $bbp_topics_template->pagination_links = paginate_links ( $bbp_topic_pagination );1281 1282 // Remove first page from pagination1283 $bbp_topics_template->pagination_links = str_replace( 'page/1/\'', '\'', $bbp_topics_template->pagination_links );1284 }1285 1286 // Return object1287 return apply_filters( 'bbp_has_topics', $bbp_topics_template->have_posts(), $bbp_topics_template );1288 }1289 1290 /**1291 * bbp_topics()1292 *1293 * Whether there are more topics available in the loop1294 *1295 * @package bbPress1296 * @subpackage Template Tags1297 * @since bbPress (r2485)1298 *1299 * @global WP_Query $bbp_topics_template1300 * @return object Forum information1301 */1302 function bbp_topics () {1303 global $bbp_topics_template;1304 return $bbp_topics_template->have_posts();1305 }1306 1307 /**1308 * bbp_the_topic()1309 *1310 * Loads up the current topic in the loop1311 *1312 * @package bbPress1313 * @subpackage Template Tags1314 * @since bbPress (r2485)1315 *1316 * @global WP_Query $bbp_topics_template1317 * @return object Forum information1318 */1319 function bbp_the_topic () {1320 global $bbp_topics_template;1321 return $bbp_topics_template->the_post();1322 }1323 1324 /**1325 * bbp_topic_id()1326 *1327 * Output id from bbp_topic_id()1328 *1329 * @package bbPress1330 * @subpackage Template Tags1331 * @since bbPress (r2485)1332 *1333 * @uses bbp_get_topic_id()1334 */1335 function bbp_topic_id () {1336 echo bbp_get_topic_id();1337 }1338 /**1339 * bbp_get_topic_id()1340 *1341 * Return the topic ID1342 *1343 * @package bbPress1344 * @subpackage Template Tags1345 * @since bbPress (r2485)1346 *1347 * @global object $topics_template1348 * @return string Forum id1349 */1350 function bbp_get_topic_id ( $topic_id = 0 ) {1351 global $bbp_topics_template, $wp_query, $bbp;1352 1353 // Easy empty checking1354 if ( !empty( $topic_id ) && is_numeric( $topic_id ) )1355 $bbp_topic_id = $topic_id;1356 1357 // Currently inside a topic loop1358 elseif ( !empty( $bbp_topics_template->in_the_loop ) && isset( $bbp_topics_template->post->ID ) )1359 $bbp_topic_id = $bbp_topics_template->post->ID;1360 1361 // Currently viewing a topic1362 elseif ( bbp_is_topic() && isset( $wp_query->post->ID ) )1363 $bbp_topic_id = $wp_query->post->ID;1364 1365 // Currently viewing a singular reply1366 elseif ( bbp_is_reply() )1367 $bbp_topic_id = bbp_get_reply_topic_id();1368 1369 // Fallback1370 else1371 $bbp_topic_id = 0;1372 1373 $bbp->current_topic_id = $bbp_topic_id;1374 1375 return apply_filters( 'bbp_get_topic_id', (int)$bbp_topic_id );1376 }1377 1378 /**1379 * bbp_topic_permalink ()1380 *1381 * Output the link to the topic in the topic loop1382 *1383 * @package bbPress1384 * @subpackage Template Tags1385 * @since bbPress (r2485)1386 *1387 * @uses bbp_get_topic_permalink()1388 * @param int $topic_id optional1389 */1390 function bbp_topic_permalink ( $topic_id = 0 ) {1391 echo bbp_get_topic_permalink( $topic_id );1392 }1393 /**1394 * bbp_get_topic_permalink()1395 *1396 * Return the link to the topic in the loop1397 *1398 * @package bbPress1399 * @subpackage Template Tags1400 * @since bbPress (r2485)1401 *1402 * @uses apply_filters1403 * @uses get_permalink1404 * @param int $topic_id optional1405 *1406 * @return string Permanent link to topic1407 */1408 function bbp_get_topic_permalink ( $topic_id = 0 ) {1409 $topic_id = bbp_get_topic_id( $topic_id );1410 1411 return apply_filters( 'bbp_get_topic_permalink', get_permalink( $topic_id ) );1412 }1413 1414 /**1415 * bbp_topic_title ()1416 *1417 * Output the title of the topic in the loop1418 *1419 * @package bbPress1420 * @subpackage Template Tags1421 * @since bbPress (r2485)1422 * @param int $topic_id optional1423 *1424 * @uses bbp_get_topic_title()1425 */1426 function bbp_topic_title ( $topic_id = 0 ) {1427 echo bbp_get_topic_title( $topic_id );1428 }1429 /**1430 * bbp_get_topic_title ()1431 *1432 * Return the title of the topic in the loop1433 *1434 * @package bbPress1435 * @subpackage Template Tags1436 * @since bbPress (r2485)1437 *1438 * @uses apply_filters1439 * @uses get_the_title()1440 * @param int $topic_id optional1441 *1442 * @return string Title of topic1443 */1444 function bbp_get_topic_title ( $topic_id = 0 ) {1445 $topic_id = bbp_get_topic_id( $topic_id );1446 1447 return apply_filters( 'bbp_get_topic_title', get_the_title( $topic_id ) );1448 }1449 1450 /**1451 * bbp_topic_status ()1452 *1453 * Output the status of the topic in the loop1454 *1455 * @package bbPress1456 * @subpackage Template Tags1457 * @since bbPress (r2667)1458 * @param int $topic_id optional1459 *1460 * @uses bbp_get_topic_status()1461 */1462 function bbp_topic_status ( $topic_id = 0 ) {1463 echo bbp_get_topic_status( $topic_id );1464 }1465 /**1466 * bbp_get_topic_status ()1467 *1468 * Return the status of the topic in the loop1469 *1470 * @package bbPress1471 * @subpackage Template Tags1472 * @since bbPress (r2667)1473 *1474 * @todo custom topic ststuses1475 *1476 * @uses apply_filters1477 * @uses get_the_title()1478 * @param int $topic_id optional1479 *1480 * @return string Status of topic1481 */1482 function bbp_get_topic_status ( $topic_id = 0 ) {1483 $topic_id = bbp_get_topic_id( $topic_id );1484 1485 return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ) );1486 }1487 1488 /**1489 * bbp_topic_author ()1490 *1491 * Output the author of the topic in the loop1492 *1493 * @package bbPress1494 * @subpackage Template Tags1495 * @since bbPress (r2590)1496 * @param int $topic_id optional1497 *1498 * @uses bbp_get_topic_author()1499 */1500 function bbp_topic_author ( $topic_id = 0 ) {1501 echo bbp_get_topic_author( $topic_id );1502 }1503 /**1504 * bbp_get_topic_author ()1505 *1506 * Return the author of the topic in the loop1507 *1508 * @package bbPress1509 * @subpackage Template Tags1510 * @since bbPress (r2590)1511 *1512 * @uses apply_filters1513 * @param int $topic_id optional1514 *1515 * @return string Author of topic1516 */1517 function bbp_get_topic_author ( $topic_id = 0 ) {1518 $topic_id = bbp_get_topic_id( $topic_id );1519 1520 if ( get_post_field( 'post_author', $topic_id ) )1521 $author = get_the_author();1522 else1523 $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );1524 1525 return apply_filters( 'bbp_get_topic_author', $author );1526 }1527 1528 /**1529 * bbp_topic_author_id ()1530 *1531 * Output the author ID of the topic in the loop1532 *1533 * @package bbPress1534 * @subpackage Template Tags1535 * @since bbPress (r2590)1536 * @param int $topic_id optional1537 *1538 * @uses bbp_get_topic_author()1539 */1540 function bbp_topic_author_id ( $topic_id = 0 ) {1541 echo bbp_get_topic_author_id( $topic_id );1542 }1543 /**1544 * bbp_get_topic_author_id ()1545 *1546 * Return the author ID of the topic in the loop1547 *1548 * @package bbPress1549 * @subpackage Template Tags1550 * @since bbPress (r2590)1551 *1552 * @uses apply_filters1553 * @param int $topic_id optional1554 *1555 * @return string Author of topic1556 */1557 function bbp_get_topic_author_id ( $topic_id = 0 ) {1558 $topic_id = bbp_get_topic_id( $topic_id );1559 1560 return apply_filters( 'bbp_get_topic_author_id', get_post_field( 'post_author', $topic_id ) );1561 }1562 1563 /**1564 * bbp_topic_author_display_name ()1565 *1566 * Output the author display_name of the topic in the loop1567 *1568 * @package bbPress1569 * @subpackage Template Tags1570 * @since bbPress (r2590)1571 * @param int $topic_id optional1572 *1573 * @uses bbp_get_topic_author()1574 */1575 function bbp_topic_author_display_name ( $topic_id = 0 ) {1576 echo bbp_get_topic_author_display_name( $topic_id );1577 }1578 /**1579 * bbp_get_topic_author_display_name ()1580 *1581 * Return the author display_name of the topic in the loop1582 *1583 * @package bbPress1584 * @subpackage Template Tags1585 * @since bbPress (r2485)1586 *1587 * @uses apply_filters1588 * @param int $topic_id optional1589 *1590 * @return string Author of topic1591 */1592 function bbp_get_topic_author_display_name ( $topic_id = 0 ) {1593 $topic_id = bbp_get_topic_id( $topic_id );1594 1595 // Check for anonymous user1596 if ( $author_id = get_post_field( 'post_author', $topic_id ) )1597 $author_name = get_the_author_meta( 'display_name', $author_id );1598 else1599 $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );1600 1601 return apply_filters( 'bbp_get_topic_author_id', esc_attr( $author_name ) );1602 }1603 1604 /**1605 * bbp_topic_author_avatar ()1606 *1607 * Output the author avatar of the topic in the loop1608 *1609 * @package bbPress1610 * @subpackage Template Tags1611 * @since bbPress (r2590)1612 * @param int $topic_id optional1613 *1614 * @uses bbp_get_topic_author()1615 */1616 function bbp_topic_author_avatar ( $topic_id = 0, $size = 40 ) {1617 echo bbp_get_topic_author_avatar( $topic_id, $size );1618 }1619 /**1620 * bbp_get_topic_author_avatar ()1621 *1622 * Return the author avatar of the topic in the loop1623 *1624 * @package bbPress1625 * @subpackage Template Tags1626 * @since bbPress (r2590)1627 *1628 * @uses apply_filters1629 * @param int $topic_id optional1630 *1631 * @return string Author of topic1632 */1633 function bbp_get_topic_author_avatar ( $topic_id = 0, $size = 40 ) {1634 $topic_id = bbp_get_topic_id( $topic_id );1635 1636 return apply_filters( 'bbp_get_topic_author_avatar', get_avatar( get_post_field( 'post_author', $topic_id ), $size ) );1637 }1638 1639 /**1640 * bbp_topic_author_avatar ()1641 *1642 * Output the author avatar of the topic in the loop1643 *1644 * @package bbPress1645 * @subpackage Template Tags1646 * @since bbPress (r2590)1647 * @param int $topic_id optional1648 *1649 * @uses bbp_get_topic_author()1650 */1651 function bbp_topic_author_url ( $topic_id = 0 ) {1652 echo bbp_get_topic_author_url( $topic_id );1653 }1654 /**1655 * bbp_get_topic_author_url ()1656 *1657 * Return the author url of the topic in the loop1658 *1659 * @package bbPress1660 * @subpackage Template Tags1661 * @since bbPress (r2590)1662 *1663 * @uses apply_filters1664 * @param int $topic_id optional1665 *1666 * @return string Author URL of topic1667 */1668 function bbp_get_topic_author_url ( $topic_id = 0 ) {1669 $topic_id = bbp_get_topic_id( $topic_id );1670 1671 // Check for anonymous user1672 if ( $author_id = get_post_field( 'post_author', $topic_id ) )1673 $author_url = get_author_posts_url( $author_id );1674 else1675 $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true );1676 1677 return apply_filters( 'bbp_get_topic_author_url', $author_url );1678 }1679 1680 /**1681 * bbp_topic_forum_title ()1682 *1683 * Output the title of the forum a topic belongs to1684 *1685 * @package bbPress1686 * @subpackage Template Tags1687 * @since bbPress (r2485)1688 *1689 * @param int $topic_id optional1690 *1691 * @uses bbp_get_topic_forum_title()1692 */1693 function bbp_topic_forum_title ( $topic_id = 0 ) {1694 echo bbp_get_topic_forum_title( $topic_id );1695 }1696 /**1697 * bbp_get_topic_forum_title ()1698 *1699 * Return the title of the forum a topic belongs to1700 *1701 * @package bbPress1702 * @subpackage Template Tags1703 * @since bbPress (r2485)1704 *1705 * @param int $topic_id optional1706 *1707 * @return string1708 */1709 function bbp_get_topic_forum_title ( $topic_id = 0 ) {1710 $topic_id = bbp_get_topic_id( $topic_id );1711 $forum_id = bbp_get_topic_forum_id( $topic_id );1712 1713 return apply_filters( 'bbp_get_topic_forum', bbp_get_forum_title( $forum_id ) );1714 }1715 1716 /**1717 * bbp_topic_forum_id ()1718 *1719 * Output the forum ID a topic belongs to1720 *1721 * @package bbPress1722 * @subpackage Template Tags1723 * @since bbPress (r2491)1724 *1725 * @param int $topic_id optional1726 *1727 * @uses bbp_get_topic_forum_id()1728 */1729 function bbp_topic_forum_id ( $topic_id = 0 ) {1730 echo bbp_get_topic_forum_id( $topic_id );1731 }1732 /**1733 * bbp_get_topic_forum_id ()1734 *1735 * Return the forum ID a topic belongs to1736 *1737 * @package bbPress1738 * @subpackage Template Tags1739 * @since bbPress (r2491)1740 *1741 * @param int $topic_id optional1742 *1743 * @return string1744 */1745 function bbp_get_topic_forum_id ( $topic_id = 0 ) {1746 $topic_id = bbp_get_topic_id( $topic_id );1747 $forum_id = get_post_field( 'post_parent', $topic_id );1748 1749 return apply_filters( 'bbp_get_topic_forum_id', $forum_id, $topic_id );1750 }1751 1752 /**1753 * bbp_topic_last_active ()1754 *1755 * Output the topics last update date/time (aka freshness)1756 *1757 * @package bbPress1758 * @subpackage Template Tags1759 * @since bbPress (r2625)1760 *1761 *1762 * @param int $topic_id optional1763 *1764 * @uses bbp_get_topic_last_active()1765 */1766 function bbp_topic_last_active ( $topic_id = 0 ) {1767 echo bbp_get_topic_last_active( $topic_id );1768 }1769 /**1770 * bbp_get_topic_last_active ()1771 *1772 * Return the topics last update date/time (aka freshness)1773 *1774 * @package bbPress1775 * @subpackage Template Tags1776 * @since bbPress (r2625)1777 *1778 * @param int $topic_id optional1779 *1780 * @return string1781 */1782 function bbp_get_topic_last_active ( $topic_id = 0 ) {1783 $topic_id = bbp_get_topic_id( $topic_id );1784 1785 if ( !$last_active = get_post_meta( $topic_id, '_bbp_topic_last_active', true ) )1786 $reply_id = bbp_get_topic_last_reply_id( $topic_id );1787 1788 return apply_filters( 'bbp_get_topic_last_active', bbp_get_time_since( bbp_get_modified_time( $last_active ) ) );1789 }1790 1791 /** TOPIC LAST REPLY **********************************************************/1792 1793 /**1794 * bbp_topic_last_reply_id ()1795 *1796 * Output the id of the topics last reply1797 *1798 * @package bbPress1799 * @subpackage Template Tags1800 * @since bbPress (r2625)1801 *1802 * @param int $topic_id optional1803 *1804 * @uses bbp_get_topic_last_active()1805 */1806 function bbp_topic_last_reply_id ( $topic_id = 0 ) {1807 echo bbp_get_topic_last_reply_id( $topic_id );1808 }1809 /**1810 * bbp_get_topic_last_reply_id ()1811 *1812 * Return the topics last update date/time (aka freshness)1813 *1814 * @package bbPress1815 * @subpackage Template Tags1816 * @since bbPress (r2625)1817 *1818 * @param int $topic_id optional1819 *1820 * @return string1821 */1822 function bbp_get_topic_last_reply_id ( $topic_id = 0 ) {1823 $topic_id = bbp_get_topic_id( $topic_id );1824 $reply_id = get_post_meta( $topic_id, '_bbp_topic_last_reply_id', true );1825 1826 return apply_filters( 'bbp_get_topic_last_reply_id', $reply_id );1827 }1828 1829 /**1830 * bbp_topic_last_reply_title ()1831 *1832 * Output the title of the last reply inside a topic1833 *1834 * @param int $topic_id1835 */1836 function bbp_topic_last_reply_title ( $topic_id = 0 ) {1837 echo bbp_get_topic_last_reply_title( $topic_id );1838 }1839 /**1840 * bbp_get_topic_last_reply_title ()1841 *1842 * Return the title of the last reply inside a topic1843 *1844 * @param int $topic_id1845 * @return string1846 */1847 function bbp_get_topic_last_reply_title( $topic_id = 0 ) {1848 $topic_id = bbp_get_topic_id( $topic_id );1849 return apply_filters( 'bbp_get_topic_last_topic_title', bbp_get_reply_title( bbp_get_topic_last_reply_id( $topic_id ) ) );1850 }1851 1852 /**1853 * bbp_topic_last_reply_permalink ()1854 *1855 * Output the link to the last reply in a topic1856 *1857 * @package bbPress1858 * @subpackage Template Tags1859 * @since bbPress (r2464)1860 *1861 * @param int $topic_id optional1862 * @uses bbp_get_topic_permalink()1863 */1864 function bbp_topic_last_reply_permalink ( $topic_id = 0 ) {1865 echo bbp_get_topic_last_reply_permalink( $topic_id );1866 }1867 /**1868 * bbp_get_topic_last_reply_permalink ()1869 *1870 * Return the link to the last reply in a topic1871 *1872 * @package bbPress1873 * @subpackage Template Tags1874 * @since bbPress (r2464)1875 *1876 * @param int $topic_id optional1877 * @uses apply_filters1878 * @uses get_permalink1879 * @return string Permanent link to topic1880 */1881 function bbp_get_topic_last_reply_permalink ( $topic_id = 0 ) {1882 $topic_id = bbp_get_topic_id( $topic_id );1883 return apply_filters( 'bbp_get_topic_last_reply_permalink', bbp_get_reply_permalink( bbp_get_topic_last_reply_id( $topic_id ) ) );1884 }1885 1886 /**1887 * bbp_topic_last_reply_url ()1888 *1889 * Output the link to the last reply in a topic1890 *1891 * @package bbPress1892 * @subpackage Template Tags1893 * @since bbPress (r2683)1894 *1895 * @param int $topic_id optional1896 * @uses bbp_get_topic_url()1897 */1898 function bbp_topic_last_reply_url ( $topic_id = 0 ) {1899 echo bbp_get_topic_last_reply_url( $topic_id );1900 }1901 /**1902 * bbp_get_topic_last_reply_url ()1903 *1904 * Return the link to the last reply in a topic1905 *1906 * @package bbPress1907 * @subpackage Template Tags1908 * @since bbPress (r2683)1909 *1910 * @param int $topic_id optional1911 * @uses apply_filters1912 * @uses get_url1913 * @return string Permanent link to topic1914 */1915 function bbp_get_topic_last_reply_url ( $topic_id = 0 ) {1916 $topic_id = bbp_get_topic_id( $topic_id );1917 $reply_id = bbp_get_topic_last_reply_id( $topic_id );1918 1919 if ( !empty( $reply_id ) )1920 $reply_url = bbp_get_reply_url( $reply_id );1921 else1922 $reply_url = bbp_get_topic_permalink( $topic_id );1923 1924 return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url );1925 }1926 1927 /**1928 * bbp_topic_freshness_link ()1929 *1930 * Output link to the most recent activity inside a topic, complete with1931 * link attributes and content.1932 *1933 * @package bbPress1934 * @subpackage Template Tags1935 * @since bbPress (r2625)1936 *1937 * @param int $topic_id1938 */1939 function bbp_topic_freshness_link ( $topic_id = 0) {1940 echo bbp_get_topic_freshness_link( $topic_id );1941 }1942 /**1943 * bbp_get_topic_freshness_link ()1944 *1945 * Returns link to the most recent activity inside a topic, complete with1946 * link attributes and content.1947 *1948 * @package bbPress1949 * @subpackage Template Tags1950 * @since bbPress (r2625)1951 *1952 * @param int $topic_id1953 */1954 function bbp_get_topic_freshness_link ( $topic_id = 0 ) {1955 $topic_id = bbp_get_topic_id( $topic_id );1956 $link_url = bbp_get_topic_last_reply_url( $topic_id );1957 $title = bbp_get_topic_last_reply_title( $topic_id );1958 $time_since = bbp_get_topic_last_active( $topic_id );1959 1960 if ( !empty( $time_since ) )1961 $anchor = '<a href="' . $link_url . '" title="' . esc_attr( $title ) . '">' . $time_since . '</a>';1962 else1963 $anchor = __( 'No Replies', 'bbpress' );1964 1965 return apply_filters( 'bbp_get_topic_freshness_link', $anchor );1966 }1967 1968 /**1969 * bbp_topic_reply_count ()1970 *1971 * Output total post count of a topic1972 *1973 * @package bbPress1974 * @subpackage Template Tags1975 * @since bbPress (r2485)1976 *1977 * @uses bbp_get_topic_reply_count()1978 * @param int $topic_id1979 */1980 function bbp_topic_reply_count ( $topic_id = 0 ) {1981 echo bbp_get_topic_reply_count( $topic_id );1982 }1983 /**1984 * bbp_get_topic_reply_count ()1985 *1986 * Return total post count of a topic1987 *1988 * @package bbPress1989 * @subpackage Template Tags1990 * @since bbPress (r2485)1991 *1992 * @uses bbp_get_topic_id()1993 * @uses get_pages1994 * @uses apply_filters1995 *1996 * @param int $topic_id1997 */1998 function bbp_get_topic_reply_count ( $topic_id = 0 ) {1999 $topic_id = bbp_get_topic_id( $topic_id );2000 $replies = get_post_meta( $topic_id, '_bbp_topic_reply_count', true );2001 2002 if ( '' === $replies )2003 $replies = bbp_update_topic_reply_count( $topic_id );2004 2005 return apply_filters( 'bbp_get_topic_reply_count', (int)$replies );2006 }2007 2008 /**2009 * bbp_topic_voice_count ()2010 *2011 * Output total voice count of a topic2012 *2013 * @package bbPress2014 * @subpackage Template Tags2015 * @since bbPress (r2567)2016 *2017 * @uses bbp_get_topic_voice_count()2018 * @uses apply_filters2019 *2020 * @param int $topic_id2021 */2022 function bbp_topic_voice_count ( $topic_id = 0 ) {2023 echo bbp_get_topic_voice_count( $topic_id );2024 }2025 /**2026 * bbp_get_topic_voice_count ()2027 *2028 * Return total voice count of a topic2029 *2030 * @package bbPress2031 * @subpackage Template Tags2032 * @since bbPress (r2567)2033 *2034 * @uses bbp_get_topic_id()2035 * @uses apply_filters2036 *2037 * @param int $topic_id2038 *2039 * @return int Voice count of the topic2040 */2041 function bbp_get_topic_voice_count ( $topic_id = 0 ) {2042 $topic_id = bbp_get_topic_id( $topic_id );2043 2044 // Look for existing count, and populate if does not exist2045 if ( !$voices = get_post_meta( $topic_id, '_bbp_topic_voice_count', true ) )2046 $voices = bbp_update_topic_voice_count( $topic_id );2047 2048 return apply_filters( 'bbp_get_topic_voice_count', (int)$voices, $topic_id );2049 }2050 2051 /**2052 * bbp_topic_tag_list ( $topic_id = 0, $args = '' )2053 *2054 * Output a the tags of a topic2055 *2056 * @param int $topic_id2057 * @param array $args2058 */2059 function bbp_topic_tag_list ( $topic_id = 0, $args = '' ) {2060 echo bbp_get_topic_tag_list( $topic_id, $args );2061 }2062 /**2063 * bbp_get_topic_tag_list ( $topic_id = 0, $args = '' )2064 *2065 * Return the tags of a topic2066 *2067 * @param int $topic_id2068 * @param array $args2069 * @return string2070 */2071 function bbp_get_topic_tag_list ( $topic_id = 0, $args = '' ) {2072 global $bbp;2073 2074 $defaults = array(2075 'before' => '<p>' . __( 'Tagged:', 'bbpress' ) . ' ',2076 'sep' => ', ',2077 'after' => '</p>'2078 );2079 2080 $r = wp_parse_args( $args, $defaults );2081 extract( $r );2082 2083 $topic_id = bbp_get_topic_id( $topic_id );2084 2085 return get_the_term_list( $topic_id, $bbp->topic_tag_id, $before, $sep, $after );2086 }2087 2088 /**2089 * bbp_topic_admin_links()2090 *2091 * Output admin links for topic2092 *2093 * @param array $args2094 */2095 function bbp_topic_admin_links( $args = '' ) {2096 echo bbp_get_topic_admin_links( $args );2097 }2098 /**2099 * bbp_get_topic_admin_links()2100 *2101 * Return admin links for topic2102 *2103 * @param array $args2104 * @return string2105 */2106 function bbp_get_topic_admin_links( $args = '' ) {2107 if ( !current_user_can( 'edit_others_topics' ) )2108 return ' ';2109 2110 $defaults = array (2111 'before' => '<span class="bbp-admin-links">',2112 'after' => '</span>',2113 'sep' => ' | ',2114 'links' => array (2115 'edit' => __( 'Edit', 'bbpress' ), // bbp_get_topic_edit_link( $args )2116 'trash' => __( 'Trash', 'bbpress' ), // bbp_get_topic_trash_link( $args ),2117 'close' => __( 'Close', 'bbpress' ), // bbp_get_topic_close_link( $args ),2118 'sticky' => __( 'Sticky', 'bbpress' ), // bbp_get_topic_sticky_link( $args ),2119 'move' => __( 'Move', 'bbpress' ), // bbp_get_topic_move_dropdown( $args )2120 ),2121 );2122 2123 $r = wp_parse_args( $args, $defaults );2124 extract( $r );2125 2126 // Process the admin links2127 $links = implode( $sep, $links );2128 2129 return apply_filters( 'bbp_get_topic_admin_links', $before . $links . $after, $args );2130 }2131 2132 /**2133 * bbp_topic_class ()2134 *2135 * Output the row class of a topic2136 *2137 * @package bbPress2138 * @subpackage Template Tags2139 * @since bbPress (r2667)2140 */2141 function bbp_topic_class ( $topic_id = 0 ) {2142 echo bbp_get_topic_class( $topic_id );2143 }2144 /**2145 * bbp_get_topic_class ()2146 *2147 * Return the row class of a topic2148 *2149 * @package bbPress2150 * @subpackage Template Tags2151 * @since bbPress (r2667)2152 *2153 * @global WP_Query $bbp_topics_template2154 * @param int $topic_id2155 * @return string2156 */2157 function bbp_get_topic_class ( $topic_id = 0 ) {2158 global $bbp_topics_template;2159 2160 $alternate = $bbp_topics_template->current_post % 2 ? '' : 'alternate';2161 $status = 'status-' . bbp_get_topic_status();2162 $post = post_class( array( $alternate, $status ) );2163 2164 return apply_filters( 'bbp_get_topic_class', $post );2165 }2166 2167 /** Topic Updaters ************************************************************/2168 2169 /**2170 * bbp_update_topic_reply_count ()2171 *2172 * Adjust the total post count of a topic2173 *2174 * @package bbPress2175 * @subpackage Template Tags2176 * @since bbPress (r2467)2177 *2178 * @uses bbp_get_topic_id()2179 * @uses apply_filters2180 *2181 * @param int $topic_id optional Forum ID to update2182 *2183 * @return int2184 */2185 function bbp_update_topic_reply_count ( $topic_id = 0 ) {2186 global $wpdb, $bbp;2187 2188 $topic_id = bbp_get_topic_id( $topic_id );2189 2190 // If it's a reply, then get the parent (topic id)2191 if ( $bbp->reply_id == get_post_field( 'post_type', $topic_id ) )2192 $topic_id = get_post_field( 'post_parent', $topic_id );2193 2194 // Get replies of topic2195 $replies = count( $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "';", $topic_id ) ) );2196 2197 // Update the count2198 update_post_meta( $topic_id, '_bbp_topic_reply_count', (int)$replies );2199 2200 return apply_filters( 'bbp_update_topic_reply_count', (int)$replies );2201 }2202 2203 /**2204 * bbp_update_topic_last_active ()2205 *2206 * Update the topics last active date/time (aka freshness)2207 *2208 * @package bbPress2209 * @subpackage Template Tags2210 * @since bbPress (r2680)2211 *2212 * @param int $topic_id optional2213 *2214 * @return string2215 */2216 function bbp_update_topic_last_active ( $topic_id = 0, $new_time = '' ) {2217 $topic_id = bbp_get_topic_id( $topic_id );2218 2219 // Check time and use current if empty2220 if ( empty( $new_time ) )2221 $new_time = current_time( 'mysql' );2222 2223 // Update the last reply ID2224 if ( !empty( $topic_id ) ) {2225 update_post_meta( $topic_id, '_bbp_topic_last_active', $new_time );2226 return true;2227 }2228 2229 return false;2230 }2231 2232 /**2233 * bbp_update_topic_last_reply_id ()2234 *2235 * Update the topic with the most recent reply ID2236 *2237 * @package bbPress2238 * @subpackage Template Tags2239 * @since bbPress (r2625)2240 *2241 * @todo everything2242 * @param int $topic_id2243 */2244 function bbp_update_topic_last_reply_id ( $topic_id = 0, $reply_id = 0 ) {2245 $topic_id = bbp_get_topic_id( $topic_id );2246 $reply_id = bbp_get_reply_id( $reply_id );2247 2248 // Update the last reply ID2249 if ( !empty( $topic_id ) ) {2250 update_post_meta( $topic_id, '_bbp_topic_last_reply_id', $reply_id );2251 return true;2252 }2253 2254 return false;2255 }2256 2257 /**2258 * bbp_update_topic_voice_count ()2259 *2260 * Adjust the total voice count of a topic2261 *2262 * @package bbPress2263 * @subpackage Template Tags2264 * @since bbPress (r2567)2265 *2266 * @uses bbp_get_topic_id()2267 * @uses apply_filters2268 *2269 * @todo cache2270 *2271 * @param int $topic_id optional Topic ID to update2272 * @return bool false on failure, voice count on success2273 */2274 function bbp_update_topic_voice_count ( $topic_id = 0 ) {2275 global $wpdb, $bbp;2276 2277 $topic_id = bbp_get_topic_id( $topic_id );2278 2279 // If it is not a topic or reply, then we don't need it2280 if ( !in_array( get_post_field( 'post_type', $topic_id ), array( $bbp->topic_id, $bbp->reply_id ) ) )2281 return false;2282 2283 // If it's a reply, then get the parent (topic id)2284 if ( $bbp->reply_id == get_post_field( 'post_type', $topic_id ) )2285 $topic_id = get_post_field( 'post_parent', $topic_id );2286 2287 // There should always be at least 1 voice2288 if ( !$voices = count( $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE ( post_parent = %d AND post_status = 'publish' AND post_type = '" . $bbp->reply_id . "' ) OR ( ID = %d AND post_type = '" . $bbp->topic_id . "' );", $topic_id, $topic_id ) ) ) )2289 $voices = 1;2290 2291 // Update the count2292 update_post_meta( $topic_id, '_bbp_topic_voice_count', (int)$voices );2293 2294 return apply_filters( 'bbp_update_topic_voice_count', (int)$voices );2295 }2296 2297 /** Topic Pagination **********************************************************/2298 2299 /**2300 * bbp_forum_pagination_count ()2301 *2302 * Output the pagination count2303 *2304 * @package bbPress2305 * @subpackage Template Tags2306 * @since bbPress (r2519)2307 *2308 * @global WP_Query $bbp_topics_template2309 */2310 function bbp_forum_pagination_count () {2311 echo bbp_get_forum_pagination_count();2312 }2313 /**2314 * bbp_get_forum_pagination_count ()2315 *2316 * Return the pagination count2317 *2318 * @package bbPress2319 * @subpackage Template Tags2320 * @since bbPress (r2519)2321 *2322 * @global WP_Query $bbp_topics_template2323 * @return string2324 */2325 function bbp_get_forum_pagination_count () {2326 global $bbp_topics_template;2327 2328 if ( !isset( $bbp_topics_template ) )2329 return false;2330 2331 // Set pagination values2332 $start_num = intval( ( $bbp_topics_template->paged - 1 ) * $bbp_topics_template->posts_per_page ) + 1;2333 $from_num = bbp_number_format( $start_num );2334 $to_num = bbp_number_format( ( $start_num + ( $bbp_topics_template->posts_per_page - 1 ) > $bbp_topics_template->found_posts ) ? $bbp_topics_template->found_posts : $start_num + ( $bbp_topics_template->posts_per_page - 1 ) );2335 $total = bbp_number_format( !empty( $bbp_topics_template->found_posts ) ? $bbp_topics_template->found_posts : $bbp_topics_template->post_count );2336 2337 // Set return string2338 if ( $total > 1 && (int)$from_num == (int)$to_num )2339 $retstr = sprintf( __( 'Viewing topic %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );2340 elseif ( $total > 1 && empty( $to_num ) )2341 $retstr = sprintf( __( 'Viewing %1$s topics', 'bbpress' ), $total );2342 elseif ( $total > 1 && (int)$from_num != (int)$to_num )2343 $retstr = sprintf( __( 'Viewing topics %1$s through %2$s (of %3$s total)', 'bbpress' ), $from_num, $to_num, $total );2344 else2345 $retstr = sprintf( __( 'Viewing %1$s topic', 'bbpress' ), $total );2346 2347 // Filter and return2348 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );2349 }2350 2351 /**2352 * bbp_forum_pagination_links ()2353 *2354 * Output pagination links2355 *2356 * @package bbPress2357 * @subpackage Template Tags2358 * @since bbPress (r2519)2359 */2360 function bbp_forum_pagination_links () {2361 echo bbp_get_forum_pagination_links();2362 }2363 /**2364 * bbp_get_forum_pagination_links ()2365 *2366 * Return pagination links2367 *2368 * @package bbPress2369 * @subpackage Template Tags2370 * @since bbPress (r2519)2371 *2372 * @global WP_Query $bbp_topics_template2373 * @return string2374 */2375 function bbp_get_forum_pagination_links () {2376 global $bbp_topics_template;2377 2378 if ( !isset( $bbp_topics_template ) )2379 return false;2380 2381 return apply_filters( 'bbp_get_topic_pagination_links', $bbp_topics_template->pagination_links );2382 }2383 2384 /** END - Topic Loop Functions ************************************************/2385 2386 /** START - Reply Loop Functions **********************************************/2387 2388 /**2389 * bbp_has_replies ( $args )2390 *2391 * The main reply loop. WordPress makes this easy for us2392 *2393 * @package bbPress2394 * @subpackage Template Tags2395 * @since bbPress (r2553)2396 *2397 * @global WP_Query $bbp_replies_template2398 * @param array $args Possible arguments to change returned replies2399 * @return object Multidimensional array of reply information2400 */2401 function bbp_has_replies ( $args = '' ) {2402 global $wp_rewrite, $bbp_replies_template, $bbp;2403 2404 $default = array(2405 // Narrow query down to bbPress topics2406 'post_type' => $bbp->reply_id,2407 2408 // Forum ID2409 'post_parent' => isset( $_REQUEST['topic_id'] ) ? $_REQUEST['topic_id'] : bbp_get_topic_id(),2410 2411 //'author', 'date', 'title', 'modified', 'parent', rand',2412 'orderby' => isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'date',2413 2414 // 'ASC', 'DESC'2415 'order' => isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : 'ASC',2416 2417 // @todo replace 15 with setting2418 'posts_per_page' => isset( $_REQUEST['posts'] ) ? $_REQUEST['posts'] : 15,2419 2420 // Page Number2421 'paged' => bbp_get_paged(),2422 2423 // Reply Search2424 's' => empty( $_REQUEST['rs'] ) ? '' : $_REQUEST['rs'],2425 );2426 2427 // Set up topic variables2428 $bbp_r = wp_parse_args( $args, $default );2429 $r = extract( $bbp_r );2430 2431 // Call the query2432 $bbp_replies_template = new WP_Query( $bbp_r );2433 2434 // Add pagination values to query object2435 $bbp_replies_template->posts_per_page = $posts_per_page;2436 $bbp_replies_template->paged = $paged;2437 2438 // Only add pagination if query returned results2439 if ( (int)$bbp_replies_template->found_posts && (int)$bbp_replies_template->posts_per_page ) {2440 2441 // If pretty permalinks are enabled, make our pagination pretty2442 if ( $wp_rewrite->using_permalinks() )2443 $base = user_trailingslashit( trailingslashit( get_permalink( $post_parent ) ) . 'page/%#%/' );2444 else2445 $base = add_query_arg( 'page', '%#%' );2446 2447 // Pagination settings with filter2448 $bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array(2449 'base' => $base,2450 'format' => '',2451 'total' => ceil( (int)$bbp_replies_template->found_posts / (int)$posts_per_page ),2452 'current' => (int)$bbp_replies_template->paged,2453 'prev_text' => '←',2454 'next_text' => '→',2455 'mid_size' => 12456 ) );2457 2458 // Add pagination to query object2459 $bbp_replies_template->pagination_links = paginate_links( $bbp_replies_pagination );2460 2461 // Remove first page from pagination2462 $bbp_replies_template->pagination_links = str_replace( 'page/1/\'', '\'', $bbp_replies_template->pagination_links );2463 }2464 2465 // Return object2466 return apply_filters( 'bbp_has_replies', $bbp_replies_template->have_posts(), $bbp_replies_template );2467 }2468 2469 /**2470 * bbp_replies ()2471 *2472 * Whether there are more replies available in the loop2473 *2474 * @package bbPress2475 * @subpackage Template Tags2476 * @since bbPress (r2553)2477 *2478 * @global WP_Query $bbp_replies_template2479 * @return object Replies information2480 */2481 function bbp_replies () {2482 global $bbp_replies_template;2483 return $bbp_replies_template->have_posts();2484 }2485 2486 /**2487 * bbp_the_reply ()2488 *2489 * Loads up the current reply in the loop2490 *2491 * @package bbPress2492 * @subpackage Template Tags2493 * @since bbPress (r2553)2494 *2495 * @global WP_Query $bbp_replies_template2496 * @return object Reply information2497 */2498 function bbp_the_reply () {2499 global $bbp_replies_template;2500 return $bbp_replies_template->the_post();2501 }2502 2503 /**2504 * bbp_reply_id ()2505 *2506 * Output id from bbp_get_reply_id()2507 *2508 * @package bbPress2509 * @subpackage Template Tags2510 * @since bbPress (r2553)2511 *2512 * @uses bbp_get_reply_id()2513 */2514 function bbp_reply_id () {2515 echo bbp_get_reply_id();2516 }2517 /**2518 * bbp_get_reply_id ()2519 *2520 * Return the id of the reply in a replies loop2521 *2522 * @package bbPress2523 * @subpackage Template Tags2524 * @since bbPress (r2553)2525 *2526 * @global object $bbp_replies_template2527 * @return int Reply id2528 */2529 function bbp_get_reply_id ( $reply_id = 0 ) {2530 global $bbp_replies_template, $wp_query, $bbp;2531 2532 // Easy empty checking2533 if ( !empty( $reply_id ) && is_numeric( $reply_id ) )2534 $bbp_reply_id = $reply_id;2535 2536 // Currently viewing a reply2537 elseif ( bbp_is_reply() && isset( $wp_query->post->ID ) )2538 $bbp_reply_id = $wp_query->post->ID;2539 2540 // Currently inside a replies loop2541 elseif ( isset( $bbp_replies_template->post->ID ) )2542 $bbp_reply_id = $bbp_replies_template->post->ID;2543 2544 // Fallback2545 else2546 $bbp_reply_id = 0;2547 2548 $bbp->current_reply_id = $bbp_reply_id;2549 2550 return apply_filters( 'bbp_get_reply_id', (int)$bbp_reply_id );2551 }2552 2553 /**2554 * bbp_reply_permalink ()2555 *2556 * Output the link to the reply in the reply loop2557 *2558 * @package bbPress2559 * @subpackage Template Tags2560 * @since bbPress (r2553)2561 *2562 * @uses bbp_get_reply_permalink()2563 * @param int $reply_id optional2564 */2565 function bbp_reply_permalink ( $reply_id = 0 ) {2566 echo bbp_get_reply_permalink( $reply_id );2567 }2568 /**2569 * bbp_get_reply_permalink()2570 *2571 * Return the link to the reply in the loop2572 *2573 * @package bbPress2574 * @subpackage Template Tags2575 * @since bbPress (r2553)2576 *2577 * @uses apply_filters2578 * @uses get_permalink2579 * @param int $reply_id optional2580 *2581 * @return string Permanent link to reply2582 */2583 function bbp_get_reply_permalink ( $reply_id = 0 ) {2584 $reply_id = bbp_get_reply_id( $reply_id );2585 2586 return apply_filters( 'bbp_get_reply_permalink', get_permalink( $reply_id ), $reply_id );2587 }2588 /**2589 * bbp_reply_url ()2590 *2591 * Output the paginated url to the reply in the reply loop2592 *2593 * @package bbPress2594 * @subpackage Template Tags2595 * @since bbPress (r2679)2596 *2597 * @uses bbp_get_reply_url()2598 * @param int $reply_id optional2599 */2600 function bbp_reply_url ( $reply_id = 0 ) {2601 echo bbp_get_reply_url( $reply_id );2602 }2603 /**2604 * bbp_get_reply_url()2605 *2606 * Return the paginated url to the reply in the reply loop2607 *2608 * @package bbPress2609 * @subpackage Template Tags2610 * @since bbPress (r2679)2611 *2612 * @uses apply_filters2613 * @uses bbp_get_reply_id2614 * @uses bbp_get_reply_topic_id2615 * @uses bbp_get_topic_permalink2616 * @param int $reply_id optional2617 *2618 * @return string Link to reply relative to paginated topic2619 */2620 function bbp_get_reply_url ( $reply_id = 0 ) {2621 global $bbp_replies_template;2622 2623 // Set needed variables2624 $reply_id = bbp_get_reply_id( $reply_id );2625 $topic_id = bbp_get_reply_topic_id( $reply_id );2626 $topic_url = bbp_get_topic_permalink( $topic_id );2627 2628 // If $bbp_replies_template isn't set, we're handling a new reply redirect2629 if ( !isset( $bbp_replies_template ) ) {2630 2631 // Populate the replies global2632 bbp_has_replies();2633 2634 // Do some math and see if we need to bounce to the newest page2635 $new_reply_location = ceil( $bbp_replies_template->found_posts / $bbp_replies_template->posts_per_page );2636 if ( $bbp_replies_template->paged < (int) $new_reply_location )2637 $reply_page = $new_reply_location;2638 else2639 $reply_page = $bbp_replies_template->paged;2640 2641 // All good, so assign the reply_page to the current page2642 } else {2643 $reply_page = $bbp_replies_template->paged;2644 }2645 2646 // Don't include pagination if on first page2647 if ( 1 >= $reply_page )2648 $url = untrailingslashit( $topic_url ) . "/#reply-{$reply_id}";2649 else2650 $url = trailingslashit( $topic_url ) . "page/{$reply_page}/#reply-{$reply_id}";2651 2652 return apply_filters( 'bbp_get_reply_url', $url, $reply_id );2653 }2654 2655 /**2656 * bbp_reply_title ()2657 *2658 * Output the title of the reply in the loop2659 *2660 * @package bbPress2661 * @subpackage Template Tags2662 * @since bbPress (r2553)2663 * @param int $reply_id optional2664 *2665 * @uses bbp_get_reply_title()2666 */2667 function bbp_reply_title ( $reply_id = 0 ) {2668 echo bbp_get_reply_title( $reply_id );2669 }2670 2671 /**2672 * bbp_get_reply_title ()2673 *2674 * Return the title of the reply in the loop2675 *2676 * @package bbPress2677 * @subpackage Template Tags2678 * @since bbPress (r2553)2679 *2680 * @uses apply_filters2681 * @uses get_the_title()2682 * @param int $reply_id optional2683 *2684 * @return string Title of reply2685 */2686 function bbp_get_reply_title ( $reply_id = 0 ) {2687 return apply_filters( 'bbp_get_reply_title', get_the_title( $reply_id ), $reply_id );2688 }2689 2690 /**2691 * bbp_reply_content ()2692 *2693 * Output the content of the reply in the loop2694 *2695 * @package bbPress2696 * @subpackage Template Tags2697 * @since bbPress (r2553)2698 *2699 * @todo Have a parameter reply_id2700 *2701 * @uses bbp_get_reply_content()2702 */2703 function bbp_reply_content () {2704 echo bbp_get_reply_content();2705 }2706 /**2707 * bbp_get_reply_content ()2708 *2709 * Return the content of the reply in the loop2710 *2711 * @package bbPress2712 * @subpackage Template Tags2713 * @since bbPress (r2553)2714 *2715 * @uses apply_filters2716 * @uses get_the_content()2717 *2718 * @return string Content of the reply2719 */2720 function bbp_get_reply_content () {2721 return apply_filters( 'bbp_get_reply_content', get_the_content() );2722 }2723 2724 /**2725 * bbp_reply_status ()2726 *2727 * Output the status of the reply in the loop2728 *2729 * @package bbPress2730 * @subpackage Template Tags2731 * @since bbPress (r2667)2732 * @param int $reply_id optional2733 *2734 * @uses bbp_get_reply_status()2735 */2736 function bbp_reply_status ( $reply_id = 0 ) {2737 echo bbp_get_reply_status( $reply_id );2738 }2739 /**2740 * bbp_get_reply_status ()2741 *2742 * Return the status of the reply in the loop2743 *2744 * @package bbPress2745 * @subpackage Template Tags2746 * @since bbPress (r2667)2747 *2748 * @todo custom topic ststuses2749 *2750 * @uses apply_filters2751 * @uses get_post_status()2752 * @param int $reply_id optional2753 *2754 * @return string Status of reply2755 */2756 function bbp_get_reply_status ( $reply_id = 0 ) {2757 $reply_id = bbp_get_reply_id( $reply_id );2758 2759 return apply_filters( 'bbp_get_reply_status', get_post_status( $reply_id ) );2760 }2761 2762 /**2763 * bbp_reply_author ()2764 *2765 * Output the author of the reply in the loop2766 *2767 * @package bbPress2768 * @subpackage Template Tags2769 * @since bbPress (r2667)2770 * @param int $reply_id optional2771 *2772 * @uses bbp_get_reply_author()2773 */2774 function bbp_reply_author ( $reply_id = 0 ) {2775 echo bbp_get_reply_author( $reply_id );2776 }2777 /**2778 * bbp_get_reply_author ()2779 *2780 * Return the author of the reply in the loop2781 *2782 * @package bbPress2783 * @subpackage Template Tags2784 * @since bbPress (r2667)2785 *2786 * @uses apply_filters2787 * @param int $reply_id optional2788 *2789 * @return string Author of reply2790 */2791 function bbp_get_reply_author ( $reply_id = 0 ) {2792 $reply_id = bbp_get_reply_id( $reply_id );2793 2794 if ( get_post_field( 'post_author', $reply_id ) )2795 $author = get_the_author();2796 else2797 $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );2798 2799 return apply_filters( 'bbp_get_reply_author', $author );2800 }2801 2802 /**2803 * bbp_reply_author_id ()2804 *2805 * Output the author ID of the reply in the loop2806 *2807 * @package bbPress2808 * @subpackage Template Tags2809 * @since bbPress (r2667)2810 * @param int $reply_id optional2811 *2812 * @uses bbp_get_reply_author()2813 */2814 function bbp_reply_author_id ( $reply_id = 0 ) {2815 echo bbp_get_reply_author_id( $reply_id );2816 }2817 /**2818 * bbp_get_reply_author_id ()2819 *2820 * Return the author ID of the reply in the loop2821 *2822 * @package bbPress2823 * @subpackage Template Tags2824 * @since bbPress (r2667)2825 *2826 * @uses apply_filters2827 * @param int $reply_id optional2828 *2829 * @return string Author of reply2830 */2831 function bbp_get_reply_author_id ( $reply_id = 0 ) {2832 $reply_id = bbp_get_reply_id( $reply_id );2833 2834 return apply_filters( 'bbp_get_reply_author_id', get_post_field( 'post_author', $reply_id ) );2835 }2836 2837 /**2838 * bbp_reply_author_display_name ()2839 *2840 * Output the author display_name of the reply in the loop2841 *2842 * @package bbPress2843 * @subpackage Template Tags2844 * @since bbPress (r2667)2845 * @param int $reply_id optional2846 *2847 * @uses bbp_get_reply_author()2848 */2849 function bbp_reply_author_display_name ( $reply_id = 0 ) {2850 echo bbp_get_reply_author_display_name( $reply_id );2851 }2852 /**2853 * bbp_get_reply_author_display_name ()2854 *2855 * Return the author display_name of the reply in the loop2856 *2857 * @package bbPress2858 * @subpackage Template Tags2859 * @since bbPress (r2667)2860 *2861 * @uses apply_filters2862 * @param int $reply_id optional2863 *2864 * @return string Author of reply2865 */2866 function bbp_get_reply_author_display_name ( $reply_id = 0 ) {2867 $reply_id = bbp_get_reply_id( $reply_id );2868 2869 // Check for anonymous user2870 if ( $author_id = get_post_field( 'post_author', $reply_id ) )2871 $author_name = get_the_author_meta( 'display_name', $author_id );2872 else2873 $author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true );2874 2875 return apply_filters( 'bbp_get_reply_author_id', esc_attr( $author_name ) );2876 }2877 2878 /**2879 * bbp_reply_author_avatar ()2880 *2881 * Output the author avatar of the reply in the loop2882 *2883 * @package bbPress2884 * @subpackage Template Tags2885 * @since bbPress (r2667)2886 * @param int $reply_id optional2887 *2888 * @uses bbp_get_reply_author()2889 */2890 function bbp_reply_author_avatar ( $reply_id = 0, $size = 40 ) {2891 echo bbp_get_reply_author_avatar( $reply_id, $size );2892 }2893 /**2894 * bbp_get_reply_author_avatar ()2895 *2896 * Return the author avatar of the reply in the loop2897 *2898 * @package bbPress2899 * @subpackage Template Tags2900 * @since bbPress (r2667)2901 *2902 * @uses apply_filters2903 * @param int $reply_id optional2904 *2905 * @return string Author of reply2906 */2907 function bbp_get_reply_author_avatar ( $reply_id = 0, $size = 40 ) {2908 $reply_id = bbp_get_reply_id( $reply_id );2909 2910 return apply_filters( 'bbp_get_reply_author_avatar', get_avatar( get_post_field( 'post_author', $reply_id ), $size ) );2911 }2912 2913 /**2914 * bbp_reply_author_url ()2915 *2916 * Output the author url of the reply in the loop2917 *2918 * @package bbPress2919 * @subpackage Template Tags2920 * @since bbPress (r2667)2921 * @param int $reply_id optional2922 *2923 * @uses bbp_get_reply_author_url()2924 */2925 function bbp_reply_author_url ( $reply_id = 0 ) {2926 echo bbp_get_reply_author_url( $reply_id );2927 }2928 /**2929 * bbp_get_reply_author_url ()2930 *2931 * Return the author url of the reply in the loop2932 *2933 * @package bbPress2934 * @subpackage Template Tags2935 * @since bbPress (r2667)2936 *2937 * @uses apply_filters2938 * @param int $reply_id optional2939 *2940 * @return string Author URL of reply2941 */2942 function bbp_get_reply_author_url ( $reply_id = 0 ) {2943 $reply_id = bbp_get_reply_id( $reply_id );2944 2945 // Check for anonymous user2946 if ( $author_id = get_post_field( 'post_author', $reply_id ) )2947 $author_url = get_author_posts_url( $author_id );2948 else2949 $author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true );2950 2951 return apply_filters( 'bbp_get_reply_author_url', $author_url );2952 }2953 2954 /**2955 * bbp_reply_topic_title ()2956 *2957 * Output the topic title a reply belongs to2958 *2959 * @package bbPress2960 * @subpackage Template Tags2961 * @since bbPress (r2553)2962 *2963 * @param int $reply_id optional2964 *2965 * @uses bbp_get_reply_topic()2966 */2967 function bbp_reply_topic_title ( $reply_id = 0 ) {2968 echo bbp_get_reply_topic_title( $reply_id );2969 }2970 /**2971 * bbp_get_reply_topic_title ()2972 *2973 * Return the topic title a reply belongs to2974 *2975 * @package bbPress2976 * @subpackage Template Tags2977 * @since bbPress (r2553)2978 *2979 * @param int $reply_id optional2980 *2981 * @uses bbp_get_reply_topic_id ()2982 * @uses bbp_topic_title ()2983 *2984 * @return string2985 */2986 function bbp_get_reply_topic_title ( $reply_id = 0 ) {2987 $reply_id = bbp_get_reply_id( $reply_id );2988 $topic_id = bbp_get_reply_topic_id( $reply_id );2989 2990 return apply_filters( 'bbp_get_reply_topic_title', bbp_get_topic_title( $topic_id ), $reply_id, $topic_id );2991 }2992 2993 /**2994 * bbp_reply_topic_id ()2995 *2996 * Output the topic ID a reply belongs to2997 *2998 * @package bbPress2999 * @subpackage Template Tags3000 * @since bbPress (r2553)3001 *3002 * @param int $reply_id optional3003 *3004 * @uses bbp_get_reply_topic_id ()3005 */3006 function bbp_reply_topic_id ( $reply_id = 0 ) {3007 echo bbp_get_reply_topic_id( $reply_id );3008 }3009 /**3010 * bbp_get_reply_topic_id ()3011 *3012 * Return the topic ID a reply belongs to3013 *3014 * @package bbPress3015 * @subpackage Template Tags3016 * @since bbPress (r2553)3017 *3018 * @param int $reply_id optional3019 *3020 * @todo - Walk ancestors and look for topic post_type (for threaded replies)3021 *3022 * @return string3023 */3024 function bbp_get_reply_topic_id ( $reply_id = 0 ) {3025 $reply_id = bbp_get_reply_id( $reply_id );3026 $topic_id = get_post_field( 'post_parent', $reply_id );3027 3028 return apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id );3029 }3030 3031 /**3032 * bbp_reply_forum_id ()3033 *3034 * Output the forum ID a reply belongs to3035 *3036 * @package bbPress3037 * @subpackage Template Tags3038 * @since bbPress (r2679)3039 *3040 * @param int $reply_id optional3041 *3042 * @uses bbp_get_reply_topic_id ()3043 */3044 function bbp_reply_forum_id ( $reply_id = 0 ) {3045 echo bbp_get_reply_forum_id( $reply_id );3046 }3047 /**3048 * bbp_get_reply_forum_id ()3049 *3050 * Return the forum ID a reply belongs to3051 *3052 * @package bbPress3053 * @subpackage Template Tags3054 * @since bbPress (r2679)3055 *3056 * @param int $reply_id optional3057 *3058 * @todo - Walk ancestors and look for forum post_type3059 *3060 * @return string3061 */3062 function bbp_get_reply_forum_id ( $reply_id = 0 ) {3063 $reply_id = bbp_get_forum_id( $reply_id );3064 $topic_id = get_post_field( 'post_parent', $reply_id );3065 $forum_id = get_post_field( 'post_parent', $topic_id );3066 3067 return apply_filters( 'bbp_get_reply_topic_id', $forum_id, $reply_id );3068 }3069 3070 /**3071 * bbp_reply_admin_links()3072 *3073 * Output admin links for reply3074 *3075 * @param array $args3076 */3077 function bbp_reply_admin_links( $args = '' ) {3078 echo bbp_get_reply_admin_links( $args );3079 }3080 /**3081 * bbp_get_reply_admin_links()3082 *3083 * Return admin links for reply3084 *3085 * @param array $args3086 * @return string3087 */3088 function bbp_get_reply_admin_links( $args = '' ) {3089 if ( !current_user_can( 'edit_others_replies' ) )3090 return;3091 3092 $defaults = array (3093 'before' => '<span class="bbp-admin-links">',3094 'after' => '</span>',3095 'sep' => ' | ',3096 'links' => array (3097 'edit' => __( 'Edit', 'bbpress' ), // bbp_get_reply_close_link( $args ),3098 'trash' => __( 'Trash', 'bbpress' ), // bbp_get_reply_delete_link( $args ),3099 ),3100 );3101 3102 $r = wp_parse_args( $args, $defaults );3103 extract( $r );3104 3105 // Process the admin links3106 $links = implode( $sep, $links );3107 3108 return apply_filters( 'bbp_get_reply_admin_links', $before . $links . $after, $args );3109 }3110 3111 /**3112 * bbp_reply_class ()3113 *3114 * Output the row class of a reply3115 */3116 function bbp_reply_class ( $reply_id = 0 ) {3117 echo bbp_get_reply_class( $reply_id );3118 }3119 /**3120 * bbp_get_reply_class ()3121 *3122 * Return the row class of a reply3123 *3124 * @global WP_Query $bbp_replies_template3125 * @param int $reply_id3126 * @return string3127 */3128 function bbp_get_reply_class ( $reply_id = 0 ) {3129 global $bbp_replies_template;3130 3131 $alternate = $bbp_replies_template->current_post % 2 ? '' : 'alternate';3132 $status = 'status-' . bbp_get_reply_status();3133 $post = post_class( array( $alternate, $status ) );3134 3135 return apply_filters( 'bbp_reply_class', $post );3136 }3137 3138 /**3139 * bbp_topic_pagination_count ()3140 *3141 * Output the pagination count3142 *3143 * @package bbPress3144 * @subpackage Template Tags3145 * @since bbPress (r2519)3146 *3147 * @global WP_Query $bbp_topics_template3148 */3149 function bbp_topic_pagination_count () {3150 echo bbp_get_topic_pagination_count();3151 }3152 /**3153 * bbp_get_topic_pagination_count ()3154 *3155 * Return the pagination count3156 *3157 * @package bbPress3158 * @subpackage Template Tags3159 * @since bbPress (r2519)3160 *3161 * @global WP_Query $bbp_replies_template3162 * @return string3163 */3164 function bbp_get_topic_pagination_count () {3165 global $bbp_replies_template;3166 3167 // Set pagination values3168 $start_num = intval( ( $bbp_replies_template->paged - 1 ) * $bbp_replies_template->posts_per_page ) + 1;3169 $from_num = bbp_number_format( $start_num );3170 $to_num = bbp_number_format( ( $start_num + ( $bbp_replies_template->posts_per_page - 1 ) > $bbp_replies_template->found_posts ) ? $bbp_replies_template->found_posts : $start_num + ( $bbp_replies_template->posts_per_page - 1 ) );3171 $total = bbp_number_format( $bbp_replies_template->found_posts );3172 3173 // Set return string3174 if ( $total > 1 && $from_num != $to_num )3175 $retstr = sprintf( __( 'Viewing replies %1$s through %2$s (of %3$s total)', 'bbpress' ), $from_num, $to_num, $total );3176 elseif ( $total > 1 && $from_num == $to_num )3177 $retstr = sprintf( __( 'Viewing reply %1$s (of %2$s total)', 'bbpress' ), $from_num, $total );3178 else3179 $retstr = sprintf( __( 'Viewing %1$s reply', 'bbpress' ), $total );3180 3181 // Filter and return3182 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );3183 }3184 3185 /**3186 * bbp_topic_pagination_links ()3187 *3188 * Output pagination links3189 *3190 * @package bbPress3191 * @subpackage Template Tags3192 * @since bbPress (r2519)3193 */3194 function bbp_topic_pagination_links () {3195 echo bbp_get_topic_pagination_links();3196 }3197 /**3198 * bbp_get_topic_pagination_links ()3199 *3200 * Return pagination links3201 *3202 * @package bbPress3203 * @subpackage Template Tags3204 * @since bbPress (r2519)3205 *3206 * @global WP_Query $bbp_replies_template3207 * @return string3208 */3209 function bbp_get_topic_pagination_links () {3210 global $bbp_replies_template;3211 3212 if ( !isset( $bbp_replies_template->pagination_links ) || empty( $bbp_replies_template->pagination_links ) )3213 return false;3214 else3215 return apply_filters( 'bbp_get_topic_pagination_links', $bbp_replies_template->pagination_links );3216 }3217 3218 /** END reply Loop Functions **************************************************/3219 3220 35 /** START is_ Functions *******************************************************/ 3221 36 … … 3298 113 * bbp_is_favorites () 3299 114 * 3300 * Check if current page is a bbPress user's favorites page ( authorpage)115 * Check if current page is a bbPress user's favorites page (profile page) 3301 116 * 3302 117 * @since bbPress (r2652) 3303 118 * 3304 * @return bool 3305 */ 3306 function bbp_is_favorites () { 3307 return (bool) is_author(); 119 * @param bool $query_name_check Optional. Check the query name (_bbp_query_name query var), if it is 'bbp_user_profile_favorites' or not. Defaults to true. 120 * @return bool 121 */ 122 function bbp_is_favorites ( $query_name_check = true ) { 123 if ( !bbp_is_user_profile_page() ) 124 return false; 125 126 if ( !empty( $query_name_check ) && 'bbp_user_profile_favorites' != get_query_var( '_bbp_query_name' ) ) 127 return false; 128 129 return true; 3308 130 } 3309 131 … … 3311 133 * bbp_is_subscriptions () 3312 134 * 3313 * Check if current page is a bbPress user's subscriptions page ( authorpage)135 * Check if current page is a bbPress user's subscriptions page (profile page) 3314 136 * 3315 137 * @since bbPress (r2652) 3316 138 * 3317 * @return bool 3318 */ 3319 function bbp_is_subscriptions () { 3320 return (bool) is_author(); 139 * @param bool $query_name_check Optional. Check the query name (_bbp_query_name query var), if it is 'bbp_user_profile_subscriptions' or not. Defaults to true. 140 * @return bool 141 */ 142 function bbp_is_subscriptions ( $query_name_check = true ) { 143 if ( !bbp_is_user_profile_page() ) 144 return false; 145 146 if ( !empty( $query_name_check ) && 'bbp_user_profile_subscriptions' != get_query_var( '_bbp_query_name' ) ) 147 return false; 148 149 return true; 150 } 151 152 /** 153 * bbp_is_topics_created () 154 * 155 * Check if current page shows the topics created by a bbPress user (profile page) 156 * 157 * @since bbPress (r2688) 158 * 159 * @param bool $query_name_check Optional. Check the query name (_bbp_query_name query var), if it is 'bbp_user_profile_subscriptions' or not. Defaults to true. 160 * @return bool 161 */ 162 function bbp_is_topics_created ( $query_name_check = true ) { 163 if ( !bbp_is_user_profile_page() ) 164 return false; 165 166 if ( !empty( $query_name_check ) && 'bbp_user_profile_topics_created' != get_query_var( '_bbp_query_name' ) ) 167 return false; 168 169 return true; 3321 170 } 3322 171 … … 3329 178 * @return bool 3330 179 */ 3331 function bbp_is_user_home() { 3332 global $current_user; 3333 3334 $current_user = wp_get_current_user(); 3335 3336 if ( $current_user->ID == get_the_author_meta( 'ID' ) ) 3337 $retval = true; 180 function bbp_is_user_home () { 181 global $bbp; 182 183 if ( !isset( $bbp->displayed_user ) ) 184 $retval = false; 3338 185 else 3339 $retval = false; 3340 3341 return apply_filters( 'bbp_is_user_home', $retval, $current_user ); 3342 } 3343 3344 /** 3345 * bbp_is_anonymous () 3346 * 3347 * Return true if anonymous is allowed and user is not logged in. 3348 * Return false if anonymous is not allowed or user is logged in 3349 * 3350 * @return bool 3351 */ 3352 function bbp_is_anonymous () { 3353 if ( !is_user_logged_in() && bbp_allow_anonymous() ) 3354 $is_anonymous = true; 186 $retval = $bbp->current_user->ID == $bbp->displayed_user->ID ? true : false; 187 188 return apply_filters( 'bbp_is_user_home', $retval ); 189 } 190 191 /** 192 * bbp_is_user_profile_page () 193 * 194 * Check if current page is a user profile page 195 * 196 * @since bbPress (r2688) 197 * 198 * @global object $wp_query 199 * @return bool 200 */ 201 function bbp_is_user_profile_page () { 202 global $wp_query; 203 204 if ( !empty( $wp_query->bbp_is_user_profile_page ) && $wp_query->bbp_is_user_profile_page == true ) 205 return true; 3355 206 else 3356 $is_anonymous = false; 3357 3358 return apply_filters( 'bbp_is_anonymous', $is_anonymous ); 207 return false; 208 209 return apply_filters( 'bbp_is_user_profile_page', $retval, $wp_query ); 210 } 211 212 /** 213 * bbp_is_user_profile_edit () 214 * 215 * Check if current page is a user profile edit page 216 * 217 * @since bbPress (r2688) 218 * 219 * @global object $wp_query 220 * @return bool 221 */ 222 function bbp_is_user_profile_edit () { 223 global $wp_query; 224 225 if ( !empty( $wp_query->bbp_is_user_profile_edit ) && $wp_query->bbp_is_user_profile_edit == true ) 226 return true; 227 else 228 return false; 229 230 return apply_filters( 'bbp_is_user_profile_edit', $retval, $wp_query ); 3359 231 } 3360 232 3361 233 /** END is_ Functions *********************************************************/ 3362 3363 /** START Favorites Functions *************************************************/3364 3365 /**3366 * bbp_favorites_permalink ()3367 *3368 * Output the link to the user's favorites page (author page)3369 *3370 * @package bbPress3371 * @subpackage Template Tags3372 * @since bbPress (r2652)3373 *3374 * @param int $user_id optional3375 * @uses bbp_get_favorites_permalink()3376 */3377 function bbp_favorites_permalink ( $user_id = 0 ) {3378 echo bbp_get_favorites_permalink( $user_id );3379 }3380 /**3381 * bbp_get_favorites_permalink ()3382 *3383 * Return the link to the user's favorites page (author page)3384 *3385 * @package bbPress3386 * @subpackage Template Tags3387 * @since bbPress (r2652)3388 *3389 * @param int $user_id optional3390 * @uses apply_filters3391 * @uses get_author_posts_url3392 * @return string Permanent link to topic3393 */3394 function bbp_get_favorites_permalink ( $user_id = 0 ) {3395 return apply_filters( 'bbp_get_favorites_permalink', get_author_posts_url( $user_id ) );3396 }3397 3398 /**3399 * bbp_user_favorites_link ()3400 *3401 * Output the link to make a topic favorite/remove a topic from favorites3402 *3403 * @package bbPress3404 * @subpackage Template Tags3405 * @since bbPress (r2652)3406 *3407 * @param array $add optional3408 * @param array $rem optional3409 * @param int $user_id optional3410 *3411 * @uses bbp_get_user_favorites_link()3412 */3413 function bbp_user_favorites_link ( $add = array(), $rem = array(), $user_id = 0 ) {3414 echo bbp_get_user_favorites_link( $add, $rem, $user_id );3415 }3416 /**3417 * bbp_get_user_favorites_link ()3418 *3419 * Return the link to make a topic favorite/remove a topic from favorites3420 *3421 * @package bbPress3422 * @subpackage Template Tags3423 * @since bbPress (r2652)3424 *3425 * @param array $add optional3426 * @param array $rem optional3427 * @param int $user_id optional3428 *3429 * @uses apply_filters3430 * @return string Permanent link to topic3431 */3432 function bbp_get_user_favorites_link ( $add = array(), $rem = array(), $user_id = 0 ) {3433 global $current_user;3434 3435 $current_user = wp_get_current_user();3436 3437 if ( empty( $user_id ) && !$user_id = $current_user->ID )3438 return false;3439 3440 if ( !current_user_can( 'edit_user', (int) $user_id ) )3441 return false;3442 3443 if ( !$topic_id = bbp_get_topic_id() )3444 return false;3445 3446 if ( empty( $add ) || !is_array( $add ) ) {3447 $add = array(3448 'mid' => __( 'Add this topic to your favorites', 'bbpress' ),3449 'post' => __( ' (%?%)', 'bbpress' )3450 );3451 }3452 3453 if ( empty( $rem ) || !is_array( $rem ) ) {3454 $rem = array(3455 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ),3456 'mid' => __( '×', 'bbpress' ),3457 'post' => __( ']', 'bbpress' )3458 );3459 }3460 3461 if ( $is_fav = bbp_is_user_favorite( $user_id, $topic_id ) ) {3462 $url = esc_url( bbp_get_favorites_permalink( $user_id ) );3463 $rem = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem );3464 $favs = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id );3465 $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : '';3466 $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' );3467 $post = ( is_array( $rem ) && isset( $rem['post'] ) ) ? $rem['post'] : '';3468 } else {3469 $url = esc_url( bbp_get_topic_permalink( $topic_id ) );3470 $add = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $add );3471 $favs = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id );3472 $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : '';3473 $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' );3474 $post = ( is_array( $add ) && isset( $add['post'] ) ) ? $add['post'] : '';3475 }3476 3477 // Create the link based where the user is and if the topic is already the user's favorite3478 $permalink = bbp_is_favorites() ? bbp_get_favorites_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id );3479 $url = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) );3480 $is_fav = $is_fav ? 'is-favorite' : '';3481 $html = '<span id="favorite-toggle"><span id="favorite-' . $topic_id . '" class="' . $is_fav . '">' . $pre . '<a href="' . $url . '" class="dim:favorite-toggle:favorite-' . $topic_id . ':is-favorite">' . $mid . '</a>' . $post . '</span></span>';3482 3483 // Return the link3484 return apply_filters( 'bbp_get_user_favorites_link', $html, $add, $rem, $user_id, $topic_id );3485 }3486 3487 /** END Favorites Functions ***************************************************/3488 3489 /** START Subscriptions Functions *********************************************/3490 3491 /**3492 * bbp_user_subscribe_link ()3493 *3494 * Output the link to subscribe/unsubscribe from a topic3495 *3496 * @package bbPress3497 * @subpackage Template Tags3498 * @since bbPress (r2668)3499 *3500 * @param mixed $args3501 *3502 * @uses bbp_get_user_subscribe_link()3503 */3504 function bbp_user_subscribe_link ( $args = '' ) {3505 echo bbp_get_user_subscribe_link( $args );3506 }3507 /**3508 * bbp_get_user_subscribe_link ()3509 *3510 * Return the link to subscribe/unsubscribe from a topic3511 *3512 * @package bbPress3513 * @subpackage Template Tags3514 * @since bbPress (r2668)3515 *3516 * @param mixed $args3517 *3518 * @uses apply_filters3519 * @return string Permanent link to topic3520 */3521 function bbp_get_user_subscribe_link ( $args = '' ) {3522 if ( !bbp_is_subscriptions_active() )3523 return;3524 3525 $defaults = array (3526 'subscribe' => __( 'Subscribe', 'bbpress' ),3527 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ),3528 'user_id' => 0,3529 'topic_id' => 0,3530 'before' => ' | ',3531 'after' => ''3532 );3533 3534 $args = wp_parse_args( $args, $defaults );3535 extract( $args );3536 3537 // Try to get a user_id from $current_user3538 if ( empty( $user_id ) ) {3539 global $current_user;3540 $current_user = wp_get_current_user();3541 3542 // Return if not logged in3543 if ( !$user_id = $current_user->ID ) {3544 return false;3545 }3546 }3547 3548 if ( !current_user_can( 'edit_user', (int) $user_id ) )3549 return false;3550 3551 if ( !$topic_id = bbp_get_topic_id( $topic_id ) )3552 return false;3553 3554 if ( $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ) ) {3555 $text = $unsubscribe;3556 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );3557 } else {3558 $text = $subscribe;3559 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );3560 }3561 3562 // Create the link based where the user is and if the user is subscribed already3563 $permalink = bbp_is_subscriptions() ? bbp_get_favorites_permalink( $user_id ) : bbp_get_topic_permalink( $topic_id );3564 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );3565 $is_subscribed = $is_subscribed ? 'is-subscribed' : '';3566 $html = '<span id="subscription-toggle">' . $before . '<span id="subscribe-' . $topic_id . '" class="' . $is_subscribed . '"><a href="' . $url . '" class="dim:subscription-toggle:subscribe-' . $topic_id . ':is-subscribed">' . $text . '</a></span>' . $after . '</span>';3567 3568 // Return the link3569 return apply_filters( 'bbp_get_user_subscribe_link', $html, $subscribe, $unsubscribe, $user_id, $topic_id );3570 }3571 3572 /** END Subscriptions Functions ***********************************************/3573 3574 /** START User Functions ******************************************************/3575 3576 /**3577 * bbp_current_user_id ()3578 *3579 * Output ID of current user3580 *3581 * @uses bbp_get_current_user_id()3582 */3583 function bbp_current_user_id () {3584 echo bbp_get_current_user_id();3585 }3586 /**3587 * bbp_get_current_user_id ()3588 *3589 * Return ID of current user3590 *3591 * @global object $current_user3592 * @global string $user_identity3593 * @return int3594 */3595 function bbp_get_current_user_id () {3596 global $current_user;3597 3598 if ( is_user_logged_in() )3599 $current_user_id = $current_user->ID;3600 else3601 $current_user_id = 0;3602 3603 return apply_filters( 'bbp_get_current_user_id', $current_user_id );3604 }3605 3606 /**3607 * bbp_current_user_name ()3608 *3609 * Output name of current user3610 *3611 * @uses bbp_get_current_user_name()3612 */3613 function bbp_current_user_name () {3614 echo bbp_get_current_user_name();3615 }3616 /**3617 * bbp_get_current_user_name ()3618 *3619 * Return name of current user3620 *3621 * @global object $current_user3622 * @global string $user_identity3623 * @return string3624 */3625 function bbp_get_current_user_name () {3626 global $current_user, $user_identity;3627 3628 if ( is_user_logged_in() )3629 $current_user_name = $user_identity;3630 else3631 $current_user_name = __( 'Anonymous', 'bbpress' );3632 3633 return apply_filters( 'bbp_get_current_user_name', $current_user_name );3634 }3635 3636 /**3637 * bbp_current_user_avatar ()3638 *3639 * Output avatar of current user3640 *3641 * @uses bbp_get_current_user_avatar()3642 */3643 function bbp_current_user_avatar ( $size = 40 ) {3644 echo bbp_get_current_user_avatar( $size );3645 }3646 3647 /**3648 * bbp_get_current_user_avatar ( $size = 40 )3649 *3650 * Return avatar of current user3651 *3652 * @global object $current_user3653 * @param int $size3654 * @return string3655 */3656 function bbp_get_current_user_avatar ( $size = 40 ) {3657 global $current_user;3658 3659 return apply_filters( 'bbp_get_current_user_avatar', get_avatar( bbp_get_current_user_id(), $size ) );3660 }3661 3662 /** END User Functions ********************************************************/3663 234 3664 235 /** START Form Functions ******************************************************/ … … 3749 320 3750 321 /** 322 * bbp_error_messages () 323 * 324 * Display possible error messages inside a template file 325 * 326 * @global WP_Error $errors 327 */ 328 function bbp_error_messages () { 329 global $errors; 330 331 if ( isset( $errors ) && is_wp_error( $errors ) ) : ?> 332 333 <div class="bp-messages error"> 334 <p> 335 <?php echo implode( "</p>\n<p>", $errors->get_error_messages() ); ?> 336 </p> 337 </div> 338 339 <?php endif; 340 } 341 add_action( 'bbp_template_notices', 'bbp_error_messages' ); 342 343 /** 3751 344 * bbp_title_breadcrumb ( $sep ) 3752 345 * -
branches/plugin/bbp-includes/bbp-loader.php
r2679 r2688 13 13 14 14 // Attach to WordPress actions 15 add_action( 'plugins_loaded', 'bbp_loaded' , 10 ); 16 add_action( 'init', 'bbp_init' , 10 ); 15 add_action( 'plugins_loaded', 'bbp_loaded' , 10 ); 16 add_action( 'init', 'bbp_init' , 10 ); 17 add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules' , 12 ); 17 18 18 19 // Attach to bbp_loaded. 19 add_action( 'bbp_loaded', 'bbp_constants' , 2 );20 add_action( 'bbp_loaded', 'bbp_boot_strap_globals' , 4 );21 add_action( 'bbp_loaded', 'bbp_includes' , 6 );22 add_action( 'bbp_loaded', 'bbp_setup_globals' , 8 );23 add_action( 'bbp_loaded', 'bbp_register_theme_directory' , 10 );20 add_action( 'bbp_loaded', 'bbp_constants' , 2 ); 21 add_action( 'bbp_loaded', 'bbp_boot_strap_globals' , 4 ); 22 add_action( 'bbp_loaded', 'bbp_includes' , 6 ); 23 add_action( 'bbp_loaded', 'bbp_setup_globals' , 8 ); 24 add_action( 'bbp_loaded', 'bbp_register_theme_directory' , 10 ); 24 25 25 26 // Attach to bbp_init. 26 add_action( 'bbp_init', 'bbp_register_post_types' , 4 ); 27 add_action( 'bbp_init', 'bbp_register_taxonomies' , 6 ); 28 add_action( 'bbp_init', 'bbp_register_textdomain' , 8 ); 29 add_action( 'bbp_init', 'bbp_ready' , 10 ); 27 add_action( 'bbp_init', 'bbp_register_post_types' , 4 ); 28 add_action( 'bbp_init', 'bbp_register_taxonomies' , 6 ); 29 add_action( 'bbp_init', 'bbp_register_textdomain' , 8 ); 30 add_action( 'bbp_init', 'bbp_add_user_rewrite_tag' , 10 ); 31 add_action( 'bbp_init', 'bbp_ready' , 14 ); 30 32 31 33 /** … … 126 128 127 129 /** 130 * bbp_add_user_rewrite_tag () 131 * 132 * Add the %bbp_user% rewrite tag 133 * 134 * @since bbPress (r2688) 135 */ 136 function bbp_add_user_rewrite_tag () { 137 do_action ( 'bbp_add_user_rewrite_tag' ); 138 } 139 140 /** 141 * bbp_generate_rewrite_rules () 142 * 143 * Generate rewrite rules, particularly for /profile/%bbp_user%/ pages 144 * 145 * @since bbPress (r2688) 146 * 147 * @param object $wp_rewrite 148 */ 149 function bbp_generate_rewrite_rules ( $wp_rewrite ) { 150 do_action_ref_array( 'bbp_generate_rewrite_rules', array( &$wp_rewrite ) ); 151 } 152 153 /** 128 154 * bbp_ready () 129 155 * -
branches/plugin/bbp-includes/bbp-users.php
r2686 r2688 2 2 3 3 /** 4 * bbp_has_access() 5 * 6 * Make sure user can perform special tasks 7 * 8 * @package bbPress 9 * @subpackage Functions 10 * @since bbPress (r2464) 11 * 12 * @uses is_super_admin () 13 * @uses apply_filters 14 * 15 * @todo bbPress port of existing roles/caps 16 * @return bool $has_access 17 */ 18 function bbp_has_access () { 19 20 if ( is_super_admin () ) 21 $has_access = true; 4 * bbp_is_anonymous () 5 * 6 * Return true if anonymous is allowed and user is not logged in. 7 * Return false if anonymous is not allowed or user is logged in 8 * 9 * @return bool 10 */ 11 function bbp_is_anonymous () { 12 if ( !is_user_logged_in() && bbp_allow_anonymous() ) 13 $is_anonymous = true; 22 14 else 23 $has_access = false; 24 25 return apply_filters( 'bbp_has_access', $has_access ); 26 } 15 $is_anonymous = false; 16 17 return apply_filters( 'bbp_is_anonymous', $is_anonymous ); 18 } 19 20 /** 21 * bbp_set_current_user () 22 * 23 * Sets the current user in bbPress scope 24 * 25 * @global bbPress $bbp 26 * @global WP_User $current_user 27 * @return If already set 28 */ 29 function bbp_set_current_user () { 30 global $bbp, $current_user; 31 32 // Don't set again 33 if ( isset( $bbp->current_user ) ) 34 return; 35 36 // Load current user if somehow it hasn't been set yet 37 if ( !isset( $current_user ) ) 38 wp_die( 'Loading the user too soon!' ); 39 40 // Set bbPress current user to WordPress current user 41 $bbp->current_user = $current_user; 42 } 43 add_action( 'bbp_init', 'bbp_set_current_user', 2 ); 27 44 28 45 /** … … 83 100 */ 84 101 function bbp_get_user_favorites ( $user_id = 0 ) { 102 // Default to the query var set before (if it is a profile page) 103 if ( empty( $user_id ) && bbp_is_user_profile_page() ) 104 $user_id = get_query_var( 'bbp_user_id' ); 105 85 106 // Default to author 86 107 if ( empty( $user_id ) ) 87 108 $user_id = get_the_author_meta( 'ID' ); 88 109 89 // If nothing passed and not an author page, return nothing 90 if ( empty( $user_id ) ) 91 return false; 92 93 // Get users' favorites 94 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 110 // If nothing passed and not an author/profile page, return nothing 111 if ( empty( $user_id ) ) 112 return false; 95 113 96 114 // If user has favorites, load them 97 if ( !empty( $favorites) ) {98 $query = bbp_has_topics( array( 'post__in' => $favorites , 'posts_per_page' => -1) );115 if ( $favorites = bbp_get_user_favorites_topic_ids( $user_id ) ) { 116 $query = bbp_has_topics( array( 'post__in' => $favorites ) ); 99 117 return apply_filters( 'bbp_get_user_favorites', $query, $user_id ); 100 118 } … … 122 140 $favorites = (array) explode( ',', $favorites ); 123 141 $favorites = array_filter( $favorites ); 124 $favorites = apply_filters( 'bbp_get_user_favorites_topic_ids', $favorites, $user_id ); 125 126 if ( !empty( $favorites ) ) 127 return $favorites; 128 129 return false; 142 143 return apply_filters( 'bbp_get_user_favorites_topic_ids', $favorites, $user_id ); 130 144 } 131 145 … … 294 308 */ 295 309 function bbp_get_user_subscriptions ( $user_id = 0 ) { 310 311 // Default to the displayed user 312 if ( empty( $user_id ) && bbp_is_user_profile_page() ) 313 $user_id = bbp_get_displayed_user_id(); 314 296 315 // Default to author 297 316 if ( empty( $user_id ) ) 298 317 $user_id = get_the_author_meta( 'ID' ); 299 318 300 // If nothing passed and not an author page, return nothing 301 if ( empty( $user_id ) ) 302 return false; 303 304 // Get users' subscriptions 305 $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id ); 319 // If nothing passed and not an author/profile page, return nothing 320 if ( empty( $user_id ) ) 321 return false; 306 322 307 323 // If user has subscriptions, load them 308 if ( !empty( $subscriptions) ) {309 $query = bbp_has_topics( array( 'post__in' => $subscriptions , 'posts_per_page' => -1) );310 return apply_filters( 'bbp_get_user_subscriptions', $query );324 if ( $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id ) ) { 325 $query = bbp_has_topics( array( 'post__in' => $subscriptions ) ); 326 return apply_filters( 'bbp_get_user_subscriptions', $query, $user_id ); 311 327 } 312 328 … … 333 349 $subscriptions = (array) explode( ',', $subscriptions ); 334 350 $subscriptions = array_filter( $subscriptions ); 335 $subscriptions = apply_filters( 'bbp_get_user_subscribed_topic_ids', $subscriptions ); 336 337 if ( !empty( $subscriptions ) ) 338 return $subscriptions; 339 340 return false; 351 352 return apply_filters( 'bbp_get_user_subscribed_topic_ids', $subscriptions ); 341 353 } 342 354 … … 355 367 */ 356 368 function bbp_is_user_subscribed ( $user_id = 0, $topic_id = 0 ) { 357 global $post, $current_user; 358 359 if ( empty( $user_id ) ) { 360 $current_user = wp_get_current_user(); 361 $user_id = $current_user->ID; 362 } 369 global $bbp, $post; 370 371 if ( empty( $user_id ) ) 372 $user_id = $bbp->current_user->ID; 363 373 364 374 if ( empty( $user_id ) ) … … 368 378 369 379 if ( !empty( $topic_id ) ) { 370 $post = get_post( $topic_id );380 $post = get_post( $topic_id ); 371 381 $topic_id = $post->ID; 372 382 } elseif ( !$topic_id = bbp_get_topic_id() ) { … … 475 485 */ 476 486 function bbp_get_user_topics_started ( $user_id = 0 ) { 487 // Default to the query var set before (if it is a profile page) 488 if ( empty( $user_id ) && bbp_is_user_profile_page() ) 489 $user_id = get_query_var( 'bbp_user_id' ); 490 477 491 // Default to author 478 492 if ( empty( $user_id ) ) 479 493 $user_id = get_the_author_meta( 'ID' ); 480 494 481 // If nothing passed and not an author page, return nothing495 // If nothing passed and not an author/profile page, return nothing 482 496 if ( empty( $user_id ) ) 483 497 return false; -
branches/plugin/bbp-themes/bbp-twentyten/css/bbpress.css
r2679 r2688 155 155 clear: left; 156 156 } 157 158 /* edit user */ 159 div.bbp-edit-user fieldset { 160 margin-top: 20px; 161 padding: 20px 20px 0 20px; 162 } 163 div.bbp-edit-user fieldset div { 164 margin-bottom: 20px; 165 float: left; 166 width: 100%; 167 clear: left; 168 } 169 div.bbp-edit-user fieldset textarea { 170 line-height: 0; 171 } 172 div.bbp-edit-user fieldset select { 173 margin-bottom: 0; 174 } 175 div.bbp-edit-user fieldset input, 176 div.bbp-edit-user fieldset textarea { 177 margin-bottom: 0; 178 width: 250px; 179 } 180 div.bbp-edit-user fieldset legend { 181 display: none; 182 } 183 div.bbp-edit-user fieldset label { 184 float: left; 185 width: 150px; 186 padding-right: 20px; 187 text-align: right; 188 } 189 div.bbp-edit-user fieldset span.description { 190 margin-left: 170px; 191 font-size: 12px; 192 font-style: italic; 193 float: left; 194 clear: left; 195 width: 233px; 196 padding: 5px 10px; 197 border: #E6DB55 1px solid; 198 background-color: #FFFBCC; 199 } 200 201 div.bbp-edit-user fieldset fieldset { 202 margin: 0; 203 width: 260px; 204 border: none; 205 padding: 0; 206 } 207 div.bbp-edit-user fieldset fieldset span.description { 208 margin-left: 0; 209 margin-bottom: 20px; 210 } 211 212 /* notices */ 213 div.bbp-template-notice { 214 border: #bbddbb 1px solid; 215 background-color: #ddffdd; 216 padding: 10px; 217 margin-top: 20px; 218 } 219 div.bbp-template-notice.important { 220 border: #E6DB55 1px solid; 221 background-color: #FFFBCC; 222 } 223 #main div.bbp-template-notice p { 224 margin: 0; 225 } -
branches/plugin/bbp-themes/bbp-twentyten/functions.php
r2679 r2688 98 98 99 99 /** 100 * bbp_twentyten_enqueue_topic_script () 101 * 102 * Enqueue the topic page Javascript file 103 * 104 * @package bbPress 105 * @subpackage bbPress TwentyTen 106 * @since bbPress (r2652) 107 * 108 * @return void 109 */ 110 function bbp_twentyten_enqueue_topic_script () { 111 if ( !bbp_is_topic() ) 112 return; 113 114 wp_enqueue_script( 'bbp_topic', get_stylesheet_directory_uri() . '/js/topic.js', array( 'wp-lists' ), '20101202' ); 115 } 116 add_filter( 'wp_enqueue_scripts', 'bbp_twentyten_enqueue_topic_script' ); 100 * bbp_twentyten_enqueue_scripts () 101 * 102 * Enqueue the required Javascript files 103 * 104 * @package bbPress 105 * @subpackage bbPress TwentyTen 106 * @since bbPress (r2652) 107 * 108 * @return void 109 */ 110 function bbp_twentyten_enqueue_scripts () { 111 if ( bbp_is_topic() ) 112 wp_enqueue_script( 'bbp_topic', get_stylesheet_directory_uri() . '/js/topic.js', array( 'wp-lists' ), '20101202' ); 113 114 if ( bbp_is_user_profile_edit() ) 115 wp_enqueue_script( 'user-profile' ); 116 } 117 add_action( 'wp_enqueue_scripts', 'bbp_twentyten_enqueue_scripts' ); 117 118 118 119 /** … … 128 129 */ 129 130 function bbp_twentyten_scripts () { 130 if ( !bbp_is_topic() ) 131 return; ?> 131 if ( bbp_is_topic() ) : ?> 132 132 133 133 <script type='text/javascript'> … … 137 137 </script> 138 138 139 <?php 139 <?php elseif ( bbp_is_user_profile_edit() ) : ?> 140 141 <script type="text/javascript" charset="utf-8"> 142 if ( window.location.hash == '#password' ) { 143 document.getElementById('pass1').focus(); 144 } 145 </script> 146 147 <?php 148 endif; 140 149 } 141 150 add_filter( 'wp_head', 'bbp_twentyten_scripts', -1 ); -
branches/plugin/bbp-themes/bbp-twentyten/loop-bbp_forums.php
r2679 r2688 44 44 </tr><!-- bbp-forum-<?php bbp_forum_id(); ?> --> 45 45 46 <?php endwhile; global $bbp_forums_template; unset( $bbp_forums_template );?>46 <?php endwhile; ?> 47 47 48 48 </table> -
branches/plugin/bbp-themes/bbp-twentyten/loop-bbp_topics.php
r2679 r2688 7 7 */ 8 8 9 if ( bbp_is_ favorites() || bbp_has_topics() ) : ?>9 if ( bbp_is_subscriptions() || bbp_is_favorites() || bbp_has_topics() ) : ?> 10 10 11 11 <?php get_template_part( 'pagination', 'bbp_topics' ); ?> … … 18 18 <th class="bbp-topic-voice-count"><?php _e( 'Voices', 'bbpress' ); ?></th> 19 19 <th class="bbp-topic-freshness"><?php _e( 'Freshness', 'bbpress' ); ?></th> 20 <?php if ( bbp_is_favorites() ) : ?><th class="bbp-topic-action"><?php _e( 'Favorite', 'bbpress' ); ?></th><?php endif; ?>20 <?php if ( ( bbp_is_user_home() && ( bbp_is_favorites() || bbp_is_subscriptions() ) ) ) : ?><th class="bbp-topic-action"><?php _e( 'Remove', 'bbpress' ); ?></th><?php endif; ?> 21 21 </tr> 22 22 </thead> 23 23 24 24 <tfoot> 25 <tr><td colspan="<?php echo bbp_is_favorites() ? '5' : '4'; ?>"> </td></tr>25 <tr><td colspan="<?php echo ( bbp_is_user_home() && ( bbp_is_favorites() || bbp_is_subscriptions() ) ) ? '5' : '4'; ?>"> </td></tr> 26 26 </tfoot> 27 27 … … 51 51 <td class="bbp-topic-freshness"><?php bbp_topic_freshness_link(); ?></td> 52 52 53 <?php if ( bbp_is_ favorites() ) : ?>53 <?php if ( bbp_is_user_home() ) : ?> 54 54 55 < td class="bbp-topic-action">55 <?php if ( bbp_is_favorites() ) : ?> 56 56 57 < ?php bbp_user_favorites_link( array( 'mid' => '+', 'post' => '' ), array( 'pre' => '', 'mid' => '×', 'post' => '' ) ); ?>57 <td class="bbp-topic-action"> 58 58 59 </td> 59 <?php bbp_user_favorites_link( array( 'mid' => '+', 'post' => '' ), array( 'pre' => '', 'mid' => '×', 'post' => '' ) ); ?> 60 61 </td> 62 63 <?php elseif ( bbp_is_subscriptions() ) : ?> 64 65 <td class="bbp-topic-action"> 66 67 <?php bbp_user_subscribe_link( array( 'before' => '', 'subscribe' => '+', 'unsubscribe' => '×' ) ); ?> 68 69 </td> 70 71 <?php endif; ?> 60 72 61 73 <?php endif; ?> -
branches/plugin/bbpress.php
r2679 r2688 40 40 var $reply_slug; 41 41 var $topic_tag_slug; 42 var $user_slug; 42 43 43 44 // Absolute Paths … … 54 55 var $current_topic_id; 55 56 var $current_reply_id; 57 58 // User objects 59 var $current_user; 60 var $displayed_user; 61 62 // Query objects 63 var $forum_query; 64 var $topic_query; 65 var $reply_query; 56 66 57 67 /** … … 101 111 $this->reply_slug = apply_filters( 'bbp_reply_slug', 'reply' ); 102 112 $this->topic_tag_slug = apply_filters( 'bbp_topic_tag_slug', 'topic-tag' ); 113 $this->user_slug = apply_filters( 'bbp_user_slug', 'user' ); 103 114 } 104 115 … … 120 131 require_once ( $this->plugin_dir . '/bbp-includes/bbp-widgets.php' ); 121 132 require_once ( $this->plugin_dir . '/bbp-includes/bbp-users.php' ); 122 require_once ( $this->plugin_dir . '/bbp-includes/bbp-template.php' ); 133 134 // Load template files 135 require_once ( $this->plugin_dir . '/bbp-includes/bbp-general-template.php' ); 136 require_once ( $this->plugin_dir . '/bbp-includes/bbp-forum-template.php' ); 137 require_once ( $this->plugin_dir . '/bbp-includes/bbp-topic-template.php' ); 138 require_once ( $this->plugin_dir . '/bbp-includes/bbp-reply-template.php' ); 139 require_once ( $this->plugin_dir . '/bbp-includes/bbp-user-template.php' ); 123 140 124 141 // Quick admin check and load if needed … … 148 165 // Load textdomain 149 166 add_action( 'bbp_load_textdomain', array ( $this, 'register_textdomain' ), 10, 2 ); 167 168 // Add the %bbp_user% rewrite tag 169 add_action( 'bbp_add_user_rewrite_tag', array ( $this, 'add_user_rewrite_tag' ), 10, 2 ); 170 171 // Generate rewrite rules, particularly for /profile/%bbp_user%/ pages 172 add_action( 'bbp_generate_rewrite_rules', array ( $this, 'generate_rewrite_rules' ), 10, 2 ); 150 173 } 151 174 … … 403 426 ); 404 427 } 428 429 /** 430 * add_user_rewrite_tag () 431 * 432 * Add the %bbp_user% rewrite tag 433 * 434 * @since bbPress (r2688) 435 * @uses add_rewrite_tag 436 */ 437 function add_user_rewrite_tag () { 438 add_rewrite_tag( '%bbp_user%', '([^/]+)' ); 439 add_rewrite_tag( '%bbp_edit_profile%', '([1]{1})' ); 440 } 441 442 /** 443 * generate_rewrite_rules () 444 * 445 * Generate rewrite rules for /profile/%bbp_user%/ pages 446 * 447 * @since bbPress (r2688) 448 * 449 * @param object $wp_rewrite 450 */ 451 function generate_rewrite_rules ( $wp_rewrite ) { 452 $user_rules = array( 453 // @todo - feeds 454 //$this->user_slug . '/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ) . '&feed=' . $wp_rewrite->preg_index( 2 ), 455 //$this->user_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ) . '&feed=' . $wp_rewrite->preg_index( 2 ), 456 $this->user_slug . '/([^/]+)/edit/?$' => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ) . '&bbp_edit_profile=1', 457 $this->user_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ), 458 $this->user_slug . '/([^/]+)/?$' => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ) 459 ); 460 461 $wp_rewrite->rules = array_merge( $user_rules, $wp_rewrite->rules ); 462 } 405 463 } 406 464
Note:
See TracChangeset
for help on using the changeset viewer.