Ticket #3498: wp_plugins_cleanup.diff

File wp_plugins_cleanup.diff, 6.5 kB (added by charleshooper, 2 years ago)

Cleans up admin plugin page and adds "deactivate all" feature

  • wp-admin/plugin-functions.php

    old new  
     1<?php 
     2 
     3function 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 
     26function 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 
     49function 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 
     58function 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  
    99     
    1010require_once(ABSPATH . 'wp-admin/admin-functions.php'); 
    1111require_once(ABSPATH . 'wp-admin/admin-db.php'); 
     12require_once(ABSPATH . 'wp-admin/plugin-functions.php'); 
    1213require_once(ABSPATH . WPINC . '/registration.php'); 
    1314 
    1415auth_redirect(); 
  • wp-admin/plugins.php

    old new  
    44if ( isset($_GET['action']) ) { 
    55        if ('activate' == $_GET['action']) { 
    66                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']); 
    208                wp_redirect('plugins.php?activate=true'); 
    219        } else if ('deactivate' == $_GET['action']) { 
    2210                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']); 
    2712                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'); 
    2817        } 
    2918        exit; 
    3019} 
     
    3221$title = __('Manage Plugins'); 
    3322require_once('admin-header.php'); 
    3423 
    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 
     24plugin_sanity_check(); 
    5925?> 
    6026 
    6127<?php if (isset($_GET['activate'])) : ?> 
     
    6632<div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p> 
    6733</div> 
    6834<?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; ?> 
    7039<div class="wrap"> 
    7140<h2><?php _e('Plugin Management'); ?></h2> 
    7241<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> 
     
    140109} 
    141110?> 
    142111 
    143 <p><?php printf(__('If something goes wrong with a plugin and you can&#8217;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&#8217;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> 
    144113 
     114 
    145115<h2><?php _e('Get More Plugins'); ?></h2> 
    146116<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> 
    147117<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>