Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created December 11, 2023 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugin-republic/b3afda784c976115dfc3cc4d61cf2c0b to your computer and use it in GitHub Desktop.
Save plugin-republic/b3afda784c976115dfc3cc4d61cf2c0b to your computer and use it in GitHub Desktop.
<?php
/**
* Restrict access to pages by log-in status
*/
function prefix_is_post_restricted( $is_restricted, $restricted_content ) {
// Edit the page IDs below
$restricted_page_ids = array( 2, 10 );
if( is_page() ) {
$page_id = get_the_ID();
if( in_array( $page_id, $restricted_page_ids ) ) {
if( ! is_user_logged_in() ) {
return true;
}
}
}
return $is_restricted;
}
add_filter( 'wcmo_is_content_restricted', 'prefix_is_post_restricted', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment