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' => '