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

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