bbp_admin_repair_sticky()
Repair the relationship of sticky topics to the actual parent forum
Description Description
Return Return
(array) An array of the status code and the message
Source Source
File: includes/admin/tools/repair.php
function bbp_admin_repair_sticky() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Repairing the sticky topic to the parent forum relationships… %s', 'bbpress' );
$result = esc_html__( 'Failed!', 'bbpress' );
$forums = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "'" );
// 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, esc_html__( 'Complete!', 'bbpress' ) ) );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |