| @@ -1,14 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | -namespace PXLBSAdminify\Inc\Classes\Notifications; | |
| 2 | +namespace WPAdminify\Inc\Classes\Notifications; | |
| 3 | 3 | |
| 4 | -use PXLBSAdminify\Inc\Classes\Notifications\Model\Notice; | |
| 4 | +use WPAdminify\Inc\Classes\Notifications\Base\User_Data; | |
| 5 | +use WPAdminify\Inc\Classes\Notifications\Model\Notice; | |
| 5 | 6 | |
| 6 | -// no direct access allowed | |
| 7 | -if (!defined('ABSPATH')) { | |
| 8 | - exit; | |
| 9 | -} | |
| 10 | - | |
| 11 | 7 | if ( ! class_exists( 'Module_Conflicts' ) ) { |
| 12 | 8 | /** |
| 13 | 9 | * Module_Conflicts Class |
| 14 | 10 | * |
| @@ -17,32 +13,21 @@ | ||
| 17 | 13 | class Module_Conflicts extends Notice { |
| 18 | 14 | |
| 19 | 15 | public $color = 'warning'; |
| 20 | 16 | |
| 21 | - public function __construct() { | |
| 17 | + public function __construct() | |
| 18 | + { | |
| 19 | + parent::__construct(); | |
| 22 | 20 | 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 | 21 | |
| 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; | |
| 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' ) ); | |
| 41 | 25 | } |
| 42 | - return $result; | |
| 43 | 26 | } |
| 44 | 27 | |
| 28 | + | |
| 29 | + | |
| 45 | 30 | /** |
| 46 | 31 | * Dismiss module conflict notice via AJAX. |
| 47 | 32 | * |
| 48 | 33 | * Stores the conflict notice dismissal state in the options table. |
| @@ -50,9 +35,9 @@ | ||
| 50 | 35 | * Handle AJAX request to dismiss the admin notice. |
| 51 | 36 | * |
| 52 | 37 | * @since 1.0.0 |
| 53 | 38 | */ |
| 54 | - public function pxlbsadminify_module_conflicts() { | |
| 39 | + public function jltwp_adminify_module_conflicts() { | |
| 55 | 40 | |
| 56 | 41 | if (!current_user_can('install_plugins')) { |
| 57 | 42 | return; |
| 58 | 43 | } |
| @@ -57,21 +42,18 @@ | ||
| 57 | 42 | return; |
| 58 | 43 | } |
| 59 | 44 | |
| 60 | 45 | // 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'); | |
| 46 | + check_ajax_referer( 'dismiss_notice_nonce', 'nonce' ); | |
| 47 | + $conflicted_plugins = []; | |
| 48 | + $plugin_exists = get_option('_wpadminify_plugin_conflict'); | |
| 67 | 49 | $plugin_exists = is_array($plugin_exists) ? $plugin_exists : []; |
| 68 | - $conflicted_plugins = array_merge( $plugin_exists, [ $plugin_name ] ); | |
| 50 | + $conflicted_plugins = array_merge( $plugin_exists, [$_POST['plugin_name']] ); | |
| 69 | 51 | |
| 70 | 52 | // Update user meta to store dismissal state. |
| 71 | - update_option('pxlbsadminify_plugin_conflict', $conflicted_plugins ); | |
| 53 | + update_option('_wpadminify_plugin_conflict', $conflicted_plugins ); | |
| 72 | 54 | |
| 73 | - $this->force_disable_module('folders'); | |
| 55 | + $this->jltwp_force_disable_module('folders'); | |
| 74 | 56 | wp_send_json_success( array( 'message' => 'Notice dismissed.' ) ); |
| 75 | 57 | } |
| 76 | 58 | |
| 77 | 59 | /** |
| @@ -78,15 +60,15 @@ | ||
| 78 | 60 | * Disable WP Adminify Module. |
| 79 | 61 | * |
| 80 | 62 | * @param string $module_name Module name to disable. |
| 81 | 63 | */ |
| 82 | - public function force_disable_module( $module_name) { | |
| 64 | + public function jltwp_force_disable_module( $module_name) { | |
| 83 | 65 | // Disable WP Adminify Folder Module |
| 84 | - $adminSettings = \PXLBSAdminify\Inc\Admin\AdminSettings::get_instance(); | |
| 66 | + $adminSettings = \WPAdminify\Inc\Admin\AdminSettings::get_instance(); | |
| 85 | 67 | $options = get_option($adminSettings->get_prefix()); |
| 86 | 68 | |
| 87 | 69 | $options[$module_name] = false; // force disable |
| 88 | - update_option('pxlbsadminify_settings', $options); | |
| 70 | + update_option('_wpadminify', $options); | |
| 89 | 71 | } |
| 90 | 72 | |
| 91 | 73 | |
| 92 | 74 | /** |
| @@ -140,18 +122,30 @@ | ||
| 140 | 122 | * @since 1.0.0 |
| 141 | 123 | */ |
| 142 | 124 | public function maybe_show_folder_module_notice() |
| 143 | 125 | { |
| 144 | - $result = $this->check_folder_module_conflict(); | |
| 145 | - if(! $result){ | |
| 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) { | |
| 146 | 139 | return; |
| 147 | 140 | } |
| 148 | - $this->force_disable_module('folders'); | |
| 141 | + | |
| 142 | + $this->jltwp_force_disable_module('folders'); | |
| 149 | 143 | // Check if the notice has already been dismissed. |
| 150 | - $plugin_exists = get_option('pxlbsadminify_plugin_conflict'); | |
| 144 | + $plugin_exists = get_option('_wpadminify_plugin_conflict'); | |
| 151 | 145 | if(!empty($plugin_exists)){ |
| 152 | 146 | if(in_array( $result['Name'], $plugin_exists)){ |
| 153 | - // $this->force_disable_module('folders'); | |
| 147 | + // $this->jltwp_force_disable_module('folders'); | |
| 154 | 148 | return; |
| 155 | 149 | } |
| 156 | 150 | } |
| 157 | 151 | |
| @@ -160,14 +154,8 @@ | ||
| 160 | 154 | <button type="button" class="notice-dismiss wp-adminify-notice-dismiss" data-plugin-name="<?php echo esc_html($result['Name']);?>"></button> |
| 161 | 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'])); ?> |
| 162 | 156 | </div> |
| 163 | 157 | <?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 | 158 | } |
| 171 | 159 | |
| 172 | 160 | /** |
| 173 | 161 | * Enqueue JavaScript for conflict plugins notice. |
| @@ -173,21 +161,19 @@ | ||
| 173 | 161 | * Enqueue JavaScript for conflict plugins notice. |
| 174 | 162 | * |
| 175 | 163 | * Enqueue JavaScript that handles the conflict notice dismissal. |
| 176 | 164 | */ |
| 177 | - public function enqueue_conflict_plugin_admin_scripts() { | |
| 178 | - if( ! $this->check_folder_module_conflict()) return; | |
| 179 | - | |
| 180 | - ?> | |
| 165 | + public function enqueue_conflict_plugin_admin_scripts() { ?> | |
| 166 | + | |
| 181 | 167 | <script> |
| 182 | 168 | |
| 183 | - function pxlbsadminify_notice_action(evt, $this, action_type) { | |
| 169 | + function jltwp_adminify_notice_action(evt, $this, action_type) { | |
| 184 | 170 | if (evt) evt.preventDefault(); |
| 185 | 171 | $this.closest('.conflict-notice-wp-adminify').slideUp(200); |
| 186 | 172 | |
| 187 | 173 | 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' ) ); ?>', | |
| 174 | + action: 'jltwp_adminify_module_conflicts', | |
| 175 | + _wpnonce: '<?php echo esc_js( wp_create_nonce( 'dismiss_notice_nonce' ) ); ?>', | |
| 190 | 176 | action_type: action_type, |
| 191 | 177 | plugin_name: $this.data('pluginName') |
| 192 | 178 | }); |
| 193 | 179 | } |
| @@ -193,9 +179,9 @@ | ||
| 193 | 179 | } |
| 194 | 180 | |
| 195 | 181 | // Notice Dismiss |
| 196 | 182 | jQuery('body').on('click', '.conflict-notice-wp-adminify .wp-adminify-notice-dismiss', function(evt) { |
| 197 | - pxlbsadminify_notice_action(evt, jQuery(this), 'dismiss'); | |
| 183 | + jltwp_adminify_notice_action(evt, jQuery(this), 'dismiss'); | |
| 198 | 184 | }); |
| 199 | 185 | </script> |
| 200 | 186 | |
| 201 | 187 | <?php |
| @@ -215,5 +201,5 @@ | ||
| 215 | 201 | return array(0); |
| 216 | 202 | } |
| 217 | 203 | |
| 218 | 204 | } |
| 219 | -} | |
| 205 | +} | |