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