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

Output post classes in the editor #60642

Merged
merged 9 commits into from
May 1, 2024

Conversation

huubl
Copy link
Contributor

@huubl huubl commented Apr 10, 2024

What?

This pull request addresses issue #33887 (and I think #10640 is related to this) by introducing post classes within the query loop in the Gutenberg editor.

Note:
I would like to know if the approach in this pull request is in the right redirection.

Why?

This allows users to target specific elements and apply custom styles to them.

How?

Extends the WordPress REST API to include post classes in the response data for all public post types.

Alternatives

  • Alternative using a new REST API route to retrieve CSS classes of a specific post: #60645

  • Recreating all the classes in JS along with a JS filter could be an alternative solution.

Testing Instructions

Insert a Query block and observe the post classes added next to the wp-post-block class in the block inspector.

Testing Instructions for Keyboard

--

Screenshots or screencast

image

@huubl huubl requested a review from ajitbohra as a code owner April 10, 2024 20:35
Copy link

github-actions bot commented Apr 10, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: huubl <huubl@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: TimothyBJacobs <timothyblynjacobs@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @huubl! In case you missed it, we'd love to have you join us in our Slack community.

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

@huubl huubl force-pushed the post-class-in-editor branch from 39d01bf to d8e437c Compare April 10, 2024 21:15
@huubl huubl requested a review from spacedmonkey as a code owner April 11, 2024 08:24
@ntsekouras ntsekouras added Core REST API Task Task for Core REST API efforts [Type] Enhancement A suggestion for improvement. labels Apr 16, 2024
lib/rest-api.php Outdated Show resolved Hide resolved
lib/rest-api.php Outdated Show resolved Hide resolved
@TimothyBJacobs
Copy link
Member

My main flag here is that get_post_class calls template tags functions like is_home that won't be reliable when used over the REST API.

That being said, I don't think that's a blocker since this is a well known property of the REST API already.

@TimothyBJacobs
Copy link
Member

Thanks for making those changes! This looks good to me from a REST API perspective.

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.

Thanks @huubl! I've left a couple of small comment where we can simplify and it should be good to land.

packages/block-library/src/post-template/edit.js Outdated Show resolved Hide resolved
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! Let's 🚢

@ntsekouras ntsekouras merged commit 907c8b1 into WordPress:trunk May 1, 2024
63 of 64 checks passed
@ntsekouras ntsekouras added the Needs PHP backport Needs PHP backport to Core label May 1, 2024
@github-actions github-actions bot added this to the Gutenberg 18.3 milestone May 1, 2024
@ellatrix
Copy link
Member

ellatrix commented May 1, 2024

What happens when you change categories etc.? These things don't remain constant in the editor like they do on the front-end.

@ntsekouras
Copy link
Contributor

What happens when you change categories etc.? These things don't remain constant in the editor like they do on the front-end.

What do you mean? Classes are applied from REST API using get_post_class, same as we do in front end, as it's a dynamic block. Do you have a specific use case that something is wrong?

@ellatrix
Copy link
Member

ellatrix commented May 1, 2024

If you edit a post and change the categories, the generated classes for these categories should change too? Same for status, featured image and a lot of these properties.

@ellatrix
Copy link
Member

ellatrix commented May 1, 2024

Ah, if this is just for the query block and not for editable content in a template, then I guess it's not relevant. At some point we'll have to apply this class outside the query block as well and make it dynamic.

@youknowriad
Copy link
Contributor

The query block can be dynamic as well, it can show posts that are "dirty". So this is more of an escape hatch I would say.

@huubl huubl deleted the post-class-in-editor branch May 2, 2024 20:23
@ntsekouras
Copy link
Contributor

it can show posts that are "dirty".

@youknowriad what do you mean with this?

@youknowriad
Copy link
Contributor

@ntsekouras I mean posts with unsaved changes.

@ellatrix
Copy link
Member

ellatrix commented Jun 3, 2024

@anton-vlasenko or @TimothyBJacobs Would it be possible to make a backport PR for this?

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Jun 4, 2024
See WordPress/gutenberg#60642.
See #6716.

Fixes #61360.

Props antonvlasenko, timothyblynjacobs, ellatrix, oandregal.



git-svn-id: https://develop.svn.wordpress.org/trunk@58326 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jun 4, 2024
See WordPress/gutenberg#60642.
See WordPress/wordpress-develop#6716.

Fixes #61360.

Props antonvlasenko, timothyblynjacobs, ellatrix, oandregal.


Built from https://develop.svn.wordpress.org/trunk@58326


git-svn-id: http://core.svn.wordpress.org/trunk@57783 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Jun 4, 2024
See WordPress/gutenberg#60642.
See WordPress/wordpress-develop#6716.

Fixes #61360.

Props antonvlasenko, timothyblynjacobs, ellatrix, oandregal.


Built from https://develop.svn.wordpress.org/trunk@58326


git-svn-id: https://core.svn.wordpress.org/trunk@57783 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core REST API Task Task for Core REST API efforts First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository Needs PHP backport Needs PHP backport to Core [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants