Image Restriction by custom post type

Good evening,

I am using a plugin (“Enhanced Media Library” ) which allow me to attached categories on images of the Media Library.

I have defined 3 categories:

  • Public (few images per gallery) => users which are not logged (visitor)
  • Private (more images per gallery) => logged users (subscriber)
  • Friends (full access) => logged users with more permissions (contributors)

As you can see below:

I would like to publish all pictures in my post so every users can see only what they should see.

I would like achieve this without using any shortcode of S2member.

Can you please help me to create the PHP function that allow S2member automatically restrict the visibility of images (taking in consideration media categories), for each users, as it perfectly does for post categories?

I am very bad developper in PHP so my code is certainly wrong and stupid. It’s just a try to help you understand my need.

The custom post type is “media_category”.


$args =
        'post_type' => 'post',
            'taxonomy' => 'media_category',
            'field' => 'slug',
            'terms' => 'public,private,friends'

add_action('ws_plugin__s2member_after_security_gate', 'my_custom_security_gate');

function my_custom_security_gate()
    if is_user_not_logged_in() 

    global $post;

    if(is_singular() && $post->post_type === 'post')
   while  {
    >>>> echo media_category term('public') <<<<
    >>>> RESTRICT media_category term('private,friends') <<<<
  if  current_user_is())(str  $subscribor )() {

    >>>> echo media_category term('public,private') <<<<
    >>>> RESTRICT media_category term('friends') <<<<

   if current_user_is())(str  $contributor )() {

  >>>> echo 'Public,Private,Friends' <<<<
Thank you in advance for your help,