bbp_admin_repair_sticky()

Repairs the relationship of sticky topics to the actual parent forum

Description

Return

(array) An array of the status code and the message

Source

File: bp-forums/admin/tools.php

1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
function bbp_admin_repair_sticky() {
    global $wpdb;
 
    $statement = __( 'Repairing the sticky discussion to the parent forum relationships… %s', 'buddyboss' );
    $result    = __( 'Failed!', 'buddyboss' );
    $forums    = $wpdb->get_col( "SELECT ID FROM `{$wpdb->posts}` WHERE `post_type` = 'forum';" );
 
    // Bail if no forums found
    if ( empty( $forums ) || is_wp_error( $forums ) )
        return array( 1, sprintf( $statement, $result ) );
 
    // Loop through forums and get their sticky topics
    foreach ( $forums as $forum ) {
        $forum_stickies[$forum] = get_post_meta( $forum, '_bbp_sticky_topics', true );
    }
 
    // Cleanup
    unset( $forums, $forum );
 
    // Loop through each forum with sticky topics
    foreach ( $forum_stickies as $forum_id => $stickies ) {
 
        // Skip if no stickies
        if ( empty( $stickies ) ) {
            continue;
        }
 
        // Loop through each sticky topic
        foreach ( $stickies as $id => $topic_id ) {
 
            // If the topic is not a super sticky, and the forum ID does not
            // match the topic's forum ID, unset the forum's sticky meta.
            if ( ! bbp_is_topic_super_sticky( $topic_id ) && $forum_id !== bbp_get_topic_forum_id( $topic_id ) ) {
                unset( $forum_stickies[$forum_id][$id] );
            }
        }
 
        // Get sticky topic ID's, or use empty string
        $stickers = empty( $forum_stickies[$forum_id] ) ? '' : array_values( $forum_stickies[$forum_id] );
 
        // Update the forum's sticky topics meta
        update_post_meta( $forum_id, '_bbp_sticky_topics', $stickers );
    }
 
    // Complete results
    return array( 0, sprintf( $statement, __( 'Complete!', 'buddyboss' ) ) );
}

Changelog

Changelog
Version Description
bbPress (r4695) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.