bp_search_is_post_restricted( int $post_id, int $user_id, string $type = 'post' )
Function to prevent to show the restricted content by third part plugins.
Description
Parameters
- $post_id
-
(Required) post id to check that it is restricted or not
- $user_id
-
(Required) user id to check that it is restricted or not
- $type
-
(Optional) component type
Default value: 'post'
Return
(array)
Source
File: bp-search/bp-search-functions.php
function bp_search_is_post_restricted( $post_id = 0, $user_id = 0, $type = 'post' ) {
$restricted_post_data = array();
if ( empty( $post_id ) ) {
return $restricted_post_data;
}
if ( class_exists( 'PMPro_Members_List_Table' ) ) {
$user_has_post_access = pmpro_has_membership_access( $post_id, $user_id );
// check for the default post.
if ( $user_has_post_access && 'post' === $type ) {
$restricted_post_data['post_class'] = 'has-access';
$restricted_post_data['post_thumbnail'] = get_the_post_thumbnail_url() ?: bp_search_get_post_thumbnail_default( get_post_type() );
$restricted_post_data['post_content'] = make_clickable( get_the_excerpt() );
} elseif ( 'post' === $type ) {
$restricted_post_data['post_class'] = 'has-no-access';
$restricted_post_data['post_thumbnail'] = bp_search_get_post_thumbnail_default( get_post_type() );
$restricted_post_data['post_content'] = pmpro_membership_content_filter( apply_filters( 'bp_post_restricted_message',
'This post has restricted content' ),
false );
}
// Check for the forums.
if ( $user_has_post_access && 'forum' === $type ) {
$restricted_post_data['post_class'] = 'has-access';
$restricted_post_data['post_thumbnail'] = bbp_get_forum_thumbnail_src( $post_id ) ?: bp_search_get_post_thumbnail_default( get_post_type() );
$restricted_post_data['post_content'] = wp_trim_words( bbp_get_forum_content( $post_id ), 30, '...' );
} elseif ( 'forum' === $type ) {
$restricted_post_data['post_class'] = 'has-no-access';
$restricted_post_data['post_thumbnail'] = bp_search_get_post_thumbnail_default( get_post_type() );
$restricted_post_data['post_content'] = pmpro_membership_content_filter( apply_filters( 'bp_post_restricted_message',
'This post has restricted content' ),
false );
}
} else {
$restricted_post_data['post_class'] = 'has-access';
$restricted_post_data['post_thumbnail'] = get_the_post_thumbnail_url() ?: bp_search_get_post_thumbnail_default( get_post_type() );
$restricted_post_data['post_content'] = make_clickable( get_the_excerpt() );
}
return $restricted_post_data;
}
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.