Make WordPress Core


Ignore:
Timestamp:
07/02/2008 06:41:11 PM (18 years ago)
Author:
ryan
Message:

Image captions from azaozz. see #6812

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r8201 r8239  
    6262    return $html;
    6363}
     64
     65function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
     66
     67    if ( empty($alt) ) return $html;
     68    $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
     69
     70    preg_match( '/width="([0-9]+)/', $html, $matches );
     71    if ( ! isset($matches[1]) ) return $html;
     72    $width = $matches[1];
     73
     74    $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
     75    if ( empty($align) ) $align = 'none';
     76
     77    $shcode = '[wp_caption id="' . $id . '" align="align' . $align
     78    . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/wp_caption]';
     79
     80    return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
     81}
     82add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
    6483
    6584function media_send_to_editor($html) {
Note: See TracChangeset for help on using the changeset viewer.