Displays a human readable HTML representation of the difference between two strings.
Description
The Diff is available for getting the changes between versions. The output is HTML, so the primary use is for displaying the changes. If the two strings are equivalent, then an empty string will be returned.
See also
- wp_parse_args(): Used to change defaults to user defined settings.
Parameters
$left_string
stringrequired- "old" (left) version of string.
$right_string
stringrequired- "new" (right) version of string.
$args
string|arrayoptional- Associative array of options to pass to WP_Text_Diff_Renderer_Table().
title
stringTitles the diff in a manner compatible with the output. Default empty.title_left
stringChange the HTML to the left of the title.
Default empty.title_right
stringChange the HTML to the right of the title.
Default empty.show_split_view
boolTrue for split view (two columns), false for un-split view (single column). Default true.
Default:
null
Source
$args = array_merge( $args, $loading_optimization_attr );
if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
$id_or_email = get_comment( $id_or_email );
}
/**
* Allows the HTML for a user's avatar to be returned early.
*
* Returning a non-null value will effectively short-circuit get_avatar(), passing
* the value through the 'get_avatar' filter and returning early.
*
* @since 4.2.0
*
* @param string|null $avatar HTML for the user's avatar. Default null.
* @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* @param array $args Arguments passed to get_avatar_url(), after processing.
*/
$avatar = apply_filters( 'pre_get_avatar', null, $id_or_email, $args );
if ( ! is_null( $avatar ) ) {
/** This filter is documented in wp-includes/pluggable.php */
return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args );
}
if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) {
return false;
}
$url2x = get_avatar_url( $id_or_email, array_merge( $args, array( 'size' => $args['size'] * 2 ) ) );
$args = get_avatar_data( $id_or_email, $args );
$url = $args['url'];
if ( ! $url || is_wp_error( $url ) ) {
return false;
}
$class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' );
if ( ! $args['found_avatar'] || $args['force_default'] ) {
$class[] = 'avatar-default';
}
if ( $args['class'] ) {
if ( is_array( $args['class'] ) ) {
$class = array_merge( $class, $args['class'] );
} else {
$class[] = $args['class'];
}
}
// Add `loading`, `fetchpriority`, and `decoding` attributes.
$extra_attr = $args['extra_attr'];
if ( in_array( $args['loading'], array( 'lazy', 'eager' ), true )
&& ! preg_match( '/\bloading\s*=/', $extra_attr )
Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |
Example
This will output the following html:
[html]
<table class="diff">
<colgroup>
<col class="ltype">
<col class="content">
<col class="ltype">
<col class="content">
</colgroup>
<thead>
<tr class="diff-title">
<th colspan="4">Differences</th>
</tr>
<tr class="diff-sub-title">
<td></td>
<th>Old Version</th>
<td></td>
<th>New version</th>
</tr>
</thead>
<tbody>
<tr>
<td>-</td>
<td class="diff-deletedline">
This is the <del>original</del> string
</td>
<td>+</td>
<td class="diff-addedline">
This is the <ins>revised</ins> string
</td>
</tr>
</tbody>
</table>
[/html]