Make WordPress Core


Ignore:
Timestamp:
11/19/2014 11:20:07 PM (10 years ago)
Author:
johnbillion
Message:

Introduce two new filters to the post revisions screen:

  • process_text_diff_html for contextually filtering a diffed line. Allows for the line to be processed in a different manner to the default htmlspecialchars.
  • revision_text_diff_options for filtering the options passed to wp_text_diff() when viewing a post revision.

Fixes #24908
Props adamsilverstein

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-diff.php

    r30192 r30396  
    154154        $r = '';
    155155        foreach ($lines as $line) {
    156             if ( $encode )
    157                 $line = htmlspecialchars( $line );
     156            if ( $encode ) {
     157                $processed_line = htmlspecialchars( $line );
     158
     159                /**
     160                 * Contextually filter a diffed line.
     161                 *
     162                 * Filters TextDiff processing of diffed line. By default, diffs are processed with
     163                 * htmlspecialchars. Use this filter to remove or change the processing. Passes a context
     164                 * indicating if the line is added, deleted or unchanged.
     165                 *
     166                 * @since 4.1.0
     167                 *
     168                 * @param String $processed_line The processed diffed line.
     169                 * @param String $line           The unprocessed diffed line.
     170                 * @param string null            The line context. Values are 'added', 'deleted' or 'unchanged'.
     171                 */
     172                $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' );
     173            }
     174
    158175            if ( $this->_show_split_view ) {
    159176                $r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n";
     
    176193        $r = '';
    177194        foreach ($lines as $line) {
    178             if ( $encode )
    179                 $line = htmlspecialchars( $line );
     195            if ( $encode ) {
     196                $processed_line = htmlspecialchars( $line );
     197                /** This filter is documented in wp-includes/wp-diff.php */
     198                $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'deleted' );
     199            }
    180200            if ( $this->_show_split_view ) {
    181201                $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "</tr>\n";
     
    199219        $r = '';
    200220        foreach ($lines as $line) {
    201             if ( $encode )
    202                 $line = htmlspecialchars( $line );
     221            if ( $encode ) {
     222                $processed_line = htmlspecialchars( $line );
     223                /** This filter is documented in wp-includes/wp-diff.php */
     224                $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'unchanged' );
     225            }
    203226            if (  $this->_show_split_view ) {
    204227                $r .= '<tr>' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line )  . "</tr>\n";
Note: See TracChangeset for help on using the changeset viewer.