| 1 |
<?php |
| 2 |
|
| 3 |
use wpforo\wpforo; |
| 4 |
|
| 5 |
spl_autoload_register( function( $namespace ) { |
| 6 |
if( strpos( (string) $namespace, 'wpforo' ) === 0 || strpos( (string) $namespace, 'go2wpforo' ) === 0 ) { |
| 7 |
$filepath = rtrim( |
| 8 |
trim( |
| 9 |
str_replace( |
| 10 |
[ '/', '\\', '\\\\' ], DIRECTORY_SEPARATOR, WP_PLUGIN_DIR . "\\" . $namespace |
| 11 |
) |
| 12 |
), |
| 13 |
DIRECTORY_SEPARATOR |
| 14 |
) . ".php"; |
| 15 |
if( is_file( $filepath ) && is_readable( $filepath ) ) require_once $filepath; |
| 16 |
} |
| 17 |
} ); |
| 18 |
|
| 19 |
/** |
| 20 |
* Main instance of wpForo. |
| 21 |
* |
| 22 |
* Returns the main instance of WPF to prevent the need to use globals. |
| 23 |
* |
| 24 |
* @return wpforo |
| 25 |
* @since 1.4.3 |
| 26 |
*/ |
| 27 |
if( ! function_exists( 'WPF' ) ) { |
| 28 |
function WPF() { |
| 29 |
return wpforo::instance(); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// Global for backwards compatibility. |
| 34 |
$GLOBALS['wpforo'] = WPF(); |
| 35 |
|
| 36 |
// #### deactivate old addons |
| 37 |
function wpforo_deactivate_all_old_addons() { |
| 38 |
$v = get_option( 'wpforo_version', '' ); |
| 39 |
if( WPFORO_VERSION !== $v && version_compare( $v, '2.0.3', '<' ) ){ |
| 40 |
// #### deactivate old addons |
| 41 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 42 |
require_once WPFORO_DIR . '/includes/functions.php'; |
| 43 |
$plugins = []; |
| 44 |
foreach( wpforo_get_addons_info() as $addon ){ |
| 45 |
if( file_exists( $addon['ABSPATH'] ) ){ |
| 46 |
$plugin_data = get_plugin_data( $addon['ABSPATH'] ); |
| 47 |
if( $plugin_data['Version'] ){ |
| 48 |
$plugin_basename = plugin_basename( $addon['ABSPATH'] ); |
| 49 |
if( version_compare( $plugin_data['Version'], '3.0.0', '<' ) && is_plugin_active( $plugin_basename ) ) $plugins[] = $plugin_basename; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
if( $plugins ) deactivate_plugins($plugins); |
| 54 |
} |
| 55 |
|
| 56 |
add_action('admin_init', function(){ |
| 57 |
if( strpos( (string) $_SERVER['REQUEST_URI'], '/plugins.php' ) !== false ){ |
| 58 |
$new_plugins_by_text_domain = [ |
| 59 |
'wpforo_mempress', |
| 60 |
'wpforo_surmem', |
| 61 |
'wpforo_mempro', |
| 62 |
'wpforo_groups' |
| 63 |
]; |
| 64 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 65 |
require_once WPFORO_DIR . '/includes/functions.php'; |
| 66 |
foreach( wpforo_get_addons_info() as $addon ){ |
| 67 |
if( file_exists( $addon['ABSPATH'] ) ){ |
| 68 |
$plugin_data = get_plugin_data( $addon['ABSPATH'] ); |
| 69 |
// Allow new addons to start versioning from 1.0.0 |
| 70 |
if( $plugin_data['TextDomain'] && in_array($plugin_data['TextDomain'], $new_plugins_by_text_domain) ) continue; |
| 71 |
if( $plugin_data['Version'] ){ |
| 72 |
$plugin_basename = plugin_basename( $addon['ABSPATH'] ); |
| 73 |
if( version_compare( $plugin_data['Version'], '3.0.0', '<' ) ){ |
| 74 |
if( is_plugin_active( $plugin_basename ) ){ |
| 75 |
deactivate_plugins( (array) $plugin_basename ); |
| 76 |
}else{ |
| 77 |
add_filter( 'plugin_action_links_' . $plugin_basename, function ( $links ) { |
| 78 |
$links['activate'] = '<a style="color: #ccc; cursor: pointer" onclick="alert( \'This plugin is not compatible with wpForo 2.0 version! Please update the plugin to the latest 3.0.x version, then activate it again. If the license key is expired, you should renew your license to get product updates. Otherwise, you should use old wpForo versions (1.9.X).\' );">Activate</a>'; |
| 79 |
return $links; |
| 80 |
} ); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
}); |
| 88 |
} |
| 89 |
wpforo_deactivate_all_old_addons(); |
| 90 |
|