Skip to content

Sync image removal to Castos and add featured image filters#901

Merged
zahardev merged 1 commit into
developfrom
version/3.16.0-castos-image
May 12, 2026
Merged

Sync image removal to Castos and add featured image filters#901
zahardev merged 1 commit into
developfrom
version/3.16.0-castos-image

Conversation

@zahardev

@zahardev zahardev commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix Castos sync to clear stale episode images when removed in SSP — previously the empty featured_image_url was omitted from the payload, so Castos kept the old image
  • Add ssp_use_featured_image_for_castos, ssp_use_featured_image_for_player, and ssp_use_featured_image_for_feed filters (all default true) to control featured image fallback per path
  • Add ssp_allow_castos_image_removal filter (default true) to control whether empty values clear images on Castos
  • All filters receive $episode_id as second argument for per-episode control
  • Extract image payload logic into Castos_Handler::get_image_for_castos() for clarity

Test plan

  • Remove episode-specific image on an existing episode, save — verify image is cleared on Castos
  • Set a square featured image with no cover image — verify it syncs to Castos
  • Add add_filter('ssp_use_featured_image_for_castos', '__return_false') — verify featured image is not synced
  • Add add_filter('ssp_allow_castos_image_removal', '__return_false') — verify removing image does not clear on Castos
  • Add add_filter('ssp_use_featured_image_for_player', '__return_false') — verify player shows placeholder instead of featured image
  • Add add_filter('ssp_use_featured_image_for_feed', '__return_false') — verify feed item omits featured image
  • Run full WPUnit suite — 264 tests pass

Closes CastosHQ/ssp-issues#849

Summary by CodeRabbit

  • New Features

    • Introduced filterable controls for episode image fallback behavior across feeds, player, and podcast hosting services.
    • Episodes can now conditionally use featured images as image sources based on context-specific filters.
    • Added control to manage image removal during podcast hosting synchronization.
  • Tests

    • Added comprehensive test coverage for new image handling filters and fallback behaviors.

Review Change Stack

Castos API now distinguishes absent vs empty featured_image_url. Send
empty value on updates so stale images get cleared. Add four filters
for developer control over featured image fallback and removal.

Co-Authored-By: Claude via AIContext
@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds filter-driven control over featured-image fallback behavior across three image contexts: feed URLs, player album art, and Castos sync. Each context introduces a corresponding filter (ssp_use_featured_image_for_feed, ssp_use_featured_image_for_player, ssp_use_featured_image_for_castos) allowing independent opt-in/opt-out of featured-image fallbacks, plus comprehensive test coverage.

Changes

Featured-Image Fallback Filters Across Feed, Player, and Castos Sync

Layer / File(s) Summary
Frontend Controller featured-image fallback
php/classes/controllers/class-frontend-controller.php, tests/WPUnit/FrontendControllerTest.php
Frontend_Controller::get_episode_image_url() now conditionally falls back to the post's featured image only when the ssp_use_featured_image_for_feed filter permits it. Tests verify default behavior, filter-driven disabling, episode ID parameter passing, and that filter does not override explicit cover images.
Episode Repository featured-image fallback for album art
php/classes/repositories/class-episode-repository.php, tests/WPUnit/EpisodeRepositoryAlbumArtTest.php
Episode_Repository::get_album_art() gates its featured-image fallback (Option 5) behind the ssp_use_featured_image_for_player filter (default true). Tests validate filter-driven disabling and confirm the episode ID is passed through to filter callbacks.
Castos Handler featured-image integration and removal semantics
php/classes/handlers/class-castos-handler.php, tests/WPUnit/CastosHandlerImageTest.php
New private get_image_for_castos() method determines whether to send a valid image URL, an empty string to clear an image (when ssp_allow_castos_image_removal permits), or null to omit the key entirely. Enhanced get_episode_image_url() respects the ssp_use_featured_image_for_castos filter. Upload payload construction now uses the helper to conditionally include featured images. Comprehensive tests cover fallback/skip behavior, filter interactions, and upload payload composition for both new and existing episodes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • CastosHQ/seriouslysimplehosting#4295: The main changes implement episode-image removal by adding key-presence semantics to the Castos sync (get_image_for_castos() and ssp_allow_castos_image_removal filter), enabling explicit clearing of featured images via empty featured_image_url payloads.

Possibly related PRs

  • CastosHQ/Seriously-Simple-Podcasting#897: Both modify Episode_Repository::get_album_art() to use featured images; this PR additionally gates that behavior behind the ssp_use_featured_image_for_player filter.
  • CastosHQ/Seriously-Simple-Podcasting#864: Both modify episode image handling in Episode_Repository; this PR gates featured-image fallback while the retrieved PR adds featured-image helpers and restructures controllers.

Poem

A rabbit hops through filters three,
Feed and player, Castos spree!
Featured images now obey your call,
With ssp_use_featured for them all. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding featured image filters and syncing image removal to Castos, matching the core PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 90.63% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch version/3.16.0-castos-image

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/WPUnit/CastosHandlerImageTest.php (1)

24-25: ⚡ Quick win

Scope pre_http_request cleanup to test-owned callbacks only.

remove_all_filters('pre_http_request') can wipe unrelated callbacks and create cross-test coupling. Prefer storing the callback and removing that specific callback.

Suggested change
 class CastosHandlerImageTest extends \Codeception\TestCase\WPTestCase
 {
+    /** `@var` callable|null */
+    protected $pre_http_request_callback = null;
+
     protected function tearDown(): void
     {
         remove_all_filters('ssp_use_featured_image_for_castos');
         remove_all_filters('ssp_allow_castos_image_removal');
-        remove_all_filters('pre_http_request');
+        if ($this->pre_http_request_callback) {
+            remove_filter('pre_http_request', $this->pre_http_request_callback, 10);
+            $this->pre_http_request_callback = null;
+        }
         parent::tearDown();
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WPUnit/CastosHandlerImageTest.php` around lines 24 - 25, The test
currently calls remove_all_filters('pre_http_request') which can remove other
tests' callbacks; instead, store the specific callback when adding the filter
(e.g., assign the callable to a property like $this->preHttpRequestCallback in
setUp or where add_filter('pre_http_request', ...) is called) and in tearDown
call remove_filter('pre_http_request', $this->preHttpRequestCallback, $priority)
(matching the original priority) rather than remove_all_filters; update the test
class (CastosHandlerImageTest) to keep the callback reference and use
remove_filter in tearDown to only remove the test-owned callback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/WPUnit/CastosHandlerImageTest.php`:
- Around line 24-25: The test currently calls
remove_all_filters('pre_http_request') which can remove other tests' callbacks;
instead, store the specific callback when adding the filter (e.g., assign the
callable to a property like $this->preHttpRequestCallback in setUp or where
add_filter('pre_http_request', ...) is called) and in tearDown call
remove_filter('pre_http_request', $this->preHttpRequestCallback, $priority)
(matching the original priority) rather than remove_all_filters; update the test
class (CastosHandlerImageTest) to keep the callback reference and use
remove_filter in tearDown to only remove the test-owned callback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec106371-5d32-4f93-a980-6544c07b00e9

📥 Commits

Reviewing files that changed from the base of the PR and between 2101798 and 62e92e8.

📒 Files selected for processing (6)
  • php/classes/controllers/class-frontend-controller.php
  • php/classes/handlers/class-castos-handler.php
  • php/classes/repositories/class-episode-repository.php
  • tests/WPUnit/CastosHandlerImageTest.php
  • tests/WPUnit/EpisodeRepositoryAlbumArtTest.php
  • tests/WPUnit/FrontendControllerTest.php

@zahardev zahardev merged commit 7cf17af into develop May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant