Skip to content

Instantly share code, notes, and snippets.

View tommyferry's full-sized avatar

Tommy Ferry tommyferry

View GitHub Profile
@tommyferry
tommyferry / gutenberg-paywalls.php
Last active August 15, 2023 10:57
A PHP snippet to protect paywalled content (e.g. whitepapers) from being freely accessed by the WordPress REST API
<?php
function tf_filter_gutenberg_post_types( $args, $post_type ) {
// Return early - we're not registering the right CPT
if ( 'whitepaper' !== $post_type ) {
return $args;
}
// Only enable the REST API for users with edit permissions, otherwise
// explicitly disable it. This prevents other users having access to