Skip to content

Comments

Add filters for paywall content customization#1

Merged
Ninodevo merged 3 commits intoWordPress:trunkfrom
a8cteam51:add/paywall-filters
Feb 11, 2026
Merged

Add filters for paywall content customization#1
Ninodevo merged 3 commits intoWordPress:trunkfrom
a8cteam51:add/paywall-filters

Conversation

@Ninodevo
Copy link
Contributor

Description

This PR adds three new filters to make the Substack Importer more extensible, particularly for handling paywalled content conversion. These filters allow developers to customize how paywall markers are displayed and how paywalled content is processed during import, enabling integration with membership plugins and other custom paywall solutions.

Changes

  1. substack_importer_paywall_marker_text filter: Allows customization of the paywall marker text that appears in imported content.

  2. substack_importer_paywall_content filter: Allows complete override of the paywall block conversion process, enabling custom block types or markup.

  3. substack_importer_post_content_after_conversion filter: Allows modification of post content after Gutenberg conversion but before it's added to the WXR. This is particularly useful for wrapping paywalled content in custom membership blocks.

Testing Instructions

Test 1: Custom Paywall Marker Text

  1. Add the following code to your theme's functions.php or a custom plugin:
add_filter( 'substack_importer_paywall_marker_text', function( $marker_text, $node, $parent ) {
	return __( 'Premium content below', 'your-textdomain' );
}, 10, 3 );
  1. Import a Substack export that contains paywalled posts
  2. Expected result: The paywall marker should display "Premium content below" instead of the default "The content below was originally paywalled."

Test 2: Custom Paywall Block Conversion

  1. Add the following code to customize the paywall conversion:
add_filter( 'substack_importer_paywall_content', function( $result, $node, $parent ) {
	// Create a custom group block instead of paragraph
	$new_node = new DOMElement( 'div' );
	$parent->replaceChild( $new_node, $node );
	$new_node->setAttribute( 'class', 'custom-paywall-block' );
	
	return array(
		'node'             => $new_node,
		'block_attributes' => array( 'className' => 'custom-paywall-block' ),
		'block_name'       => 'wp:group',
	);
}, 10, 3 );
  1. Import a Substack export with paywalled content
  2. Expected result: Paywall markers should be converted to group blocks with the custom class instead of paragraph blocks

Test 3: Wrap Paywalled Content in Custom Block

  1. Add the following code to wrap paywalled content in a custom restricted content block:
add_filter( 'substack_importer_post_content_after_conversion', function( $post_content, $post, $post_meta ) {
	$marker = "<!-- wp:paragraph --><p>The content below was originally paywalled.</p>\n<!-- /wp:paragraph -->";
	$parts = explode( $marker, $post_content );
	
	if ( count( $parts ) > 1 ) {
		$free_content = $parts[0];
		$paid_content = $parts[1];
		
		// Wrap paid content in your membership block
		$paid_content = '<!-- wp:your-plugin/restricted -->' . $paid_content . '<!-- /wp:your-plugin/restricted -->';
		
		return $free_content . $paid_content;
	}
	
	return $post_content;
}, 10, 3 );
  1. Import a Substack export with paywalled posts
  2. Expected result: Content after the paywall marker should be wrapped in the custom restricted content block

Test 4: Verify Default Behavior (No Filters)

  1. Import a Substack export without adding any filters
  2. Expected result: Paywall markers should display the default text "The content below was originally paywalled." as paragraph blocks

Unit Testing

Run the PHPUnit test suite to verify all filter functionality.

@Ninodevo Ninodevo requested a review from zaerl February 11, 2026 11:21
Copy link
Contributor

@zaerl zaerl left a comment

Choose a reason for hiding this comment

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

This LGTM, great work.

I've seen you have bumped the version to 1.2.0. Remember to change it on:

  1. readme.txt
  2. substack-importer.php
  3. package.json

This can be done in another PR.

*
* This filter allows modification of the converted Gutenberg block content
* before it is added to the WXR. Useful for wrapping paywalled content in
* custom blocks (e.g., membership plugins).
Copy link
Contributor

Choose a reason for hiding this comment

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

Great idea.

@Ninodevo
Copy link
Contributor Author

Thanks @zaerl! I will bump the version in those files and add more features to the 1.2.0 release before deploying

@Ninodevo Ninodevo merged commit 178b5f6 into WordPress:trunk Feb 11, 2026
18 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.

2 participants