bbp_admin_repair_sticky

Repairs the relationship of sticky topics to the actual parent forum.

Description

(array) bbp_admin_repair_sticky(); 

Returns (array)

An array of the status code and the message


Usage

  1. if ( !function_exists( 'bbp_admin_repair_sticky' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/admin/tools.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_admin_repair_sticky(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/tools.php  
  1. function bbp_admin_repair_sticky() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Repairing the sticky topic to the parent forum relationships… %s', bbpress ); 
  5. $result = __( 'Failed!', bbpress ); 
  6. $forums = $wpdb->get_col( "SELECT ID FROM `{$wpdb->posts}` WHERE `post_type` = 'forum';" ); 
  7.  
  8. // Bail if no forums found 
  9. if ( empty( $forums ) || is_wp_error( $forums ) ) 
  10. return array( 1, sprintf( $statement, $result ) ); 
  11.  
  12. // Loop through forums and get their sticky topics 
  13. foreach ( $forums as $forum ) { 
  14. $forum_stickies[$forum] = get_post_meta( $forum, '_bbp_sticky_topics', true ); 
  15.  
  16. // Cleanup 
  17. unset( $forums, $forum ); 
  18.  
  19. // Loop through each forum with sticky topics 
  20. foreach ( $forum_stickies as $forum_id => $stickies ) { 
  21.  
  22. // Skip if no stickies 
  23. if ( empty( $stickies ) ) { 
  24. continue; 
  25.  
  26. // Loop through each sticky topic 
  27. foreach ( $stickies as $id => $topic_id ) { 
  28.  
  29. // If the topic is not a super sticky, and the forum ID does not 
  30. // match the topic's forum ID, unset the forum's sticky meta. 
  31. if ( ! bbp_is_topic_super_sticky( $topic_id ) && $forum_id !== bbp_get_topic_forum_id( $topic_id ) ) { 
  32. unset( $forum_stickies[$forum_id][$id] ); 
  33.  
  34. // Get sticky topic ID's, or use empty string 
  35. $stickers = empty( $forum_stickies[$forum_id] ) ? '' : array_values( $forum_stickies[$forum_id] ); 
  36.  
  37. // Update the forum's sticky topics meta 
  38. update_post_meta( $forum_id, '_bbp_sticky_topics', $stickers ); 
  39.  
  40. // Complete results 
  41. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );