PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / class-lp-backward-plugins.php

class-lp-backward-plugins.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7, at inc/class-lp-backward-plugins.php

118 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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