bbp_admin_reset_handler

Handle the processing and feedback of the admin tools page.

Description

bbp_admin_reset_handler(); 

Usage

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

Defined (1)

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

/includes/admin/tools.php  
  1. function bbp_admin_reset_handler() { 
  2.  
  3. // Bail if not resetting 
  4. if ( ! bbp_is_post_request() || empty( $_POST['bbpress-are-you-sure'] ) ) 
  5. return; 
  6.  
  7. // Only keymasters can proceed 
  8. if ( ! bbp_is_user_keymaster() ) 
  9. return; 
  10.  
  11. check_admin_referer( 'bbpress-reset' ); 
  12.  
  13. global $wpdb; 
  14.  
  15. // Stores messages 
  16. $messages = array(); 
  17. $failed = __( 'Failed', bbpress ); 
  18. $success = __( 'Success!', bbpress ); 
  19.  
  20. // Flush the cache; things are about to get ugly. 
  21. wp_cache_flush(); 
  22.  
  23. /** Posts *****************************************************************/ 
  24.  
  25. $statement = __( 'Deleting Posts… %s', bbpress ); 
  26. $sql_posts = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')", OBJECT_K ); 
  27. $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')"; 
  28. $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 
  29. $messages[] = sprintf( $statement, $result ); 
  30.  
  31. /** Post Meta *************************************************************/ 
  32.  
  33. if ( !empty( $sql_posts ) ) { 
  34. $sql_meta = array(); 
  35. foreach ( $sql_posts as $key => $value ) { 
  36. $sql_meta[] = $key; 
  37. $statement = __( 'Deleting Post Meta… %s', bbpress ); 
  38. $sql_meta = implode( "', '", $sql_meta ); 
  39. $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` IN ('{$sql_meta}');"; 
  40. $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 
  41. $messages[] = sprintf( $statement, $result ); 
  42.  
  43. /** Topic Tags ************************************************************/ 
  44.  
  45. $statement = __( 'Deleting Topic Tags… %s', bbpress ); 
  46. $sql_delete = "DELETE a, b, c FROM `{$wpdb->terms}` AS a LEFT JOIN `{$wpdb->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$wpdb->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';"; 
  47. $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 
  48. $messages[] = sprintf( $statement, $result ); 
  49.  
  50. /** User ******************************************************************/ 
  51.  
  52. // Delete users 
  53. if ( !empty( $_POST['bbpress-delete-imported-users'] ) ) { 
  54. $sql_users = $wpdb->get_results( "SELECT `user_id` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K ); 
  55. if ( !empty( $sql_users ) ) { 
  56. $sql_meta = array(); 
  57. foreach ( $sql_users as $key => $value ) { 
  58. $sql_meta[] = $key; 
  59. $statement = __( 'Deleting User… %s', bbpress ); 
  60. $sql_meta = implode( "', '", $sql_meta ); 
  61. $sql_delete = "DELETE FROM `{$wpdb->users}` WHERE `ID` IN ('{$sql_meta}');"; 
  62. $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 
  63. $messages[] = sprintf( $statement, $result ); 
  64. $statement = __( 'Deleting User Meta… %s', bbpress ); 
  65. $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `user_id` IN ('{$sql_meta}');"; 
  66. $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 
  67. $messages[] = sprintf( $statement, $result ); 
  68.  
  69. // Delete imported user metadata 
  70. } else { 
  71. $statement = __( 'Deleting User Meta… %s', bbpress ); 
  72. $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';"; 
  73. $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 
  74. $messages[] = sprintf( $statement, $result ); 
  75.  
  76. /** Converter *************************************************************/ 
  77.  
  78. $statement = __( 'Deleting Conversion Table… %s', bbpress ); 
  79. $table_name = $wpdb->prefix . 'bbp_converter_translator'; 
  80. if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) { 
  81. $wpdb->query( "DROP TABLE {$table_name}" ); 
  82. $result = $success; 
  83. } else { 
  84. $result = $failed; 
  85. $messages[] = sprintf( $statement, $result ); 
  86.  
  87. /** Options ***************************************************************/ 
  88.  
  89. $statement = __( 'Deleting Settings… %s', bbpress ); 
  90. $messages[] = sprintf( $statement, $success ); 
  91.  
  92. /** Roles *****************************************************************/ 
  93.  
  94. $statement = __( 'Deleting Roles and Capabilities… %s', bbpress ); 
  95. remove_role( bbp_get_moderator_role() ); 
  96. remove_role( bbp_get_participant_role() ); 
  97. $messages[] = sprintf( $statement, $success ); 
  98.  
  99. /** Output ****************************************************************/ 
  100.  
  101. if ( count( $messages ) ) { 
  102. foreach ( $messages as $message ) { 
  103. bbp_admin_tools_feedback( $message );