wp_dashboard_plugins_output

Display plugins text for the WordPress news widget.

Description

wp_dashboard_plugins_output( (string) $rss, (array) $args = array() ); 

Parameters (2)

0. $rss (string)
The RSS feed URL.
1. $args — Optional. (array) => array()
Array of arguments for this RSS feed.

Usage

  1. if ( !function_exists( 'wp_dashboard_plugins_output' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4. // The RSS feed URL. 
  5. $rss = ''; 
  6.  
  7. // Array of arguments for this RSS feed. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_dashboard_plugins_output($rss, $args); 
  12.  

Defined (1)

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

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_plugins_output( $rss, $args = array() ) { 
  2. // Plugin feeds plus link to install them 
  3. $popular = fetch_feed( $args['url']['popular'] ); 
  4.  
  5. if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) { 
  6. $plugin_slugs = array_keys( get_plugins() ); 
  7. set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS ); 
  8.  
  9. echo '<ul>'; 
  10.  
  11. foreach ( array( $popular ) as $feed ) { 
  12. if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() ) 
  13. continue; 
  14.  
  15. $items = $feed->get_items(0, 5); 
  16.  
  17. // Pick a random, non-installed plugin 
  18. while ( true ) { 
  19. // Abort this foreach loop iteration if there's no plugins left of this type 
  20. if ( 0 == count($items) ) 
  21. continue 2; 
  22.  
  23. $item_key = array_rand($items); 
  24. $item = $items[$item_key]; 
  25.  
  26. list($link, $frag) = explode( '#', $item->get_link() ); 
  27.  
  28. $link = esc_url($link); 
  29. if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) ) 
  30. $slug = $matches[1]; 
  31. else { 
  32. unset( $items[$item_key] ); 
  33. continue; 
  34.  
  35. // Is this random plugin's slug already installed? If so, try again. 
  36. reset( $plugin_slugs ); 
  37. foreach ( $plugin_slugs as $plugin_slug ) { 
  38. if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) { 
  39. unset( $items[$item_key] ); 
  40. continue 2; 
  41.  
  42. // If we get to this point, then the random plugin isn't installed and we can stop the while(). 
  43. break; 
  44.  
  45. // Eliminate some common badly formed plugin descriptions 
  46. while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) ) 
  47. unset($items[$item_key]); 
  48.  
  49. if ( !isset($items[$item_key]) ) 
  50. continue; 
  51.  
  52. $raw_title = $item->get_title(); 
  53.  
  54. $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800'; 
  55. echo '<li class="dashboard-news-plugin"><span>' . __( 'Popular Plugin' ) . ':</span> ' . esc_html( $raw_title ) . 
  56. ' <a href="' . $ilink . '" class="thickbox open-plugin-details-modal" aria-label="' . 
  57. /** translators: %s: plugin name */ 
  58. esc_attr( sprintf( __( 'Install %s' ), $raw_title ) ) . '">(' . __( 'Install' ) . ')</a></li>'; 
  59.  
  60. $feed->__destruct(); 
  61. unset( $feed ); 
  62.  
  63. echo '</ul>';