# bbpress/2.6.19/includes/admin/tools/converter.php

bbPress, version 2.6.19. 118 lines.

- Page: https://pluginprobe.com/plugins/bbpress/2.6.19/code/includes/admin/tools/converter.php
- Raw: https://pluginprobe.com/plugins/bbpress/2.6.19/raw/includes/admin/tools/converter.php
- Modified: 2026-09-29T23:39:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/bbpress/2.6.19/code/includes/admin/tools/converter.php#L10-L20`.

```php
<?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 (r6448)
 *
 * @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 );
}

/**
 * Check a source database table prefix before using it in converter queries.
 *
 * @since 2.6.19 bbPress (r7737)
 *
 * @param mixed $prefix Source database table prefix.
 * @return bool Whether the prefix contains only valid table-prefix characters.
 */
function bbp_is_valid_converter_prefix( $prefix ) {
	return is_string( $prefix ) && ( 0 === preg_match( '|[^a-z0-9_]|i', $prefix ) );
}

/**
 * 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.1.0 bbPress (r3816)
 *
 * @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;
	}

	// Never build source-table queries with an invalid saved prefix.
	if ( ! bbp_is_valid_converter_prefix( get_option( '_bbp_converter_db_prefix', '' ) ) ) {
		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 );
}

```
