Changeset 13233
- Timestamp:
- 02/19/2010 09:16:14 PM (15 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/plugin.php
r13167 r13233 267 267 268 268 /** 269 * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data. 270 * 271 * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins). 272 * 273 * @since 3.0.0 274 * @return array Key is the mu-plugin file path and the value is an array of the mu-plugin data. 275 */ 276 function get_mu_plugins() { 277 $wp_plugins = array(); 278 // Files in wp-content/mu-plugins directory 279 $plugin_files = array(); 280 281 if ( ! is_dir( WPMU_PLUGIN_DIR ) ) 282 return $wp_plugins; 283 if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) { 284 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { 285 if ( substr( $file, -4 ) == '.php' ) 286 $plugin_files[] = $file; 287 } 288 } 289 290 @closedir( $plugins_dir ); 291 292 if ( !$plugins_dir || empty($plugin_files) ) 293 return $wp_plugins; 294 295 foreach ( $plugin_files as $plugin_file ) { 296 if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) 297 continue; 298 299 $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. 300 301 if ( empty ( $plugin_data['Name'] ) ) 302 $plugin_data['Name'] = $plugin_file; 303 304 $wp_plugins[ $plugin_file ] = $plugin_data; 305 } 306 307 if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden 308 unset( $wp_plugins['index.php'] ); 309 310 uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); 311 312 return $wp_plugins; 313 } 314 315 /** 316 * Check the wp-content directory and retrieve all drop-ins with any plugin data. 317 * 318 * @since 3.0.0 319 * @return array Key is the file path and the value is an array of the plugin data. 320 */ 321 function get_dropins() { 322 $dropins = array(); 323 $plugin_files = array(); 324 325 $_dropins = _get_dropins(); 326 327 // These exist in the wp-content directory 328 if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) { 329 while ( ( $file = readdir( $plugins_dir ) ) !== false ) { 330 if ( isset( $_dropins[ $file ] ) ) 331 $plugin_files[] = $file; 332 } 333 } 334 335 @closedir( $plugins_dir ); 336 337 if ( !$plugins_dir || empty($plugin_files) ) 338 return $dropins; 339 340 foreach ( $plugin_files as $plugin_file ) { 341 if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) 342 continue; 343 $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. 344 if ( empty ( $plugin_data['Name'] ) ) 345 $plugin_data['Name'] = $plugin_file; 346 $dropins[ $plugin_file ] = $plugin_data; 347 } 348 349 uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' )); 350 351 return $dropins; 352 } 353 354 /** 355 * Returns drop-ins that WordPress uses. 356 * 357 * Includes Multisite drop-ins only when is_multisite() 358 * 359 * @since 3.0.0 360 * @return array Key is file name. The value is an array, with the first value the 361 * purpose of the drop-in and the second value the name of the constant that must be 362 * true for the drop-in to be used, or true if no constant is required. 363 */ 364 function _get_dropins() { 365 $dropins = array( 366 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE 367 'db.php' => array( __( 'Custom database class.' ), true ), // auto on load 368 'db-error.php' => array( __( 'Custom database error message.' ), true ), // auto on error 369 'install.php' => array( __( 'Custom install script.' ), true ), // auto on install 370 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance 371 'object-cache.php' => array( __( 'External object cache.' ), true ), // auto on load 372 ); 373 374 if ( is_multisite() ) { 375 $dropins['sunrise.php' ] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE 376 $dropins['blog-deleted.php' ] = array( __( 'Custom blog deleted message.' ), true ); // auto on deleted blog 377 $dropins['blog-inactive.php' ] = array( __( 'Custom blog inactive message.' ), true ); // auto on inactive blog 378 $dropins['blog-suspended.php'] = array( __( 'Custom blog suspended message.' ), true ); // auto on archived or spammed blog 379 } 380 381 return $dropins; 382 } 383 384 /** 269 385 * Check whether the plugin is active by checking the active_plugins list. 270 386 * -
trunk/wp-admin/plugins.php
r13167 r13233 28 28 $default_status = 'all'; 29 29 $status = isset($_REQUEST['plugin_status']) ? $_REQUEST['plugin_status'] : $default_status; 30 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', ' search')) )30 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'mustuse', 'dropins', 'search')) ) 31 31 $status = 'all'; 32 32 if ( $status != $default_status && 'search' != $status ) … … 366 366 $upgrade_plugins = array(); 367 367 $network_plugins = array(); 368 $mustuse_plugins = get_mu_plugins(); 369 $dropins_plugins = get_dropins(); 368 370 369 371 set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 ); … … 377 379 $current = get_site_transient( 'update_plugins' ); 378 380 379 foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { 380 381 // Translate, Apply Markup, Sanitize HTML 382 $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true); 383 $all_plugins[ $plugin_file ] = $plugin_data; 384 381 foreach ( array( 'all_plugins', 'mustuse_plugins', 'dropins_plugins' ) as $plugin_array_name) { 382 foreach ( (array) $$plugin_array_name as $plugin_file => $plugin_data ) { 383 // Translate, Apply Markup, Sanitize HTML 384 $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true); 385 $$plugin_array_name[ $plugin_file ] = $plugin_data; 386 } 387 } 388 unset( $plugin_array_name ); 389 390 foreach ( (array) $all_plugins as $plugin_file => $plugin_data) { 385 391 // Filter into individual sections 386 392 if ( is_plugin_active_for_network($plugin_file) && is_super_admin() ) { … … 407 413 $total_upgrade_plugins = count($upgrade_plugins); 408 414 $total_network_plugins = count($network_plugins); 415 $total_mustuse_plugins = count($mustuse_plugins); 416 $total_dropins_plugins = count($dropins_plugins); 409 417 410 418 //Searching. … … 470 478 function print_plugins_table($plugins, $context = '') { 471 479 global $page; 480 $checkbox = ! in_array( $context, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : ''; 472 481 ?> 473 482 <table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table"> 474 483 <thead> 475 484 <tr> 476 <th scope="col" class="manage-column check-column">< input type="checkbox" /></th>485 <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th> 477 486 <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th> 478 487 <th scope="col" class="manage-column"><?php _e('Description'); ?></th> … … 482 491 <tfoot> 483 492 <tr> 484 <th scope="col" class="manage-column check-column">< input type="checkbox" /></th>493 <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th> 485 494 <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th> 486 495 <th scope="col" class="manage-column"><?php _e('Description'); ?></th> … … 498 507 foreach ( (array)$plugins as $plugin_file => $plugin_data) { 499 508 $actions = array(); 500 $is_active_for_network = is_plugin_active_for_network($plugin_file); 501 $is_active = $is_active_for_network || is_plugin_active( $plugin_file ); 502 503 if ( $is_active_for_network && !is_super_admin() ) 504 continue; 505 506 if ( $is_active ) { 507 if ( $is_active_for_network ) { 508 if ( is_super_admin() ) 509 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; 509 if ( 'mustuse' == $context ) { 510 $is_active = true; 511 } elseif ( 'dropins' == $context ) { 512 $dropins = _get_dropins(); 513 $plugin_name = $plugin_file; 514 if ( $plugin_file != $plugin_data['Name'] ) 515 $plugin_name .= '<br/>' . $plugin_data['Name']; 516 if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant 517 $is_active = true; 518 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 519 } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true 520 $is_active = true; 521 $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; 510 522 } else { 511 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; 512 } 523 $is_active = false; 524 $description = '<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>'; 525 } 526 $description .= '<p>' . $plugin_data['Description'] . '</p>'; 513 527 } else { 528 $is_active_for_network = is_plugin_active_for_network($plugin_file); 529 $is_active = $is_active_for_network || is_plugin_active( $plugin_file ); 530 if ( $is_active_for_network && !is_super_admin() ) 531 continue; 532 533 if ( $is_active ) { 534 if ( $is_active_for_network ) { 535 if ( is_super_admin() ) 536 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; 537 } else { 538 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; 539 } 540 } else { 541 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; 542 if ( is_multisite() && is_super_admin() ) 543 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; 544 } 545 514 546 if ( is_multisite() && is_network_only_plugin( $plugin_file ) ) 515 547 $actions[] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>'; … … 518 550 if ( is_multisite() && is_super_admin() ) 519 551 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; 552 553 if ( !is_multisite() && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) 554 $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; 555 556 if ( ! $is_active && current_user_can('delete_plugins') ) 557 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; 558 520 559 } 521 522 if ( !is_multisite() && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )523 $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';524 525 if ( ! $is_active && current_user_can('delete_plugins') )526 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';527 560 528 561 $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); 529 562 $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context ); 530 $action_count = count($actions); 563 531 564 $class = $is_active ? 'active' : 'inactive'; 565 $checkbox = in_array( $context, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />"; 566 if ( 'dropins' != $context ) { 567 $description = '<p>' . $plugin_data['Description'] . '</p>'; 568 $plugin_name = $plugin_data['Name']; 569 } 532 570 echo " 533 571 <tr class='$class'> 534 <th scope='row' class='check-column'> <input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>535 <td class='plugin-title'><strong> {$plugin_data['Name']}</strong></td>536 <td class='desc'> <p>{$plugin_data['Description']}</p></td>572 <th scope='row' class='check-column'>$checkbox</th> 573 <td class='plugin-title'><strong>$plugin_name</strong></td> 574 <td class='desc'>$description</td> 537 575 </tr> 538 576 <tr class='$class second'> … … 578 616 */ 579 617 function print_plugin_actions($context, $field_name = 'action' ) { 618 if ( in_array( $context, array( 'mustuse', 'dropins' ) ) ) 619 return; 580 620 ?> 581 621 <div class="alignleft actions"> … … 643 683 $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>'; 644 684 } 685 if ( ! empty($mustuse_plugins) ) { 686 $class = ( 'mustuse' == $status ) ? ' class="current"' : ''; 687 $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>'; 688 } 689 if ( ! empty($dropins_plugins) ) { 690 $class = ( 'dropins' == $status ) ? ' class="current"' : ''; 691 $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>'; 692 } 645 693 if ( ! empty($upgrade_plugins) ) { 646 694 $class = ( 'upgrade' == $status ) ? ' class="current"' : ''; … … 657 705 </ul> 658 706 659 <?php if ( ! empty( $plugins ) ) { ?> 660 707 <?php 708 if ( 'mustuse' == $status ) 709 echo '<div class="clear"><p>' . __( 'Files in the <code>wp-content/mu-plugins</code> directory are executed automatically.' ) . '</p>'; 710 elseif ( 'dropins' == $status ) 711 echo '<div class="clear"><p>' . __( 'Drop-ins are advanced plugins in the <code>wp-content</code> directory that replace WordPress functionality when present.' ) . '</p>'; 712 713 if ( !empty( $plugins ) && ( ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) ) : 714 ?> 661 715 <div class="tablenav"> 662 716 <?php … … 669 723 <div class="clear"></div> 670 724 <?php 671 if ( $total_this_page > $plugins_per_page ) 672 $plugins = array_slice($plugins, $start, $plugins_per_page); 673 674 print_plugins_table($plugins, $status); 725 endif; 726 727 if ( $total_this_page > $plugins_per_page ) 728 $plugins = array_slice($plugins, $start, $plugins_per_page); 729 730 print_plugins_table($plugins, $status); 731 732 if ( !empty( $plugins ) && ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) { 675 733 ?> 676 734 <div class="tablenav">
Note: See TracChangeset
for help on using the changeset viewer.