PluginProbe
bbPress / trunk
bbPress vtrunk
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / includes / admin / tools / common.php

common.php in bbPress trunk, at includes/admin/tools/common.php

975 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Admin Tools Common.
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Return the current admin repair tool page.
15 *
16 * @since 2.6.0 bbPress (r6894)
17 *
18 * @return string
19 */
20 function bbp_get_admin_repair_tool_page() {
21 return sanitize_key( $_GET['page'] );
22 }
23
24 /**
25 * Return the current admin repair tool page ID.
26 *
27 * @since 2.6.0 bbPress (r6894)
28 *
29 * @return string
30 */
31 function bbp_get_admin_repair_tool_page_id() {
32
33 // Get the page
34 $page = bbp_get_admin_repair_tool_page();
35
36 // Maybe trim prefix off of page
37 if ( ! empty( $page ) && ( 0 === strpos( $page, 'bbp-' ) ) ) {
38 $page = str_replace( 'bbp-', '', $page );
39 } else {
40 $page = '';
41 }
42
43 return $page;
44 }
45
46 /**
47 * Return a URL to the repair tool page.
48 *
49 * @since 2.6.0 bbPress (r6894)
50 *
51 * @param array $args
52 *
53 * @return string
54 */
55 function bbp_get_admin_repair_tool_page_url( $args = array() ) {
56
57 // Parse arguments
58 $r = wp_parse_args(
59 $args,
60 array(
61 'page' => bbp_get_admin_repair_tool_page()
62 )
63 );
64
65 return add_query_arg( $r, admin_url( 'tools.php' ) );
66 }
67
68 /**
69 * Output the URL to run a specific repair tool.
70 *
71 * @since 2.6.0 bbPress (r5885)
72 *
73 * @param string $component
74 */
75 function bbp_admin_repair_tool_run_url( $component = array() ) {
76 echo esc_url( bbp_get_admin_repair_tool_run_url( $component ) );
77 }
78
79 /**
80 * Return the URL to run a specific repair tool.
81 *
82 * @since 2.6.0 bbPress (r5885)
83 *
84 * @param string $component
85 */
86 function bbp_get_admin_repair_tool_run_url( $component = array() ) {
87
88 // Page
89 $page = ( 'repair' === $component['type'] )
90 ? 'bbp-repair'
91 : 'bbp-upgrade';
92
93 // Arguments
94 $args = array(
95 'page' => $page,
96 'action' => 'run',
97 'checked' => array( $component['id'] )
98 );
99
100 // Url
101 $nonced = wp_nonce_url( bbp_get_admin_repair_tool_page_url( $args ), 'bbpress-do-counts' );
102
103 // Filter & return
104 return apply_filters( 'bbp_get_admin_repair_tool_run_url', $nonced, $component );
105 }
106
107 /**
108 * Assemble the admin notices.
109 *
110 * @since 2.0.0 bbPress (r2613)
111 *
112 * @param string|WP_Error $message A message to be displayed or {@link WP_Error}
113 * @param string $class Optional. A class to be added to the message div
114 * @param bool $is_dismissible Optional. True to dismiss, false to persist
115 *
116 * @return string The message HTML
117 */
118 function bbp_admin_tools_feedback( $message, $class = false, $is_dismissible = true ) {
119 return bbp_admin()->add_notice( $message, $class, $is_dismissible );
120 }
121
122 /**
123 * Handle the processing and feedback of the admin tools page.
124 *
125 * @since 2.0.0 bbPress (r2613)
126 *
127 */
128 function bbp_admin_repair_handler() {
129
130 // Bail if not an actionable request
131 if ( ! bbp_is_get_request() ) {
132 return;
133 }
134
135 // Get the current action or bail
136 if ( ! empty( $_GET['action'] ) ) {
137 $action = sanitize_key( $_GET['action'] );
138 } elseif ( ! empty( $_GET['action2'] ) ) {
139 $action = sanitize_key( $_GET['action2'] );
140 } else {
141 return;
142 }
143
144 // Bail if not running an action
145 if ( 'run' !== $action ) {
146 return;
147 }
148
149 check_admin_referer( 'bbpress-do-counts' );
150
151 // Parse list of checked repairs
152 $checked = ! empty( $_GET['checked'] )
153 ? array_map( 'sanitize_key', $_GET['checked'] )
154 : array();
155
156 // Flush all caches before running tools
157 wp_cache_flush();
158
159 // Get the list
160 $list = bbp_get_admin_repair_tools();
161
162 // Stores messages
163 $messages = array();
164
165 // Run through checked repair tools
166 if ( count( $checked ) ) {
167 foreach ( $checked as $item_id ) {
168 if ( isset( $list[ $item_id ] ) && is_callable( $list[ $item_id ]['callback'] ) ) {
169 $messages[] = call_user_func( $list[ $item_id ]['callback'] );
170
171 // Remove from pending
172 bbp_remove_pending_upgrade( $item_id );
173 }
174 }
175 }
176
177 // Feedback
178 if ( count( $messages ) ) {
179 foreach ( $messages as $message ) {
180 bbp_admin_tools_feedback( $message[1] );
181 }
182 }
183
184 // Flush all caches after running tools
185 wp_cache_flush();
186 }
187
188 /**
189 * Get the array of available repair tools.
190 *
191 * @since 2.6.0 bbPress (r5885)
192 *
193 * @param string $type repair|upgrade The type of tools to get. Default empty for all tools.
194 * @return array
195 */
196 function bbp_get_admin_repair_tools( $type = '' ) {
197
198 // Get tools array
199 $tools = ! empty( bbp_admin()->tools )
200 ? bbp_admin()->tools
201 : array();
202
203 // Maybe limit to type (otherwise return all tools)
204 if ( ! empty( $type ) ) {
205 $tools = wp_list_filter( bbp_admin()->tools, array( 'type' => $type ) );
206 }
207
208 // Filter & return
209 return (array) apply_filters( 'bbp_get_admin_repair_tools', $tools, $type );
210 }
211
212 /**
213 * Return array of components from the array of registered tools.
214 *
215 * @since 2.5.0 bbPress (r5885)
216 *
217 * @return array
218 */
219 function bbp_get_admin_repair_tool_registered_components() {
220
221 // Default return value
222 $retval = array();
223
224 // Get tools
225 $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
226
227 // Loop through tools
228 if ( ! empty( $tools ) ) {
229 $plucked = wp_list_pluck( $tools, 'components' );
230
231 // Loop through components
232 if ( count( $plucked ) ) {
233 foreach ( $plucked as $components ) {
234 foreach ( $components as $component ) {
235
236 // Skip if already in array
237 if ( in_array( $component, $retval, true ) ) {
238 continue;
239 }
240
241 // Add component to the array
242 $retval[] = $component;
243 }
244 }
245 }
246 }
247
248 // Filter & return
249 return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_components', $retval );
250 }
251
252 /**
253 * Output the repair list search form.
254 *
255 * @since 2.6.0 bbPress (r5885)
256 */
257 function bbp_admin_repair_list_search_form() {
258 ?>
259
260 <p class="search-box">
261 <label class="screen-reader-text" for="bbp-repair-search-input"><?php esc_html_e( 'Search Tools:', 'bbpress' ); ?></label>
262 <input type="search" id="bbp-repair-search-input" name="s" value="<?php _admin_search_query(); ?>">
263 <input type="submit" id="search-submit" class="button" value="<?php esc_html_e( 'Search Tools', 'bbpress' ); ?>">
264 </p>
265
266 <?php
267 }
268
269 /**
270 * Output a select drop-down of components to filter by.
271 *
272 * @since 2.5.0 bbPress (r5885)
273 */
274 function bbp_admin_repair_list_components_filter() {
275
276 // Sanitize component value, if exists
277 $selected = ! empty( $_GET['components'] )
278 ? sanitize_key( $_GET['components'] )
279 : '';
280
281 // Get registered components
282 $components = bbp_get_admin_repair_tool_registered_components();
283
284 // Bail if no components
285 if ( empty( $components ) ) {
286 return;
287 } ?>
288
289 <label class="screen-reader-text" for="components"><?php esc_html_e( 'Filter by Component', 'bbpress' ); ?></label>
290 <select name="components" id="components" class="postform">
291 <option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Components', 'bbpress' ); ?></option>
292
293 <?php foreach ( $components as $component ) : ?>
294
295 <option class="level-0" value="<?php echo esc_attr( $component ); ?>" <?php selected( $selected, $component ); ?>><?php echo esc_html( bbp_admin_repair_tool_translate_component( $component ) ); ?></option>
296
297 <?php endforeach; ?>
298
299 </select>
300
301 <?php
302 }
303
304 /**
305 * Return array of versions from the array of registered tools.
306 *
307 * @since 2.6.0 bbPress (r6894)
308 *
309 * @return array
310 */
311 function bbp_get_admin_repair_tool_registered_versions() {
312
313 // Default return value
314 $retval = array();
315
316 // Get tools
317 $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
318
319 // Loop through tools
320 if ( ! empty( $tools ) ) {
321 $plucked = wp_list_pluck( $tools, 'version' );
322
323 // Loop through components
324 if ( count( $plucked ) ) {
325 foreach ( $plucked as $versions ) {
326
327 // Skip if empty
328 if ( empty( $versions ) ) {
329 continue;
330
331 // Cast to array if string
332 } elseif ( is_string( $versions ) ) {
333 $versions = (array) $versions;
334 }
335
336 // Loop through versions
337 foreach ( $versions as $version ) {
338
339 // Skip if already in array
340 if ( in_array( $version, $retval, true ) ) {
341 continue;
342 }
343
344 // Add component to the array
345 $retval[] = $version;
346 }
347 }
348 }
349 }
350
351 // Filter & return
352 return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_versions', $retval );
353 }
354
355 /**
356 * Output a select drop-down of versions to filter by.
357 *
358 * @since 2.5.0 bbPress (r6894)
359 */
360 function bbp_admin_repair_list_versions_filter() {
361
362 // Sanitize component value, if exists
363 $selected = ! empty( $_GET['version'] )
364 ? sanitize_text_field( $_GET['version'] )
365 : '';
366
367 // Get registered components
368 $versions = bbp_get_admin_repair_tool_registered_versions();
369
370 // Bail if no components
371 if ( empty( $versions ) ) {
372 return;
373 } ?>
374
375 <label class="screen-reader-text" for="version"><?php esc_html_e( 'Filter by Version', 'bbpress' ); ?></label>
376 <select name="version" id="version" class="postform">
377 <option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Versions', 'bbpress' ); ?></option>
378
379 <?php foreach ( $versions as $version ) : ?>
380
381 <option class="level-0" value="<?php echo esc_attr( $version ); ?>" <?php selected( $selected, $version ); ?>><?php echo esc_html( bbp_admin_repair_tool_translate_version( $version ) ); ?></option>
382
383 <?php endforeach; ?>
384
385 </select>
386
387 <?php
388 }
389
390 /** Translations **************************************************************/
391
392 /**
393 * Maybe translate a repair tool overhead name.
394 *
395 * @since 2.6.0 bbPress (r6177)
396 *
397 * @param string $overhead
398 * @return string
399 */
400 function bbp_admin_repair_tool_translate_overhead( $overhead = '' ) {
401
402 // Get the name of the component
403 switch ( $overhead ) {
404 case 'low' :
405 $name = esc_html__( 'Low', 'bbpress' );
406 break;
407 case 'medium' :
408 $name = esc_html__( 'Medium', 'bbpress' );
409 break;
410 case 'high' :
411 $name = esc_html__( 'High', 'bbpress' );
412 break;
413 default :
414 $name = ucwords( $overhead );
415 break;
416 }
417
418 return $name;
419 }
420
421 /**
422 * Maybe translate a repair tool component name.
423 *
424 * @since 2.6.0 bbPress (r5885)
425 *
426 * @param string $component
427 * @return string
428 */
429 function bbp_admin_repair_tool_translate_component( $component = '' ) {
430
431 // Get the name of the component
432 switch ( $component ) {
433 case 'bbp_user' :
434 $name = esc_html__( 'Users', 'bbpress' );
435 break;
436 case bbp_get_forum_post_type() :
437 $name = esc_html__( 'Forums', 'bbpress' );
438 break;
439 case bbp_get_topic_post_type() :
440 $name = esc_html__( 'Topics', 'bbpress' );
441 break;
442 case bbp_get_reply_post_type() :
443 $name = esc_html__( 'Replies', 'bbpress' );
444 break;
445 case bbp_get_topic_tag_tax_id() :
446 $name = esc_html__( 'Topic Tags', 'bbpress' );
447 break;
448 case bbp_get_user_rewrite_id() :
449 $name = esc_html__( 'Users', 'bbpress' );
450 break;
451 case bbp_get_user_favorites_rewrite_id() :
452 $name = esc_html__( 'Favorites', 'bbpress' );
453 break;
454 case bbp_get_user_subscriptions_rewrite_id() :
455 $name = esc_html__( 'Subscriptions', 'bbpress' );
456 break;
457 case bbp_get_user_engagements_rewrite_id() :
458 $name = esc_html__( 'Engagements', 'bbpress' );
459 break;
460 default :
461 $name = ucwords( $component );
462 break;
463 }
464
465 return $name;
466 }
467
468 /**
469 * Maybe translate a repair tool overhead name.
470 *
471 * @since 2.6.0 bbPress (r6894)
472 *
473 * @param string $version
474 * @return string
475 */
476 function bbp_admin_repair_tool_translate_version( $version = '' ) {
477
478 // Get the version
479 switch ( $version ) {
480 case '2.5' :
481 case '2.5.0' :
482 $name = esc_html__( '2.5.0', 'bbpress' );
483 break;
484 case '2.6' :
485 case '2.6.0' :
486 $name = esc_html__( '2.6.0', 'bbpress' );
487 break;
488 default :
489 $name = sanitize_text_field( $version );
490 break;
491 }
492
493 return $name;
494 }
495
496 /** Lists *********************************************************************/
497
498 /**
499 * Get the array of the repairs to show in a list table.
500 *
501 * Uses known filters to reduce the registered results down to the most finite
502 * set of tools.
503 *
504 * @since 2.0.0 bbPress (r2613)
505 *
506 * @return array Repair list of options.
507 */
508 function bbp_admin_repair_list( $type = 'repair' ) {
509
510 // Define empty array
511 $repair_list = array();
512
513 // Get the available tools
514 $list = bbp_get_admin_repair_tools( $type );
515
516 // Get pending upgrades
517 $pending = bbp_get_pending_upgrades();
518
519 // Search
520 $search = ! empty( $_GET['s'] )
521 ? stripslashes( $_GET['s'] )
522 : '';
523
524 // Status
525 $status = ! empty( $_GET['status'] )
526 ? sanitize_key( $_GET['status'] )
527 : '';
528
529 // Overhead
530 $overhead = ! empty( $_GET['overhead'] )
531 ? sanitize_key( $_GET['overhead'] )
532 : '';
533
534 // Component
535 $component = ! empty( $_GET['components'] )
536 ? sanitize_key( $_GET['components'] )
537 : '';
538
539 // Version
540 $version = ! empty( $_GET['version'] )
541 ? sanitize_text_field( $_GET['version'] )
542 : '';
543
544 // Orderby
545 $orderby = ! empty( $_GET['orderby'] )
546 ? sanitize_key( $_GET['orderby'] )
547 : 'priority';
548
549 // Order
550 $order = ! empty( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), array( 'asc', 'desc' ), true )
551 ? strtolower( $_GET['order'] )
552 : 'asc';
553
554 // Overhead filter
555 if ( ! empty( $overhead ) ) {
556 $list = wp_list_filter( $list, array( 'overhead' => $overhead ) );
557 }
558
559 if ( count( $list ) ) {
560
561 // Loop through and key by priority for sorting
562 foreach ( $list as $id => $tool ) {
563
564 // Status filter
565 if ( ! empty( $status ) && ( 'pending' === $status ) ) {
566 if ( ! in_array( $id, (array) $pending, true ) ) {
567 continue;
568 }
569 }
570
571 // Component filter
572 if ( ! empty( $component ) ) {
573 if ( ! in_array( $component, (array) $tool['components'], true ) ) {
574 continue;
575 }
576 }
577
578 // Version filter
579 if ( ! empty( $version ) ) {
580 if ( ! in_array( $version, (array) $tool['version'], true ) ) {
581 continue;
582 }
583 }
584
585 // Search
586 if ( ! empty( $search ) ) {
587 if ( ! strstr( strtolower( $tool['title'] ), strtolower( $search ) ) ) {
588 continue;
589 }
590 }
591
592 // Add to repair list
593 $repair_list[ $tool['priority'] ] = array(
594 'id' => sanitize_key( $id ),
595 'type' => $tool['type'],
596 'title' => $tool['title'],
597 'priority' => $tool['priority'],
598 'description' => $tool['description'],
599 'callback' => $tool['callback'],
600 'overhead' => $tool['overhead'],
601 'version' => $tool['version'],
602 'components' => $tool['components']
603 );
604 }
605 }
606
607 // Sort
608 $retval = wp_list_sort( $repair_list, $orderby, $order, true );
609
610 // Filter & return
611 return (array) apply_filters( 'bbp_repair_list', $retval );
612 }
613
614 /**
615 * Get filter links for components for a specific admin repair tool.
616 *
617 * @since 2.6.0 bbPress (r5885)
618 *
619 * @param array $item
620 * @return array
621 */
622 function bbp_get_admin_repair_tool_components( $item = array() ) {
623
624 // Get the tools URL
625 $tools_url = bbp_get_admin_repair_tool_page_url();
626
627 // Define links array
628 $links = array();
629 $components = ! empty( $item['components'] )
630 ? (array) $item['components']
631 : array();
632
633 // Loop through tool components and build links
634 if ( count( $components ) ) {
635 foreach ( $components as $component ) {
636 $args = array( 'components' => $component );
637 $filter_url = add_query_arg( $args, $tools_url );
638 $name = bbp_admin_repair_tool_translate_component( $component );
639 $links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
640 }
641
642 // No components, so return a dash
643 } else {
644 $links[] = '&mdash;';
645 }
646
647 // Filter & return
648 return (array) apply_filters( 'bbp_get_admin_repair_tool_components', $links, $item );
649 }
650
651 /**
652 * Get filter links for versions for a specific admin repair tool.
653 *
654 * @since 2.6.0 bbPress (r6894)
655 *
656 * @param array $item
657 * @return array
658 */
659 function bbp_get_admin_repair_tool_version( $item = array() ) {
660
661 // Get the tools URL
662 $tools_url = bbp_get_admin_repair_tool_page_url();
663
664 // Define links array
665 $links = array();
666 $versions = ! empty( $item['version'] )
667 ? (array) $item['version']
668 : array();
669
670 // Loop through tool versions and build links
671 if ( count( $versions ) ) {
672 foreach ( $versions as $version ) {
673 $args = array( 'version' => $version );
674 $filter_url = add_query_arg( $args, $tools_url );
675 $name = bbp_admin_repair_tool_translate_version( $version );
676 $links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
677 }
678
679 // No versions, so return a dash
680 } else {
681 $links[] = '&mdash;';
682 }
683
684 // Filter & return
685 return (array) apply_filters( 'bbp_get_admin_repair_tool_version', $links, $item );
686 }
687
688 /**
689 * Get filter links for overhead for a specific admin repair tool.
690 *
691 * @since 2.6.0 bbPress (r5885)
692 *
693 * @param array $item
694 * @return array
695 */
696 function bbp_get_admin_repair_tool_overhead( $item = array() ) {
697
698 // Get the tools URL
699 $tools_url = bbp_get_admin_repair_tool_page_url();
700
701 // Define links array
702 $links = array();
703 $overheads = ! empty( $item['overhead'] )
704 ? (array) $item['overhead']
705 : array();
706
707 // Loop through tool overhead and build links
708 if ( count( $overheads ) ) {
709 foreach ( $overheads as $overhead ) {
710 $args = array( 'overhead' => $overhead );
711 $filter_url = add_query_arg( $args, $tools_url );
712 $name = bbp_admin_repair_tool_translate_overhead( $overhead );
713 $links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
714 }
715
716 // No overhead, so return a single dash
717 } else {
718 $links[] = '&mdash;';
719 }
720
721 // Filter & return
722 return (array) apply_filters( 'bbp_get_admin_repair_tool_overhead', $links, $item );
723 }
724
725 /** Overhead ******************************************************************/
726
727 /**
728 * Output filter links for overheads for a specific admin repair tool.
729 *
730 * @since 2.6.0 bbPress (r5885)
731 *
732 * @param array $args
733 */
734 function bbp_admin_repair_tool_overhead_filters( $args = array() ) {
735 echo bbp_get_admin_repair_tool_overhead_filters( $args );
736 }
737
738 /**
739 * Get filter links for overheads for a specific admin repair tool.
740 *
741 * @since 2.6.0 bbPress (r5885)
742 *
743 * @param array $args
744 * @return array
745 */
746 function bbp_get_admin_repair_tool_overhead_filters( $args = array() ) {
747
748 // Parse args
749 $r = bbp_parse_args(
750 $args,
751 array(
752 'before' => '<ul class="subsubsub">',
753 'after' => '</ul>',
754 'link_before' => '<li>',
755 'link_after' => '</li>',
756 'count_before' => ' <span class="count">(',
757 'count_after' => ')</span>',
758 'sep' => ' | ',
759
760 // Retired, use 'sep' instead
761 'separator' => false
762 ),
763 'get_admin_repair_tool_overhead_filters'
764 );
765
766 /**
767 * Necessary for backwards compatibility
768 * @see https://bbpress.trac.wordpress.org/ticket/2900
769 */
770 if ( ! empty( $r['separator'] ) ) {
771 $r['sep'] = $r['separator'];
772 }
773
774 // Count the tools
775 $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() );
776
777 // Get the tools URL
778 $tools_url = bbp_get_admin_repair_tool_page_url();
779
780 // Define arrays
781 $overheads = $links = array();
782
783 // Loop through tools and count overheads
784 if ( count( $tools ) ) {
785 foreach ( $tools as $tool ) {
786
787 // Get the overhead level
788 $overhead = $tool['overhead'];
789
790 // Set an empty count
791 if ( empty( $overheads[ $overhead ] ) ) {
792 $overheads[ $overhead ] = 0;
793 }
794
795 // Bump the overhead count
796 ++$overheads[ $overhead ];
797 }
798 }
799
800 // Get the current overhead, if any
801 $selected = ! empty( $_GET['overhead'] )
802 ? sanitize_key( $_GET['overhead'] )
803 : '';
804
805 // Create the "All" link
806 $current = empty( $selected ) ? 'current' : '';
807
808 $all_text = sprintf(
809 /* translators: %s: Number of items */
810 esc_html__( 'All %s', 'bbpress' ),
811 $r['count_before'] . count( $tools ) . $r['count_after']
812 );
813
814 $links[] = sprintf(
815 '%1$s<a href="%2$s" class="%3$s">%4$s</a>%5$s',
816 $r['link_before'],
817 esc_url( $tools_url ),
818 esc_attr( $current ),
819 $all_text,
820 $r['link_after']
821 );
822
823 // Loop through overheads and created links
824 if ( count( $overheads ) ) {
825
826 // Sort
827 ksort( $overheads );
828
829 // Loop through overheads and build filter
830 foreach ( $overheads as $overhead => $count ) {
831
832 // Build the filter URL
833 $key = sanitize_key( $overhead );
834 $args = array( 'overhead' => $key );
835 $filter_url = add_query_arg( $args, $tools_url );
836
837 // Figure out separator and active class
838 $current = ( $selected === $key )
839 ? 'current'
840 : '';
841
842 // Counts to show
843 if ( ! empty( $count ) ) {
844 $overhead_count = $r['count_before'] . $count . $r['count_after'];
845 }
846
847 // Build the link
848 $links[] = $r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $current ) . '">' . bbp_admin_repair_tool_translate_overhead( $overhead ) . $overhead_count . '</a>' . $r['link_after'];
849 }
850 }
851
852 // Surround output with before & after strings
853 $output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
854
855 // Filter & return
856 return apply_filters( 'bbp_get_admin_repair_tool_overhead_filters', $output, $r, $args );
857 }
858
859 /** Pending ******************************************************************/
860
861 /**
862 * Output filter links for statuses.
863 *
864 * @since 2.6.0 bbPress (r6925)
865 *
866 * @param array $args
867 */
868 function bbp_admin_repair_tool_status_filters( $args = array() ) {
869 echo bbp_get_admin_repair_tool_status_filters( $args );
870 }
871
872 /**
873 * Get filter links for statuses.
874 *
875 * @since 2.6.0 bbPress (r5885)
876 *
877 * @param array $args
878 * @return array
879 */
880 function bbp_get_admin_repair_tool_status_filters( $args = array() ) {
881
882 // Parse args
883 $r = bbp_parse_args(
884 $args,
885 array(
886 'before' => '<ul class="subsubsub">',
887 'after' => '</ul>',
888 'link_before' => '<li>',
889 'link_after' => '</li>',
890 'count_before' => ' <span class="count">(',
891 'count_after' => ')</span>',
892 'sep' => ' | ',
893
894 // Retired, use 'sep' instead
895 'separator' => false
896 ),
897 'get_admin_repair_tool_status_filters'
898 );
899
900 /**
901 * Necessary for backwards compatibility
902 * @see https://bbpress.trac.wordpress.org/ticket/2900
903 */
904 if ( ! empty( $r['separator'] ) ) {
905 $r['sep'] = $r['separator'];
906 }
907
908 // Get the type of tool
909 $type = bbp_get_admin_repair_tool_page_id();
910
911 // Count the tools
912 $tools = bbp_get_admin_repair_tools( $type );
913
914 // Get the tools URL
915 $tools_url = bbp_get_admin_repair_tool_page_url();
916
917 // Get pending upgrades
918 $pending = bbp_get_pending_upgrades( $type );
919
920 // Get the current status, if any
921 $selected = ! empty( $_GET['status'] )
922 ? sanitize_key( $_GET['status'] )
923 : '';
924
925 // Nothing is current?
926 $all_current = empty( $selected )
927 ? 'current'
928 : '';
929
930 // Pending is current?
931 $pending_current = ( 'pending' === $selected )
932 ? 'current'
933 : '';
934
935 // Sort
936 ksort( $pending );
937
938 // Build the filter URL
939 $filter_url = add_query_arg(
940 array(
941 'status' => 'pending'
942 ),
943 $tools_url
944 );
945
946 // Count HTML
947 $all_count = $r['count_before'] . count( $tools ) . $r['count_after'];
948 $pending_count = $r['count_before'] . count( $pending ) . $r['count_after'];
949
950 // Define links
951 $links = array(
952 $r['link_before'] . '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $all_current ) . '">' .
953 sprintf(
954 /* translators: %s: Number of items */
955 esc_html__( 'All %s', 'bbpress' ),
956 $all_count
957 ) .
958 '</a>' . $r['link_after'],
959
960 $r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $pending_current ) . '">' .
961 sprintf(
962 /* translators: %s: Number of pending items */
963 esc_html__( 'Pending %s', 'bbpress' ),
964 $pending_count
965 ) .
966 '</a>' . $r['link_after']
967 );
968
969 // Surround output with before & after strings
970 $output = $r['before'] . implode( $r['sep'], $links ) . $r['after'];
971
972 // Filter & return
973 return apply_filters( 'bbp_get_admin_repair_tool_status_filters', $output, $r, $args );
974 }
975