| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class LP_Backward_Addons |
| 5 |
* |
| 6 |
* @since 3.0.0 |
| 7 |
* @depecated 4.1.6.4 |
| 8 |
*/ |
| 9 |
class LP_Backward_Addons { |
| 10 |
|
| 11 |
/** |
| 12 |
* LP_Backward_Addons constructor. |
| 13 |
*/ |
| 14 |
public function __construct() { |
| 15 |
add_action( 'plugins_loaded', array( $this, 'deactivate_old_addons' ), - 100 ); |
| 16 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
public function admin_notices() { |
| 20 |
$invalid_plugins = get_transient( 'lp-deactivated-addons' ); |
| 21 |
delete_transient( 'lp-deactivated-addons' ); |
| 22 |
|
| 23 |
if ( ! $invalid_plugins ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
$plugin_names = array(); |
| 28 |
|
| 29 |
foreach ( $invalid_plugins as $plugin ) { |
| 30 |
if ( ! file_exists( $plugin['path'] ) ) { |
| 31 |
continue; |
| 32 |
} |
| 33 |
|
| 34 |
if ( get_plugin_data( $plugin['path'] ) ) { |
| 35 |
$plugin_data = get_plugin_data( $plugin['path'] ); |
| 36 |
$plugin_names[] = $plugin_data['Name']; |
| 37 |
} |
| 38 |
} |
| 39 |
?> |
| 40 |
<div class="notice notice-warning"> |
| 41 |
<p> |
| 42 |
<?php |
| 43 |
echo sprintf( |
| 44 |
__( 'There are some add-ons had gone outdated and might conflict with <strong>LearnPress</strong> that need to be deactivated. Please upgrade them to the newest version to ensure stability and performance of your site.', 'learnpress' ), |
| 45 |
LEARNPRESS_VERSION |
| 46 |
); |
| 47 |
?> |
| 48 |
</p> |
| 49 |
<p><?php echo '<strong>' . join( '</strong>, <strong>', $plugin_names ) . '</strong>'; ?>.</p> |
| 50 |
</div> |
| 51 |
<?php |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Hooked to plugins_loaded in highest priority and check if an addon |
| 56 |
* is not valid with new structure present in LP 3 then remove it |
| 57 |
* from activated plugins array |
| 58 |
*/ |
| 59 |
public function deactivate_old_addons() { |
| 60 |
$valid_plugins = wp_get_active_and_valid_plugins(); |
| 61 |
$active_plugins = get_option( 'active_plugins' ); |
| 62 |
$invalid_plugins = array(); |
| 63 |
$invalid_slug = false; |
| 64 |
|
| 65 |
foreach ( $valid_plugins as $file ) { |
| 66 |
$base_name = plugin_basename( $file ); |
| 67 |
|
| 68 |
if ( strpos( $base_name, 'learnpress-' ) !== 0 ) { |
| 69 |
continue; |
| 70 |
} |
| 71 |
|
| 72 |
$path = dirname( $file ); |
| 73 |
|
| 74 |
// LP 3 addons usually have a file load.php in inc/incs folder |
| 75 |
if ( file_exists( "$path/inc/load.php" ) || file_exists( "$path/incs/load.php" ) ) { |
| 76 |
continue; |
| 77 |
} |
| 78 |
|
| 79 |
// Remove addon from activated plugins |
| 80 |
if ( false !== ( $at = array_search( $base_name, $active_plugins ) ) ) { // phpcs:ignore |
| 81 |
unset( $active_plugins[ $at ] ); |
| 82 |
$invalid_plugins[] = array( |
| 83 |
'slug' => $base_name, |
| 84 |
'path' => $file, |
| 85 |
); |
| 86 |
|
| 87 |
if ( preg_match( '!learnpress-(.*)/learnpress.php!', $base_name ) ) { |
| 88 |
$invalid_slug = $base_name; |
| 89 |
break; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
if ( sizeof( $invalid_plugins ) ) { |
| 95 |
// Re-update |
| 96 |
update_option( 'active_plugins', $active_plugins ); |
| 97 |
|
| 98 |
if ( $invalid_slug ) { |
| 99 |
wp_die( |
| 100 |
sprintf( |
| 101 |
__( 'LearnPress plugin slug should be <strong>%1$s</strong> to make sure it works properly. Currently, it is <strong>%2$s</strong>. Please correct it\'s name and active again. <a href="%3$s">Back</a>', 'learnpress' ), |
| 102 |
'learnpress/learnpress.php', |
| 103 |
$invalid_slug, |
| 104 |
admin_url( 'plugins.php' ) |
| 105 |
) |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
set_transient( 'lp-deactivated-addons', $invalid_plugins ); |
| 110 |
|
| 111 |
wp_redirect( esc_url_raw( remove_query_arg( 'activate' ) ) ); |
| 112 |
exit(); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
new LP_Backward_Addons(); |
| 118 |
|