Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "Add new post" link text with more meaningful Label (v2) #62277

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
import { addQueryArgs } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

const CreateNewPostLink = ( {
attributes: { query: { postType } = {} } = {},
} ) => {
if ( ! postType ) {
return null;
}
const CreateNewPostLink = ( { postType } ) => {
const newPostUrl = addQueryArgs( 'post-new.php', {
post_type: postType,
} );

const addNewItemLabel = useSelect(
( select ) => {
const { getPostType } = select( coreStore );
return getPostType( postType )?.labels?.add_new_item;
},
[ postType ]
);
return (
<div className="wp-block-query__create-new-link">
{ createInterpolateElement(
__( '<a>Add new post</a>' ),
'<a>' + addNewItemLabel + '</a>',
// eslint-disable-next-line jsx-a11y/anchor-has-content
{ a: <a href={ newPostUrl } /> }
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ export default function QueryInspectorControls( props ) {

return (
<>
<BlockInfo>
<CreateNewPostLink { ...props } />
</BlockInfo>
{ !! postType && (
<BlockInfo>
<CreateNewPostLink postType={ postType } />
</BlockInfo>
) }
{ showSettingsPanel && (
<PanelBody title={ __( 'Settings' ) }>
{ showInheritControl && (
Expand Down
Loading