| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Admin Tools Page. |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage Administration |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Output a bbPress specific tools box. |
| 15 |
* |
| 16 |
* @since 2.6.0 bbPress (r6273) |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
function bbp_admin_tools_box() { |
| 21 |
|
| 22 |
// Bail if user cannot access tools page |
| 23 |
if ( ! current_user_can( 'bbp_tools_page' ) ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
// Get the tools pages |
| 28 |
$links = array(); |
| 29 |
$tools = bbp_get_tools_admin_pages(); ?> |
| 30 |
|
| 31 |
<div class="card"> |
| 32 |
<h3 class="title"><?php esc_html_e( 'Forums', 'bbpress' ); ?></h3> |
| 33 |
<p><?php esc_html_e( 'bbPress provides the following tools to help you manage your forums:', 'bbpress' ); ?></p> |
| 34 |
|
| 35 |
<?php |
| 36 |
|
| 37 |
// Loop through tools and create links |
| 38 |
foreach ( $tools as $tool ) { |
| 39 |
|
| 40 |
// Skip if user cannot see this page |
| 41 |
if ( ! current_user_can( $tool['cap'] ) ) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
// Add link to array |
| 46 |
$links[] = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $tool['page'] ), admin_url( 'tools.php' ) ) ), $tool['name'] ); |
| 47 |
} |
| 48 |
|
| 49 |
// Output links |
| 50 |
echo '<p class="bbp-tools-links">' . implode( ' · ', $links ) . '</p>'; |
| 51 |
|
| 52 |
?></div> |
| 53 |
|
| 54 |
<?php |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Register an admin area repair tool. |
| 59 |
* |
| 60 |
* @since 2.6.0 bbPress (r5885) |
| 61 |
* |
| 62 |
* @param array $args |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
function bbp_register_repair_tool( $args = array() ) { |
| 66 |
|
| 67 |
// Parse arguments |
| 68 |
$r = bbp_parse_args( |
| 69 |
$args, |
| 70 |
array( |
| 71 |
'id' => '', |
| 72 |
'type' => '', |
| 73 |
'title' => '', |
| 74 |
'description' => '', |
| 75 |
'callback' => '', |
| 76 |
'priority' => 0, |
| 77 |
'overhead' => 'low', |
| 78 |
'version' => '', |
| 79 |
'components' => array(), |
| 80 |
|
| 81 |
// @todo |
| 82 |
'success' => esc_html__( 'The repair was completed successfully', 'bbpress' ), |
| 83 |
'failure' => esc_html__( 'The repair was not successful', 'bbpress' ) |
| 84 |
), |
| 85 |
'register_repair_tool' |
| 86 |
); |
| 87 |
|
| 88 |
// Bail if missing required values |
| 89 |
if ( empty( $r['id'] ) || empty( $r['priority'] ) || empty( $r['title'] ) || empty( $r['callback'] ) ) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
// Add tool to the registered tools array |
| 94 |
bbp_admin()->tools[ $r['id'] ] = array( |
| 95 |
'type' => $r['type'], |
| 96 |
'title' => $r['title'], |
| 97 |
'description' => $r['description'], |
| 98 |
'priority' => $r['priority'], |
| 99 |
'callback' => $r['callback'], |
| 100 |
'overhead' => $r['overhead'], |
| 101 |
'components' => $r['components'], |
| 102 |
'version' => $r['version'], |
| 103 |
|
| 104 |
// @todo |
| 105 |
'success' => $r['success'], |
| 106 |
'failure' => $r['failure'], |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Register the default repair tools. |
| 112 |
* |
| 113 |
* @since 2.6.0 bbPress (r5885) |
| 114 |
*/ |
| 115 |
function bbp_register_default_repair_tools() { |
| 116 |
|
| 117 |
// Topic meta |
| 118 |
bbp_register_repair_tool( |
| 119 |
array( |
| 120 |
'id' => 'bbp-sync-topic-meta', |
| 121 |
'type' => 'repair', |
| 122 |
'title' => esc_html__( 'Recalculate parent topic for each reply', 'bbpress' ), |
| 123 |
'description' => esc_html__( 'Run this if replies appear in the wrong topics.', 'bbpress' ), |
| 124 |
'callback' => 'bbp_admin_repair_topic_meta', |
| 125 |
'priority' => 5, |
| 126 |
'overhead' => 'low', |
| 127 |
'components' => array( bbp_get_reply_post_type() ) |
| 128 |
) |
| 129 |
); |
| 130 |
|
| 131 |
// Forum meta |
| 132 |
bbp_register_repair_tool( |
| 133 |
array( |
| 134 |
'id' => 'bbp-sync-forum-meta', |
| 135 |
'type' => 'repair', |
| 136 |
'title' => esc_html__( 'Recalculate parent forum for each topic and reply', 'bbpress' ), |
| 137 |
'description' => esc_html__( 'Run this if topics or replies appear in the wrong forums.', 'bbpress' ), |
| 138 |
'callback' => 'bbp_admin_repair_forum_meta', |
| 139 |
'priority' => 10, |
| 140 |
'overhead' => 'low', |
| 141 |
'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) |
| 142 |
) |
| 143 |
); |
| 144 |
|
| 145 |
// Forum visibility |
| 146 |
bbp_register_repair_tool( |
| 147 |
array( |
| 148 |
'id' => 'bbp-sync-forum-visibility', |
| 149 |
'type' => 'repair', |
| 150 |
'title' => esc_html__( 'Recalculate private and hidden forums', 'bbpress' ), |
| 151 |
'description' => esc_html__( 'Run this if non-public forums are publicly visible.', 'bbpress' ), |
| 152 |
'callback' => 'bbp_admin_repair_forum_visibility', |
| 153 |
'priority' => 15, |
| 154 |
'overhead' => 'low', |
| 155 |
'components' => array( bbp_get_forum_post_type() ) |
| 156 |
) |
| 157 |
); |
| 158 |
|
| 159 |
// Sync all topics in all forums |
| 160 |
bbp_register_repair_tool( |
| 161 |
array( |
| 162 |
'id' => 'bbp-sync-all-topics-forums', |
| 163 |
'type' => 'repair', |
| 164 |
'title' => esc_html__( 'Recalculate last activity in each topic and forum', 'bbpress' ), |
| 165 |
'description' => esc_html__( 'Run this if freshness appears incorrectly.', 'bbpress' ), |
| 166 |
'callback' => 'bbp_admin_repair_freshness', |
| 167 |
'priority' => 20, |
| 168 |
'overhead' => 'high', |
| 169 |
'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) |
| 170 |
) |
| 171 |
); |
| 172 |
|
| 173 |
// Sync all sticky topics in all forums |
| 174 |
bbp_register_repair_tool( |
| 175 |
array( |
| 176 |
'id' => 'bbp-sync-all-topics-sticky', |
| 177 |
'type' => 'repair', |
| 178 |
'title' => esc_html__( 'Recalculate sticky relationship of each topic', 'bbpress' ), |
| 179 |
'description' => esc_html__( 'Run this if sticky topics appear incorrectly.', 'bbpress' ), |
| 180 |
'callback' => 'bbp_admin_repair_sticky', |
| 181 |
'priority' => 25, |
| 182 |
'overhead' => 'low', |
| 183 |
'components' => array( bbp_get_topic_post_type() ) |
| 184 |
) |
| 185 |
); |
| 186 |
|
| 187 |
// Sync all hierarchical reply positions |
| 188 |
bbp_register_repair_tool( |
| 189 |
array( |
| 190 |
'id' => 'bbp-sync-all-reply-positions', |
| 191 |
'type' => 'repair', |
| 192 |
'title' => esc_html__( 'Recalculate position of each reply in each topic', 'bbpress' ), |
| 193 |
'description' => esc_html__( 'Run this if replies appear in the wrong order.', 'bbpress' ), |
| 194 |
'callback' => 'bbp_admin_repair_reply_menu_order', |
| 195 |
'priority' => 30, |
| 196 |
'overhead' => 'high', |
| 197 |
'components' => array( bbp_get_reply_post_type() ) |
| 198 |
) |
| 199 |
); |
| 200 |
|
| 201 |
// Sync all topic engagements for all users |
| 202 |
bbp_register_repair_tool( |
| 203 |
array( |
| 204 |
'id' => 'bbp-topic-engagements', |
| 205 |
'type' => 'repair', |
| 206 |
'title' => esc_html__( 'Recalculate engagements in each topic for each user', 'bbpress' ), |
| 207 |
'description' => esc_html__( 'Run this if voices appear incorrectly.', 'bbpress' ), |
| 208 |
'callback' => 'bbp_admin_repair_topic_voice_count', |
| 209 |
'priority' => 35, |
| 210 |
'overhead' => 'high', |
| 211 |
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) |
| 212 |
) |
| 213 |
); |
| 214 |
|
| 215 |
// Update closed topic counts |
| 216 |
bbp_register_repair_tool( |
| 217 |
array( |
| 218 |
'id' => 'bbp-sync-closed-topics', |
| 219 |
'type' => 'repair', |
| 220 |
'title' => esc_html__( 'Repair closed topic statuses', 'bbpress' ), |
| 221 |
'description' => esc_html__( 'Run this if closed topics appear incorrectly.', 'bbpress' ), |
| 222 |
'callback' => 'bbp_admin_repair_closed_topics', |
| 223 |
'priority' => 40, |
| 224 |
'overhead' => 'medium', |
| 225 |
'components' => array( bbp_get_topic_post_type() ) |
| 226 |
) |
| 227 |
); |
| 228 |
|
| 229 |
// Count topics |
| 230 |
bbp_register_repair_tool( |
| 231 |
array( |
| 232 |
'id' => 'bbp-forum-topics', |
| 233 |
'type' => 'repair', |
| 234 |
'title' => esc_html__( 'Recount topics in each forum', 'bbpress' ), |
| 235 |
'description' => esc_html__( 'Run this if the number of topics in any forums are incorrect.', 'bbpress' ), |
| 236 |
'callback' => 'bbp_admin_repair_forum_topic_count', |
| 237 |
'priority' => 45, |
| 238 |
'overhead' => 'medium', |
| 239 |
'components' => array( bbp_get_forum_post_type(), bbp_get_topic_post_type() ) |
| 240 |
) |
| 241 |
); |
| 242 |
|
| 243 |
// Count topic tags |
| 244 |
bbp_register_repair_tool( |
| 245 |
array( |
| 246 |
'id' => 'bbp-topic-tags', |
| 247 |
'type' => 'repair', |
| 248 |
'title' => esc_html__( 'Recount topics in each topic-tag', 'bbpress' ), |
| 249 |
'description' => esc_html__( 'Run this if the number of topics in any topic-tags are incorrect.', 'bbpress' ), |
| 250 |
'callback' => 'bbp_admin_repair_topic_tag_count', |
| 251 |
'priority' => 50, |
| 252 |
'overhead' => 'medium', |
| 253 |
'components' => array( bbp_get_topic_post_type(), bbp_get_topic_tag_tax_id() ) |
| 254 |
) |
| 255 |
); |
| 256 |
|
| 257 |
// Count forum replies |
| 258 |
bbp_register_repair_tool( |
| 259 |
array( |
| 260 |
'id' => 'bbp-forum-replies', |
| 261 |
'type' => 'repair', |
| 262 |
'title' => esc_html__( 'Recount replies in each forum', 'bbpress' ), |
| 263 |
'description' => esc_html__( 'Run this if the number of replies in any forums are incorrect.', 'bbpress' ), |
| 264 |
'callback' => 'bbp_admin_repair_forum_reply_count', |
| 265 |
'priority' => 55, |
| 266 |
'overhead' => 'high', |
| 267 |
'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() ) |
| 268 |
) |
| 269 |
); |
| 270 |
|
| 271 |
// Count non-published replies to each forum |
| 272 |
bbp_register_repair_tool( |
| 273 |
array( |
| 274 |
'id' => 'bbp-forum-hidden-replies', |
| 275 |
'type' => 'repair', |
| 276 |
'title' => esc_html__( 'Recount pending, spammed, and trashed replies in each forum', 'bbpress' ), |
| 277 |
'description' => esc_html__( 'Run this if non-public replies display incorrectly in forums.', 'bbpress' ), |
| 278 |
'callback' => 'bbp_admin_repair_forum_hidden_reply_count', |
| 279 |
'priority' => 60, |
| 280 |
'overhead' => 'high', |
| 281 |
'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() ) |
| 282 |
) |
| 283 |
); |
| 284 |
|
| 285 |
// Count topic replies |
| 286 |
bbp_register_repair_tool( |
| 287 |
array( |
| 288 |
'id' => 'bbp-topic-replies', |
| 289 |
'type' => 'repair', |
| 290 |
'title' => esc_html__( 'Recount replies in each topic', 'bbpress' ), |
| 291 |
'description' => esc_html__( 'Run this if the number of replies in any topics are incorrect.', 'bbpress' ), |
| 292 |
'callback' => 'bbp_admin_repair_topic_reply_count', |
| 293 |
'priority' => 65, |
| 294 |
'overhead' => 'high', |
| 295 |
'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) |
| 296 |
) |
| 297 |
); |
| 298 |
|
| 299 |
// Count non-published replies to each topic |
| 300 |
bbp_register_repair_tool( |
| 301 |
array( |
| 302 |
'id' => 'bbp-topic-hidden-replies', |
| 303 |
'type' => 'repair', |
| 304 |
'title' => esc_html__( 'Recount pending, spammed, and trashed replies in each topic', 'bbpress' ), |
| 305 |
'description' => esc_html__( 'Run this if non-public replies display incorrectly in topics.', 'bbpress' ), |
| 306 |
'callback' => 'bbp_admin_repair_topic_hidden_reply_count', |
| 307 |
'priority' => 70, |
| 308 |
'overhead' => 'high', |
| 309 |
'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) |
| 310 |
) |
| 311 |
); |
| 312 |
|
| 313 |
// Recount topics for each user |
| 314 |
bbp_register_repair_tool( |
| 315 |
array( |
| 316 |
'id' => 'bbp-user-topics', |
| 317 |
'type' => 'repair', |
| 318 |
'title' => esc_html__( 'Recount topics for each user', 'bbpress' ), |
| 319 |
'description' => esc_html__( 'Run this to get fresh topic counts for all users.', 'bbpress' ), |
| 320 |
'callback' => 'bbp_admin_repair_user_topic_count', |
| 321 |
'priority' => 75, |
| 322 |
'overhead' => 'medium', |
| 323 |
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) |
| 324 |
) |
| 325 |
); |
| 326 |
|
| 327 |
// Recount topics for each user |
| 328 |
bbp_register_repair_tool( |
| 329 |
array( |
| 330 |
'id' => 'bbp-user-replies', |
| 331 |
'type' => 'repair', |
| 332 |
'title' => esc_html__( 'Recount replies for each user', 'bbpress' ), |
| 333 |
'description' => esc_html__( 'Run this to get fresh reply counts for all users.', 'bbpress' ), |
| 334 |
'callback' => 'bbp_admin_repair_user_reply_count', |
| 335 |
'priority' => 80, |
| 336 |
'overhead' => 'medium', |
| 337 |
'components' => array( bbp_get_reply_post_type(), bbp_get_user_rewrite_id() ) |
| 338 |
) |
| 339 |
); |
| 340 |
|
| 341 |
// Remove unpublished topics from user favorites |
| 342 |
bbp_register_repair_tool( |
| 343 |
array( |
| 344 |
'id' => 'bbp-user-favorites', |
| 345 |
'type' => 'repair', |
| 346 |
'title' => esc_html__( 'Remove unpublished topics from user favorites', 'bbpress' ), |
| 347 |
'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user favorites.', 'bbpress' ), |
| 348 |
'callback' => 'bbp_admin_repair_user_favorites', |
| 349 |
'priority' => 85, |
| 350 |
'overhead' => 'medium', |
| 351 |
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) |
| 352 |
) |
| 353 |
); |
| 354 |
|
| 355 |
// Remove unpublished topics from user subscriptions |
| 356 |
bbp_register_repair_tool( |
| 357 |
array( |
| 358 |
'id' => 'bbp-user-topic-subscriptions', |
| 359 |
'type' => 'repair', |
| 360 |
'title' => esc_html__( 'Remove unpublished topics from user subscriptions', 'bbpress' ), |
| 361 |
'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user subscriptions.', 'bbpress' ), |
| 362 |
'callback' => 'bbp_admin_repair_user_topic_subscriptions', |
| 363 |
'priority' => 90, |
| 364 |
'overhead' => 'medium', |
| 365 |
'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) |
| 366 |
) |
| 367 |
); |
| 368 |
|
| 369 |
// Remove unpublished forums from user subscriptions |
| 370 |
bbp_register_repair_tool( |
| 371 |
array( |
| 372 |
'id' => 'bbp-user-forum-subscriptions', |
| 373 |
'type' => 'repair', |
| 374 |
'title' => esc_html__( 'Remove unpublished forums from user subscriptions', 'bbpress' ), |
| 375 |
'description' => esc_html__( 'Run this to remove trashed or deleted forums from all user subscriptions.', 'bbpress' ), |
| 376 |
'callback' => 'bbp_admin_repair_user_forum_subscriptions', |
| 377 |
'priority' => 95, |
| 378 |
'overhead' => 'medium', |
| 379 |
'components' => array( bbp_get_forum_post_type(), bbp_get_user_rewrite_id() ) |
| 380 |
) |
| 381 |
); |
| 382 |
|
| 383 |
// Remove unpublished forums from user subscriptions |
| 384 |
bbp_register_repair_tool( |
| 385 |
array( |
| 386 |
'id' => 'bbp-user-role-map', |
| 387 |
'type' => 'repair', |
| 388 |
'title' => esc_html__( 'Remap all users to default forum roles', 'bbpress' ), |
| 389 |
'description' => esc_html__( 'Run this if users have issues accessing the forums.', 'bbpress' ), |
| 390 |
'callback' => 'bbp_admin_repair_user_roles', |
| 391 |
'priority' => 100, |
| 392 |
'overhead' => 'low', |
| 393 |
'components' => array( bbp_get_user_rewrite_id() ) |
| 394 |
) |
| 395 |
); |
| 396 |
|
| 397 |
// Migrate topic engagements to post-meta |
| 398 |
bbp_register_repair_tool( |
| 399 |
array( |
| 400 |
'id' => 'bbp-user-topic-engagements-move', |
| 401 |
'type' => 'upgrade', |
| 402 |
'title' => esc_html__( 'Upgrade user topic engagements', 'bbpress' ), |
| 403 |
'description' => esc_html__( 'Copies engagements from user meta to topic meta.', 'bbpress' ), |
| 404 |
'callback' => 'bbp_admin_upgrade_user_engagements', |
| 405 |
'priority' => 105, |
| 406 |
'version' => '2.6.0', |
| 407 |
'overhead' => 'high', |
| 408 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_engagements_rewrite_id() ) |
| 409 |
) |
| 410 |
); |
| 411 |
|
| 412 |
// Migrate favorites from user-meta to post-meta |
| 413 |
bbp_register_repair_tool( |
| 414 |
array( |
| 415 |
'id' => 'bbp-user-favorites-move', |
| 416 |
'type' => 'upgrade', |
| 417 |
'title' => esc_html__( 'Upgrade user topic favorites', 'bbpress' ), |
| 418 |
'description' => esc_html__( 'Copies favorites from user meta to topic meta.', 'bbpress' ), |
| 419 |
'callback' => 'bbp_admin_upgrade_user_favorites', |
| 420 |
'priority' => 110, |
| 421 |
'version' => '2.6.0', |
| 422 |
'overhead' => 'high', |
| 423 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_favorites_rewrite_id() ) |
| 424 |
) |
| 425 |
); |
| 426 |
|
| 427 |
// Migrate topic subscriptions from user-meta to post-meta |
| 428 |
bbp_register_repair_tool( |
| 429 |
array( |
| 430 |
'id' => 'bbp-user-topic-subscriptions-move', |
| 431 |
'type' => 'upgrade', |
| 432 |
'title' => esc_html__( 'Upgrade user topic subscriptions', 'bbpress' ), |
| 433 |
'description' => esc_html__( 'Copies topic subscriptions from user meta to topic meta.', 'bbpress' ), |
| 434 |
'callback' => 'bbp_admin_upgrade_user_topic_subscriptions', |
| 435 |
'priority' => 115, |
| 436 |
'version' => '2.6.0', |
| 437 |
'overhead' => 'high', |
| 438 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() ) |
| 439 |
) |
| 440 |
); |
| 441 |
|
| 442 |
// Migrate forum subscriptions from user-meta to post-meta |
| 443 |
bbp_register_repair_tool( |
| 444 |
array( |
| 445 |
'id' => 'bbp-user-forum-subscriptions-move', |
| 446 |
'type' => 'upgrade', |
| 447 |
'title' => esc_html__( 'Upgrade user forum subscriptions', 'bbpress' ), |
| 448 |
'description' => esc_html__( 'Copies forum subscriptions from user meta to forum meta.', 'bbpress' ), |
| 449 |
'callback' => 'bbp_admin_upgrade_user_forum_subscriptions', |
| 450 |
'priority' => 120, |
| 451 |
'version' => '2.6.0', |
| 452 |
'overhead' => 'high', |
| 453 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() ) |
| 454 |
) |
| 455 |
); |
| 456 |
|
| 457 |
// Remove favorites from user-meta |
| 458 |
bbp_register_repair_tool( |
| 459 |
array( |
| 460 |
'id' => 'bbp-user-favorites-delete', |
| 461 |
'type' => 'upgrade', |
| 462 |
'title' => esc_html__( 'Remove favorites from user-meta', 'bbpress' ), |
| 463 |
'description' => esc_html__( 'Run this to delete old data (after confirming successful favorites upgrade)', 'bbpress' ), |
| 464 |
'callback' => 'bbp_admin_upgrade_remove_favorites_from_usermeta', |
| 465 |
'priority' => 125, |
| 466 |
'version' => '2.6.1', |
| 467 |
'overhead' => 'medium', |
| 468 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_favorites_rewrite_id() ) |
| 469 |
) |
| 470 |
); |
| 471 |
|
| 472 |
// Remove topic subscriptions from user-meta |
| 473 |
bbp_register_repair_tool( |
| 474 |
array( |
| 475 |
'id' => 'bbp-user-topic-subscriptions-delete', |
| 476 |
'type' => 'upgrade', |
| 477 |
'title' => esc_html__( 'Remove topic subscriptions from user-meta', 'bbpress' ), |
| 478 |
'description' => esc_html__( 'Run this to delete old data (after confirming successful topic subscriptions upgrade)', 'bbpress' ), |
| 479 |
'callback' => 'bbp_admin_upgrade_remove_topic_subscriptions_from_usermeta', |
| 480 |
'priority' => 130, |
| 481 |
'version' => '2.6.1', |
| 482 |
'overhead' => 'medium', |
| 483 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() ) |
| 484 |
) |
| 485 |
); |
| 486 |
|
| 487 |
// Remove forum subscriptions from user-meta |
| 488 |
bbp_register_repair_tool( |
| 489 |
array( |
| 490 |
'id' => 'bbp-user-forum-subscriptions-delete', |
| 491 |
'type' => 'upgrade', |
| 492 |
'title' => esc_html__( 'Remove forum subscriptions from user-meta', 'bbpress' ), |
| 493 |
'description' => esc_html__( 'Run this to delete old data (after confirming successful forum subscriptions upgrade)', 'bbpress' ), |
| 494 |
'callback' => 'bbp_admin_upgrade_remove_forum_subscriptions_from_usermeta', |
| 495 |
'priority' => 135, |
| 496 |
'version' => '2.6.1', |
| 497 |
'overhead' => 'medium', |
| 498 |
'components' => array( bbp_get_user_rewrite_id(), bbp_get_user_subscriptions_rewrite_id() ) |
| 499 |
) |
| 500 |
); |
| 501 |
|
| 502 |
// Sync all BuddyPress group forum relationships |
| 503 |
bbp_register_repair_tool( |
| 504 |
array( |
| 505 |
'id' => 'bbp-group-forums', |
| 506 |
'type' => 'upgrade', |
| 507 |
'title' => esc_html__( 'Upgrade BuddyPress Group Forum relationships', 'bbpress' ), |
| 508 |
'description' => esc_html__( 'Run this if you just upgraded BuddyPress Forums from Legacy.', 'bbpress' ), |
| 509 |
'callback' => 'bbp_admin_upgrade_group_forum_relationship', |
| 510 |
'priority' => 140, |
| 511 |
'version' => esc_html__( 'Any', 'bbpress' ), |
| 512 |
'overhead' => 'low', |
| 513 |
'components' => array( bbp_get_forum_post_type() ) |
| 514 |
) |
| 515 |
); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* Output the tabs in the admin area. |
| 520 |
* |
| 521 |
* @since 2.1.0 bbPress (r3872) |
| 522 |
* |
| 523 |
* @param string $active_tab Name of the tab that is active. |
| 524 |
*/ |
| 525 |
function bbp_tools_admin_tabs( $active_tab = '' ) { |
| 526 |
echo bbp_get_tools_admin_tabs( $active_tab ); |
| 527 |
} |
| 528 |
|
| 529 |
/** |
| 530 |
* Output the tabs in the admin area. |
| 531 |
* |
| 532 |
* @since 2.1.0 bbPress (r3872) |
| 533 |
* |
| 534 |
* @param string $active_tab Name of the tab that is active. |
| 535 |
* |
| 536 |
* @return string |
| 537 |
*/ |
| 538 |
function bbp_get_tools_admin_tabs( $active_tab = '' ) { |
| 539 |
|
| 540 |
// Declare local variables |
| 541 |
$tabs_html = ''; |
| 542 |
$idle_class = 'nav-tab'; |
| 543 |
$active_class = 'nav-tab nav-tab-active'; |
| 544 |
|
| 545 |
// Setup core admin tabs |
| 546 |
$tabs = bbp_get_tools_admin_pages(); |
| 547 |
|
| 548 |
// Loop through tabs and build navigation |
| 549 |
foreach ( $tabs as $tab ) { |
| 550 |
|
| 551 |
// Skip if user cannot visit page |
| 552 |
if ( ! current_user_can( $tab['cap'] ) ) { |
| 553 |
continue; |
| 554 |
} |
| 555 |
|
| 556 |
// Setup tab HTML |
| 557 |
$is_current = (bool) ( $tab['page'] === $active_tab ); |
| 558 |
$tab_class = $is_current ? $active_class : $idle_class; |
| 559 |
$tab_url = add_query_arg( array( 'page' => $tab['page'] ), admin_url( 'tools.php' ) ); |
| 560 |
|
| 561 |
// Tab name is not escaped - may contain HTML |
| 562 |
$tabs_html .= '<a href="' . esc_url( $tab_url ) . '" class="' . esc_attr( $tab_class ) . '">' . $tab['name'] . '</a>'; |
| 563 |
} |
| 564 |
|
| 565 |
// Output the tabs |
| 566 |
return $tabs_html; |
| 567 |
} |
| 568 |
|
| 569 |
/** |
| 570 |
* Return possible tools pages. |
| 571 |
* |
| 572 |
* @since 2.6.0 bbPress (r6273) |
| 573 |
* |
| 574 |
* @return array |
| 575 |
*/ |
| 576 |
function bbp_get_tools_admin_pages() { |
| 577 |
|
| 578 |
// Get tools URL one time & use in each tab |
| 579 |
$tools_url = admin_url( 'tools.php' ); |
| 580 |
|
| 581 |
/** |
| 582 |
* Filters the tools admin pages. |
| 583 |
* |
| 584 |
* @since 2.6.0 bbPress (r6273) |
| 585 |
* |
| 586 |
* @param array $pages The default array of tools pages. |
| 587 |
*/ |
| 588 |
return (array) apply_filters( |
| 589 |
'bbp_tools_admin_tabs', |
| 590 |
array( |
| 591 |
array( |
| 592 |
'page' => 'bbp-repair', |
| 593 |
'func' => 'bbp_admin_repair_page', |
| 594 |
'cap' => 'bbp_tools_repair_page', |
| 595 |
'name' => bbp_maybe_append_pending_upgrade_count( esc_html__( 'Repair Forums', 'bbpress' ), 'repair' ), |
| 596 |
|
| 597 |
// Deprecated 2.6.0 |
| 598 |
'href' => add_query_arg( array( 'page' => 'bbp-repair' ), $tools_url ) |
| 599 |
), |
| 600 |
array( |
| 601 |
'page' => 'bbp-upgrade', |
| 602 |
'func' => 'bbp_admin_upgrade_page', |
| 603 |
'cap' => 'bbp_tools_upgrade_page', |
| 604 |
'name' => bbp_maybe_append_pending_upgrade_count( esc_html__( 'Upgrade Forums', 'bbpress' ), 'upgrade' ), |
| 605 |
|
| 606 |
// Deprecated 2.6.0 |
| 607 |
'href' => add_query_arg( array( 'page' => 'bbp-upgrade' ), $tools_url ) |
| 608 |
), |
| 609 |
array( |
| 610 |
'page' => 'bbp-converter', |
| 611 |
'func' => 'bbp_converter_settings_page', |
| 612 |
'cap' => 'bbp_tools_import_page', |
| 613 |
'name' => esc_html__( 'Import Forums', 'bbpress' ), |
| 614 |
|
| 615 |
// Deprecated 2.6.0 |
| 616 |
'href' => add_query_arg( array( 'page' => 'bbp-converter' ), $tools_url ) |
| 617 |
), |
| 618 |
array( |
| 619 |
'page' => 'bbp-reset', |
| 620 |
'func' => 'bbp_admin_reset_page', |
| 621 |
'cap' => 'bbp_tools_reset_page', |
| 622 |
'name' => esc_html__( 'Reset Forums', 'bbpress' ), |
| 623 |
|
| 624 |
// Deprecated 2.6.0 |
| 625 |
'href' => add_query_arg( array( 'page' => 'bbp-reset' ), $tools_url ) |
| 626 |
) |
| 627 |
) |
| 628 |
); |
| 629 |
} |
| 630 |
|