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

Add post count to dynamic block output #205

Conversation

salcode
Copy link
Contributor

@salcode salcode commented Mar 28, 2022

Add post count to dynamic block output to demonstrate how values can be
included in the block output that are updated without updating the post
itself.

Resolves #203

Before PR

Hello from a dynamic block!

image

After PR

Hello from a dynamic block! on a blog with 2 published posts

where the number 2 is dynamically generated based on how many posts have been published on this blog

image

Add post count to dynamic block output to demonstrate how values can be
included in the block output that are updated without updating the post
itself.

Resolves WordPress#203
@salcode salcode marked this pull request as ready for review March 28, 2022 19:35
Copy link
Contributor

@ryanwelcher ryanwelcher 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 taking the time to put this together! Overall, I like the idea I just had a comment on how we're demonstrating how a dynamic block is used to access the database.

My other thought is that whatever example we end up using, we should also update the Edit component to reflect that change as well as most of the example blocks try to match the Block Editor experience with the Front End as closely as possible.


// Append "on a blog with 27 published posts"
// where 27 is replaced dynamically with the number of published posts on this blog.
printf(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty straightforward example however there is a lot to unpack here.

The usage of printf, the placeholder for the count, wp_count_posts(), that ->publish part should all be explained as we can't assume any knowledge on the part of the person reading this code. See the explanation and links for wp_kses_post above as an example. The output should also be escaped as we're escaping the line above.

Just for argument's sake, we could use a simpler example to demonstrate accessing the database from this block by doing something like:

echo esc_html( get_bloginfo( 'name' ) );

or

echo wp_kses_post( $attributes['message'] . ' | ' . get_bloginfo( 'name' )  );
@salcode
Copy link
Contributor Author

salcode commented Apr 29, 2022

This PR is superseded by #216

@salcode salcode closed this Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants