Browse Source

Expiring the oEmbed cache

widget
Lee Willis 12 years ago
parent
commit
6fc8ae05bb
  1. 3
      README.md
  2. 38
      github-embed.php
  3. 6
      readme.txt

3
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

38
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

6
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,6 +43,10 @@ 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

Loading…
Cancel
Save