benecaster_powerpress_episode_imported
Fires after each draft episode is created from a PowerPress post. The draft episode and all mappable meta fields — title, description, media URL, file size, format, duration, episode number, season, episode type, artwork, publish date, explicit flag, and any published transcript and chapters — are already set when this hook fires. A chapter carries image_id where its image could be brought across, and _benecaster_podcast2_transcript_language is set when PowerPress’s language is a valid code. Use it to populate additional fields the importer does not map automatically, trigger external actions, or modify the draft before the podcaster reviews it.
The import spans several WP-Cron runs. If a host stops a run partway through an episode, that episode keeps what it had and this hook may not fire for it.
This hook does not fire for posts skipped because they were already imported in a previous run. The $pp_post parameter is the original post. PowerPress does not keep its per-episode fields as separate post meta: they are the fourth line of the post’s enclosure meta, a serialized array, after the URL, size and type on lines one to three. Split the value on newlines and unserialize that line with [ 'allowed_classes' => false ], as PowerPress itself does, so an object placed there through Custom Fields is never instantiated.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$episode_id |
int |
— | ID of the created Benecaster draft episode post |
$show_id |
int |
— | ID of the show |
$pp_post |
\WP_Post |
— | The original PowerPress WP_Post object that was imported |
Examples
Copy a PowerPress episode field to a custom field
add_action( 'benecaster_powerpress_episode_imported', function ( int $episode_id, int $show_id, \WP_Post $pp_post ): void {
$lines = explode( "\n", (string) get_post_meta( $pp_post->ID, 'enclosure', true ), 4 );
if ( ! isset( $lines[3] ) ) {
return; // No per-episode fields stored.
}
$extras = unserialize( trim( $lines[3] ), [ 'allowed_classes' => false ] );
if ( is_array( $extras ) && ! empty( $extras['subtitle'] ) && is_string( $extras['subtitle'] ) ) {
update_post_meta( $episode_id, 'my_episode_subtitle', sanitize_text_field( $extras['subtitle'] ) );
}
}, 10, 3 );
Notes
Each PowerPress post is tracked by the PowerPress post it came from, so imports are safe to re-run. Posts already imported in a previous run increment the skipped count and do not trigger this hook.
In the example, subtitle is the old iTunes Subtitle field. Current PowerPress no longer saves it, so only episodes last saved under an older PowerPress carry one, and on the rest nothing is copied. Swap in any key your episodes do hold.
Need this built rather than just documented? See our services →