bbp_get_admin_repair_tool_page() ) ); return add_query_arg( $r, admin_url( 'tools.php' ) ); } /** * Output the URL to run a specific repair tool * * @since 2.6.0 bbPress (r5885) * * @param string $component */ function bbp_admin_repair_tool_run_url( $component = array() ) { echo esc_url( bbp_get_admin_repair_tool_run_url( $component ) ); } /** * Return the URL to run a specific repair tool * * @since 2.6.0 bbPress (r5885) * * @param string $component */ function bbp_get_admin_repair_tool_run_url( $component = array() ) { // Page $page = ( 'repair' === $component['type'] ) ? 'bbp-repair' : 'bbp-upgrade'; // Arguments $args = array( 'page' => $page, 'action' => 'run', 'checked' => array( $component['id'] ) ); // Url $nonced = wp_nonce_url( bbp_get_admin_repair_tool_page_url( $args ), 'bbpress-do-counts' ); // Filter & return return apply_filters( 'bbp_get_admin_repair_tool_run_url', $nonced, $component ); } /** * Assemble the admin notices * * @since 2.0.0 bbPress (r2613) * * @param string|WP_Error $message A message to be displayed or {@link WP_Error} * @param string $class Optional. A class to be added to the message div * @param bool $is_dismissible Optional. True to dismiss, false to persist * * @return string The message HTML */ function bbp_admin_tools_feedback( $message, $class = false, $is_dismissible = true ) { return bbp_admin()->add_notice( $message, $class, $is_dismissible ); } /** * Handle the processing and feedback of the admin tools page * * @since 2.0.0 bbPress (r2613) * */ function bbp_admin_repair_handler() { // Bail if not an actionable request if ( ! bbp_is_get_request() ) { return; } // Get the current action or bail if ( ! empty( $_GET['action'] ) ) { $action = sanitize_key( $_GET['action'] ); } elseif ( ! empty( $_GET['action2'] ) ) { $action = sanitize_key( $_GET['action2'] ); } else { return; } // Bail if not running an action if ( 'run' !== $action ) { return; } check_admin_referer( 'bbpress-do-counts' ); // Parse list of checked repairs $checked = ! empty( $_GET['checked'] ) ? array_map( 'sanitize_key', $_GET['checked'] ) : array(); // Flush all caches before running tools wp_cache_flush(); // Get the list $list = bbp_get_admin_repair_tools(); // Stores messages $messages = array(); // Run through checked repair tools if ( count( $checked ) ) { foreach ( $checked as $item_id ) { if ( isset( $list[ $item_id ] ) && is_callable( $list[ $item_id ]['callback'] ) ) { $messages[] = call_user_func( $list[ $item_id ]['callback'] ); // Remove from pending bbp_remove_pending_upgrade( $item_id ); } } } // Feedback if ( count( $messages ) ) { foreach ( $messages as $message ) { bbp_admin_tools_feedback( $message[1] ); } } // Flush all caches after running tools wp_cache_flush(); } /** * Get the array of available repair tools * * @since 2.6.0 bbPress (r5885) * * @param string $type repair|upgrade The type of tools to get. Default empty for all tools. * @return array */ function bbp_get_admin_repair_tools( $type = '' ) { // Get tools array $tools = ! empty( bbp_admin()->tools ) ? bbp_admin()->tools : array(); // Maybe limit to type (otherwise return all tools) if ( ! empty( $type ) ) { $tools = wp_list_filter( bbp_admin()->tools, array( 'type' => $type ) ); } // Filter & return return (array) apply_filters( 'bbp_get_admin_repair_tools', $tools, $type ); } /** * Return array of components from the array of registered tools * * @since 2.5.0 bbPress (r5885) * * @return array */ function bbp_get_admin_repair_tool_registered_components() { // Default return value $retval = array(); // Get tools $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() ); // Loop through tools if ( ! empty( $tools ) ) { $plucked = wp_list_pluck( $tools, 'components' ); // Loop through components if ( count( $plucked ) ) { foreach ( $plucked as $components ) { foreach ( $components as $component ) { // Skip if already in array if ( in_array( $component, $retval, true ) ) { continue; } // Add component to the array $retval[] = $component; } } } } // Filter & return return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_components', $retval ); } /** * Output the repair list search form * * @since 2.6.0 bbPress (r5885) */ function bbp_admin_repair_list_search_form() { ?> $overhead ) ); } if ( count( $list ) ) { // Loop through and key by priority for sorting foreach ( $list as $id => $tool ) { // Status filter if ( ! empty( $status ) && ( 'pending' === $status ) ) { if ( ! in_array( $id, (array) $pending, true ) ) { continue; } } // Component filter if ( ! empty( $component ) ) { if ( ! in_array( $component, (array) $tool['components'], true ) ) { continue; } } // Version filter if ( ! empty( $version ) ) { if ( ! in_array( $version, (array) $tool['version'], true ) ) { continue; } } // Search if ( ! empty( $search ) ) { if ( ! strstr( strtolower( $tool['title'] ), strtolower( $search ) ) ) { continue; } } // Add to repair list $repair_list[ $tool['priority'] ] = array( 'id' => sanitize_key( $id ), 'type' => $tool['type'], 'title' => $tool['title'], 'priority' => $tool['priority'], 'description' => $tool['description'], 'callback' => $tool['callback'], 'overhead' => $tool['overhead'], 'version' => $tool['version'], 'components' => $tool['components'] ); } } // Sort $retval = wp_list_sort( $repair_list, $orderby, $order, true ); // Filter & return return (array) apply_filters( 'bbp_repair_list', $retval ); } /** * Get filter links for components for a specific admin repair tool * * @since 2.6.0 bbPress (r5885) * * @param array $item * @return array */ function bbp_get_admin_repair_tool_components( $item = array() ) { // Get the tools URL $tools_url = bbp_get_admin_repair_tool_page_url(); // Define links array $links = array(); $components = ! empty( $item['components'] ) ? (array) $item['components'] : array(); // Loop through tool components and build links if ( count( $components ) ) { foreach ( $components as $component ) { $args = array( 'components' => $component ); $filter_url = add_query_arg( $args, $tools_url ); $name = bbp_admin_repair_tool_translate_component( $component ); $links[] = '' . esc_html( $name ) . ''; } // No components, so return a dash } else { $links[] = '—'; } // Filter & return return (array) apply_filters( 'bbp_get_admin_repair_tool_components', $links, $item ); } /** * Get filter links for versions for a specific admin repair tool * * @since 2.6.0 bbPress (r6894) * * @param array $item * @return array */ function bbp_get_admin_repair_tool_version( $item = array() ) { // Get the tools URL $tools_url = bbp_get_admin_repair_tool_page_url(); // Define links array $links = array(); $versions = ! empty( $item['version'] ) ? (array) $item['version'] : array(); // Loop through tool versions and build links if ( count( $versions ) ) { foreach ( $versions as $version ) { $args = array( 'version' => $version ); $filter_url = add_query_arg( $args, $tools_url ); $name = bbp_admin_repair_tool_translate_version( $version ); $links[] = '' . esc_html( $name ) . ''; } // No versions, so return a dash } else { $links[] = '—'; } // Filter & return return (array) apply_filters( 'bbp_get_admin_repair_tool_version', $links, $item ); } /** * Get filter links for overhead for a specific admin repair tool * * @since 2.6.0 bbPress (r5885) * * @param array $item * @return array */ function bbp_get_admin_repair_tool_overhead( $item = array() ) { // Get the tools URL $tools_url = bbp_get_admin_repair_tool_page_url(); // Define links array $links = array(); $overheads = ! empty( $item['overhead'] ) ? (array) $item['overhead'] : array(); // Loop through tool overhead and build links if ( count( $overheads ) ) { foreach ( $overheads as $overhead ) { $args = array( 'overhead' => $overhead ); $filter_url = add_query_arg( $args, $tools_url ); $name = bbp_admin_repair_tool_translate_overhead( $overhead ); $links[] = '' . esc_html( $name ) . ''; } // No overhead, so return a single dash } else { $links[] = '—'; } // Filter & return return (array) apply_filters( 'bbp_get_admin_repair_tool_overhead', $links, $item ); } /** Overhead ******************************************************************/ /** * Output filter links for overheads for a specific admin repair tool * * @since 2.6.0 bbPress (r5885) * * @param array $args */ function bbp_admin_repair_tool_overhead_filters( $args = array() ) { echo bbp_get_admin_repair_tool_overhead_filters( $args ); } /** * Get filter links for overheads for a specific admin repair tool * * @since 2.6.0 bbPress (r5885) * * @param array $args * @return array */ function bbp_get_admin_repair_tool_overhead_filters( $args = array() ) { // Parse args $r = bbp_parse_args( $args, array( 'before' => '', 'link_before' => '
  • ', 'link_after' => '
  • ', 'count_before' => ' (', 'count_after' => ')', 'sep' => ' | ', // Retired, use 'sep' instead 'separator' => false ), 'get_admin_repair_tool_overhead_filters' ); /** * Necessary for backwards compatibility * @see https://bbpress.trac.wordpress.org/ticket/2900 */ if ( ! empty( $r['separator'] ) ) { $r['sep'] = $r['separator']; } // Count the tools $tools = bbp_get_admin_repair_tools( bbp_get_admin_repair_tool_page_id() ); // Get the tools URL $tools_url = bbp_get_admin_repair_tool_page_url(); // Define arrays $overheads = $links = array(); // Loop through tools and count overheads if ( count( $tools ) ) { foreach ( $tools as $tool ) { // Get the overhead level $overhead = $tool['overhead']; // Set an empty count if ( empty( $overheads[ $overhead ] ) ) { $overheads[ $overhead ] = 0; } // Bump the overhead count $overheads[ $overhead ]++; } } // Get the current overhead, if any $selected = ! empty( $_GET['overhead'] ) ? sanitize_key( $_GET['overhead'] ) : ''; // Create the "All" link $current = empty( $selected ) ? 'current' : ''; $links[] = $r['link_before'] . '' . sprintf( esc_html__( 'All %s', 'bbpress' ), $r['count_before'] . count( $tools ) . $r['count_after'] ) . '' . $r['link_after']; // Loop through overheads and created links if ( count( $overheads ) ) { // Sort ksort( $overheads ); // Loop through overheads and build filter foreach ( $overheads as $overhead => $count ) { // Build the filter URL $key = sanitize_key( $overhead ); $args = array( 'overhead' => $key ); $filter_url = add_query_arg( $args, $tools_url ); // Figure out separator and active class $current = ( $selected === $key ) ? 'current' : ''; // Counts to show if ( ! empty( $count ) ) { $overhead_count = $r['count_before'] . $count . $r['count_after']; } // Build the link $links[] = $r['link_before'] . '' . bbp_admin_repair_tool_translate_overhead( $overhead ) . $overhead_count . '' . $r['link_after']; } } // Surround output with before & after strings $output = $r['before'] . implode( $r['sep'], $links ) . $r['after']; // Filter & return return apply_filters( 'bbp_get_admin_repair_tool_overhead_filters', $output, $r, $args ); } /** Pending ******************************************************************/ /** * Output filter links for statuses * * @since 2.6.0 bbPress (r6925) * * @param array $args */ function bbp_admin_repair_tool_status_filters( $args = array() ) { echo bbp_get_admin_repair_tool_status_filters( $args ); } /** * Get filter links for statuses * * @since 2.6.0 bbPress (r5885) * * @param array $args * @return array */ function bbp_get_admin_repair_tool_status_filters( $args = array() ) { // Parse args $r = bbp_parse_args( $args, array( 'before' => '', 'link_before' => '
  • ', 'link_after' => '
  • ', 'count_before' => ' (', 'count_after' => ')', 'sep' => ' | ', // Retired, use 'sep' instead 'separator' => false ), 'get_admin_repair_tool_status_filters' ); /** * Necessary for backwards compatibility * @see https://bbpress.trac.wordpress.org/ticket/2900 */ if ( ! empty( $r['separator'] ) ) { $r['sep'] = $r['separator']; } // Get the type of tool $type = bbp_get_admin_repair_tool_page_id(); // Count the tools $tools = bbp_get_admin_repair_tools( $type ); // Get the tools URL $tools_url = bbp_get_admin_repair_tool_page_url(); // Get pending upgrades $pending = bbp_get_pending_upgrades( $type ); // Get the current status, if any $selected = ! empty( $_GET['status'] ) ? sanitize_key( $_GET['status'] ) : ''; // Nothing is current? $all_current = empty( $selected ) ? 'current' : ''; // Pending is current? $pending_current = ( 'pending' === $selected ) ? 'current' : ''; // Sort ksort( $pending ); // Build the filter URL $filter_url = add_query_arg( array( 'status' => 'pending' ), $tools_url ); // Count HTML $all_count = $r['count_before'] . count( $tools ) . $r['count_after']; $pending_count = $r['count_before'] . count( $pending ) . $r['count_after']; // Define links $links = array( $r['link_before'] . '' . sprintf( esc_html__( 'All %s', 'bbpress' ), $all_count ) . '' . $r['link_after'], $r['link_before'] . '' . sprintf( esc_html__( 'Pending %s', 'bbpress' ), $pending_count ) . '' . $r['link_after'] ); // Surround output with before & after strings $output = $r['before'] . implode( $r['sep'], $links ) . $r['after']; // Filter & return return apply_filters( 'bbp_get_admin_repair_tool_status_filters', $output, $r, $args ); }