WordPress / twentytwentyfive

72 stars 28 forks source link

Add block bindings for copyright date and privacy policy link #7

Open carolinan opened 1 month ago

carolinan commented 1 month ago

What

Add a block binding for a dynamic copyright date. Add a block binding for a link to the privacy policy page. This link should only display if the privacy policy page is published.

Why

The purpose of this task is twofold: To solve two common problems and showcase how to use the block bindings api.

Resources

https://make.wordpress.org/core/2024/03/06/new-feature-the-block-bindings-api/ https://developer.wordpress.org/news/2024/02/20/introducing-block-bindings-part-1-connecting-custom-fields/ https://developer.wordpress.org/news/2024/03/06/introducing-block-bindings-part-2-working-with-custom-binding-sources/ https://developer.wordpress.org/news/2024/05/06/building-a-book-review-site-with-block-bindings-part-1-custom-fields-and-block-variations/ https://developer.wordpress.org/news/2024/06/06/building-a-book-review-site-with-block-bindings-part-2-queries-patterns-and-templates/

justintadlock commented 1 month ago

I'd love to see this.

I'd say the one downside of the Privacy Policy is that you'll get an empty <p> on the front end if it's not published because there's no good way to do conditionals. I know there's some discussion around this here (not sure if there's a dedicated ticket, though): https://github.com/WordPress/gutenberg/issues/59272#issuecomment-2003113628

carolinan commented 1 month ago

Perhaps the paragraph could contain something more than the link, like the site title?

Let's start with the copyright info.

dballari commented 1 month ago

I think the empty p could be solved by using the empty css selector, something like this: .site-footer p:empty { display: none; } This could be added in a css section of the theme.json file

carstingaxion commented 3 weeks ago

@carolinan @justintadlock I would create a block variation for the policy link. This variation can be addressed within a pre_render_block filter to be only visible if a policy is already published and preventing the empty paragraph as a side effect.

justintadlock commented 3 weeks ago

@carstingaxion - Yep, that's a solution that I've employed in similar situations. Just not sure if that's something OK to go in a default theme or not, but I'll leave that up to folks to decide.

richtabor commented 3 weeks ago

Let's at least do the copyright. Would be a good use case others can learn from as well (and easy as it doesn't rely on conditionals).

carolinan commented 3 weeks ago

Part of it is choosing what the bound text should be, in the editor :)