Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Debug RSS Widgets Cache
- Version: 0.1
- Plugin URI: http://ru.forums.wordpress.org/topic/21580
- Description: Allows to see when the RSS widgets cache expires.
- Author: Sergey Biryukov
- Author URI: http://profiles.wordpress.org/sergeybiryukov/
- */
- function drwc_dashboard_widget() {
- require_once( ABSPATH . WPINC . '/class-feed.php' );
- $rss_widget = new WP_Widget_RSS();
- $instances = $rss_widget->get_settings();
- ?>
- <p>Current time: <?php echo date_i18n( 'd.m.Y H:i:s' ); ?></p>
- <?php if ( ! empty( $instances ) ) : ?>
- <table id="rss-cache" cellspacing="0">
- <tr>
- <th>URL</th>
- <th>Cache Status</th>
- </tr>
- <?php
- foreach ( (array) $instances as $instance ) :
- $feed = new SimplePie();
- $feed->set_feed_url( $instance['url'] );
- $feed->set_cache_class( 'WP_Feed_Cache' );
- $feed->set_file_class( 'WP_SimplePie_File' );
- $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 43200, $instance['url'] ) );
- do_action_ref_array( 'wp_feed_options', array( &$feed, $instance['url'] ) );
- $cache_status = 'Unknown';
- if ( ! $feed->cache ) {
- $cache_status = 'Disabled';
- } else {
- $cache = call_user_func( array( $feed->cache_class, 'create' ), $feed->cache_location, call_user_func( $feed->cache_name_function, $feed->feed_url ), 'spc' );
- if ( $cache ) {
- if ( $cache->mtime() )
- $cache_status = 'Expires: ' . date_i18n( 'd.m.Y H:i', $cache->mtime() + $feed->cache_duration + get_option( 'gmt_offset' ) * 3600 );
- else
- $cache_status = 'Expired';
- } else {
- $cache_status = 'Could not create WP_Feed_Cache object.';
- }
- }
- ?>
- <tr>
- <td><a href="<?php echo esc_url( $instance['url'] ); ?>"><?php echo $instance['url']; ?></a></td>
- <td><?php echo $cache_status; ?></td>
- </tr>
- <?php
- endforeach;
- ?>
- </table>
- <?php else : ?>
- <p>No RSS widgets found.</p>
- <?php endif; ?>
- <?php
- }
- function drwc_dashboard_widget_style() { ?>
- <style type="text/css">
- #rss-cache {
- width: 100%;
- }
- #rss-cache th {
- font-size: 12px;
- text-align: left;
- padding-bottom: 12px;
- }
- </style>
- <?php
- }
- add_action( 'admin_head-index.php', 'drwc_dashboard_widget_style' );
- function drwc_add_dashboard_widget() {
- wp_add_dashboard_widget( 'rss_cache', 'RSS Widgets Cache', 'drwc_dashboard_widget' );
- }
- add_action( 'wp_dashboard_setup', 'drwc_add_dashboard_widget' );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement