Changeset 42343 for trunk/src/wp-admin/includes/plugin-install.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/plugin-install.php
r42228 r42343 146 146 147 147 $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/'; 148 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 148 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { 149 149 $url = set_url_scheme( $url, 'https' ); 150 } 150 151 151 152 $http_args = array( 152 'timeout' => 15,153 'timeout' => 15, 153 154 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 154 'body' => array(155 'action' => $action,156 'request' => serialize( $args ) 157 ) 155 'body' => array( 156 'action' => $action, 157 'request' => serialize( $args ), 158 ), 158 159 ); 159 $request = wp_remote_post( $url, $http_args );160 $request = wp_remote_post( $url, $http_args ); 160 161 161 162 if ( $ssl && is_wp_error( $request ) ) { … … 171 172 } 172 173 173 if ( is_wp_error($request) ) { 174 $res = new WP_Error( 'plugins_api_failed', 174 if ( is_wp_error( $request ) ) { 175 $res = new WP_Error( 176 'plugins_api_failed', 175 177 sprintf( 176 178 /* translators: %s: support forums URL */ … … 183 185 $res = maybe_unserialize( wp_remote_retrieve_body( $request ) ); 184 186 if ( ! is_object( $res ) && ! is_array( $res ) ) { 185 $res = new WP_Error( 'plugins_api_failed', 187 $res = new WP_Error( 188 'plugins_api_failed', 186 189 sprintf( 187 190 /* translators: %s: support forums URL */ … … 193 196 } 194 197 } 195 } elseif ( ! is_wp_error($res) ) {198 } elseif ( ! is_wp_error( $res ) ) { 196 199 $res->external = true; 197 200 } … … 218 221 */ 219 222 function install_popular_tags( $args = array() ) { 220 $key = md5( serialize($args));221 if ( false !== ( $tags = get_site_transient('poptags_' . $key) ) )223 $key = md5( serialize( $args ) ); 224 if ( false !== ( $tags = get_site_transient( 'poptags_' . $key ) ) ) { 222 225 return $tags; 223 224 $tags = plugins_api('hot_tags', $args); 225 226 if ( is_wp_error($tags) ) 226 } 227 228 $tags = plugins_api( 'hot_tags', $args ); 229 230 if ( is_wp_error( $tags ) ) { 227 231 return $tags; 232 } 228 233 229 234 set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS ); … … 242 247 243 248 <div class="plugins-popular-tags-wrapper"> 244 <h2><?php _e( 'Popular tags' ) ?></h2>245 <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ) ?></p>249 <h2><?php _e( 'Popular tags' ); ?></h2> 250 <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p> 246 251 <?php 247 252 … … 249 254 250 255 echo '<p class="popular-tags">'; 251 if ( is_wp_error( $api_tags) ) {256 if ( is_wp_error( $api_tags ) ) { 252 257 echo $api_tags->get_error_message(); 253 258 } else { … … 255 260 $tags = array(); 256 261 foreach ( (array) $api_tags as $tag ) { 257 $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) );258 $data = array(259 'link' => esc_url( $url ),260 'name' => $tag['name'],261 'slug' => $tag['slug'],262 'id' => sanitize_title_with_dashes( $tag['name'] ),263 'count' => $tag['count'] 262 $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) ); 263 $data = array( 264 'link' => esc_url( $url ), 265 'name' => $tag['name'], 266 'slug' => $tag['slug'], 267 'id' => sanitize_title_with_dashes( $tag['name'] ), 268 'count' => $tag['count'], 264 269 ); 265 270 $tags[ $tag['name'] ] = (object) $data; 266 271 } 267 echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin'), 'multiple_text' => __('%s plugins') ) ); 272 echo wp_generate_tag_cloud( 273 $tags, array( 274 'single_text' => __( '%s plugin' ), 275 'multiple_text' => __( '%s plugins' ), 276 ) 277 ); 268 278 } 269 279 echo '</p><br class="clear" /></div>'; … … 281 291 $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; 282 292 $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; 283 ?><form class="search-form search-plugins" method="get"> 293 ?> 294 <form class="search-form search-plugins" method="get"> 284 295 <input type="hidden" name="tab" value="search" /> 285 296 <label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label> … … 290 301 </select> 291 302 <label><span class="screen-reader-text"><?php _e( 'Search Plugins' ); ?></span> 292 <input type="search" name="s" value="<?php echo esc_attr( $term ) ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" />303 <input type="search" name="s" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" /> 293 304 </label> 294 305 <?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?> 295 </form><?php 306 </form> 307 <?php 296 308 } 297 309 298 310 /** 299 311 * Upload from zip 312 * 300 313 * @since 2.8.0 301 314 */ … … 303 316 ?> 304 317 <div class="upload-plugin"> 305 <p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install it by uploading it here.'); ?></p>306 <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin'); ?>">318 <p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install it by uploading it here.' ); ?></p> 319 <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>"> 307 320 <?php wp_nonce_field( 'plugin-upload' ); ?> 308 321 <label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label> … … 316 329 /** 317 330 * Show a username form for the favorites page 331 * 318 332 * @since 3.5.0 319 *320 333 */ 321 334 function install_plugins_favorites_form() { … … 347 360 348 361 switch ( current_filter() ) { 349 case 'install_plugins_favorites' 362 case 'install_plugins_favorites': 350 363 if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) { 351 364 return; 352 365 } 353 366 break; 354 case 'install_plugins_recommended' 367 case 'install_plugins_recommended': 355 368 echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>'; 356 369 break; 357 case 'install_plugins_beta' 370 case 'install_plugins_beta': 358 371 printf( 359 372 '<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>', … … 386 399 * } 387 400 */ 388 function install_plugin_install_status( $api, $loop = false) {401 function install_plugin_install_status( $api, $loop = false ) { 389 402 // This function is called recursively, $loop prevents further loops. 390 if ( is_array( $api) )403 if ( is_array( $api ) ) { 391 404 $api = (object) $api; 405 } 392 406 393 407 // Default to a "new" plugin 394 $status = 'install';395 $url = false;408 $status = 'install'; 409 $url = false; 396 410 $update_file = false; 397 411 … … 400 414 * and has an update awaiting it. 401 415 */ 402 $update_plugins = get_site_transient( 'update_plugins');416 $update_plugins = get_site_transient( 'update_plugins' ); 403 417 if ( isset( $update_plugins->response ) ) { 404 foreach ( (array) $update_plugins->response as $file => $plugin ) {418 foreach ( (array) $update_plugins->response as $file => $plugin ) { 405 419 if ( $plugin->slug === $api->slug ) { 406 $status = 'update_available';420 $status = 'update_available'; 407 421 $update_file = $file; 408 $version = $plugin->new_version; 409 if ( current_user_can('update_plugins') ) 410 $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file); 422 $version = $plugin->new_version; 423 if ( current_user_can( 'update_plugins' ) ) { 424 $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); 425 } 411 426 break; 412 427 } … … 416 431 if ( 'install' == $status ) { 417 432 if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { 418 $installed_plugin = get_plugins('/' . $api->slug); 419 if ( empty($installed_plugin) ) { 420 if ( current_user_can('install_plugins') ) 421 $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); 433 $installed_plugin = get_plugins( '/' . $api->slug ); 434 if ( empty( $installed_plugin ) ) { 435 if ( current_user_can( 'install_plugins' ) ) { 436 $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); 437 } 422 438 } else { 423 $key = array_keys( $installed_plugin );424 $key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers439 $key = array_keys( $installed_plugin ); 440 $key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers 425 441 $update_file = $api->slug . '/' . $key; 426 if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=') ){442 if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { 427 443 $status = 'latest_installed'; 428 } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<') ) {429 $status = 'newer_installed';444 } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { 445 $status = 'newer_installed'; 430 446 $version = $installed_plugin[ $key ]['Version']; 431 447 } else { 432 448 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh 433 449 if ( ! $loop ) { 434 delete_site_transient( 'update_plugins');450 delete_site_transient( 'update_plugins' ); 435 451 wp_update_plugins(); 436 return install_plugin_install_status( $api, true);452 return install_plugin_install_status( $api, true ); 437 453 } 438 454 } … … 440 456 } else { 441 457 // "install" & no directory with that slug 442 if ( current_user_can('install_plugins') ) 443 $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); 444 } 445 } 446 if ( isset($_GET['from']) ) 458 if ( current_user_can( 'install_plugins' ) ) { 459 $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); 460 } 461 } 462 } 463 if ( isset( $_GET['from'] ) ) { 447 464 $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); 465 } 448 466 449 467 $file = $update_file; … … 465 483 } 466 484 467 $api = plugins_api( 'plugin_information', array( 468 'slug' => wp_unslash( $_REQUEST['plugin'] ), 469 'is_ssl' => is_ssl(), 470 'fields' => array( 471 'banners' => true, 472 'reviews' => true, 473 'downloaded' => false, 474 'active_installs' => true 485 $api = plugins_api( 486 'plugin_information', array( 487 'slug' => wp_unslash( $_REQUEST['plugin'] ), 488 'is_ssl' => is_ssl(), 489 'fields' => array( 490 'banners' => true, 491 'reviews' => true, 492 'downloaded' => false, 493 'active_installs' => true, 494 ), 475 495 ) 476 ) );496 ); 477 497 478 498 if ( is_wp_error( $api ) ) { … … 481 501 482 502 $plugins_allowedtags = array( 483 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ), 484 'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ), 485 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), 486 'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ), 487 'p' => array(), 'br' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 488 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 489 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ), 503 'a' => array( 504 'href' => array(), 505 'title' => array(), 506 'target' => array(), 507 ), 508 'abbr' => array( 'title' => array() ), 509 'acronym' => array( 'title' => array() ), 510 'code' => array(), 511 'pre' => array(), 512 'em' => array(), 513 'strong' => array(), 514 'div' => array( 'class' => array() ), 515 'span' => array( 'class' => array() ), 516 'p' => array(), 517 'br' => array(), 518 'ul' => array(), 519 'ol' => array(), 520 'li' => array(), 521 'h1' => array(), 522 'h2' => array(), 523 'h3' => array(), 524 'h4' => array(), 525 'h5' => array(), 526 'h6' => array(), 527 'img' => array( 528 'src' => array(), 529 'class' => array(), 530 'alt' => array(), 531 ), 490 532 'blockquote' => array( 'cite' => true ), 491 533 ); 492 534 493 535 $plugins_section_titles = array( 494 'description' => _x( 'Description', 536 'description' => _x( 'Description', 'Plugin installer section title' ), 495 537 'installation' => _x( 'Installation', 'Plugin installer section title' ), 496 'faq' => _x( 'FAQ', 497 'screenshots' => _x( 'Screenshots', 498 'changelog' => _x( 'Changelog', 499 'reviews' => _x( 'Reviews', 500 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' )538 'faq' => _x( 'FAQ', 'Plugin installer section title' ), 539 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), 540 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), 541 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), 542 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), 501 543 ); 502 544 503 545 // Sanitize HTML 504 546 foreach ( (array) $api->sections as $section_name => $content ) { 505 $api->sections[ $section_name] = wp_kses( $content, $plugins_allowedtags );547 $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); 506 548 } 507 549 … … 517 559 if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { 518 560 $section_titles = array_keys( (array) $api->sections ); 519 $section = reset( $section_titles );561 $section = reset( $section_titles ); 520 562 } 521 563 … … 526 568 if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { 527 569 $_with_banner = 'with-banner'; 528 $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];529 $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];570 $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; 571 $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; 530 572 ?> 531 573 <style type="text/css"> … … 557 599 } 558 600 559 $class = ( $section_name === $section ) ? ' class="current"' : ''; 560 $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) ); 561 $href = esc_url( $href ); 601 $class = ( $section_name === $section ) ? ' class="current"' : ''; 602 $href = add_query_arg( 603 array( 604 'tab' => $tab, 605 'section' => $section_name, 606 ) 607 ); 608 $href = esc_url( $href ); 562 609 $san_section = esc_attr( $section_name ); 563 610 echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; … … 592 639 <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li> 593 640 <?php } if ( isset( $api->active_installs ) ) { ?> 594 <li><strong><?php _e( 'Active Installations:' ); ?></strong> <?php 595 if ( $api->active_installs >= 1000000 ) { 596 _ex( '1+ Million', 'Active plugin installations' ); 597 } elseif ( 0 == $api->active_installs ) { 598 _ex( 'Less Than 10', 'Active plugin installations' ); 599 } else { 600 echo number_format_i18n( $api->active_installs ) . '+'; 601 } 602 ?></li> 641 <li><strong><?php _e( 'Active Installations:' ); ?></strong> 642 <?php 643 if ( $api->active_installs >= 1000000 ) { 644 _ex( '1+ Million', 'Active plugin installations' ); 645 } elseif ( 0 == $api->active_installs ) { 646 _ex( 'Less Than 10', 'Active plugin installations' ); 647 } else { 648 echo number_format_i18n( $api->active_installs ) . '+'; 649 } 650 ?> 651 </li> 603 652 <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?> 604 653 <li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a></li> … … 611 660 <?php if ( ! empty( $api->rating ) ) { ?> 612 661 <h3><?php _e( 'Average Rating' ); ?></h3> 613 <?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?> 662 <?php 663 wp_star_rating( 664 array( 665 'rating' => $api->rating, 666 'type' => 'percent', 667 'number' => $api->num_ratings, 668 ) 669 ); 670 ?> 614 671 <p aria-hidden="true" class="fyi-description"><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></p> 615 <?php } 616 617 if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { ?> 672 <?php 673 } 674 675 if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { 676 ?> 618 677 <h3><?php _e( 'Reviews' ); ?></h3> 619 678 <p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p> … … 623 682 $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; 624 683 /* translators: 1: number of stars (used to determine singular/plural), 2: number of reviews */ 625 $aria_label = esc_attr( sprintf( _n( 'Reviews with %1$d star: %2$s. Opens in a new window.', 'Reviews with %1$d stars: %2$s. Opens in a new window.', $key ), 626 $key, 627 number_format_i18n( $ratecount ) 628 ) ); 684 $aria_label = esc_attr( 685 sprintf( 686 _n( 'Reviews with %1$d star: %2$s. Opens in a new window.', 'Reviews with %1$d stars: %2$s. Opens in a new window.', $key ), 687 $key, 688 number_format_i18n( $ratecount ) 689 ) 690 ); 629 691 ?> 630 692 <div class="counter-container"> … … 640 702 <?php 641 703 } 642 } 643 if ( ! empty( $api->contributors ) ) { ?> 704 } 705 if ( ! empty( $api->contributors ) ) { 706 ?> 644 707 <h3><?php _e( 'Contributors' ); ?></h3> 645 708 <ul class="contributors"> … … 702 765 case 'update_available': 703 766 if ( $status['url'] ) { 704 echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';767 echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>'; 705 768 } 706 769 break; 707 770 case 'newer_installed': 708 771 /* translators: %s: Plugin version */ 709 echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';772 echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>'; 710 773 break; 711 774 case 'latest_installed':
Note: See TracChangeset
for help on using the changeset viewer.