install_plugin_information

Display plugin information in dialog box form.

Description

install_plugin_information(); 

Usage

  1. if ( !function_exists( 'install_plugin_information' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/plugin-install.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = install_plugin_information(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/plugin-install.php  
  1. function install_plugin_information() { 
  2. global $tab; 
  3.  
  4. if ( empty( $_REQUEST['plugin'] ) ) { 
  5. return; 
  6.  
  7. $api = plugins_api( 'plugin_information', array( 
  8. 'slug' => wp_unslash( $_REQUEST['plugin'] ),  
  9. 'is_ssl' => is_ssl(),  
  10. 'fields' => array( 
  11. 'banners' => true,  
  12. 'reviews' => true,  
  13. 'downloaded' => false,  
  14. 'active_installs' => true 
  15. ) ); 
  16.  
  17. if ( is_wp_error( $api ) ) { 
  18. wp_die( $api ); 
  19.  
  20. $plugins_allowedtags = array( 
  21. 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),  
  22. 'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ),  
  23. 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),  
  24. 'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ),  
  25. 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),  
  26. 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),  
  27. 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ) 
  28. ); 
  29.  
  30. $plugins_section_titles = array( 
  31. 'description' => _x( 'Description', 'Plugin installer section title' ),  
  32. 'installation' => _x( 'Installation', 'Plugin installer section title' ),  
  33. 'faq' => _x( 'FAQ', 'Plugin installer section title' ),  
  34. 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),  
  35. 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),  
  36. 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),  
  37. 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ) 
  38. ); 
  39.  
  40. // Sanitize HTML 
  41. foreach ( (array) $api->sections as $section_name => $content ) { 
  42. $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags ); 
  43.  
  44. foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { 
  45. if ( isset( $api->$key ) ) { 
  46. $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); 
  47.  
  48. $_tab = esc_attr( $tab ); 
  49.  
  50. $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English. 
  51. if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { 
  52. $section_titles = array_keys( (array) $api->sections ); 
  53. $section = reset( $section_titles ); 
  54.  
  55. iframe_header( __( 'Plugin Install' ) ); 
  56.  
  57. $_with_banner = ''; 
  58.  
  59. if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { 
  60. $_with_banner = 'with-banner'; 
  61. $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; 
  62. $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; 
  63. ?> 
  64. <style type="text/css"> 
  65. #plugin-information-title.with-banner { 
  66. background-image: url( <?php echo esc_url( $low ); ?> ); 
  67. @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) { 
  68. #plugin-information-title.with-banner { 
  69. background-image: url( <?php echo esc_url( $high ); ?> ); 
  70. </style> 
  71. <?php 
  72.  
  73. echo '<div id="plugin-information-scrollable">'; 
  74. echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; 
  75. echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; 
  76.  
  77. foreach ( (array) $api->sections as $section_name => $content ) { 
  78. if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { 
  79. continue; 
  80.  
  81. if ( isset( $plugins_section_titles[ $section_name ] ) ) { 
  82. $title = $plugins_section_titles[ $section_name ]; 
  83. } else { 
  84. $title = ucwords( str_replace( '_', ' ', $section_name ) ); 
  85.  
  86. $class = ( $section_name === $section ) ? ' class="current"' : ''; 
  87. $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) ); 
  88. $href = esc_url( $href ); 
  89. $san_section = esc_attr( $section_name ); 
  90. echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; 
  91.  
  92. echo "</div>\n"; 
  93.  
  94. ?> 
  95. <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'> 
  96. <div class="fyi"> 
  97. <ul> 
  98. <?php if ( ! empty( $api->version ) ) { ?> 
  99. <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li> 
  100. <?php } if ( ! empty( $api->author ) ) { ?> 
  101. <li><strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?></li> 
  102. <?php } if ( ! empty( $api->last_updated ) ) { ?> 
  103. <li><strong><?php _e( 'Last Updated:' ); ?></strong> 
  104. <?php 
  105. /** translators: %s: Time since the last update */ 
  106. printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); 
  107. ?> 
  108. </li> 
  109. <?php } if ( ! empty( $api->requires ) ) { ?> 
  110. <li> 
  111. <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> 
  112. <?php 
  113. /** translators: %s: WordPress version */ 
  114. printf( __( '%s or higher' ), $api->requires ); 
  115. ?> 
  116. </li> 
  117. <?php } if ( ! empty( $api->tested ) ) { ?> 
  118. <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li> 
  119. <?php } if ( isset( $api->active_installs ) ) { ?> 
  120. <li><strong><?php _e( 'Active Installs:' ); ?></strong> <?php 
  121. if ( $api->active_installs >= 1000000 ) { 
  122. _ex( '1+ Million', 'Active plugin installs' ); 
  123. } elseif ( 0 == $api->active_installs ) { 
  124. _ex( 'Less Than 10', 'Active plugin installs' ); 
  125. } else { 
  126. echo number_format_i18n( $api->active_installs ) . '+'; 
  127. ?></li> 
  128. <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?> 
  129. <li><a target="_blank" href="<?php echo __( 'https://wordpress.org/plugins/' ) . $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a></li> 
  130. <?php } if ( ! empty( $api->homepage ) ) { ?> 
  131. <li><a target="_blank" href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage »' ); ?></a></li> 
  132. <?php } if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?> 
  133. <li><a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a></li> 
  134. <?php } ?> 
  135. </ul> 
  136. <?php if ( ! empty( $api->rating ) ) { ?> 
  137. <h3><?php _e( 'Average Rating' ); ?></h3> 
  138. <?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?> 
  139. <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> 
  140. <?php } 
  141.  
  142. if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { ?> 
  143. <h3><?php _e( 'Reviews' ); ?></h3> 
  144. <p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p> 
  145. <?php 
  146. foreach ( $api->ratings as $key => $ratecount ) { 
  147. // Avoid div-by-zero. 
  148. $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; 
  149. /** translators: 1: number of stars (used to determine singular/plural), 2: number of reviews */ 
  150. $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 ),  
  151. $key,  
  152. number_format_i18n( $ratecount ) 
  153. ) ); 
  154. ?> 
  155. <div class="counter-container"> 
  156. <span class="counter-label"><a href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>" 
  157. target="_blank" aria-label="<?php echo $aria_label; ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span> 
  158. <span class="counter-back"> 
  159. <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span> 
  160. </span> 
  161. <span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span> 
  162. </div> 
  163. <?php 
  164. if ( ! empty( $api->contributors ) ) { ?> 
  165. <h3><?php _e( 'Contributors' ); ?></h3> 
  166. <ul class="contributors"> 
  167. <?php 
  168. foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) { 
  169. if ( empty( $contrib_username ) && empty( $contrib_profile ) ) { 
  170. continue; 
  171. if ( empty( $contrib_username ) ) { 
  172. $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile ); 
  173. $contrib_username = sanitize_user( $contrib_username ); 
  174. if ( empty( $contrib_profile ) ) { 
  175. echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' alt='' />{$contrib_username}</li>"; 
  176. } else { 
  177. echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' alt='' />{$contrib_username}</a></li>"; 
  178. ?> 
  179. </ul> 
  180. <?php if ( ! empty( $api->donate_link ) ) { ?> 
  181. <a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> 
  182. <?php } ?> 
  183. <?php } ?> 
  184. </div> 
  185. <div id="section-holder" class="wrap"> 
  186. <?php 
  187. $wp_version = get_bloginfo( 'version' ); 
  188.  
  189. if ( ! empty( $api->tested ) && version_compare( substr( $wp_version, 0, strlen( $api->tested ) ), $api->tested, '>' ) ) { 
  190. echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.' ) . '</p></div>'; 
  191. } elseif ( ! empty( $api->requires ) && version_compare( substr( $wp_version, 0, strlen( $api->requires ) ), $api->requires, '<' ) ) { 
  192. echo '<div class="notice notice-warning notice-alt"><p>' . __( '<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.' ) . '</p></div>'; 
  193.  
  194. foreach ( (array) $api->sections as $section_name => $content ) { 
  195. $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); 
  196. $content = links_add_target( $content, '_blank' ); 
  197.  
  198. $san_section = esc_attr( $section_name ); 
  199.  
  200. $display = ( $section_name === $section ) ? 'block' : 'none'; 
  201.  
  202. echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; 
  203. echo $content; 
  204. echo "\t</div>\n"; 
  205. echo "</div>\n"; 
  206. echo "</div>\n"; 
  207. echo "</div>\n"; // #plugin-information-scrollable 
  208. echo "<div id='$tab-footer'>\n"; 
  209. if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { 
  210. $status = install_plugin_install_status( $api ); 
  211. switch ( $status['status'] ) { 
  212. case 'install': 
  213. if ( $status['url'] ) { 
  214. 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>'; 
  215. break; 
  216. case 'update_available': 
  217. if ( $status['url'] ) { 
  218. 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>'; 
  219. break; 
  220. case 'newer_installed': 
  221. /** translators: %s: Plugin version */ 
  222. echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed'), $status['version'] ) . '</a>'; 
  223. break; 
  224. case 'latest_installed': 
  225. echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>'; 
  226. break; 
  227. echo "</div>\n"; 
  228.  
  229. exit;