Last active
August 29, 2015 14:12
-
-
Save thefuxia/47fc50f875473ee537e6 to your computer and use it in GitHub Desktop.
Refresh the feed for the built-in RSS widget every two hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php # -*- coding: utf-8 -*- | |
/** | |
* Plugin Name: T5 Refresh RSS Widget | |
* Plugin URI: https://gist.github.com/toscho/47fc50f875473ee537e6 | |
* Description: Refresh the feed for the built-in RSS widget every two hours. | |
* Version: 03.01.15 | |
* Required: 4.0 | |
* Author: Thomas Scholz <info@toscho.de> | |
* Author URI: http://toscho.de | |
* License: MIT | |
* License URI: http://www.opensource.org/licenses/mit-license.php | |
*/ | |
add_action( 'dynamic_sidebar_before', 't5_register_rss_refresh_time' ); | |
add_action( 'dynamic_sidebar_after', 't5_unregister_rss_refresh_time' ); | |
/** | |
* Set cache time to two hours. | |
* | |
* @wp-hook wp_feed_cache_transient_lifetime | |
* @return int | |
*/ | |
function t5_change_rss_refresh_time() { | |
return 2 * HOUR_IN_SECONDS; | |
} | |
/** | |
* Register the callback for cache invalidation | |
* | |
* @wp-hook dynamic_sidebar_before | |
* @return void | |
*/ | |
function t5_register_rss_refresh_time() { | |
add_filter( | |
'wp_feed_cache_transient_lifetime', | |
't5_change_rss_refresh_time' | |
); | |
} | |
/** | |
* Unregister the callback for cache invalidation | |
* | |
* @wp-hook dynamic_sidebar_after | |
* @return void | |
*/ | |
function t5_unregister_rss_refresh_time() { | |
remove_filter( | |
'wp_feed_cache_transient_lifetime', | |
't5_change_rss_refresh_time' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment