WordPress.org

Make WordPress Core

Ticket #15709: 15709.3.diff

File 15709.3.diff, 3.4 KB (added by PeteMall, 7 years ago)

New patch removes the delete action link from the network admin if the plugin is active on the main site. It also removes the plugin(s) from the deletion list for the bulk actions and shows an error if no other plugin was selected for bulk-deletion.

  • wp-admin/includes/class-wp-plugins-list-table.php

     
    362362                                } else {
    363363                                        if ( current_user_can( 'manage_network_plugins' ) )
    364364                                                $actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
    365                                         if ( current_user_can('delete_plugins') )
     365                                        if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
    366366                                                $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
    367367                                }
    368368                        } else {
  • wp-admin/plugins.php

     
    195195
    196196                        //$_POST = from the plugin form; $_GET = from the FTP details screen.
    197197                        $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
    198                         $plugins = array_filter($plugins, 'is_plugin_inactive'); // Do not allow to delete Activated plugins.
    199                         if ( empty($plugins) ) {
     198                        if ( empty( $plugins ) ) {
    200199                                wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
    201200                                exit;
    202201                        }
    203 
     202                       
     203                        $plugins = array_filter($plugins, 'is_plugin_inactive'); // Do not allow to delete Activated plugins.
     204                        if ( empty( $plugins ) ) {
     205                                wp_redirect( self_admin_url( "plugins.php?error=true&main=true&plugin_status=$status&paged=$page&s=$s" ) );
     206                                exit;
     207                        }
     208                                               
    204209                        include(ABSPATH . 'wp-admin/update.php');
    205210
    206211                        $parent_file = 'plugins.php';
     
    330335
    331336<?php if ( isset($_GET['error']) ) :
    332337
    333         if ( isset($_GET['charsout']) )
     338        if ( isset( $_GET['main'] ) )
     339                $errmsg = __( 'You can not delete a plugin that is active on the main site. Please deactivate the plugin from the site admin and try again.' );         
     340        elseif ( isset($_GET['charsout']) )
    334341                $errmsg = sprintf(__('The plugin generated %d characters of <strong>unexpected output</strong> during activation.  If you notice &#8220;headers already sent&#8221; messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.'), $_GET['charsout']);
    335342        else
    336343                $errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
    337344        ?>
    338345        <div id="message" class="updated"><p><?php echo $errmsg; ?></p>
    339346        <?php
    340                 if ( !isset($_GET['charsout']) && wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
     347                if ( !isset( $_GET['main'] ) && !isset($_GET['charsout']) && wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
    341348        <iframe style="border:0" width="100%" height="70px" src="<?php echo 'plugins.php?action=error_scrape&amp;plugin=' . esc_attr($plugin) . '&amp;_wpnonce=' . esc_attr($_GET['_error_nonce']); ?>"></iframe>
    342349        <?php
    343350                }