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