Skip to content

Commit

Permalink
Fix: Display HTML in titles of latest posts block. (#13622)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored and youknowriad committed Mar 6, 2019
1 parent 03749b3 commit 3ca7834
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { Component, Fragment } from '@wordpress/element';
import {
Component,
Fragment,
RawHTML,
} from '@wordpress/element';
import {
PanelBody,
Placeholder,
Expand All @@ -21,7 +25,6 @@ import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
import { dateI18n, format, __experimentalGetSettings } from '@wordpress/date';
import { decodeEntities } from '@wordpress/html-entities';
import {
InspectorControls,
BlockAlignmentToolbar,
Expand Down Expand Up @@ -171,16 +174,27 @@ class LatestPostsEdit extends Component {
[ `columns-${ columns }` ]: postLayout === 'grid',
} ) }
>
{ displayPosts.map( ( post, i ) =>
<li key={ i }>
<a href={ post.link } target="_blank">{ decodeEntities( post.title.rendered.trim() ) || __( '(Untitled)' ) }</a>
{ displayPostDate && post.date_gmt &&
<time dateTime={ format( 'c', post.date_gmt ) } className="wp-block-latest-posts__post-date">
{ dateI18n( dateFormat, post.date_gmt ) }
</time>
}
</li>
) }
{ displayPosts.map( ( post, i ) => {
const titleTrimmed = post.title.rendered.trim();
return (
<li key={ i }>
<a href={ post.link } target="_blank">
{ titleTrimmed ? (
<RawHTML>
{ titleTrimmed }
</RawHTML>
) :
__( '(Untitled)' )
}
</a>
{ displayPostDate && post.date_gmt &&
<time dateTime={ format( 'c', post.date_gmt ) } className="wp-block-latest-posts__post-date">
{ dateI18n( dateFormat, post.date_gmt ) }
</time>
}
</li>
);
} ) }
</ul>
</Fragment>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function render_block_core_latest_posts( $attributes ) {
$list_items_markup .= sprintf(
'<li><a href="%1$s">%2$s</a>',
esc_url( get_permalink( $post ) ),
esc_html( $title )
$title
);

if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) {
Expand Down

0 comments on commit 3ca7834

Please sign in to comment.