Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
14ceb3f
Add a typed helper for the Ipsum version in patterns.
westonruter Oct 22, 2026
33d9e91
Version Ipsum's stylesheet with the parent theme version.
westonruter Oct 22, 2026
375a77f
Build Ipsum pattern image URLs with an asset URL helper.
westonruter Oct 22, 2026
027fa2d
Narrow the Ipsum asset path to a non-falsy string.
westonruter Oct 22, 2026
91f1a88
Specify the value type of Ipsum's block binding args.
westonruter Oct 22, 2026
c1ea213
Resolve the post for Ipsum's comments call to action.
westonruter Oct 22, 2026
6a48360
Specify the value type of Ipsum's template types.
westonruter Oct 22, 2026
797d616
Specify the value type of Ipsum's block metadata.
westonruter Oct 22, 2026
b9b7aba
Narrow the Search block supports before adding ARIA label.
westonruter Oct 22, 2026
2449bb3
Unset the unused block binding args in Ipsum.
westonruter Oct 22, 2026
d065411
Document Ipsum's block binding args as unused.
westonruter Oct 22, 2026
730f5a5
Add a helper to serialize Ipsum pattern block attributes.
westonruter Oct 22, 2026
343519e
Serialize Ipsum's translated block names as JSON.
westonruter Oct 22, 2026
213034d
Serialize Ipsum's translated ARIA labels and alt as JSON.
westonruter Oct 22, 2026
4deb906
Serialize Ipsum's translated HTML attributes as JSON.
westonruter Oct 22, 2026
7e5d2e3
Serialize Ipsum's cover image URLs as JSON.
westonruter Oct 22, 2026
54b4b1c
Serialize Ipsum's search placeholder and button text as JSON.
westonruter Oct 22, 2026
b7e08e2
Treat ipsum_serialize_block_attribute() as an escaping function in PH…
westonruter Oct 22, 2026
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
85 changes: 73 additions & 12 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ipsum_enqueue_styles() {
'ipsum-style',
get_parent_theme_file_uri( 'style.css' ),
array(),
wp_get_theme()->get( 'Version' )
wp_get_theme( get_template() )->get( 'Version' )
);

// Enqueue theme stylesheet.
Expand All @@ -62,26 +62,84 @@ function ipsum_enqueue_styles() {
endif;
add_action( 'wp_enqueue_scripts', 'ipsum_enqueue_styles' );

if ( ! function_exists( 'ipsum_get_asset_url' ) ) :
/**
* Gets the URL of a theme asset, with the theme version added for cache busting.
*
* The asset and the version both come from the parent theme, so a child
* theme's version doesn't stand in for Ipsum's.
*
* @since Ipsum 1.0
*
* @param string $path Path to the asset, relative to the theme directory, such as
* 'assets/images/ipsum-polygons.webp'.
* @return string The asset URL, with a `ver` query argument when the theme
* version can be read.
*
* @phpstan-param non-falsy-string $path
*/
function ipsum_get_asset_url( string $path ): string {
$url = get_parent_theme_file_uri( $path );
$version = wp_get_theme( get_template() )->get( 'Version' );
if ( false !== $version ) {
$url = add_query_arg( 'ver', $version, $url );
}
return $url;
}
endif;

if ( ! function_exists( 'ipsum_serialize_block_attribute' ) ) :
/**
* Serializes a value for a block attribute in a pattern's block delimiter.
*
* Block attributes are JSON in an HTML comment, so a value computed in PHP,
* such as a translated string, has to be encoded the way the block editor
* serializes attributes, not escaped for HTML. HTML entities would be kept
* as literal text in the attribute value, and a backslash or a line break in
* a translation would make the JSON invalid, losing all the block's attributes.
*
* The value is serialized under a key, which is then removed, so that it gets
* the same escaping as serialize_block_attributes() gives a whole block.
*
* @since Ipsum 1.0
*
* @param mixed $value Attribute value. A value for an attribute that holds HTML,
* such as a label, must be escaped for HTML first.
* @return string The serialized value, including the quotes around a string.
*/
function ipsum_serialize_block_attribute( $value ): string {
$prefix = '{"value":';
return substr( serialize_block_attributes( array( 'value' => $value ) ), strlen( $prefix ), -1 );
}
endif;

if ( ! function_exists( 'ipsum_comments_cta_binding' ) ) :
/**
* Returns the comments call to action for the current post.
*
* @since Ipsum 1.0
*
* @param array $source_args Block binding source arguments.
* @param WP_Block $block_instance The block instance.
* @return string The call to action text.
* @param array<string, mixed> $source_args Block binding source arguments. Unused.
* @param WP_Block $block_instance The block instance.
* @return string|null The call to action text, or null to keep the block's
* original content when there is no post.
*/
function ipsum_comments_cta_binding( $source_args, $block_instance ) {
$post_id = $block_instance->context['postId'] ?? get_the_ID();
unset( $source_args ); // Unused, but must be accepted to get the block instance.

$post_id = $block_instance->context['postId'] ?? null;
$post = get_post( is_numeric( $post_id ) ? (int) $post_id : null );
if ( ! $post ) {
return null;
}

if ( get_comments_number( $post_id ) > 0 ) {
if ( get_comments_number( $post ) > 0 ) {
$text = __( 'Join the conversation', 'ipsum' );
} else {
$text = __( 'Be the first to comment', 'ipsum' );
}

return '<a href="' . esc_url( get_comments_link( $post_id ) ) . '">' . esc_html( $text ) . '</a>';
return '<a href="' . esc_url( get_comments_link( $post ) ) . '">' . esc_html( $text ) . '</a>';
}
endif;

Expand Down Expand Up @@ -113,8 +171,9 @@ function ipsum_register_block_bindings() {
*
* @since Ipsum 1.0
*
* @param array $default_template_types The default template types.
* @return array The template types, with the sidebar variants added.
* @param array<string, array<string, string>> $default_template_types The default template types, keyed by
* slug, each with a title and description.
* @return array<string, array<string, string>> The template types, with the sidebar variants added.
*/
function ipsum_sidebar_template_types( $default_template_types ) {
$default_template_types['index-sidebar'] = array(
Expand Down Expand Up @@ -162,12 +221,14 @@ function ipsum_register_pattern_categories() {
*
* @since Ipsum 1.0
*
* @param array $metadata Metadata for the block type being registered.
* @return array The block metadata, with ARIA label support on the Search block.
* @param array<string, mixed> $metadata Metadata for the block type being registered.
* @return array<string, mixed> The block metadata, with ARIA label support on the Search block.
*/
function ipsum_search_aria_label_support( $metadata ) {
if ( isset( $metadata['name'] ) && 'core/search' === $metadata['name'] ) {
$metadata['supports']['ariaLabel'] = true;
$supports = isset( $metadata['supports'] ) && is_array( $metadata['supports'] ) ? $metadata['supports'] : array();
$supports['ariaLabel'] = true;
$metadata['supports'] = $supports;
}
return $metadata;
}
Expand Down
4 changes: 2 additions & 2 deletions patterns/about-row.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

?>
<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'About Row', 'Name of the about row group', 'ipsum' ); ?>"},"align":"full","style":{"elements":{"link":{"color":{"text":"var:preset|color|theme-1"}}},"spacing":{"padding":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50"},"margin":{"top":"0","bottom":"0"}}},"backgroundColor":"theme-6","textColor":"theme-1","layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'About Row', 'Name of the about row group', 'ipsum' ) ); ?>},"align":"full","style":{"elements":{"link":{"color":{"text":"var:preset|color|theme-1"}}},"spacing":{"padding":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50"},"margin":{"top":"0","bottom":"0"}}},"backgroundColor":"theme-6","textColor":"theme-1","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull has-theme-1-color has-theme-6-background-color has-text-color has-background has-link-color" style="margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50)"><!-- wp:columns {"verticalAlignment":"bottom","align":"wide","style":{"spacing":{"blockGap":{"top":"var:preset|spacing|60","left":"var:preset|spacing|80"}}}} -->
<div class="wp-block-columns alignwide are-vertically-aligned-bottom"><!-- wp:column {"verticalAlignment":"bottom","width":"50%"} -->
<div class="wp-block-column is-vertically-aligned-bottom" style="flex-basis:50%"><!-- wp:heading {"fitText":true} -->
Expand All @@ -29,7 +29,7 @@

<!-- wp:column {"verticalAlignment":"bottom","width":"50%","layout":{"type":"default"}} -->
<div class="wp-block-column is-vertically-aligned-bottom" style="flex-basis:50%"><!-- wp:image {"aspectRatio":"1","scale":"cover","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/assets/images/ipsum-portrait-editorial.webp?ver=<?php echo esc_attr( wp_get_theme( get_template() )->get( 'Version' ) ); ?>" alt="<?php esc_attr_e( 'Portrait of the author.', 'ipsum' ); ?>" style="aspect-ratio:1;object-fit:cover"/></figure>
<figure class="wp-block-image size-full"><img src="<?php echo esc_url( ipsum_get_asset_url( 'assets/images/ipsum-portrait-editorial.webp' ) ); ?>" alt="<?php esc_attr_e( 'Portrait of the author.', 'ipsum' ); ?>" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div>
Expand Down
10 changes: 5 additions & 5 deletions patterns/archive-columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
*/

?>
<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null,"parents":[],"excludeCurrent":null},"metadata":{"categories":["posts"],"name":"<?php echo esc_html_x( 'Archive Columns', 'Name of the Archive Columns query', 'ipsum' ); ?>"},"align":"wide","layout":{"type":"default"}} -->
<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null,"parents":[],"excludeCurrent":null},"metadata":{"categories":["posts"],"name":<?php echo ipsum_serialize_block_attribute( _x( 'Archive Columns', 'Name of the Archive Columns query', 'ipsum' ) ); ?>},"align":"wide","layout":{"type":"default"}} -->
<div class="wp-block-query alignwide"><!-- wp:post-template {"style":{"spacing":{"blockGap":"var:preset|spacing|60"}},"layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Media and Content', 'Name of the group holding the media and content', 'ipsum' ); ?>"},"style":{"@mobile":{"layout":{"orientation":"vertical","justifyContent":"stretch"}},"@tablet":{"layout":{"orientation":"vertical","justifyContent":"stretch"}},"spacing":{"blockGap":"var:preset|spacing|40"}},"layout":{"type":"flex","flexWrap":"nowrap","verticalAlignment":"top"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Media and Content', 'Name of the group holding the media and content', 'ipsum' ) ); ?>},"style":{"@mobile":{"layout":{"orientation":"vertical","justifyContent":"stretch"}},"@tablet":{"layout":{"orientation":"vertical","justifyContent":"stretch"}},"spacing":{"blockGap":"var:preset|spacing|40"}},"layout":{"type":"flex","flexWrap":"nowrap","verticalAlignment":"top"}} -->
<div class="wp-block-group"><!-- wp:post-featured-image {"isLink":true,"aspectRatio":"4/3","sizeSlug":"large","style":{"@mobile":{"layout":{"selfStretch":"fit"}},"@tablet":{"layout":{"selfStretch":"fit"}},"layout":{"selfStretch":"fixedNoShrink","flexSize":"300px"}}} /-->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Title and Meta', 'Name of the group holding the post title and meta', 'ipsum' ); ?>"},"style":{"layout":{"selfStretch":"fill"},"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"flex","orientation":"vertical"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Title and Meta', 'Name of the group holding the post title and meta', 'ipsum' ) ); ?>},"style":{"layout":{"selfStretch":"fill"},"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"flex","orientation":"vertical"}} -->
<div class="wp-block-group"><!-- wp:post-title {"isLink":true,"fontSize":"large"} /-->

<!-- wp:post-date {"isLink":true,"style":{"typography":{"fontStyle":"normal","fontWeight":"400"}}} /--></div>
<!-- /wp:group --></div>
<!-- /wp:group -->
<!-- /wp:post-template -->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'No Results Wrapper', 'Name of the group shown when a query has no results', 'ipsum' ); ?>"},"layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'No Results Wrapper', 'Name of the group shown when a query has no results', 'ipsum' ) ); ?>},"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p><?php esc_html_e( 'No posts have been published in this section yet.', 'ipsum' ); ?></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:group -->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Pagination Wrapper', 'Name of the group wrapping the pagination', 'ipsum' ); ?>"},"align":"wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|60"}}},"layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Pagination Wrapper', 'Name of the group wrapping the pagination', 'ipsum' ) ); ?>},"align":"wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|60"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide" style="margin-top:var(--wp--preset--spacing--60)"><!-- wp:query-pagination {"paginationArrow":"arrow","layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous /-->

Expand Down
16 changes: 8 additions & 8 deletions patterns/archive-compact.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/

?>
<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null,"parents":[],"excludeCurrent":null},"metadata":{"categories":["posts"],"name":"<?php echo esc_html_x( 'Archive Compact', 'Name of the Archive Compact query', 'ipsum' ); ?>"},"layout":{"type":"default"}} -->
<!-- wp:query {"query":{"perPage":10,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true,"taxQuery":null,"parents":[],"excludeCurrent":null},"metadata":{"categories":["posts"],"name":<?php echo ipsum_serialize_block_attribute( _x( 'Archive Compact', 'Name of the Archive Compact query', 'ipsum' ) ); ?>},"layout":{"type":"default"}} -->
<div class="wp-block-query"><!-- wp:post-template {"className":"hover-together","style":{"spacing":{"blockGap":"var:preset|spacing|60"}},"layout":{"type":"default"}} -->
<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Post Template Wrapper', 'Name of the group wrapping each post in a list', 'ipsum' ); ?>"},"style":{"spacing":{"margin":{"bottom":"var:preset|spacing|50"},"padding":{"bottom":"var:preset|spacing|50"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group" style="margin-bottom:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50)"><!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Post Title', 'Name of the group holding the post title', 'ipsum' ); ?>"},"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Post Template Wrapper', 'Name of the group wrapping each post in a list', 'ipsum' ) ); ?>},"style":{"spacing":{"margin":{"bottom":"var:preset|spacing|50"},"padding":{"bottom":"var:preset|spacing|50"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group" style="margin-bottom:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50)"><!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Post Title', 'Name of the group holding the post title', 'ipsum' ) ); ?>},"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:post-title {"isLink":true,"fontSize":"2-x-large"} /-->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Date and Categories', 'Name of the group holding the post date and categories', 'ipsum' ); ?>"},"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Date and Categories', 'Name of the group holding the post date and categories', 'ipsum' ) ); ?>},"style":{"spacing":{"blockGap":"var:preset|spacing|20"}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group"><!-- wp:post-date {"isLink":true} /-->

<!-- wp:paragraph {"metadata":{"name":"·"},"style":{"typography":{"fontStyle":"normal","fontWeight":"600"}},"fontSize":"small"} -->
Expand All @@ -29,23 +29,23 @@
<!-- /wp:group --></div>
<!-- /wp:group -->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Post Template Copy', 'Name of the group holding the post excerpt and read more link', 'ipsum' ); ?>"},"layout":{"type":"constrained","justifyContent":"left"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Post Template Copy', 'Name of the group holding the post excerpt and read more link', 'ipsum' ) ); ?>},"layout":{"type":"constrained","justifyContent":"left"}} -->
<div class="wp-block-group"><!-- wp:post-excerpt {"showMoreOnNewLine":false} /-->

<!-- wp:read-more {"content":"<?php esc_attr_e( 'Read more ›', 'ipsum' ); ?>"} /--></div>
<!-- wp:read-more {"content":<?php echo ipsum_serialize_block_attribute( esc_html__( 'Read more ›', 'ipsum' ) ); ?>} /--></div>
<!-- /wp:group --></div>
<!-- /wp:group -->
<!-- /wp:post-template -->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'No Results Wrapper', 'Name of the group shown when a query has no results', 'ipsum' ); ?>"},"layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'No Results Wrapper', 'Name of the group shown when a query has no results', 'ipsum' ) ); ?>},"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:query-no-results -->
<!-- wp:paragraph -->
<p><?php esc_html_e( 'No posts have been published in this section yet.', 'ipsum' ); ?></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:group -->

<!-- wp:group {"metadata":{"name":"<?php echo esc_html_x( 'Pagination Wrapper', 'Name of the group wrapping the pagination', 'ipsum' ); ?>"},"align":"wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|60"}}},"layout":{"type":"constrained"}} -->
<!-- wp:group {"metadata":{"name":<?php echo ipsum_serialize_block_attribute( _x( 'Pagination Wrapper', 'Name of the group wrapping the pagination', 'ipsum' ) ); ?>},"align":"wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|60"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide" style="margin-top:var(--wp--preset--spacing--60)"><!-- wp:query-pagination {"paginationArrow":"arrow","layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous /-->

Expand Down
Loading
Loading