Skip to:
Content

bbPress.org

Changeset 6788


Ignore:
Timestamp:
03/27/2018 05:11:57 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Converter: add filter to bbp_new_converter().

This change makes it possible to include a custom converter class for the platform being converted from, especially useful if you've changed password storage schemas or want to handle data migration in a way that is specific to your needs.

See #3191.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools/converter.php

    r6785 r6788  
    6363 *
    6464 * @param string $platform Name of valid platform class.
     65 *
     66 * @return mixed Object if converter exists, null if not
    6567 */
    6668function bbp_new_converter( $platform = '' ) {
    6769
     70    // Default converter
     71    $converter = null;
     72
    6873    // Bail if no platform
    69     if ( ! empty( $platform ) ) {
     74    if ( empty( $platform ) ) {
     75        return $converter;
     76    }
    7077
    71         // Get the available converters
    72         $converters = bbp_get_converters();
     78    // Get the available converters
     79    $converters = bbp_get_converters();
    7380
    74         // Create a new converter object if it's found
    75         if ( isset( $converters[ $platform ] ) ) {
     81    // Get the converter file form converters array
     82    $converter_file = isset( $converters[ $platform ] )
     83        ? $converters[ $platform ]
     84        : '';
    7685
    77             // Include & create the converter
    78             require_once $converters[ $platform ];
    79             if ( class_exists( $platform ) ) {
    80                 return new $platform;
    81             }
     86    // Try to create a new converter object
     87    if ( ! empty( $converter_file ) ) {
     88
     89        // Try to include the converter
     90        @include_once $converter_file;
     91
     92        // Try to instantiate the converter object
     93        if ( class_exists( $platform ) ) {
     94            $converter = new $platform;
    8295        }
    8396    }
    8497
    85     // Return null if no converter was found
    86     return null;
     98    // Filter & return
     99    return apply_filters( 'bbp_new_converter', $converter, $platform );
    87100}
Note: See TracChangeset for help on using the changeset viewer.