Advertisement
SergeyBiryukov

Debug RSS Widgets Cache

Jul 19th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Debug RSS Widgets Cache
  4. Version: 0.1
  5. Plugin URI: http://ru.forums.wordpress.org/topic/21580
  6. Description: Allows to see when the RSS widgets cache expires.
  7. Author: Sergey Biryukov
  8. Author URI: http://profiles.wordpress.org/sergeybiryukov/
  9. */
  10.  
  11. function drwc_dashboard_widget() {
  12.     require_once( ABSPATH . WPINC . '/class-feed.php' );
  13.  
  14.     $rss_widget = new WP_Widget_RSS();
  15.     $instances = $rss_widget->get_settings();
  16. ?>
  17. <p>Current time: <?php echo date_i18n( 'd.m.Y H:i:s' ); ?></p>
  18. <?php if ( ! empty( $instances ) ) : ?>
  19. <table id="rss-cache" cellspacing="0">
  20. <tr>
  21.     <th>URL</th>
  22.     <th>Cache Status</th>
  23. </tr>
  24. <?php
  25.     foreach ( (array) $instances as $instance ) :
  26.         $feed = new SimplePie();
  27.         $feed->set_feed_url( $instance['url'] );
  28.         $feed->set_cache_class( 'WP_Feed_Cache' );
  29.         $feed->set_file_class( 'WP_SimplePie_File' );
  30.         $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 43200, $instance['url'] ) );
  31.         do_action_ref_array( 'wp_feed_options', array( &$feed, $instance['url'] ) );
  32.  
  33.         $cache_status = 'Unknown';
  34.         if ( ! $feed->cache ) {
  35.             $cache_status = 'Disabled';
  36.         } else {
  37.             $cache = call_user_func( array( $feed->cache_class, 'create' ), $feed->cache_location, call_user_func( $feed->cache_name_function, $feed->feed_url ), 'spc' );
  38.             if ( $cache ) {
  39.                 if ( $cache->mtime() )
  40.                     $cache_status = 'Expires: ' . date_i18n( 'd.m.Y H:i', $cache->mtime() + $feed->cache_duration + get_option( 'gmt_offset' ) * 3600 );
  41.                 else
  42.                     $cache_status = 'Expired';
  43.             } else {
  44.                 $cache_status = 'Could not create WP_Feed_Cache object.';
  45.             }
  46.         }
  47. ?>
  48. <tr>
  49.     <td><a href="<?php echo esc_url( $instance['url'] ); ?>"><?php echo $instance['url']; ?></a></td>
  50.     <td><?php echo $cache_status; ?></td>
  51. </tr>
  52. <?php
  53.     endforeach;
  54. ?>
  55. </table>
  56. <?php else : ?>
  57. <p>No RSS widgets found.</p>
  58. <?php endif; ?>
  59. <?php
  60. }
  61.  
  62. function drwc_dashboard_widget_style() { ?>
  63. <style type="text/css">
  64. #rss-cache {
  65.     width: 100%;
  66. }
  67. #rss-cache th {
  68.     font-size: 12px;
  69.     text-align: left;
  70.     padding-bottom: 12px;
  71. }
  72. </style>
  73. <?php
  74. }
  75. add_action( 'admin_head-index.php', 'drwc_dashboard_widget_style' );
  76.  
  77. function drwc_add_dashboard_widget() {
  78.     wp_add_dashboard_widget( 'rss_cache', 'RSS Widgets Cache', 'drwc_dashboard_widget' );
  79. }
  80. add_action( 'wp_dashboard_setup', 'drwc_add_dashboard_widget' );
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement