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