WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/14/2012 09:53:11 PM (7 years ago)
Author:
azaozz
Message:

Add support for line breaks to the caption textareas, see #18311

File:
1 edited

Legend:

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

    r20168 r20174  
    145145    $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
    146146
    147     if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
     147    if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
    148148        return $html;
    149149
    150150    $width = $matches[1];
    151151
    152     // look only for html tags with attributes
    153     $caption = preg_replace_callback( '/<[a-zA-Z0-9]+ [^<>]+>/', '_cleanup_image_add_caption', $caption );
    154     $caption = str_replace( '"', '&quot;', $caption );
     152    $caption = str_replace( array("\r\n", "\r"), "\n", $caption);
     153    $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
     154    $caption = preg_replace( '/\n+/', '<br />', str_replace('"', '&quot;', $caption) );
    155155
    156156    $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
     
    168168function _cleanup_image_add_caption($str) {
    169169    if ( isset($str[0]) ) {
     170        // remove any line breaks from inside the tags
     171        $s = preg_replace( '/[\r\n\t]+/', ' ', $str[0]);
    170172        // look for single quotes inside html attributes (for example in title)
    171         $s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption2', $str[0] );
     173        $s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption2', $s );
    172174        return str_replace( '"', "'", $s );
    173175    }
     
    15431545<?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
    15441546        if ( f.caption.value ) {
    1545             caption = f.caption.value.replace(/<[a-zA-Z0-9]+ [^<>]+>/g, function(a){
    1546                 a = a.replace(/="[^"]+"/, function(b){
     1547            caption = f.caption.value.replace(/\r\n|\r/g, '\n');
     1548            caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
     1549                a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){
    15471550                    return b.replace(/'/g, '&#39;');
    15481551                });
     
    15501553            });
    15511554
    1552             caption = caption.replace(/"/g, '&quot;');
     1555            caption = caption.replace(/\n+/g, '<br />').replace(/"/g, '&quot;');
    15531556        }
    15541557<?php } ?>
Note: See TracChangeset for help on using the changeset viewer.