bp_media_forum_privacy_repair()

Repair BuddyBoss media forums privacy.

Description

Source

File: bp-media/bp-media-filters.php

1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
function bp_media_forum_privacy_repair() {
    global $wpdb;
    $offset     = isset( $_POST['offset'] ) ? (int) ( $_POST['offset'] ) : 0;
    $bp         = buddypress();
 
    $squery  = "SELECT p.ID as post_id FROM {$wpdb->posts} p, {$wpdb->postmeta} pm WHERE p.ID = pm.post_id and p.post_type in ( 'forum', 'topic', 'reply' ) and pm.meta_key = 'bp_media_ids' and pm.meta_value != '' LIMIT 20 OFFSET $offset ";
    $records = $wpdb->get_col( $squery );
    if ( ! empty( $records ) ) {
        foreach ( $records as $record ) {
            if ( ! empty( $record ) ) {
                $media_ids = get_post_meta( $record, 'bp_media_ids', true );
                if ( $media_ids ) {
                    $update_query = "UPDATE {$bp->media->table_name} SET `privacy`= 'forums' WHERE id in (" . $media_ids . ")";
                    $wpdb->query( $update_query );
                }
            }
            $offset ++;
        }
        $records_updated = sprintf( __( '%s Forums media privacy updated successfully.', 'buddyboss' ), number_format_i18n( $offset ) );
 
        return array(
                'status'  => 'running',
                'offset'  => $offset,
                'records' => $records_updated,
        );
    } else {
        $statement = __( 'Forums media privacy updated %s', 'buddyboss' );
 
        return array(
                'status'  => 1,
                'message' => sprintf( $statement, __( 'Complete!', 'buddyboss' ) ),
        );
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.2 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.