Skip to content

Podcast: add + Create episode button and post-new prefill#48884

Draft
robertbpugh wants to merge 2 commits into
trunkfrom
pods/create-episode-button
Draft

Podcast: add + Create episode button and post-new prefill#48884
robertbpugh wants to merge 2 commits into
trunkfrom
pods/create-episode-button

Conversation

@robertbpugh
Copy link
Copy Markdown
Contributor

Fixes #

Proposed changes

Persistent "+ Create episode" header CTA on /podcast plus a server-side prefill behind the same URL flag.

Dashboard

  • + Create episode button rendered into the AdminPage actions slot (top-right of the unified header). Visible whenever isSetUp is true (a podcast category is configured) and hidden before setup. Same label, same destination for every plan — the Premium value-add lives inside the editor, not at this button.

Server-side prefill (new Automattic\Jetpack\Podcast\New_Episode_Prefill)

  • Registers on admin_init only when $pagenow === 'post-new.php' and ?podcast_episode=1.
  • wp_insert_post action runs once on the initial auto-draft and calls wp_set_post_categories( $post_id, [ podcasting_category_id ] ). Guards on ! $update && post_type === 'post' && post_status === 'auto-draft' so user-driven saves later in the session aren't re-overridden.
  • On Premium (Podcast_Gate::has_product_access() from Podcast: add product-access gate and grandfather sticker constant #48702), the default_content filter returns <!-- wp:jetpack/podcast-episode /-->. Free users get a plain new post and add a core Audio block themselves with an externally hosted URL.

Dependencies

Per Rob's override: branched from current trunk rather than from pods-141-add-gate-helper-and-grandfather-sticker-constant because that branch doesn't yet include the jetpack/podcast-episode block this PR's default_content filter references. Trunk has both the block and (after #48702 merges) the gate helper.

Related product discussion/links

  • Part of the /podcast UI polish batch.

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  1. Enable the package: add_filter( 'jetpack_podcast_untangle', '__return_true' );
  2. Header button visibility:
    • With no podcast category configured (Settings > Disable podcasting), open /podcast. The "+ Create episode" button should NOT be visible.
    • Pick a category in the setup modal. Now the button should appear in the top-right of the header on every tab (Stats, Episodes, Distribution, Settings).
  3. Category prefill (all plans): Click "+ Create episode". You should land on wp-admin/post-new.php?podcast_episode=1 with your configured podcast category already ticked in the post sidebar.
  4. Premium block prefill: With Premium (or the podcasting-grandfathered blog sticker), the new post should already contain an inserted Podcast Episode block ready to receive media.
  5. Free plain new post: Without Premium and without the grandfather sticker, the new post should be empty — no block prefilled. The configured category is still ticked.
  6. No double-override: Pick a different category in-editor before publishing. The user choice should survive the next refresh — the auto-draft hook only fires on the initial insert.

Notes for reviewer:

  • I'm an automation that can't drive a browser, so I haven't captured before/after screenshots. Visual verification still needs a sandbox check at review time.
  • The CTA target URL matches what PR 5's empty-Episodes-state CTA uses, by design.
  • The default_content filter no-ops if $content is already non-empty, so this composes politely with other plugins that prefill new posts.

Spec excerpt (from the work order):

PR 7: Create episode button

Placement

  • Persistent "+ Create episode" button in the top-right of the /podcast page header.
  • Visible on every tab once the podcast category is configured. Hidden before setup.
  • Empty Episodes state also includes a "+ Create episode" CTA (covered in PR 5).

Behavior on click

  • All plans: navigate to a new post URL (try /wp-admin/post-new.php?podcast_episode=1 first, or the Calypso equivalent if the dashboard's existing post-create links use that), with the configured podcast category pre-set on the new post.
  • Premium plan: server-side filter inserts the Podcast Episode block on load.
  • Free plan: plain new post. No block inserted. User adds a core Audio block themselves with an externally hosted URL.

Same button and same destination for everyone. The Premium value-add lives inside the editor, not at the button. No upgrade modal at click time. No Premium indicator on the button.

Per Rob's override (out-of-office): using Podcast_Gate::has_product_access() from #48702. Branched from trunk so the Podcast Episode block referenced by default_content exists on this branch.

Persistent header CTA on the /podcast dashboard plus a server-side
prefill that catches post-new.php?podcast_episode=1.

Dashboard:
- '+ Create episode' button rendered into AdminPage's 'actions' slot
  (top-right of the unified header). Visible once isSetUp is true;
  hidden before the user picks a category. Same destination and
  label for every plan.

Server-side prefill (new class New_Episode_Prefill):
- On post-new.php?podcast_episode=1, hook wp_insert_post on the
  initial auto-draft and wp_set_post_categories to the configured
  podcasting_category_id. Filters narrow to single insert (not
  update), post post-type, auto-draft status, so the user can still
  pick a different category in-editor without re-override.
- On Premium (Podcast_Gate::has_product_access()), hook
  default_content to inject '<!-- wp:jetpack/podcast-episode /-->'
  as the post's initial content. Free users get a plain new post and
  add a core Audio block themselves.

Depends on the Podcast_Gate helper from #48702. CI will fail on
class-not-found until that lands; once it merges this should rebase
clean on trunk.
@robertbpugh robertbpugh self-assigned this May 15, 2026
@robertbpugh robertbpugh requested a review from arcangelini May 15, 2026 23:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the pods/create-episode-button branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack pods/create-episode-button
bin/jetpack-downloader test jetpack-mu-wpcom-plugin pods/create-episode-button

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 15, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 15, 2026

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@robertbpugh
Copy link
Copy Markdown
Contributor Author

Review verdict: READY (after fix), with one flagged dependency

Scope reviewed: branch diff against trunk — 4 files:

  • src/class-new-episode-prefill.php — new handler. Registers on admin_init, scoped to post-new.php?podcast_episode=1. Hooks wp_insert_post to assign podcasting_category_id on the auto-draft insert. On Premium (via Podcast_Gate::has_product_access()), adds default_content filter to inject <!-- wp:jetpack/podcast-episode /-->.
  • src/class-podcast.php — registers New_Episode_Prefill::init() inside the is_admin() branch.
  • src/dashboard/index.tsx — Button rendered into AdminPage's actions slot when isSetUp is true.
  • changelog/pods-create-episode-button — minor/added entry.

Findings

  • CI PHPCS failed on class-new-episode-prefill.php:51: $_GET[ self::QUERY_VAR ] was not unslashed or sanitized. Patched in 94dbdca6: split the isset check from the value check and route the value through sanitize_text_field( wp_unslash( ... ) ) before the literal comparison against '1'.
  • The wp_insert_post guard correctly scopes to ! $update && post_type === 'post' && post_status === 'auto-draft', so user-driven saves later in the editor session do not re-override the user's manual category choice.
  • The default_content filter early-returns if $content is already non-empty, leaving other plugins' prefill alone.

Flagged dependency (P1, documented in PR body)

Codex flagged Podcast_Gate::has_product_access() as an undeclared class. This matches the PR body's "Depends on #48702" note. The gate class lives in #48702 which is still OPEN. Until #48702 merges, the prefill path fatals when the user clicks "+ Create episode". The Static analysis CI failure (PhanUndeclaredClassMethod) is the same root cause and clears once #48702 lands.

Severity

None CRITICAL, 1 MAJOR (cross-PR dependency, already documented), none MINOR.

@robertbpugh robertbpugh marked this pull request as ready for review May 15, 2026 23:34
Copilot AI review requested due to automatic review settings May 15, 2026 23:34
@robertbpugh robertbpugh marked this pull request as draft May 15, 2026 23:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a "+ Create episode" button to the Podcast dashboard header and wires server-side prefill on post-new.php?podcast_episode=1 to assign the configured podcast category (all plans) and inject a Podcast Episode block (Premium only, via the still-unmerged Podcast_Gate).

Changes:

  • New header CTA in dashboard/index.tsx, visible only once a podcast category is configured.
  • New New_Episode_Prefill class wiring wp_insert_post (category assignment) and default_content (block prefill) under admin_init, query-flag-guarded.
  • Boot the new class from Podcast::init() inside the is_admin() branch.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
projects/packages/podcast/src/dashboard/index.tsx Adds the + Create episode Button and passes it as AdminPage actions slot; builds the new-post URL at module load.
projects/packages/podcast/src/class-podcast.php Boots New_Episode_Prefill::init() alongside Admin_Page::init().
projects/packages/podcast/src/class-new-episode-prefill.php New class implementing the category and block-content prefill on the ?podcast_episode=1 flag.
projects/packages/podcast/changelog/pods-create-episode-button Changelog entry (minor / added) describing the new CTA and prefill.

Comment on lines +25 to +117
class New_Episode_Prefill {

const QUERY_VAR = 'podcast_episode';

/**
* Register hooks.
*
* Called from `Podcast::init()` inside the `is_admin()` branch.
*/
public static function init() {
add_action( 'admin_init', array( __CLASS__, 'maybe_register_handlers' ) );
}

/**
* Wire the auto-draft / default-content filters only on
* `post-new.php?podcast_episode=1`.
*
* We bind on `admin_init` rather than at load time so `$pagenow` is
* settled.
*/
public static function maybe_register_handlers() {
global $pagenow;
if ( 'post-new.php' !== $pagenow ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! isset( $_GET[ self::QUERY_VAR ] ) ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( '1' !== sanitize_text_field( wp_unslash( $_GET[ self::QUERY_VAR ] ) ) ) {
return;
}

add_action( 'wp_insert_post', array( __CLASS__, 'assign_category' ), 10, 3 );

if ( Podcast_Gate::has_product_access() ) {
add_filter( 'default_content', array( __CLASS__, 'prefill_block_content' ), 10, 2 );
}
}

/**
* Assign the configured podcast category to the new auto-draft.
*
* Fires on `wp_insert_post` once for the auto-draft `post-new.php` creates;
* we filter to that single insert (new, not update; post post-type;
* auto-draft status) so user-driven saves later in the editor session
* aren't re-overridden.
*
* @param int $post_id Post ID.
* @param \WP_Post $post Post object.
* @param bool $update True for updates, false for inserts.
*/
public static function assign_category( $post_id, $post, $update ) {
if ( $update ) {
return;
}
if ( ! ( $post instanceof \WP_Post ) ) {
return;
}
if ( 'post' !== $post->post_type || 'auto-draft' !== $post->post_status ) {
return;
}

$category_id = (int) get_option( 'podcasting_category_id', 0 );
if ( $category_id <= 0 ) {
return;
}

wp_set_post_categories( $post_id, array( $category_id ) );
}

/**
* Inject a Podcast Episode block as the new post's initial content.
*
* The `default_content` filter runs once when the editor loads the
* auto-draft. If a previous filter (or another plugin) has already filled
* `$content`, leave it alone.
*
* @param string $content Default post content.
* @param \WP_Post $post Post object.
* @return string
*/
public static function prefill_block_content( $content, $post ) {
if ( ! ( $post instanceof \WP_Post ) || 'post' !== $post->post_type ) {
return $content;
}
if ( '' !== trim( (string) $content ) ) {
return $content;
}
return "<!-- wp:jetpack/podcast-episode /-->\n";
}
}
Comment on lines +145 to +147
<Button variant="primary" href={ NEW_EPISODE_URL }>
{ __( '+ Create episode', 'jetpack-podcast' ) }
</Button>
Comment on lines +13 to +17
const ADMIN_URL = getSiteData()?.admin_url ?? '/wp-admin/';

// Server-side filters key off `?podcast_episode=1` to apply the configured
// podcast category (and, on Premium, prefill the Podcast Episode block).
const NEW_EPISODE_URL = `${ ADMIN_URL }post-new.php?podcast_episode=1`;
Comment on lines +78 to +115
public static function assign_category( $post_id, $post, $update ) {
if ( $update ) {
return;
}
if ( ! ( $post instanceof \WP_Post ) ) {
return;
}
if ( 'post' !== $post->post_type || 'auto-draft' !== $post->post_status ) {
return;
}

$category_id = (int) get_option( 'podcasting_category_id', 0 );
if ( $category_id <= 0 ) {
return;
}

wp_set_post_categories( $post_id, array( $category_id ) );
}

/**
* Inject a Podcast Episode block as the new post's initial content.
*
* The `default_content` filter runs once when the editor loads the
* auto-draft. If a previous filter (or another plugin) has already filled
* `$content`, leave it alone.
*
* @param string $content Default post content.
* @param \WP_Post $post Post object.
* @return string
*/
public static function prefill_block_content( $content, $post ) {
if ( ! ( $post instanceof \WP_Post ) || 'post' !== $post->post_type ) {
return $content;
}
if ( '' !== trim( (string) $content ) ) {
return $content;
}
return "<!-- wp:jetpack/podcast-episode /-->\n";

// Header CTA: visible once the show is configured. Same destination and
// label for every plan — the Premium value-add lives inside the editor
// (PR 7's server-side filter inserts the Podcast Episode block on load),

add_action( 'wp_insert_post', array( __CLASS__, 'assign_category' ), 10, 3 );

if ( Podcast_Gate::has_product_access() ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Podcast [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants