Ticket #3498: wp_plugins_cleanup.diff
| File wp_plugins_cleanup.diff, 6.5 kB (added by charleshooper, 2 years ago) |
|---|
-
wp-admin/plugin-functions.php
old new 1 <?php 2 3 function plugin_sanity_check() { 4 $check_plugins = get_option('active_plugins'); 5 6 // If the active plugin list is not an array, make it an empty array. 7 if ( !is_array($check_plugins) ) { 8 $check_plugins = array(); 9 update_option('active_plugins', $check_plugins); 10 } 11 12 // If a plugin file does not exist, remove it from the list of active 13 // plugins. 14 foreach ($check_plugins as $check_plugin) { 15 if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) { 16 $current = get_option('active_plugins'); 17 $key = array_search($check_plugin, $current); 18 if ( false !== $key && NULL !== $key ) { 19 unset($current[$key]); 20 update_option('active_plugins', $current); 21 } 22 } 23 } 24 } 25 26 function plugin_activate ( $plugin ) { 27 $plugin_list = get_option('active_plugins'); 28 $plugin = trim($plugin); 29 30 if ( validate_file ( $plugin ) ) 31 wp_die(__('Invalid plugin.')); 32 33 if ( ! file_exists ( ABSPATH . PLUGINDIR . '/' . $plugin ) ) 34 wp_die(__('Plugin file does not exist.')); 35 36 if ( !in_array ( $plugin, $plugin_list ) ) { 37 $plugin_list[] = $plugin; 38 sort($plugin_list); 39 40 update_option('active_plugins', $plugin_list); 41 42 include(ABSPATH . PLUGINDIR . '/' . $plugin); 43 do_action('activate_' . $plugin); 44 45 return $plugin_list; 46 } 47 } 48 49 function plugin_deactivate ( $plugin ) { 50 $plugin_list = get_option( 'active_plugins' ); 51 array_splice($plugin_list, array_search( $plugin, $plugin_list), 1 ); 52 update_option('active_plugins', $plugin_list); 53 do_action('deactivate_' . trim( $plugin )); 54 55 return $plugin_list; 56 } 57 58 function plugin_deactivate_all() { 59 $plugin_list = get_option('active_plugins'); 60 61 foreach ( $plugin_list as $plugin ) { 62 array_splice($plugin_list, array_search( $plugin, $plugin_list), 1 ); 63 do_action('deactivate_' . $plugin); 64 } 65 update_option('active_plugins', $plugin_list); 66 67 return $plugin_list; 68 } 69 70 ?> -
wp-admin/admin.php
old new 9 9 10 10 require_once(ABSPATH . 'wp-admin/admin-functions.php'); 11 11 require_once(ABSPATH . 'wp-admin/admin-db.php'); 12 require_once(ABSPATH . 'wp-admin/plugin-functions.php'); 12 13 require_once(ABSPATH . WPINC . '/registration.php'); 13 14 14 15 auth_redirect(); -
wp-admin/plugins.php
old new 4 4 if ( isset($_GET['action']) ) { 5 5 if ('activate' == $_GET['action']) { 6 6 check_admin_referer('activate-plugin_' . $_GET['plugin']); 7 $current = get_option('active_plugins'); 8 $plugin = trim($_GET['plugin']); 9 if ( validate_file($plugin) ) 10 wp_die(__('Invalid plugin.')); 11 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 12 wp_die(__('Plugin file does not exist.')); 13 if (!in_array($plugin, $current)) { 14 $current[] = $plugin; 15 sort($current); 16 update_option('active_plugins', $current); 17 include(ABSPATH . PLUGINDIR . '/' . $plugin); 18 do_action('activate_' . $plugin); 19 } 7 plugin_activate($_GET['plugin']); 20 8 wp_redirect('plugins.php?activate=true'); 21 9 } else if ('deactivate' == $_GET['action']) { 22 10 check_admin_referer('deactivate-plugin_' . $_GET['plugin']); 23 $current = get_option('active_plugins'); 24 array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu! 25 update_option('active_plugins', $current); 26 do_action('deactivate_' . trim( $_GET['plugin'] )); 11 plugin_deactivate($_GET['plugin']); 27 12 wp_redirect('plugins.php?deactivate=true'); 13 } else if ( 'deactivate-all' == $_GET['action'] ) { 14 check_admin_referer('deactivate-all'); 15 plugin_deactivate_all(); 16 wp_redirect('plugins.php?deactivate-all=true'); 28 17 } 29 18 exit; 30 19 } … … 32 21 $title = __('Manage Plugins'); 33 22 require_once('admin-header.php'); 34 23 35 // Clean up options 36 // If any plugins don't exist, axe 'em 37 38 $check_plugins = get_option('active_plugins'); 39 40 // Sanity check. If the active plugin list is not an array, make it an 41 // empty array. 42 if ( !is_array($check_plugins) ) { 43 $check_plugins = array(); 44 update_option('active_plugins', $check_plugins); 45 } 46 47 // If a plugin file does not exist, remove it from the list of active 48 // plugins. 49 foreach ($check_plugins as $check_plugin) { 50 if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) { 51 $current = get_option('active_plugins'); 52 $key = array_search($check_plugin, $current); 53 if ( false !== $key && NULL !== $key ) { 54 unset($current[$key]); 55 update_option('active_plugins', $current); 56 } 57 } 58 } 24 plugin_sanity_check(); 59 25 ?> 60 26 61 27 <?php if (isset($_GET['activate'])) : ?> … … 66 32 <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p> 67 33 </div> 68 34 <?php endif; ?> 69 35 <?php if (isset($_GET['deactivate-all'])) : ?> 36 <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.') ?></p> 37 </div> 38 <?php endif; ?> 70 39 <div class="wrap"> 71 40 <h2><?php _e('Plugin Management'); ?></h2> 72 41 <p><?php _e('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.'); ?></p> … … 140 109 } 141 110 ?> 142 111 143 <p><?php printf(__('If something goes wrong with a plugin and you can’t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated. '), PLUGINDIR); ?></p>112 <p><?php printf(__('If something goes wrong with a plugin and you can’t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated. Alternatively, you can also <a href="%s">deactivate all plugins</a>!'), PLUGINDIR, wp_nonce_url('plugins.php?action=deactivate-all')); ?></p> 144 113 114 145 115 <h2><?php _e('Get More Plugins'); ?></h2> 146 116 <p><?php _e('You can find additional plugins for your site in the <a href="http://wordpress.org/extend/plugins/">WordPress plugin directory</a>.'); ?></p> 147 117 <p><?php printf(__('To install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory. Once a plugin is uploaded, you may activate it here.'), PLUGINDIR); ?></p>
