| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cannot access directly. |
| 4 |
*/ |
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Show notice if other Knowledge Base plugins are active. |
| 11 |
*/ |
| 12 |
add_action( 'admin_notices', function () { |
| 13 |
$conflicting_plugins = [ |
| 14 |
'bbpress/bbpress.php' => [ |
| 15 |
'name' => 'bbPress', |
| 16 |
'migrate'=> false |
| 17 |
] |
| 18 |
]; |
| 19 |
foreach ( $conflicting_plugins as $plugin_file => $plugin_data ) : |
| 20 |
if ( is_plugin_active( $plugin_file ) ) : |
| 21 |
?> |
| 22 |
<div class="notice notice-warning bbpc-notice"> |
| 23 |
<p> |
| 24 |
<?php esc_html_e( 'We have detected the bbPress plugin is installed on the site.', 'forumax' ); ?> |
| 25 |
<br> |
| 26 |
<?php esc_html_e( 'To ensure Forumax works properly and without conflicts, please deactivate bbPress.', 'forumax' ); ?> |
| 27 |
</p> |
| 28 |
<p> |
| 29 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( [ 'bbpc_deactivate' => $plugin_file ] ), 'bbpc_deactivate_plugin' ) ); ?>" class="button-primary button-large red-bg"> |
| 30 |
<?php |
| 31 |
// translators: %s is the name of the plugin being deactivated. |
| 32 |
printf( esc_html__( 'Deactivate %s', 'forumax' ), esc_html( $plugin_data['name'] ) ); |
| 33 |
?> |
| 34 |
</a> |
| 35 |
</p> |
| 36 |
</div> |
| 37 |
<?php |
| 38 |
endif; |
| 39 |
endforeach; |
| 40 |
}); |
| 41 |
|
| 42 |
/** |
| 43 |
* Deactivate other Knowledge Base plugins securely. |
| 44 |
*/ |
| 45 |
add_action( 'admin_init', function () { |
| 46 |
if ( isset( $_GET['bbpc_deactivate'] ) && check_admin_referer( 'bbpc_deactivate_plugin' ) ) { |
| 47 |
|
| 48 |
if ( ! current_user_can( 'activate_plugins' ) ) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$plugin_file = sanitize_text_field( wp_unslash( $_GET['bbpc_deactivate'] ) ); |
| 53 |
|
| 54 |
if ( is_plugin_active( $plugin_file ) ) { |
| 55 |
deactivate_plugins( $plugin_file ); |
| 56 |
|
| 57 |
wp_safe_redirect( add_query_arg( [ |
| 58 |
'deactivated' => 'true', |
| 59 |
'plugin' => urlencode( $plugin_file ) |
| 60 |
], admin_url( 'plugins.php' ) ) ); |
| 61 |
exit; |
| 62 |
} |
| 63 |
} |
| 64 |
}); |