Skip to content

Commit 76cb0ff

Browse files
Mamadukayogeshbhutkartalldant-hamanoajaxStardust
authored
Categories: Disable links in the editor (#70896)
Co-authored-by: Mamaduka <[email protected]> Co-authored-by: yogeshbhutkar <[email protected]> Co-authored-by: talldan <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: ajaxStardust <[email protected]> Co-authored-by: sabernhardt <[email protected]>
1 parent b94e18a commit 76cb0ff

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/block-library/src/categories/edit.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { decodeEntities } from '@wordpress/html-entities';
2525
import { __, sprintf } from '@wordpress/i18n';
2626
import { pin } from '@wordpress/icons';
2727
import { useEntityRecords } from '@wordpress/core-data';
28+
import { useDispatch } from '@wordpress/data';
29+
import { store as noticeStore } from '@wordpress/notices';
2830

2931
/**
3032
* Internal dependencies
@@ -44,6 +46,7 @@ export default function CategoriesEdit( {
4446
},
4547
setAttributes,
4648
className,
49+
clientId,
4750
} ) {
4851
const selectId = useInstanceId( CategoriesEdit, 'blocks-category-select' );
4952

@@ -70,6 +73,15 @@ export default function CategoriesEdit( {
7073
query
7174
);
7275

76+
const { createWarningNotice } = useDispatch( noticeStore );
77+
const showRedirectionPreventedNotice = ( event ) => {
78+
event.preventDefault();
79+
createWarningNotice( __( 'Links are disabled in the editor.' ), {
80+
id: `block-library/core/categories/redirection-prevented/${ clientId }`,
81+
type: 'snackbar',
82+
} );
83+
};
84+
7385
const getCategoriesList = ( parentId ) => {
7486
if ( ! categories?.length ) {
7587
return [];
@@ -99,7 +111,7 @@ export default function CategoriesEdit( {
99111
const { id, link, count, name } = category;
100112
return (
101113
<li key={ id } className={ `cat-item cat-item-${ id }` }>
102-
<a href={ link } target="_blank" rel="noreferrer noopener">
114+
<a href={ link } onClick={ showRedirectionPreventedNotice }>
103115
{ renderCategoryName( name ) }
104116
</a>
105117
{ showPostCounts && ` (${ count })` }

packages/block-library/src/latest-posts/edit.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,6 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
774774
{ addLinkToFeaturedImage ? (
775775
<a
776776
href={ post.link }
777-
rel="noreferrer noopener"
778777
onClick={
779778
showRedirectionPreventedNotice
780779
}
@@ -789,7 +788,6 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
789788
<a
790789
className="wp-block-latest-posts__post-title"
791790
href={ post.link }
792-
rel="noreferrer noopener"
793791
dangerouslySetInnerHTML={
794792
!! titleTrimmed
795793
? {

0 commit comments

Comments
 (0)