From 6fc8ae05bbf1ff0d7477d36e9b84763226a7b5c4 Mon Sep 17 00:00:00 2001 From: Lee Willis Date: Wed, 13 Mar 2013 20:54:52 +0000 Subject: [PATCH] Expiring the oEmbed cache --- README.md | 3 +++ github-embed.php | 38 +++++++++++++++++++++++++++++++++++++- readme.txt | 8 ++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a2d1b63..8b64c60 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ Not yet, we're hoping to add templating - all contributions welcome! ## Changelog +- 1.3 + - Expire the oEmbed cache daily + - 1.2 - Support for milestone summaries - Support for contributor lists diff --git a/github-embed.php b/github-embed.php index 36344e7..9e762f6 100644 --- a/github-embed.php +++ b/github-embed.php @@ -4,7 +4,7 @@ Plugin Name: Github Embed Plugin URI: http://www.leewillis.co.uk/wordpress-plugins Description: Paste the URL to a Github project into your posts or pages, and have the project information pulled in and displayed automatically -Version: 1.2 +Version: 1.3 Author: Lee Willis Author URI: http://www.leewillis.co.uk/ */ @@ -56,6 +56,8 @@ class github_embed { add_action ( 'init', array ( $this, 'register_oembed_handler' ) ); add_action ( 'init', array ( $this, 'maybe_handle_oembed' ) ); add_action ( 'wp_enqueue_scripts', array ( $this, 'enqueue_styles' ) ); + add_action ( 'admin_init', array ( $this, 'schedule_expiry' ) ); + add_action ( 'github_embed_cron', array ( $this, 'cron' ) ); // @TODO i18n @@ -63,6 +65,40 @@ class github_embed { + /** + * Make sure we have a scheduled event set to clear down the oEmbed cache until + * WordPress supports cache_age in oEmbed responses. + */ + function schedule_expiry() { + + if( ! wp_next_scheduled( 'github_embed_cron' ) ) { + $frequency = apply_filters ( 'github_embed_cache_frequency', 'daily' ); + wp_schedule_event( time(), $frequency, 'github_embed_cron' ); + } + + } + + + + /** + * Expire old oEmbeds. + * Note: This is a bit sledgehammer-to-crack-a-nut hence why I'm only running it + * daily. Ideally WP should honour cache_age in oEmbed responses properly + */ + function cron() { + + global $wpdb, $table_prefix; + + $sql = "DELETE + FROM {$table_prefix}postmeta + WHERE meta_key LIKE '_oembed_%'"; + + $results = $wpdb->get_results ( $sql ); + + } + + + /** * Enqueue the frontend CSS * @return void diff --git a/readme.txt b/readme.txt index be2d377..da30964 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: http://www.leewillis.co.uk/wordpress-plugins/?utm_source=wordpress& Tags: github, embed, oembed Requires at least: 3.5 Tested up to: 3.5.1 -Stable tag: 1.2 +Stable tag: 1.3 == Description == @@ -43,9 +43,13 @@ Not yet, we're hoping to add templating - [all contributions welcome](https://gi == Changelog == += 1.3 = + +* Expire the oEmbed cache daily + = 1.2 = -* Split API calls into separate class +* Split API calls into separate class * Implement milestone summaries * Implement contributor lists