fix: fall back to placeholder art when a cover attachment is gone

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
chrnxandClaude Opus 5 committed 2026-08-15 15:34:37 -05:00
1 parent 77dc2ee33b
commit 6f418f1a51
9 files changed
+71 -14

No files matched your search

+3 -2
View File
@@ -13,6 +13,7 @@ if ( ! $chrnx_term instanceof WP_Term || 'chrnx_project' !== $chrnx_term->taxono
$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true ); $chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_project_status', true );
$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) ); $chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_project_cover', true ) );
$chrnx_links = chrnx_get_project_links( $chrnx_term->term_id ); $chrnx_links = chrnx_get_project_links( $chrnx_term->term_id );
$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-project-detail__cover' ) ) : '';
// Without status, description or links there is no second column to fill. // Without status, description or links there is no second column to fill.
$chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links ); $chrnx_has_intro = '' !== $chrnx_status || '' !== $chrnx_term->description || ! empty( $chrnx_links );
$chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' ); $chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' is-bare' );
@@ -20,8 +21,8 @@ $chrnx_head_class = 'chrnx-project-detail__head' . ( $chrnx_has_intro ? '' : ' i
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> <section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-project-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<div class="<?php echo esc_attr( $chrnx_head_class ); ?>"> <div class="<?php echo esc_attr( $chrnx_head_class ); ?>">
<div class="chrnx-project-detail__art"> <div class="chrnx-project-detail__art">
<?php if ( $chrnx_cover > 0 ) : ?> <?php if ( '' !== $chrnx_cover_markup ) : ?>
<?php echo wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-project-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> <?php echo $chrnx_cover_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?> <?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-project', '', 'chrnx-project-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?> <?php echo chrnx_get_topic_portrait_markup( 'placeholder-project', '', 'chrnx-project-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?> <?php endif; ?>
+5 -2
View File
@@ -29,8 +29,11 @@ if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) {
<a class="chrnx-project-card__link" href="<?php echo esc_url( $chrnx_link ); ?>"> <a class="chrnx-project-card__link" href="<?php echo esc_url( $chrnx_link ); ?>">
<?php endif; ?> <?php endif; ?>
<span class="chrnx-project-card__art"> <span class="chrnx-project-card__art">
<?php if ( $chrnx_cover > 0 ) : ?> <?php
<?php echo wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-project-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> $chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-project-card__cover' ) ) : '';
?>
<?php if ( '' !== $chrnx_cover_markup ) : ?>
<?php echo $chrnx_cover_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?> <?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-project', '', 'chrnx-project-card__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?> <?php echo chrnx_get_topic_portrait_markup( 'placeholder-project', '', 'chrnx-project-card__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?> <?php endif; ?>
+3 -2
View File
@@ -14,6 +14,7 @@ $chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true ); $chrnx_status = (string) get_term_meta( $chrnx_term->term_id, 'chrnx_release_status', true );
$chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) ); $chrnx_cover = absint( get_term_meta( $chrnx_term->term_id, 'chrnx_release_cover', true ) );
$chrnx_links = chrnx_get_release_links( $chrnx_term->term_id ); $chrnx_links = chrnx_get_release_links( $chrnx_term->term_id );
$chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-release-detail__cover' ) ) : '';
$chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug ); $chrnx_tracks = chrnx_get_release_track_ids( $chrnx_term->slug );
$chrnx_track_h = min( 6, $chrnx_heading + 1 ); $chrnx_track_h = min( 6, $chrnx_heading + 1 );
// Without status, description or links there is no second column to fill. // Without status, description or links there is no second column to fill.
@@ -23,8 +24,8 @@ $chrnx_head_class = 'chrnx-release-detail__head' . ( $chrnx_has_intro ? '' : ' i
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-release-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> <section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-release-detail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<div class="<?php echo esc_attr( $chrnx_head_class ); ?>"> <div class="<?php echo esc_attr( $chrnx_head_class ); ?>">
<div class="chrnx-release-detail__art"> <div class="chrnx-release-detail__art">
<?php if ( $chrnx_cover > 0 ) : ?> <?php if ( '' !== $chrnx_cover_markup ) : ?>
<?php echo wp_get_attachment_image( $chrnx_cover, 'large', false, array( 'class' => 'chrnx-release-detail__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> <?php echo $chrnx_cover_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?> <?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?> <?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-detail__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?> <?php endif; ?>
+5 -2
View File
@@ -29,8 +29,11 @@ if ( is_wp_error( $chrnx_terms ) || empty( $chrnx_terms ) ) {
<a class="chrnx-release-card__link" href="<?php echo esc_url( $chrnx_link ); ?>"> <a class="chrnx-release-card__link" href="<?php echo esc_url( $chrnx_link ); ?>">
<?php endif; ?> <?php endif; ?>
<span class="chrnx-release-card__art"> <span class="chrnx-release-card__art">
<?php if ( $chrnx_cover > 0 ) : ?> <?php
<?php echo wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-release-card__cover' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> $chrnx_cover_markup = $chrnx_cover > 0 ? wp_get_attachment_image( $chrnx_cover, 'chrnx-card', false, array( 'class' => 'chrnx-release-card__cover' ) ) : '';
?>
<?php if ( '' !== $chrnx_cover_markup ) : ?>
<?php echo $chrnx_cover_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?> <?php else : ?>
<?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-card__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?> <?php echo chrnx_get_topic_portrait_markup( 'placeholder-release', '', 'chrnx-release-card__fallback' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?> <?php endif; ?>
+1 -1
View File
@@ -16,7 +16,7 @@
<!-- wp:html --><div class="chrnx-character-stage__atmosphere" aria-hidden="true"><?php echo chrnx_get_atmosphere_markup( 'projects-grunge', 'chrnx-character-stage__backdrop' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?><?php echo chrnx_get_topic_portrait_markup( 'research', '', 'chrnx-character-stage__secondary-art' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html --> <!-- wp:html --><div class="chrnx-character-stage__atmosphere" aria-hidden="true"><?php echo chrnx_get_atmosphere_markup( 'projects-grunge', 'chrnx-character-stage__backdrop' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?><?php echo chrnx_get_topic_portrait_markup( 'research', '', 'chrnx-character-stage__secondary-art' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?></div><!-- /wp:html -->
<!-- wp:group {"className":"chrnx-character-stage__content","layout":{"type":"constrained"}} --> <!-- wp:group {"className":"chrnx-character-stage__content","layout":{"type":"constrained"}} -->
<div class="wp-block-group chrnx-character-stage__content"> <div class="wp-block-group chrnx-character-stage__content">
<!-- wp:heading --><h2 class="wp-block-heading"><?php echo esc_html__( 'Selected work', 'chrnx' ); ?></h2><!-- /wp:heading --> <!-- wp:heading --><h2 class="wp-block-heading"><?php echo esc_html__( 'Proyectos', 'chrnx' ); ?></h2><!-- /wp:heading -->
<!-- wp:paragraph --><p><?php echo esc_html__( 'Lo que sobrevive a la loquera nocturna, con su repo y su estado real.', 'chrnx' ); ?></p><!-- /wp:paragraph --> <!-- wp:paragraph --><p><?php echo esc_html__( 'Lo que sobrevive a la loquera nocturna, con su repo y su estado real.', 'chrnx' ); ?></p><!-- /wp:paragraph -->
</div> </div>
<!-- /wp:group --> <!-- /wp:group -->
+2 -2
View File
@@ -559,9 +559,9 @@ const immutableSurfaces = [
], ],
// Project names come from the project list query: picked projects newest-first, // Project names come from the project list query: picked projects newest-first,
// then the most recent ones. This is the seeded order, not a frozen string. // then the most recent ones. This is the seeded order, not a frozen string.
headings: [ 'Selected work', 'Ailed', 'Expressive Tea', 'Published research' ], headings: [ 'Proyectos', 'Ailed', 'Expressive Tea', 'Published research' ],
paragraphs: [], paragraphs: [],
contentText: 'Selected work Ailed Expressive Tea Published research', contentText: 'Proyectos Ailed Expressive Tea Published research',
}, },
{ {
name: 'About', name: 'About',
+1 -1
View File
@@ -193,7 +193,7 @@ test( 'home remains coherent at all approved review viewports', async ( { page }
await expect( page.locator( 'main#chrnx-main' ) ).toBeVisible(); await expect( page.locator( 'main#chrnx-main' ) ).toBeVisible();
await expect( page.getByRole( 'contentinfo' ) ).toBeVisible(); await expect( page.getByRole( 'contentinfo' ) ).toBeVisible();
await expect( page.getByRole( 'heading', { level: 1 } ) ).toHaveCount( 1 ); await expect( page.getByRole( 'heading', { level: 1 } ) ).toHaveCount( 1 );
await expect( page.getByText( 'Selected work', { exact: true } ) ).toBeVisible(); await expect( page.getByText( 'Proyectos', { exact: true } ) ).toBeVisible();
await expect( page.getByText( 'The No Names', { exact: true } ).first() ).toBeVisible(); await expect( page.getByText( 'The No Names', { exact: true } ).first() ).toBeVisible();
await expect( page.locator( 'picture source[type="image/avif"]' ).first() ).toHaveAttribute( await expect( page.locator( 'picture source[type="image/avif"]' ).first() ).toHaveAttribute(
'srcset', 'srcset',
+2 -2
View File
@@ -205,9 +205,9 @@ class PatternsTest extends WP_UnitTestCase {
public function test_character_led_patterns_use_the_exact_shared_stage_api() { public function test_character_led_patterns_use_the_exact_shared_stage_api() {
$contracts = array( $contracts = array(
'home-projects' => array( 'home-projects' => array(
'heading' => 'Selected work', 'heading' => 'Proyectos',
// The project names come from the project list query now, not the pattern. // The project names come from the project list query now, not the pattern.
'order' => array( 'Selected work' ), 'order' => array( 'Proyectos' ),
'art' => 'alter-ego-code-768.webp', 'art' => 'alter-ego-code-768.webp',
'art_alt' => '', 'art_alt' => '',
'atmosphere' => 'chrnx-character-stage__secondary-art', 'atmosphere' => 'chrnx-character-stage__secondary-art',
+49
View File
@@ -107,6 +107,55 @@ class ProjectBlocksTest extends WP_UnitTestCase {
$this->assertSame( '', trim( do_blocks( '<!-- wp:chrnx/project-detail /-->' ) ) ); $this->assertSame( '', trim( do_blocks( '<!-- wp:chrnx/project-detail /-->' ) ) );
} }
/**
* Ensure a list card falls back to placeholder art when the stored cover
* attachment no longer exists, instead of rendering a blank art column.
*/
public function test_project_list_with_deleted_cover_uses_placeholder_art() {
$term_id = self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'slug' => 'deleted-cover-list-test',
)
);
update_term_meta( $term_id, 'chrnx_project_cover', 999999 );
$markup = do_blocks( '<!-- wp:chrnx/project-list /-->' );
// Scope the assertion to this term's own card: the taxonomy query is
// unfiltered, so other projects' cards must not mask a broken one.
$needle = 'chrnx_project=deleted-cover-list-test';
$link_offset = strpos( $markup, $needle );
$this->assertNotFalse( $link_offset, 'Expected a card linking to the test project.' );
$card_start = strrpos( substr( $markup, 0, $link_offset ), '<article' );
$card_end = strpos( $markup, '</article>', $link_offset );
$card = substr( $markup, $card_start, $card_end - $card_start );
$this->assertStringContainsString( 'chrnx-project-card__fallback', $card );
$this->assertStringNotContainsString( 'chrnx-project-card__cover', $card );
}
/**
* Ensure the detail block falls back to placeholder art when the stored
* cover attachment no longer exists, instead of rendering a blank art column.
*/
public function test_project_detail_with_deleted_cover_uses_placeholder_art() {
$term_id = self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'slug' => 'deleted-cover-detail-test',
)
);
update_term_meta( $term_id, 'chrnx_project_cover', 999999 );
$this->go_to( get_term_link( $term_id ) );
$markup = do_blocks( '<!-- wp:chrnx/project-detail /-->' );
$this->assertStringContainsString( 'chrnx-project-detail__fallback', $markup );
$this->assertStringNotContainsString( 'chrnx-project-detail__cover', $markup );
}
/** /**
* Ensure a project archive filters the journal to that project. * Ensure a project archive filters the journal to that project.
*/ */