1<?php 2/** 3 * WordPress Plugin Install Administration API 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9/** 10 * Retrieves plugin installer pages from the WordPress.org Plugins API. 11 * 12 * It is possible for a plugin to override the Plugin API result with three 13 * filters. Assume this is for plugins, which can extend on the Plugin Info to 14 * offer more choices. This is very powerful and must be used with care when 15 * overriding the filters. 16 * 17 * The first filter, {@see 'plugins_api_args'}, is for the args and gives the action 18 * as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that 19 * an object is returned. 20 * 21 * The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org 22 * Plugin Installation API entirely. If `$action` is 'query_plugins' or 'plugin_information', 23 * an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST 24 * be passed. 25 * 26 * Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the 27 * response object or array, depending on the `$action` type. 28 * 29 * Supported arguments per action: 30 * 31 * | Argument Name | query_plugins | plugin_information | hot_tags | hot_categories | 32 * | -------------------- | :-----------: | :----------------: | :------: | :------------: | 33 * | `$slug` | No | Yes | No | No | 34 * | `$per_page` | Yes | No | No | No | 35 * | `$page` | Yes | No | No | No | 36 * | `$number` | No | No | Yes | Yes | 37 * | `$search` | Yes | No | No | No | 38 * | `$tag` | Yes | No | No | No | 39 * | `$author` | Yes | No | No | No | 40 * | `$user` | Yes | No | No | No | 41 * | `$browse` | Yes | No | No | No | 42 * | `$locale` | Yes | Yes | No | No | 43 * | `$installed_plugins` | Yes | No | No | No | 44 * | `$is_ssl` | Yes | Yes | No | No | 45 * | `$fields` | Yes | Yes | No | No | 46 * 47 * @since 2.7.0 48 * 49 * @param string $action API action to perform: 'query_plugins', 'plugin_information', 50 * 'hot_tags' or 'hot_categories'. 51 * @param array|object $args { 52 * Optional. Array or object of arguments to serialize for the Plugin Info API. 53 * 54 * @type string $slug The plugin slug. Default empty. 55 * @type int $per_page Number of plugins per page. Default 24. 56 * @type int $page Number of current page. Default 1. 57 * @type int $number Number of tags or categories to be queried. 58 * @type string $search A search term. Default empty. 59 * @type string $tag Tag to filter plugins. Default empty. 60 * @type string $author Username of an plugin author to filter plugins. Default empty. 61 * @type string $user Username to query for their favorites. Default empty. 62 * @type string $browse Browse view: 'popular', 'new', 'beta', 'recommended'. 63 * @type string $locale Locale to provide context-sensitive results. Default is the value 64 * of get_locale(). 65 * @type string $installed_plugins Installed plugins to provide context-sensitive results. 66 * @type bool $is_ssl Whether links should be returned with https or not. Default false. 67 * @type array $fields { 68 * Array of fields which should or should not be returned. 69 * 70 * @type bool $short_description Whether to return the plugin short description. Default true. 71 * @type bool $description Whether to return the plugin full description. Default false. 72 * @type bool $sections Whether to return the plugin readme sections: description, installation, 73 * FAQ, screenshots, other notes, and changelog. Default false. 74 * @type bool $tested Whether to return the 'Compatible up to' value. Default true. 75 * @type bool $requires Whether to return the required WordPress version. Default true. 76 * @type bool $requires_php Whether to return the required PHP version. Default true. 77 * @type bool $rating Whether to return the rating in percent and total number of ratings. 78 * Default true. 79 * @type bool $ratings Whether to return the number of rating for each star (1-5). Default true. 80 * @type bool $downloaded Whether to return the download count. Default true. 81 * @type bool $downloadlink Whether to return the download link for the package. Default true. 82 * @type bool $last_updated Whether to return the date of the last update. Default true. 83 * @type bool $added Whether to return the date when the plugin was added to the wordpress.org 84 * repository. Default true. 85 * @type bool $tags Whether to return the assigned tags. Default true. 86 * @type bool $compatibility Whether to return the WordPress compatibility list. Default true. 87 * @type bool $homepage Whether to return the plugin homepage link. Default true. 88 * @type bool $versions Whether to return the list of all available versions. Default false. 89 * @type bool $donate_link Whether to return the donation link. Default true. 90 * @type bool $reviews Whether to return the plugin reviews. Default false. 91 * @type bool $banners Whether to return the banner images links. Default false. 92 * @type bool $icons Whether to return the icon links. Default false. 93 * @type bool $active_installs Whether to return the number of active installations. Default false. 94 * @type bool $group Whether to return the assigned group. Default false. 95 * @type bool $contributors Whether to return the list of contributors. Default false. 96 * } 97 * } 98 * @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the 99 * {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article} 100 * for more information on the make-up of possible return values depending on the value of `$action`. 101 */ 102function plugins_api( $action, $args = array() ) { 103 // Include an unmodified $wp_version. 104 require ABSPATH . WPINC . '/version.php'; 105 106 if ( is_array( $args ) ) { 107 $args = (object) $args; 108 } 109 110 if ( 'query_plugins' === $action ) { 111 if ( ! isset( $args->per_page ) ) { 112 $args->per_page = 24; 113 } 114 } 115 116 if ( ! isset( $args->locale ) ) { 117 $args->locale = get_user_locale(); 118 } 119 120 if ( ! isset( $args->wp_version ) ) { 121 $args->wp_version = substr( $wp_version, 0, 3 ); // x.y 122 } 123 124 /** 125 * Filters the WordPress.org Plugin Installation API arguments. 126 * 127 * Important: An object MUST be returned to this filter. 128 * 129 * @since 2.7.0 130 * 131 * @param object $args Plugin API arguments. 132 * @param string $action The type of information being requested from the Plugin Installation API. 133 */ 134 $args = apply_filters( 'plugins_api_args', $args, $action ); 135 136 /** 137 * Filters the response for the current WordPress.org Plugin Installation API request. 138 * 139 * Passing a non-false value will effectively short-circuit the WordPress.org API request. 140 * 141 * If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed. 142 * If `$action` is 'hot_tags' or 'hot_categories', an array should be passed. 143 * 144 * @since 2.7.0 145 * 146 * @param false|object|array $result The result object or array. Default false. 147 * @param string $action The type of information being requested from the Plugin Installation API. 148 * @param object $args Plugin API arguments. 149 */ 150 $res = apply_filters( 'plugins_api', false, $action, $args ); 151 152 if ( false === $res ) { 153 154 $url = 'http://api.wordpress.org/plugins/info/1.2/'; 155 $url = add_query_arg( 156 array( 157 'action' => $action, 158 'request' => $args, 159 ), 160 $url 161 ); 162 163 $http_url = $url; 164 $ssl = wp_http_supports( array( 'ssl' ) ); 165 if ( $ssl ) { 166 $url = set_url_scheme( $url, 'https' ); 167 } 168 169 $http_args = array( 170 'timeout' => 15, 171 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 172 ); 173 $request = wp_remote_get( $url, $http_args ); 174 175 if ( $ssl && is_wp_error( $request ) ) { 176 if ( ! wp_is_json_request() ) { 177 trigger_error( 178 sprintf( 179 /* translators: %s: Support forums URL. */ 180 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), 181 __( 'https://wordpress.org/support/forums/' ) 182 ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), 183 headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 184 ); 185 } 186 187 $request = wp_remote_get( $http_url, $http_args ); 188 } 189 190 if ( is_wp_error( $request ) ) { 191 $res = new WP_Error( 192 'plugins_api_failed', 193 sprintf( 194 /* translators: %s: Support forums URL. */ 195 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), 196 __( 'https://wordpress.org/support/forums/' ) 197 ), 198 $request->get_error_message() 199 ); 200 } else { 201 $res = json_decode( wp_remote_retrieve_body( $request ), true ); 202 if ( is_array( $res ) ) { 203 // Object casting is required in order to match the info/1.0 format. 204 $res = (object) $res; 205 } elseif ( null === $res ) { 206 $res = new WP_Error( 207 'plugins_api_failed', 208 sprintf( 209 /* translators: %s: Support forums URL. */ 210 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), 211 __( 'https://wordpress.org/support/forums/' ) 212 ), 213 wp_remote_retrieve_body( $request ) 214 ); 215 } 216 217 if ( isset( $res->error ) ) { 218 $res = new WP_Error( 'plugins_api_failed', $res->error ); 219 } 220 } 221 } elseif ( ! is_wp_error( $res ) ) { 222 $res->external = true; 223 } 224 225 /** 226 * Filters the Plugin Installation API response results. 227 * 228 * @since 2.7.0 229 * 230 * @param object|WP_Error $res Response object or WP_Error. 231 * @param string $action The type of information being requested from the Plugin Installation API. 232 * @param object $args Plugin API arguments. 233 */ 234 return apply_filters( 'plugins_api_result', $res, $action, $args ); 235} 236 237/** 238 * Retrieve popular WordPress plugin tags. 239 * 240 * @since 2.7.0 241 * 242 * @param array $args 243 * @return array|WP_Error 244 */ 245function install_popular_tags( $args = array() ) { 246 $key = md5( serialize( $args ) ); 247 $tags = get_site_transient( 'poptags_' . $key ); 248 if ( false !== $tags ) { 249 return $tags; 250 } 251 252 $tags = plugins_api( 'hot_tags', $args ); 253 254 if ( is_wp_error( $tags ) ) { 255 return $tags; 256 } 257 258 set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS ); 259 260 return $tags; 261} 262 263/** 264 * @since 2.7.0 265 */ 266function install_dashboard() { 267 ?> 268 <p> 269 <?php 270 printf( 271 /* translators: %s: https://wordpress.org/plugins/ */ 272 __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ), 273 __( 'https://wordpress.org/plugins/' ) 274 ); 275 ?> 276 </p> 277 278 <?php display_plugins_table(); ?> 279 280 <div class="plugins-popular-tags-wrapper"> 281 <h2><?php _e( 'Popular tags' ); ?></h2> 282 <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p> 283 <?php 284 285 $api_tags = install_popular_tags(); 286 287 echo '<p class="popular-tags">'; 288 if ( is_wp_error( $api_tags ) ) { 289 echo $api_tags->get_error_message(); 290 } else { 291 // Set up the tags in a way which can be interpreted by wp_generate_tag_cloud(). 292 $tags = array(); 293 foreach ( (array) $api_tags as $tag ) { 294 $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) ); 295 $data = array( 296 'link' => esc_url( $url ), 297 'name' => $tag['name'], 298 'slug' => $tag['slug'], 299 'id' => sanitize_title_with_dashes( $tag['name'] ), 300 'count' => $tag['count'], 301 ); 302 $tags[ $tag['name'] ] = (object) $data; 303 } 304 echo wp_generate_tag_cloud( 305 $tags, 306 array( 307 /* translators: %s: Number of plugins. */ 308 'single_text' => __( '%s plugin' ), 309 /* translators: %s: Number of plugins. */ 310 'multiple_text' => __( '%s plugins' ), 311 ) 312 ); 313 } 314 echo '</p><br class="clear" /></div>'; 315} 316 317/** 318 * Displays a search form for searching plugins. 319 * 320 * @since 2.7.0 321 * @since 4.6.0 The `$type_selector` parameter was deprecated. 322 * 323 * @param bool $deprecated Not used. 324 */ 325function install_search_form( $deprecated = true ) { 326 $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; 327 $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; 328 ?> 329 <form class="search-form search-plugins" method="get"> 330 <input type="hidden" name="tab" value="search" /> 331 <label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label> 332 <select name="type" id="typeselector"> 333 <option value="term"<?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option> 334 <option value="author"<?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option> 335 <option value="tag"<?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Plugin Installer' ); ?></option> 336 </select> 337 <label class="screen-reader-text" for="search-plugins"><?php _e( 'Search Plugins' ); ?></label> 338 <input type="search" name="s" id="search-plugins" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" placeholder="<?php esc_attr_e( 'Search plugins...' ); ?>" /> 339 <?php submit_button( __( 'Search Plugins' ), 'hide-if-js', false, false, array( 'id' => 'search-submit' ) ); ?> 340 </form> 341 <?php 342} 343 344/** 345 * Upload from zip 346 * 347 * @since 2.8.0 348 */ 349function install_plugins_upload() { 350 ?> 351<div class="upload-plugin"> 352 <p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install or update it by uploading it here.' ); ?></p> 353 <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>"> 354 <?php wp_nonce_field( 'plugin-upload' ); ?> 355 <label class="screen-reader-text" for="pluginzip"><?php _e( 'Plugin zip file' ); ?></label> 356 <input type="file" id="pluginzip" name="pluginzip" accept=".zip" /> 357 <?php submit_button( __( 'Install Now' ), '', 'install-plugin-submit', false ); ?> 358 </form> 359</div> 360 <?php 361} 362 363/** 364 * Show a username form for the favorites page 365 * 366 * @since 3.5.0 367 */ 368function install_plugins_favorites_form() { 369 $user = get_user_option( 'wporg_favorites' ); 370 $action = 'save_wporg_username_' . get_current_user_id(); 371 ?> 372 <p><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p> 373 <form method="get"> 374 <input type="hidden" name="tab" value="favorites" /> 375 <p> 376 <label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label> 377 <input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" /> 378 <input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" /> 379 <input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" /> 380 </p> 381 </form> 382 <?php 383} 384 385/** 386 * Display plugin content based on plugin list. 387 * 388 * @since 2.7.0 389 * 390 * @global WP_List_Table $wp_list_table 391 */ 392function display_plugins_table() { 393 global $wp_list_table; 394 395 switch ( current_filter() ) { 396 case 'install_plugins_favorites': 397 if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) { 398 return; 399 } 400 break; 401 case 'install_plugins_recommended': 402 echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>'; 403 break; 404 case 'install_plugins_beta': 405 printf( 406 /* translators: %s: URL to "Features as Plugins" page. */ 407 '<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>', 408 'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/' 409 ); 410 break; 411 } 412 413 ?> 414 <form id="plugin-filter" method="post"> 415 <?php $wp_list_table->display(); ?> 416 </form> 417 <?php 418} 419 420/** 421 * Determine the status we can perform on a plugin. 422 * 423 * @since 3.0.0 424 * 425 * @param array|object $api Data about the plugin retrieved from the API. 426 * @param bool $loop Optional. Disable further loops. Default false. 427 * @return array { 428 * Plugin installation status data. 429 * 430 * @type string $status Status of a plugin. Could be one of 'install', 'update_available', 'latest_installed' or 'newer_installed'. 431 * @type string $url Plugin installation URL. 432 * @type string $version The most recent version of the plugin. 433 * @type string $file Plugin filename relative to the plugins directory. 434 * } 435 */ 436function install_plugin_install_status( $api, $loop = false ) { 437 // This function is called recursively, $loop prevents further loops. 438 if ( is_array( $api ) ) { 439 $api = (object) $api; 440 } 441 442 // Default to a "new" plugin. 443 $status = 'install'; 444 $url = false; 445 $update_file = false; 446 $version = ''; 447 448 /* 449 * Check to see if this plugin is known to be installed, 450 * and has an update awaiting it. 451 */ 452 $update_plugins = get_site_transient( 'update_plugins' ); 453 if ( isset( $update_plugins->response ) ) { 454 foreach ( (array) $update_plugins->response as $file => $plugin ) { 455 if ( $plugin->slug === $api->slug ) { 456 $status = 'update_available'; 457 $update_file = $file; 458 $version = $plugin->new_version; 459 if ( current_user_can( 'update_plugins' ) ) { 460 $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); 461 } 462 break; 463 } 464 } 465 } 466 467 if ( 'install' === $status ) { 468 if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { 469 $installed_plugin = get_plugins( '/' . $api->slug ); 470 if ( empty( $installed_plugin ) ) { 471 if ( current_user_can( 'install_plugins' ) ) { 472 $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); 473 } 474 } else { 475 $key = array_keys( $installed_plugin ); 476 // Use the first plugin regardless of the name. 477 // Could have issues for multiple plugins in one directory if they share different version numbers. 478 $key = reset( $key ); 479 480 $update_file = $api->slug . '/' . $key; 481 if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { 482 $status = 'latest_installed'; 483 } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { 484 $status = 'newer_installed'; 485 $version = $installed_plugin[ $key ]['Version']; 486 } else { 487 // If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh. 488 if ( ! $loop ) { 489 delete_site_transient( 'update_plugins' ); 490 wp_update_plugins(); 491 return install_plugin_install_status( $api, true ); 492 } 493 } 494 } 495 } else { 496 // "install" & no directory with that slug. 497 if ( current_user_can( 'install_plugins' ) ) { 498 $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); 499 } 500 } 501 } 502 if ( isset( $_GET['from'] ) ) { 503 $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); 504 } 505 506 $file = $update_file; 507 return compact( 'status', 'url', 'version', 'file' ); 508} 509 510/** 511 * Display plugin information in dialog box form. 512 * 513 * @since 2.7.0 514 * 515 * @global string $tab 516 */ 517function install_plugin_information() { 518 global $tab; 519 520 if ( empty( $_REQUEST['plugin'] ) ) { 521 return; 522 } 523 524 $api = plugins_api( 525 'plugin_information', 526 array( 527 'slug' => wp_unslash( $_REQUEST['plugin'] ), 528 ) 529 ); 530 531 if ( is_wp_error( $api ) ) { 532 wp_die( $api ); 533 } 534 535 $plugins_allowedtags = array( 536 'a' => array( 537 'href' => array(), 538 'title' => array(), 539 'target' => array(), 540 ), 541 'abbr' => array( 'title' => array() ), 542 'acronym' => array( 'title' => array() ), 543 'code' => array(), 544 'pre' => array(), 545 'em' => array(), 546 'strong' => array(), 547 'div' => array( 'class' => array() ), 548 'span' => array( 'class' => array() ), 549 'p' => array(), 550 'br' => array(), 551 'ul' => array(), 552 'ol' => array(), 553 'li' => array(), 554 'h1' => array(), 555 'h2' => array(), 556 'h3' => array(), 557 'h4' => array(), 558 'h5' => array(), 559 'h6' => array(), 560 'img' => array( 561 'src' => array(), 562 'class' => array(), 563 'alt' => array(), 564 ), 565 'blockquote' => array( 'cite' => true ), 566 ); 567 568 $plugins_section_titles = array( 569 'description' => _x( 'Description', 'Plugin installer section title' ), 570 'installation' => _x( 'Installation', 'Plugin installer section title' ), 571 'faq' => _x( 'FAQ', 'Plugin installer section title' ), 572 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), 573 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), 574 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), 575 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), 576 ); 577 578 // Sanitize HTML. 579 foreach ( (array) $api->sections as $section_name => $content ) { 580 $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); 581 } 582 583 foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { 584 if ( isset( $api->$key ) ) { 585 $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); 586 } 587 } 588 589 $_tab = esc_attr( $tab ); 590 591 // Default to the Description tab, Do not translate, API returns English. 592 $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; 593 if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { 594 $section_titles = array_keys( (array) $api->sections ); 595 $section = reset( $section_titles ); 596 } 597 598 iframe_header( __( 'Plugin Installation' ) ); 599 600 $_with_banner = ''; 601 602 if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { 603 $_with_banner = 'with-banner'; 604 $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; 605 $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; 606 ?> 607 <style type="text/css"> 608 #plugin-information-title.with-banner { 609 background-image: url( <?php echo esc_url( $low ); ?> ); 610 } 611 @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) { 612 #plugin-information-title.with-banner { 613 background-image: url( <?php echo esc_url( $high ); ?> ); 614 } 615 } 616 </style> 617 <?php 618 } 619 620 echo '<div id="plugin-information-scrollable">'; 621 echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; 622 echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; 623 624 foreach ( (array) $api->sections as $section_name => $content ) { 625 if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { 626 continue; 627 } 628 629 if ( isset( $plugins_section_titles[ $section_name ] ) ) { 630 $title = $plugins_section_titles[ $section_name ]; 631 } else { 632 $title = ucwords( str_replace( '_', ' ', $section_name ) ); 633 } 634 635 $class = ( $section_name === $section ) ? ' class="current"' : ''; 636 $href = add_query_arg( 637 array( 638 'tab' => $tab, 639 'section' => $section_name, 640 ) 641 ); 642 $href = esc_url( $href ); 643 $san_section = esc_attr( $section_name ); 644 echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; 645 } 646 647 echo "</div>\n"; 648 649 ?> 650<div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'> 651 <div class="fyi"> 652 <ul> 653 <?php if ( ! empty( $api->version ) ) { ?> 654 <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li> 655 <?php } if ( ! empty( $api->author ) ) { ?> 656 <li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li> 657 <?php } if ( ! empty( $api->last_updated ) ) { ?> 658 <li><strong><?php _e( 'Last Updated:' ); ?></strong> 659 <?php 660 /* translators: %s: Human-readable time difference. */ 661 printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); 662 ?> 663 </li> 664 <?php } if ( ! empty( $api->requires ) ) { ?> 665 <li> 666 <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> 667 <?php 668 /* translators: %s: Version number. */ 669 printf( __( '%s or higher' ), $api->requires ); 670 ?> 671 </li> 672 <?php } if ( ! empty( $api->tested ) ) { ?> 673 <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li> 674 <?php } if ( ! empty( $api->requires_php ) ) { ?> 675 <li> 676 <strong><?php _e( 'Requires PHP Version:' ); ?></strong> 677 <?php 678 /* translators: %s: Version number. */ 679 printf( __( '%s or higher' ), $api->requires_php ); 680 ?> 681 </li> 682 <?php } if ( isset( $api->active_installs ) ) { ?> 683 <li><strong><?php _e( 'Active Installations:' ); ?></strong> 684 <?php 685 if ( $api->active_installs >= 1000000 ) { 686 $active_installs_millions = floor( $api->active_installs / 1000000 ); 687 printf( 688 /* translators: %s: Number of millions. */ 689 _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ), 690 number_format_i18n( $active_installs_millions ) 691 ); 692 } elseif ( $api->active_installs < 10 ) { 693 _ex( 'Less Than 10', 'Active plugin installations' ); 694 } else { 695 echo number_format_i18n( $api->active_installs ) . '+'; 696 } 697 ?> 698 </li> 699 <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?> 700 <li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a></li> 701 <?php } if ( ! empty( $api->homepage ) ) { ?> 702 <li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage »' ); ?></a></li> 703 <?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?> 704 <li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a></li> 705 <?php } ?> 706 </ul> 707 <?php if ( ! empty( $api->rating ) ) { ?> 708 <h3><?php _e( 'Average Rating' ); ?></h3> 709 <?php 710 wp_star_rating( 711 array( 712 'rating' => $api->rating, 713 'type' => 'percent', 714 'number' => $api->num_ratings, 715 ) 716 ); 717 ?> 718 <p aria-hidden="true" class="fyi-description"> 719 <?php 720 printf( 721 /* translators: %s: Number of ratings. */ 722 _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), 723 number_format_i18n( $api->num_ratings ) 724 ); 725 ?> 726 </p> 727 <?php 728 } 729 730 if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { 731 ?> 732 <h3><?php _e( 'Reviews' ); ?></h3> 733 <p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p> 734 <?php 735 foreach ( $api->ratings as $key => $ratecount ) { 736 // Avoid div-by-zero. 737 $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; 738 $aria_label = esc_attr( 739 sprintf( 740 /* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */ 741 _n( 742 'Reviews with %1$d star: %2$s. Opens in a new tab.', 743 'Reviews with %1$d stars: %2$s. Opens in a new tab.', 744 $key 745 ), 746 $key, 747 number_format_i18n( $ratecount ) 748 ) 749 ); 750 ?> 751 <div class="counter-container"> 752 <span class="counter-label"> 753 <?php 754 printf( 755 '<a href="%s" target="_blank" aria-label="%s">%s</a>', 756 "https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}", 757 $aria_label, 758 /* translators: %s: Number of stars. */ 759 sprintf( _n( '%d star', '%d stars', $key ), $key ) 760 ); 761 ?> 762 </span> 763 <span class="counter-back"> 764 <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span> 765 </span> 766 <span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span> 767 </div> 768 <?php 769 } 770 } 771 if ( ! empty( $api->contributors ) ) { 772 ?> 773 <h3><?php _e( 'Contributors' ); ?></h3> 774 <ul class="contributors"> 775 <?php 776 foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) { 777 $contrib_name = $contrib_details['display_name']; 778 if ( ! $contrib_name ) { 779 $contrib_name = $contrib_username; 780 } 781 $contrib_name = esc_html( $contrib_name ); 782 783 $contrib_profile = esc_url( $contrib_details['profile'] ); 784 $contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) ); 785 786 echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>"; 787 } 788 ?> 789 </ul> 790 <?php if ( ! empty( $api->donate_link ) ) { ?> 791 <a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> 792 <?php } ?> 793 <?php } ?> 794 </div> 795 <div id="section-holder"> 796 <?php 797 $requires_php = isset( $api->requires_php ) ? $api->requires_php : null; 798 $requires_wp = isset( $api->requires ) ? $api->requires : null; 799 800 $compatible_php = is_php_version_compatible( $requires_php ); 801 $compatible_wp = is_wp_version_compatible( $requires_wp ); 802 $tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) ); 803 804 if ( ! $compatible_php ) { 805 echo '<div class="notice notice-error notice-alt"><p>'; 806 _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' ); 807 if ( current_user_can( 'update_php' ) ) { 808 printf( 809 /* translators: %s: URL to Update PHP page. */ 810 ' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ), 811 esc_url( wp_get_update_php_url() ) 812 ); 813 814 wp_update_php_annotation( '</p><p><em>', '</em>' ); 815 } else { 816 echo '</p>'; 817 } 818 echo '</div>'; 819 } 820 821 if ( ! $tested_wp ) { 822 echo '<div class="notice notice-warning notice-alt"><p>'; 823 _e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ); 824 echo '</p></div>'; 825 } elseif ( ! $compatible_wp ) { 826 echo '<div class="notice notice-error notice-alt"><p>'; 827 _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' ); 828 if ( current_user_can( 'update_core' ) ) { 829 printf( 830 /* translators: %s: URL to WordPress Updates screen. */ 831 ' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ), 832 self_admin_url( 'update-core.php' ) 833 ); 834 } 835 echo '</p></div>'; 836 } 837 838 foreach ( (array) $api->sections as $section_name => $content ) { 839 $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); 840 $content = links_add_target( $content, '_blank' ); 841 842 $san_section = esc_attr( $section_name ); 843 844 $display = ( $section_name === $section ) ? 'block' : 'none'; 845 846 echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; 847 echo $content; 848 echo "\t</div>\n"; 849 } 850 echo "</div>\n"; 851 echo "</div>\n"; 852 echo "</div>\n"; // #plugin-information-scrollable 853 echo "<div id='$tab-footer'>\n"; 854 if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { 855 $status = install_plugin_install_status( $api ); 856 switch ( $status['status'] ) { 857 case 'install': 858 if ( $status['url'] ) { 859 if ( $compatible_php && $compatible_wp ) { 860 echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>'; 861 } else { 862 printf( 863 '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>', 864 _x( 'Cannot Install', 'plugin' ) 865 ); 866 } 867 } 868 break; 869 case 'update_available': 870 if ( $status['url'] ) { 871 if ( $compatible_php ) { 872 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>'; 873 } else { 874 printf( 875 '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>', 876 _x( 'Cannot Update', 'plugin' ) 877 ); 878 } 879 } 880 break; 881 case 'newer_installed': 882 /* translators: %s: Plugin version. */ 883 echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), esc_html( $status['version'] ) ) . '</a>'; 884 break; 885 case 'latest_installed': 886 echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>'; 887 break; 888 } 889 } 890 echo "</div>\n"; 891 892 iframe_footer(); 893 exit; 894} 895