Make WordPress Core


Ignore:
Timestamp:
04/19/2012 03:41:29 AM (14 years ago)
Author:
nacin
Message:

Clean up plugins.php with regards to recently edited files, deactivations, and the network admin. see #20468, #20104.

  • Limit recently_activated to the site dashboard, and properly remove bulk-activated plugins from the array.
  • Remove code used from before the network admin, such as the unused 'network' plugin_status.
  • Don't try to deactivate a plugin already deactivated.
  • Use more specific caps (manage_network_plugins) rather than is_super_admin().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-plugins-list-table.php

    r20236 r20525  
    1414
    1515                $status = 'all';
    16                 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'network', 'mustuse', 'dropins', 'search' ) ) )
     16                if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
    1717                        $status = $_REQUEST['plugin_status'];
    1818
    … …  
    7979                set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 );
    8080
    81                 $recently_activated = get_option( 'recently_activated', array() );
    82 
    83                 $one_week = 7*24*60*60;
    84                 foreach ( $recently_activated as $key => $time )
    85                         if ( $time + $one_week < time() )
    86                                 unset( $recently_activated[$key] );
    87                 update_option( 'recently_activated', $recently_activated );
     81                if ( ! $screen->is_network ) {
     82                        $recently_activated = get_option( 'recently_activated', array() );
     83
     84                        $one_week = 7*24*60*60;
     85                        foreach ( $recently_activated as $key => $time )
     86                                if ( $time + $one_week < time() )
     87                                        unset( $recently_activated[$key] );
     88                        update_option( 'recently_activated', $recently_activated );
     89                }
    8890
    8991                foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
    9092                        // Filter into individual sections
    91                         if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !$screen->is_network ) {
    92                                 unset( $plugins['all'][ $plugin_file] );
    93                         } elseif ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) {
     93                        if ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) {
    9494                                unset( $plugins['all'][ $plugin_file ] );
    95                         } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
    96                                 $plugins['network'][ $plugin_file ] = $plugin_data;
    97                         } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) )
     95                        } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) )
    9896                                || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
    9997                                $plugins['active'][ $plugin_file ] = $plugin_data;
    … …  
    216214                                        $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count );
    217215                                        break;
    218                                 case 'network':
    219                                         $text = _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $count );
    220                                         break;
    221216                                case 'mustuse':
    222217                                        $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count );
    … …  
    249244                $screen = get_current_screen();
    250245
    251                 if ( 'active' != $status ) {
    252                         $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected';
    253                         $actions[ $action ] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
    254                 }
     246                if ( 'active' != $status )
     247                        $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
    255248
    256249                if ( 'inactive' != $status && 'recent' != $status )
    … …  
    284277                echo '<div class="alignleft actions">';
    285278
    286                 if ( 'recently_activated' == $status )
     279                $screen = get_current_screen();
     280
     281                if ( ! $screen->is_network && 'recently_activated' == $status )
    287282                        submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false );
    288283                elseif ( 'top' == $which && 'mustuse' == $status )
    … …  
    322317                // preorder
    323318                $actions = array(
    324                         'network_deactivate' => '', 'deactivate' => '',
    325                         'network_only' => '', 'activate' => '',
    326                         'network_activate' => '',
     319                        'deactivate' => '',
     320                        'activate' => '',
    327321                        'edit' => '',
    328322                        'delete' => '',
    … …  
    349343                                $description .= '<p>' . $plugin_data['Description'] . '</p>';
    350344                } else {
    351                         $is_active_for_network = is_plugin_active_for_network($plugin_file);
    352345                        if ( $screen->is_network )
    353                                 $is_active = $is_active_for_network;
     346                                $is_active = is_plugin_active_for_network( $plugin_file );
    354347                        else
    355348                                $is_active = is_plugin_active( $plugin_file );
    356349
    357                         if ( $is_active_for_network && !is_super_admin() && !$screen->is_network )
    358                                 return;
    359 
    360350                        if ( $screen->is_network ) {
    361                                 if ( $is_active_for_network ) {
     351                                if ( $is_active ) {
    362352                                        if ( current_user_can( 'manage_network_plugins' ) )
    363                                                 $actions['network_deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
     353                                                $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
    364354                                } else {
    365355                                        if ( current_user_can( 'manage_network_plugins' ) )
    366                                                 $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="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
     356                                                $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
    367357                                        if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) )
    368358                                                $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="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
Note: See TracChangeset for help on using the changeset viewer.