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

219 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace PXLBSAdminify\Inc\Classes\Notifications;
3
4 use PXLBSAdminify\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_pxlbsadminify_module_conflicts', [$this, 'pxlbsadminify_module_conflicts']);
25 }
26
27 public function 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 pxlbsadminify_module_conflicts() {
55
56 if (!current_user_can('install_plugins')) {
57 return;
58 }
59
60 // Verify nonce for security.
61 check_ajax_referer( 'pxlbsadminify_dismiss_notice_nonce', 'nonce' );
62 $plugin_name = isset($_POST['plugin_name']) ? sanitize_text_field(wp_unslash($_POST['plugin_name'])) : '';
63 if ('' === $plugin_name) {
64 wp_send_json_error( array( 'message' => __( 'Missing plugin name.', 'adminify' ) ), 400 );
65 }
66 $plugin_exists = get_option('pxlbsadminify_plugin_conflict');
67 $plugin_exists = is_array($plugin_exists) ? $plugin_exists : [];
68 $conflicted_plugins = array_merge( $plugin_exists, [ $plugin_name ] );
69
70 // Update user meta to store dismissal state.
71 update_option('pxlbsadminify_plugin_conflict', $conflicted_plugins );
72
73 $this->force_disable_module('folders');
74 wp_send_json_success( array( 'message' => 'Notice dismissed.' ) );
75 }
76
77 /**
78 * Disable WP Adminify Module.
79 *
80 * @param string $module_name Module name to disable.
81 */
82 public function force_disable_module( $module_name) {
83 // Disable WP Adminify Folder Module
84 $adminSettings = \PXLBSAdminify\Inc\Admin\AdminSettings::get_instance();
85 $options = get_option($adminSettings->get_prefix());
86
87 $options[$module_name] = false; // force disable
88 update_option('pxlbsadminify_settings', $options);
89 }
90
91
92 /**
93 * Checks if any of the given plugins are active.
94 *
95 * @param string[] $plugins The list of plugins to check.
96 *
97 * @return array|false The plugin data if found, otherwise false.
98 */
99 public function maybe_conflicted_plugins_active( $plugins )
100 {
101 // $options = (array) AdminSettings::get_instance()->get();
102 // if (!Utils::check_modules($options[$module_name])) {
103 // return false;
104 // }
105
106 $active_plugins = get_option('active_plugins', []);
107
108 $is_found = false;
109
110 $_plugin = null;
111
112 foreach ($active_plugins as $plugin) {
113 if (in_array($plugin, $plugins)) {
114 $is_found = true;
115 $_plugin = $plugin;
116 }
117 }
118
119 if (!$is_found) {
120 return false;
121 }
122
123 require_once ABSPATH . 'wp-admin/includes/plugin.php';
124
125 $all_plugins = get_plugins();
126
127 return $all_plugins[$_plugin];
128 }
129
130
131
132 /**
133 * Shows an admin notice about the conflict with other folder plugins.
134 *
135 * If the user has installed one of the conflicting plugins, this notice will be displayed.
136 * The notice will be dismissed if the user clicks on the dismiss button.
137 * The notice will also be dismissed if the user has already dismissed the notice before.
138 * The folder module will be disabled if the notice is shown.
139 *
140 * @since 1.0.0
141 */
142 public function maybe_show_folder_module_notice()
143 {
144 $result = $this->check_folder_module_conflict();
145 if(! $result){
146 return;
147 }
148 $this->force_disable_module('folders');
149 // Check if the notice has already been dismissed.
150 $plugin_exists = get_option('pxlbsadminify_plugin_conflict');
151 if(!empty($plugin_exists)){
152 if(in_array( $result['Name'], $plugin_exists)){
153 // $this->force_disable_module('folders');
154 return;
155 }
156 }
157
158 ?>
159 <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() ); ?>">
160 <button type="button" class="notice-dismiss wp-adminify-notice-dismiss" data-plugin-name="<?php echo esc_html($result['Name']);?>"></button>
161 <?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'])); ?>
162 </div>
163 <?php
164
165
166 // if (is_admin()) {
167 // add_action('admin_footer', array($this, 'enqueue_conflict_plugin_admin_scripts'), 99999);
168 // add_action('wp_ajax_pxlbsadminify_module_conflicts', array($this, 'pxlbsadminify_module_conflicts'));
169 // }
170 }
171
172 /**
173 * Enqueue JavaScript for conflict plugins notice.
174 *
175 * Enqueue JavaScript that handles the conflict notice dismissal.
176 */
177 public function enqueue_conflict_plugin_admin_scripts() {
178 if( ! $this->check_folder_module_conflict()) return;
179
180 ?>
181 <script>
182
183 function pxlbsadminify_notice_action(evt, $this, action_type) {
184 if (evt) evt.preventDefault();
185 $this.closest('.conflict-notice-wp-adminify').slideUp(200);
186
187 jQuery.post('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
188 action: 'pxlbsadminify_module_conflicts',
189 _wpnonce: '<?php echo esc_js( wp_create_nonce( 'pxlbsadminify_dismiss_notice_nonce' ) ); ?>',
190 action_type: action_type,
191 plugin_name: $this.data('pluginName')
192 });
193 }
194
195 // Notice Dismiss
196 jQuery('body').on('click', '.conflict-notice-wp-adminify .wp-adminify-notice-dismiss', function(evt) {
197 pxlbsadminify_notice_action(evt, jQuery(this), 'dismiss');
198 });
199 </script>
200
201 <?php
202 }
203
204
205 /**
206 * Gets the available intervals.
207 *
208 * @since 1.0.0
209 * @access public
210 *
211 * @return array An array of available intervals.
212 */
213 public function intervals()
214 {
215 return array(0);
216 }
217
218 }
219 }