Permalink
Browse files

Add an image URL handler

Converts lone image URLs to image tags.

Fixes #39.
  • Loading branch information...
nb committed Dec 26, 2012
1 parent b28723f commit 186ea96e331d25be5984ab573a5ec17cc5a988d5
Showing with 11 additions and 0 deletions.
  1. +11 −0 liveblog.php
View
@@ -65,6 +65,7 @@ public static function load() {
self::add_actions();
self::add_filters();
self::add_admin_actions();
+ self::register_embed_handlers();
}
/**
@@ -126,6 +127,11 @@ private static function add_admin_actions() {
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_box' ) );
}
+ private static function register_embed_handlers() {
+ // register it to run later, because the regex is pretty general and we don't want it to prevent more specific handlers from running
+ wp_embed_register_handler( 'liveblog_image', '/\.(png|jpe?g|gif)(\?.*)?$/', array( 'WPCOM_Liveblog', 'image_embed_handler' ), 99 );
+ }
+
/** Public Methods ********************************************************/
/**
@@ -613,6 +619,11 @@ public static function add_meta_box( $post_type ) {
add_meta_box( self::key, __( 'Liveblog', 'liveblog' ), array( __CLASS__, 'display_meta_box' ) );
}
+ public static function image_embed_handler( $matches, $attr, $url, $rawattr ) {
+ $embed = sprintf( '<img src="%s" alt="" />', esc_url( $url ) );
+ return apply_filters( 'embed_liveblog_image', $embed, $matches, $attr, $url, $rawattr );
+ }
+
/**
* Output the metabox
*

0 comments on commit 186ea96

Please sign in to comment.