PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.17
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.17
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.1.17, at Inc/Classes/Notifications/Module_Conflicts.php

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