Skip to:
Content

bbPress.org

Changeset 3799


Ignore:
Timestamp:
03/09/2012 11:03:12 PM (10 years ago)
Author:
johnjamesjacoby
Message:

BuddyPress group forums:

  • Fix new reply and topic redirects
  • Remove first group forum topic and reply in lieu of more customization
  • See #1669
  • Fixes #1776
  • Fixes #1778
  • Fixes #1777
  • Props boonebgorges
Location:
branches/plugin/bbp-includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-extend-buddypress.php

    r3789 r3799  
    966966        add_action( 'bp_actions', 'bbp_edit_topic_handler' );
    967967        add_action( 'bp_actions', 'bbp_edit_reply_handler' );
     968
     969        // Tweak the redirect field
     970        add_filter( 'bbp_new_topic_redirect_to', array( $this, 'new_topic_redirect_to' ), 10, 3 );
     971        add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to' ), 10, 2 );
    968972    }
    969973
     
    987991        // Hide breadcrumb
    988992        add_filter( 'bbp_no_breadcrumb', '__return_true' );
    989 
    990         // Tweak the redirect field
    991         add_filter( 'bbp_new_topic_redirect_to', array( $this, 'new_topic_redirect_to' ), 10, 2 );
    992         add_filter( 'bbp_new_reply_redirect_to', array( $this, 'new_reply_redirect_to' ), 10, 2 );
    993993
    994994        $this->display_forums( 0 );
     
    11931193            return false;
    11941194
    1195         $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' );
    1196         ?>
     1195        $checked = bp_get_new_group_enable_forum() || groups_get_groupmeta( bp_get_new_group_id(), 'forum_id' ); ?>
    11971196
    11981197        <h4><?php _e( 'Group Forums', 'buddypress' ); ?></h4>
     
    12541253                ) );
    12551254
    1256                 // Create the initial topic
    1257                 $topic_id = bbp_insert_topic(
    1258                     array(
    1259                         'post_parent'  => $forum_id,
    1260                         'post_title'   => __( 'Hello World!', 'bbpress' ),
    1261                         'post_content' => __( 'I am the first topic in your group forum. You can keep me, edit me, trash me, or delete me.', 'bbpress' )
    1262                     ),
    1263                     array( 'forum_id'  => $forum_id )
    1264                 );
    1265 
    1266                 // Create the initial reply
    1267                 $reply_id = bbp_insert_reply(
    1268                     array(
    1269                         'post_parent'  => $topic_id,
    1270                         'post_title'   => __( 'Re: Hello World!', 'bbpress' ),
    1271                         'post_content' => __( 'Oh, and this is what a reply looks like.', 'bbpress' )
    1272                     ),
    1273                     array(
    1274                         'forum_id'     => $forum_id,
    1275                         'topic_id'     => $topic_id
    1276                     )
    1277                 );
    1278 
    12791255                // Add the ID's to group meta
    1280                 groups_update_groupmeta( bp_get_new_group_id(), 'forum_id',       $forum_id );
    1281                 groups_update_groupmeta( bp_get_new_group_id(), 'first_topic_id', $topic_id );
    1282                 groups_update_groupmeta( bp_get_new_group_id(), 'first_reply_id', $reply_id );
     1256                groups_update_groupmeta( bp_get_new_group_id(), 'forum_id', $forum_id );
    12831257
    12841258                break;
     
    12871261                // Forum was created but is now being undone
    12881262                if ( !empty( $forum_id ) ) {
    1289                     $topic_id = groups_get_groupmeta( bp_get_new_group_id(), 'first_topic_id' );
    1290                     $reply_id = groups_get_groupmeta( bp_get_new_group_id(), 'first_reply_id' );
    1291 
    1292                     // Delete initial content
    12931263                    wp_delete_post( $forum_id, true );
    1294                     wp_delete_post( $topic_id, true );
    1295                     wp_delete_post( $reply_id, true );
    1296 
    1297                     // Remove the forum ID to group meta
    1298                     groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id'       );
    1299                     groups_delete_groupmeta( bp_get_new_group_id(), 'first_topic_id' );
    1300                     groups_delete_groupmeta( bp_get_new_group_id(), 'first_reply_id' );
     1264                    groups_delete_groupmeta( bp_get_new_group_id(), 'forum_id' );
    13011265                }
    13021266
     
    15721536     *
    15731537     * @since bbPress (r3653)
     1538     * @param str $redirect_url
     1539     * @param str $redirect_to
     1540     */
     1541    public function new_topic_redirect_to( $redirect_url = '', $redirect_to = '', $topic_id = 0 ) {
     1542        if ( bp_is_group() ) {
     1543            $topic        = bbp_get_topic( $topic_id );
     1544            $topic_hash   = '#post-' . $topic_id;
     1545            $redirect_url = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash;
     1546        }
     1547
     1548        return $redirect_url;
     1549    }
     1550
     1551    /**
     1552     * Redirect to the group forum screen
     1553     *
     1554     * @since bbPress (r3653)
     1555     */
     1556    public function new_reply_redirect_to( $redirect_url = '', $redirect_to = '', $reply_id = 0 ) {
     1557        global $wp_rewrite;
     1558       
     1559        if ( bp_is_group() ) {
     1560            $topic_id       = bbp_get_reply_topic_id( $reply_id );
     1561            $topic          = bbp_get_topic( $topic_id );
     1562            $reply_position = bbp_get_reply_position( $reply_id, $topic_id );
     1563            $reply_page     = ceil( (int) $reply_position / (int) bbp_get_replies_per_page() );
     1564            $reply_hash     = '#post-' . $reply_id;
     1565            $topic_url      = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name );
     1566           
     1567            // Don't include pagination if on first page
     1568            if ( 1 >= $reply_page ) {
     1569                $redirect_url = trailingslashit( $topic_url ) . $reply_hash;
     1570   
     1571            // Include pagination
     1572            } else {
     1573                $redirect_url = trailingslashit( $topic_url ) . trailingslashit( $wp_rewrite->pagination_base ) . trailingslashit( $reply_page ) . $reply_hash;
     1574            }
     1575   
     1576            // Add topic view query arg back to end if it is set
     1577            if ( bbp_get_view_all() ) {
     1578                $redirect_url = bbp_add_view_all( $redirect_url );
     1579            }
     1580        }
     1581       
     1582        return $redirect_url;
     1583    }
     1584
     1585    /**
     1586     * Redirect to the group admin forum edit screen
     1587     *
     1588     * @since bbPress (r3653)
    15741589     *
    15751590     * @uses groups_get_current_group()
     
    15791594     * @uses bp_get_groups_root_slug()
    15801595     */
    1581     public function new_topic_redirect_to( $redirect_url = '', $redirect_to = '' ) {
    1582         return $redirect_url;
    1583     }
    1584 
    1585     /**
    1586      * Redirect to the group admin forum edit screen
    1587      *
    1588      * @since bbPress (r3653)
    1589      *
    1590      * @uses groups_get_current_group()
    1591      * @uses bp_is_group_admin_screen()
    1592      * @uses trailingslashit()
    1593      * @uses bp_get_root_domain()
    1594      * @uses bp_get_groups_root_slug()
    1595      */
    15961596    public function edit_redirect_to( $redirect_url = '' ) {
    15971597
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3790 r3799  
    16281628function bbp_forum_query_subforum_ids( $forum_id ) {
    16291629    $subforum_ids = bbp_get_public_child_ids( $forum_id, bbp_get_forum_post_type() );
    1630     usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' );
     1630    //usort( $subforum_ids, '_bbp_forum_query_usort_subforum_ids' );
    16311631
    16321632    return apply_filters( 'bbp_get_forum_subforum_ids', $subforum_ids, $forum_id );
  • branches/plugin/bbp-includes/bbp-reply-functions.php

    r3767 r3799  
    314314
    315315            // Allow to be filtered
    316             $reply_url = apply_filters( 'bbp_new_reply_redirect_to', $reply_url, $redirect_to );
     316            $reply_url = apply_filters( 'bbp_new_reply_redirect_to', $reply_url, $redirect_to, $reply_id );
    317317
    318318            /** Successful Save ***********************************************/
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r3767 r3799  
    365365
    366366            // Allow to be filtered
    367             $redirect_url = apply_filters( 'bbp_new_topic_redirect_to', $redirect_url, $redirect_to );
     367            $redirect_url = apply_filters( 'bbp_new_topic_redirect_to', $redirect_url, $redirect_to, $topic_id );
    368368
    369369            /** Successful Save ***********************************************/
Note: See TracChangeset for help on using the changeset viewer.