Skip to content

Commit

Permalink
Add an image URL handler
Browse files Browse the repository at this point in the history
Converts lone image URLs to image tags.

Fixes #39.
  • Loading branch information
nb committed Dec 26, 2012
1 parent b28723f commit 186ea96
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions liveblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static function load() {
self::add_actions();
self::add_filters();
self::add_admin_actions();
self::register_embed_handlers();
}

/**
Expand Down Expand Up @@ -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 ********************************************************/

/**
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 186ea96

Please sign in to comment.