wpgenie

Disable Drag and Drop Image Improved Plugin in WP-Admin for iOS Safari

Jul 27th, 2026
33,306
2
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 2 0
  1. <?php
  2. /**
  3.  * Plugin Name: Disable Drag and Drop Image Improved Plugin in WP-Admin for iOS Safari
  4.  * this code snippet goes to wp-content/mu-plugins/disable-drag-and-drop.php file
  5.  */
  6.  
  7. define('TARGET_PLUGIN_FILE', 'drag-drop-featured-image-improved/index.php');
  8.  
  9. // Helper function to detect iOS Safari
  10. function is_ios_safari() {
  11.     $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
  12.     $is_ios = (bool) preg_match('/(iPhone|iPod|iPad)/i', $user_agent);
  13.     $is_safari = (bool) preg_match('/Safari/i', $user_agent) && !preg_match('/(CriOS|FxiOS|EdgiOS|OPiOS|GSA)/i', $user_agent);
  14.  
  15.     return $is_ios && $is_safari;
  16. }
  17.  
  18. // 1. FILTER ACTIVE PLUGINS FOR BOTH FRONTEND & WP-ADMIN
  19. add_filter('option_active_plugins', function($plugins) {
  20.     if (is_ios_safari()) {
  21.         $key = array_search(TARGET_PLUGIN_FILE, $plugins);
  22.         if ($key !== false) {
  23.             unset($plugins[$key]);
  24.             $plugins = array_values($plugins); // Re-index
  25.         }
  26.     }
  27.     return $plugins;
  28. });
  29.  
  30. // 2. ADMIN DEBUG MESSAGE (Shows banner at top of WP Admin screen on iOS Safari)
  31. add_action('admin_notices', function() {
  32.     if (is_ios_safari()) {
  33.         echo '<div class="notice notice-warning"><p><strong>MU-Plugin Active:</strong> iOS Safari detected. Target plugin disabled for this session.</p></div>';
  34.     }
  35. });
Advertisement