Skip to:
Content

bbPress.org

Changeset 3136


Ignore:
Timestamp:
05/11/2011 10:47:51 PM (11 years ago)
Author:
johnjamesjacoby
Message:

More security sweep and final code clean-up on bbp-topic-functions.php. See #1514.

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

Legend:

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

    r3135 r3136  
    10871087        global $wpdb, $bbp;
    10881088
    1089         if ( !$from_reply_id = (int) $_POST['bbp_reply_id'] )
     1089        // Prevent debug notices
     1090        $from_reply_id = $destination_topic_id = 0;
     1091        $destination_topic_title = '';
     1092        $destination_topic = $from_reply = $source_topic = '';
     1093        $split_option = false;
     1094
     1095        /** Split Reply *******************************************************/
     1096
     1097        if ( empty( $_POST['bbp_reply_id'] ) )
    10901098            $bbp->errors->add( 'bbp_split_topic_reply_id', __( '<strong>ERROR</strong>: Reply ID to split the topic from not found!', 'bbpress' ) );
    1091 
    1092         if ( !$from_reply = bbp_get_reply( $from_reply_id ) )
    1093             $bbp->errors->add( 'bbp_split_topic_r_not_found', __( '<strong>ERROR</strong>: The reply you want to split from was not found!', 'bbpress' ) );
    1094 
    1095         if ( !$source_topic = bbp_get_topic( $from_reply->post_parent ) )
    1096             $bbp->errors->add( 'bbp_split_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to split was not found!', 'bbpress' ) );
     1099        else
     1100            $from_reply_id = (int) $_POST['bbp_reply_id'];
     1101
     1102        $from_reply = bbp_get_reply( $from_reply_id );
     1103
     1104        // Reply exists
     1105        if ( empty( $from_reply ) )
     1106            $bbp->errors->add( 'bbp_split_topic_r_not_found', __( '<strong>ERROR</strong>: The reply you want to split from was not found.', 'bbpress' ) );
     1107
     1108        /** Topic to Split ****************************************************/
     1109
     1110        // Get the topic being split
     1111        $source_topic = bbp_get_topic( $from_reply->post_parent );
     1112
     1113        // No topic
     1114        if ( empty( $source_topic ) )
     1115            $bbp->errors->add( 'bbp_split_topic_source_not_found', __( '<strong>ERROR</strong>: The topic you want to split was not found.', 'bbpress' ) );
    10971116
    10981117        // Nonce check
    10991118        check_admin_referer( 'bbp-split-topic_' . $source_topic->ID );
    11001119
     1120        // Use cannot edit topic
    11011121        if ( !current_user_can( 'edit_topic', $source_topic->ID ) )
    1102             $bbp->errors->add( 'bbp_split_topic_source_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the source topic!', 'bbpress' ) );
    1103 
    1104         $split_option = !empty( $_POST['bbp_topic_split_option'] ) ? (string) trim( $_POST['bbp_topic_split_option'] ) : false;
    1105         if ( empty( $split_option ) || !in_array( $split_option, array( 'existing', 'reply' ) ) )
    1106             $bbp->errors->add( 'bbp_split_topic_option', __( '<strong>ERROR</strong>: You need to choose a valid split option!', 'bbpress' ) );
    1107 
    1108         switch ( $split_option ) {
    1109             case 'existing' :
    1110                 if ( !$destination_topic_id = (int) $_POST['bbp_destination_topic'] )
    1111                     $bbp->errors->add( 'bbp_split_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress' ) );
    1112 
    1113                 if ( !$destination_topic = bbp_get_topic( $destination_topic_id ) )
    1114                     $bbp->errors->add( 'bbp_split_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to split to was not found!', 'bbpress' ) );
    1115 
    1116                 if ( !current_user_can( 'edit_topic', $destination_topic->ID ) )
    1117                     $bbp->errors->add( 'bbp_split_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the destination topic!', 'bbpress' ) );
    1118 
    1119                 break;
    1120 
    1121             case 'reply' :
    1122             default :
    1123                 if ( current_user_can( 'publish_topics' ) ) {
    1124 
    1125                     if ( !$destination_topic_title = esc_attr( strip_tags( $_POST['bbp_topic_split_destination_title'] ) ) )
    1126                         $destination_topic_title = $source_topic->post_title;
    1127 
     1122            $bbp->errors->add( 'bbp_split_topic_source_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the source topic.', 'bbpress' ) );
     1123
     1124        /** How to Split ******************************************************/
     1125
     1126        if ( !empty( $_POST['bbp_topic_split_option'] ) )
     1127            $split_option = (string) trim( $_POST['bbp_topic_split_option'] );
     1128
     1129        // Invalid split option
     1130        if ( empty( $split_option ) || !in_array( $split_option, array( 'existing', 'reply' ) ) ) {
     1131            $bbp->errors->add( 'bbp_split_topic_option', __( '<strong>ERROR</strong>: You need to choose a valid split option.', 'bbpress' ) );
     1132
     1133        // Valid Split Option
     1134        } else {
     1135
     1136            // What kind of split
     1137            switch ( $split_option ) {
     1138
     1139                // Into an existing topic
     1140                case 'existing' :
     1141
     1142                    // Get destination topic id
     1143                    if ( empty( $_POST['bbp_destination_topic'] ) )
     1144                        $bbp->errors->add( 'bbp_split_topic_destination_id', __( '<strong>ERROR</strong>: Destination topic ID not found!', 'bbpress' ) );
     1145                    else
     1146                        $destination_topic_id = (int) $_POST['bbp_destination_topic'];
     1147
     1148                    // Get the destination topic
     1149                    $destination_topic = bbp_get_topic( $destination_topic_id );
     1150
     1151                    // No destination topic
     1152                    if ( empty( $destination_topic ) )
     1153                        $bbp->errors->add( 'bbp_split_topic_destination_not_found', __( '<strong>ERROR</strong>: The topic you want to split to was not found!', 'bbpress' ) );
     1154
     1155                    // User cannot edit the destination topic
     1156                    if ( !current_user_can( 'edit_topic', $destination_topic->ID ) )
     1157                        $bbp->errors->add( 'bbp_split_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to edit the destination topic!', 'bbpress' ) );
     1158
     1159                    break;
     1160
     1161                // Split at reply into a new topic
     1162                case 'reply' :
     1163                default :
     1164
     1165                    // User needs to be able to publish topics
     1166                    if ( current_user_can( 'publish_topics' ) ) {
     1167
     1168                        // Use the new title that was passed
     1169                        if ( !empty( $_POST['bbp_topic_split_destination_title'] ) )
     1170                            $destination_topic_title = esc_attr( strip_tags( $_POST['bbp_topic_split_destination_title'] ) );
     1171
     1172                        // Use the source topic title
     1173                        else
     1174                            $destination_topic_title = $source_topic->post_title;
     1175
     1176                        // Setup the new post parameters
     1177                        $postarr = array(
     1178                            'ID'          => $from_reply->ID,
     1179                            'post_title'  => $destination_topic_title,
     1180                            'post_name'   => false,
     1181                            'post_type'   => bbp_get_topic_post_type(),
     1182                            'post_parent' => $source_topic->post_parent,
     1183                            'guid'        => ''
     1184                        );
     1185
     1186                        $destination_topic_id = wp_update_post( $postarr );
     1187
     1188                        // Shouldn't happen
     1189                        if ( false == $destination_topic_id || is_wp_error( $destination_topic_id ) || !$destination_topic = bbp_get_topic( $destination_topic_id ) )
     1190                            $bbp->errors->add( 'bbp_split_topic_destination_reply', __( '<strong>ERROR</strong>: There was a problem converting the reply into the topic. Please try again.', 'bbpress' ) );
     1191
     1192                    // User cannot publish posts
     1193                    } else {
     1194                        $bbp->errors->add( 'bbp_split_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to create new topics. The reply could not be converted into a topic.', 'bbpress' ) );
     1195                    }
     1196
     1197                    break;
     1198            }
     1199        }
     1200
     1201        /** No Errors - Do the Spit *******************************************/
     1202
     1203        if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) {
     1204
     1205            // Update counts, etc...
     1206            do_action( 'bbp_pre_split_topic', $from_reply->ID, $source_topic->ID, $destination_topic->ID );
     1207
     1208            /** Subscriptions *************************************************/
     1209
     1210            // Copy the subscribers
     1211            if ( !empty( $_POST['bbp_topic_subscribers'] ) && 1 == $_POST['bbp_topic_subscribers'] && bbp_is_subscriptions_active() ) {
     1212
     1213                // Get the subscribers
     1214                if ( $subscribers = bbp_get_topic_subscribers( $source_topic->ID ) ) {
     1215
     1216                    // Add subscribers to new topic
     1217                    foreach ( (array) $subscribers as $subscriber ) {
     1218                        bbp_add_user_subscription( $subscriber, $destination_topic->ID );
     1219                    }
     1220                }
     1221            }
     1222
     1223            /** Favorites *****************************************************/
     1224
     1225            // Copy the favoriters if told to
     1226            if ( !empty( $_POST['bbp_topic_favoriters'] ) && 1 == $_POST['bbp_topic_favoriters'] ) {
     1227
     1228                // Get the favoriters
     1229                if ( $favoriters = bbp_get_topic_favoriters( $source_topic->ID ) ) {
     1230
     1231                    // Add the favoriters to new topic
     1232                    foreach ( (array) $favoriters as $favoriter ) {
     1233                        bbp_add_user_favorite( $favoriter, $destination_topic->ID );
     1234                    }
     1235                }
     1236            }
     1237
     1238            /** Tags **********************************************************/
     1239
     1240            // Copy the tags if told to
     1241            if ( !empty( $_POST['bbp_topic_tags'] ) && 1 == $_POST['bbp_topic_tags'] ) {
     1242
     1243                // Get the source topic tags
     1244                if ( $source_topic_tags = wp_get_post_terms( $source_topic->ID, $bbp->topic_tag_id, array( 'fields' => 'names' ) ) ) {
     1245                    wp_set_post_terms( $destination_topic->ID, $source_topic_tags, $bbp->topic_tag_id, true );
     1246                }
     1247            }
     1248
     1249            /** Split Replies *************************************************/
     1250
     1251            // get_posts() is not used because it doesn't allow us to use '>='
     1252            // comparision without a filter.
     1253            $replies = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type() ) );
     1254
     1255            // Make sure there are replies to loop through
     1256            if ( !empty( $replies ) && !is_wp_error( $replies ) ) {
     1257
     1258                // Change the post_parent of each reply to the destination topic id
     1259                foreach ( $replies as $reply ) {
     1260
     1261                    // New reply data
    11281262                    $postarr = array(
    1129                         'ID'          => $from_reply->ID,
    1130                         'post_title'  => $destination_topic_title,
    1131                         'post_name'   => false,
    1132                         'post_type'   => bbp_get_topic_post_type(),
    1133                         'post_parent' => $source_topic->post_parent,
     1263                        'ID'          => $reply->ID,
     1264                        'post_title'  => sprintf( __( 'Reply To: %s', 'bbpress' ), $destination_topic->post_title ),
     1265                        'post_name'   => false, // will be automatically generated
     1266                        'post_parent' => $destination_topic->ID,
    11341267                        'guid'        => ''
    11351268                    );
    11361269
    1137                     $destination_topic_id = wp_update_post( $postarr );
    1138 
    1139                     // Shouldn't happen
    1140                     if ( false == $destination_topic_id || is_wp_error( $destination_topic_id ) || !$destination_topic = bbp_get_topic( $destination_topic_id ) )
    1141                         $bbp->errors->add( 'bbp_split_topic_destination_reply', __( '<strong>ERROR</strong>: There was a problem converting the reply into the topic, please try again!', 'bbpress' ) );
    1142 
    1143                 } else {
    1144                     $bbp->errors->add( 'bbp_split_topic_destination_permission', __( '<strong>ERROR</strong>: You do not have the permissions to create new topics and hence the reply could not be converted into a topic!', 'bbpress' ) );
    1145                 }
    1146 
    1147                 break;
    1148         }
    1149 
    1150         // We should have the from reply, source topic & destination topic by now.
    1151 
    1152         // Handle the split
    1153         if ( !is_wp_error( $bbp->errors ) || !$bbp->errors->get_error_codes() ) {
    1154 
    1155             // Update counts, etc...
    1156             do_action( 'bbp_pre_split_topic', $from_reply->ID, $source_topic->ID, $destination_topic->ID );
    1157 
    1158             // Copy the subscribers if told to
    1159             if ( !empty( $_POST['bbp_topic_subscribers'] ) && 1 == $_POST['bbp_topic_subscribers'] && bbp_is_subscriptions_active() ) {
    1160                 $subscribers = bbp_get_topic_subscribers( $source_topic->ID );
    1161 
    1162                 foreach ( (array) $subscribers as $subscriber ) {
    1163                     bbp_add_user_subscription( $subscriber, $destination_topic->ID );
     1270                    // Update the reply
     1271                    wp_update_post( $postarr );
     1272
     1273                    // Adjust reply meta values
     1274                    bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID                           );
     1275                    bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) );
     1276
     1277                    // Do additional actions per split reply
     1278                    do_action( 'bbp_split_topic_reply', $reply->ID, $destination_topic->ID );
    11641279                }
    11651280            }
    11661281
    1167             // Copy the favoriters if told to
    1168             if ( !empty( $_POST['bbp_topic_favoriters'] ) && 1 == $_POST['bbp_topic_favoriters'] ) {
    1169                 $favoriters = bbp_get_topic_favoriters( $source_topic->ID );
    1170 
    1171                 foreach ( (array) $favoriters as $favoriter ) {
    1172                     bbp_add_user_favorite( $favoriter, $destination_topic->ID );
    1173                 }
    1174             }
    1175 
    1176             // Copy the tags if told to
    1177             if ( !empty( $_POST['bbp_topic_tags'] ) && 1 == $_POST['bbp_topic_tags'] ) {
    1178                 // Get the source topic tags
    1179                 $source_topic_tags = wp_get_post_terms( $source_topic->ID, $bbp->topic_tag_id, array( 'fields' => 'names' ) );
    1180 
    1181                 wp_set_post_terms( $destination_topic->ID, $source_topic_tags, $bbp->topic_tag_id, true );
    1182             }
    1183 
    1184             // Get the replies of the source topic
    1185             // get_posts() is not used because it doesn't allow us to use '>=' comparision without a filter
    1186             $replies = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type() ) );
    1187 
    1188             // Change the post_parent of each reply to the destination topic id
    1189             foreach ( $replies as $reply ) {
    1190                 $postarr = array(
    1191                     'ID'          => $reply->ID,
    1192                     'post_title'  => sprintf( __( 'Reply To: %s', 'bbpress' ), $destination_topic->post_title ),
    1193                     'post_name'   => false, // will be automatically generated
    1194                     'post_parent' => $destination_topic->ID,
    1195                     'guid'        => ''
    1196                 );
    1197 
    1198                 wp_update_post( $postarr );
    1199 
    1200                 // Adjust reply meta values
    1201                 bbp_update_reply_topic_id( $reply->ID, $destination_topic->ID                           );
    1202                 bbp_update_reply_forum_id( $reply->ID, bbp_get_topic_forum_id( $destination_topic->ID ) );
    1203 
    1204                 // Do additional actions per split reply
    1205                 do_action( 'bbp_split_topic_reply', $reply->ID, $destination_topic->ID );
    1206             }
    1207 
    1208             // It is a new topic and we need to set some default metas to make the topic display in bbp_has_topics() list
     1282            // It is a new topic and we need to set some default metas to make
     1283            // the topic display in bbp_has_topics() list
    12091284            if ( 'reply' == $split_option ) {
    12101285                $last_reply_id = ( empty( $reply ) || empty( $reply->ID        ) ) ? 0  : $reply->ID;
     
    12141289                bbp_update_topic_last_active_time( $destination_topic->ID, $freshness     );
    12151290            }
     1291
     1292            /** Successful Split **********************************************/
    12161293
    12171294            // Update counts, etc...
     
    12501327
    12511328    // Forum Topic Counts
    1252     // bbp_update_forum_topic_count( $source_topic_id      );
    12531329    bbp_update_forum_topic_count( $destination_topic_id );
    12541330
    12551331    // Forum Reply Counts
    1256     // bbp_update_forum_reply_count( $source_topic_id      );
    12571332    bbp_update_forum_reply_count( $destination_topic_id );
    12581333
     
    13081383        }
    13091384
    1310         // What action are we trying to perform
     1385        // What action are we trying to perform?
    13111386        switch ( $action ) {
     1387
     1388            // Update tag
    13121389            case 'bbp-update-topic-tag' :
    13131390
     
    13171394                // Can user edit topic tags?
    13181395                if ( !current_user_can( 'edit_topic_tags' ) ) {
    1319                     $bbp->errors->add( 'bbp_manage_topic_tag_update_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to edit the topic tags!', 'bbpress' ) );
     1396                    $bbp->errors->add( 'bbp_manage_topic_tag_update_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to edit the topic tags.', 'bbpress' ) );
    13201397                    return;
    13211398                }
     
    13231400                // No tag name was provided
    13241401                if ( empty( $_POST['tag-name'] ) || !$name = $_POST['tag-name'] ) {
    1325                     $bbp->errors->add( 'bbp_manage_topic_tag_update_name', __( '<strong>ERROR</strong>: You need to enter a tag name!', 'bbpress' ) );
     1402                    $bbp->errors->add( 'bbp_manage_topic_tag_update_name', __( '<strong>ERROR</strong>: You need to enter a tag name.', 'bbpress' ) );
    13261403                    return;
    13271404                }
     
    13451422                break;
    13461423
     1424            // Merge two tags
    13471425            case 'bbp-merge-topic-tag'  :
    13481426
     
    13521430                // Can user edit topic tags?
    13531431                if ( !current_user_can( 'edit_topic_tags' ) ) {
    1354                     $bbp->errors->add( 'bbp_manage_topic_tag_merge_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to edit the topic tags!', 'bbpress' ) );
     1432                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to edit the topic tags.', 'bbpress' ) );
    13551433                    return;
    13561434                }
     
    13581436                // No tag name was provided
    13591437                if ( empty( $_POST['tag-name'] ) || !$name = $_POST['tag-name'] ) {
    1360                     $bbp->errors->add( 'bbp_manage_topic_tag_merge_name', __( '<strong>ERROR</strong>: You need to enter a tag name!', 'bbpress' ) );
     1438                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_name', __( '<strong>ERROR</strong>: You need to enter a tag name.', 'bbpress' ) );
    13611439                    return;
    13621440                }
     
    13981476                break;
    13991477
     1478            // Delete tag
    14001479            case 'bbp-delete-topic-tag' :
    14011480
     
    14051484                // Can user delete topic tags?
    14061485                if ( !current_user_can( 'delete_topic_tags' ) ) {
    1407                     $bbp->errors->add( 'bbp_manage_topic_tag_delete_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to delete the topic tags!', 'bbpress' ) );
     1486                    $bbp->errors->add( 'bbp_manage_topic_tag_delete_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to delete the topic tags.', 'bbpress' ) );
    14081487                    return;
    14091488                }
     
    14261505                break;
    14271506        }
     1507
     1508        /** Successful Moderation *********************************************/
    14281509
    14291510        // Redirect back
     
    15221603        // What is the user doing here?
    15231604        if ( !current_user_can( 'edit_topic', $topic->ID ) || ( 'bbp_toggle_topic_trash' == $action && !current_user_can( 'delete_topic', $topic->ID ) ) ) {
    1524             $bbp->errors->add( 'bbp_toggle_topic_permission', __( '<strong>ERROR:</strong> You do not have the permission to do that!', 'bbpress' ) );
     1605            $bbp->errors->add( 'bbp_toggle_topic_permission', __( '<strong>ERROR:</strong> You do not have the permission to do that.', 'bbpress' ) );
    15251606            return;
    15261607        }
    15271608
     1609        // What action are we trying to perform?
    15281610        switch ( $action ) {
     1611
     1612            // Toggle open/close
    15291613            case 'bbp_toggle_topic_close' :
    15301614                check_ajax_referer( 'close-topic_' . $topic_id );
     
    15321616                $is_open = bbp_is_topic_open( $topic_id );
    15331617                $success = $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id );
    1534                 $failure = $is_open ? __( '<strong>ERROR</strong>: There was a problem closing the topic!', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem opening the topic!', 'bbpress' );
     1618                $failure = $is_open ? __( '<strong>ERROR</strong>: There was a problem closing the topic.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem opening the topic.', 'bbpress' );
    15351619
    15361620                break;
    15371621
     1622            // Toggle sticky/super-sticky/unstick
    15381623            case 'bbp_toggle_topic_stick' :
    15391624                check_ajax_referer( 'stick-topic_' . $topic_id );
     
    15421627                $is_super  = ( empty( $is_sticky ) && !empty( $_GET['super'] ) && 1 == (int) $_GET['super'] ) ? true : false;
    15431628                $success   = $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super );
    1544                 $failure   = $is_sticky ? __( '<strong>ERROR</strong>: There was a problem unsticking the topic!', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem sticking the topic!', 'bbpress' );
     1629                $failure   = $is_sticky ? __( '<strong>ERROR</strong>: There was a problem unsticking the topic.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem sticking the topic.', 'bbpress' );
    15451630
    15461631                break;
    15471632
     1633            // Toggle spam
    15481634            case 'bbp_toggle_topic_spam' :
    15491635                check_ajax_referer( 'spam-topic_' . $topic_id );
     
    15511637                $is_spam = bbp_is_topic_spam( $topic_id );
    15521638                $success = $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id );
    1553                 $failure = $is_spam ? __( '<strong>ERROR</strong>: There was a problem unmarking the topic as spam!', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem marking the topic as spam!', 'bbpress' );
     1639                $failure = $is_spam ? __( '<strong>ERROR</strong>: There was a problem unmarking the topic as spam.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem marking the topic as spam.', 'bbpress' );
    15541640
    15551641                break;
    15561642
     1643            // Toggle trash
    15571644            case 'bbp_toggle_topic_trash' :
    15581645
     
    15671654
    15681655                        $success = wp_trash_post( $topic_id );
    1569                         $failure = __( '<strong>ERROR</strong>: There was a problem trashing the topic!', 'bbpress' );
     1656                        $failure = __( '<strong>ERROR</strong>: There was a problem trashing the topic.', 'bbpress' );
    15701657
    15711658                        break;
     
    15751662
    15761663                        $success = wp_untrash_post( $topic_id );
    1577                         $failure = __( '<strong>ERROR</strong>: There was a problem untrashing the topic!', 'bbpress' );
     1664                        $failure = __( '<strong>ERROR</strong>: There was a problem untrashing the topic.', 'bbpress' );
    15781665
    15791666                        break;
     
    15831670
    15841671                        $success = wp_delete_post( $topic_id );
    1585                         $failure = __( '<strong>ERROR</strong>: There was a problem deleting the topic!', 'bbpress' );
     1672                        $failure = __( '<strong>ERROR</strong>: There was a problem deleting the topic.', 'bbpress' );
    15861673
    15871674                        break;
     
    15941681        do_action( 'bbp_toggle_topic_handler', $success, $post_data, $action );
    15951682
    1596         // Check for errors
     1683        // No Errors
    15971684        if ( false != $success && !is_wp_error( $success ) ) {
    15981685
     
    16291716 */
    16301717function bbp_remove_topic_from_all_favorites( $topic_id = 0 ) {
     1718    $topic_id = bbp_get_topic_id( $topic_id );
     1719
     1720    // Bail if no topic
    16311721    if ( empty( $topic_id ) )
    16321722        return;
    16331723
     1724    // Get users
    16341725    $users = (array) bbp_get_topic_favoriters( $topic_id );
    16351726
     1727    // Users exist
    16361728    if ( !empty( $users ) ) {
     1729
     1730        // Loop through users
    16371731        foreach ( $users as $user ) {
     1732
     1733            // Remove each user
    16381734            bbp_remove_user_favorite( $user, $topic_id );
    16391735        }
     
    16521748 */
    16531749function bbp_remove_topic_from_all_subscriptions( $topic_id = 0 ) {
     1750
     1751    // Subscriptions are not active
     1752    if ( !bbp_is_subscriptions_active() )
     1753        return;
     1754
     1755    $topic_id = bbp_get_topic_id( $topic_id );
     1756
     1757    // Bail if no topic
    16541758    if ( empty( $topic_id ) )
    16551759        return;
    16561760
    1657     if ( !bbp_is_subscriptions_active() )
    1658         return;
    1659 
     1761    // Get users
    16601762    $users = (array) bbp_get_topic_subscribers( $topic_id );
    16611763
     1764    // Users exist
    16621765    if ( !empty( $users ) ) {
     1766
     1767        // Loop through users
    16631768        foreach ( $users as $user ) {
     1769
     1770            // Remove each user
    16641771            bbp_remove_user_subscription( $user, $topic_id );
    16651772        }
     
    17141821 */
    17151822function bbp_update_topic_topic_id( $topic_id = 0 ) {
    1716 
    1717     // If it's a reply, then get the parent (topic id)
    17181823    $topic_id = bbp_get_topic_id( $topic_id );
    17191824
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r3134 r3136  
    12551255     * @uses bbp_get_topic_id() To get topic id
    12561256     * @uses get_post_meta() To retrieve get topic's forum id meta
    1257      * @uses get_post_field() To get the topic's parent, i.e. forum id
    1258      * @uses bbp_update_topic_forum_id() To update the topic forum id
    12591257     * @uses apply_filters() Calls 'bbp_get_topic_forum_id' with the forum
    12601258     *                        id and topic id
Note: See TracChangeset for help on using the changeset viewer.