Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-admin/plugins.php

    r17322 r16373  
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    11 
    1211if ( is_multisite() ) {
    1312    $menu_perms = get_site_option( 'menu_items', array() );
    1413
    15     if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() )
     14    if ( empty($menu_perms['plugins']) && ! is_super_admin() )
    1615        wp_die( __( 'Cheatin’ uh?' ) );
    17 }
    18 
    19 if ( !current_user_can('activate_plugins') )
     16    else if ( $menu_perms['plugins'] != 1 && is_super_admin() )
     17        add_action( 'admin_notices', '_admin_notice_multisite_activate_plugins_page' );
     18}
     19
     20if ( ! current_user_can( 'activate_plugins' ) )
    2021    wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
    2122
    22 $wp_list_table = _get_list_table('WP_Plugins_List_Table');
    23 $pagenum = $wp_list_table->get_pagenum();
    24 
    25 $action = $wp_list_table->current_action();
     23if ( isset($_POST['clear-recent-list']) )
     24    $action = 'clear-recent-list';
     25elseif ( !empty($_REQUEST['action']) )
     26    $action = $_REQUEST['action'];
     27elseif ( !empty($_REQUEST['action2']) )
     28    $action = $_REQUEST['action2'];
     29else
     30    $action = false;
    2631
    2732$plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
    28 $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
    29 
    30 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
     33
     34$default_status = get_user_option('plugins_last_view');
     35if ( empty($default_status) )
     36    $default_status = 'all';
     37$status = isset($_REQUEST['plugin_status']) ? $_REQUEST['plugin_status'] : $default_status;
     38if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'mustuse', 'dropins', 'search')) )
     39    $status = 'all';
     40if ( $status != $default_status && 'search' != $status )
     41    update_user_meta($current_user->ID, 'plugins_last_view', $status);
     42
     43$page = isset($_REQUEST['paged']) ? $_REQUEST['paged'] : 1;
     44
     45//Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    3146$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', '_error_nonce'), $_SERVER['REQUEST_URI']);
    3247
    33 if ( $action ) {
     48if ( !empty($action) ) {
    3449    $network_wide = false;
    3550    if ( ( isset( $_GET['networkwide'] ) || 'network-activate-selected' == $action ) && is_multisite() && current_user_can( 'manage_network_plugins' ) )
     
    4358            check_admin_referer('activate-plugin_' . $plugin);
    4459
    45             $result = activate_plugin($plugin, self_admin_url('plugins.php?error=true&plugin=' . $plugin), $network_wide);
     60            $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
    4661            if ( is_wp_error( $result ) ) {
    4762                if ( 'unexpected_output' == $result->get_error_code() ) {
    48                     $redirect = self_admin_url('plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin . "&plugin_status=$status&paged=$page&s=$s");
     63                    $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
    4964                    wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
    5065                    exit;
     
    6075            }
    6176            if ( isset($_GET['from']) && 'import' == $_GET['from'] ) {
    62                 wp_redirect( self_admin_url("import.php?import=" . str_replace('-importer', '', dirname($plugin))) ); // overrides the ?error=true one above and redirects to the Imports page, striping the -importer suffix
     77                wp_redirect("import.php?import=" . str_replace('-importer', '', dirname($plugin)) ); // overrides the ?error=true one above and redirects to the Imports page, striping the -importer suffix
    6378            } else {
    64                 wp_redirect( self_admin_url("plugins.php?activate=true&plugin_status=$status&paged=$page&s=$s") ); // overrides the ?error=true one above
     79                wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above
    6580            }
    6681            exit;
     
    7186                wp_die(__('You do not have sufficient permissions to activate plugins for this site.'));
    7287
    73             check_admin_referer('bulk-plugins');
     88            check_admin_referer('bulk-manage-plugins');
    7489
    7590            $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    76 
    77             // Only activate plugins which are not already active.
    78             $check = $network_wide ? 'is_plugin_active_for_network' : 'is_plugin_active';
    79             foreach ( $plugins as $i => $plugin )
    80                 if ( $check( $plugin ) )
    81                     unset( $plugins[ $i ] );
    82 
     91            $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); // Only activate plugins which are not already active.
    8392            if ( empty($plugins) ) {
    84                 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
     93                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
    8594                exit;
    8695            }
    8796
    88             activate_plugins($plugins, self_admin_url('plugins.php?error=true'), $network_wide);
     97            activate_plugins($plugins, 'plugins.php?error=true', $network_wide);
    8998
    9099            $recent = (array)get_option('recently_activated');
     
    95104            update_option('recently_activated', $recent);
    96105
    97             wp_redirect( self_admin_url("plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s") );
     106            wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
    98107            exit;
    99108            break;
    100109        case 'update-selected' :
    101110
    102             check_admin_referer( 'bulk-plugins' );
     111            check_admin_referer( 'bulk-manage-plugins' );
    103112
    104113            if ( isset( $_GET['plugins'] ) )
     
    109118                $plugins = array();
    110119
    111             $title = __( 'Update Plugins' );
     120            $title = __( 'Upgrade Plugins' );
    112121            $parent_file = 'plugins.php';
    113122
    114             require_once(ABSPATH . 'wp-admin/admin-header.php');
     123            require_once( './admin-header.php' );
    115124
    116125            echo '<div class="wrap">';
     
    119128
    120129
    121             $url = self_admin_url('update.php?action=update-selected&amp;plugins=' . urlencode( join(',', $plugins) ));
     130            $url = 'update.php?action=update-selected&amp;plugins=' . urlencode( join(',', $plugins) );
    122131            $url = wp_nonce_url($url, 'bulk-update-plugins');
    123132
    124133            echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
    125134            echo '</div>';
    126             require_once(ABSPATH . 'wp-admin/admin-footer.php');
     135            require_once( './admin-footer.php' );
    127136            exit;
    128137            break;
     
    160169            deactivate_plugins($plugin);
    161170            update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
    162             if ( headers_sent() )
    163                 echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />";
     171            if (headers_sent())
     172                echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page" ) . "' />";
    164173            else
    165                 wp_redirect( self_admin_url("plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s") );
     174                wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
    166175            exit;
    167176            break;
     
    170179                wp_die(__('You do not have sufficient permissions to deactivate plugins for this site.'));
    171180
    172             check_admin_referer('bulk-plugins');
     181            check_admin_referer('bulk-manage-plugins');
    173182
    174183            $plugins = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    175184            $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
    176185            if ( empty($plugins) ) {
    177                 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
     186                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
    178187                exit;
    179188            }
     
    186195
    187196            update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
    188             wp_redirect( self_admin_url("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s") );
     197            wp_redirect("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page");
    189198            exit;
    190199            break;
     
    193202                wp_die(__('You do not have sufficient permissions to delete plugins for this site.'));
    194203
    195             check_admin_referer('bulk-plugins');
     204            check_admin_referer('bulk-manage-plugins');
    196205
    197206            //$_POST = from the plugin form; $_GET = from the FTP details screen.
    198207            $plugins = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
    199             if ( empty( $plugins ) ) {
    200                 wp_redirect( self_admin_url("plugins.php?plugin_status=$status&paged=$page&s=$s") );
    201                 exit;
    202             }
    203 
    204             $plugins = array_filter($plugins, 'is_plugin_inactive'); // Do not allow to delete Activated plugins.
    205             if ( empty( $plugins ) ) {
    206                 wp_redirect( self_admin_url( "plugins.php?error=true&main=true&plugin_status=$status&paged=$page&s=$s" ) );
     208            $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
     209            if ( empty($plugins) ) {
     210                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
    207211                exit;
    208212            }
     
    214218            if ( ! isset($_REQUEST['verify-delete']) ) {
    215219                wp_enqueue_script('jquery');
    216                 require_once(ABSPATH . 'wp-admin/admin-header.php');
     220                require_once('./admin-header.php');
    217221                ?>
    218222            <div class="wrap">
    219223                <?php
    220224                    $files_to_delete = $plugin_info = array();
    221                     $have_non_network_plugins = false;
    222225                    foreach ( (array) $plugins as $plugin ) {
    223226                        if ( '.' == dirname($plugin) ) {
     
    226229                                $plugin_info[ $plugin ] = $data;
    227230                                $plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
    228                                 if ( ! $plugin_info[ $plugin ]['Network'] )
    229                                     $have_non_network_plugins = true;
    230231                            }
    231232                        } else {
     
    238239                            if ( $folder_plugins = get_plugins( '/' . dirname($plugin)) ) {
    239240                                foreach( $folder_plugins as $plugin_file => $data ) {
    240                                     $plugin_info[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $data );
     241                                    $plugin_info[ $plugin_file ] = $data;
    241242                                    $plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
    242                                     if ( ! $plugin_info[ $plugin_file ]['Network'] )
    243                                         $have_non_network_plugins = true;
    244243                                }
    245244                            }
     
    250249                    echo '<h2>' . _n( 'Delete Plugin', 'Delete Plugins', $plugins_to_delete ) . '</h2>';
    251250                ?>
    252                 <?php if ( $have_non_network_plugins && is_network_admin() ) : ?>
    253                 <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php echo _n( 'This plugin may be active on other sites in the network.', 'These plugins may be active on other sites in the network.', $plugins_to_delete ); ?></p></div>
    254                 <?php endif; ?>
    255251                <p><?php echo _n( 'You are about to remove the following plugin:', 'You are about to remove the following plugins:', $plugins_to_delete ); ?></p>
    256252                    <ul class="ul-disc">
     
    260256                            if ( $plugin['is_uninstallable'] ) {
    261257                                /* translators: 1: plugin name, 2: plugin author */
    262                                 echo '<li>', sprintf( __( '<strong>%1$s</strong> by <em>%2$s</em> (will also <strong>delete its data</strong>)' ), esc_html($plugin['Name']), esc_html($plugin['AuthorName']) ), '</li>';
     258                                echo '<li>', sprintf( __( '<strong>%1$s</strong> by <em>%2$s</em> (will also <strong>delete its data</strong>)' ), esc_html($plugin['Name']), esc_html($plugin['Author']) ), '</li>';
    263259                                $data_to_delete = true;
    264260                            } else {
    265261                                /* translators: 1: plugin name, 2: plugin author */
    266                                 echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), esc_html($plugin['Name']), esc_html($plugin['AuthorName']) ), '</li>';
     262                                echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), esc_html($plugin['Name']), esc_html($plugin['Author']) ), '</li>';
    267263                            }
    268264                        }
     
    279275                    <input type="hidden" name="action" value="delete-selected" />
    280276                    <?php
    281                         foreach ( (array) $plugins as $plugin )
     277                        foreach ( (array)$plugins as $plugin )
    282278                            echo '<input type="hidden" name="checked[]" value="' . esc_attr($plugin) . '" />';
    283279                    ?>
    284                     <?php wp_nonce_field('bulk-plugins') ?>
    285                     <?php submit_button( $data_to_delete ? __( 'Yes, Delete these files and data' ) : __( 'Yes, Delete these files' ), 'button', 'submit', false ); ?>
     280                    <?php wp_nonce_field('bulk-manage-plugins') ?>
     281                    <input type="submit" name="submit" value="<?php $data_to_delete ? esc_attr_e('Yes, Delete these files and data') : esc_attr_e('Yes, Delete these files') ?>" class="button" />
    286282                </form>
    287283                <form method="post" action="<?php echo esc_url(wp_get_referer()); ?>" style="display:inline;">
    288                     <?php submit_button( __( 'No, Return me to the plugin list' ), 'button', 'submit', false ); ?>
     284                    <input type="submit" name="submit" value="<?php esc_attr_e('No, Return me to the plugin list') ?>" class="button" />
    289285                </form>
    290286
     
    300296            </div>
    301297                <?php
    302                 require_once(ABSPATH . 'wp-admin/admin-footer.php');
     298                require_once('./admin-footer.php');
    303299                exit;
    304300            } //Endif verify-delete
    305301            $delete_result = delete_plugins($plugins);
    306302
    307             set_transient('plugins_delete_result_' . $user_ID, $delete_result); //Store the result in a cache rather than a URL param due to object type & length
    308             wp_redirect( self_admin_url("plugins.php?deleted=true&plugin_status=$status&paged=$page&s=$s") );
     303            set_transient('plugins_delete_result_'.$user_ID, $delete_result); //Store the result in a cache rather than a URL param due to object type & length
     304            wp_redirect("plugins.php?deleted=true&plugin_status=$status&paged=$page");
    309305            exit;
    310306            break;
     
    315311}
    316312
    317 $wp_list_table->prepare_items();
    318 
    319 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
    320 if ( $pagenum > $total_pages && $total_pages > 0 ) {
    321     wp_redirect( add_query_arg( 'paged', $total_pages ) );
    322     exit;
    323 }
    324 
    325313wp_enqueue_script('plugin-install');
    326314add_thickbox();
    327 
    328 add_screen_option( 'per_page', array('label' => _x( 'Plugins', 'plugins per page (screen options)' )) );
    329315
    330316add_contextual_help($current_screen,
     
    339325
    340326$title = __('Plugins');
    341 $parent_file = 'plugins.php';
    342 
    343 require_once(ABSPATH . 'wp-admin/admin-header.php');
     327
     328require_once('./admin-header.php');
    344329
    345330$invalid = validate_active_plugins();
     
    351336<?php if ( isset($_GET['error']) ) :
    352337
    353     if ( isset( $_GET['main'] ) )
    354         $errmsg = __( 'You cannot delete a plugin while it is active on the main site.' );
    355     elseif ( isset($_GET['charsout']) )
     338    if ( isset($_GET['charsout']) )
    356339        $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']);
    357340    else
     
    360343    <div id="message" class="updated"><p><?php echo $errmsg; ?></p>
    361344    <?php
    362         if ( !isset( $_GET['main'] ) && !isset($_GET['charsout']) && wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
    363     <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>
     345        if ( !isset($_GET['charsout']) && wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
     346    <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&amp;plugin=' . esc_attr($plugin) . '&amp;_wpnonce=' . esc_attr($_GET['_error_nonce'])); ?>"></iframe>
    364347    <?php
    365348        }
     
    389372<div class="wrap">
    390373<?php screen_icon(); ?>
    391 <h2><?php echo esc_html( $title );
    392 if ( ( ! is_multisite() || is_network_admin() ) && current_user_can('install_plugins') ) { ?>
    393 <a href="<?php echo self_admin_url( 'plugin-install.php' ); ?>" class="button add-new-h2"><?php echo esc_html_x('Add New', 'plugin'); ?></a>
    394 <?php }
    395 if ( $s )
    396     printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
    397 </h2>
    398 
    399 <?php do_action( 'pre_current_active_plugins', $plugins['all'] ) ?>
    400 
    401 <?php $wp_list_table->views(); ?>
    402 
    403 <form method="post" action="">
    404 
    405 <?php $wp_list_table->search_box( __( 'Search Plugins' ), 'plugin' ); ?>
    406 
     374<h2><?php echo esc_html( $title ); if ( current_user_can('install_plugins') ) { ?> <a href="plugin-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'plugin'); ?></a><?php } ?></h2>
     375
     376<?php
     377
     378$all_plugins = apply_filters( 'all_plugins', get_plugins() );
     379$search_plugins = array();
     380$active_plugins = array();
     381$inactive_plugins = array();
     382$recent_plugins = array();
     383$recently_activated = get_option('recently_activated', array());
     384$upgrade_plugins = array();
     385$network_plugins = array();
     386$mustuse_plugins = $dropins_plugins = array();
     387if ( ! is_multisite() || current_user_can('manage_network_plugins') ) {
     388    if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
     389        $mustuse_plugins = get_mu_plugins();
     390    if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) )
     391        $dropins_plugins = get_dropins();
     392}
     393
     394set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 );
     395
     396// Clean out any plugins which were deactivated over a week ago.
     397foreach ( $recently_activated as $key => $time )
     398    if ( $time + (7*24*60*60) < time() ) //1 week
     399        unset($recently_activated[ $key ]);
     400if ( $recently_activated != get_option('recently_activated') ) //If array changed, update it.
     401    update_option('recently_activated', $recently_activated);
     402$current = get_site_transient( 'update_plugins' );
     403
     404foreach ( array( 'all_plugins', 'mustuse_plugins', 'dropins_plugins' ) as $plugin_array_name) {
     405    foreach ( (array) $$plugin_array_name as $plugin_file => $plugin_data ) {
     406        // Translate, Apply Markup, Sanitize HTML
     407        $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
     408        ${$plugin_array_name}[ $plugin_file ] = $plugin_data;
     409    }
     410}
     411unset( $plugin_array_name );
     412
     413foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {
     414    // Filter into individual sections
     415    if ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) {
     416        unset( $all_plugins[ $plugin_file ] );
     417        continue;
     418    } elseif ( is_plugin_active_for_network($plugin_file) ) {
     419        $network_plugins[ $plugin_file ] = $plugin_data;
     420    } elseif ( is_plugin_active($plugin_file) ) {
     421        $active_plugins[ $plugin_file ] = $plugin_data;
     422    } else {
     423        if ( isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
     424            $recent_plugins[ $plugin_file ] = $plugin_data;
     425        $inactive_plugins[ $plugin_file ] = $plugin_data;
     426    }
     427
     428    if ( isset( $current->response[ $plugin_file ] ) )
     429        $upgrade_plugins[ $plugin_file ] = $plugin_data;
     430}
     431
     432if ( !current_user_can('update_plugins') )
     433    $upgrade_plugins = array();
     434
     435$total_all_plugins = count($all_plugins);
     436$total_inactive_plugins = count($inactive_plugins);
     437$total_active_plugins = count($active_plugins);
     438$total_recent_plugins = count($recent_plugins);
     439$total_upgrade_plugins = count($upgrade_plugins);
     440$total_network_plugins = count($network_plugins);
     441$total_mustuse_plugins = count($mustuse_plugins);
     442$total_dropins_plugins = count($dropins_plugins);
     443
     444// Searching.
     445if ( !empty($_GET['s']) ) {
     446    function _search_plugins_filter_callback($plugin) {
     447        static $term;
     448        if ( is_null($term) )
     449            $term = stripslashes($_GET['s']);
     450        if (    stripos($plugin['Name'], $term) !== false ||
     451                stripos($plugin['Description'], $term) !== false ||
     452                stripos($plugin['Author'], $term) !== false ||
     453                stripos($plugin['PluginURI'], $term) !== false ||
     454                stripos($plugin['AuthorURI'], $term) !== false ||
     455                stripos($plugin['Version'], $term) !== false )
     456            return true;
     457        else
     458            return false;
     459    }
     460    $status = 'search';
     461    $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback');
     462    $total_search_plugins = count($search_plugins);
     463}
     464
     465$plugin_array_name = "${status}_plugins";
     466if ( empty($$plugin_array_name) && !in_array($status, array('all', 'search')) ) {
     467    $status = 'all';
     468    $plugin_array_name = "${status}_plugins";
     469}
     470
     471$plugins = &$$plugin_array_name;
     472
     473// Paging.
     474$total_this_page = "total_{$status}_plugins";
     475$total_this_page = $$total_this_page;
     476$plugins_per_page = (int) get_user_option( 'plugins_per_page' );
     477if ( empty( $plugins_per_page ) || $plugins_per_page < 1 )
     478    $plugins_per_page = 999;
     479$plugins_per_page = apply_filters( 'plugins_per_page', $plugins_per_page );
     480
     481$start = ($page - 1) * $plugins_per_page;
     482
     483$page_links = paginate_links( array(
     484    'base' => add_query_arg( 'paged', '%#%' ),
     485    'format' => '',
     486    'prev_text' => __('&laquo;'),
     487    'next_text' => __('&raquo;'),
     488    'total' => ceil($total_this_page / $plugins_per_page),
     489    'current' => $page
     490));
     491$page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
     492    number_format_i18n( $start + 1 ),
     493    number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ),
     494    '<span class="total-type-count">' . number_format_i18n( $total_this_page ) . '</span>',
     495    $page_links
     496);
     497
     498/**
     499 * @ignore
     500 *
     501 * @param array $plugins
     502 * @param string $context
     503 */
     504function print_plugins_table($plugins, $context = '') {
     505    global $page;
     506    $checkbox = ! in_array( $context, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '';
     507?>
     508<table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table">
     509    <thead>
     510    <tr>
     511        <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
     512        <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
     513        <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
     514    </tr>
     515    </thead>
     516
     517    <tfoot>
     518    <tr>
     519        <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
     520        <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
     521        <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
     522    </tr>
     523    </tfoot>
     524
     525    <tbody class="plugins">
     526<?php
     527
     528    if ( empty($plugins) ) {
     529        echo '<tr>
     530            <td colspan="3">' . __('No plugins to show') . '</td>
     531        </tr>';
     532    }
     533    foreach ( (array)$plugins as $plugin_file => $plugin_data) {
     534        // preorder
     535        $actions = array(
     536            'network_deactivate' => '', 'deactivate' => '',
     537            'network_only' => '', 'activate' => '',
     538            'network_activate' => '',
     539            'edit' => '',
     540            'delete' => '',
     541        );
     542
     543        if ( 'mustuse' == $context ) {
     544            $is_active = true;
     545        } elseif ( 'dropins' == $context ) {
     546            $dropins = _get_dropins();
     547            $plugin_name = $plugin_file;
     548            if ( $plugin_file != $plugin_data['Name'] )
     549                $plugin_name .= '<br/>' . $plugin_data['Name'];
     550            if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
     551                $is_active = true;
     552                $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
     553            } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
     554                $is_active = true;
     555                $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
     556            } else {
     557                $is_active = false;
     558                $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>';
     559            }
     560            if ( $plugin_data['Description'] )
     561                $description .= '<p>' . $plugin_data['Description'] . '</p>';
     562        } else {
     563            $is_active_for_network = is_plugin_active_for_network($plugin_file);
     564            $is_active = $is_active_for_network || is_plugin_active( $plugin_file );
     565            if ( $is_active_for_network && !is_super_admin() )
     566                continue;
     567
     568            if ( $is_active ) {
     569                if ( $is_active_for_network ) {
     570                    if ( is_super_admin() )
     571                        $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, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
     572                } else {
     573                    $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
     574                }
     575            } else {
     576                if ( is_multisite() && is_network_only_plugin( $plugin_file ) )
     577                    $actions['network_only'] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
     578                else
     579                    $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
     580
     581                if ( is_multisite() && current_user_can( 'manage_network_plugins' ) )
     582                    $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, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
     583
     584                if ( current_user_can('delete_plugins') )
     585                    $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
     586            } // end if $is_active
     587
     588            if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
     589                $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
     590        } // end if $context
     591
     592        $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
     593        $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
     594
     595        $class = $is_active ? 'active' : 'inactive';
     596        $checkbox = in_array( $context, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />";
     597        if ( 'dropins' != $context ) {
     598            $description = '<p>' . $plugin_data['Description'] . '</p>';
     599            $plugin_name = $plugin_data['Name'];
     600        }
     601        echo "
     602    <tr class='$class'>
     603        <th scope='row' class='check-column'>$checkbox</th>
     604        <td class='plugin-title'><strong>$plugin_name</strong></td>
     605        <td class='desc'>$description</td>
     606    </tr>
     607    <tr class='$class second'>
     608        <td></td>
     609        <td class='plugin-title'>";
     610        echo '<div class="row-actions-visible">';
     611        foreach ( $actions as $action => $link ) {
     612            $sep = end($actions) == $link ? '' : ' | ';
     613            echo "<span class='$action'>$link$sep</span>";
     614        }
     615        echo "</div></td>
     616        <td class='desc'>";
     617        $plugin_meta = array();
     618        if ( !empty($plugin_data['Version']) )
     619            $plugin_meta[] = sprintf(__('Version %s'), $plugin_data['Version']);
     620        if ( !empty($plugin_data['Author']) ) {
     621            $author = $plugin_data['Author'];
     622            if ( !empty($plugin_data['AuthorURI']) )
     623                $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
     624            $plugin_meta[] = sprintf( __('By %s'), $author );
     625        }
     626        if ( ! empty($plugin_data['PluginURI']) )
     627            $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin site' ) . '">' . __('Visit plugin site') . '</a>';
     628
     629        $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $context);
     630        echo implode(' | ', $plugin_meta);
     631        echo "</td>
     632    </tr>\n";
     633
     634        do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
     635        do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $context );
     636    }
     637?>
     638    </tbody>
     639</table>
     640<?php
     641} //End print_plugins_table()
     642
     643/**
     644 * @ignore
     645 *
     646 * @param string $context
     647 */
     648function print_plugin_actions($context, $field_name = 'action' ) {
     649    if ( in_array( $context, array( 'mustuse', 'dropins' ) ) )
     650        return;
     651?>
     652    <div class="alignleft actions">
     653        <select name="<?php echo $field_name; ?>">
     654            <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
     655    <?php if ( 'active' != $context ) : ?>
     656            <option value="activate-selected"><?php _e('Activate'); ?></option>
     657    <?php endif; ?>
     658    <?php if ( is_multisite() && 'network' != $context ) : ?>
     659            <option value="network-activate-selected"><?php _e('Network Activate'); ?></option>
     660    <?php endif; ?>
     661    <?php if ( 'inactive' != $context && 'recent' != $context ) : ?>
     662            <option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
     663    <?php endif; ?>
     664    <?php if ( current_user_can( 'update_plugins' ) ) : ?>
     665            <option value="update-selected"><?php _e( 'Upgrade' ); ?></option>
     666    <?php endif; ?>
     667    <?php if ( current_user_can('delete_plugins') && ( 'active' != $context ) ) : ?>
     668            <option value="delete-selected"><?php _e('Delete'); ?></option>
     669    <?php endif; ?>
     670        </select>
     671        <input type="submit" name="doaction_active" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary action" />
     672    <?php if ( 'recent' == $context ) : ?>
     673        <input type="submit" name="clear-recent-list" value="<?php esc_attr_e('Clear List') ?>" class="button-secondary" />
     674    <?php endif; ?>
     675    </div>
     676<?php
     677}
     678?>
     679
     680<form method="get" action="">
     681<p class="search-box">
     682    <label class="screen-reader-text" for="plugin-search-input"><?php _e( 'Search Plugins' ); ?>:</label>
     683    <input type="text" id="plugin-search-input" name="s" value="<?php _admin_search_query(); ?>" />
     684    <input type="submit" value="<?php esc_attr_e( 'Search Installed Plugins' ); ?>" class="button" />
     685</p>
     686</form>
     687
     688<?php do_action( 'pre_current_active_plugins', $all_plugins ) ?>
     689
     690<form method="post" action="<?php echo admin_url('plugins.php') ?>">
     691<?php wp_nonce_field('bulk-manage-plugins') ?>
    407692<input type="hidden" name="plugin_status" value="<?php echo esc_attr($status) ?>" />
    408693<input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
    409694
     695<ul class="subsubsub">
     696<?php
     697$status_links = array();
     698$class = ( 'all' == $status ) ? ' class="current"' : '';
     699$status_links[] = "<li><a href='plugins.php?plugin_status=all' $class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_all_plugins, 'plugins' ), number_format_i18n( $total_all_plugins ) ) . '</a>';
     700if ( ! empty($active_plugins) ) {
     701    $class = ( 'active' == $status ) ? ' class="current"' : '';
     702    $status_links[] = "<li><a href='plugins.php?plugin_status=active' $class>" . sprintf( _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $total_active_plugins ), number_format_i18n( $total_active_plugins ) ) . '</a>';
     703}
     704if ( ! empty($recent_plugins) ) {
     705    $class = ( 'recent' == $status ) ? ' class="current"' : '';
     706    $status_links[] = "<li><a href='plugins.php?plugin_status=recent' $class>" . sprintf( _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $total_recent_plugins ), number_format_i18n( $total_recent_plugins ) ) . '</a>';
     707}
     708if ( ! empty($inactive_plugins) ) {
     709    $class = ( 'inactive' == $status ) ? ' class="current"' : '';
     710    $status_links[] = "<li><a href='plugins.php?plugin_status=inactive' $class>" . sprintf( _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $total_inactive_plugins ), number_format_i18n( $total_inactive_plugins ) ) . '</a>';
     711}
     712if ( ! empty($network_plugins) ) {
     713    $class = ( 'network' == $status ) ? ' class="current"' : '';
     714    $status_links[] = "<li><a href='plugins.php?plugin_status=network' $class>" . sprintf( _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $total_network_plugins ), number_format_i18n( $total_network_plugins ) ) . '</a>';
     715}
     716if ( ! empty($mustuse_plugins) ) {
     717    $class = ( 'mustuse' == $status ) ? ' class="current"' : '';
     718    $status_links[] = "<li><a href='plugins.php?plugin_status=mustuse' $class>" . sprintf( _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $total_mustuse_plugins ), number_format_i18n( $total_mustuse_plugins ) ) . '</a>';
     719}
     720if ( ! empty($dropins_plugins) ) {
     721    $class = ( 'dropins' == $status ) ? ' class="current"' : '';
     722    $status_links[] = "<li><a href='plugins.php?plugin_status=dropins' $class>" . sprintf( _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $total_dropins_plugins ), number_format_i18n( $total_dropins_plugins ) ) . '</a>';
     723}
     724if ( ! empty($upgrade_plugins) ) {
     725    $class = ( 'upgrade' == $status ) ? ' class="current"' : '';
     726    $status_links[] = "<li><a href='plugins.php?plugin_status=upgrade' $class>" . sprintf( _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $total_upgrade_plugins ), number_format_i18n( $total_upgrade_plugins ) ) . '</a>';
     727}
     728if ( ! empty($search_plugins) ) {
     729    $class = ( 'search' == $status ) ? ' class="current"' : '';
     730    $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : '';
     731    $status_links[] = "<li><a href='plugins.php?s=$term' $class>" . sprintf( _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . '</a>';
     732}
     733echo implode( " |</li>\n", $status_links ) . '</li>';
     734unset( $status_links );
     735?>
     736</ul>
     737
    410738<?php
    411739if ( 'mustuse' == $status )
    412     echo '<br class="clear" /><p>' . __( 'Files in the <code>/wp-content/mu-plugins</code> directory are executed automatically.' ) . '</p>';
     740    echo '<div class="clear"></div><p>' . __( 'Files in the <code>/wp-content/mu-plugins</code> directory are executed automatically.' ) . '</p>';
    413741elseif ( 'dropins' == $status )
    414     echo '<br class="clear" /><p>' . __( 'Drop-ins are advanced plugins in the <code>/wp-content</code> directory that replace WordPress functionality when present.' ) . '</p>';
    415 ?>
    416 
    417 <?php $wp_list_table->display(); ?>
     742    echo '<div class="clear"></div><p>' . __( 'Drop-ins are advanced plugins in the <code>/wp-content</code> directory that replace WordPress functionality when present.' ) . '</p>';
     743
     744if ( !empty( $plugins ) && ( ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) ) :
     745?>
     746<div class="tablenav">
     747<?php
     748if ( $page_links )
     749    echo '<div class="tablenav-pages">', $page_links_text, '</div>';
     750
     751print_plugin_actions($status);
     752?>
     753</div>
     754<div class="clear"></div>
     755<?php
     756endif;
     757
     758if ( $total_this_page > $plugins_per_page )
     759    $plugins = array_slice($plugins, $start, $plugins_per_page);
     760
     761print_plugins_table($plugins, $status);
     762
     763if ( !empty( $plugins ) && ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) {
     764?>
     765<div class="tablenav">
     766<?php
     767if ( $page_links )
     768    echo "<div class='tablenav-pages'>$page_links_text</div>";
     769
     770print_plugin_actions($status, "action2");
     771?>
     772</div>
     773<?php } ?>
    418774</form>
    419775
     776<?php if ( empty($all_plugins) ) : ?>
     777<br class="clear" />
     778<p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
     779<?php endif; ?>
     780
    420781</div>
    421782
    422783<?php
    423 include(ABSPATH . 'wp-admin/admin-footer.php');
     784include('./admin-footer.php');
     785?>
Note: See TracChangeset for help on using the changeset viewer.