Skip to:
Content

bbPress.org

Ticket #3430: 3430.01.patch

File 3430.01.patch, 4.9 KB (added by r-a-y, 4 years ago)
  • src/includes/extend/buddypress/functions.php

     
    129129                if ( bp_is_group_forum_topic() || bp_is_group_forum_topic_edit() ) {
    130130
    131131                        // Get the topic
    132                         $topic = get_posts( array(
     132                        $topic_args = array(
    133133                                'name'        => bp_action_variable( 1 ),
    134134                                'post_status' => array_keys( bbp_get_topic_statuses() ),
    135135                                'post_type'   => bbp_get_topic_post_type(),
    136136                                'numberposts' => 1
    137                         ) );
     137                        );
     138
     139                        // Pending topic requires a different format
     140                        $pending_prefix = bbp_get_pending_status_id() . '-';
     141                        if ( 0 === strpos( bp_action_variable( 1 ), $pending_prefix ) ) {
     142                                $id = substr( bp_action_variable( 1 ), strlen( $pending_prefix ) );
     143                                if ( is_numeric( $id ) ) {
     144                                        $topic_args['p'] = $id;
     145                                        unset( $topic_args['name'] );
     146                                }
     147                        }
     148
     149                        $topic = get_posts( $topic_args );
    138150
    139151                        // Add the topic title to the <title>
    140152                        $new_title .= bbp_get_topic_title( $topic[0]->ID ) . ' ' . $sep . ' ';
  • src/includes/extend/buddypress/groups.php

     
    10281028                                        // hide the 'to front' admin links
    10291029                                        add_filter( 'bbp_get_topic_stick_link', array( $this, 'hide_super_sticky_admin_link' ), 10, 2 );
    10301030
    1031                                         // Get the topic
    1032                                         bbp_has_topics( array(
    1033                                                 'name'           => bp_action_variable( $offset + 1 ),
     1031                                        $slug = bp_action_variable( $offset + 1 );
     1032
     1033                                        $topic_args = array(
     1034                                                'name'           => $slug,
    10341035                                                'posts_per_page' => 1,
    10351036                                                'show_stickies'  => false
    1036                                         ) );
     1037                                        );
     1038
     1039                                        // Pending topic requires a different format
     1040                                        $pending_prefix = bbp_get_pending_status_id() . '-';
     1041                                        if ( 0 === strpos( $slug, $pending_prefix ) ) {
     1042                                                $id = substr( $slug, strlen( $pending_prefix ) );
     1043                                                if ( is_numeric( $id ) ) {
     1044                                                        $topic_args['p'] = $id;
     1045                                                        unset( $topic_args['name'] );
     1046                                                }
     1047                                        }
     1048
     1049                                        // Get the topic
     1050                                        bbp_has_topics( $topic_args );
    10371051
    10381052                                        // If no topic, 404
    10391053                                        if ( ! bbp_topics() ) {
     
    12321246         */
    12331247        public function new_topic_redirect_to( $redirect_url = '', $redirect_to = '', $topic_id = 0 ) {
    12341248                if ( bp_is_group() ) {
    1235                         $topic        = bbp_get_topic( $topic_id );
    1236                         $topic_hash   = '#post-' . $topic_id;
    1237                         $redirect_url = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . trailingslashit( $topic->post_name ) . $topic_hash;
     1249                        $topic      = bbp_get_topic( $topic_id );
     1250                        $slug       = trailingslashit( $topic->post_name );
     1251                        $topic_hash = '#post-' . $topic_id;
     1252
     1253                        // Pending status
     1254                        if ( bbp_get_pending_status_id() === get_post_status( $topic_id ) ) {
     1255                                $slug = bbp_add_view_all( sprintf( 'pending-%d', $topic_id ), true );
     1256                        }
     1257
     1258                        $redirect_url = trailingslashit( bp_get_group_permalink( groups_get_current_group() ) ) . trailingslashit( $this->slug ) . trailingslashit( $this->topic_slug ) . $slug . $topic_hash;
    12381259                }
    12391260
    12401261                return $redirect_url;
     
    14321453                        case bbp_get_topic_post_type() :
    14331454                                $topic_id = $post_id;
    14341455                                $forum_id = bbp_get_topic_forum_id( $post_id );
    1435                                 $url_end  = trailingslashit( $this->topic_slug ) . get_post_field( 'post_name', $post_id );
     1456                                $url_end  = trailingslashit( $this->topic_slug );
     1457
     1458                                // Pending status
     1459                                if ( bbp_get_pending_status_id() === get_post_status( $post_id ) ) {
     1460                                        $url_end .= sprintf( 'pending-%d/', $post_id );
     1461
     1462                                // Everything else
     1463                                } else {
     1464                                        $url_end .= get_post_field( 'post_name', $post_id );
     1465                                }
    14361466                                break;
    14371467
    14381468                        // Forum
     
    14641494                        $group_permalink = trailingslashit( bp_get_group_permalink( $group ) );
    14651495                }
    14661496
    1467                 return trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );
     1497                $retval = trailingslashit( trailingslashit( $group_permalink . $this->slug ) . $url_end );
     1498
     1499                if ( bbp_get_pending_status_id() === get_post_status( $post_id ) ) {
     1500                        $retval = bbp_add_view_all( $retval, true );
     1501                }
     1502
     1503                return $retval;
    14681504        }
    14691505
    14701506        /**
     
    16321668                        $forum_id  = bbp_get_topic_forum_id( $topic_id );
    16331669                        $group_ids = bbp_get_forum_group_ids( $forum_id );
    16341670
     1671                        // Pending status
     1672                        if ( bbp_get_pending_status_id() === get_post_status( $topic_id ) ) {
     1673                                $slug = sprintf( '%s-%d', bbp_get_pending_status_id(), $topic_id );
     1674                        }
     1675
    16351676                // Not a forum or topic
    16361677                } else {
    16371678                        return;
     
    16511692                // Add topic slug to URL
    16521693                if ( bbp_is_single_topic() ) {
    16531694                        $redirect_to  = trailingslashit( $redirect_to . $this->topic_slug . '/' . $slug );
     1695
     1696                        if ( bbp_get_pending_status_id() === get_post_status( $topic_id ) ) {
     1697                                $redirect_to = bbp_add_view_all( $redirect_to, true );
     1698                        }
    16541699                }
    16551700
    16561701                bp_core_redirect( $redirect_to );