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
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | 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.