Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active January 16, 2019 14:59
Show Gist options
  • Save kimcoleman/16868cadce280415073b3d8812b56a91 to your computer and use it in GitHub Desktop.
Save kimcoleman/16868cadce280415073b3d8812b56a91 to your computer and use it in GitHub Desktop.
Filter the output of the Series post list to exclude posts the current user cannot access.
<?php
/*
* Filter the output of the Series post list to exclude posts the current user cannot access.
*/
function hide_noaccess_posts_pmpro_series( $post_list_posts, $series ) {
if ( function_exists( 'pmpro_has_membership_access' ) ) {
foreach ( $post_list_posts as $key => $sp ) {
$hasaccess = pmpro_has_membership_access( $sp->id, NULL, false );
if ( empty( $hasaccess ) ) {
unset( $post_list_posts[ $key ] );
}
}
}
return $post_list_posts;
}
add_filter( 'pmpro_series_post_list_posts', 'hide_noaccess_posts_pmpro_series', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment