Changeset 13920 for trunk/wp-admin/includes/plugin-install.php
- Timestamp:
- 04/01/2010 11:17:53 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/plugin-install.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/plugin-install.php
r13522 r13920 355 355 $action_links = array(); 356 356 $action_links[] = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] . 357 '&TB_iframe=true&width=600&height=550') . '" class="thickbox onclick" title="' . 358 esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __('Install') . '</a>'; 357 '&TB_iframe=true&width=600&height=550') . '" class="thickbox" title="' . 358 esc_attr( sprintf( __( 'Information about %s' ), $name ) ) . '">' . __('More Information') . '</a>'; 359 360 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) { 361 $status = install_plugin_install_status($plugin); 362 363 switch ( $status['status'] ) { 364 case 'install': 365 if ( $url ) 366 $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __('Install Now') . '</a>'; 367 break; 368 case 'update_available': 369 if ( $url ) 370 $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to %s' ), $status['version'] ) ) . '">' . sprintf(__('Update to version %s'), $status['version']) . '</a>'; 371 break; 372 case 'latest_installed': 373 case 'newer_installed': 374 $action_links[] = '<span>' . __('This plugin is already installed') . '</span>'; 375 break; 376 } 377 } 359 378 360 379 $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin ); … … 395 414 396 415 /** 416 * Determine the status we can perform on a plugin. 417 * 418 * @since 3.0.0 419 */ 420 function install_plugin_install_status($api, $loop = false) { 421 // this function is called recursivly, $loop prevents futhur loops. 422 if ( is_array($api) ) 423 $api = (object) $api; 424 425 //Default to a "new" plugin 426 $status = 'install'; 427 $url = false; 428 429 //Check to see if this plugin is known to be installed, and has an update awaiting it. 430 $update_plugins = get_site_transient('update_plugins'); 431 if ( is_object( $update_plugins ) ) { 432 foreach ( (array)$update_plugins->response as $file => $plugin ) { 433 if ( $plugin->slug === $api->slug ) { 434 $status = 'update_available'; 435 $update_file = $file; 436 $version = $plugin->new_version; 437 if ( current_user_can('update_plugins') ) 438 $url = wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file); 439 break; 440 } 441 } 442 } 443 444 if ( 'install' == $status ) { 445 if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { 446 $installed_plugin = get_plugins('/' . $api->slug); 447 if ( empty($installed_plugin) ) { 448 if ( current_user_can('install_plugins') ) 449 $url = wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); 450 } else { 451 $key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers 452 if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){ 453 $status = 'latest_installed'; 454 } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) { 455 $status = 'newer_installed'; 456 $version = $installed_plugin[ $key ]['Version']; 457 } else { 458 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh 459 if ( ! $loop ) { 460 delete_site_transient('update_plugins'); 461 wp_update_plugins(); 462 return install_plugin_install_status($api, true); 463 } 464 } 465 } 466 } else { 467 // "install" & no directory with that slug 468 if ( current_user_can('install_plugins') ) 469 $url = wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); 470 } 471 } 472 473 return compact('status', 'url', 'version'); 474 } 475 476 /** 397 477 * Display plugin information in dialog box form. 398 478 * … … 441 521 ?> 442 522 <div class="alignright fyi"> 443 <?php if ( ! empty($api->download_link) ) : ?>523 <?php if ( ! empty($api->download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?> 444 524 <p class="action-button"> 445 525 <?php 446 //Default to a "new" plugin 447 $type = 'install'; 448 //Check to see if this plugin is known to be installed, and has an update awaiting it. 449 $update_plugins = get_site_transient('update_plugins'); 450 if ( is_object( $update_plugins ) ) { 451 foreach ( (array)$update_plugins->response as $file => $plugin ) { 452 if ( $plugin->slug === $api->slug ) { 453 $type = 'update_available'; 454 $update_file = $file; 455 break; 456 } 457 } 458 } 459 if ( 'install' == $type && is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { 460 $installed_plugin = get_plugins('/' . $api->slug); 461 if ( ! empty($installed_plugin) ) { 462 $key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers 463 if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){ 464 $type = 'latest_installed'; 465 } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) { 466 $type = 'newer_installed'; 467 $newer_version = $installed_plugin[ $key ]['Version']; 468 } else { 469 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh 470 delete_site_transient('update_plugins'); 471 $update_file = $api->slug . '/' . $key; //This code branch only deals with a plugin which is in a folder the same name as its slug, Doesnt support plugins which have 'non-standard' names 472 $type = 'update_available'; 473 } 474 } 475 } 476 477 switch ( $type ) : 478 default: 479 case 'install': 480 if ( current_user_can('install_plugins') ) : 481 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php 482 endif; 526 $status = install_plugin_install_status($api); 527 switch ( $status['status'] ) { 528 case 'install': 529 if ( $url ) 530 echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>'; 483 531 break; 484 case 'update_available': 485 if ( current_user_can('update_plugins') ) : 486 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file) ?>" target="_parent"><?php _e('Install Update Now') ?></a><?php 487 endif; 532 case 'update_available': 533 if ( $url ) 534 echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') .'</a>'; 488 535 break; 489 case 'newer_installed': 490 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) : 491 ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php 492 endif; 536 case 'newer_installed': 537 echo '<a>' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>'; 493 538 break; 494 case 'latest_installed': 495 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) : 496 ?><a><?php _e('Latest Version Installed') ?></a><?php 497 endif; 539 case 'latest_installed': 540 echo '<a>' . __('Latest Version Installed') . '</a>'; 498 541 break; 499 endswitch; ?> 542 } 543 ?> 500 544 </p> 501 545 <?php endif; ?>
Note: See TracChangeset
for help on using the changeset viewer.