| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Plugins List Table class. 4 * 5 * @package WordPress 6 * @subpackage List_Table 7 * @since 3.1.0 8 * @access private 9 */ 10 class WP_Plugins_List_Table extends WP_List_Table { 11 12 function __construct() { 13 global $status, $page; 14 15 $status = 'all'; 16 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) ) 17 $status = $_REQUEST['plugin_status']; 18 19 if ( isset($_REQUEST['s']) ) 20 $_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) ); 21 22 $page = $this->get_pagenum(); 23 24 parent::__construct( array( 25 'plural' => 'plugins', 26 ) ); 27 } 28 29 function get_table_classes() { 30 return array( 'widefat', $this->_args['plural'] ); 31 } 32 33 function ajax_user_can() { 34 if ( is_multisite() ) { 35 $menu_perms = get_site_option( 'menu_items', array() ); 36 37 if ( empty( $menu_perms['plugins'] ) && ! is_super_admin() ) 38 return false; 39 } 40 41 return current_user_can('activate_plugins'); 42 } 43 44 function prepare_items() { 45 global $status, $plugins, $totals, $page, $orderby, $order, $s; 46 47 wp_reset_vars( array( 'orderby', 'order', 's' ) ); 48 49 $plugins = array( 50 'all' => apply_filters( 'all_plugins', get_plugins() ), 51 'search' => array(), 52 'active' => array(), 53 'inactive' => array(), 54 'recently_activated' => array(), 55 'upgrade' => array(), 56 'mustuse' => array(), 57 'dropins' => array() 58 ); 59 60 $screen = get_current_screen(); 61 62 if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) { 63 if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) 64 $plugins['mustuse'] = get_mu_plugins(); 65 if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) 66 $plugins['dropins'] = get_dropins(); 67 68 if ( current_user_can( 'update_plugins' ) ) { 69 $current = get_site_transient( 'update_plugins' ); 70 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 71 if ( isset( $current->response[ $plugin_file ] ) ) { 72 $plugins['all'][ $plugin_file ]['update'] = true; 73 $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; 74 } 75 } 76 } 77 } 78 79 set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), 86400 ); 80 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 } 90 91 foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { 92 // Filter into individual sections 93 if ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) { 94 unset( $plugins['all'][ $plugin_file ] ); 95 } elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) ) 96 || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) { 97 $plugins['active'][ $plugin_file ] = $plugin_data; 98 } else { 99 if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated? 100 $plugins['recently_activated'][ $plugin_file ] = $plugin_data; 101 $plugins['inactive'][ $plugin_file ] = $plugin_data; 102 } 103 } 104 105 if ( $s ) { 106 $status = 'search'; 107 $plugins['search'] = array_filter( $plugins['all'], array( &$this, '_search_callback' ) ); 108 } 109 110 $totals = array(); 111 foreach ( $plugins as $type => $list ) 112 $totals[ $type ] = count( $list ); 113 114 if ( empty( $plugins[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) 115 $status = 'all'; 116 117 $this->items = array(); 118 foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { 119 // Translate, Don't Apply Markup, Sanitize HTML 120 $this->items[$plugin_file] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); 121 } 122 123 $total_this_page = $totals[ $status ]; 124 125 if ( $orderby ) { 126 $orderby = ucfirst( $orderby ); 127 $order = strtoupper( $order ); 128 129 uasort( $this->items, array( &$this, '_order_callback' ) ); 130 } 131 132 $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 ); 133 134 $start = ( $page - 1 ) * $plugins_per_page; 135 136 if ( $total_this_page > $plugins_per_page ) 137 $this->items = array_slice( $this->items, $start, $plugins_per_page ); 138 139 $this->set_pagination_args( array( 140 'total_items' => $total_this_page, 141 'per_page' => $plugins_per_page, 142 ) ); 143 } 144 145 function _search_callback( $plugin ) { 146 static $term; 147 if ( is_null( $term ) ) 148 $term = stripslashes( $_REQUEST['s'] ); 149 150 foreach ( $plugin as $value ) 151 if ( stripos( $value, $term ) !== false ) 152 return true; 153 154 return false; 155 } 156 157 function _order_callback( $plugin_a, $plugin_b ) { 158 global $orderby, $order; 159 160 $a = $plugin_a[$orderby]; 161 $b = $plugin_b[$orderby]; 162 163 if ( $a == $b ) 164 return 0; 165 166 if ( 'DESC' == $order ) 167 return ( $a < $b ) ? 1 : -1; 168 else 169 return ( $a < $b ) ? -1 : 1; 170 } 171 172 function no_items() { 173 global $plugins; 174 175 if ( !empty( $plugins['all'] ) ) 176 _e( 'No plugins found.' ); 177 else 178 _e( 'You do not appear to have any plugins available at this time.' ); 179 } 180 181 function get_columns() { 182 global $status; 183 184 return array( 185 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '', 186 'name' => __( 'Plugin' ), 187 'description' => __( 'Description' ), 188 ); 189 } 190 191 function get_sortable_columns() { 192 return array(); 193 } 194 195 function get_views() { 196 global $totals, $status; 197 198 $status_links = array(); 199 foreach ( $totals as $type => $count ) { 200 if ( !$count ) 201 continue; 202 203 switch ( $type ) { 204 case 'all': 205 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' ); 206 break; 207 case 'active': 208 $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count ); 209 break; 210 case 'recently_activated': 211 $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count ); 212 break; 213 case 'inactive': 214 $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); 215 break; 216 case 'mustuse': 217 $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); 218 break; 219 case 'dropins': 220 $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count ); 221 break; 222 case 'upgrade': 223 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); 224 break; 225 } 226 227 if ( 'search' != $type ) { 228 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", 229 add_query_arg('plugin_status', $type, 'plugins.php'), 230 ( $type == $status ) ? ' class="current"' : '', 231 sprintf( $text, number_format_i18n( $count ) ) 232 ); 233 } 234 } 235 236 return $status_links; 237 } 238 239 function get_bulk_actions() { 240 global $status; 241 242 $actions = array(); 243 244 $screen = get_current_screen(); 245 246 if ( 'active' != $status ) 247 $actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' ); 248 249 if ( 'inactive' != $status && 'recent' != $status ) 250 $actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' ); 251 252 if ( !is_multisite() || $screen->is_network ) { 253 if ( current_user_can( 'update_plugins' ) ) 254 $actions['update-selected'] = __( 'Update' ); 255 if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) 256 $actions['delete-selected'] = __( 'Delete' ); 257 } 258 259 return $actions; 260 } 261 262 function bulk_actions( $which ) { 263 global $status; 264 265 if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) 266 return; 267 268 parent::bulk_actions( $which ); 269 } 270 271 function extra_tablenav( $which ) { 272 global $status; 273 274 if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) ) 275 return; 276 277 echo '<div class="alignleft actions">'; 278 279 $screen = get_current_screen(); 280 281 if ( ! $screen->is_network && 'recently_activated' == $status ) 282 submit_button( __( 'Clear List' ), 'secondary', 'clear-recent-list', false ); 283 elseif ( 'top' == $which && 'mustuse' == $status ) 284 echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>'; 285 elseif ( 'top' == $which && 'dropins' == $status ) 286 echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>'; 287 288 echo '</div>'; 289 } 290 291 function current_action() { 292 if ( isset($_POST['clear-recent-list']) ) 293 return 'clear-recent-list'; 294 295 return parent::current_action(); 296 } 297 298 function display_rows() { 299 global $status; 300 301 $screen = get_current_screen(); 302 303 if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) ) 304 return; 305 306 foreach ( $this->items as $plugin_file => $plugin_data ) 307 $this->single_row( $plugin_file, $plugin_data ); 308 } 309 310 function single_row( $plugin_file, $plugin_data ) { 311 global $status, $page, $s, $totals; 312 313 $context = $status; 314 315 $screen = get_current_screen(); 316 317 // preorder 318 $actions = array( 319 'deactivate' => '', 320 'activate' => '', 321 'edit' => '', 322 'delete' => '', 323 ); 324 325 if ( 'mustuse' == $context ) { 326 $is_active = true; 327 } elseif ( 'dropins' == $context ) { 328 $dropins = _get_dropins(); 329 $plugin_name = $plugin_file; 330 if ( $plugin_file != $plugin_data['Name'] ) 331 $plugin_name .= '<br/>' . $plugin_data['Name']; 332 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant 333 $is_active = true; 334 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 335 } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true 336 $is_active = true; 337 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 338 } else { 339 $is_active = false; 340 $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>'; 341 } 342 if ( $plugin_data['Description'] ) 343 $description .= '<p>' . $plugin_data['Description'] . '</p>'; 344 } else { 345 if ( $screen->is_network ) 346 $is_active = is_plugin_active_for_network( $plugin_file ); 347 else 348 $is_active = is_plugin_active( $plugin_file ); 349 350 if ( $screen->is_network ) { 351 if ( $is_active ) { 352 if ( current_user_can( 'manage_network_plugins' ) ) 353 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; 354 } else { 355 if ( current_user_can( 'manage_network_plugins' ) ) 356 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; 357 if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) 358 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; 359 } 360 } else { 361 if ( $is_active ) { 362 $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; 363 } else { 364 $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; 365 366 if ( ! is_multisite() && current_user_can('delete_plugins') ) 367 $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; 368 } // end if $is_active 369 } // end if $screen->is_network 370 371 if ( ( ! is_multisite() || $screen->is_network ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) 372 $actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; 373 } // end if $context 374 375 $prefix = $screen->is_network ? 'network_admin_' : ''; 376 $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context ); 377 $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context ); 378 379 $class = $is_active ? 'active' : 'inactive'; 380 $checkbox_id = "checkbox_" . md5($plugin_data['Name']); 381 $checkbox = in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $plugin_data['Name'] . "</label>"; 382 if ( 'dropins' != $context ) { 383 $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>'; 384 $plugin_name = $plugin_data['Name']; 385 } 386 387 $id = sanitize_title( $plugin_name ); 388 if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) 389 $class .= ' update'; 390 391 echo "<tr id='$id' class='$class'>"; 392 393 list( $columns, $hidden ) = $this->get_column_info(); 394 395 foreach ( $columns as $column_name => $column_display_name ) { 396 $style = ''; 397 if ( in_array( $column_name, $hidden ) ) 398 $style = ' style="display:none;"'; 399 400 switch ( $column_name ) { 401 case 'cb': 402 echo "<th scope='row' class='check-column'>$checkbox</th>"; 403 break; 404 case 'name': 405 echo "<td class='plugin-title'$style><strong>$plugin_name</strong>"; 406 echo $this->row_actions( $actions, true ); 407 echo "</td>"; 408 break; 409 case 'description': 410 echo "<td class='column-description desc'$style> 411 <div class='plugin-description'>$description</div> 412 <div class='$class second plugin-version-author-uri'>"; 413 414 $plugin_meta = array(); 415 if ( !empty( $plugin_data['Version'] ) ) 416 $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 417 if ( !empty( $plugin_data['Author'] ) ) { 418 $author = $plugin_data['Author']; 419 if ( !empty( $plugin_data['AuthorURI'] ) ) 420 $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; 421 $plugin_meta[] = sprintf( __( 'By %s' ), $author ); 422 } 423 if ( ! empty( $plugin_data['PluginURI'] ) ) 424 $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>'; 425 426 $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); 427 echo implode( ' | ', $plugin_meta ); 428 429 echo "</div></td>"; 430 break; 431 default: 432 echo "<td class='$column_name column-$column_name'$style>"; 433 do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); 434 echo "</td>"; 435 } 436 } 437 438 echo "</tr>"; 439 440 do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); 441 do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); 442 } 443 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |