wp_dashboard_cached_rss_widget

Checks to see if all of the feed url in $check_urls are cached.

Description

wp_dashboard_cached_rss_widget( (string) $widget_id, (callable) $callback, (array) $check_urls = array() ); 

If $check_urls is empty, look for the rss feed url found in the dashboard widget options of $widget_id. If cached, call $callback, a function that echoes out output for this widget. If not cache, echo a Loading... stub which is later replaced by Ajax call (see top of /wp-admin/index.php)

Parameters (3)

0. $widget_id (string)
The widget id.
1. $callback (callable)
The callback.
2. $check_urls — Optional. (array) => array()
The check urls.

Usage

  1. if ( !function_exists( 'wp_dashboard_cached_rss_widget' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4. // The widget id. 
  5. $widget_id = ''; 
  6.  
  7. // The callback. 
  8. $callback = null; 
  9.  
  10. // The check urls. 
  11. $check_urls = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_dashboard_cached_rss_widget($widget_id, $callback, $check_urls); 
  15.  

Defined (1)

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

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) { 
  2. $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>'; 
  3. $doing_ajax = wp_doing_ajax(); 
  4.  
  5. if ( empty($check_urls) ) { 
  6. $widgets = get_option( 'dashboard_widget_options' ); 
  7. if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) { 
  8. echo $loading; 
  9. return false; 
  10. $check_urls = array( $widgets[$widget_id]['url'] ); 
  11.  
  12. $locale = get_locale(); 
  13. $cache_key = 'dash_' . md5( $widget_id . '_' . $locale ); 
  14. if ( false !== ( $output = get_transient( $cache_key ) ) ) { 
  15. echo $output; 
  16. return true; 
  17.  
  18. if ( ! $doing_ajax ) { 
  19. echo $loading; 
  20. return false; 
  21.  
  22. if ( $callback && is_callable( $callback ) ) { 
  23. $args = array_slice( func_get_args(), 3 ); 
  24. array_unshift( $args, $widget_id, $check_urls ); 
  25. ob_start(); 
  26. call_user_func_array( $callback, $args ); 
  27. set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds) 
  28.  
  29. return true;