first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

View File

@@ -0,0 +1,933 @@
<?php
/**
* bbPress Admin Tools Common
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Return the current admin repair tool page
*
* @since 2.6.0 bbPress (r6894)
*
* @return string
*/
function bbp_get_admin_repair_tool_page() {
return sanitize_key( $_GET['page'] );
}
/**
* Return the current admin repair tool page ID
*
* @since 2.6.0 bbPress (r6894)
*
* @return string
*/
function bbp_get_admin_repair_tool_page_id() {
// Get the page
$page = bbp_get_admin_repair_tool_page();
// Maybe trim prefix off of page
if ( ! empty( $page ) && ( 0 === strpos( $page, 'bbp-' ) ) ) {
$page = str_replace( 'bbp-', '', $page );
} else {
$page = '';
}
return $page;
}
/**
* Return a URL to the repair tool page
*
* @since 2.6.0 bbPress (r6894)
*
* @param array $args
*
* @return string
*/
function bbp_get_admin_repair_tool_page_url( $args = array() ) {
// Parse arguments
$r = wp_parse_args( $args, array(
'page' => 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() {
?>
<p class="search-box">
<label class="screen-reader-text" for="bbp-repair-search-input"><?php esc_html_e( 'Search Tools:', 'bbpress' ); ?></label>
<input type="search" id="bbp-repair-search-input" name="s" value="<?php _admin_search_query(); ?>">
<input type="submit" id="search-submit" class="button" value="<?php esc_html_e( 'Search Tools', 'bbpress' ); ?>">
</p>
<?php
}
/**
* Output a select drop-down of components to filter by
*
* @since 2.5.0 bbPress (r5885)
*/
function bbp_admin_repair_list_components_filter() {
// Sanitize component value, if exists
$selected = ! empty( $_GET['components'] )
? sanitize_key( $_GET['components'] )
: '';
// Get registered components
$components = bbp_get_admin_repair_tool_registered_components();
// Bail if no components
if ( empty( $components ) ) {
return;
} ?>
<label class="screen-reader-text" for="components"><?php esc_html_e( 'Filter by Component', 'bbpress' ); ?></label>
<select name="components" id="components" class="postform">
<option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Components', 'bbpress' ); ?></option>
<?php foreach ( $components as $component ) : ?>
<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>
<?php endforeach; ?>
</select>
<?php
}
/**
* Return array of versions from the array of registered tools
*
* @since 2.6.0 bbPress (r6894)
*
* @return array
*/
function bbp_get_admin_repair_tool_registered_versions() {
// 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, 'version' );
// Loop through components
if ( count( $plucked ) ) {
foreach ( $plucked as $versions ) {
// Skip if empty
if ( empty( $versions ) ) {
continue;
// Cast to array if string
} elseif ( is_string( $versions ) ) {
$versions = (array) $versions;
}
// Loop through versions
foreach ( $versions as $version ) {
// Skip if already in array
if ( in_array( $version, $retval, true ) ) {
continue;
}
// Add component to the array
$retval[] = $version;
}
}
}
}
// Filter & return
return (array) apply_filters( 'bbp_get_admin_repair_tool_registered_versions', $retval );
}
/**
* Output a select drop-down of versions to filter by
*
* @since 2.5.0 bbPress (r6894)
*/
function bbp_admin_repair_list_versions_filter() {
// Sanitize component value, if exists
$selected = ! empty( $_GET['version'] )
? sanitize_text_field( $_GET['version'] )
: '';
// Get registered components
$versions = bbp_get_admin_repair_tool_registered_versions();
// Bail if no components
if ( empty( $versions ) ) {
return;
} ?>
<label class="screen-reader-text" for="version"><?php esc_html_e( 'Filter by Version', 'bbpress' ); ?></label>
<select name="version" id="version" class="postform">
<option value="" <?php selected( $selected, false ); ?>><?php esc_html_e( 'All Versions', 'bbpress' ); ?></option>
<?php foreach ( $versions as $version ) : ?>
<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>
<?php endforeach; ?>
</select>
<?php
}
/** Translations **************************************************************/
/**
* Maybe translate a repair tool overhead name
*
* @since 2.6.0 bbPress (r6177)
*
* @param string $overhead
* @return string
*/
function bbp_admin_repair_tool_translate_overhead( $overhead = '' ) {
// Get the name of the component
switch ( $overhead ) {
case 'low' :
$name = esc_html__( 'Low', 'bbpress' );
break;
case 'medium' :
$name = esc_html__( 'Medium', 'bbpress' );
break;
case 'high' :
$name = esc_html__( 'High', 'bbpress' );
break;
default :
$name = ucwords( $overhead );
break;
}
return $name;
}
/**
* Maybe translate a repair tool component name
*
* @since 2.6.0 bbPress (r5885)
*
* @param string $component
* @return string
*/
function bbp_admin_repair_tool_translate_component( $component = '' ) {
// Get the name of the component
switch ( $component ) {
case 'bbp_user' :
$name = esc_html__( 'Users', 'bbpress' );
break;
case bbp_get_forum_post_type() :
$name = esc_html__( 'Forums', 'bbpress' );
break;
case bbp_get_topic_post_type() :
$name = esc_html__( 'Topics', 'bbpress' );
break;
case bbp_get_reply_post_type() :
$name = esc_html__( 'Replies', 'bbpress' );
break;
case bbp_get_topic_tag_tax_id() :
$name = esc_html__( 'Topic Tags', 'bbpress' );
break;
case bbp_get_user_rewrite_id() :
$name = esc_html__( 'Users', 'bbpress' );
break;
case bbp_get_user_favorites_rewrite_id() :
$name = esc_html__( 'Favorites', 'bbpress' );
break;
case bbp_get_user_subscriptions_rewrite_id() :
$name = esc_html__( 'Subscriptions', 'bbpress' );
break;
case bbp_get_user_engagements_rewrite_id() :
$name = esc_html__( 'Engagements', 'bbpress' );
break;
default :
$name = ucwords( $component );
break;
}
return $name;
}
/**
* Maybe translate a repair tool overhead name
*
* @since 2.6.0 bbPress (r6894)
*
* @param string $version
* @return string
*/
function bbp_admin_repair_tool_translate_version( $version = '' ) {
// Get the version
switch ( $version ) {
case '2.5' :
case '2.5.0' :
$name = esc_html__( '2.5.0', 'bbpress' );
break;
case '2.6' :
case '2.6.0' :
$name = esc_html__( '2.6.0', 'bbpress' );
break;
default :
$name = sanitize_text_field( $version );
break;
}
return $name;
}
/** Lists *********************************************************************/
/**
* Get the array of the repairs to show in a list table.
*
* Uses known filters to reduce the registered results down to the most finite
* set of tools.
*
* @since 2.0.0 bbPress (r2613)
*
* @return array Repair list of options
*/
function bbp_admin_repair_list( $type = 'repair' ) {
// Define empty array
$repair_list = array();
// Get the available tools
$list = bbp_get_admin_repair_tools( $type );
// Get pending upgrades
$pending = bbp_get_pending_upgrades();
// Search
$search = ! empty( $_GET['s'] )
? stripslashes( $_GET['s'] )
: '';
// Status
$status = ! empty( $_GET['status'] )
? sanitize_key( $_GET['status'] )
: '';
// Overhead
$overhead = ! empty( $_GET['overhead'] )
? sanitize_key( $_GET['overhead'] )
: '';
// Component
$component = ! empty( $_GET['components'] )
? sanitize_key( $_GET['components'] )
: '';
// Version
$version = ! empty( $_GET['version'] )
? sanitize_text_field( $_GET['version'] )
: '';
// Orderby
$orderby = ! empty( $_GET['orderby'] )
? sanitize_key( $_GET['orderby'] )
: 'priority';
// Order
$order = ! empty( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), array( 'asc', 'desc' ), true )
? strtolower( $_GET['order'] )
: 'asc';
// Overhead filter
if ( ! empty( $overhead ) ) {
$list = wp_list_filter( $list, array( 'overhead' => $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[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
}
// No components, so return a dash
} else {
$links[] = '&mdash;';
}
// 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[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
}
// No versions, so return a dash
} else {
$links[] = '&mdash;';
}
// 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[] = '<a href="' . esc_url( $filter_url ) . '">' . esc_html( $name ) . '</a>';
}
// No overhead, so return a single dash
} else {
$links[] = '&mdash;';
}
// 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' => '<ul class="subsubsub">',
'after' => '</ul>',
'link_before' => '<li>',
'link_after' => '</li>',
'count_before' => ' <span class="count">(',
'count_after' => ')</span>',
'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'] . '<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'];
// 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'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $current ) . '">' . bbp_admin_repair_tool_translate_overhead( $overhead ) . $overhead_count . '</a>' . $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' => '<ul class="subsubsub">',
'after' => '</ul>',
'link_before' => '<li>',
'link_after' => '</li>',
'count_before' => ' <span class="count">(',
'count_after' => ')</span>',
'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'] . '<a href="' . esc_url( $tools_url ) . '" class="' . esc_attr( $all_current ) . '">' . sprintf( esc_html__( 'All %s', 'bbpress' ), $all_count ) . '</a>' . $r['link_after'],
$r['link_before'] . '<a href="' . esc_url( $filter_url ) . '" class="' . esc_attr( $pending_current ) . '">' . sprintf( esc_html__( 'Pending %s', 'bbpress' ), $pending_count ) . '</a>' . $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 );
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* bbPress Converter
*
* Based on the hard work of Adam Ellis
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Return an array of available converters
*
* @since 2.6.0 bbPress (r6447)
*
* @return array
*/
function bbp_get_converters() {
static $files = array();
// Only hit the file system one time per page load
if ( empty( $files ) ) {
// Open the converter directory
$path = bbp_setup_converter()->converters_dir;
$curdir = opendir( $path );
// Look for the converter file in the converters directory
if ( false !== $curdir ) {
while ( $file = readdir( $curdir ) ) {
if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) {
$name = preg_replace( '/.php/', '', $file );
if ( 'Example' !== $name ) {
$files[ $name ] = $path . $file;
}
}
}
}
// Close the directory
closedir( $curdir );
// Sort keys alphabetically, ignoring upper/lower casing
if ( ! empty( $files ) ) {
natcasesort( $files );
}
}
// Filter & return
return (array) apply_filters( 'bbp_get_converters', $files );
}
/**
* This is a function that is purposely written to look like a "new" statement.
* It is basically a dynamic loader that will load in the platform conversion
* of your choice.
*
* @since 2.0.0
*
* @param string $platform Name of valid platform class.
*
* @return mixed Object if converter exists, null if not
*/
function bbp_new_converter( $platform = '' ) {
// Default converter
$converter = null;
// Bail if no platform
if ( empty( $platform ) ) {
return $converter;
}
// Get the available converters
$converters = bbp_get_converters();
// Get the converter file form converters array
$converter_file = isset( $converters[ $platform ] )
? $converters[ $platform ]
: '';
// Try to create a new converter object
if ( ! empty( $converter_file ) ) {
// Try to include the converter
@include_once $converter_file;
// Try to instantiate the converter object
if ( class_exists( $platform ) ) {
$converter = new $platform();
}
}
// Filter & return
return apply_filters( 'bbp_new_converter', $converter, $platform );
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* bbPress Admin Tools Help
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Contextual help for Repair Forums tools page
*
* @since 2.6.0 bbPress (r5314)
*/
function bbp_admin_tools_repair_help() {
$current_screen = get_current_screen();
// Bail if current screen could not be found
if ( empty( $current_screen ) ) {
return;
}
// Repair Forums
$current_screen->add_help_tab( array(
'id' => 'repair_forums',
'title' => __( 'Repair Forums', 'bbpress' ),
'content' => '<p>' . __( 'There is more detailed information available on the bbPress and BuddyPress codex for the following:', 'bbpress' ) . '</p>' .
'<p>' .
'<ul>' .
'<li>' . __( 'BuddyPress Group Forums: <a href="https://codex.buddypress.org/getting-started/installing-group-and-sitewide-forums/">Installing Group and Sitewide Forums</a> and <a href="https://codex.buddypress.org/getting-started/guides/migrating-from-old-forums-to-bbpress-2/">Migrating from old forums to bbPress 2.2+</a>.', 'bbpress' ) . '</li>' .
'<li>' . __( 'bbPress roles: <a href="https://codex.bbpress.org/bbpress-user-roles-and-capabilities/" target="_blank">bbPress User Roles and Capabilities</a>', 'bbpress' ) . '</li>' .
'</ul>' .
'</p>' .
'<p>' . __( 'Also see <a href="https://codex.bbpress.org/repair-forums/">bbPress: Repair Forums</a>.', 'bbpress' ) . '</p>'
) );
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}
/**
* Contextual help for Reset Forums tools page
*
* @since 2.6.0 bbPress (r5314)
*/
function bbp_admin_tools_reset_help() {
$current_screen = get_current_screen();
// Bail if current screen could not be found
if ( empty( $current_screen ) ) {
return;
}
// Reset Forums
$current_screen->add_help_tab( array(
'id' => 'reset_forums',
'title' => __( 'Reset Forums', 'bbpress' ),
'content' => '<p>' . __( 'Also see <a href="https://codex.bbpress.org/reset-forums/">bbPress: Reset Forums</a>.', 'bbpress' ) . '</p>'
) );
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}
/**
* Contextual help for Import Forums tools page
*
* @since 2.6.0 bbPress (r5314)
*/
function bbp_admin_tools_converter_help() {
$current_screen = get_current_screen();
// Bail if current screen could not be found
if ( empty( $current_screen ) ) {
return;
}
// Overview
$current_screen->add_help_tab( array(
'id' => 'overview',
'title' => __( 'Overview', 'bbpress' ),
'content' => '<p>' . __( 'This screen provides access to all of the bbPress Import Forums settings and resources.', 'bbpress' ) . '</p>' .
'<p>' . __( 'Please see the additional help tabs for more information on each individual section.', 'bbpress' ) . '</p>' .
'<p>' . __( 'Also see the main article on the bbPress codex <a href="https://codex.bbpress.org/import-forums/">bbPress: Import Forums</a>.', 'bbpress' ) . '</p>'
) );
// Database Settings
$current_screen->add_help_tab( array(
'id' => 'database_settings',
'title' => __( 'Database Settings', 'bbpress' ),
'content' => '<p>' . __( 'In the Database Settings you have a number of options:', 'bbpress' ) . '</p>' .
'<p>' .
'<ul>' .
'<li>' . __( 'The settings in this section refer to the database connection strings used by your old forum software. The best way to determine the exact settings you need is to copy them from your legacy forums configuration file or contact your web hosting provider.', 'bbpress' ) . '</li>' .
'</ul>' .
'</p>'
) );
// Importer Options
$current_screen->add_help_tab( array(
'id' => 'importer_options',
'title' => __( 'Importer Options', 'bbpress' ),
'content' => '<p>' . __( 'In the Options you have a number of options:', 'bbpress' ) . '</p>' .
'<p>' .
'<ul>' .
'<li>' . __( 'Depending on your MySQL configuration you can tweak the "Rows Limit" and "Delay Time" that may help to improve the overall time it takes to perform a complete forum import.', 'bbpress' ) . '</li>' .
'<li>' . __( '"Convert Users" will import your legacy forum members as WordPress Users.', 'bbpress' ) . '</li>' .
'<li>' . __( '"Start Over" will start the importer fresh, if your import failed for any reason leaving this setting unchecked the importer will begin from where it left off.', 'bbpress' ) . '</li>' .
'<li>' . __( '"Purge Previous Import" will remove data imported from a failed import without removing your existing forum data.', 'bbpress' ) . '</li>' .
'</ul>' .
'</p>'
) );
// Help Sidebar
$current_screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
'<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
'<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,272 @@
<?php
/**
* bbPress Admin Tools Reset
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Admin reset page
*
* @since 2.0.0 bbPress (r2613)
*
*/
function bbp_admin_reset_page() {
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
<hr class="wp-header-end">
<h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-reset' ); ?></h2>
<p><?php esc_html_e( 'Revert your forums back to a brand new installation, as if bbPress were never installed. This process cannot be undone.', 'bbpress' ); ?></p>
<form class="settings" method="post" action="">
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'The following data will be removed:', 'bbpress' ) ?></th>
<td>
<?php esc_html_e( 'All Forums', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Topics', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Replies', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Topic Tags', 'bbpress' ); ?><br />
<?php esc_html_e( 'All Meta Data', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum Settings', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum Activity', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum User Roles', 'bbpress' ); ?><br />
<?php esc_html_e( 'Forum Moderators', 'bbpress' ); ?><br />
<?php esc_html_e( 'Importer Helper Data', 'bbpress' ); ?><br />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Delete imported users?', 'bbpress' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e( "Say it ain't so!", 'bbpress' ); ?></span></legend>
<label><input type="checkbox" class="checkbox" name="bbpress-delete-imported-users" id="bbpress-delete-imported-users" value="1" /> <?php esc_html_e( 'This option will delete all previously imported users, and cannot be undone.', 'bbpress' ); ?></label>
<p class="description"><?php esc_html_e( 'Proceeding without this checked removes the meta-data necessary to delete these users later.', 'bbpress' ); ?></p>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e( 'Do you really want to do this?', 'bbpress' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php esc_html_e( "Say it ain't so!", 'bbpress' ); ?></span></legend>
<label><input type="checkbox" class="checkbox" name="bbpress-are-you-sure" id="bbpress-are-you-sure" value="1" /> <?php esc_html_e( 'This process cannot be undone.', 'bbpress' ); ?></label>
<p class="description"><?php esc_html_e( 'Backup your database before proceeding.', 'bbpress' ); ?></p>
</fieldset>
</td>
</tr>
</tbody>
</table>
<fieldset class="submit">
<input class="button-primary" type="submit" name="submit" value="<?php esc_attr_e( 'Reset bbPress', 'bbpress' ); ?>" />
<?php wp_nonce_field( 'bbpress-reset' ); ?>
</fieldset>
</form>
</div>
<?php
}
/**
* Handle a bbPress admin area reset request.
*
* @since 2.0.0 bbPress (r2613)
*/
function bbp_admin_reset_handler() {
// Bail if not resetting.
if ( ! bbp_is_post_request() || empty( $_POST['bbpress-are-you-sure'] ) ) {
return;
}
// Only keymasters can proceed.
if ( ! bbp_is_user_keymaster() ) {
return;
}
// Bail if not referred from resetter
check_admin_referer( 'bbpress-reset' );
// Reset all of bbPress
bbp_admin_reset_database();
}
/**
* Wrapper for determining admin reset query feedback presented to a user.
*
* @since 2.6.0 bbPress (r6758)
*
* @param array $args Array of query, message, and possible responses
*
* @return string
*/
function bbp_admin_reset_query_feedback( $args = array() ) {
static $defaults = null;
// Only set defaults one time to avoid hitting the GetText API repeatedly
if ( null === $defaults ) {
$defaults = array(
'query' => '',
'message' => esc_html__( 'Resetting&hellip;', 'bbpress' ),
'responses' => array(
'success' => esc_html__( 'Success!', 'bbpress' ),
'failure' => esc_html__( 'Failed!', 'bbpress' ),
'skipped' => esc_html__( 'Skipped.', 'bbpress' )
)
);
}
// Parse arguments
$r = bbp_parse_args( $args, $defaults, 'admin_reset_query_feedback' );
// Success/Failure based on query error
if ( ! empty( $r['query'] ) ) {
$query = bbp_db()->query( $r['query'] );
$result = ! is_wp_error( $query )
? $r['responses']['success']
: $r['responses']['failure'];
// Skip if empty
} else {
$result = $r['responses']['skipped'];
}
// Return feedback
return sprintf( $r['message'], $result );
}
/**
* Perform a bbPress database reset.
*
* @since 2.6.0 bbPress
*/
function bbp_admin_reset_database() {
// Define variables.
$messages = array();
$sql_meta = array();
$bbp_db = bbp_db();
// Flush the whole cache; things are about to get ugly.
wp_cache_flush();
/** Posts *****************************************************************/
// Post types and status.
$fpt = bbp_get_forum_post_type();
$tpt = bbp_get_topic_post_type();
$rpt = bbp_get_reply_post_type();
// Get post IDs
$sql_posts = $bbp_db->get_results( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K );
if ( ! empty( $sql_posts ) ) {
// Meta data
foreach ( $sql_posts as $key => $value ) {
$sql_meta[] = $key;
}
$sql_meta = implode( "', '", $sql_meta );
// Delete posts
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')",
'message' => esc_html__( 'Removing Forums, Topics, and Replies&hellip; %s', 'bbpress' )
) );
/** Post Meta *********************************************************/
if ( ! empty( $sql_posts ) ) {
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}')",
'message' => esc_html__( 'Removing Forum, Topic, and Reply Meta Data&hellip; %s', 'bbpress' )
) );
}
/** Post Revisions ****************************************************/
if ( ! empty( $sql_posts ) ) {
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->posts}` WHERE `post_parent` IN ('{$sql_meta}') AND `post_type` = 'revision'",
'message' => esc_html__( 'Removing Revision Data&hellip; %s', 'bbpress' )
) );
}
}
/** Topic Tags ************************************************************/
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag'",
'message' => esc_html__( 'Deleting Topic Tags&hellip; %s', 'bbpress' )
) );
/** User ******************************************************************/
// First, if we're deleting previously imported users, delete them now
if ( ! empty( $_POST['bbpress-delete-imported-users'] ) ) {
$sql_users = $bbp_db->get_results( "SELECT `user_id` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '_bbp_old_user_id'", OBJECT_K );
if ( ! empty( $sql_users ) ) {
$sql_meta = array();
foreach ( $sql_users as $key => $value ) {
$sql_meta[] = $key;
}
// Users
$sql_meta = implode( "', '", $sql_meta );
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}')",
'message' => esc_html__( 'Deleting Imported Users&hellip; %s', 'bbpress' )
) );
// User meta
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}')",
'message' => esc_html__( 'Deleting Imported User Meta&hellip; %s', 'bbpress' )
) );
}
}
// Next, if we still have users that were not imported delete that meta data
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%'",
'message' => esc_html__( 'Deleting bbPress Specific User Meta&hellip; %s', 'bbpress' )
) );
/** Converter *************************************************************/
$table_name = $bbp_db->prefix . 'bbp_converter_translator';
if ( $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) {
$messages[] = bbp_admin_reset_query_feedback( array(
'query' => "DROP TABLE {$table_name}",
'message' => esc_html__( 'Dropping Conversion Table&hellip; %s', 'bbpress' )
) );
}
/** Options ***************************************************************/
bbp_delete_options();
$messages[] = esc_html__( 'Deleting Settings&hellip; Success!', 'bbpress' );
/** Roles *****************************************************************/
bbp_remove_roles();
bbp_remove_caps();
$messages[] = esc_html__( 'Removing Roles and Capabilities&hellip; Success!', 'bbpress' );
/** Output ****************************************************************/
if ( count( $messages ) ) {
foreach ( $messages as $message ) {
bbp_admin_tools_feedback( $message );
}
}
}

View File

@@ -0,0 +1,678 @@
<?php
/**
* bbPress Admin Upgrade Functions
*
* @package bbPress
* @subpackage Administration
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Admin repair page
*
* @since 2.6.0 bbPress (r6278)
*
*/
function bbp_admin_upgrade_page() {
// Get the registered upgrade tools
$tools = bbp_admin_repair_list( 'upgrade' );
// Orderby
$orderby = ! empty( $_GET['orderby'] )
? sanitize_key( $_GET['orderby'] )
: 'priority';
// Order
$order = ! empty( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), array( 'asc', 'desc' ), true )
? strtolower( $_GET['order'] )
: 'asc';
// New order
$new_order = ( 'desc' === $order )
? 'asc'
: 'desc'; ?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
<hr class="wp-header-end">
<h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( 'bbp-upgrade' ); ?></h2>
<p><?php esc_html_e( 'As bbPress improves, occasionally database upgrades are required but some forums are too large to upgrade automatically. Use the tools below to manually run upgrade routines.', 'bbpress' ); ?></p>
<p class="description"><?php esc_html_e( 'Some of these tools create substantial database overhead. Use caution when running more than 1 upgrade at a time.', 'bbpress' ); ?></p>
<?php bbp_admin_repair_tool_status_filters(); ?>
<form class="settings" method="get" action="">
<?php bbp_admin_repair_list_search_form(); ?>
<input type="hidden" name="page" value="bbp-upgrade" />
<?php wp_nonce_field( 'bbpress-do-counts' ); ?>
<div class="tablenav top">
<div class="alignleft actions bulkactions">
<label for="bulk-action-selector-top" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'bbpress' ); ?></label>
<select name="action" id="bulk-action-selector-top">
<option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'bbpress' ); ?></option>
<option value="run" class="hide-if-no-js"><?php esc_html_e( 'Run', 'bbpress' ); ?></option>
</select>
<input type="submit" id="doaction" class="button action" value="<?php esc_attr_e( 'Apply', 'bbpress' ); ?>">
</div>
<div class="alignleft actions">
<?php bbp_admin_repair_list_components_filter(); ?>
<?php bbp_admin_repair_list_versions_filter(); ?>
<input type="submit" name="filter_action" id="components-submit" class="button" value="<?php esc_html_e( 'Filter', 'bbpress' ); ?>">
</div>
<br class="clear">
</div>
<table class="wp-list-table widefat striped posts">
<thead>
<tr>
<td id="cb" class="manage-column column-cb check-column">
<label class="screen-reader-text" for="cb-select-all-1">
<?php esc_html_e( 'Select All', 'bbpress' ); ?>
</label>
<input id="cb-select-all-1" type="checkbox">
</td>
<th scope="col" id="description" class="manage-column column-primary column-description sortable <?php echo ( 'priority' === $orderby ) ? esc_attr( $order ) : 'asc'; ?>">
<a href="<?php echo esc_url( bbp_get_admin_repair_tool_page_url( array(
'orderby' => 'priority',
'order' => $new_order
) ) ); ?>"><span><?php esc_html_e( 'Description', 'bbpress' ); ?></span><span class="sorting-indicator"></span>
</a>
</th>
<th scope="col" id="version" class="manage-column column-version sortable <?php echo ( 'version' === $orderby ) ? esc_attr( $order ) : 'asc'; ?>">
<a href="<?php echo esc_url( bbp_get_admin_repair_tool_page_url( array(
'orderby' => 'version',
'order' => $new_order
) ) ); ?>"><span><?php esc_html_e( 'Version', 'bbpress' ); ?></span><span class="sorting-indicator"></span>
</a>
</th>
<th scope="col" id="components" class="manage-column column-components"><?php esc_html_e( 'Components', 'bbpress' ); ?></th>
<th scope="col" id="overhead" class="manage-column column-overhead sortable <?php echo ( 'overhead' === $orderby ) ? esc_attr( $order ) : 'asc'; ?>">
<a href="<?php echo esc_url( bbp_get_admin_repair_tool_page_url( array(
'orderby' => 'overhead',
'order' => $new_order
) ) ); ?>"><span><?php esc_html_e( 'Overhead', 'bbpress' ); ?></span><span class="sorting-indicator"></span>
</a>
</th>
</tr>
</thead>
<tbody id="the-list">
<?php if ( ! empty( $tools ) ) : ?>
<?php foreach ( $tools as $item ) : ?>
<tr id="bbp-repair-tools" class="inactive">
<th scope="row" class="check-column">
<label class="screen-reader-text" for="<?php echo esc_attr( str_replace( '_', '-', $item['id'] ) ); ?>"></label>
<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $item['id'] ); ?>" id="<?php echo esc_attr( str_replace( '_', '-', $item['id'] ) ); ?>">
</th>
<td class="bbp-tool-title column-primary column-description" data-colname="<?php esc_html_e( 'Description', 'bbpress' ); ?>">
<strong><?php echo esc_html( $item['title'] ); ?></strong><?php
// Optional description
if ( ! empty( $item['description'] ) ) :
echo '<p class="description">' . esc_html( $item['description'] ) . '</p>';
endif;
?><div class="row-actions hide-if-no-js">
<span class="run">
<a href="<?php bbp_admin_repair_tool_run_url( $item ); ?>" aria-label="<?php printf( esc_html__( 'Run %s', 'bbpress' ), $item['title'] ); ?>" id="<?php echo esc_attr( $item['id'] ); ?>" ><?php esc_html_e( 'Run', 'bbpress' ); ?></a>
</span>
</div>
<button type="button" class="toggle-row">
<span class="screen-reader-text"><?php esc_html_e( 'Show more details', 'bbpress' ); ?></span>
</button>
</td>
<td class="column-version desc" data-colname="<?php esc_html_e( 'Version', 'bbpress' ); ?>">
<div class="bbp-tool-version">
<?php echo implode( ', ', bbp_get_admin_repair_tool_version( $item ) ); ?>
</div>
</td>
<td class="column-components desc" data-colname="<?php esc_html_e( 'Components', 'bbpress' ); ?>">
<div class="bbp-tool-components">
<?php echo implode( ', ', bbp_get_admin_repair_tool_components( $item ) ); ?>
</div>
</td>
<td class="column-overhead desc" data-colname="<?php esc_html_e( 'Overhead', 'bbpress' ); ?>">
<div class="bbp-tool-overhead">
<?php echo implode( ', ', bbp_get_admin_repair_tool_overhead( $item ) ); ?>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="4">
<?php esc_html_e( 'No repair tools match this criteria.', 'bbpress' ); ?>
</td>
</tr>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<td class="manage-column column-cb check-column">
<label class="screen-reader-text" for="cb-select-all-2">
<?php esc_html_e( 'Select All', 'bbpress' ); ?>
</label>
<input id="cb-select-all-2" type="checkbox">
</td>
<th scope="col" class="manage-column column-primary column-description"><?php esc_html_e( 'Description', 'bbpress' ); ?></th>
<th scope="col" class="manage-column column-version"><?php esc_html_e( 'Version', 'bbpress' ); ?></th>
<th scope="col" class="manage-column column-components"><?php esc_html_e( 'Components', 'bbpress' ); ?></th>
<th scope="col" class="manage-column column-overhead"><?php esc_html_e( 'Overhead', 'bbpress' ); ?></th>
</tr>
</tfoot>
</table>
<div class="tablenav bottom">
<div class="alignleft actions bulkactions">
<label for="bulk-action-selector-bottom" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'bbpress' ); ?></label>
<select name="action2" id="bulk-action-selector-bottom">
<option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'bbpress' ); ?></option>
<option value="run" class="hide-if-no-js"><?php esc_html_e( 'Run', 'bbpress' ); ?></option>
</select>
<input type="submit" id="doaction2" class="button action" value="<?php esc_attr_e( 'Apply', 'bbpress' ); ?>">
</div>
</div>
</form>
</div>
<?php
}
/**
* Upgrade user engagements for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6320)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_engagements() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user engagements&hellip; %s', 'bbpress' );
$result = esc_html__( 'No engagements to upgrade.', 'bbpress' );
// Delete previous engagements
$sql_delete = "DELETE FROM {$bbp_db->postmeta} WHERE meta_key = '_bbp_engagement'";
if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Post types and statuses
$tpt = bbp_get_topic_post_type();
$rpt = bbp_get_reply_post_type();
$pps = bbp_get_public_status_id();
$cps = bbp_get_closed_status_id();
$sql = "INSERT INTO {$bbp_db->postmeta} (post_id, meta_key, meta_value) (
SELECT postmeta.meta_value, '_bbp_engagement', posts.post_author
FROM {$bbp_db->posts} AS posts
LEFT JOIN {$bbp_db->postmeta} AS postmeta
ON posts.ID = postmeta.post_id
AND postmeta.meta_key = '_bbp_topic_id'
WHERE posts.post_type IN (%s, %s)
AND posts.post_status IN (%s, %s)
GROUP BY postmeta.meta_value, posts.post_author)";
// Run the big query
$prepare = $bbp_db->prepare( $sql, $tpt, $rpt, $pps, $cps );
$engagements = $bbp_db->query( $prepare );
// Bail if no closed topics found
if ( empty( $engagements ) || is_wp_error( $engagements ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Complete results
$result = sprintf( _n( 'Complete! %d engagement upgraded.', 'Complete! %d engagements upgraded.', $engagements, 'bbpress' ), bbp_number_format( $engagements ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade group forum ID mappings after a bbPress 1.x to bbPress 2.x conversion
*
* Previously named: bbp_admin_repair_group_forum_relationships()
*
* @since 2.6.0 bbPress (r4395)
*
* @return If a wp_error() occurs and no converted forums are found
*/
function bbp_admin_upgrade_group_forum_relationships() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading BuddyPress group-forum relationships&hellip; %s', 'bbpress' );
$g_count = 0;
$f_count = 0;
$s_count = 0;
// Copy the BuddyPress filter here, incase BuddyPress is not active
$prefix = apply_filters( 'bp_core_get_table_prefix', $bbp_db->base_prefix );
$groups_table = $prefix . 'bp_groups';
$groups_meta_table = $prefix . 'bp_groups_groupmeta';
// Get the converted forum IDs
$forum_ids = $bbp_db->query( "SELECT `forum`.`ID`, `forummeta`.`meta_value`
FROM `{$bbp_db->posts}` AS `forum`
LEFT JOIN `{$bbp_db->postmeta}` AS `forummeta`
ON `forum`.`ID` = `forummeta`.`post_id`
AND `forummeta`.`meta_key` = '_bbp_old_forum_id'
WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "'
GROUP BY `forum`.`ID`" );
// Bail if forum IDs returned an error
if ( is_wp_error( $forum_ids ) || empty( $bbp_db->last_result ) ) {
return array( 2, sprintf( $statement, esc_html__( 'Failed!', 'bbpress' ) ) );
}
// Stash the last results
$results = $bbp_db->last_result;
// Update each group forum
foreach ( $results as $group_forums ) {
// Only update if is a converted forum
if ( empty( $group_forums->meta_value ) ) {
continue;
}
// Attempt to update group meta
$updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}'" );
// Bump the count
if ( ! empty( $updated ) && ! is_wp_error( $updated ) ) {
++$g_count;
}
// Update group to forum relationship data
$group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}'" );
if ( ! empty( $group_id ) ) {
// Update the group to forum meta connection in forums
update_post_meta( $group_forums->ID, '_bbp_group_ids', array( $group_id ) );
// Get the group status
$group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}'" );
// Sync up forum visibility based on group status
switch ( $group_status ) {
// Public groups have public forums
case 'public' :
bbp_publicize_forum( $group_forums->ID );
// Bump the count for output later
++$s_count;
break;
// Private/hidden groups have hidden forums
case 'private' :
case 'hidden' :
bbp_hide_forum( $group_forums->ID );
// Bump the count for output later
++$s_count;
break;
}
// Bump the count for output later
++$f_count;
}
}
// Make some logical guesses at the old group root forum
if ( function_exists( 'bp_forums_parent_forum_id' ) ) {
$old_default_forum_id = bp_forums_parent_forum_id();
} elseif ( defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
$old_default_forum_id = (int) BP_FORUMS_PARENT_FORUM_ID;
} else {
$old_default_forum_id = 1;
}
// Try to get the group root forum
$posts = get_posts( array(
'post_type' => bbp_get_forum_post_type(),
'meta_key' => '_bbp_old_forum_id',
'meta_type' => 'NUMERIC',
'meta_value' => $old_default_forum_id,
'numberposts' => 1
) );
// Found the group root forum
if ( ! empty( $posts ) ) {
// Rename 'Default Forum' since it's now visible in sitewide forums
if ( 'Default Forum' === $posts[0]->post_title ) {
wp_update_post( array(
'ID' => $posts[0]->ID,
'post_title' => esc_html__( 'Group Forums', 'bbpress' ),
'post_name' => esc_html__( 'group-forums', 'bbpress' ),
) );
}
// Update the group forums root metadata
update_option( '_bbp_group_forums_root_id', $posts[0]->ID );
}
// Remove old bbPress 1.1 roles (BuddyPress)
remove_role( 'member' );
remove_role( 'inactive' );
remove_role( 'blocked' );
remove_role( 'moderator' );
remove_role( 'keymaster' );
// Complete results
$result = sprintf( esc_html__( 'Complete! %s groups updated; %s forums updated; %s forum statuses synced.', 'bbpress' ), bbp_number_format( $g_count ), bbp_number_format( $f_count ), bbp_number_format( $s_count ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade user favorites for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6174)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_favorites() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user favorites&hellip; %s', 'bbpress' );
$result = esc_html__( 'No favorites to upgrade.', 'bbpress' );
$total = 0;
$old_key = $bbp_db->prefix . '_bbp_favorites';
$new_key = '_bbp_favorite';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s";
$prepare = $bbp_db->prepare( $query, $old_key );
$favs = $bbp_db->get_results( $prepare );
// Bail if no closed topics found
if ( empty( $favs ) || is_wp_error( $favs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Loop through each user's favorites
foreach ( $favs as $meta ) {
// Get post IDs
$post_ids = explode( ',', $meta->meta_value );
// Add user ID to all favorited posts
foreach ( $post_ids as $post_id ) {
// Skip if already exists
if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $new_key, $meta->user_id ) ) ) {
continue;
}
// Add the post meta
$added = add_post_meta( $post_id, $new_key, $meta->user_id, false );
// Bump counts if successfully added
if ( ! empty( $added ) ) {
++$total;
}
}
}
// Cleanup
unset( $favs, $added, $post_ids );
// Complete results
$result = sprintf( _n( 'Complete! %d favorite upgraded.', 'Complete! %d favorites upgraded.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade user topic subscriptions for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6174)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_topic_subscriptions() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user topic subscriptions&hellip; %s', 'bbpress' );
$result = esc_html__( 'No topic subscriptions to upgrade.', 'bbpress' );
$total = 0;
$old_key = $bbp_db->prefix . '_bbp_subscriptions';
$new_key = '_bbp_subscription';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $old_key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no topic subscriptions found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Loop through each user's topic subscriptions
foreach ( $subs as $meta ) {
// Get post IDs
$post_ids = explode( ',', $meta->meta_value );
// Add user ID to all subscribed topics
foreach ( $post_ids as $post_id ) {
// Skip if already exists
if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $new_key, $meta->user_id ) ) ) {
continue;
}
// Add the post meta
$added = add_post_meta( $post_id, $new_key, $meta->user_id, false );
// Bump counts if successfully added
if ( ! empty( $added ) ) {
++$total;
}
}
}
// Cleanup
unset( $subs, $added, $post_ids );
// Complete results
$result = sprintf( _n( 'Complete! %d topic subscription upgraded.', 'Complete! %d topic subscriptions upgraded.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Upgrade user forum subscriptions for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6193)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_user_forum_subscriptions() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Upgrading user forum subscriptions&hellip; %s', 'bbpress' );
$result = esc_html__( 'No forum subscriptions to upgrade.', 'bbpress' );
$total = 0;
$old_key = $bbp_db->prefix . '_bbp_forum_subscriptions';
$new_key = '_bbp_subscription';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $old_key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no forum subscriptions found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Loop through each user's forum subscriptions
foreach ( $subs as $meta ) {
// Get post IDs
$post_ids = explode( ',', $meta->meta_value );
// Add user ID to all subscribed forums
foreach ( $post_ids as $post_id ) {
// Skip if already exists
if ( $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(*) FROM {$bbp_db->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $new_key, $meta->user_id ) ) ) {
continue;
}
// Add the post meta
$added = add_post_meta( $post_id, $new_key, $meta->user_id, false );
// Bump counts if successfully added
if ( ! empty( $added ) ) {
++$total;
}
}
}
// Cleanup
unset( $subs, $added, $post_ids );
// Complete results
$result = sprintf( _n( 'Complete! %d forum subscription upgraded.', 'Complete! %d forum subscriptions upgraded.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Remove favorites data from user meta for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6281)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_remove_favorites_from_usermeta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Remove favorites from usermeta&hellip; %s', 'bbpress' );
$result = esc_html__( 'No favorites to remove.', 'bbpress' );
$total = 0;
$key = $bbp_db->prefix . '_bbp_favorites';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $key );
$favs = $bbp_db->get_results( $prepare );
// Bail if no favorites found
if ( empty( $favs ) || is_wp_error( $favs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Delete all user-meta with this key
delete_metadata( 'user', false, $key, false, true );
$total = count( $favs );
// Complete results
$result = sprintf( _n( 'Complete! %d favorite deleted.', 'Complete! %d favorites deleted.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Remove topic subscriptions data from user meta for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6281)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_remove_topic_subscriptions_from_usermeta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Remove topic subscriptions from usermeta&hellip; %s', 'bbpress' );
$result = esc_html__( 'No topic subscriptions to remove.', 'bbpress' );
$total = 0;
$key = $bbp_db->prefix . '_bbp_subscriptions';
// Results
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no forum favorites found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Delete all user-meta with this key
delete_metadata( 'user', false, $key, false, true );
$total = count( $subs );
// Complete results
$result = sprintf( _n( 'Complete! %d topic subscription deleted.', 'Complete! %d topic subscriptions deleted.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}
/**
* Remove topic subscriptions data from user meta for bbPress 2.6 and higher
*
* @since 2.6.0 bbPress (r6281)
*
* @return array An array of the status code and the message
*/
function bbp_admin_upgrade_remove_forum_subscriptions_from_usermeta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Remove forum subscriptions from usermeta&hellip; %s', 'bbpress' );
$result = esc_html__( 'No forum subscriptions to remove.', 'bbpress' );
$total = 0;
$key = $bbp_db->prefix . '_bbp_forum_subscriptions';
// Query
$query = "SELECT * FROM {$bbp_db->usermeta} WHERE meta_key = %s ORDER BY user_id";
$prepare = $bbp_db->prepare( $query, $key );
$subs = $bbp_db->get_results( $prepare );
// Bail if no forum favorites found
if ( empty( $subs ) || is_wp_error( $subs ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Delete all user-meta with this key
delete_metadata( 'user', false, $key, false, true );
$total = count( $subs );
// Complete results
$result = sprintf( _n( 'Complete! %d forum subscription deleted.', 'Complete! %d forum subscriptions deleted.', $total, 'bbpress' ), bbp_number_format( $total ) );
return array( 0, sprintf( $statement, $result ) );
}