Changeset 6279
- Timestamp:
- 02/03/2017 05:47:03 PM (9 years ago)
- Location:
- trunk/src/includes/admin
- Files:
-
- 1 added
- 4 edited
-
actions.php (modified) (1 diff)
-
admin.php (modified) (2 diffs)
-
functions.php (modified) (1 diff)
-
tools.php (modified) (40 diffs)
-
upgrades.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/actions.php
r6274 r6279 79 79 80 80 // Load the default repair tools 81 add_action( 'load-tools_page_bbp-repair', 'bbp_register_default_repair_tools' ); 81 add_action( 'load-tools_page_bbp-repair', 'bbp_register_default_repair_tools' ); 82 add_action( 'load-tools_page_bbp-upgrade', 'bbp_register_default_repair_tools' ); 82 83 83 84 // Contextual Helpers 84 add_action( 'load-settings_page_bbpress', 'bbp_admin_settings_help' ); 85 add_action( 'load-tools_page_bbp-repair', 'bbp_admin_tools_repair_help' ); 85 add_action( 'load-settings_page_bbpress', 'bbp_admin_settings_help' ); 86 add_action( 'load-tools_page_bbp-repair', 'bbp_admin_tools_repair_help' ); 87 add_action( 'load-tools_page_bbp-upgrade', 'bbp_admin_tools_repair_help' ); 86 88 add_action( 'load-tools_page_bbp-converter', 'bbp_admin_tools_converter_help' ); 87 add_action( 'load-tools_page_bbp-reset', 'bbp_admin_tools_reset_help' );89 add_action( 'load-tools_page_bbp-reset', 'bbp_admin_tools_reset_help' ); 88 90 89 91 // Handle submission of Tools pages 90 add_action( 'load-tools_page_bbp-repair', 'bbp_admin_repair_handler' ); 91 add_action( 'load-tools_page_bbp-reset', 'bbp_admin_reset_handler' ); 92 add_action( 'bbp_admin_tool_box', 'bbp_admin_tools_box' ); 92 add_action( 'load-tools_page_bbp-repair', 'bbp_admin_repair_handler' ); 93 add_action( 'load-tools_page_bbp-upgrade', 'bbp_admin_repair_handler' ); 94 add_action( 'load-tools_page_bbp-reset', 'bbp_admin_reset_handler' ); 95 add_action( 'bbp_admin_tool_box', 'bbp_admin_tools_box' ); 93 96 94 97 // Add sample permalink filter -
trunk/src/includes/admin/admin.php
r6276 r6279 119 119 private function includes() { 120 120 require( $this->admin_dir . 'tools.php' ); 121 require( $this->admin_dir . 'upgrades.php' ); 121 122 require( $this->admin_dir . 'converter.php' ); 122 123 require( $this->admin_dir . 'settings.php' ); … … 234 235 'bbp_tools_page', 235 236 'bbp-repair', 236 'bbp_admin_repair '237 'bbp_admin_repair_page' 237 238 ); 238 239 -
trunk/src/includes/admin/functions.php
r6277 r6279 318 318 ), 319 319 array( 320 'page' => 'bbp-upgrade', 321 'func' => 'bbp_admin_upgrade_page', 322 'cap' => 'bbp_tools_upgrade_page', 323 'name' => esc_html__( 'Upgrade Forums', 'bbpress' ), 324 325 // Deprecated 2.6.0 326 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-upgrade' ), 'tools.php' ) ) 327 ), 328 array( 320 329 'page' => 'bbp-converter', 321 330 'func' => 'bbp_converter_settings_page', -
trunk/src/includes/admin/tools.php
r6278 r6279 136 136 <div class="row-actions hide-if-no-js"> 137 137 <span class="run"> 138 <a href="<?php bbp_admin_repair_tool_run_url( $item ['id']); ?>" aria-label="<?php printf( esc_html__( 'Run %s', 'bbpress' ), $item['description'] ); ?>" id="<?php echo esc_attr( $item['id'] ); ?>" ><?php esc_html_e( 'Run', 'bbpress' ); ?></a>138 <a href="<?php bbp_admin_repair_tool_run_url( $item ); ?>" aria-label="<?php printf( esc_html__( 'Run %s', 'bbpress' ), $item['description'] ); ?>" id="<?php echo esc_attr( $item['id'] ); ?>" ><?php esc_html_e( 'Run', 'bbpress' ); ?></a> 139 139 </span> 140 140 </div> … … 269 269 * @param string $component 270 270 */ 271 function bbp_admin_repair_tool_run_url( $component = '') {271 function bbp_admin_repair_tool_run_url( $component = array() ) { 272 272 echo esc_url( bbp_get_admin_repair_tool_run_url( $component ) ); 273 273 } … … 280 280 * @param string $component 281 281 */ 282 function bbp_get_admin_repair_tool_run_url( $component = '') {282 function bbp_get_admin_repair_tool_run_url( $component = array() ) { 283 283 $tools = admin_url( 'tools.php' ); 284 $args = array( 'page' => 'bbp-repair', 'action' => 'run', 'checked' => array( $component ) ); 284 $page = ( 'repair' === $component['type'] ) ? 'bbp-repair' : 'bbp-upgrade'; 285 $args = array( 'page' => $page, 'action' => 'run', 'checked' => array( $component['id'] ) ); 285 286 $url = add_query_arg( $args, $tools ); 286 287 $nonced = wp_nonce_url( $url, 'bbpress-do-counts' ); … … 487 488 $r = bbp_parse_args( $args, array( 488 489 'id' => '', 490 'type' => '', 489 491 'description' => '', 490 492 'callback' => '', … … 505 507 // Add tool to the registered tools array 506 508 bbpress()->admin->tools[ $r['id'] ] = array( 509 'type' => $r['type'], 507 510 'description' => $r['description'], 508 511 'priority' => $r['priority'], … … 527 530 bbp_register_repair_tool( array( 528 531 'id' => 'bbp-sync-topic-meta', 532 'type' => 'repair', 529 533 'description' => __( 'Recalculate parent topic for each reply', 'bbpress' ), 530 534 'callback' => 'bbp_admin_repair_topic_meta', … … 537 541 bbp_register_repair_tool( array( 538 542 'id' => 'bbp-sync-forum-meta', 543 'type' => 'repair', 539 544 'description' => __( 'Recalculate parent forum for each topic and reply', 'bbpress' ), 540 545 'callback' => 'bbp_admin_repair_forum_meta', … … 547 552 bbp_register_repair_tool( array( 548 553 'id' => 'bbp-sync-forum-visibility', 554 'type' => 'repair', 549 555 'description' => __( 'Recalculate private and hidden forums', 'bbpress' ), 550 556 'callback' => 'bbp_admin_repair_forum_visibility', … … 557 563 bbp_register_repair_tool( array( 558 564 'id' => 'bbp-sync-all-topics-forums', 565 'type' => 'repair', 559 566 'description' => __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 560 567 'callback' => 'bbp_admin_repair_freshness', … … 567 574 bbp_register_repair_tool( array( 568 575 'id' => 'bbp-sync-all-topics-sticky', 576 'type' => 'repair', 569 577 'description' => __( 'Recalculate sticky relationship of each topic', 'bbpress' ), 570 578 'callback' => 'bbp_admin_repair_sticky', … … 577 585 bbp_register_repair_tool( array( 578 586 'id' => 'bbp-sync-all-reply-positions', 587 'type' => 'repair', 579 588 'description' => __( 'Recalculate the position of each reply', 'bbpress' ), 580 589 'callback' => 'bbp_admin_repair_reply_menu_order', … … 587 596 bbp_register_repair_tool( array( 588 597 'id' => 'bbp-group-forums', 598 'type' => 'repair', 589 599 'description' => __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 590 600 'callback' => 'bbp_admin_repair_group_forum_relationship', … … 597 607 bbp_register_repair_tool( array( 598 608 'id' => 'bbp-sync-closed-topics', 609 'type' => 'repair', 599 610 'description' => __( 'Repair closed topics', 'bbpress' ), 600 611 'callback' => 'bbp_admin_repair_closed_topics', … … 607 618 bbp_register_repair_tool( array( 608 619 'id' => 'bbp-forum-topics', 620 'type' => 'repair', 609 621 'description' => __( 'Recount topics in each forum', 'bbpress' ), 610 622 'callback' => 'bbp_admin_repair_forum_topic_count', … … 617 629 bbp_register_repair_tool( array( 618 630 'id' => 'bbp-topic-tags', 631 'type' => 'repair', 619 632 'description' => __( 'Recount topics in each topic-tag', 'bbpress' ), 620 633 'callback' => 'bbp_admin_repair_topic_tag_count', … … 627 640 bbp_register_repair_tool( array( 628 641 'id' => 'bbp-forum-replies', 642 'type' => 'repair', 629 643 'description' => __( 'Recount replies in each forum', 'bbpress' ), 630 644 'callback' => 'bbp_admin_repair_forum_reply_count', … … 637 651 bbp_register_repair_tool( array( 638 652 'id' => 'bbp-topic-replies', 653 'type' => 'repair', 639 654 'description' => __( 'Recount replies in each topic', 'bbpress' ), 640 655 'callback' => 'bbp_admin_repair_topic_reply_count', … … 647 662 bbp_register_repair_tool( array( 648 663 'id' => 'bbp-topic-voices', 664 'type' => 'repair', 649 665 'description' => __( 'Recount voices in each topic', 'bbpress' ), 650 666 'callback' => 'bbp_admin_repair_topic_voice_count', … … 657 673 bbp_register_repair_tool( array( 658 674 'id' => 'bbp-topic-hidden-replies', 675 'type' => 'repair', 659 676 'description' => __( 'Recount pending, spammed, & trashed replies in each topic', 'bbpress' ), 660 677 'callback' => 'bbp_admin_repair_topic_hidden_reply_count', … … 667 684 bbp_register_repair_tool( array( 668 685 'id' => 'bbp-user-topics', 686 'type' => 'repair', 669 687 'description' => __( 'Recount topics for each user', 'bbpress' ), 670 688 'callback' => 'bbp_admin_repair_user_topic_count', … … 677 695 bbp_register_repair_tool( array( 678 696 'id' => 'bbp-user-replies', 697 'type' => 'repair', 679 698 'description' => __( 'Recount replies for each user', 'bbpress' ), 680 699 'callback' => 'bbp_admin_repair_user_reply_count', … … 687 706 bbp_register_repair_tool( array( 688 707 'id' => 'bbp-user-favorites', 708 'type' => 'repair', 689 709 'description' => __( 'Remove unpublished topics from user favorites', 'bbpress' ), 690 710 'callback' => 'bbp_admin_repair_user_favorites', … … 697 717 bbp_register_repair_tool( array( 698 718 'id' => 'bbp-user-topic-subscriptions', 719 'type' => 'repair', 699 720 'description' => __( 'Remove unpublished topics from user subscriptions', 'bbpress' ), 700 721 'callback' => 'bbp_admin_repair_user_topic_subscriptions', … … 707 728 bbp_register_repair_tool( array( 708 729 'id' => 'bbp-user-forum-subscriptions', 730 'type' => 'repair', 709 731 'description' => __( 'Remove unpublished forums from user subscriptions', 'bbpress' ), 710 732 'callback' => 'bbp_admin_repair_user_forum_subscriptions', … … 717 739 bbp_register_repair_tool( array( 718 740 'id' => 'bbp-user-role-map', 741 'type' => 'repair', 719 742 'description' => __( 'Remap existing users to default forum roles', 'bbpress' ), 720 743 'callback' => 'bbp_admin_repair_user_roles', … … 727 750 bbp_register_repair_tool( array( 728 751 'id' => 'bbp-user-favorites-move', 752 'type' => 'upgrade', 729 753 'description' => __( 'Upgrade user favorites', 'bbpress' ), 730 754 'callback' => 'bbp_admin_upgrade_user_favorites', … … 737 761 bbp_register_repair_tool( array( 738 762 'id' => 'bbp-user-topic-subscriptions-move', 763 'type' => 'upgrade', 739 764 'description' => __( 'Upgrade user topic subscriptions', 'bbpress' ), 740 765 'callback' => 'bbp_admin_upgrade_user_topic_subscriptions', … … 747 772 bbp_register_repair_tool( array( 748 773 'id' => 'bbp-user-forum-subscriptions-move', 774 'type' => 'upgrade', 749 775 'description' => __( 'Upgrade user forum subscriptions', 'bbpress' ), 750 776 'callback' => 'bbp_admin_upgrade_user_forum_subscriptions', … … 760 786 * @since 2.6.0 bbPress (r5885) 761 787 * 788 * @param string $type repair|upgrade The type of tools to get. Default to 'repair' 762 789 * @return array 763 790 */ 764 function bbp_get_admin_repair_tools( ) {791 function bbp_get_admin_repair_tools( $type = '' ) { 765 792 766 793 // Get tools array … … 769 796 : array(); 770 797 771 return apply_filters( 'bbp_get_admin_repair_tools', $tools ); 798 // Maybe limit to type (otherwise return all tools) 799 if ( ! empty( $type ) ) { 800 $tools = wp_list_filter( bbpress()->admin->tools, array( 'type' => $type ) ); 801 } 802 803 return apply_filters( 'bbp_get_admin_repair_tools', $tools, $type ); 772 804 } 773 805 … … 780 812 */ 781 813 function bbp_get_admin_repair_tool_registered_components() { 782 $tools = bbp_get_admin_repair_tools( );814 $tools = bbp_get_admin_repair_tools( str_replace( 'bbp-', '', sanitize_key( $_GET['page'] ) ) ); 783 815 $plucked = wp_list_pluck( $tools, 'components' ); 784 816 $retval = array(); … … 916 948 * @return array Repair list of options 917 949 */ 918 function bbp_admin_repair_list( ) {950 function bbp_admin_repair_list( $type = 'repair' ) { 919 951 920 952 // Define empty array … … 922 954 923 955 // Get the available tools 924 $list = bbp_get_admin_repair_tools( );956 $list = bbp_get_admin_repair_tools( $type ); 925 957 $search = ! empty( $_GET['s'] ) ? stripslashes( $_GET['s'] ) : ''; 926 958 $overhead = ! empty( $_GET['overhead'] ) ? sanitize_key( $_GET['overhead'] ) : ''; … … 952 984 $repair_list[ $tool['priority'] ] = array( 953 985 'id' => sanitize_key( $id ), 986 'type' => $tool['type'], 954 987 'description' => $tool['description'], 955 988 'callback' => $tool['callback'], … … 976 1009 977 1010 // Get the tools URL 978 $tools_url = add_query_arg( array( 'page' => 'bbp-repair'), admin_url( 'tools.php' ) );1011 $tools_url = add_query_arg( array( 'page' => sanitize_key( $_GET['page'] ) ), admin_url( 'tools.php' ) ); 979 1012 980 1013 // Define links array … … 1002 1035 function bbp_admin_repair_tool_overhead_filters( $args = array() ) { 1003 1036 echo bbp_get_admin_repair_tool_overhead_filters( $args ); 1004 }1005 1006 /**1007 * Get filter links for overhead for a specific admin repair tool1008 *1009 * @since 2.6.0 bbPress (r5885)1010 *1011 * @param array $item1012 * @return array1013 */1014 function bbp_get_admin_repair_tool_overhead( $item = array() ) {1015 1016 // Get the tools URL1017 $tools_url = add_query_arg( array( 'page' => 'bbp-repair' ), admin_url( 'tools.php' ) );1018 1019 // Define links array1020 $links = array();1021 $overheads = array( $item['overhead'] );1022 1023 // Loop through tool overhead and build links1024 foreach ( $overheads as $overhead ) {1025 $args = array( 'overhead' => $overhead );1026 $filter_url = add_query_arg( $args, $tools_url );1027 $name = bbp_admin_repair_tool_translate_overhead( $overhead );1028 $links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';1029 }1030 1031 // Filter & return1032 return apply_filters( 'bbp_get_admin_repair_tool_overhead', $links, $item );1033 1037 } 1034 1038 … … 1054 1058 ), 'get_admin_repair_tool_overhead_filters' ); 1055 1059 1060 // Get page 1061 $page = sanitize_key( $_GET['page'] ); 1062 1056 1063 // Count the tools 1057 $tools = bbp_get_admin_repair_tools( );1064 $tools = bbp_get_admin_repair_tools( str_replace( 'bbp-', '', $page ) ); 1058 1065 1059 1066 // Get the tools URL 1060 $tools_url = add_query_arg( array( 'page' => 'bbp-repair'), admin_url( 'tools.php' ) );1067 $tools_url = add_query_arg( array( 'page' => $page ), admin_url( 'tools.php' ) ); 1061 1068 1062 1069 // Define arrays 1063 $overheads = array();1070 $overheads = $links = array(); 1064 1071 1065 1072 // Loop through tools and count overheads … … 1080 1087 // Create the "All" link 1081 1088 $current = empty( $_GET['overhead'] ) ? 'current' : ''; 1082 $ output = $r['link_before']. '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $current ) . '">' . sprintf( esc_html__( 'All %s', 'bbpress' ), $r['count_before'] . count( $tools ) . $r['count_after'] ) . '</a>' . $r['separator']. $r['link_after'];1089 $links[] = $r['link_before']. '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $current ) . '">' . sprintf( esc_html__( 'All %s', 'bbpress' ), $r['count_before'] . count( $tools ) . $r['count_after'] ) . '</a>' . $r['link_after']; 1083 1090 1084 1091 // Default ticker … … 1097 1104 1098 1105 // Figure out separator and active class 1099 $show_sep = count( $overheads ) > $i ? $r['separator'] : '';1100 1106 $current = ! empty( $_GET['overhead'] ) && ( sanitize_key( $_GET['overhead'] ) === $key ) ? 'current' : ''; 1101 1107 … … 1106 1112 1107 1113 // Build the link 1108 $ output .= $r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $current ) . '">' . bbp_admin_repair_tool_translate_overhead( $overhead ) . $overhead_count . '</a>' . $show_sep. $r['link_after'];1114 $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']; 1109 1115 } 1110 1116 1111 1117 // Surround output with before & after strings 1112 $output = $r['before'] . $output. $r['after'];1118 $output = $r['before'] . implode( $r['separator'], $links ) . $r['after']; 1113 1119 1114 1120 // Filter & return 1115 1121 return apply_filters( 'bbp_get_admin_repair_tool_components', $output, $r, $args ); 1122 } 1123 1124 /** 1125 * Get filter links for overhead for a specific admin repair tool 1126 * 1127 * @since 2.6.0 bbPress (r5885) 1128 * 1129 * @param array $item 1130 * @return array 1131 */ 1132 function bbp_get_admin_repair_tool_overhead( $item = array() ) { 1133 1134 // Get the tools URL 1135 $tools_url = add_query_arg( array( 'page' => sanitize_key( $_GET['page'] ) ), admin_url( 'tools.php' ) ); 1136 1137 // Define links array 1138 $links = array(); 1139 $overheads = array( $item['overhead'] ); 1140 1141 // Loop through tool overhead and build links 1142 foreach ( $overheads as $overhead ) { 1143 $args = array( 'overhead' => $overhead ); 1144 $filter_url = add_query_arg( $args, $tools_url ); 1145 $name = bbp_admin_repair_tool_translate_overhead( $overhead ); 1146 $links[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>'; 1147 } 1148 1149 // Filter & return 1150 return apply_filters( 'bbp_get_admin_repair_tool_overhead', $links, $item ); 1116 1151 } 1117 1152
Note: See TracChangeset
for help on using the changeset viewer.