Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created September 6, 2020 23:35
Show Gist options
  • Save KaineLabs/3f396e0c1c95ad0ff85803eb581d899e to your computer and use it in GitHub Desktop.
Save KaineLabs/3f396e0c1c95ad0ff85803eb581d899e to your computer and use it in GitHub Desktop.
Get Restrict Post Types for Visitors and Specific Roles and Show Restricted Content Notice
<?php
/**
* Get Restrict Post Types for Visitors and Specific Roles and Show Restricted Content Notice.
*/
function yzc_restrict_content( $content = null, $activity = null ) {
// Add Forbidden post types!
$forbidden_posts = array( 'activity_photo' );
// Add Forbidden roles.
$forbidden_roles = array( 'administrator' );
if ( in_array( $activity->type, $forbidden_posts ) ) {
// Get Current User Data.
$user = get_userdata( bp_loggedin_user_id() );
// Get Roles.
$user_role = (array) $user->roles[0];
if ( ! is_user_logged_in() || in_array( $user_role[0], $forbidden_roles ) ) {
// Change subscription link here.
$subscribe_link = 'https://wwww.website.com/subscribe-link-here';
return '<div class="yzc-restricted-content"style="background: #e0e0e0; padding: 35px;"><div style="text-align: center; padding: 100px; border-radius: 5px; color: #898989; border: 2px solid #eee; "><i class="fas fa-lock" style="width: 50px; height: 50px; color: #717171; background: #eeeeee; text-align: center; border-radius: 100%; line-height: 50px;"></i></div><a href="' . $subscribe_link . '" style="display: block; background: #03A9F4; text-align: center; padding: 18px; color: #fff; font-weight: 600; font-size: 14px; border-radius: 4px; margin-top: 15px; ">SUBSCRIBE TO SEE USERS POSTS</a></div>';
}
}
return $content;
}
add_filter( 'yz_activity_attachment_content', 'yzc_restrict_content', 10, 2 );
@mahfelwp
Copy link

mahfelwp commented Oct 16, 2020

doesnt exist "yz_activity_attachment_content" filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment