Skip to:
Content

bbPress.org

Changeset 2914


Ignore:
Timestamp:
02/18/2011 10:16:22 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Decouple bbp_is_ functionality from bbp_get_{post_type}_id functionality, and use correctly through-out. Add ability to show all forums regardless of post_parent, and fix forums widget to use this functionality correctly.

Location:
branches/plugin/bbp-includes
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r2908 r2914  
    186186 * @param int $reply_id Optional. Reply id
    187187 * @uses bbp_get_forum_id() To get the forum id
    188  * @uses bbp_get_reply_id() To get the reply id
    189188 * @uses update_post_meta() To update the forum's last reply id meta
    190189 * @return bool True on success, false on failure
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r2905 r2914  
    6464
    6565    $r = wp_parse_args( $args, $default );
     66
     67    // Allow all forums to be queried if post_parent is set to -1
     68    if ( -1 == $r['post_parent'] )
     69        unset( $r['post_parent'] );
    6670
    6771    // Don't show private forums to normal users
     
    152156        // Fallback
    153157        else
    154             $bbp_forum_id = 0;
    155 
    156         // Check the post_type for good measure
    157         if ( get_post_field( 'post_type', $bbp_forum_id ) != bbp_get_forum_post_type() )
    158158            $bbp_forum_id = 0;
    159159
     
    416416            $active_id = bbp_get_forum_last_topic_id( $forum_id );
    417417
    418         if ( bbp_get_topic_id( $active_id ) ) {
     418        if ( bbp_is_topic( $active_id ) ) {
    419419            $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
    420420            $title    = bbp_get_forum_last_topic_title( $forum_id );
    421         } elseif ( bbp_get_reply_id( $active_id ) ) {
     421        } elseif ( bbp_is_reply( $active_id ) ) {
    422422            $link_url = bbp_get_forum_last_reply_url( $forum_id );
    423423            $title    = bbp_get_forum_last_reply_title( $forum_id );
     
    488488 *                           reading private forums
    489489 * @uses get_posts() To get the subforums
    490  * @uses apply_filters() Calls 'bbp_forum_has_subforums' with the subforums
     490 * @uses apply_filters() Calls 'bbp_forum_get_subforums' with the subforums
    491491 *                        and the args
    492492 * @return mixed false if none, array of subs if yes
    493493 */
    494 function bbp_forum_has_subforums( $args = '' ) {
     494function bbp_forum_get_subforums( $args = '' ) {
    495495    if ( is_numeric( $args ) )
    496496        $args = array( 'post_parent' => $args );
     
    516516    $sub_forums = !empty( $r['post_parent'] ) ? get_posts( $r ) : '';
    517517
    518     return apply_filters( 'bbp_forum_has_sub_forums', (array) $sub_forums, $args );
     518    return apply_filters( 'bbp_forum_get_sub_forums', (array) $sub_forums, $args );
    519519}
    520520
     
    533533 *  - show_topic_count - To show forum topic count or not. Defaults to true
    534534 *  - show_reply_count - To show forum reply count or not. Defaults to true
    535  * @uses bbp_forum_has_subforums() To check if the forum has subforums or not
     535 * @uses bbp_forum_get_subforums() To check if the forum has subforums or not
    536536 * @uses bbp_get_forum_permalink() To get forum permalink
    537537 * @uses bbp_get_forum_title() To get forum title
     
    565565
    566566    // Loop through forums and create a list
    567     if ( $sub_forums = bbp_forum_has_subforums( $forum_id ) ) {
     567    if ( $sub_forums = bbp_forum_get_subforums( $forum_id ) ) {
    568568        // Total count (for separator)
    569569        $total_subs = count( $sub_forums );
  • branches/plugin/bbp-includes/bbp-general-template.php

    r2905 r2914  
    4747    global $wp_query, $bbp;
    4848
    49     if ( is_singular( bbp_get_forum_post_type() ) )
    50         return true;
    51 
    52     if ( isset( $wp_query->query_vars['post_type'] ) && bbp_get_forum_post_type() === $wp_query->query_vars['post_type'] )
    53         return true;
    54 
    55     if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && bbp_get_forum_post_type() === $_GET['post_type'] )
    56         return true;
    57 
    58     if ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_field( 'post_type', $post_id ) ) )
     49    if ( empty( $post_id ) ) {
     50
     51        if ( is_singular( bbp_get_forum_post_type() ) )
     52            return true;
     53
     54        if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_forum_post_type() === $wp_query->query_vars['post_type'] ) )
     55            return true;
     56
     57        if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_forum_post_type() === $_GET['post_type'] ) )
     58            return true;
     59
     60    } elseif ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_field( 'post_type', $post_id ) ) )
    5961        return true;
    6062
     
    8082        return false;
    8183
    82     if ( is_singular( bbp_get_topic_post_type() ) )
    83         return true;
    84 
    85     if ( isset( $wp_query->query_vars['post_type'] ) && bbp_get_topic_post_type() === $wp_query->query_vars['post_type'] )
    86         return true;
    87 
    88     if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && bbp_get_topic_post_type() === $_GET['post_type'] )
    89         return true;
    90 
    91     if ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_field( 'post_type', $post_id ) ) )
     84    if ( empty( $post_id ) ) {
     85
     86        if ( is_singular( bbp_get_topic_post_type() ) )
     87            return true;
     88
     89        if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_topic_post_type() === $wp_query->query_vars['post_type'] ) )
     90            return true;
     91
     92        if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_topic_post_type() === $_GET['post_type'] ) )
     93            return true;
     94
     95    } elseif ( !empty( $post_id ) && ( bbp_get_topic_post_type() == get_post_field( 'post_type', $post_id ) ) )
    9296        return true;
    9397
     
    122126function bbp_is_topic_merge() {
    123127
    124     if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && 'merge' == $_GET['action'] )
     128    if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
    125129        return true;
    126130
     
    138142function bbp_is_topic_split() {
    139143
    140     if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && 'split' == $_GET['action'] )
     144    if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
    141145        return true;
    142146
     
    162166        return false;
    163167
    164     if ( is_singular( bbp_get_reply_post_type() ) )
    165         return true;
    166 
    167     if ( isset( $wp_query->query_vars['post_type'] ) && bbp_get_reply_post_type() === $wp_query->query_vars['post_type'] )
    168         return true;
    169 
    170     if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && bbp_get_reply_post_type() === $_GET['post_type'] )
    171         return true;
    172 
    173     if ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_field( 'post_type', $post_id ) ) )
     168    if ( empty( $post_id ) ) {
     169
     170        if ( is_singular( bbp_get_reply_post_type() ) )
     171            return true;
     172
     173        if ( isset( $wp_query->query_vars['post_type'] ) && ( bbp_get_reply_post_type() === $wp_query->query_vars['post_type'] ) )
     174            return true;
     175
     176        if ( isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) && ( bbp_get_reply_post_type() === $_GET['post_type'] ) )
     177            return true;
     178
     179    } elseif ( !empty( $post_id ) && ( bbp_get_reply_post_type() == get_post_field( 'post_type', $post_id ) ) )
    174180        return true;
    175181
     
    188194    global $wp_query;
    189195
    190     if ( !empty( $wp_query->bbp_is_reply_edit ) && $wp_query->bbp_is_reply_edit == true )
     196    if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) )
    191197        return true;
    192198
     
    211217        return false;
    212218
    213     if ( !empty( $query_name_check ) && 'bbp_user_profile_favorites' != bbp_get_query_name() )
     219    if ( !empty( $query_name_check ) && ( 'bbp_user_profile_favorites' != bbp_get_query_name() ) )
    214220        return false;
    215221
     
    234240        return false;
    235241
    236     if ( !empty( $query_name_check ) && 'bbp_user_profile_subscriptions' != bbp_get_query_name() )
     242    if ( !empty( $query_name_check ) && ( 'bbp_user_profile_subscriptions' != bbp_get_query_name() ) )
    237243        return false;
    238244
     
    258264        return false;
    259265
    260     if ( !empty( $query_name_check ) && 'bbp_user_profile_topics_created' != bbp_get_query_name() )
     266    if ( !empty( $query_name_check ) && ( 'bbp_user_profile_topics_created' != bbp_get_query_name() ) )
    261267        return false;
    262268
     
    292298    global $wp_query;
    293299
    294     if ( !empty( $wp_query->bbp_is_user_profile_page ) && $wp_query->bbp_is_user_profile_page == true )
     300    if ( !empty( $wp_query->bbp_is_user_profile_page ) && ( true == $wp_query->bbp_is_user_profile_page ) )
    295301        return true;
    296302
     
    309315    global $wp_query;
    310316
    311     if ( !empty( $wp_query->bbp_is_user_profile_edit ) && $wp_query->bbp_is_user_profile_edit == true )
     317    if ( !empty( $wp_query->bbp_is_user_profile_edit ) && ( true == $wp_query->bbp_is_user_profile_edit ) )
    312318        return true;
    313319
     
    326332    global $wp_query;
    327333
    328     if ( !empty( $wp_query->bbp_is_view ) && $wp_query->bbp_is_view == true )
     334    if ( !empty( $wp_query->bbp_is_view ) && ( true == $wp_query->bbp_is_view ) )
    329335        return true;
    330336
  • branches/plugin/bbp-includes/bbp-reply-functions.php

    r2905 r2914  
    430430
    431431        // Reply meta relating to most recent reply
    432         if ( bbp_get_reply_id( $ancestor ) ) {
     432        if ( bbp_is_reply( $ancestor ) ) {
    433433            // @todo - hierarchical replies
    434434
    435435        // Topic meta relating to most recent reply
    436         } elseif ( bbp_get_topic_id( $ancestor ) ) {
     436        } elseif ( bbp_is_topic( $ancestor ) ) {
    437437
    438438            // Last reply and active ID's
     
    454454
    455455        // Forum meta relating to most recent topic
    456         } elseif ( bbp_get_forum_id( $ancestor ) ) {
     456        } elseif ( bbp_is_forum( $ancestor ) ) {
    457457
    458458            // Last topic and reply ID's
  • branches/plugin/bbp-includes/bbp-reply-template.php

    r2905 r2914  
    195195        // Fallback
    196196        else
    197             $bbp_reply_id = 0;
    198 
    199         // Check the post_type for good measure
    200         if ( get_post_field( 'post_type', $bbp_reply_id ) != bbp_get_reply_post_type() )
    201197            $bbp_reply_id = 0;
    202198
     
    502498        // Create necessary variables
    503499        $reply_id     = bbp_get_reply_id( $reply_id );
    504         $revisions    = bbp_get_reply_revisions( $reply_id );
    505500        $revision_log = bbp_get_reply_raw_revision_log( $reply_id );
    506501
    507         if ( empty( $reply_id ) || empty( $revisions ) || empty( $revision_log ) || !is_array( $revisions ) || !is_array( $revision_log ) )
     502        // Check reply and revision log exist
     503        if ( empty( $reply_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
     504            return false;
     505
     506        // Get the actual revisions
     507        if ( !$revisions = bbp_get_reply_revisions( $reply_id ) )
    508508            return false;
    509509
     
    547547         */
    548548        function bbp_get_reply_raw_revision_log( $reply_id = 0 ) {
    549             $reply_id = bbp_get_reply_id( $reply_id );
    550 
     549            $reply_id     = bbp_get_reply_id( $reply_id );
    551550            $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true );
    552551            $revision_log = empty( $revision_log ) ? array() : $revision_log;
     
    628627
    629628    // Finally, update
    630     return update_post_meta( $reply_id, '_bbp_revision_log', $revision_log );
     629    update_post_meta( $reply_id, '_bbp_revision_log', $revision_log );
     630
     631    return apply_filters( 'bbp_update_reply_revision_log', $revision_log, $reply_id );
    631632}
    632633
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r2907 r2914  
    13581358
    13591359    // If it's a reply, then get the parent (topic id)
    1360     if ( $reply_id = bbp_get_reply_id( $topic_id ) )
    1361         $topic_id = bbp_get_reply_topic_id( $reply_id );
     1360    if ( bbp_is_reply( $topic_id ) )
     1361        $topic_id = bbp_get_reply_topic_id( $topic_id );
    13621362    else
    13631363        $topic_id = bbp_get_topic_id( $topic_id );
     
    13911391
    13921392    // If it's a reply, then get the parent (topic id)
    1393     if ( $reply_id = bbp_get_reply_id( $topic_id ) )
     1393    if ( bbp_is_reply( $topic_id ) )
    13941394        $topic_id = bbp_get_reply_topic_id( $reply_id );
    13951395    else
     
    14261426
    14271427    // If it's a reply, then get the parent (topic id)
    1428     if ( $reply_id = bbp_get_reply_id( $topic_id ) )
    1429         $topic_id = bbp_get_reply_topic_id( $reply_id );
     1428    if ( bbp_is_reply( $topic_id ) )
     1429        $topic_id = bbp_get_reply_topic_id( $topic_id );
    14301430    else
    14311431        $topic_id = bbp_get_topic_id( $topic_id );
     
    14551455
    14561456    // If it's a reply, then get the parent (topic id)
    1457     if ( $reply_id = bbp_get_reply_id( $topic_id ) )
    1458         $topic_id = bbp_get_reply_topic_id( $reply_id );
     1457    if ( bbp_is_reply( $topic_id ) )
     1458        $topic_id = bbp_get_reply_topic_id( $topic_id );
    14591459    else
    14601460        $topic_id = bbp_get_topic_id( $topic_id );
     
    14881488
    14891489    // If it's a reply, then get the parent (topic id)
    1490     if ( $reply_id = bbp_get_reply_id( $topic_id ) )
     1490    if ( bbp_is_reply( $topic_id ) )
    14911491        $topic_id = bbp_get_reply_topic_id( $reply_id );
    14921492    else
     
    15171517
    15181518    // If it's a reply, then get the parent (topic id)
    1519     if ( empty( $reply_id ) && $reply_id = bbp_get_reply_id( $topic_id ) ) {
     1519    if ( empty( $reply_id ) && bbp_is_reply( $topic_id ) ) {
     1520        $reply_id = bbp_get_reply_id( $topic_id );
    15201521        $topic_id = bbp_get_reply_topic_id( $reply_id );
    15211522    } else {
     
    15561557
    15571558    // If it's a reply, then get the parent (topic id)
    1558     if ( $reply_id = bbp_get_reply_id( $topic_id ) )
    1559         $topic_id = bbp_get_reply_topic_id( $reply_id );
     1559    if ( bbp_is_reply( $topic_id ) )
     1560        $topic_id = bbp_get_reply_topic_id( $topic_id );
    15601561    else
    15611562        $topic_id = bbp_get_topic_id( $topic_id );
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r2905 r2914  
    314314            $bbp_topic_id = 0;
    315315
    316         // Check the post_type for good measure
    317         if ( get_post_field( 'post_type', $bbp_topic_id ) != bbp_get_topic_post_type() )
    318             $bbp_topic_id = 0;
    319 
    320316        $bbp->current_topic_id = $bbp_topic_id;
    321317
     
    552548        // Create necessary variables
    553549        $topic_id     = bbp_get_topic_id( $topic_id );
    554         $revisions    = bbp_get_topic_revisions( $topic_id );
    555550        $revision_log = bbp_get_topic_raw_revision_log( $topic_id );
    556551
    557         if ( empty( $topic_id ) || empty( $revisions ) || empty( $revision_log ) || !is_array( $revisions ) || !is_array( $revision_log ) )
     552        if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
     553            return false;
     554
     555        if ( !$revisions = bbp_get_topic_revisions( $topic_id ) )
    558556            return false;
    559557
  • branches/plugin/bbp-includes/bbp-user-template.php

    r2894 r2914  
    889889            $post_id = $args;
    890890
    891         if ( bbp_get_topic_id( $post_id ) )
     891        if ( bbp_is_topic( $post_id ) )
    892892            return bbp_get_topic_author_link( $args );
    893         elseif ( bbp_get_reply_id( $post_id ) )
     893        elseif ( bbp_is_reply( $post_id ) )
    894894            return bbp_get_reply_author_link( $args );
    895895        else
  • branches/plugin/bbp-includes/bbp-widgets.php

    r2879 r2914  
    194194
    195195        $title        = apply_filters( 'bbp_forum_widget_title', $instance['title'] );
    196         $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : false;
     196        $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 0;
    197197
    198198        $default = array(
    199199            'post_parent'    => $parent_forum,
    200             'posts_per_page' => -1,
     200            'posts_per_page' => get_option( '_bbp_forums_per_page', 15 ),
    201201            'orderby'        => 'menu_order',
    202202            'order'          => 'ASC'
    203203        );
    204204
     205        // Don't show private forums to normal users
     206        if ( !current_user_can( 'read_private_forums' ) && empty( $default['meta_key'] ) && empty( $default['meta_value'] ) ) {
     207            $default['meta_key']   = '_bbp_visibility';
     208            $default['meta_value'] = 'public';
     209        }
     210
    205211        if ( bbp_has_forums( $default ) ) :
    206212
     
    234240        $instance                 = $old_instance;
    235241        $instance['title']        = strip_tags( $new_instance['title']        );
    236         $instance['parent_forum'] = absint    ( $new_instance['parent_forum'] );
     242        $instance['parent_forum'] = $new_instance['parent_forum'];
    237243
    238244        return $instance;
     
    250256    function form( $instance ) {
    251257        $title        = !empty( $instance['title']        ) ? esc_attr( $instance['title']        ) : '';
    252         $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : ''; ?>
     258        $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : 0; ?>
    253259
    254260        <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
     
    260266            <br />
    261267
    262             <small><?php _e( 'Forum ID number. Blank to display all top level forums, "null" to display all forums.', 'bbpress' ); ?></small>
     268            <small><?php _e( 'Forum ID number. "0" to show only root forums, "-1" to display all forums.', 'bbpress' ); ?></small>
    263269        </p>
    264270
     
    321327        $max_shown    = !empty( $instance['max_shown']    ) ? $instance['max_shown']    : '5';
    322328        $show_date    = !empty( $instance['show_date']    ) ? 'on'                      : false;
    323         $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : false;
     329        $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 0;
    324330        $pop_check    = ( $instance['pop_check'] < $max_shown || empty( $instance['pop_check'] ) ) ? -1 : $instance['pop_check'];
    325331
Note: See TracChangeset for help on using the changeset viewer.