From 7184b861c3a582ebac74bee02d53a8ba5cfb2212 Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 13 Nov 2010 16:30:20 +0000 Subject: [PATCH] Introduce WP_Plugins_List_table:single_row(). See #15318 git-svn-id: http://svn.automattic.com/wordpress/trunk@16347 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-plugins-list-table.php | 236 +++++++++--------- 1 file changed, 122 insertions(+), 114 deletions(-) diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 8baeba94ac..b86ead3565 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -302,137 +302,145 @@ class WP_Plugins_List_Table extends WP_List_Table { } function display_rows() { + global $status; + + $screen = get_current_screen(); + + if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) ) + return; + + foreach ( $this->items as $plugin_file => $plugin_data ) + $this->single_row( $plugin_file, $plugin_data ); + } + + function single_row( $plugin_file, $plugin_data ) { global $status, $page, $s; $context = $status; $screen = get_current_screen(); - if ( is_multisite() && !$screen->is_network && in_array( $context, array( 'mustuse', 'dropins' ) ) ) - return; + // preorder + $actions = array( + 'network_deactivate' => '', 'deactivate' => '', + 'network_only' => '', 'activate' => '', + 'network_activate' => '', + 'edit' => '', + 'delete' => '', + ); - foreach ( $this->items as $plugin_file => $plugin_data ) { - // preorder - $actions = array( - 'network_deactivate' => '', 'deactivate' => '', - 'network_only' => '', 'activate' => '', - 'network_activate' => '', - 'edit' => '', - 'delete' => '', - ); - - if ( 'mustuse' == $context ) { + if ( 'mustuse' == $context ) { + $is_active = true; + } elseif ( 'dropins' == $context ) { + $dropins = _get_dropins(); + $plugin_name = $plugin_file; + if ( $plugin_file != $plugin_data['Name'] ) + $plugin_name .= '
' . $plugin_data['Name']; + if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant $is_active = true; - } elseif ( 'dropins' == $context ) { - $dropins = _get_dropins(); - $plugin_name = $plugin_file; - if ( $plugin_file != $plugin_data['Name'] ) - $plugin_name .= '
' . $plugin_data['Name']; - if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant - $is_active = true; - $description = '

' . $dropins[ $plugin_file ][0] . '

'; - } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true - $is_active = true; - $description = '

' . $dropins[ $plugin_file ][0] . '

'; - } else { - $is_active = false; - $description = '

' . $dropins[ $plugin_file ][0] . ' ' . __('Inactive:') . ' ' . sprintf( __( 'Requires %s in wp-config.php.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '

'; - } - if ( $plugin_data['Description'] ) - $description .= '

' . $plugin_data['Description'] . '

'; + $description = '

' . $dropins[ $plugin_file ][0] . '

'; + } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true + $is_active = true; + $description = '

' . $dropins[ $plugin_file ][0] . '

'; } else { - $is_active_for_network = is_plugin_active_for_network($plugin_file); - if ( $screen->is_network ) - $is_active = $is_active_for_network; - else - $is_active = is_plugin_active( $plugin_file ); - - if ( $is_active_for_network && !is_super_admin() && !$screen->is_network ) - continue; - - if ( $screen->is_network ) { - if ( $is_active_for_network ) { - if ( current_user_can( 'manage_network_plugins' ) ) - $actions['network_deactivate'] = '' . __('Network Deactivate') . ''; - } else { - if ( current_user_can( 'manage_network_plugins' ) ) - $actions['network_activate'] = '' . __('Network Activate') . ''; - if ( current_user_can('delete_plugins') ) - $actions['delete'] = '' . __('Delete') . ''; - } - } else { - if ( $is_active ) { - $actions['deactivate'] = '' . __('Deactivate') . ''; - } else { - if ( is_network_only_plugin( $plugin_file ) && !$screen->is_network ) - continue; - - $actions['activate'] = '' . __('Activate') . ''; - - if ( ! is_multisite() && current_user_can('delete_plugins') ) - $actions['delete'] = '' . __('Delete') . ''; - } // end if $is_active - } // end if $screen->is_network - - if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) - $actions['edit'] = '' . __('Edit') . ''; - } // end if $context - - $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context ); - $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context ); - - $class = $is_active ? 'active' : 'inactive'; - $checkbox_id = md5($plugin_data['Name']) . "_checkbox"; - $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : ""; - if ( 'dropins' != $status ) { - $description = '

' . $plugin_data['Description'] . '

'; - $plugin_name = $plugin_data['Name']; + $is_active = false; + $description = '

' . $dropins[ $plugin_file ][0] . ' ' . __('Inactive:') . ' ' . sprintf( __( 'Requires %s in wp-config.php.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '

'; } + if ( $plugin_data['Description'] ) + $description .= '

' . $plugin_data['Description'] . '

'; + } else { + $is_active_for_network = is_plugin_active_for_network($plugin_file); + if ( $screen->is_network ) + $is_active = $is_active_for_network; + else + $is_active = is_plugin_active( $plugin_file ); - $id = sanitize_title( $plugin_name ); + if ( $is_active_for_network && !is_super_admin() && !$screen->is_network ) + return; - echo " - - $checkbox - - $plugin_name - "; - - echo $this->row_actions( $actions, true ); + if ( $screen->is_network ) { + if ( $is_active_for_network ) { + if ( current_user_can( 'manage_network_plugins' ) ) + $actions['network_deactivate'] = '' . __('Network Deactivate') . ''; + } else { + if ( current_user_can( 'manage_network_plugins' ) ) + $actions['network_activate'] = '' . __('Network Activate') . ''; + if ( current_user_can('delete_plugins') ) + $actions['delete'] = '' . __('Delete') . ''; + } + } else { + if ( $is_active ) { + $actions['deactivate'] = '' . __('Deactivate') . ''; + } else { + if ( is_network_only_plugin( $plugin_file ) && !$screen->is_network ) + return; - echo " - - -
- $description -
-
- "; + $actions['activate'] = '' . __('Activate') . ''; + + if ( ! is_multisite() && current_user_can('delete_plugins') ) + $actions['delete'] = '' . __('Delete') . ''; + } // end if $is_active + } // end if $screen->is_network + + if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) + $actions['edit'] = '' . __('Edit') . ''; + } // end if $context + + $actions = apply_filters( 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context ); + $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context ); + + $class = $is_active ? 'active' : 'inactive'; + $checkbox_id = md5($plugin_data['Name']) . "_checkbox"; + $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : ""; + if ( 'dropins' != $status ) { + $description = '

' . $plugin_data['Description'] . '

'; + $plugin_name = $plugin_data['Name']; + } + + $id = sanitize_title( $plugin_name ); + + + echo " + + $checkbox + + $plugin_name + "; - $plugin_meta = array(); - if ( !empty( $plugin_data['Version'] ) ) - $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); - if ( !empty( $plugin_data['Author'] ) ) { - $author = $plugin_data['Author']; - if ( !empty( $plugin_data['AuthorURI'] ) ) - $author = '' . $plugin_data['Author'] . ''; - $plugin_meta[] = sprintf( __( 'By %s' ), $author ); - } - if ( ! empty( $plugin_data['PluginURI'] ) ) - $plugin_meta[] = '' . __( 'Visit plugin site' ) . ''; - - $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); - echo implode( ' | ', $plugin_meta ); + echo $this->row_actions( $actions, true ); - echo " -
- - + echo " + + +
+ $description +
+
+ "; + + $plugin_meta = array(); + if ( !empty( $plugin_data['Version'] ) ) + $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); + if ( !empty( $plugin_data['Author'] ) ) { + $author = $plugin_data['Author']; + if ( !empty( $plugin_data['AuthorURI'] ) ) + $author = '' . $plugin_data['Author'] . ''; + $plugin_meta[] = sprintf( __( 'By %s' ), $author ); + } + if ( ! empty( $plugin_data['PluginURI'] ) ) + $plugin_meta[] = '' . __( 'Visit plugin site' ) . ''; + + $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); + echo implode( ' | ', $plugin_meta ); + + echo " +
+ + "; - do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); - do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); - } + do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); + do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); } }