PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.2.5
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.2.5
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Notifications / Module_Conflicts.php

Module_Conflicts.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.0.2.5, at Inc/Classes/Notifications/Module_Conflicts.php

206 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPAdminify\Inc\Classes\Notifications;
3
4 use WPAdminify\Inc\Classes\Notifications\Base\User_Data;
5 use WPAdminify\Inc\Classes\Notifications\Model\Notice;
6
7 if ( ! class_exists( 'Module_Conflicts' ) ) {
8 /**
9 * Module_Conflicts Class
10 *
11 * Jewel Theme <support@jeweltheme.com>
12 */
13 class Module_Conflicts extends Notice {
14
15 public $color = 'warning';
16
17 public function __construct()
18 {
19 parent::__construct();
20 add_action('admin_notices', [$this, 'maybe_show_folder_module_notice'], -9999999);
21
22 if(is_admin()){
23 add_action( 'admin_footer', array( $this, 'enqueue_conflict_plugin_admin_scripts' ),99999 );
24 add_action( 'wp_ajax_jltwp_adminify_module_conflicts', array( $this, 'jltwp_adminify_module_conflicts' ) );
25 }
26 }
27
28
29
30 /**
31 * Dismiss module conflict notice via AJAX.
32 *
33 * Stores the conflict notice dismissal state in the options table.
34 *
35 * Handle AJAX request to dismiss the admin notice.
36 *
37 * @since 1.0.0
38 */
39 public function jltwp_adminify_module_conflicts() {
40
41 if (!current_user_can('install_plugins')) {
42 return;
43 }
44
45 // Verify nonce for security.
46 check_ajax_referer( 'dismiss_notice_nonce', 'nonce' );
47 $conflicted_plugins = [];
48 $plugin_exists = get_option('_wpadminify_plugin_conflict');
49 $plugin_exists = is_array($plugin_exists) ? $plugin_exists : [];
50 $conflicted_plugins = array_merge( $plugin_exists, [$_POST['plugin_name']] );
51
52 // Update user meta to store dismissal state.
53 update_option('_wpadminify_plugin_conflict', $conflicted_plugins );
54
55 $this->jltwp_force_disable_module('folders');
56 wp_send_json_success( array( 'message' => 'Notice dismissed.' ) );
57 }
58
59 /**
60 * Disable WP Adminify Module.
61 *
62 * @param string $module_name Module name to disable.
63 */
64 public function jltwp_force_disable_module( $module_name) {
65 // Disable WP Adminify Folder Module
66 $adminSettings = \WPAdminify\Inc\Admin\AdminSettings::get_instance();
67 $options = get_option($adminSettings->get_prefix());
68
69 $options[$module_name] = false; // force disable
70 update_option('_wpadminify', $options);
71 }
72
73
74 /**
75 * Checks if any of the given plugins are active.
76 *
77 * @param string[] $plugins The list of plugins to check.
78 *
79 * @return array|false The plugin data if found, otherwise false.
80 */
81 public function maybe_conflicted_plugins_active( $plugins )
82 {
83 // $options = (array) AdminSettings::get_instance()->get();
84 // if (!Utils::check_modules($options[$module_name])) {
85 // return false;
86 // }
87
88 $active_plugins = get_option('active_plugins', []);
89
90 $is_found = false;
91
92 $_plugin = null;
93
94 foreach ($active_plugins as $plugin) {
95 if (in_array($plugin, $plugins)) {
96 $is_found = true;
97 $_plugin = $plugin;
98 }
99 }
100
101 if (!$is_found) {
102 return false;
103 }
104
105 require_once ABSPATH . 'wp-admin/includes/plugin.php';
106
107 $all_plugins = get_plugins();
108
109 return $all_plugins[$_plugin];
110 }
111
112
113
114 /**
115 * Shows an admin notice about the conflict with other folder plugins.
116 *
117 * If the user has installed one of the conflicting plugins, this notice will be displayed.
118 * The notice will be dismissed if the user clicks on the dismiss button.
119 * The notice will also be dismissed if the user has already dismissed the notice before.
120 * The folder module will be disabled if the notice is shown.
121 *
122 * @since 1.0.0
123 */
124 public function maybe_show_folder_module_notice()
125 {
126 $plugins = [
127 'folders/folders.php',
128 'filebird/filebird.php',
129 'real-media-library-lite/index.php',
130 'wicked-folders/wicked-folders.php',
131 'real-category-library-lite/index.php',
132 'wp-media-folders/wp-media-folders.php',
133 'media-library-plus/maxgalleria-media-library.php',
134 ];
135
136 $result = $this->maybe_conflicted_plugins_active( $plugins );
137
138 if (!$result) {
139 return;
140 }
141
142 $this->jltwp_force_disable_module('folders');
143 // Check if the notice has already been dismissed.
144 $plugin_exists = get_option('_wpadminify_plugin_conflict');
145 if(!empty($plugin_exists)){
146 if(in_array( $result['Name'], $plugin_exists)){
147 // $this->jltwp_force_disable_module('folders');
148 return;
149 }
150 }
151
152 ?>
153 <div class="notice conflict-notice-wp-adminify is-dismissible notice-conflict-plugins notice-<?php echo esc_attr( $this->color ); ?> wp-adminify-notice-<?php echo esc_attr( $this->get_id() ); ?>">
154 <button type="button" class="notice-dismiss wp-adminify-notice-dismiss" data-plugin-name="<?php echo esc_html($result['Name']);?>"></button>
155 <?php echo sprintf( wp_kses_post('<p>You are using <strong>%s</strong> plugin, which serve the same purpose as our folder module.</p><p>We have Disabled our <strong>Folder</strong> module, to avoid conflicts.</p>' ), esc_html($result['Name'])); ?>
156 </div>
157 <?php
158 }
159
160 /**
161 * Enqueue JavaScript for conflict plugins notice.
162 *
163 * Enqueue JavaScript that handles the conflict notice dismissal.
164 */
165 public function enqueue_conflict_plugin_admin_scripts() { ?>
166
167 <script>
168
169 function jltwp_adminify_notice_action(evt, $this, action_type) {
170 if (evt) evt.preventDefault();
171 $this.closest('.conflict-notice-wp-adminify').slideUp(200);
172
173 jQuery.post('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
174 action: 'jltwp_adminify_module_conflicts',
175 _wpnonce: '<?php echo esc_js( wp_create_nonce( 'dismiss_notice_nonce' ) ); ?>',
176 action_type: action_type,
177 plugin_name: $this.data('pluginName')
178 });
179 }
180
181 // Notice Dismiss
182 jQuery('body').on('click', '.conflict-notice-wp-adminify .wp-adminify-notice-dismiss', function(evt) {
183 jltwp_adminify_notice_action(evt, jQuery(this), 'dismiss');
184 });
185 </script>
186
187 <?php
188 }
189
190
191 /**
192 * Gets the available intervals.
193 *
194 * @since 1.0.0
195 * @access public
196 *
197 * @return array An array of available intervals.
198 */
199 public function intervals()
200 {
201 return array(0);
202 }
203
204 }
205 }
206