Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Created August 28, 2026 10:18
Show Gist options
  • Select an option

  • Save dwanjuki/06eefc4faa0b8afe7d38a53f297cf57e to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/06eefc4faa0b8afe7d38a53f297cf57e to your computer and use it in GitHub Desktop.
Display restricted PDFs inline in the browser
<?php
/**
* Display restricted PDFs inline in the browser for members with access.
*
* Restrict files: https://www.paidmembershipspro.com/locking-down-protecting-files-with-pmpro/
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_inline_restricted_pdfs( $content_disposition, $file, $file_dir, $file_path ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mime_type = finfo_file( $finfo, $file_path );
finfo_close( $finfo );
if ( 'application/pdf' === $mime_type ) {
return 'inline';
}
return $content_disposition;
}
add_filter( 'pmpro_restricted_file_content_disposition', 'my_pmpro_inline_restricted_pdfs', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment