Skip to content
Pro Requires Foliora Pro

Access rules and free previews

Choose who reads the full document — logged-in users, roles, buyers or members — and give everyone else a real preview or a locked card.

2 min read Updated

On this page

Restrict a document#

  1. Open Foliora → Access and click Restrict a document.
  2. Select a document (PDF or EPUB) from the Media Library.
  3. Under Who can read the full document pick one or more:
    • Everyone (no restriction)
    • Logged-in users
    • Users with these roles
    • Customers who bought a WooCommerce product
    • Members of a plan — MemberPress, Paid Memberships Pro or WooCommerce Memberships
  4. Under Everyone else set the number of free preview pages (0 = no preview, show a locked card) and an optional message such as “Members get the full 40-page report.”
  5. Keep Protect the file ticked so its public URL stops working, then save.
  6. For PDFs, open the document again and click Build preview.

How previews work#

A preview is a separate small PDF with only the first pages, built in your browser from the original with pdf-lib — nothing goes to an outside service. Readers without access receive only that file; the rest of the document never reaches their browser.

  • Previews are PDF-only. EPUB readers without access see the locked card.
  • Encrypted or password-protected PDFs cannot be cut — upload an unprotected copy or use no preview.
  • After replacing the PDF or changing the page count, click Rebuild preview. An outdated preview is never served; the locked card is shown instead.
  • Until a preview is built, readers without access see the locked card.

Who always has access#

  • Administrators and editors of the file.
  • Anyone opening a protected link — links skip access rules.

Good to know#

  • Rules live on the file, so they apply everywhere it is embedded: posts, the library, the bookshelf, product pages and embeds on other sites.
  • Without Secure Mode the public file URL bypasses the rules — the Access screen warns you.
  • Removing a product link never removes the rule; the document stays locked until you change it here.
  • If no role, product or plan is selected, only editors can read the document.
  • Enforcement keeps working if your licence lapses; only editing rules needs an active licence.

Selling through WooCommerce? Linking a document from the product is easier — see WooCommerce.

For developers#

// Custom access logic.
add_filter( 'foliora_pro/user_has_access', function ( $ok, $user_id, $attachment_id, $rules ) {
	return $ok || user_can( $user_id, 'read_private_reports' );
}, 10, 4 );

// List plans from another membership plugin on the Access screen…
add_filter( 'foliora_pro/membership_options', function ( $plans ) {
	$plans['myplugin:gold'] = 'My Plugin — Gold';
	return $plans;
} );

// …and grant access to members of that plan.
add_filter( 'foliora_pro/user_has_access', function ( $ok, $user_id, $attachment_id, $rules ) {
	if ( ! $ok && my_plugin_is_member( $user_id, 'gold' ) ) {
		$ok = true; // Check $rules first if only some documents are for Gold.
	}
	return $ok;
}, 10, 4 );

Built-in plan keys look like mepr:{ID} (MemberPress) and pmpro:{level} (Paid Memberships Pro).