bb_upgrade_process_all_slugs

The BuddyPress bb upgrade process all slugs function.

Description

bb_upgrade_process_all_slugs(); 

Usage

  1. if ( !function_exists( 'bb_upgrade_process_all_slugs' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-admin/includes/functions.bb-upgrade.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_upgrade_process_all_slugs(); 
  7.  

Defined (1)

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

/bp-forums/bbpress/bb-admin/includes/functions.bb-upgrade.php  
  1. function bb_upgrade_process_all_slugs() { 
  2. global $bbdb; 
  3. // Forums 
  4.  
  5. $forums = (array) $bbdb->get_results("SELECT forum_id, forum_name FROM $bbdb->forums ORDER BY forum_order ASC" ); 
  6.  
  7. $slugs = array(); 
  8. foreach ( $forums as $forum ) : 
  9. $slug = bb_slug_sanitize( wp_specialchars_decode( $forum->forum_name, ENT_QUOTES ) ); 
  10. $slugs[$slug][] = $forum->forum_id; 
  11. endforeach; 
  12.  
  13. foreach ( $slugs as $slug => $forum_ids ) : 
  14. foreach ( $forum_ids as $count => $forum_id ) : 
  15. $_slug = $slug; 
  16. $count = - $count; // madness 
  17. if ( is_numeric($slug) || $count ) 
  18. $_slug = bb_slug_increment( $slug, $count ); 
  19. $bbdb->query("UPDATE $bbdb->forums SET forum_slug = '$_slug' WHERE forum_id = '$forum_id';"); 
  20. endforeach; 
  21. endforeach; 
  22. unset($forums, $forum, $slugs, $slug, $_slug, $forum_ids, $forum_id, $count); 
  23.  
  24. // Topics 
  25.  
  26. $topics = (array) $bbdb->get_results("SELECT topic_id, topic_title FROM $bbdb->topics ORDER BY topic_start_time ASC" ); 
  27.  
  28. $slugs = array(); 
  29. foreach ( $topics as $topic) : 
  30. $slug = bb_slug_sanitize( wp_specialchars_decode( $topic->topic_title, ENT_QUOTES ) ); 
  31. $slugs[$slug][] = $topic->topic_id; 
  32. endforeach; 
  33.  
  34. foreach ( $slugs as $slug => $topic_ids ) : 
  35. foreach ( $topic_ids as $count => $topic_id ) : 
  36. $_slug = $slug; 
  37. $count = - $count; 
  38. if ( is_numeric($slug) || $count ) 
  39. $_slug = bb_slug_increment( $slug, $count ); 
  40. $bbdb->query("UPDATE $bbdb->topics SET topic_slug = '$_slug' WHERE topic_id = '$topic_id';"); 
  41. endforeach; 
  42. endforeach; 
  43. unset($topics, $topic, $slugs, $slug, $_slug, $topic_ids, $topic_id, $count);