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

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.