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

feat: Added command to set featured image #57335

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

singhakanshu00
Copy link
Contributor

What?

  • Creating a command to set the featured image of the post and pages

  • Used useCommand hook from @wordpress/commands package to create the command.

Why?

  • Setting featured image using direct command instead of manually following the below steps:

    • Click on “post” in the sidebar.
    • Scroll down.
    • Click on “Set Featured Image”.
    • Pick whether I want to select or upload.

How?

  • This PR addresses Issue

Testing Instructions

  • In the post editor open command palette.
  • Search 'Select Featured Image'.
  • Media dialog box will appear asking to select the featured image.
  • On selecting, it will edit/add a featured image.

Testing Instructions for Keyboard

  • In the post editor press cmd + k or ctrl + k to open command palette.

Screenshots or screencast

featured-image.mp4

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 22, 2023
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @singhakanshu00! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@dsas dsas requested a review from youknowriad February 8, 2024 17:23
@dsas dsas added the [Type] Enhancement A suggestion for improvement. label Feb 8, 2024
@youknowriad youknowriad requested review from a team and oandregal and removed request for a team February 12, 2024 08:53
@mtias mtias added the [Package] Commands /packages/commands label Feb 12, 2024
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @singhakanshu00! Maybe someone with more knowledge at the media upload flow could help more, but here are some first thoughts:

  1. The command should not be available when a user has no permissions to upload/set a featured image, or a theme has disabled the support for featured images, or a post type doesn't support them(see PostFeaturedImageCheck).
  2. I'm not sure how we could use(either reuse or add any missing things) from media utils package. Here is the code for unstableFeaturedImageFlow
  3. In the current state of this PR, the media library also shows other type of files(audio, etc..), besides images.

Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Alongside what @ntsekouras mentioned, ideally we should not rely on the global state since there are utils which are incorporated into Gutenberg's framework which are used specifically in the set featured image control that this command emulates. The behaviour and implementation should be very similar.

See packages/editor/src/components/post-featured-image/index.js.

Following that route of implementation will also solve some of the issues above (permissions, media library setup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Commands /packages/commands [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants