Make WordPress Core

Ticket #24908: 24908.5.diff

File 24908.5.diff, 3.9 KB (added by johnbillion, 10 years ago)
  • src/wp-includes/wp-diff.php

     
    153153        public function _added( $lines, $encode = true ) {
    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";
    160177                        } else {
     
    175192        public function _deleted( $lines, $encode = true ) {
    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";
    182202                        } else {
     
    198218        public function _context( $lines, $encode = true ) {
    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";
    205228                        } else {
  • src/wp-admin/includes/revision.php

     
    7373                /** This filter is documented in wp-admin/includes/revision.php */
    7474                $content_to = apply_filters( "_wp_post_revision_field_$field", $compare_to->$field, $field, $compare_to, 'to' );
    7575
    76                 $diff = wp_text_diff( $content_from, $content_to, array( 'show_split_view' => true ) );
     76                $args = array(
     77                        'show_split_view' => false
     78                );
     79                /**
     80                 * Filter revisions text diff options.
     81                 *
     82                 * Filter the options passed to `wp_text_diff()` when viewing a post revision.
     83                 *
     84                 * @since 4.1.0
     85                 *
     86                 * @param array   $args {
     87                 *     Associative array of options to pass to `wp_text_diff()`.
     88                 *
     89                 *     @type bool $show_split_view False for split view (two columns), true for
     90                 *                                 un-split view (single column). Default false.
     91                 * }
     92                 * @param string  $field        The current revision field.
     93                 * @param WP_Post $compare_from The revision post to compare from.
     94                 * @param WP_Post $compare_to   The revision post to compare to.
     95                 */
     96                $args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
     97                $diff = wp_text_diff( $content_from, $content_to, $args );
    7798
    7899                if ( ! $diff && 'post_title' === $field ) {
    79100                        // It's a better user experience to still show the Title, even if it didn't change.